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 AtError "@error"
232 %token AtClass "@class"
236 %token Typedef "typedef"
237 %token Unsigned "unsigned"
238 %token Signed "signed"
239 %token Extern "extern"
243 %token AtEncode "@encode"
247 %token AtImplementation "@implementation"
248 %token AtImplementation_ ";@implementation"
249 %token AtImport "@import"
251 %token AtSelector "@selector"
252 %token AtNull "@null"
255 %token AtTrue "@true"
256 %token AtFalse "@false"
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"
291 %token Switch "switch"
295 %token TypeOf "typeof"
301 %token Abstract "abstract"
303 %token Boolean "boolean"
306 %token Double "double"
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"
321 %token Static "static"
322 %token Synchronized "synchronized"
323 %token Throws "throws"
324 %token Transient "transient"
325 %token Volatile "volatile"
333 %token Namespace "namespace"
339 %token <identifier_> Identifier_
340 %token <number_> NumericLiteral
341 %token <string_> StringLiteral
342 %token <literal_> RegularExpressionLiteral
344 %type <expression_> AdditiveExpression
345 %type <argument_> ArgumentList_
346 %type <argument_> ArgumentList
347 %type <argument_> ArgumentListOpt
348 %type <argument_> Arguments
349 %type <expression_> ArrayComprehension
350 %type <expression_> ArrayInitialiser
351 %type <literal_> ArrayLiteral
352 %type <expression_> ArrowFunction
353 %type <functionParameter_> ArrowParameters
354 %type <expression_> AssignmentExpression
355 %type <identifier_> Binding
356 %type <identifier_> BindingIdentifier
357 %type <expression_> BitwiseANDExpression
358 %type <statement_> Block_
359 %type <statement_> Block
360 %type <boolean_> BooleanLiteral
361 %type <declaration_> BindingElement
362 %type <expression_> BitwiseORExpression
363 %type <expression_> BitwiseXORExpression
364 %type <statement_> BreakStatement
365 %type <statement_> BreakableStatement
366 %type <expression_> CallExpression_
367 %type <expression_> CallExpression
368 %type <clause_> CaseBlock
369 %type <clause_> CaseClause
370 %type <clause_> CaseClausesOpt
371 %type <catch_> CatchOpt
372 %type <expression_> Comprehension
373 %type <comprehension_> ComprehensionFor
374 %type <comprehension_> ComprehensionIf
375 %type <comprehension_> ComprehensionTail
376 %type <expression_> ConditionalExpression
377 %type <statement_> ContinueStatement
378 %type <statement_> ConciseBody
379 %type <statement_> DebuggerStatement
380 %type <statement_> Declaration__
381 %type <statement_> Declaration_
382 %type <statement_> Declaration
383 %type <clause_> DefaultClause
384 %type <expression_> Element
385 %type <expression_> ElementOpt
386 %type <element_> ElementList
387 %type <element_> ElementListOpt
388 %type <statement_> ElseStatementOpt
389 %type <statement_> EmptyStatement
390 %type <expression_> EqualityExpression
391 %type <expression_> Expression
392 %type <expression_> ExpressionOpt
393 %type <statement_> ExpressionStatement
394 %type <finally_> FinallyOpt
395 %type <for_> ForStatementInitialiser
396 %type <forin_> ForInStatementInitialiser
397 %type <declaration_> FormalParameter
398 %type <functionParameter_> FormalParameterList_
399 %type <functionParameter_> FormalParameterList
400 %type <functionParameter_> FormalParameterListOpt
401 %type <statement_> FunctionBody
402 %type <statement_> FunctionDeclaration
403 %type <expression_> FunctionExpression
404 %type <identifier_> Identifier
405 %type <identifier_> IdentifierOpt
406 %type <identifier_> IdentifierType
407 %type <word_> IdentifierName
408 %type <statement_> IfStatement
409 %type <expression_> Initialiser
410 %type <expression_> InitialiserOpt
411 %type <statement_> IterationStatement
412 %type <statement_> LabelledStatement
413 %type <expression_> LeftHandSideExpression
414 %type <statement_> LetStatement
415 %type <statement_> LexicalDeclaration
416 %type <literal_> Literal
417 %type <literal_> ValueLiteral
418 %type <expression_> LogicalANDExpression
419 %type <expression_> LogicalORExpression
420 %type <member_> MemberAccess
421 %type <expression_> MemberExpression_
422 %type <expression_> MemberExpression
423 %type <module_> Module
424 %type <expression_> MultiplicativeExpression
425 %type <expression_> NewExpression
426 %type <null_> NullLiteral
427 %type <literal_> ObjectLiteral
428 %type <parenthetical_> Parenthetical
429 %type <expression_> PostfixExpression
430 %type <expression_> PrimaryExpression
431 %type <statement_> Program
432 %type <statement_> ProgramBody
433 %type <statement_> ProgramBodyOpt
434 %type <propertyName_> PropertyName_
435 %type <propertyName_> PropertyName
436 %type <property_> PropertyDefinition
437 %type <property_> PropertyDefinitionList_
438 %type <property_> PropertyDefinitionList
439 %type <property_> PropertyDefinitionListOpt
440 %type <expression_> RelationalExpression
441 %type <statement_> ReturnStatement
442 %type <rubyProc_> RubyProcExpression
443 %type <functionParameter_> RubyProcParameterList_
444 %type <functionParameter_> RubyProcParameterList
445 %type <functionParameter_> RubyProcParameters
446 %type <functionParameter_> RubyProcParametersOpt
447 %type <expression_> ShiftExpression
448 %type <declaration_> SingleNameBinding
449 %type <statement_> Statement__
450 %type <statement_> Statement_
451 %type <statement_> Statement
452 %type <statement_> StatementList
453 %type <statement_> StatementListOpt
454 %type <statement_> StatementListItem
455 %type <statement_> SwitchStatement
456 %type <statement_> ThrowStatement
457 %type <statement_> TryStatement
458 %type <expression_> UnaryExpression_
459 %type <expression_> UnaryExpression
460 %type <declaration_> VariableDeclaration
461 %type <declarations_> VariableDeclarationList_
462 %type <declarations_> VariableDeclarationList
463 %type <statement_> VariableStatement
464 %type <statement_> WithStatement
467 %type <word_> WordOpt
469 %type <expression_> Variable
472 %type <specifier_> IntegerType
473 %type <specifier_> IntegerTypeOpt
474 %type <typedIdentifier_> PrefixedType
475 %type <specifier_> PrimitiveType
476 %type <typedIdentifier_> SuffixedType
477 %type <typedIdentifier_> TypeSignifier
478 %type <modifier_> TypeQualifierLeft
479 %type <typedIdentifier_> TypeQualifierRight
480 %type <typedIdentifier_> TypedIdentifier
481 %type <typedParameter_> TypedParameterList_
482 %type <typedParameter_> TypedParameterList
483 %type <typedParameter_> TypedParameterListOpt
487 %type <expression_> BoxableExpression
488 %type <statement_> CategoryStatement
489 %type <expression_> ClassExpression
490 %type <classField_> ClassFieldListOpt
491 %type <classField_> ClassFields
492 %type <statement_> ClassStatement
493 %type <expression_> ClassSuperOpt
494 %type <message_> ClassMessageDeclaration
495 %type <message_> ClassMessageDeclarationListOpt
496 %type <className_> ClassName
497 %type <className_> ClassNameOpt
498 %type <protocol_> ClassProtocolListOpt
499 %type <protocol_> ClassProtocols
500 %type <protocol_> ClassProtocolsOpt
501 %type <expression_> MessageExpression
502 %type <messageParameter_> MessageParameter
503 %type <messageParameter_> MessageParameters
504 %type <messageParameter_> MessageParameterList
505 %type <messageParameter_> MessageParameterListOpt
506 %type <bool_> MessageScope
507 %type <argument_> SelectorCall_
508 %type <argument_> SelectorCall
509 %type <selector_> SelectorExpression_
510 %type <selector_> SelectorExpression
511 %type <selector_> SelectorExpressionOpt
512 %type <argument_> SelectorList
513 %type <word_> SelectorWordOpt
514 %type <typedIdentifier_> TypeOpt
515 %type <argument_> VariadicCall
519 %type <propertyIdentifier_> PropertyIdentifier_
520 %type <selector_> PropertySelector_
521 %type <selector_> PropertySelector
522 %type <identifier_> QualifiedIdentifier_
523 %type <identifier_> QualifiedIdentifier
524 %type <identifier_> WildcardIdentifier
525 %type <identifier_> XMLComment
526 %type <identifier_> XMLCDATA
527 %type <identifier_> XMLElement
528 %type <identifier_> XMLElementContent
529 %type <identifier_> XMLMarkup
530 %type <identifier_> XMLPI
532 %type <attribute_> AttributeIdentifier
533 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
534 %type <expression_> PropertyIdentifier
535 %type <expression_> XMLListInitialiser
536 %type <expression_> XMLInitialiser
539 /* Token Priorities {{{ */
551 /* Lexer State {{{ */
553 : { driver.in_.push(true); }
557 : { driver.in_.push(false); }
561 : { driver.in_.pop(); }
565 : { driver.SetCondition(CYDriver::RegExpCondition); }
569 : { if (yyla.empty()) driver.no_.OpenBrace = true; else if (yyla.type == yytranslate_(token::OpenBrace) || yyla.type == yytranslate_(token::OpenBrace_)) yyla.type = yytranslate_(token::OpenBrace__); }
573 : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::Function)) yyla.type = yytranslate_(token::Function_); }
576 LexNoAtImplementation :
578 { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::AtImplementation)) yyla.type = yytranslate_(token::AtImplementation_); }
583 : LexNoBrace LexNoFunction LexNoAtImplementation
586 /* Virtual Tokens {{{ */
597 /* 7.6 Identifier Names and Identifiers {{{ */
608 : Identifier { $$ = $1; }
610 | "auto" { $$ = CYNew CYWord("auto"); }
611 | "break" NewLineOpt { $$ = CYNew CYWord("break"); }
612 | "case" { $$ = CYNew CYWord("case"); }
613 | "catch" { $$ = CYNew CYWord("catch"); }
614 | "class" { $$ = CYNew CYWord("class"); }
615 | "const" { $$ = CYNew CYWord("const"); }
616 | "continue" NewLineOpt { $$ = CYNew CYWord("continue"); }
617 | "debugger" { $$ = CYNew CYWord("debugger"); }
618 | "default" { $$ = CYNew CYWord("default"); }
619 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
620 | "do" { $$ = CYNew CYWord("do"); }
621 | "else" { $$ = CYNew CYWord("else"); }
622 | "enum" { $$ = CYNew CYWord("enum"); }
623 | "export" { $$ = CYNew CYWord("export"); }
624 | "extends" { $$ = CYNew CYWord("extends"); }
625 | "false" { $$ = CYNew CYWord("false"); }
626 | "finally" { $$ = CYNew CYWord("finally"); }
627 /* XXX: | "for" { $$ = CYNew CYWord("for"); } */
628 | "function" { $$ = CYNew CYWord("function"); }
629 | "if" { $$ = CYNew CYWord("if"); }
630 | "import" { $$ = CYNew CYWord("import"); }
631 /* XXX: | "in" { $$ = CYNew CYWord("in"); } */
632 | "!in" { $$ = CYNew CYWord("in"); }
633 /* XXX: | "instanceof" { $$ = CYNew CYWord("instanceof"); } */
635 // XXX: as it currently is not an Identifier
636 | "let" { $$ = CYNew CYIdentifier("let"); }
638 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
639 | "null" { $$ = CYNew CYWord("null"); }
640 | "return" NewLineOpt { $$ = CYNew CYWord("return"); }
641 | "super" { $$ = CYNew CYWord("super"); }
642 | "switch" { $$ = CYNew CYWord("switch"); }
643 | "this" { $$ = CYNew CYWord("this"); }
644 | "throw" NewLineOpt { $$ = CYNew CYWord("throw"); }
645 | "true" { $$ = CYNew CYWord("true"); }
646 | "try" { $$ = CYNew CYWord("try"); }
647 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
648 | "var" { $$ = CYNew CYWord("var"); }
649 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
650 | "while" { $$ = CYNew CYWord("while"); }
651 | "with" { $$ = CYNew CYWord("with"); }
662 : Identifier_ { $$ = $1; }
664 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
665 | "await" { $$ = CYNew CYIdentifier("await"); }
666 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
667 | "byte" { $$ = CYNew CYIdentifier("byte"); }
668 | "double" { $$ = CYNew CYIdentifier("double"); }
669 | "final" { $$ = CYNew CYIdentifier("final"); }
670 | "float" { $$ = CYNew CYIdentifier("float"); }
671 | "goto" { $$ = CYNew CYIdentifier("goto"); }
672 | "implements" { $$ = CYNew CYIdentifier("implements"); }
673 | "interface" { $$ = CYNew CYIdentifier("interface"); }
674 | "native" { $$ = CYNew CYIdentifier("native"); }
675 | "package" { $$ = CYNew CYIdentifier("package"); }
676 | "private" { $$ = CYNew CYIdentifier("private"); }
677 | "protected" { $$ = CYNew CYIdentifier("protected"); }
678 | "public" { $$ = CYNew CYIdentifier("public"); }
679 | "static" { $$ = CYNew CYIdentifier("static"); }
680 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
681 | "throws" { $$ = CYNew CYIdentifier("throws"); }
682 | "transient" { $$ = CYNew CYIdentifier("transient"); }
684 // XXX: currently I only have this as Word
685 // | "let" { $$ = CYNew CYIdentifier("let"); }
687 | "yield" NewLineOpt { $$ = CYNew CYIdentifier("yield"); }
689 | "each" { $$ = CYNew CYIdentifier("each"); }
690 | "of" { $$ = CYNew CYIdentifier("of"); }
695 | "char" { $$ = CYNew CYIdentifier("char"); }
696 | "int" { $$ = CYNew CYIdentifier("int"); }
697 | "long" { $$ = CYNew CYIdentifier("long"); }
698 | "short" { $$ = CYNew CYIdentifier("short"); }
699 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
701 | "extern" { $$ = CYNew CYIdentifier("extern"); }
702 | "signed" { $$ = CYNew CYIdentifier("signed"); }
703 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
704 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
707 | "NO" { $$ = CYNew CYIdentifier("NO"); }
708 | "YES" { $$ = CYNew CYIdentifier("YES"); }
713 : Identifier { $$ = $1; }
718 /* 7.8 Literals {{{ */
720 : NullLiteral { $$ = $1; }
721 | ValueLiteral { $$ = $1; }
725 : BooleanLiteral { $$ = $1; }
726 | NumericLiteral { $$ = $1; }
727 | StringLiteral { $$ = $1; }
728 | RegularExpressionLiteral { $$ = $1; }
731 /* 7.8.1 Null Literals {{{ */
733 : "null" { $$ = CYNew CYNull(); }
736 /* 7.8.2 Boolean Literals {{{ */
738 : "true" { $$ = CYNew CYTrue(); }
739 | "false" { $$ = CYNew CYFalse(); }
743 /* 7.9 Automatic Semicolon Insertion {{{ */
745 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
750 | 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
755 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
759 /* 11.1 Primary Expressions {{{ */
761 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
765 : Identifier { $$ = CYNew CYVariable($1); }
769 : "this" { $$ = CYNew CYThis(); }
770 | Variable { $$ = $1; }
771 | Literal { $$ = $1; }
772 | ArrayInitialiser { $$ = $1; }
773 | ObjectLiteral { $$ = $1; }
774 | Parenthetical { $$ = $1; }
775 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
778 /* 11.1.4 Array Initializer {{{ */
780 : ArrayLiteral { $$ = $1; }
781 | ArrayComprehension { $$ = $1; }
784 /* 11.1.4.1 Array Literal {{{ */
786 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
790 : AssignmentExpression { $$ = $1; }
794 : Element { $$ = $1; }
795 | LexSetRegExp { $$ = NULL; }
799 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
800 | Element { $$ = CYNew CYElement($1, NULL); }
804 : ElementList { $$ = $1; }
805 | LexSetRegExp { $$ = NULL; }
808 /* 11.1.4.2 Array Comprehension {{{ */
810 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
814 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
819 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
820 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
824 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
828 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
831 /* 11.1.5 Object Initialiser {{{ */
833 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
836 PropertyDefinitionList_
837 : "," PropertyDefinitionList { $$ = $2; }
838 | "," LexSetRegExp { $$ = NULL; }
842 PropertyDefinitionList
843 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
846 PropertyDefinitionListOpt
847 : PropertyDefinitionList { $$ = $1; }
848 | LexSetRegExp { $$ = NULL; }
852 // XXX: this should be IdentifierName
853 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
854 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
859 : IdentifierName { $$ = $1; }
860 | StringLiteral { $$ = $1; }
861 | NumericLiteral { $$ = $1; }
865 : LexSetRegExp PropertyName_ { $$ = $2; }
869 /* 11.2 Left-Hand-Side Expressions {{{ */
871 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
872 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
873 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
877 : MemberExpression { $$ = $1; }
878 //| "super" { $$ = $1; }
882 : LexSetRegExp PrimaryExpression { $$ = $2; }
883 | LexSetRegExp FunctionExpression { $$ = $2; }
884 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
885 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
889 : MemberExpression { $$ = $1; }
890 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
899 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
900 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
904 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
908 : "," ArgumentList { $$ = $2; }
913 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
914 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
918 : ArgumentList { $$ = $1; }
919 | LexSetRegExp { $$ = NULL; }
922 LeftHandSideExpression
923 : NewExpression { $$ = $1; }
924 | CallExpression { $$ = $1; }
927 /* 11.3 Postfix Expressions {{{ */
929 : %prec "" LeftHandSideExpression { $$ = $1; }
930 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
931 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
934 /* 11.4 Unary Operators {{{ */
936 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
937 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
938 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
939 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
940 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
941 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
942 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
943 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
944 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
945 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
946 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
950 : PostfixExpression { $$ = $1; }
951 | LexSetRegExp UnaryExpression_ { $$ = $2; }
954 /* 11.5 Multiplicative Operators {{{ */
955 MultiplicativeExpression
956 : UnaryExpression { $$ = $1; }
957 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
958 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
959 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
962 /* 11.6 Additive Operators {{{ */
964 : MultiplicativeExpression { $$ = $1; }
965 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
966 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
969 /* 11.7 Bitwise Shift Operators {{{ */
971 : AdditiveExpression { $$ = $1; }
972 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
973 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
974 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
977 /* 11.8 Relational Operators {{{ */
979 : ShiftExpression { $$ = $1; }
980 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
981 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
982 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
983 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
984 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
985 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
988 /* 11.9 Equality Operators {{{ */
990 : RelationalExpression { $$ = $1; }
991 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
992 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
993 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
994 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
997 /* 11.10 Binary Bitwise Operators {{{ */
999 : EqualityExpression { $$ = $1; }
1000 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1003 BitwiseXORExpression
1004 : BitwiseANDExpression { $$ = $1; }
1005 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1009 : BitwiseXORExpression { $$ = $1; }
1010 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1013 /* 11.11 Binary Logical Operators {{{ */
1014 LogicalANDExpression
1015 : BitwiseORExpression { $$ = $1; }
1016 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1020 : LogicalANDExpression { $$ = $1; }
1021 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1024 /* 11.12 Conditional Operator ( ? : ) {{{ */
1025 ConditionalExpression
1026 : LogicalORExpression { $$ = $1; }
1027 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1028 | LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1031 /* 11.13 Assignment Operators {{{ */
1032 AssignmentExpression
1033 : ConditionalExpression { $$ = $1; }
1034 | ArrowFunction { $$ = $1; }
1035 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1036 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1037 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1038 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1039 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1040 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1041 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1042 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1043 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1044 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1045 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1046 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1049 /* 11.14 Comma Operator {{{ */
1051 : AssignmentExpression { $$ = $1; }
1052 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
1056 : Expression { $$ = $1; }
1057 | LexSetRegExp { $$ = NULL; }
1061 /* 12 Statements {{{ */
1063 : Block { $$ = $1; }
1064 | VariableStatement { $$ = $1; }
1065 | EmptyStatement { $$ = $1; }
1066 | IfStatement { $$ = $1; }
1067 | BreakableStatement { $$ = $1; }
1068 | ContinueStatement { $$ = $1; }
1069 | BreakStatement { $$ = $1; }
1070 | ReturnStatement { $$ = $1; }
1071 | WithStatement { $$ = $1; }
1072 | LabelledStatement { $$ = $1; }
1073 | ThrowStatement { $$ = $1; }
1074 | TryStatement { $$ = $1; }
1075 | DebuggerStatement { $$ = $1; }
1079 : LexSetRegExp Statement__ { $$ = $2; }
1080 | ExpressionStatement { $$ = $1; }
1084 : LexSetStatement Statement_ { $$ = $2; }
1088 : FunctionDeclaration { $$ = $1; }
1089 | LexicalDeclaration { $$ = $1; }
1093 : LexSetRegExp Declaration__ { $$ = $2; }
1097 : LexSetStatement Declaration_ { $$ = $2; }
1101 : IterationStatement { $$ = $1; }
1102 | SwitchStatement { $$ = $1; }
1105 /* 12.1 Block {{{ */
1107 : BRACE StatementListOpt "}" { $$ = $2; }
1111 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1115 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1119 : StatementList { $$ = $1; }
1120 | LexSetStatement LexSetRegExp { $$ = NULL; }
1124 : Statement { $$ = $1; }
1125 | Declaration { $$ = $1; }
1129 /* 12.2 Declarations {{{ */
1131 : Identifier { $$ = $1; }
1138 // XXX: BindingPattern
1140 /* 12.2.1 Let and Const Declarations {{{ */
1142 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1150 /* 12.2.2 Variable Statement {{{ */
1152 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1155 VariableDeclarationList_
1156 : "," VariableDeclarationList { $$ = $2; }
1160 VariableDeclarationList
1161 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1165 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1166 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1170 : "=" AssignmentExpression { $$ = $2; }
1174 : Initialiser { $$ = $1; }
1178 /* 12.2.4 Destructuring Binding Patterns {{{ */
1182 : SingleNameBinding { $$ = $1; }
1186 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1190 /* 12.3 Empty Statement {{{ */
1192 : ";" { $$ = CYNew CYEmpty(); }
1195 /* 12.4 Expression Statement {{{ */
1197 : Expression Terminator { $$ = CYNew CYExpress($1); }
1200 /* 12.5 The if Statement {{{ */
1202 : "else" Statement { $$ = $2; }
1203 | %prec "if" { $$ = NULL; }
1207 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1211 /* 12.6.1 The do-while Statement {{{ */
1213 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1216 /* 12.6.2 The while Statement {{{ */
1218 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1221 /* 12.6.3 The for Statement {{{ */
1223 : "for" "(" LexPushInOn ForStatementInitialiser ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1226 ForStatementInitialiser
1227 : ExpressionOpt { $$ = $1; }
1228 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1231 /* 12.6.4 The for-in and for-of Statements {{{ */
1233 : "for" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1234 | "for" "(" LexPushInOn ForInStatementInitialiser "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1237 ForInStatementInitialiser
1238 : LeftHandSideExpression { $$ = $1; }
1239 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1243 /* 12.7 The continue Statement {{{ */
1245 : "continue" "\n" StrictSemi { $$ = CYNew CYContinue(NULL); }
1246 | "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1249 /* 12.8 The break Statement {{{ */
1251 : "break" "\n" StrictSemi { $$ = CYNew CYBreak(NULL); }
1252 | "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1255 /* 12.9 The return Statement {{{ */
1257 : "return" LexSetRegExp "\n" StrictSemi { $$ = CYNew CYReturn(NULL); }
1258 | "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1261 /* 12.10 The with Statement {{{ */
1263 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1267 /* 12.11 The switch Statement {{{ */
1269 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1273 : BRACE CaseClausesOpt "}" { $$ = $2; }
1277 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1281 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1282 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1287 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1290 /* 12.12 Labelled Statements {{{ */
1292 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1295 /* 12.13 The throw Statement {{{ */
1297 : "throw" LexSetRegExp "\n" StrictSemi { error(@1, "throw without exception"); }
1298 | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1301 /* 12.14 The try Statement {{{ */
1303 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1307 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1312 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1316 /* 12.14 The debugger Statement {{{ */
1318 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1322 /* 13.1 Function Definitions {{{ */
1324 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1328 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1331 FormalParameterList_
1332 : "," FormalParameterList { $$ = $2; }
1337 // XXX: : FunctionRestParameter { $$ = $1; }
1338 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1341 FormalParameterListOpt
1342 : FormalParameterList
1346 /* XXX: FunctionRestParameter
1347 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1351 : BindingElement { $$ = $1; }
1355 : StatementListOpt { $$ = $1; }
1358 /* 13.2 Arrow Function Definitions {{{ */
1360 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1364 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1365 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
1366 | Parenthetical { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); }
1370 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1371 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1374 /* 14 Program {{{ */
1376 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1380 : StatementList { $$ = $1; }
1384 : ProgramBody { $$ = $1; }
1385 | LexSetStatement LexSetRegExp { $$ = NULL; }
1390 /* Cycript (C): Type Encoding {{{ */
1392 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1393 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1397 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1398 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1399 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1400 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1401 | TypeSignifier { $$ = $1; }
1402 | { $$ = CYNew CYTypedIdentifier(@$); }
1406 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1411 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1412 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1416 : PrefixedType { $$ = $1; }
1417 | SuffixedType { $$ = $1; }
1418 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1419 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1423 : "int" { $$ = CYNew CYTypeVariable("int"); }
1424 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1425 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1426 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1427 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1431 : IntegerType { $$ = $1; }
1432 | { $$ = CYNew CYTypeVariable("int"); }
1436 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1437 | IntegerType { $$ = $1; }
1438 | "void" { $$ = CYNew CYTypeVoid(); }
1439 | "char" { $$ = CYNew CYTypeVariable("char"); }
1440 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1441 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1445 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1449 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1455 /* Cycript (Objective-C): @class Declaration {{{ */
1457 /* XXX: why the hell did I choose MemberExpression? */
1458 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1463 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1464 | LexSetRegExp { $$ = NULL; }
1468 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1472 : "+" { $$ = false; }
1473 | "-" { $$ = true; }
1477 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; }
1478 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1482 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1485 MessageParameterList
1486 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1489 MessageParameterListOpt
1490 : MessageParameterList { $$ = $1; }
1495 : MessageParameterList { $$ = $1; }
1496 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1499 ClassMessageDeclaration
1500 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1503 ClassMessageDeclarationListOpt
1504 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1505 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1510 : Identifier { $$ = $1; }
1511 | "(" AssignmentExpression ")" { $$ = $2; }
1515 : ClassName { $$ = $1; }
1519 // XXX: this should be AssignmentExpressionNoRight
1521 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1525 : "," ClassProtocols { $$ = $2; }
1529 ClassProtocolListOpt
1530 : "<" ClassProtocols ">" { $$ = $2; }
1535 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1539 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1547 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1551 : ClassExpression { $$ = $1; }
1555 : ClassStatement { $$ = $1; }
1556 | CategoryStatement { $$ = $1; }
1559 /* Cycript (Objective-C): Send Message {{{ */
1561 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1566 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1567 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1571 : SelectorCall { $$ = $1; }
1572 | VariadicCall { $$ = $1; }
1576 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1580 : SelectorCall { $$ = $1; }
1581 | Word { $$ = CYNew CYArgument($1, NULL); }
1585 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1586 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1590 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1594 : SelectorExpression_ { $$ = $1; }
1595 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1598 SelectorExpressionOpt
1599 : SelectorExpression_ { $$ = $1; }
1604 : MessageExpression { $$ = $1; }
1605 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1610 /* Cycript: @import Directive {{{ */
1612 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1613 | Word { $$ = CYNew CYModule($1); }
1617 : "@import" Module { $$ = CYNew CYImport($2); }
1622 /* Cycript (Objective-C): Boxed Expressions {{{ */
1624 : NullLiteral { $$ = $1; }
1625 | BooleanLiteral { $$ = $1; }
1626 | NumericLiteral { $$ = $1; }
1627 | StringLiteral { $$ = $1; }
1628 | ArrayLiteral { $$ = $1; }
1629 | ObjectLiteral { $$ = $1; }
1630 | Parenthetical { $$ = $1; }
1631 | "YES" { $$ = CYNew CYTrue(); }
1632 | "NO" { $$ = CYNew CYFalse(); }
1636 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1637 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1638 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1639 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1640 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1641 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
1644 /* Cycript (Objective-C): Block Expressions {{{ */
1646 : "^" 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"); }
1649 /* Cycript (Objective-C): Instance Literals {{{ */
1651 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1657 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1658 LeftHandSideExpression
1659 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1663 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1667 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1668 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1669 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1672 /* Cycript (C): auto Compatibility {{{ */
1677 /* Cycript (C): Lambda Expressions {{{ */
1679 : "," TypedParameterList { $$ = $2; }
1684 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1687 TypedParameterListOpt
1688 : TypedParameterList { $$ = $1; }
1693 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1696 /* Cycript (C): Type Definitions {{{ */
1698 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
1701 /* Cycript (C): extern "C" {{{ */
1703 : "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); }
1709 /* YUI: Documentation Comments {{{ */
1711 : Comment { $$ = $1; }
1716 /* Lexer State {{{ */
1718 : { driver.PushCondition(CYDriver::RegExpCondition); }
1722 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1726 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1730 : { driver.PopCondition(); }
1734 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1738 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1741 /* Virtual Tokens {{{ */
1748 /* 8.1 Context Keywords {{{ */
1750 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
1751 | "xml" { $$ = CYNew CYIdentifier("xml"); }
1754 /* 8.3 XML Initialiser Input Elements {{{ */
1756 : XMLComment { $$ = $1; }
1757 | XMLCDATA { $$ = $1; }
1758 | XMLPI { $$ = $1; }
1762 /* 11.1 Primary Expressions {{{ */
1764 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1765 | XMLInitialiser { $$ = $1; }
1766 | XMLListInitialiser { $$ = $1; }
1770 : AttributeIdentifier { $$ = $1; }
1771 | QualifiedIdentifier { $$ = $1; }
1772 | WildcardIdentifier { $$ = $1; }
1775 /* 11.1.1 Attribute Identifiers {{{ */
1777 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1781 : PropertySelector { $$ = $1; }
1782 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1786 : Identifier { $$ = CYNew CYSelector($1); }
1787 | WildcardIdentifier { $$ = $1; }
1790 /* 11.1.2 Qualified Identifiers {{{ */
1791 QualifiedIdentifier_
1792 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1793 | QualifiedIdentifier { $$ = $1; }
1797 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1800 /* 11.1.3 Wildcard Identifiers {{{ */
1802 : "*" { $$ = CYNew CYWildcard(); }
1805 /* 11.1.4 XML Initialiser {{{ */
1807 : XMLMarkup { $$ = $1; }
1808 | XMLElement { $$ = $1; }
1812 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1813 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1817 : LexPushXMLTag XMLTagName XMLAttributes
1821 : BRACE LexPushRegExp Expression LexPop "}"
1830 : XMLAttributes_ XMLAttribute
1835 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1836 | XMLAttributes_ XMLWhitespaceOpt
1845 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1849 : XMLExpression XMLElementContentOpt
1850 | XMLMarkup XMLElementContentOpt
1851 | XMLText XMLElementContentOpt
1852 | XMLElement XMLElementContentOpt
1855 XMLElementContentOpt
1860 /* 11.1.5 XMLList Initialiser {{{ */
1862 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1866 /* 11.2 Left-Hand-Side Expressions {{{ */
1868 : Identifier { $$ = $1; }
1869 | PropertyIdentifier { $$ = $1; }
1873 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1874 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1875 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1878 /* 12.1 The default xml namespace Statement {{{ */
1879 /* XXX: DefaultXMLNamespaceStatement
1880 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1884 : DefaultXMLNamespaceStatement { $$ = $1; }
1889 /* JavaScript 1.7: Array Comprehensions {{{ */
1891 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1895 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1896 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1899 /* JavaScript 1.7: for each {{{ */
1901 : "for" "each" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1904 /* JavaScript 1.7: let Statements {{{ */
1906 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1914 /* JavaScript FTW: Ruby Blocks {{{ */
1915 RubyProcParameterList_
1916 : "," RubyProcParameterList { $$ = $2; }
1920 RubyProcParameterList
1921 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1926 : "|" RubyProcParameterList "|" { $$ = $2; }
1927 | "||" { $$ = NULL; }
1930 RubyProcParametersOpt
1931 : RubyProcParameters
1936 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1940 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
1944 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }