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 cyscanner driver.scanner_
24 #define YYSTACKEXPANDABLE 1
31 #define CYNew new(driver.pool_)
34 #include "ObjectiveC/Syntax.hpp"
38 #include "E4X/Syntax.hpp"
41 #include "Highlight.hpp"
44 %union { bool bool_; }
46 %union { CYArgument *argument_; }
47 %union { CYAssignment *assignment_; }
48 %union { CYBoolean *boolean_; }
49 %union { CYClause *clause_; }
50 %union { cy::Syntax::Catch *catch_; }
51 %union { CYComment *comment_; }
52 %union { CYComprehension *comprehension_; }
53 %union { CYDeclaration *declaration_; }
54 %union { CYDeclarations *declarations_; }
55 %union { CYElement *element_; }
56 %union { CYExpression *expression_; }
57 %union { CYFalse *false_; }
58 %union { CYFinally *finally_; }
59 %union { CYForInitializer *for_; }
60 %union { CYForInInitializer *forin_; }
61 %union { CYFunctionParameter *functionParameter_; }
62 %union { CYIdentifier *identifier_; }
63 %union { CYInfix *infix_; }
64 %union { CYLiteral *literal_; }
65 %union { CYMember *member_; }
66 %union { CYModule *module_; }
67 %union { CYNull *null_; }
68 %union { CYNumber *number_; }
69 %union { CYParenthetical *parenthetical_; }
70 %union { CYProperty *property_; }
71 %union { CYPropertyName *propertyName_; }
72 %union { CYRubyProc *rubyProc_; }
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, void *scanner) {
117 int token(cylex(&data, location, scanner));
118 *semantic = data.semantic_;
129 @$.begin.filename = @$.end.filename = &driver.filename_;
135 %define api.location.type { CYLocation }
142 %parse-param { CYDriver &driver }
143 %lex-param { void *cyscanner }
145 /* Token Declarations {{{ */
151 %token XMLAttributeValue
153 %token XMLTagCharacters
159 %token LeftRight "<>"
160 %token LeftSlashRight "</>"
162 %token SlashRight "/>"
163 %token LeftSlash "</"
165 %token ColonColon "::"
166 %token PeriodPeriod ".."
169 @begin E4X ObjectiveC
175 %token AmpersandAmpersand "&&"
176 %token AmpersandEqual "&="
178 %token CarrotEqual "^="
180 %token EqualEqual "=="
181 %token EqualEqualEqual "==="
182 %token EqualRight "=>"
183 %token EqualRight_ "\n=>"
184 %token Exclamation "!"
185 %token ExclamationEqual "!="
186 %token ExclamationEqualEqual "!=="
188 %token HyphenEqual "-="
189 %token HyphenHyphen "--"
190 %token HyphenHyphen_ "\n--"
191 %token HyphenRight "->"
193 %token LeftEqual "<="
195 %token LeftLeftEqual "<<="
197 %token PercentEqual "%="
199 %token PeriodPeriodPeriod "..."
201 %token PipeEqual "|="
204 %token PlusEqual "+="
206 %token PlusPlus_ "\n++"
208 %token RightEqual ">="
209 %token RightRight ">>"
210 %token RightRightEqual ">>="
211 %token RightRightRight ">>>"
212 %token RightRightRightEqual ">>>="
214 %token SlashEqual "/="
216 %token StarEqual "*="
225 %token <comment_> Comment
228 %token CloseParen ")"
231 %token OpenBrace_ "\n{"
232 %token OpenBrace__ ";{"
233 %token CloseBrace "}"
235 %token OpenBracket "["
236 %token CloseBracket "]"
238 %token At_error_ "@error"
241 %token At_class_ "@class"
245 %token _typedef_ "typedef"
246 %token _unsigned_ "unsigned"
247 %token _signed_ "signed"
248 %token _extern_ "extern"
252 %token At_encode_ "@encode"
256 %token At_implementation_ "@implementation"
257 %token At_implementation__ ";@implementation"
258 %token At_import_ "@import"
259 %token At_end_ "@end"
260 %token At_selector_ "@selector"
261 %token At_null_ "@null"
262 %token At_YES_ "@YES"
264 %token At_true_ "@true"
265 %token At_false_ "@false"
270 %token _false_ "false"
274 %token _break_ "break"
276 %token _catch_ "catch"
277 %token _class_ "class"
278 %token _class__ "!class"
279 %token _const_ "const"
280 %token _continue_ "continue"
281 %token _debugger_ "debugger"
282 %token _default_ "default"
283 %token _delete_ "delete"
287 %token _export_ "export"
288 %token _extends_ "extends"
289 %token _finally_ "finally"
291 %token _function_ "function"
292 %token _function__ ";function"
294 %token _import_ "import"
297 %token _instanceof_ "instanceof"
299 %token _return_ "return"
300 %token _super_ "super"
301 %token _switch_ "switch"
303 %token _throw_ "throw"
305 %token _typeof_ "typeof"
308 %token _while_ "while"
311 %token _abstract_ "abstract"
312 %token _await_ "await"
313 %token _boolean_ "boolean"
316 %token _double_ "double"
317 %token _final_ "final"
318 %token _float_ "float"
320 %token _implements_ "implements"
322 %token _interface_ "interface"
325 %token _native_ "native"
326 %token _package_ "package"
327 %token _private_ "private"
328 %token _protected_ "protected"
329 %token _public_ "public"
330 %token _short_ "short"
331 %token _static_ "static"
332 %token _synchronized_ "synchronized"
333 %token _throws_ "throws"
334 %token _transient_ "transient"
335 %token _volatile_ "volatile"
336 %token _yield_ "yield"
338 %token _undefined_ "undefined"
354 %token _namespace_ "namespace"
360 %token <identifier_> Identifier_
361 %token <number_> NumericLiteral
362 %token <string_> StringLiteral
363 %token <literal_> RegularExpressionLiteral
365 %type <expression_> AdditiveExpression
366 %type <argument_> ArgumentList_
367 %type <argument_> ArgumentList
368 %type <argument_> ArgumentListOpt
369 %type <argument_> Arguments
370 %type <expression_> ArrayComprehension
371 %type <literal_> ArrayLiteral
372 %type <expression_> ArrowFunction
373 %type <functionParameter_> ArrowParameters
374 %type <expression_> AssignmentExpression
375 %type <identifier_> Binding
376 %type <identifier_> BindingIdentifier
377 %type <expression_> BitwiseANDExpression
378 %type <statement_> Block
379 %type <statement_> BlockStatement
380 %type <boolean_> BooleanLiteral
381 %type <declaration_> BindingElement
382 %type <expression_> BitwiseORExpression
383 %type <expression_> BitwiseXORExpression
384 %type <statement_> BreakStatement
385 %type <statement_> BreakableStatement
386 %type <expression_> CallExpression_
387 %type <expression_> CallExpression
388 %type <clause_> CaseBlock
389 %type <clause_> CaseClause
390 %type <clause_> CaseClausesOpt
392 %type <identifier_> CatchParameter
393 %type <expression_> Comprehension
394 %type <comprehension_> ComprehensionFor
395 %type <comprehension_> ComprehensionIf
396 %type <comprehension_> ComprehensionTail
397 %type <expression_> ConditionalExpression
398 %type <statement_> ContinueStatement
399 %type <statement_> ConciseBody
400 %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList
401 %type <statement_> DebuggerStatement
402 %type <statement_> Declaration__
403 %type <statement_> Declaration_
404 %type <statement_> Declaration
405 %type <clause_> DefaultClause
406 %type <expression_> Element
407 %type <expression_> ElementOpt
408 %type <element_> ElementList
409 %type <element_> ElementListOpt
410 %type <statement_> ElseStatementOpt
411 %type <statement_> EmptyStatement
412 %type <expression_> EqualityExpression
413 %type <expression_> Expression
414 %type <expression_> ExpressionOpt
415 %type <statement_> ExpressionStatement
416 %type <finally_> Finally
417 %type <for_> ForStatementInitializer
418 %type <forin_> ForInStatementInitializer
419 %type <declaration_> FormalParameter
420 %type <functionParameter_> FormalParameterList_
421 %type <functionParameter_> FormalParameterList
422 %type <functionParameter_> FormalParameterListOpt
423 %type <statement_> FunctionBody
424 %type <statement_> FunctionDeclaration
425 %type <expression_> FunctionExpression
426 %type <statement_> HoistableDeclaration
427 %type <identifier_> Identifier
428 %type <identifier_> IdentifierOpt
429 %type <identifier_> IdentifierType
430 %type <word_> IdentifierName
431 %type <expression_> IdentifierReference
432 %type <statement_> IfStatement
433 %type <expression_> Initializer
434 %type <expression_> InitializerOpt
435 %type <statement_> IterationStatement
436 %type <identifier_> LabelIdentifier
437 %type <statement_> LabelledItem
438 %type <statement_> LabelledStatement
439 %type <expression_> LeftHandSideExpression
440 %type <statement_> LetStatement
441 %type <statement_> LexicalDeclaration
442 %type <literal_> Literal
443 %type <expression_> LogicalANDExpression
444 %type <expression_> LogicalORExpression
445 %type <member_> MemberAccess
446 %type <expression_> MemberExpression_
447 %type <expression_> MemberExpression
448 %type <module_> Module
449 %type <expression_> MultiplicativeExpression
450 %type <expression_> NewExpression
451 %type <null_> NullLiteral
452 %type <literal_> ObjectLiteral
453 %type <expression_> PostfixExpression
454 %type <expression_> PrimaryExpression
455 %type <propertyName_> PropertyName_
456 %type <propertyName_> PropertyName
457 %type <property_> PropertyDefinition
458 %type <property_> PropertyDefinitionList_
459 %type <property_> PropertyDefinitionList
460 %type <property_> PropertyDefinitionListOpt
461 %type <expression_> RelationalExpression
462 %type <statement_> ReturnStatement
463 %type <rubyProc_> RubyProcExpression
464 %type <functionParameter_> RubyProcParameterList_
465 %type <functionParameter_> RubyProcParameterList
466 %type <functionParameter_> RubyProcParameters
467 %type <functionParameter_> RubyProcParametersOpt
468 %type <statement_> Script
469 %type <statement_> ScriptBody
470 %type <statement_> ScriptBodyOpt
471 %type <expression_> ShiftExpression
472 %type <declaration_> SingleNameBinding
473 %type <statement_> Statement__
474 %type <statement_> Statement_
475 %type <statement_> Statement
476 %type <statement_> StatementList
477 %type <statement_> StatementListOpt
478 %type <statement_> StatementListItem
479 %type <statement_> SwitchStatement
480 %type <statement_> ThrowStatement
481 %type <statement_> TryStatement
482 %type <expression_> UnaryExpression_
483 %type <expression_> UnaryExpression
484 %type <declaration_> VariableDeclaration
485 %type <declarations_> VariableDeclarationList_
486 %type <declarations_> VariableDeclarationList
487 %type <statement_> VariableStatement
488 %type <statement_> WithStatement
491 %type <word_> WordOpt
495 %type <specifier_> IntegerType
496 %type <specifier_> IntegerTypeOpt
497 %type <typedIdentifier_> PrefixedType
498 %type <specifier_> PrimitiveType
499 %type <typedIdentifier_> SuffixedType
500 %type <typedIdentifier_> TypeSignifier
501 %type <modifier_> TypeQualifierLeft
502 %type <typedIdentifier_> TypeQualifierRight
503 %type <typedIdentifier_> TypedIdentifier
504 %type <typedParameter_> TypedParameterList_
505 %type <typedParameter_> TypedParameterList
506 %type <typedParameter_> TypedParameterListOpt
510 %type <expression_> BoxableExpression
511 %type <statement_> CategoryStatement
512 %type <expression_> ClassExpression
513 %type <classField_> ClassFieldListOpt
514 %type <classField_> ClassFields
515 %type <statement_> ClassStatement
516 %type <expression_> ClassSuperOpt
517 %type <message_> ClassMessageDeclaration
518 %type <message_> ClassMessageDeclarationListOpt
519 %type <className_> ClassName
520 %type <className_> ClassNameOpt
521 %type <protocol_> ClassProtocolListOpt
522 %type <protocol_> ClassProtocols
523 %type <protocol_> ClassProtocolsOpt
524 %type <expression_> MessageExpression
525 %type <messageParameter_> MessageParameter
526 %type <messageParameter_> MessageParameters
527 %type <messageParameter_> MessageParameterList
528 %type <messageParameter_> MessageParameterListOpt
529 %type <bool_> MessageScope
530 %type <argument_> SelectorCall_
531 %type <argument_> SelectorCall
532 %type <selector_> SelectorExpression_
533 %type <selector_> SelectorExpression
534 %type <selector_> SelectorExpressionOpt
535 %type <argument_> SelectorList
536 %type <word_> SelectorWordOpt
537 %type <typedIdentifier_> TypeOpt
538 %type <argument_> VariadicCall
542 %type <propertyIdentifier_> PropertyIdentifier_
543 %type <selector_> PropertySelector_
544 %type <selector_> PropertySelector
545 %type <identifier_> QualifiedIdentifier_
546 %type <identifier_> QualifiedIdentifier
547 %type <identifier_> WildcardIdentifier
548 %type <identifier_> XMLComment
549 %type <identifier_> XMLCDATA
550 %type <identifier_> XMLElement
551 %type <identifier_> XMLElementContent
552 %type <identifier_> XMLMarkup
553 %type <identifier_> XMLPI
555 %type <attribute_> AttributeIdentifier
556 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
557 %type <expression_> PropertyIdentifier
558 %type <expression_> XMLListInitialiser
559 %type <expression_> XMLInitialiser
562 /* Token Priorities {{{ */
574 /* Lexer State {{{ */
576 : { driver.in_.push(true); }
580 : { driver.in_.push(false); }
584 : { driver.in_.pop(); }
588 : { driver.SetCondition(CYDriver::RegExpCondition); }
592 : { if (!yyla.empty() && yyla.type_get() != yyeof_) error(@$, "unexpected lookahead"); driver.no_.NewLine = true; }
596 : { if (yyla.empty()) driver.no_.OpenBrace = true; else if (yyla.type == yytranslate_(token::OpenBrace) || yyla.type == yytranslate_(token::OpenBrace_)) yyla.type = yytranslate_(token::OpenBrace__); }
600 : { if (yyla.empty()) driver.no_.Class = true; else if (yyla.type == yytranslate_(token::_class_)) yyla.type = yytranslate_(token::_class__); }
604 : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::_function_)) yyla.type = yytranslate_(token::_function__); }
607 LexNoAtImplementation :
609 { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::At_implementation_)) yyla.type = yytranslate_(token::At_implementation__); }
614 : LexNoBrace LexNoClass LexNoFunction LexNoAtImplementation
617 /* Virtual Tokens {{{ */
628 /* 11.6 Names and Keywords {{{ */
634 : Identifier { $$ = $1; }
636 | "auto" { $$ = CYNew CYWord("auto"); }
637 | "break" { $$ = CYNew CYWord("break"); }
638 | "case" { $$ = CYNew CYWord("case"); }
639 | "catch" { $$ = CYNew CYWord("catch"); }
640 | "class" { $$ = CYNew CYWord("class"); }
641 | "!class" { $$ = CYNew CYWord("class"); }
642 | "const" { $$ = CYNew CYWord("const"); }
643 | "continue" { $$ = CYNew CYWord("continue"); }
644 | "debugger" { $$ = CYNew CYWord("debugger"); }
645 | "default" { $$ = CYNew CYWord("default"); }
646 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
647 | "do" { $$ = CYNew CYWord("do"); }
648 | "else" { $$ = CYNew CYWord("else"); }
649 | "enum" { $$ = CYNew CYWord("enum"); }
650 | "export" { $$ = CYNew CYWord("export"); }
651 | "extends" { $$ = CYNew CYWord("extends"); }
652 | "false" { $$ = CYNew CYWord("false"); }
653 | "finally" { $$ = CYNew CYWord("finally"); }
654 /* XXX: | "for" { $$ = CYNew CYWord("for"); } */
655 | "function" { $$ = CYNew CYWord("function"); }
656 | "if" { $$ = CYNew CYWord("if"); }
657 | "import" { $$ = CYNew CYWord("import"); }
658 /* XXX: | "in" { $$ = CYNew CYWord("in"); } */
659 | "!in" { $$ = CYNew CYWord("in"); }
660 /* XXX: | "instanceof" { $$ = CYNew CYWord("instanceof"); } */
662 // XXX: as it currently is not an Identifier
663 | "let" { $$ = CYNew CYIdentifier("let"); }
665 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
666 | "null" { $$ = CYNew CYWord("null"); }
667 | "return" { $$ = CYNew CYWord("return"); }
668 | "super" { $$ = CYNew CYWord("super"); }
669 | "switch" { $$ = CYNew CYWord("switch"); }
670 | "this" { $$ = CYNew CYWord("this"); }
671 | "throw" { $$ = CYNew CYWord("throw"); }
672 | "true" { $$ = CYNew CYWord("true"); }
673 | "try" { $$ = CYNew CYWord("try"); }
674 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
675 | "var" { $$ = CYNew CYWord("var"); }
676 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
677 | "while" { $$ = CYNew CYWord("while"); }
678 | "with" { $$ = CYNew CYWord("with"); }
688 /* 11.8.1 Null Literals {{{ */
690 : "null" { $$ = CYNew CYNull(); }
693 /* 11.8.2 Boolean Literals {{{ */
695 : "true" { $$ = CYNew CYTrue(); }
696 | "false" { $$ = CYNew CYFalse(); }
700 /* 11.9 Automatic Semicolon Insertion {{{ */
702 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
712 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) { error(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
717 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
721 /* 12.1 Identifiers {{{ */
723 : Identifier { $$ = CYNew CYVariable($1); }
728 : Identifier { $$ = $1; }
733 : Identifier { $$ = $1; }
738 : Identifier_ { $$ = $1; }
740 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
741 | "await" { $$ = CYNew CYIdentifier("await"); }
742 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
743 | "byte" { $$ = CYNew CYIdentifier("byte"); }
744 | "double" { $$ = CYNew CYIdentifier("double"); }
745 | "final" { $$ = CYNew CYIdentifier("final"); }
746 | "float" { $$ = CYNew CYIdentifier("float"); }
747 | "goto" { $$ = CYNew CYIdentifier("goto"); }
748 | "implements" { $$ = CYNew CYIdentifier("implements"); }
749 | "interface" { $$ = CYNew CYIdentifier("interface"); }
750 | "native" { $$ = CYNew CYIdentifier("native"); }
751 | "package" { $$ = CYNew CYIdentifier("package"); }
752 | "private" { $$ = CYNew CYIdentifier("private"); }
753 | "protected" { $$ = CYNew CYIdentifier("protected"); }
754 | "public" { $$ = CYNew CYIdentifier("public"); }
755 | "static" { $$ = CYNew CYIdentifier("static"); }
756 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
757 | "throws" { $$ = CYNew CYIdentifier("throws"); }
758 | "transient" { $$ = CYNew CYIdentifier("transient"); }
760 // XXX: currently I only have this as Word
761 // | "let" { $$ = CYNew CYIdentifier("let"); }
763 | "yield" { $$ = CYNew CYIdentifier("yield"); }
765 | "each" { $$ = CYNew CYIdentifier("each"); }
766 | "of" { $$ = CYNew CYIdentifier("of"); }
769 | "bool" { $$ = CYNew CYIdentifier("bool"); }
770 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
771 | "id" { $$ = CYNew CYIdentifier("id"); }
772 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
778 | "char" { $$ = CYNew CYIdentifier("char"); }
779 | "int" { $$ = CYNew CYIdentifier("int"); }
780 | "long" { $$ = CYNew CYIdentifier("long"); }
781 | "short" { $$ = CYNew CYIdentifier("short"); }
782 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
783 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
785 | "extern" { $$ = CYNew CYIdentifier("extern"); }
786 | "signed" { $$ = CYNew CYIdentifier("signed"); }
787 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
788 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
791 | "nil" { $$ = CYNew CYIdentifier("nil"); }
792 | "NO" { $$ = CYNew CYIdentifier("NO"); }
793 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
794 | "YES" { $$ = CYNew CYIdentifier("YES"); }
799 : Identifier { $$ = $1; }
803 /* 12.2 Primary Expression {{{ */
805 : "this" { $$ = CYNew CYThis(); }
806 | IdentifierReference { $$ = $1; }
807 | Literal { $$ = $1; }
808 | ArrayLiteral { $$ = $1; }
809 | ObjectLiteral { $$ = $1; }
810 | RegularExpressionLiteral { $$ = $1; }
811 | CoverParenthesizedExpressionAndArrowParameterList { if ($1 == NULL) error(@1, "invalid parenthetical"); $$ = $1; }
812 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
815 CoverParenthesizedExpressionAndArrowParameterList
816 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
817 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
820 /* 12.2.4 Literals {{{ */
822 : NullLiteral { $$ = $1; }
823 | BooleanLiteral { $$ = $1; }
824 | NumericLiteral { $$ = $1; }
825 | StringLiteral { $$ = $1; }
828 /* 12.2.5 Array Initializer {{{ */
830 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
834 : AssignmentExpression { $$ = $1; }
838 : Element { $$ = $1; }
839 | LexSetRegExp { $$ = NULL; }
843 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
844 | Element { $$ = CYNew CYElement($1, NULL); }
848 : ElementList { $$ = $1; }
849 | LexSetRegExp { $$ = NULL; }
852 /* 12.2.6 Object Initializer {{{ */
854 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
857 PropertyDefinitionList_
858 : "," PropertyDefinitionList { $$ = $2; }
859 | "," LexSetRegExp { $$ = NULL; }
863 PropertyDefinitionList
864 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
867 PropertyDefinitionListOpt
868 : PropertyDefinitionList { $$ = $1; }
869 | LexSetRegExp { $$ = NULL; }
873 // XXX: this should be IdentifierName
874 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
875 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
880 : IdentifierName { $$ = $1; }
881 | StringLiteral { $$ = $1; }
882 | NumericLiteral { $$ = $1; }
886 : LexSetRegExp PropertyName_ { $$ = $2; }
891 : "=" AssignmentExpression { $$ = $2; }
895 : Initializer { $$ = $1; }
899 /* 12.2.9 Template Literals {{{ */
903 /* 12.3+ Left-Hand-Side Expressions {{{ */
905 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
906 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
907 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
911 : MemberExpression { $$ = $1; }
912 //| "super" { $$ = $1; }
916 : LexSetRegExp PrimaryExpression { $$ = $2; }
917 | LexSetRegExp FunctionExpression { $$ = $2; }
918 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
919 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
923 : MemberExpression { $$ = $1; }
924 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
933 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
934 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
938 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
942 : "," ArgumentList { $$ = $2; }
947 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
948 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
952 : ArgumentList { $$ = $1; }
953 | LexSetRegExp { $$ = NULL; }
956 LeftHandSideExpression
957 : NewExpression { $$ = $1; }
958 | CallExpression { $$ = $1; }
961 /* 12.4 Postfix Expressions {{{ */
963 : %prec "" LeftHandSideExpression { $$ = $1; }
964 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
965 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
968 /* 12.5 Unary Operators {{{ */
970 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
971 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
972 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
973 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
974 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
975 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
976 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
977 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
978 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
979 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
980 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
984 : PostfixExpression { $$ = $1; }
985 | LexSetRegExp UnaryExpression_ { $$ = $2; }
988 /* 12.6 Multiplicative Operators {{{ */
989 MultiplicativeExpression
990 : UnaryExpression { $$ = $1; }
991 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
992 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
993 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
996 /* 12.7 Additive Operators {{{ */
998 : MultiplicativeExpression { $$ = $1; }
999 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
1000 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
1003 /* 12.8 Bitwise Shift Operators {{{ */
1005 : AdditiveExpression { $$ = $1; }
1006 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
1007 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
1008 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
1011 /* 12.9 Relational Operators {{{ */
1012 RelationalExpression
1013 : ShiftExpression { $$ = $1; }
1014 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
1015 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
1016 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
1017 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
1018 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
1019 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
1022 /* 12.10 Equality Operators {{{ */
1024 : RelationalExpression { $$ = $1; }
1025 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1026 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1027 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1028 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1031 /* 12.11 Binary Bitwise Operators {{{ */
1032 BitwiseANDExpression
1033 : EqualityExpression { $$ = $1; }
1034 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1037 BitwiseXORExpression
1038 : BitwiseANDExpression { $$ = $1; }
1039 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1043 : BitwiseXORExpression { $$ = $1; }
1044 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1047 /* 12.12 Binary Logical Operators {{{ */
1048 LogicalANDExpression
1049 : BitwiseORExpression { $$ = $1; }
1050 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1054 : LogicalANDExpression { $$ = $1; }
1055 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1058 /* 12.13 Conditional Operator ( ? : ) {{{ */
1059 ConditionalExpression
1060 : LogicalORExpression { $$ = $1; }
1061 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1064 /* 12.14 Assignment Operators {{{ */
1065 AssignmentExpression
1066 : ConditionalExpression { $$ = $1; }
1067 // XXX: | YieldExpression { $$ = $1; }
1068 | ArrowFunction { $$ = $1; }
1069 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1070 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1071 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1072 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1073 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1074 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1075 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1076 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1077 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1078 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1079 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1080 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1083 /* 12.15 Comma Operator ( , ) {{{ */
1085 : AssignmentExpression { $$ = $1; }
1086 /* XXX: I have this backwards... */
1087 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
1091 : Expression { $$ = $1; }
1092 | LexSetRegExp { $$ = NULL; }
1096 /* 13 Statements and Declarations {{{ */
1098 : BlockStatement { $$ = $1; }
1099 | VariableStatement { $$ = $1; }
1100 | EmptyStatement { $$ = $1; }
1101 | IfStatement { $$ = $1; }
1102 | BreakableStatement { $$ = $1; }
1103 | ContinueStatement { $$ = $1; }
1104 | BreakStatement { $$ = $1; }
1105 | ReturnStatement { $$ = $1; }
1106 | WithStatement { $$ = $1; }
1107 | LabelledStatement { $$ = $1; }
1108 | ThrowStatement { $$ = $1; }
1109 | TryStatement { $$ = $1; }
1110 | DebuggerStatement { $$ = $1; }
1114 : LexSetRegExp Statement__ { $$ = $2; }
1115 | ExpressionStatement { $$ = $1; }
1119 : LexSetStatement Statement_ { $$ = $2; }
1123 : HoistableDeclaration { $$ = $1; }
1124 // XXX: | ClassDeclaration { $$ = $1; }
1125 | LexicalDeclaration { $$ = $1; }
1129 : LexSetRegExp Declaration__ { $$ = $2; }
1133 : LexSetStatement Declaration_ { $$ = $2; }
1136 HoistableDeclaration
1137 : FunctionDeclaration
1138 // XXX: | GeneratorDeclaration
1142 : IterationStatement { $$ = $1; }
1143 | SwitchStatement { $$ = $1; }
1146 /* 13.2 Block {{{ */
1148 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1152 : BRACE StatementListOpt "}" { $$ = $2; }
1156 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1160 : StatementList { $$ = $1; }
1161 | LexSetStatement LexSetRegExp { $$ = NULL; }
1165 : Statement { $$ = $1; }
1166 | Declaration { $$ = $1; }
1169 /* 13.3+ Let and Const Declarations {{{ */
1171 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1183 // XXX: lots of binding stuff
1185 /* 13.3.2+ Variable Statement {{{ */
1187 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1190 VariableDeclarationList_
1191 : "," VariableDeclarationList { $$ = $2; }
1195 VariableDeclarationList
1196 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1200 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1201 // XXX: | BindingPattern Initializer { $$ = CYNew CYDeclaration($1, $2); }
1204 /* 13.3.3+ Destructuring Binding Patterns {{{ */
1208 : SingleNameBinding { $$ = $1; }
1212 : BindingIdentifier InitializerOpt { $$ = CYNew CYDeclaration($1, $2); }
1215 /* 13.4 Empty Statement {{{ */
1217 : ";" { $$ = CYNew CYEmpty(); }
1220 /* 13.5 Expression Statement {{{ */
1222 : Expression Terminator { $$ = CYNew CYExpress($1); }
1225 /* 13.6 The if Statement {{{ */
1227 : "else" Statement { $$ = $2; }
1228 | %prec "if" { $$ = NULL; }
1232 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1235 /* 13.7+ Iteration Statements {{{ */
1237 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1238 | "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1239 | "for" "(" LexPushInOn ForStatementInitializer ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1240 | "for" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1241 | "for" "(" LexPushInOn ForInStatementInitializer "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1244 ForStatementInitializer
1245 : ExpressionOpt { $$ = $1; }
1246 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1249 ForInStatementInitializer
1250 : LeftHandSideExpression { $$ = $1; }
1251 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1254 /* 13.8 The continue Statement {{{ */
1256 : "continue" LexNoNewLine
1260 : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1261 | Continue Identifier Terminator { $$ = CYNew CYContinue($2); }
1264 /* 13.9 The break Statement {{{ */
1266 : "break" LexNoNewLine
1270 : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1271 | Break Identifier Terminator { $$ = CYNew CYBreak($2); }
1274 /* 13.10 The return Statement {{{ */
1276 : "return" LexNoNewLine
1280 : Return LexSetRegExp TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1281 | Return Expression Terminator { $$ = CYNew CYReturn($2); }
1284 /* 13.11 The with Statement {{{ */
1286 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1289 /* 13.12 The switch Statement {{{ */
1291 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1295 : BRACE CaseClausesOpt "}" { $$ = $2; }
1299 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1303 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1304 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1308 // XXX: the standard makes certain you can only have one of these
1310 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1313 /* 13.13 Labelled Statements {{{ */
1315 : LabelIdentifier ":" LabelledItem { $$ = CYNew CYLabel($1, $3); }
1319 : Statement { $$ = $1; }
1320 | LexSetStatement LexSetRegExp FunctionDeclaration { $$ = $3; }
1323 /* 13.14 The throw Statement {{{ */
1325 : "throw" LexNoNewLine
1329 : Throw LexSetRegExp TerminatorSoft { error(@1, "throw without exception"); }
1330 | Throw Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1333 /* 13.15 The try Statement {{{ */
1335 : "try" Block Catch { $$ = CYNew cy::Syntax::Try($2, $3, NULL); }
1336 | "try" Block Finally { $$ = CYNew cy::Syntax::Try($2, NULL, $3); }
1337 | "try" Block Catch Finally { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1341 : "catch" "(" CatchParameter ")" Block { $$ = CYNew cy::Syntax::Catch($3, $5); }
1345 : "finally" Block { $$ = CYNew CYFinally($2); }
1349 : BindingIdentifier { $$ = $1; }
1350 // XXX: BindingPattern
1353 /* 13.16 The debugger Statement {{{ */
1355 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1359 /* 14.1+ Function Definitions {{{ */
1361 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1365 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1368 FormalParameterList_
1369 : "," FormalParameterList { $$ = $2; }
1374 // XXX: : FunctionRestParameter { $$ = $1; }
1375 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1378 FormalParameterListOpt
1379 : FormalParameterList
1383 /* XXX: FunctionRestParameter
1384 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1388 : BindingElement { $$ = $1; }
1392 : StatementListOpt { $$ = $1; }
1395 /* 14.2 Arrow Function Definitions {{{ */
1397 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1401 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1402 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); }
1406 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1407 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1410 /* 14.3+ Method Definitions {{{ */
1412 /* 14.4+ Generator Function Definitions {{{ */
1414 /* 14.5+ Class Definitions {{{ */
1417 /* 15.1 Scripts {{{ */
1419 : ScriptBodyOpt { driver.script_ = CYNew CYScript($1); }
1423 : StatementList { $$ = $1; }
1427 : ScriptBody { $$ = $1; }
1428 | LexSetStatement LexSetRegExp { $$ = NULL; }
1431 /* 15.2+ Modules {{{ */
1433 /* 15.2.2+ Imports {{{ */
1435 /* 15.2.3+ Exports {{{ */
1439 /* Cycript (C): Type Encoding {{{ */
1441 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1442 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1446 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1447 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1448 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1449 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1450 | TypeSignifier { $$ = $1; }
1451 | { $$ = CYNew CYTypedIdentifier(@$); }
1455 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1460 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1461 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1465 : PrefixedType { $$ = $1; }
1466 | SuffixedType { $$ = $1; }
1467 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1468 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1472 : "int" { $$ = CYNew CYTypeVariable("int"); }
1473 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1474 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1475 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1476 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1480 : IntegerType { $$ = $1; }
1481 | { $$ = CYNew CYTypeVariable("int"); }
1485 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1486 | IntegerType { $$ = $1; }
1487 | "void" { $$ = CYNew CYTypeVoid(); }
1488 | "char" { $$ = CYNew CYTypeVariable("char"); }
1489 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1490 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1494 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1498 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1504 /* Cycript (Objective-C): @class Declaration {{{ */
1506 /* XXX: why the hell did I choose MemberExpression? */
1507 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1512 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1513 | LexSetRegExp { $$ = NULL; }
1517 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1521 : "+" { $$ = false; }
1522 | "-" { $$ = true; }
1526 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; }
1527 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1531 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1534 MessageParameterList
1535 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1538 MessageParameterListOpt
1539 : MessageParameterList { $$ = $1; }
1544 : MessageParameterList { $$ = $1; }
1545 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1548 ClassMessageDeclaration
1549 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1552 ClassMessageDeclarationListOpt
1553 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1554 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1559 : Identifier { $$ = $1; }
1560 | "(" AssignmentExpression ")" { $$ = $2; }
1564 : ClassName { $$ = $1; }
1568 // XXX: this should be AssignmentExpressionNoRight
1570 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1574 : "," ClassProtocols { $$ = $2; }
1578 ClassProtocolListOpt
1579 : "<" ClassProtocols ">" { $$ = $2; }
1584 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1588 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1596 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1600 : ClassExpression { $$ = $1; }
1604 : ClassStatement { $$ = $1; }
1605 | CategoryStatement { $$ = $1; }
1608 /* Cycript (Objective-C): Send Message {{{ */
1610 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1615 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1616 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1620 : SelectorCall { $$ = $1; }
1621 | VariadicCall { $$ = $1; }
1625 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1629 : SelectorCall { $$ = $1; }
1630 | Word { $$ = CYNew CYArgument($1, NULL); }
1634 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1635 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1639 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1643 : SelectorExpression_ { $$ = $1; }
1644 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1647 SelectorExpressionOpt
1648 : SelectorExpression_ { $$ = $1; }
1653 : MessageExpression { $$ = $1; }
1654 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1659 /* Cycript: @import Directive {{{ */
1661 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1662 | Word { $$ = CYNew CYModule($1); }
1666 : "@import" Module { $$ = CYNew CYImport($2); }
1671 /* Cycript (Objective-C): Boxed Expressions {{{ */
1673 : NullLiteral { $$ = $1; }
1674 | BooleanLiteral { $$ = $1; }
1675 | NumericLiteral { $$ = $1; }
1676 | StringLiteral { $$ = $1; }
1677 | ArrayLiteral { $$ = $1; }
1678 | ObjectLiteral { $$ = $1; }
1679 | CoverParenthesizedExpressionAndArrowParameterList { $$ = $1; }
1680 | "YES" { $$ = CYNew CYTrue(); }
1681 | "NO" { $$ = CYNew CYFalse(); }
1685 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1686 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1687 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1688 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1689 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1690 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
1693 /* Cycript (Objective-C): Block Expressions {{{ */
1695 : "^" TypedIdentifier { if ($2->identifier_ != NULL) error($2->location_, "unexpected identifier"); } BRACE LexPushInOff FunctionBody "}" LexPopIn { if (CYTypeFunctionWith *function = $2->Function()) $$ = CYNew CYObjCBlock($2, function->parameters_, $6); else error($2->location_, "expected parameters"); }
1698 /* Cycript (Objective-C): Instance Literals {{{ */
1700 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1706 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1707 LeftHandSideExpression
1708 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1712 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1716 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1717 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1718 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1721 /* Cycript (C): auto Compatibility {{{ */
1726 /* Cycript (C): Lambda Expressions {{{ */
1728 : "," TypedParameterList { $$ = $2; }
1733 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1736 TypedParameterListOpt
1737 : TypedParameterList { $$ = $1; }
1742 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1745 /* Cycript (C): Type Definitions {{{ */
1747 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
1750 /* Cycript (C): extern "C" {{{ */
1752 : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) error(@2, "unknown extern binding"); } TypedIdentifier { if ($4->identifier_ == NULL) error($4->location_, "expected identifier"); } Terminator { $$ = CYNew CYExternal($2, $4); }
1758 /* YUI: Documentation Comments {{{ */
1760 : Comment { $$ = $1; }
1765 /* Lexer State {{{ */
1767 : { driver.PushCondition(CYDriver::RegExpCondition); }
1771 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1775 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1779 : { driver.PopCondition(); }
1783 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1787 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1790 /* Virtual Tokens {{{ */
1797 /* 8.1 Context Keywords {{{ */
1799 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
1800 | "xml" { $$ = CYNew CYIdentifier("xml"); }
1803 /* 8.3 XML Initializer Input Elements {{{ */
1805 : XMLComment { $$ = $1; }
1806 | XMLCDATA { $$ = $1; }
1807 | XMLPI { $$ = $1; }
1811 /* 11.1 Primary Expressions {{{ */
1813 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1814 | XMLInitialiser { $$ = $1; }
1815 | XMLListInitialiser { $$ = $1; }
1819 : AttributeIdentifier { $$ = $1; }
1820 | QualifiedIdentifier { $$ = $1; }
1821 | WildcardIdentifier { $$ = $1; }
1824 /* 11.1.1 Attribute Identifiers {{{ */
1826 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1830 : PropertySelector { $$ = $1; }
1831 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1835 : Identifier { $$ = CYNew CYSelector($1); }
1836 | WildcardIdentifier { $$ = $1; }
1839 /* 11.1.2 Qualified Identifiers {{{ */
1840 QualifiedIdentifier_
1841 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1842 | QualifiedIdentifier { $$ = $1; }
1846 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1849 /* 11.1.3 Wildcard Identifiers {{{ */
1851 : "*" { $$ = CYNew CYWildcard(); }
1854 /* 11.1.4 XML Initializer {{{ */
1856 : XMLMarkup { $$ = $1; }
1857 | XMLElement { $$ = $1; }
1861 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1862 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1866 : LexPushXMLTag XMLTagName XMLAttributes
1870 : BRACE LexPushRegExp Expression LexPop "}"
1879 : XMLAttributes_ XMLAttribute
1884 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1885 | XMLAttributes_ XMLWhitespaceOpt
1894 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1898 : XMLExpression XMLElementContentOpt
1899 | XMLMarkup XMLElementContentOpt
1900 | XMLText XMLElementContentOpt
1901 | XMLElement XMLElementContentOpt
1904 XMLElementContentOpt
1909 /* 11.1.5 XMLList Initializer {{{ */
1911 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1915 /* 11.2 Left-Hand-Side Expressions {{{ */
1917 : Identifier { $$ = $1; }
1918 | PropertyIdentifier { $$ = $1; }
1922 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1923 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1924 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1927 /* 12.1 The default xml namespace Statement {{{ */
1928 /* XXX: DefaultXMLNamespaceStatement
1929 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1933 : DefaultXMLNamespaceStatement { $$ = $1; }
1938 /* JavaScript FTL: Array Comprehensions {{{ */
1940 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1944 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1945 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1948 /* JavaScript FTL: for each {{{ */
1950 : "for" "each" "(" LexPushInOn ForInStatementInitializer "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1953 /* JavaScript FTL: let Statements {{{ */
1955 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1963 /* JavaScript FTW: Array Comprehensions {{{ */
1965 : ArrayComprehension
1969 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
1973 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
1978 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
1979 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
1983 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
1987 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
1990 /* JavaScript FTW: Coalesce Operator {{{ */
1991 ConditionalExpression
1992 : LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1995 /* JavaScript FTW: Ruby Blocks {{{ */
1996 RubyProcParameterList_
1997 : "," RubyProcParameterList { $$ = $2; }
2001 RubyProcParameterList
2002 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
2007 : "|" RubyProcParameterList "|" { $$ = $2; }
2008 | "||" { $$ = NULL; }
2011 RubyProcParametersOpt
2012 : RubyProcParameters
2017 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
2021 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
2025 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }