1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2014 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/>.
24 @if Bison24 %code top {
25 #define cyscanner driver.scanner_
26 #define YYSTACKEXPANDABLE 1
27 @if Bison23 #define yyerrok (yyerrstatus_ = 0)
30 @if Bison24 %code requires {
33 #define CYNew new($pool)
36 #include "ObjectiveC/Syntax.hpp"
40 #include "E4X/Syntax.hpp"
43 #include "Highlight.hpp"
52 CYDriver::Condition condition_;
54 CYArgument *argument_;
55 CYAssignment *assignment_;
58 cy::Syntax::Catch *catch_;
60 CYComprehension *comprehension_;
61 CYCompound *compound_;
62 CYDeclaration *declaration_;
63 CYDeclarations *declarations_;
65 CYExpression *expression_;
68 CYForInitialiser *for_;
69 CYForInInitialiser *forin_;
70 CYFunctionParameter *functionParameter_;
71 CYIdentifier *identifier_;
79 CYProperty *property_;
80 CYPropertyName *propertyName_;
81 CYRubyProc *rubyProc_;
82 CYStatement *statement_;
89 CYTypeModifier *modifier_;
90 CYTypeSpecifier *specifier_;
91 CYTypedIdentifier *typedIdentifier_;
92 CYTypedParameter *typedParameter_;
96 CYClassName *className_;
99 CYMessageParameter *messageParameter_;
100 CYProtocol *protocol_;
101 CYSelectorPart *selector_;
105 CYAttribute *attribute_;
106 CYPropertyIdentifier *propertyIdentifier_;
107 CYSelector *selector_;
112 #define YYSTYPE YYSTYPE
114 @if Bison24 %code provides {
115 int cylex(YYSTYPE *, cy::location *, void *);
128 @if Bison23 %skeleton "lalr1.cc"
129 @if Bison24 %language "C++"
132 @$.begin.filename = @$.end.filename = &driver.filename_;
143 %parse-param { CYDriver &driver }
144 %lex-param { void *cyscanner }
146 /* Token Declarations {{{ */
152 %token XMLAttributeValue
154 %token XMLTagCharacters
160 %token LeftRight "<>"
161 %token LeftSlashRight "</>"
163 %token SlashRight "/>"
164 %token LeftSlash "</"
166 %token ColonColon "::"
167 %token PeriodPeriod ".."
170 @begin E4X ObjectiveC
176 %token AmpersandAmpersand "&&"
177 %token AmpersandEqual "&="
179 %token CarrotEqual "^="
181 %token EqualEqual "=="
182 %token EqualEqualEqual "==="
183 %token EqualRight "=>"
184 %token Exclamation "!"
185 %token ExclamationEqual "!="
186 %token ExclamationEqualEqual "!=="
188 %token HyphenEqual "-="
189 %token HyphenHyphen "--"
190 %token HyphenHyphen_ "\n--"
191 %token HyphenRight "->"
193 %token LeftEqual "<="
195 %token LeftLeftEqual "<<="
197 %token PercentEqual "%="
199 %token PeriodPeriodPeriod "..."
201 %token PipeEqual "|="
204 %token PlusEqual "+="
206 %token PlusPlus_ "\n++"
208 %token RightEqual ">="
209 %token RightRight ">>"
210 %token RightRightEqual ">>="
211 %token RightRightRight ">>>"
212 %token RightRightRightEqual ">>>="
214 %token SlashEqual "/="
216 %token StarEqual "*="
225 %token <comment_> Comment
228 %token CloseParen ")"
231 %token OpenBrace_ "\n{"
232 %token OpenBrace__ ";{"
233 %token CloseBrace "}"
235 %token OpenBracket "["
236 %token CloseBracket "]"
238 %token AtError "@error"
241 %token AtClass "@class"
245 %token <identifier_> Typedef "typedef"
246 %token <identifier_> Unsigned "unsigned"
247 %token <identifier_> Signed "signed"
248 %token <identifier_> Extern "extern"
252 %token AtEncode "@encode"
256 %token AtImplementation "@implementation"
257 %token AtImplementation_ ";@implementation"
258 %token AtImport "@import"
260 %token AtSelector "@selector"
261 %token <identifier_> Yes "YES"
262 %token <identifier_> No "NO"
265 %token <false_> False "false"
266 %token <null_> Null "null"
267 %token <true_> True "true"
269 // ES3/ES5/WIE/JSC Reserved
270 %token <word_> Auto "auto"
271 %token <word_> Break "break"
272 %token <word_> Case "case"
273 %token <word_> Catch "catch"
274 %token <word_> Continue "continue"
275 %token <word_> Default "default"
276 %token <word_> Delete "delete"
277 %token <word_> Do "do"
278 %token <word_> Else "else"
279 %token <word_> Finally "finally"
280 %token <word_> For "for"
281 %token <word_> Function "function"
282 %token <word_> Function_ ";function"
283 %token <word_> If "if"
284 %token <word_> In "in"
285 %token <word_> In_ "!in"
286 %token <word_> InstanceOf "instanceof"
287 %token <word_> New "new"
288 %token <word_> Return "return"
289 %token <word_> Switch "switch"
290 %token <this_> This "this"
291 %token <word_> Throw "throw"
292 %token <word_> Try "try"
293 %token <word_> TypeOf "typeof"
294 %token <word_> Var "var"
295 %token <word_> Void "void"
296 %token <word_> While "while"
297 %token <word_> With "with"
299 // ES3/IE6 Future, ES5/JSC Reserved
300 %token <word_> Debugger "debugger"
302 // ES3/ES5/IE6 Future, JSC Reserved
303 %token <word_> Const "const"
305 // ES3/ES5/IE6/JSC Future
306 %token <word_> Class "class"
307 %token <word_> Enum "enum"
308 %token <word_> Export "export"
309 %token <word_> Extends "extends"
310 %token <word_> Import "import"
311 %token <word_> Super "super"
313 // ES3 Future, ES5 Strict Future
314 %token <identifier_> Implements "implements"
315 %token <identifier_> Interface "interface"
316 %token <identifier_> Package "package"
317 %token <identifier_> Private "private"
318 %token <identifier_> Protected "protected"
319 %token <identifier_> Public "public"
320 %token <identifier_> Static "static"
323 %token <identifier_> Abstract "abstract"
324 %token <identifier_> Boolean "boolean"
325 %token <identifier_> Byte "byte"
326 %token <identifier_> Char "char"
327 %token <identifier_> Double "double"
328 %token <identifier_> Final "final"
329 %token <identifier_> Float "float"
330 %token <identifier_> Goto "goto"
331 %token <identifier_> Int "int"
332 %token <identifier_> Long "long"
333 %token <identifier_> Native "native"
334 %token <identifier_> Short "short"
335 %token <identifier_> Synchronized "synchronized"
336 %token <identifier_> Throws "throws"
337 %token <identifier_> Transient "transient"
338 %token <identifier_> Volatile "volatile"
341 %token <identifier_> Let "let"
342 %token <identifier_> Yield "yield"
345 %token <identifier_> Each "each"
346 %token <identifier_> Of "of"
350 %token <identifier_> Namespace "namespace"
351 %token <identifier_> XML "xml"
356 %token <identifier_> Identifier_
357 %token <number_> NumericLiteral
358 %token <string_> StringLiteral
359 %token <literal_> RegularExpressionLiteral
361 %type <expression_> AdditiveExpression
362 %type <argument_> ArgumentList_
363 %type <argument_> ArgumentList
364 %type <argument_> ArgumentListOpt
365 %type <argument_> Arguments
366 %type <expression_> ArrayComprehension
367 %type <expression_> ArrayInitialiser
368 %type <literal_> ArrayLiteral
369 %type <expression_> ArrowFunction
370 %type <functionParameter_> ArrowParameters
371 %type <expression_> AssignmentExpression
372 %type <identifier_> Binding
373 %type <identifier_> BindingIdentifier
374 %type <expression_> BitwiseANDExpression
375 %type <statement_> Block_
376 %type <statement_> Block
377 %type <boolean_> BooleanLiteral
378 %type <declaration_> BindingElement
379 %type <expression_> BitwiseORExpression
380 %type <expression_> BitwiseXORExpression
381 %type <statement_> BreakStatement
382 %type <statement_> BreakableStatement
383 %type <expression_> CallExpression_
384 %type <expression_> CallExpression
385 %type <clause_> CaseBlock
386 %type <clause_> CaseClause
387 %type <clause_> CaseClausesOpt
388 %type <catch_> CatchOpt
389 %type <expression_> Comprehension
390 %type <comprehension_> ComprehensionFor
391 %type <comprehension_> ComprehensionIf
392 %type <comprehension_> ComprehensionTail
393 %type <expression_> ConditionalExpression
394 %type <statement_> ContinueStatement
395 %type <statement_> ConciseBody
396 %type <statement_> DebuggerStatement
397 %type <statement_> Declaration__
398 %type <statement_> Declaration_
399 %type <statement_> Declaration
400 %type <clause_> DefaultClause
401 %type <expression_> Element
402 %type <expression_> ElementOpt
403 %type <element_> ElementList
404 %type <element_> ElementListOpt
405 %type <statement_> ElseStatementOpt
406 %type <statement_> EmptyStatement
407 %type <expression_> EqualityExpression
408 %type <compound_> Expression_
409 %type <compound_> Expression
410 %type <expression_> ExpressionOpt
411 %type <statement_> ExpressionStatement
412 %type <finally_> FinallyOpt
413 %type <for_> ForStatementInitialiser
414 %type <forin_> ForInStatementInitialiser
415 %type <declaration_> FormalParameter
416 %type <functionParameter_> FormalParameterList_
417 %type <functionParameter_> FormalParameterList
418 %type <functionParameter_> FormalParameterListOpt
419 %type <statement_> FunctionBody
420 %type <statement_> FunctionDeclaration
421 %type <expression_> FunctionExpression
422 %type <identifier_> Identifier
423 %type <identifier_> IdentifierOpt
424 %type <identifier_> IdentifierType
425 %type <word_> IdentifierName
426 %type <statement_> IfStatement
427 %type <expression_> Initialiser
428 %type <expression_> InitialiserOpt
429 %type <statement_> IterationStatement
430 %type <statement_> LabelledStatement
431 %type <expression_> LeftHandSideExpression
432 %type <statement_> LetStatement
433 %type <statement_> LexicalDeclaration
434 %type <literal_> Literal
435 %type <literal_> ValueLiteral
436 %type <expression_> LogicalANDExpression
437 %type <expression_> LogicalORExpression
438 %type <member_> MemberAccess
439 %type <expression_> MemberExpression_
440 %type <expression_> MemberExpression
441 %type <module_> Module
442 %type <expression_> MultiplicativeExpression
443 %type <expression_> NewExpression
444 %type <null_> NullLiteral
445 %type <literal_> ObjectLiteral
446 %type <compound_> Parenthetical
447 %type <compound_> ParentheticalOpt
448 %type <expression_> PostfixExpression
449 %type <expression_> PrimaryExpression
450 %type <statement_> Program
451 %type <statement_> ProgramBody
452 %type <statement_> ProgramBodyOpt
453 %type <propertyName_> PropertyName_
454 %type <propertyName_> PropertyName
455 %type <property_> PropertyDefinition
456 %type <property_> PropertyDefinitionList_
457 %type <property_> PropertyDefinitionList
458 %type <property_> PropertyDefinitionListOpt
459 %type <expression_> RelationalExpression
460 %type <statement_> ReturnStatement
461 %type <rubyProc_> RubyProcExpression
462 %type <functionParameter_> RubyProcParameterList_
463 %type <functionParameter_> RubyProcParameterList
464 %type <functionParameter_> RubyProcParameters
465 %type <functionParameter_> RubyProcParametersOpt
466 %type <expression_> ShiftExpression
467 %type <declaration_> SingleNameBinding
468 %type <statement_> Statement__
469 %type <statement_> Statement_
470 %type <statement_> Statement
471 %type <statement_> StatementList
472 %type <statement_> StatementListOpt
473 %type <statement_> StatementListItem
474 %type <statement_> SwitchStatement
475 %type <statement_> ThrowStatement
476 %type <statement_> TryStatement
477 %type <expression_> UnaryExpression_
478 %type <expression_> UnaryExpression
479 %type <declaration_> VariableDeclaration
480 %type <declarations_> VariableDeclarationList_
481 %type <declarations_> VariableDeclarationList
482 %type <statement_> VariableStatement
483 %type <statement_> WithStatement
485 %type <word_> WordOpt
486 %type <expression_> Variable
489 %type <typedIdentifier_> ArrayedType
490 %type <modifier_> FunctionedType
491 %type <specifier_> IntegerType
492 %type <specifier_> IntegerTypeOpt
493 %type <typedIdentifier_> PrefixedType
494 %type <specifier_> PrimitiveType
495 %type <typedIdentifier_> TypeParenthetical
496 %type <typedIdentifier_> TypeSignifier
497 %type <typedIdentifier_> SuffixedType
498 %type <modifier_> TypeQualifierLeft
499 %type <typedIdentifier_> TypeQualifierRight
500 %type <typedIdentifier_> TypedIdentifier
501 %type <typedParameter_> TypedParameterList_
502 %type <typedParameter_> TypedParameterList
503 %type <typedParameter_> TypedParameterListOpt
507 %type <expression_> BoxableExpression
508 %type <statement_> CategoryStatement
509 %type <expression_> ClassExpression
510 %type <field_> ClassFieldListOpt
511 %type <field_> ClassFields
512 %type <statement_> ClassStatement
513 %type <expression_> ClassSuperOpt
514 %type <message_> ClassMessageDeclaration
515 %type <message_> ClassMessageDeclarationListOpt
516 %type <className_> ClassName
517 %type <className_> ClassNameOpt
518 %type <protocol_> ClassProtocolListOpt
519 %type <protocol_> ClassProtocols
520 %type <protocol_> ClassProtocolsOpt
521 %type <expression_> MessageExpression
522 %type <messageParameter_> MessageParameter
523 %type <messageParameter_> MessageParameters
524 %type <messageParameter_> MessageParameterList
525 %type <messageParameter_> MessageParameterListOpt
526 %type <bool_> MessageScope
527 %type <typedIdentifier_> ModifiedType
528 %type <argument_> SelectorCall_
529 %type <argument_> SelectorCall
530 %type <selector_> SelectorExpression_
531 %type <selector_> SelectorExpression
532 %type <selector_> SelectorExpressionOpt
533 %type <argument_> SelectorList
534 %type <word_> SelectorWordOpt
535 %type <typedIdentifier_> TypeOpt
536 %type <argument_> VariadicCall
540 %type <propertyIdentifier_> PropertyIdentifier_
541 %type <selector_> PropertySelector_
542 %type <selector_> PropertySelector
543 %type <identifier_> QualifiedIdentifier_
544 %type <identifier_> QualifiedIdentifier
545 %type <identifier_> WildcardIdentifier
546 %type <identifier_> XMLComment
547 %type <identifier_> XMLCDATA
548 %type <identifier_> XMLElement
549 %type <identifier_> XMLElementContent
550 %type <identifier_> XMLMarkup
551 %type <identifier_> XMLPI
553 %type <attribute_> AttributeIdentifier
554 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
555 %type <expression_> PropertyIdentifier
556 %type <expression_> XMLListInitialiser
557 %type <expression_> XMLInitialiser
560 /* Token Priorities {{{ */
572 /* Lexer State {{{ */
574 : { driver.in_.push(true); }
578 : { driver.in_.push(false); }
582 : { driver.in_.pop(); }
586 : { driver.SetCondition(CYDriver::RegExpCondition); }
590 : { if (yychar == yyempty_) driver.no_.OpenBrace = true; else if (yychar == token::OpenBrace || yychar == token::OpenBrace_) yychar = token::OpenBrace__; }
594 : { if (yychar == yyempty_) driver.no_.Function = true; else if (yychar == token::Function) yychar = token::Function_; }
597 LexNoAtImplementation :
599 { if (yychar == yyempty_) driver.no_.AtImplementation = true; else if (yychar == token::AtImplementation) yychar = token::AtImplementation_; }
604 : LexNoBrace LexNoFunction LexNoAtImplementation
607 /* Virtual Tokens {{{ */
618 /* 7.6 Identifier Names and Identifiers {{{ */
629 : Identifier { $$ = $1; }
630 | "auto" { $$ = $1; }
631 | "break" NewLineOpt { $$ = $1; }
632 | "case" { $$ = $1; }
633 | "catch" { $$ = $1; }
634 | "class" { $$ = $1; }
635 | "const" { $$ = $1; }
636 | "continue" NewLineOpt { $$ = $1; }
637 | "debugger" { $$ = $1; }
638 | "default" { $$ = $1; }
639 | "delete" { $$ = $1; }
641 | "else" { $$ = $1; }
642 | "enum" { $$ = $1; }
643 | "export" { $$ = $1; }
644 | "extends" { $$ = $1; }
645 | "false" { $$ = $1; }
646 | "finally" { $$ = $1; }
647 /* XXX: | "for" { $$ = $1; } */
648 | "function" { $$ = $1; }
650 | "import" { $$ = $1; }
651 /* XXX: | "in" { $$ = $1; } */
653 /* XXX: | "instanceof" { $$ = $1; } */
655 // XXX: as it currently is not an Identifier
659 | "null" { $$ = $1; }
660 | "return" NewLineOpt { $$ = $1; }
661 | "super" { $$ = $1; }
662 | "switch" { $$ = $1; }
663 | "this" { $$ = $1; }
664 | "throw" NewLineOpt { $$ = $1; }
665 | "true" { $$ = $1; }
667 | "typeof" { $$ = $1; }
669 | "void" { $$ = $1; }
670 | "while" { $$ = $1; }
671 | "with" { $$ = $1; }
680 : Identifier_ { $$ = $1; }
682 | "implements" { $$ = $1; }
683 | "interface" { $$ = $1; }
684 | "package" { $$ = $1; }
685 | "private" { $$ = $1; }
686 | "protected" { $$ = $1; }
687 | "public" { $$ = $1; }
688 | "static" { $$ = $1; }
690 | "abstract" { $$ = $1; }
691 | "boolean" { $$ = $1; }
692 | "byte" { $$ = $1; }
693 | "double" { $$ = $1; }
694 | "final" { $$ = $1; }
695 | "float" { $$ = $1; }
696 | "goto" { $$ = $1; }
697 | "native" { $$ = $1; }
698 | "synchronized" { $$ = $1; }
699 | "throws" { $$ = $1; }
700 | "transient" { $$ = $1; }
702 // XXX: currently I only have this as Word
703 // | "let" { $$ = $1; }
705 | "yield" { $$ = $1; }
707 | "each" { $$ = $1; }
713 | "char" { $$ = $1; }
715 | "long" { $$ = $1; }
716 | "short" { $$ = $1; }
717 | "volatile" { $$ = $1; }
719 | "typedef" { $$ = $1; }
720 | "unsigned" { $$ = $1; }
721 | "signed" { $$ = $1; }
722 | "extern" { $$ = $1; }
731 : Identifier { $$ = $1; }
736 /* 7.8 Literals {{{ */
738 : NullLiteral { $$ = $1; }
739 | ValueLiteral { $$ = $1; }
743 : BooleanLiteral { $$ = $1; }
744 | NumericLiteral { $$ = $1; }
745 | StringLiteral { $$ = $1; }
746 | RegularExpressionLiteral { $$ = $1; }
749 /* 7.8.1 Null Literals {{{ */
751 : "null" { $$ = $1; }
754 /* 7.8.2 Boolean Literals {{{ */
756 : "true" { $$ = $1; }
757 | "false" { $$ = $1; }
761 /* 7.9 Automatic Semicolon Insertion {{{ */
763 : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
768 | error { if (yychar != yyeof_ && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
773 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
777 /* 11.1 Primary Expressions {{{ */
779 : "(" LexPushInOff Expression ")" LexPopIn { $$ = $3; }
783 : Parenthetical { $$ = $1; }
788 : Identifier { $$ = CYNew CYVariable($1); }
792 : "this" { $$ = $1; }
793 | Variable { $$ = $1; }
794 | Literal { $$ = $1; }
795 | ArrayInitialiser { $$ = $1; }
796 | ObjectLiteral { $$ = $1; }
797 | Parenthetical { $$ = $1; }
798 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
801 /* 11.1.4 Array Initializer {{{ */
803 : ArrayLiteral { $$ = $1; }
804 | ArrayComprehension { $$ = $1; }
807 /* 11.1.4.1 Array Literal {{{ */
809 : "[" LexPushInOff ElementListOpt "]" LexPopIn { $$ = CYNew CYArray($3); }
813 : AssignmentExpression { $$ = $1; }
817 : Element { $$ = $1; }
818 | LexSetRegExp { $$ = NULL; }
822 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
823 | Element { $$ = CYNew CYElement($1, NULL); }
827 : ElementList { $$ = $1; }
828 | LexSetRegExp { $$ = NULL; }
831 /* 11.1.4.2 Array Comprehension {{{ */
833 : "[" LexPushInOff Comprehension "]" LexPopIn { $$ = $3; }
837 : LexSetRegExp ComprehensionFor ComprehensionTail AssignmentExpression { $$ = CYNew CYArrayComprehension($4, $2->Modify($3)); }
842 | ComprehensionFor ComprehensionTail { $$ = $1->Modify($2); }
843 | ComprehensionIf ComprehensionTail { $$ = $1->Modify($2); }
847 : "for" "(" Binding "of" Expression ")" { $$ = CYNew CYForOfComprehension($3, $5); }
851 : "if" "(" AssignmentExpression ")" { $$ = CYNew CYIfComprehension($3); }
854 /* 11.1.5 Object Initialiser {{{ */
856 : BRACE LexPushInOff PropertyDefinitionListOpt "}" LexPopIn { $$ = CYNew CYObject($3); }
859 PropertyDefinitionList_
860 : "," PropertyDefinitionList { $$ = $2; }
861 | "," LexSetRegExp { $$ = NULL; }
865 PropertyDefinitionList
866 : PropertyDefinition PropertyDefinitionList_ { $1->SetNext($2); $$ = $1; }
869 PropertyDefinitionListOpt
870 : PropertyDefinitionList { $$ = $1; }
871 | LexSetRegExp { $$ = NULL; }
875 // XXX: this should be IdentifierName
876 : LexSetRegExp Identifier { $$ = CYNew CYProperty($2, CYNew CYVariable($2)); }
877 | PropertyName ":" AssignmentExpression { $$ = CYNew CYProperty($1, $3); }
882 : IdentifierName { $$ = $1; }
883 | StringLiteral { $$ = $1; }
884 | NumericLiteral { $$ = $1; }
888 : LexSetRegExp PropertyName_ { $$ = $2; }
892 /* 11.2 Left-Hand-Side Expressions {{{ */
894 : "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYDirectMember(NULL, $3); }
895 | "." IdentifierName { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
896 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
900 : MemberExpression { $$ = $1; }
901 //| "super" { $$ = $1; }
905 : LexSetRegExp PrimaryExpression { $$ = $2; }
906 | LexSetRegExp FunctionExpression { $$ = $2; }
907 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
908 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
912 : MemberExpression { $$ = $1; }
913 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
922 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
923 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
927 : "(" LexPushInOff ArgumentListOpt ")" LexPopIn { $$ = $3; }
931 : "," ArgumentList { $$ = $2; }
936 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
940 : ArgumentList { $$ = $1; }
941 | LexSetRegExp { $$ = NULL; }
944 LeftHandSideExpression
945 : NewExpression { $$ = $1; }
946 | CallExpression { $$ = $1; }
949 /* 11.3 Postfix Expressions {{{ */
951 : %prec "" LeftHandSideExpression { $$ = $1; }
952 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
953 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
956 /* 11.4 Unary Operators {{{ */
958 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
959 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
960 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
961 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
962 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
963 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
964 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
965 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
966 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
967 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
968 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
972 : PostfixExpression { $$ = $1; }
973 | LexSetRegExp UnaryExpression_ { $$ = $2; }
976 /* 11.5 Multiplicative Operators {{{ */
977 MultiplicativeExpression
978 : UnaryExpression { $$ = $1; }
979 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
980 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
981 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
984 /* 11.6 Additive Operators {{{ */
986 : MultiplicativeExpression { $$ = $1; }
987 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
988 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
991 /* 11.7 Bitwise Shift Operators {{{ */
993 : AdditiveExpression { $$ = $1; }
994 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
995 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
996 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
999 /* 11.8 Relational Operators {{{ */
1000 RelationalExpression
1001 : ShiftExpression { $$ = $1; }
1002 | RelationalExpression "<" ShiftExpression { $$ = CYNew CYLess($1, $3); }
1003 | RelationalExpression ">" ShiftExpression { $$ = CYNew CYGreater($1, $3); }
1004 | RelationalExpression "<=" ShiftExpression { $$ = CYNew CYLessOrEqual($1, $3); }
1005 | RelationalExpression ">=" ShiftExpression { $$ = CYNew CYGreaterOrEqual($1, $3); }
1006 | RelationalExpression "instanceof" ShiftExpression { $$ = CYNew CYInstanceOf($1, $3); }
1007 | RelationalExpression "in" ShiftExpression { $$ = CYNew CYIn($1, $3); }
1010 /* 11.9 Equality Operators {{{ */
1012 : RelationalExpression { $$ = $1; }
1013 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
1014 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
1015 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
1016 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
1019 /* 11.10 Binary Bitwise Operators {{{ */
1020 BitwiseANDExpression
1021 : EqualityExpression { $$ = $1; }
1022 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
1025 BitwiseXORExpression
1026 : BitwiseANDExpression { $$ = $1; }
1027 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
1031 : BitwiseXORExpression { $$ = $1; }
1032 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
1035 /* 11.11 Binary Logical Operators {{{ */
1036 LogicalANDExpression
1037 : BitwiseORExpression { $$ = $1; }
1038 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
1042 : LogicalANDExpression { $$ = $1; }
1043 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
1046 /* 11.12 Conditional Operator ( ? : ) {{{ */
1047 ConditionalExpression
1048 : LogicalORExpression { $$ = $1; }
1049 | LogicalORExpression "?" LexPushInOff AssignmentExpression ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
1050 | LogicalORExpression "?" LexPushInOff LexSetRegExp ":" LexPopIn AssignmentExpression { $$ = CYNew CYCondition($1, $1, $7); }
1053 /* 11.13 Assignment Operators {{{ */
1054 AssignmentExpression
1055 : ConditionalExpression { $$ = $1; }
1056 | ArrowFunction { $$ = $1; }
1057 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
1058 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
1059 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
1060 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
1061 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
1062 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
1063 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
1064 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
1065 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
1066 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
1067 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
1068 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
1071 /* 11.14 Comma Operator {{{ */
1073 : "," Expression { $$ = $2; }
1078 : AssignmentExpression Expression_ { $$ = CYNew CYCompound($1, $2); }
1082 : Expression { $$ = $1; }
1083 | LexSetRegExp { $$ = NULL; }
1087 /* 12 Statements {{{ */
1089 : Block { $$ = $1; }
1090 | VariableStatement { $$ = $1; }
1091 | EmptyStatement { $$ = $1; }
1092 | IfStatement { $$ = $1; }
1093 | BreakableStatement { $$ = $1; }
1094 | ContinueStatement { $$ = $1; }
1095 | BreakStatement { $$ = $1; }
1096 | ReturnStatement { $$ = $1; }
1097 | WithStatement { $$ = $1; }
1098 | LabelledStatement { $$ = $1; }
1099 | ThrowStatement { $$ = $1; }
1100 | TryStatement { $$ = $1; }
1101 | DebuggerStatement { $$ = $1; }
1105 : LexSetRegExp Statement__ { $$ = $2; }
1106 | ExpressionStatement { $$ = $1; }
1110 : LexSetStatement Statement_ { $$ = $2; }
1114 : FunctionDeclaration { $$ = $1; }
1115 | LexicalDeclaration { $$ = $1; }
1119 : LexSetRegExp Declaration__ { $$ = $2; }
1123 : LexSetStatement Declaration_ { $$ = $2; }
1127 : IterationStatement { $$ = $1; }
1128 | SwitchStatement { $$ = $1; }
1131 /* 12.1 Block {{{ */
1133 : BRACE StatementListOpt "}" { $$ = $2; }
1137 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1141 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1145 : StatementList { $$ = $1; }
1146 | LexSetStatement LexSetRegExp { $$ = NULL; }
1150 : Statement { $$ = $1; }
1151 | Declaration { $$ = $1; }
1155 /* 12.2 Declarations {{{ */
1157 : Identifier { $$ = $1; }
1164 // XXX: BindingPattern
1166 /* 12.2.1 Let and Const Declarations {{{ */
1168 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1176 /* 12.2.2 Variable Statement {{{ */
1178 : Var_ VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1181 VariableDeclarationList_
1182 : "," VariableDeclarationList { $$ = $2; }
1186 VariableDeclarationList
1187 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1191 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1192 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1196 : "=" AssignmentExpression { $$ = $2; }
1200 : Initialiser { $$ = $1; }
1204 /* 12.2.4 Destructuring Binding Patterns {{{ */
1208 : SingleNameBinding { $$ = $1; }
1212 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1216 /* 12.3 Empty Statement {{{ */
1218 : ";" { $$ = CYNew CYEmpty(); }
1221 /* 12.4 Expression Statement {{{ */
1223 : Expression Terminator { $$ = CYNew CYExpress($1); }
1226 /* 12.5 The if Statement {{{ */
1228 : "else" Statement { $$ = $2; }
1229 | %prec "if" { $$ = NULL; }
1233 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1237 /* 12.6.1 The do-while Statement {{{ */
1239 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1242 /* 12.6.2 The while Statement {{{ */
1244 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1247 /* 12.6.3 The for Statement {{{ */
1249 : "for" "(" LexPushInOn ForStatementInitialiser ";" LexPopIn ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1252 ForStatementInitialiser
1253 : ExpressionOpt { $$ = $1; }
1254 | LexSetRegExp Var_ VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1257 /* 12.6.4 The for-in and for-of Statements {{{ */
1259 : "for" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1260 | "for" "(" LexPushInOn ForInStatementInitialiser "of" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($4, $7, $9); }
1263 ForInStatementInitialiser
1264 : LeftHandSideExpression { $$ = $1; }
1265 | LexSetRegExp Var_ VariableDeclaration { $$ = $3; }
1269 /* 12.7 The continue Statement {{{ */
1271 : "continue" "\n" StrictSemi { $$ = CYNew CYContinue(NULL); }
1272 | "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1275 /* 12.8 The break Statement {{{ */
1277 : "break" "\n" StrictSemi { $$ = CYNew CYBreak(NULL); }
1278 | "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1281 /* 12.9 The return Statement {{{ */
1283 : "return" LexSetRegExp "\n" StrictSemi { $$ = CYNew CYReturn(NULL); }
1284 | "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1287 /* 12.10 The with Statement {{{ */
1289 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1293 /* 12.11 The switch Statement {{{ */
1295 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1299 : BRACE CaseClausesOpt "}" { $$ = $2; }
1303 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1307 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1308 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1313 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1316 /* 12.12 Labelled Statements {{{ */
1318 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1321 /* 12.13 The throw Statement {{{ */
1323 : "throw" LexSetRegExp "\n" StrictSemi { YYABORT; }
1324 | "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1327 /* 12.14 The try Statement {{{ */
1329 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1333 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1338 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1342 /* 12.14 The debugger Statement {{{ */
1344 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1348 /* 13.1 Function Definitions {{{ */
1350 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1354 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1357 FormalParameterList_
1358 : "," FormalParameterList { $$ = $2; }
1363 // XXX: : FunctionRestParameter { $$ = $1; }
1364 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1367 FormalParameterListOpt
1368 : FormalParameterList
1372 /* XXX: FunctionRestParameter
1373 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1377 : BindingElement { $$ = $1; }
1381 : StatementListOpt { $$ = $1; }
1384 /* 13.2 Arrow Function Definitions {{{ */
1386 : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); }
1390 : BindingIdentifier { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1)); }
1391 //| ParentheticalOpt { $$ = $1; }
1395 : AssignmentExpression { $$ = CYNew CYReturn($1); }
1396 | LexSetRegExp ";{" LexPushInOff FunctionBody "}" LexPopIn { $$ = $4; }
1399 /* 14 Program {{{ */
1401 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1405 : StatementList { $$ = $1; }
1409 : ProgramBody { $$ = $1; }
1410 | LexSetStatement LexSetRegExp { $$ = NULL; }
1415 /* Cycript (C): Type Encoding {{{ */
1417 : "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; }
1421 : IdentifierType { $$ = CYNew CYTypedIdentifier($1); }
1422 | TypeParenthetical { $$ = $1; }
1426 : ArrayedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
1427 | TypeSignifier { $$ = $1; }
1428 | { $$ = CYNew CYTypedIdentifier(); }
1432 : "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypeFunctionWith($3); }
1436 : ArrayedType { $$ = $1; }
1437 | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
1438 | TypeParenthetical FunctionedType { $$ = $1; CYSetLast($2) = $$->modifier_; $$->modifier_ = $2; }
1439 | IdentifierType FunctionedType { $$ = CYNew CYTypedIdentifier($1); CYSetLast($2) = $$->modifier_; $$->modifier_ = $2; }
1440 | FunctionedType { $$ = CYNew CYTypedIdentifier(); CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1444 : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1449 | "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
1450 | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); }
1454 : PrefixedType { $$ = $1; }
1455 | SuffixedType { $$ = $1; }
1456 | "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
1457 | "volatile" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); }
1461 : "int" { $$ = CYNew CYTypeVariable("int"); }
1462 | "unsigned" IntegerTypeOpt { $$ = CYNew CYTypeUnsigned($2); }
1463 | "signed" IntegerTypeOpt { $$ = CYNew CYTypeSigned($2); }
1464 | "long" IntegerTypeOpt { $$ = CYNew CYTypeLong($2); }
1465 | "short" IntegerTypeOpt { $$ = CYNew CYTypeShort($2); }
1469 : IntegerType { $$ = $1; }
1470 | { $$ = CYNew CYTypeVariable("int"); }
1474 : IdentifierType { $$ = CYNew CYTypeVariable($1); }
1475 | IntegerType { $$ = $1; }
1476 | "void" { $$ = CYNew CYTypeVoid(); }
1477 | "char" { $$ = CYNew CYTypeVariable("char"); }
1478 | "signed" "char" { $$ = CYNew CYTypeSigned(CYNew CYTypeVariable("char")); }
1479 | "unsigned" "char" { $$ = CYNew CYTypeUnsigned(CYNew CYTypeVariable("char")); }
1483 : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->specifier_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
1487 : "@encode" "(" TypedIdentifier ")" { $$ = CYNew CYEncodedType($3); }
1493 /* Cycript (Objective-C): @class Declaration {{{ */
1495 /* XXX: why the hell did I choose MemberExpression? */
1496 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1501 : TypedIdentifier ";" ClassFieldListOpt { $$ = CYNew CYField($1, $3); }
1502 | LexSetRegExp { $$ = NULL; }
1506 : BRACE ClassFieldListOpt "}" { $$ = $2; }
1510 : "+" { $$ = false; }
1511 | "-" { $$ = true; }
1515 : "(" LexSetRegExp TypedIdentifier ")" { $$ = $3; }
1520 : Word ":" TypeOpt Identifier { $$ = CYNew CYMessageParameter($1, $3, $4); }
1523 MessageParameterList
1524 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1527 MessageParameterListOpt
1528 : MessageParameterList { $$ = $1; }
1533 : MessageParameterList { $$ = $1; }
1534 | Word { $$ = CYNew CYMessageParameter($1, NULL, NULL); }
1537 ClassMessageDeclaration
1538 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1541 ClassMessageDeclarationListOpt
1542 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1543 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1548 : Identifier { $$ = $1; }
1549 | "(" AssignmentExpression ")" { $$ = $2; }
1553 : ClassName { $$ = $1; }
1557 // XXX: this should be AssignmentExpressionNoRight
1559 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1563 : "," ClassProtocols { $$ = $2; }
1567 ClassProtocolListOpt
1568 : "<" ClassProtocols ">" { $$ = $2; }
1573 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" LexPopIn { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1577 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFields ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1585 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1589 : ClassExpression { $$ = $1; }
1593 : ClassStatement { $$ = $1; }
1594 | CategoryStatement { $$ = $1; }
1597 /* Cycript (Objective-C): Send Message {{{ */
1599 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1604 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1605 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1609 : SelectorCall { $$ = $1; }
1610 | VariadicCall { $$ = $1; }
1614 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYBlank(), $3, $4); }
1618 : SelectorCall { $$ = $1; }
1619 | Word { $$ = CYNew CYArgument($1, NULL); }
1623 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList "]" LexPopIn { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1624 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList "]" LexPopIn { $$ = CYNew CYSendSuper($6); }
1628 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1632 : SelectorExpression_ { $$ = $1; }
1633 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1636 SelectorExpressionOpt
1637 : SelectorExpression_ { $$ = $1; }
1642 : MessageExpression { $$ = $1; }
1643 | "@selector" "(" LexPushInOff SelectorExpression ")" LexPopIn { $$ = CYNew CYSelector($4); }
1648 /* Cycript: @import Directive {{{ */
1650 : Module "." Word { $$ = CYNew CYModule($3, $1); }
1651 | Word { $$ = CYNew CYModule($1); }
1655 : "@import" Module { $$ = CYNew CYImport($2); }
1660 /* Cycript (Objective-C): Boxed Expressions {{{ */
1662 : NullLiteral { $$ = $1; }
1663 | BooleanLiteral { $$ = $1; }
1664 | NumericLiteral { $$ = $1; }
1665 | StringLiteral { $$ = $1; }
1666 | ArrayLiteral { $$ = $1; }
1667 | ObjectLiteral { $$ = $1; }
1668 | Parenthetical { $$ = $1; }
1669 | "YES" { $$ = CYNew CYTrue(); }
1670 | "NO" { $$ = CYNew CYFalse(); }
1674 : "@" BoxableExpression { $$ = CYNew CYBox($2); }
1677 /* Cycript (Objective-C): Block Expressions {{{ */
1679 : TypeQualifierLeft PrimitiveType { $$ = CYNew CYTypedIdentifier(); $$->specifier_ = $2; $$->modifier_ = $1; }
1680 | ModifiedType "*" { $$ = $1; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
1684 : "^" ModifiedType "(" LexPushInOff TypedParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYObjCBlock($2, $5, $10); }
1687 /* Cycript (Objective-C): Instance Literals {{{ */
1689 : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); }
1695 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1696 LeftHandSideExpression
1697 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1701 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1705 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1706 | "->" IdentifierName { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1707 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1710 /* Cycript (C): auto Compatibility {{{ */
1715 /* Cycript (C): Lambda Expressions {{{ */
1717 : "," TypedParameterList { $$ = $2; }
1722 : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
1725 TypedParameterListOpt
1726 : TypedParameterList { $$ = $1; }
1731 : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
1734 /* Cycript (C): Type Definitions {{{ */
1736 : "typedef" TypedIdentifier { if ($2->identifier_ == NULL) YYABORT; } Terminator { $$ = CYNew CYTypeDefinition($2); }
1739 /* Cycript (C): extern "C" {{{ */
1741 : "extern" StringLiteral { if (strcmp($2->Value(), "C") != 0) YYABORT; } TypedIdentifier Terminator { $$ = CYNew CYExternal($2, $4); }
1747 /* YUI: Documentation Comments {{{ */
1749 : Comment { $$ = $1; }
1754 /* Lexer State {{{ */
1756 : { driver.PushCondition(CYDriver::RegExpCondition); }
1760 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1764 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1768 : { driver.PopCondition(); }
1772 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1776 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1779 /* Virtual Tokens {{{ */
1786 /* 8.1 Context Keywords {{{ */
1788 : "namespace" { $$ = $1; }
1789 | "xml" { $$ = $1; }
1792 /* 8.3 XML Initialiser Input Elements {{{ */
1794 : XMLComment { $$ = $1; }
1795 | XMLCDATA { $$ = $1; }
1796 | XMLPI { $$ = $1; }
1800 /* 11.1 Primary Expressions {{{ */
1802 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1803 | XMLInitialiser { $$ = $1; }
1804 | XMLListInitialiser { $$ = $1; }
1808 : AttributeIdentifier { $$ = $1; }
1809 | QualifiedIdentifier { $$ = $1; }
1810 | WildcardIdentifier { $$ = $1; }
1813 /* 11.1.1 Attribute Identifiers {{{ */
1815 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1819 : PropertySelector { $$ = $1; }
1820 | "[" LexPushInOff Expression "]" LexPopIn { $$ = CYNew CYSelector($3); }
1824 : Identifier { $$ = CYNew CYSelector($1); }
1825 | WildcardIdentifier { $$ = $1; }
1828 /* 11.1.2 Qualified Identifiers {{{ */
1829 QualifiedIdentifier_
1830 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1831 | QualifiedIdentifier { $$ = $1; }
1835 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1838 /* 11.1.3 Wildcard Identifiers {{{ */
1840 : "*" { $$ = CYNew CYWildcard(); }
1843 /* 11.1.4 XML Initialiser {{{ */
1845 : XMLMarkup { $$ = $1; }
1846 | XMLElement { $$ = $1; }
1850 : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn
1851 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn
1855 : LexPushXMLTag XMLTagName XMLAttributes
1859 : BRACE LexPushRegExp Expression LexPop "}"
1868 : XMLAttributes_ XMLAttribute
1873 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1874 | XMLAttributes_ XMLWhitespaceOpt
1883 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1887 : XMLExpression XMLElementContentOpt
1888 | XMLMarkup XMLElementContentOpt
1889 | XMLText XMLElementContentOpt
1890 | XMLElement XMLElementContentOpt
1893 XMLElementContentOpt
1898 /* 11.1.5 XMLList Initialiser {{{ */
1900 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); }
1904 /* 11.2 Left-Hand-Side Expressions {{{ */
1906 : Identifier { $$ = $1; }
1907 | PropertyIdentifier { $$ = $1; }
1911 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1912 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1913 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1916 /* 12.1 The default xml namespace Statement {{{ */
1917 /* XXX: DefaultXMLNamespaceStatement
1918 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1922 : DefaultXMLNamespaceStatement { $$ = $1; }
1927 /* JavaScript 1.7: Array Comprehensions {{{ */
1929 : AssignmentExpression ComprehensionFor ComprehensionTail { $$ = CYNew CYArrayComprehension($1, $2->Modify($3)); }
1933 : "for" "(" Binding "in" Expression ")" { $$ = CYNew CYForInComprehension($3, $5); }
1934 | "for" "each" "(" Binding "in" Expression ")" { $$ = CYNew CYForOfComprehension($4, $6); }
1937 /* JavaScript 1.7: for each {{{ */
1939 : "for" "each" "(" LexPushInOn ForInStatementInitialiser "!in" LexPopIn Expression ")" Statement { $$ = CYNew CYForOf($5, $8, $10); }
1942 /* JavaScript 1.7: let Statements {{{ */
1944 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1952 /* JavaScript FTW: Ruby Blocks {{{ */
1953 RubyProcParameterList_
1954 : "," RubyProcParameterList { $$ = $2; }
1958 RubyProcParameterList
1959 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1964 : "|" RubyProcParameterList "|" { $$ = $2; }
1965 | "||" { $$ = NULL; }
1968 RubyProcParametersOpt
1969 : RubyProcParameters
1974 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1978 : "{" LexPushInOff RubyProcParameters StatementListOpt "}" LexPopIn { $$ = CYNew CYRubyProc($3, $4); }
1982 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }