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