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