1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
5 /* GNU Affero General Public License, Version 3 {{{ */
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.
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.
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/>.
23 #define YYSTACKEXPANDABLE 1
30 #define CYNew new(driver.pool_)
33 #include "ObjectiveC/Syntax.hpp"
37 #include "E4X/Syntax.hpp"
40 #include "Highlight.hpp"
43 %union { bool bool_; }
45 %union { CYMember *access_; }
46 %union { CYArgument *argument_; }
47 %union { CYAssignment *assignment_; }
48 %union { CYBinding *binding_; }
49 %union { CYBindings *bindings_; }
50 %union { CYBoolean *boolean_; }
51 %union { CYClause *clause_; }
52 %union { cy::Syntax::Catch *catch_; }
53 %union { CYClassTail *classTail_; }
54 %union { CYComprehension *comprehension_; }
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 { CYImportSpecifier *import_; }
65 %union { CYInfix *infix_; }
66 %union { CYLiteral *literal_; }
67 %union { CYMethod *method_; }
68 %union { CYModule *module_; }
69 %union { CYNull *null_; }
70 %union { CYNumber *number_; }
71 %union { CYParenthetical *parenthetical_; }
72 %union { CYProperty *property_; }
73 %union { CYPropertyName *propertyName_; }
74 %union { CYRubyProc *rubyProc_; }
75 %union { CYSpan *span_; }
76 %union { CYStatement *statement_; }
77 %union { CYString *string_; }
78 %union { CYTarget *target_; }
79 %union { CYThis *this_; }
80 %union { CYTrue *true_; }
81 %union { CYWord *word_; }
84 %union { CYTypeStructField *structField_; }
85 %union { CYTypeModifier *modifier_; }
86 %union { CYTypeSpecifier *specifier_; }
87 %union { CYTypedIdentifier *typedIdentifier_; }
88 %union { CYTypedParameter *typedParameter_; }
92 %union { CYImplementationField *implementationField_; }
93 %union { CYMessage *message_; }
94 %union { CYMessageParameter *messageParameter_; }
95 %union { CYProtocol *protocol_; }
96 %union { CYSelectorPart *selector_; }
100 %union { CYAttribute *attribute_; }
101 %union { CYPropertyIdentifier *propertyIdentifier_; }
102 %union { CYSelector *selector_; }
108 cy::parser::semantic_type semantic_;
109 hi::Value highlight_;
112 int cylex(YYSTYPE *, CYLocation *, void *);
120 typedef cy::parser::token tk;
122 _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
123 driver.newline_ = false;
126 int token(cylex(&data, location, driver.scanner_));
127 *semantic = data.semantic_;
131 case tk::OpenBracket:
133 driver.in_.push(false);
137 if (driver.in_.top())
142 case tk::CloseBracket:
149 if (driver.yield_.top())
150 token = tk::_yield__;
154 driver.newline_ = true;
162 #define yylex_(semantic, location, driver) ({ \
164 if (driver.hold_ == cy::parser::empty_symbol) \
165 type = yytranslate_(cylex_(semantic, location, driver)); \
167 type = driver.hold_; \
168 driver.hold_ = cy::parser::empty_symbol; \
172 #define CYLEX() do if (yyla.empty()) { \
173 YYCDEBUG << "Mapping a token: "; \
174 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
175 YY_SYMBOL_PRINT("Next token is", yyla); \
178 #define CYMAP(to, from) do { \
180 if (yyla.type == yytranslate_(token::from)) \
181 yyla.type = yytranslate_(token::to); \
184 #define CYERR(location, message) do { \
185 error(location, message); \
189 #define CYEOK() do { \
191 driver.errors_.pop_back(); \
194 #define CYNOT(location) \
195 CYERR(location, "unimplemented feature")
197 #define CYMPT(location) do { \
198 if (!yyla.empty() && yyla.type_get() != yyeof_) \
199 CYERR(location, "unexpected lookahead"); \
209 @$.begin.filename = @$.end.filename = &driver.filename_;
211 switch (driver.mark_) {
213 driver.hold_ = yytranslate_(token::MarkScript);
216 driver.hold_ = yytranslate_(token::MarkModule);
224 %define api.location.type { CYLocation }
231 %param { CYDriver &driver }
233 /* Token Declarations {{{ */
239 %token XMLAttributeValue
241 %token XMLTagCharacters
247 %token LeftRight "<>"
248 %token LeftSlashRight "</>"
250 %token SlashRight "/>"
251 %token LeftSlash "</"
253 %token ColonColon "::"
254 %token PeriodPeriod ".."
257 @begin E4X ObjectiveC
263 %token AmpersandAmpersand "&&"
264 %token AmpersandEqual "&="
266 %token CarrotEqual "^="
268 %token EqualEqual "=="
269 %token EqualEqualEqual "==="
270 %token EqualRight "=>"
271 %token Exclamation "!"
272 %token ExclamationEqual "!="
273 %token ExclamationEqualEqual "!=="
275 %token HyphenEqual "-="
276 %token HyphenHyphen "--"
277 %token HyphenRight "->"
279 %token LeftEqual "<="
281 %token LeftLeftEqual "<<="
283 %token PercentEqual "%="
285 %token PeriodPeriodPeriod "..."
287 %token PipeEqual "|="
290 %token PlusEqual "+="
293 %token RightEqual ">="
294 %token RightRight ">>"
295 %token RightRightEqual ">>="
296 %token RightRightRight ">>>"
297 %token RightRightRightEqual ">>>="
299 %token SlashEqual "/="
301 %token StarEqual "*="
314 %token CloseParen ")"
317 %token OpenBrace_ ";{"
318 %token OpenBrace_let "let {"
319 %token CloseBrace "}"
321 %token OpenBracket "["
322 %token OpenBracket_let "let ["
323 %token CloseBracket "]"
325 %token At_error_ "@error"
328 %token At_class_ "@class"
332 %token _typedef_ "typedef"
333 %token _unsigned_ "unsigned"
334 %token _signed_ "signed"
335 %token _struct_ "struct"
336 %token _extern_ "extern"
340 %token At_encode_ "@encode"
344 %token At_implementation_ "@implementation"
345 %token At_import_ "@import"
346 %token At_end_ "@end"
347 %token At_selector_ "@selector"
348 %token At_null_ "@null"
349 %token At_YES_ "@YES"
351 %token At_true_ "@true"
352 %token At_false_ "@false"
357 %token _false_ "false"
362 %token _break_ "break"
364 %token _catch_ "catch"
365 %token _class_ "class"
366 %token _class__ ";class"
367 %token _const_ "const"
368 %token _continue_ "continue"
369 %token _debugger_ "debugger"
370 %token _default_ "default"
371 %token _delete_ "delete"
375 %token _export_ "export"
376 %token _extends_ "extends"
377 %token _finally_ "finally"
379 %token _function_ "function"
380 %token _function__ ";function"
382 %token _import_ "import"
385 %token _Infinity_ "Infinity"
386 %token _instanceof_ "instanceof"
388 %token _return_ "return"
389 %token _super_ "super"
390 %token _switch_ "switch"
391 %token _target_ "target"
393 %token _throw_ "throw"
395 %token _typeof_ "typeof"
398 %token _while_ "while"
401 %token _abstract_ "abstract"
402 %token _await_ "await"
403 %token _boolean_ "boolean"
406 %token _constructor_ "constructor"
407 %token _double_ "double"
409 %token _final_ "final"
410 %token _float_ "float"
414 %token _implements_ "implements"
416 %token _interface_ "interface"
420 %token _native_ "native"
421 %token _package_ "package"
422 %token _private_ "private"
423 %token _protected_ "protected"
424 %token ___proto___ "__proto__"
425 %token _prototype_ "prototype"
426 %token _public_ "public"
428 %token _short_ "short"
429 %token _static_ "static"
430 %token _synchronized_ "synchronized"
431 %token _throws_ "throws"
432 %token _transient_ "transient"
433 %token _volatile_ "volatile"
434 %token _yield_ "yield"
435 %token _yield__ "!yield"
437 %token _undefined_ "undefined"
453 %token _namespace_ "namespace"
458 %token YieldStar "yield *"
460 %token <identifier_> Identifier_
461 %token <number_> NumericLiteral
462 %token <string_> StringLiteral
463 %token <literal_> RegularExpressionLiteral_
465 %token <string_> NoSubstitutionTemplate
466 %token <string_> TemplateHead
467 %token <string_> TemplateMiddle
468 %token <string_> TemplateTail
470 %type <target_> AccessExpression
471 %type <expression_> AdditiveExpression
472 %type <argument_> ArgumentList_
473 %type <argument_> ArgumentList
474 %type <argument_> ArgumentListOpt
475 %type <argument_> Arguments
476 %type <target_> ArrayComprehension
477 %type <literal_> ArrayLiteral
478 %type <expression_> ArrowFunction
479 %type <functionParameter_> ArrowParameters
480 %type <expression_> AssignmentExpression
481 %type <expression_> AssignmentExpressionOpt
482 %type <identifier_> BindingIdentifier
483 %type <identifier_> BindingIdentifierOpt
484 %type <bindings_> BindingList_
485 %type <bindings_> BindingList
486 %type <expression_> BitwiseANDExpression
487 %type <statement_> Block
488 %type <statement_> BlockStatement
489 %type <boolean_> BooleanLiteral
490 %type <binding_> BindingElement
491 %type <expression_> BitwiseORExpression
492 %type <expression_> BitwiseXORExpression
493 %type <statement_> BreakStatement
494 %type <statement_> BreakableStatement
495 %type <expression_> CallExpression_
496 %type <target_> CallExpression
497 %type <clause_> CaseBlock
498 %type <clause_> CaseClause
499 %type <clause_> CaseClausesOpt
501 %type <identifier_> CatchParameter
502 %type <statement_> ClassDeclaration
503 %type <target_> ClassExpression
504 %type <classTail_> ClassHeritage
505 %type <classTail_> ClassHeritageOpt
506 %type <classTail_> ClassTail
507 %type <target_> Comprehension
508 %type <comprehension_> ComprehensionFor
509 %type <comprehension_> ComprehensionIf
510 %type <comprehension_> ComprehensionTail
511 %type <propertyName_> ComputedPropertyName
512 %type <expression_> ConditionalExpression
513 %type <statement_> ContinueStatement
514 %type <statement_> ConciseBody
515 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
516 %type <statement_> DebuggerStatement
517 %type <statement_> Declaration_
518 %type <statement_> Declaration
519 %type <clause_> DefaultClause
520 %type <element_> ElementList
521 %type <element_> ElementListOpt
522 %type <statement_> ElseStatementOpt
523 %type <for_> EmptyStatement
524 %type <expression_> EqualityExpression
525 %type <expression_> Expression
526 %type <expression_> ExpressionOpt
527 %type <for_> ExpressionStatement_
528 %type <statement_> ExpressionStatement
529 %type <statement_> ExternC
530 %type <statement_> ExternCStatement
531 %type <statement_> ExternCStatementListOpt
532 %type <finally_> Finally
533 %type <binding_> ForBinding
534 %type <forin_> ForDeclaration
535 %type <forin_> ForInStatementInitializer
536 %type <for_> ForStatementInitializer
537 %type <binding_> FormalParameter
538 %type <functionParameter_> FormalParameterList_
539 %type <functionParameter_> FormalParameterList
540 %type <functionParameter_> FormalParameters
541 %type <string_> FromClause
542 %type <statement_> FunctionBody
543 %type <statement_> FunctionDeclaration
544 %type <target_> FunctionExpression
545 %type <statement_> FunctionStatementList
546 %type <statement_> GeneratorBody
547 %type <statement_> GeneratorDeclaration
548 %type <target_> GeneratorExpression
549 %type <method_> GeneratorMethod
550 %type <statement_> HoistableDeclaration
551 %type <identifier_> Identifier
552 %type <identifier_> IdentifierNoOf
553 %type <identifier_> IdentifierType
554 %type <identifier_> IdentifierTypeNoOf
555 %type <identifier_> IdentifierTypeOpt
556 %type <word_> IdentifierName
557 %type <variable_> IdentifierReference
558 %type <statement_> IfStatement
559 %type <import_> ImportClause
560 %type <statement_> ImportDeclaration
561 %type <import_> ImportSpecifier
562 %type <identifier_> ImportedBinding
563 %type <import_> ImportedDefaultBinding
564 %type <import_> ImportsList_
565 %type <import_> ImportsList
566 %type <import_> ImportsListOpt
567 %type <target_> IndirectExpression
568 %type <expression_> Initializer
569 %type <expression_> InitializerOpt
570 %type <statement_> IterationStatement
571 %type <identifier_> LabelIdentifier
572 %type <statement_> LabelledItem
573 %type <statement_> LabelledStatement
574 %type <assignment_> LeftHandSideAssignment
575 %type <target_> LeftHandSideExpression
576 %type <bool_> LetOrConst
577 %type <binding_> LexicalBinding
578 %type <for_> LexicalDeclaration_
579 %type <statement_> LexicalDeclaration
580 %type <literal_> Literal
581 %type <propertyName_> LiteralPropertyName
582 %type <expression_> LogicalANDExpression
583 %type <expression_> LogicalORExpression
584 %type <access_> MemberAccess
585 %type <target_> MemberExpression
586 %type <method_> MethodDefinition
587 %type <statement_> ModuleBody
588 %type <statement_> ModuleBodyOpt
589 %type <statement_> ModuleItem
590 %type <statement_> ModuleItemList
591 %type <statement_> ModuleItemListOpt
592 %type <module_> ModulePath
593 %type <string_> ModuleSpecifier
594 %type <expression_> MultiplicativeExpression
595 %type <import_> NameSpaceImport
596 %type <import_> NamedImports
597 %type <target_> NewExpression
598 %type <null_> NullLiteral
599 %type <literal_> ObjectLiteral
600 %type <expression_> PostfixExpression
601 %type <target_> PrimaryExpression
602 %type <propertyName_> PropertyName
603 %type <property_> PropertyDefinition
604 %type <property_> PropertyDefinitionList_
605 %type <property_> PropertyDefinitionList
606 %type <property_> PropertyDefinitionListOpt
607 %type <functionParameter_> PropertySetParameterList
608 %type <literal_> RegularExpressionLiteral
609 %type <bool_> RegularExpressionSlash
610 %type <expression_> RelationalExpression
611 %type <statement_> ReturnStatement
612 %type <target_> RubyBlockExpression_
613 %type <target_> RubyBlockExpression
614 %type <rubyProc_> RubyProcExpression
615 %type <functionParameter_> RubyProcParameterList_
616 %type <functionParameter_> RubyProcParameterList
617 %type <functionParameter_> RubyProcParameters
618 %type <functionParameter_> RubyProcParametersOpt
619 %type <statement_> Script
620 %type <statement_> ScriptBody
621 %type <statement_> ScriptBodyOpt
622 %type <expression_> ShiftExpression
623 %type <binding_> SingleNameBinding
624 %type <statement_> Statement__
625 %type <statement_> Statement_
626 %type <statement_> Statement
627 %type <statement_> StatementList
628 %type <statement_> StatementListOpt
629 %type <statement_> StatementListItem
630 %type <functionParameter_> StrictFormalParameters
631 %type <target_> SuperCall
632 %type <target_> SuperProperty
633 %type <statement_> SwitchStatement
634 %type <target_> TemplateLiteral
635 %type <span_> TemplateSpans
636 %type <statement_> ThrowStatement
637 %type <statement_> TryStatement
638 %type <statement_> TypeDefinition
639 %type <expression_> UnaryExpression_
640 %type <expression_> UnaryExpression
641 %type <binding_> VariableDeclaration
642 %type <bindings_> VariableDeclarationList_
643 %type <bindings_> VariableDeclarationList
644 %type <for_> VariableStatement_
645 %type <statement_> VariableStatement
646 %type <statement_> WithStatement
649 %type <word_> WordOpt
651 %type <expression_> YieldExpression
654 %type <specifier_> IntegerType
655 %type <specifier_> IntegerTypeOpt
656 %type <typedIdentifier_> PrefixedType
657 %type <specifier_> PrimitiveType
658 %type <structField_> StructFieldListOpt
659 %type <typedIdentifier_> SuffixedType
660 %type <typedIdentifier_> SuffixedTypeOpt
661 %type <typedIdentifier_> TypeSignifier
662 %type <typedIdentifier_> TypeSignifierOpt
663 %type <modifier_> TypeQualifierLeft
664 %type <modifier_> TypeQualifierLeftOpt
665 %type <typedIdentifier_> TypeQualifierRight
666 %type <typedIdentifier_> TypeQualifierRightOpt
667 %type <typedIdentifier_> TypedIdentifierMaybe
668 %type <typedIdentifier_> TypedIdentifierNo
669 %type <typedIdentifier_> TypedIdentifierYes
670 %type <typedParameter_> TypedParameterList_
671 %type <typedParameter_> TypedParameterList
672 %type <typedParameter_> TypedParameterListOpt
676 %type <expression_> AssignmentExpressionClassic
677 %type <expression_> BoxableExpression
678 %type <statement_> CategoryStatement
679 %type <expression_> ClassSuperOpt
680 %type <expression_> ConditionalExpressionClassic
681 %type <message_> ClassMessageDeclaration
682 %type <message_> ClassMessageDeclarationListOpt
683 %type <protocol_> ClassProtocolListOpt
684 %type <protocol_> ClassProtocols
685 %type <protocol_> ClassProtocolsOpt
686 %type <implementationField_> ImplementationFieldListOpt
687 %type <statement_> ImplementationStatement
688 %type <target_> MessageExpression
689 %type <messageParameter_> MessageParameter
690 %type <messageParameter_> MessageParameters
691 %type <messageParameter_> MessageParameterList
692 %type <messageParameter_> MessageParameterListOpt
693 %type <bool_> MessageScope
694 %type <argument_> SelectorCall_
695 %type <argument_> SelectorCall
696 %type <selector_> SelectorExpression_
697 %type <selector_> SelectorExpression
698 %type <selector_> SelectorExpressionOpt
699 %type <argument_> SelectorList
700 %type <word_> SelectorWordOpt
701 %type <typedIdentifier_> TypeOpt
702 %type <argument_> VariadicCall
706 %type <propertyIdentifier_> PropertyIdentifier_
707 %type <selector_> PropertySelector_
708 %type <selector_> PropertySelector
709 %type <identifier_> QualifiedIdentifier_
710 %type <identifier_> QualifiedIdentifier
711 %type <identifier_> WildcardIdentifier
712 %type <identifier_> XMLComment
713 %type <identifier_> XMLCDATA
714 %type <identifier_> XMLElement
715 %type <identifier_> XMLElementContent
716 %type <identifier_> XMLMarkup
717 %type <identifier_> XMLPI
719 %type <attribute_> AttributeIdentifier
720 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
721 %type <expression_> PropertyIdentifier
722 %type <expression_> XMLListInitilizer
723 %type <expression_> XMLInitilizer
726 /* Token Priorities {{{ */
742 /* Lexer State {{{ */
743 LexPushInOn: { driver.in_.push(true); };
744 LexPushInOff: { driver.in_.push(false); };
745 LexPopIn: { driver.in_.pop(); };
747 LexPushReturnOn: { driver.return_.push(true); };
748 LexPopReturn: { driver.return_.pop(); };
749 Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
751 LexPushSuperOn: { driver.super_.push(true); };
752 LexPushSuperOff: { driver.super_.push(false); };
753 LexPopSuper: { driver.super_.pop(); };
754 Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
756 LexPushYieldOn: { driver.yield_.push(true); };
757 LexPushYieldOff: { driver.yield_.push(false); };
758 LexPopYield: { driver.yield_.pop(); };
761 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); if (driver.newline_) { driver.hold_ = yyla.type; yyla.type = yytranslate_(cy::parser::token::NewLine); } }
765 : { CYLEX(); if (driver.hold_ != empty_symbol) CYERR(@$, "unexpected hold"); driver.hold_ = yyla.type; yyla.type = yytranslate_(driver.newline_ ? cy::parser::token::NewLine : cy::parser::token::__); }
769 : { CYMAP(YieldStar, Star); }
773 : { CYMAP(OpenBrace_, OpenBrace); }
777 : { CYMAP(_class__, _class_); }
781 : { CYMAP(_function__, _function_); }
785 : LexNoBrace LexNoClass LexNoFunction
788 /* Virtual Tokens {{{ */
794 /* 11.6 Names and Keywords {{{ */
796 : Word[pass] { $$ = $pass; }
797 | "for" { $$ = CYNew CYWord("for"); }
798 | "in" { $$ = CYNew CYWord("in"); }
799 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
803 : IdentifierNoOf[pass] { $$ = $pass; }
804 | "break" { $$ = CYNew CYWord("break"); }
805 | "case" { $$ = CYNew CYWord("case"); }
806 | "catch" { $$ = CYNew CYWord("catch"); }
807 | "class" LexOf { $$ = CYNew CYWord("class"); }
808 | ";class" { $$ = CYNew CYWord("class"); }
809 | "const" { $$ = CYNew CYWord("const"); }
810 | "continue" { $$ = CYNew CYWord("continue"); }
811 | "debugger" { $$ = CYNew CYWord("debugger"); }
812 | "default" { $$ = CYNew CYWord("default"); }
813 | "delete" { $$ = CYNew CYWord("delete"); }
814 | "do" { $$ = CYNew CYWord("do"); }
815 | "else" { $$ = CYNew CYWord("else"); }
816 | "enum" { $$ = CYNew CYWord("enum"); }
817 | "export" { $$ = CYNew CYWord("export"); }
818 | "extends" { $$ = CYNew CYWord("extends"); }
819 | "false" { $$ = CYNew CYWord("false"); }
820 | "finally" { $$ = CYNew CYWord("finally"); }
821 | "function" LexOf { $$ = CYNew CYWord("function"); }
822 | "if" { $$ = CYNew CYWord("if"); }
823 | "import" { $$ = CYNew CYWord("import"); }
824 | "!in" { $$ = CYNew CYWord("in"); }
825 | "!of" { $$ = CYNew CYWord("of"); }
826 | "new" { $$ = CYNew CYWord("new"); }
827 | "null" { $$ = CYNew CYWord("null"); }
828 | "return" { $$ = CYNew CYWord("return"); }
829 | "super" { $$ = CYNew CYWord("super"); }
830 | "switch" { $$ = CYNew CYWord("switch"); }
831 | "this" { $$ = CYNew CYWord("this"); }
832 | "throw" { $$ = CYNew CYWord("throw"); }
833 | "true" { $$ = CYNew CYWord("true"); }
834 | "try" { $$ = CYNew CYWord("try"); }
835 | "typeof" { $$ = CYNew CYWord("typeof"); }
836 | "var" { $$ = CYNew CYWord("var"); }
837 | "void" { $$ = CYNew CYWord("void"); }
838 | "while" { $$ = CYNew CYWord("while"); }
839 | "with" { $$ = CYNew CYWord("with"); }
840 | "yield" { $$ = CYNew CYIdentifier("yield"); }
845 : Word[pass] { $$ = $pass; }
850 /* 11.8.1 Null Literals {{{ */
852 : "null" { $$ = CYNew CYNull(); }
855 /* 11.8.2 Boolean Literals {{{ */
857 : "true" { $$ = CYNew CYTrue(); }
858 | "false" { $$ = CYNew CYFalse(); }
861 /* 11.8.5 Regular Expression Literals {{{ */
862 RegularExpressionSlash
863 : "/" { $$ = false; }
864 | "/=" { $$ = true; }
867 RegularExpressionLiteral
868 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
872 /* 11.9 Automatic Semicolon Insertion {{{ */
874 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
882 : LexNewLineOrNot "\n"
887 : LexNewLineOrNot "\n" StrictSemi
888 | NewLineNot LexOf Terminator
893 | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
898 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
903 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
907 /* 12.1 Identifiers {{{ */
909 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
910 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
914 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
915 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
916 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
920 : BindingIdentifier[pass] { $$ = $pass; }
921 | LexOf { $$ = NULL; }
925 : Identifier[pass] { $$ = $pass; }
926 | "yield" { $$ = CYNew CYIdentifier("yield"); }
930 : Identifier_[pass] { $$ = $pass; }
931 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
932 | "as" { $$ = CYNew CYIdentifier("as"); }
933 | "await" { $$ = CYNew CYIdentifier("await"); }
934 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
935 | "byte" { $$ = CYNew CYIdentifier("byte"); }
936 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
937 | "double" { $$ = CYNew CYIdentifier("double"); }
938 | "each" { $$ = CYNew CYIdentifier("each"); }
939 | "eval" { $$ = CYNew CYIdentifier("eval"); }
940 | "final" { $$ = CYNew CYIdentifier("final"); }
941 | "float" { $$ = CYNew CYIdentifier("float"); }
942 | "from" { $$ = CYNew CYIdentifier("from"); }
943 | "get" { $$ = CYNew CYIdentifier("get"); }
944 | "goto" { $$ = CYNew CYIdentifier("goto"); }
945 | "implements" { $$ = CYNew CYIdentifier("implements"); }
946 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
947 | "interface" { $$ = CYNew CYIdentifier("interface"); }
948 | "let" { $$ = CYNew CYIdentifier("let"); }
949 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
950 | "native" { $$ = CYNew CYIdentifier("native"); }
951 | "package" { $$ = CYNew CYIdentifier("package"); }
952 | "private" { $$ = CYNew CYIdentifier("private"); }
953 | "protected" { $$ = CYNew CYIdentifier("protected"); }
954 | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
955 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
956 | "public" { $$ = CYNew CYIdentifier("public"); }
957 | "set" { $$ = CYNew CYIdentifier("set"); }
958 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
959 | "target" { $$ = CYNew CYIdentifier("target"); }
960 | "throws" { $$ = CYNew CYIdentifier("throws"); }
961 | "transient" { $$ = CYNew CYIdentifier("transient"); }
962 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
964 | "bool" { $$ = CYNew CYIdentifier("bool"); }
965 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
966 | "id" { $$ = CYNew CYIdentifier("id"); }
967 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
972 : IdentifierTypeNoOf[pass] { $$ = $pass; }
973 | "of" { $$ = CYNew CYIdentifier("of"); }
977 : IdentifierType[pass] { $$ = $pass; }
983 | "char" { $$ = CYNew CYIdentifier("char"); }
984 | "int" { $$ = CYNew CYIdentifier("int"); }
985 | "long" { $$ = CYNew CYIdentifier("long"); }
986 | "short" { $$ = CYNew CYIdentifier("short"); }
987 | "static" { $$ = CYNew CYIdentifier("static"); }
988 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
990 | "signed" { $$ = CYNew CYIdentifier("signed"); }
991 | "struct" { $$ = CYNew CYIdentifier("struct"); }
992 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
995 | "nil" { $$ = CYNew CYIdentifier("nil"); }
996 | "NO" { $$ = CYNew CYIdentifier("NO"); }
997 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
998 | "YES" { $$ = CYNew CYIdentifier("YES"); }
1003 : IdentifierNoOf[pass] { $$ = $pass; }
1004 | "of" { $$ = CYNew CYIdentifier("of"); }
1005 | "!of" { $$ = CYNew CYIdentifier("of"); }
1008 /* 12.2 Primary Expression {{{ */
1010 : "this" { $$ = CYNew CYThis(); }
1011 | IdentifierReference[pass] { $$ = $pass; }
1012 | Literal[pass] { $$ = $pass; }
1013 | ArrayLiteral[pass] { $$ = $pass; }
1014 | ObjectLiteral[pass] { $$ = $pass; }
1015 | FunctionExpression[pass] { $$ = $pass; }
1016 | ClassExpression[pass] { $$ = $pass; }
1017 | GeneratorExpression[pass] { $$ = $pass; }
1018 | RegularExpressionLiteral[pass] { $$ = $pass; }
1019 | TemplateLiteral[pass] { $$ = $pass; }
1020 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
1021 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1024 CoverParenthesizedExpressionAndArrowParameterList
1025 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
1026 | "(" LexOf ")" { $$ = NULL; }
1027 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1028 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1031 /* 12.2.4 Literals {{{ */
1033 : NullLiteral[pass] { $$ = $pass; }
1034 | BooleanLiteral[pass] { $$ = $pass; }
1035 | NumericLiteral[pass] { $$ = $pass; }
1036 | StringLiteral[pass] { $$ = $pass; }
1039 /* 12.2.5 Array Initializer {{{ */
1041 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1045 : AssignmentExpressionOpt[value] "," ElementListOpt[next] { $$ = CYNew CYElementValue($value, $next); }
1046 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1047 | AssignmentExpression[value] { $$ = CYNew CYElementValue($value, NULL); }
1051 : ElementList[pass] { $$ = $pass; }
1052 | LexOf { $$ = NULL; }
1055 /* 12.2.6 Object Initializer {{{ */
1057 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1060 PropertyDefinitionList_
1061 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1065 PropertyDefinitionList
1066 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1069 PropertyDefinitionListOpt
1070 : PropertyDefinitionList[properties] { $$ = $properties; }
1075 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1076 | CoverInitializedName[name] { CYNOT(@$); }
1077 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1078 | MethodDefinition[pass] { $$ = $pass; }
1082 : LiteralPropertyName[pass] { $$ = $pass; }
1083 | ComputedPropertyName[pass] { $$ = $pass; }
1087 : IdentifierName[pass] { $$ = $pass; }
1088 | StringLiteral[pass] { $$ = $pass; }
1089 | NumericLiteral[pass] { $$ = $pass; }
1092 ComputedPropertyName
1093 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1096 CoverInitializedName
1097 : IdentifierReference Initializer
1101 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1105 : Initializer[pass] { $$ = $pass; }
1109 /* 12.2.9 Template Literals {{{ */
1111 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1112 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1116 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1117 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1121 /* 12.3 Left-Hand-Side Expressions {{{ */
1123 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1124 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1125 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1126 | TemplateLiteral { CYNOT(@$); }
1130 : PrimaryExpression[pass] { $$ = $pass; }
1131 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1132 | SuperProperty[pass] { $$ = $pass; }
1133 | MetaProperty { CYNOT(@$); }
1134 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1138 : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1139 | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1147 : "new" "." "target"
1151 : MemberExpression[pass] { $$ = $pass; }
1152 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1156 : MemberExpression[pass] { $$ = $pass; }
1157 | CallExpression[pass] { $$ = $pass; }
1161 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1162 | SuperCall[pass] { $$ = $pass; }
1163 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1167 : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1171 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1175 : "," ArgumentList[arguments] { $$ = $arguments; }
1180 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1181 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1185 : ArgumentList[pass] { $$ = $pass; }
1186 | LexOf { $$ = NULL; }
1190 : NewExpression[pass] { $$ = $pass; }
1191 | CallExpression[pass] { $$ = $pass; }
1194 LeftHandSideExpression
1195 : RubyBlockExpression[pass] { $$ = $pass; }
1196 | IndirectExpression[pass] { $$ = $pass; }
1199 /* 12.4 Postfix Expressions {{{ */
1201 : RubyBlockExpression[pass] { $$ = $pass; }
1202 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1203 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1206 /* 12.5 Unary Operators {{{ */
1208 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1209 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1210 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1211 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1212 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1213 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1214 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1215 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1216 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1220 : PostfixExpression[expression] { $$ = $expression; }
1221 | UnaryExpression_[pass] { $$ = $pass; }
1224 /* 12.6 Multiplicative Operators {{{ */
1225 MultiplicativeExpression
1226 : UnaryExpression[pass] { $$ = $pass; }
1227 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1228 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1229 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1232 /* 12.7 Additive Operators {{{ */
1234 : MultiplicativeExpression[pass] { $$ = $pass; }
1235 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1236 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1239 /* 12.8 Bitwise Shift Operators {{{ */
1241 : AdditiveExpression[pass] { $$ = $pass; }
1242 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1243 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1244 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1247 /* 12.9 Relational Operators {{{ */
1248 RelationalExpression
1249 : ShiftExpression[pass] { $$ = $pass; }
1250 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1251 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1252 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1253 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1254 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1255 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1258 /* 12.10 Equality Operators {{{ */
1260 : RelationalExpression[pass] { $$ = $pass; }
1261 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1262 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1263 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1264 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1267 /* 12.11 Binary Bitwise Operators {{{ */
1268 BitwiseANDExpression
1269 : EqualityExpression[pass] { $$ = $pass; }
1270 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1273 BitwiseXORExpression
1274 : BitwiseANDExpression[pass] { $$ = $pass; }
1275 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1279 : BitwiseXORExpression[pass] { $$ = $pass; }
1280 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1283 /* 12.12 Binary Logical Operators {{{ */
1284 LogicalANDExpression
1285 : BitwiseORExpression[pass] { $$ = $pass; }
1286 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1290 : LogicalANDExpression[pass] { $$ = $pass; }
1291 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1294 /* 12.13 Conditional Operator ( ? : ) {{{ */
1296 ConditionalExpressionClassic
1297 : LogicalORExpression[pass] { $$ = $pass; }
1298 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1302 ConditionalExpression
1303 : LogicalORExpression[pass] { $$ = $pass; }
1304 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1307 /* 12.14 Assignment Operators {{{ */
1308 LeftHandSideAssignment
1309 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1310 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1311 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1312 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1313 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1314 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1315 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1316 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1317 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1318 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1319 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1320 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1324 AssignmentExpressionClassic
1325 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1326 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1330 AssignmentExpression
1331 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1332 | LexOf YieldExpression[pass] { $$ = $pass; }
1333 | ArrowFunction[pass] { $$ = $pass; }
1334 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1337 AssignmentExpressionOpt
1338 : AssignmentExpression[pass] { $$ = $pass; }
1339 | LexOf { $$ = NULL; }
1342 /* 12.15 Comma Operator ( , ) {{{ */
1344 : AssignmentExpression[pass] { $$ = $pass; }
1345 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1349 : Expression[pass] { $$ = $pass; }
1350 | LexOf { $$ = NULL; }
1354 /* 13 Statements and Declarations {{{ */
1356 : BlockStatement[pass] { $$ = $pass; }
1357 | VariableStatement[pass] { $$ = $pass; }
1358 | EmptyStatement[pass] { $$ = $pass; }
1359 | IfStatement[pass] { $$ = $pass; }
1360 | BreakableStatement[pass] { $$ = $pass; }
1361 | ContinueStatement[pass] { $$ = $pass; }
1362 | BreakStatement[pass] { $$ = $pass; }
1363 | ReturnStatement[pass] { $$ = $pass; }
1364 | WithStatement[pass] { $$ = $pass; }
1365 | LabelledStatement[pass] { $$ = $pass; }
1366 | ThrowStatement[pass] { $$ = $pass; }
1367 | TryStatement[pass] { $$ = $pass; }
1368 | DebuggerStatement[pass] { $$ = $pass; }
1372 : LexOf Statement__[pass] { $$ = $pass; }
1373 | ExpressionStatement[pass] { $$ = $pass; }
1377 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1381 : HoistableDeclaration[pass] { $$ = $pass; }
1382 | ClassDeclaration[pass] { $$ = $pass; }
1386 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1387 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1390 HoistableDeclaration
1391 : FunctionDeclaration[pass] { $$ = $pass; }
1392 | GeneratorDeclaration[pass] { $$ = $pass; }
1396 : IterationStatement[pass] { $$ = $pass; }
1397 | SwitchStatement[pass] { $$ = $pass; }
1400 /* 13.2 Block {{{ */
1402 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1406 : "{" StatementListOpt[code] "}" { $$ = $code; }
1410 : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1414 : StatementList[pass] { $$ = $pass; }
1415 | LexSetStatement LexLet LexOf { $$ = NULL; }
1419 : Statement[pass] { $$ = $pass; }
1420 | Declaration[pass] { $$ = $pass; }
1423 /* 13.3 Let and Const Declarations {{{ */
1425 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1429 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1433 : { CYMAP(_let__, _let_); }
1437 : { CYMAP(_of__, _of_); }
1441 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1445 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1446 | LexLet LexOf "const" { $$ = true; }
1450 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1455 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1459 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1460 | LexOf BindingPattern Initializer { CYNOT(@$); }
1463 /* 13.3.2 Variable Statement {{{ */
1465 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1469 : VariableStatement_[statement] Terminator { $$ = $statement; }
1472 VariableDeclarationList_
1473 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1477 VariableDeclarationList
1478 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1482 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1483 | LexOf BindingPattern Initializer { CYNOT(@$); }
1486 /* 13.3.3 Destructuring Binding Patterns {{{ */
1488 : ObjectBindingPattern
1489 | ArrayBindingPattern
1492 ObjectBindingPattern
1493 : "let {" BindingPropertyListOpt "}"
1497 : "let [" BindingElementListOpt "]"
1500 BindingPropertyList_
1501 : "," BindingPropertyListOpt
1506 : BindingProperty BindingPropertyList_
1509 BindingPropertyListOpt
1510 : BindingPropertyList
1515 : BindingElementOpt[element] "," BindingElementListOpt[next]
1516 | BindingRestElement[element]
1517 | BindingElement[element]
1520 BindingElementListOpt
1521 : BindingElementList[pass]
1527 | LexOf PropertyName ":" BindingElement
1531 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1532 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1536 : BindingElement[pass]
1541 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1545 : LexBind LexOf "..." BindingIdentifier
1548 /* 13.4 Empty Statement {{{ */
1550 : ";" { $$ = CYNew CYEmpty(); }
1553 /* 13.5 Expression Statement {{{ */
1554 ExpressionStatement_
1555 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1558 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1561 /* 13.6 The if Statement {{{ */
1563 : "else" Statement[false] { $$ = $false; }
1564 | %prec "if" { $$ = NULL; }
1568 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1571 /* 13.7 Iteration Statements {{{ */
1573 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1574 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1575 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1576 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1577 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1578 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1581 ForStatementInitializer
1582 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1583 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1584 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1585 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1588 ForInStatementInitializer
1589 : LexLet LexOf RubyBlockExpression[pass] { $$ = $pass; }
1590 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1591 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1592 | ForDeclaration[pass] { $$ = $pass; }
1596 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1600 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1601 | LexOf BindingPattern { CYNOT(@$); }
1604 /* 13.8 The continue Statement {{{ */
1606 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1607 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1610 /* 13.9 The break Statement {{{ */
1612 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1613 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1616 /* 13.10 The return Statement {{{ */
1618 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1619 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1622 /* 13.11 The with Statement {{{ */
1624 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1627 /* 13.12 The switch Statement {{{ */
1629 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1633 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1637 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1641 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1642 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1646 // XXX: the standard makes certain you can only have one of these
1648 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1651 /* 13.13 Labelled Statements {{{ */
1653 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1657 : Statement[pass] { $$ = $pass; }
1658 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1661 /* 13.14 The throw Statement {{{ */
1663 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1664 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1667 /* 13.15 The try Statement {{{ */
1669 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1670 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1671 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1675 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1679 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1683 : BindingIdentifier[pass] { $$ = $pass; }
1684 | LexOf BindingPattern { CYNOT(@$); }
1687 /* 13.16 The debugger Statement {{{ */
1689 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1693 /* 14.1 Function Definitions {{{ */
1695 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1699 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1702 StrictFormalParameters
1703 : FormalParameters[pass] { $$ = $pass; }
1707 : LexBind LexOf { $$ = NULL; }
1708 | FormalParameterList
1711 FormalParameterList_
1712 : "," FormalParameterList[parameters] { $$ = $parameters; }
1717 : FunctionRestParameter { CYNOT(@$); }
1718 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1721 FunctionRestParameter
1722 : BindingRestElement
1726 : BindingElement[pass] { $$ = $pass; }
1730 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1733 FunctionStatementList
1734 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1737 /* 14.2 Arrow Function Definitions {{{ */
1739 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1743 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1744 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1748 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1749 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1752 /* 14.3 Method Definitions {{{ */
1754 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1755 | GeneratorMethod[pass] { $$ = $pass; }
1756 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1757 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1760 PropertySetParameterList
1761 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1764 /* 14.4 Generator Function Definitions {{{ */
1766 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1769 GeneratorDeclaration
1770 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1774 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1778 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1782 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1783 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1784 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1785 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1788 /* 14.5 Class Definitions {{{ */
1790 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1794 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1798 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1802 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1806 : ClassHeritage[pass] { $$ = $pass; }
1807 | { $$ = CYNew CYClassTail(NULL); }
1820 : ClassElementListOpt ClassElement
1829 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1830 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1835 /* 15.1 Scripts {{{ */
1837 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1841 : StatementList[pass] { $$ = $pass; }
1845 : ScriptBody[pass] { $$ = $pass; }
1846 | LexSetStatement LexLet LexOf { $$ = NULL; }
1849 /* 15.2 Modules {{{ */
1851 : ModuleBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1855 : ModuleItemList[pass] { $$ = $pass; }
1859 : ModuleBody[pass] { $$ = $pass; }
1860 | LexSetStatement LexLet LexOf { $$ = NULL; }
1864 : ModuleItem[statement] ModuleItemListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1868 : ModuleItemList[pass] { $$ = $pass; }
1869 | LexSetStatement LexLet LexOf { $$ = NULL; }
1873 : LexSetStatement LexLet LexOf ImportDeclaration[pass] { $$ = $pass; }
1874 | LexSetStatement LexLet LexOf ExportDeclaration { CYNOT(@$); }
1875 | StatementListItem[pass] { $$ = $pass; }
1878 /* 15.2.2 Imports {{{ */
1880 : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); }
1881 | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); }
1885 : ImportedDefaultBinding[default] { $$ = $default; }
1886 | LexOf NameSpaceImport[pass] { $$ = $pass; }
1887 | LexOf NamedImports[pass] { $$ = $pass; }
1888 | ImportedDefaultBinding[default] "," NameSpaceImport[next] { $$ = $default; CYSetLast($$) = $next; }
1889 | ImportedDefaultBinding[default] "," NamedImports[next] { $$ = $default; CYSetLast($$) = $next; }
1892 ImportedDefaultBinding
1893 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(CYNew CYIdentifier("default"), $binding); }
1897 : "*" "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(NULL, $binding); }
1901 : "{" ImportsListOpt[pass] "}" { $$ = $pass; }
1905 : "from" ModuleSpecifier[pass] { $$ = $pass; }
1909 : "," ImportsListOpt[pass] { $$ = $pass; }
1914 : ImportSpecifier[import] ImportsList_[next] { $$ = $import; CYSetLast($$) = $next; }
1918 : ImportsList[pass] { $$ = $pass; }
1919 | LexOf { $$ = NULL; }
1923 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($binding, $binding); }
1924 | LexOf IdentifierName[name] "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($name, $binding); }
1928 : StringLiteral[pass] { $$ = $pass; }
1932 : BindingIdentifier[pass] { $$ = $pass; }
1935 /* 15.2.3 Exports {{{ */
1937 : "*" FromClause Terminator
1938 | ExportClause FromClause Terminator
1939 | ExportClause Terminator
1941 | "default" LexSetStatement LexOf HoistableDeclaration
1942 | "default" LexSetStatement LexOf ClassDeclaration
1943 | "default" LexSetStatement AssignmentExpression Terminator
1947 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1948 | "export" Declaration
1952 : ";{" ExportsListOpt "}"
1956 : "," ExportsListOpt
1961 : ExportSpecifier ExportsList_
1971 | IdentifierName "as" IdentifierName
1976 /* Cycript (C): Type Encoding {{{ */
1978 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
1979 | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1983 : TypeSignifier[pass] { $$ = $pass; }
1984 | { $$ = CYNew CYTypedIdentifier(@$); }
1988 : SuffixedTypeOpt[typed] "[" NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
1989 | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
1990 | TypeSignifier[typed] "(" TypedParameterListOpt[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1991 | "("[parenthesis] TypedParameterListOpt[parameters] ")" { $$ = CYNew CYTypedIdentifier(@parenthesis); $$->modifier_ = CYNew CYTypeFunctionWith($parameters, $$->modifier_); }
1995 : SuffixedType[pass] { $$ = $pass; }
1996 | TypeSignifierOpt[pass] { $$ = $pass; }
2000 : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2004 : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
2005 | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
2008 TypeQualifierLeftOpt
2009 : TypeQualifierLeft[pass] { $$ = $pass; }
2014 : SuffixedType[pass] { $$ = $pass; }
2015 | PrefixedType[pass] { $$ = $pass; }
2016 | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
2017 | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
2020 TypeQualifierRightOpt
2021 : TypeQualifierRight[pass] { $$ = $pass; }
2022 | TypeSignifierOpt[pass] { $$ = $pass; }
2026 : "int" { $$ = CYNew CYTypeVariable("int"); }
2027 | "unsigned" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeUnsigned($specifier); }
2028 | "signed" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeSigned($specifier); }
2029 | "long" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeLong($specifier); }
2030 | "short" IntegerTypeOpt[specifier] { $$ = CYNew CYTypeShort($specifier); }
2034 : IntegerType[pass] { $$ = $pass; }
2035 | { $$ = CYNew CYTypeVariable("int"); }
2039 : TypedIdentifierMaybe[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
2044 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
2045 | IntegerType[pass] { $$ = $pass; }
2046 | "char" { $$ = CYNew CYTypeVariable("char"); }
2047 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
2048 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
2049 | "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYTypeStruct($name, $fields); }
2052 TypedIdentifierMaybe
2053 : TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2054 | TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2055 | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2059 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2063 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2067 : "@encode" "(" TypedIdentifierMaybe[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2073 /* Cycript (Objective-C): @class Declaration {{{ */
2075 /* XXX: why the hell did I choose MemberExpression? */
2076 : ":" MemberExpression[extends] { $$ = $extends; }
2080 ImplementationFieldListOpt
2081 : TypedIdentifierMaybe[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2086 : "+" { $$ = false; }
2087 | "-" { $$ = true; }
2091 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2092 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2096 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2099 MessageParameterList
2100 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2103 MessageParameterListOpt
2104 : MessageParameterList[pass] { $$ = $pass; }
2109 : MessageParameterList[pass] { $$ = $pass; }
2110 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2113 ClassMessageDeclaration
2114 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2117 ClassMessageDeclarationListOpt
2118 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2122 // XXX: this should be AssignmentExpressionNoRight
2124 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2128 : "," ClassProtocols[protocols] { $$ = $protocols; }
2132 ClassProtocolListOpt
2133 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2137 ImplementationStatement
2138 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2146 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2150 : ImplementationStatement[pass] { $$ = $pass; }
2151 | CategoryStatement[pass] { $$ = $pass; }
2154 /* Cycript (Objective-C): Send Message {{{ */
2156 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2161 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2162 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2166 : SelectorCall[pass] { $$ = $pass; }
2167 | VariadicCall[pass] { $$ = $pass; }
2171 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2175 : SelectorCall[pass] { $$ = $pass; }
2176 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2180 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2181 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2185 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2189 : SelectorExpression_[pass] { $$ = $pass; }
2190 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2193 SelectorExpressionOpt
2194 : SelectorExpression_[pass] { $$ = $pass; }
2199 : MessageExpression[pass] { $$ = $pass; }
2200 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2205 /* Cycript: @import Directive {{{ */
2207 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2208 | Word[part] { $$ = CYNew CYModule($part); }
2212 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2217 /* Cycript (Objective-C): Boxed Expressions {{{ */
2219 : NullLiteral[pass] { $$ = $pass; }
2220 | BooleanLiteral[pass] { $$ = $pass; }
2221 | NumericLiteral[pass] { $$ = $pass; }
2222 | StringLiteral[pass] { $$ = $pass; }
2223 | ArrayLiteral[pass] { $$ = $pass; }
2224 | ObjectLiteral[pass] { $$ = $pass; }
2225 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2226 | "YES" { $$ = CYNew CYTrue(); }
2227 | "NO" { $$ = CYNew CYFalse(); }
2231 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2232 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2233 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2234 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2235 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2236 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2239 /* Cycript (Objective-C): Block Expressions {{{ */
2241 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2244 /* Cycript (Objective-C): Instance Literals {{{ */
2246 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2252 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2254 : IndirectExpression[pass] { $$ = $pass; }
2258 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2262 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2266 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2267 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2268 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2271 /* Cycript (C): Lambda Expressions {{{ */
2273 : "," TypedParameterList[parameters] { $$ = $parameters; }
2278 : TypedIdentifierMaybe[typed] TypedParameterList_[next] { $$ = CYNew CYTypedParameter($typed, $next); }
2281 TypedParameterListOpt
2282 : TypedParameterList[pass] { $$ = $pass; }
2283 | "void" { $$ = NULL; }
2288 : "[" LexOf "&" "]" "(" TypedParameterListOpt[parameters] ")" "->" TypedIdentifierMaybe[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2291 /* Cycript (C): Type Definitions {{{ */
2293 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2297 : "typedef" NewLineNot TypedIdentifierYes[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
2301 : TypeDefinition[pass] { $$ = $pass; }
2305 : "(" LexOf "typedef" NewLineOpt TypedIdentifierNo[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2308 /* Cycript (C): extern "C" {{{ */
2310 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2314 : TypedIdentifierYes[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
2315 | TypeDefinition[pass] { $$ = $pass; }
2318 ExternCStatementListOpt
2319 : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
2324 : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
2325 | ExternCStatement[pass] { $$ = $pass; }
2329 : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; }
2336 /* Lexer State {{{ */
2338 : { driver.PushCondition(CYDriver::RegExpCondition); }
2342 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2346 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2350 : { driver.PopCondition(); }
2354 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2358 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2361 /* Virtual Tokens {{{ */
2368 /* 8.1 Context Keywords {{{ */
2370 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2371 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2374 /* 8.3 XML Initializer Input Elements {{{ */
2376 : XMLComment { $$ = $1; }
2377 | XMLCDATA { $$ = $1; }
2378 | XMLPI { $$ = $1; }
2382 /* 11.1 Primary Expressions {{{ */
2384 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2385 | XMLInitilizer { $$ = $1; }
2386 | XMLListInitilizer { $$ = $1; }
2390 : AttributeIdentifier { $$ = $1; }
2391 | QualifiedIdentifier { $$ = $1; }
2392 | WildcardIdentifier { $$ = $1; }
2395 /* 11.1.1 Attribute Identifiers {{{ */
2397 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2401 : PropertySelector { $$ = $1; }
2402 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2406 : Identifier { $$ = CYNew CYSelector($1); }
2407 | WildcardIdentifier { $$ = $1; }
2410 /* 11.1.2 Qualified Identifiers {{{ */
2411 QualifiedIdentifier_
2412 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2413 | QualifiedIdentifier { $$ = $1; }
2417 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2420 /* 11.1.3 Wildcard Identifiers {{{ */
2422 : "*" { $$ = CYNew CYWildcard(); }
2425 /* 11.1.4 XML Initializer {{{ */
2427 : XMLMarkup { $$ = $1; }
2428 | XMLElement { $$ = $1; }
2432 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2433 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2437 : LexPushXMLTag XMLTagName XMLAttributes
2441 : "{" LexPushRegExp Expression LexPop "}"
2450 : XMLAttributes_ XMLAttribute
2455 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2456 | XMLAttributes_ XMLWhitespaceOpt
2465 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2469 : XMLExpression XMLElementContentOpt
2470 | XMLMarkup XMLElementContentOpt
2471 | XMLText XMLElementContentOpt
2472 | XMLElement XMLElementContentOpt
2475 XMLElementContentOpt
2480 /* 11.1.5 XMLList Initializer {{{ */
2482 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2486 /* 11.2 Left-Hand-Side Expressions {{{ */
2488 : Identifier { $$ = $1; }
2489 | PropertyIdentifier { $$ = $1; }
2493 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2494 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2495 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2498 /* 12.1 The default xml namespace Statement {{{ */
2499 /* XXX: DefaultXMLNamespaceStatement
2500 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2504 : DefaultXMLNamespaceStatement { $$ = $1; }
2509 /* JavaScript FTL: Array Comprehensions {{{ */
2511 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2515 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2518 /* JavaScript FTL: for each {{{ */
2520 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2524 /* JavaScript FTW: Array Comprehensions {{{ */
2526 : ArrayComprehension
2530 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2534 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2539 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2540 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2544 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2545 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2549 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2552 /* JavaScript FTW: Coalesce Operator {{{ */
2553 ConditionalExpression
2554 : LogicalORExpression[test] "?" LexPushInOff LexOf ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $test, $false); }
2557 /* JavaScript FTW: Named Arguments {{{ */
2559 : LexOf Word[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2562 /* JavaScript FTW: Ruby Blocks {{{ */
2563 RubyProcParameterList_
2564 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2568 RubyProcParameterList
2569 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2570 | LexOf { $$ = NULL; }
2574 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2575 | "||" { $$ = NULL; }
2578 RubyProcParametersOpt
2579 : RubyProcParameters[pass] { $$ = $pass; }
2584 : "{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2588 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2591 RubyBlockExpression_
2592 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
2593 | RubyBlockExpression_[lhs] RubyProcExpression[rhs] LexNewLineOrOpt { $$ = CYNew CYRubyBlock($lhs, $rhs); }
2597 : RubyBlockExpression_[pass] "\n" { $$ = $pass; }
2598 | RubyBlockExpression_[pass] { $$ = $pass; }
2604 bool CYDriver::Parse(CYMark mark) {
2606 CYLocal<CYPool> local(&pool_);
2607 cy::parser parser(*this);
2609 parser.set_debug_level(debug_);
2611 return parser.parse() != 0;
2614 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2618 CYDriver::Error error;
2619 error.warning_ = true;
2620 error.location_ = location;
2621 error.message_ = message;
2622 errors_.push_back(error);
2625 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2626 CYDriver::Error error;
2627 error.warning_ = false;
2628 error.location_ = location;
2629 error.message_ = message;
2630 driver.errors_.push_back(error);