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 { CYArgument *argument_; }
46 %union { CYAssignment *assignment_; }
47 %union { CYBoolean *boolean_; }
48 %union { CYClause *clause_; }
49 %union { cy::Syntax::Catch *catch_; }
50 %union { CYComprehension *comprehension_; }
51 %union { CYDeclaration *declaration_; }
52 %union { CYDeclarations *declarations_; }
53 %union { CYElement *element_; }
54 %union { CYExpression *expression_; }
55 %union { CYFalse *false_; }
56 %union { CYVariable *variable_; }
57 %union { CYFinally *finally_; }
58 %union { CYForInitializer *for_; }
59 %union { CYForInInitializer *forin_; }
60 %union { CYFunctionParameter *functionParameter_; }
61 %union { CYIdentifier *identifier_; }
62 %union { CYInfix *infix_; }
63 %union { CYLiteral *literal_; }
64 %union { CYMember *member_; }
65 %union { CYModule *module_; }
66 %union { CYNull *null_; }
67 %union { CYNumber *number_; }
68 %union { CYParenthetical *parenthetical_; }
69 %union { CYProperty *property_; }
70 %union { CYPropertyName *propertyName_; }
71 %union { CYRubyProc *rubyProc_; }
72 %union { CYSpan *span_; }
73 %union { CYStatement *statement_; }
74 %union { CYString *string_; }
75 %union { CYThis *this_; }
76 %union { CYTrue *true_; }
77 %union { CYWord *word_; }
80 %union { CYTypeModifier *modifier_; }
81 %union { CYTypeSpecifier *specifier_; }
82 %union { CYTypedIdentifier *typedIdentifier_; }
83 %union { CYTypedParameter *typedParameter_; }
87 %union { CYClassName *className_; }
88 %union { CYClassField *classField_; }
89 %union { CYMessage *message_; }
90 %union { CYMessageParameter *messageParameter_; }
91 %union { CYProtocol *protocol_; }
92 %union { CYSelectorPart *selector_; }
96 %union { CYAttribute *attribute_; }
97 %union { CYPropertyIdentifier *propertyIdentifier_; }
98 %union { CYSelector *selector_; }
104 cy::parser::semantic_type semantic_;
105 hi::Value highlight_;
108 int cylex(YYSTYPE *, CYLocation *, void *);
115 _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
116 if (driver.mark_ == CYMarkIgnore);
117 else if (driver.mark_ == CYMarkScript) {
118 driver.mark_ = CYMarkIgnore;
119 return cy::parser::token::MarkScript;
120 } else if (driver.mark_ == CYMarkModule) {
121 driver.mark_ = CYMarkIgnore;
122 return cy::parser::token::MarkModule;
126 int token(cylex(&data, location, driver.scanner_));
127 *semantic = data.semantic_;
131 #define CYMAP(to, from) do { \
133 yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \
134 if (yyla.type == yytranslate_(token::from)) \
135 yyla.type = yytranslate_(token::to); \
138 #define CYERR(location, message) do { \
139 error(location, message); \
143 #define CYNOT(location) \
144 CYERR(location, "unimplemented feature")
153 @$.begin.filename = @$.end.filename = &driver.filename_;
159 %define api.location.type { CYLocation }
166 %param { CYDriver &driver }
168 /* Token Declarations {{{ */
174 %token XMLAttributeValue
176 %token XMLTagCharacters
182 %token LeftRight "<>"
183 %token LeftSlashRight "</>"
185 %token SlashRight "/>"
186 %token LeftSlash "</"
188 %token ColonColon "::"
189 %token PeriodPeriod ".."
192 @begin E4X ObjectiveC
198 %token AmpersandAmpersand "&&"
199 %token AmpersandEqual "&="
201 %token CarrotEqual "^="
203 %token EqualEqual "=="
204 %token EqualEqualEqual "==="
205 %token EqualRight "=>"
206 %token EqualRight_ "\n=>"
207 %token Exclamation "!"
208 %token ExclamationEqual "!="
209 %token ExclamationEqualEqual "!=="
211 %token HyphenEqual "-="
212 %token HyphenHyphen "--"
213 %token HyphenHyphen_ "\n--"
214 %token HyphenRight "->"
216 %token LeftEqual "<="
218 %token LeftLeftEqual "<<="
220 %token PercentEqual "%="
222 %token PeriodPeriodPeriod "..."
224 %token PipeEqual "|="
227 %token PlusEqual "+="
229 %token PlusPlus_ "\n++"
231 %token RightEqual ">="
232 %token RightRight ">>"
233 %token RightRightEqual ">>="
234 %token RightRightRight ">>>"
235 %token RightRightRightEqual ">>>="
237 %token SlashEqual "/="
239 %token StarEqual "*="
251 %token CloseParen ")"
254 %token OpenBrace_ "\n{"
255 %token OpenBrace__ ";{"
256 %token CloseBrace "}"
258 %token OpenBracket "["
259 %token CloseBracket "]"
261 %token At_error_ "@error"
264 %token At_class_ "@class"
268 %token _typedef_ "typedef"
269 %token _unsigned_ "unsigned"
270 %token _signed_ "signed"
271 %token _extern_ "extern"
275 %token At_encode_ "@encode"
279 %token At_implementation_ "@implementation"
280 %token At_import_ "@import"
281 %token At_end_ "@end"
282 %token At_selector_ "@selector"
283 %token At_null_ "@null"
284 %token At_YES_ "@YES"
286 %token At_true_ "@true"
287 %token At_false_ "@false"
292 %token _false_ "false"
296 %token _break_ "break"
298 %token _catch_ "catch"
299 %token _class_ "class"
300 %token _class__ ";class"
301 %token _const_ "const"
302 %token _continue_ "continue"
303 %token _debugger_ "debugger"
304 %token _default_ "default"
305 %token _delete_ "delete"
309 %token _export_ "export"
310 %token _extends_ "extends"
311 %token _finally_ "finally"
313 %token _function_ "function"
314 %token _function__ ";function"
316 %token _import_ "import"
319 %token _instanceof_ "instanceof"
321 %token _return_ "return"
322 %token _return__ "!return"
323 %token _super_ "super"
324 %token _switch_ "switch"
326 %token _throw_ "throw"
328 %token _typeof_ "typeof"
331 %token _while_ "while"
334 %token _abstract_ "abstract"
335 %token _await_ "await"
336 %token _boolean_ "boolean"
339 %token _double_ "double"
340 %token _final_ "final"
341 %token _float_ "float"
345 %token _implements_ "implements"
347 %token _interface_ "interface"
350 %token _native_ "native"
351 %token _package_ "package"
352 %token _private_ "private"
353 %token _protected_ "protected"
354 %token _public_ "public"
356 %token _short_ "short"
357 %token _static_ "static"
358 %token _synchronized_ "synchronized"
359 %token _throws_ "throws"
360 %token _transient_ "transient"
361 %token _volatile_ "volatile"
362 %token _yield_ "yield"
363 %token _yield__ "!yield"
365 %token _undefined_ "undefined"
381 %token _namespace_ "namespace"
388 %token <identifier_> Identifier_
389 %token <number_> NumericLiteral
390 %token <string_> StringLiteral
391 %token <literal_> RegularExpressionLiteral
393 %token <string_> NoSubstitutionTemplate
394 %token <string_> TemplateHead
395 %token <string_> TemplateMiddle
396 %token <string_> TemplateTail
398 %type <expression_> AdditiveExpression
399 %type <argument_> ArgumentList_
400 %type <argument_> ArgumentList
401 %type <argument_> ArgumentListOpt
402 %type <argument_> Arguments
403 %type <expression_> ArrayComprehension
404 %type <literal_> ArrayLiteral
405 %type <expression_> ArrowFunction
406 %type <functionParameter_> ArrowParameters
407 %type <expression_> AssignmentExpression
408 %type <expression_> AssignmentExpressionOpt
409 %type <identifier_> Binding
410 %type <identifier_> BindingIdentifier
411 %type <identifier_> BindingIdentifierOpt
412 %type <expression_> BitwiseANDExpression
413 %type <statement_> Block
414 %type <statement_> BlockStatement
415 %type <boolean_> BooleanLiteral
416 %type <declaration_> BindingElement
417 %type <expression_> BitwiseORExpression
418 %type <expression_> BitwiseXORExpression
419 %type <statement_> BreakStatement
420 %type <statement_> BreakableStatement
421 %type <expression_> CallExpression_
422 %type <expression_> CallExpression
423 %type <clause_> CaseBlock
424 %type <clause_> CaseClause
425 %type <clause_> CaseClausesOpt
427 %type <identifier_> CatchParameter
428 %type <statement_> ClassDeclaration
429 %type <expression_> ClassExpression
430 %type <expression_> Comprehension
431 %type <comprehension_> ComprehensionFor
432 %type <comprehension_> ComprehensionIf
433 %type <comprehension_> ComprehensionTail
434 %type <expression_> ComputedPropertyName
435 %type <expression_> ConditionalExpression
436 %type <statement_> ContinueStatement
437 %type <statement_> ConciseBody
438 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
439 %type <statement_> DebuggerStatement
440 %type <statement_> Declaration__
441 %type <statement_> Declaration_
442 %type <statement_> Declaration
443 %type <clause_> DefaultClause
444 %type <element_> ElementList
445 %type <element_> ElementListOpt
446 %type <statement_> ElseStatementOpt
447 %type <statement_> EmptyStatement
448 %type <expression_> EqualityExpression
449 %type <expression_> Expression
450 %type <expression_> ExpressionOpt
451 %type <statement_> ExpressionStatement
452 %type <finally_> Finally
453 %type <for_> ForStatementInitializer
454 %type <forin_> ForInStatementInitializer
455 %type <declaration_> FormalParameter
456 %type <functionParameter_> FormalParameterList_
457 %type <functionParameter_> FormalParameterList
458 %type <functionParameter_> FormalParameters
459 %type <statement_> FunctionBody
460 %type <statement_> FunctionDeclaration
461 %type <expression_> FunctionExpression
462 %type <statement_> FunctionStatementList
463 %type <statement_> GeneratorBody
464 %type <statement_> GeneratorDeclaration
465 %type <expression_> GeneratorExpression
466 %type <property_> GeneratorMethod
467 %type <statement_> HoistableDeclaration
468 %type <identifier_> Identifier
469 %type <identifier_> IdentifierType
470 %type <word_> IdentifierName
471 %type <variable_> IdentifierReference
472 %type <statement_> IfStatement
473 %type <expression_> Initializer
474 %type <expression_> InitializerOpt
475 %type <statement_> IterationStatement
476 %type <identifier_> LabelIdentifier
477 %type <statement_> LabelledItem
478 %type <statement_> LabelledStatement
479 %type <expression_> LeftHandSideExpression
480 %type <statement_> LetStatement
481 %type <statement_> LexicalDeclaration
482 %type <literal_> Literal
483 %type <propertyName_> LiteralPropertyName
484 %type <expression_> LogicalANDExpression
485 %type <expression_> LogicalORExpression
486 %type <member_> MemberAccess
487 %type <expression_> MemberExpression
488 %type <property_> MethodDefinition
489 %type <module_> ModulePath
490 %type <expression_> MultiplicativeExpression
491 %type <expression_> NewExpression
492 %type <null_> NullLiteral
493 %type <literal_> ObjectLiteral
494 %type <expression_> PostfixExpression
495 %type <expression_> PrimaryExpression
496 %type <propertyName_> PropertyName
497 %type <property_> PropertyDefinition
498 %type <property_> PropertyDefinitionList_
499 %type <property_> PropertyDefinitionList
500 %type <property_> PropertyDefinitionListOpt
501 %type <declaration_> PropertySetParameterList
502 %type <expression_> RelationalExpression
503 %type <statement_> ReturnStatement
504 %type <rubyProc_> RubyProcExpression
505 %type <functionParameter_> RubyProcParameterList_
506 %type <functionParameter_> RubyProcParameterList
507 %type <functionParameter_> RubyProcParameters
508 %type <functionParameter_> RubyProcParametersOpt
509 %type <statement_> Script
510 %type <statement_> ScriptBody
511 %type <statement_> ScriptBodyOpt
512 %type <expression_> ShiftExpression
513 %type <declaration_> SingleNameBinding
514 %type <statement_> Statement__
515 %type <statement_> Statement_
516 %type <statement_> Statement
517 %type <statement_> StatementList
518 %type <statement_> StatementListOpt
519 %type <statement_> StatementListItem
520 %type <functionParameter_> StrictFormalParameters
521 %type <statement_> SwitchStatement
522 %type <expression_> TemplateLiteral
523 %type <span_> TemplateSpans
524 %type <statement_> ThrowStatement
525 %type <statement_> TryStatement
526 %type <expression_> UnaryExpression_
527 %type <expression_> UnaryExpression
528 %type <declaration_> VariableDeclaration
529 %type <declarations_> VariableDeclarationList_
530 %type <declarations_> VariableDeclarationList
531 %type <statement_> VariableStatement
532 %type <statement_> WithStatement
535 %type <word_> WordOpt
537 %type <expression_> YieldExpression
540 %type <specifier_> IntegerType
541 %type <specifier_> IntegerTypeOpt
542 %type <typedIdentifier_> PrefixedType
543 %type <specifier_> PrimitiveType
544 %type <typedIdentifier_> SuffixedType
545 %type <typedIdentifier_> TypeSignifier
546 %type <modifier_> TypeQualifierLeft
547 %type <typedIdentifier_> TypeQualifierRight
548 %type <typedIdentifier_> TypedIdentifier
549 %type <typedParameter_> TypedParameterList_
550 %type <typedParameter_> TypedParameterList
551 %type <typedParameter_> TypedParameterListOpt
555 %type <expression_> BoxableExpression
556 %type <statement_> CategoryStatement
557 %type <classField_> ClassFieldListOpt
558 %type <classField_> ClassFields
559 %type <statement_> ClassStatement
560 %type <expression_> ClassSuperOpt
561 %type <message_> ClassMessageDeclaration
562 %type <message_> ClassMessageDeclarationListOpt
563 %type <className_> ClassName
564 %type <protocol_> ClassProtocolListOpt
565 %type <protocol_> ClassProtocols
566 %type <protocol_> ClassProtocolsOpt
567 %type <expression_> MessageExpression
568 %type <messageParameter_> MessageParameter
569 %type <messageParameter_> MessageParameters
570 %type <messageParameter_> MessageParameterList
571 %type <messageParameter_> MessageParameterListOpt
572 %type <bool_> MessageScope
573 %type <argument_> SelectorCall_
574 %type <argument_> SelectorCall
575 %type <selector_> SelectorExpression_
576 %type <selector_> SelectorExpression
577 %type <selector_> SelectorExpressionOpt
578 %type <argument_> SelectorList
579 %type <word_> SelectorWordOpt
580 %type <typedIdentifier_> TypeOpt
581 %type <argument_> VariadicCall
585 %type <propertyIdentifier_> PropertyIdentifier_
586 %type <selector_> PropertySelector_
587 %type <selector_> PropertySelector
588 %type <identifier_> QualifiedIdentifier_
589 %type <identifier_> QualifiedIdentifier
590 %type <identifier_> WildcardIdentifier
591 %type <identifier_> XMLComment
592 %type <identifier_> XMLCDATA
593 %type <identifier_> XMLElement
594 %type <identifier_> XMLElementContent
595 %type <identifier_> XMLMarkup
596 %type <identifier_> XMLPI
598 %type <attribute_> AttributeIdentifier
599 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
600 %type <expression_> PropertyIdentifier
601 %type <expression_> XMLListInitialiser
602 %type <expression_> XMLInitialiser
605 /* Token Priorities {{{ */
624 /* Lexer State {{{ */
625 LexPushInOn: { driver.in_.push(true); };
626 LexPushInOff: { driver.in_.push(false); };
627 LexPopIn: { driver.in_.pop(); };
629 LexPushReturnOn: { driver.return_.push(true); };
630 LexPopReturn: { driver.return_.pop(); };
632 LexPushYieldOn: { driver.yield_.push(true); };
633 LexPushYieldOff: { driver.yield_.push(false); };
634 LexPopYield: { driver.yield_.pop(); };
637 : { driver.SetCondition(CYDriver::RegExpCondition); }
641 : { if (!yyla.empty() && yyla.type_get() != yyeof_) CYERR(@$, "unexpected lookahead"); driver.next_ = true; }
645 : { CYMAP(YieldStar, Star); }
649 : { CYMAP(OpenBrace__, OpenBrace); CYMAP(OpenBrace__, OpenBrace_); }
653 : { CYMAP(_class__, _class_); }
657 : { CYMAP(_function__, _function_); }
661 : LexNoBrace LexNoClass LexNoFunction
664 /* Virtual Tokens {{{ */
675 /* 11.6 Names and Keywords {{{ */
678 | "for" { $$ = CYNew CYWord("for"); }
679 | "in" { $$ = CYNew CYWord("in"); }
680 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
689 : Identifier { $$ = $1; }
690 | "auto" { $$ = CYNew CYWord("auto"); }
691 | "break" { $$ = CYNew CYWord("break"); }
692 | "case" { $$ = CYNew CYWord("case"); }
693 | "catch" { $$ = CYNew CYWord("catch"); }
694 | "class" { $$ = CYNew CYWord("class"); }
695 | ";class" { $$ = CYNew CYWord("class"); }
696 | "const" { $$ = CYNew CYWord("const"); }
697 | "continue" { $$ = CYNew CYWord("continue"); }
698 | "debugger" { $$ = CYNew CYWord("debugger"); }
699 | "default" { $$ = CYNew CYWord("default"); }
700 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
701 | "do" { $$ = CYNew CYWord("do"); }
702 | "else" { $$ = CYNew CYWord("else"); }
703 | "enum" { $$ = CYNew CYWord("enum"); }
704 | "export" { $$ = CYNew CYWord("export"); }
705 | "extends" { $$ = CYNew CYWord("extends"); }
706 | "false" { $$ = CYNew CYWord("false"); }
707 | "finally" { $$ = CYNew CYWord("finally"); }
708 | "function" { $$ = CYNew CYWord("function"); }
709 | "if" { $$ = CYNew CYWord("if"); }
710 | "import" { $$ = CYNew CYWord("import"); }
711 | "!in" { $$ = CYNew CYWord("in"); }
712 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
713 | "null" { $$ = CYNew CYWord("null"); }
714 | "return" { $$ = CYNew CYWord("return"); }
715 | "!return" { $$ = CYNew CYWord("return"); }
716 | "super" { $$ = CYNew CYWord("super"); }
717 | "switch" { $$ = CYNew CYWord("switch"); }
718 | "this" { $$ = CYNew CYWord("this"); }
719 | "throw" { $$ = CYNew CYWord("throw"); }
720 | "true" { $$ = CYNew CYWord("true"); }
721 | "try" { $$ = CYNew CYWord("try"); }
722 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
723 | "var" { $$ = CYNew CYWord("var"); }
724 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
725 | "while" { $$ = CYNew CYWord("while"); }
726 | "with" { $$ = CYNew CYWord("with"); }
727 | "yield" { $$ = CYNew CYIdentifier("yield"); }
729 | Yield LexSetRegExp NewLineOpt { $$ = CYNew CYIdentifier("yield"); }
731 // XXX: should be Identifier
732 | "let" { $$ = CYNew CYIdentifier("let"); }
742 /* 11.8.1 Null Literals {{{ */
744 : "null" { $$ = CYNew CYNull(); }
747 /* 11.8.2 Boolean Literals {{{ */
749 : "true" { $$ = CYNew CYTrue(); }
750 | "false" { $$ = CYNew CYFalse(); }
754 /* 11.9 Automatic Semicolon Insertion {{{ */
756 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
766 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) { CYERR(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
771 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
775 /* 12.1 Identifiers {{{ */
777 : Identifier { $$ = CYNew CYVariable($1); }
778 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
782 : Identifier { $$ = $1; }
783 | "yield" { $$ = CYNew CYIdentifier("yield"); }
787 : BindingIdentifier { $$ = $1; }
792 : Identifier { $$ = $1; }
793 | "yield" { $$ = CYNew CYIdentifier("yield"); }
797 : Identifier_ { $$ = $1; }
798 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
799 | "await" { $$ = CYNew CYIdentifier("await"); }
800 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
801 | "byte" { $$ = CYNew CYIdentifier("byte"); }
802 | "double" { $$ = CYNew CYIdentifier("double"); }
803 | "each" { $$ = CYNew CYIdentifier("each"); }
804 | "final" { $$ = CYNew CYIdentifier("final"); }
805 | "float" { $$ = CYNew CYIdentifier("float"); }
806 | "goto" { $$ = CYNew CYIdentifier("goto"); }
807 | "implements" { $$ = CYNew CYIdentifier("implements"); }
808 | "interface" { $$ = CYNew CYIdentifier("interface"); }
809 | "native" { $$ = CYNew CYIdentifier("native"); }
810 | "of" { $$ = CYNew CYIdentifier("of"); }
811 | "package" { $$ = CYNew CYIdentifier("package"); }
812 | "private" { $$ = CYNew CYIdentifier("private"); }
813 | "protected" { $$ = CYNew CYIdentifier("protected"); }
814 | "public" { $$ = CYNew CYIdentifier("public"); }
815 | "static" { $$ = CYNew CYIdentifier("static"); }
816 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
817 | "throws" { $$ = CYNew CYIdentifier("throws"); }
818 | "transient" { $$ = CYNew CYIdentifier("transient"); }
820 | "bool" { $$ = CYNew CYIdentifier("bool"); }
821 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
822 | "id" { $$ = CYNew CYIdentifier("id"); }
823 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
829 | "char" { $$ = CYNew CYIdentifier("char"); }
830 | "from" { $$ = CYNew CYIdentifier("from"); }
831 | "get" { $$ = CYNew CYIdentifier("get"); }
832 | "int" { $$ = CYNew CYIdentifier("int"); }
833 | "long" { $$ = CYNew CYIdentifier("long"); }
834 | "set" { $$ = CYNew CYIdentifier("set"); }
835 | "short" { $$ = CYNew CYIdentifier("short"); }
836 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
837 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
839 | "extern" { $$ = CYNew CYIdentifier("extern"); }
840 | "signed" { $$ = CYNew CYIdentifier("signed"); }
841 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
842 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
845 | "nil" { $$ = CYNew CYIdentifier("nil"); }
846 | "NO" { $$ = CYNew CYIdentifier("NO"); }
847 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
848 | "YES" { $$ = CYNew CYIdentifier("YES"); }
852 /* 12.2 Primary Expression {{{ */
854 : "this" { $$ = CYNew CYThis(); }
855 | IdentifierReference { $$ = $1; }
856 | Literal { $$ = $1; }
857 | ArrayLiteral { $$ = $1; }
858 | ObjectLiteral { $$ = $1; }
859 | FunctionExpression { $$ = $1; }
860 | ClassExpression { $$ = $1; }
861 | GeneratorExpression { $$ = $1; }
862 | RegularExpressionLiteral { $$ = $1; }
863 | TemplateLiteral { $$ = $1; }
864 | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) CYERR(@1, "invalid parenthetical"); $$ = $1; }
865 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
868 CoverParenthesizedExpressionAndArrowParameterList
869 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
870 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
871 | "(" LexPushInOff LexSetRegExp "..." BindingIdentifier ")" LexPopIn { CYNOT(@$); }
872 | "(" LexPushInOff Expression "," LexSetRegExp "..." BindingIdentifier ")" LexPopIn { CYNOT(@$); }
875 /* 12.2.4 Literals {{{ */
877 : NullLiteral { $$ = $1; }
878 | BooleanLiteral { $$ = $1; }
879 | NumericLiteral { $$ = $1; }
880 | StringLiteral { $$ = $1; }
883 /* 12.2.5 Array Initializer {{{ */
885 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
889 : AssignmentExpressionOpt "," ElementListOpt { $$ = CYNew CYElementValue($1, $3); }
890 | LexSetRegExp "..." AssignmentExpression { $$ = CYNew CYElementSpread($3); }
891 | AssignmentExpression { $$ = CYNew CYElementValue($1, NULL); }
895 : ElementList { $$ = $1; }
896 | LexSetRegExp { $$ = NULL; }
899 /* 12.2.6 Object Initializer {{{ */
901 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
904 PropertyDefinitionList_
905 : "," PropertyDefinitionListOpt { $$ = $2; }
909 PropertyDefinitionList
910 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
913 PropertyDefinitionListOpt
914 : LexSetRegExp PropertyDefinitionList { $$ = $2; }
915 | LexSetRegExp { $$ = NULL; }
919 : IdentifierReference { $$ = CYNew CYProperty($1->name_, $1); }
920 | CoverInitializedName { CYNOT(@$); }
921 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
922 | MethodDefinition { $$ = $1; }
926 : LiteralPropertyName { $$ = $1; }
927 | ComputedPropertyName { CYNOT(@$); /* $$ = $1; */ }
931 : IdentifierName { $$ = $1; }
932 | StringLiteral { $$ = $1; }
933 | NumericLiteral { $$ = $1; }
937 : "[" AssignmentExpression "]" { $$ = $2; }
941 : IdentifierReference Initializer
945 : "=" AssignmentExpression { $$ = $2; }
949 : Initializer { $$ = $1; }
953 /* 12.2.9 Template Literals {{{ */
955 : NoSubstitutionTemplate { $$ = CYNew CYTemplate($1, NULL); }
956 | TemplateHead TemplateSpans { $$ = CYNew CYTemplate($1, $2); }
960 : Expression TemplateMiddle TemplateSpans { $$ = CYNew CYSpan($1, $2, $3); }
961 | Expression TemplateTail { $$ = CYNew CYSpan($1, $2, NULL); }
965 /* 12.3 Left-Hand-Side Expressions {{{ */
967 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
968 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
969 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
970 | TemplateLiteral { CYNOT(@$); }
974 : LexSetRegExp PrimaryExpression { $$ = $2; }
975 | MemberExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
976 | SuperProperty { CYNOT(@$); }
977 | MetaProperty { CYNOT(@$); }
978 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
982 : LexSetRegExp "super" "[" Expression "]"
983 | LexSetRegExp "super" "." IdentifierName
991 : LexSetRegExp "new" LexSetRegExp "." "target"
995 : MemberExpression { $$ = $1; }
996 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
1005 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
1006 | SuperCall { CYNOT(@$); }
1007 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
1011 : LexSetRegExp "super" Arguments
1015 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
1019 : "," ArgumentList { $$ = $2; }
1024 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
1025 | LexSetRegExp "..." AssignmentExpression { CYNOT(@$); }
1029 : ArgumentList { $$ = $1; }
1030 | LexSetRegExp { $$ = NULL; }
1033 LeftHandSideExpression
1034 : NewExpression { $$ = $1; }
1035 | CallExpression { $$ = $1; }
1038 /* 12.4 Postfix Expressions {{{ */
1040 : %prec "" LeftHandSideExpression { $$ = $1; }
1041 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
1042 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
1045 /* 12.5 Unary Operators {{{ */
1047 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
1048 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
1049 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
1050 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
1051 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
1052 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
1053 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
1054 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
1055 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
1056 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
1057 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
1061 : PostfixExpression { $$ = $1; }
1062 | LexSetRegExp UnaryExpression_ { $$ = $2; }
1065 /* 12.6 Multiplicative Operators {{{ */
1066 MultiplicativeExpression
1067 : UnaryExpression { $$ = $1; }
1068 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
1069 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
1070 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
1073 /* 12.7 Additive Operators {{{ */
1075 : MultiplicativeExpression { $$ = $1; }
1076 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
1077 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
1080 /* 12.8 Bitwise Shift Operators {{{ */
1082 : AdditiveExpression { $$ = $1; }
1083 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
1084 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
1085 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
1088 /* 12.9 Relational Operators {{{ */
1089 RelationalExpression
1090 : ShiftExpression { $$ = $1; }
1091 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
1092 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
1093 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
1094 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
1095 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
1096 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
1099 /* 12.10 Equality Operators {{{ */
1101 : RelationalExpression { $$ = $1; }
1102 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1103 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1104 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1105 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1108 /* 12.11 Binary Bitwise Operators {{{ */
1109 BitwiseANDExpression
1110 : EqualityExpression { $$ = $1; }
1111 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1114 BitwiseXORExpression
1115 : BitwiseANDExpression { $$ = $1; }
1116 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1120 : BitwiseXORExpression { $$ = $1; }
1121 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1124 /* 12.12 Binary Logical Operators {{{ */
1125 LogicalANDExpression
1126 : BitwiseORExpression { $$ = $1; }
1127 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1131 : LogicalANDExpression { $$ = $1; }
1132 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1135 /* 12.13 Conditional Operator ( ? : ) {{{ */
1136 ConditionalExpression
1137 : LogicalORExpression { $$ = $1; }
1138 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1141 /* 12.14 Assignment Operators {{{ */
1142 AssignmentExpression
1143 : ConditionalExpression { $$ = $1; }
1144 | LexSetRegExp YieldExpression { $$ = $2; }
1145 | ArrowFunction { $$ = $1; }
1146 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1147 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1148 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1149 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1150 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1151 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1152 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1153 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1154 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1155 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1156 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1157 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1160 AssignmentExpressionOpt
1161 : AssignmentExpression { $$ = $1; }
1162 | LexSetRegExp { $$ = NULL; }
1165 /* 12.15 Comma Operator ( , ) {{{ */
1167 : AssignmentExpression { $$ = $1; }
1168 | Expression "," AssignmentExpression { $$ = CYNew CYCompound($1, $3); }
1172 : Expression { $$ = $1; }
1173 | LexSetRegExp { $$ = NULL; }
1177 /* 13 Statements and Declarations {{{ */
1179 : BlockStatement { $$ = $1; }
1180 | VariableStatement { $$ = $1; }
1181 | EmptyStatement { $$ = $1; }
1182 | IfStatement { $$ = $1; }
1183 | BreakableStatement { $$ = $1; }
1184 | ContinueStatement { $$ = $1; }
1185 | BreakStatement { $$ = $1; }
1186 | ReturnStatement { $$ = $1; }
1187 | WithStatement { $$ = $1; }
1188 | LabelledStatement { $$ = $1; }
1189 | ThrowStatement { $$ = $1; }
1190 | TryStatement { $$ = $1; }
1191 | DebuggerStatement { $$ = $1; }
1195 : LexSetRegExp Statement__ { $$ = $2; }
1196 | ExpressionStatement { $$ = $1; }
1200 : LexSetStatement Statement_ { $$ = $2; }
1204 : HoistableDeclaration { $$ = $1; }
1205 | ClassDeclaration { $$ = $1; }
1206 | LexicalDeclaration { $$ = $1; }
1210 : LexSetRegExp Declaration__ { $$ = $2; }
1214 : LexSetStatement Declaration_ { $$ = $2; }
1217 HoistableDeclaration
1218 : FunctionDeclaration { $$ = $1; }
1219 | GeneratorDeclaration { $$ = $1; }
1223 : IterationStatement { $$ = $1; }
1224 | SwitchStatement { $$ = $1; }
1227 /* 13.2 Block {{{ */
1229 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1233 : BRACE StatementListOpt "}" { $$ = $2; }
1237 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1241 : StatementList { $$ = $1; }
1242 | LexSetStatement LexSetRegExp { $$ = NULL; }
1246 : Statement { $$ = $1; }
1247 | Declaration { $$ = $1; }
1250 /* 13.3+ Let and Const Declarations {{{ */
1252 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1264 // XXX: lots of binding stuff
1266 /* 13.3.2+ Variable Statement {{{ */
1268 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1271 VariableDeclarationList_
1272 : "," VariableDeclarationList { $$ = $2; }
1276 VariableDeclarationList
1277 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1281 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1282 // XXX: | BindingPattern Initializer { $$ = CYNew CYDeclaration($1, $2); }
1285 /* 13.3.3 Destructuring Binding Patterns {{{ */
1287 : ObjectBindingPattern
1288 | ArrayBindingPattern
1291 ObjectBindingPattern
1292 : BRACE BindingPropertyListOpt "}"
1296 : "[" { CYNOT(@$); }
1299 BindingPropertyList_
1300 : "," BindingPropertyListOpt
1305 : BindingProperty BindingPropertyList_
1308 BindingPropertyListOpt
1309 : BindingPropertyList
1315 | PropertyName ":" BindingElement
1319 : SingleNameBinding { $$ = $1; }
1320 | BindingPattern InitializerOpt { CYNOT(@$); }
1324 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1328 : "..." BindingIdentifier
1331 /* 13.4 Empty Statement {{{ */
1333 : ";" { $$ = CYNew CYEmpty(); }
1336 /* 13.5 Expression Statement {{{ */
1338 : Expression Terminator { $$ = CYNew CYExpress($1); }
1341 /* 13.6 The if Statement {{{ */
1343 : "else" Statement { $$ = $2; }
1344 | %prec "if" { $$ = NULL; }
1348 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1351 /* 13.7+ Iteration Statements {{{ */
1353 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1354 | "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1355 | "for" "(" LexPushInOn ForStatementInitializer ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1356 | "for" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1357 | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1360 ForStatementInitializer
1361 : ExpressionOpt { $$ = $1; }
1362 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1365 ForInStatementInitializer
1366 : LeftHandSideExpression { $$ = $1; }
1367 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1370 /* 13.8 The continue Statement {{{ */
1372 : "continue" LexNewLine
1376 : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1377 | Continue Identifier Terminator { $$ = CYNew CYContinue($2); }
1380 /* 13.9 The break Statement {{{ */
1382 : "break" LexNewLine
1386 : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1387 | Break Identifier Terminator { $$ = CYNew CYBreak($2); }
1390 /* 13.10 The return Statement {{{ */
1392 : "!return" LexNewLine
1396 : Return LexSetRegExp TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1397 | Return Expression Terminator { $$ = CYNew CYReturn($2); }
1400 /* 13.11 The with Statement {{{ */
1402 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1405 /* 13.12 The switch Statement {{{ */
1407 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1411 : BRACE CaseClausesOpt "}" { $$ = $2; }
1415 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1419 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1420 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1424 // XXX: the standard makes certain you can only have one of these
1426 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1429 /* 13.13 Labelled Statements {{{ */
1431 : LabelIdentifier ":" LabelledItem { $$ = CYNew CYLabel($1, $3); }
1435 : Statement { $$ = $1; }
1436 | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; }
1439 /* 13.14 The throw Statement {{{ */
1441 : "throw" LexNewLine
1445 : Throw LexSetRegExp TerminatorSoft { CYERR(@1, "throw without exception"); }
1446 | Throw Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1449 /* 13.15 The try Statement {{{ */
1451 : "try" Block Catch { $$ = CYNew cy::Syntax::Try($2, $3, NULL); }
1452 | "try" Block Finally { $$ = CYNew cy::Syntax::Try($2, NULL, $3); }
1453 | "try" Block Catch Finally { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1457 : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); }
1461 : "finally" Block { $$ = CYNew CYFinally($2); }
1465 : BindingIdentifier { $$ = $1; }
1466 | BindingPattern { CYNOT(@$); }
1469 /* 13.16 The debugger Statement {{{ */
1471 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1475 /* 14.1 Function Definitions {{{ */
1477 : ";function" BindingIdentifier "(" FormalParameters ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1481 : "function" BindingIdentifierOpt "(" LexPushInOff FormalParameters ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1484 StrictFormalParameters
1485 : FormalParameters { $$ = $1; }
1490 | FormalParameterList
1493 FormalParameterList_
1494 : "," FormalParameterList { $$ = $2; }
1499 : FunctionRestParameter { CYNOT(@$); }
1500 | FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1503 FunctionRestParameter
1504 : BindingRestElement
1508 : BindingElement { $$ = $1; }
1512 : LexPushYieldOff FunctionStatementList LexPopYield { $$ = $2; }
1515 FunctionStatementList
1516 : LexPushReturnOn StatementListOpt LexPopReturn { $$ = $2; }
1519 /* 14.2 Arrow Function Definitions {{{ */
1521 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1525 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1526 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1->expression_->Parameter(); if ($$ == NULL) CYERR(@1, "invalid parameter list"); }
1530 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1531 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1534 /* 14.3 Method Definitions {{{ */
1536 : PropertyName "(" StrictFormalParameters ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYFunctionMethod($1, $3, $6); */ }
1537 | GeneratorMethod { $$ = $1; }
1538 | "get" PropertyName "(" ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYMethodGet($2, $6); */ }
1539 | "set" PropertyName "(" PropertySetParameterList ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYMethodSet($2, $4); */ }
1542 PropertySetParameterList
1543 : FormalParameter { $$ = $1; }
1546 /* 14.4 Generator Function Definitions {{{ */
1548 : "*" PropertyName "(" StrictFormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($2, $4, $7); */ }
1551 GeneratorDeclaration
1552 : ";function" "*" BindingIdentifier "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($3, $5, $8); */ }
1556 : "function" "*" BindingIdentifierOpt "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($3, $5, $8); */ }
1560 : LexPushYieldOn FunctionStatementList LexPopYield { $$ = $2; }
1564 : "!yield" LexNewLine LexNoStar
1568 : Yield LexSetRegExp "\n" { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1569 | Yield AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldValue($2); */ }
1570 | Yield LexSetRegExp YieldStar AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($4); */ }
1573 /* 14.5 Class Definitions {{{ */
1575 : ";class" BindingIdentifier ClassTail { CYNOT(@$); }
1579 : "class" BindingIdentifierOpt ClassTail { CYNOT(@$); }
1583 : ClassHeritageOpt BRACE ClassBodyOpt "}"
1587 : "extends" LeftHandSideExpression
1605 : ClassElementListOpt ClassElement
1615 | "static" MethodDefinition
1620 /* 15.1 Scripts {{{ */
1622 : ScriptBodyOpt { driver.script_ = CYNew CYScript($1); }
1626 : StatementList { $$ = $1; }
1630 : ScriptBody { $$ = $1; }
1631 | LexSetStatement LexSetRegExp { $$ = NULL; }
1634 /* 15.2 Modules {{{ */
1649 : ModuleItemListOpt ModuleItem
1658 : LexSetStatement LexSetRegExp ImportDeclaration
1659 | LexSetStatement LexSetRegExp ExportDeclaration
1663 /* 15.2.2 Imports {{{ */
1665 : "import" ImportClause FromClause Terminator
1666 | "import" ModuleSpecifier Terminator
1670 : ImportedDefaultBinding
1673 | ImportedDefaultBinding "," NameSpaceImport
1674 | ImportedDefaultBinding "," NamedImports
1677 ImportedDefaultBinding
1682 : "*" "as" ImportedBinding
1686 : BRACE ImportsListOpt "}"
1690 : "from" ModuleSpecifier
1694 : "," ImportsListOpt
1699 : ImportSpecifier ImportsList_
1709 | IdentifierName "as" ImportedBinding
1720 /* 15.2.3 Exports {{{ */
1722 : "*" FromClause Terminator
1723 | ExportClause FromClause Terminator
1724 | ExportClause Terminator
1726 | "default" LexSetStatement LexSetRegExp HoistableDeclaration
1727 | "default" LexSetStatement LexSetRegExp ClassDeclaration
1728 | "default" LexSetStatement AssignmentExpression Terminator
1732 : "export" LexSetStatement LexSetRegExp ExportDeclaration_
1733 | "export" Declaration
1737 : ";{" ExportsListOpt "}"
1741 : "," ExportsListOpt
1746 : ExportSpecifier ExportsList_
1756 | IdentifierName "as" IdentifierName
1761 /* Cycript (C): Type Encoding {{{ */
1763 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1764 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1768 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1769 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1770 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1771 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1772 | TypeSignifier { $$ = $1; }
1773 | { $$ = CYNew CYTypedIdentifier(@$); }
1777 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1782 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1783 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1787 : PrefixedType { $$ = $1; }
1788 | SuffixedType { $$ = $1; }
1789 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1790 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1794 : "int" { $$ = CYNew CYTypeVariable("int"); }
1795 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1796 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1797 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1798 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1802 : IntegerType { $$ = $1; }
1803 | { $$ = CYNew CYTypeVariable("int"); }
1807 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1808 | IntegerType { $$ = $1; }
1809 | "void" { $$ = CYNew CYTypeVoid(); }
1810 | "char" { $$ = CYNew CYTypeVariable("char"); }
1811 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1812 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1816 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1820 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1826 /* Cycript (Objective-C): @class Declaration {{{ */
1828 /* XXX: why the hell did I choose MemberExpression? */
1829 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1834 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1835 | LexSetRegExp { $$ = NULL; }
1839 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1843 : "+" { $$ = false; }
1844 | "-" { $$ = true; }
1848 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) CYERR($3->location_, "unexpected identifier"); $$ = $3; }
1849 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1853 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1856 MessageParameterList
1857 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1860 MessageParameterListOpt
1861 : MessageParameterList { $$ = $1; }
1866 : MessageParameterList { $$ = $1; }
1867 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1870 ClassMessageDeclaration
1871 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1874 ClassMessageDeclarationListOpt
1875 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1880 : Identifier { $$ = $1; }
1881 | "(" AssignmentExpression ")" { $$ = $2; }
1884 // XXX: this should be AssignmentExpressionNoRight
1886 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1890 : "," ClassProtocols { $$ = $2; }
1894 ClassProtocolListOpt
1895 : "<" ClassProtocols ">" { $$ = $2; }
1900 : "@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1908 : "@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1912 : ClassStatement { $$ = $1; }
1913 | CategoryStatement { $$ = $1; }
1916 /* Cycript (Objective-C): Send Message {{{ */
1918 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1923 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1924 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1928 : SelectorCall { $$ = $1; }
1929 | VariadicCall { $$ = $1; }
1933 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1937 : SelectorCall { $$ = $1; }
1938 | Word { $$ = CYNew CYArgument($1, NULL); }
1942 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1943 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1947 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1951 : SelectorExpression_ { $$ = $1; }
1952 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1955 SelectorExpressionOpt
1956 : SelectorExpression_ { $$ = $1; }
1961 : MessageExpression { $$ = $1; }
1962 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1967 /* Cycript: @import Directive {{{ */
1969 : ModulePath "." Word { $$ = CYNew CYModule($3, $1); }
1970 | Word { $$ = CYNew CYModule($1); }
1974 : "@import" ModulePath { $$ = CYNew CYImport($2); }
1979 /* Cycript (Objective-C): Boxed Expressions {{{ */
1981 : NullLiteral { $$ = $1; }
1982 | BooleanLiteral { $$ = $1; }
1983 | NumericLiteral { $$ = $1; }
1984 | StringLiteral { $$ = $1; }
1985 | ArrayLiteral { $$ = $1; }
1986 | ObjectLiteral { $$ = $1; }
1987 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1; }
1988 | "YES" { $$ = CYNew CYTrue(); }
1989 | "NO" { $$ = CYNew CYFalse(); }
1993 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1994 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1995 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1996 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1997 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1998 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2001 /* Cycript (Objective-C): Block Expressions {{{ */
2003 : "^" TypedIdentifier { if ($2->identifier_ != NULL) CYERR($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else CYERR($2->location_, "expected parameters"); }
2006 /* Cycript (Objective-C): Instance Literals {{{ */
2008 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
2014 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2015 LeftHandSideExpression
2016 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
2020 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
2024 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
2025 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
2026 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2029 /* Cycript (C): auto Compatibility {{{ */
2034 /* Cycript (C): Lambda Expressions {{{ */
2036 : "," TypedParameterList { $$ = $2; }
2041 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
2044 TypedParameterListOpt
2045 : TypedParameterList { $$ = $1; }
2050 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
2053 /* Cycript (C): Type Definitions {{{ */
2055 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) CYERR($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
2058 /* Cycript (C): extern "C" {{{ */
2060 : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) CYERR(@2, "unknown extern binding"); } TypedIdentifier { if ($4->identifier_ == NULL) CYERR($4->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($2, $4); }
2067 /* Lexer State {{{ */
2069 : { driver.PushCondition(CYDriver::RegExpCondition); }
2073 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2077 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2081 : { driver.PopCondition(); }
2085 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2089 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2092 /* Virtual Tokens {{{ */
2099 /* 8.1 Context Keywords {{{ */
2101 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2102 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2105 /* 8.3 XML Initializer Input Elements {{{ */
2107 : XMLComment { $$ = $1; }
2108 | XMLCDATA { $$ = $1; }
2109 | XMLPI { $$ = $1; }
2113 /* 11.1 Primary Expressions {{{ */
2115 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2116 | XMLInitialiser { $$ = $1; }
2117 | XMLListInitialiser { $$ = $1; }
2121 : AttributeIdentifier { $$ = $1; }
2122 | QualifiedIdentifier { $$ = $1; }
2123 | WildcardIdentifier { $$ = $1; }
2126 /* 11.1.1 Attribute Identifiers {{{ */
2128 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2132 : PropertySelector { $$ = $1; }
2133 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
2137 : Identifier { $$ = CYNew CYSelector($1); }
2138 | WildcardIdentifier { $$ = $1; }
2141 /* 11.1.2 Qualified Identifiers {{{ */
2142 QualifiedIdentifier_
2143 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2144 | QualifiedIdentifier { $$ = $1; }
2148 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2151 /* 11.1.3 Wildcard Identifiers {{{ */
2153 : "*" { $$ = CYNew CYWildcard(); }
2156 /* 11.1.4 XML Initializer {{{ */
2158 : XMLMarkup { $$ = $1; }
2159 | XMLElement { $$ = $1; }
2163 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2164 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2168 : LexPushXMLTag XMLTagName XMLAttributes
2172 : BRACE LexPushRegExp Expression LexPop "}"
2181 : XMLAttributes_ XMLAttribute
2186 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2187 | XMLAttributes_ XMLWhitespaceOpt
2196 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2200 : XMLExpression XMLElementContentOpt
2201 | XMLMarkup XMLElementContentOpt
2202 | XMLText XMLElementContentOpt
2203 | XMLElement XMLElementContentOpt
2206 XMLElementContentOpt
2211 /* 11.1.5 XMLList Initializer {{{ */
2213 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2217 /* 11.2 Left-Hand-Side Expressions {{{ */
2219 : Identifier { $$ = $1; }
2220 | PropertyIdentifier { $$ = $1; }
2224 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2225 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2226 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2229 /* 12.1 The default xml namespace Statement {{{ */
2230 /* XXX: DefaultXMLNamespaceStatement
2231 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2235 : DefaultXMLNamespaceStatement { $$ = $1; }
2240 /* JavaScript FTL: Array Comprehensions {{{ */
2242 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
2246 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
2247 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
2250 /* JavaScript FTL: for each {{{ */
2252 : "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
2255 /* JavaScript FTL: let Statements {{{ */
2257 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
2265 /* JavaScript FTW: Array Comprehensions {{{ */
2267 : ArrayComprehension
2271 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
2275 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
2280 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
2281 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
2285 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
2289 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
2292 /* JavaScript FTW: Coalesce Operator {{{ */
2293 ConditionalExpression
2294 : LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
2297 /* JavaScript FTW: Named Arguments {{{ */
2299 : LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
2302 /* JavaScript FTW: Ruby Blocks {{{ */
2303 RubyProcParameterList_
2304 : "," RubyProcParameterList { $$ = $2; }
2308 RubyProcParameterList
2309 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
2314 : LexSetRegExp "|" RubyProcParameterList "|" { $$ = $3; }
2315 | LexSetRegExp "||" { $$ = NULL; }
2318 RubyProcParametersOpt
2319 : RubyProcParameters { $$ = $1; }
2324 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
2328 : BRACE LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
2332 : LeftHandSideExpression RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
2338 bool CYDriver::Parse(CYMark mark) {
2340 CYLocal<CYPool> local(&pool_);
2341 cy::parser parser(*this);
2343 parser.set_debug_level(debug_);
2345 return parser.parse() != 0;
2348 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2352 CYDriver::Error error;
2353 error.warning_ = true;
2354 error.location_ = location;
2355 error.message_ = message;
2356 errors_.push_back(error);
2359 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2360 CYDriver::Error error;
2361 error.warning_ = false;
2362 error.location_ = location;
2363 error.message_ = message;
2364 driver.errors_.push_back(error);