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