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