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"
50 CYArgument *argument_;
51 CYAssignment *assignment_;
54 cy::Syntax::Catch *catch_;
56 CYComprehension *comprehension_;
57 CYDeclaration *declaration_;
58 CYDeclarations *declarations_;
60 CYExpression *expression_;
63 CYForInitialiser *for_;
64 CYForInInitialiser *forin_;
65 CYFunctionParameter *functionParameter_;
66 CYIdentifier *identifier_;
73 CYParenthetical *parenthetical_;
75 CYProperty *property_;
76 CYPropertyName *propertyName_;
77 CYRubyProc *rubyProc_;
78 CYStatement *statement_;
85 CYTypeModifier *modifier_;
86 CYTypeSpecifier *specifier_;
87 CYTypedIdentifier *typedIdentifier_;
88 CYTypedParameter *typedParameter_;
92 CYClassName *className_;
93 CYClassField *classField_;
95 CYMessageParameter *messageParameter_;
96 CYProtocol *protocol_;
97 CYSelectorPart *selector_;
101 CYAttribute *attribute_;
102 CYPropertyIdentifier *propertyIdentifier_;
103 CYSelector *selector_;
108 #define YYSTYPE YYSTYPE
112 int cylex(YYSTYPE *, CYLocation *, void *);
120 @$.begin.filename = @$.end.filename = &driver.filename_;
126 %define api.location.type { CYLocation }
133 %parse-param { CYDriver &driver }
134 %lex-param { void *cyscanner }
136 /* Token Declarations {{{ */
142 %token XMLAttributeValue
144 %token XMLTagCharacters
150 %token LeftRight "<>"
151 %token LeftSlashRight "</>"
153 %token SlashRight "/>"
154 %token LeftSlash "</"
156 %token ColonColon "::"
157 %token PeriodPeriod ".."
160 @begin E4X ObjectiveC
166 %token AmpersandAmpersand "&&"
167 %token AmpersandEqual "&="
169 %token CarrotEqual "^="
171 %token EqualEqual "=="
172 %token EqualEqualEqual "==="
173 %token EqualRight "=>"
174 %token EqualRight_ "\n=>"
175 %token Exclamation "!"
176 %token ExclamationEqual "!="
177 %token ExclamationEqualEqual "!=="
179 %token HyphenEqual "-="
180 %token HyphenHyphen "--"
181 %token HyphenHyphen_ "\n--"
182 %token HyphenRight "->"
184 %token LeftEqual "<="
186 %token LeftLeftEqual "<<="
188 %token PercentEqual "%="
190 %token PeriodPeriodPeriod "..."
192 %token PipeEqual "|="
195 %token PlusEqual "+="
197 %token PlusPlus_ "\n++"
199 %token RightEqual ">="
200 %token RightRight ">>"
201 %token RightRightEqual ">>="
202 %token RightRightRight ">>>"
203 %token RightRightRightEqual ">>>="
205 %token SlashEqual "/="
207 %token StarEqual "*="
216 %token <comment_> Comment
219 %token CloseParen ")"
222 %token OpenBrace_ "\n{"
223 %token OpenBrace__ ";{"
224 %token CloseBrace "}"
226 %token OpenBracket "["
227 %token CloseBracket "]"
229 %token At_error_ "@error"
232 %token At_class_ "@class"
236 %token _typedef_ "typedef"
237 %token _unsigned_ "unsigned"
238 %token _signed_ "signed"
239 %token _extern_ "extern"
243 %token At_encode_ "@encode"
247 %token At_implementation_ "@implementation"
248 %token At_implementation__ ";@implementation"
249 %token At_import_ "@import"
250 %token At_end_ "@end"
251 %token At_selector_ "@selector"
252 %token At_null_ "@null"
253 %token At_YES_ "@YES"
255 %token At_true_ "@true"
256 %token At_false_ "@false"
261 %token _false_ "false"
265 %token _break_ "break"
267 %token _catch_ "catch"
268 %token _class_ "class"
269 %token _const_ "const"
270 %token _continue_ "continue"
271 %token _debugger_ "debugger"
272 %token _default_ "default"
273 %token _delete_ "delete"
277 %token _export_ "export"
278 %token _extends_ "extends"
279 %token _finally_ "finally"
281 %token _function_ "function"
282 %token _function__ ";function"
284 %token _import_ "import"
287 %token _instanceof_ "instanceof"
289 %token _return_ "return"
290 %token _super_ "super"
291 %token _switch_ "switch"
293 %token _throw_ "throw"
295 %token _typeof_ "typeof"
298 %token _while_ "while"
301 %token _abstract_ "abstract"
302 %token _await_ "await"
303 %token _boolean_ "boolean"
306 %token _double_ "double"
307 %token _final_ "final"
308 %token _float_ "float"
310 %token _implements_ "implements"
312 %token _interface_ "interface"
315 %token _native_ "native"
316 %token _package_ "package"
317 %token _private_ "private"
318 %token _protected_ "protected"
319 %token _public_ "public"
320 %token _short_ "short"
321 %token _static_ "static"
322 %token _synchronized_ "synchronized"
323 %token _throws_ "throws"
324 %token _transient_ "transient"
325 %token _volatile_ "volatile"
326 %token _yield_ "yield"
328 %token _undefined_ "undefined"
344 %token _namespace_ "namespace"
350 %token <identifier_> Identifier_
351 %token <number_> NumericLiteral
352 %token <string_> StringLiteral
353 %token <literal_> RegularExpressionLiteral
355 %type <expression_> AdditiveExpression
356 %type <argument_> ArgumentList_
357 %type <argument_> ArgumentList
358 %type <argument_> ArgumentListOpt
359 %type <argument_> Arguments
360 %type <expression_> ArrayComprehension
361 %type <expression_> ArrayInitialiser
362 %type <literal_> ArrayLiteral
363 %type <expression_> ArrowFunction
364 %type <functionParameter_> ArrowParameters
365 %type <expression_> AssignmentExpression
366 %type <identifier_> Binding
367 %type <identifier_> BindingIdentifier
368 %type <expression_> BitwiseANDExpression
369 %type <statement_> Block_
370 %type <statement_> Block
371 %type <boolean_> BooleanLiteral
372 %type <declaration_> BindingElement
373 %type <expression_> BitwiseORExpression
374 %type <expression_> BitwiseXORExpression
375 %type <statement_> BreakStatement
376 %type <statement_> BreakableStatement
377 %type <expression_> CallExpression_
378 %type <expression_> CallExpression
379 %type <clause_> CaseBlock
380 %type <clause_> CaseClause
381 %type <clause_> CaseClausesOpt
382 %type <catch_> CatchOpt
383 %type <expression_> Comprehension
384 %type <comprehension_> ComprehensionFor
385 %type <comprehension_> ComprehensionIf
386 %type <comprehension_> ComprehensionTail
387 %type <expression_> ConditionalExpression
388 %type <statement_> ContinueStatement
389 %type <statement_> ConciseBody
390 %type <statement_> DebuggerStatement
391 %type <statement_> Declaration__
392 %type <statement_> Declaration_
393 %type <statement_> Declaration
394 %type <clause_> DefaultClause
395 %type <expression_> Element
396 %type <expression_> ElementOpt
397 %type <element_> ElementList
398 %type <element_> ElementListOpt
399 %type <statement_> ElseStatementOpt
400 %type <statement_> EmptyStatement
401 %type <expression_> EqualityExpression
402 %type <expression_> Expression
403 %type <expression_> ExpressionOpt
404 %type <statement_> ExpressionStatement
405 %type <finally_> FinallyOpt
406 %type <for_> ForStatementInitialiser
407 %type <forin_> ForInStatementInitialiser
408 %type <declaration_> FormalParameter
409 %type <functionParameter_> FormalParameterList_
410 %type <functionParameter_> FormalParameterList
411 %type <functionParameter_> FormalParameterListOpt
412 %type <statement_> FunctionBody
413 %type <statement_> FunctionDeclaration
414 %type <expression_> FunctionExpression
415 %type <identifier_> Identifier
416 %type <identifier_> IdentifierOpt
417 %type <identifier_> IdentifierType
418 %type <word_> IdentifierName
419 %type <statement_> IfStatement
420 %type <expression_> Initialiser
421 %type <expression_> InitialiserOpt
422 %type <statement_> IterationStatement
423 %type <statement_> LabelledStatement
424 %type <expression_> LeftHandSideExpression
425 %type <statement_> LetStatement
426 %type <statement_> LexicalDeclaration
427 %type <literal_> Literal
428 %type <literal_> ValueLiteral
429 %type <expression_> LogicalANDExpression
430 %type <expression_> LogicalORExpression
431 %type <member_> MemberAccess
432 %type <expression_> MemberExpression_
433 %type <expression_> MemberExpression
434 %type <module_> Module
435 %type <expression_> MultiplicativeExpression
436 %type <expression_> NewExpression
437 %type <null_> NullLiteral
438 %type <literal_> ObjectLiteral
439 %type <parenthetical_> Parenthetical
440 %type <expression_> PostfixExpression
441 %type <expression_> PrimaryExpression
442 %type <statement_> Program
443 %type <statement_> ProgramBody
444 %type <statement_> ProgramBodyOpt
445 %type <propertyName_> PropertyName_
446 %type <propertyName_> PropertyName
447 %type <property_> PropertyDefinition
448 %type <property_> PropertyDefinitionList_
449 %type <property_> PropertyDefinitionList
450 %type <property_> PropertyDefinitionListOpt
451 %type <expression_> RelationalExpression
452 %type <statement_> ReturnStatement
453 %type <rubyProc_> RubyProcExpression
454 %type <functionParameter_> RubyProcParameterList_
455 %type <functionParameter_> RubyProcParameterList
456 %type <functionParameter_> RubyProcParameters
457 %type <functionParameter_> RubyProcParametersOpt
458 %type <expression_> ShiftExpression
459 %type <declaration_> SingleNameBinding
460 %type <statement_> Statement__
461 %type <statement_> Statement_
462 %type <statement_> Statement
463 %type <statement_> StatementList
464 %type <statement_> StatementListOpt
465 %type <statement_> StatementListItem
466 %type <statement_> SwitchStatement
467 %type <statement_> ThrowStatement
468 %type <statement_> TryStatement
469 %type <expression_> UnaryExpression_
470 %type <expression_> UnaryExpression
471 %type <declaration_> VariableDeclaration
472 %type <declarations_> VariableDeclarationList_
473 %type <declarations_> VariableDeclarationList
474 %type <statement_> VariableStatement
475 %type <statement_> WithStatement
478 %type <word_> WordOpt
480 %type <expression_> Variable
483 %type <specifier_> IntegerType
484 %type <specifier_> IntegerTypeOpt
485 %type <typedIdentifier_> PrefixedType
486 %type <specifier_> PrimitiveType
487 %type <typedIdentifier_> SuffixedType
488 %type <typedIdentifier_> TypeSignifier
489 %type <modifier_> TypeQualifierLeft
490 %type <typedIdentifier_> TypeQualifierRight
491 %type <typedIdentifier_> TypedIdentifier
492 %type <typedParameter_> TypedParameterList_
493 %type <typedParameter_> TypedParameterList
494 %type <typedParameter_> TypedParameterListOpt
498 %type <expression_> BoxableExpression
499 %type <statement_> CategoryStatement
500 %type <expression_> ClassExpression
501 %type <classField_> ClassFieldListOpt
502 %type <classField_> ClassFields
503 %type <statement_> ClassStatement
504 %type <expression_> ClassSuperOpt
505 %type <message_> ClassMessageDeclaration
506 %type <message_> ClassMessageDeclarationListOpt
507 %type <className_> ClassName
508 %type <className_> ClassNameOpt
509 %type <protocol_> ClassProtocolListOpt
510 %type <protocol_> ClassProtocols
511 %type <protocol_> ClassProtocolsOpt
512 %type <expression_> MessageExpression
513 %type <messageParameter_> MessageParameter
514 %type <messageParameter_> MessageParameters
515 %type <messageParameter_> MessageParameterList
516 %type <messageParameter_> MessageParameterListOpt
517 %type <bool_> MessageScope
518 %type <argument_> SelectorCall_
519 %type <argument_> SelectorCall
520 %type <selector_> SelectorExpression_
521 %type <selector_> SelectorExpression
522 %type <selector_> SelectorExpressionOpt
523 %type <argument_> SelectorList
524 %type <word_> SelectorWordOpt
525 %type <typedIdentifier_> TypeOpt
526 %type <argument_> VariadicCall
530 %type <propertyIdentifier_> PropertyIdentifier_
531 %type <selector_> PropertySelector_
532 %type <selector_> PropertySelector
533 %type <identifier_> QualifiedIdentifier_
534 %type <identifier_> QualifiedIdentifier
535 %type <identifier_> WildcardIdentifier
536 %type <identifier_> XMLComment
537 %type <identifier_> XMLCDATA
538 %type <identifier_> XMLElement
539 %type <identifier_> XMLElementContent
540 %type <identifier_> XMLMarkup
541 %type <identifier_> XMLPI
543 %type <attribute_> AttributeIdentifier
544 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
545 %type <expression_> PropertyIdentifier
546 %type <expression_> XMLListInitialiser
547 %type <expression_> XMLInitialiser
550 /* Token Priorities {{{ */
562 /* Lexer State {{{ */
564 : { driver.in_.push(true); }
568 : { driver.in_.push(false); }
572 : { driver.in_.pop(); }
576 : { driver.SetCondition(CYDriver::RegExpCondition); }
580 : { if (yyla.empty()) driver.no_.OpenBrace = true; else if (yyla.type == yytranslate_(token::OpenBrace) || yyla.type == yytranslate_(token::OpenBrace_)) yyla.type = yytranslate_(token::OpenBrace__); }
584 : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::_function_)) yyla.type = yytranslate_(token::_function__); }
587 LexNoAtImplementation :
589 { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::At_implementation_)) yyla.type = yytranslate_(token::At_implementation__); }
594 : LexNoBrace LexNoFunction LexNoAtImplementation
597 /* Virtual Tokens {{{ */
608 /* 7.6 Identifier Names and Identifiers {{{ */
619 : Identifier { $$ = $1; }
621 | "auto" { $$ = CYNew CYWord("auto"); }
622 | "break" NewLineOpt { $$ = CYNew CYWord("break"); }
623 | "case" { $$ = CYNew CYWord("case"); }
624 | "catch" { $$ = CYNew CYWord("catch"); }
625 | "class" { $$ = CYNew CYWord("class"); }
626 | "const" { $$ = CYNew CYWord("const"); }
627 | "continue" NewLineOpt { $$ = CYNew CYWord("continue"); }
628 | "debugger" { $$ = CYNew CYWord("debugger"); }
629 | "default" { $$ = CYNew CYWord("default"); }
630 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
631 | "do" { $$ = CYNew CYWord("do"); }
632 | "else" { $$ = CYNew CYWord("else"); }
633 | "enum" { $$ = CYNew CYWord("enum"); }
634 | "export" { $$ = CYNew CYWord("export"); }
635 | "extends" { $$ = CYNew CYWord("extends"); }
636 | "false" { $$ = CYNew CYWord("false"); }
637 | "finally" { $$ = CYNew CYWord("finally"); }
638 /* XXX: | "for" { $$ = CYNew CYWord("for"); } */
639 | "function" { $$ = CYNew CYWord("function"); }
640 | "if" { $$ = CYNew CYWord("if"); }
641 | "import" { $$ = CYNew CYWord("import"); }
642 /* XXX: | "in" { $$ = CYNew CYWord("in"); } */
643 | "!in" { $$ = CYNew CYWord("in"); }
644 /* XXX: | "instanceof" { $$ = CYNew CYWord("instanceof"); } */
646 // XXX: as it currently is not an Identifier
647 | "let" { $$ = CYNew CYIdentifier("let"); }
649 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
650 | "null" { $$ = CYNew CYWord("null"); }
651 | "return" NewLineOpt { $$ = CYNew CYWord("return"); }
652 | "super" { $$ = CYNew CYWord("super"); }
653 | "switch" { $$ = CYNew CYWord("switch"); }
654 | "this" { $$ = CYNew CYWord("this"); }
655 | "throw" NewLineOpt { $$ = CYNew CYWord("throw"); }
656 | "true" { $$ = CYNew CYWord("true"); }
657 | "try" { $$ = CYNew CYWord("try"); }
658 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
659 | "var" { $$ = CYNew CYWord("var"); }
660 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
661 | "while" { $$ = CYNew CYWord("while"); }
662 | "with" { $$ = CYNew CYWord("with"); }
673 : Identifier_ { $$ = $1; }
675 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
676 | "await" { $$ = CYNew CYIdentifier("await"); }
677 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
678 | "byte" { $$ = CYNew CYIdentifier("byte"); }
679 | "double" { $$ = CYNew CYIdentifier("double"); }
680 | "final" { $$ = CYNew CYIdentifier("final"); }
681 | "float" { $$ = CYNew CYIdentifier("float"); }
682 | "goto" { $$ = CYNew CYIdentifier("goto"); }
683 | "implements" { $$ = CYNew CYIdentifier("implements"); }
684 | "interface" { $$ = CYNew CYIdentifier("interface"); }
685 | "native" { $$ = CYNew CYIdentifier("native"); }
686 | "package" { $$ = CYNew CYIdentifier("package"); }
687 | "private" { $$ = CYNew CYIdentifier("private"); }
688 | "protected" { $$ = CYNew CYIdentifier("protected"); }
689 | "public" { $$ = CYNew CYIdentifier("public"); }
690 | "static" { $$ = CYNew CYIdentifier("static"); }
691 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
692 | "throws" { $$ = CYNew CYIdentifier("throws"); }
693 | "transient" { $$ = CYNew CYIdentifier("transient"); }
695 // XXX: currently I only have this as Word
696 // | "let" { $$ = CYNew CYIdentifier("let"); }
698 | "yield" NewLineOpt { $$ = CYNew CYIdentifier("yield"); }
700 | "each" { $$ = CYNew CYIdentifier("each"); }
701 | "of" { $$ = CYNew CYIdentifier("of"); }
704 | "bool" { $$ = CYNew CYIdentifier("bool"); }
705 | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); }
706 | "id" { $$ = CYNew CYIdentifier("id"); }
707 | "SEL" { $$ = CYNew CYIdentifier("SEL"); }
713 | "char" { $$ = CYNew CYIdentifier("char"); }
714 | "int" { $$ = CYNew CYIdentifier("int"); }
715 | "long" { $$ = CYNew CYIdentifier("long"); }
716 | "short" { $$ = CYNew CYIdentifier("short"); }
717 | "undefined" { $$ = CYNew CYIdentifier("undefined"); }
718 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
720 | "extern" { $$ = CYNew CYIdentifier("extern"); }
721 | "signed" { $$ = CYNew CYIdentifier("signed"); }
722 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
723 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
726 | "nil" { $$ = CYNew CYIdentifier("nil"); }
727 | "NO" { $$ = CYNew CYIdentifier("NO"); }
728 | "NULL" { $$ = CYNew CYIdentifier("NULL"); }
729 | "YES" { $$ = CYNew CYIdentifier("YES"); }
734 : Identifier { $$ = $1; }
739 /* 7.8 Literals {{{ */
741 : NullLiteral { $$ = $1; }
742 | ValueLiteral { $$ = $1; }
746 : BooleanLiteral { $$ = $1; }
747 | NumericLiteral { $$ = $1; }
748 | StringLiteral { $$ = $1; }
749 | RegularExpressionLiteral { $$ = $1; }
752 /* 7.8.1 Null Literals {{{ */
754 : "null" { $$ = CYNew CYNull(); }
757 /* 7.8.2 Boolean Literals {{{ */
759 : "true" { $$ = CYNew CYTrue(); }
760 | "false" { $$ = CYNew CYFalse(); }
764 /* 7.9 Automatic Semicolon Insertion {{{ */
766 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
771 | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !yyla.value.newline_) { error(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
776 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
780 /* 11.1 Primary Expressions {{{ */
782 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
786 : Identifier { $$ = CYNew CYVariable($1); }
790 : "this" { $$ = CYNew CYThis(); }
791 | Variable { $$ = $1; }
792 | Literal { $$ = $1; }
793 | ArrayInitialiser { $$ = $1; }
794 | ObjectLiteral { $$ = $1; }
795 | Parenthetical { $$ = $1; }
796 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
799 /* 11.1.4 Array Initializer {{{ */
801 : ArrayLiteral { $$ = $1; }
802 | ArrayComprehension { $$ = $1; }
805 /* 11.1.4.1 Array Literal {{{ */
807 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
811 : AssignmentExpression { $$ = $1; }
815 : Element { $$ = $1; }
816 | LexSetRegExp { $$ = NULL; }
820 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
821 | Element { $$ = CYNew CYElement($1, NULL); }
825 : ElementList { $$ = $1; }
826 | LexSetRegExp { $$ = NULL; }
829 /* 11.1.4.2 Array Comprehension {{{ */
831 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
835 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
840 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
841 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
845 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
849 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
852 /* 11.1.5 Object Initialiser {{{ */
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; }
890 /* 11.2 Left-Hand-Side Expressions {{{ */
892 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
893 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
894 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
898 : MemberExpression { $$ = $1; }
899 //| "super" { $$ = $1; }
903 : LexSetRegExp PrimaryExpression { $$ = $2; }
904 | LexSetRegExp FunctionExpression { $$ = $2; }
905 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
906 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
910 : MemberExpression { $$ = $1; }
911 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
920 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
921 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
925 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
929 : "," ArgumentList { $$ = $2; }
934 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
935 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
939 : ArgumentList { $$ = $1; }
940 | LexSetRegExp { $$ = NULL; }
943 LeftHandSideExpression
944 : NewExpression { $$ = $1; }
945 | CallExpression { $$ = $1; }
948 /* 11.3 Postfix Expressions {{{ */
950 : %prec "" LeftHandSideExpression { $$ = $1; }
951 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
952 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
955 /* 11.4 Unary Operators {{{ */
957 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
958 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
959 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
960 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
961 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
962 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
963 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
964 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
965 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
966 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
967 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
971 : PostfixExpression { $$ = $1; }
972 | LexSetRegExp UnaryExpression_ { $$ = $2; }
975 /* 11.5 Multiplicative Operators {{{ */
976 MultiplicativeExpression
977 : UnaryExpression { $$ = $1; }
978 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
979 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
980 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
983 /* 11.6 Additive Operators {{{ */
985 : MultiplicativeExpression { $$ = $1; }
986 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
987 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
990 /* 11.7 Bitwise Shift Operators {{{ */
992 : AdditiveExpression { $$ = $1; }
993 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
994 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
995 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
998 /* 11.8 Relational Operators {{{ */
1000 : ShiftExpression { $$ = $1; }
1001 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
1002 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
1003 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
1004 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
1005 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
1006 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
1009 /* 11.9 Equality Operators {{{ */
1011 : RelationalExpression { $$ = $1; }
1012 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1013 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1014 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1015 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1018 /* 11.10 Binary Bitwise Operators {{{ */
1019 BitwiseANDExpression
1020 : EqualityExpression { $$ = $1; }
1021 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1024 BitwiseXORExpression
1025 : BitwiseANDExpression { $$ = $1; }
1026 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1030 : BitwiseXORExpression { $$ = $1; }
1031 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1034 /* 11.11 Binary Logical Operators {{{ */
1035 LogicalANDExpression
1036 : BitwiseORExpression { $$ = $1; }
1037 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1041 : LogicalANDExpression { $$ = $1; }
1042 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1045 /* 11.12 Conditional Operator ( ? : ) {{{ */
1046 ConditionalExpression
1047 : LogicalORExpression { $$ = $1; }
1048 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1049 | LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1052 /* 11.13 Assignment Operators {{{ */
1053 AssignmentExpression
1054 : ConditionalExpression { $$ = $1; }
1055 | ArrowFunction { $$ = $1; }
1056 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1057 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1058 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1059 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1060 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1061 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1062 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1063 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1064 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1065 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1066 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1067 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1070 /* 11.14 Comma Operator {{{ */
1072 : AssignmentExpression { $$ = $1; }
1073 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
1077 : Expression { $$ = $1; }
1078 | LexSetRegExp { $$ = NULL; }
1082 /* 12 Statements {{{ */
1084 : Block { $$ = $1; }
1085 | VariableStatement { $$ = $1; }
1086 | EmptyStatement { $$ = $1; }
1087 | IfStatement { $$ = $1; }
1088 | BreakableStatement { $$ = $1; }
1089 | ContinueStatement { $$ = $1; }
1090 | BreakStatement { $$ = $1; }
1091 | ReturnStatement { $$ = $1; }
1092 | WithStatement { $$ = $1; }
1093 | LabelledStatement { $$ = $1; }
1094 | ThrowStatement { $$ = $1; }
1095 | TryStatement { $$ = $1; }
1096 | DebuggerStatement { $$ = $1; }
1100 : LexSetRegExp Statement__ { $$ = $2; }
1101 | ExpressionStatement { $$ = $1; }
1105 : LexSetStatement Statement_ { $$ = $2; }
1109 : FunctionDeclaration { $$ = $1; }
1110 | LexicalDeclaration { $$ = $1; }
1114 : LexSetRegExp Declaration__ { $$ = $2; }
1118 : LexSetStatement Declaration_ { $$ = $2; }
1122 : IterationStatement { $$ = $1; }
1123 | SwitchStatement { $$ = $1; }
1126 /* 12.1 Block {{{ */
1128 : BRACE StatementListOpt "}" { $$ = $2; }
1132 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1136 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1140 : StatementList { $$ = $1; }
1141 | LexSetStatement LexSetRegExp { $$ = NULL; }
1145 : Statement { $$ = $1; }
1146 | Declaration { $$ = $1; }
1150 /* 12.2 Declarations {{{ */
1152 : Identifier { $$ = $1; }
1159 // XXX: BindingPattern
1161 /* 12.2.1 Let and Const Declarations {{{ */
1163 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1171 /* 12.2.2 Variable Statement {{{ */
1173 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1176 VariableDeclarationList_
1177 : "," VariableDeclarationList { $$ = $2; }
1181 VariableDeclarationList
1182 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1186 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1187 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1191 : "=" AssignmentExpression { $$ = $2; }
1195 : Initialiser { $$ = $1; }
1199 /* 12.2.4 Destructuring Binding Patterns {{{ */
1203 : SingleNameBinding { $$ = $1; }
1207 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1211 /* 12.3 Empty Statement {{{ */
1213 : ";" { $$ = CYNew CYEmpty(); }
1216 /* 12.4 Expression Statement {{{ */
1218 : Expression Terminator { $$ = CYNew CYExpress($1); }
1221 /* 12.5 The if Statement {{{ */
1223 : "else" Statement { $$ = $2; }
1224 | %prec "if" { $$ = NULL; }
1228 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1232 /* 12.6.1 The do-while Statement {{{ */
1234 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1237 /* 12.6.2 The while Statement {{{ */
1239 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1242 /* 12.6.3 The for Statement {{{ */
1244 : "for" "(" LexPushInOn ForStatementInitialiser ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1247 ForStatementInitialiser
1248 : ExpressionOpt { $$ = $1; }
1249 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1252 /* 12.6.4 The for-in and for-of Statements {{{ */
1254 : "for" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1255 | "for" "(" LexPushInOn ForInStatementInitialiser "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1258 ForInStatementInitialiser
1259 : LeftHandSideExpression { $$ = $1; }
1260 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1264 /* 12.7 The continue Statement {{{ */
1266 : "continue" "\n" StrictSemi { $$ = CYNew CYContinue(NULL); }
1267 | "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1270 /* 12.8 The break Statement {{{ */
1272 : "break" "\n" StrictSemi { $$ = CYNew CYBreak(NULL); }
1273 | "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1276 /* 12.9 The return Statement {{{ */
1278 : "return" LexSetRegExp "\n" StrictSemi { $$ = CYNew CYReturn(NULL); }
1279 | "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1282 /* 12.10 The with Statement {{{ */
1284 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1288 /* 12.11 The switch Statement {{{ */
1290 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1294 : BRACE CaseClausesOpt "}" { $$ = $2; }
1298 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1302 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1303 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1308 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1311 /* 12.12 Labelled Statements {{{ */
1313 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1316 /* 12.13 The throw Statement {{{ */
1318 : "throw" LexSetRegExp "\n" StrictSemi { error(@1, "throw without exception"); }
1319 | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1322 /* 12.14 The try Statement {{{ */
1324 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1328 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1333 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1337 /* 12.14 The debugger Statement {{{ */
1339 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1343 /* 13.1 Function Definitions {{{ */
1345 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1349 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1352 FormalParameterList_
1353 : "," FormalParameterList { $$ = $2; }
1358 // XXX: : FunctionRestParameter { $$ = $1; }
1359 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1362 FormalParameterListOpt
1363 : FormalParameterList
1367 /* XXX: FunctionRestParameter
1368 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1372 : BindingElement { $$ = $1; }
1376 : StatementListOpt { $$ = $1; }
1379 /* 13.2 Arrow Function Definitions {{{ */
1381 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1385 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1386 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
1387 | Parenthetical { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); }
1391 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1392 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1395 /* 14 Program {{{ */
1397 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1401 : StatementList { $$ = $1; }
1405 : ProgramBody { $$ = $1; }
1406 | LexSetStatement LexSetRegExp { $$ = NULL; }
1411 /* Cycript (C): Type Encoding {{{ */
1413 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1414 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1418 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1419 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1420 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1421 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1422 | TypeSignifier { $$ = $1; }
1423 | { $$ = CYNew CYTypedIdentifier(@$); }
1427 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1432 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1433 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1437 : PrefixedType { $$ = $1; }
1438 | SuffixedType { $$ = $1; }
1439 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1440 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1444 : "int" { $$ = CYNew CYTypeVariable("int"); }
1445 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1446 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1447 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1448 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1452 : IntegerType { $$ = $1; }
1453 | { $$ = CYNew CYTypeVariable("int"); }
1457 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1458 | IntegerType { $$ = $1; }
1459 | "void" { $$ = CYNew CYTypeVoid(); }
1460 | "char" { $$ = CYNew CYTypeVariable("char"); }
1461 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1462 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1466 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1470 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1476 /* Cycript (Objective-C): @class Declaration {{{ */
1478 /* XXX: why the hell did I choose MemberExpression? */
1479 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1484 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1485 | LexSetRegExp { $$ = NULL; }
1489 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1493 : "+" { $$ = false; }
1494 | "-" { $$ = true; }
1498 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; }
1499 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1503 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1506 MessageParameterList
1507 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1510 MessageParameterListOpt
1511 : MessageParameterList { $$ = $1; }
1516 : MessageParameterList { $$ = $1; }
1517 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1520 ClassMessageDeclaration
1521 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1524 ClassMessageDeclarationListOpt
1525 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1526 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1531 : Identifier { $$ = $1; }
1532 | "(" AssignmentExpression ")" { $$ = $2; }
1536 : ClassName { $$ = $1; }
1540 // XXX: this should be AssignmentExpressionNoRight
1542 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1546 : "," ClassProtocols { $$ = $2; }
1550 ClassProtocolListOpt
1551 : "<" ClassProtocols ">" { $$ = $2; }
1556 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1560 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1568 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1572 : ClassExpression { $$ = $1; }
1576 : ClassStatement { $$ = $1; }
1577 | CategoryStatement { $$ = $1; }
1580 /* Cycript (Objective-C): Send Message {{{ */
1582 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1587 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1588 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1592 : SelectorCall { $$ = $1; }
1593 | VariadicCall { $$ = $1; }
1597 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1601 : SelectorCall { $$ = $1; }
1602 | Word { $$ = CYNew CYArgument($1, NULL); }
1606 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1607 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1611 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1615 : SelectorExpression_ { $$ = $1; }
1616 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1619 SelectorExpressionOpt
1620 : SelectorExpression_ { $$ = $1; }
1625 : MessageExpression { $$ = $1; }
1626 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1631 /* Cycript: @import Directive {{{ */
1633 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1634 | Word { $$ = CYNew CYModule($1); }
1638 : "@import" Module { $$ = CYNew CYImport($2); }
1643 /* Cycript (Objective-C): Boxed Expressions {{{ */
1645 : NullLiteral { $$ = $1; }
1646 | BooleanLiteral { $$ = $1; }
1647 | NumericLiteral { $$ = $1; }
1648 | StringLiteral { $$ = $1; }
1649 | ArrayLiteral { $$ = $1; }
1650 | ObjectLiteral { $$ = $1; }
1651 | Parenthetical { $$ = $1; }
1652 | "YES" { $$ = CYNew CYTrue(); }
1653 | "NO" { $$ = CYNew CYFalse(); }
1657 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1658 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1659 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1660 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1661 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1662 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
1665 /* Cycript (Objective-C): Block Expressions {{{ */
1667 : "^" 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"); }
1670 /* Cycript (Objective-C): Instance Literals {{{ */
1672 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1678 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1679 LeftHandSideExpression
1680 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1684 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1688 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1689 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1690 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1693 /* Cycript (C): auto Compatibility {{{ */
1698 /* Cycript (C): Lambda Expressions {{{ */
1700 : "," TypedParameterList { $$ = $2; }
1705 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1708 TypedParameterListOpt
1709 : TypedParameterList { $$ = $1; }
1714 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1717 /* Cycript (C): Type Definitions {{{ */
1719 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
1722 /* Cycript (C): extern "C" {{{ */
1724 : "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); }
1730 /* YUI: Documentation Comments {{{ */
1732 : Comment { $$ = $1; }
1737 /* Lexer State {{{ */
1739 : { driver.PushCondition(CYDriver::RegExpCondition); }
1743 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1747 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1751 : { driver.PopCondition(); }
1755 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1759 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1762 /* Virtual Tokens {{{ */
1769 /* 8.1 Context Keywords {{{ */
1771 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
1772 | "xml" { $$ = CYNew CYIdentifier("xml"); }
1775 /* 8.3 XML Initialiser Input Elements {{{ */
1777 : XMLComment { $$ = $1; }
1778 | XMLCDATA { $$ = $1; }
1779 | XMLPI { $$ = $1; }
1783 /* 11.1 Primary Expressions {{{ */
1785 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1786 | XMLInitialiser { $$ = $1; }
1787 | XMLListInitialiser { $$ = $1; }
1791 : AttributeIdentifier { $$ = $1; }
1792 | QualifiedIdentifier { $$ = $1; }
1793 | WildcardIdentifier { $$ = $1; }
1796 /* 11.1.1 Attribute Identifiers {{{ */
1798 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1802 : PropertySelector { $$ = $1; }
1803 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1807 : Identifier { $$ = CYNew CYSelector($1); }
1808 | WildcardIdentifier { $$ = $1; }
1811 /* 11.1.2 Qualified Identifiers {{{ */
1812 QualifiedIdentifier_
1813 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1814 | QualifiedIdentifier { $$ = $1; }
1818 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1821 /* 11.1.3 Wildcard Identifiers {{{ */
1823 : "*" { $$ = CYNew CYWildcard(); }
1826 /* 11.1.4 XML Initialiser {{{ */
1828 : XMLMarkup { $$ = $1; }
1829 | XMLElement { $$ = $1; }
1833 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1834 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1838 : LexPushXMLTag XMLTagName XMLAttributes
1842 : BRACE LexPushRegExp Expression LexPop "}"
1851 : XMLAttributes_ XMLAttribute
1856 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1857 | XMLAttributes_ XMLWhitespaceOpt
1866 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1870 : XMLExpression XMLElementContentOpt
1871 | XMLMarkup XMLElementContentOpt
1872 | XMLText XMLElementContentOpt
1873 | XMLElement XMLElementContentOpt
1876 XMLElementContentOpt
1881 /* 11.1.5 XMLList Initialiser {{{ */
1883 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1887 /* 11.2 Left-Hand-Side Expressions {{{ */
1889 : Identifier { $$ = $1; }
1890 | PropertyIdentifier { $$ = $1; }
1894 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1895 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1896 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1899 /* 12.1 The default xml namespace Statement {{{ */
1900 /* XXX: DefaultXMLNamespaceStatement
1901 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1905 : DefaultXMLNamespaceStatement { $$ = $1; }
1910 /* JavaScript 1.7: Array Comprehensions {{{ */
1912 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1916 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1917 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1920 /* JavaScript 1.7: for each {{{ */
1922 : "for" "each" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1925 /* JavaScript 1.7: let Statements {{{ */
1927 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1935 /* JavaScript FTW: Ruby Blocks {{{ */
1936 RubyProcParameterList_
1937 : "," RubyProcParameterList { $$ = $2; }
1941 RubyProcParameterList
1942 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1947 : "|" RubyProcParameterList "|" { $$ = $2; }
1948 | "||" { $$ = NULL; }
1951 RubyProcParametersOpt
1952 : RubyProcParameters
1957 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1961 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
1965 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }