]> git.saurik.com Git - cycript.git/blame - Cycript.y
Added console commands.
[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
cde525f7
JF
329%left "*" "/" "%"
330%left "+" "-"
331%left "<<" ">>" ">>>"
332%left "<" ">" "<=" ">=" "instanceof" "in"
333%left "==" "!=" "===" "!=="
334%left "&"
335%left "^"
336%left "|"
337%left "&&"
338%left "||"
339
340%right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|="
341
c3c20102
JF
342%nonassoc "if"
343%nonassoc "else"
344
693d501b 345%start Program
e5332278 346
693d501b 347%%
c3c20102 348
c3c20102
JF
349TerminatorOpt
350 : ";"
693d501b 351 | "\n"
5befe15e 352 | error { yyerrok; driver.errors_.pop_back(); }
c3c20102
JF
353 ;
354
355Terminator
356 : ";"
693d501b 357 | "\n"
5befe15e 358 | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } }
c3c20102
JF
359 ;
360
693d501b
JF
361CommaOpt
362 : ","
363 |
364 ;
365
c3c20102 366NewLineOpt
693d501b 367 : "\n"
c3c20102
JF
368 |
369 ;
1dbba6cc 370
36cd3cb9 371WordOpt
cf7d4c69
JF
372 : Word { $$ = $1; }
373 | { $$ = NULL; }
2bf24581
JF
374 ;
375
36cd3cb9 376Word
cf7d4c69 377 : Identifier { $$ = $1; }
d35a3b07
JF
378 | "abstract" { $$ = $1; }
379 | "boolean" { $$ = $1; }
c3c20102 380 | "break" NewLineOpt { $$ = $1; }
d35a3b07 381 | "byte" { $$ = $1; }
cf7d4c69
JF
382 | "case" { $$ = $1; }
383 | "catch" { $$ = $1; }
d35a3b07
JF
384 | "char" { $$ = $1; }
385 | "class" { $$ = $1; }
386 | "const" { $$ = $1; }
c3c20102 387 | "continue" NewLineOpt { $$ = $1; }
d35a3b07 388 | "debugger" { $$ = $1; }
cf7d4c69
JF
389 | "default" { $$ = $1; }
390 | "delete" { $$ = $1; }
391 | "do" { $$ = $1; }
d35a3b07 392 | "double" { $$ = $1; }
cf7d4c69 393 | "else" { $$ = $1; }
d35a3b07
JF
394 | "enum" { $$ = $1; }
395 | "export" { $$ = $1; }
396 | "extends" { $$ = $1; }
cf7d4c69 397 | "false" { $$ = $1; }
d35a3b07 398 | "final" { $$ = $1; }
cf7d4c69 399 | "finally" { $$ = $1; }
d35a3b07 400 | "float" { $$ = $1; }
cf7d4c69
JF
401 | "for" { $$ = $1; }
402 | "function" { $$ = $1; }
d35a3b07 403 | "goto" { $$ = $1; }
cf7d4c69 404 | "if" { $$ = $1; }
d35a3b07
JF
405 | "implements" { $$ = $1; }
406 | "import" { $$ = $1; }
693d501b
JF
407 /* XXX: | "in" { $$ = $1; } */
408 /* XXX: | "instanceof" { $$ = $1; } */
d35a3b07
JF
409 | "int" { $$ = $1; }
410 | "interface" { $$ = $1; }
411 | "long" { $$ = $1; }
412 | "native" { $$ = $1; }
cf7d4c69
JF
413 | "new" { $$ = $1; }
414 | "null" { $$ = $1; }
d35a3b07
JF
415 | "package" { $$ = $1; }
416 | "private" { $$ = $1; }
417 | "protected" { $$ = $1; }
418 | "public" { $$ = $1; }
c3c20102 419 | "return" NewLineOpt { $$ = $1; }
d35a3b07
JF
420 | "short" { $$ = $1; }
421 | "static" { $$ = $1; }
422 | "super" { $$ = $1; }
cf7d4c69 423 | "switch" { $$ = $1; }
d35a3b07 424 | "synchronized" { $$ = $1; }
cf7d4c69 425 | "this" { $$ = $1; }
c3c20102 426 | "throw" NewLineOpt { $$ = $1; }
d35a3b07
JF
427 | "throws" { $$ = $1; }
428 | "transient" { $$ = $1; }
cf7d4c69
JF
429 | "true" { $$ = $1; }
430 | "try" { $$ = $1; }
431 | "typeof" { $$ = $1; }
432 | "var" { $$ = $1; }
433 | "void" { $$ = $1; }
d35a3b07 434 | "volatile" { $$ = $1; }
cf7d4c69
JF
435 | "while" { $$ = $1; }
436 | "with" { $$ = $1; }
2bf24581
JF
437 ;
438
36cd3cb9 439IdentifierOpt
cf7d4c69
JF
440 : Identifier { $$ = $1; }
441 | { $$ = NULL; }
1dbba6cc
JF
442 ;
443
36cd3cb9 444Literal
cf7d4c69
JF
445 : NullLiteral { $$ = $1; }
446 | BooleanLiteral { $$ = $1; }
447 | NumericLiteral { $$ = $1; }
448 | StringLiteral { $$ = $1; }
1dbba6cc
JF
449 ;
450
36cd3cb9 451NullLiteral
cf7d4c69 452 : "null" { $$ = $1; }
1dbba6cc
JF
453 ;
454
36cd3cb9 455BooleanLiteral
cf7d4c69
JF
456 : "true" { $$ = $1; }
457 | "false" { $$ = $1; }
1dbba6cc
JF
458 ;
459
1dbba6cc 460/* 11.1 Primary Expressions {{{ */
693d501b 461PrimaryExpression_
cf7d4c69 462 : "this" { $$ = $1; }
b1ff2d78 463 | Identifier { $$ = new(driver.pool_) CYVariable($1); }
cf7d4c69
JF
464 | Literal { $$ = $1; }
465 | ArrayLiteral { $$ = $1; }
36cd3cb9 466 | "(" Expression ")" { $$ = $2; }
693d501b
JF
467 ;
468
469PrimaryExpression
470 : ObjectLiteral { $$ = $1; }
471 | PrimaryExpression_ { $$ = $1; }
472 ;
473
474PrimaryExpressionNoBF
475 : PrimaryExpression_ { $$ = $1; }
1dbba6cc
JF
476 ;
477/* }}} */
478/* 11.1.4 Array Initialiser {{{ */
36cd3cb9 479ArrayLiteral
d35a3b07 480 : "[" ElementListOpt "]" { $$ = new(driver.pool_) CYArray($2); }
1dbba6cc
JF
481 ;
482
36cd3cb9 483Element
cf7d4c69 484 : AssignmentExpression { $$ = $1; }
5befe15e
JF
485 ;
486
487ElementOpt
488 : Element { $$ = $1; }
cf7d4c69 489 | { $$ = NULL; }
1dbba6cc
JF
490 ;
491
5befe15e
JF
492ElementListOpt
493 : ElementList { $$ = $1; }
cf7d4c69 494 | { $$ = NULL; }
1dbba6cc
JF
495 ;
496
36cd3cb9 497ElementList
5befe15e
JF
498 : ElementOpt "," ElementListOpt { $$ = new(driver.pool_) CYElement($1, $3); }
499 | Element { $$ = new(driver.pool_) CYElement($1, NULL); }
1dbba6cc
JF
500 ;
501/* }}} */
502/* 11.1.5 Object Initialiser {{{ */
36cd3cb9 503ObjectLiteral
5befe15e 504 : "{" PropertyNameAndValueListOpt "}" { $$ = new(driver.pool_) CYObject($2); }
1dbba6cc
JF
505 ;
506
36cd3cb9 507PropertyNameAndValueList_
cf7d4c69 508 : "," PropertyNameAndValueList { $$ = $2; }
693d501b 509 | CommaOpt { $$ = NULL; }
1dbba6cc
JF
510 ;
511
36cd3cb9 512PropertyNameAndValueListOpt
cf7d4c69 513 : PropertyNameAndValueList { $$ = $1; }
36cd3cb9 514 | { $$ = NULL; }
1dbba6cc
JF
515 ;
516
36cd3cb9
JF
517PropertyNameAndValueList
518 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); }
1dbba6cc
JF
519 ;
520
521PropertyName
36cd3cb9
JF
522 : Identifier { $$ = $1; }
523 | StringLiteral { $$ = $1; }
524 | NumericLiteral { $$ = $1; }
1dbba6cc
JF
525 ;
526/* }}} */
527
693d501b
JF
528MemberExpression_
529 : "new" MemberExpression Arguments { $$ = new(driver.pool_) CYNew($2, $3); }
530 ;
531
36cd3cb9 532MemberExpression
cf7d4c69
JF
533 : PrimaryExpression { $$ = $1; }
534 | FunctionExpression { $$ = $1; }
36cd3cb9
JF
535 | MemberExpression "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
536 | MemberExpression "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
693d501b
JF
537 | MemberExpression_ { $$ = $1; }
538 ;
539
540MemberExpressionNoBF
541 : PrimaryExpressionNoBF { $$ = $1; }
542 | MemberExpressionNoBF "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
543 | MemberExpressionNoBF "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
544 | MemberExpression_ { $$ = $1; }
545 ;
546
547NewExpression_
548 : "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); }
1dbba6cc
JF
549 ;
550
36cd3cb9 551NewExpression
cf7d4c69 552 : MemberExpression { $$ = $1; }
693d501b
JF
553 | NewExpression_ { $$ = $1; }
554 ;
555
556NewExpressionNoBF
557 : MemberExpressionNoBF { $$ = $1; }
558 | NewExpression_ { $$ = $1; }
1dbba6cc
JF
559 ;
560
36cd3cb9 561CallExpression
b1ff2d78
JF
562 : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
563 | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
36cd3cb9
JF
564 | CallExpression "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
565 | CallExpression "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
1dbba6cc
JF
566 ;
567
693d501b
JF
568CallExpressionNoBF
569 : MemberExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
570 | CallExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
571 | CallExpressionNoBF "[" Expression "]" { $$ = new(driver.pool_) CYMember($1, $3); }
572 | CallExpressionNoBF "." Identifier { $$ = new(driver.pool_) CYMember($1, new(driver.pool_) CYString($3)); }
573 ;
574
36cd3cb9 575ArgumentList_
cf7d4c69
JF
576 : "," ArgumentList { $$ = $2; }
577 | { $$ = NULL; }
1dbba6cc
JF
578 ;
579
36cd3cb9 580ArgumentListOpt
cf7d4c69 581 : ArgumentList { $$ = $1; }
36cd3cb9 582 | { $$ = NULL; }
1dbba6cc
JF
583 ;
584
36cd3cb9
JF
585ArgumentList
586 : AssignmentExpression ArgumentList_ { $$ = new(driver.pool_) CYArgument(NULL, $1, $2); }
1dbba6cc
JF
587 ;
588
589Arguments
36cd3cb9 590 : "(" ArgumentListOpt ")" { $$ = $2; }
1dbba6cc
JF
591 ;
592
36cd3cb9 593LeftHandSideExpression
cf7d4c69
JF
594 : NewExpression { $$ = $1; }
595 | CallExpression { $$ = $1; }
693d501b
JF
596 | LeftHandSideExpression_ { $$ = $1; }
597 ;
598
599LeftHandSideExpressionNoBF
600 : NewExpressionNoBF { $$ = $1; }
601 | CallExpressionNoBF { $$ = $1; }
602 | LeftHandSideExpression_ { $$ = $1; }
1dbba6cc
JF
603 ;
604
36cd3cb9 605PostfixExpression
cf7d4c69 606 : LeftHandSideExpression { $$ = $1; }
b1ff2d78
JF
607 | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
608 | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
1dbba6cc
JF
609 ;
610
693d501b
JF
611PostfixExpressionNoBF
612 : LeftHandSideExpressionNoBF { $$ = $1; }
613 | LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
614 | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
615 ;
616
617UnaryExpression_
618 : "delete" UnaryExpression { $$ = new(driver.pool_) CYDelete($2); }
36cd3cb9
JF
619 | "void" UnaryExpression { $$ = new(driver.pool_) CYVoid($2); }
620 | "typeof" UnaryExpression { $$ = new(driver.pool_) CYTypeOf($2); }
621 | "++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
622 | "\n++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
623 | "--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
624 | "\n--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
625 | "+" UnaryExpression { $$ = $2; }
626 | "-" UnaryExpression { $$ = new(driver.pool_) CYNegate($2); }
627 | "~" UnaryExpression { $$ = new(driver.pool_) CYBitwiseNot($2); }
628 | "!" UnaryExpression { $$ = new(driver.pool_) CYLogicalNot($2); }
693d501b
JF
629 ;
630
631UnaryExpression
632 : PostfixExpression { $$ = $1; }
633 | UnaryExpression_ { $$ = $1; }
634 ;
635
636UnaryExpressionNoBF
637 : PostfixExpressionNoBF { $$ = $1; }
638 | UnaryExpression_ { $$ = $1; }
1dbba6cc
JF
639 ;
640
36cd3cb9 641MultiplicativeExpression
cf7d4c69 642 : UnaryExpression { $$ = $1; }
36cd3cb9
JF
643 | MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
644 | MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
645 | MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
1dbba6cc
JF
646 ;
647
693d501b
JF
648MultiplicativeExpressionNoBF
649 : UnaryExpressionNoBF { $$ = $1; }
650 | MultiplicativeExpressionNoBF "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
651 | MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
652 | MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
653 ;
654
36cd3cb9 655AdditiveExpression
cf7d4c69 656 : MultiplicativeExpression { $$ = $1; }
36cd3cb9
JF
657 | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
658 | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
1dbba6cc
JF
659 ;
660
693d501b
JF
661AdditiveExpressionNoBF
662 : MultiplicativeExpressionNoBF { $$ = $1; }
663 | AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
664 | AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
665 ;
666
36cd3cb9 667ShiftExpression
cf7d4c69 668 : AdditiveExpression { $$ = $1; }
36cd3cb9
JF
669 | ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
670 | ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
671 | ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
1dbba6cc
JF
672 ;
673
693d501b
JF
674ShiftExpressionNoBF
675 : AdditiveExpressionNoBF { $$ = $1; }
676 | ShiftExpressionNoBF "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
677 | ShiftExpressionNoBF ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
678 | ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
679 ;
680
36cd3cb9 681RelationalExpression
cf7d4c69 682 : ShiftExpression { $$ = $1; }
36cd3cb9
JF
683 | RelationalExpression "<" ShiftExpression { $$ = new(driver.pool_) CYLess($1, $3); }
684 | RelationalExpression ">" ShiftExpression { $$ = new(driver.pool_) CYGreater($1, $3); }
685 | RelationalExpression "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual($1, $3); }
686 | RelationalExpression ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual($1, $3); }
687 | RelationalExpression "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf($1, $3); }
688 | RelationalExpression "in" ShiftExpression { $$ = new(driver.pool_) CYIn($1, $3); }
1dbba6cc
JF
689 ;
690
693d501b
JF
691RelationalExpressionNoIn
692 : ShiftExpression { $$ = $1; }
693 | RelationalExpressionNoIn "<" ShiftExpression { $$ = new(driver.pool_) CYLess($1, $3); }
694 | RelationalExpressionNoIn ">" ShiftExpression { $$ = new(driver.pool_) CYGreater($1, $3); }
695 | RelationalExpressionNoIn "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual($1, $3); }
696 | RelationalExpressionNoIn ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual($1, $3); }
697 | RelationalExpressionNoIn "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf($1, $3); }
698 ;
699
700RelationalExpressionNoBF
701 : ShiftExpressionNoBF { $$ = $1; }
702 | RelationalExpressionNoBF "<" ShiftExpression { $$ = new(driver.pool_) CYLess($1, $3); }
703 | RelationalExpressionNoBF ">" ShiftExpression { $$ = new(driver.pool_) CYGreater($1, $3); }
704 | RelationalExpressionNoBF "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual($1, $3); }
705 | RelationalExpressionNoBF ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual($1, $3); }
706 | RelationalExpressionNoBF "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf($1, $3); }
707 | RelationalExpressionNoBF "in" ShiftExpression { $$ = new(driver.pool_) CYIn($1, $3); }
708 ;
709
36cd3cb9 710EqualityExpression
cf7d4c69 711 : RelationalExpression { $$ = $1; }
36cd3cb9
JF
712 | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
713 | EqualityExpression "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
714 | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
715 | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
1dbba6cc
JF
716 ;
717
693d501b
JF
718EqualityExpressionNoIn
719 : RelationalExpressionNoIn { $$ = $1; }
720 | EqualityExpressionNoIn "==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYEqual($1, $3); }
721 | EqualityExpressionNoIn "!=" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotEqual($1, $3); }
722 | EqualityExpressionNoIn "===" RelationalExpressionNoIn { $$ = new(driver.pool_) CYIdentical($1, $3); }
723 | EqualityExpressionNoIn "!==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
724 ;
725
726EqualityExpressionNoBF
727 : RelationalExpressionNoBF { $$ = $1; }
728 | EqualityExpressionNoBF "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
729 | EqualityExpressionNoBF "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
730 | EqualityExpressionNoBF "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
731 | EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
732 ;
733
36cd3cb9 734BitwiseANDExpression
cf7d4c69 735 : EqualityExpression { $$ = $1; }
36cd3cb9 736 | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
1dbba6cc
JF
737 ;
738
693d501b
JF
739BitwiseANDExpressionNoIn
740 : EqualityExpressionNoIn { $$ = $1; }
741 | BitwiseANDExpressionNoIn "&" EqualityExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
742 ;
743
744BitwiseANDExpressionNoBF
745 : EqualityExpressionNoBF { $$ = $1; }
746 | BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
747 ;
748
36cd3cb9 749BitwiseXORExpression
cf7d4c69 750 : BitwiseANDExpression { $$ = $1; }
36cd3cb9 751 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
1dbba6cc
JF
752 ;
753
693d501b
JF
754BitwiseXORExpressionNoIn
755 : BitwiseANDExpressionNoIn { $$ = $1; }
756 | BitwiseXORExpressionNoIn "^" BitwiseANDExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
757 ;
758
759BitwiseXORExpressionNoBF
760 : BitwiseANDExpressionNoBF { $$ = $1; }
761 | BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
762 ;
763
36cd3cb9 764BitwiseORExpression
cf7d4c69 765 : BitwiseXORExpression { $$ = $1; }
36cd3cb9 766 | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
1dbba6cc
JF
767 ;
768
693d501b
JF
769BitwiseORExpressionNoIn
770 : BitwiseXORExpressionNoIn { $$ = $1; }
771 | BitwiseORExpressionNoIn "|" BitwiseXORExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
772 ;
773
774BitwiseORExpressionNoBF
775 : BitwiseXORExpressionNoBF { $$ = $1; }
776 | BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
777 ;
778
36cd3cb9 779LogicalANDExpression
cf7d4c69 780 : BitwiseORExpression { $$ = $1; }
36cd3cb9 781 | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
1dbba6cc
JF
782 ;
783
693d501b
JF
784LogicalANDExpressionNoIn
785 : BitwiseORExpressionNoIn { $$ = $1; }
786 | LogicalANDExpressionNoIn "&&" BitwiseORExpressionNoIn { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
787 ;
788
789LogicalANDExpressionNoBF
790 : BitwiseORExpressionNoBF { $$ = $1; }
791 | LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
792 ;
793
36cd3cb9 794LogicalORExpression
cf7d4c69 795 : LogicalANDExpression { $$ = $1; }
36cd3cb9 796 | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
1dbba6cc
JF
797 ;
798
693d501b
JF
799LogicalORExpressionNoIn
800 : LogicalANDExpressionNoIn { $$ = $1; }
801 | LogicalORExpressionNoIn "||" LogicalANDExpressionNoIn { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
802 ;
803
804LogicalORExpressionNoBF
805 : LogicalANDExpressionNoBF { $$ = $1; }
806 | LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
807 ;
808
36cd3cb9 809ConditionalExpression
cf7d4c69 810 : LogicalORExpression { $$ = $1; }
36cd3cb9 811 | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
1dbba6cc
JF
812 ;
813
693d501b
JF
814ConditionalExpressionNoIn
815 : LogicalORExpressionNoIn { $$ = $1; }
816 | LogicalORExpressionNoIn "?" AssignmentExpression ":" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
817 ;
818
819ConditionalExpressionNoBF
820 : LogicalORExpressionNoBF { $$ = $1; }
821 | LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
822 ;
823
36cd3cb9 824AssignmentExpression
cf7d4c69 825 : ConditionalExpression { $$ = $1; }
36cd3cb9
JF
826 | LeftHandSideExpression "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign($1, $3); }
827 | LeftHandSideExpression "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
828 | LeftHandSideExpression "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
829 | LeftHandSideExpression "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
830 | LeftHandSideExpression "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign($1, $3); }
831 | LeftHandSideExpression "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
832 | LeftHandSideExpression "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
833 | LeftHandSideExpression ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
834 | LeftHandSideExpression ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
835 | LeftHandSideExpression "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
836 | LeftHandSideExpression "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
837 | LeftHandSideExpression "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
838 ;
839
693d501b
JF
840AssignmentExpressionNoIn
841 : ConditionalExpressionNoIn { $$ = $1; }
842 | LeftHandSideExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); }
843 | LeftHandSideExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
844 | LeftHandSideExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
845 | LeftHandSideExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
846 | LeftHandSideExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); }
847 | LeftHandSideExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
848 | LeftHandSideExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
849 | LeftHandSideExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
850 | LeftHandSideExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
851 | LeftHandSideExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
852 | LeftHandSideExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
853 | LeftHandSideExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
854 ;
855
856AssignmentExpressionNoBF
857 : ConditionalExpressionNoBF { $$ = $1; }
858 | LeftHandSideExpressionNoBF "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign($1, $3); }
859 | LeftHandSideExpressionNoBF "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
860 | LeftHandSideExpressionNoBF "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
861 | LeftHandSideExpressionNoBF "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
862 | LeftHandSideExpressionNoBF "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign($1, $3); }
863 | LeftHandSideExpressionNoBF "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
864 | LeftHandSideExpressionNoBF "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
865 | LeftHandSideExpressionNoBF ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
866 | LeftHandSideExpressionNoBF ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
867 | LeftHandSideExpressionNoBF "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
868 | LeftHandSideExpressionNoBF "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
869 | LeftHandSideExpressionNoBF "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
870 ;
871
36cd3cb9 872Expression_
d35a3b07 873 : "," Expression { $$ = new(driver.pool_) CYCompound($2); }
cf7d4c69 874 | { $$ = NULL; }
1dbba6cc
JF
875 ;
876
693d501b 877ExpressionNoIn_
d35a3b07 878 : "," ExpressionNoIn { $$ = new(driver.pool_) CYCompound($2); }
693d501b
JF
879 | { $$ = NULL; }
880 ;
881
36cd3cb9 882ExpressionOpt
cf7d4c69 883 : Expression { $$ = $1; }
36cd3cb9 884 | { $$ = NULL; }
1dbba6cc
JF
885 ;
886
693d501b
JF
887ExpressionNoInOpt
888 : ExpressionNoIn { $$ = $1; }
889 | { $$ = NULL; }
890 ;
891
36cd3cb9 892Expression
d35a3b07 893 : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1dbba6cc
JF
894 ;
895
693d501b 896ExpressionNoIn
d35a3b07 897 : AssignmentExpressionNoIn ExpressionNoIn_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
693d501b
JF
898 ;
899
900ExpressionNoBF
d35a3b07 901 : AssignmentExpressionNoBF Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
693d501b
JF
902 ;
903
36cd3cb9
JF
904Statement
905 : Block { $$ = $1; }
906 | VariableStatement { $$ = $1; }
907 | EmptyStatement { $$ = $1; }
908 | ExpressionStatement { $$ = $1; }
cf7d4c69
JF
909 | IfStatement { $$ = $1; }
910 | IterationStatement { $$ = $1; }
36cd3cb9
JF
911 | ContinueStatement { $$ = $1; }
912 | BreakStatement { $$ = $1; }
913 | ReturnStatement { $$ = $1; }
cf7d4c69
JF
914 | WithStatement { $$ = $1; }
915 | LabelledStatement { $$ = $1; }
36cd3cb9
JF
916 | SwitchStatement { $$ = $1; }
917 | ThrowStatement { $$ = $1; }
918 | TryStatement { $$ = $1; }
1dbba6cc
JF
919 ;
920
36cd3cb9 921Block
5befe15e 922 : "{" StatementListOpt "}" { $$ = $2 ?: new(driver.pool_) CYEmpty(); }
1dbba6cc
JF
923 ;
924
693d501b 925StatementList
cf7d4c69 926 : Statement StatementListOpt { $1->SetNext($2); $$ = $1; }
693d501b
JF
927 ;
928
929StatementListOpt
930 : StatementList { $$ = $1; }
cf7d4c69 931 | { $$ = NULL; }
1dbba6cc
JF
932 ;
933
36cd3cb9 934VariableStatement
c3c20102 935 : "var" VariableDeclarationList Terminator { $$ = $2; }
1dbba6cc
JF
936 ;
937
36cd3cb9 938VariableDeclarationList_
cf7d4c69
JF
939 : "," VariableDeclarationList { $$ = $2; }
940 | { $$ = NULL; }
1dbba6cc
JF
941 ;
942
693d501b
JF
943VariableDeclarationListNoIn_
944 : "," VariableDeclarationListNoIn { $$ = $2; }
945 | { $$ = NULL; }
946 ;
947
36cd3cb9 948VariableDeclarationList
b1ff2d78 949 : VariableDeclaration VariableDeclarationList_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1dbba6cc
JF
950 ;
951
693d501b
JF
952VariableDeclarationListNoIn
953 : VariableDeclarationNoIn VariableDeclarationListNoIn_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
954 ;
955
36cd3cb9
JF
956VariableDeclaration
957 : Identifier InitialiserOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1dbba6cc
JF
958 ;
959
693d501b
JF
960VariableDeclarationNoIn
961 : Identifier InitialiserNoInOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
962 ;
963
36cd3cb9 964InitialiserOpt
cf7d4c69 965 : Initialiser { $$ = $1; }
36cd3cb9 966 | { $$ = NULL; }
1dbba6cc
JF
967 ;
968
693d501b
JF
969InitialiserNoInOpt
970 : InitialiserNoIn { $$ = $1; }
971 | { $$ = NULL; }
972 ;
973
36cd3cb9
JF
974Initialiser
975 : "=" AssignmentExpression { $$ = $2; }
1dbba6cc
JF
976 ;
977
693d501b
JF
978InitialiserNoIn
979 : "=" AssignmentExpressionNoIn { $$ = $2; }
980 ;
981
36cd3cb9 982EmptyStatement
b1ff2d78 983 : ";" { $$ = new(driver.pool_) CYEmpty(); }
1dbba6cc
JF
984 ;
985
36cd3cb9 986ExpressionStatement
693d501b 987 : ExpressionNoBF Terminator { $$ = new(driver.pool_) CYExpress($1); }
1dbba6cc
JF
988 ;
989
36cd3cb9
JF
990ElseStatementOpt
991 : "else" Statement { $$ = $2; }
c3c20102 992 | %prec "if" { $$ = NULL; }
1dbba6cc
JF
993 ;
994
36cd3cb9
JF
995IfStatement
996 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new(driver.pool_) CYIf($3, $5, $6); }
1dbba6cc
JF
997 ;
998
36cd3cb9
JF
999IterationStatement
1000 : DoWhileStatement { $$ = $1; }
cf7d4c69
JF
1001 | WhileStatement { $$ = $1; }
1002 | ForStatement { $$ = $1; }
1003 | ForInStatement { $$ = $1; }
1dbba6cc
JF
1004 ;
1005
36cd3cb9
JF
1006DoWhileStatement
1007 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = new(driver.pool_) CYDoWhile($5, $2); }
1dbba6cc
JF
1008 ;
1009
36cd3cb9
JF
1010WhileStatement
1011 : "while" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWhile($3, $5); }
1dbba6cc
JF
1012 ;
1013
36cd3cb9
JF
1014ForStatement
1015 : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new(driver.pool_) CYFor($3, $5, $7, $9); }
1dbba6cc
JF
1016 ;
1017
36cd3cb9 1018ForStatementInitialiser
693d501b
JF
1019 : ExpressionNoInOpt { $$ = $1; }
1020 | "var" VariableDeclarationListNoIn { $$ = $2; }
1dbba6cc
JF
1021 ;
1022
36cd3cb9
JF
1023ForInStatement
1024 : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForIn($3, $5, $7); }
1dbba6cc
JF
1025 ;
1026
36cd3cb9
JF
1027ForInStatementInitialiser
1028 : LeftHandSideExpression { $$ = $1; }
693d501b 1029 | "var" VariableDeclarationNoIn { $$ = $2; }
1dbba6cc
JF
1030 ;
1031
36cd3cb9
JF
1032ContinueStatement
1033 : "continue" IdentifierOpt Terminator { $$ = new(driver.pool_) CYContinue($2); }
1dbba6cc
JF
1034 ;
1035
36cd3cb9
JF
1036BreakStatement
1037 : "break" IdentifierOpt Terminator { $$ = new(driver.pool_) CYBreak($2); }
1dbba6cc
JF
1038 ;
1039
36cd3cb9 1040ReturnStatement
c3c20102 1041 : "return" ExpressionOpt Terminator { $$ = new(driver.pool_) CYReturn($2); }
1dbba6cc
JF
1042 ;
1043
36cd3cb9
JF
1044WithStatement
1045 : "with" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWith($3, $5); }
1dbba6cc
JF
1046 ;
1047
36cd3cb9
JF
1048SwitchStatement
1049 : "switch" "(" Expression ")" CaseBlock { $$ = new(driver.pool_) CYSwitch($3, $5); }
1dbba6cc
JF
1050 ;
1051
1052CaseBlock
36cd3cb9 1053 : "{" CaseClausesOpt "}" { $$ = $2; }
1dbba6cc
JF
1054 ;
1055
36cd3cb9 1056CaseClausesOpt
cf7d4c69
JF
1057 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1058 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1059 | { $$ = NULL; }
1dbba6cc
JF
1060 ;
1061
36cd3cb9
JF
1062CaseClause
1063 : "case" Expression ":" StatementListOpt { $$ = new(driver.pool_) CYClause($2, $4); }
1dbba6cc
JF
1064 ;
1065
36cd3cb9
JF
1066DefaultClause
1067 : "default" ":" StatementListOpt { $$ = new(driver.pool_) CYClause(NULL, $3); }
1dbba6cc
JF
1068 ;
1069
36cd3cb9
JF
1070LabelledStatement
1071 : Identifier ":" Statement { $3->AddLabel($1); $$ = $3; }
1dbba6cc
JF
1072 ;
1073
36cd3cb9 1074ThrowStatement
c3c20102 1075 : "throw" Expression Terminator { $$ = new(driver.pool_) CYThrow($2); }
1dbba6cc
JF
1076 ;
1077
36cd3cb9 1078TryStatement
b1ff2d78 1079 : "try" Block CatchOpt FinallyOpt { $$ = new(driver.pool_) CYTry($2, $3, $4); }
1dbba6cc
JF
1080 ;
1081
1082CatchOpt
36cd3cb9 1083 : "catch" "(" Identifier ")" Block { $$ = new(driver.pool_) CYCatch($3, $5); }
cf7d4c69 1084 | { $$ = NULL; }
1dbba6cc
JF
1085 ;
1086
1087FinallyOpt
36cd3cb9 1088 : "finally" Block { $$ = $2; }
cf7d4c69 1089 | { $$ = NULL; }
1dbba6cc
JF
1090 ;
1091
36cd3cb9
JF
1092FunctionDeclaration
1093 : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunction($2, $4, $7); }
1dbba6cc
JF
1094 ;
1095
36cd3cb9
JF
1096FunctionExpression
1097 : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYLambda($2, $4, $7); }
1dbba6cc
JF
1098 ;
1099
1100FormalParameterList_
36cd3cb9 1101 : "," FormalParameterList { $$ = $2; }
cf7d4c69 1102 | { $$ = NULL; }
1dbba6cc
JF
1103 ;
1104
1105FormalParameterList
36cd3cb9 1106 : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYParameter($1, $2); }
cf7d4c69 1107 | { $$ = NULL; }
1dbba6cc
JF
1108 ;
1109
36cd3cb9
JF
1110FunctionBody
1111 : SourceElements { $$ = $1; }
1dbba6cc
JF
1112 ;
1113
1114Program
5befe15e 1115 : SourceElements { driver.source_ = $1; }
1dbba6cc
JF
1116 ;
1117
36cd3cb9
JF
1118SourceElements
1119 : SourceElement SourceElements { $1->SetNext($2); $$ = $1; }
cf7d4c69 1120 | { $$ = NULL; }
1dbba6cc
JF
1121 ;
1122
36cd3cb9 1123SourceElement
cf7d4c69 1124 : Statement { $$ = $1; }
36cd3cb9 1125 | FunctionDeclaration { $$ = $1; }
1dbba6cc 1126 ;
e5332278 1127
693d501b
JF
1128/* Objective-C Extensions {{{ */
1129VariadicCall
1130 : "," AssignmentExpression VariadicCall { $$ = new(driver.pool_) CYArgument(NULL, $2, $3); }
1131 | { $$ = NULL; }
1132 ;
1133
1134SelectorCall_
1135 : SelectorCall { $$ = $1; }
1136 | VariadicCall { $$ = $1; }
1137 ;
1138
1139SelectorCall
1140 : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new(driver.pool_) CYArgument($1 ?: new(driver.pool_) CYBlank(), $3, $4); }
1141 ;
1142
1143SelectorList
1144 : SelectorCall { $$ = $1; }
1145 | Word { $$ = new(driver.pool_) CYArgument($1, NULL); }
1146 ;
1147
1148MessageExpression
1149 : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYMessage($2, $3); }
1150 ;
1151
e7ed5354
JF
1152SelectorExpressionOpt
1153 : SelectorExpression_ { $$ = $1; }
1154 | { $$ = NULL; }
1155 ;
1156
1157SelectorExpression_
62014ea9 1158 : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelectorPart($1, true, $3); }
e7ed5354
JF
1159 ;
1160
1161SelectorExpression
1162 : SelectorExpression_ { $$ = $1; }
62014ea9 1163 | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); }
e7ed5354
JF
1164 ;
1165
457afcc9 1166PrimaryExpression_
693d501b 1167 : MessageExpression { $$ = $1; }
62014ea9 1168 | "@selector" "(" SelectorExpression ")" { $$ = new CYSelector($3); }
693d501b
JF
1169 ;
1170/* }}} */
1171
1172LeftHandSideExpression_
1173 : "*" LeftHandSideExpression { $$ = new(driver.pool_) CYIndirect($2); }
1174 ;
1175
1176UnaryExpression_
1177 : "&" UnaryExpression { $$ = new(driver.pool_) CYAddressOf($2); }
1178 ;
1179
e5332278 1180%%