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 <word_> Break "break"
182 %token <word_> Case "case"
183 %token <word_> Catch "catch"
184 %token <word_> Continue "continue"
185 %token <word_> Default "default"
186 %token <word_> Delete "delete"
187 %token <word_> Do "do"
188 %token <word_> Else "else"
189 %token <false_> False "false"
190 %token <word_> Finally "finally"
191 %token <word_> For "for"
192 %token <word_> Function "function"
193 %token <word_> If "if"
194 %token <word_> In "in"
195 %token <word_> InstanceOf "instanceof"
196 %token <word_> New "new"
197 %token <null_> Null "null"
198 %token <word_> Return "return"
199 %token <word_> Switch "switch"
200 %token <this_> This "this"
201 %token <word_> Throw "throw"
202 %token <true_> True "true"
203 %token <word_> Try "try"
204 %token <word_> TypeOf "typeof"
205 %token <word_> Var "var"
206 %token <word_> Void "void"
207 %token <word_> While "while"
208 %token <word_> With "with"
210 %token <word_> Abstract "abstract"
211 %token <word_> Boolean "boolean"
212 %token <word_> Byte "byte"
213 %token <word_> Char "char"
214 %token <word_> Class "class"
215 %token <word_> Const "const"
216 %token <word_> Debugger "debugger"
217 %token <word_> Double "double"
218 %token <word_> Enum "enum"
219 %token <word_> Export "export"
220 %token <word_> Extends "extends"
221 %token <word_> Final "final"
222 %token <word_> Float "float"
223 %token <word_> Goto "goto"
224 %token <word_> Implements "implements"
225 %token <word_> Import "import"
226 %token <word_> Int "int"
227 %token <word_> Interface "interface"
228 %token <word_> Long "long"
229 %token <word_> Native "native"
230 %token <word_> Package "package"
231 %token <word_> Private "private"
232 %token <word_> Protected "protected"
233 %token <word_> Public "public"
234 %token <word_> Short "short"
235 %token <word_> Static "static"
236 %token <word_> Super "super"
237 %token <word_> Synchronized "synchronized"
238 %token <word_> Throws "throws"
239 %token <word_> Transient "transient"
240 %token <word_> Volatile "volatile"
242 %token <identifier_> Each "each"
243 %token <identifier_> Let "let"
245 %token <identifier_> Identifier_
246 %token <number_> NumericLiteral
247 %token <string_> StringLiteral
249 %type <expression_> AdditiveExpression
250 %type <expression_> AdditiveExpressionNoBF
251 %type <argument_> ArgumentList
252 %type <argument_> ArgumentList_
253 %type <argument_> ArgumentListOpt
254 %type <argument_> Arguments
255 %type <literal_> ArrayLiteral
256 %type <expression_> AssigneeExpression
257 %type <expression_> AssigneeExpression_
258 %type <expression_> AssigneeExpressionNoBF
259 %type <expression_> AssignmentExpression
260 %type <assignment_> AssignmentExpression_
261 %type <expression_> AssignmentExpressionNoBF
262 %type <expression_> AssignmentExpressionNoIn
263 %type <expression_> BitwiseANDExpression
264 %type <expression_> BitwiseANDExpressionNoBF
265 %type <expression_> BitwiseANDExpressionNoIn
266 %type <statement_> Block
267 %type <statement_> Block_
268 %type <boolean_> BooleanLiteral
269 %type <expression_> BitwiseORExpression
270 %type <expression_> BitwiseORExpressionNoBF
271 %type <expression_> BitwiseORExpressionNoIn
272 %type <expression_> BitwiseXORExpression
273 %type <expression_> BitwiseXORExpressionNoBF
274 %type <expression_> BitwiseXORExpressionNoIn
275 %type <statement_> BreakStatement
276 %type <expression_> CallExpression
277 %type <expression_> CallExpressionNoBF
278 %type <clause_> CaseBlock
279 %type <clause_> CaseClause
280 %type <clause_> CaseClausesOpt
281 %type <catch_> CatchOpt
282 %type <statement_> CategoryStatement
283 %type <class_> ClassDefinition
284 %type <message_> ClassMessageDeclaration
285 %type <message_> ClassMessageDeclarationListOpt
286 %type <className_> ClassName
287 %type <className_> ClassNameOpt
288 %type <expression_> ClassSuperOpt
289 %type <field_> ClassFieldList
290 %type <comprehension_> ComprehensionList
291 %type <comprehension_> ComprehensionListOpt
292 %type <expression_> ConditionalExpression
293 %type <expression_> ConditionalExpressionNoBF
294 %type <expression_> ConditionalExpressionNoIn
295 %type <statement_> ContinueStatement
296 %type <clause_> DefaultClause
297 %type <statement_> DoWhileStatement
298 %type <expression_> Element
299 %type <expression_> ElementOpt
300 %type <element_> ElementList
301 %type <element_> ElementListOpt
302 %type <statement_> ElseStatementOpt
303 %type <statement_> EmptyStatement
304 %type <expression_> EqualityExpression
305 %type <expression_> EqualityExpressionNoBF
306 %type <expression_> EqualityExpressionNoIn
307 %type <expression_> Expression
308 %type <expression_> ExpressionOpt
309 %type <compound_> Expression_
310 %type <expression_> ExpressionNoBF
311 %type <expression_> ExpressionNoIn
312 %type <compound_> ExpressionNoIn_
313 %type <expression_> ExpressionNoInOpt
314 %type <statement_> ExpressionStatement
315 %type <statement_> FinallyOpt
316 %type <comprehension_> ForComprehension
317 %type <statement_> ForStatement
318 %type <for_> ForStatementInitialiser
319 %type <statement_> ForInStatement
320 %type <forin_> ForInStatementInitialiser
321 %type <functionParameter_> FormalParameterList
322 %type <functionParameter_> FormalParameterList_
323 %type <source_> FunctionBody
324 %type <source_> FunctionDeclaration
325 %type <expression_> FunctionExpression
326 %type <identifier_> Identifier
327 %type <identifier_> IdentifierOpt
328 %type <comprehension_> IfComprehension
329 %type <statement_> IfStatement
330 %type <expression_> Initialiser
331 %type <expression_> InitialiserOpt
332 %type <expression_> InitialiserNoIn
333 %type <expression_> InitialiserNoInOpt
334 %type <statement_> IterationStatement
335 %type <statement_> LabelledStatement
336 %type <expression_> LeftHandSideExpression
337 %type <expression_> LeftHandSideExpressionNoBF
338 %type <statement_> LetStatement
339 %type <literal_> Literal
340 %type <expression_> LogicalANDExpression
341 %type <expression_> LogicalANDExpressionNoBF
342 %type <expression_> LogicalANDExpressionNoIn
343 %type <expression_> LogicalORExpression
344 %type <expression_> LogicalORExpressionNoBF
345 %type <expression_> LogicalORExpressionNoIn
346 %type <member_> MemberAccess
347 %type <expression_> MemberExpression
348 %type <expression_> MemberExpression_
349 %type <expression_> MemberExpressionNoBF
350 %type <messageParameter_> MessageParameter
351 %type <messageParameter_> MessageParameters
352 %type <messageParameter_> MessageParameterList
353 %type <messageParameter_> MessageParameterListOpt
354 %type <bool_> MessageScope
355 %type <expression_> MultiplicativeExpression
356 %type <expression_> MultiplicativeExpressionNoBF
357 %type <expression_> NewExpression
358 %type <expression_> NewExpression_
359 %type <expression_> NewExpressionNoBF
360 %type <null_> NullLiteral
361 %type <literal_> ObjectLiteral
362 %type <expression_> PostfixExpression
363 %type <expression_> PostfixExpressionNoBF
364 %type <expression_> PrimaryExpression
365 %type <expression_> PrimaryExpression_
366 %type <expression_> PrimaryExpressionNoBF
367 %type <source_> Program
368 %type <propertyName_> PropertyName
369 %type <property_> PropertyNameAndValueList
370 %type <property_> PropertyNameAndValueList_
371 %type <property_> PropertyNameAndValueListOpt
372 %type <expression_> RelationalExpression
373 %type <infix_> RelationalExpression_
374 %type <expression_> RelationalExpressionNoBF
375 %type <expression_> RelationalExpressionNoIn
376 %type <infix_> RelationalExpressionNoIn_
377 %type <statement_> ReturnStatement
378 %type <selector_> SelectorExpression
379 %type <selector_> SelectorExpression_
380 %type <selector_> SelectorExpressionOpt
381 %type <expression_> ShiftExpression
382 %type <expression_> ShiftExpressionNoBF
383 %type <source_> SourceElement
384 %type <source_> SourceElements
385 %type <statement_> Statement
386 %type <statement_> StatementList
387 %type <statement_> StatementListOpt
388 %type <statement_> SwitchStatement
389 %type <statement_> ThrowStatement
390 %type <statement_> TryStatement
391 %type <expression_> TypeOpt
392 %type <expression_> UnaryExpression
393 %type <expression_> UnaryExpression_
394 %type <expression_> UnaryExpressionNoBF
395 %type <declaration_> VariableDeclaration
396 %type <declaration_> VariableDeclarationNoIn
397 %type <declarations_> VariableDeclarationList
398 %type <declarations_> VariableDeclarationList_
399 %type <declarations_> VariableDeclarationListNoIn
400 %type <declarations_> VariableDeclarationListNoIn_
401 %type <statement_> VariableStatement
402 %type <statement_> WhileStatement
403 %type <statement_> WithStatement
405 %type <word_> WordOpt
407 %type <expression_> MessageExpression
408 %type <argument_> SelectorCall
409 %type <argument_> SelectorCall_
410 %type <argument_> SelectorList
411 %type <argument_> VariadicCall
415 %left "<<" ">>" ">>>"
416 %left "<" ">" "<=" ">=" "instanceof" "in"
417 %left "==" "!=" "===" "!=="
424 %right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|="
436 | error { yyerrok; driver.errors_.pop_back(); }
442 | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } }
461 : Identifier { $$ = $1; }
462 | "abstract" { $$ = $1; }
463 | "boolean" { $$ = $1; }
464 | "break" NewLineOpt { $$ = $1; }
465 | "byte" { $$ = $1; }
466 | "case" { $$ = $1; }
467 | "catch" { $$ = $1; }
468 | "char" { $$ = $1; }
469 | "class" { $$ = $1; }
470 | "const" { $$ = $1; }
471 | "continue" NewLineOpt { $$ = $1; }
472 | "debugger" { $$ = $1; }
473 | "default" { $$ = $1; }
474 | "delete" { $$ = $1; }
476 | "double" { $$ = $1; }
477 | "else" { $$ = $1; }
478 | "enum" { $$ = $1; }
479 | "export" { $$ = $1; }
480 | "extends" { $$ = $1; }
481 | "false" { $$ = $1; }
482 | "final" { $$ = $1; }
483 | "finally" { $$ = $1; }
484 | "float" { $$ = $1; }
486 | "function" { $$ = $1; }
487 | "goto" { $$ = $1; }
489 | "implements" { $$ = $1; }
490 | "import" { $$ = $1; }
491 /* XXX: | "in" { $$ = $1; } */
492 /* XXX: | "instanceof" { $$ = $1; } */
494 | "interface" { $$ = $1; }
495 | "long" { $$ = $1; }
496 | "native" { $$ = $1; }
498 | "null" { $$ = $1; }
499 | "package" { $$ = $1; }
500 | "private" { $$ = $1; }
501 | "protected" { $$ = $1; }
502 | "public" { $$ = $1; }
503 | "return" NewLineOpt { $$ = $1; }
504 | "short" { $$ = $1; }
505 | "static" { $$ = $1; }
506 | "super" { $$ = $1; }
507 | "switch" { $$ = $1; }
508 | "synchronized" { $$ = $1; }
509 | "this" { $$ = $1; }
510 | "throw" NewLineOpt { $$ = $1; }
511 | "throws" { $$ = $1; }
512 | "transient" { $$ = $1; }
513 | "true" { $$ = $1; }
515 | "typeof" { $$ = $1; }
517 | "void" { $$ = $1; }
518 | "volatile" { $$ = $1; }
519 | "while" { $$ = $1; }
520 | "with" { $$ = $1; }
524 : Identifier_ { $$ = $1; }
525 | "each" { $$ = $1; }
530 : Identifier { $$ = $1; }
535 : NullLiteral { $$ = $1; }
536 | BooleanLiteral { $$ = $1; }
537 | NumericLiteral { $$ = $1; }
538 | StringLiteral { $$ = $1; }
542 : "null" { $$ = $1; }
546 : "true" { $$ = $1; }
547 | "false" { $$ = $1; }
550 /* 11.1 Primary Expressions {{{ */
552 : "this" { $$ = $1; }
553 | Identifier { $$ = new(driver.pool_) CYVariable($1); }
554 | Literal { $$ = $1; }
555 | ArrayLiteral { $$ = $1; }
556 | "(" Expression ")" { $$ = $2; }
560 : ObjectLiteral { $$ = $1; }
561 | PrimaryExpression_ { $$ = $1; }
564 PrimaryExpressionNoBF
565 : PrimaryExpression_ { $$ = $1; }
568 /* 11.1.4 Array Initialiser {{{ */
570 : "[" ElementListOpt "]" { $$ = new(driver.pool_) CYArray($2); }
574 : AssignmentExpression { $$ = $1; }
578 : Element { $$ = $1; }
583 : ElementList { $$ = $1; }
588 : ElementOpt "," ElementListOpt { $$ = new(driver.pool_) CYElement($1, $3); }
589 | Element { $$ = new(driver.pool_) CYElement($1, NULL); }
592 /* 11.1.5 Object Initialiser {{{ */
594 : "{" PropertyNameAndValueListOpt "}" { $$ = new(driver.pool_) CYObject($2); }
597 PropertyNameAndValueList_
598 : "," PropertyNameAndValueList { $$ = $2; }
602 PropertyNameAndValueListOpt
603 : PropertyNameAndValueList { $$ = $1; }
607 PropertyNameAndValueList
608 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); }
612 : Identifier { $$ = $1; }
613 | StringLiteral { $$ = $1; }
614 | NumericLiteral { $$ = $1; }
619 : "new" MemberExpression Arguments { $$ = new(driver.pool_) CYNew($2, $3); }
623 : "[" Expression "]" { $$ = new(driver.pool_) CYDirectMember(NULL, $2); }
624 | "." Identifier { $$ = new(driver.pool_) CYDirectMember(NULL, new(driver.pool_) CYString($2)); }
628 : PrimaryExpression { $$ = $1; }
629 | FunctionExpression { $$ = $1; }
630 | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
631 | MemberExpression_ { $$ = $1; }
635 : PrimaryExpressionNoBF { $$ = $1; }
636 | MemberExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
637 | MemberExpression_ { $$ = $1; }
641 : "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); }
645 : MemberExpression { $$ = $1; }
646 | NewExpression_ { $$ = $1; }
650 : MemberExpressionNoBF { $$ = $1; }
651 | NewExpression_ { $$ = $1; }
655 : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
656 | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
657 | CallExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
661 : MemberExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
662 | CallExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
663 | CallExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
667 : "," ArgumentList { $$ = $2; }
672 : ArgumentList { $$ = $1; }
677 : AssignmentExpression ArgumentList_ { $$ = new(driver.pool_) CYArgument(NULL, $1, $2); }
681 : "(" ArgumentListOpt ")" { $$ = $2; }
684 LeftHandSideExpression
685 : NewExpression { $$ = $1; }
686 | CallExpression { $$ = $1; }
689 LeftHandSideExpressionNoBF
690 : NewExpressionNoBF { $$ = $1; }
691 | CallExpressionNoBF { $$ = $1; }
695 : AssigneeExpression { $$ = $1; }
696 | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
697 | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
700 PostfixExpressionNoBF
701 : AssigneeExpressionNoBF { $$ = $1; }
702 | LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
703 | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
707 : "delete" UnaryExpression { $$ = new(driver.pool_) CYDelete($2); }
708 | "void" UnaryExpression { $$ = new(driver.pool_) CYVoid($2); }
709 | "typeof" UnaryExpression { $$ = new(driver.pool_) CYTypeOf($2); }
710 | "++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
711 | "\n++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
712 | "--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
713 | "\n--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
714 | "+" UnaryExpression { $$ = $2; }
715 | "-" UnaryExpression { $$ = new(driver.pool_) CYNegate($2); }
716 | "~" UnaryExpression { $$ = new(driver.pool_) CYBitwiseNot($2); }
717 | "!" UnaryExpression { $$ = new(driver.pool_) CYLogicalNot($2); }
721 : PostfixExpression { $$ = $1; }
722 | UnaryExpression_ { $$ = $1; }
726 : PostfixExpressionNoBF { $$ = $1; }
727 | UnaryExpression_ { $$ = $1; }
730 MultiplicativeExpression
731 : UnaryExpression { $$ = $1; }
732 | MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
733 | MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
734 | MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
737 MultiplicativeExpressionNoBF
738 : UnaryExpressionNoBF { $$ = $1; }
739 | MultiplicativeExpressionNoBF "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
740 | MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
741 | MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
745 : MultiplicativeExpression { $$ = $1; }
746 | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
747 | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
750 AdditiveExpressionNoBF
751 : MultiplicativeExpressionNoBF { $$ = $1; }
752 | AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
753 | AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
757 : AdditiveExpression { $$ = $1; }
758 | ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
759 | ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
760 | ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
764 : AdditiveExpressionNoBF { $$ = $1; }
765 | ShiftExpressionNoBF "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
766 | ShiftExpressionNoBF ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
767 | ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
770 RelationalExpressionNoIn_
771 : "<" ShiftExpression { $$ = new(driver.pool_) CYLess(NULL, $2); }
772 | ">" ShiftExpression { $$ = new(driver.pool_) CYGreater(NULL, $2); }
773 | "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual(NULL, $2); }
774 | ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual(NULL, $2); }
775 | "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf(NULL, $2); }
778 RelationalExpression_
779 : RelationalExpressionNoIn_ { $$ = $1; }
780 | "in" ShiftExpression { $$ = new(driver.pool_) CYIn(NULL, $2); }
784 : ShiftExpression { $$ = $1; }
785 | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
788 RelationalExpressionNoIn
789 : ShiftExpression { $$ = $1; }
790 | RelationalExpressionNoIn RelationalExpressionNoIn_ { $2->SetLeft($1); $$ = $2; }
793 RelationalExpressionNoBF
794 : ShiftExpressionNoBF { $$ = $1; }
795 | RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
799 : RelationalExpression { $$ = $1; }
800 | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
801 | EqualityExpression "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
802 | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
803 | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
806 EqualityExpressionNoIn
807 : RelationalExpressionNoIn { $$ = $1; }
808 | EqualityExpressionNoIn "==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYEqual($1, $3); }
809 | EqualityExpressionNoIn "!=" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotEqual($1, $3); }
810 | EqualityExpressionNoIn "===" RelationalExpressionNoIn { $$ = new(driver.pool_) CYIdentical($1, $3); }
811 | EqualityExpressionNoIn "!==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
814 EqualityExpressionNoBF
815 : RelationalExpressionNoBF { $$ = $1; }
816 | EqualityExpressionNoBF "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
817 | EqualityExpressionNoBF "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
818 | EqualityExpressionNoBF "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
819 | EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
823 : EqualityExpression { $$ = $1; }
824 | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
827 BitwiseANDExpressionNoIn
828 : EqualityExpressionNoIn { $$ = $1; }
829 | BitwiseANDExpressionNoIn "&" EqualityExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
832 BitwiseANDExpressionNoBF
833 : EqualityExpressionNoBF { $$ = $1; }
834 | BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
838 : BitwiseANDExpression { $$ = $1; }
839 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
842 BitwiseXORExpressionNoIn
843 : BitwiseANDExpressionNoIn { $$ = $1; }
844 | BitwiseXORExpressionNoIn "^" BitwiseANDExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
847 BitwiseXORExpressionNoBF
848 : BitwiseANDExpressionNoBF { $$ = $1; }
849 | BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
853 : BitwiseXORExpression { $$ = $1; }
854 | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
857 BitwiseORExpressionNoIn
858 : BitwiseXORExpressionNoIn { $$ = $1; }
859 | BitwiseORExpressionNoIn "|" BitwiseXORExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
862 BitwiseORExpressionNoBF
863 : BitwiseXORExpressionNoBF { $$ = $1; }
864 | BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
868 : BitwiseORExpression { $$ = $1; }
869 | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
872 LogicalANDExpressionNoIn
873 : BitwiseORExpressionNoIn { $$ = $1; }
874 | LogicalANDExpressionNoIn "&&" BitwiseORExpressionNoIn { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
877 LogicalANDExpressionNoBF
878 : BitwiseORExpressionNoBF { $$ = $1; }
879 | LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
883 : LogicalANDExpression { $$ = $1; }
884 | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
887 LogicalORExpressionNoIn
888 : LogicalANDExpressionNoIn { $$ = $1; }
889 | LogicalORExpressionNoIn "||" LogicalANDExpressionNoIn { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
892 LogicalORExpressionNoBF
893 : LogicalANDExpressionNoBF { $$ = $1; }
894 | LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
897 ConditionalExpression
898 : LogicalORExpression { $$ = $1; }
899 | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
902 ConditionalExpressionNoIn
903 : LogicalORExpressionNoIn { $$ = $1; }
904 | LogicalORExpressionNoIn "?" AssignmentExpression ":" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
907 ConditionalExpressionNoBF
908 : LogicalORExpressionNoBF { $$ = $1; }
909 | LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
912 AssignmentExpression_
913 : "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign(NULL, $2); }
914 | "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign(NULL, $2); }
915 | "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign(NULL, $2); }
916 | "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign(NULL, $2); }
917 | "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign(NULL, $2); }
918 | "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign(NULL, $2); }
919 | "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign(NULL, $2); }
920 | ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign(NULL, $2); }
921 | ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign(NULL, $2); }
922 | "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign(NULL, $2); }
923 | "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign(NULL, $2); }
924 | "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign(NULL, $2); }
928 : LeftHandSideExpression { $$ = $1; }
929 | AssigneeExpression_ { $$ = $1; }
932 AssigneeExpressionNoBF
933 : LeftHandSideExpressionNoBF { $$ = $1; }
934 | AssigneeExpression_ { $$ = $1; }
938 : ConditionalExpression { $$ = $1; }
939 | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
942 AssignmentExpressionNoIn
943 : ConditionalExpressionNoIn { $$ = $1; }
944 | AssigneeExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); }
945 | AssigneeExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
946 | AssigneeExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
947 | AssigneeExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
948 | AssigneeExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); }
949 | AssigneeExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
950 | AssigneeExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
951 | AssigneeExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
952 | AssigneeExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
953 | AssigneeExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
954 | AssigneeExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
955 | AssigneeExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
958 AssignmentExpressionNoBF
959 : ConditionalExpressionNoBF { $$ = $1; }
960 | AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
964 : "," Expression { $$ = new(driver.pool_) CYCompound($2); }
969 : "," ExpressionNoIn { $$ = new(driver.pool_) CYCompound($2); }
974 : Expression { $$ = $1; }
979 : ExpressionNoIn { $$ = $1; }
984 : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
988 : AssignmentExpressionNoIn ExpressionNoIn_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
992 : AssignmentExpressionNoBF Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
997 | VariableStatement { $$ = $1; }
998 | EmptyStatement { $$ = $1; }
999 | ExpressionStatement { $$ = $1; }
1000 | IfStatement { $$ = $1; }
1001 | IterationStatement { $$ = $1; }
1002 | ContinueStatement { $$ = $1; }
1003 | BreakStatement { $$ = $1; }
1004 | ReturnStatement { $$ = $1; }
1005 | WithStatement { $$ = $1; }
1006 | LabelledStatement { $$ = $1; }
1007 | SwitchStatement { $$ = $1; }
1008 | ThrowStatement { $$ = $1; }
1009 | TryStatement { $$ = $1; }
1013 : "{" StatementListOpt "}" { $$ = $2; }
1017 : Block_ { if ($1) $$ = new(driver.pool_) CYBlock($1); else $$ = new(driver.pool_) CYEmpty(); }
1021 : Statement StatementListOpt { $1->SetNext($2); $$ = $1; }
1025 : StatementList { $$ = $1; }
1030 : "var" VariableDeclarationList Terminator { $$ = new(driver.pool_) CYVar($2); }
1033 VariableDeclarationList_
1034 : "," VariableDeclarationList { $$ = $2; }
1038 VariableDeclarationListNoIn_
1039 : "," VariableDeclarationListNoIn { $$ = $2; }
1043 VariableDeclarationList
1044 : VariableDeclaration VariableDeclarationList_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1047 VariableDeclarationListNoIn
1048 : VariableDeclarationNoIn VariableDeclarationListNoIn_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1052 : Identifier InitialiserOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1055 VariableDeclarationNoIn
1056 : Identifier InitialiserNoInOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1060 : Initialiser { $$ = $1; }
1065 : InitialiserNoIn { $$ = $1; }
1070 : "=" AssignmentExpression { $$ = $2; }
1074 : "=" AssignmentExpressionNoIn { $$ = $2; }
1078 : ";" { $$ = new(driver.pool_) CYEmpty(); }
1082 : ExpressionNoBF Terminator { $$ = new(driver.pool_) CYExpress($1); }
1086 : "else" Statement { $$ = $2; }
1087 | %prec "if" { $$ = NULL; }
1091 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new(driver.pool_) CYIf($3, $5, $6); }
1095 : DoWhileStatement { $$ = $1; }
1096 | WhileStatement { $$ = $1; }
1097 | ForStatement { $$ = $1; }
1098 | ForInStatement { $$ = $1; }
1102 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = new(driver.pool_) CYDoWhile($5, $2); }
1106 : "while" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWhile($3, $5); }
1110 : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new(driver.pool_) CYFor($3, $5, $7, $9); }
1113 ForStatementInitialiser
1114 : ExpressionNoInOpt { $$ = $1; }
1115 | "var" VariableDeclarationListNoIn { $$ = $2; }
1119 : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForIn($3, $5, $7); }
1122 ForInStatementInitialiser
1123 : LeftHandSideExpression { $$ = $1; }
1124 | "var" VariableDeclarationNoIn { $$ = $2; }
1128 : "continue" IdentifierOpt Terminator { $$ = new(driver.pool_) CYContinue($2); }
1132 : "break" IdentifierOpt Terminator { $$ = new(driver.pool_) CYBreak($2); }
1136 : "return" ExpressionOpt Terminator { $$ = new(driver.pool_) CYReturn($2); }
1140 : "with" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWith($3, $5); }
1144 : "switch" "(" Expression ")" CaseBlock { $$ = new(driver.pool_) CYSwitch($3, $5); }
1148 : "{" CaseClausesOpt "}" { $$ = $2; }
1152 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1153 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1158 : "case" Expression ":" StatementListOpt { $$ = new(driver.pool_) CYClause($2, $4); }
1162 : "default" ":" StatementListOpt { $$ = new(driver.pool_) CYClause(NULL, $3); }
1166 : Identifier ":" Statement { $3->AddLabel($1); $$ = $3; }
1170 : "throw" Expression Terminator { $$ = new(driver.pool_) CYThrow($2); }
1174 : "try" Block_ CatchOpt FinallyOpt { $$ = new(driver.pool_) CYTry($2, $3, $4); }
1178 : "catch" "(" Identifier ")" Block_ { $$ = new(driver.pool_) CYCatch($3, $5); }
1183 : "finally" Block_ { $$ = $2; }
1188 : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunction($2, $4, $7); }
1192 : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYLambda($2, $4, $7); }
1195 FormalParameterList_
1196 : "," FormalParameterList { $$ = $2; }
1201 : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYFunctionParameter($1, $2); }
1206 : SourceElements { $$ = $1; }
1210 : SourceElements { driver.source_ = $1; }
1214 : SourceElement SourceElements { $1->SetNext($2); $$ = $1; }
1219 : Statement { $$ = $1; }
1220 | FunctionDeclaration { $$ = $1; }
1223 /* Cycript: @class Declaration {{{ */
1225 : ":" MemberExpressionNoBF { $$ = $2; }
1230 : "{" "}" { $$ = NULL; }
1234 : "+" { $$ = false; }
1235 | "-" { $$ = true; }
1239 : "(" Expression ")" { $$ = $2; }
1244 : Word ":" TypeOpt Identifier { $$ = new(driver.pool_) CYMessageParameter($1, $3, $4); }
1247 MessageParameterListOpt
1248 : MessageParameterList { $$ = $1; }
1252 MessageParameterList
1253 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1257 : MessageParameterList { $$ = $1; }
1258 | Word { $$ = new(driver.pool_) CYMessageParameter($1, NULL, NULL); }
1261 ClassMessageDeclaration
1262 : MessageScope TypeOpt MessageParameters "{" FunctionBody "}" { $$ = new(driver.pool_) CYMessage($1, $2, $3, $5); }
1265 ClassMessageDeclarationListOpt
1266 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1271 : Identifier { $$ = $1; }
1272 | "(" AssignmentExpression ")" { $$ = $2; }
1276 : ClassName { $$ = $1; }
1281 : "@class" ClassNameOpt ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClass($2, $3, $4, $5); }
1285 : "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); }
1289 : ClassDefinition { $$ = $1; }
1293 : ClassDefinition { $$ = $1; }
1294 | CategoryStatement { $$ = $1; }
1297 /* Cycript: Send Message {{{ */
1299 : "," AssignmentExpression VariadicCall { $$ = new(driver.pool_) CYArgument(NULL, $2, $3); }
1304 : SelectorCall { $$ = $1; }
1305 | VariadicCall { $$ = $1; }
1309 : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new(driver.pool_) CYArgument($1 ?: new(driver.pool_) CYBlank(), $3, $4); }
1313 : SelectorCall { $$ = $1; }
1314 | Word { $$ = new(driver.pool_) CYArgument($1, NULL); }
1318 : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSend($2, $3); }
1321 SelectorExpressionOpt
1322 : SelectorExpression_ { $$ = $1; }
1327 : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelectorPart($1, true, $3); }
1331 : SelectorExpression_ { $$ = $1; }
1332 | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); }
1336 : MessageExpression { $$ = $1; }
1337 | "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); }
1340 /* Cycript: Pointer Indirection/Addressing {{{ */
1342 : "*" UnaryExpression { $$ = new(driver.pool_) CYIndirect($2); }
1346 : "&" UnaryExpression { $$ = new(driver.pool_) CYAddressOf($2); }
1350 : "->" Identifier { $$ = new(driver.pool_) CYIndirectMember(NULL, new(driver.pool_) CYString($2)); }
1353 /* ECMAScript5: Object Literal Trailing Comma {{{ */
1354 PropertyNameAndValueList_
1355 : "," { $$ = NULL; }
1358 /* JavaScript 1.7: Array Comprehensions {{{ */
1360 : "if" "(" Expression ")" { $$ = new(driver.pool_) CYIfComprehension($3); }
1364 : "for" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForInComprehension($3, $5); }
1365 | "for" "each" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForEachInComprehension($4, $6); }
1368 ComprehensionListOpt
1369 : ComprehensionList { $$ = $1; }
1370 | IfComprehension { $$ = $1; }
1375 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
1379 : "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); }
1382 /* JavaScript 1.7: for each {{{ */
1384 : "for" "each" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForEachIn($4, $6, $8); }
1387 /* JavaScript 1.7: Let Statements {{{ */
1389 : "let" "(" VariableDeclarationList ")" Block_ { $$ = new(driver.pool_) CYLet($3, $5); }