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