]> git.saurik.com Git - cycript.git/blob - Cycript.y
9a3480de4cd6ea2e62587f4cff734174f76081ad
[cycript.git] / Cycript.y
1 /* Cycript - Remove Execution Server and Disassembler
2 * Copyright (C) 2009 Jay Freeman (saurik)
3 */
4
5 /* Modified BSD License {{{ */
6 /*
7 * Redistribution and use in source and binary
8 * forms, with or without modification, are permitted
9 * provided that the following conditions are met:
10 *
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
18 * distribution.
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.
22 *
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.
37 */
38 /* }}} */
39
40 %code top {
41 #include "Cycript.tab.hh"
42 #define scanner driver.scanner_
43 #define YYSTACKEXPANDABLE 1
44 }
45
46 %code requires {
47 #include "Parser.hpp"
48
49 typedef struct {
50 bool newline_;
51
52 union {
53 bool bool_;
54
55 CYArgument *argument_;
56 CYBoolean *boolean_;
57 CYClause *clause_;
58 CYCatch *catch_;
59 CYClassName *className_;
60 CYCompound *compound_;
61 CYDeclaration *declaration_;
62 CYDeclarations *declarations_;
63 CYElement *element_;
64 CYExpression *expression_;
65 CYFalse *false_;
66 CYField *field_;
67 CYForInitialiser *for_;
68 CYForInInitialiser *forin_;
69 CYFunctionParameter *functionParameter_;
70 CYIdentifier *identifier_;
71 CYLiteral *literal_;
72 CYMessage *message_;
73 CYMessageParameter *messageParameter_;
74 CYNull *null_;
75 CYNumber *number_;
76 CYProperty *property_;
77 CYPropertyName *propertyName_;
78 CYSelectorPart *selector_;
79 CYSource *source_;
80 CYStatement *statement_;
81 CYString *string_;
82 CYThis *this_;
83 CYTrue *true_;
84 CYWord *word_;
85 };
86 } YYSTYPE;
87
88 }
89
90 %code provides {
91 int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
92 }
93
94 %name-prefix "cy"
95
96 %language "C++"
97 %locations
98
99 %initial-action {
100 @$.begin.filename = @$.end.filename = &driver.filename_;
101 };
102
103 %defines
104
105 %debug
106 %error-verbose
107
108 %parse-param { CYDriver &driver }
109 %lex-param { void *scanner }
110
111 %token Ampersand "&"
112 %token AmpersandAmpersand "&&"
113 %token AmpersandEqual "&="
114 %token Carrot "^"
115 %token CarrotEqual "^="
116 %token Equal "="
117 %token EqualEqual "=="
118 %token EqualEqualEqual "==="
119 %token Exclamation "!"
120 %token ExclamationEqual "!="
121 %token ExclamationEqualEqual "!=="
122 %token Hyphen "-"
123 %token HyphenEqual "-="
124 %token HyphenHyphen "--"
125 %token HyphenHyphen_ "\n--"
126 %token HyphenRight "->"
127 %token Left "<"
128 %token LeftEqual "<="
129 %token LeftLeft "<<"
130 %token LeftLeftEqual "<<="
131 %token Percent "%"
132 %token PercentEqual "%="
133 %token Period "."
134 %token Pipe "|"
135 %token PipeEqual "|="
136 %token PipePipe "||"
137 %token Plus "+"
138 %token PlusEqual "+="
139 %token PlusPlus "++"
140 %token PlusPlus_ "\n++"
141 %token Right ">"
142 %token RightEqual ">="
143 %token RightRight ">>"
144 %token RightRightEqual ">>="
145 %token RightRightRight ">>>"
146 %token RightRightRightEqual ">>>="
147 %token Slash "/"
148 %token SlashEqual "/="
149 %token Star "*"
150 %token StarEqual "*="
151 %token Tilde "~"
152
153 %token Colon ":"
154 %token Comma ","
155 %token Question "?"
156 %token SemiColon ";"
157 %token NewLine "\n"
158
159 %token OpenParen "("
160 %token CloseParen ")"
161
162 %token OpenBrace "{"
163 %token CloseBrace "}"
164
165 %token OpenBracket "["
166 %token CloseBracket "]"
167
168 %token AtClass "@class"
169 %token AtSelector "@selector"
170 %token AtEnd "@end"
171
172 %token <word_> Break "break"
173 %token <word_> Case "case"
174 %token <word_> Catch "catch"
175 %token <word_> Continue "continue"
176 %token <word_> Default "default"
177 %token <word_> Delete "delete"
178 %token <word_> Do "do"
179 %token <word_> Else "else"
180 %token <false_> False "false"
181 %token <word_> Finally "finally"
182 %token <word_> For "for"
183 %token <word_> Function "function"
184 %token <word_> If "if"
185 %token <word_> In "in"
186 %token <word_> InstanceOf "instanceof"
187 %token <word_> New "new"
188 %token <null_> Null "null"
189 %token <word_> Return "return"
190 %token <word_> Switch "switch"
191 %token <this_> This "this"
192 %token <word_> Throw "throw"
193 %token <true_> True "true"
194 %token <word_> Try "try"
195 %token <word_> TypeOf "typeof"
196 %token <word_> Var "var"
197 %token <word_> Void "void"
198 %token <word_> While "while"
199 %token <word_> With "with"
200
201 %token <word_> Abstract "abstract"
202 %token <word_> Boolean "boolean"
203 %token <word_> Byte "byte"
204 %token <word_> Char "char"
205 %token <word_> Class "class"
206 %token <word_> Const "const"
207 %token <word_> Debugger "debugger"
208 %token <word_> Double "double"
209 %token <word_> Enum "enum"
210 %token <word_> Export "export"
211 %token <word_> Extends "extends"
212 %token <word_> Final "final"
213 %token <word_> Float "float"
214 %token <word_> Goto "goto"
215 %token <word_> Implements "implements"
216 %token <word_> Import "import"
217 %token <word_> Int "int"
218 %token <word_> Interface "interface"
219 %token <word_> Long "long"
220 %token <word_> Native "native"
221 %token <word_> Package "package"
222 %token <word_> Private "private"
223 %token <word_> Protected "protected"
224 %token <word_> Public "public"
225 %token <word_> Short "short"
226 %token <word_> Static "static"
227 %token <word_> Super "super"
228 %token <word_> Synchronized "synchronized"
229 %token <word_> Throws "throws"
230 %token <word_> Transient "transient"
231 %token <word_> Volatile "volatile"
232
233 %token <identifier_> Identifier
234 %token <number_> NumericLiteral
235 %token <string_> StringLiteral
236
237 %type <expression_> AdditiveExpression
238 %type <expression_> AdditiveExpressionNoBF
239 %type <argument_> ArgumentList
240 %type <argument_> ArgumentList_
241 %type <argument_> ArgumentListOpt
242 %type <argument_> Arguments
243 %type <literal_> ArrayLiteral
244 %type <expression_> AssignmentExpression
245 %type <expression_> AssignmentExpressionNoBF
246 %type <expression_> AssignmentExpressionNoIn
247 %type <expression_> BitwiseANDExpression
248 %type <expression_> BitwiseANDExpressionNoBF
249 %type <expression_> BitwiseANDExpressionNoIn
250 %type <statement_> Block
251 %type <boolean_> BooleanLiteral
252 %type <expression_> BitwiseORExpression
253 %type <expression_> BitwiseORExpressionNoBF
254 %type <expression_> BitwiseORExpressionNoIn
255 %type <expression_> BitwiseXORExpression
256 %type <expression_> BitwiseXORExpressionNoBF
257 %type <expression_> BitwiseXORExpressionNoIn
258 %type <statement_> BreakStatement
259 %type <expression_> CallExpression
260 %type <expression_> CallExpressionNoBF
261 %type <clause_> CaseBlock
262 %type <clause_> CaseClause
263 %type <clause_> CaseClausesOpt
264 %type <catch_> CatchOpt
265 %type <source_> ClassDeclaration
266 %type <message_> ClassMessageDeclaration
267 %type <message_> ClassMessageDeclarationListOpt
268 %type <className_> ClassName
269 %type <expression_> ClassSuperOpt
270 %type <field_> ClassFieldList
271 %type <expression_> ConditionalExpression
272 %type <expression_> ConditionalExpressionNoBF
273 %type <expression_> ConditionalExpressionNoIn
274 %type <statement_> ContinueStatement
275 %type <clause_> DefaultClause
276 %type <statement_> DoWhileStatement
277 %type <expression_> Element
278 %type <expression_> ElementOpt
279 %type <element_> ElementList
280 %type <element_> ElementListOpt
281 %type <statement_> ElseStatementOpt
282 %type <statement_> EmptyStatement
283 %type <expression_> EqualityExpression
284 %type <expression_> EqualityExpressionNoBF
285 %type <expression_> EqualityExpressionNoIn
286 %type <expression_> Expression
287 %type <expression_> ExpressionOpt
288 %type <compound_> Expression_
289 %type <expression_> ExpressionNoBF
290 %type <expression_> ExpressionNoIn
291 %type <compound_> ExpressionNoIn_
292 %type <expression_> ExpressionNoInOpt
293 %type <statement_> ExpressionStatement
294 %type <statement_> FinallyOpt
295 %type <statement_> ForStatement
296 %type <for_> ForStatementInitialiser
297 %type <statement_> ForInStatement
298 %type <forin_> ForInStatementInitialiser
299 %type <functionParameter_> FormalParameterList
300 %type <functionParameter_> FormalParameterList_
301 %type <source_> FunctionBody
302 %type <source_> FunctionDeclaration
303 %type <expression_> FunctionExpression
304 %type <identifier_> IdentifierOpt
305 %type <statement_> IfStatement
306 %type <expression_> Initialiser
307 %type <expression_> InitialiserOpt
308 %type <expression_> InitialiserNoIn
309 %type <expression_> InitialiserNoInOpt
310 %type <statement_> IterationStatement
311 %type <statement_> LabelledStatement
312 %type <expression_> LeftHandSideExpression
313 %type <expression_> LeftHandSideExpression_
314 %type <expression_> LeftHandSideExpressionNoBF
315 %type <literal_> Literal
316 %type <expression_> LogicalANDExpression
317 %type <expression_> LogicalANDExpressionNoBF
318 %type <expression_> LogicalANDExpressionNoIn
319 %type <expression_> LogicalORExpression
320 %type <expression_> LogicalORExpressionNoBF
321 %type <expression_> LogicalORExpressionNoIn
322 %type <expression_> MemberExpression
323 %type <expression_> MemberExpression_
324 %type <expression_> MemberExpressionNoBF
325 %type <messageParameter_> MessageParameter
326 %type <messageParameter_> MessageParameters
327 %type <messageParameter_> MessageParameterList
328 %type <messageParameter_> MessageParameterListOpt
329 %type <bool_> MessageScope
330 %type <expression_> MultiplicativeExpression
331 %type <expression_> MultiplicativeExpressionNoBF
332 %type <expression_> NewExpression
333 %type <expression_> NewExpression_
334 %type <expression_> NewExpressionNoBF
335 %type <null_> NullLiteral
336 %type <literal_> ObjectLiteral
337 %type <expression_> PostfixExpression
338 %type <expression_> PostfixExpressionNoBF
339 %type <expression_> PrimaryExpression
340 %type <expression_> PrimaryExpression_
341 %type <expression_> PrimaryExpressionNoBF
342 %type <source_> Program
343 %type <propertyName_> PropertyName
344 %type <property_> PropertyNameAndValueList
345 %type <property_> PropertyNameAndValueList_
346 %type <property_> PropertyNameAndValueListOpt
347 %type <expression_> RelationalExpression
348 %type <expression_> RelationalExpressionNoBF
349 %type <expression_> RelationalExpressionNoIn
350 %type <statement_> ReturnStatement
351 %type <selector_> SelectorExpression
352 %type <selector_> SelectorExpression_
353 %type <selector_> SelectorExpressionOpt
354 %type <expression_> ShiftExpression
355 %type <expression_> ShiftExpressionNoBF
356 %type <source_> SourceElement
357 %type <source_> SourceElements
358 %type <statement_> Statement
359 %type <statement_> StatementList
360 %type <statement_> StatementListOpt
361 %type <statement_> SwitchStatement
362 %type <statement_> ThrowStatement
363 %type <statement_> TryStatement
364 %type <expression_> TypeOpt
365 %type <expression_> UnaryExpression
366 %type <expression_> UnaryExpression_
367 %type <expression_> UnaryExpressionNoBF
368 %type <declaration_> VariableDeclaration
369 %type <declaration_> VariableDeclarationNoIn
370 %type <declarations_> VariableDeclarationList
371 %type <declarations_> VariableDeclarationList_
372 %type <declarations_> VariableDeclarationListNoIn
373 %type <declarations_> VariableDeclarationListNoIn_
374 %type <statement_> VariableStatement
375 %type <statement_> WhileStatement
376 %type <statement_> WithStatement
377 %type <word_> Word
378 %type <word_> WordOpt
379
380 %type <expression_> MessageExpression
381 %type <argument_> SelectorCall
382 %type <argument_> SelectorCall_
383 %type <argument_> SelectorList
384 %type <argument_> VariadicCall
385
386 %left "*" "/" "%"
387 %left "+" "-"
388 %left "<<" ">>" ">>>"
389 %left "<" ">" "<=" ">=" "instanceof" "in"
390 %left "==" "!=" "===" "!=="
391 %left "&"
392 %left "^"
393 %left "|"
394 %left "&&"
395 %left "||"
396
397 %right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|="
398
399 %nonassoc "if"
400 %nonassoc "else"
401
402 %start Program
403
404 %%
405
406 TerminatorOpt
407 : ";"
408 | "\n"
409 | error { yyerrok; driver.errors_.pop_back(); }
410 ;
411
412 Terminator
413 : ";"
414 | "\n"
415 | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } }
416 ;
417
418 CommaOpt
419 : ","
420 |
421 ;
422
423 NewLineOpt
424 : "\n"
425 |
426 ;
427
428 WordOpt
429 : Word { $$ = $1; }
430 | { $$ = NULL; }
431 ;
432
433 Word
434 : Identifier { $$ = $1; }
435 | "abstract" { $$ = $1; }
436 | "boolean" { $$ = $1; }
437 | "break" NewLineOpt { $$ = $1; }
438 | "byte" { $$ = $1; }
439 | "case" { $$ = $1; }
440 | "catch" { $$ = $1; }
441 | "char" { $$ = $1; }
442 | "class" { $$ = $1; }
443 | "const" { $$ = $1; }
444 | "continue" NewLineOpt { $$ = $1; }
445 | "debugger" { $$ = $1; }
446 | "default" { $$ = $1; }
447 | "delete" { $$ = $1; }
448 | "do" { $$ = $1; }
449 | "double" { $$ = $1; }
450 | "else" { $$ = $1; }
451 | "enum" { $$ = $1; }
452 | "export" { $$ = $1; }
453 | "extends" { $$ = $1; }
454 | "false" { $$ = $1; }
455 | "final" { $$ = $1; }
456 | "finally" { $$ = $1; }
457 | "float" { $$ = $1; }
458 | "for" { $$ = $1; }
459 | "function" { $$ = $1; }
460 | "goto" { $$ = $1; }
461 | "if" { $$ = $1; }
462 | "implements" { $$ = $1; }
463 | "import" { $$ = $1; }
464 /* XXX: | "in" { $$ = $1; } */
465 /* XXX: | "instanceof" { $$ = $1; } */
466 | "int" { $$ = $1; }
467 | "interface" { $$ = $1; }
468 | "long" { $$ = $1; }
469 | "native" { $$ = $1; }
470 | "new" { $$ = $1; }
471 | "null" { $$ = $1; }
472 | "package" { $$ = $1; }
473 | "private" { $$ = $1; }
474 | "protected" { $$ = $1; }
475 | "public" { $$ = $1; }
476 | "return" NewLineOpt { $$ = $1; }
477 | "short" { $$ = $1; }
478 | "static" { $$ = $1; }
479 | "super" { $$ = $1; }
480 | "switch" { $$ = $1; }
481 | "synchronized" { $$ = $1; }
482 | "this" { $$ = $1; }
483 | "throw" NewLineOpt { $$ = $1; }
484 | "throws" { $$ = $1; }
485 | "transient" { $$ = $1; }
486 | "true" { $$ = $1; }
487 | "try" { $$ = $1; }
488 | "typeof" { $$ = $1; }
489 | "var" { $$ = $1; }
490 | "void" { $$ = $1; }
491 | "volatile" { $$ = $1; }
492 | "while" { $$ = $1; }
493 | "with" { $$ = $1; }
494 ;
495
496 IdentifierOpt
497 : Identifier { $$ = $1; }
498 | { $$ = NULL; }
499 ;
500
501 Literal
502 : NullLiteral { $$ = $1; }
503 | BooleanLiteral { $$ = $1; }
504 | NumericLiteral { $$ = $1; }
505 | StringLiteral { $$ = $1; }
506 ;
507
508 NullLiteral
509 : "null" { $$ = $1; }
510 ;
511
512 BooleanLiteral
513 : "true" { $$ = $1; }
514 | "false" { $$ = $1; }
515 ;
516
517 /* 11.1 Primary Expressions {{{ */
518 PrimaryExpression_
519 : "this" { $$ = $1; }
520 | Identifier { $$ = new(driver.pool_) CYVariable($1); }
521 | Literal { $$ = $1; }
522 | ArrayLiteral { $$ = $1; }
523 | "(" Expression ")" { $$ = $2; }
524 ;
525
526 PrimaryExpression
527 : ObjectLiteral { $$ = $1; }
528 | PrimaryExpression_ { $$ = $1; }
529 ;
530
531 PrimaryExpressionNoBF
532 : PrimaryExpression_ { $$ = $1; }
533 ;
534 /* }}} */
535 /* 11.1.4 Array Initialiser {{{ */
536 ArrayLiteral
537 : "[" ElementListOpt "]" { $$ = new(driver.pool_) CYArray($2); }
538 ;
539
540 Element
541 : AssignmentExpression { $$ = $1; }
542 ;
543
544 ElementOpt
545 : Element { $$ = $1; }
546 | { $$ = NULL; }
547 ;
548
549 ElementListOpt
550 : ElementList { $$ = $1; }
551 | { $$ = NULL; }
552 ;
553
554 ElementList
555 : ElementOpt "," ElementListOpt { $$ = new(driver.pool_) CYElement($1, $3); }
556 | Element { $$ = new(driver.pool_) CYElement($1, NULL); }
557 ;
558 /* }}} */
559 /* 11.1.5 Object Initialiser {{{ */
560 ObjectLiteral
561 : "{" PropertyNameAndValueListOpt "}" { $$ = new(driver.pool_) CYObject($2); }
562 ;
563
564 PropertyNameAndValueList_
565 : "," PropertyNameAndValueList { $$ = $2; }
566 | CommaOpt { $$ = NULL; }
567 ;
568
569 PropertyNameAndValueListOpt
570 : PropertyNameAndValueList { $$ = $1; }
571 | { $$ = NULL; }
572 ;
573
574 PropertyNameAndValueList
575 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); }
576 ;
577
578 PropertyName
579 : Identifier { $$ = $1; }
580 | StringLiteral { $$ = $1; }
581 | NumericLiteral { $$ = $1; }
582 ;
583 /* }}} */
584
585 MemberExpression_
586 : "new" MemberExpression Arguments { $$ = new(driver.pool_) CYNew($2, $3); }
587 ;
588
589 MemberExpression
590 : PrimaryExpression { $$ = $1; }
591 | FunctionExpression { $$ = $1; }
592 | MemberExpression "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
593 | MemberExpression "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
594 | MemberExpression_ { $$ = $1; }
595 ;
596
597 MemberExpressionNoBF
598 : PrimaryExpressionNoBF { $$ = $1; }
599 | MemberExpressionNoBF "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
600 | MemberExpressionNoBF "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
601 | MemberExpression_ { $$ = $1; }
602 ;
603
604 NewExpression_
605 : "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); }
606 ;
607
608 NewExpression
609 : MemberExpression { $$ = $1; }
610 | NewExpression_ { $$ = $1; }
611 ;
612
613 NewExpressionNoBF
614 : MemberExpressionNoBF { $$ = $1; }
615 | NewExpression_ { $$ = $1; }
616 ;
617
618 CallExpression
619 : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
620 | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
621 | CallExpression "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
622 | CallExpression "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
623 ;
624
625 CallExpressionNoBF
626 : MemberExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
627 | CallExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
628 | CallExpressionNoBF "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
629 | CallExpressionNoBF "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
630 ;
631
632 ArgumentList_
633 : "," ArgumentList { $$ = $2; }
634 | { $$ = NULL; }
635 ;
636
637 ArgumentListOpt
638 : ArgumentList { $$ = $1; }
639 | { $$ = NULL; }
640 ;
641
642 ArgumentList
643 : AssignmentExpression ArgumentList_ { $$ = new(driver.pool_) CYArgument(NULL, $1, $2); }
644 ;
645
646 Arguments
647 : "(" ArgumentListOpt ")" { $$ = $2; }
648 ;
649
650 LeftHandSideExpression
651 : NewExpression { $$ = $1; }
652 | CallExpression { $$ = $1; }
653 | LeftHandSideExpression_ { $$ = $1; }
654 ;
655
656 LeftHandSideExpressionNoBF
657 : NewExpressionNoBF { $$ = $1; }
658 | CallExpressionNoBF { $$ = $1; }
659 | LeftHandSideExpression_ { $$ = $1; }
660 ;
661
662 PostfixExpression
663 : LeftHandSideExpression { $$ = $1; }
664 | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
665 | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
666 ;
667
668 PostfixExpressionNoBF
669 : LeftHandSideExpressionNoBF { $$ = $1; }
670 | LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
671 | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
672 ;
673
674 UnaryExpression_
675 : "delete" UnaryExpression { $$ = new(driver.pool_) CYDelete($2); }
676 | "void" UnaryExpression { $$ = new(driver.pool_) CYVoid($2); }
677 | "typeof" UnaryExpression { $$ = new(driver.pool_) CYTypeOf($2); }
678 | "++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
679 | "\n++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
680 | "--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
681 | "\n--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
682 | "+" UnaryExpression { $$ = $2; }
683 | "-" UnaryExpression { $$ = new(driver.pool_) CYNegate($2); }
684 | "~" UnaryExpression { $$ = new(driver.pool_) CYBitwiseNot($2); }
685 | "!" UnaryExpression { $$ = new(driver.pool_) CYLogicalNot($2); }
686 ;
687
688 UnaryExpression
689 : PostfixExpression { $$ = $1; }
690 | UnaryExpression_ { $$ = $1; }
691 ;
692
693 UnaryExpressionNoBF
694 : PostfixExpressionNoBF { $$ = $1; }
695 | UnaryExpression_ { $$ = $1; }
696 ;
697
698 MultiplicativeExpression
699 : UnaryExpression { $$ = $1; }
700 | MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
701 | MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
702 | MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
703 ;
704
705 MultiplicativeExpressionNoBF
706 : UnaryExpressionNoBF { $$ = $1; }
707 | MultiplicativeExpressionNoBF "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
708 | MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
709 | MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
710 ;
711
712 AdditiveExpression
713 : MultiplicativeExpression { $$ = $1; }
714 | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
715 | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
716 ;
717
718 AdditiveExpressionNoBF
719 : MultiplicativeExpressionNoBF { $$ = $1; }
720 | AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
721 | AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
722 ;
723
724 ShiftExpression
725 : AdditiveExpression { $$ = $1; }
726 | ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
727 | ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
728 | ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
729 ;
730
731 ShiftExpressionNoBF
732 : AdditiveExpressionNoBF { $$ = $1; }
733 | ShiftExpressionNoBF "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
734 | ShiftExpressionNoBF ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
735 | ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
736 ;
737
738 RelationalExpression
739 : ShiftExpression { $$ = $1; }
740 | RelationalExpression "<" ShiftExpression { $$ = new(driver.pool_) CYLess($1, $3); }
741 | RelationalExpression ">" ShiftExpression { $$ = new(driver.pool_) CYGreater($1, $3); }
742 | RelationalExpression "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual($1, $3); }
743 | RelationalExpression ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual($1, $3); }
744 | RelationalExpression "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf($1, $3); }
745 | RelationalExpression "in" ShiftExpression { $$ = new(driver.pool_) CYIn($1, $3); }
746 ;
747
748 RelationalExpressionNoIn
749 : ShiftExpression { $$ = $1; }
750 | RelationalExpressionNoIn "<" ShiftExpression { $$ = new(driver.pool_) CYLess($1, $3); }
751 | RelationalExpressionNoIn ">" ShiftExpression { $$ = new(driver.pool_) CYGreater($1, $3); }
752 | RelationalExpressionNoIn "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual($1, $3); }
753 | RelationalExpressionNoIn ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual($1, $3); }
754 | RelationalExpressionNoIn "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf($1, $3); }
755 ;
756
757 RelationalExpressionNoBF
758 : ShiftExpressionNoBF { $$ = $1; }
759 | RelationalExpressionNoBF "<" ShiftExpression { $$ = new(driver.pool_) CYLess($1, $3); }
760 | RelationalExpressionNoBF ">" ShiftExpression { $$ = new(driver.pool_) CYGreater($1, $3); }
761 | RelationalExpressionNoBF "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual($1, $3); }
762 | RelationalExpressionNoBF ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual($1, $3); }
763 | RelationalExpressionNoBF "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf($1, $3); }
764 | RelationalExpressionNoBF "in" ShiftExpression { $$ = new(driver.pool_) CYIn($1, $3); }
765 ;
766
767 EqualityExpression
768 : RelationalExpression { $$ = $1; }
769 | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
770 | EqualityExpression "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
771 | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
772 | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
773 ;
774
775 EqualityExpressionNoIn
776 : RelationalExpressionNoIn { $$ = $1; }
777 | EqualityExpressionNoIn "==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYEqual($1, $3); }
778 | EqualityExpressionNoIn "!=" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotEqual($1, $3); }
779 | EqualityExpressionNoIn "===" RelationalExpressionNoIn { $$ = new(driver.pool_) CYIdentical($1, $3); }
780 | EqualityExpressionNoIn "!==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
781 ;
782
783 EqualityExpressionNoBF
784 : RelationalExpressionNoBF { $$ = $1; }
785 | EqualityExpressionNoBF "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
786 | EqualityExpressionNoBF "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
787 | EqualityExpressionNoBF "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
788 | EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
789 ;
790
791 BitwiseANDExpression
792 : EqualityExpression { $$ = $1; }
793 | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
794 ;
795
796 BitwiseANDExpressionNoIn
797 : EqualityExpressionNoIn { $$ = $1; }
798 | BitwiseANDExpressionNoIn "&" EqualityExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
799 ;
800
801 BitwiseANDExpressionNoBF
802 : EqualityExpressionNoBF { $$ = $1; }
803 | BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
804 ;
805
806 BitwiseXORExpression
807 : BitwiseANDExpression { $$ = $1; }
808 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
809 ;
810
811 BitwiseXORExpressionNoIn
812 : BitwiseANDExpressionNoIn { $$ = $1; }
813 | BitwiseXORExpressionNoIn "^" BitwiseANDExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
814 ;
815
816 BitwiseXORExpressionNoBF
817 : BitwiseANDExpressionNoBF { $$ = $1; }
818 | BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
819 ;
820
821 BitwiseORExpression
822 : BitwiseXORExpression { $$ = $1; }
823 | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
824 ;
825
826 BitwiseORExpressionNoIn
827 : BitwiseXORExpressionNoIn { $$ = $1; }
828 | BitwiseORExpressionNoIn "|" BitwiseXORExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
829 ;
830
831 BitwiseORExpressionNoBF
832 : BitwiseXORExpressionNoBF { $$ = $1; }
833 | BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
834 ;
835
836 LogicalANDExpression
837 : BitwiseORExpression { $$ = $1; }
838 | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
839 ;
840
841 LogicalANDExpressionNoIn
842 : BitwiseORExpressionNoIn { $$ = $1; }
843 | LogicalANDExpressionNoIn "&&" BitwiseORExpressionNoIn { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
844 ;
845
846 LogicalANDExpressionNoBF
847 : BitwiseORExpressionNoBF { $$ = $1; }
848 | LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
849 ;
850
851 LogicalORExpression
852 : LogicalANDExpression { $$ = $1; }
853 | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
854 ;
855
856 LogicalORExpressionNoIn
857 : LogicalANDExpressionNoIn { $$ = $1; }
858 | LogicalORExpressionNoIn "||" LogicalANDExpressionNoIn { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
859 ;
860
861 LogicalORExpressionNoBF
862 : LogicalANDExpressionNoBF { $$ = $1; }
863 | LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
864 ;
865
866 ConditionalExpression
867 : LogicalORExpression { $$ = $1; }
868 | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
869 ;
870
871 ConditionalExpressionNoIn
872 : LogicalORExpressionNoIn { $$ = $1; }
873 | LogicalORExpressionNoIn "?" AssignmentExpression ":" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
874 ;
875
876 ConditionalExpressionNoBF
877 : LogicalORExpressionNoBF { $$ = $1; }
878 | LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
879 ;
880
881 AssignmentExpression
882 : ConditionalExpression { $$ = $1; }
883 | LeftHandSideExpression "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign($1, $3); }
884 | LeftHandSideExpression "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
885 | LeftHandSideExpression "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
886 | LeftHandSideExpression "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
887 | LeftHandSideExpression "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign($1, $3); }
888 | LeftHandSideExpression "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
889 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
890 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
891 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
892 | LeftHandSideExpression "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
893 | LeftHandSideExpression "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
894 | LeftHandSideExpression "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
895 ;
896
897 AssignmentExpressionNoIn
898 : ConditionalExpressionNoIn { $$ = $1; }
899 | LeftHandSideExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); }
900 | LeftHandSideExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
901 | LeftHandSideExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
902 | LeftHandSideExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
903 | LeftHandSideExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); }
904 | LeftHandSideExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
905 | LeftHandSideExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
906 | LeftHandSideExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
907 | LeftHandSideExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
908 | LeftHandSideExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
909 | LeftHandSideExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
910 | LeftHandSideExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
911 ;
912
913 AssignmentExpressionNoBF
914 : ConditionalExpressionNoBF { $$ = $1; }
915 | LeftHandSideExpressionNoBF "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign($1, $3); }
916 | LeftHandSideExpressionNoBF "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
917 | LeftHandSideExpressionNoBF "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
918 | LeftHandSideExpressionNoBF "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
919 | LeftHandSideExpressionNoBF "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign($1, $3); }
920 | LeftHandSideExpressionNoBF "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
921 | LeftHandSideExpressionNoBF "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
922 | LeftHandSideExpressionNoBF ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
923 | LeftHandSideExpressionNoBF ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
924 | LeftHandSideExpressionNoBF "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
925 | LeftHandSideExpressionNoBF "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
926 | LeftHandSideExpressionNoBF "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
927 ;
928
929 Expression_
930 : "," Expression { $$ = new(driver.pool_) CYCompound($2); }
931 | { $$ = NULL; }
932 ;
933
934 ExpressionNoIn_
935 : "," ExpressionNoIn { $$ = new(driver.pool_) CYCompound($2); }
936 | { $$ = NULL; }
937 ;
938
939 ExpressionOpt
940 : Expression { $$ = $1; }
941 | { $$ = NULL; }
942 ;
943
944 ExpressionNoInOpt
945 : ExpressionNoIn { $$ = $1; }
946 | { $$ = NULL; }
947 ;
948
949 Expression
950 : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
951 ;
952
953 ExpressionNoIn
954 : AssignmentExpressionNoIn ExpressionNoIn_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
955 ;
956
957 ExpressionNoBF
958 : AssignmentExpressionNoBF Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
959 ;
960
961 Statement
962 : Block { $$ = $1; }
963 | VariableStatement { $$ = $1; }
964 | EmptyStatement { $$ = $1; }
965 | ExpressionStatement { $$ = $1; }
966 | IfStatement { $$ = $1; }
967 | IterationStatement { $$ = $1; }
968 | ContinueStatement { $$ = $1; }
969 | BreakStatement { $$ = $1; }
970 | ReturnStatement { $$ = $1; }
971 | WithStatement { $$ = $1; }
972 | LabelledStatement { $$ = $1; }
973 | SwitchStatement { $$ = $1; }
974 | ThrowStatement { $$ = $1; }
975 | TryStatement { $$ = $1; }
976 ;
977
978 Block
979 : "{" StatementListOpt "}" { $$ = $2 ?: new(driver.pool_) CYEmpty(); }
980 ;
981
982 StatementList
983 : Statement StatementListOpt { $1->SetNext($2); $$ = $1; }
984 ;
985
986 StatementListOpt
987 : StatementList { $$ = $1; }
988 | { $$ = NULL; }
989 ;
990
991 VariableStatement
992 : "var" VariableDeclarationList Terminator { $$ = $2; }
993 ;
994
995 VariableDeclarationList_
996 : "," VariableDeclarationList { $$ = $2; }
997 | { $$ = NULL; }
998 ;
999
1000 VariableDeclarationListNoIn_
1001 : "," VariableDeclarationListNoIn { $$ = $2; }
1002 | { $$ = NULL; }
1003 ;
1004
1005 VariableDeclarationList
1006 : VariableDeclaration VariableDeclarationList_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1007 ;
1008
1009 VariableDeclarationListNoIn
1010 : VariableDeclarationNoIn VariableDeclarationListNoIn_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1011 ;
1012
1013 VariableDeclaration
1014 : Identifier InitialiserOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1015 ;
1016
1017 VariableDeclarationNoIn
1018 : Identifier InitialiserNoInOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1019 ;
1020
1021 InitialiserOpt
1022 : Initialiser { $$ = $1; }
1023 | { $$ = NULL; }
1024 ;
1025
1026 InitialiserNoInOpt
1027 : InitialiserNoIn { $$ = $1; }
1028 | { $$ = NULL; }
1029 ;
1030
1031 Initialiser
1032 : "=" AssignmentExpression { $$ = $2; }
1033 ;
1034
1035 InitialiserNoIn
1036 : "=" AssignmentExpressionNoIn { $$ = $2; }
1037 ;
1038
1039 EmptyStatement
1040 : ";" { $$ = new(driver.pool_) CYEmpty(); }
1041 ;
1042
1043 ExpressionStatement
1044 : ExpressionNoBF Terminator { $$ = new(driver.pool_) CYExpress($1); }
1045 ;
1046
1047 ElseStatementOpt
1048 : "else" Statement { $$ = $2; }
1049 | %prec "if" { $$ = NULL; }
1050 ;
1051
1052 IfStatement
1053 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new(driver.pool_) CYIf($3, $5, $6); }
1054 ;
1055
1056 IterationStatement
1057 : DoWhileStatement { $$ = $1; }
1058 | WhileStatement { $$ = $1; }
1059 | ForStatement { $$ = $1; }
1060 | ForInStatement { $$ = $1; }
1061 ;
1062
1063 DoWhileStatement
1064 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = new(driver.pool_) CYDoWhile($5, $2); }
1065 ;
1066
1067 WhileStatement
1068 : "while" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWhile($3, $5); }
1069 ;
1070
1071 ForStatement
1072 : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new(driver.pool_) CYFor($3, $5, $7, $9); }
1073 ;
1074
1075 ForStatementInitialiser
1076 : ExpressionNoInOpt { $$ = $1; }
1077 | "var" VariableDeclarationListNoIn { $$ = $2; }
1078 ;
1079
1080 ForInStatement
1081 : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForIn($3, $5, $7); }
1082 ;
1083
1084 ForInStatementInitialiser
1085 : LeftHandSideExpression { $$ = $1; }
1086 | "var" VariableDeclarationNoIn { $$ = $2; }
1087 ;
1088
1089 ContinueStatement
1090 : "continue" IdentifierOpt Terminator { $$ = new(driver.pool_) CYContinue($2); }
1091 ;
1092
1093 BreakStatement
1094 : "break" IdentifierOpt Terminator { $$ = new(driver.pool_) CYBreak($2); }
1095 ;
1096
1097 ReturnStatement
1098 : "return" ExpressionOpt Terminator { $$ = new(driver.pool_) CYReturn($2); }
1099 ;
1100
1101 WithStatement
1102 : "with" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWith($3, $5); }
1103 ;
1104
1105 SwitchStatement
1106 : "switch" "(" Expression ")" CaseBlock { $$ = new(driver.pool_) CYSwitch($3, $5); }
1107 ;
1108
1109 CaseBlock
1110 : "{" CaseClausesOpt "}" { $$ = $2; }
1111 ;
1112
1113 CaseClausesOpt
1114 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1115 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1116 | { $$ = NULL; }
1117 ;
1118
1119 CaseClause
1120 : "case" Expression ":" StatementListOpt { $$ = new(driver.pool_) CYClause($2, $4); }
1121 ;
1122
1123 DefaultClause
1124 : "default" ":" StatementListOpt { $$ = new(driver.pool_) CYClause(NULL, $3); }
1125 ;
1126
1127 LabelledStatement
1128 : Identifier ":" Statement { $3->AddLabel($1); $$ = $3; }
1129 ;
1130
1131 ThrowStatement
1132 : "throw" Expression Terminator { $$ = new(driver.pool_) CYThrow($2); }
1133 ;
1134
1135 TryStatement
1136 : "try" Block CatchOpt FinallyOpt { $$ = new(driver.pool_) CYTry($2, $3, $4); }
1137 ;
1138
1139 CatchOpt
1140 : "catch" "(" Identifier ")" Block { $$ = new(driver.pool_) CYCatch($3, $5); }
1141 | { $$ = NULL; }
1142 ;
1143
1144 FinallyOpt
1145 : "finally" Block { $$ = $2; }
1146 | { $$ = NULL; }
1147 ;
1148
1149 FunctionDeclaration
1150 : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunction($2, $4, $7); }
1151 ;
1152
1153 FunctionExpression
1154 : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYLambda($2, $4, $7); }
1155 ;
1156
1157 FormalParameterList_
1158 : "," FormalParameterList { $$ = $2; }
1159 | { $$ = NULL; }
1160 ;
1161
1162 FormalParameterList
1163 : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYFunctionParameter($1, $2); }
1164 | { $$ = NULL; }
1165 ;
1166
1167 FunctionBody
1168 : SourceElements { $$ = $1; }
1169 ;
1170
1171 Program
1172 : SourceElements { driver.source_ = $1; }
1173 ;
1174
1175 SourceElements
1176 : SourceElement SourceElements { $1->SetNext($2); $$ = $1; }
1177 | { $$ = NULL; }
1178 ;
1179
1180 SourceElement
1181 : Statement { $$ = $1; }
1182 | FunctionDeclaration { $$ = $1; }
1183 ;
1184
1185 /* Objective-C Extensions {{{ */
1186 ClassSuperOpt
1187 : ":" MemberExpressionNoBF { $$ = $2; }
1188 | { $$ = NULL; }
1189 ;
1190
1191 ClassFieldList
1192 : "{" "}" { $$ = NULL; }
1193 ;
1194
1195 MessageScope
1196 : "+" { $$ = false; }
1197 | "-" { $$ = true; }
1198 ;
1199
1200 TypeOpt
1201 : "(" Expression ")" { $$ = $2; }
1202 | { $$ = NULL; }
1203 ;
1204
1205 MessageParameter
1206 : Word ":" TypeOpt Identifier { $$ = new CYMessageParameter($1, $3, $4); }
1207 ;
1208
1209 MessageParameterListOpt
1210 : MessageParameterList { $$ = $1; }
1211 | { $$ = NULL; }
1212 ;
1213
1214 MessageParameterList
1215 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1216 ;
1217
1218 MessageParameters
1219 : MessageParameterList { $$ = $1; }
1220 | Word { $$ = new CYMessageParameter($1, NULL, NULL); }
1221 ;
1222
1223 ClassMessageDeclaration
1224 : MessageScope TypeOpt MessageParameters "{" FunctionBody "}" { $$ = new CYMessage($1, $2, $3, $5); }
1225 ;
1226
1227 ClassMessageDeclarationListOpt
1228 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
1229 | { $$ = NULL; }
1230 ;
1231
1232 ClassName
1233 : Identifier { $$ = $1; }
1234 | "(" AssignmentExpression ")" { $$ = $2; }
1235 ;
1236
1237 ClassDeclaration
1238 : "@class" Identifier ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new CYClass($2, $3, $4, $5); }
1239 | "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new CYCategory($2, $3); }
1240 ;
1241
1242 SourceElement
1243 : ClassDeclaration { $$ = $1; }
1244 ;
1245
1246 VariadicCall
1247 : "," AssignmentExpression VariadicCall { $$ = new(driver.pool_) CYArgument(NULL, $2, $3); }
1248 | { $$ = NULL; }
1249 ;
1250
1251 SelectorCall_
1252 : SelectorCall { $$ = $1; }
1253 | VariadicCall { $$ = $1; }
1254 ;
1255
1256 SelectorCall
1257 : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new(driver.pool_) CYArgument($1 ?: new(driver.pool_) CYBlank(), $3, $4); }
1258 ;
1259
1260 SelectorList
1261 : SelectorCall { $$ = $1; }
1262 | Word { $$ = new(driver.pool_) CYArgument($1, NULL); }
1263 ;
1264
1265 MessageExpression
1266 : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSend($2, $3); }
1267 ;
1268
1269 SelectorExpressionOpt
1270 : SelectorExpression_ { $$ = $1; }
1271 | { $$ = NULL; }
1272 ;
1273
1274 SelectorExpression_
1275 : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelectorPart($1, true, $3); }
1276 ;
1277
1278 SelectorExpression
1279 : SelectorExpression_ { $$ = $1; }
1280 | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); }
1281 ;
1282
1283 PrimaryExpression_
1284 : MessageExpression { $$ = $1; }
1285 | "@selector" "(" SelectorExpression ")" { $$ = new CYSelector($3); }
1286 ;
1287 /* }}} */
1288
1289 LeftHandSideExpression_
1290 : "*" LeftHandSideExpression { $$ = new(driver.pool_) CYIndirect($2); }
1291 ;
1292
1293 UnaryExpression_
1294 : "&" UnaryExpression { $$ = new(driver.pool_) CYAddressOf($2); }
1295 ;
1296
1297 %%