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