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