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