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