1 /* Cycript - Remove Execution Server and Disassembler
2 * Copyright (C) 2009 Jay Freeman (saurik)
5 /* Modified BSD License {{{ */
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
11 * 1. Redistributions of source code must retain the
12 * above copyright notice, this list of conditions
13 * and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the
15 * above copyright notice, this list of conditions
16 * and the following disclaimer in the documentation
17 * and/or other materials provided with the
19 * 3. The name of the author may not be used to endorse
20 * or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
25 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include "Cycript.tab.hh"
42 #define scanner driver.scanner_
43 #define YYSTACKEXPANDABLE 1
55 CYArgument *argument_;
56 CYAssignment *assignment_;
61 CYClassName *className_;
62 CYComprehension *comprehension_;
63 CYCompound *compound_;
64 CYDeclaration *declaration_;
65 CYDeclarations *declarations_;
67 CYExpression *expression_;
70 CYForInitialiser *for_;
71 CYForInInitialiser *forin_;
72 CYFunctionParameter *functionParameter_;
73 CYIdentifier *identifier_;
78 CYMessageParameter *messageParameter_;
81 CYProperty *property_;
82 CYPropertyName *propertyName_;
83 CYSelectorPart *selector_;
85 CYStatement *statement_;
96 int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
105 @$.begin.filename = @$.end.filename = &driver.filename_;
117 %parse-param { CYDriver &driver }
118 %lex-param { void *scanner }
121 %token AmpersandAmpersand "&&"
122 %token AmpersandEqual "&="
124 %token CarrotEqual "^="
126 %token EqualEqual "=="
127 %token EqualEqualEqual "==="
128 %token Exclamation "!"
129 %token ExclamationEqual "!="
130 %token ExclamationEqualEqual "!=="
132 %token HyphenEqual "-="
133 %token HyphenHyphen "--"
134 %token HyphenHyphen_ "\n--"
135 %token HyphenRight "->"
137 %token LeftEqual "<="
139 %token LeftLeftEqual "<<="
141 %token PercentEqual "%="
144 %token PipeEqual "|="
147 %token PlusEqual "+="
149 %token PlusPlus_ "\n++"
151 %token RightEqual ">="
152 %token RightRight ">>"
153 %token RightRightEqual ">>="
154 %token RightRightRight ">>>"
155 %token RightRightRightEqual ">>>="
157 %token SlashEqual "/="
159 %token StarEqual "*="
169 %token CloseParen ")"
172 %token CloseBrace "}"
174 %token OpenBracket "["
175 %token CloseBracket "]"
177 %token AtClass "@class"
178 %token AtSelector "@selector"
181 %token <false_> False "false"
182 %token <null_> Null "null"
183 %token <true_> True "true"
185 // ES3/ES5/WIE/JSC Reserved
186 %token <word_> Break "break"
187 %token <word_> Case "case"
188 %token <word_> Catch "catch"
189 %token <word_> Continue "continue"
190 %token <word_> Default "default"
191 %token <word_> Delete "delete"
192 %token <word_> Do "do"
193 %token <word_> Else "else"
194 %token <word_> Finally "finally"
195 %token <word_> For "for"
196 %token <word_> Function "function"
197 %token <word_> If "if"
198 %token <word_> In "in"
199 %token <word_> InstanceOf "instanceof"
200 %token <word_> New "new"
201 %token <word_> Return "return"
202 %token <word_> Switch "switch"
203 %token <this_> This "this"
204 %token <word_> Throw "throw"
205 %token <word_> Try "try"
206 %token <word_> TypeOf "typeof"
207 %token <word_> Var "var"
208 %token <word_> Void "void"
209 %token <word_> While "while"
210 %token <word_> With "with"
212 // ES3/IE6 Future, ES5/JSC Reserved
213 %token <word_> Debugger "debugger"
215 // ES3/ES5/IE6 Future, JSC Reserved
216 %token <word_> Const "const"
218 // ES3/ES5/IE6/JSC Future
219 %token <word_> Class "class"
220 %token <word_> Enum "enum"
221 %token <word_> Export "export"
222 %token <word_> Extends "extends"
223 %token <word_> Import "import"
224 %token <word_> Super "super"
226 // ES3 Future, ES5 Strict Future
227 %token <identifier_> Implements "implements"
228 %token <identifier_> Interface "interface"
229 %token <identifier_> Package "package"
230 %token <identifier_> Private "private"
231 %token <identifier_> Protected "protected"
232 %token <identifier_> Public "public"
233 %token <identifier_> Static "static"
236 %token <identifier_> Abstract "abstract"
237 %token <identifier_> Boolean "boolean"
238 %token <identifier_> Byte "byte"
239 %token <identifier_> Char "char"
240 %token <identifier_> Double "double"
241 %token <identifier_> Final "final"
242 %token <identifier_> Float "float"
243 %token <identifier_> Goto "goto"
244 %token <identifier_> Int "int"
245 %token <identifier_> Long "long"
246 %token <identifier_> Native "native"
247 %token <identifier_> Short "short"
248 %token <identifier_> Synchronized "synchronized"
249 %token <identifier_> Throws "throws"
250 %token <identifier_> Transient "transient"
251 %token <identifier_> Volatile "volatile"
254 %token <identifier_> Let "let"
255 %token <identifier_> Yield "yield"
258 %token <identifier_> Each "each"
260 %token <identifier_> Identifier_
261 %token <number_> NumericLiteral
262 %token <string_> StringLiteral
264 %type <expression_> AdditiveExpression
265 %type <expression_> AdditiveExpressionNoBF
266 %type <argument_> ArgumentList
267 %type <argument_> ArgumentList_
268 %type <argument_> ArgumentListOpt
269 %type <argument_> Arguments
270 %type <literal_> ArrayLiteral
271 %type <expression_> AssigneeExpression
272 %type <expression_> AssigneeExpression_
273 %type <expression_> AssigneeExpressionNoBF
274 %type <expression_> AssignmentExpression
275 %type <assignment_> AssignmentExpression_
276 %type <expression_> AssignmentExpressionNoBF
277 %type <expression_> AssignmentExpressionNoIn
278 %type <expression_> BitwiseANDExpression
279 %type <expression_> BitwiseANDExpressionNoBF
280 %type <expression_> BitwiseANDExpressionNoIn
281 %type <statement_> Block
282 %type <statement_> Block_
283 %type <boolean_> BooleanLiteral
284 %type <expression_> BitwiseORExpression
285 %type <expression_> BitwiseORExpressionNoBF
286 %type <expression_> BitwiseORExpressionNoIn
287 %type <expression_> BitwiseXORExpression
288 %type <expression_> BitwiseXORExpressionNoBF
289 %type <expression_> BitwiseXORExpressionNoIn
290 %type <statement_> BreakStatement
291 %type <expression_> CallExpression
292 %type <expression_> CallExpressionNoBF
293 %type <clause_> CaseBlock
294 %type <clause_> CaseClause
295 %type <clause_> CaseClausesOpt
296 %type <catch_> CatchOpt
297 %type <statement_> CategoryStatement
298 %type <class_> ClassDefinition
299 %type <message_> ClassMessageDeclaration
300 %type <message_> ClassMessageDeclarationListOpt
301 %type <className_> ClassName
302 %type <className_> ClassNameOpt
303 %type <expression_> ClassSuperOpt
304 %type <field_> ClassFieldList
305 %type <comprehension_> ComprehensionList
306 %type <comprehension_> ComprehensionListOpt
307 %type <expression_> ConditionalExpression
308 %type <expression_> ConditionalExpressionNoBF
309 %type <expression_> ConditionalExpressionNoIn
310 %type <statement_> ContinueStatement
311 %type <clause_> DefaultClause
312 %type <statement_> DoWhileStatement
313 %type <expression_> Element
314 %type <expression_> ElementOpt
315 %type <element_> ElementList
316 %type <element_> ElementListOpt
317 %type <statement_> ElseStatementOpt
318 %type <statement_> EmptyStatement
319 %type <expression_> EqualityExpression
320 %type <expression_> EqualityExpressionNoBF
321 %type <expression_> EqualityExpressionNoIn
322 %type <expression_> Expression
323 %type <expression_> ExpressionOpt
324 %type <compound_> Expression_
325 %type <expression_> ExpressionNoBF
326 %type <expression_> ExpressionNoIn
327 %type <compound_> ExpressionNoIn_
328 %type <expression_> ExpressionNoInOpt
329 %type <statement_> ExpressionStatement
330 %type <statement_> FinallyOpt
331 %type <comprehension_> ForComprehension
332 %type <statement_> ForStatement
333 %type <for_> ForStatementInitialiser
334 %type <statement_> ForInStatement
335 %type <forin_> ForInStatementInitialiser
336 %type <functionParameter_> FormalParameterList
337 %type <functionParameter_> FormalParameterList_
338 %type <source_> FunctionBody
339 %type <source_> FunctionDeclaration
340 %type <expression_> FunctionExpression
341 %type <identifier_> Identifier
342 %type <identifier_> IdentifierOpt
343 %type <comprehension_> IfComprehension
344 %type <statement_> IfStatement
345 %type <expression_> Initialiser
346 %type <expression_> InitialiserOpt
347 %type <expression_> InitialiserNoIn
348 %type <expression_> InitialiserNoInOpt
349 %type <statement_> IterationStatement
350 %type <statement_> LabelledStatement
351 %type <expression_> LeftHandSideExpression
352 %type <expression_> LeftHandSideExpressionNoBF
353 //%type <statement_> LetStatement
354 %type <literal_> Literal
355 %type <expression_> LogicalANDExpression
356 %type <expression_> LogicalANDExpressionNoBF
357 %type <expression_> LogicalANDExpressionNoIn
358 %type <expression_> LogicalORExpression
359 %type <expression_> LogicalORExpressionNoBF
360 %type <expression_> LogicalORExpressionNoIn
361 %type <member_> MemberAccess
362 %type <expression_> MemberExpression
363 %type <expression_> MemberExpression_
364 %type <expression_> MemberExpressionNoBF
365 %type <messageParameter_> MessageParameter
366 %type <messageParameter_> MessageParameters
367 %type <messageParameter_> MessageParameterList
368 %type <messageParameter_> MessageParameterListOpt
369 %type <bool_> MessageScope
370 %type <expression_> MultiplicativeExpression
371 %type <expression_> MultiplicativeExpressionNoBF
372 %type <expression_> NewExpression
373 %type <expression_> NewExpression_
374 %type <expression_> NewExpressionNoBF
375 %type <null_> NullLiteral
376 %type <literal_> ObjectLiteral
377 %type <expression_> PostfixExpression
378 %type <expression_> PostfixExpressionNoBF
379 %type <expression_> PrimaryExpression
380 %type <expression_> PrimaryExpression_
381 %type <expression_> PrimaryExpressionNoBF
382 %type <source_> Program
383 %type <propertyName_> PropertyName
384 %type <property_> PropertyNameAndValueList
385 %type <property_> PropertyNameAndValueList_
386 %type <property_> PropertyNameAndValueListOpt
387 %type <expression_> RelationalExpression
388 %type <infix_> RelationalExpression_
389 %type <expression_> RelationalExpressionNoBF
390 %type <expression_> RelationalExpressionNoIn
391 %type <infix_> RelationalExpressionNoIn_
392 %type <statement_> ReturnStatement
393 %type <selector_> SelectorExpression
394 %type <selector_> SelectorExpression_
395 %type <selector_> SelectorExpressionOpt
396 %type <expression_> ShiftExpression
397 %type <expression_> ShiftExpressionNoBF
398 %type <source_> SourceElement
399 %type <source_> SourceElements
400 %type <statement_> Statement
401 %type <statement_> StatementList
402 %type <statement_> StatementListOpt
403 %type <statement_> SwitchStatement
404 %type <statement_> ThrowStatement
405 %type <statement_> TryStatement
406 %type <expression_> TypeOpt
407 %type <expression_> UnaryExpression
408 %type <expression_> UnaryExpression_
409 %type <expression_> UnaryExpressionNoBF
410 %type <declaration_> VariableDeclaration
411 %type <declaration_> VariableDeclarationNoIn
412 %type <declarations_> VariableDeclarationList
413 %type <declarations_> VariableDeclarationList_
414 %type <declarations_> VariableDeclarationListNoIn
415 %type <declarations_> VariableDeclarationListNoIn_
416 %type <statement_> VariableStatement
417 %type <statement_> WhileStatement
418 %type <statement_> WithStatement
420 %type <word_> WordOpt
422 %type <expression_> MessageExpression
423 %type <argument_> SelectorCall
424 %type <argument_> SelectorCall_
425 %type <argument_> SelectorList
426 %type <argument_> VariadicCall
430 %left "<<" ">>" ">>>"
431 %left "<" ">" "<=" ">=" "instanceof" "in"
432 %left "==" "!=" "===" "!=="
439 %right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|="
451 | error { yyerrok; driver.errors_.pop_back(); }
457 | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } }
476 : Identifier { $$ = $1; }
477 | "break" NewLineOpt { $$ = $1; }
478 | "case" { $$ = $1; }
479 | "catch" { $$ = $1; }
480 | "class" { $$ = $1; }
481 | "const" { $$ = $1; }
482 | "continue" NewLineOpt { $$ = $1; }
483 | "debugger" { $$ = $1; }
484 | "default" { $$ = $1; }
485 | "delete" { $$ = $1; }
487 | "else" { $$ = $1; }
488 | "enum" { $$ = $1; }
489 | "export" { $$ = $1; }
490 | "extends" { $$ = $1; }
491 | "false" { $$ = $1; }
492 | "finally" { $$ = $1; }
494 | "function" { $$ = $1; }
496 | "import" { $$ = $1; }
497 /* XXX: | "in" { $$ = $1; } */
498 /* XXX: | "instanceof" { $$ = $1; } */
500 | "null" { $$ = $1; }
501 | "return" NewLineOpt { $$ = $1; }
502 | "super" { $$ = $1; }
503 | "switch" { $$ = $1; }
504 | "this" { $$ = $1; }
505 | "throw" NewLineOpt { $$ = $1; }
506 | "true" { $$ = $1; }
508 | "typeof" { $$ = $1; }
510 | "void" { $$ = $1; }
511 | "while" { $$ = $1; }
512 | "with" { $$ = $1; }
516 : Identifier_ { $$ = $1; }
518 | "implements" { $$ = $1; }
519 | "interface" { $$ = $1; }
520 | "package" { $$ = $1; }
521 | "private" { $$ = $1; }
522 | "protected" { $$ = $1; }
523 | "public" { $$ = $1; }
524 | "static" { $$ = $1; }
526 | "abstract" { $$ = $1; }
527 | "boolean" { $$ = $1; }
528 | "byte" { $$ = $1; }
529 | "char" { $$ = $1; }
530 | "double" { $$ = $1; }
531 | "final" { $$ = $1; }
532 | "float" { $$ = $1; }
533 | "goto" { $$ = $1; }
535 | "long" { $$ = $1; }
536 | "native" { $$ = $1; }
537 | "short" { $$ = $1; }
538 | "synchronized" { $$ = $1; }
539 | "throws" { $$ = $1; }
540 | "transient" { $$ = $1; }
541 | "volatile" { $$ = $1; }
544 | "yield" { $$ = $1; }
546 | "each" { $$ = $1; }
550 : Identifier { $$ = $1; }
555 : NullLiteral { $$ = $1; }
556 | BooleanLiteral { $$ = $1; }
557 | NumericLiteral { $$ = $1; }
558 | StringLiteral { $$ = $1; }
562 : "null" { $$ = $1; }
566 : "true" { $$ = $1; }
567 | "false" { $$ = $1; }
570 /* 11.1 Primary Expressions {{{ */
572 : "this" { $$ = $1; }
573 | Identifier { $$ = new(driver.pool_) CYVariable($1); }
574 | Literal { $$ = $1; }
575 | ArrayLiteral { $$ = $1; }
576 | "(" Expression ")" { $$ = $2; }
580 : ObjectLiteral { $$ = $1; }
581 | PrimaryExpression_ { $$ = $1; }
584 PrimaryExpressionNoBF
585 : PrimaryExpression_ { $$ = $1; }
588 /* 11.1.4 Array Initialiser {{{ */
590 : "[" ElementListOpt "]" { $$ = new(driver.pool_) CYArray($2); }
594 : AssignmentExpression { $$ = $1; }
598 : Element { $$ = $1; }
603 : ElementList { $$ = $1; }
608 : ElementOpt "," ElementListOpt { $$ = new(driver.pool_) CYElement($1, $3); }
609 | Element { $$ = new(driver.pool_) CYElement($1, NULL); }
612 /* 11.1.5 Object Initialiser {{{ */
614 : "{" PropertyNameAndValueListOpt "}" { $$ = new(driver.pool_) CYObject($2); }
617 PropertyNameAndValueList_
618 : "," PropertyNameAndValueList { $$ = $2; }
622 PropertyNameAndValueListOpt
623 : PropertyNameAndValueList { $$ = $1; }
627 PropertyNameAndValueList
628 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); }
632 : Identifier { $$ = $1; }
633 | StringLiteral { $$ = $1; }
634 | NumericLiteral { $$ = $1; }
639 : "new" MemberExpression Arguments { $$ = new(driver.pool_) CYNew($2, $3); }
643 : "[" Expression "]" { $$ = new(driver.pool_) CYDirectMember(NULL, $2); }
644 | "." Identifier { $$ = new(driver.pool_) CYDirectMember(NULL, new(driver.pool_) CYString($2)); }
648 : PrimaryExpression { $$ = $1; }
649 | FunctionExpression { $$ = $1; }
650 | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
651 | MemberExpression_ { $$ = $1; }
655 : PrimaryExpressionNoBF { $$ = $1; }
656 | MemberExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
657 | MemberExpression_ { $$ = $1; }
661 : "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); }
665 : MemberExpression { $$ = $1; }
666 | NewExpression_ { $$ = $1; }
670 : MemberExpressionNoBF { $$ = $1; }
671 | NewExpression_ { $$ = $1; }
675 : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
676 | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
677 | CallExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
681 : MemberExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
682 | CallExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
683 | CallExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
687 : "," ArgumentList { $$ = $2; }
692 : ArgumentList { $$ = $1; }
697 : AssignmentExpression ArgumentList_ { $$ = new(driver.pool_) CYArgument(NULL, $1, $2); }
701 : "(" ArgumentListOpt ")" { $$ = $2; }
704 LeftHandSideExpression
705 : NewExpression { $$ = $1; }
706 | CallExpression { $$ = $1; }
709 LeftHandSideExpressionNoBF
710 : NewExpressionNoBF { $$ = $1; }
711 | CallExpressionNoBF { $$ = $1; }
715 : AssigneeExpression { $$ = $1; }
716 | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
717 | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
720 PostfixExpressionNoBF
721 : AssigneeExpressionNoBF { $$ = $1; }
722 | LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
723 | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
727 : "delete" UnaryExpression { $$ = new(driver.pool_) CYDelete($2); }
728 | "void" UnaryExpression { $$ = new(driver.pool_) CYVoid($2); }
729 | "typeof" UnaryExpression { $$ = new(driver.pool_) CYTypeOf($2); }
730 | "++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
731 | "\n++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
732 | "--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
733 | "\n--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
734 | "+" UnaryExpression { $$ = $2; }
735 | "-" UnaryExpression { $$ = new(driver.pool_) CYNegate($2); }
736 | "~" UnaryExpression { $$ = new(driver.pool_) CYBitwiseNot($2); }
737 | "!" UnaryExpression { $$ = new(driver.pool_) CYLogicalNot($2); }
741 : PostfixExpression { $$ = $1; }
742 | UnaryExpression_ { $$ = $1; }
746 : PostfixExpressionNoBF { $$ = $1; }
747 | UnaryExpression_ { $$ = $1; }
750 MultiplicativeExpression
751 : UnaryExpression { $$ = $1; }
752 | MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
753 | MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
754 | MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
757 MultiplicativeExpressionNoBF
758 : UnaryExpressionNoBF { $$ = $1; }
759 | MultiplicativeExpressionNoBF "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
760 | MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
761 | MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
765 : MultiplicativeExpression { $$ = $1; }
766 | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
767 | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
770 AdditiveExpressionNoBF
771 : MultiplicativeExpressionNoBF { $$ = $1; }
772 | AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
773 | AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
777 : AdditiveExpression { $$ = $1; }
778 | ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
779 | ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
780 | ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
784 : AdditiveExpressionNoBF { $$ = $1; }
785 | ShiftExpressionNoBF "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
786 | ShiftExpressionNoBF ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
787 | ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
790 RelationalExpressionNoIn_
791 : "<" ShiftExpression { $$ = new(driver.pool_) CYLess(NULL, $2); }
792 | ">" ShiftExpression { $$ = new(driver.pool_) CYGreater(NULL, $2); }
793 | "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual(NULL, $2); }
794 | ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual(NULL, $2); }
795 | "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf(NULL, $2); }
798 RelationalExpression_
799 : RelationalExpressionNoIn_ { $$ = $1; }
800 | "in" ShiftExpression { $$ = new(driver.pool_) CYIn(NULL, $2); }
804 : ShiftExpression { $$ = $1; }
805 | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
808 RelationalExpressionNoIn
809 : ShiftExpression { $$ = $1; }
810 | RelationalExpressionNoIn RelationalExpressionNoIn_ { $2->SetLeft($1); $$ = $2; }
813 RelationalExpressionNoBF
814 : ShiftExpressionNoBF { $$ = $1; }
815 | RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
819 : RelationalExpression { $$ = $1; }
820 | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
821 | EqualityExpression "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
822 | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
823 | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
826 EqualityExpressionNoIn
827 : RelationalExpressionNoIn { $$ = $1; }
828 | EqualityExpressionNoIn "==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYEqual($1, $3); }
829 | EqualityExpressionNoIn "!=" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotEqual($1, $3); }
830 | EqualityExpressionNoIn "===" RelationalExpressionNoIn { $$ = new(driver.pool_) CYIdentical($1, $3); }
831 | EqualityExpressionNoIn "!==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
834 EqualityExpressionNoBF
835 : RelationalExpressionNoBF { $$ = $1; }
836 | EqualityExpressionNoBF "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
837 | EqualityExpressionNoBF "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
838 | EqualityExpressionNoBF "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
839 | EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
843 : EqualityExpression { $$ = $1; }
844 | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
847 BitwiseANDExpressionNoIn
848 : EqualityExpressionNoIn { $$ = $1; }
849 | BitwiseANDExpressionNoIn "&" EqualityExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
852 BitwiseANDExpressionNoBF
853 : EqualityExpressionNoBF { $$ = $1; }
854 | BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
858 : BitwiseANDExpression { $$ = $1; }
859 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
862 BitwiseXORExpressionNoIn
863 : BitwiseANDExpressionNoIn { $$ = $1; }
864 | BitwiseXORExpressionNoIn "^" BitwiseANDExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
867 BitwiseXORExpressionNoBF
868 : BitwiseANDExpressionNoBF { $$ = $1; }
869 | BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
873 : BitwiseXORExpression { $$ = $1; }
874 | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
877 BitwiseORExpressionNoIn
878 : BitwiseXORExpressionNoIn { $$ = $1; }
879 | BitwiseORExpressionNoIn "|" BitwiseXORExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
882 BitwiseORExpressionNoBF
883 : BitwiseXORExpressionNoBF { $$ = $1; }
884 | BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
888 : BitwiseORExpression { $$ = $1; }
889 | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
892 LogicalANDExpressionNoIn
893 : BitwiseORExpressionNoIn { $$ = $1; }
894 | LogicalANDExpressionNoIn "&&" BitwiseORExpressionNoIn { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
897 LogicalANDExpressionNoBF
898 : BitwiseORExpressionNoBF { $$ = $1; }
899 | LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
903 : LogicalANDExpression { $$ = $1; }
904 | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
907 LogicalORExpressionNoIn
908 : LogicalANDExpressionNoIn { $$ = $1; }
909 | LogicalORExpressionNoIn "||" LogicalANDExpressionNoIn { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
912 LogicalORExpressionNoBF
913 : LogicalANDExpressionNoBF { $$ = $1; }
914 | LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
917 ConditionalExpression
918 : LogicalORExpression { $$ = $1; }
919 | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
922 ConditionalExpressionNoIn
923 : LogicalORExpressionNoIn { $$ = $1; }
924 | LogicalORExpressionNoIn "?" AssignmentExpression ":" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
927 ConditionalExpressionNoBF
928 : LogicalORExpressionNoBF { $$ = $1; }
929 | LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
932 AssignmentExpression_
933 : "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign(NULL, $2); }
934 | "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign(NULL, $2); }
935 | "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign(NULL, $2); }
936 | "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign(NULL, $2); }
937 | "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign(NULL, $2); }
938 | "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign(NULL, $2); }
939 | "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign(NULL, $2); }
940 | ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign(NULL, $2); }
941 | ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign(NULL, $2); }
942 | "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign(NULL, $2); }
943 | "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign(NULL, $2); }
944 | "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign(NULL, $2); }
948 : LeftHandSideExpression { $$ = $1; }
949 | AssigneeExpression_ { $$ = $1; }
952 AssigneeExpressionNoBF
953 : LeftHandSideExpressionNoBF { $$ = $1; }
954 | AssigneeExpression_ { $$ = $1; }
958 : ConditionalExpression { $$ = $1; }
959 | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
962 AssignmentExpressionNoIn
963 : ConditionalExpressionNoIn { $$ = $1; }
964 | AssigneeExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); }
965 | AssigneeExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
966 | AssigneeExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
967 | AssigneeExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
968 | AssigneeExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); }
969 | AssigneeExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
970 | AssigneeExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
971 | AssigneeExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
972 | AssigneeExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
973 | AssigneeExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
974 | AssigneeExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
975 | AssigneeExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
978 AssignmentExpressionNoBF
979 : ConditionalExpressionNoBF { $$ = $1; }
980 | AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
984 : "," Expression { $$ = new(driver.pool_) CYCompound($2); }
989 : "," ExpressionNoIn { $$ = new(driver.pool_) CYCompound($2); }
994 : Expression { $$ = $1; }
999 : ExpressionNoIn { $$ = $1; }
1004 : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1008 : AssignmentExpressionNoIn ExpressionNoIn_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1012 : AssignmentExpressionNoBF Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1016 : Block { $$ = $1; }
1017 | VariableStatement { $$ = $1; }
1018 | EmptyStatement { $$ = $1; }
1019 | ExpressionStatement { $$ = $1; }
1020 | IfStatement { $$ = $1; }
1021 | IterationStatement { $$ = $1; }
1022 | ContinueStatement { $$ = $1; }
1023 | BreakStatement { $$ = $1; }
1024 | ReturnStatement { $$ = $1; }
1025 | WithStatement { $$ = $1; }
1026 | LabelledStatement { $$ = $1; }
1027 | SwitchStatement { $$ = $1; }
1028 | ThrowStatement { $$ = $1; }
1029 | TryStatement { $$ = $1; }
1033 : "{" StatementListOpt "}" { $$ = $2; }
1037 : Block_ { if ($1) $$ = new(driver.pool_) CYBlock($1); else $$ = new(driver.pool_) CYEmpty(); }
1041 : Statement StatementListOpt { $1->SetNext($2); $$ = $1; }
1045 : StatementList { $$ = $1; }
1050 : "var" VariableDeclarationList Terminator { $$ = new(driver.pool_) CYVar($2); }
1053 VariableDeclarationList_
1054 : "," VariableDeclarationList { $$ = $2; }
1058 VariableDeclarationListNoIn_
1059 : "," VariableDeclarationListNoIn { $$ = $2; }
1063 VariableDeclarationList
1064 : VariableDeclaration VariableDeclarationList_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1067 VariableDeclarationListNoIn
1068 : VariableDeclarationNoIn VariableDeclarationListNoIn_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1072 : Identifier InitialiserOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1075 VariableDeclarationNoIn
1076 : Identifier InitialiserNoInOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1080 : Initialiser { $$ = $1; }
1085 : InitialiserNoIn { $$ = $1; }
1090 : "=" AssignmentExpression { $$ = $2; }
1094 : "=" AssignmentExpressionNoIn { $$ = $2; }
1098 : ";" { $$ = new(driver.pool_) CYEmpty(); }
1102 : ExpressionNoBF Terminator { $$ = new(driver.pool_) CYExpress($1); }
1106 : "else" Statement { $$ = $2; }
1107 | %prec "if" { $$ = NULL; }
1111 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new(driver.pool_) CYIf($3, $5, $6); }
1115 : DoWhileStatement { $$ = $1; }
1116 | WhileStatement { $$ = $1; }
1117 | ForStatement { $$ = $1; }
1118 | ForInStatement { $$ = $1; }
1122 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = new(driver.pool_) CYDoWhile($5, $2); }
1126 : "while" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWhile($3, $5); }
1130 : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new(driver.pool_) CYFor($3, $5, $7, $9); }
1133 ForStatementInitialiser
1134 : ExpressionNoInOpt { $$ = $1; }
1135 | "var" VariableDeclarationListNoIn { $$ = $2; }
1139 : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForIn($3, $5, $7); }
1142 ForInStatementInitialiser
1143 : LeftHandSideExpression { $$ = $1; }
1144 | "var" VariableDeclarationNoIn { $$ = $2; }
1148 : "continue" IdentifierOpt Terminator { $$ = new(driver.pool_) CYContinue($2); }
1152 : "break" IdentifierOpt Terminator { $$ = new(driver.pool_) CYBreak($2); }
1156 : "return" ExpressionOpt Terminator { $$ = new(driver.pool_) CYReturn($2); }
1160 : "with" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWith($3, $5); }
1164 : "switch" "(" Expression ")" CaseBlock { $$ = new(driver.pool_) CYSwitch($3, $5); }
1168 : "{" CaseClausesOpt "}" { $$ = $2; }
1172 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1173 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1178 : "case" Expression ":" StatementListOpt { $$ = new(driver.pool_) CYClause($2, $4); }
1182 : "default" ":" StatementListOpt { $$ = new(driver.pool_) CYClause(NULL, $3); }
1186 : Identifier ":" Statement { $3->AddLabel($1); $$ = $3; }
1190 : "throw" Expression Terminator { $$ = new(driver.pool_) CYThrow($2); }
1194 : "try" Block_ CatchOpt FinallyOpt { $$ = new(driver.pool_) CYTry($2, $3, $4); }
1198 : "catch" "(" Identifier ")" Block_ { $$ = new(driver.pool_) CYCatch($3, $5); }
1203 : "finally" Block_ { $$ = $2; }
1208 : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunction($2, $4, $7); }
1212 : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYLambda($2, $4, $7); }
1215 FormalParameterList_
1216 : "," FormalParameterList { $$ = $2; }
1221 : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYFunctionParameter($1, $2); }
1226 : SourceElements { $$ = $1; }
1230 : SourceElements { driver.source_ = $1; }
1234 : SourceElement SourceElements { $1->SetNext($2); $$ = $1; }
1239 : Statement { $$ = $1; }
1240 | FunctionDeclaration { $$ = $1; }
1243 /* Cycript: @class Declaration {{{ */
1245 : ":" MemberExpressionNoBF { $$ = $2; }
1250 : "{" "}" { $$ = NULL; }
1254 : "+" { $$ = false; }
1255 | "-" { $$ = true; }
1259 : "(" Expression ")" { $$ = $2; }
1264 : Word ":" TypeOpt Identifier { $$ = new(driver.pool_) CYMessageParameter($1, $3, $4); }
1267 MessageParameterListOpt
1268 : MessageParameterList { $$ = $1; }
1272 MessageParameterList
1273 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1277 : MessageParameterList { $$ = $1; }
1278 | Word { $$ = new(driver.pool_) CYMessageParameter($1, NULL, NULL); }
1281 ClassMessageDeclaration
1282 : MessageScope TypeOpt MessageParameters "{" FunctionBody "}" { $$ = new(driver.pool_) CYMessage($1, $2, $3, $5); }
1285 ClassMessageDeclarationListOpt
1286 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1291 : Identifier { $$ = $1; }
1292 | "(" AssignmentExpression ")" { $$ = $2; }
1296 : ClassName { $$ = $1; }
1301 : "@class" ClassNameOpt ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClass($2, $3, $4, $5); }
1305 : "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); }
1309 : ClassDefinition { $$ = $1; }
1313 : ClassDefinition { $$ = $1; }
1314 | CategoryStatement { $$ = $1; }
1317 /* Cycript: Send Message {{{ */
1319 : "," AssignmentExpression VariadicCall { $$ = new(driver.pool_) CYArgument(NULL, $2, $3); }
1324 : SelectorCall { $$ = $1; }
1325 | VariadicCall { $$ = $1; }
1329 : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new(driver.pool_) CYArgument($1 ?: new(driver.pool_) CYBlank(), $3, $4); }
1333 : SelectorCall { $$ = $1; }
1334 | Word { $$ = new(driver.pool_) CYArgument($1, NULL); }
1338 : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSend($2, $3); }
1341 SelectorExpressionOpt
1342 : SelectorExpression_ { $$ = $1; }
1347 : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelectorPart($1, true, $3); }
1351 : SelectorExpression_ { $$ = $1; }
1352 | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); }
1356 : MessageExpression { $$ = $1; }
1357 | "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); }
1360 /* Cycript: Pointer Indirection/Addressing {{{ */
1362 : "*" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); }
1366 : "&" UnaryExpression { $$ = new(driver.pool_) CYAddressOf($2); }
1370 : "->" Identifier { $$ = new(driver.pool_) CYIndirectMember(NULL, new(driver.pool_) CYString($2)); }
1373 /* ECMAScript5: Object Literal Trailing Comma {{{ */
1374 PropertyNameAndValueList_
1375 : "," { $$ = NULL; }
1378 /* JavaScript 1.7: Array Comprehensions {{{ */
1380 : "if" "(" Expression ")" { $$ = new(driver.pool_) CYIfComprehension($3); }
1384 : "for" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForInComprehension($3, $5); }
1385 | "for" "each" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForEachInComprehension($4, $6); }
1388 ComprehensionListOpt
1389 : ComprehensionList { $$ = $1; }
1390 | IfComprehension { $$ = $1; }
1395 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
1399 : "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); }
1402 /* JavaScript 1.7: for each {{{ */
1404 : "for" "each" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForEachIn($4, $6, $8); }
1407 /* JavaScript 1.7: Let Statements {{{ *//*
1409 : "let" "(" VariableDeclarationList ")" Block_ { $$ = new(driver.pool_) CYLet($3, $5); }