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