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 Typedef "typedef"
239 %token Unsigned "unsigned"
240 %token Signed "signed"
241 %token 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"
272 %token Continue "continue"
273 %token Debugger "debugger"
274 %token Default "default"
275 %token Delete "delete"
279 %token Export "export"
280 %token Extends "extends"
281 %token Finally "finally"
283 %token Function "function"
284 %token Function_ ";function"
286 %token Import "import"
289 %token InstanceOf "instanceof"
291 %token Return "return"
293 %token Switch "switch"
297 %token TypeOf "typeof"
303 %token Abstract "abstract"
305 %token Boolean "boolean"
308 %token Double "double"
312 %token Implements "implements"
314 %token Interface "interface"
317 %token Native "native"
318 %token Package "package"
319 %token Private "private"
320 %token Protected "protected"
321 %token Public "public"
323 %token Static "static"
324 %token Synchronized "synchronized"
325 %token Throws "throws"
326 %token Transient "transient"
327 %token Volatile "volatile"
335 %token Namespace "namespace"
341 %token <identifier_> Identifier_
342 %token <number_> NumericLiteral
343 %token <string_> StringLiteral
344 %token <literal_> RegularExpressionLiteral
346 %type <expression_> AdditiveExpression
347 %type <argument_> ArgumentList_
348 %type <argument_> ArgumentList
349 %type <argument_> ArgumentListOpt
350 %type <argument_> Arguments
351 %type <expression_> ArrayComprehension
352 %type <expression_> ArrayInitialiser
353 %type <literal_> ArrayLiteral
354 %type <expression_> ArrowFunction
355 %type <functionParameter_> ArrowParameters
356 %type <expression_> AssignmentExpression
357 %type <identifier_> Binding
358 %type <identifier_> BindingIdentifier
359 %type <expression_> BitwiseANDExpression
360 %type <statement_> Block_
361 %type <statement_> Block
362 %type <boolean_> BooleanLiteral
363 %type <declaration_> BindingElement
364 %type <expression_> BitwiseORExpression
365 %type <expression_> BitwiseXORExpression
366 %type <statement_> BreakStatement
367 %type <statement_> BreakableStatement
368 %type <expression_> CallExpression_
369 %type <expression_> CallExpression
370 %type <clause_> CaseBlock
371 %type <clause_> CaseClause
372 %type <clause_> CaseClausesOpt
373 %type <catch_> CatchOpt
374 %type <expression_> Comprehension
375 %type <comprehension_> ComprehensionFor
376 %type <comprehension_> ComprehensionIf
377 %type <comprehension_> ComprehensionTail
378 %type <expression_> ConditionalExpression
379 %type <statement_> ContinueStatement
380 %type <statement_> ConciseBody
381 %type <statement_> DebuggerStatement
382 %type <statement_> Declaration__
383 %type <statement_> Declaration_
384 %type <statement_> Declaration
385 %type <clause_> DefaultClause
386 %type <expression_> Element
387 %type <expression_> ElementOpt
388 %type <element_> ElementList
389 %type <element_> ElementListOpt
390 %type <statement_> ElseStatementOpt
391 %type <statement_> EmptyStatement
392 %type <expression_> EqualityExpression
393 %type <expression_> Expression
394 %type <expression_> ExpressionOpt
395 %type <statement_> ExpressionStatement
396 %type <finally_> FinallyOpt
397 %type <for_> ForStatementInitialiser
398 %type <forin_> ForInStatementInitialiser
399 %type <declaration_> FormalParameter
400 %type <functionParameter_> FormalParameterList_
401 %type <functionParameter_> FormalParameterList
402 %type <functionParameter_> FormalParameterListOpt
403 %type <statement_> FunctionBody
404 %type <statement_> FunctionDeclaration
405 %type <expression_> FunctionExpression
406 %type <identifier_> Identifier
407 %type <identifier_> IdentifierOpt
408 %type <identifier_> IdentifierType
409 %type <word_> IdentifierName
410 %type <statement_> IfStatement
411 %type <expression_> Initialiser
412 %type <expression_> InitialiserOpt
413 %type <statement_> IterationStatement
414 %type <statement_> LabelledStatement
415 %type <expression_> LeftHandSideExpression
416 %type <statement_> LetStatement
417 %type <statement_> LexicalDeclaration
418 %type <literal_> Literal
419 %type <literal_> ValueLiteral
420 %type <expression_> LogicalANDExpression
421 %type <expression_> LogicalORExpression
422 %type <member_> MemberAccess
423 %type <expression_> MemberExpression_
424 %type <expression_> MemberExpression
425 %type <module_> Module
426 %type <expression_> MultiplicativeExpression
427 %type <expression_> NewExpression
428 %type <null_> NullLiteral
429 %type <literal_> ObjectLiteral
430 %type <parenthetical_> Parenthetical
431 %type <expression_> PostfixExpression
432 %type <expression_> PrimaryExpression
433 %type <statement_> Program
434 %type <statement_> ProgramBody
435 %type <statement_> ProgramBodyOpt
436 %type <propertyName_> PropertyName_
437 %type <propertyName_> PropertyName
438 %type <property_> PropertyDefinition
439 %type <property_> PropertyDefinitionList_
440 %type <property_> PropertyDefinitionList
441 %type <property_> PropertyDefinitionListOpt
442 %type <expression_> RelationalExpression
443 %type <statement_> ReturnStatement
444 %type <rubyProc_> RubyProcExpression
445 %type <functionParameter_> RubyProcParameterList_
446 %type <functionParameter_> RubyProcParameterList
447 %type <functionParameter_> RubyProcParameters
448 %type <functionParameter_> RubyProcParametersOpt
449 %type <expression_> ShiftExpression
450 %type <declaration_> SingleNameBinding
451 %type <statement_> Statement__
452 %type <statement_> Statement_
453 %type <statement_> Statement
454 %type <statement_> StatementList
455 %type <statement_> StatementListOpt
456 %type <statement_> StatementListItem
457 %type <statement_> SwitchStatement
458 %type <statement_> ThrowStatement
459 %type <statement_> TryStatement
460 %type <expression_> UnaryExpression_
461 %type <expression_> UnaryExpression
462 %type <declaration_> VariableDeclaration
463 %type <declarations_> VariableDeclarationList_
464 %type <declarations_> VariableDeclarationList
465 %type <statement_> VariableStatement
466 %type <statement_> WithStatement
469 %type <word_> WordOpt
471 %type <expression_> Variable
474 %type <specifier_> IntegerType
475 %type <specifier_> IntegerTypeOpt
476 %type <typedIdentifier_> PrefixedType
477 %type <specifier_> PrimitiveType
478 %type <typedIdentifier_> SuffixedType
479 %type <typedIdentifier_> TypeSignifier
480 %type <modifier_> TypeQualifierLeft
481 %type <typedIdentifier_> TypeQualifierRight
482 %type <typedIdentifier_> TypedIdentifier
483 %type <typedParameter_> TypedParameterList_
484 %type <typedParameter_> TypedParameterList
485 %type <typedParameter_> TypedParameterListOpt
489 %type <expression_> BoxableExpression
490 %type <statement_> CategoryStatement
491 %type <expression_> ClassExpression
492 %type <classField_> ClassFieldListOpt
493 %type <classField_> ClassFields
494 %type <statement_> ClassStatement
495 %type <expression_> ClassSuperOpt
496 %type <message_> ClassMessageDeclaration
497 %type <message_> ClassMessageDeclarationListOpt
498 %type <className_> ClassName
499 %type <className_> ClassNameOpt
500 %type <protocol_> ClassProtocolListOpt
501 %type <protocol_> ClassProtocols
502 %type <protocol_> ClassProtocolsOpt
503 %type <expression_> MessageExpression
504 %type <messageParameter_> MessageParameter
505 %type <messageParameter_> MessageParameters
506 %type <messageParameter_> MessageParameterList
507 %type <messageParameter_> MessageParameterListOpt
508 %type <bool_> MessageScope
509 %type <argument_> SelectorCall_
510 %type <argument_> SelectorCall
511 %type <selector_> SelectorExpression_
512 %type <selector_> SelectorExpression
513 %type <selector_> SelectorExpressionOpt
514 %type <argument_> SelectorList
515 %type <word_> SelectorWordOpt
516 %type <typedIdentifier_> TypeOpt
517 %type <argument_> VariadicCall
521 %type <propertyIdentifier_> PropertyIdentifier_
522 %type <selector_> PropertySelector_
523 %type <selector_> PropertySelector
524 %type <identifier_> QualifiedIdentifier_
525 %type <identifier_> QualifiedIdentifier
526 %type <identifier_> WildcardIdentifier
527 %type <identifier_> XMLComment
528 %type <identifier_> XMLCDATA
529 %type <identifier_> XMLElement
530 %type <identifier_> XMLElementContent
531 %type <identifier_> XMLMarkup
532 %type <identifier_> XMLPI
534 %type <attribute_> AttributeIdentifier
535 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
536 %type <expression_> PropertyIdentifier
537 %type <expression_> XMLListInitialiser
538 %type <expression_> XMLInitialiser
541 /* Token Priorities {{{ */
553 /* Lexer State {{{ */
555 : { driver.in_.push(true); }
559 : { driver.in_.push(false); }
563 : { driver.in_.pop(); }
567 : { driver.SetCondition(CYDriver::RegExpCondition); }
571 : { if (yyla.empty()) driver.no_.OpenBrace = true; else if (yyla.type == yytranslate_(token::OpenBrace) || yyla.type == yytranslate_(token::OpenBrace_)) yyla.type = yytranslate_(token::OpenBrace__); }
575 : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::Function)) yyla.type = yytranslate_(token::Function_); }
578 LexNoAtImplementation :
580 { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::AtImplementation)) yyla.type = yytranslate_(token::AtImplementation_); }
585 : LexNoBrace LexNoFunction LexNoAtImplementation
588 /* Virtual Tokens {{{ */
599 /* 7.6 Identifier Names and Identifiers {{{ */
610 : Identifier { $$ = $1; }
612 | "auto" { $$ = CYNew CYWord("auto"); }
613 | "break" NewLineOpt { $$ = CYNew CYWord("break"); }
614 | "case" { $$ = CYNew CYWord("case"); }
615 | "catch" { $$ = CYNew CYWord("catch"); }
616 | "class" { $$ = CYNew CYWord("class"); }
617 | "const" { $$ = CYNew CYWord("const"); }
618 | "continue" NewLineOpt { $$ = CYNew CYWord("continue"); }
619 | "debugger" { $$ = CYNew CYWord("debugger"); }
620 | "default" { $$ = CYNew CYWord("default"); }
621 | "delete" LexSetRegExp { $$ = CYNew CYWord("delete"); }
622 | "do" { $$ = CYNew CYWord("do"); }
623 | "else" { $$ = CYNew CYWord("else"); }
624 | "enum" { $$ = CYNew CYWord("enum"); }
625 | "export" { $$ = CYNew CYWord("export"); }
626 | "extends" { $$ = CYNew CYWord("extends"); }
627 | "false" { $$ = CYNew CYWord("false"); }
628 | "finally" { $$ = CYNew CYWord("finally"); }
629 /* XXX: | "for" { $$ = CYNew CYWord("for"); } */
630 | "function" { $$ = CYNew CYWord("function"); }
631 | "if" { $$ = CYNew CYWord("if"); }
632 | "import" { $$ = CYNew CYWord("import"); }
633 /* XXX: | "in" { $$ = CYNew CYWord("in"); } */
634 | "!in" { $$ = CYNew CYWord("in"); }
635 /* XXX: | "instanceof" { $$ = CYNew CYWord("instanceof"); } */
637 // XXX: as it currently is not an Identifier
638 | "let" { $$ = CYNew CYIdentifier("let"); }
640 | "new" LexSetRegExp { $$ = CYNew CYWord("new"); }
641 | "null" { $$ = CYNew CYWord("null"); }
642 | "return" NewLineOpt { $$ = CYNew CYWord("return"); }
643 | "super" { $$ = CYNew CYWord("super"); }
644 | "switch" { $$ = CYNew CYWord("switch"); }
645 | "this" { $$ = CYNew CYWord("this"); }
646 | "throw" NewLineOpt { $$ = CYNew CYWord("throw"); }
647 | "true" { $$ = CYNew CYWord("true"); }
648 | "try" { $$ = CYNew CYWord("try"); }
649 | "typeof" LexSetRegExp { $$ = CYNew CYWord("typeof"); }
650 | "var" { $$ = CYNew CYWord("var"); }
651 | "void" LexSetRegExp { $$ = CYNew CYWord("void"); }
652 | "while" { $$ = CYNew CYWord("while"); }
653 | "with" { $$ = CYNew CYWord("with"); }
664 : Identifier_ { $$ = $1; }
666 | "abstract" { $$ = CYNew CYIdentifier("abstract"); }
667 | "await" { $$ = CYNew CYIdentifier("await"); }
668 | "boolean" { $$ = CYNew CYIdentifier("boolean"); }
669 | "byte" { $$ = CYNew CYIdentifier("byte"); }
670 | "double" { $$ = CYNew CYIdentifier("double"); }
671 | "final" { $$ = CYNew CYIdentifier("final"); }
672 | "float" { $$ = CYNew CYIdentifier("float"); }
673 | "goto" { $$ = CYNew CYIdentifier("goto"); }
674 | "implements" { $$ = CYNew CYIdentifier("implements"); }
675 | "interface" { $$ = CYNew CYIdentifier("interface"); }
676 | "native" { $$ = CYNew CYIdentifier("native"); }
677 | "package" { $$ = CYNew CYIdentifier("package"); }
678 | "private" { $$ = CYNew CYIdentifier("private"); }
679 | "protected" { $$ = CYNew CYIdentifier("protected"); }
680 | "public" { $$ = CYNew CYIdentifier("public"); }
681 | "static" { $$ = CYNew CYIdentifier("static"); }
682 | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); }
683 | "throws" { $$ = CYNew CYIdentifier("throws"); }
684 | "transient" { $$ = CYNew CYIdentifier("transient"); }
686 // XXX: currently I only have this as Word
687 // | "let" { $$ = CYNew CYIdentifier("let"); }
689 | "yield" NewLineOpt { $$ = CYNew CYIdentifier("yield"); }
691 | "each" { $$ = CYNew CYIdentifier("each"); }
692 | "of" { $$ = CYNew CYIdentifier("of"); }
697 | "char" { $$ = CYNew CYIdentifier("char"); }
698 | "int" { $$ = CYNew CYIdentifier("int"); }
699 | "long" { $$ = CYNew CYIdentifier("long"); }
700 | "short" { $$ = CYNew CYIdentifier("short"); }
701 | "volatile" { $$ = CYNew CYIdentifier("volatile"); }
703 | "extern" { $$ = CYNew CYIdentifier("extern"); }
704 | "signed" { $$ = CYNew CYIdentifier("signed"); }
705 | "typedef" { $$ = CYNew CYIdentifier("typedef"); }
706 | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); }
709 | "NO" { $$ = CYNew CYIdentifier("NO"); }
710 | "YES" { $$ = CYNew CYIdentifier("YES"); }
715 : Identifier { $$ = $1; }
720 /* 7.8 Literals {{{ */
722 : NullLiteral { $$ = $1; }
723 | ValueLiteral { $$ = $1; }
727 : BooleanLiteral { $$ = $1; }
728 | NumericLiteral { $$ = $1; }
729 | StringLiteral { $$ = $1; }
730 | RegularExpressionLiteral { $$ = $1; }
733 /* 7.8.1 Null Literals {{{ */
735 : "null" { $$ = CYNew CYNull(); }
738 /* 7.8.2 Boolean Literals {{{ */
740 : "true" { $$ = CYNew CYTrue(); }
741 | "false" { $$ = CYNew CYFalse(); }
745 /* 7.9 Automatic Semicolon Insertion {{{ */
747 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
752 | 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
757 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
761 /* 11.1 Primary Expressions {{{ */
763 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
767 : Identifier { $$ = CYNew CYVariable($1); }
771 : "this" { $$ = CYNew CYThis(); }
772 | Variable { $$ = $1; }
773 | Literal { $$ = $1; }
774 | ArrayInitialiser { $$ = $1; }
775 | ObjectLiteral { $$ = $1; }
776 | Parenthetical { $$ = $1; }
777 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
780 /* 11.1.4 Array Initializer {{{ */
782 : ArrayLiteral { $$ = $1; }
783 | ArrayComprehension { $$ = $1; }
786 /* 11.1.4.1 Array Literal {{{ */
788 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
792 : AssignmentExpression { $$ = $1; }
796 : Element { $$ = $1; }
797 | LexSetRegExp { $$ = NULL; }
801 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
802 | Element { $$ = CYNew CYElement($1, NULL); }
806 : ElementList { $$ = $1; }
807 | LexSetRegExp { $$ = NULL; }
810 /* 11.1.4.2 Array Comprehension {{{ */
812 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
816 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
821 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
822 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
826 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
830 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
833 /* 11.1.5 Object Initialiser {{{ */
835 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
838 PropertyDefinitionList_
839 : "," PropertyDefinitionList { $$ = $2; }
840 | "," LexSetRegExp { $$ = NULL; }
844 PropertyDefinitionList
845 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
848 PropertyDefinitionListOpt
849 : PropertyDefinitionList { $$ = $1; }
850 | LexSetRegExp { $$ = NULL; }
854 // XXX: this should be IdentifierName
855 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
856 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
861 : IdentifierName { $$ = $1; }
862 | StringLiteral { $$ = $1; }
863 | NumericLiteral { $$ = $1; }
867 : LexSetRegExp PropertyName_ { $$ = $2; }
871 /* 11.2 Left-Hand-Side Expressions {{{ */
873 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
874 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
875 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
879 : MemberExpression { $$ = $1; }
880 //| "super" { $$ = $1; }
884 : LexSetRegExp PrimaryExpression { $$ = $2; }
885 | LexSetRegExp FunctionExpression { $$ = $2; }
886 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
887 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
891 : MemberExpression { $$ = $1; }
892 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
901 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
902 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
906 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
910 : "," ArgumentList { $$ = $2; }
915 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
916 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
920 : ArgumentList { $$ = $1; }
921 | LexSetRegExp { $$ = NULL; }
924 LeftHandSideExpression
925 : NewExpression { $$ = $1; }
926 | CallExpression { $$ = $1; }
929 /* 11.3 Postfix Expressions {{{ */
931 : %prec "" LeftHandSideExpression { $$ = $1; }
932 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
933 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
936 /* 11.4 Unary Operators {{{ */
938 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
939 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
940 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
941 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
942 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
943 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
944 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
945 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
946 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
947 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
948 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
952 : PostfixExpression { $$ = $1; }
953 | LexSetRegExp UnaryExpression_ { $$ = $2; }
956 /* 11.5 Multiplicative Operators {{{ */
957 MultiplicativeExpression
958 : UnaryExpression { $$ = $1; }
959 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
960 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
961 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
964 /* 11.6 Additive Operators {{{ */
966 : MultiplicativeExpression { $$ = $1; }
967 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
968 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
971 /* 11.7 Bitwise Shift Operators {{{ */
973 : AdditiveExpression { $$ = $1; }
974 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
975 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
976 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
979 /* 11.8 Relational Operators {{{ */
981 : ShiftExpression { $$ = $1; }
982 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
983 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
984 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
985 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
986 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
987 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
990 /* 11.9 Equality Operators {{{ */
992 : RelationalExpression { $$ = $1; }
993 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
994 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
995 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
996 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
999 /* 11.10 Binary Bitwise Operators {{{ */
1000 BitwiseANDExpression
1001 : EqualityExpression { $$ = $1; }
1002 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1005 BitwiseXORExpression
1006 : BitwiseANDExpression { $$ = $1; }
1007 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1011 : BitwiseXORExpression { $$ = $1; }
1012 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1015 /* 11.11 Binary Logical Operators {{{ */
1016 LogicalANDExpression
1017 : BitwiseORExpression { $$ = $1; }
1018 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1022 : LogicalANDExpression { $$ = $1; }
1023 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1026 /* 11.12 Conditional Operator ( ? : ) {{{ */
1027 ConditionalExpression
1028 : LogicalORExpression { $$ = $1; }
1029 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1030 | LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1033 /* 11.13 Assignment Operators {{{ */
1034 AssignmentExpression
1035 : ConditionalExpression { $$ = $1; }
1036 | ArrowFunction { $$ = $1; }
1037 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1038 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1039 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1040 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1041 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1042 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1043 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1044 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1045 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1046 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1047 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1048 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1051 /* 11.14 Comma Operator {{{ */
1053 : AssignmentExpression { $$ = $1; }
1054 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
1058 : Expression { $$ = $1; }
1059 | LexSetRegExp { $$ = NULL; }
1063 /* 12 Statements {{{ */
1065 : Block { $$ = $1; }
1066 | VariableStatement { $$ = $1; }
1067 | EmptyStatement { $$ = $1; }
1068 | IfStatement { $$ = $1; }
1069 | BreakableStatement { $$ = $1; }
1070 | ContinueStatement { $$ = $1; }
1071 | BreakStatement { $$ = $1; }
1072 | ReturnStatement { $$ = $1; }
1073 | WithStatement { $$ = $1; }
1074 | LabelledStatement { $$ = $1; }
1075 | ThrowStatement { $$ = $1; }
1076 | TryStatement { $$ = $1; }
1077 | DebuggerStatement { $$ = $1; }
1081 : LexSetRegExp Statement__ { $$ = $2; }
1082 | ExpressionStatement { $$ = $1; }
1086 : LexSetStatement Statement_ { $$ = $2; }
1090 : FunctionDeclaration { $$ = $1; }
1091 | LexicalDeclaration { $$ = $1; }
1095 : LexSetRegExp Declaration__ { $$ = $2; }
1099 : LexSetStatement Declaration_ { $$ = $2; }
1103 : IterationStatement { $$ = $1; }
1104 | SwitchStatement { $$ = $1; }
1107 /* 12.1 Block {{{ */
1109 : BRACE StatementListOpt "}" { $$ = $2; }
1113 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1117 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1121 : StatementList { $$ = $1; }
1122 | LexSetStatement LexSetRegExp { $$ = NULL; }
1126 : Statement { $$ = $1; }
1127 | Declaration { $$ = $1; }
1131 /* 12.2 Declarations {{{ */
1133 : Identifier { $$ = $1; }
1140 // XXX: BindingPattern
1142 /* 12.2.1 Let and Const Declarations {{{ */
1144 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1152 /* 12.2.2 Variable Statement {{{ */
1154 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1157 VariableDeclarationList_
1158 : "," VariableDeclarationList { $$ = $2; }
1162 VariableDeclarationList
1163 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1167 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1168 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1172 : "=" AssignmentExpression { $$ = $2; }
1176 : Initialiser { $$ = $1; }
1180 /* 12.2.4 Destructuring Binding Patterns {{{ */
1184 : SingleNameBinding { $$ = $1; }
1188 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1192 /* 12.3 Empty Statement {{{ */
1194 : ";" { $$ = CYNew CYEmpty(); }
1197 /* 12.4 Expression Statement {{{ */
1199 : Expression Terminator { $$ = CYNew CYExpress($1); }
1202 /* 12.5 The if Statement {{{ */
1204 : "else" Statement { $$ = $2; }
1205 | %prec "if" { $$ = NULL; }
1209 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1213 /* 12.6.1 The do-while Statement {{{ */
1215 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1218 /* 12.6.2 The while Statement {{{ */
1220 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1223 /* 12.6.3 The for Statement {{{ */
1225 : "for" "(" LexPushInOn ForStatementInitialiser ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1228 ForStatementInitialiser
1229 : ExpressionOpt { $$ = $1; }
1230 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1233 /* 12.6.4 The for-in and for-of Statements {{{ */
1235 : "for" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1236 | "for" "(" LexPushInOn ForInStatementInitialiser "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1239 ForInStatementInitialiser
1240 : LeftHandSideExpression { $$ = $1; }
1241 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1245 /* 12.7 The continue Statement {{{ */
1247 : "continue" "\n" StrictSemi { $$ = CYNew CYContinue(NULL); }
1248 | "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1251 /* 12.8 The break Statement {{{ */
1253 : "break" "\n" StrictSemi { $$ = CYNew CYBreak(NULL); }
1254 | "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1257 /* 12.9 The return Statement {{{ */
1259 : "return" LexSetRegExp "\n" StrictSemi { $$ = CYNew CYReturn(NULL); }
1260 | "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1263 /* 12.10 The with Statement {{{ */
1265 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1269 /* 12.11 The switch Statement {{{ */
1271 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1275 : BRACE CaseClausesOpt "}" { $$ = $2; }
1279 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1283 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1284 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1289 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1292 /* 12.12 Labelled Statements {{{ */
1294 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1297 /* 12.13 The throw Statement {{{ */
1299 : "throw" LexSetRegExp "\n" StrictSemi { error(@1, "throw without exception"); }
1300 | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1303 /* 12.14 The try Statement {{{ */
1305 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1309 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1314 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1318 /* 12.14 The debugger Statement {{{ */
1320 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1324 /* 13.1 Function Definitions {{{ */
1326 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1330 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1333 FormalParameterList_
1334 : "," FormalParameterList { $$ = $2; }
1339 // XXX: : FunctionRestParameter { $$ = $1; }
1340 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1343 FormalParameterListOpt
1344 : FormalParameterList
1348 /* XXX: FunctionRestParameter
1349 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1353 : BindingElement { $$ = $1; }
1357 : StatementListOpt { $$ = $1; }
1360 /* 13.2 Arrow Function Definitions {{{ */
1362 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1366 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1367 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
1368 | Parenthetical { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); }
1372 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1373 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1376 /* 14 Program {{{ */
1378 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1382 : StatementList { $$ = $1; }
1386 : ProgramBody { $$ = $1; }
1387 | LexSetStatement LexSetRegExp { $$ = NULL; }
1392 /* Cycript (C): Type Encoding {{{ */
1394 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1395 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1399 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1400 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1401 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1402 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1403 | TypeSignifier { $$ = $1; }
1404 | { $$ = CYNew CYTypedIdentifier(@$); }
1408 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1413 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1414 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1418 : PrefixedType { $$ = $1; }
1419 | SuffixedType { $$ = $1; }
1420 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1421 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1425 : "int" { $$ = CYNew CYTypeVariable("int"); }
1426 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1427 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1428 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1429 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1433 : IntegerType { $$ = $1; }
1434 | { $$ = CYNew CYTypeVariable("int"); }
1438 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1439 | IntegerType { $$ = $1; }
1440 | "void" { $$ = CYNew CYTypeVoid(); }
1441 | "char" { $$ = CYNew CYTypeVariable("char"); }
1442 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1443 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1447 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1451 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1457 /* Cycript (Objective-C): @class Declaration {{{ */
1459 /* XXX: why the hell did I choose MemberExpression? */
1460 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1465 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1466 | LexSetRegExp { $$ = NULL; }
1470 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1474 : "+" { $$ = false; }
1475 | "-" { $$ = true; }
1479 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; }
1480 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1484 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1487 MessageParameterList
1488 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1491 MessageParameterListOpt
1492 : MessageParameterList { $$ = $1; }
1497 : MessageParameterList { $$ = $1; }
1498 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1501 ClassMessageDeclaration
1502 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1505 ClassMessageDeclarationListOpt
1506 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1507 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1512 : Identifier { $$ = $1; }
1513 | "(" AssignmentExpression ")" { $$ = $2; }
1517 : ClassName { $$ = $1; }
1521 // XXX: this should be AssignmentExpressionNoRight
1523 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1527 : "," ClassProtocols { $$ = $2; }
1531 ClassProtocolListOpt
1532 : "<" ClassProtocols ">" { $$ = $2; }
1537 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1541 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1549 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1553 : ClassExpression { $$ = $1; }
1557 : ClassStatement { $$ = $1; }
1558 | CategoryStatement { $$ = $1; }
1561 /* Cycript (Objective-C): Send Message {{{ */
1563 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1568 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1569 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1573 : SelectorCall { $$ = $1; }
1574 | VariadicCall { $$ = $1; }
1578 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYWord(""), $3, $4); }
1582 : SelectorCall { $$ = $1; }
1583 | Word { $$ = CYNew CYArgument($1, NULL); }
1587 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1588 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1592 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1596 : SelectorExpression_ { $$ = $1; }
1597 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1600 SelectorExpressionOpt
1601 : SelectorExpression_ { $$ = $1; }
1606 : MessageExpression { $$ = $1; }
1607 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1612 /* Cycript: @import Directive {{{ */
1614 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1615 | Word { $$ = CYNew CYModule($1); }
1619 : "@import" Module { $$ = CYNew CYImport($2); }
1624 /* Cycript (Objective-C): Boxed Expressions {{{ */
1626 : NullLiteral { $$ = $1; }
1627 | BooleanLiteral { $$ = $1; }
1628 | NumericLiteral { $$ = $1; }
1629 | StringLiteral { $$ = $1; }
1630 | ArrayLiteral { $$ = $1; }
1631 | ObjectLiteral { $$ = $1; }
1632 | Parenthetical { $$ = $1; }
1633 | "YES" { $$ = CYNew CYTrue(); }
1634 | "NO" { $$ = CYNew CYFalse(); }
1638 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1639 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1640 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1641 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1642 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1643 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
1646 /* Cycript (Objective-C): Block Expressions {{{ */
1648 : "^" 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"); }
1651 /* Cycript (Objective-C): Instance Literals {{{ */
1653 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1659 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1660 LeftHandSideExpression
1661 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1665 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1669 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1670 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1671 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1674 /* Cycript (C): auto Compatibility {{{ */
1679 /* Cycript (C): Lambda Expressions {{{ */
1681 : "," TypedParameterList { $$ = $2; }
1686 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1689 TypedParameterListOpt
1690 : TypedParameterList { $$ = $1; }
1695 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1698 /* Cycript (C): Type Definitions {{{ */
1700 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
1703 /* Cycript (C): extern "C" {{{ */
1705 : "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); }
1711 /* YUI: Documentation Comments {{{ */
1713 : Comment { $$ = $1; }
1718 /* Lexer State {{{ */
1720 : { driver.PushCondition(CYDriver::RegExpCondition); }
1724 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1728 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1732 : { driver.PopCondition(); }
1736 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1740 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1743 /* Virtual Tokens {{{ */
1750 /* 8.1 Context Keywords {{{ */
1752 : "namespace" { $$ = CYNew CYIdentifier("namespace"); }
1753 | "xml" { $$ = CYNew CYIdentifier("xml"); }
1756 /* 8.3 XML Initialiser Input Elements {{{ */
1758 : XMLComment { $$ = $1; }
1759 | XMLCDATA { $$ = $1; }
1760 | XMLPI { $$ = $1; }
1764 /* 11.1 Primary Expressions {{{ */
1766 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1767 | XMLInitialiser { $$ = $1; }
1768 | XMLListInitialiser { $$ = $1; }
1772 : AttributeIdentifier { $$ = $1; }
1773 | QualifiedIdentifier { $$ = $1; }
1774 | WildcardIdentifier { $$ = $1; }
1777 /* 11.1.1 Attribute Identifiers {{{ */
1779 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1783 : PropertySelector { $$ = $1; }
1784 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1788 : Identifier { $$ = CYNew CYSelector($1); }
1789 | WildcardIdentifier { $$ = $1; }
1792 /* 11.1.2 Qualified Identifiers {{{ */
1793 QualifiedIdentifier_
1794 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1795 | QualifiedIdentifier { $$ = $1; }
1799 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1802 /* 11.1.3 Wildcard Identifiers {{{ */
1804 : "*" { $$ = CYNew CYWildcard(); }
1807 /* 11.1.4 XML Initialiser {{{ */
1809 : XMLMarkup { $$ = $1; }
1810 | XMLElement { $$ = $1; }
1814 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1815 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1819 : LexPushXMLTag XMLTagName XMLAttributes
1823 : BRACE LexPushRegExp Expression LexPop "}"
1832 : XMLAttributes_ XMLAttribute
1837 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1838 | XMLAttributes_ XMLWhitespaceOpt
1847 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1851 : XMLExpression XMLElementContentOpt
1852 | XMLMarkup XMLElementContentOpt
1853 | XMLText XMLElementContentOpt
1854 | XMLElement XMLElementContentOpt
1857 XMLElementContentOpt
1862 /* 11.1.5 XMLList Initialiser {{{ */
1864 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1868 /* 11.2 Left-Hand-Side Expressions {{{ */
1870 : Identifier { $$ = $1; }
1871 | PropertyIdentifier { $$ = $1; }
1875 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1876 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1877 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1880 /* 12.1 The default xml namespace Statement {{{ */
1881 /* XXX: DefaultXMLNamespaceStatement
1882 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1886 : DefaultXMLNamespaceStatement { $$ = $1; }
1891 /* JavaScript 1.7: Array Comprehensions {{{ */
1893 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1897 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1898 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1901 /* JavaScript 1.7: for each {{{ */
1903 : "for" "each" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1906 /* JavaScript 1.7: let Statements {{{ */
1908 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1916 /* JavaScript FTW: Ruby Blocks {{{ */
1917 RubyProcParameterList_
1918 : "," RubyProcParameterList { $$ = $2; }
1922 RubyProcParameterList
1923 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1928 : "|" RubyProcParameterList "|" { $$ = $2; }
1929 | "||" { $$ = NULL; }
1932 RubyProcParametersOpt
1933 : RubyProcParameters
1938 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1942 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
1946 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }