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