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 CYDriver::Condition condition_;
52 CYArgument *argument_;
53 CYAssignment *assignment_;
56 cy::Syntax::Catch *catch_;
58 CYComprehension *comprehension_;
59 CYDeclaration *declaration_;
60 CYDeclarations *declarations_;
62 CYExpression *expression_;
65 CYForInitialiser *for_;
66 CYForInInitialiser *forin_;
67 CYFunctionParameter *functionParameter_;
68 CYIdentifier *identifier_;
75 CYParenthetical *parenthetical_;
77 CYProperty *property_;
78 CYPropertyName *propertyName_;
79 CYRubyProc *rubyProc_;
80 CYStatement *statement_;
87 CYTypeModifier *modifier_;
88 CYTypeSpecifier *specifier_;
89 CYTypedIdentifier *typedIdentifier_;
90 CYTypedParameter *typedParameter_;
94 CYClassName *className_;
95 CYClassField *classField_;
97 CYMessageParameter *messageParameter_;
98 CYProtocol *protocol_;
99 CYSelectorPart *selector_;
103 CYAttribute *attribute_;
104 CYPropertyIdentifier *propertyIdentifier_;
105 CYSelector *selector_;
110 #define YYSTYPE YYSTYPE
114 int cylex(YYSTYPE *, CYLocation *, void *);
122 @$.begin.filename = @$.end.filename = &driver.filename_;
128 %define api.location.type { CYLocation }
135 %parse-param { CYDriver &driver }
136 %lex-param { void *cyscanner }
138 /* Token Declarations {{{ */
144 %token XMLAttributeValue
146 %token XMLTagCharacters
152 %token LeftRight "<>"
153 %token LeftSlashRight "</>"
155 %token SlashRight "/>"
156 %token LeftSlash "</"
158 %token ColonColon "::"
159 %token PeriodPeriod ".."
162 @begin E4X ObjectiveC
168 %token AmpersandAmpersand "&&"
169 %token AmpersandEqual "&="
171 %token CarrotEqual "^="
173 %token EqualEqual "=="
174 %token EqualEqualEqual "==="
175 %token EqualRight "=>"
176 %token EqualRight_ "\n=>"
177 %token Exclamation "!"
178 %token ExclamationEqual "!="
179 %token ExclamationEqualEqual "!=="
181 %token HyphenEqual "-="
182 %token HyphenHyphen "--"
183 %token HyphenHyphen_ "\n--"
184 %token HyphenRight "->"
186 %token LeftEqual "<="
188 %token LeftLeftEqual "<<="
190 %token PercentEqual "%="
192 %token PeriodPeriodPeriod "..."
194 %token PipeEqual "|="
197 %token PlusEqual "+="
199 %token PlusPlus_ "\n++"
201 %token RightEqual ">="
202 %token RightRight ">>"
203 %token RightRightEqual ">>="
204 %token RightRightRight ">>>"
205 %token RightRightRightEqual ">>>="
207 %token SlashEqual "/="
209 %token StarEqual "*="
218 %token <comment_> Comment
221 %token CloseParen ")"
224 %token OpenBrace_ "\n{"
225 %token OpenBrace__ ";{"
226 %token CloseBrace "}"
228 %token OpenBracket "["
229 %token CloseBracket "]"
231 %token AtError "@error"
234 %token AtClass "@class"
238 %token <identifier_> Typedef "typedef"
239 %token <identifier_> Unsigned "unsigned"
240 %token <identifier_> Signed "signed"
241 %token <identifier_> Extern "extern"
245 %token AtEncode "@encode"
249 %token AtImplementation "@implementation"
250 %token AtImplementation_ ";@implementation"
251 %token AtImport "@import"
253 %token AtSelector "@selector"
254 %token AtNull "@null"
257 %token AtTrue "@true"
258 %token AtFalse "@false"
259 %token <identifier_> Yes "YES"
260 %token <identifier_> No "NO"
267 // ES3/ES5/WIE/JSC Reserved
272 %token Continue "continue"
273 %token Default "default"
274 %token Delete "delete"
277 %token Finally "finally"
279 %token Function "function"
280 %token Function_ ";function"
284 %token InstanceOf "instanceof"
286 %token Return "return"
287 %token Switch "switch"
291 %token TypeOf "typeof"
297 // ES3/IE6 Future, ES5/JSC Reserved
298 %token Debugger "debugger"
300 // ES3/ES5/IE6 Future, JSC Reserved
303 // ES3/ES5/IE6/JSC Future
306 %token Export "export"
307 %token Extends "extends"
308 %token Import "import"
311 // ES3 Future, ES5 Strict Future
312 %token <identifier_> Implements "implements"
313 %token <identifier_> Interface "interface"
314 %token <identifier_> Package "package"
315 %token <identifier_> Private "private"
316 %token <identifier_> Protected "protected"
317 %token <identifier_> Public "public"
318 %token <identifier_> Static "static"
321 %token <identifier_> Abstract "abstract"
322 %token <identifier_> Boolean "boolean"
323 %token <identifier_> Byte "byte"
324 %token <identifier_> Char "char"
325 %token <identifier_> Double "double"
326 %token <identifier_> Final "final"
327 %token <identifier_> Float "float"
328 %token <identifier_> Goto "goto"
329 %token <identifier_> Int "int"
330 %token <identifier_> Long "long"
331 %token <identifier_> Native "native"
332 %token <identifier_> Short "short"
333 %token <identifier_> Synchronized "synchronized"
334 %token <identifier_> Throws "throws"
335 %token <identifier_> Transient "transient"
336 %token <identifier_> Volatile "volatile"
339 %token <identifier_> Let "let"
340 %token <identifier_> Yield "yield"
343 %token <identifier_> Each "each"
344 %token <identifier_> Of "of"
348 %token <identifier_> Namespace "namespace"
349 %token <identifier_> XML "xml"
354 %token <identifier_> Identifier_
355 %token <number_> NumericLiteral
356 %token <string_> StringLiteral
357 %token <literal_> RegularExpressionLiteral
359 %type <expression_> AdditiveExpression
360 %type <argument_> ArgumentList_
361 %type <argument_> ArgumentList
362 %type <argument_> ArgumentListOpt
363 %type <argument_> Arguments
364 %type <expression_> ArrayComprehension
365 %type <expression_> ArrayInitialiser
366 %type <literal_> ArrayLiteral
367 %type <expression_> ArrowFunction
368 %type <functionParameter_> ArrowParameters
369 %type <expression_> AssignmentExpression
370 %type <identifier_> Binding
371 %type <identifier_> BindingIdentifier
372 %type <expression_> BitwiseANDExpression
373 %type <statement_> Block_
374 %type <statement_> Block
375 %type <boolean_> BooleanLiteral
376 %type <declaration_> BindingElement
377 %type <expression_> BitwiseORExpression
378 %type <expression_> BitwiseXORExpression
379 %type <statement_> BreakStatement
380 %type <statement_> BreakableStatement
381 %type <expression_> CallExpression_
382 %type <expression_> CallExpression
383 %type <clause_> CaseBlock
384 %type <clause_> CaseClause
385 %type <clause_> CaseClausesOpt
386 %type <catch_> CatchOpt
387 %type <expression_> Comprehension
388 %type <comprehension_> ComprehensionFor
389 %type <comprehension_> ComprehensionIf
390 %type <comprehension_> ComprehensionTail
391 %type <expression_> ConditionalExpression
392 %type <statement_> ContinueStatement
393 %type <statement_> ConciseBody
394 %type <statement_> DebuggerStatement
395 %type <statement_> Declaration__
396 %type <statement_> Declaration_
397 %type <statement_> Declaration
398 %type <clause_> DefaultClause
399 %type <expression_> Element
400 %type <expression_> ElementOpt
401 %type <element_> ElementList
402 %type <element_> ElementListOpt
403 %type <statement_> ElseStatementOpt
404 %type <statement_> EmptyStatement
405 %type <expression_> EqualityExpression
406 %type <expression_> Expression
407 %type <expression_> ExpressionOpt
408 %type <statement_> ExpressionStatement
409 %type <finally_> FinallyOpt
410 %type <for_> ForStatementInitialiser
411 %type <forin_> ForInStatementInitialiser
412 %type <declaration_> FormalParameter
413 %type <functionParameter_> FormalParameterList_
414 %type <functionParameter_> FormalParameterList
415 %type <functionParameter_> FormalParameterListOpt
416 %type <statement_> FunctionBody
417 %type <statement_> FunctionDeclaration
418 %type <expression_> FunctionExpression
419 %type <identifier_> Identifier
420 %type <identifier_> IdentifierOpt
421 %type <identifier_> IdentifierType
422 %type <word_> IdentifierName
423 %type <statement_> IfStatement
424 %type <expression_> Initialiser
425 %type <expression_> InitialiserOpt
426 %type <statement_> IterationStatement
427 %type <statement_> LabelledStatement
428 %type <expression_> LeftHandSideExpression
429 %type <statement_> LetStatement
430 %type <statement_> LexicalDeclaration
431 %type <literal_> Literal
432 %type <literal_> ValueLiteral
433 %type <expression_> LogicalANDExpression
434 %type <expression_> LogicalORExpression
435 %type <member_> MemberAccess
436 %type <expression_> MemberExpression_
437 %type <expression_> MemberExpression
438 %type <module_> Module
439 %type <expression_> MultiplicativeExpression
440 %type <expression_> NewExpression
441 %type <null_> NullLiteral
442 %type <literal_> ObjectLiteral
443 %type <parenthetical_> Parenthetical
444 %type <expression_> PostfixExpression
445 %type <expression_> PrimaryExpression
446 %type <statement_> Program
447 %type <statement_> ProgramBody
448 %type <statement_> ProgramBodyOpt
449 %type <propertyName_> PropertyName_
450 %type <propertyName_> PropertyName
451 %type <property_> PropertyDefinition
452 %type <property_> PropertyDefinitionList_
453 %type <property_> PropertyDefinitionList
454 %type <property_> PropertyDefinitionListOpt
455 %type <expression_> RelationalExpression
456 %type <statement_> ReturnStatement
457 %type <rubyProc_> RubyProcExpression
458 %type <functionParameter_> RubyProcParameterList_
459 %type <functionParameter_> RubyProcParameterList
460 %type <functionParameter_> RubyProcParameters
461 %type <functionParameter_> RubyProcParametersOpt
462 %type <expression_> ShiftExpression
463 %type <declaration_> SingleNameBinding
464 %type <statement_> Statement__
465 %type <statement_> Statement_
466 %type <statement_> Statement
467 %type <statement_> StatementList
468 %type <statement_> StatementListOpt
469 %type <statement_> StatementListItem
470 %type <statement_> SwitchStatement
471 %type <statement_> ThrowStatement
472 %type <statement_> TryStatement
473 %type <expression_> UnaryExpression_
474 %type <expression_> UnaryExpression
475 %type <declaration_> VariableDeclaration
476 %type <declarations_> VariableDeclarationList_
477 %type <declarations_> VariableDeclarationList
478 %type <statement_> VariableStatement
479 %type <statement_> WithStatement
482 %type <word_> WordOpt
484 %type <expression_> Variable
487 %type <specifier_> IntegerType
488 %type <specifier_> IntegerTypeOpt
489 %type <typedIdentifier_> PrefixedType
490 %type <specifier_> PrimitiveType
491 %type <typedIdentifier_> SuffixedType
492 %type <typedIdentifier_> TypeSignifier
493 %type <modifier_> TypeQualifierLeft
494 %type <typedIdentifier_> TypeQualifierRight
495 %type <typedIdentifier_> TypedIdentifier
496 %type <typedParameter_> TypedParameterList_
497 %type <typedParameter_> TypedParameterList
498 %type <typedParameter_> TypedParameterListOpt
502 %type <expression_> BoxableExpression
503 %type <statement_> CategoryStatement
504 %type <expression_> ClassExpression
505 %type <classField_> ClassFieldListOpt
506 %type <classField_> ClassFields
507 %type <statement_> ClassStatement
508 %type <expression_> ClassSuperOpt
509 %type <message_> ClassMessageDeclaration
510 %type <message_> ClassMessageDeclarationListOpt
511 %type <className_> ClassName
512 %type <className_> ClassNameOpt
513 %type <protocol_> ClassProtocolListOpt
514 %type <protocol_> ClassProtocols
515 %type <protocol_> ClassProtocolsOpt
516 %type <expression_> MessageExpression
517 %type <messageParameter_> MessageParameter
518 %type <messageParameter_> MessageParameters
519 %type <messageParameter_> MessageParameterList
520 %type <messageParameter_> MessageParameterListOpt
521 %type <bool_> MessageScope
522 %type <argument_> SelectorCall_
523 %type <argument_> SelectorCall
524 %type <selector_> SelectorExpression_
525 %type <selector_> SelectorExpression
526 %type <selector_> SelectorExpressionOpt
527 %type <argument_> SelectorList
528 %type <word_> SelectorWordOpt
529 %type <typedIdentifier_> TypeOpt
530 %type <argument_> VariadicCall
534 %type <propertyIdentifier_> PropertyIdentifier_
535 %type <selector_> PropertySelector_
536 %type <selector_> PropertySelector
537 %type <identifier_> QualifiedIdentifier_
538 %type <identifier_> QualifiedIdentifier
539 %type <identifier_> WildcardIdentifier
540 %type <identifier_> XMLComment
541 %type <identifier_> XMLCDATA
542 %type <identifier_> XMLElement
543 %type <identifier_> XMLElementContent
544 %type <identifier_> XMLMarkup
545 %type <identifier_> XMLPI
547 %type <attribute_> AttributeIdentifier
548 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
549 %type <expression_> PropertyIdentifier
550 %type <expression_> XMLListInitialiser
551 %type <expression_> XMLInitialiser
554 /* Token Priorities {{{ */
566 /* Lexer State {{{ */
568 : { driver.in_.push(true); }
572 : { driver.in_.push(false); }
576 : { driver.in_.pop(); }
580 : { driver.SetCondition(CYDriver::RegExpCondition); }
584 : { if (yyla.empty()) driver.no_.OpenBrace = true; else if (yyla.type == yytranslate_(token::OpenBrace) || yyla.type == yytranslate_(token::OpenBrace_)) yyla.type = yytranslate_(token::OpenBrace__); }
588 : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::Function)) yyla.type = yytranslate_(token::Function_); }
591 LexNoAtImplementation :
593 { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::AtImplementation)) yyla.type = yytranslate_(token::AtImplementation_); }
598 : LexNoBrace LexNoFunction LexNoAtImplementation
601 /* Virtual Tokens {{{ */
612 /* 7.6 Identifier Names and Identifiers {{{ */
623 : Identifier { $$ = $1; }
624 | "auto" { $$ = CYNew CYWord("auto"); }
625 | "break" NewLineOpt { $$ = CYNew CYWord("break"); }
626 | "case" { $$ = CYNew CYWord("case"); }
627 | "catch" { $$ = CYNew CYWord("catch"); }
628 | "class" { $$ = CYNew CYWord("class"); }
629 | "const" { $$ = CYNew CYWord("const"); }
630 | "continue" NewLineOpt { $$ = CYNew CYWord("continue"); }
631 | "debugger" { $$ = CYNew CYWord("debugger"); }
632 | "default" { $$ = CYNew CYWord("default"); }
633 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
634 | "do" { $$ = CYNew CYWord("do"); }
635 | "else" { $$ = CYNew CYWord("else"); }
636 | "enum" { $$ = CYNew CYWord("enum"); }
637 | "export" { $$ = CYNew CYWord("export"); }
638 | "extends" { $$ = CYNew CYWord("extends"); }
639 | "false" { $$ = CYNew CYWord("false"); }
640 | "finally" { $$ = CYNew CYWord("finally"); }
641 /* XXX: | "for" { $$ = CYNew CYWord("for"); } */
642 | "function" { $$ = CYNew CYWord("function"); }
643 | "if" { $$ = CYNew CYWord("if"); }
644 | "import" { $$ = CYNew CYWord("import"); }
645 /* XXX: | "in" { $$ = CYNew CYWord("in"); } */
646 | "!in" { $$ = CYNew CYWord("in"); }
647 /* XXX: | "instanceof" { $$ = CYNew CYWord("instanceof"); } */
649 // XXX: as it currently is not an Identifier
652 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
653 | "null" { $$ = CYNew CYWord("null"); }
654 | "return" NewLineOpt { $$ = CYNew CYWord("return"); }
655 | "super" { $$ = CYNew CYWord("super"); }
656 | "switch" { $$ = CYNew CYWord("switch"); }
657 | "this" { $$ = CYNew CYWord("this"); }
658 | "throw" NewLineOpt { $$ = CYNew CYWord("throw"); }
659 | "true" { $$ = CYNew CYWord("true"); }
660 | "try" { $$ = CYNew CYWord("try"); }
661 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
662 | "var" { $$ = CYNew CYWord("var"); }
663 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
664 | "while" { $$ = CYNew CYWord("while"); }
665 | "with" { $$ = CYNew CYWord("with"); }
676 : Identifier_ { $$ = $1; }
678 | "implements" { $$ = $1; }
679 | "interface" { $$ = $1; }
680 | "package" { $$ = $1; }
681 | "private" { $$ = $1; }
682 | "protected" { $$ = $1; }
683 | "public" { $$ = $1; }
684 | "static" { $$ = $1; }
686 | "abstract" { $$ = $1; }
687 | "boolean" { $$ = $1; }
688 | "byte" { $$ = $1; }
689 | "double" { $$ = $1; }
690 | "final" { $$ = $1; }
691 | "float" { $$ = $1; }
692 | "goto" { $$ = $1; }
693 | "native" { $$ = $1; }
694 | "synchronized" { $$ = $1; }
695 | "throws" { $$ = $1; }
696 | "transient" { $$ = $1; }
698 // XXX: currently I only have this as Word
699 // | "let" { $$ = $1; }
701 | "yield" NewLineOpt { $$ = $1; }
703 | "each" { $$ = $1; }
709 | "char" { $$ = $1; }
711 | "long" { $$ = $1; }
712 | "short" { $$ = $1; }
713 | "volatile" { $$ = $1; }
715 | "typedef" { $$ = $1; }
716 | "unsigned" { $$ = $1; }
717 | "signed" { $$ = $1; }
718 | "extern" { $$ = $1; }
727 : Identifier { $$ = $1; }
732 /* 7.8 Literals {{{ */
734 : NullLiteral { $$ = $1; }
735 | ValueLiteral { $$ = $1; }
739 : BooleanLiteral { $$ = $1; }
740 | NumericLiteral { $$ = $1; }
741 | StringLiteral { $$ = $1; }
742 | RegularExpressionLiteral { $$ = $1; }
745 /* 7.8.1 Null Literals {{{ */
747 : "null" { $$ = CYNew CYNull(); }
750 /* 7.8.2 Boolean Literals {{{ */
752 : "true" { $$ = CYNew CYTrue(); }
753 | "false" { $$ = CYNew CYFalse(); }
757 /* 7.9 Automatic Semicolon Insertion {{{ */
759 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
764 | 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
769 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
773 /* 11.1 Primary Expressions {{{ */
775 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
779 : Identifier { $$ = CYNew CYVariable($1); }
783 : "this" { $$ = CYNew CYThis(); }
784 | Variable { $$ = $1; }
785 | Literal { $$ = $1; }
786 | ArrayInitialiser { $$ = $1; }
787 | ObjectLiteral { $$ = $1; }
788 | Parenthetical { $$ = $1; }
789 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
792 /* 11.1.4 Array Initializer {{{ */
794 : ArrayLiteral { $$ = $1; }
795 | ArrayComprehension { $$ = $1; }
798 /* 11.1.4.1 Array Literal {{{ */
800 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
804 : AssignmentExpression { $$ = $1; }
808 : Element { $$ = $1; }
809 | LexSetRegExp { $$ = NULL; }
813 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
814 | Element { $$ = CYNew CYElement($1, NULL); }
818 : ElementList { $$ = $1; }
819 | LexSetRegExp { $$ = NULL; }
822 /* 11.1.4.2 Array Comprehension {{{ */
824 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
828 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
833 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
834 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
838 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
842 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
845 /* 11.1.5 Object Initialiser {{{ */
847 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
850 PropertyDefinitionList_
851 : "," PropertyDefinitionList { $$ = $2; }
852 | "," LexSetRegExp { $$ = NULL; }
856 PropertyDefinitionList
857 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
860 PropertyDefinitionListOpt
861 : PropertyDefinitionList { $$ = $1; }
862 | LexSetRegExp { $$ = NULL; }
866 // XXX: this should be IdentifierName
867 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
868 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
873 : IdentifierName { $$ = $1; }
874 | StringLiteral { $$ = $1; }
875 | NumericLiteral { $$ = $1; }
879 : LexSetRegExp PropertyName_ { $$ = $2; }
883 /* 11.2 Left-Hand-Side Expressions {{{ */
885 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
886 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
887 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
891 : MemberExpression { $$ = $1; }
892 //| "super" { $$ = $1; }
896 : LexSetRegExp PrimaryExpression { $$ = $2; }
897 | LexSetRegExp FunctionExpression { $$ = $2; }
898 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
899 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
903 : MemberExpression { $$ = $1; }
904 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
913 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
914 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
918 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
922 : "," ArgumentList { $$ = $2; }
927 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
928 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
932 : ArgumentList { $$ = $1; }
933 | LexSetRegExp { $$ = NULL; }
936 LeftHandSideExpression
937 : NewExpression { $$ = $1; }
938 | CallExpression { $$ = $1; }
941 /* 11.3 Postfix Expressions {{{ */
943 : %prec "" LeftHandSideExpression { $$ = $1; }
944 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
945 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
948 /* 11.4 Unary Operators {{{ */
950 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
951 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
952 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
953 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
954 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
955 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
956 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
957 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
958 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
959 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
960 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
964 : PostfixExpression { $$ = $1; }
965 | LexSetRegExp UnaryExpression_ { $$ = $2; }
968 /* 11.5 Multiplicative Operators {{{ */
969 MultiplicativeExpression
970 : UnaryExpression { $$ = $1; }
971 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
972 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
973 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
976 /* 11.6 Additive Operators {{{ */
978 : MultiplicativeExpression { $$ = $1; }
979 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
980 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
983 /* 11.7 Bitwise Shift Operators {{{ */
985 : AdditiveExpression { $$ = $1; }
986 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
987 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
988 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
991 /* 11.8 Relational Operators {{{ */
993 : ShiftExpression { $$ = $1; }
994 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
995 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
996 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
997 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
998 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
999 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
1002 /* 11.9 Equality Operators {{{ */
1004 : RelationalExpression { $$ = $1; }
1005 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1006 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1007 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1008 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1011 /* 11.10 Binary Bitwise Operators {{{ */
1012 BitwiseANDExpression
1013 : EqualityExpression { $$ = $1; }
1014 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1017 BitwiseXORExpression
1018 : BitwiseANDExpression { $$ = $1; }
1019 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1023 : BitwiseXORExpression { $$ = $1; }
1024 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1027 /* 11.11 Binary Logical Operators {{{ */
1028 LogicalANDExpression
1029 : BitwiseORExpression { $$ = $1; }
1030 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1034 : LogicalANDExpression { $$ = $1; }
1035 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1038 /* 11.12 Conditional Operator ( ? : ) {{{ */
1039 ConditionalExpression
1040 : LogicalORExpression { $$ = $1; }
1041 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1042 | LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1045 /* 11.13 Assignment Operators {{{ */
1046 AssignmentExpression
1047 : ConditionalExpression { $$ = $1; }
1048 | ArrowFunction { $$ = $1; }
1049 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1050 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1051 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1052 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1053 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1054 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1055 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1056 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1057 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1058 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1059 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1060 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1063 /* 11.14 Comma Operator {{{ */
1065 : AssignmentExpression { $$ = $1; }
1066 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
1070 : Expression { $$ = $1; }
1071 | LexSetRegExp { $$ = NULL; }
1075 /* 12 Statements {{{ */
1077 : Block { $$ = $1; }
1078 | VariableStatement { $$ = $1; }
1079 | EmptyStatement { $$ = $1; }
1080 | IfStatement { $$ = $1; }
1081 | BreakableStatement { $$ = $1; }
1082 | ContinueStatement { $$ = $1; }
1083 | BreakStatement { $$ = $1; }
1084 | ReturnStatement { $$ = $1; }
1085 | WithStatement { $$ = $1; }
1086 | LabelledStatement { $$ = $1; }
1087 | ThrowStatement { $$ = $1; }
1088 | TryStatement { $$ = $1; }
1089 | DebuggerStatement { $$ = $1; }
1093 : LexSetRegExp Statement__ { $$ = $2; }
1094 | ExpressionStatement { $$ = $1; }
1098 : LexSetStatement Statement_ { $$ = $2; }
1102 : FunctionDeclaration { $$ = $1; }
1103 | LexicalDeclaration { $$ = $1; }
1107 : LexSetRegExp Declaration__ { $$ = $2; }
1111 : LexSetStatement Declaration_ { $$ = $2; }
1115 : IterationStatement { $$ = $1; }
1116 | SwitchStatement { $$ = $1; }
1119 /* 12.1 Block {{{ */
1121 : BRACE StatementListOpt "}" { $$ = $2; }
1125 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1129 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1133 : StatementList { $$ = $1; }
1134 | LexSetStatement LexSetRegExp { $$ = NULL; }
1138 : Statement { $$ = $1; }
1139 | Declaration { $$ = $1; }
1143 /* 12.2 Declarations {{{ */
1145 : Identifier { $$ = $1; }
1152 // XXX: BindingPattern
1154 /* 12.2.1 Let and Const Declarations {{{ */
1156 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1164 /* 12.2.2 Variable Statement {{{ */
1166 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1169 VariableDeclarationList_
1170 : "," VariableDeclarationList { $$ = $2; }
1174 VariableDeclarationList
1175 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1179 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1180 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1184 : "=" AssignmentExpression { $$ = $2; }
1188 : Initialiser { $$ = $1; }
1192 /* 12.2.4 Destructuring Binding Patterns {{{ */
1196 : SingleNameBinding { $$ = $1; }
1200 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1204 /* 12.3 Empty Statement {{{ */
1206 : ";" { $$ = CYNew CYEmpty(); }
1209 /* 12.4 Expression Statement {{{ */
1211 : Expression Terminator { $$ = CYNew CYExpress($1); }
1214 /* 12.5 The if Statement {{{ */
1216 : "else" Statement { $$ = $2; }
1217 | %prec "if" { $$ = NULL; }
1221 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1225 /* 12.6.1 The do-while Statement {{{ */
1227 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1230 /* 12.6.2 The while Statement {{{ */
1232 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1235 /* 12.6.3 The for Statement {{{ */
1237 : "for" "(" LexPushInOn ForStatementInitialiser ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1240 ForStatementInitialiser
1241 : ExpressionOpt { $$ = $1; }
1242 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1245 /* 12.6.4 The for-in and for-of Statements {{{ */
1247 : "for" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1248 | "for" "(" LexPushInOn ForInStatementInitialiser "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1251 ForInStatementInitialiser
1252 : LeftHandSideExpression { $$ = $1; }
1253 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1257 /* 12.7 The continue Statement {{{ */
1259 : "continue" "\n" StrictSemi { $$ = CYNew CYContinue(NULL); }
1260 | "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1263 /* 12.8 The break Statement {{{ */
1265 : "break" "\n" StrictSemi { $$ = CYNew CYBreak(NULL); }
1266 | "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1269 /* 12.9 The return Statement {{{ */
1271 : "return" LexSetRegExp "\n" StrictSemi { $$ = CYNew CYReturn(NULL); }
1272 | "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1275 /* 12.10 The with Statement {{{ */
1277 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1281 /* 12.11 The switch Statement {{{ */
1283 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1287 : BRACE CaseClausesOpt "}" { $$ = $2; }
1291 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1295 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1296 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1301 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1304 /* 12.12 Labelled Statements {{{ */
1306 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1309 /* 12.13 The throw Statement {{{ */
1311 : "throw" LexSetRegExp "\n" StrictSemi { error(@1, "throw without exception"); }
1312 | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1315 /* 12.14 The try Statement {{{ */
1317 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1321 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1326 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1330 /* 12.14 The debugger Statement {{{ */
1332 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1336 /* 13.1 Function Definitions {{{ */
1338 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1342 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1345 FormalParameterList_
1346 : "," FormalParameterList { $$ = $2; }
1351 // XXX: : FunctionRestParameter { $$ = $1; }
1352 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1355 FormalParameterListOpt
1356 : FormalParameterList
1360 /* XXX: FunctionRestParameter
1361 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1365 : BindingElement { $$ = $1; }
1369 : StatementListOpt { $$ = $1; }
1372 /* 13.2 Arrow Function Definitions {{{ */
1374 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1378 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1379 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
1380 | Parenthetical { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); }
1384 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1385 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1388 /* 14 Program {{{ */
1390 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1394 : StatementList { $$ = $1; }
1398 : ProgramBody { $$ = $1; }
1399 | LexSetStatement LexSetRegExp { $$ = NULL; }
1404 /* Cycript (C): Type Encoding {{{ */
1406 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1407 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1411 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1412 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1413 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1414 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1415 | TypeSignifier { $$ = $1; }
1416 | { $$ = CYNew CYTypedIdentifier(@$); }
1420 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1425 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1426 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1430 : PrefixedType { $$ = $1; }
1431 | SuffixedType { $$ = $1; }
1432 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1433 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1437 : "int" { $$ = CYNew CYTypeVariable("int"); }
1438 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1439 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1440 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1441 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1445 : IntegerType { $$ = $1; }
1446 | { $$ = CYNew CYTypeVariable("int"); }
1450 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1451 | IntegerType { $$ = $1; }
1452 | "void" { $$ = CYNew CYTypeVoid(); }
1453 | "char" { $$ = CYNew CYTypeVariable("char"); }
1454 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1455 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1459 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1463 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1469 /* Cycript (Objective-C): @class Declaration {{{ */
1471 /* XXX: why the hell did I choose MemberExpression? */
1472 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1477 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1478 | LexSetRegExp { $$ = NULL; }
1482 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1486 : "+" { $$ = false; }
1487 | "-" { $$ = true; }
1491 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; }
1492 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1496 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1499 MessageParameterList
1500 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1503 MessageParameterListOpt
1504 : MessageParameterList { $$ = $1; }
1509 : MessageParameterList { $$ = $1; }
1510 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1513 ClassMessageDeclaration
1514 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1517 ClassMessageDeclarationListOpt
1518 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1519 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1524 : Identifier { $$ = $1; }
1525 | "(" AssignmentExpression ")" { $$ = $2; }
1529 : ClassName { $$ = $1; }
1533 // XXX: this should be AssignmentExpressionNoRight
1535 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1539 : "," ClassProtocols { $$ = $2; }
1543 ClassProtocolListOpt
1544 : "<" ClassProtocols ">" { $$ = $2; }
1549 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1553 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1561 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1565 : ClassExpression { $$ = $1; }
1569 : ClassStatement { $$ = $1; }
1570 | CategoryStatement { $$ = $1; }
1573 /* Cycript (Objective-C): Send Message {{{ */
1575 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1580 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1581 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1585 : SelectorCall { $$ = $1; }
1586 | VariadicCall { $$ = $1; }
1590 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1594 : SelectorCall { $$ = $1; }
1595 | Word { $$ = CYNew CYArgument($1, NULL); }
1599 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1600 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1604 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1608 : SelectorExpression_ { $$ = $1; }
1609 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1612 SelectorExpressionOpt
1613 : SelectorExpression_ { $$ = $1; }
1618 : MessageExpression { $$ = $1; }
1619 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1624 /* Cycript: @import Directive {{{ */
1626 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1627 | Word { $$ = CYNew CYModule($1); }
1631 : "@import" Module { $$ = CYNew CYImport($2); }
1636 /* Cycript (Objective-C): Boxed Expressions {{{ */
1638 : NullLiteral { $$ = $1; }
1639 | BooleanLiteral { $$ = $1; }
1640 | NumericLiteral { $$ = $1; }
1641 | StringLiteral { $$ = $1; }
1642 | ArrayLiteral { $$ = $1; }
1643 | ObjectLiteral { $$ = $1; }
1644 | Parenthetical { $$ = $1; }
1645 | "YES" { $$ = CYNew CYTrue(); }
1646 | "NO" { $$ = CYNew CYFalse(); }
1650 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1651 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1652 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1653 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1654 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1655 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
1658 /* Cycript (Objective-C): Block Expressions {{{ */
1660 : "^" 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"); }
1663 /* Cycript (Objective-C): Instance Literals {{{ */
1665 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1671 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1672 LeftHandSideExpression
1673 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1677 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1681 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1682 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1683 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1686 /* Cycript (C): auto Compatibility {{{ */
1691 /* Cycript (C): Lambda Expressions {{{ */
1693 : "," TypedParameterList { $$ = $2; }
1698 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1701 TypedParameterListOpt
1702 : TypedParameterList { $$ = $1; }
1707 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1710 /* Cycript (C): Type Definitions {{{ */
1712 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
1715 /* Cycript (C): extern "C" {{{ */
1717 : "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); }
1723 /* YUI: Documentation Comments {{{ */
1725 : Comment { $$ = $1; }
1730 /* Lexer State {{{ */
1732 : { driver.PushCondition(CYDriver::RegExpCondition); }
1736 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1740 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1744 : { driver.PopCondition(); }
1748 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1752 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1755 /* Virtual Tokens {{{ */
1762 /* 8.1 Context Keywords {{{ */
1764 : "namespace" { $$ = $1; }
1765 | "xml" { $$ = $1; }
1768 /* 8.3 XML Initialiser Input Elements {{{ */
1770 : XMLComment { $$ = $1; }
1771 | XMLCDATA { $$ = $1; }
1772 | XMLPI { $$ = $1; }
1776 /* 11.1 Primary Expressions {{{ */
1778 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1779 | XMLInitialiser { $$ = $1; }
1780 | XMLListInitialiser { $$ = $1; }
1784 : AttributeIdentifier { $$ = $1; }
1785 | QualifiedIdentifier { $$ = $1; }
1786 | WildcardIdentifier { $$ = $1; }
1789 /* 11.1.1 Attribute Identifiers {{{ */
1791 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1795 : PropertySelector { $$ = $1; }
1796 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1800 : Identifier { $$ = CYNew CYSelector($1); }
1801 | WildcardIdentifier { $$ = $1; }
1804 /* 11.1.2 Qualified Identifiers {{{ */
1805 QualifiedIdentifier_
1806 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1807 | QualifiedIdentifier { $$ = $1; }
1811 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1814 /* 11.1.3 Wildcard Identifiers {{{ */
1816 : "*" { $$ = CYNew CYWildcard(); }
1819 /* 11.1.4 XML Initialiser {{{ */
1821 : XMLMarkup { $$ = $1; }
1822 | XMLElement { $$ = $1; }
1826 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1827 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1831 : LexPushXMLTag XMLTagName XMLAttributes
1835 : BRACE LexPushRegExp Expression LexPop "}"
1844 : XMLAttributes_ XMLAttribute
1849 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1850 | XMLAttributes_ XMLWhitespaceOpt
1859 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1863 : XMLExpression XMLElementContentOpt
1864 | XMLMarkup XMLElementContentOpt
1865 | XMLText XMLElementContentOpt
1866 | XMLElement XMLElementContentOpt
1869 XMLElementContentOpt
1874 /* 11.1.5 XMLList Initialiser {{{ */
1876 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1880 /* 11.2 Left-Hand-Side Expressions {{{ */
1882 : Identifier { $$ = $1; }
1883 | PropertyIdentifier { $$ = $1; }
1887 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1888 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1889 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1892 /* 12.1 The default xml namespace Statement {{{ */
1893 /* XXX: DefaultXMLNamespaceStatement
1894 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1898 : DefaultXMLNamespaceStatement { $$ = $1; }
1903 /* JavaScript 1.7: Array Comprehensions {{{ */
1905 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1909 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1910 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1913 /* JavaScript 1.7: for each {{{ */
1915 : "for" "each" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1918 /* JavaScript 1.7: let Statements {{{ */
1920 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1928 /* JavaScript FTW: Ruby Blocks {{{ */
1929 RubyProcParameterList_
1930 : "," RubyProcParameterList { $$ = $2; }
1934 RubyProcParameterList
1935 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1940 : "|" RubyProcParameterList "|" { $$ = $2; }
1941 | "||" { $$ = NULL; }
1944 RubyProcParametersOpt
1945 : RubyProcParameters
1950 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1954 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
1958 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }