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