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 { CYBraced *braced_; }
52 %union { CYClause *clause_; }
53 %union { cy::Syntax::Catch *catch_; }
54 %union { CYClassTail *classTail_; }
55 %union { CYComprehension *comprehension_; }
56 %union { CYElement *element_; }
57 %union { CYExpression *expression_; }
58 %union { CYFalse *false_; }
59 %union { CYVariable *variable_; }
60 %union { CYFinally *finally_; }
61 %union { CYForInitializer *for_; }
62 %union { CYForInInitializer *forin_; }
63 %union { CYFunctionParameter *functionParameter_; }
64 %union { CYIdentifier *identifier_; }
65 %union { CYImportSpecifier *import_; }
66 %union { CYInfix *infix_; }
67 %union { CYLiteral *literal_; }
68 %union { CYMethod *method_; }
69 %union { CYModule *module_; }
70 %union { CYNull *null_; }
71 %union { CYNumber *number_; }
72 %union { CYParenthetical *parenthetical_; }
73 %union { CYProperty *property_; }
74 %union { CYPropertyName *propertyName_; }
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 { CYTypeIntegral *integral_; }
85 %union { CYTypeStructField *structField_; }
86 %union { CYTypeModifier *modifier_; }
87 %union { CYTypeSpecifier *specifier_; }
88 %union { CYTypedFormal *typedFormal_; }
89 %union { CYTypedIdentifier *typedIdentifier_; }
90 %union { CYTypedParameter *typedParameter_; }
94 %union { CYObjCKeyValue *keyValue_; }
95 %union { CYImplementationField *implementationField_; }
96 %union { CYMessage *message_; }
97 %union { CYMessageParameter *messageParameter_; }
98 %union { CYProtocol *protocol_; }
99 %union { CYSelectorPart *selector_; }
103 %union { CYAttribute *attribute_; }
104 %union { CYPropertyIdentifier *propertyIdentifier_; }
105 %union { CYSelector *selector_; }
111 cy::parser::semantic_type semantic_;
112 hi::Value highlight_;
115 int cylex(YYSTYPE *, CYLocation *, void *);
123 typedef cy::parser::token tk;
125 _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
126 driver.newline_ = false;
129 int token(cylex(&data, location, driver.scanner_));
130 *semantic = data.semantic_;
134 case tk::OpenBracket:
136 driver.in_.push(false);
140 if (driver.in_.top())
145 case tk::CloseBracket:
152 if (driver.yield_.top())
153 token = tk::_yield__;
157 driver.newline_ = true;
165 #define yylex_(semantic, location, driver) ({ \
167 if (driver.hold_ == cy::parser::empty_symbol) \
168 type = yytranslate_(cylex_(semantic, location, driver)); \
170 type = driver.hold_; \
171 driver.hold_ = cy::parser::empty_symbol; \
175 #define CYLEX() do if (yyla.empty()) { \
176 YYCDEBUG << "Mapping a token: "; \
177 yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
178 YY_SYMBOL_PRINT("Next token is", yyla); \
181 #define CYMAP(to, from) do { \
183 if (yyla.type == yytranslate_(token::from)) \
184 yyla.type = yytranslate_(token::to); \
187 #define CYHLD(location, token) do { \
188 if (driver.hold_ != empty_symbol) \
189 CYERR(location, "unexpected hold"); \
190 driver.hold_ = yyla.type; \
191 yyla.type = yytranslate_(token); \
194 #define CYERR(location, message) do { \
195 error(location, message); \
199 #define CYEOK() do { \
201 driver.errors_.pop_back(); \
204 #define CYNOT(location) \
205 CYERR(location, "unimplemented feature")
207 #define CYMPT(location) do { \
208 if (!yyla.empty() && yyla.type_get() != yyeof_) \
209 CYERR(location, "unexpected lookahead"); \
219 @$.begin.filename = @$.end.filename = &driver.filename_;
221 switch (driver.mark_) {
223 driver.hold_ = yytranslate_(token::MarkScript);
226 driver.hold_ = yytranslate_(token::MarkModule);
234 %define api.location.type { CYLocation }
241 %param { CYDriver &driver }
243 /* Token Declarations {{{ */
249 %token XMLAttributeValue
251 %token XMLTagCharacters
257 %token LeftRight "<>"
258 %token LeftSlashRight "</>"
260 %token SlashRight "/>"
261 %token LeftSlash "</"
263 %token PeriodPeriod ".."
266 @begin E4X ObjectiveC
272 %token AmpersandAmpersand "&&"
273 %token AmpersandEqual "&="
275 %token CarrotEqual "^="
277 %token EqualEqual "=="
278 %token EqualEqualEqual "==="
279 %token EqualRight "=>"
280 %token Exclamation "!"
281 %token ExclamationEqual "!="
282 %token ExclamationEqualEqual "!=="
284 %token HyphenEqual "-="
285 %token HyphenHyphen "--"
286 %token HyphenRight "->"
288 %token LeftEqual "<="
290 %token LeftLeftEqual "<<="
292 %token PercentEqual "%="
294 %token PeriodPeriodPeriod "..."
296 %token PipeEqual "|="
299 %token PlusEqual "+="
302 %token RightEqual ">="
303 %token RightRight ">>"
304 %token RightRightEqual ">>="
305 %token RightRightRight ">>>"
306 %token RightRightRightEqual ">>>="
308 %token SlashEqual "/="
310 %token StarEqual "*="
314 %token ColonColon "::"
324 %token CloseParen ")"
327 %token OpenBrace_ ";{"
328 %token OpenBrace_let "let {"
329 %token CloseBrace "}"
331 %token OpenBracket "["
332 %token OpenBracket_let "let ["
333 %token CloseBracket "]"
335 %token At_error_ "@error"
338 %token At_class_ "@class"
342 %token _typedef_ "typedef"
343 %token _unsigned_ "unsigned"
344 %token _signed_ "signed"
345 %token _struct_ "struct"
346 %token _extern_ "extern"
350 %token At_encode_ "@encode"
354 %token At_implementation_ "@implementation"
355 %token At_import_ "@import"
356 %token At_end_ "@end"
357 %token At_selector_ "@selector"
358 %token At_null_ "@null"
359 %token At_YES_ "@YES"
361 %token At_true_ "@true"
362 %token At_false_ "@false"
367 %token _false_ "false"
372 %token _break_ "break"
374 %token _catch_ "catch"
375 %token _class_ "class"
376 %token _class__ ";class"
377 %token _const_ "const"
378 %token _continue_ "continue"
379 %token _debugger_ "debugger"
380 %token _default_ "default"
381 %token _delete_ "delete"
385 %token _export_ "export"
386 %token _extends_ "extends"
387 %token _finally_ "finally"
389 %token _function_ "function"
390 %token _function__ ";function"
392 %token _import_ "import"
395 %token _Infinity_ "Infinity"
396 %token _instanceof_ "instanceof"
398 %token _return_ "return"
399 %token _super_ "super"
400 %token _switch_ "switch"
401 %token _target_ "target"
403 %token _throw_ "throw"
405 %token _typeof_ "typeof"
408 %token _while_ "while"
411 %token _abstract_ "abstract"
412 %token _await_ "await"
413 %token _boolean_ "boolean"
416 %token _constructor_ "constructor"
417 %token _double_ "double"
419 %token _final_ "final"
420 %token _float_ "float"
424 %token _implements_ "implements"
426 %token _interface_ "interface"
430 %token _native_ "native"
431 %token _package_ "package"
432 %token _private_ "private"
433 %token _protected_ "protected"
434 %token ___proto___ "__proto__"
435 %token _prototype_ "prototype"
436 %token _public_ "public"
437 %token ___restrict_ "__restrict"
438 %token _restrict_ "restrict"
440 %token _short_ "short"
441 %token _static_ "static"
442 %token _synchronized_ "synchronized"
443 %token _throws_ "throws"
444 %token _transient_ "transient"
445 %token _typeid_ "typeid"
446 %token _volatile_ "volatile"
447 %token _yield_ "yield"
448 %token _yield__ "!yield"
450 %token _undefined_ "undefined"
466 %token _namespace_ "namespace"
471 %token YieldStar "yield *"
473 %token <identifier_> Identifier_
474 %token <number_> NumericLiteral
475 %token <string_> StringLiteral
476 %token <literal_> RegularExpressionLiteral_
478 %token <string_> NoSubstitutionTemplate
479 %token <string_> TemplateHead
480 %token <string_> TemplateMiddle
481 %token <string_> TemplateTail
483 %type <target_> AccessExpression
484 %type <expression_> AdditiveExpression
485 %type <argument_> ArgumentList_
486 %type <argument_> ArgumentList
487 %type <argument_> ArgumentListOpt
488 %type <argument_> Arguments
489 %type <target_> ArrayComprehension
490 %type <element_> ArrayElement
491 %type <literal_> ArrayLiteral
492 %type <expression_> ArrowFunction
493 %type <functionParameter_> ArrowParameters
494 %type <expression_> AssignmentExpression
495 %type <identifier_> BindingIdentifier
496 %type <identifier_> BindingIdentifierOpt
497 %type <bindings_> BindingList_
498 %type <bindings_> BindingList
499 %type <expression_> BitwiseANDExpression
500 %type <statement_> Block
501 %type <statement_> BlockStatement
502 %type <boolean_> BooleanLiteral
503 %type <binding_> BindingElement
504 %type <expression_> BitwiseORExpression
505 %type <expression_> BitwiseXORExpression
506 %type <target_> BracedExpression_
507 %type <target_> BracedExpression
508 %type <statement_> BreakStatement
509 %type <statement_> BreakableStatement
510 %type <expression_> CallExpression_
511 %type <target_> CallExpression
512 %type <clause_> CaseBlock
513 %type <clause_> CaseClause
514 %type <clause_> CaseClausesOpt
516 %type <identifier_> CatchParameter
517 %type <statement_> ClassDeclaration
518 %type <target_> ClassExpression
519 %type <classTail_> ClassHeritage
520 %type <classTail_> ClassHeritageOpt
521 %type <classTail_> ClassTail
522 %type <target_> Comprehension
523 %type <comprehension_> ComprehensionFor
524 %type <comprehension_> ComprehensionIf
525 %type <comprehension_> ComprehensionTail
526 %type <propertyName_> ComputedPropertyName
527 %type <expression_> ConditionalExpression
528 %type <statement_> ContinueStatement
529 %type <statement_> ConciseBody
530 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
531 %type <statement_> DebuggerStatement
532 %type <statement_> Declaration_
533 %type <statement_> Declaration
534 %type <clause_> DefaultClause
535 %type <element_> ElementList_
536 %type <element_> ElementList
537 %type <element_> ElementListOpt
538 %type <statement_> ElseStatementOpt
539 %type <for_> EmptyStatement
540 %type <expression_> EqualityExpression
541 %type <expression_> Expression
542 %type <expression_> ExpressionOpt
543 %type <for_> ExpressionStatement_
544 %type <statement_> ExpressionStatement
545 %type <statement_> ExternC
546 %type <statement_> ExternCStatement
547 %type <statement_> ExternCStatementListOpt
548 %type <finally_> Finally
549 %type <binding_> ForBinding
550 %type <forin_> ForDeclaration
551 %type <forin_> ForInStatementInitializer
552 %type <for_> ForStatementInitializer
553 %type <binding_> FormalParameter
554 %type <functionParameter_> FormalParameterList_
555 %type <functionParameter_> FormalParameterList
556 %type <functionParameter_> FormalParameters
557 %type <string_> FromClause
558 %type <statement_> FunctionBody
559 %type <statement_> FunctionDeclaration
560 %type <target_> FunctionExpression
561 %type <statement_> FunctionStatementList
562 %type <statement_> GeneratorBody
563 %type <statement_> GeneratorDeclaration
564 %type <target_> GeneratorExpression
565 %type <method_> GeneratorMethod
566 %type <statement_> HoistableDeclaration
567 %type <identifier_> Identifier
568 %type <identifier_> IdentifierNoOf
569 %type <identifier_> IdentifierType
570 %type <identifier_> IdentifierTypeNoOf
571 %type <identifier_> IdentifierTypeOpt
572 %type <word_> IdentifierName
573 %type <variable_> IdentifierReference
574 %type <statement_> IfStatement
575 %type <import_> ImportClause
576 %type <statement_> ImportDeclaration
577 %type <import_> ImportSpecifier
578 %type <identifier_> ImportedBinding
579 %type <import_> ImportedDefaultBinding
580 %type <import_> ImportsList_
581 %type <import_> ImportsList
582 %type <import_> ImportsListOpt
583 %type <target_> IndirectExpression
584 %type <expression_> Initializer
585 %type <expression_> InitializerOpt
586 %type <statement_> IterationStatement
587 %type <identifier_> LabelIdentifier
588 %type <statement_> LabelledItem
589 %type <statement_> LabelledStatement
590 %type <assignment_> LeftHandSideAssignment
591 %type <target_> LeftHandSideExpression
592 %type <bool_> LetOrConst
593 %type <binding_> LexicalBinding
594 %type <for_> LexicalDeclaration_
595 %type <statement_> LexicalDeclaration
596 %type <literal_> Literal
597 %type <propertyName_> LiteralPropertyName
598 %type <expression_> LogicalANDExpression
599 %type <expression_> LogicalORExpression
600 %type <access_> MemberAccess
601 %type <target_> MemberExpression
602 %type <method_> MethodDefinition
603 %type <statement_> ModuleBody
604 %type <statement_> ModuleBodyOpt
605 %type <statement_> ModuleItem
606 %type <statement_> ModuleItemList
607 %type <statement_> ModuleItemListOpt
608 %type <module_> ModulePath
609 %type <string_> ModuleSpecifier
610 %type <expression_> MultiplicativeExpression
611 %type <import_> NameSpaceImport
612 %type <import_> NamedImports
613 %type <target_> NewExpression
614 %type <null_> NullLiteral
615 %type <literal_> ObjectLiteral
616 %type <expression_> PostfixExpression
617 %type <target_> PrimaryExpression
618 %type <propertyName_> PropertyName
619 %type <property_> PropertyDefinition
620 %type <property_> PropertyDefinitionList_
621 %type <property_> PropertyDefinitionList
622 %type <property_> PropertyDefinitionListOpt
623 %type <functionParameter_> PropertySetParameterList
624 %type <literal_> RegularExpressionLiteral
625 %type <bool_> RegularExpressionSlash
626 %type <expression_> RelationalExpression
627 %type <statement_> ReturnStatement
628 %type <braced_> BracedParameter
629 %type <functionParameter_> RubyProcParameterList_
630 %type <functionParameter_> RubyProcParameterList
631 %type <functionParameter_> RubyProcParameters
632 %type <functionParameter_> RubyProcParametersOpt
633 %type <statement_> Script
634 %type <statement_> ScriptBody
635 %type <statement_> ScriptBodyOpt
636 %type <expression_> ShiftExpression
637 %type <binding_> SingleNameBinding
638 %type <statement_> Statement__
639 %type <statement_> Statement_
640 %type <statement_> Statement
641 %type <statement_> StatementList
642 %type <statement_> StatementListOpt
643 %type <statement_> StatementListItem
644 %type <functionParameter_> StrictFormalParameters
645 %type <target_> SuperCall
646 %type <target_> SuperProperty
647 %type <statement_> SwitchStatement
648 %type <target_> TemplateLiteral
649 %type <span_> TemplateSpans
650 %type <statement_> ThrowStatement
651 %type <statement_> TryStatement
652 %type <statement_> TypeDefinition
653 %type <expression_> UnaryExpression_
654 %type <expression_> UnaryExpression
655 %type <binding_> VariableDeclaration
656 %type <bindings_> VariableDeclarationList_
657 %type <bindings_> VariableDeclarationList
658 %type <for_> VariableStatement_
659 %type <statement_> VariableStatement
660 %type <statement_> WithStatement
662 %type <word_> WordNoUnary
664 %type <word_> WordOpt
666 %type <expression_> YieldExpression
669 %type <integral_> IntegerType
670 %type <integral_> IntegerTypeOpt
671 %type <typedIdentifier_> PrefixedType
672 %type <specifier_> PrimitiveType
673 %type <structField_> StructFieldListOpt
674 %type <typedIdentifier_> SuffixedType
675 %type <typedIdentifier_> SuffixedTypeOpt
676 %type <typedIdentifier_> TypeSignifier
677 %type <typedIdentifier_> TypeSignifierNone
678 %type <typedIdentifier_> TypeSignifierOpt
679 %type <modifier_> ParameterTail
680 %type <modifier_> TypeQualifierLeft
681 %type <modifier_> TypeQualifierLeftOpt
682 %type <typedIdentifier_> TypeQualifierRight
683 %type <typedIdentifier_> TypeQualifierRightOpt
684 %type <typedIdentifier_> TypedIdentifierDefinition
685 %type <typedIdentifier_> TypedIdentifierEncoding
686 %type <typedIdentifier_> TypedIdentifierField
687 %type <typedIdentifier_> TypedIdentifierMaybe
688 %type <typedIdentifier_> TypedIdentifierNo
689 %type <typedIdentifier_> TypedIdentifierYes
690 %type <typedFormal_> TypedParameterList_
691 %type <typedFormal_> TypedParameterList
692 %type <typedFormal_> TypedParameterListOpt
693 %type <typedParameter_> TypedParameters
697 %type <expression_> AssignmentExpressionClassic
698 %type <expression_> BoxableExpression
699 %type <statement_> CategoryStatement
700 %type <expression_> ClassSuperOpt
701 %type <expression_> ConditionalExpressionClassic
702 %type <message_> ClassMessageDeclaration
703 %type <message_> ClassMessageDeclarationListOpt
704 %type <protocol_> ClassProtocolListOpt
705 %type <protocol_> ClassProtocols
706 %type <protocol_> ClassProtocolsOpt
707 %type <implementationField_> ImplementationFieldListOpt
708 %type <statement_> ImplementationStatement
709 %type <keyValue_> KeyValuePairList_
710 %type <keyValue_> KeyValuePairList
711 %type <keyValue_> KeyValuePairListOpt
712 %type <target_> MessageExpression
713 %type <messageParameter_> MessageParameter
714 %type <messageParameter_> MessageParameters
715 %type <messageParameter_> MessageParameterList
716 %type <messageParameter_> MessageParameterListOpt
717 %type <bool_> MessageScope
718 %type <argument_> SelectorCall_
719 %type <argument_> SelectorCall
720 %type <selector_> SelectorExpression_
721 %type <selector_> SelectorExpression
722 %type <selector_> SelectorExpressionOpt
723 %type <argument_> SelectorList
724 %type <word_> SelectorWordOpt
725 %type <typedIdentifier_> TypeOpt
726 %type <argument_> VariadicCall
730 %type <propertyIdentifier_> PropertyIdentifier_
731 %type <selector_> PropertySelector_
732 %type <selector_> PropertySelector
733 %type <identifier_> QualifiedIdentifier_
734 %type <identifier_> QualifiedIdentifier
735 %type <identifier_> WildcardIdentifier
736 %type <identifier_> XMLComment
737 %type <identifier_> XMLCDATA
738 %type <identifier_> XMLElement
739 %type <identifier_> XMLElementContent
740 %type <identifier_> XMLMarkup
741 %type <identifier_> XMLPI
743 %type <attribute_> AttributeIdentifier
744 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
745 %type <expression_> PropertyIdentifier
746 %type <expression_> XMLListInitilizer
747 %type <expression_> XMLInitilizer
750 /* Token Priorities {{{ */
769 /* Lexer State {{{ */
770 LexPushInOn: { driver.in_.push(true); };
771 LexPushInOff: { driver.in_.push(false); };
772 LexPopIn: { driver.in_.pop(); };
774 LexPushReturnOn: { driver.return_.push(true); };
775 LexPopReturn: { driver.return_.pop(); };
776 Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); };
778 LexPushSuperOn: { driver.super_.push(true); };
779 LexPushSuperOff: { driver.super_.push(false); };
780 LexPopSuper: { driver.super_.pop(); };
781 Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); };
783 LexPushYieldOn: { driver.yield_.push(true); };
784 LexPushYieldOff: { driver.yield_.push(false); };
785 LexPopYield: { driver.yield_.pop(); };
788 : { CYLEX(); if (driver.newline_) { CYHLD(@$, tk::NewLine); } }
792 : { CYLEX(); CYHLD(@$, driver.newline_ ? tk::NewLine : tk::__); }
796 : { CYMAP(YieldStar, Star); }
800 : { CYMAP(OpenBrace_, OpenBrace); }
804 : { CYMAP(_class__, _class_); }
808 : { CYMAP(_function__, _function_); }
812 : LexNoBrace LexNoClass LexNoFunction
815 /* Virtual Tokens {{{ */
821 /* 11.6 Names and Keywords {{{ */
823 : Word[pass] { $$ = $pass; }
824 | "for" { $$ = CYNew CYWord("for"); }
825 | "in" { $$ = CYNew CYWord("in"); }
826 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
830 : IdentifierNoOf[pass] { $$ = $pass; }
831 | "break" { $$ = CYNew CYWord("break"); }
832 | "case" { $$ = CYNew CYWord("case"); }
833 | "catch" { $$ = CYNew CYWord("catch"); }
834 | "class" LexOf { $$ = CYNew CYWord("class"); }
835 | ";class" { $$ = CYNew CYWord("class"); }
836 | "const" { $$ = CYNew CYWord("const"); }
837 | "continue" { $$ = CYNew CYWord("continue"); }
838 | "debugger" { $$ = CYNew CYWord("debugger"); }
839 | "default" { $$ = CYNew CYWord("default"); }
840 | "do" { $$ = CYNew CYWord("do"); }
841 | "else" { $$ = CYNew CYWord("else"); }
842 | "enum" { $$ = CYNew CYWord("enum"); }
843 | "export" { $$ = CYNew CYWord("export"); }
844 | "extends" { $$ = CYNew CYWord("extends"); }
845 | "false" { $$ = CYNew CYWord("false"); }
846 | "finally" { $$ = CYNew CYWord("finally"); }
847 | "function" LexOf { $$ = CYNew CYWord("function"); }
848 | "if" { $$ = CYNew CYWord("if"); }
849 | "import" { $$ = CYNew CYWord("import"); }
850 | "!in" { $$ = CYNew CYWord("in"); }
851 | "!of" { $$ = CYNew CYWord("of"); }
852 | "null" { $$ = CYNew CYWord("null"); }
853 | "return" { $$ = CYNew CYWord("return"); }
854 | "super" { $$ = CYNew CYWord("super"); }
855 | "switch" { $$ = CYNew CYWord("switch"); }
856 | "this" { $$ = CYNew CYWord("this"); }
857 | "throw" { $$ = CYNew CYWord("throw"); }
858 | "true" { $$ = CYNew CYWord("true"); }
859 | "try" { $$ = CYNew CYWord("try"); }
860 | "var" { $$ = CYNew CYWord("var"); }
861 | "while" { $$ = CYNew CYWord("while"); }
862 | "with" { $$ = CYNew CYWord("with"); }
866 : WordNoUnary[pass] { $$ = $pass; }
867 | "delete" { $$ = CYNew CYWord("delete"); }
868 | "typeof" { $$ = CYNew CYWord("typeof"); }
869 | "void" { $$ = CYNew CYWord("void"); }
870 | "yield" { $$ = CYNew CYIdentifier("yield"); }
875 : Word[pass] { $$ = $pass; }
880 /* 11.8.1 Null Literals {{{ */
882 : "null" { $$ = CYNew CYNull(); }
885 /* 11.8.2 Boolean Literals {{{ */
887 : "true" { $$ = CYNew CYTrue(); }
888 | "false" { $$ = CYNew CYFalse(); }
891 /* 11.8.5 Regular Expression Literals {{{ */
892 RegularExpressionSlash
893 : "/" { $$ = false; }
894 | "/=" { $$ = true; }
897 RegularExpressionLiteral
898 : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; }
902 /* 11.9 Automatic Semicolon Insertion {{{ */
904 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
912 : LexNewLineOrNot "\n"
917 : LexNewLineOrNot "\n" StrictSemi
918 | NewLineNot LexOf Terminator
923 | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
928 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi
933 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
937 /* 12.1 Identifiers {{{ */
939 : Identifier[pass] { $$ = CYNew CYVariable($pass); }
940 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
944 : LexOf IdentifierNoOf[pass] { $$ = $pass; }
945 | LexOf "!of" { $$ = CYNew CYIdentifier("of"); }
946 | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); }
950 : BindingIdentifier[pass] { $$ = $pass; }
951 | LexOf { $$ = NULL; }
955 : Identifier[pass] { $$ = $pass; }
956 | "yield" { $$ = CYNew CYIdentifier("yield"); }
960 : Identifier_[pass] { $$ = $pass; }
961 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
962 | "as" { $$ = CYNew CYIdentifier("as"); }
963 | "await" { $$ = CYNew CYIdentifier("await"); }
964 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
965 | "byte" { $$ = CYNew CYIdentifier("byte"); }
966 | "constructor" { $$ = CYNew CYIdentifier("constructor"); }
967 | "double" { $$ = CYNew CYIdentifier("double"); }
968 | "each" { $$ = CYNew CYIdentifier("each"); }
969 | "eval" { $$ = CYNew CYIdentifier("eval"); }
970 | "final" { $$ = CYNew CYIdentifier("final"); }
971 | "float" { $$ = CYNew CYIdentifier("float"); }
972 | "from" { $$ = CYNew CYIdentifier("from"); }
973 | "get" { $$ = CYNew CYIdentifier("get"); }
974 | "goto" { $$ = CYNew CYIdentifier("goto"); }
975 | "implements" { $$ = CYNew CYIdentifier("implements"); }
976 | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); }
977 | "interface" { $$ = CYNew CYIdentifier("interface"); }
978 | "let" { $$ = CYNew CYIdentifier("let"); }
979 | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); }
980 | "native" { $$ = CYNew CYIdentifier("native"); }
981 | "package" { $$ = CYNew CYIdentifier("package"); }
982 | "private" { $$ = CYNew CYIdentifier("private"); }
983 | "protected" { $$ = CYNew CYIdentifier("protected"); }
984 | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); }
985 | "prototype" { $$ = CYNew CYIdentifier("prototype"); }
986 | "public" { $$ = CYNew CYIdentifier("public"); }
987 | "set" { $$ = CYNew CYIdentifier("set"); }
988 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
989 | "target" { $$ = CYNew CYIdentifier("target"); }
990 | "throws" { $$ = CYNew CYIdentifier("throws"); }
991 | "transient" { $$ = CYNew CYIdentifier("transient"); }
992 | "typeid" { $$ = CYNew CYIdentifier("typeid"); }
993 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
995 | "bool" { $$ = CYNew CYIdentifier("bool"); }
996 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
997 | "id" { $$ = CYNew CYIdentifier("id"); }
998 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
1003 : IdentifierTypeNoOf[pass] { $$ = $pass; }
1004 | "of" { $$ = CYNew CYIdentifier("of"); }
1008 : IdentifierType[pass] { $$ = $pass; }
1013 : IdentifierTypeNoOf
1014 | "char" { $$ = CYNew CYIdentifier("char"); }
1015 | "int" { $$ = CYNew CYIdentifier("int"); }
1016 | "long" { $$ = CYNew CYIdentifier("long"); }
1017 | "__restrict" { $$ = CYNew CYIdentifier("__restrict"); }
1018 | "restrict" { $$ = CYNew CYIdentifier("restrict"); }
1019 | "short" { $$ = CYNew CYIdentifier("short"); }
1020 | "static" { $$ = CYNew CYIdentifier("static"); }
1021 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
1023 | "signed" { $$ = CYNew CYIdentifier("signed"); }
1024 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
1027 | "nil" { $$ = CYNew CYIdentifier("nil"); }
1028 | "NO" { $$ = CYNew CYIdentifier("NO"); }
1029 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
1030 | "YES" { $$ = CYNew CYIdentifier("YES"); }
1035 : IdentifierNoOf[pass] { $$ = $pass; }
1036 | "of" { $$ = CYNew CYIdentifier("of"); }
1037 | "!of" { $$ = CYNew CYIdentifier("of"); }
1040 /* 12.2 Primary Expression {{{ */
1042 : "this" { $$ = CYNew CYThis(); }
1043 | IdentifierReference[pass] { $$ = $pass; }
1044 | Literal[pass] { $$ = $pass; }
1045 | ArrayLiteral[pass] { $$ = $pass; }
1046 | ObjectLiteral[pass] { $$ = $pass; }
1047 | FunctionExpression[pass] { $$ = $pass; }
1048 | ClassExpression[pass] { $$ = $pass; }
1049 | GeneratorExpression[pass] { $$ = $pass; }
1050 | RegularExpressionLiteral[pass] { $$ = $pass; }
1051 | TemplateLiteral[pass] { $$ = $pass; }
1052 | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; }
1053 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
1056 CoverParenthesizedExpressionAndArrowParameterList
1057 : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); }
1058 | "(" LexOf ")" { $$ = NULL; }
1059 | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1060 | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); }
1063 /* 12.2.4 Literals {{{ */
1065 : NullLiteral[pass] { $$ = $pass; }
1066 | BooleanLiteral[pass] { $$ = $pass; }
1067 | NumericLiteral[pass] { $$ = $pass; }
1068 | StringLiteral[pass] { $$ = $pass; }
1071 /* 12.2.5 Array Initializer {{{ */
1073 : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); }
1077 : AssignmentExpression[value] { $$ = CYNew CYElementValue($value); }
1078 | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); }
1082 : "," ElementListOpt[elements] { $$ = $elements; }
1087 : ArrayElement[element] ElementList_[next] { $$ = $element; $$->SetNext($next); }
1088 | LexOf "," ElementListOpt[next] { $$ = CYNew CYElementValue(NULL, $next); }
1092 : ElementList[pass] { $$ = $pass; }
1093 | LexOf { $$ = NULL; }
1096 /* 12.2.6 Object Initializer {{{ */
1098 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); }
1101 PropertyDefinitionList_
1102 : "," PropertyDefinitionListOpt[properties] { $$ = $properties; }
1106 PropertyDefinitionList
1107 : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; }
1110 PropertyDefinitionListOpt
1111 : PropertyDefinitionList[properties] { $$ = $properties; }
1116 : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); }
1117 | CoverInitializedName[name] { CYNOT(@$); }
1118 | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); }
1119 | MethodDefinition[pass] { $$ = $pass; }
1123 : LiteralPropertyName[pass] { $$ = $pass; }
1124 | ComputedPropertyName[pass] { $$ = $pass; }
1128 : IdentifierName[pass] { $$ = $pass; }
1129 | StringLiteral[pass] { $$ = $pass; }
1130 | NumericLiteral[pass] { $$ = $pass; }
1133 ComputedPropertyName
1134 : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); }
1137 CoverInitializedName
1138 : IdentifierReference Initializer
1142 : "=" AssignmentExpression[initializer] { $$ = $initializer; }
1146 : Initializer[pass] { $$ = $pass; }
1150 /* 12.2.9 Template Literals {{{ */
1152 : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); }
1153 | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); }
1157 : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); }
1158 | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); }
1162 /* 12.3 Left-Hand-Side Expressions {{{ */
1164 : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); }
1165 | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); }
1166 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
1167 | TemplateLiteral { CYNOT(@$); }
1171 : PrimaryExpression[pass] { $$ = $pass; }
1172 | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1173 | SuperProperty[pass] { $$ = $pass; }
1174 | MetaProperty { CYNOT(@$); }
1175 | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); }
1179 : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); }
1180 | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); }
1188 : "new" "." "target"
1192 : MemberExpression[pass] { $$ = $pass; }
1193 | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); }
1197 : MemberExpression[pass] { $$ = $pass; }
1198 | CallExpression[pass] { $$ = $pass; }
1202 : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); }
1203 | SuperCall[pass] { $$ = $pass; }
1204 | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; }
1208 : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); }
1212 : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; }
1216 : "," ArgumentList[arguments] { $$ = $arguments; }
1221 : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
1222 | LexOf "..." AssignmentExpression { CYNOT(@$); }
1226 : ArgumentList[pass] { $$ = $pass; }
1227 | LexOf { $$ = NULL; }
1231 : NewExpression[pass] { $$ = $pass; }
1232 | CallExpression[pass] { $$ = $pass; }
1235 LeftHandSideExpression
1236 : BracedExpression[pass] { $$ = $pass; }
1237 | IndirectExpression[pass] { $$ = $pass; }
1240 /* 12.4 Postfix Expressions {{{ */
1242 : BracedExpression[pass] { $$ = $pass; }
1243 | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); }
1244 | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); }
1247 /* 12.5 Unary Operators {{{ */
1249 : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); }
1250 | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); }
1251 | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); }
1252 | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); }
1253 | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); }
1254 | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); }
1255 | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); }
1256 | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); }
1257 | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); }
1261 : PostfixExpression[expression] { $$ = $expression; }
1262 | UnaryExpression_[pass] { $$ = $pass; }
1265 /* 12.6 Multiplicative Operators {{{ */
1266 MultiplicativeExpression
1267 : UnaryExpression[pass] { $$ = $pass; }
1268 | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); }
1269 | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); }
1270 | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); }
1273 /* 12.7 Additive Operators {{{ */
1275 : MultiplicativeExpression[pass] { $$ = $pass; }
1276 | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); }
1277 | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); }
1280 /* 12.8 Bitwise Shift Operators {{{ */
1282 : AdditiveExpression[pass] { $$ = $pass; }
1283 | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); }
1284 | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); }
1285 | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); }
1288 /* 12.9 Relational Operators {{{ */
1289 RelationalExpression
1290 : ShiftExpression[pass] { $$ = $pass; }
1291 | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); }
1292 | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); }
1293 | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); }
1294 | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); }
1295 | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); }
1296 | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); }
1299 /* 12.10 Equality Operators {{{ */
1301 : RelationalExpression[pass] { $$ = $pass; }
1302 | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); }
1303 | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); }
1304 | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); }
1305 | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); }
1308 /* 12.11 Binary Bitwise Operators {{{ */
1309 BitwiseANDExpression
1310 : EqualityExpression[pass] { $$ = $pass; }
1311 | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); }
1314 BitwiseXORExpression
1315 : BitwiseANDExpression[pass] { $$ = $pass; }
1316 | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); }
1320 : BitwiseXORExpression[pass] { $$ = $pass; }
1321 | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); }
1324 /* 12.12 Binary Logical Operators {{{ */
1325 LogicalANDExpression
1326 : BitwiseORExpression[pass] { $$ = $pass; }
1327 | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); }
1331 : LogicalANDExpression[pass] { $$ = $pass; }
1332 | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); }
1335 /* 12.13 Conditional Operator ( ? : ) {{{ */
1337 ConditionalExpressionClassic
1338 : LogicalORExpression[pass] { $$ = $pass; }
1339 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); }
1343 ConditionalExpression
1344 : LogicalORExpression[pass] { $$ = $pass; }
1345 | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); }
1348 /* 12.14 Assignment Operators {{{ */
1349 LeftHandSideAssignment
1350 : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); }
1351 | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); }
1352 | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); }
1353 | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); }
1354 | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); }
1355 | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); }
1356 | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); }
1357 | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); }
1358 | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); }
1359 | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); }
1360 | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); }
1361 | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); }
1365 AssignmentExpressionClassic
1366 : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; }
1367 | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1371 AssignmentExpression
1372 : LexOf ConditionalExpression[pass] { $$ = $pass; }
1373 | LexOf YieldExpression[pass] { $$ = $pass; }
1374 | ArrowFunction[pass] { $$ = $pass; }
1375 | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; }
1378 /* 12.15 Comma Operator ( , ) {{{ */
1380 : AssignmentExpression[pass] { $$ = $pass; }
1381 | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); }
1385 : Expression[pass] { $$ = $pass; }
1386 | LexOf { $$ = NULL; }
1390 /* 13 Statements and Declarations {{{ */
1392 : BlockStatement[pass] { $$ = $pass; }
1393 | VariableStatement[pass] { $$ = $pass; }
1394 | EmptyStatement[pass] { $$ = $pass; }
1395 | IfStatement[pass] { $$ = $pass; }
1396 | BreakableStatement[pass] { $$ = $pass; }
1397 | ContinueStatement[pass] { $$ = $pass; }
1398 | BreakStatement[pass] { $$ = $pass; }
1399 | ReturnStatement[pass] { $$ = $pass; }
1400 | WithStatement[pass] { $$ = $pass; }
1401 | LabelledStatement[pass] { $$ = $pass; }
1402 | ThrowStatement[pass] { $$ = $pass; }
1403 | TryStatement[pass] { $$ = $pass; }
1404 | DebuggerStatement[pass] { $$ = $pass; }
1408 : LexOf Statement__[pass] { $$ = $pass; }
1409 | ExpressionStatement[pass] { $$ = $pass; }
1413 : LexSetStatement LexLet Statement_[pass] { $$ = $pass; }
1417 : HoistableDeclaration[pass] { $$ = $pass; }
1418 | ClassDeclaration[pass] { $$ = $pass; }
1422 : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; }
1423 | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; }
1426 HoistableDeclaration
1427 : FunctionDeclaration[pass] { $$ = $pass; }
1428 | GeneratorDeclaration[pass] { $$ = $pass; }
1432 : IterationStatement[pass] { $$ = $pass; }
1433 | SwitchStatement[pass] { $$ = $pass; }
1436 /* 13.2 Block {{{ */
1438 : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); }
1442 : "{" StatementListOpt[code] "}" { $$ = $code; }
1446 : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1450 : StatementList[pass] { $$ = $pass; }
1451 | LexSetStatement LexLet LexOf { $$ = NULL; }
1455 : Statement[pass] { $$ = $pass; }
1456 | Declaration[pass] { $$ = $pass; }
1459 /* 13.3 Let and Const Declarations {{{ */
1461 : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); }
1465 : LexicalDeclaration_[statement] Terminator { $$ = $statement; }
1469 : { CYMAP(_let__, _let_); }
1473 : { CYMAP(_of__, _of_); }
1477 : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); }
1481 : LexLet LexOf "!let" LexBind LexOf { $$ = false; }
1482 | LexLet LexOf "const" { $$ = true; }
1486 : "," LexBind BindingList[bindings] { $$ = $bindings; }
1491 : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); }
1495 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1496 | LexOf BindingPattern Initializer { CYNOT(@$); }
1499 /* 13.3.2 Variable Statement {{{ */
1501 : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); }
1505 : VariableStatement_[statement] Terminator { $$ = $statement; }
1508 VariableDeclarationList_
1509 : "," VariableDeclarationList[bindings] { $$ = $bindings; }
1513 VariableDeclarationList
1514 : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); }
1518 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1519 | LexOf BindingPattern Initializer { CYNOT(@$); }
1522 /* 13.3.3 Destructuring Binding Patterns {{{ */
1524 : ObjectBindingPattern
1525 | ArrayBindingPattern
1528 ObjectBindingPattern
1529 : "let {" BindingPropertyListOpt "}"
1533 : "let [" BindingElementListOpt "]"
1536 BindingPropertyList_
1537 : "," BindingPropertyListOpt
1542 : BindingProperty BindingPropertyList_
1545 BindingPropertyListOpt
1546 : BindingPropertyList
1551 : BindingElementOpt[element] "," BindingElementListOpt[next]
1552 | BindingRestElement[element]
1553 | BindingElement[element]
1556 BindingElementListOpt
1557 : BindingElementList[pass]
1563 | LexOf PropertyName ":" BindingElement
1567 : LexBind SingleNameBinding[pass] { $$ = $pass; }
1568 | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); }
1572 : BindingElement[pass]
1577 : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); }
1581 : LexBind LexOf "..." BindingIdentifier
1584 /* 13.4 Empty Statement {{{ */
1586 : ";" { $$ = CYNew CYEmpty(); }
1589 /* 13.5 Expression Statement {{{ */
1590 ExpressionStatement_
1591 : Expression[expression] { $$ = CYNew CYExpress($[expression]); }
1594 : ExpressionStatement_[statement] Terminator { $$ = $statement; }
1597 /* 13.6 The if Statement {{{ */
1599 : "else" Statement[false] { $$ = $false; }
1600 | %prec "if" { $$ = NULL; }
1604 : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); }
1607 /* 13.7 Iteration Statements {{{ */
1609 : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); }
1610 | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); }
1611 | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); }
1612 | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); }
1613 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); }
1614 | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
1617 ForStatementInitializer
1618 : LexLet LexOf EmptyStatement[pass] { $$ = $pass; }
1619 | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; }
1620 | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; }
1621 | LexicalDeclaration_[initializer] ";" { $$ = $initializer; }
1624 ForInStatementInitializer
1625 : LexLet LexOf BracedExpression[pass] { $$ = $pass; }
1626 | LexLet LexOf IndirectExpression[pass] { $$ = $pass; }
1627 | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); }
1628 | ForDeclaration[pass] { $$ = $pass; }
1632 : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); }
1636 : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); }
1637 | LexOf BindingPattern { CYNOT(@$); }
1640 /* 13.8 The continue Statement {{{ */
1642 : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1643 | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); }
1646 /* 13.9 The break Statement {{{ */
1648 : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1649 | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); }
1652 /* 13.10 The return Statement {{{ */
1654 : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1655 | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); }
1658 /* 13.11 The with Statement {{{ */
1660 : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); }
1663 /* 13.12 The switch Statement {{{ */
1665 : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); }
1669 : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; }
1673 : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); }
1677 : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1678 | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; }
1682 // XXX: the standard makes certain you can only have one of these
1684 : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); }
1687 /* 13.13 Labelled Statements {{{ */
1689 : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); }
1693 : Statement[pass] { $$ = $pass; }
1694 | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; }
1697 /* 13.14 The throw Statement {{{ */
1699 : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); }
1700 | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); }
1703 /* 13.15 The try Statement {{{ */
1705 : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); }
1706 | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); }
1707 | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); }
1711 : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); }
1715 : "finally" Block[code] { $$ = CYNew CYFinally($code); }
1719 : BindingIdentifier[pass] { $$ = $pass; }
1720 | LexOf BindingPattern { CYNOT(@$); }
1723 /* 13.16 The debugger Statement {{{ */
1725 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1729 /* 14.1 Function Definitions {{{ */
1731 : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); }
1735 : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); }
1738 StrictFormalParameters
1739 : FormalParameters[pass] { $$ = $pass; }
1743 : LexBind LexOf { $$ = NULL; }
1744 | FormalParameterList
1747 FormalParameterList_
1748 : "," FormalParameterList[parameters] { $$ = $parameters; }
1753 : FunctionRestParameter { CYNOT(@$); }
1754 | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); }
1757 FunctionRestParameter
1758 : BindingRestElement
1762 : BindingElement[pass] { $$ = $pass; }
1766 : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; }
1769 FunctionStatementList
1770 : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; }
1773 /* 14.2 Arrow Function Definitions {{{ */
1775 : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); }
1779 : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); }
1780 | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } }
1784 : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); }
1785 | LexOf ";{" FunctionBody[code] "}" { $$ = $code; }
1788 /* 14.3 Method Definitions {{{ */
1790 : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); }
1791 | GeneratorMethod[pass] { $$ = $pass; }
1792 | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); }
1793 | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); }
1796 PropertySetParameterList
1797 : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); }
1800 /* 14.4 Generator Function Definitions {{{ */
1802 : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ }
1805 GeneratorDeclaration
1806 : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ }
1810 : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ }
1814 : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; }
1818 : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1819 | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } %prec "!yield"
1820 | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ }
1821 | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ }
1824 /* 14.5 Class Definitions {{{ */
1826 : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); }
1830 : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); }
1834 : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; }
1838 : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); }
1842 : ClassHeritage[pass] { $$ = $pass; }
1843 | { $$ = CYNew CYClassTail(NULL); }
1856 : ClassElementListOpt ClassElement
1865 : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; }
1866 | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; }
1871 /* 15.1 Scripts {{{ */
1873 : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1877 : StatementList[pass] { $$ = $pass; }
1881 : ScriptBody[pass] { $$ = $pass; }
1882 | LexSetStatement LexLet LexOf { $$ = NULL; }
1885 /* 15.2 Modules {{{ */
1887 : ModuleBodyOpt[code] { driver.script_ = CYNew CYScript($code); }
1891 : ModuleItemList[pass] { $$ = $pass; }
1895 : ModuleBody[pass] { $$ = $pass; }
1896 | LexSetStatement LexLet LexOf { $$ = NULL; }
1900 : ModuleItem[statement] ModuleItemListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
1904 : ModuleItemList[pass] { $$ = $pass; }
1905 | LexSetStatement LexLet LexOf { $$ = NULL; }
1909 : LexSetStatement LexLet LexOf ImportDeclaration[pass] { $$ = $pass; }
1910 | LexSetStatement LexLet LexOf ExportDeclaration { CYNOT(@$); }
1911 | StatementListItem[pass] { $$ = $pass; }
1914 /* 15.2.2 Imports {{{ */
1916 : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); }
1917 | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); }
1921 : ImportedDefaultBinding[default] { $$ = $default; }
1922 | LexOf NameSpaceImport[pass] { $$ = $pass; }
1923 | LexOf NamedImports[pass] { $$ = $pass; }
1924 | ImportedDefaultBinding[default] "," NameSpaceImport[next] { $$ = $default; CYSetLast($$) = $next; }
1925 | ImportedDefaultBinding[default] "," NamedImports[next] { $$ = $default; CYSetLast($$) = $next; }
1928 ImportedDefaultBinding
1929 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(CYNew CYIdentifier("default"), $binding); }
1933 : "*" "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(NULL, $binding); }
1937 : "{" ImportsListOpt[pass] "}" { $$ = $pass; }
1941 : "from" ModuleSpecifier[pass] { $$ = $pass; }
1945 : "," ImportsListOpt[pass] { $$ = $pass; }
1950 : ImportSpecifier[import] ImportsList_[next] { $$ = $import; CYSetLast($$) = $next; }
1954 : ImportsList[pass] { $$ = $pass; }
1955 | LexOf { $$ = NULL; }
1959 : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($binding, $binding); }
1960 | LexOf IdentifierName[name] "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($name, $binding); }
1964 : StringLiteral[pass] { $$ = $pass; }
1968 : BindingIdentifier[pass] { $$ = $pass; }
1971 /* 15.2.3 Exports {{{ */
1973 : "*" FromClause Terminator
1974 | ExportClause FromClause Terminator
1975 | ExportClause Terminator
1977 | "default" LexSetStatement LexOf HoistableDeclaration
1978 | "default" LexSetStatement LexOf ClassDeclaration
1979 | "default" LexSetStatement AssignmentExpression Terminator
1983 : "export" LexSetStatement LexLet LexOf ExportDeclaration_
1984 | "export" Declaration
1988 : ";{" ExportsListOpt "}"
1992 : "," ExportsListOpt
1997 : ExportSpecifier ExportsList_
2007 | IdentifierName "as" IdentifierName
2012 /* Cycript (C): Type Encoding {{{ */
2014 : IdentifierType[identifier] { $$ = CYNew CYTypedIdentifier(@identifier, $identifier); }
2015 | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2019 : { $$ = CYNew CYTypedIdentifier(@$); }
2023 : TypeSignifier[pass] { $$ = $pass; }
2024 | TypeSignifierNone[pass] { $$ = $pass; }
2041 ParameterModifierOpt
2047 : TypedParameterListOpt[formal] ")" ParameterModifierOpt { $$ = CYNew CYTypeFunctionWith($formal->variadic_, $formal->parameters_); }
2051 : SuffixedTypeOpt[typed] "[" RestrictOpt NumericLiteral[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); }
2052 | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameters[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); }
2053 | TypeSignifier[typed] "(" ParameterTail[modifier] { $$ = $typed; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2054 | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedIdentifier(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2058 : SuffixedType[pass] { $$ = $pass; }
2059 | TypeSignifierOpt[pass] { $$ = $pass; }
2063 : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
2067 : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); }
2068 | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); }
2071 TypeQualifierLeftOpt
2072 : TypeQualifierLeft[pass] { $$ = $pass; }
2077 : SuffixedType[pass] { $$ = $pass; }
2078 | PrefixedType[pass] { $$ = $pass; }
2079 | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
2080 | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
2081 | Restrict TypeQualifierRightOpt[typed] { $$ = $typed; }
2084 TypeQualifierRightOpt
2085 : TypeQualifierRight[pass] { $$ = $pass; }
2086 | TypeSignifierOpt[pass] { $$ = $pass; }
2090 : "int" { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2091 | "unsigned" IntegerTypeOpt[integral] { $$ = $integral->Unsigned(); if ($$ == NULL) CYERR(@1, "incompatible unsigned"); }
2092 | "signed" IntegerTypeOpt[integral] { $$ = $integral->Signed(); if ($$ == NULL) CYERR(@1, "incompatible signed"); }
2093 | "long" IntegerTypeOpt[integral] { $$ = $integral->Long(); if ($$ == NULL) CYERR(@1, "incompatible long"); }
2094 | "short" IntegerTypeOpt[integral] { $$ = $integral->Short(); if ($$ == NULL) CYERR(@1, "incompatible short"); }
2098 : IntegerType[pass] { $$ = $pass; }
2099 | { $$ = CYNew CYTypeIntegral(CYTypeNeutral); }
2103 : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $next); }
2108 : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); }
2109 | IntegerType[pass] { $$ = $pass; }
2110 | "char" { $$ = CYNew CYTypeCharacter(CYTypeNeutral); }
2111 | "signed" "char" { $$ = CYNew CYTypeCharacter(CYTypeSigned); }
2112 | "unsigned" "char" { $$ = CYNew CYTypeCharacter(CYTypeUnsigned); }
2113 | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference($name); }
2116 TypedIdentifierMaybe
2117 : TypeQualifierLeft[modifier] "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2118 | "void" TypeQualifierRight[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeVoid(); }
2119 | TypeQualifierLeftOpt[modifier] PrimitiveType[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2123 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; }
2127 : TypedIdentifierMaybe[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; }
2130 TypedIdentifierField
2131 : TypedIdentifierYes[pass] { $$ = $pass; }
2132 | TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2135 TypedIdentifierEncoding
2136 : TypedIdentifierNo[pass] { $$ = $pass; }
2137 | TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2140 TypedIdentifierDefinition
2141 : TypedIdentifierYes[pass] { $$ = $pass; }
2142 | TypeQualifierLeftOpt[modifier] "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->identifier_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct($name, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; }
2146 : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); }
2152 /* Cycript (Objective-C): @class Declaration {{{ */
2154 /* XXX: why the hell did I choose MemberExpression? */
2155 : ":" MemberExpression[extends] { $$ = $extends; }
2159 ImplementationFieldListOpt
2160 : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $next); }
2165 : "+" { $$ = false; }
2166 | "-" { $$ = true; }
2170 : "(" TypedIdentifierNo[type] ")" { $$ = $type; }
2171 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
2175 : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $type->identifier_ = $identifier; $$ = CYNew CYMessageParameter($tag, $type); }
2178 MessageParameterList
2179 : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; }
2182 MessageParameterListOpt
2183 : MessageParameterList[pass] { $$ = $pass; }
2184 | TypedParameterList_[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); /*XXX*/ if ($formal->parameters_ != NULL) CYERR(@$, "temporarily unsupported"); $$ = NULL; }
2188 : MessageParameterList[pass] { $$ = $pass; }
2189 | Word[tag] { $$ = CYNew CYMessageParameter($tag, NULL); }
2192 ClassMessageDeclaration
2193 : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); }
2196 ClassMessageDeclarationListOpt
2197 : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; }
2201 // XXX: this should be AssignmentExpressionNoRight
2203 : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); }
2207 : "," ClassProtocols[protocols] { $$ = $protocols; }
2211 ClassProtocolListOpt
2212 : "<" ClassProtocols[protocols] ">" { $$ = $protocols; }
2216 ImplementationStatement
2217 : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); }
2225 : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); }
2229 : ImplementationStatement[pass] { $$ = $pass; }
2230 | CategoryStatement[pass] { $$ = $pass; }
2233 /* Cycript (Objective-C): Send Message {{{ */
2235 : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); }
2240 : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; }
2241 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
2245 : SelectorCall[pass] { $$ = $pass; }
2246 | VariadicCall[pass] { $$ = $pass; }
2250 : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); }
2254 : SelectorCall[pass] { $$ = $pass; }
2255 | Word[name] { $$ = CYNew CYArgument($name, NULL); }
2259 : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); }
2260 | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); }
2264 : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); }
2268 : SelectorExpression_[pass] { $$ = $pass; }
2269 | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); }
2272 SelectorExpressionOpt
2273 : SelectorExpression_[pass] { $$ = $pass; }
2278 : MessageExpression[pass] { $$ = $pass; }
2279 | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); }
2284 /* Cycript: @import Directive {{{ */
2286 : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); }
2287 | Word[part] { $$ = CYNew CYModule($part); }
2291 : "@import" ModulePath[path] { $$ = CYNew CYImport($path); }
2296 /* Cycript (Objective-C): Boxed Expressions {{{ */
2298 : NullLiteral[pass] { $$ = $pass; }
2299 | BooleanLiteral[pass] { $$ = $pass; }
2300 | NumericLiteral[pass] { $$ = $pass; }
2301 | StringLiteral[pass] { $$ = $pass; }
2302 | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; }
2303 | "YES" { $$ = CYNew CYTrue(); }
2304 | "NO" { $$ = CYNew CYFalse(); }
2308 : "," KeyValuePairListOpt[next] { $$ = $next; }
2312 : AssignmentExpression[key] ":" AssignmentExpression[value] KeyValuePairList_[next] { $$ = CYNew CYObjCKeyValue($key, $value, $next); }
2316 : KeyValuePairList[pass] { $$ = $pass; }
2317 | LexOf { $$ = NULL; }
2321 : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); }
2322 | "@" "[" ElementListOpt[elements] "]" { $$ = CYNew CYObjCArray($elements); }
2323 | "@" "{" KeyValuePairListOpt[pairs] "}" { $$ = CYNew CYObjCDictionary($pairs); }
2325 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2326 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2327 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2328 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2329 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2332 /* Cycript (Objective-C): Block Expressions {{{ */
2334 : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); }
2337 /* Cycript (Objective-C): Instance Literals {{{ */
2339 : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); }
2345 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2347 : IndirectExpression[pass] { $$ = $pass; }
2351 : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); }
2355 : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); }
2359 : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); }
2360 | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); }
2361 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2364 /* Cycript (C): Lambda Expressions {{{ */
2366 : "," TypedParameterList[parameters] { $$ = $parameters; }
2367 | { $$ = CYNew CYTypedFormal(false); }
2371 : TypedIdentifierMaybe[typed] TypedParameterList_[formal] { $$ = $formal; $$->parameters_ = CYNew CYTypedParameter($typed, $$->parameters_); }
2372 | "..." { $$ = CYNew CYTypedFormal(true); }
2375 TypedParameterListOpt
2376 : TypedParameterList[pass] { $$ = $pass; }
2377 | "void" { $$ = CYNew CYTypedFormal(false); }
2378 | { $$ = CYNew CYTypedFormal(false); }
2382 : TypedParameterListOpt[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); $$ = $formal->parameters_; }
2386 : "[" LexOf "&" "]" "(" TypedParameters[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); }
2389 /* Cycript (C): Structure Definitions {{{ */
2391 : "struct" NewLineOpt { $$ = CYNew CYIdentifier("struct"); }
2395 : "struct" NewLineNot IdentifierType[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYStructDefinition($name, CYNew CYStructTail($fields)); }
2399 : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference($name); $$ = CYNew CYTypeExpression($typed); }
2402 /* Cycript (C): Type Definitions {{{ */
2404 : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); }
2408 : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { $$ = CYNew CYTypeDefinition($typed); }
2412 : TypeDefinition[pass] { $$ = $pass; }
2416 : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); }
2419 /* Cycript (C): extern "C" {{{ */
2421 : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); }
2425 : TypedIdentifierField[typed] TerminatorHard { $$ = CYNew CYExternal(CYNew CYString("C"), $typed); }
2426 | TypeDefinition[pass] { $$ = $pass; }
2429 ExternCStatementListOpt
2430 : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; }
2435 : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; }
2436 | ExternCStatement[pass] { $$ = $pass; }
2440 : "extern" NewLineNot StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } ExternC[pass] { $$ = $pass; }
2446 /* Lexer State {{{ */
2448 : { driver.PushCondition(CYDriver::RegExpCondition); }
2452 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2456 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2460 : { driver.PopCondition(); }
2464 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2468 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2471 /* Virtual Tokens {{{ */
2478 /* 8.1 Context Keywords {{{ */
2480 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2481 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2484 /* 8.3 XML Initializer Input Elements {{{ */
2486 : XMLComment { $$ = $1; }
2487 | XMLCDATA { $$ = $1; }
2488 | XMLPI { $$ = $1; }
2492 /* 11.1 Primary Expressions {{{ */
2494 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2495 | XMLInitilizer { $$ = $1; }
2496 | XMLListInitilizer { $$ = $1; }
2500 : AttributeIdentifier { $$ = $1; }
2501 | QualifiedIdentifier { $$ = $1; }
2502 | WildcardIdentifier { $$ = $1; }
2505 /* 11.1.1 Attribute Identifiers {{{ */
2507 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2511 : PropertySelector { $$ = $1; }
2512 | "[" Expression "]" { $$ = CYNew CYSelector($2); }
2516 : Identifier { $$ = CYNew CYSelector($1); }
2517 | WildcardIdentifier { $$ = $1; }
2520 /* 11.1.2 Qualified Identifiers {{{ */
2521 QualifiedIdentifier_
2522 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2523 | QualifiedIdentifier { $$ = $1; }
2527 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2530 /* 11.1.3 Wildcard Identifiers {{{ */
2532 : "*" { $$ = CYNew CYWildcard(); }
2535 /* 11.1.4 XML Initializer {{{ */
2537 : XMLMarkup { $$ = $1; }
2538 | XMLElement { $$ = $1; }
2542 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2543 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2547 : LexPushXMLTag XMLTagName XMLAttributes
2551 : "{" LexPushRegExp Expression LexPop "}"
2560 : XMLAttributes_ XMLAttribute
2565 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2566 | XMLAttributes_ XMLWhitespaceOpt
2575 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2579 : XMLExpression XMLElementContentOpt
2580 | XMLMarkup XMLElementContentOpt
2581 | XMLText XMLElementContentOpt
2582 | XMLElement XMLElementContentOpt
2585 XMLElementContentOpt
2590 /* 11.1.5 XMLList Initializer {{{ */
2592 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2596 /* 11.2 Left-Hand-Side Expressions {{{ */
2598 : Identifier { $$ = $1; }
2599 | PropertyIdentifier { $$ = $1; }
2603 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2604 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2605 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2608 /* 12.1 The default xml namespace Statement {{{ */
2609 /* XXX: DefaultXMLNamespaceStatement
2610 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2614 : DefaultXMLNamespaceStatement { $$ = $1; }
2619 /* JavaScript FTL: Array Comprehensions {{{ */
2621 : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2625 : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2628 /* JavaScript FTL: for each {{{ */
2630 : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); }
2634 /* JavaScript FTW: Array Comprehensions {{{ */
2636 : ArrayComprehension
2640 : "[" Comprehension[comprehension] "]" { $$ = $comprehension; }
2644 : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); }
2649 | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2650 | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; }
2654 : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); }
2655 | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); }
2659 : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); }
2662 /* JavaScript FTW: Named Arguments {{{ */
2664 : LexOf WordNoUnary[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); }
2667 /* JavaScript FTW: Subscript Access {{{ */
2669 : "." "[" AssignmentExpression[property] "]" { $$ = CYNew CYSubscriptMember(NULL, $property); }
2673 /* JavaScript FTW: Java "Anonymous Inner Classes" {{{ */
2675 : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYExtend(NULL, $properties); }
2679 /* JavaScript FTW: Ruby Blocks {{{ */
2680 RubyProcParameterList_
2681 : "," RubyProcParameterList[parameters] { $$ = $parameters; }
2685 RubyProcParameterList
2686 : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); }
2687 | LexOf { $$ = NULL; }
2691 : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; }
2692 | "||" { $$ = NULL; }
2695 RubyProcParametersOpt
2696 : RubyProcParameters[pass] { $$ = $pass; }
2701 : ";{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyBlock(NULL, CYNew CYRubyProc($parameters, $code)); }
2705 : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); }
2709 : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; }
2710 | BracedExpression_[lhs] { if (!$lhs->IsNew()) CYMAP(OpenBrace_, OpenBrace); } BracedParameter[rhs] LexNewLineOrOpt { $rhs->SetLeft($lhs); $$ = $rhs; }
2714 : BracedExpression_[pass] "\n" { $$ = $pass; }
2715 | BracedExpression_[pass] { $$ = $pass; }
2718 /* JavaScript FTW: Ruby Scopes {{{ */
2720 : "::" "[" Expression[property] "]" { $$ = CYNew CYResolveMember(NULL, $property); }
2721 | "::" IdentifierName[property] { $$ = CYNew CYResolveMember(NULL, CYNew CYString($property)); }
2722 | "::" AutoComplete { driver.mode_ = CYDriver::AutoResolve; YYACCEPT; }
2725 /* JavaScript FTW: Ruby Symbols {{{ */
2727 : ":" Word[name] { $$ = CYNew CYSymbol($name->Word()); }
2733 bool CYDriver::Parse(CYMark mark) {
2735 CYLocal<CYPool> local(&pool_);
2736 cy::parser parser(*this);
2738 parser.set_debug_level(debug_);
2740 return parser.parse() != 0;
2743 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2747 CYDriver::Error error;
2748 error.warning_ = true;
2749 error.location_ = location;
2750 error.message_ = message;
2751 errors_.push_back(error);
2754 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2755 CYDriver::Error error;
2756 error.warning_ = false;
2757 error.location_ = location;
2758 error.message_ = message;
2759 driver.errors_.push_back(error);