1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2010 Jay Freeman (saurik)
5 /* GNU Lesser General Public License, Version 3 {{{ */
7 * Cycript is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
12 * Cycript is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with Cycript. 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 {
32 #define CYNew new($pool)
35 #include "ObjectiveC/Syntax.hpp"
39 #include "E4X/Syntax.hpp"
48 CYDriver::Condition condition_;
50 CYArgument *argument_;
51 CYAssignment *assignment_;
54 cy::Syntax::Catch *catch_;
56 CYComprehension *comprehension_;
57 CYCompound *compound_;
58 CYDeclaration *declaration_;
59 CYDeclarations *declarations_;
61 CYExpression *expression_;
64 CYForInitialiser *for_;
65 CYForInInitialiser *forin_;
66 CYFunctionParameter *functionParameter_;
67 CYIdentifier *identifier_;
74 CYProperty *property_;
75 CYPropertyName *propertyName_;
76 CYRubyProc *rubyProc_;
77 CYStatement *statement_;
84 CYClassName *className_;
87 CYMessageParameter *messageParameter_;
88 CYProtocol *protocol_;
89 CYSelectorPart *selector_;
93 CYAttribute *attribute_;
94 CYPropertyIdentifier *propertyIdentifier_;
95 CYSelector *selector_;
100 #define YYSTYPE YYSTYPE
103 @if Bison24 %code provides {
104 int cylex(YYSTYPE *, cy::location *, void *);
111 @if Bison23 %skeleton "lalr1.cc"
112 @if Bison24 %language "C++"
115 @$.begin.filename = @$.end.filename = &driver.filename_;
126 %parse-param { CYDriver &driver }
127 %lex-param { void *cyscanner }
134 %token XMLAttributeValue
136 %token XMLTagCharacters
142 %token LeftRight "<>"
143 %token LeftSlashRight "</>"
145 %token SlashRight "/>"
146 %token LeftSlash "</"
148 %token ColonColon "::"
149 %token PeriodPeriod ".."
152 @begin E4X ObjectiveC
157 %token AmpersandAmpersand "&&"
158 %token AmpersandEqual "&="
160 %token CarrotEqual "^="
162 %token EqualEqual "=="
163 %token EqualEqualEqual "==="
164 %token Exclamation "!"
165 %token ExclamationEqual "!="
166 %token ExclamationEqualEqual "!=="
168 %token HyphenEqual "-="
169 %token HyphenHyphen "--"
170 %token HyphenHyphen_ "\n--"
171 %token HyphenRight "->"
173 %token LeftEqual "<="
175 %token LeftLeftEqual "<<="
177 %token PercentEqual "%="
179 %token PeriodPeriodPeriod "..."
181 %token PipeEqual "|="
184 %token PlusEqual "+="
186 %token PlusPlus_ "\n++"
188 %token RightEqual ">="
189 %token RightRight ">>"
190 %token RightRightEqual ">>="
191 %token RightRightRight ">>>"
192 %token RightRightRightEqual ">>>="
194 %token SlashEqual "/="
196 %token StarEqual "*="
205 %token <comment_> Comment
208 %token CloseParen ")"
211 %token OpenBrace_ "\n{"
212 %token OpenBrace__ ";{"
213 %token CloseBrace "}"
215 %token OpenBracket "["
216 %token CloseBracket "]"
219 %token AtClass "@class"
223 %token AtImplementation "@implementation"
224 %token AtImplementation_ ";@implementation"
225 %token AtImport "@import"
227 %token AtSelector "@selector"
230 %token <false_> False "false"
231 %token <null_> Null "null"
232 %token <true_> True "true"
234 // ES3/ES5/WIE/JSC Reserved
235 %token <word_> Break "break"
236 %token <word_> Case "case"
237 %token <word_> Catch "catch"
238 %token <word_> Continue "continue"
239 %token <word_> Default "default"
240 %token <word_> Delete "delete"
241 %token <word_> Do "do"
242 %token <word_> Else "else"
243 %token <word_> Finally "finally"
244 %token <word_> For "for"
245 %token <word_> Function "function"
246 %token <word_> Function_ ";function"
247 %token <word_> If "if"
248 %token <word_> In "in"
249 %token <word_> In_ "!in"
250 %token <word_> InstanceOf "instanceof"
251 %token <word_> New "new"
252 %token <word_> Return "return"
253 %token <word_> Switch "switch"
254 %token <this_> This "this"
255 %token <word_> Throw "throw"
256 %token <word_> Try "try"
257 %token <word_> TypeOf "typeof"
258 %token <word_> Var "var"
259 %token <word_> Void "void"
260 %token <word_> While "while"
261 %token <word_> With "with"
263 // ES3/IE6 Future, ES5/JSC Reserved
264 %token <word_> Debugger "debugger"
266 // ES3/ES5/IE6 Future, JSC Reserved
267 %token <word_> Const "const"
269 // ES3/ES5/IE6/JSC Future
270 %token <word_> Class "class"
271 %token <word_> Enum "enum"
272 %token <word_> Export "export"
273 %token <word_> Extends "extends"
274 %token <word_> Import "import"
275 %token <word_> Super "super"
277 // ES3 Future, ES5 Strict Future
278 %token <identifier_> Implements "implements"
279 %token <identifier_> Interface "interface"
280 %token <identifier_> Package "package"
281 %token <identifier_> Private "private"
282 %token <identifier_> Protected "protected"
283 %token <identifier_> Public "public"
284 %token <identifier_> Static "static"
287 %token <identifier_> Abstract "abstract"
288 %token <identifier_> Boolean "boolean"
289 %token <identifier_> Byte "byte"
290 %token <identifier_> Char "char"
291 %token <identifier_> Double "double"
292 %token <identifier_> Final "final"
293 %token <identifier_> Float "float"
294 %token <identifier_> Goto "goto"
295 %token <identifier_> Int "int"
296 %token <identifier_> Long "long"
297 %token <identifier_> Native "native"
298 %token <identifier_> Short "short"
299 %token <identifier_> Synchronized "synchronized"
300 %token <identifier_> Throws "throws"
301 %token <identifier_> Transient "transient"
302 %token <identifier_> Volatile "volatile"
305 %token <identifier_> Let "let"
306 %token <identifier_> Yield "yield"
309 %token <identifier_> Each "each"
313 %token <identifier_> Namespace "namespace"
314 %token <identifier_> XML "xml"
319 %token <identifier_> Identifier_
320 %token <number_> NumericLiteral
321 %token <string_> StringLiteral
322 %token <literal_> RegularExpressionLiteral
324 %type <expression_> AdditiveExpression
325 %type <argument_> ArgumentList_
326 %type <argument_> ArgumentList
327 %type <argument_> ArgumentListOpt
328 %type <argument_> Arguments
329 %type <literal_> ArrayLiteral
330 %type <expression_> AssignmentExpression
331 %type <identifier_> BindingIdentifier
332 %type <expression_> BitwiseANDExpression
333 %type <statement_> Block_
334 %type <statement_> Block
335 %type <boolean_> BooleanLiteral
336 %type <declaration_> BindingElement
337 %type <expression_> BitwiseORExpression
338 %type <expression_> BitwiseXORExpression
339 %type <statement_> BreakStatement
340 %type <statement_> BreakableStatement
341 %type <expression_> CallExpression_
342 %type <expression_> CallExpression
343 %type <clause_> CaseBlock
344 %type <clause_> CaseClause
345 %type <clause_> CaseClausesOpt
346 %type <catch_> CatchOpt
347 %type <comprehension_> ComprehensionList
348 %type <comprehension_> ComprehensionListOpt
349 %type <expression_> ConditionalExpression
350 %type <statement_> ContinueStatement
351 %type <statement_> DebuggerStatement
352 %type <statement_> Declaration__
353 %type <statement_> Declaration_
354 %type <statement_> Declaration
355 %type <clause_> DefaultClause
356 %type <statement_> DoWhileStatement
357 %type <expression_> Element
358 %type <expression_> ElementOpt
359 %type <element_> ElementList
360 %type <element_> ElementListOpt
361 %type <statement_> ElseStatementOpt
362 %type <statement_> EmptyStatement
363 %type <expression_> EqualityExpression
364 %type <compound_> Expression_
365 %type <expression_> Expression
366 %type <expression_> ExpressionOpt
367 %type <statement_> ExpressionStatement
368 %type <finally_> FinallyOpt
369 %type <comprehension_> ForComprehension
370 %type <statement_> ForStatement
371 %type <for_> ForStatementInitialiser
372 %type <statement_> ForInStatement
373 %type <forin_> ForInStatementInitialiser
374 %type <declaration_> FormalParameter
375 %type <functionParameter_> FormalParameterList_
376 %type <functionParameter_> FormalParameterList
377 %type <functionParameter_> FormalParameterListOpt
378 %type <statement_> FunctionBody
379 %type <statement_> FunctionDeclaration
380 %type <expression_> FunctionExpression
381 %type <identifier_> Identifier
382 %type <identifier_> IdentifierOpt
383 %type <comprehension_> IfComprehension
384 %type <statement_> IfStatement
385 %type <expression_> Initialiser
386 %type <expression_> InitialiserOpt
387 %type <statement_> IterationStatement
388 %type <statement_> LabelledStatement
389 %type <expression_> LeftHandSideExpression
390 %type <statement_> LetStatement
391 %type <statement_> LexicalDeclaration
392 %type <literal_> Literal
393 %type <literal_> LiteralNoRE
394 %type <expression_> LogicalANDExpression
395 %type <expression_> LogicalORExpression
396 %type <member_> MemberAccess
397 %type <expression_> MemberExpression_
398 %type <expression_> MemberExpression
399 %type <expression_> MultiplicativeExpression
400 %type <expression_> NewExpression
401 %type <null_> NullLiteral
402 %type <literal_> ObjectLiteral
403 %type <expression_> Parenthetical
404 %type <expression_> PostfixExpression
405 %type <expression_> PrimaryExpression
406 %type <statement_> Program
407 %type <statement_> ProgramBody
408 %type <statement_> ProgramBodyOpt
409 %type <propertyName_> PropertyName_
410 %type <propertyName_> PropertyName
411 %type <property_> PropertyNameAndValueList_
412 %type <property_> PropertyNameAndValueList
413 %type <property_> PropertyNameAndValueListOpt
414 %type <expression_> RelationalExpression_
415 %type <expression_> RelationalExpression
416 %type <statement_> ReturnStatement
417 %type <rubyProc_> RubyProcExpression
418 %type <functionParameter_> RubyProcParameterList_
419 %type <functionParameter_> RubyProcParameterList
420 %type <functionParameter_> RubyProcParameters
421 %type <functionParameter_> RubyProcParametersOpt
422 %type <expression_> ShiftExpression
423 %type <declaration_> SingleNameBinding
424 %type <statement_> Statement__
425 %type <statement_> Statement_
426 %type <statement_> Statement
427 %type <statement_> StatementList
428 %type <statement_> StatementListOpt
429 %type <statement_> StatementListItem
430 %type <statement_> SwitchStatement
431 %type <statement_> ThrowStatement
432 %type <statement_> TryStatement
433 %type <expression_> UnaryExpression_
434 %type <expression_> UnaryExpression
435 %type <declaration_> VariableDeclaration
436 %type <declarations_> VariableDeclarationList_
437 %type <declarations_> VariableDeclarationList
438 %type <statement_> VariableStatement
439 %type <statement_> WhileStatement
440 %type <statement_> WithStatement
443 %type <statement_> CategoryStatement
444 %type <expression_> ClassExpression
445 %type <statement_> ClassStatement
446 %type <expression_> ClassSuperOpt
447 %type <field_> ClassFieldList
448 %type <message_> ClassMessageDeclaration
449 %type <message_> ClassMessageDeclarationListOpt
450 %type <className_> ClassName
451 %type <className_> ClassNameOpt
452 %type <protocol_> ClassProtocolListOpt
453 %type <protocol_> ClassProtocols
454 %type <protocol_> ClassProtocolsOpt
455 %type <expression_> MessageExpression
456 %type <messageParameter_> MessageParameter
457 %type <messageParameter_> MessageParameters
458 %type <messageParameter_> MessageParameterList
459 %type <messageParameter_> MessageParameterListOpt
460 %type <bool_> MessageScope
461 %type <argument_> SelectorCall_
462 %type <argument_> SelectorCall
463 %type <selector_> SelectorExpression_
464 %type <selector_> SelectorExpression
465 %type <selector_> SelectorExpressionOpt
466 %type <argument_> SelectorList
467 %type <word_> SelectorWordOpt
468 %type <expression_> TypeOpt
469 %type <argument_> VariadicCall
471 %type <word_> WordOpt
475 %type <propertyIdentifier_> PropertyIdentifier_
476 %type <selector_> PropertySelector_
477 %type <selector_> PropertySelector
478 %type <identifier_> QualifiedIdentifier_
479 %type <identifier_> QualifiedIdentifier
480 %type <identifier_> WildcardIdentifier
481 %type <identifier_> XMLComment
482 %type <identifier_> XMLCDATA
483 %type <identifier_> XMLElement
484 %type <identifier_> XMLElementContent
485 %type <identifier_> XMLMarkup
486 %type <identifier_> XMLPI
488 %type <attribute_> AttributeIdentifier
489 /* XXX: %type <statement_> DefaultXMLNamespaceStatement */
490 %type <expression_> PropertyIdentifier
491 %type <expression_> XMLListInitialiser
492 %type <expression_> XMLInitialiser
505 /* Lexer State {{{ */
507 : { driver.in_.push(true); }
511 : { driver.in_.push(false); }
515 : { driver.in_.pop(); }
519 : { driver.SetCondition(CYDriver::RegExpCondition); }
523 : { switch (yychar) {
524 case token::Function:
525 yychar = token::Function_;
528 case token::OpenBrace:
529 case token::OpenBrace_:
530 yychar = token::OpenBrace__;
542 : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
552 | error { if (yychar != 0 && yychar != token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
557 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
572 : Identifier { $$ = $1; }
573 | "break" NewLineOpt { $$ = $1; }
574 | "case" { $$ = $1; }
575 | "catch" { $$ = $1; }
576 | "class" { $$ = $1; }
577 | "const" { $$ = $1; }
578 | "continue" NewLineOpt { $$ = $1; }
579 | "debugger" { $$ = $1; }
580 | "default" { $$ = $1; }
581 | "delete" { $$ = $1; }
583 | "else" { $$ = $1; }
584 | "enum" { $$ = $1; }
585 | "export" { $$ = $1; }
586 | "extends" { $$ = $1; }
587 | "false" { $$ = $1; }
588 | "finally" { $$ = $1; }
589 /* XXX: | "for" { $$ = $1; } */
590 | "function" { $$ = $1; }
592 | "import" { $$ = $1; }
593 /* XXX: | "in" { $$ = $1; } */
594 /* XXX: | "instanceof" { $$ = $1; } */
596 | "null" { $$ = $1; }
597 | "return" NewLineOpt { $$ = $1; }
598 | "super" { $$ = $1; }
599 | "switch" { $$ = $1; }
600 | "this" { $$ = $1; }
601 | "throw" NewLineOpt { $$ = $1; }
602 | "true" { $$ = $1; }
604 | "typeof" { $$ = $1; }
606 | "void" { $$ = $1; }
607 | "while" { $$ = $1; }
608 | "with" { $$ = $1; }
617 : "@" LiteralNoRE { $$ = CYNew CYBox($2); }
618 | "@" ArrayLiteral { $$ = CYNew CYBox($2); }
619 | "@" ObjectLiteral { $$ = CYNew CYBox($2); }
620 | "@" Parenthetical { $$ = CYNew CYBox($2); }
625 : Identifier_ { $$ = $1; }
627 | "implements" { $$ = $1; }
628 | "interface" { $$ = $1; }
629 | "package" { $$ = $1; }
630 | "private" { $$ = $1; }
631 | "protected" { $$ = $1; }
632 | "public" { $$ = $1; }
633 | "static" { $$ = $1; }
635 | "abstract" { $$ = $1; }
636 | "boolean" { $$ = $1; }
637 | "byte" { $$ = $1; }
638 | "char" { $$ = $1; }
639 | "double" { $$ = $1; }
640 | "final" { $$ = $1; }
641 | "float" { $$ = $1; }
642 | "goto" { $$ = $1; }
644 | "long" { $$ = $1; }
645 | "native" { $$ = $1; }
646 | "short" { $$ = $1; }
647 | "synchronized" { $$ = $1; }
648 | "throws" { $$ = $1; }
649 | "transient" { $$ = $1; }
650 | "volatile" { $$ = $1; }
652 // XXX: is this allowed?! | "let" { $$ = $1; }
653 | "yield" { $$ = $1; }
655 | "each" { $$ = $1; }
659 : Identifier { $$ = $1; }
664 : NullLiteral { $$ = $1; }
665 | BooleanLiteral { $$ = $1; }
666 | NumericLiteral { $$ = $1; }
667 | StringLiteral { $$ = $1; }
671 : LiteralNoRE { $$ = $1; }
672 | RegularExpressionLiteral { $$ = $1; }
676 : "null" { $$ = $1; }
680 : "true" { $$ = $1; }
681 | "false" { $$ = $1; }
684 /* 11.1 Primary Expressions {{{ */
686 : "(" LexPushInOff Expression LexPopIn ")" { $$ = $3; }
690 : "this" { $$ = $1; }
691 | Identifier { $$ = CYNew CYVariable($1); }
692 | Literal { $$ = $1; }
693 | ArrayLiteral { $$ = $1; }
694 | ObjectLiteral { $$ = $1; }
695 | FunctionExpression { $$ = $1; }
696 | Parenthetical { $$ = $1; }
697 | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
700 /* 11.1.4.1 Array Initialiser {{{ */
702 : "[" LexPushInOff ElementListOpt LexPopIn "]" { $$ = CYNew CYArray($3); }
706 : AssignmentExpression { $$ = $1; }
710 : Element { $$ = $1; }
711 | LexSetRegExp { $$ = NULL; }
715 : ElementOpt "," ElementListOpt { $$ = CYNew CYElement($1, $3); }
716 | Element { $$ = CYNew CYElement($1, NULL); }
720 : ElementList { $$ = $1; }
721 | LexSetRegExp { $$ = NULL; }
724 /* 11.1.5 Object Initialiser {{{ */
726 : BRACE LexPushInOff PropertyNameAndValueListOpt LexPopIn "}" { $$ = CYNew CYObject($3); }
729 PropertyNameAndValueList_
730 : "," PropertyNameAndValueList { $$ = $2; }
734 PropertyNameAndValueList
735 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = CYNew CYProperty($1, $3, $4); }
738 PropertyNameAndValueListOpt
739 : PropertyNameAndValueList { $$ = $1; }
744 : Identifier { $$ = $1; }
745 | StringLiteral { $$ = $1; }
746 | NumericLiteral { $$ = $1; }
750 : LexSetRegExp PropertyName_ { $$ = $2; }
754 /* 11.2 Left-Hand-Side Expressions {{{ */
756 : "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYDirectMember(NULL, $3); }
757 | "." Identifier { $$ = CYNew CYDirectMember(NULL, CYNew CYString($2)); }
758 | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; }
762 : MemberExpression { $$ = $1; }
763 //| "super" { $$ = $1; }
767 : LexSetRegExp PrimaryExpression { $$ = $2; }
768 | MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
769 | LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
773 : MemberExpression { $$ = $1; }
774 | LexSetRegExp "new" NewExpression { $$ = CYNew cy::Syntax::New($3, NULL); }
783 : CallExpression_ Arguments { $$ = CYNew CYCall($1, $2); }
784 | CallExpression { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
788 : "(" LexPushInOff ArgumentListOpt LexPopIn ")" { $$ = $3; }
792 : "," ArgumentList { $$ = $2; }
797 : AssignmentExpression ArgumentList_ { $$ = CYNew CYArgument(NULL, $1, $2); }
801 : ArgumentList { $$ = $1; }
802 | LexSetRegExp { $$ = NULL; }
805 LeftHandSideExpression
806 : NewExpression { $$ = $1; }
807 | CallExpression { $$ = $1; }
810 /* 11.3 Postfix Expressions {{{ */
812 : %prec "" LeftHandSideExpression { $$ = $1; }
813 | LeftHandSideExpression "++" { $$ = CYNew CYPostIncrement($1); }
814 | LeftHandSideExpression "--" { $$ = CYNew CYPostDecrement($1); }
817 /* 11.4 Unary Operators {{{ */
819 : "delete" UnaryExpression { $$ = CYNew CYDelete($2); }
820 | "void" UnaryExpression { $$ = CYNew CYVoid($2); }
821 | "typeof" UnaryExpression { $$ = CYNew CYTypeOf($2); }
822 | "++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
823 | "\n++" UnaryExpression { $$ = CYNew CYPreIncrement($2); }
824 | "--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
825 | "\n--" UnaryExpression { $$ = CYNew CYPreDecrement($2); }
826 | "+" UnaryExpression { $$ = CYNew CYAffirm($2); }
827 | "-" UnaryExpression { $$ = CYNew CYNegate($2); }
828 | "~" UnaryExpression { $$ = CYNew CYBitwiseNot($2); }
829 | "!" UnaryExpression { $$ = CYNew CYLogicalNot($2); }
833 : PostfixExpression { $$ = $1; }
834 | LexSetRegExp UnaryExpression_ { $$ = $2; }
837 /* 11.5 Multiplicative Operators {{{ */
838 MultiplicativeExpression
839 : UnaryExpression { $$ = $1; }
840 | MultiplicativeExpression "*" UnaryExpression { $$ = CYNew CYMultiply($1, $3); }
841 | MultiplicativeExpression "/" UnaryExpression { $$ = CYNew CYDivide($1, $3); }
842 | MultiplicativeExpression "%" UnaryExpression { $$ = CYNew CYModulus($1, $3); }
845 /* 11.6 Additive Operators {{{ */
847 : MultiplicativeExpression { $$ = $1; }
848 | AdditiveExpression "+" MultiplicativeExpression { $$ = CYNew CYAdd($1, $3); }
849 | AdditiveExpression "-" MultiplicativeExpression { $$ = CYNew CYSubtract($1, $3); }
852 /* 11.7 Bitwise Shift Operators {{{ */
854 : AdditiveExpression { $$ = $1; }
855 | ShiftExpression "<<" AdditiveExpression { $$ = CYNew CYShiftLeft($1, $3); }
856 | ShiftExpression ">>" AdditiveExpression { $$ = CYNew CYShiftRightSigned($1, $3); }
857 | ShiftExpression ">>>" AdditiveExpression { $$ = CYNew CYShiftRightUnsigned($1, $3); }
860 /* 11.8 Relational Operators {{{ */
861 RelationalExpression_
862 : ShiftExpression { $$ = $1; }
866 : RelationalExpression_ { $$ = $1; }
867 | RelationalExpression "<" RelationalExpression_ { $$ = CYNew CYLess($1, $3); }
868 | RelationalExpression ">" RelationalExpression_ { $$ = CYNew CYGreater($1, $3); }
869 | RelationalExpression "<=" RelationalExpression_ { $$ = CYNew CYLessOrEqual($1, $3); }
870 | RelationalExpression ">=" RelationalExpression_ { $$ = CYNew CYGreaterOrEqual($1, $3); }
871 | RelationalExpression "instanceof" RelationalExpression_ { $$ = CYNew CYInstanceOf($1, $3); }
872 | RelationalExpression "in" RelationalExpression_ { $$ = CYNew CYIn($1, $3); }
875 /* 11.9 Equality Operators {{{ */
877 : RelationalExpression { $$ = $1; }
878 | EqualityExpression "==" RelationalExpression { $$ = CYNew CYEqual($1, $3); }
879 | EqualityExpression "!=" RelationalExpression { $$ = CYNew CYNotEqual($1, $3); }
880 | EqualityExpression "===" RelationalExpression { $$ = CYNew CYIdentical($1, $3); }
881 | EqualityExpression "!==" RelationalExpression { $$ = CYNew CYNotIdentical($1, $3); }
884 /* 11.10 Binary Bitwise Operators {{{ */
886 : EqualityExpression { $$ = $1; }
887 | BitwiseANDExpression "&" EqualityExpression { $$ = CYNew CYBitwiseAnd($1, $3); }
891 : BitwiseANDExpression { $$ = $1; }
892 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = CYNew CYBitwiseXOr($1, $3); }
896 : BitwiseXORExpression { $$ = $1; }
897 | BitwiseORExpression "|" BitwiseXORExpression { $$ = CYNew CYBitwiseOr($1, $3); }
900 /* 11.11 Binary Logical Operators {{{ */
902 : BitwiseORExpression { $$ = $1; }
903 | LogicalANDExpression "&&" BitwiseORExpression { $$ = CYNew CYLogicalAnd($1, $3); }
907 : LogicalANDExpression { $$ = $1; }
908 | LogicalORExpression "||" LogicalANDExpression { $$ = CYNew CYLogicalOr($1, $3); }
911 /* 11.12 Conditional Operator ( ? : ) {{{ */
912 ConditionalExpression
913 : LogicalORExpression { $$ = $1; }
914 | LogicalORExpression "?" LexPushInOff AssignmentExpression LexPopIn ":" AssignmentExpression { $$ = CYNew CYCondition($1, $4, $7); }
917 /* 11.13 Assignment Operators {{{ */
919 : ConditionalExpression { $$ = $1; }
920 | LeftHandSideExpression "=" AssignmentExpression { $$ = CYNew CYAssign($1, $3); }
921 | LeftHandSideExpression "*=" AssignmentExpression { $$ = CYNew CYMultiplyAssign($1, $3); }
922 | LeftHandSideExpression "/=" AssignmentExpression { $$ = CYNew CYDivideAssign($1, $3); }
923 | LeftHandSideExpression "%=" AssignmentExpression { $$ = CYNew CYModulusAssign($1, $3); }
924 | LeftHandSideExpression "+=" AssignmentExpression { $$ = CYNew CYAddAssign($1, $3); }
925 | LeftHandSideExpression "-=" AssignmentExpression { $$ = CYNew CYSubtractAssign($1, $3); }
926 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = CYNew CYShiftLeftAssign($1, $3); }
927 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = CYNew CYShiftRightSignedAssign($1, $3); }
928 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = CYNew CYShiftRightUnsignedAssign($1, $3); }
929 | LeftHandSideExpression "&=" AssignmentExpression { $$ = CYNew CYBitwiseAndAssign($1, $3); }
930 | LeftHandSideExpression "^=" AssignmentExpression { $$ = CYNew CYBitwiseXOrAssign($1, $3); }
931 | LeftHandSideExpression "|=" AssignmentExpression { $$ = CYNew CYBitwiseOrAssign($1, $3); }
934 /* 11.14 Comma Operator {{{ */
936 : "," Expression { $$ = CYNew CYCompound($2); }
941 : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
945 : Expression { $$ = $1; }
946 | LexSetRegExp { $$ = NULL; }
950 /* 12 Statements {{{ */
953 | VariableStatement { $$ = $1; }
954 | EmptyStatement { $$ = $1; }
955 | IfStatement { $$ = $1; }
956 | BreakableStatement { $$ = $1; }
957 | ContinueStatement { $$ = $1; }
958 | BreakStatement { $$ = $1; }
959 | ReturnStatement { $$ = $1; }
960 | WithStatement { $$ = $1; }
961 | LabelledStatement { $$ = $1; }
962 | ThrowStatement { $$ = $1; }
963 | TryStatement { $$ = $1; }
964 | DebuggerStatement { $$ = $1; }
968 : LexSetRegExp Statement__ { $$ = $2; }
969 | ExpressionStatement { $$ = $1; }
973 : LexSetStatement Statement_ { $$ = $2; }
977 : FunctionDeclaration { $$ = $1; }
978 | LexicalDeclaration { $$ = $1; }
982 : LexSetRegExp Declaration__ { $$ = $2; }
986 : LexSetStatement Declaration_ { $$ = $2; }
990 : IterationStatement { $$ = $1; }
991 | SwitchStatement { $$ = $1; }
996 : BRACE StatementListOpt "}" { $$ = $2; }
1000 : ";{" StatementListOpt "}" { $$ = CYNew CYBlock($2); }
1004 : StatementListItem StatementListOpt { $1->SetNext($2); $$ = $1; }
1008 : StatementList { $$ = $1; }
1009 | LexSetRegExp { $$ = NULL; }
1013 : Statement { $$ = $1; }
1014 | Declaration { $$ = $1; }
1017 /* 12.2 Declarations {{{ */
1019 : Identifier { $$ = $1; }
1022 // XXX: BindingPattern
1024 /* 12.2.1 Let and Const Declarations {{{ */
1026 : LetOrConst VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1034 /* 12.2.2 Variable Statement {{{ */
1036 : "var" VariableDeclarationList Terminator { $$ = CYNew CYVar($2); }
1039 VariableDeclarationList_
1040 : "," VariableDeclarationList { $$ = $2; }
1044 VariableDeclarationList
1045 : VariableDeclaration VariableDeclarationList_ { $$ = CYNew CYDeclarations($1, $2); }
1049 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1050 // XXX: | BindingPattern Initialiser { $$ = CYNew CYDeclaration($1, $2); }
1054 : "=" AssignmentExpression { $$ = $2; }
1058 : Initialiser { $$ = $1; }
1062 /* 12.2.4 Destructuring Binding Patterns {{{ */
1066 : SingleNameBinding { $$ = $1; }
1070 : BindingIdentifier InitialiserOpt { $$ = CYNew CYDeclaration($1, $2); }
1073 /* 12.3 Empty Statement {{{ */
1075 : ";" { $$ = CYNew CYEmpty(); }
1078 /* 12.4 Expression Statement {{{ */
1080 : Expression Terminator { $$ = CYNew CYExpress($1); }
1083 /* 12.5 The if Statement {{{ */
1085 : "else" Statement { $$ = $2; }
1086 | %prec "if" { $$ = NULL; }
1090 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = CYNew CYIf($3, $5, $6); }
1094 /* 12.6 Iteration Statements {{{ */
1096 : DoWhileStatement { $$ = $1; }
1097 | WhileStatement { $$ = $1; }
1098 | ForStatement { $$ = $1; }
1099 | ForInStatement { $$ = $1; }
1102 /* 12.6.1 The do-while Statement {{{ */
1104 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = CYNew CYDoWhile($5, $2); }
1107 /* 12.6.2 The while Statement {{{ */
1109 : "while" "(" Expression ")" Statement { $$ = CYNew CYWhile($3, $5); }
1112 /* 12.6.3 The for Statement {{{ */
1114 : "for" "(" LexPushInOn ForStatementInitialiser LexPopIn ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = CYNew CYFor($4, $7, $9, $11); }
1117 ForStatementInitialiser
1118 : ExpressionOpt { $$ = $1; }
1119 | LexSetRegExp "var" VariableDeclarationList { $$ = CYNew CYForDeclarations($3); }
1122 /* 12.6.4 The for-in Statement {{{ */
1124 : "for" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForIn($4, $7, $9); }
1127 ForInStatementInitialiser
1128 : LeftHandSideExpression { $$ = $1; }
1129 | LexSetRegExp "var" VariableDeclaration { $$ = $3; }
1133 /* 12.7 The continue Statement {{{ */
1135 : "continue" IdentifierOpt Terminator { $$ = CYNew CYContinue($2); }
1138 /* 12.8 The break Statement {{{ */
1140 : "break" IdentifierOpt Terminator { $$ = CYNew CYBreak($2); }
1143 /* 12.9 The return Statement {{{ */
1145 : "return" ExpressionOpt Terminator { $$ = CYNew CYReturn($2); }
1148 /* 12.10 The with Statement {{{ */
1150 : "with" "(" Expression ")" Statement { $$ = CYNew CYWith($3, $5); }
1154 /* 12.11 The switch Statement {{{ */
1156 : "switch" "(" Expression ")" CaseBlock { $$ = CYNew CYSwitch($3, $5); }
1160 : BRACE CaseClausesOpt "}" { $$ = $2; }
1164 : "case" Expression ":" StatementListOpt { $$ = CYNew CYClause($2, $4); }
1168 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1169 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1174 : "default" ":" StatementListOpt { $$ = CYNew CYClause(NULL, $3); }
1177 /* 12.12 Labelled Statements {{{ */
1179 : Identifier ":" Statement { $$ = CYNew CYLabel($1, $3); }
1182 /* 12.13 The throw Statement {{{ */
1184 : "throw" Expression Terminator { $$ = CYNew cy::Syntax::Throw($2); }
1187 /* 12.14 The try Statement {{{ */
1189 : "try" Block_ CatchOpt FinallyOpt { $$ = CYNew cy::Syntax::Try($2, $3, $4); }
1193 : "catch" "(" Identifier ")" Block_ { $$ = CYNew cy::Syntax::Catch($3, $5); }
1198 : "finally" Block_ { $$ = CYNew CYFinally($2); }
1202 /* 12.14 The debugger Statement {{{ */
1204 : "debugger" Terminator { $$ = CYNew CYDebugger(); }
1208 /* 13 Function Definition {{{ */
1210 : ";function" Identifier "(" FormalParameterListOpt ")" BRACE FunctionBody "}" { $$ = CYNew CYFunctionStatement($2, $4, $7); }
1214 : "function" IdentifierOpt "(" LexPushInOff FormalParameterListOpt LexPopIn ")" BRACE LexPushInOff FunctionBody LexPopIn "}" { $$ = CYNew CYFunctionExpression($2, $5, $10); }
1217 FormalParameterList_
1218 : "," FormalParameterList { $$ = $2; }
1223 // XXX: : FunctionRestParameter { $$ = $1; }
1224 : FormalParameter FormalParameterList_ { $$ = CYNew CYFunctionParameter($1, $2); }
1227 FormalParameterListOpt
1228 : FormalParameterList
1232 /* XXX: FunctionRestParameter
1233 : "..." BindingIdentifier { $$ = CYNew CYFunctionRestParameter($2); }
1237 : BindingElement { $$ = $1; }
1241 : StatementListOpt { $$ = $1; }
1244 /* 14 Program {{{ */
1246 : ProgramBodyOpt { driver.program_ = CYNew CYProgram($1); }
1250 : StatementList { $$ = $1; }
1254 : ProgramBody { $$ = $1; }
1260 /* Cycript (Objective-C): @class Declaration {{{ */
1262 /* XXX: why the hell did I choose MemberExpression? */
1263 : ":" LexSetRegExp MemberExpression { $$ = $3; }
1268 : Expression Identifier ";"
1272 : BRACE ClassFieldListOpt "}" { $$ = NULL; }
1276 : ClassFieldListOpt ClassField
1281 : "+" { $$ = false; }
1282 | "-" { $$ = true; }
1286 : "(" Expression ")" { $$ = $2; }
1287 | "(" LexSetRegExp "void" ")" { $$ = NULL; }
1292 : Word ":" TypeOpt Identifier { $$ = CYNew CYMessageParameter($1, $3, $4); }
1295 MessageParameterList
1296 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1299 MessageParameterListOpt
1300 : MessageParameterList { $$ = $1; }
1305 : MessageParameterList { $$ = $1; }
1306 | Word { $$ = CYNew CYMessageParameter($1, NULL, NULL); }
1309 ClassMessageDeclaration
1310 : MessageScope TypeOpt MessageParameters BRACE FunctionBody "}" { $$ = CYNew CYMessage($1, $2, $3, $5); }
1313 ClassMessageDeclarationListOpt
1314 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1315 | ClassMessageDeclarationListOpt Comment { $$ = $1; }
1320 : Identifier { $$ = $1; }
1321 | "(" AssignmentExpression ")" { $$ = $2; }
1325 : ClassName { $$ = $1; }
1329 // XXX: this should be AssignmentExpressionNoRight
1331 : ShiftExpression ClassProtocolsOpt { $$ = CYNew CYProtocol($1, $2); }
1335 : "," ClassProtocols { $$ = $2; }
1339 ClassProtocolListOpt
1340 : "<" ClassProtocols ">" { $$ = $2; }
1345 : "@implementation" LexPushInOff ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt LexPopIn "@end" { $$ = CYNew CYClassExpression($3, $4, $5, $6, $7); }
1349 : ";@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYClassStatement($2, $3, $4, $5, $6); }
1357 : ";@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = CYNew CYCategory($2, $4); }
1361 : ClassExpression { $$ = $1; }
1365 : ClassStatement { $$ = $1; }
1366 | CategoryStatement { $$ = $1; }
1369 /* Cycript (Objective-C): Send Message {{{ */
1371 : "," AssignmentExpression VariadicCall { $$ = CYNew CYArgument(NULL, $2, $3); }
1376 : WordOpt { driver.contexts_.back().words_.push_back($1); } { $$ = $1; }
1377 | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; }
1381 : SelectorCall { $$ = $1; }
1382 | VariadicCall { $$ = $1; }
1386 : SelectorWordOpt ":" AssignmentExpression SelectorCall_ { $$ = CYNew CYArgument($1 ?: CYNew CYBlank(), $3, $4); }
1390 : SelectorCall { $$ = $1; }
1391 | Word { $$ = CYNew CYArgument($1, NULL); }
1395 : "[" LexPushInOff AssignmentExpression { driver.contexts_.push_back($3); } SelectorList LexPopIn "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($3, $5); }
1396 | "[" LexPushInOff LexSetRegExp "super" { driver.context_ = NULL; } SelectorList LexPopIn "]" { $$ = CYNew CYSendSuper($6); }
1400 : WordOpt ":" SelectorExpressionOpt { $$ = CYNew CYSelectorPart($1, true, $3); }
1404 : SelectorExpression_ { $$ = $1; }
1405 | Word { $$ = CYNew CYSelectorPart($1, false, NULL); }
1408 SelectorExpressionOpt
1409 : SelectorExpression_ { $$ = $1; }
1414 : MessageExpression { $$ = $1; }
1415 | "@selector" "(" LexPushInOff SelectorExpression LexPopIn ")" { $$ = CYNew CYSelector($4); }
1418 /* Cycript (Objective-C): @import Directive {{{ */
1432 : "@import" ImportPath { $$ = CYNew CYImport(); }
1438 /* Cycript (C): Pointer Indirection/Addressing {{{ */
1439 LeftHandSideExpression
1440 : LexSetRegExp "*" UnaryExpression { $$ = CYNew CYIndirect($3); }
1444 : "&" UnaryExpression { $$ = CYNew CYAddressOf($2); }
1448 : "->" "[" Expression "]" { $$ = CYNew CYIndirectMember(NULL, $3); }
1449 | "->" Identifier { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($2)); }
1450 | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; }
1455 /* YUI: Documentation Comments {{{ */
1457 : Comment { $$ = $1; }
1462 /* Lexer State {{{ */
1464 : { driver.PushCondition(CYDriver::RegExpCondition); }
1468 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1472 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1476 : { driver.PopCondition(); }
1480 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1484 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1493 /* 8.1 Context Keywords {{{ */
1495 : "namespace" { $$ = $1; }
1496 | "xml" { $$ = $1; }
1499 /* 8.3 XML Initialiser Input Elements {{{ */
1501 : XMLComment { $$ = $1; }
1502 | XMLCDATA { $$ = $1; }
1503 | XMLPI { $$ = $1; }
1506 /* 11.1 Primary Expressions {{{ */
1508 : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); }
1509 | XMLInitialiser { $$ = $1; }
1510 | XMLListInitialiser { $$ = $1; }
1514 : AttributeIdentifier { $$ = $1; }
1515 | QualifiedIdentifier { $$ = $1; }
1516 | WildcardIdentifier { $$ = $1; }
1519 /* 11.1.1 Attribute Identifiers {{{ */
1521 : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); }
1525 : PropertySelector { $$ = $1; }
1526 | "[" LexPushInOff Expression LexPopIn "]" { $$ = CYNew CYSelector($3); }
1530 : Identifier { $$ = CYNew CYSelector($1); }
1531 | WildcardIdentifier { $$ = $1; }
1534 /* 11.1.2 Qualified Identifiers {{{ */
1535 QualifiedIdentifier_
1536 : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); }
1537 | QualifiedIdentifier { $$ = $1; }
1541 : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); }
1544 /* 11.1.3 Wildcard Identifiers {{{ */
1546 : "*" { $$ = CYNew CYWildcard(); }
1549 /* 11.1.4 XML Initialiser {{{ */
1551 : XMLMarkup { $$ = $1; }
1552 | XMLElement { $$ = $1; }
1556 : "<" LexPushInOff XMLTagContent LexPop LexPopIn "/>"
1557 | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop LexPopIn ">"
1561 : LexPushXMLTag XMLTagName XMLAttributes
1565 : BRACE LexPushRegExp Expression LexPop "}"
1574 : XMLAttributes_ XMLAttribute
1579 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1580 | XMLAttributes_ XMLWhitespaceOpt
1589 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
1593 : XMLExpression XMLElementContentOpt
1594 | XMLMarkup XMLElementContentOpt
1595 | XMLText XMLElementContentOpt
1596 | XMLElement XMLElementContentOpt
1599 XMLElementContentOpt
1604 /* 11.1.5 XMLList Initialiser {{{ */
1606 : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop LexPopIn "</>" { $$ = CYNew CYXMLList($4); }
1609 /* 11.2 Left-Hand-Side Expressions {{{ */
1611 : Identifier { $$ = $1; }
1612 | PropertyIdentifier { $$ = $1; }
1616 : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); }
1617 | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); }
1618 | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); }
1621 /* 12.1 The default xml namespace Statement {{{ */
1622 /* XXX: DefaultXMLNamespaceStatement
1623 : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); }
1627 : DefaultXMLNamespaceStatement { $$ = $1; }
1632 /* ECMAScript5: Object Literal Trailing Comma {{{ */
1633 PropertyNameAndValueList_
1634 : "," { $$ = NULL; }
1638 /* JavaScript 1.7: Array Comprehensions {{{ */
1640 : "if" "(" Expression ")" { $$ = CYNew CYIfComprehension($3); }
1644 : "for" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForInComprehension($4, $7); }
1645 | "for" "each" "(" LexPushInOn Identifier LexPopIn "!in" Expression ")" { $$ = CYNew CYForEachInComprehension($5, $8); }
1649 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
1652 ComprehensionListOpt
1653 : ComprehensionList { $$ = $1; }
1654 | IfComprehension { $$ = $1; }
1659 : "[" LexPushInOff AssignmentExpression ComprehensionList LexPopIn "]" { $$ = CYNew CYArrayComprehension($3, $4); }
1662 /* JavaScript 1.7: for each {{{ */
1664 : "for" "each" "(" LexPushInOn ForInStatementInitialiser LexPopIn "!in" Expression ")" Statement { $$ = CYNew CYForEachIn($5, $8, $10); }
1667 /* JavaScript 1.7: let Statements {{{ */
1669 : "let" "(" VariableDeclarationList ")" Statement { $$ = CYNew CYLetStatement($3, $5); }
1677 /* JavaScript FTW: Ruby Blocks {{{ */
1678 RubyProcParameterList_
1679 : "," RubyProcParameterList { $$ = $2; }
1683 RubyProcParameterList
1684 : Identifier RubyProcParameterList_ { $$ = CYNew CYFunctionParameter(CYNew CYDeclaration($1), $2); }
1689 : "|" RubyProcParameterList "|" { $$ = $2; }
1690 | "||" { $$ = NULL; }
1693 RubyProcParametersOpt
1694 : RubyProcParameters
1699 : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); }
1703 : "{" LexPushInOff RubyProcParameters StatementListOpt LexPopIn "}" { $$ = CYNew CYRubyProc($3, $4); }
1707 : CallExpression_ RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); }