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 { CYForInitialiser *for_; }
60 %union { CYForInInitialiser *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 { CYProgram *program_; }
71 %union { CYProperty *property_; }
72 %union { CYPropertyName *propertyName_; }
73 %union { CYRubyProc *rubyProc_; }
74 %union { CYStatement *statement_; }
75 %union { CYString *string_; }
76 %union { CYThis *this_; }
77 %union { CYTrue *true_; }
78 %union { CYWord *word_; }
81 %union { CYTypeModifier *modifier_; }
82 %union { CYTypeSpecifier *specifier_; }
83 %union { CYTypedIdentifier *typedIdentifier_; }
84 %union { CYTypedParameter *typedParameter_; }
88 %union { CYClassName *className_; }
89 %union { CYClassField *classField_; }
90 %union { CYMessage *message_; }
91 %union { CYMessageParameter *messageParameter_; }
92 %union { CYProtocol *protocol_; }
93 %union { CYSelectorPart *selector_; }
97 %union { CYAttribute *attribute_; }
98 %union { CYPropertyIdentifier *propertyIdentifier_; }
99 %union { CYSelector *selector_; }
105 cy::parser::semantic_type semantic_;
106 hi::Value highlight_;
109 int cylex(YYSTYPE *, CYLocation *, void *);
116 _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, void *scanner) {
118 int token(cylex(&data, location, scanner));
119 *semantic = data.semantic_;
130 @$.begin.filename = @$.end.filename = &driver.filename_;
136 %define api.location.type { CYLocation }
143 %parse-param { CYDriver &driver }
144 %lex-param { void *cyscanner }
146 /* Token Declarations {{{ */
152 %token XMLAttributeValue
154 %token XMLTagCharacters
160 %token LeftRight "<>"
161 %token LeftSlashRight "</>"
163 %token SlashRight "/>"
164 %token LeftSlash "</"
166 %token ColonColon "::"
167 %token PeriodPeriod ".."
170 @begin E4X ObjectiveC
176 %token AmpersandAmpersand "&&"
177 %token AmpersandEqual "&="
179 %token CarrotEqual "^="
181 %token EqualEqual "=="
182 %token EqualEqualEqual "==="
183 %token EqualRight "=>"
184 %token EqualRight_ "\n=>"
185 %token Exclamation "!"
186 %token ExclamationEqual "!="
187 %token ExclamationEqualEqual "!=="
189 %token HyphenEqual "-="
190 %token HyphenHyphen "--"
191 %token HyphenHyphen_ "\n--"
192 %token HyphenRight "->"
194 %token LeftEqual "<="
196 %token LeftLeftEqual "<<="
198 %token PercentEqual "%="
200 %token PeriodPeriodPeriod "..."
202 %token PipeEqual "|="
205 %token PlusEqual "+="
207 %token PlusPlus_ "\n++"
209 %token RightEqual ">="
210 %token RightRight ">>"
211 %token RightRightEqual ">>="
212 %token RightRightRight ">>>"
213 %token RightRightRightEqual ">>>="
215 %token SlashEqual "/="
217 %token StarEqual "*="
226 %token <comment_> Comment
229 %token CloseParen ")"
232 %token OpenBrace_ "\n{"
233 %token OpenBrace__ ";{"
234 %token CloseBrace "}"
236 %token OpenBracket "["
237 %token CloseBracket "]"
239 %token At_error_ "@error"
242 %token At_class_ "@class"
246 %token _typedef_ "typedef"
247 %token _unsigned_ "unsigned"
248 %token _signed_ "signed"
249 %token _extern_ "extern"
253 %token At_encode_ "@encode"
257 %token At_implementation_ "@implementation"
258 %token At_implementation__ ";@implementation"
259 %token At_import_ "@import"
260 %token At_end_ "@end"
261 %token At_selector_ "@selector"
262 %token At_null_ "@null"
263 %token At_YES_ "@YES"
265 %token At_true_ "@true"
266 %token At_false_ "@false"
271 %token _false_ "false"
275 %token _break_ "break"
277 %token _catch_ "catch"
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 <expression_> ArrayInitialiser
372 %type <literal_> ArrayLiteral
373 %type <expression_> ArrowFunction
374 %type <functionParameter_> ArrowParameters
375 %type <expression_> AssignmentExpression
376 %type <identifier_> Binding
377 %type <identifier_> BindingIdentifier
378 %type <expression_> BitwiseANDExpression
379 %type <statement_> Block_
380 %type <statement_> Block
381 %type <boolean_> BooleanLiteral
382 %type <declaration_> BindingElement
383 %type <expression_> BitwiseORExpression
384 %type <expression_> BitwiseXORExpression
385 %type <statement_> BreakStatement
386 %type <statement_> BreakableStatement
387 %type <expression_> CallExpression_
388 %type <expression_> CallExpression
389 %type <clause_> CaseBlock
390 %type <clause_> CaseClause
391 %type <clause_> CaseClausesOpt
392 %type <catch_> CatchOpt
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 <statement_> DebuggerStatement
401 %type <statement_> Declaration__
402 %type <statement_> Declaration_
403 %type <statement_> Declaration
404 %type <clause_> DefaultClause
405 %type <expression_> Element
406 %type <expression_> ElementOpt
407 %type <element_> ElementList
408 %type <element_> ElementListOpt
409 %type <statement_> ElseStatementOpt
410 %type <statement_> EmptyStatement
411 %type <expression_> EqualityExpression
412 %type <expression_> Expression
413 %type <expression_> ExpressionOpt
414 %type <statement_> ExpressionStatement
415 %type <finally_> FinallyOpt
416 %type <for_> ForStatementInitialiser
417 %type <forin_> ForInStatementInitialiser
418 %type <declaration_> FormalParameter
419 %type <functionParameter_> FormalParameterList_
420 %type <functionParameter_> FormalParameterList
421 %type <functionParameter_> FormalParameterListOpt
422 %type <statement_> FunctionBody
423 %type <statement_> FunctionDeclaration
424 %type <expression_> FunctionExpression
425 %type <identifier_> Identifier
426 %type <identifier_> IdentifierOpt
427 %type <identifier_> IdentifierType
428 %type <word_> IdentifierName
429 %type <statement_> IfStatement
430 %type <expression_> Initialiser
431 %type <expression_> InitialiserOpt
432 %type <statement_> IterationStatement
433 %type <statement_> LabelledStatement
434 %type <expression_> LeftHandSideExpression
435 %type <statement_> LetStatement
436 %type <statement_> LexicalDeclaration
437 %type <literal_> Literal
438 %type <literal_> ValueLiteral
439 %type <expression_> LogicalANDExpression
440 %type <expression_> LogicalORExpression
441 %type <member_> MemberAccess
442 %type <expression_> MemberExpression_
443 %type <expression_> MemberExpression
444 %type <module_> Module
445 %type <expression_> MultiplicativeExpression
446 %type <expression_> NewExpression
447 %type <null_> NullLiteral
448 %type <literal_> ObjectLiteral
449 %type <parenthetical_> Parenthetical
450 %type <expression_> PostfixExpression
451 %type <expression_> PrimaryExpression
452 %type <statement_> Program
453 %type <statement_> ProgramBody
454 %type <statement_> ProgramBodyOpt
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 <expression_> ShiftExpression
469 %type <declaration_> SingleNameBinding
470 %type <statement_> Statement__
471 %type <statement_> Statement_
472 %type <statement_> Statement
473 %type <statement_> StatementList
474 %type <statement_> StatementListOpt
475 %type <statement_> StatementListItem
476 %type <statement_> SwitchStatement
477 %type <statement_> ThrowStatement
478 %type <statement_> TryStatement
479 %type <expression_> UnaryExpression_
480 %type <expression_> UnaryExpression
481 %type <declaration_> VariableDeclaration
482 %type <declarations_> VariableDeclarationList_
483 %type <declarations_> VariableDeclarationList
484 %type <statement_> VariableStatement
485 %type <statement_> WithStatement
488 %type <word_> WordOpt
490 %type <expression_> Variable
493 %type <specifier_> IntegerType
494 %type <specifier_> IntegerTypeOpt
495 %type <typedIdentifier_> PrefixedType
496 %type <specifier_> PrimitiveType
497 %type <typedIdentifier_> SuffixedType
498 %type <typedIdentifier_> TypeSignifier
499 %type <modifier_> TypeQualifierLeft
500 %type <typedIdentifier_> TypeQualifierRight
501 %type <typedIdentifier_> TypedIdentifier
502 %type <typedParameter_> TypedParameterList_
503 %type <typedParameter_> TypedParameterList
504 %type <typedParameter_> TypedParameterListOpt
508 %type <expression_> BoxableExpression
509 %type <statement_> CategoryStatement
510 %type <expression_> ClassExpression
511 %type <classField_> ClassFieldListOpt
512 %type <classField_> ClassFields
513 %type <statement_> ClassStatement
514 %type <expression_> ClassSuperOpt
515 %type <message_> ClassMessageDeclaration
516 %type <message_> ClassMessageDeclarationListOpt
517 %type <className_> ClassName
518 %type <className_> ClassNameOpt
519 %type <protocol_> ClassProtocolListOpt
520 %type <protocol_> ClassProtocols
521 %type <protocol_> ClassProtocolsOpt
522 %type <expression_> MessageExpression
523 %type <messageParameter_> MessageParameter
524 %type <messageParameter_> MessageParameters
525 %type <messageParameter_> MessageParameterList
526 %type <messageParameter_> MessageParameterListOpt
527 %type <bool_> MessageScope
528 %type <argument_> SelectorCall_
529 %type <argument_> SelectorCall
530 %type <selector_> SelectorExpression_
531 %type <selector_> SelectorExpression
532 %type <selector_> SelectorExpressionOpt
533 %type <argument_> SelectorList
534 %type <word_> SelectorWordOpt
535 %type <typedIdentifier_> TypeOpt
536 %type <argument_> VariadicCall
540 %type <propertyIdentifier_> PropertyIdentifier_
541 %type <selector_> PropertySelector_
542 %type <selector_> PropertySelector
543 %type <identifier_> QualifiedIdentifier_
544 %type <identifier_> QualifiedIdentifier
545 %type <identifier_> WildcardIdentifier
546 %type <identifier_> XMLComment
547 %type <identifier_> XMLCDATA
548 %type <identifier_> XMLElement
549 %type <identifier_> XMLElementContent
550 %type <identifier_> XMLMarkup
551 %type <identifier_> XMLPI
553 %type <attribute_> AttributeIdentifier
554 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
555 %type <expression_> PropertyIdentifier
556 %type <expression_> XMLListInitialiser
557 %type <expression_> XMLInitialiser
560 /* Token Priorities {{{ */
572 /* Lexer State {{{ */
574 : { driver.in_.push(true); }
578 : { driver.in_.push(false); }
582 : { driver.in_.pop(); }
586 : { driver.SetCondition(CYDriver::RegExpCondition); }
590 : { if (!yyla.empty() && yyla.type_get() != yyeof_) error(@$, "unexpected lookahead"); driver.no_.NewLine = true; }
594 : { if (yyla.empty()) driver.no_.OpenBrace = true; else if (yyla.type == yytranslate_(token::OpenBrace) || yyla.type == yytranslate_(token::OpenBrace_)) yyla.type = yytranslate_(token::OpenBrace__); }
598 : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::_function_)) yyla.type = yytranslate_(token::_function__); }
601 LexNoAtImplementation :
603 { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::At_implementation_)) yyla.type = yytranslate_(token::At_implementation__); }
608 : LexNoBrace LexNoFunction LexNoAtImplementation
611 /* Virtual Tokens {{{ */
622 /* 7.6 Identifier Names and Identifiers {{{ */
628 : Identifier { $$ = $1; }
630 | "auto" { $$ = CYNew CYWord("auto"); }
631 | "break" { $$ = CYNew CYWord("break"); }
632 | "case" { $$ = CYNew CYWord("case"); }
633 | "catch" { $$ = CYNew CYWord("catch"); }
634 | "class" { $$ = CYNew CYWord("class"); }
635 | "const" { $$ = CYNew CYWord("const"); }
636 | "continue" { $$ = CYNew CYWord("continue"); }
637 | "debugger" { $$ = CYNew CYWord("debugger"); }
638 | "default" { $$ = CYNew CYWord("default"); }
639 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
640 | "do" { $$ = CYNew CYWord("do"); }
641 | "else" { $$ = CYNew CYWord("else"); }
642 | "enum" { $$ = CYNew CYWord("enum"); }
643 | "export" { $$ = CYNew CYWord("export"); }
644 | "extends" { $$ = CYNew CYWord("extends"); }
645 | "false" { $$ = CYNew CYWord("false"); }
646 | "finally" { $$ = CYNew CYWord("finally"); }
647 /* XXX: | "for" { $$ = CYNew CYWord("for"); } */
648 | "function" { $$ = CYNew CYWord("function"); }
649 | "if" { $$ = CYNew CYWord("if"); }
650 | "import" { $$ = CYNew CYWord("import"); }
651 /* XXX: | "in" { $$ = CYNew CYWord("in"); } */
652 | "!in" { $$ = CYNew CYWord("in"); }
653 /* XXX: | "instanceof" { $$ = CYNew CYWord("instanceof"); } */
655 // XXX: as it currently is not an Identifier
656 | "let" { $$ = CYNew CYIdentifier("let"); }
658 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
659 | "null" { $$ = CYNew CYWord("null"); }
660 | "return" { $$ = CYNew CYWord("return"); }
661 | "super" { $$ = CYNew CYWord("super"); }
662 | "switch" { $$ = CYNew CYWord("switch"); }
663 | "this" { $$ = CYNew CYWord("this"); }
664 | "throw" { $$ = CYNew CYWord("throw"); }
665 | "true" { $$ = CYNew CYWord("true"); }
666 | "try" { $$ = CYNew CYWord("try"); }
667 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
668 | "var" { $$ = CYNew CYWord("var"); }
669 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
670 | "while" { $$ = CYNew CYWord("while"); }
671 | "with" { $$ = CYNew CYWord("with"); }
682 : Identifier_ { $$ = $1; }
684 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
685 | "await" { $$ = CYNew CYIdentifier("await"); }
686 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
687 | "byte" { $$ = CYNew CYIdentifier("byte"); }
688 | "double" { $$ = CYNew CYIdentifier("double"); }
689 | "final" { $$ = CYNew CYIdentifier("final"); }
690 | "float" { $$ = CYNew CYIdentifier("float"); }
691 | "goto" { $$ = CYNew CYIdentifier("goto"); }
692 | "implements" { $$ = CYNew CYIdentifier("implements"); }
693 | "interface" { $$ = CYNew CYIdentifier("interface"); }
694 | "native" { $$ = CYNew CYIdentifier("native"); }
695 | "package" { $$ = CYNew CYIdentifier("package"); }
696 | "private" { $$ = CYNew CYIdentifier("private"); }
697 | "protected" { $$ = CYNew CYIdentifier("protected"); }
698 | "public" { $$ = CYNew CYIdentifier("public"); }
699 | "static" { $$ = CYNew CYIdentifier("static"); }
700 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
701 | "throws" { $$ = CYNew CYIdentifier("throws"); }
702 | "transient" { $$ = CYNew CYIdentifier("transient"); }
704 // XXX: currently I only have this as Word
705 // | "let" { $$ = CYNew CYIdentifier("let"); }
707 | "yield" { $$ = CYNew CYIdentifier("yield"); }
709 | "each" { $$ = CYNew CYIdentifier("each"); }
710 | "of" { $$ = CYNew CYIdentifier("of"); }
713 | "bool" { $$ = CYNew CYIdentifier("bool"); }
714 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
715 | "id" { $$ = CYNew CYIdentifier("id"); }
716 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
722 | "char" { $$ = CYNew CYIdentifier("char"); }
723 | "int" { $$ = CYNew CYIdentifier("int"); }
724 | "long" { $$ = CYNew CYIdentifier("long"); }
725 | "short" { $$ = CYNew CYIdentifier("short"); }
726 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
727 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
729 | "extern" { $$ = CYNew CYIdentifier("extern"); }
730 | "signed" { $$ = CYNew CYIdentifier("signed"); }
731 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
732 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
735 | "nil" { $$ = CYNew CYIdentifier("nil"); }
736 | "NO" { $$ = CYNew CYIdentifier("NO"); }
737 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
738 | "YES" { $$ = CYNew CYIdentifier("YES"); }
743 : Identifier { $$ = $1; }
748 /* 7.8 Literals {{{ */
750 : NullLiteral { $$ = $1; }
751 | ValueLiteral { $$ = $1; }
755 : BooleanLiteral { $$ = $1; }
756 | NumericLiteral { $$ = $1; }
757 | StringLiteral { $$ = $1; }
758 | RegularExpressionLiteral { $$ = $1; }
761 /* 7.8.1 Null Literals {{{ */
763 : "null" { $$ = CYNew CYNull(); }
766 /* 7.8.2 Boolean Literals {{{ */
768 : "true" { $$ = CYNew CYTrue(); }
769 | "false" { $$ = CYNew CYFalse(); }
773 /* 7.9 Automatic Semicolon Insertion {{{ */
775 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
785 | 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
790 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
794 /* 11.1 Primary Expressions {{{ */
796 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
800 : Identifier { $$ = CYNew CYVariable($1); }
804 : "this" { $$ = CYNew CYThis(); }
805 | Variable { $$ = $1; }
806 | Literal { $$ = $1; }
807 | ArrayInitialiser { $$ = $1; }
808 | ObjectLiteral { $$ = $1; }
809 | Parenthetical { $$ = $1; }
810 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
813 /* 11.1.4 Array Initializer {{{ */
815 : ArrayLiteral { $$ = $1; }
816 | ArrayComprehension { $$ = $1; }
819 /* 11.1.4.1 Array Literal {{{ */
821 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
825 : AssignmentExpression { $$ = $1; }
829 : Element { $$ = $1; }
830 | LexSetRegExp { $$ = NULL; }
834 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
835 | Element { $$ = CYNew CYElement($1, NULL); }
839 : ElementList { $$ = $1; }
840 | LexSetRegExp { $$ = NULL; }
843 /* 11.1.4.2 Array Comprehension {{{ */
845 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
849 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
854 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
855 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
859 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
863 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
866 /* 11.1.5 Object Initialiser {{{ */
868 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
871 PropertyDefinitionList_
872 : "," PropertyDefinitionList { $$ = $2; }
873 | "," LexSetRegExp { $$ = NULL; }
877 PropertyDefinitionList
878 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
881 PropertyDefinitionListOpt
882 : PropertyDefinitionList { $$ = $1; }
883 | LexSetRegExp { $$ = NULL; }
887 // XXX: this should be IdentifierName
888 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
889 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
894 : IdentifierName { $$ = $1; }
895 | StringLiteral { $$ = $1; }
896 | NumericLiteral { $$ = $1; }
900 : LexSetRegExp PropertyName_ { $$ = $2; }
904 /* 11.2 Left-Hand-Side Expressions {{{ */
906 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
907 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
908 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
912 : MemberExpression { $$ = $1; }
913 //| "super" { $$ = $1; }
917 : LexSetRegExp PrimaryExpression { $$ = $2; }
918 | LexSetRegExp FunctionExpression { $$ = $2; }
919 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
920 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
924 : MemberExpression { $$ = $1; }
925 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
934 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
935 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
939 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
943 : "," ArgumentList { $$ = $2; }
948 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
949 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
953 : ArgumentList { $$ = $1; }
954 | LexSetRegExp { $$ = NULL; }
957 LeftHandSideExpression
958 : NewExpression { $$ = $1; }
959 | CallExpression { $$ = $1; }
962 /* 11.3 Postfix Expressions {{{ */
964 : %prec "" LeftHandSideExpression { $$ = $1; }
965 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
966 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
969 /* 11.4 Unary Operators {{{ */
971 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
972 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
973 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
974 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
975 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
976 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
977 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
978 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
979 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
980 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
981 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
985 : PostfixExpression { $$ = $1; }
986 | LexSetRegExp UnaryExpression_ { $$ = $2; }
989 /* 11.5 Multiplicative Operators {{{ */
990 MultiplicativeExpression
991 : UnaryExpression { $$ = $1; }
992 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
993 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
994 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
997 /* 11.6 Additive Operators {{{ */
999 : MultiplicativeExpression { $$ = $1; }
1000 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
1001 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
1004 /* 11.7 Bitwise Shift Operators {{{ */
1006 : AdditiveExpression { $$ = $1; }
1007 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
1008 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
1009 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
1012 /* 11.8 Relational Operators {{{ */
1013 RelationalExpression
1014 : ShiftExpression { $$ = $1; }
1015 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
1016 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
1017 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
1018 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
1019 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
1020 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
1023 /* 11.9 Equality Operators {{{ */
1025 : RelationalExpression { $$ = $1; }
1026 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1027 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1028 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1029 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1032 /* 11.10 Binary Bitwise Operators {{{ */
1033 BitwiseANDExpression
1034 : EqualityExpression { $$ = $1; }
1035 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1038 BitwiseXORExpression
1039 : BitwiseANDExpression { $$ = $1; }
1040 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1044 : BitwiseXORExpression { $$ = $1; }
1045 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1048 /* 11.11 Binary Logical Operators {{{ */
1049 LogicalANDExpression
1050 : BitwiseORExpression { $$ = $1; }
1051 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1055 : LogicalANDExpression { $$ = $1; }
1056 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1059 /* 11.12 Conditional Operator ( ? : ) {{{ */
1060 ConditionalExpression
1061 : LogicalORExpression { $$ = $1; }
1062 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1063 | LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1066 /* 11.13 Assignment Operators {{{ */
1067 AssignmentExpression
1068 : ConditionalExpression { $$ = $1; }
1069 | ArrowFunction { $$ = $1; }
1070 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1071 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1072 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1073 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1074 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1075 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1076 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1077 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1078 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1079 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1080 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1081 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1084 /* 11.14 Comma Operator {{{ */
1086 : AssignmentExpression { $$ = $1; }
1087 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
1091 : Expression { $$ = $1; }
1092 | LexSetRegExp { $$ = NULL; }
1096 /* 12 Statements {{{ */
1098 : Block { $$ = $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 : FunctionDeclaration { $$ = $1; }
1124 | LexicalDeclaration { $$ = $1; }
1128 : LexSetRegExp Declaration__ { $$ = $2; }
1132 : LexSetStatement Declaration_ { $$ = $2; }
1136 : IterationStatement { $$ = $1; }
1137 | SwitchStatement { $$ = $1; }
1140 /* 12.1 Block {{{ */
1142 : BRACE StatementListOpt "}" { $$ = $2; }
1146 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1150 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1154 : StatementList { $$ = $1; }
1155 | LexSetStatement LexSetRegExp { $$ = NULL; }
1159 : Statement { $$ = $1; }
1160 | Declaration { $$ = $1; }
1164 /* 12.2 Declarations {{{ */
1166 : Identifier { $$ = $1; }
1173 // XXX: BindingPattern
1175 /* 12.2.1 Let and Const Declarations {{{ */
1177 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1185 /* 12.2.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 InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1201 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1205 : "=" AssignmentExpression { $$ = $2; }
1209 : Initialiser { $$ = $1; }
1213 /* 12.2.4 Destructuring Binding Patterns {{{ */
1217 : SingleNameBinding { $$ = $1; }
1221 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1225 /* 12.3 Empty Statement {{{ */
1227 : ";" { $$ = CYNew CYEmpty(); }
1230 /* 12.4 Expression Statement {{{ */
1232 : Expression Terminator { $$ = CYNew CYExpress($1); }
1235 /* 12.5 The if Statement {{{ */
1237 : "else" Statement { $$ = $2; }
1238 | %prec "if" { $$ = NULL; }
1242 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1246 /* 12.6.1 The do-while Statement {{{ */
1248 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1251 /* 12.6.2 The while Statement {{{ */
1253 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1256 /* 12.6.3 The for Statement {{{ */
1258 : "for" "(" LexPushInOn ForStatementInitialiser ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1261 ForStatementInitialiser
1262 : ExpressionOpt { $$ = $1; }
1263 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1266 /* 12.6.4 The for-in and for-of Statements {{{ */
1268 : "for" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1269 | "for" "(" LexPushInOn ForInStatementInitialiser "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1272 ForInStatementInitialiser
1273 : LeftHandSideExpression { $$ = $1; }
1274 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1278 /* 12.7 The continue Statement {{{ */
1280 : "continue" LexNoNewLine
1284 : Continue TerminatorSoft { $$ = CYNew CYContinue(NULL); }
1285 | Continue Identifier Terminator { $$ = CYNew CYContinue($2); }
1288 /* 12.8 The break Statement {{{ */
1290 : "break" LexNoNewLine
1294 : Break TerminatorSoft { $$ = CYNew CYBreak(NULL); }
1295 | Break Identifier Terminator { $$ = CYNew CYBreak($2); }
1298 /* 12.9 The return Statement {{{ */
1300 : "return" LexNoNewLine
1304 : Return LexSetRegExp TerminatorSoft { $$ = CYNew CYReturn(NULL); }
1305 | Return Expression Terminator { $$ = CYNew CYReturn($2); }
1308 /* 12.10 The with Statement {{{ */
1310 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1314 /* 12.11 The switch Statement {{{ */
1316 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1320 : BRACE CaseClausesOpt "}" { $$ = $2; }
1324 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1328 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1329 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1334 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1337 /* 12.12 Labelled Statements {{{ */
1339 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1342 /* 12.13 The throw Statement {{{ */
1344 : "throw" LexNoNewLine
1348 : ThrowWord LexSetRegExp TerminatorSoft { error(@1, "throw without exception"); }
1349 | ThrowWord Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1352 /* 12.14 The try Statement {{{ */
1354 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1358 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1363 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1367 /* 12.14 The debugger Statement {{{ */
1369 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1373 /* 13.1 Function Definitions {{{ */
1375 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1379 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1382 FormalParameterList_
1383 : "," FormalParameterList { $$ = $2; }
1388 // XXX: : FunctionRestParameter { $$ = $1; }
1389 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1392 FormalParameterListOpt
1393 : FormalParameterList
1397 /* XXX: FunctionRestParameter
1398 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1402 : BindingElement { $$ = $1; }
1406 : StatementListOpt { $$ = $1; }
1409 /* 13.2 Arrow Function Definitions {{{ */
1411 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1415 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1416 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
1417 | Parenthetical { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); }
1421 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1422 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1425 /* 14 Program {{{ */
1427 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1431 : StatementList { $$ = $1; }
1435 : ProgramBody { $$ = $1; }
1436 | LexSetStatement LexSetRegExp { $$ = NULL; }
1441 /* Cycript (C): Type Encoding {{{ */
1443 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1444 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1448 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1449 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1450 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1451 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1452 | TypeSignifier { $$ = $1; }
1453 | { $$ = CYNew CYTypedIdentifier(@$); }
1457 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1462 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1463 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1467 : PrefixedType { $$ = $1; }
1468 | SuffixedType { $$ = $1; }
1469 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1470 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1474 : "int" { $$ = CYNew CYTypeVariable("int"); }
1475 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1476 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1477 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1478 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1482 : IntegerType { $$ = $1; }
1483 | { $$ = CYNew CYTypeVariable("int"); }
1487 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1488 | IntegerType { $$ = $1; }
1489 | "void" { $$ = CYNew CYTypeVoid(); }
1490 | "char" { $$ = CYNew CYTypeVariable("char"); }
1491 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1492 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1496 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1500 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1506 /* Cycript (Objective-C): @class Declaration {{{ */
1508 /* XXX: why the hell did I choose MemberExpression? */
1509 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1514 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1515 | LexSetRegExp { $$ = NULL; }
1519 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1523 : "+" { $$ = false; }
1524 | "-" { $$ = true; }
1528 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; }
1529 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1533 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1536 MessageParameterList
1537 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1540 MessageParameterListOpt
1541 : MessageParameterList { $$ = $1; }
1546 : MessageParameterList { $$ = $1; }
1547 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1550 ClassMessageDeclaration
1551 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1554 ClassMessageDeclarationListOpt
1555 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1556 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1561 : Identifier { $$ = $1; }
1562 | "(" AssignmentExpression ")" { $$ = $2; }
1566 : ClassName { $$ = $1; }
1570 // XXX: this should be AssignmentExpressionNoRight
1572 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1576 : "," ClassProtocols { $$ = $2; }
1580 ClassProtocolListOpt
1581 : "<" ClassProtocols ">" { $$ = $2; }
1586 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1590 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1598 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1602 : ClassExpression { $$ = $1; }
1606 : ClassStatement { $$ = $1; }
1607 | CategoryStatement { $$ = $1; }
1610 /* Cycript (Objective-C): Send Message {{{ */
1612 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1617 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1618 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1622 : SelectorCall { $$ = $1; }
1623 | VariadicCall { $$ = $1; }
1627 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1631 : SelectorCall { $$ = $1; }
1632 | Word { $$ = CYNew CYArgument($1, NULL); }
1636 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1637 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1641 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1645 : SelectorExpression_ { $$ = $1; }
1646 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1649 SelectorExpressionOpt
1650 : SelectorExpression_ { $$ = $1; }
1655 : MessageExpression { $$ = $1; }
1656 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1661 /* Cycript: @import Directive {{{ */
1663 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1664 | Word { $$ = CYNew CYModule($1); }
1668 : "@import" Module { $$ = CYNew CYImport($2); }
1673 /* Cycript (Objective-C): Boxed Expressions {{{ */
1675 : NullLiteral { $$ = $1; }
1676 | BooleanLiteral { $$ = $1; }
1677 | NumericLiteral { $$ = $1; }
1678 | StringLiteral { $$ = $1; }
1679 | ArrayLiteral { $$ = $1; }
1680 | ObjectLiteral { $$ = $1; }
1681 | Parenthetical { $$ = $1; }
1682 | "YES" { $$ = CYNew CYTrue(); }
1683 | "NO" { $$ = CYNew CYFalse(); }
1687 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1688 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1689 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1690 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1691 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1692 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
1695 /* Cycript (Objective-C): Block Expressions {{{ */
1697 : "^" 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"); }
1700 /* Cycript (Objective-C): Instance Literals {{{ */
1702 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1708 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1709 LeftHandSideExpression
1710 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1714 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1718 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1719 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1720 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1723 /* Cycript (C): auto Compatibility {{{ */
1728 /* Cycript (C): Lambda Expressions {{{ */
1730 : "," TypedParameterList { $$ = $2; }
1735 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1738 TypedParameterListOpt
1739 : TypedParameterList { $$ = $1; }
1744 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1747 /* Cycript (C): Type Definitions {{{ */
1749 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
1752 /* Cycript (C): extern "C" {{{ */
1754 : "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); }
1760 /* YUI: Documentation Comments {{{ */
1762 : Comment { $$ = $1; }
1767 /* Lexer State {{{ */
1769 : { driver.PushCondition(CYDriver::RegExpCondition); }
1773 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1777 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1781 : { driver.PopCondition(); }
1785 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1789 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1792 /* Virtual Tokens {{{ */
1799 /* 8.1 Context Keywords {{{ */
1801 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
1802 | "xml" { $$ = CYNew CYIdentifier("xml"); }
1805 /* 8.3 XML Initialiser Input Elements {{{ */
1807 : XMLComment { $$ = $1; }
1808 | XMLCDATA { $$ = $1; }
1809 | XMLPI { $$ = $1; }
1813 /* 11.1 Primary Expressions {{{ */
1815 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1816 | XMLInitialiser { $$ = $1; }
1817 | XMLListInitialiser { $$ = $1; }
1821 : AttributeIdentifier { $$ = $1; }
1822 | QualifiedIdentifier { $$ = $1; }
1823 | WildcardIdentifier { $$ = $1; }
1826 /* 11.1.1 Attribute Identifiers {{{ */
1828 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1832 : PropertySelector { $$ = $1; }
1833 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1837 : Identifier { $$ = CYNew CYSelector($1); }
1838 | WildcardIdentifier { $$ = $1; }
1841 /* 11.1.2 Qualified Identifiers {{{ */
1842 QualifiedIdentifier_
1843 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1844 | QualifiedIdentifier { $$ = $1; }
1848 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1851 /* 11.1.3 Wildcard Identifiers {{{ */
1853 : "*" { $$ = CYNew CYWildcard(); }
1856 /* 11.1.4 XML Initialiser {{{ */
1858 : XMLMarkup { $$ = $1; }
1859 | XMLElement { $$ = $1; }
1863 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1864 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1868 : LexPushXMLTag XMLTagName XMLAttributes
1872 : BRACE LexPushRegExp Expression LexPop "}"
1881 : XMLAttributes_ XMLAttribute
1886 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1887 | XMLAttributes_ XMLWhitespaceOpt
1896 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1900 : XMLExpression XMLElementContentOpt
1901 | XMLMarkup XMLElementContentOpt
1902 | XMLText XMLElementContentOpt
1903 | XMLElement XMLElementContentOpt
1906 XMLElementContentOpt
1911 /* 11.1.5 XMLList Initialiser {{{ */
1913 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1917 /* 11.2 Left-Hand-Side Expressions {{{ */
1919 : Identifier { $$ = $1; }
1920 | PropertyIdentifier { $$ = $1; }
1924 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1925 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1926 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1929 /* 12.1 The default xml namespace Statement {{{ */
1930 /* XXX: DefaultXMLNamespaceStatement
1931 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1935 : DefaultXMLNamespaceStatement { $$ = $1; }
1940 /* JavaScript 1.7: Array Comprehensions {{{ */
1942 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1946 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1947 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1950 /* JavaScript 1.7: for each {{{ */
1952 : "for" "each" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1955 /* JavaScript 1.7: let Statements {{{ */
1957 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1965 /* JavaScript FTW: Ruby Blocks {{{ */
1966 RubyProcParameterList_
1967 : "," RubyProcParameterList { $$ = $2; }
1971 RubyProcParameterList
1972 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1977 : "|" RubyProcParameterList "|" { $$ = $2; }
1978 | "||" { $$ = NULL; }
1981 RubyProcParametersOpt
1982 : RubyProcParameters
1987 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1991 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
1995 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }