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