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_> BindingIdentifier
410 %type <identifier_> BindingIdentifierOpt
411 %type <declarations_> BindingList_
412 %type <declarations_> BindingList
413 %type <expression_> BitwiseANDExpression
414 %type <statement_> Block
415 %type <statement_> BlockStatement
416 %type <boolean_> BooleanLiteral
417 %type <declaration_> BindingElement
418 %type <expression_> BitwiseORExpression
419 %type <expression_> BitwiseXORExpression
420 %type <statement_> BreakStatement
421 %type <statement_> BreakableStatement
422 %type <expression_> CallExpression_
423 %type <expression_> CallExpression
424 %type <clause_> CaseBlock
425 %type <clause_> CaseClause
426 %type <clause_> CaseClausesOpt
428 %type <identifier_> CatchParameter
429 %type <statement_> ClassDeclaration
430 %type <expression_> ClassExpression
431 %type <expression_> Comprehension
432 %type <comprehension_> ComprehensionFor
433 %type <comprehension_> ComprehensionIf
434 %type <comprehension_> ComprehensionTail
435 %type <expression_> ComputedPropertyName
436 %type <expression_> ConditionalExpression
437 %type <statement_> ContinueStatement
438 %type <statement_> ConciseBody
439 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
440 %type <statement_> DebuggerStatement
441 %type <statement_> Declaration__
442 %type <statement_> Declaration_
443 %type <statement_> Declaration
444 %type <clause_> DefaultClause
445 %type <element_> ElementList
446 %type <element_> ElementListOpt
447 %type <statement_> ElseStatementOpt
448 %type <statement_> EmptyStatement
449 %type <expression_> EqualityExpression
450 %type <expression_> Expression
451 %type <expression_> ExpressionOpt
452 %type <statement_> ExpressionStatement
453 %type <finally_> Finally
454 %type <declaration_> ForBinding
455 %type <declaration_> ForDeclaration
456 %type <forin_> ForInStatementInitializer
457 %type <for_> ForStatementInitializer
458 %type <declaration_> FormalParameter
459 %type <functionParameter_> FormalParameterList_
460 %type <functionParameter_> FormalParameterList
461 %type <functionParameter_> FormalParameters
462 %type <statement_> FunctionBody
463 %type <statement_> FunctionDeclaration
464 %type <expression_> FunctionExpression
465 %type <statement_> FunctionStatementList
466 %type <statement_> GeneratorBody
467 %type <statement_> GeneratorDeclaration
468 %type <expression_> GeneratorExpression
469 %type <property_> GeneratorMethod
470 %type <statement_> HoistableDeclaration
471 %type <identifier_> Identifier
472 %type <identifier_> IdentifierType
473 %type <word_> IdentifierName
474 %type <variable_> IdentifierReference
475 %type <statement_> IfStatement
476 %type <expression_> Initializer
477 %type <expression_> InitializerOpt
478 %type <statement_> IterationStatement
479 %type <identifier_> LabelIdentifier
480 %type <statement_> LabelledItem
481 %type <statement_> LabelledStatement
482 %type <expression_> LeftHandSideExpression
483 %type <statement_> LetStatement
484 %type <declaration_> LexicalBinding
485 %type <statement_> LexicalDeclaration
486 %type <literal_> Literal
487 %type <propertyName_> LiteralPropertyName
488 %type <expression_> LogicalANDExpression
489 %type <expression_> LogicalORExpression
490 %type <member_> MemberAccess
491 %type <expression_> MemberExpression
492 %type <property_> MethodDefinition
493 %type <module_> ModulePath
494 %type <expression_> MultiplicativeExpression
495 %type <expression_> NewExpression
496 %type <null_> NullLiteral
497 %type <literal_> ObjectLiteral
498 %type <expression_> PostfixExpression
499 %type <expression_> PrimaryExpression
500 %type <propertyName_> PropertyName
501 %type <property_> PropertyDefinition
502 %type <property_> PropertyDefinitionList_
503 %type <property_> PropertyDefinitionList
504 %type <property_> PropertyDefinitionListOpt
505 %type <declaration_> PropertySetParameterList
506 %type <expression_> RelationalExpression
507 %type <statement_> ReturnStatement
508 %type <rubyProc_> RubyProcExpression
509 %type <functionParameter_> RubyProcParameterList_
510 %type <functionParameter_> RubyProcParameterList
511 %type <functionParameter_> RubyProcParameters
512 %type <functionParameter_> RubyProcParametersOpt
513 %type <statement_> Script
514 %type <statement_> ScriptBody
515 %type <statement_> ScriptBodyOpt
516 %type <expression_> ShiftExpression
517 %type <declaration_> SingleNameBinding
518 %type <statement_> Statement__
519 %type <statement_> Statement_
520 %type <statement_> Statement
521 %type <statement_> StatementList
522 %type <statement_> StatementListOpt
523 %type <statement_> StatementListItem
524 %type <functionParameter_> StrictFormalParameters
525 %type <statement_> SwitchStatement
526 %type <expression_> TemplateLiteral
527 %type <span_> TemplateSpans
528 %type <statement_> ThrowStatement
529 %type <statement_> TryStatement
530 %type <expression_> UnaryExpression_
531 %type <expression_> UnaryExpression
532 %type <declaration_> VariableDeclaration
533 %type <declarations_> VariableDeclarationList_
534 %type <declarations_> VariableDeclarationList
535 %type <statement_> VariableStatement
536 %type <statement_> WithStatement
539 %type <word_> WordOpt
541 %type <expression_> YieldExpression
544 %type <specifier_> IntegerType
545 %type <specifier_> IntegerTypeOpt
546 %type <typedIdentifier_> PrefixedType
547 %type <specifier_> PrimitiveType
548 %type <typedIdentifier_> SuffixedType
549 %type <typedIdentifier_> TypeSignifier
550 %type <modifier_> TypeQualifierLeft
551 %type <typedIdentifier_> TypeQualifierRight
552 %type <typedIdentifier_> TypedIdentifier
553 %type <typedParameter_> TypedParameterList_
554 %type <typedParameter_> TypedParameterList
555 %type <typedParameter_> TypedParameterListOpt
559 %type <expression_> BoxableExpression
560 %type <statement_> CategoryStatement
561 %type <classField_> ClassFieldListOpt
562 %type <classField_> ClassFields
563 %type <statement_> ClassStatement
564 %type <expression_> ClassSuperOpt
565 %type <message_> ClassMessageDeclaration
566 %type <message_> ClassMessageDeclarationListOpt
567 %type <className_> ClassName
568 %type <protocol_> ClassProtocolListOpt
569 %type <protocol_> ClassProtocols
570 %type <protocol_> ClassProtocolsOpt
571 %type <expression_> MessageExpression
572 %type <messageParameter_> MessageParameter
573 %type <messageParameter_> MessageParameters
574 %type <messageParameter_> MessageParameterList
575 %type <messageParameter_> MessageParameterListOpt
576 %type <bool_> MessageScope
577 %type <argument_> SelectorCall_
578 %type <argument_> SelectorCall
579 %type <selector_> SelectorExpression_
580 %type <selector_> SelectorExpression
581 %type <selector_> SelectorExpressionOpt
582 %type <argument_> SelectorList
583 %type <word_> SelectorWordOpt
584 %type <typedIdentifier_> TypeOpt
585 %type <argument_> VariadicCall
589 %type <propertyIdentifier_> PropertyIdentifier_
590 %type <selector_> PropertySelector_
591 %type <selector_> PropertySelector
592 %type <identifier_> QualifiedIdentifier_
593 %type <identifier_> QualifiedIdentifier
594 %type <identifier_> WildcardIdentifier
595 %type <identifier_> XMLComment
596 %type <identifier_> XMLCDATA
597 %type <identifier_> XMLElement
598 %type <identifier_> XMLElementContent
599 %type <identifier_> XMLMarkup
600 %type <identifier_> XMLPI
602 %type <attribute_> AttributeIdentifier
603 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
604 %type <expression_> PropertyIdentifier
605 %type <expression_> XMLListInitialiser
606 %type <expression_> XMLInitialiser
609 /* Token Priorities {{{ */
628 /* Lexer State {{{ */
629 LexPushInOn: { driver.in_.push(true); };
630 LexPushInOff: { driver.in_.push(false); };
631 LexPopIn: { driver.in_.pop(); };
633 LexPushReturnOn: { driver.return_.push(true); };
634 LexPopReturn: { driver.return_.pop(); };
636 LexPushYieldOn: { driver.yield_.push(true); };
637 LexPushYieldOff: { driver.yield_.push(false); };
638 LexPopYield: { driver.yield_.pop(); };
641 : { driver.SetCondition(CYDriver::RegExpCondition); }
645 : { if (!yyla.empty() && yyla.type_get() != yyeof_) CYERR(@$, "unexpected lookahead"); driver.next_ = true; }
649 : { CYMAP(YieldStar, Star); }
653 : { CYMAP(OpenBrace__, OpenBrace); CYMAP(OpenBrace__, OpenBrace_); }
657 : { CYMAP(_class__, _class_); }
661 : { CYMAP(_function__, _function_); }
665 : LexNoBrace LexNoClass LexNoFunction
668 /* Virtual Tokens {{{ */
679 /* 11.6 Names and Keywords {{{ */
682 | "for" { $$ = CYNew CYWord("for"); }
683 | "in" { $$ = CYNew CYWord("in"); }
684 | "instanceof" { $$ = CYNew CYWord("instanceof"); }
693 : Identifier { $$ = $1; }
694 | "auto" { $$ = CYNew CYWord("auto"); }
695 | "break" { $$ = CYNew CYWord("break"); }
696 | "case" { $$ = CYNew CYWord("case"); }
697 | "catch" { $$ = CYNew CYWord("catch"); }
698 | "class" { $$ = CYNew CYWord("class"); }
699 | ";class" { $$ = CYNew CYWord("class"); }
700 | "const" { $$ = CYNew CYWord("const"); }
701 | "continue" { $$ = CYNew CYWord("continue"); }
702 | "debugger" { $$ = CYNew CYWord("debugger"); }
703 | "default" { $$ = CYNew CYWord("default"); }
704 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
705 | "do" { $$ = CYNew CYWord("do"); }
706 | "else" { $$ = CYNew CYWord("else"); }
707 | "enum" { $$ = CYNew CYWord("enum"); }
708 | "export" { $$ = CYNew CYWord("export"); }
709 | "extends" { $$ = CYNew CYWord("extends"); }
710 | "false" { $$ = CYNew CYWord("false"); }
711 | "finally" { $$ = CYNew CYWord("finally"); }
712 | "function" { $$ = CYNew CYWord("function"); }
713 | "if" { $$ = CYNew CYWord("if"); }
714 | "import" { $$ = CYNew CYWord("import"); }
715 | "!in" { $$ = CYNew CYWord("in"); }
716 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
717 | "null" { $$ = CYNew CYWord("null"); }
718 | "return" { $$ = CYNew CYWord("return"); }
719 | "!return" { $$ = CYNew CYWord("return"); }
720 | "super" { $$ = CYNew CYWord("super"); }
721 | "switch" { $$ = CYNew CYWord("switch"); }
722 | "this" { $$ = CYNew CYWord("this"); }
723 | "throw" { $$ = CYNew CYWord("throw"); }
724 | "true" { $$ = CYNew CYWord("true"); }
725 | "try" { $$ = CYNew CYWord("try"); }
726 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
727 | "var" { $$ = CYNew CYWord("var"); }
728 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
729 | "while" { $$ = CYNew CYWord("while"); }
730 | "with" { $$ = CYNew CYWord("with"); }
731 | "yield" { $$ = CYNew CYIdentifier("yield"); }
733 | Yield LexSetRegExp NewLineOpt { $$ = CYNew CYIdentifier("yield"); }
735 // XXX: should be Identifier
736 | "let" { $$ = CYNew CYIdentifier("let"); }
746 /* 11.8.1 Null Literals {{{ */
748 : "null" { $$ = CYNew CYNull(); }
751 /* 11.8.2 Boolean Literals {{{ */
753 : "true" { $$ = CYNew CYTrue(); }
754 | "false" { $$ = CYNew CYFalse(); }
758 /* 11.9 Automatic Semicolon Insertion {{{ */
760 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
770 | 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
775 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
779 /* 12.1 Identifiers {{{ */
781 : Identifier { $$ = CYNew CYVariable($1); }
782 | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); }
786 : Identifier { $$ = $1; }
787 | "yield" { $$ = CYNew CYIdentifier("yield"); }
791 : BindingIdentifier { $$ = $1; }
796 : Identifier { $$ = $1; }
797 | "yield" { $$ = CYNew CYIdentifier("yield"); }
801 : Identifier_ { $$ = $1; }
802 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
803 | "await" { $$ = CYNew CYIdentifier("await"); }
804 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
805 | "byte" { $$ = CYNew CYIdentifier("byte"); }
806 | "double" { $$ = CYNew CYIdentifier("double"); }
807 | "each" { $$ = CYNew CYIdentifier("each"); }
808 | "final" { $$ = CYNew CYIdentifier("final"); }
809 | "float" { $$ = CYNew CYIdentifier("float"); }
810 | "goto" { $$ = CYNew CYIdentifier("goto"); }
811 | "implements" { $$ = CYNew CYIdentifier("implements"); }
812 | "interface" { $$ = CYNew CYIdentifier("interface"); }
813 | "native" { $$ = CYNew CYIdentifier("native"); }
814 | "of" { $$ = CYNew CYIdentifier("of"); }
815 | "package" { $$ = CYNew CYIdentifier("package"); }
816 | "private" { $$ = CYNew CYIdentifier("private"); }
817 | "protected" { $$ = CYNew CYIdentifier("protected"); }
818 | "public" { $$ = CYNew CYIdentifier("public"); }
819 | "static" { $$ = CYNew CYIdentifier("static"); }
820 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
821 | "throws" { $$ = CYNew CYIdentifier("throws"); }
822 | "transient" { $$ = CYNew CYIdentifier("transient"); }
824 | "bool" { $$ = CYNew CYIdentifier("bool"); }
825 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
826 | "id" { $$ = CYNew CYIdentifier("id"); }
827 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
833 | "char" { $$ = CYNew CYIdentifier("char"); }
834 | "from" { $$ = CYNew CYIdentifier("from"); }
835 | "get" { $$ = CYNew CYIdentifier("get"); }
836 | "int" { $$ = CYNew CYIdentifier("int"); }
837 | "long" { $$ = CYNew CYIdentifier("long"); }
838 | "set" { $$ = CYNew CYIdentifier("set"); }
839 | "short" { $$ = CYNew CYIdentifier("short"); }
840 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
841 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
843 | "extern" { $$ = CYNew CYIdentifier("extern"); }
844 | "signed" { $$ = CYNew CYIdentifier("signed"); }
845 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
846 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
849 | "nil" { $$ = CYNew CYIdentifier("nil"); }
850 | "NO" { $$ = CYNew CYIdentifier("NO"); }
851 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
852 | "YES" { $$ = CYNew CYIdentifier("YES"); }
856 /* 12.2 Primary Expression {{{ */
858 : "this" { $$ = CYNew CYThis(); }
859 | IdentifierReference { $$ = $1; }
860 | Literal { $$ = $1; }
861 | ArrayLiteral { $$ = $1; }
862 | ObjectLiteral { $$ = $1; }
863 | FunctionExpression { $$ = $1; }
864 | ClassExpression { $$ = $1; }
865 | GeneratorExpression { $$ = $1; }
866 | RegularExpressionLiteral { $$ = $1; }
867 | TemplateLiteral { $$ = $1; }
868 | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) CYERR(@1, "invalid parenthetical"); $$ = $1; }
869 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
872 CoverParenthesizedExpressionAndArrowParameterList
873 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
874 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
875 | "(" LexPushInOff LexSetRegExp "..." BindingIdentifier ")" LexPopIn { CYNOT(@$); }
876 | "(" LexPushInOff Expression "," LexSetRegExp "..." BindingIdentifier ")" LexPopIn { CYNOT(@$); }
879 /* 12.2.4 Literals {{{ */
881 : NullLiteral { $$ = $1; }
882 | BooleanLiteral { $$ = $1; }
883 | NumericLiteral { $$ = $1; }
884 | StringLiteral { $$ = $1; }
887 /* 12.2.5 Array Initializer {{{ */
889 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
893 : AssignmentExpressionOpt "," ElementListOpt { $$ = CYNew CYElementValue($1, $3); }
894 | LexSetRegExp "..." AssignmentExpression { $$ = CYNew CYElementSpread($3); }
895 | AssignmentExpression { $$ = CYNew CYElementValue($1, NULL); }
899 : ElementList { $$ = $1; }
900 | LexSetRegExp { $$ = NULL; }
903 /* 12.2.6 Object Initializer {{{ */
905 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
908 PropertyDefinitionList_
909 : "," PropertyDefinitionListOpt { $$ = $2; }
913 PropertyDefinitionList
914 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
917 PropertyDefinitionListOpt
918 : LexSetRegExp PropertyDefinitionList { $$ = $2; }
919 | LexSetRegExp { $$ = NULL; }
923 : IdentifierReference { $$ = CYNew CYProperty($1->name_, $1); }
924 | CoverInitializedName { CYNOT(@$); }
925 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
926 | MethodDefinition { $$ = $1; }
930 : LiteralPropertyName { $$ = $1; }
931 | ComputedPropertyName { CYNOT(@$); /* $$ = $1; */ }
935 : IdentifierName { $$ = $1; }
936 | StringLiteral { $$ = $1; }
937 | NumericLiteral { $$ = $1; }
941 : "[" AssignmentExpression "]" { $$ = $2; }
945 : IdentifierReference Initializer
949 : "=" AssignmentExpression { $$ = $2; }
953 : Initializer { $$ = $1; }
957 /* 12.2.9 Template Literals {{{ */
959 : NoSubstitutionTemplate { $$ = CYNew CYTemplate($1, NULL); }
960 | TemplateHead TemplateSpans { $$ = CYNew CYTemplate($1, $2); }
964 : Expression TemplateMiddle TemplateSpans { $$ = CYNew CYSpan($1, $2, $3); }
965 | Expression TemplateTail { $$ = CYNew CYSpan($1, $2, NULL); }
969 /* 12.3 Left-Hand-Side Expressions {{{ */
971 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
972 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
973 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
974 | TemplateLiteral { CYNOT(@$); }
978 : LexSetRegExp PrimaryExpression { $$ = $2; }
979 | MemberExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
980 | SuperProperty { CYNOT(@$); }
981 | MetaProperty { CYNOT(@$); }
982 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
986 : LexSetRegExp "super" "[" Expression "]"
987 | LexSetRegExp "super" "." IdentifierName
995 : LexSetRegExp "new" LexSetRegExp "." "target"
999 : MemberExpression { $$ = $1; }
1000 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
1009 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
1010 | SuperCall { CYNOT(@$); }
1011 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
1015 : LexSetRegExp "super" Arguments
1019 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
1023 : "," ArgumentList { $$ = $2; }
1028 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
1029 | LexSetRegExp "..." AssignmentExpression { CYNOT(@$); }
1033 : ArgumentList { $$ = $1; }
1034 | LexSetRegExp { $$ = NULL; }
1037 LeftHandSideExpression
1038 : NewExpression { $$ = $1; }
1039 | CallExpression { $$ = $1; }
1042 /* 12.4 Postfix Expressions {{{ */
1044 : %prec "" LeftHandSideExpression { $$ = $1; }
1045 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
1046 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
1049 /* 12.5 Unary Operators {{{ */
1051 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
1052 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
1053 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
1054 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
1055 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
1056 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
1057 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
1058 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
1059 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
1060 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
1061 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
1065 : PostfixExpression { $$ = $1; }
1066 | LexSetRegExp UnaryExpression_ { $$ = $2; }
1069 /* 12.6 Multiplicative Operators {{{ */
1070 MultiplicativeExpression
1071 : UnaryExpression { $$ = $1; }
1072 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
1073 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
1074 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
1077 /* 12.7 Additive Operators {{{ */
1079 : MultiplicativeExpression { $$ = $1; }
1080 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
1081 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
1084 /* 12.8 Bitwise Shift Operators {{{ */
1086 : AdditiveExpression { $$ = $1; }
1087 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
1088 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
1089 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
1092 /* 12.9 Relational Operators {{{ */
1093 RelationalExpression
1094 : ShiftExpression { $$ = $1; }
1095 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
1096 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
1097 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
1098 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
1099 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
1100 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
1103 /* 12.10 Equality Operators {{{ */
1105 : RelationalExpression { $$ = $1; }
1106 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1107 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1108 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1109 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1112 /* 12.11 Binary Bitwise Operators {{{ */
1113 BitwiseANDExpression
1114 : EqualityExpression { $$ = $1; }
1115 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1118 BitwiseXORExpression
1119 : BitwiseANDExpression { $$ = $1; }
1120 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1124 : BitwiseXORExpression { $$ = $1; }
1125 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1128 /* 12.12 Binary Logical Operators {{{ */
1129 LogicalANDExpression
1130 : BitwiseORExpression { $$ = $1; }
1131 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1135 : LogicalANDExpression { $$ = $1; }
1136 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1139 /* 12.13 Conditional Operator ( ? : ) {{{ */
1140 ConditionalExpression
1141 : LogicalORExpression { $$ = $1; }
1142 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1145 /* 12.14 Assignment Operators {{{ */
1146 AssignmentExpression
1147 : ConditionalExpression { $$ = $1; }
1148 | LexSetRegExp YieldExpression { $$ = $2; }
1149 | ArrowFunction { $$ = $1; }
1150 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1151 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1152 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1153 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1154 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1155 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1156 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1157 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1158 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1159 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1160 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1161 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1164 AssignmentExpressionOpt
1165 : AssignmentExpression { $$ = $1; }
1166 | LexSetRegExp { $$ = NULL; }
1169 /* 12.15 Comma Operator ( , ) {{{ */
1171 : AssignmentExpression { $$ = $1; }
1172 | Expression "," AssignmentExpression { $$ = CYNew CYCompound($1, $3); }
1176 : Expression { $$ = $1; }
1177 | LexSetRegExp { $$ = NULL; }
1181 /* 13 Statements and Declarations {{{ */
1183 : BlockStatement { $$ = $1; }
1184 | VariableStatement { $$ = $1; }
1185 | EmptyStatement { $$ = $1; }
1186 | IfStatement { $$ = $1; }
1187 | BreakableStatement { $$ = $1; }
1188 | ContinueStatement { $$ = $1; }
1189 | BreakStatement { $$ = $1; }
1190 | ReturnStatement { $$ = $1; }
1191 | WithStatement { $$ = $1; }
1192 | LabelledStatement { $$ = $1; }
1193 | ThrowStatement { $$ = $1; }
1194 | TryStatement { $$ = $1; }
1195 | DebuggerStatement { $$ = $1; }
1199 : LexSetRegExp Statement__ { $$ = $2; }
1200 | ExpressionStatement { $$ = $1; }
1204 : LexSetStatement Statement_ { $$ = $2; }
1208 : HoistableDeclaration { $$ = $1; }
1209 | ClassDeclaration { $$ = $1; }
1210 | LexicalDeclaration { $$ = $1; }
1214 : LexSetRegExp Declaration__ { $$ = $2; }
1218 : LexSetStatement Declaration_ { $$ = $2; }
1221 HoistableDeclaration
1222 : FunctionDeclaration { $$ = $1; }
1223 | GeneratorDeclaration { $$ = $1; }
1227 : IterationStatement { $$ = $1; }
1228 | SwitchStatement { $$ = $1; }
1231 /* 13.2 Block {{{ */
1233 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1237 : BRACE StatementListOpt "}" { $$ = $2; }
1241 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1245 : StatementList { $$ = $1; }
1246 | LexSetStatement LexSetRegExp { $$ = NULL; }
1250 : Statement { $$ = $1; }
1251 | Declaration { $$ = $1; }
1254 /* 13.3 Let and Const Declarations {{{ */
1256 : LetOrConst BindingList Terminator { $$ = CYNew CYVar($2); }
1265 : "," BindingList { $$ = $2; }
1270 : LexicalBinding BindingList_ { $$ = CYNew CYDeclarations($1, $2); }
1274 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1275 | BindingPattern Initializer { CYNOT(@1); }
1278 /* 13.3.2 Variable Statement {{{ */
1280 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1283 VariableDeclarationList_
1284 : "," VariableDeclarationList { $$ = $2; }
1288 VariableDeclarationList
1289 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1293 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1294 | BindingPattern Initializer { CYNOT(@1); }
1297 /* 13.3.3 Destructuring Binding Patterns {{{ */
1299 : ObjectBindingPattern
1300 | ArrayBindingPattern
1303 ObjectBindingPattern
1304 : BRACE BindingPropertyListOpt "}"
1308 : "[" { CYNOT(@$); }
1311 BindingPropertyList_
1312 : "," BindingPropertyListOpt
1317 : BindingProperty BindingPropertyList_
1320 BindingPropertyListOpt
1321 : BindingPropertyList
1327 | PropertyName ":" BindingElement
1331 : SingleNameBinding { $$ = $1; }
1332 | BindingPattern InitializerOpt { CYNOT(@$); }
1336 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1340 : "..." BindingIdentifier
1343 /* 13.4 Empty Statement {{{ */
1345 : ";" { $$ = CYNew CYEmpty(); }
1348 /* 13.5 Expression Statement {{{ */
1350 : Expression Terminator { $$ = CYNew CYExpress($1); }
1353 /* 13.6 The if Statement {{{ */
1355 : "else" Statement { $$ = $2; }
1356 | %prec "if" { $$ = NULL; }
1360 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1363 /* 13.7 Iteration Statements {{{ */
1365 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1366 | "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1367 | "for" "(" LexPushInOn ForStatementInitializer ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1368 | "for" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1369 | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1372 ForStatementInitializer
1373 : ExpressionOpt { $$ = $1; }
1374 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1375 | LexSetRegExp LexicalDeclaration { CYNOT(@$); }
1378 ForInStatementInitializer
1379 : LeftHandSideExpression { $$ = $1; }
1380 | LexSetRegExp Var_ ForBinding { $$ = $3; }
1381 | LexSetRegExp ForDeclaration { $$ = $2; }
1385 : LetOrConst ForBinding { $$ = $2; }
1389 : BindingIdentifier { $$ = CYNew CYDeclaration($1, NULL); }
1390 | BindingPattern { CYNOT(@1); }
1393 /* 13.8 The continue Statement {{{ */
1395 : "continue" LexNewLine
1399 : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1400 | Continue Identifier Terminator { $$ = CYNew CYContinue($2); }
1403 /* 13.9 The break Statement {{{ */
1405 : "break" LexNewLine
1409 : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1410 | Break Identifier Terminator { $$ = CYNew CYBreak($2); }
1413 /* 13.10 The return Statement {{{ */
1415 : "!return" LexNewLine
1419 : Return LexSetRegExp TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1420 | Return Expression Terminator { $$ = CYNew CYReturn($2); }
1423 /* 13.11 The with Statement {{{ */
1425 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1428 /* 13.12 The switch Statement {{{ */
1430 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1434 : BRACE CaseClausesOpt "}" { $$ = $2; }
1438 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1442 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1443 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1447 // XXX: the standard makes certain you can only have one of these
1449 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1452 /* 13.13 Labelled Statements {{{ */
1454 : LabelIdentifier ":" LabelledItem { $$ = CYNew CYLabel($1, $3); }
1458 : Statement { $$ = $1; }
1459 | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; }
1462 /* 13.14 The throw Statement {{{ */
1464 : "throw" LexNewLine
1468 : Throw LexSetRegExp TerminatorSoft { CYERR(@1, "throw without exception"); }
1469 | Throw Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1472 /* 13.15 The try Statement {{{ */
1474 : "try" Block Catch { $$ = CYNew cy::Syntax::Try($2, $3, NULL); }
1475 | "try" Block Finally { $$ = CYNew cy::Syntax::Try($2, NULL, $3); }
1476 | "try" Block Catch Finally { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1480 : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); }
1484 : "finally" Block { $$ = CYNew CYFinally($2); }
1488 : BindingIdentifier { $$ = $1; }
1489 | BindingPattern { CYNOT(@$); }
1492 /* 13.16 The debugger Statement {{{ */
1494 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1498 /* 14.1 Function Definitions {{{ */
1500 : ";function" BindingIdentifier "(" FormalParameters ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1504 : "function" BindingIdentifierOpt "(" LexPushInOff FormalParameters ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1507 StrictFormalParameters
1508 : FormalParameters { $$ = $1; }
1513 | FormalParameterList
1516 FormalParameterList_
1517 : "," FormalParameterList { $$ = $2; }
1522 : FunctionRestParameter { CYNOT(@$); }
1523 | FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1526 FunctionRestParameter
1527 : BindingRestElement
1531 : BindingElement { $$ = $1; }
1535 : LexPushYieldOff FunctionStatementList LexPopYield { $$ = $2; }
1538 FunctionStatementList
1539 : LexPushReturnOn StatementListOpt LexPopReturn { $$ = $2; }
1542 /* 14.2 Arrow Function Definitions {{{ */
1544 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1548 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1549 | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) $$ = NULL; else { $$ = $1->expression_->Parameter(); if ($$ == NULL) CYERR(@1, "invalid parameter list"); } }
1553 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1554 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1557 /* 14.3 Method Definitions {{{ */
1559 : PropertyName "(" StrictFormalParameters ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYFunctionMethod($1, $3, $6); */ }
1560 | GeneratorMethod { $$ = $1; }
1561 | "get" PropertyName "(" ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYMethodGet($2, $6); */ }
1562 | "set" PropertyName "(" PropertySetParameterList ")" BRACE FunctionBody "}" { CYNOT(@$); /* $$ = CYNew CYMethodSet($2, $4); */ }
1565 PropertySetParameterList
1566 : FormalParameter { $$ = $1; }
1569 /* 14.4 Generator Function Definitions {{{ */
1571 : "*" PropertyName "(" StrictFormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($2, $4, $7); */ }
1574 GeneratorDeclaration
1575 : ";function" "*" BindingIdentifier "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($3, $5, $8); */ }
1579 : "function" "*" BindingIdentifierOpt "(" FormalParameters ")" BRACE GeneratorBody "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($3, $5, $8); */ }
1583 : LexPushYieldOn FunctionStatementList LexPopYield { $$ = $2; }
1587 : "!yield" LexNewLine LexNoStar
1591 : Yield LexSetRegExp "\n" { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ }
1592 | Yield AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldValue($2); */ }
1593 | Yield LexSetRegExp YieldStar AssignmentExpression { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($4); */ }
1596 /* 14.5 Class Definitions {{{ */
1598 : ";class" BindingIdentifier ClassTail { CYNOT(@$); }
1602 : "class" BindingIdentifierOpt ClassTail { CYNOT(@$); }
1606 : ClassHeritageOpt BRACE ClassBodyOpt "}"
1610 : "extends" LeftHandSideExpression
1628 : ClassElementListOpt ClassElement
1638 | "static" MethodDefinition
1643 /* 15.1 Scripts {{{ */
1645 : ScriptBodyOpt { driver.script_ = CYNew CYScript($1); }
1649 : StatementList { $$ = $1; }
1653 : ScriptBody { $$ = $1; }
1654 | LexSetStatement LexSetRegExp { $$ = NULL; }
1657 /* 15.2 Modules {{{ */
1672 : ModuleItemListOpt ModuleItem
1681 : LexSetStatement LexSetRegExp ImportDeclaration
1682 | LexSetStatement LexSetRegExp ExportDeclaration
1686 /* 15.2.2 Imports {{{ */
1688 : "import" ImportClause FromClause Terminator
1689 | "import" ModuleSpecifier Terminator
1693 : ImportedDefaultBinding
1696 | ImportedDefaultBinding "," NameSpaceImport
1697 | ImportedDefaultBinding "," NamedImports
1700 ImportedDefaultBinding
1705 : "*" "as" ImportedBinding
1709 : BRACE ImportsListOpt "}"
1713 : "from" ModuleSpecifier
1717 : "," ImportsListOpt
1722 : ImportSpecifier ImportsList_
1732 | IdentifierName "as" ImportedBinding
1743 /* 15.2.3 Exports {{{ */
1745 : "*" FromClause Terminator
1746 | ExportClause FromClause Terminator
1747 | ExportClause Terminator
1749 | "default" LexSetStatement LexSetRegExp HoistableDeclaration
1750 | "default" LexSetStatement LexSetRegExp ClassDeclaration
1751 | "default" LexSetStatement AssignmentExpression Terminator
1755 : "export" LexSetStatement LexSetRegExp ExportDeclaration_
1756 | "export" Declaration
1760 : ";{" ExportsListOpt "}"
1764 : "," ExportsListOpt
1769 : ExportSpecifier ExportsList_
1779 | IdentifierName "as" IdentifierName
1784 /* Cycript (C): Type Encoding {{{ */
1786 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1787 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1791 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1792 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1793 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1794 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1795 | TypeSignifier { $$ = $1; }
1796 | { $$ = CYNew CYTypedIdentifier(@$); }
1800 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1805 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1806 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1810 : PrefixedType { $$ = $1; }
1811 | SuffixedType { $$ = $1; }
1812 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1813 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1817 : "int" { $$ = CYNew CYTypeVariable("int"); }
1818 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1819 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1820 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1821 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1825 : IntegerType { $$ = $1; }
1826 | { $$ = CYNew CYTypeVariable("int"); }
1830 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1831 | IntegerType { $$ = $1; }
1832 | "void" { $$ = CYNew CYTypeVoid(); }
1833 | "char" { $$ = CYNew CYTypeVariable("char"); }
1834 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1835 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1839 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1843 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1849 /* Cycript (Objective-C): @class Declaration {{{ */
1851 /* XXX: why the hell did I choose MemberExpression? */
1852 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1857 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1858 | LexSetRegExp { $$ = NULL; }
1862 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1866 : "+" { $$ = false; }
1867 | "-" { $$ = true; }
1871 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) CYERR($3->location_, "unexpected identifier"); $$ = $3; }
1872 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1876 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1879 MessageParameterList
1880 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1883 MessageParameterListOpt
1884 : MessageParameterList { $$ = $1; }
1889 : MessageParameterList { $$ = $1; }
1890 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1893 ClassMessageDeclaration
1894 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1897 ClassMessageDeclarationListOpt
1898 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1903 : Identifier { $$ = $1; }
1904 | "(" AssignmentExpression ")" { $$ = $2; }
1907 // XXX: this should be AssignmentExpressionNoRight
1909 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1913 : "," ClassProtocols { $$ = $2; }
1917 ClassProtocolListOpt
1918 : "<" ClassProtocols ">" { $$ = $2; }
1923 : "@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1931 : "@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1935 : ClassStatement { $$ = $1; }
1936 | CategoryStatement { $$ = $1; }
1939 /* Cycript (Objective-C): Send Message {{{ */
1941 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1946 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1947 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1951 : SelectorCall { $$ = $1; }
1952 | VariadicCall { $$ = $1; }
1956 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1960 : SelectorCall { $$ = $1; }
1961 | Word { $$ = CYNew CYArgument($1, NULL); }
1965 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1966 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1970 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1974 : SelectorExpression_ { $$ = $1; }
1975 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1978 SelectorExpressionOpt
1979 : SelectorExpression_ { $$ = $1; }
1984 : MessageExpression { $$ = $1; }
1985 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1990 /* Cycript: @import Directive {{{ */
1992 : ModulePath "." Word { $$ = CYNew CYModule($3, $1); }
1993 | Word { $$ = CYNew CYModule($1); }
1997 : "@import" ModulePath { $$ = CYNew CYImport($2); }
2002 /* Cycript (Objective-C): Boxed Expressions {{{ */
2004 : NullLiteral { $$ = $1; }
2005 | BooleanLiteral { $$ = $1; }
2006 | NumericLiteral { $$ = $1; }
2007 | StringLiteral { $$ = $1; }
2008 | ArrayLiteral { $$ = $1; }
2009 | ObjectLiteral { $$ = $1; }
2010 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1; }
2011 | "YES" { $$ = CYNew CYTrue(); }
2012 | "NO" { $$ = CYNew CYFalse(); }
2016 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
2017 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
2018 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
2019 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
2020 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
2021 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
2024 /* Cycript (Objective-C): Block Expressions {{{ */
2026 : "^" 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"); }
2029 /* Cycript (Objective-C): Instance Literals {{{ */
2031 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
2037 /* Cycript (C): Pointer Indirection/Addressing {{{ */
2038 LeftHandSideExpression
2039 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
2043 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
2047 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
2048 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
2049 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
2052 /* Cycript (C): auto Compatibility {{{ */
2057 /* Cycript (C): Lambda Expressions {{{ */
2059 : "," TypedParameterList { $$ = $2; }
2064 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
2067 TypedParameterListOpt
2068 : TypedParameterList { $$ = $1; }
2073 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
2076 /* Cycript (C): Type Definitions {{{ */
2078 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) CYERR($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
2081 /* Cycript (C): extern "C" {{{ */
2083 : "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); }
2090 /* Lexer State {{{ */
2092 : { driver.PushCondition(CYDriver::RegExpCondition); }
2096 : { driver.PushCondition(CYDriver::XMLContentCondition); }
2100 : { driver.PushCondition(CYDriver::XMLTagCondition); }
2104 : { driver.PopCondition(); }
2108 : { driver.SetCondition(CYDriver::XMLContentCondition); }
2112 : { driver.SetCondition(CYDriver::XMLTagCondition); }
2115 /* Virtual Tokens {{{ */
2122 /* 8.1 Context Keywords {{{ */
2124 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
2125 | "xml" { $$ = CYNew CYIdentifier("xml"); }
2128 /* 8.3 XML Initializer Input Elements {{{ */
2130 : XMLComment { $$ = $1; }
2131 | XMLCDATA { $$ = $1; }
2132 | XMLPI { $$ = $1; }
2136 /* 11.1 Primary Expressions {{{ */
2138 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
2139 | XMLInitialiser { $$ = $1; }
2140 | XMLListInitialiser { $$ = $1; }
2144 : AttributeIdentifier { $$ = $1; }
2145 | QualifiedIdentifier { $$ = $1; }
2146 | WildcardIdentifier { $$ = $1; }
2149 /* 11.1.1 Attribute Identifiers {{{ */
2151 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
2155 : PropertySelector { $$ = $1; }
2156 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
2160 : Identifier { $$ = CYNew CYSelector($1); }
2161 | WildcardIdentifier { $$ = $1; }
2164 /* 11.1.2 Qualified Identifiers {{{ */
2165 QualifiedIdentifier_
2166 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
2167 | QualifiedIdentifier { $$ = $1; }
2171 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
2174 /* 11.1.3 Wildcard Identifiers {{{ */
2176 : "*" { $$ = CYNew CYWildcard(); }
2179 /* 11.1.4 XML Initializer {{{ */
2181 : XMLMarkup { $$ = $1; }
2182 | XMLElement { $$ = $1; }
2186 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
2187 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
2191 : LexPushXMLTag XMLTagName XMLAttributes
2195 : BRACE LexPushRegExp Expression LexPop "}"
2204 : XMLAttributes_ XMLAttribute
2209 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
2210 | XMLAttributes_ XMLWhitespaceOpt
2219 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
2223 : XMLExpression XMLElementContentOpt
2224 | XMLMarkup XMLElementContentOpt
2225 | XMLText XMLElementContentOpt
2226 | XMLElement XMLElementContentOpt
2229 XMLElementContentOpt
2234 /* 11.1.5 XMLList Initializer {{{ */
2236 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
2240 /* 11.2 Left-Hand-Side Expressions {{{ */
2242 : Identifier { $$ = $1; }
2243 | PropertyIdentifier { $$ = $1; }
2247 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
2248 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
2249 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
2252 /* 12.1 The default xml namespace Statement {{{ */
2253 /* XXX: DefaultXMLNamespaceStatement
2254 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
2258 : DefaultXMLNamespaceStatement { $$ = $1; }
2263 /* JavaScript FTL: Array Comprehensions {{{ */
2265 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
2269 : "for" "each" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($5, $8); }
2272 /* JavaScript FTL: for each {{{ */
2274 : "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
2277 /* JavaScript FTL: let Statements {{{ */
2279 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
2287 /* JavaScript FTW: Array Comprehensions {{{ */
2289 : ArrayComprehension
2293 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
2297 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
2302 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
2303 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
2307 : "for" "(" LexPushInOn LexicalBinding "!in" LexPopIn Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
2308 | "for" "(" LexPushInOn LexicalBinding "of" LexPopIn Expression ")" { $$ = CYNew CYForOfComprehension($4, $7); }
2312 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
2315 /* JavaScript FTW: Coalesce Operator {{{ */
2316 ConditionalExpression
2317 : LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
2320 /* JavaScript FTW: Named Arguments {{{ */
2322 : LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
2325 /* JavaScript FTW: Ruby Blocks {{{ */
2326 RubyProcParameterList_
2327 : "," RubyProcParameterList { $$ = $2; }
2331 RubyProcParameterList
2332 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
2337 : LexSetRegExp "|" RubyProcParameterList "|" { $$ = $3; }
2338 | LexSetRegExp "||" { $$ = NULL; }
2341 RubyProcParametersOpt
2342 : RubyProcParameters { $$ = $1; }
2347 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
2351 : BRACE LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
2355 : LeftHandSideExpression RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }
2361 bool CYDriver::Parse(CYMark mark) {
2363 CYLocal<CYPool> local(&pool_);
2364 cy::parser parser(*this);
2366 parser.set_debug_level(debug_);
2368 return parser.parse() != 0;
2371 void CYDriver::Warning(const cy::parser::location_type &location, const char *message) {
2375 CYDriver::Error error;
2376 error.warning_ = true;
2377 error.location_ = location;
2378 error.message_ = message;
2379 errors_.push_back(error);
2382 void cy::parser::error(const cy::parser::location_type &location, const std::string &message) {
2383 CYDriver::Error error;
2384 error.warning_ = false;
2385 error.location_ = location;
2386 error.message_ = message;
2387 driver.errors_.push_back(error);