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
30 #define CYNew new($pool)
33 #include "ObjectiveC/Syntax.hpp"
37 #include "E4X/Syntax.hpp"
40 #include "Highlight.hpp"
49 CYDriver::Condition condition_;
51 CYArgument *argument_;
52 CYAssignment *assignment_;
55 cy::Syntax::Catch *catch_;
57 CYComprehension *comprehension_;
58 CYDeclaration *declaration_;
59 CYDeclarations *declarations_;
61 CYExpression *expression_;
64 CYForInitialiser *for_;
65 CYForInInitialiser *forin_;
66 CYFunctionParameter *functionParameter_;
67 CYIdentifier *identifier_;
74 CYParenthetical *parenthetical_;
76 CYProperty *property_;
77 CYPropertyName *propertyName_;
78 CYRubyProc *rubyProc_;
79 CYStatement *statement_;
86 CYTypeModifier *modifier_;
87 CYTypeSpecifier *specifier_;
88 CYTypedIdentifier *typedIdentifier_;
89 CYTypedParameter *typedParameter_;
93 CYClassName *className_;
94 CYClassField *classField_;
96 CYMessageParameter *messageParameter_;
97 CYProtocol *protocol_;
98 CYSelectorPart *selector_;
102 CYAttribute *attribute_;
103 CYPropertyIdentifier *propertyIdentifier_;
104 CYSelector *selector_;
109 #define YYSTYPE YYSTYPE
113 int cylex(YYSTYPE *, CYLocation *, void *);
121 @$.begin.filename = @$.end.filename = &driver.filename_;
127 %define api.location.type { CYLocation }
134 %parse-param { CYDriver &driver }
135 %lex-param { void *cyscanner }
137 /* Token Declarations {{{ */
143 %token XMLAttributeValue
145 %token XMLTagCharacters
151 %token LeftRight "<>"
152 %token LeftSlashRight "</>"
154 %token SlashRight "/>"
155 %token LeftSlash "</"
157 %token ColonColon "::"
158 %token PeriodPeriod ".."
161 @begin E4X ObjectiveC
167 %token AmpersandAmpersand "&&"
168 %token AmpersandEqual "&="
170 %token CarrotEqual "^="
172 %token EqualEqual "=="
173 %token EqualEqualEqual "==="
174 %token EqualRight "=>"
175 %token EqualRight_ "\n=>"
176 %token Exclamation "!"
177 %token ExclamationEqual "!="
178 %token ExclamationEqualEqual "!=="
180 %token HyphenEqual "-="
181 %token HyphenHyphen "--"
182 %token HyphenHyphen_ "\n--"
183 %token HyphenRight "->"
185 %token LeftEqual "<="
187 %token LeftLeftEqual "<<="
189 %token PercentEqual "%="
191 %token PeriodPeriodPeriod "..."
193 %token PipeEqual "|="
196 %token PlusEqual "+="
198 %token PlusPlus_ "\n++"
200 %token RightEqual ">="
201 %token RightRight ">>"
202 %token RightRightEqual ">>="
203 %token RightRightRight ">>>"
204 %token RightRightRightEqual ">>>="
206 %token SlashEqual "/="
208 %token StarEqual "*="
217 %token <comment_> Comment
220 %token CloseParen ")"
223 %token OpenBrace_ "\n{"
224 %token OpenBrace__ ";{"
225 %token CloseBrace "}"
227 %token OpenBracket "["
228 %token CloseBracket "]"
230 %token AtError "@error"
233 %token AtClass "@class"
237 %token <identifier_> Typedef "typedef"
238 %token <identifier_> Unsigned "unsigned"
239 %token <identifier_> Signed "signed"
240 %token <identifier_> Extern "extern"
244 %token AtEncode "@encode"
248 %token AtImplementation "@implementation"
249 %token AtImplementation_ ";@implementation"
250 %token AtImport "@import"
252 %token AtSelector "@selector"
253 %token AtNull "@null"
256 %token AtTrue "@true"
257 %token AtFalse "@false"
258 %token <identifier_> Yes "YES"
259 %token <identifier_> No "NO"
262 %token <false_> False "false"
263 %token <null_> Null "null"
264 %token <true_> True "true"
266 // ES3/ES5/WIE/JSC Reserved
267 %token <word_> Auto "auto"
268 %token <word_> Break "break"
269 %token <word_> Case "case"
270 %token <word_> Catch "catch"
271 %token <word_> Continue "continue"
272 %token <word_> Default "default"
273 %token <word_> Delete "delete"
274 %token <word_> Do "do"
275 %token <word_> Else "else"
276 %token <word_> Finally "finally"
277 %token <word_> For "for"
278 %token <word_> Function "function"
279 %token <word_> Function_ ";function"
280 %token <word_> If "if"
281 %token <word_> In "in"
282 %token <word_> In_ "!in"
283 %token <word_> InstanceOf "instanceof"
284 %token <word_> New "new"
285 %token <word_> Return "return"
286 %token <word_> Switch "switch"
287 %token <this_> This "this"
288 %token <word_> Throw "throw"
289 %token <word_> Try "try"
290 %token <word_> TypeOf "typeof"
291 %token <word_> Var "var"
292 %token <word_> Void "void"
293 %token <word_> While "while"
294 %token <word_> With "with"
296 // ES3/IE6 Future, ES5/JSC Reserved
297 %token <word_> Debugger "debugger"
299 // ES3/ES5/IE6 Future, JSC Reserved
300 %token <word_> Const "const"
302 // ES3/ES5/IE6/JSC Future
303 %token <word_> Class "class"
304 %token <word_> Enum "enum"
305 %token <word_> Export "export"
306 %token <word_> Extends "extends"
307 %token <word_> Import "import"
308 %token <word_> Super "super"
310 // ES3 Future, ES5 Strict Future
311 %token <identifier_> Implements "implements"
312 %token <identifier_> Interface "interface"
313 %token <identifier_> Package "package"
314 %token <identifier_> Private "private"
315 %token <identifier_> Protected "protected"
316 %token <identifier_> Public "public"
317 %token <identifier_> Static "static"
320 %token <identifier_> Abstract "abstract"
321 %token <identifier_> Boolean "boolean"
322 %token <identifier_> Byte "byte"
323 %token <identifier_> Char "char"
324 %token <identifier_> Double "double"
325 %token <identifier_> Final "final"
326 %token <identifier_> Float "float"
327 %token <identifier_> Goto "goto"
328 %token <identifier_> Int "int"
329 %token <identifier_> Long "long"
330 %token <identifier_> Native "native"
331 %token <identifier_> Short "short"
332 %token <identifier_> Synchronized "synchronized"
333 %token <identifier_> Throws "throws"
334 %token <identifier_> Transient "transient"
335 %token <identifier_> Volatile "volatile"
338 %token <identifier_> Let "let"
339 %token <identifier_> Yield "yield"
342 %token <identifier_> Each "each"
343 %token <identifier_> Of "of"
347 %token <identifier_> Namespace "namespace"
348 %token <identifier_> XML "xml"
353 %token <identifier_> Identifier_
354 %token <number_> NumericLiteral
355 %token <string_> StringLiteral
356 %token <literal_> RegularExpressionLiteral
358 %type <expression_> AdditiveExpression
359 %type <argument_> ArgumentList_
360 %type <argument_> ArgumentList
361 %type <argument_> ArgumentListOpt
362 %type <argument_> Arguments
363 %type <expression_> ArrayComprehension
364 %type <expression_> ArrayInitialiser
365 %type <literal_> ArrayLiteral
366 %type <expression_> ArrowFunction
367 %type <functionParameter_> ArrowParameters
368 %type <expression_> AssignmentExpression
369 %type <identifier_> Binding
370 %type <identifier_> BindingIdentifier
371 %type <expression_> BitwiseANDExpression
372 %type <statement_> Block_
373 %type <statement_> Block
374 %type <boolean_> BooleanLiteral
375 %type <declaration_> BindingElement
376 %type <expression_> BitwiseORExpression
377 %type <expression_> BitwiseXORExpression
378 %type <statement_> BreakStatement
379 %type <statement_> BreakableStatement
380 %type <expression_> CallExpression_
381 %type <expression_> CallExpression
382 %type <clause_> CaseBlock
383 %type <clause_> CaseClause
384 %type <clause_> CaseClausesOpt
385 %type <catch_> CatchOpt
386 %type <expression_> Comprehension
387 %type <comprehension_> ComprehensionFor
388 %type <comprehension_> ComprehensionIf
389 %type <comprehension_> ComprehensionTail
390 %type <expression_> ConditionalExpression
391 %type <statement_> ContinueStatement
392 %type <statement_> ConciseBody
393 %type <statement_> DebuggerStatement
394 %type <statement_> Declaration__
395 %type <statement_> Declaration_
396 %type <statement_> Declaration
397 %type <clause_> DefaultClause
398 %type <expression_> Element
399 %type <expression_> ElementOpt
400 %type <element_> ElementList
401 %type <element_> ElementListOpt
402 %type <statement_> ElseStatementOpt
403 %type <statement_> EmptyStatement
404 %type <expression_> EqualityExpression
405 %type <expression_> Expression
406 %type <expression_> ExpressionOpt
407 %type <statement_> ExpressionStatement
408 %type <finally_> FinallyOpt
409 %type <for_> ForStatementInitialiser
410 %type <forin_> ForInStatementInitialiser
411 %type <declaration_> FormalParameter
412 %type <functionParameter_> FormalParameterList_
413 %type <functionParameter_> FormalParameterList
414 %type <functionParameter_> FormalParameterListOpt
415 %type <statement_> FunctionBody
416 %type <statement_> FunctionDeclaration
417 %type <expression_> FunctionExpression
418 %type <identifier_> Identifier
419 %type <identifier_> IdentifierOpt
420 %type <identifier_> IdentifierType
421 %type <word_> IdentifierName
422 %type <statement_> IfStatement
423 %type <expression_> Initialiser
424 %type <expression_> InitialiserOpt
425 %type <statement_> IterationStatement
426 %type <statement_> LabelledStatement
427 %type <expression_> LeftHandSideExpression
428 %type <statement_> LetStatement
429 %type <statement_> LexicalDeclaration
430 %type <literal_> Literal
431 %type <literal_> ValueLiteral
432 %type <expression_> LogicalANDExpression
433 %type <expression_> LogicalORExpression
434 %type <member_> MemberAccess
435 %type <expression_> MemberExpression_
436 %type <expression_> MemberExpression
437 %type <module_> Module
438 %type <expression_> MultiplicativeExpression
439 %type <expression_> NewExpression
440 %type <null_> NullLiteral
441 %type <literal_> ObjectLiteral
442 %type <parenthetical_> Parenthetical
443 %type <expression_> PostfixExpression
444 %type <expression_> PrimaryExpression
445 %type <statement_> Program
446 %type <statement_> ProgramBody
447 %type <statement_> ProgramBodyOpt
448 %type <propertyName_> PropertyName_
449 %type <propertyName_> PropertyName
450 %type <property_> PropertyDefinition
451 %type <property_> PropertyDefinitionList_
452 %type <property_> PropertyDefinitionList
453 %type <property_> PropertyDefinitionListOpt
454 %type <expression_> RelationalExpression
455 %type <statement_> ReturnStatement
456 %type <rubyProc_> RubyProcExpression
457 %type <functionParameter_> RubyProcParameterList_
458 %type <functionParameter_> RubyProcParameterList
459 %type <functionParameter_> RubyProcParameters
460 %type <functionParameter_> RubyProcParametersOpt
461 %type <expression_> ShiftExpression
462 %type <declaration_> SingleNameBinding
463 %type <statement_> Statement__
464 %type <statement_> Statement_
465 %type <statement_> Statement
466 %type <statement_> StatementList
467 %type <statement_> StatementListOpt
468 %type <statement_> StatementListItem
469 %type <statement_> SwitchStatement
470 %type <statement_> ThrowStatement
471 %type <statement_> TryStatement
472 %type <expression_> UnaryExpression_
473 %type <expression_> UnaryExpression
474 %type <declaration_> VariableDeclaration
475 %type <declarations_> VariableDeclarationList_
476 %type <declarations_> VariableDeclarationList
477 %type <statement_> VariableStatement
478 %type <statement_> WithStatement
481 %type <word_> WordOpt
483 %type <expression_> Variable
486 %type <specifier_> IntegerType
487 %type <specifier_> IntegerTypeOpt
488 %type <typedIdentifier_> PrefixedType
489 %type <specifier_> PrimitiveType
490 %type <typedIdentifier_> SuffixedType
491 %type <typedIdentifier_> TypeSignifier
492 %type <modifier_> TypeQualifierLeft
493 %type <typedIdentifier_> TypeQualifierRight
494 %type <typedIdentifier_> TypedIdentifier
495 %type <typedParameter_> TypedParameterList_
496 %type <typedParameter_> TypedParameterList
497 %type <typedParameter_> TypedParameterListOpt
501 %type <expression_> BoxableExpression
502 %type <statement_> CategoryStatement
503 %type <expression_> ClassExpression
504 %type <classField_> ClassFieldListOpt
505 %type <classField_> ClassFields
506 %type <statement_> ClassStatement
507 %type <expression_> ClassSuperOpt
508 %type <message_> ClassMessageDeclaration
509 %type <message_> ClassMessageDeclarationListOpt
510 %type <className_> ClassName
511 %type <className_> ClassNameOpt
512 %type <protocol_> ClassProtocolListOpt
513 %type <protocol_> ClassProtocols
514 %type <protocol_> ClassProtocolsOpt
515 %type <expression_> MessageExpression
516 %type <messageParameter_> MessageParameter
517 %type <messageParameter_> MessageParameters
518 %type <messageParameter_> MessageParameterList
519 %type <messageParameter_> MessageParameterListOpt
520 %type <bool_> MessageScope
521 %type <argument_> SelectorCall_
522 %type <argument_> SelectorCall
523 %type <selector_> SelectorExpression_
524 %type <selector_> SelectorExpression
525 %type <selector_> SelectorExpressionOpt
526 %type <argument_> SelectorList
527 %type <word_> SelectorWordOpt
528 %type <typedIdentifier_> TypeOpt
529 %type <argument_> VariadicCall
533 %type <propertyIdentifier_> PropertyIdentifier_
534 %type <selector_> PropertySelector_
535 %type <selector_> PropertySelector
536 %type <identifier_> QualifiedIdentifier_
537 %type <identifier_> QualifiedIdentifier
538 %type <identifier_> WildcardIdentifier
539 %type <identifier_> XMLComment
540 %type <identifier_> XMLCDATA
541 %type <identifier_> XMLElement
542 %type <identifier_> XMLElementContent
543 %type <identifier_> XMLMarkup
544 %type <identifier_> XMLPI
546 %type <attribute_> AttributeIdentifier
547 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
548 %type <expression_> PropertyIdentifier
549 %type <expression_> XMLListInitialiser
550 %type <expression_> XMLInitialiser
553 /* Token Priorities {{{ */
565 /* Lexer State {{{ */
567 : { driver.in_.push(true); }
571 : { driver.in_.push(false); }
575 : { driver.in_.pop(); }
579 : { driver.SetCondition(CYDriver::RegExpCondition); }
583 : { if (yyla.empty()) driver.no_.OpenBrace = true; else if (yyla.type == yytranslate_(token::OpenBrace) || yyla.type == yytranslate_(token::OpenBrace_)) yyla.type = yytranslate_(token::OpenBrace__); }
587 : { if (yyla.empty()) driver.no_.Function = true; else if (yyla.type == yytranslate_(token::Function)) yyla.type = yytranslate_(token::Function_); }
590 LexNoAtImplementation :
592 { if (yyla.empty()) driver.no_.AtImplementation = true; else if (yyla.type == yytranslate_(token::AtImplementation)) yyla.type = yytranslate_(token::AtImplementation_); }
597 : LexNoBrace LexNoFunction LexNoAtImplementation
600 /* Virtual Tokens {{{ */
611 /* 7.6 Identifier Names and Identifiers {{{ */
622 : Identifier { $$ = $1; }
623 | "auto" { $$ = $1; }
624 | "break" NewLineOpt { $$ = $1; }
625 | "case" { $$ = $1; }
626 | "catch" { $$ = $1; }
627 | "class" { $$ = $1; }
628 | "const" { $$ = $1; }
629 | "continue" NewLineOpt { $$ = $1; }
630 | "debugger" { $$ = $1; }
631 | "default" { $$ = $1; }
632 | "delete" LexSetRegExp { $$ = $1; }
634 | "else" { $$ = $1; }
635 | "enum" { $$ = $1; }
636 | "export" { $$ = $1; }
637 | "extends" { $$ = $1; }
638 | "false" { $$ = $1; }
639 | "finally" { $$ = $1; }
640 /* XXX: | "for" { $$ = $1; } */
641 | "function" { $$ = $1; }
643 | "import" { $$ = $1; }
644 /* XXX: | "in" { $$ = $1; } */
646 /* XXX: | "instanceof" { $$ = $1; } */
648 // XXX: as it currently is not an Identifier
651 | "new" LexSetRegExp { $$ = $1; }
652 | "null" { $$ = $1; }
653 | "return" NewLineOpt { $$ = $1; }
654 | "super" { $$ = $1; }
655 | "switch" { $$ = $1; }
656 | "this" { $$ = $1; }
657 | "throw" NewLineOpt { $$ = $1; }
658 | "true" { $$ = $1; }
660 | "typeof" LexSetRegExp { $$ = $1; }
662 | "void" LexSetRegExp { $$ = $1; }
663 | "while" { $$ = $1; }
664 | "with" { $$ = $1; }
675 : Identifier_ { $$ = $1; }
677 | "implements" { $$ = $1; }
678 | "interface" { $$ = $1; }
679 | "package" { $$ = $1; }
680 | "private" { $$ = $1; }
681 | "protected" { $$ = $1; }
682 | "public" { $$ = $1; }
683 | "static" { $$ = $1; }
685 | "abstract" { $$ = $1; }
686 | "boolean" { $$ = $1; }
687 | "byte" { $$ = $1; }
688 | "double" { $$ = $1; }
689 | "final" { $$ = $1; }
690 | "float" { $$ = $1; }
691 | "goto" { $$ = $1; }
692 | "native" { $$ = $1; }
693 | "synchronized" { $$ = $1; }
694 | "throws" { $$ = $1; }
695 | "transient" { $$ = $1; }
697 // XXX: currently I only have this as Word
698 // | "let" { $$ = $1; }
700 | "yield" NewLineOpt { $$ = $1; }
702 | "each" { $$ = $1; }
708 | "char" { $$ = $1; }
710 | "long" { $$ = $1; }
711 | "short" { $$ = $1; }
712 | "volatile" { $$ = $1; }
714 | "typedef" { $$ = $1; }
715 | "unsigned" { $$ = $1; }
716 | "signed" { $$ = $1; }
717 | "extern" { $$ = $1; }
726 : Identifier { $$ = $1; }
731 /* 7.8 Literals {{{ */
733 : NullLiteral { $$ = $1; }
734 | ValueLiteral { $$ = $1; }
738 : BooleanLiteral { $$ = $1; }
739 | NumericLiteral { $$ = $1; }
740 | StringLiteral { $$ = $1; }
741 | RegularExpressionLiteral { $$ = $1; }
744 /* 7.8.1 Null Literals {{{ */
746 : "null" { $$ = $1; }
749 /* 7.8.2 Boolean Literals {{{ */
751 : "true" { $$ = $1; }
752 | "false" { $$ = $1; }
756 /* 7.9 Automatic Semicolon Insertion {{{ */
758 : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); }
763 | 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
768 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
772 /* 11.1 Primary Expressions {{{ */
774 : "(" LexPushInOff Expression ")" LexPopIn { $$ = CYNew CYParenthetical($3); }
778 : Identifier { $$ = CYNew CYVariable($1); }
782 : "this" { $$ = $1; }
783 | Variable { $$ = $1; }
784 | Literal { $$ = $1; }
785 | ArrayInitialiser { $$ = $1; }
786 | ObjectLiteral { $$ = $1; }
787 | Parenthetical { $$ = $1; }
788 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
791 /* 11.1.4 Array Initializer {{{ */
793 : ArrayLiteral { $$ = $1; }
794 | ArrayComprehension { $$ = $1; }
797 /* 11.1.4.1 Array Literal {{{ */
799 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
803 : AssignmentExpression { $$ = $1; }
807 : Element { $$ = $1; }
808 | LexSetRegExp { $$ = NULL; }
812 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
813 | Element { $$ = CYNew CYElement($1, NULL); }
817 : ElementList { $$ = $1; }
818 | LexSetRegExp { $$ = NULL; }
821 /* 11.1.4.2 Array Comprehension {{{ */
823 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
827 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
832 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
833 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
837 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
841 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
844 /* 11.1.5 Object Initialiser {{{ */
846 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
849 PropertyDefinitionList_
850 : "," PropertyDefinitionList { $$ = $2; }
851 | "," LexSetRegExp { $$ = NULL; }
855 PropertyDefinitionList
856 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
859 PropertyDefinitionListOpt
860 : PropertyDefinitionList { $$ = $1; }
861 | LexSetRegExp { $$ = NULL; }
865 // XXX: this should be IdentifierName
866 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
867 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
872 : IdentifierName { $$ = $1; }
873 | StringLiteral { $$ = $1; }
874 | NumericLiteral { $$ = $1; }
878 : LexSetRegExp PropertyName_ { $$ = $2; }
882 /* 11.2 Left-Hand-Side Expressions {{{ */
884 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
885 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
886 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
890 : MemberExpression { $$ = $1; }
891 //| "super" { $$ = $1; }
895 : LexSetRegExp PrimaryExpression { $$ = $2; }
896 | LexSetRegExp FunctionExpression { $$ = $2; }
897 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
898 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
902 : MemberExpression { $$ = $1; }
903 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
912 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
913 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
917 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
921 : "," ArgumentList { $$ = $2; }
926 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
927 | LexSetRegExp Word ":" AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument($2, $4, $5); }
931 : ArgumentList { $$ = $1; }
932 | LexSetRegExp { $$ = NULL; }
935 LeftHandSideExpression
936 : NewExpression { $$ = $1; }
937 | CallExpression { $$ = $1; }
940 /* 11.3 Postfix Expressions {{{ */
942 : %prec "" LeftHandSideExpression { $$ = $1; }
943 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
944 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
947 /* 11.4 Unary Operators {{{ */
949 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
950 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
951 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
952 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
953 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
954 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
955 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
956 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
957 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
958 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
959 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
963 : PostfixExpression { $$ = $1; }
964 | LexSetRegExp UnaryExpression_ { $$ = $2; }
967 /* 11.5 Multiplicative Operators {{{ */
968 MultiplicativeExpression
969 : UnaryExpression { $$ = $1; }
970 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
971 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
972 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
975 /* 11.6 Additive Operators {{{ */
977 : MultiplicativeExpression { $$ = $1; }
978 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
979 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
982 /* 11.7 Bitwise Shift Operators {{{ */
984 : AdditiveExpression { $$ = $1; }
985 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
986 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
987 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
990 /* 11.8 Relational Operators {{{ */
992 : ShiftExpression { $$ = $1; }
993 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
994 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
995 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
996 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
997 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
998 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
1001 /* 11.9 Equality Operators {{{ */
1003 : RelationalExpression { $$ = $1; }
1004 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1005 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1006 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1007 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1010 /* 11.10 Binary Bitwise Operators {{{ */
1011 BitwiseANDExpression
1012 : EqualityExpression { $$ = $1; }
1013 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1016 BitwiseXORExpression
1017 : BitwiseANDExpression { $$ = $1; }
1018 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1022 : BitwiseXORExpression { $$ = $1; }
1023 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1026 /* 11.11 Binary Logical Operators {{{ */
1027 LogicalANDExpression
1028 : BitwiseORExpression { $$ = $1; }
1029 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1033 : LogicalANDExpression { $$ = $1; }
1034 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1037 /* 11.12 Conditional Operator ( ? : ) {{{ */
1038 ConditionalExpression
1039 : LogicalORExpression { $$ = $1; }
1040 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1041 | LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1044 /* 11.13 Assignment Operators {{{ */
1045 AssignmentExpression
1046 : ConditionalExpression { $$ = $1; }
1047 | ArrowFunction { $$ = $1; }
1048 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1049 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1050 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1051 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1052 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1053 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1054 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1055 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1056 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1057 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1058 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1059 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1062 /* 11.14 Comma Operator {{{ */
1064 : AssignmentExpression { $$ = $1; }
1065 | AssignmentExpression "," Expression { $$ = CYNew CYCompound($1, $3); }
1069 : Expression { $$ = $1; }
1070 | LexSetRegExp { $$ = NULL; }
1074 /* 12 Statements {{{ */
1076 : Block { $$ = $1; }
1077 | VariableStatement { $$ = $1; }
1078 | EmptyStatement { $$ = $1; }
1079 | IfStatement { $$ = $1; }
1080 | BreakableStatement { $$ = $1; }
1081 | ContinueStatement { $$ = $1; }
1082 | BreakStatement { $$ = $1; }
1083 | ReturnStatement { $$ = $1; }
1084 | WithStatement { $$ = $1; }
1085 | LabelledStatement { $$ = $1; }
1086 | ThrowStatement { $$ = $1; }
1087 | TryStatement { $$ = $1; }
1088 | DebuggerStatement { $$ = $1; }
1092 : LexSetRegExp Statement__ { $$ = $2; }
1093 | ExpressionStatement { $$ = $1; }
1097 : LexSetStatement Statement_ { $$ = $2; }
1101 : FunctionDeclaration { $$ = $1; }
1102 | LexicalDeclaration { $$ = $1; }
1106 : LexSetRegExp Declaration__ { $$ = $2; }
1110 : LexSetStatement Declaration_ { $$ = $2; }
1114 : IterationStatement { $$ = $1; }
1115 | SwitchStatement { $$ = $1; }
1118 /* 12.1 Block {{{ */
1120 : BRACE StatementListOpt "}" { $$ = $2; }
1124 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1128 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1132 : StatementList { $$ = $1; }
1133 | LexSetStatement LexSetRegExp { $$ = NULL; }
1137 : Statement { $$ = $1; }
1138 | Declaration { $$ = $1; }
1142 /* 12.2 Declarations {{{ */
1144 : Identifier { $$ = $1; }
1151 // XXX: BindingPattern
1153 /* 12.2.1 Let and Const Declarations {{{ */
1155 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1163 /* 12.2.2 Variable Statement {{{ */
1165 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1168 VariableDeclarationList_
1169 : "," VariableDeclarationList { $$ = $2; }
1173 VariableDeclarationList
1174 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1178 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1179 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1183 : "=" AssignmentExpression { $$ = $2; }
1187 : Initialiser { $$ = $1; }
1191 /* 12.2.4 Destructuring Binding Patterns {{{ */
1195 : SingleNameBinding { $$ = $1; }
1199 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1203 /* 12.3 Empty Statement {{{ */
1205 : ";" { $$ = CYNew CYEmpty(); }
1208 /* 12.4 Expression Statement {{{ */
1210 : Expression Terminator { $$ = CYNew CYExpress($1); }
1213 /* 12.5 The if Statement {{{ */
1215 : "else" Statement { $$ = $2; }
1216 | %prec "if" { $$ = NULL; }
1220 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1224 /* 12.6.1 The do-while Statement {{{ */
1226 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1229 /* 12.6.2 The while Statement {{{ */
1231 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1234 /* 12.6.3 The for Statement {{{ */
1236 : "for" "(" LexPushInOn ForStatementInitialiser ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1239 ForStatementInitialiser
1240 : ExpressionOpt { $$ = $1; }
1241 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1244 /* 12.6.4 The for-in and for-of Statements {{{ */
1246 : "for" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1247 | "for" "(" LexPushInOn ForInStatementInitialiser "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1250 ForInStatementInitialiser
1251 : LeftHandSideExpression { $$ = $1; }
1252 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1256 /* 12.7 The continue Statement {{{ */
1258 : "continue" "\n" StrictSemi { $$ = CYNew CYContinue(NULL); }
1259 | "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1262 /* 12.8 The break Statement {{{ */
1264 : "break" "\n" StrictSemi { $$ = CYNew CYBreak(NULL); }
1265 | "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1268 /* 12.9 The return Statement {{{ */
1270 : "return" LexSetRegExp "\n" StrictSemi { $$ = CYNew CYReturn(NULL); }
1271 | "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1274 /* 12.10 The with Statement {{{ */
1276 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1280 /* 12.11 The switch Statement {{{ */
1282 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1286 : BRACE CaseClausesOpt "}" { $$ = $2; }
1290 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1294 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1295 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1300 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1303 /* 12.12 Labelled Statements {{{ */
1305 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1308 /* 12.13 The throw Statement {{{ */
1310 : "throw" LexSetRegExp "\n" StrictSemi { error(@1, "throw without exception"); }
1311 | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1314 /* 12.14 The try Statement {{{ */
1316 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1320 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1325 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1329 /* 12.14 The debugger Statement {{{ */
1331 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1335 /* 13.1 Function Definitions {{{ */
1337 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1341 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1344 FormalParameterList_
1345 : "," FormalParameterList { $$ = $2; }
1350 // XXX: : FunctionRestParameter { $$ = $1; }
1351 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1354 FormalParameterListOpt
1355 : FormalParameterList
1359 /* XXX: FunctionRestParameter
1360 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1364 : BindingElement { $$ = $1; }
1368 : StatementListOpt { $$ = $1; }
1371 /* 13.2 Arrow Function Definitions {{{ */
1373 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1377 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1378 | "(" LexPushInOff LexSetRegExp ")" LexPopIn { $$ = NULL; }
1379 | Parenthetical { $$ = $1->expression_->Parameter(); if ($$ == NULL) error(@1, "invalid parameter list"); }
1383 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1384 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1387 /* 14 Program {{{ */
1389 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1393 : StatementList { $$ = $1; }
1397 : ProgramBody { $$ = $1; }
1398 | LexSetStatement LexSetRegExp { $$ = NULL; }
1403 /* Cycript (C): Type Encoding {{{ */
1405 : IdentifierType { $$ = CYNew CYTypedIdentifier(@1, $1); }
1406 | "(" LexPushInOff "*" TypeQualifierRight ")" LexPopIn { $$ = $4; }
1410 : SuffixedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1411 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1412 | TypeSignifier "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $1; $$->modifier_ = CYNew CYTypeFunctionWith($4, $$->modifier_); }
1413 | "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypedIdentifier(@1); $$->modifier_ = CYNew CYTypeFunctionWith($3, $$->modifier_); }
1414 | TypeSignifier { $$ = $1; }
1415 | { $$ = CYNew CYTypedIdentifier(@$); }
1419 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1424 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1425 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1429 : PrefixedType { $$ = $1; }
1430 | SuffixedType { $$ = $1; }
1431 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1432 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1436 : "int" { $$ = CYNew CYTypeVariable("int"); }
1437 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1438 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1439 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1440 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1444 : IntegerType { $$ = $1; }
1445 | { $$ = CYNew CYTypeVariable("int"); }
1449 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1450 | IntegerType { $$ = $1; }
1451 | "void" { $$ = CYNew CYTypeVoid(); }
1452 | "char" { $$ = CYNew CYTypeVariable("char"); }
1453 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1454 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1458 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1462 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1468 /* Cycript (Objective-C): @class Declaration {{{ */
1470 /* XXX: why the hell did I choose MemberExpression? */
1471 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1476 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYClassField($1, $3); }
1477 | LexSetRegExp { $$ = NULL; }
1481 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1485 : "+" { $$ = false; }
1486 | "-" { $$ = true; }
1490 : "(" LexSetRegExp TypedIdentifier ")" { if ($3->identifier_ != NULL) error($3->location_, "unexpected identifier"); $$ = $3; }
1491 | { $$ = CYNew CYTypedIdentifier(CYNew CYTypeVariable("id")); }
1495 : Word ":" TypeOpt Identifier { $3->identifier_ = $4; $$ = CYNew CYMessageParameter($1, $3); }
1498 MessageParameterList
1499 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1502 MessageParameterListOpt
1503 : MessageParameterList { $$ = $1; }
1508 : MessageParameterList { $$ = $1; }
1509 | Word { $$ = CYNew CYMessageParameter($1, NULL); }
1512 ClassMessageDeclaration
1513 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1516 ClassMessageDeclarationListOpt
1517 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1518 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1523 : Identifier { $$ = $1; }
1524 | "(" AssignmentExpression ")" { $$ = $2; }
1528 : ClassName { $$ = $1; }
1532 // XXX: this should be AssignmentExpressionNoRight
1534 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1538 : "," ClassProtocols { $$ = $2; }
1542 ClassProtocolListOpt
1543 : "<" ClassProtocols ">" { $$ = $2; }
1548 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1552 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1560 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1564 : ClassExpression { $$ = $1; }
1568 : ClassStatement { $$ = $1; }
1569 | CategoryStatement { $$ = $1; }
1572 /* Cycript (Objective-C): Send Message {{{ */
1574 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1579 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1580 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1584 : SelectorCall { $$ = $1; }
1585 | VariadicCall { $$ = $1; }
1589 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYBlank(), $3, $4); }
1593 : SelectorCall { $$ = $1; }
1594 | Word { $$ = CYNew CYArgument($1, NULL); }
1598 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1599 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1603 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1607 : SelectorExpression_ { $$ = $1; }
1608 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1611 SelectorExpressionOpt
1612 : SelectorExpression_ { $$ = $1; }
1617 : MessageExpression { $$ = $1; }
1618 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1623 /* Cycript: @import Directive {{{ */
1625 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1626 | Word { $$ = CYNew CYModule($1); }
1630 : "@import" Module { $$ = CYNew CYImport($2); }
1635 /* Cycript (Objective-C): Boxed Expressions {{{ */
1637 : NullLiteral { $$ = $1; }
1638 | BooleanLiteral { $$ = $1; }
1639 | NumericLiteral { $$ = $1; }
1640 | StringLiteral { $$ = $1; }
1641 | ArrayLiteral { $$ = $1; }
1642 | ObjectLiteral { $$ = $1; }
1643 | Parenthetical { $$ = $1; }
1644 | "YES" { $$ = CYNew CYTrue(); }
1645 | "NO" { $$ = CYNew CYFalse(); }
1649 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1650 | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); }
1651 | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); }
1652 | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); }
1653 | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); }
1654 | "@null" { $$ = CYNew CYBox(CYNew CYNull()); }
1657 /* Cycript (Objective-C): Block Expressions {{{ */
1659 : "^" 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"); }
1662 /* Cycript (Objective-C): Instance Literals {{{ */
1664 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1670 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1671 LeftHandSideExpression
1672 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1676 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1680 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1681 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1682 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1685 /* Cycript (C): auto Compatibility {{{ */
1690 /* Cycript (C): Lambda Expressions {{{ */
1692 : "," TypedParameterList { $$ = $2; }
1697 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1700 TypedParameterListOpt
1701 : TypedParameterList { $$ = $1; }
1706 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1709 /* Cycript (C): Type Definitions {{{ */
1711 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) error($2->location_, "expected identifier"); } Terminator { $$ = CYNew CYTypeDefinition($2); }
1714 /* Cycript (C): extern "C" {{{ */
1716 : "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); }
1722 /* YUI: Documentation Comments {{{ */
1724 : Comment { $$ = $1; }
1729 /* Lexer State {{{ */
1731 : { driver.PushCondition(CYDriver::RegExpCondition); }
1735 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1739 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1743 : { driver.PopCondition(); }
1747 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1751 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1754 /* Virtual Tokens {{{ */
1761 /* 8.1 Context Keywords {{{ */
1763 : "namespace" { $$ = $1; }
1764 | "xml" { $$ = $1; }
1767 /* 8.3 XML Initialiser Input Elements {{{ */
1769 : XMLComment { $$ = $1; }
1770 | XMLCDATA { $$ = $1; }
1771 | XMLPI { $$ = $1; }
1775 /* 11.1 Primary Expressions {{{ */
1777 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1778 | XMLInitialiser { $$ = $1; }
1779 | XMLListInitialiser { $$ = $1; }
1783 : AttributeIdentifier { $$ = $1; }
1784 | QualifiedIdentifier { $$ = $1; }
1785 | WildcardIdentifier { $$ = $1; }
1788 /* 11.1.1 Attribute Identifiers {{{ */
1790 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1794 : PropertySelector { $$ = $1; }
1795 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1799 : Identifier { $$ = CYNew CYSelector($1); }
1800 | WildcardIdentifier { $$ = $1; }
1803 /* 11.1.2 Qualified Identifiers {{{ */
1804 QualifiedIdentifier_
1805 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1806 | QualifiedIdentifier { $$ = $1; }
1810 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1813 /* 11.1.3 Wildcard Identifiers {{{ */
1815 : "*" { $$ = CYNew CYWildcard(); }
1818 /* 11.1.4 XML Initialiser {{{ */
1820 : XMLMarkup { $$ = $1; }
1821 | XMLElement { $$ = $1; }
1825 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1826 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1830 : LexPushXMLTag XMLTagName XMLAttributes
1834 : BRACE LexPushRegExp Expression LexPop "}"
1843 : XMLAttributes_ XMLAttribute
1848 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1849 | XMLAttributes_ XMLWhitespaceOpt
1858 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1862 : XMLExpression XMLElementContentOpt
1863 | XMLMarkup XMLElementContentOpt
1864 | XMLText XMLElementContentOpt
1865 | XMLElement XMLElementContentOpt
1868 XMLElementContentOpt
1873 /* 11.1.5 XMLList Initialiser {{{ */
1875 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1879 /* 11.2 Left-Hand-Side Expressions {{{ */
1881 : Identifier { $$ = $1; }
1882 | PropertyIdentifier { $$ = $1; }
1886 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1887 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1888 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1891 /* 12.1 The default xml namespace Statement {{{ */
1892 /* XXX: DefaultXMLNamespaceStatement
1893 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1897 : DefaultXMLNamespaceStatement { $$ = $1; }
1902 /* JavaScript 1.7: Array Comprehensions {{{ */
1904 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1908 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1909 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1912 /* JavaScript 1.7: for each {{{ */
1914 : "for" "each" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1917 /* JavaScript 1.7: let Statements {{{ */
1919 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1927 /* JavaScript FTW: Ruby Blocks {{{ */
1928 RubyProcParameterList_
1929 : "," RubyProcParameterList { $$ = $2; }
1933 RubyProcParameterList
1934 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1939 : "|" RubyProcParameterList "|" { $$ = $2; }
1940 | "||" { $$ = NULL; }
1943 RubyProcParametersOpt
1944 : RubyProcParameters
1949 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1953 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
1957 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }