]> git.saurik.com Git - cycript.git/blob - Parser.ypp.in
97974929e8b0c1145e9624cbe5cd0dd29ea928be
[cycript.git] / Parser.ypp.in
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU Affero General Public License, Version 3 {{{ */
6 /*
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 %code top {
23 #define YYSTACKEXPANDABLE 1
24 }
25
26 %code requires {
27 #include "Driver.hpp"
28 #include "Parser.hpp"
29 #include "Stack.hpp"
30 #define CYNew new(driver.pool_)
31
32 @begin ObjectiveC
33 #include "ObjectiveC/Syntax.hpp"
34 @end
35
36 @begin E4X
37 #include "E4X/Syntax.hpp"
38 @end
39
40 #include "Highlight.hpp"
41 }
42
43 %union { bool bool_; }
44
45 %union { CYMember *access_; }
46 %union { CYArgument *argument_; }
47 %union { CYAssignment *assignment_; }
48 %union { CYBoolean *boolean_; }
49 %union { CYClause *clause_; }
50 %union { cy::Syntax::Catch *catch_; }
51 %union { CYClassTail *classTail_; }
52 %union { CYComprehension *comprehension_; }
53 %union { CYDeclaration *declaration_; }
54 %union { CYDeclarations *declarations_; }
55 %union { CYElement *element_; }
56 %union { CYExpression *expression_; }
57 %union { CYFalse *false_; }
58 %union { CYVariable *variable_; }
59 %union { CYFinally *finally_; }
60 %union { CYForInitializer *for_; }
61 %union { CYForInInitializer *forin_; }
62 %union { CYFunctionParameter *functionParameter_; }
63 %union { CYIdentifier *identifier_; }
64 %union { CYInfix *infix_; }
65 %union { CYLiteral *literal_; }
66 %union { CYMethod *method_; }
67 %union { CYModule *module_; }
68 %union { CYNull *null_; }
69 %union { CYNumber *number_; }
70 %union { CYParenthetical *parenthetical_; }
71 %union { CYProperty *property_; }
72 %union { CYPropertyName *propertyName_; }
73 %union { CYRubyProc *rubyProc_; }
74 %union { CYSpan *span_; }
75 %union { CYStatement *statement_; }
76 %union { CYString *string_; }
77 %union { CYTarget *target_; }
78 %union { CYThis *this_; }
79 %union { CYTrue *true_; }
80 %union { CYWord *word_; }
81
82 @begin C
83 %union { CYTypeModifier *modifier_; }
84 %union { CYTypeSpecifier *specifier_; }
85 %union { CYTypedIdentifier *typedIdentifier_; }
86 %union { CYTypedParameter *typedParameter_; }
87 @end
88
89 @begin ObjectiveC
90 %union { CYMessage *message_; }
91 %union { CYMessageParameter *messageParameter_; }
92 %union { CYImplementationField *implementationField_; }
93 %union { CYProtocol *protocol_; }
94 %union { CYSelectorPart *selector_; }
95 @end
96
97 @begin E4X
98 %union { CYAttribute *attribute_; }
99 %union { CYPropertyIdentifier *propertyIdentifier_; }
100 %union { CYSelector *selector_; }
101 @end
102
103 %code provides {
104
105 struct YYSTYPE {
106 cy::parser::semantic_type semantic_;
107 hi::Value highlight_;
108 };
109
110 int cylex(YYSTYPE *, CYLocation *, void *);
111
112 }
113
114 %code {
115
116 #undef yylex
117 _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
118 if (driver.mark_ == CYMarkIgnore);
119 else if (driver.mark_ == CYMarkScript) {
120 driver.mark_ = CYMarkIgnore;
121 return cy::parser::token::MarkScript;
122 } else if (driver.mark_ == CYMarkModule) {
123 driver.mark_ = CYMarkIgnore;
124 return cy::parser::token::MarkModule;
125 }
126
127 YYSTYPE data;
128 int token(cylex(&data, location, driver.scanner_));
129 *semantic = data.semantic_;
130 return token;
131 }
132
133 #define CYLEX() do if (yyla.empty()) { \
134 YYCDEBUG << "Mapping a token: "; \
135 yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \
136 YY_SYMBOL_PRINT("Next token is", yyla); \
137 } while (false)
138
139 #define CYMAP(to, from) do { \
140 CYLEX(); \
141 if (yyla.type == yytranslate_(token::from)) \
142 yyla.type = yytranslate_(token::to); \
143 } while (false)
144
145 #define CYERR(location, message) do { \
146 error(location, message); \
147 YYABORT; \
148 } while (false)
149
150 #define CYNOT(location) \
151 CYERR(location, "unimplemented feature")
152
153 }
154
155 %name-prefix "cy"
156
157 %language "C++"
158
159 %initial-action {
160 @$.begin.filename = @$.end.filename = &driver.filename_;
161 };
162
163 %locations
164 %defines
165
166 %define api.location.type { CYLocation }
167
168 //%glr-parser
169 //%expect 1
170
171 %error-verbose
172
173 %param { CYDriver &driver }
174
175 /* Token Declarations {{{ */
176 @begin E4X
177 %token XMLCDATA
178 %token XMLComment
179 %token XMLPI
180
181 %token XMLAttributeValue
182 %token XMLName
183 %token XMLTagCharacters
184 %token XMLText
185 %token XMLWhitespace
186 @end
187
188 @begin E4X
189 %token LeftRight "<>"
190 %token LeftSlashRight "</>"
191
192 %token SlashRight "/>"
193 %token LeftSlash "</"
194
195 %token ColonColon "::"
196 %token PeriodPeriod ".."
197 @end
198
199 @begin E4X ObjectiveC
200 %token At "@"
201 %token Pound "#"
202 @end
203
204 %token Ampersand "&"
205 %token AmpersandAmpersand "&&"
206 %token AmpersandEqual "&="
207 %token Carrot "^"
208 %token CarrotEqual "^="
209 %token Equal "="
210 %token EqualEqual "=="
211 %token EqualEqualEqual "==="
212 %token EqualRight "=>"
213 %token EqualRight_ "\n=>"
214 %token Exclamation "!"
215 %token ExclamationEqual "!="
216 %token ExclamationEqualEqual "!=="
217 %token Hyphen "-"
218 %token HyphenEqual "-="
219 %token HyphenHyphen "--"
220 %token HyphenHyphen_ "\n--"
221 %token HyphenRight "->"
222 %token Left "<"
223 %token LeftEqual "<="
224 %token LeftLeft "<<"
225 %token LeftLeftEqual "<<="
226 %token Percent "%"
227 %token PercentEqual "%="
228 %token Period "."
229 %token PeriodPeriodPeriod "..."
230 %token Pipe "|"
231 %token PipeEqual "|="
232 %token PipePipe "||"
233 %token Plus "+"
234 %token PlusEqual "+="
235 %token PlusPlus "++"
236 %token PlusPlus_ "\n++"
237 %token Right ">"
238 %token RightEqual ">="
239 %token RightRight ">>"
240 %token RightRightEqual ">>="
241 %token RightRightRight ">>>"
242 %token RightRightRightEqual ">>>="
243 %token Slash "/"
244 %token SlashEqual "/="
245 %token Star "*"
246 %token StarEqual "*="
247 %token Tilde "~"
248
249 %token Colon ":"
250 %token Comma ","
251 %token Question "?"
252 %token SemiColon ";"
253 %token NewLine "\n"
254
255 %token Comment
256
257 %token OpenParen "("
258 %token CloseParen ")"
259
260 %token OpenBrace "{"
261 %token OpenBrace_ "\n{"
262 %token OpenBrace__ ";{"
263 %token CloseBrace "}"
264
265 %token OpenBracket "["
266 %token CloseBracket "]"
267
268 %token At_error_ "@error"
269
270 @begin Java
271 %token At_class_ "@class"
272 @end
273
274 @begin C
275 %token _typedef_ "typedef"
276 %token _unsigned_ "unsigned"
277 %token _signed_ "signed"
278 %token _extern_ "extern"
279 @end
280
281 @begin C
282 %token At_encode_ "@encode"
283 @end
284
285 @begin ObjectiveC
286 %token At_implementation_ "@implementation"
287 %token At_import_ "@import"
288 %token At_end_ "@end"
289 %token At_selector_ "@selector"
290 %token At_null_ "@null"
291 %token At_YES_ "@YES"
292 %token At_NO_ "@NO"
293 %token At_true_ "@true"
294 %token At_false_ "@false"
295 %token _YES_ "YES"
296 %token _NO_ "NO"
297 @end
298
299 %token _false_ "false"
300 %token _null_ "null"
301 %token _true_ "true"
302
303 %token _break_ "break"
304 %token _case_ "case"
305 %token _catch_ "catch"
306 %token _class_ "class"
307 %token _class__ ";class"
308 %token _const_ "const"
309 %token _continue_ "continue"
310 %token _debugger_ "debugger"
311 %token _default_ "default"
312 %token _delete_ "delete"
313 %token _do_ "do"
314 %token _else_ "else"
315 %token _enum_ "enum"
316 %token _export_ "export"
317 %token _extends_ "extends"
318 %token _finally_ "finally"
319 %token _for_ "for"
320 %token _function_ "function"
321 %token _function__ ";function"
322 %token _if_ "if"
323 %token _import_ "import"
324 %token _in_ "in"
325 %token _in__ "!in"
326 %token _instanceof_ "instanceof"
327 %token _new_ "new"
328 %token _return_ "return"
329 %token _return__ "!return"
330 %token _super_ "super"
331 %token _super__ "!super"
332 %token _switch_ "switch"
333 %token _this_ "this"
334 %token _throw_ "throw"
335 %token _try_ "try"
336 %token _typeof_ "typeof"
337 %token _var_ "var"
338 %token _void_ "void"
339 %token _while_ "while"
340 %token _with_ "with"
341
342 %token _abstract_ "abstract"
343 %token _await_ "await"
344 %token _boolean_ "boolean"
345 %token _byte_ "byte"
346 %token _char_ "char"
347 %token _constructor_ "constructor"
348 %token _double_ "double"
349 %token _eval_ "eval"
350 %token _final_ "final"
351 %token _float_ "float"
352 %token _from_ "from"
353 %token _get_ "get"
354 %token _goto_ "goto"
355 %token _implements_ "implements"
356 %token _int_ "int"
357 %token _interface_ "interface"
358 %token _let_ "let"
359 %token _long_ "long"
360 %token _native_ "native"
361 %token _package_ "package"
362 %token _private_ "private"
363 %token _protected_ "protected"
364 %token _prototype_ "prototype"
365 %token _public_ "public"
366 %token _set_ "set"
367 %token _short_ "short"
368 %token _static_ "static"
369 %token _synchronized_ "synchronized"
370 %token _throws_ "throws"
371 %token _transient_ "transient"
372 %token _volatile_ "volatile"
373 %token _yield_ "yield"
374 %token _yield__ "!yield"
375
376 %token _undefined_ "undefined"
377
378 @begin ObjectiveC
379 %token _bool_ "bool"
380 %token _BOOL_ "BOOL"
381 %token _id_ "id"
382 %token _nil_ "nil"
383 %token _NULL_ "NULL"
384 %token _SEL_ "SEL"
385 @end
386
387 %token _auto_ "auto"
388 %token _each_ "each"
389 %token _of_ "of"
390
391 @begin E4X
392 %token _namespace_ "namespace"
393 %token _xml_ "xml"
394 @end
395
396 %token AutoComplete
397 %token YieldStar
398
399 %token <identifier_> Identifier_
400 %token <number_> NumericLiteral
401 %token <string_> StringLiteral
402 %token <literal_> RegularExpressionLiteral
403
404 %token <string_> NoSubstitutionTemplate
405 %token <string_> TemplateHead
406 %token <string_> TemplateMiddle
407 %token <string_> TemplateTail
408
409 %type <expression_> AdditiveExpression
410 %type <argument_> ArgumentList_
411 %type <argument_> ArgumentList
412 %type <argument_> ArgumentListOpt
413 %type <argument_> Arguments
414 %type <target_> ArrayComprehension
415 %type <literal_> ArrayLiteral
416 %type <expression_> ArrowFunction
417 %type <functionParameter_> ArrowParameters
418 %type <expression_> AssignmentExpression
419 %type <expression_> AssignmentExpressionOpt
420 %type <identifier_> BindingIdentifier
421 %type <identifier_> BindingIdentifierOpt
422 %type <declarations_> BindingList_
423 %type <declarations_> BindingList
424 %type <expression_> BitwiseANDExpression
425 %type <statement_> Block
426 %type <statement_> BlockStatement
427 %type <boolean_> BooleanLiteral
428 %type <declaration_> BindingElement
429 %type <expression_> BitwiseORExpression
430 %type <expression_> BitwiseXORExpression
431 %type <statement_> BreakStatement
432 %type <statement_> BreakableStatement
433 %type <expression_> CallExpression_
434 %type <target_> CallExpression
435 %type <clause_> CaseBlock
436 %type <clause_> CaseClause
437 %type <clause_> CaseClausesOpt
438 %type <catch_> Catch
439 %type <identifier_> CatchParameter
440 %type <statement_> ClassDeclaration
441 %type <target_> ClassExpression
442 %type <classTail_> ClassHeritage
443 %type <classTail_> ClassHeritageOpt
444 %type <classTail_> ClassTail
445 %type <target_> Comprehension
446 %type <comprehension_> ComprehensionFor
447 %type <comprehension_> ComprehensionIf
448 %type <comprehension_> ComprehensionTail
449 %type <propertyName_> ComputedPropertyName
450 %type <expression_> ConditionalExpression
451 %type <statement_> ContinueStatement
452 %type <statement_> ConciseBody
453 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
454 %type <statement_> DebuggerStatement
455 %type <statement_> Declaration__
456 %type <statement_> Declaration_
457 %type <statement_> Declaration
458 %type <clause_> DefaultClause
459 %type <element_> ElementList
460 %type <element_> ElementListOpt
461 %type <statement_> ElseStatementOpt
462 %type <for_> EmptyStatement
463 %type <expression_> EqualityExpression
464 %type <expression_> Expression
465 %type <expression_> ExpressionOpt
466 %type <for_> ExpressionStatement_
467 %type <statement_> ExpressionStatement
468 %type <finally_> Finally
469 %type <declaration_> ForBinding
470 %type <forin_> ForDeclaration
471 %type <forin_> ForInStatementInitializer
472 %type <for_> ForStatementInitializer
473 %type <declaration_> FormalParameter
474 %type <functionParameter_> FormalParameterList_
475 %type <functionParameter_> FormalParameterList
476 %type <functionParameter_> FormalParameters
477 %type <statement_> FunctionBody
478 %type <statement_> FunctionDeclaration
479 %type <target_> FunctionExpression
480 %type <statement_> FunctionStatementList
481 %type <statement_> GeneratorBody
482 %type <statement_> GeneratorDeclaration
483 %type <target_> GeneratorExpression
484 %type <method_> GeneratorMethod
485 %type <statement_> HoistableDeclaration
486 %type <identifier_> Identifier
487 %type <identifier_> IdentifierType
488 %type <word_> IdentifierName
489 %type <variable_> IdentifierReference
490 %type <statement_> IfStatement
491 %type <expression_> Initializer
492 %type <expression_> InitializerOpt
493 %type <statement_> IterationStatement
494 %type <identifier_> LabelIdentifier
495 %type <statement_> LabelledItem
496 %type <statement_> LabelledStatement
497 %type <target_> LeftHandSideExpression
498 %type <bool_> LetOrConst
499 %type <declaration_> LexicalBinding
500 %type <for_> LexicalDeclaration_
501 %type <statement_> LexicalDeclaration
502 %type <literal_> Literal
503 %type <propertyName_> LiteralPropertyName
504 %type <expression_> LogicalANDExpression
505 %type <expression_> LogicalORExpression
506 %type <access_> MemberAccess
507 %type <target_> MemberExpression
508 %type <method_> MethodDefinition
509 %type <module_> ModulePath
510 %type <expression_> MultiplicativeExpression
511 %type <target_> NewExpression
512 %type <null_> NullLiteral
513 %type <literal_> ObjectLiteral
514 %type <expression_> PostfixExpression
515 %type <target_> PrimaryExpression
516 %type <propertyName_> PropertyName
517 %type <property_> PropertyDefinition
518 %type <property_> PropertyDefinitionList_
519 %type <property_> PropertyDefinitionList
520 %type <property_> PropertyDefinitionListOpt
521 %type <declaration_> PropertySetParameterList
522 %type <expression_> RelationalExpression
523 %type <statement_> ReturnStatement
524 %type <rubyProc_> RubyProcExpression
525 %type <functionParameter_> RubyProcParameterList_
526 %type <functionParameter_> RubyProcParameterList
527 %type <functionParameter_> RubyProcParameters
528 %type <functionParameter_> RubyProcParametersOpt
529 %type <statement_> Script
530 %type <statement_> ScriptBody
531 %type <statement_> ScriptBodyOpt
532 %type <expression_> ShiftExpression
533 %type <declaration_> SingleNameBinding
534 %type <statement_> Statement__
535 %type <statement_> Statement_
536 %type <statement_> Statement
537 %type <statement_> StatementList
538 %type <statement_> StatementListOpt
539 %type <statement_> StatementListItem
540 %type <functionParameter_> StrictFormalParameters
541 %type <target_> SuperCall
542 %type <target_> SuperProperty
543 %type <statement_> SwitchStatement
544 %type <target_> TemplateLiteral
545 %type <span_> TemplateSpans
546 %type <statement_> ThrowStatement
547 %type <statement_> TryStatement
548 %type <expression_> UnaryExpression_
549 %type <expression_> UnaryExpression
550 %type <declaration_> VariableDeclaration
551 %type <declarations_> VariableDeclarationList_
552 %type <declarations_> VariableDeclarationList
553 %type <for_> VariableStatement_
554 %type <statement_> VariableStatement
555 %type <statement_> WithStatement
556 %type <word_> Word
557 @begin ObjectiveC
558 %type <word_> WordOpt
559 @end
560 %type <expression_> YieldExpression
561
562 @begin C
563 %type <specifier_> IntegerType
564 %type <specifier_> IntegerTypeOpt
565 %type <typedIdentifier_> PrefixedType
566 %type <specifier_> PrimitiveType
567 %type <typedIdentifier_> SuffixedType
568 %type <typedIdentifier_> TypeSignifier
569 %type <modifier_> TypeQualifierLeft
570 %type <typedIdentifier_> TypeQualifierRight
571 %type <typedIdentifier_> TypedIdentifier
572 %type <typedParameter_> TypedParameterList_
573 %type <typedParameter_> TypedParameterList
574 %type <typedParameter_> TypedParameterListOpt
575 @end
576
577 @begin ObjectiveC
578 %type <expression_> BoxableExpression
579 %type <statement_> CategoryStatement
580 %type <expression_> ClassSuperOpt
581 %type <implementationField_> ImplementationFieldListOpt
582 %type <implementationField_> ImplementationFields
583 %type <message_> ClassMessageDeclaration
584 %type <message_> ClassMessageDeclarationListOpt
585 %type <protocol_> ClassProtocolListOpt
586 %type <protocol_> ClassProtocols
587 %type <protocol_> ClassProtocolsOpt
588 %type <statement_> ImplementationStatement
589 %type <target_> MessageExpression
590 %type <messageParameter_> MessageParameter
591 %type <messageParameter_> MessageParameters
592 %type <messageParameter_> MessageParameterList
593 %type <messageParameter_> MessageParameterListOpt
594 %type <bool_> MessageScope
595 %type <argument_> SelectorCall_
596 %type <argument_> SelectorCall
597 %type <selector_> SelectorExpression_
598 %type <selector_> SelectorExpression
599 %type <selector_> SelectorExpressionOpt
600 %type <argument_> SelectorList
601 %type <word_> SelectorWordOpt
602 %type <typedIdentifier_> TypeOpt
603 %type <argument_> VariadicCall
604 @end
605
606 @begin E4X
607 %type <propertyIdentifier_> PropertyIdentifier_
608 %type <selector_> PropertySelector_
609 %type <selector_> PropertySelector
610 %type <identifier_> QualifiedIdentifier_
611 %type <identifier_> QualifiedIdentifier
612 %type <identifier_> WildcardIdentifier
613 %type <identifier_> XMLComment
614 %type <identifier_> XMLCDATA
615 %type <identifier_> XMLElement
616 %type <identifier_> XMLElementContent
617 %type <identifier_> XMLMarkup
618 %type <identifier_> XMLPI
619
620 %type <attribute_> AttributeIdentifier
621 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
622 %type <expression_> PropertyIdentifier
623 %type <expression_> XMLListInitialiser
624 %type <expression_> XMLInitialiser
625 @end
626 /* }}} */
627 /* Token Priorities {{{ */
628 %nonassoc ""
629 %left "++" "--" "{"
630
631 %nonassoc "if"
632 %nonassoc "else"
633 /* }}} */
634
635 %start Program
636 %token MarkModule
637 %token MarkScript
638
639 %%
640
641 Program
642 : MarkScript Script
643 | MarkModule Module
644 ;
645
646 /* Lexer State {{{ */
647 LexPushInOn: { driver.in_.push(true); };
648 LexPushInOff: { driver.in_.push(false); };
649 LexPopIn: { driver.in_.pop(); };
650
651 LexPushReturnOn: { driver.return_.push(true); };
652 LexPopReturn: { driver.return_.pop(); };
653
654 LexPushSuperOn: { driver.super_.push(true); };
655 LexPushSuperOff: { driver.super_.push(false); };
656 LexPopSuper: { driver.super_.pop(); };
657
658 LexPushYieldOn: { driver.yield_.push(true); };
659 LexPushYieldOff: { driver.yield_.push(false); };
660 LexPopYield: { driver.yield_.pop(); };
661
662 LexSetRegExp
663 : { CYLEX(); if (yyla.type == yytranslate_(token::Slash)) { yyla.clear(); driver.SetRegEx(false); } else if (yyla.type == yytranslate_(token::SlashEqual)) { yyla.clear(); driver.SetRegEx(true); } }
664 ;
665
666 LexNewLine
667 : { if (!yyla.empty() && yyla.type_get() != yyeof_) CYERR(@$, "unexpected lookahead"); driver.next_ = true; }
668 ;
669
670 LexNoStar
671 : { CYMAP(YieldStar, Star); }
672 ;
673
674 LexNoBrace
675 : { CYMAP(OpenBrace__, OpenBrace); CYMAP(OpenBrace__, OpenBrace_); }
676 ;
677
678 LexNoClass
679 : { CYMAP(_class__, _class_); }
680 ;
681
682 LexNoFunction
683 : { CYMAP(_function__, _function_); }
684 ;
685
686 LexSetStatement
687 : LexNoBrace LexNoClass LexNoFunction
688 ;
689 /* }}} */
690 /* Virtual Tokens {{{ */
691 BRACE
692 : "{"
693 | "\n{"
694 ;
695
696 Var_
697 : "var"
698 ;
699 /* }}} */
700
701 /* 11.6 Names and Keywords {{{ */
702 IdentifierName
703 : Word { $$ = $1; }
704 | "for" { $$ = CYNew CYWord("for"); }
705 | "in" { $$ = CYNew CYWord("in"); }
706 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
707 ;
708
709 NewLineOpt
710 : "\n"
711 |
712 ;
713
714 Word
715 : Identifier { $$ = $1; }
716 | "auto" { $$ = CYNew CYWord("auto"); }
717 | "break" { $$ = CYNew CYWord("break"); }
718 | "case" { $$ = CYNew CYWord("case"); }
719 | "catch" { $$ = CYNew CYWord("catch"); }
720 | "class" { $$ = CYNew CYWord("class"); }
721 | ";class" { $$ = CYNew CYWord("class"); }
722 | "const" { $$ = CYNew CYWord("const"); }
723 | "continue" { $$ = CYNew CYWord("continue"); }
724 | "debugger" { $$ = CYNew CYWord("debugger"); }
725 | "default" { $$ = CYNew CYWord("default"); }
726 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
727 | "do" { $$ = CYNew CYWord("do"); }
728 | "else" { $$ = CYNew CYWord("else"); }
729 | "enum" { $$ = CYNew CYWord("enum"); }
730 | "export" { $$ = CYNew CYWord("export"); }
731 | "extends" { $$ = CYNew CYWord("extends"); }
732 | "false" { $$ = CYNew CYWord("false"); }
733 | "finally" { $$ = CYNew CYWord("finally"); }
734 | "function" { $$ = CYNew CYWord("function"); }
735 | "if" { $$ = CYNew CYWord("if"); }
736 | "import" { $$ = CYNew CYWord("import"); }
737 | "!in" { $$ = CYNew CYWord("in"); }
738 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
739 | "null" { $$ = CYNew CYWord("null"); }
740 | "return" { $$ = CYNew CYWord("return"); }
741 | "!return" { $$ = CYNew CYWord("return"); }
742 | "super" { $$ = CYNew CYWord("super"); }
743 | "!super" { $$ = CYNew CYWord("super"); }
744 | "switch" { $$ = CYNew CYWord("switch"); }
745 | "this" { $$ = CYNew CYWord("this"); }
746 | "throw" { $$ = CYNew CYWord("throw"); }
747 | "true" { $$ = CYNew CYWord("true"); }
748 | "try" { $$ = CYNew CYWord("try"); }
749 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
750 | "var" { $$ = CYNew CYWord("var"); }
751 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
752 | "while" { $$ = CYNew CYWord("while"); }
753 | "with" { $$ = CYNew CYWord("with"); }
754 | "yield" { $$ = CYNew CYIdentifier("yield"); }
755
756 | Yield LexSetRegExp NewLineOpt { $$ = CYNew CYIdentifier("yield"); }
757
758 // XXX: should be Identifier
759 | "let" { $$ = CYNew CYIdentifier("let"); }
760 ;
761
762 @begin ObjectiveC
763 WordOpt
764 : Word { $$ = $1; }
765 | { $$ = NULL; }
766 ;
767 @end
768 /* }}} */
769 /* 11.8.1 Null Literals {{{ */
770 NullLiteral
771 : "null" { $$ = CYNew CYNull(); }
772 ;
773 /* }}} */
774 /* 11.8.2 Boolean Literals {{{ */
775 BooleanLiteral
776 : "true" { $$ = CYNew CYTrue(); }
777 | "false" { $$ = CYNew CYFalse(); }
778 ;
779 /* }}} */
780
781 /* 11.9 Automatic Semicolon Insertion {{{ */
782 StrictSemi
783 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
784 ;
785
786 TerminatorSoft
787 : ";"
788 | "\n" StrictSemi
789 ;
790
791 Terminator
792 : ";"
793 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) { CYERR(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
794 ;
795
796 TerminatorOpt
797 : ";"
798 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
799 ;
800 /* }}} */
801
802 /* 12.1 Identifiers {{{ */
803 IdentifierReference
804 : Identifier { $$ = CYNew CYVariable($1); }
805 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
806 ;
807
808 BindingIdentifier
809 : Identifier { $$ = $1; }
810 | "yield" { $$ = CYNew CYIdentifier("yield"); }
811 ;
812
813 BindingIdentifierOpt
814 : BindingIdentifier { $$ = $1; }
815 | { $$ = NULL; }
816 ;
817
818 LabelIdentifier
819 : Identifier { $$ = $1; }
820 | "yield" { $$ = CYNew CYIdentifier("yield"); }
821 ;
822
823 IdentifierType
824 : Identifier_ { $$ = $1; }
825 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
826 | "await" { $$ = CYNew CYIdentifier("await"); }
827 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
828 | "byte" { $$ = CYNew CYIdentifier("byte"); }
829 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
830 | "double" { $$ = CYNew CYIdentifier("double"); }
831 | "each" { $$ = CYNew CYIdentifier("each"); }
832 | "eval" { $$ = CYNew CYIdentifier("eval"); }
833 | "final" { $$ = CYNew CYIdentifier("final"); }
834 | "float" { $$ = CYNew CYIdentifier("float"); }
835 | "from" { $$ = CYNew CYIdentifier("from"); }
836 | "get" { $$ = CYNew CYIdentifier("get"); }
837 | "goto" { $$ = CYNew CYIdentifier("goto"); }
838 | "implements" { $$ = CYNew CYIdentifier("implements"); }
839 | "interface" { $$ = CYNew CYIdentifier("interface"); }
840 | "native" { $$ = CYNew CYIdentifier("native"); }
841 | "of" { $$ = CYNew CYIdentifier("of"); }
842 | "package" { $$ = CYNew CYIdentifier("package"); }
843 | "private" { $$ = CYNew CYIdentifier("private"); }
844 | "protected" { $$ = CYNew CYIdentifier("protected"); }
845 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
846 | "public" { $$ = CYNew CYIdentifier("public"); }
847 | "set" { $$ = CYNew CYIdentifier("set"); }
848 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
849 | "throws" { $$ = CYNew CYIdentifier("throws"); }
850 | "transient" { $$ = CYNew CYIdentifier("transient"); }
851 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
852 @begin ObjectiveC
853 | "bool" { $$ = CYNew CYIdentifier("bool"); }
854 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
855 | "id" { $$ = CYNew CYIdentifier("id"); }
856 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
857 @end
858 ;
859
860 Identifier
861 : IdentifierType
862 | "char" { $$ = CYNew CYIdentifier("char"); }
863 | "int" { $$ = CYNew CYIdentifier("int"); }
864 | "long" { $$ = CYNew CYIdentifier("long"); }
865 | "short" { $$ = CYNew CYIdentifier("short"); }
866 | "static" { $$ = CYNew CYIdentifier("static"); }
867 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
868 @begin C
869 | "extern" { $$ = CYNew CYIdentifier("extern"); }
870 | "signed" { $$ = CYNew CYIdentifier("signed"); }
871 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
872 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
873 @end
874 @begin ObjectiveC
875 | "nil" { $$ = CYNew CYIdentifier("nil"); }
876 | "NO" { $$ = CYNew CYIdentifier("NO"); }
877 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
878 | "YES" { $$ = CYNew CYIdentifier("YES"); }
879 @end
880 ;
881 /* }}} */
882 /* 12.2 Primary Expression {{{ */
883 PrimaryExpression
884 : "this" { $$ = CYNew CYThis(); }
885 | IdentifierReference { $$ = $1; }
886 | Literal { $$ = $1; }
887 | ArrayLiteral { $$ = $1; }
888 | ObjectLiteral { $$ = $1; }
889 | FunctionExpression { $$ = $1; }
890 | ClassExpression { $$ = $1; }
891 | GeneratorExpression { $$ = $1; }
892 | RegularExpressionLiteral { $$ = $1; }
893 | TemplateLiteral { $$ = $1; }
894 | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) CYERR(@1, "invalid parenthetical"); $$ = $1; }
895 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
896 ;
897
898 CoverParenthesizedExpressionAndArrowParameterList
899 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
900 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
901 | "(" LexPushInOff LexSetRegExp "..." BindingIdentifier ")" LexPopIn { CYNOT(@$); }
902 | "(" LexPushInOff Expression "," LexSetRegExp "..." BindingIdentifier ")" LexPopIn { CYNOT(@$); }
903 ;
904 /* }}} */
905 /* 12.2.4 Literals {{{ */
906 Literal
907 : NullLiteral { $$ = $1; }
908 | BooleanLiteral { $$ = $1; }
909 | NumericLiteral { $$ = $1; }
910 | StringLiteral { $$ = $1; }
911 ;
912 /* }}} */
913 /* 12.2.5 Array Initializer {{{ */
914 ArrayLiteral
915 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
916 ;
917
918 ElementList
919 : AssignmentExpressionOpt "," ElementListOpt { $$ = CYNew CYElementValue($1, $3); }
920 | LexSetRegExp "..." AssignmentExpression { $$ = CYNew CYElementSpread($3); }
921 | AssignmentExpression { $$ = CYNew CYElementValue($1, NULL); }
922 ;
923
924 ElementListOpt
925 : ElementList { $$ = $1; }
926 | LexSetRegExp { $$ = NULL; }
927 ;
928 /* }}} */
929 /* 12.2.6 Object Initializer {{{ */
930 ObjectLiteral
931 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
932 ;
933
934 PropertyDefinitionList_
935 : "," PropertyDefinitionListOpt { $$ = $2; }
936 | { $$ = NULL; }
937 ;
938
939 PropertyDefinitionList
940 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
941 ;
942
943 PropertyDefinitionListOpt
944 : LexSetRegExp PropertyDefinitionList { $$ = $2; }
945 | LexSetRegExp { $$ = NULL; }
946 ;
947
948 PropertyDefinition
949 : IdentifierReference { $$ = CYNew CYPropertyValue($1->name_, $1); }
950 | CoverInitializedName { CYNOT(@$); }
951 | PropertyName ":" AssignmentExpression { $$ = CYNew CYPropertyValue($1, $3); }
952 | MethodDefinition { $$ = $1; }
953 ;
954
955 PropertyName
956 : LiteralPropertyName { $$ = $1; }
957 | ComputedPropertyName { $$ = $1; }
958 ;
959
960 LiteralPropertyName
961 : IdentifierName { $$ = $1; }
962 | StringLiteral { $$ = $1; }
963 | NumericLiteral { $$ = $1; }
964 ;
965
966 ComputedPropertyName
967 : "[" AssignmentExpression "]" { $$ = CYNew CYComputed($2); }
968 ;
969
970 CoverInitializedName
971 : IdentifierReference Initializer
972 ;
973
974 Initializer
975 : "=" AssignmentExpression { $$ = $2; }
976 ;
977
978 InitializerOpt
979 : Initializer { $$ = $1; }
980 | { $$ = NULL; }
981 ;
982 /* }}} */
983 /* 12.2.9 Template Literals {{{ */
984 TemplateLiteral
985 : NoSubstitutionTemplate { $$ = CYNew CYTemplate($1, NULL); }
986 | TemplateHead TemplateSpans { $$ = CYNew CYTemplate($1, $2); }
987 ;
988
989 TemplateSpans
990 : Expression TemplateMiddle TemplateSpans { $$ = CYNew CYSpan($1, $2, $3); }
991 | Expression TemplateTail { $$ = CYNew CYSpan($1, $2, NULL); }
992 ;
993 /* }}} */
994
995 /* 12.3 Left-Hand-Side Expressions {{{ */
996 MemberAccess
997 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
998 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
999 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1000 | TemplateLiteral { CYNOT(@$); }
1001 ;
1002
1003 MemberExpression
1004 : LexSetRegExp PrimaryExpression { $$ = $2; }
1005 | MemberExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
1006 | SuperProperty { $$ = $1; }
1007 | MetaProperty { CYNOT(@$); }
1008 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
1009 ;
1010
1011 SuperProperty
1012 : LexSetRegExp "!super" "[" Expression "]" { $$ = CYNew CYSuperAccess($4); }
1013 | LexSetRegExp "!super" "." IdentifierName { $$ = CYNew CYSuperAccess(CYNew CYString($4)); }
1014 ;
1015
1016 MetaProperty
1017 : NewTarget
1018 ;
1019
1020 NewTarget
1021 : LexSetRegExp "new" LexSetRegExp "." "target"
1022 ;
1023
1024 NewExpression
1025 : MemberExpression { $$ = $1; }
1026 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
1027 ;
1028
1029 CallExpression_
1030 : MemberExpression { $$ = $1; }
1031 | CallExpression { $$ = $1; }
1032 ;
1033
1034 CallExpression
1035 : CallExpression_ Arguments { if (!$1->Eval()) $$ = CYNew CYCall($1, $2); else $$ = CYNew CYEval($2); }
1036 | SuperCall { $$ = $1; }
1037 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
1038 ;
1039
1040 SuperCall
1041 : LexSetRegExp "!super" Arguments { $$ = CYNew CYSuperCall($3); }
1042 ;
1043
1044 Arguments
1045 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
1046 ;
1047
1048 ArgumentList_
1049 : "," ArgumentList { $$ = $2; }
1050 | { $$ = NULL; }
1051 ;
1052
1053 ArgumentList
1054 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
1055 | LexSetRegExp "..." AssignmentExpression { CYNOT(@$); }
1056 ;
1057
1058 ArgumentListOpt
1059 : ArgumentList { $$ = $1; }
1060 | LexSetRegExp { $$ = NULL; }
1061 ;
1062
1063 LeftHandSideExpression
1064 : NewExpression { $$ = $1; }
1065 | CallExpression { $$ = $1; }
1066 ;
1067 /* }}} */
1068 /* 12.4 Postfix Expressions {{{ */
1069 PostfixExpression
1070 : %prec "" LeftHandSideExpression { $$ = $1; }
1071 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
1072 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
1073 ;
1074 /* }}} */
1075 /* 12.5 Unary Operators {{{ */
1076 UnaryExpression_
1077 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
1078 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
1079 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
1080 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
1081 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
1082 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
1083 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
1084 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
1085 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
1086 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
1087 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
1088 ;
1089
1090 UnaryExpression
1091 : %prec "" PostfixExpression { $$ = $1; }
1092 | LexSetRegExp UnaryExpression_ { $$ = $2; }
1093 ;
1094 /* }}} */
1095 /* 12.6 Multiplicative Operators {{{ */
1096 MultiplicativeExpression
1097 : UnaryExpression { $$ = $1; }
1098 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
1099 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
1100 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
1101 ;
1102 /* }}} */
1103 /* 12.7 Additive Operators {{{ */
1104 AdditiveExpression
1105 : MultiplicativeExpression { $$ = $1; }
1106 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
1107 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
1108 ;
1109 /* }}} */
1110 /* 12.8 Bitwise Shift Operators {{{ */
1111 ShiftExpression
1112 : AdditiveExpression { $$ = $1; }
1113 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
1114 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
1115 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
1116 ;
1117 /* }}} */
1118 /* 12.9 Relational Operators {{{ */
1119 RelationalExpression
1120 : ShiftExpression { $$ = $1; }
1121 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
1122 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
1123 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
1124 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
1125 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
1126 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
1127 ;
1128 /* }}} */
1129 /* 12.10 Equality Operators {{{ */
1130 EqualityExpression
1131 : RelationalExpression { $$ = $1; }
1132 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1133 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1134 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1135 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1136 ;
1137 /* }}} */
1138 /* 12.11 Binary Bitwise Operators {{{ */
1139 BitwiseANDExpression
1140 : EqualityExpression { $$ = $1; }
1141 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1142 ;
1143
1144 BitwiseXORExpression
1145 : BitwiseANDExpression { $$ = $1; }
1146 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1147 ;
1148
1149 BitwiseORExpression
1150 : BitwiseXORExpression { $$ = $1; }
1151 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1152 ;
1153 /* }}} */
1154 /* 12.12 Binary Logical Operators {{{ */
1155 LogicalANDExpression
1156 : BitwiseORExpression { $$ = $1; }
1157 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1158 ;
1159
1160 LogicalORExpression
1161 : LogicalANDExpression { $$ = $1; }
1162 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1163 ;
1164 /* }}} */
1165 /* 12.13 Conditional Operator ( ? : ) {{{ */
1166 ConditionalExpression
1167 : LogicalORExpression { $$ = $1; }
1168 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1169 ;
1170 /* }}} */
1171 /* 12.14 Assignment Operators {{{ */
1172 AssignmentExpression
1173 : ConditionalExpression { $$ = $1; }
1174 | LexSetRegExp YieldExpression { $$ = $2; }
1175 | ArrowFunction { $$ = $1; }
1176 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1177 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1178 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1179 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1180 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1181 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1182 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1183 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1184 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1185 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1186 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1187 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1188 ;
1189
1190 AssignmentExpressionOpt
1191 : AssignmentExpression { $$ = $1; }
1192 | LexSetRegExp { $$ = NULL; }
1193 ;
1194 /* }}} */
1195 /* 12.15 Comma Operator ( , ) {{{ */
1196 Expression
1197 : AssignmentExpression { $$ = $1; }
1198 | Expression "," AssignmentExpression { $$ = CYNew CYCompound($1, $3); }
1199 ;
1200
1201 ExpressionOpt
1202 : Expression { $$ = $1; }
1203 | LexSetRegExp { $$ = NULL; }
1204 ;
1205 /* }}} */
1206
1207 /* 13 Statements and Declarations {{{ */
1208 Statement__
1209 : BlockStatement { $$ = $1; }
1210 | VariableStatement { $$ = $1; }
1211 | EmptyStatement { $$ = $1; }
1212 | IfStatement { $$ = $1; }
1213 | BreakableStatement { $$ = $1; }
1214 | ContinueStatement { $$ = $1; }
1215 | BreakStatement { $$ = $1; }
1216 | ReturnStatement { $$ = $1; }
1217 | WithStatement { $$ = $1; }
1218 | LabelledStatement { $$ = $1; }
1219 | ThrowStatement { $$ = $1; }
1220 | TryStatement { $$ = $1; }
1221 | DebuggerStatement { $$ = $1; }
1222 ;
1223
1224 Statement_
1225 : LexSetRegExp Statement__ { $$ = $2; }
1226 | ExpressionStatement { $$ = $1; }
1227 ;
1228
1229 Statement
1230 : LexSetStatement Statement_ { $$ = $2; }
1231 ;
1232
1233 Declaration__
1234 : HoistableDeclaration { $$ = $1; }
1235 | ClassDeclaration { $$ = $1; }
1236 | LexicalDeclaration { $$ = $1; }
1237 ;
1238
1239 Declaration_
1240 : LexSetRegExp Declaration__ { $$ = $2; }
1241 ;
1242
1243 Declaration
1244 : LexSetStatement Declaration_ { $$ = $2; }
1245 ;
1246
1247 HoistableDeclaration
1248 : FunctionDeclaration { $$ = $1; }
1249 | GeneratorDeclaration { $$ = $1; }
1250 ;
1251
1252 BreakableStatement
1253 : IterationStatement { $$ = $1; }
1254 | SwitchStatement { $$ = $1; }
1255 ;
1256 /* }}} */
1257 /* 13.2 Block {{{ */
1258 BlockStatement
1259 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1260 ;
1261
1262 Block
1263 : BRACE StatementListOpt "}" { $$ = $2; }
1264 ;
1265
1266 StatementList
1267 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1268 ;
1269
1270 StatementListOpt
1271 : StatementList { $$ = $1; }
1272 | LexSetStatement LexSetRegExp { $$ = NULL; }
1273 ;
1274
1275 StatementListItem
1276 : Statement { $$ = $1; }
1277 | Declaration { $$ = $1; }
1278 ;
1279 /* }}} */
1280 /* 13.3 Let and Const Declarations {{{ */
1281 LexicalDeclaration_
1282 : LetOrConst BindingList { $$ = CYNew CYLet($1, $2); }
1283 ;
1284
1285 LexicalDeclaration
1286 : LexicalDeclaration_ Terminator { $$ = $1; }
1287 ;
1288
1289 LetOrConst
1290 : "let" { $$ = false; }
1291 | "const" { $$ = true; }
1292 ;
1293
1294 BindingList_
1295 : "," BindingList { $$ = $2; }
1296 | { $$ = NULL; }
1297 ;
1298
1299 BindingList
1300 : LexicalBinding BindingList_ { $$ = CYNew CYDeclarations($1, $2); }
1301 ;
1302
1303 LexicalBinding
1304 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1305 | BindingPattern Initializer { CYNOT(@1); }
1306 ;
1307 /* }}} */
1308 /* 13.3.2 Variable Statement {{{ */
1309 VariableStatement_
1310 : Var_ VariableDeclarationList { $$ = CYNew CYVar($2); }
1311 ;
1312
1313 VariableStatement
1314 : VariableStatement_ Terminator { $$ = $1; }
1315 ;
1316
1317 VariableDeclarationList_
1318 : "," VariableDeclarationList { $$ = $2; }
1319 | { $$ = NULL; }
1320 ;
1321
1322 VariableDeclarationList
1323 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1324 ;
1325
1326 VariableDeclaration
1327 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1328 | BindingPattern Initializer { CYNOT(@1); }
1329 ;
1330 /* }}} */
1331 /* 13.3.3 Destructuring Binding Patterns {{{ */
1332 BindingPattern
1333 : ObjectBindingPattern
1334 | ArrayBindingPattern
1335 ;
1336
1337 ObjectBindingPattern
1338 : BRACE BindingPropertyListOpt "}"
1339 ;
1340
1341 ArrayBindingPattern
1342 : "[" { CYNOT(@$); }
1343 ;
1344
1345 BindingPropertyList_
1346 : "," BindingPropertyListOpt
1347 |
1348 ;
1349
1350 BindingPropertyList
1351 : BindingProperty BindingPropertyList_
1352 ;
1353
1354 BindingPropertyListOpt
1355 : BindingPropertyList
1356 |
1357 ;
1358
1359 BindingProperty
1360 : SingleNameBinding
1361 | PropertyName ":" BindingElement
1362 ;
1363
1364 BindingElement
1365 : SingleNameBinding { $$ = $1; }
1366 | BindingPattern InitializerOpt { CYNOT(@$); }
1367 ;
1368
1369 SingleNameBinding
1370 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1371 ;
1372
1373 BindingRestElement
1374 : "..." BindingIdentifier
1375 ;
1376 /* }}} */
1377 /* 13.4 Empty Statement {{{ */
1378 EmptyStatement
1379 : ";" { $$ = CYNew CYEmpty(); }
1380 ;
1381 /* }}} */
1382 /* 13.5 Expression Statement {{{ */
1383 ExpressionStatement_
1384 : Expression { $$ = CYNew CYExpress($1); }
1385
1386 ExpressionStatement
1387 : ExpressionStatement_ Terminator { $$ = $1; }
1388 ;
1389 /* }}} */
1390 /* 13.6 The if Statement {{{ */
1391 ElseStatementOpt
1392 : "else" Statement { $$ = $2; }
1393 | %prec "if" { $$ = NULL; }
1394 ;
1395
1396 IfStatement
1397 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1398 ;
1399 /* }}} */
1400 /* 13.7 Iteration Statements {{{ */
1401 IterationStatement
1402 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1403 | "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1404 | "for" "(" LexPushInOn ForStatementInitializer LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $6, $8, $10); }
1405 | "for" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1406 | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn AssignmentExpression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1407 ;
1408
1409 ForStatementInitializer
1410 : LexSetRegExp EmptyStatement { $$ = $2; }
1411 | ExpressionStatement_ ";" { $$ = $1; }
1412 | LexSetRegExp VariableStatement_ ";" { $$ = $2; }
1413 | LexSetRegExp LexicalDeclaration_ ";" { $$ = $2; }
1414 ;
1415
1416 ForInStatementInitializer
1417 : LeftHandSideExpression { $$ = $1; }
1418 | LexSetRegExp Var_ ForBinding { $$ = CYNew CYForVariable($3); }
1419 | LexSetRegExp ForDeclaration { $$ = $2; }
1420 ;
1421
1422 ForDeclaration
1423 : LetOrConst ForBinding { $$ = CYNew CYForLexical($1, $2); }
1424 ;
1425
1426 ForBinding
1427 : BindingIdentifier { $$ = CYNew CYDeclaration($1, NULL); }
1428 | BindingPattern { CYNOT(@1); }
1429 ;
1430 /* }}} */
1431 /* 13.8 The continue Statement {{{ */
1432 Continue
1433 : "continue" LexNewLine
1434 ;
1435
1436 ContinueStatement
1437 : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1438 | Continue Identifier Terminator { $$ = CYNew CYContinue($2); }
1439 ;
1440 /* }}} */
1441 /* 13.9 The break Statement {{{ */
1442 Break
1443 : "break" LexNewLine
1444 ;
1445
1446 BreakStatement
1447 : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1448 | Break Identifier Terminator { $$ = CYNew CYBreak($2); }
1449 ;
1450 /* }}} */
1451 /* 13.10 The return Statement {{{ */
1452 Return
1453 : "!return" LexNewLine
1454 ;
1455
1456 ReturnStatement
1457 : Return LexSetRegExp TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1458 | Return Expression Terminator { $$ = CYNew CYReturn($2); }
1459 ;
1460 /* }}} */
1461 /* 13.11 The with Statement {{{ */
1462 WithStatement
1463 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1464 ;
1465 /* }}} */
1466 /* 13.12 The switch Statement {{{ */
1467 SwitchStatement
1468 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1469 ;
1470
1471 CaseBlock
1472 : BRACE CaseClausesOpt "}" { $$ = $2; }
1473 ;
1474
1475 CaseClause
1476 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1477 ;
1478
1479 CaseClausesOpt
1480 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1481 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1482 | { $$ = NULL; }
1483 ;
1484
1485 // XXX: the standard makes certain you can only have one of these
1486 DefaultClause
1487 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1488 ;
1489 /* }}} */
1490 /* 13.13 Labelled Statements {{{ */
1491 LabelledStatement
1492 : LabelIdentifier ":" LabelledItem { $$ = CYNew CYLabel($1, $3); }
1493 ;
1494
1495 LabelledItem
1496 : Statement { $$ = $1; }
1497 | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; }
1498 ;
1499 /* }}} */
1500 /* 13.14 The throw Statement {{{ */
1501 Throw
1502 : "throw" LexNewLine
1503 ;
1504
1505 ThrowStatement
1506 : Throw LexSetRegExp TerminatorSoft { CYERR(@1, "throw without exception"); }
1507 | Throw Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1508 ;
1509 /* }}} */
1510 /* 13.15 The try Statement {{{ */
1511 TryStatement
1512 : "try" Block Catch { $$ = CYNew cy::Syntax::Try($2, $3, NULL); }
1513 | "try" Block Finally { $$ = CYNew cy::Syntax::Try($2, NULL, $3); }
1514 | "try" Block Catch Finally { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1515 ;
1516
1517 Catch
1518 : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); }
1519 ;
1520
1521 Finally
1522 : "finally" Block { $$ = CYNew CYFinally($2); }
1523 ;
1524
1525 CatchParameter
1526 : BindingIdentifier { $$ = $1; }
1527 | BindingPattern { CYNOT(@$); }
1528 ;
1529 /* }}} */
1530 /* 13.16 The debugger Statement {{{ */
1531 DebuggerStatement
1532 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1533 ;
1534 /* }}} */
1535
1536 /* 14.1 Function Definitions {{{ */
1537 FunctionDeclaration
1538 : ";function" BindingIdentifier "(" FormalParameters ")" BRACE LexPushSuperOff FunctionBody "}" LexPopSuper { $$ = CYNew CYFunctionStatement($2, $4, $8); }
1539 ;
1540
1541 FunctionExpression
1542 : "function" BindingIdentifierOpt "(" LexPushInOff FormalParameters ")" LexPopIn BRACE LexPushSuperOff LexPushInOff FunctionBody "}" LexPopIn LexPopSuper { $$ = CYNew CYFunctionExpression($2, $5, $11); }
1543 ;
1544
1545 StrictFormalParameters
1546 : FormalParameters { $$ = $1; }
1547 ;
1548
1549 FormalParameters
1550 : { $$ = NULL; }
1551 | FormalParameterList
1552 ;
1553
1554 FormalParameterList_
1555 : "," FormalParameterList { $$ = $2; }
1556 | { $$ = NULL; }
1557 ;
1558
1559 FormalParameterList
1560 : FunctionRestParameter { CYNOT(@$); }
1561 | FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1562 ;
1563
1564 FunctionRestParameter
1565 : BindingRestElement
1566 ;
1567
1568 FormalParameter
1569 : BindingElement { $$ = $1; }
1570 ;
1571
1572 FunctionBody
1573 : LexPushYieldOff FunctionStatementList LexPopYield { $$ = $2; }
1574 ;
1575
1576 FunctionStatementList
1577 : LexPushReturnOn StatementListOpt LexPopReturn { $$ = $2; }
1578 ;
1579 /* }}} */
1580 /* 14.2 Arrow Function Definitions {{{ */
1581 ArrowFunction
1582 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1583 ;
1584
1585 ArrowParameters
1586 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1587 | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) $$ = NULL; else { $$ = $1->expression_->Parameter(); if ($$ == NULL) CYERR(@1, "invalid parameter list"); } }
1588 ;
1589
1590 ConciseBody
1591 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1592 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1593 ;
1594 /* }}} */
1595 /* 14.3 Method Definitions {{{ */
1596 MethodDefinition
1597 : PropertyName "(" StrictFormalParameters ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertyMethod($1, $3, $6); }
1598 | GeneratorMethod { $$ = $1; }
1599 | "get" PropertyName "(" ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertyGetter($2, $6); }
1600 | "set" PropertyName "(" PropertySetParameterList ")" BRACE FunctionBody "}" { $$ = CYNew CYPropertySetter($2, CYNew CYFunctionParameter($4), $7); }
1601 ;
1602
1603 PropertySetParameterList
1604 : FormalParameter { $$ = $1; }
1605 ;
1606 /* }}} */
1607 /* 14.4 Generator Function Definitions {{{ */
1608 GeneratorMethod
1609 : "*" PropertyName "(" StrictFormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($2, $4, $7); */ }
1610 ;
1611
1612 GeneratorDeclaration
1613 : ";function" "*" BindingIdentifier "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($3, $5, $8); */ }
1614 ;
1615
1616 GeneratorExpression
1617 : "function" "*" BindingIdentifierOpt "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($3, $5, $8); */ }
1618 ;
1619
1620 GeneratorBody
1621 : LexPushYieldOn FunctionStatementList LexPopYield { $$ = $2; }
1622 ;
1623
1624 Yield
1625 : "!yield" LexNewLine LexNoStar
1626 ;
1627
1628 YieldExpression
1629 : Yield LexSetRegExp "\n" { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1630 | Yield AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldValue($2); */ }
1631 | Yield LexSetRegExp YieldStar AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($4); */ }
1632 ;
1633 /* }}} */
1634 /* 14.5 Class Definitions {{{ */
1635 ClassDeclaration
1636 : ";class" BindingIdentifier ClassTail { $$ = CYNew CYClassStatement($2, $3); }
1637 ;
1638
1639 ClassExpression
1640 : "class" BindingIdentifierOpt ClassTail { $$ = CYNew CYClassExpression($2, $3); }
1641 ;
1642
1643 ClassTail
1644 : ClassHeritageOpt { driver.class_.push($1); } BRACE LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $1; }
1645 ;
1646
1647 ClassHeritage
1648 : "extends" LeftHandSideExpression { $$ = CYNew CYClassTail($2); }
1649 ;
1650
1651 ClassHeritageOpt
1652 : ClassHeritage { $$ = $1; }
1653 | { $$ = CYNew CYClassTail(NULL); }
1654 ;
1655
1656 ClassBody
1657 : ClassElementList
1658 ;
1659
1660 ClassBodyOpt
1661 : ClassBody
1662 |
1663 ;
1664
1665 ClassElementList
1666 : ClassElementListOpt ClassElement
1667 ;
1668
1669 ClassElementListOpt
1670 : ClassElementList
1671 |
1672 ;
1673
1674 ClassElement
1675 : MethodDefinition { if (CYFunctionExpression *constructor = $1->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$1; }
1676 | "static" MethodDefinition { driver.class_.top()->static_->*$2; }
1677 | ";"
1678 ;
1679 /* }}} */
1680
1681 /* 15.1 Scripts {{{ */
1682 Script
1683 : ScriptBodyOpt { driver.script_ = CYNew CYScript($1); }
1684 ;
1685
1686 ScriptBody
1687 : StatementList { $$ = $1; }
1688 ;
1689
1690 ScriptBodyOpt
1691 : ScriptBody { $$ = $1; }
1692 | LexSetStatement LexSetRegExp { $$ = NULL; }
1693 ;
1694 /* }}} */
1695 /* 15.2 Modules {{{ */
1696 Module
1697 : ModuleBodyOpt
1698 ;
1699
1700 ModuleBody
1701 : ModuleItemList
1702 ;
1703
1704 ModuleBodyOpt
1705 : ModuleBody
1706 |
1707 ;
1708
1709 ModuleItemList
1710 : ModuleItemListOpt ModuleItem
1711 ;
1712
1713 ModuleItemListOpt
1714 : ModuleItemList
1715 |
1716 ;
1717
1718 ModuleItem
1719 : LexSetStatement LexSetRegExp ImportDeclaration
1720 | LexSetStatement LexSetRegExp ExportDeclaration
1721 | StatementListItem
1722 ;
1723 /* }}} */
1724 /* 15.2.2 Imports {{{ */
1725 ImportDeclaration
1726 : "import" ImportClause FromClause Terminator
1727 | "import" ModuleSpecifier Terminator
1728 ;
1729
1730 ImportClause
1731 : ImportedDefaultBinding
1732 | NameSpaceImport
1733 | NamedImports
1734 | ImportedDefaultBinding "," NameSpaceImport
1735 | ImportedDefaultBinding "," NamedImports
1736 ;
1737
1738 ImportedDefaultBinding
1739 : ImportedBinding
1740 ;
1741
1742 NameSpaceImport
1743 : "*" "as" ImportedBinding
1744 ;
1745
1746 NamedImports
1747 : BRACE ImportsListOpt "}"
1748 ;
1749
1750 FromClause
1751 : "from" ModuleSpecifier
1752 ;
1753
1754 ImportsList_
1755 : "," ImportsListOpt
1756 |
1757 ;
1758
1759 ImportsList
1760 : ImportSpecifier ImportsList_
1761 ;
1762
1763 ImportsListOpt
1764 : ImportsList
1765 |
1766 ;
1767
1768 ImportSpecifier
1769 : ImportedBinding
1770 | IdentifierName "as" ImportedBinding
1771 ;
1772
1773 ModuleSpecifier
1774 : StringLiteral
1775 ;
1776
1777 ImportedBinding
1778 : BindingIdentifier
1779 ;
1780 /* }}} */
1781 /* 15.2.3 Exports {{{ */
1782 ExportDeclaration_
1783 : "*" FromClause Terminator
1784 | ExportClause FromClause Terminator
1785 | ExportClause Terminator
1786 | VariableStatement
1787 | "default" LexSetStatement LexSetRegExp HoistableDeclaration
1788 | "default" LexSetStatement LexSetRegExp ClassDeclaration
1789 | "default" LexSetStatement AssignmentExpression Terminator
1790 ;
1791
1792 ExportDeclaration
1793 : "export" LexSetStatement LexSetRegExp ExportDeclaration_
1794 | "export" Declaration
1795 ;
1796
1797 ExportClause
1798 : ";{" ExportsListOpt "}"
1799 ;
1800
1801 ExportsList_
1802 : "," ExportsListOpt
1803 |
1804 ;
1805
1806 ExportsList
1807 : ExportSpecifier ExportsList_
1808 ;
1809
1810 ExportsListOpt
1811 : ExportsList
1812 |
1813 ;
1814
1815 ExportSpecifier
1816 : IdentifierName
1817 | IdentifierName "as" IdentifierName
1818 ;
1819 /* }}} */
1820
1821 @begin C
1822 /* Cycript (C): Type Encoding {{{ */
1823 TypeSignifier
1824 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1825 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1826 ;
1827
1828 SuffixedType
1829 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1830 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1831 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1832 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1833 | TypeSignifier { $$ = $1; }
1834 | { $$ = CYNew CYTypedIdentifier(@$); }
1835 ;
1836
1837 PrefixedType
1838 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1839 ;
1840
1841 TypeQualifierLeft
1842 : { $$ = NULL; }
1843 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1844 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1845 ;
1846
1847 TypeQualifierRight
1848 : PrefixedType { $$ = $1; }
1849 | SuffixedType { $$ = $1; }
1850 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1851 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1852 ;
1853
1854 IntegerType
1855 : "int" { $$ = CYNew CYTypeVariable("int"); }
1856 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1857 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1858 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1859 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1860 ;
1861
1862 IntegerTypeOpt
1863 : IntegerType { $$ = $1; }
1864 | { $$ = CYNew CYTypeVariable("int"); }
1865 ;
1866
1867 PrimitiveType
1868 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1869 | IntegerType { $$ = $1; }
1870 | "void" { $$ = CYNew CYTypeVoid(); }
1871 | "char" { $$ = CYNew CYTypeVariable("char"); }
1872 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1873 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1874 ;
1875
1876 TypedIdentifier
1877 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1878 ;
1879
1880 PrimaryExpression
1881 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1882 ;
1883 /* }}} */
1884 @end
1885
1886 @begin ObjectiveC
1887 /* Cycript (Objective-C): @class Declaration {{{ */
1888 ClassSuperOpt
1889 /* XXX: why the hell did I choose MemberExpression? */
1890 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1891 | { $$ = NULL; }
1892 ;
1893
1894 ImplementationFieldListOpt
1895 : TypedIdentifier ";" ImplementationFieldListOpt { $$ = CYNew CYImplementationField($1, $3); }
1896 | LexSetRegExp { $$ = NULL; }
1897 ;
1898
1899 ImplementationFields
1900 : BRACE ImplementationFieldListOpt "}" { $$ = $2; }
1901 ;
1902
1903 MessageScope
1904 : "+" { $$ = false; }
1905 | "-" { $$ = true; }
1906 ;
1907
1908 TypeOpt
1909 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) CYERR($3->location_, "unexpected identifier"); $$ = $3; }
1910 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1911 ;
1912
1913 MessageParameter
1914 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1915 ;
1916
1917 MessageParameterList
1918 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1919 ;
1920
1921 MessageParameterListOpt
1922 : MessageParameterList { $$ = $1; }
1923 | { $$ = NULL; }
1924 ;
1925
1926 MessageParameters
1927 : MessageParameterList { $$ = $1; }
1928 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1929 ;
1930
1931 ClassMessageDeclaration
1932 : MessageScope TypeOpt MessageParameters BRACE LexPushSuperOn FunctionBody "}" LexPopSuper { $$ = CYNew CYMessage($1, $2, $3, $6); }
1933 ;
1934
1935 ClassMessageDeclarationListOpt
1936 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1937 | { $$ = NULL; }
1938 ;
1939
1940 // XXX: this should be AssignmentExpressionNoRight
1941 ClassProtocols
1942 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1943 ;
1944
1945 ClassProtocolsOpt
1946 : "," ClassProtocols { $$ = $2; }
1947 | { $$ = NULL; }
1948 ;
1949
1950 ClassProtocolListOpt
1951 : "<" ClassProtocols ">" { $$ = $2; }
1952 | { $$ = NULL; }
1953 ;
1954
1955 ImplementationStatement
1956 : "@implementation" Identifier ClassSuperOpt ClassProtocolListOpt ImplementationFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYImplementation($2, $3, $4, $5, $6); }
1957 ;
1958
1959 CategoryName
1960 : "(" WordOpt ")"
1961 ;
1962
1963 CategoryStatement
1964 : "@implementation" Identifier CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1965 ;
1966
1967 Statement__
1968 : ImplementationStatement { $$ = $1; }
1969 | CategoryStatement { $$ = $1; }
1970 ;
1971 /* }}} */
1972 /* Cycript (Objective-C): Send Message {{{ */
1973 VariadicCall
1974 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1975 | { $$ = NULL; }
1976 ;
1977
1978 SelectorWordOpt
1979 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1980 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1981 ;
1982
1983 SelectorCall_
1984 : SelectorCall { $$ = $1; }
1985 | VariadicCall { $$ = $1; }
1986 ;
1987
1988 SelectorCall
1989 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1990 ;
1991
1992 SelectorList
1993 : SelectorCall { $$ = $1; }
1994 | Word { $$ = CYNew CYArgument($1, NULL); }
1995 ;
1996
1997 MessageExpression
1998 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1999 | "[" LexPushInOff LexSetRegExp "!super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
2000 ;
2001
2002 SelectorExpression_
2003 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
2004 ;
2005
2006 SelectorExpression
2007 : SelectorExpression_ { $$ = $1; }
2008 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
2009 ;
2010
2011 SelectorExpressionOpt
2012 : SelectorExpression_ { $$ = $1; }
2013 | { $$ = NULL; }
2014 ;
2015
2016 PrimaryExpression
2017 : MessageExpression { $$ = $1; }
2018 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
2019 ;
2020 /* }}} */
2021 @end
2022
2023 /* Cycript: @import Directive {{{ */
2024 ModulePath
2025 : ModulePath "." Word { $$ = CYNew CYModule($3, $1); }
2026 | Word { $$ = CYNew CYModule($1); }
2027 ;
2028
2029 Declaration__
2030 : "@import" ModulePath { $$ = CYNew CYImport($2); }
2031 ;
2032 /* }}} */
2033
2034 @begin ObjectiveC
2035 /* Cycript (Objective-C): Boxed Expressions {{{ */
2036 BoxableExpression
2037 : NullLiteral { $$ = $1; }
2038 | BooleanLiteral { $$ = $1; }
2039 | NumericLiteral { $$ = $1; }
2040 | StringLiteral { $$ = $1; }
2041 | ArrayLiteral { $$ = $1; }
2042 | ObjectLiteral { $$ = $1; }
2043 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1; }
2044 | "YES" { $$ = CYNew CYTrue(); }
2045 | "NO" { $$ = CYNew CYFalse(); }
2046 ;
2047
2048 PrimaryExpression
2049 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
2050 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2051 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2052 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2053 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2054 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2055 ;
2056 /* }}} */
2057 /* Cycript (Objective-C): Block Expressions {{{ */
2058 PrimaryExpression
2059 : "^" TypedIdentifier { if ($2->identifier_ != NULL) CYERR($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else CYERR($2->location_, "expected parameters"); }
2060 ;
2061 /* }}} */
2062 /* Cycript (Objective-C): Instance Literals {{{ */
2063 PrimaryExpression
2064 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
2065 ;
2066 /* }}} */
2067 @end
2068
2069 @begin C
2070 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2071 LeftHandSideExpression
2072 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
2073 ;
2074
2075 UnaryExpression_
2076 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
2077 ;
2078
2079 MemberAccess
2080 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
2081 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
2082 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2083 ;
2084 /* }}} */
2085 /* Cycript (C): auto Compatibility {{{ */
2086 Var_
2087 : "auto"
2088 ;
2089 /* }}} */
2090 /* Cycript (C): Lambda Expressions {{{ */
2091 TypedParameterList_
2092 : "," TypedParameterList { $$ = $2; }
2093 | { $$ = NULL; }
2094 ;
2095
2096 TypedParameterList
2097 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
2098 ;
2099
2100 TypedParameterListOpt
2101 : TypedParameterList { $$ = $1; }
2102 | { $$ = NULL; }
2103 ;
2104
2105 PrimaryExpression
2106 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
2107 ;
2108 /* }}} */
2109 /* Cycript (C): Type Definitions {{{ */
2110 Statement__
2111 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) CYERR($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
2112 ;
2113 /* }}} */
2114 /* Cycript (C): extern "C" {{{ */
2115 Statement__
2116 : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) CYERR(@2, "unknown extern binding"); } TypedIdentifier { if ($4->identifier_ == NULL) CYERR($4->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($2, $4); }
2117 ;
2118 /* }}} */
2119
2120 @end
2121
2122 @begin E4X
2123 /* Lexer State {{{ */
2124 LexPushRegExp
2125 : { driver.PushCondition(CYDriver::RegExpCondition); }
2126 ;
2127
2128 LexPushXMLContent
2129 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2130 ;
2131
2132 LexPushXMLTag
2133 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2134 ;
2135
2136 LexPop
2137 : { driver.PopCondition(); }
2138 ;
2139
2140 LexSetXMLContent
2141 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2142 ;
2143
2144 LexSetXMLTag
2145 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2146 ;
2147 /* }}} */
2148 /* Virtual Tokens {{{ */
2149 XMLWhitespaceOpt
2150 : XMLWhitespace
2151 |
2152 ;
2153 /* }}} */
2154
2155 /* 8.1 Context Keywords {{{ */
2156 Identifier
2157 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2158 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2159 ;
2160 /* }}} */
2161 /* 8.3 XML Initializer Input Elements {{{ */
2162 XMLMarkup
2163 : XMLComment { $$ = $1; }
2164 | XMLCDATA { $$ = $1; }
2165 | XMLPI { $$ = $1; }
2166 ;
2167 /* }}} */
2168
2169 /* 11.1 Primary Expressions {{{ */
2170 PrimaryExpression
2171 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2172 | XMLInitialiser { $$ = $1; }
2173 | XMLListInitialiser { $$ = $1; }
2174 ;
2175
2176 PropertyIdentifier
2177 : AttributeIdentifier { $$ = $1; }
2178 | QualifiedIdentifier { $$ = $1; }
2179 | WildcardIdentifier { $$ = $1; }
2180 ;
2181 /* }}} */
2182 /* 11.1.1 Attribute Identifiers {{{ */
2183 AttributeIdentifier
2184 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2185 ;
2186
2187 PropertySelector_
2188 : PropertySelector { $$ = $1; }
2189 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
2190 ;
2191
2192 PropertySelector
2193 : Identifier { $$ = CYNew CYSelector($1); }
2194 | WildcardIdentifier { $$ = $1; }
2195 ;
2196 /* }}} */
2197 /* 11.1.2 Qualified Identifiers {{{ */
2198 QualifiedIdentifier_
2199 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2200 | QualifiedIdentifier { $$ = $1; }
2201 ;
2202
2203 QualifiedIdentifier
2204 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2205 ;
2206 /* }}} */
2207 /* 11.1.3 Wildcard Identifiers {{{ */
2208 WildcardIdentifier
2209 : "*" { $$ = CYNew CYWildcard(); }
2210 ;
2211 /* }}} */
2212 /* 11.1.4 XML Initializer {{{ */
2213 XMLInitialiser
2214 : XMLMarkup { $$ = $1; }
2215 | XMLElement { $$ = $1; }
2216 ;
2217
2218 XMLElement
2219 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2220 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2221 ;
2222
2223 XMLTagContent
2224 : LexPushXMLTag XMLTagName XMLAttributes
2225 ;
2226
2227 XMLExpression
2228 : BRACE LexPushRegExp Expression LexPop "}"
2229 ;
2230
2231 XMLTagName
2232 : XMLExpression
2233 | XMLName
2234 ;
2235
2236 XMLAttributes_
2237 : XMLAttributes_ XMLAttribute
2238 |
2239 ;
2240
2241 XMLAttributes
2242 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2243 | XMLAttributes_ XMLWhitespaceOpt
2244 ;
2245
2246 XMLAttributeValue_
2247 : XMLExpression
2248 | XMLAttributeValue
2249 ;
2250
2251 XMLAttribute
2252 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2253 ;
2254
2255 XMLElementContent
2256 : XMLExpression XMLElementContentOpt
2257 | XMLMarkup XMLElementContentOpt
2258 | XMLText XMLElementContentOpt
2259 | XMLElement XMLElementContentOpt
2260 ;
2261
2262 XMLElementContentOpt
2263 : XMLElementContent
2264 |
2265 ;
2266 /* }}} */
2267 /* 11.1.5 XMLList Initializer {{{ */
2268 XMLListInitialiser
2269 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2270 ;
2271 /* }}} */
2272
2273 /* 11.2 Left-Hand-Side Expressions {{{ */
2274 PropertyIdentifier_
2275 : Identifier { $$ = $1; }
2276 | PropertyIdentifier { $$ = $1; }
2277 ;
2278
2279 MemberAccess
2280 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2281 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2282 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2283 ;
2284 /* }}} */
2285 /* 12.1 The default xml namespace Statement {{{ */
2286 /* XXX: DefaultXMLNamespaceStatement
2287 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2288 ;
2289
2290 Statement__
2291 : DefaultXMLNamespaceStatement { $$ = $1; }
2292 ; */
2293 /* }}} */
2294 @end
2295
2296 /* JavaScript FTL: Array Comprehensions {{{ */
2297 Comprehension
2298 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
2299 ;
2300
2301 ComprehensionFor
2302 : "for" "each" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); }
2303 ;
2304 /* }}} */
2305 /* JavaScript FTL: for each {{{ */
2306 IterationStatement
2307 : "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
2308 ;
2309 /* }}} */
2310
2311 /* JavaScript FTW: Array Comprehensions {{{ */
2312 PrimaryExpression
2313 : ArrayComprehension
2314 ;
2315
2316 ArrayComprehension
2317 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
2318 ;
2319
2320 Comprehension
2321 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
2322 ;
2323
2324 ComprehensionTail
2325 : { $$ = NULL; }
2326 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
2327 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
2328 ;
2329
2330 ComprehensionFor
2331 : "for" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
2332 | "for" "(" LexPushInOn LexicalBinding "of" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($4, $7); }
2333 ;
2334
2335 ComprehensionIf
2336 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
2337 ;
2338 /* }}} */
2339 /* JavaScript FTW: Coalesce Operator {{{ */
2340 ConditionalExpression
2341 : LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
2342 ;
2343 /* }}} */
2344 /* JavaScript FTW: Named Arguments {{{ */
2345 ArgumentList
2346 : LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
2347 ;
2348 /* }}} */
2349 /* JavaScript FTW: Ruby Blocks {{{ */
2350 RubyProcParameterList_
2351 : "," RubyProcParameterList { $$ = $2; }
2352 | { $$ = NULL; }
2353 ;
2354
2355 RubyProcParameterList
2356 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
2357 | { $$ = NULL; }
2358 ;
2359
2360 RubyProcParameters
2361 : LexSetRegExp "|" RubyProcParameterList "|" { $$ = $3; }
2362 | LexSetRegExp "||" { $$ = NULL; }
2363 ;
2364
2365 RubyProcParametersOpt
2366 : RubyProcParameters { $$ = $1; }
2367 | { $$ = NULL; }
2368 ;
2369
2370 RubyProcExpression
2371 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
2372 ;
2373
2374 PrimaryExpression
2375 : BRACE LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
2376 ;
2377
2378 PostfixExpression
2379 : PostfixExpression RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
2380 ;
2381 /* }}} */
2382
2383 %%
2384
2385 bool CYDriver::Parse(CYMark mark) {
2386 mark_ = mark;
2387 CYLocal<CYPool> local(&pool_);
2388 cy::parser parser(*this);
2389 #ifdef YYDEBUG
2390 parser.set_debug_level(debug_);
2391 #endif
2392 return parser.parse() != 0;
2393 }
2394
2395 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2396 if (!strict_)
2397 return;
2398
2399 CYDriver::Error error;
2400 error.warning_ = true;
2401 error.location_ = location;
2402 error.message_ = message;
2403 errors_.push_back(error);
2404 }
2405
2406 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2407 CYDriver::Error error;
2408 error.warning_ = false;
2409 error.location_ = location;
2410 error.message_ = message;
2411 driver.errors_.push_back(error);
2412 }