]> git.saurik.com Git - cycript.git/blame - Cycript.y.in
Fixed the stupid variable renaming issue at the top level.
[cycript.git] / Cycript.y.in
CommitLineData
d15b59f5 1/* Cycript - Inlining/Optimizing JavaScript Compiler
b4aa79af
JF
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
cbaa5f0f 49@begin ObjectiveC
3c1c3635 50#include "ObjectiveC/Syntax.hpp"
4de0686f
JF
51@end
52
691e4717 53@begin E4X
b92ceddb 54#include "E4X/Syntax.hpp"
691e4717
JF
55@end
56
c3c20102
JF
57typedef struct {
58 bool newline_;
59
60 union {
b09da87b
JF
61 bool bool_;
62
63cd45c9
JF
63 CYDriver::Condition condition_;
64
c3c20102 65 CYArgument *argument_;
0ff9f149 66 CYAssignment *assignment_;
c3c20102
JF
67 CYBoolean *boolean_;
68 CYClause *clause_;
37954781 69 cy::Syntax::Catch *catch_;
320ce753 70 CYComment *comment_;
75b0a457 71 CYComprehension *comprehension_;
d35a3b07 72 CYCompound *compound_;
c3c20102
JF
73 CYDeclaration *declaration_;
74 CYDeclarations *declarations_;
75 CYElement *element_;
76 CYExpression *expression_;
77 CYFalse *false_;
b10bd496 78 CYFinally *finally_;
c3c20102
JF
79 CYForInitialiser *for_;
80 CYForInInitialiser *forin_;
b09da87b 81 CYFunctionParameter *functionParameter_;
c3c20102 82 CYIdentifier *identifier_;
0ff9f149 83 CYInfix *infix_;
c3c20102 84 CYLiteral *literal_;
9b5527f0 85 CYMember *member_;
c3c20102
JF
86 CYNull *null_;
87 CYNumber *number_;
3b52fd1a 88 CYProgram *program_;
c3c20102 89 CYProperty *property_;
e5bc40db 90 CYPropertyName *propertyName_;
c3c20102
JF
91 CYStatement *statement_;
92 CYString *string_;
93 CYThis *this_;
94 CYTrue *true_;
95 CYWord *word_;
4de0686f 96
cbaa5f0f 97@begin ObjectiveC
328ad766
JF
98 CYClassName *className_;
99 CYField *field_;
4de0686f
JF
100 CYMessage *message_;
101 CYMessageParameter *messageParameter_;
102 CYSelectorPart *selector_;
103@end
691e4717
JF
104
105@begin E4X
106 CYAttribute *attribute_;
b92ceddb
JF
107 CYPropertyIdentifier *propertyIdentifier_;
108 CYSelector *selector_;
691e4717 109@end
c3c20102
JF
110 };
111} YYSTYPE;
112
63b4c5a8
JF
113}
114
693d501b
JF
115%code provides {
116int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner);
117}
118
1dbba6cc 119%name-prefix "cy"
e5332278 120
63b4c5a8 121%language "C++"
e5332278 122%locations
1dbba6cc 123
5999c315
JF
124%initial-action {
125 @$.begin.filename = @$.end.filename = &driver.filename_;
126};
127
e5332278 128%defines
1dbba6cc 129
534fb6da
JF
130//%glr-parser
131//%expect 1
cac61857 132
e5332278
JF
133%error-verbose
134
5999c315 135%parse-param { CYDriver &driver }
924f67b2 136%lex-param { void *scanner }
e5332278 137
cb02f8ae 138@begin E4X
cb02f8ae
JF
139%token XMLCDATA
140%token XMLComment
141%token XMLPI
691e4717
JF
142
143%token XMLAttributeValue
144%token XMLName
145%token XMLTagCharacters
146%token XMLText
147%token XMLWhitespace
148@end
149
150@begin E4X
151%token LeftRight "<>"
152%token LeftSlashRight "</>"
153
154%token SlashRight "/>"
155%token LeftSlash "</"
156
691e4717
JF
157%token ColonColon "::"
158%token PeriodPeriod ".."
cb02f8ae 159@end
ac9a5ce1 160
b1589845
JF
161@begin E4X ObjectiveC
162%token At "@"
163@end
164
63b4c5a8
JF
165%token Ampersand "&"
166%token AmpersandAmpersand "&&"
167%token AmpersandEqual "&="
168%token Carrot "^"
169%token CarrotEqual "^="
170%token Equal "="
171%token EqualEqual "=="
172%token EqualEqualEqual "==="
173%token Exclamation "!"
174%token ExclamationEqual "!="
175%token ExclamationEqualEqual "!=="
176%token Hyphen "-"
177%token HyphenEqual "-="
178%token HyphenHyphen "--"
c3c20102 179%token HyphenHyphen_ "\n--"
63b4c5a8
JF
180%token HyphenRight "->"
181%token Left "<"
182%token LeftEqual "<="
183%token LeftLeft "<<"
184%token LeftLeftEqual "<<="
185%token Percent "%"
186%token PercentEqual "%="
187%token Period "."
188%token Pipe "|"
189%token PipeEqual "|="
190%token PipePipe "||"
191%token Plus "+"
192%token PlusEqual "+="
193%token PlusPlus "++"
c3c20102 194%token PlusPlus_ "\n++"
63b4c5a8
JF
195%token Right ">"
196%token RightEqual ">="
197%token RightRight ">>"
198%token RightRightEqual ">>="
199%token RightRightRight ">>>"
200%token RightRightRightEqual ">>>="
201%token Slash "/"
202%token SlashEqual "/="
203%token Star "*"
204%token StarEqual "*="
205%token Tilde "~"
206
207%token Colon ":"
208%token Comma ","
209%token Question "?"
210%token SemiColon ";"
c3c20102 211%token NewLine "\n"
63b4c5a8 212
320ce753
JF
213%token <comment_> Comment
214
63b4c5a8
JF
215%token OpenParen "("
216%token CloseParen ")"
924f67b2 217
63b4c5a8
JF
218%token OpenBrace "{"
219%token CloseBrace "}"
924f67b2 220
63b4c5a8
JF
221%token OpenBracket "["
222%token CloseBracket "]"
223
b09da87b 224%token AtClass "@class"
e7ed5354 225%token AtSelector "@selector"
d35a3b07 226%token AtEnd "@end"
e7ed5354 227
534fb6da
JF
228%token <false_> False "false"
229%token <null_> Null "null"
230%token <true_> True "true"
231
232// ES3/ES5/WIE/JSC Reserved
cf7d4c69
JF
233%token <word_> Break "break"
234%token <word_> Case "case"
235%token <word_> Catch "catch"
236%token <word_> Continue "continue"
237%token <word_> Default "default"
238%token <word_> Delete "delete"
239%token <word_> Do "do"
240%token <word_> Else "else"
cf7d4c69
JF
241%token <word_> Finally "finally"
242%token <word_> For "for"
243%token <word_> Function "function"
244%token <word_> If "if"
245%token <word_> In "in"
246%token <word_> InstanceOf "instanceof"
247%token <word_> New "new"
cf7d4c69
JF
248%token <word_> Return "return"
249%token <word_> Switch "switch"
250%token <this_> This "this"
251%token <word_> Throw "throw"
cf7d4c69
JF
252%token <word_> Try "try"
253%token <word_> TypeOf "typeof"
254%token <word_> Var "var"
255%token <word_> Void "void"
256%token <word_> While "while"
257%token <word_> With "with"
63b4c5a8 258
534fb6da 259// ES3/IE6 Future, ES5/JSC Reserved
d35a3b07 260%token <word_> Debugger "debugger"
534fb6da
JF
261
262// ES3/ES5/IE6 Future, JSC Reserved
263%token <word_> Const "const"
264
265// ES3/ES5/IE6/JSC Future
266%token <word_> Class "class"
d35a3b07
JF
267%token <word_> Enum "enum"
268%token <word_> Export "export"
269%token <word_> Extends "extends"
d35a3b07 270%token <word_> Import "import"
d35a3b07 271%token <word_> Super "super"
d35a3b07 272
534fb6da
JF
273// ES3 Future, ES5 Strict Future
274%token <identifier_> Implements "implements"
275%token <identifier_> Interface "interface"
276%token <identifier_> Package "package"
277%token <identifier_> Private "private"
278%token <identifier_> Protected "protected"
279%token <identifier_> Public "public"
280%token <identifier_> Static "static"
281
282// ES3 Future
283%token <identifier_> Abstract "abstract"
284%token <identifier_> Boolean "boolean"
285%token <identifier_> Byte "byte"
286%token <identifier_> Char "char"
287%token <identifier_> Double "double"
288%token <identifier_> Final "final"
289%token <identifier_> Float "float"
290%token <identifier_> Goto "goto"
291%token <identifier_> Int "int"
292%token <identifier_> Long "long"
293%token <identifier_> Native "native"
294%token <identifier_> Short "short"
295%token <identifier_> Synchronized "synchronized"
296%token <identifier_> Throws "throws"
297%token <identifier_> Transient "transient"
298%token <identifier_> Volatile "volatile"
299
300// ES5 Strict
cac61857 301%token <identifier_> Let "let"
534fb6da
JF
302%token <identifier_> Yield "yield"
303
304// Woah?!
305%token <identifier_> Each "each"
75b0a457 306
691e4717
JF
307@begin E4X
308// E4X Conditional
309%token <identifier_> Namespace "namespace"
310%token <identifier_> XML "xml"
311@end
312
75b0a457 313%token <identifier_> Identifier_
63b4c5a8
JF
314%token <number_> NumericLiteral
315%token <string_> StringLiteral
63cd45c9 316%token <literal_> RegularExpressionLiteral
1dbba6cc 317
cf7d4c69 318%type <expression_> AdditiveExpression
693d501b 319%type <expression_> AdditiveExpressionNoBF
cf7d4c69
JF
320%type <argument_> ArgumentList
321%type <argument_> ArgumentList_
322%type <argument_> ArgumentListOpt
323%type <argument_> Arguments
324%type <literal_> ArrayLiteral
9b5527f0 325%type <expression_> AssigneeExpression
9b5527f0 326%type <expression_> AssigneeExpressionNoBF
cf7d4c69 327%type <expression_> AssignmentExpression
0ff9f149 328%type <assignment_> AssignmentExpression_
693d501b
JF
329%type <expression_> AssignmentExpressionNoBF
330%type <expression_> AssignmentExpressionNoIn
cf7d4c69 331%type <expression_> BitwiseANDExpression
693d501b
JF
332%type <expression_> BitwiseANDExpressionNoBF
333%type <expression_> BitwiseANDExpressionNoIn
cf7d4c69 334%type <statement_> Block
cac61857 335%type <statement_> Block_
cf7d4c69
JF
336%type <boolean_> BooleanLiteral
337%type <expression_> BitwiseORExpression
693d501b
JF
338%type <expression_> BitwiseORExpressionNoBF
339%type <expression_> BitwiseORExpressionNoIn
cf7d4c69 340%type <expression_> BitwiseXORExpression
693d501b
JF
341%type <expression_> BitwiseXORExpressionNoBF
342%type <expression_> BitwiseXORExpressionNoIn
cf7d4c69
JF
343%type <statement_> BreakStatement
344%type <expression_> CallExpression
693d501b 345%type <expression_> CallExpressionNoBF
cf7d4c69
JF
346%type <clause_> CaseBlock
347%type <clause_> CaseClause
348%type <clause_> CaseClausesOpt
349%type <catch_> CatchOpt
75b0a457
JF
350%type <comprehension_> ComprehensionList
351%type <comprehension_> ComprehensionListOpt
cf7d4c69 352%type <expression_> ConditionalExpression
693d501b
JF
353%type <expression_> ConditionalExpressionNoBF
354%type <expression_> ConditionalExpressionNoIn
cf7d4c69
JF
355%type <statement_> ContinueStatement
356%type <clause_> DefaultClause
357%type <statement_> DoWhileStatement
358%type <expression_> Element
5befe15e 359%type <expression_> ElementOpt
cf7d4c69 360%type <element_> ElementList
5befe15e 361%type <element_> ElementListOpt
cf7d4c69
JF
362%type <statement_> ElseStatementOpt
363%type <statement_> EmptyStatement
364%type <expression_> EqualityExpression
693d501b
JF
365%type <expression_> EqualityExpressionNoBF
366%type <expression_> EqualityExpressionNoIn
cf7d4c69 367%type <expression_> Expression
cf7d4c69 368%type <expression_> ExpressionOpt
d35a3b07 369%type <compound_> Expression_
693d501b
JF
370%type <expression_> ExpressionNoBF
371%type <expression_> ExpressionNoIn
d35a3b07 372%type <compound_> ExpressionNoIn_
693d501b 373%type <expression_> ExpressionNoInOpt
cf7d4c69 374%type <statement_> ExpressionStatement
b10bd496 375%type <finally_> FinallyOpt
75b0a457 376%type <comprehension_> ForComprehension
cf7d4c69
JF
377%type <statement_> ForStatement
378%type <for_> ForStatementInitialiser
379%type <statement_> ForInStatement
380%type <forin_> ForInStatementInitialiser
b09da87b
JF
381%type <functionParameter_> FormalParameterList
382%type <functionParameter_> FormalParameterList_
b10bd496
JF
383%type <statement_> FunctionBody
384%type <statement_> FunctionDeclaration
cf7d4c69 385%type <expression_> FunctionExpression
75b0a457 386%type <identifier_> Identifier
cf7d4c69 387%type <identifier_> IdentifierOpt
75b0a457 388%type <comprehension_> IfComprehension
cf7d4c69
JF
389%type <statement_> IfStatement
390%type <expression_> Initialiser
391%type <expression_> InitialiserOpt
693d501b
JF
392%type <expression_> InitialiserNoIn
393%type <expression_> InitialiserNoInOpt
cf7d4c69
JF
394%type <statement_> IterationStatement
395%type <statement_> LabelledStatement
396%type <expression_> LeftHandSideExpression
693d501b 397%type <expression_> LeftHandSideExpressionNoBF
534fb6da 398//%type <statement_> LetStatement
cf7d4c69 399%type <literal_> Literal
561ac418
JF
400%type <literal_> LiteralNoRE
401%type <literal_> LiteralRE
cf7d4c69 402%type <expression_> LogicalANDExpression
693d501b
JF
403%type <expression_> LogicalANDExpressionNoBF
404%type <expression_> LogicalANDExpressionNoIn
cf7d4c69 405%type <expression_> LogicalORExpression
693d501b
JF
406%type <expression_> LogicalORExpressionNoBF
407%type <expression_> LogicalORExpressionNoIn
9b5527f0 408%type <member_> MemberAccess
cf7d4c69 409%type <expression_> MemberExpression
693d501b
JF
410%type <expression_> MemberExpression_
411%type <expression_> MemberExpressionNoBF
cf7d4c69 412%type <expression_> MultiplicativeExpression
693d501b 413%type <expression_> MultiplicativeExpressionNoBF
cf7d4c69 414%type <expression_> NewExpression
693d501b
JF
415%type <expression_> NewExpression_
416%type <expression_> NewExpressionNoBF
cf7d4c69
JF
417%type <null_> NullLiteral
418%type <literal_> ObjectLiteral
cf7d4c69 419%type <expression_> PostfixExpression
693d501b 420%type <expression_> PostfixExpressionNoBF
cf7d4c69 421%type <expression_> PrimaryExpression
561ac418 422%type <expression_> PrimaryExpressionNo
693d501b 423%type <expression_> PrimaryExpressionNoBF
b1589845 424%type <expression_> PrimaryExpressionNoRE
561ac418 425%type <expression_> PrimaryExpressionBF
b10bd496 426%type <statement_> Program
e5bc40db 427%type <propertyName_> PropertyName
b92ceddb 428%type <propertyName_> PropertyName_
cf7d4c69
JF
429%type <property_> PropertyNameAndValueList
430%type <property_> PropertyNameAndValueList_
431%type <property_> PropertyNameAndValueListOpt
432%type <expression_> RelationalExpression
0ff9f149 433%type <infix_> RelationalExpression_
693d501b
JF
434%type <expression_> RelationalExpressionNoBF
435%type <expression_> RelationalExpressionNoIn
0ff9f149 436%type <infix_> RelationalExpressionNoIn_
cf7d4c69 437%type <statement_> ReturnStatement
cf7d4c69 438%type <expression_> ShiftExpression
693d501b 439%type <expression_> ShiftExpressionNoBF
b10bd496 440%type <statement_> SourceElement
697d6fd2 441%type <statement_> SourceElement_
b10bd496 442%type <statement_> SourceElements
cf7d4c69 443%type <statement_> Statement
b10bd496 444%type <statement_> Statement_
693d501b 445%type <statement_> StatementList
cf7d4c69
JF
446%type <statement_> StatementListOpt
447%type <statement_> SwitchStatement
448%type <statement_> ThrowStatement
449%type <statement_> TryStatement
450%type <expression_> UnaryExpression
693d501b
JF
451%type <expression_> UnaryExpression_
452%type <expression_> UnaryExpressionNoBF
cf7d4c69 453%type <declaration_> VariableDeclaration
693d501b 454%type <declaration_> VariableDeclarationNoIn
cf7d4c69
JF
455%type <declarations_> VariableDeclarationList
456%type <declarations_> VariableDeclarationList_
693d501b
JF
457%type <declarations_> VariableDeclarationListNoIn
458%type <declarations_> VariableDeclarationListNoIn_
cf7d4c69 459%type <statement_> VariableStatement
cf7d4c69
JF
460%type <statement_> WhileStatement
461%type <statement_> WithStatement
cf7d4c69 462
9cad30fa
JF
463@begin C
464%type <expression_> AssigneeExpressionNoRE
465%type <expression_> CallExpressionNoRE
466%type <expression_> LeftHandSideExpressionNoRE
467%type <expression_> MemberExpressionNoRE
468%type <expression_> NewExpressionNoRE
469%type <expression_> PostfixExpressionNoRE
470%type <expression_> UnaryAssigneeExpression
471%type <expression_> UnaryExpressionNoRE
472@end
473
cbaa5f0f 474@begin ObjectiveC
328ad766
JF
475%type <statement_> CategoryStatement
476%type <expression_> ClassExpression
477%type <statement_> ClassStatement
478%type <expression_> ClassSuperOpt
479%type <field_> ClassFieldList
480%type <message_> ClassMessageDeclaration
481%type <message_> ClassMessageDeclarationListOpt
482%type <className_> ClassName
483%type <className_> ClassNameOpt
693d501b 484%type <expression_> MessageExpression
328ad766
JF
485%type <messageParameter_> MessageParameter
486%type <messageParameter_> MessageParameters
487%type <messageParameter_> MessageParameterList
488%type <messageParameter_> MessageParameterListOpt
489%type <bool_> MessageScope
693d501b
JF
490%type <argument_> SelectorCall
491%type <argument_> SelectorCall_
328ad766
JF
492%type <selector_> SelectorExpression
493%type <selector_> SelectorExpression_
494%type <selector_> SelectorExpressionOpt
693d501b 495%type <argument_> SelectorList
328ad766 496%type <expression_> TypeOpt
693d501b 497%type <argument_> VariadicCall
328ad766
JF
498%type <word_> Word
499%type <word_> WordOpt
500@end
693d501b 501
691e4717 502@begin E4X
b92ceddb
JF
503%type <propertyIdentifier_> PropertyIdentifier_
504%type <selector_> PropertySelector
505%type <selector_> PropertySelector_
691e4717
JF
506%type <identifier_> QualifiedIdentifier
507%type <identifier_> QualifiedIdentifier_
508%type <identifier_> WildcardIdentifier
509%type <identifier_> XMLComment
510%type <identifier_> XMLCDATA
511%type <identifier_> XMLElement
512%type <identifier_> XMLElementContent
513%type <identifier_> XMLMarkup
514%type <identifier_> XMLPI
515
516%type <attribute_> AttributeIdentifier
b92ceddb 517/* XXX: %type <statement_> DefaultXMLNamespaceStatement */
691e4717
JF
518%type <expression_> PropertyIdentifier
519%type <expression_> XMLListInitialiser
520%type <expression_> XMLInitialiser
521@end
522
b92ceddb
JF
523%nonassoc Identifier_ "abstract" "boolean" "break" "byte" "case" "catch" "char" "class" "const" "continue" "debugger" "default" "delete" "do" "double" "each" "enum" "export" "extends" "false" "final" "finally" "float" /*"for"*/ "function" "goto" "implements" "import" /*"in"*/ /*"instanceof"*/ "int" "interface" "let" "long" "namespace" "native" "new" "null" "package" "private" "protected" "public" "return" "short" "super" "static" "switch" "synchronized" "this" "throw" "throws" "transient" "true" "try" "typeof" "var" "void" "volatile" "while" "with" "xml" "yield"
524
525%nonassoc "if"
526%nonassoc "else"
527
528%nonassoc "++" "--"
529%nonassoc "(" "["
530
cde525f7
JF
531%left "*" "/" "%"
532%left "+" "-"
533%left "<<" ">>" ">>>"
534%left "<" ">" "<=" ">=" "instanceof" "in"
535%left "==" "!=" "===" "!=="
536%left "&"
537%left "^"
538%left "|"
539%left "&&"
540%left "||"
541
542%right "=" "*=" "/=" "%=" "+=" "-=" "<<=" ">>=" ">>>=" "&=" "^=" "|="
c3c20102 543
693d501b 544%start Program
e5332278 545
693d501b 546%%
c3c20102 547
691e4717
JF
548/* Lexer State {{{ */
549LexSetRegExp
550 : { driver.SetCondition(CYDriver::RegExpCondition); }
551 ;
552/* }}} */
553
b10bd496
JF
554StrictSemi
555 : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); }
556 ;
557
558Terminator_
c3c20102 559 : ";"
b10bd496
JF
560 | "\n" StrictSemi
561 ;
562
563TerminatorOpt
564 : Terminator_
565 | error { yyerrok; driver.errors_.pop_back(); } StrictSemi
c3c20102
JF
566 ;
567
568Terminator
b10bd496
JF
569 : Terminator_
570 | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
c3c20102
JF
571 ;
572
cac61857 573/*CommaOpt
693d501b
JF
574 : ","
575 |
cac61857 576 ;*/
693d501b 577
cbaa5f0f 578@begin ObjectiveC
c3c20102 579NewLineOpt
693d501b 580 : "\n"
c3c20102
JF
581 |
582 ;
1dbba6cc 583
36cd3cb9 584WordOpt
cf7d4c69
JF
585 : Word { $$ = $1; }
586 | { $$ = NULL; }
2bf24581
JF
587 ;
588
36cd3cb9 589Word
cf7d4c69 590 : Identifier { $$ = $1; }
c3c20102 591 | "break" NewLineOpt { $$ = $1; }
cf7d4c69
JF
592 | "case" { $$ = $1; }
593 | "catch" { $$ = $1; }
d35a3b07
JF
594 | "class" { $$ = $1; }
595 | "const" { $$ = $1; }
c3c20102 596 | "continue" NewLineOpt { $$ = $1; }
d35a3b07 597 | "debugger" { $$ = $1; }
cf7d4c69
JF
598 | "default" { $$ = $1; }
599 | "delete" { $$ = $1; }
600 | "do" { $$ = $1; }
601 | "else" { $$ = $1; }
d35a3b07
JF
602 | "enum" { $$ = $1; }
603 | "export" { $$ = $1; }
604 | "extends" { $$ = $1; }
cf7d4c69
JF
605 | "false" { $$ = $1; }
606 | "finally" { $$ = $1; }
561ac418 607 /* XXX: | "for" { $$ = $1; } */
cf7d4c69
JF
608 | "function" { $$ = $1; }
609 | "if" { $$ = $1; }
d35a3b07 610 | "import" { $$ = $1; }
693d501b
JF
611 /* XXX: | "in" { $$ = $1; } */
612 /* XXX: | "instanceof" { $$ = $1; } */
cf7d4c69
JF
613 | "new" { $$ = $1; }
614 | "null" { $$ = $1; }
c3c20102 615 | "return" NewLineOpt { $$ = $1; }
d35a3b07 616 | "super" { $$ = $1; }
cf7d4c69
JF
617 | "switch" { $$ = $1; }
618 | "this" { $$ = $1; }
c3c20102 619 | "throw" NewLineOpt { $$ = $1; }
cf7d4c69
JF
620 | "true" { $$ = $1; }
621 | "try" { $$ = $1; }
622 | "typeof" { $$ = $1; }
623 | "var" { $$ = $1; }
624 | "void" { $$ = $1; }
625 | "while" { $$ = $1; }
626 | "with" { $$ = $1; }
2bf24581 627 ;
328ad766 628@end
2bf24581 629
75b0a457
JF
630Identifier
631 : Identifier_ { $$ = $1; }
534fb6da
JF
632
633 | "implements" { $$ = $1; }
634 | "interface" { $$ = $1; }
635 | "package" { $$ = $1; }
636 | "private" { $$ = $1; }
637 | "protected" { $$ = $1; }
638 | "public" { $$ = $1; }
639 | "static" { $$ = $1; }
640
641 | "abstract" { $$ = $1; }
642 | "boolean" { $$ = $1; }
643 | "byte" { $$ = $1; }
644 | "char" { $$ = $1; }
645 | "double" { $$ = $1; }
646 | "final" { $$ = $1; }
647 | "float" { $$ = $1; }
648 | "goto" { $$ = $1; }
649 | "int" { $$ = $1; }
650 | "long" { $$ = $1; }
651 | "native" { $$ = $1; }
652 | "short" { $$ = $1; }
653 | "synchronized" { $$ = $1; }
654 | "throws" { $$ = $1; }
655 | "transient" { $$ = $1; }
656 | "volatile" { $$ = $1; }
657
cac61857 658 | "let" { $$ = $1; }
534fb6da
JF
659 | "yield" { $$ = $1; }
660
661 | "each" { $$ = $1; }
75b0a457
JF
662 ;
663
36cd3cb9 664IdentifierOpt
cf7d4c69
JF
665 : Identifier { $$ = $1; }
666 | { $$ = NULL; }
1dbba6cc
JF
667 ;
668
561ac418 669LiteralNoRE
cf7d4c69
JF
670 : NullLiteral { $$ = $1; }
671 | BooleanLiteral { $$ = $1; }
672 | NumericLiteral { $$ = $1; }
673 | StringLiteral { $$ = $1; }
b92ceddb 674 | "@" StringLiteral { $$ = $2; }
561ac418
JF
675 ;
676
677LiteralRE
678 : RegularExpressionLiteral { $$ = $1; }
679 ;
680
681Literal
682 : LiteralNoRE { $$ = $1; }
683 | LiteralRE { $$ = $1; }
1dbba6cc
JF
684 ;
685
36cd3cb9 686NullLiteral
cf7d4c69 687 : "null" { $$ = $1; }
1dbba6cc
JF
688 ;
689
36cd3cb9 690BooleanLiteral
cf7d4c69
JF
691 : "true" { $$ = $1; }
692 | "false" { $$ = $1; }
1dbba6cc
JF
693 ;
694
1dbba6cc 695/* 11.1 Primary Expressions {{{ */
561ac418 696PrimaryExpression
fdb013ca 697 : LexSetRegExp PrimaryExpressionNoRE { $$ = $2; }
697d6fd2
JF
698 ;
699
561ac418
JF
700PrimaryExpressionNoBF
701 : PrimaryExpressionNo { $$ = $1; }
561ac418
JF
702 ;
703
b1589845 704PrimaryExpressionNoRE
561ac418
JF
705 : PrimaryExpressionBF { $$ = $1; }
706 | PrimaryExpressionNo { $$ = $1; }
707 ;
708
561ac418 709PrimaryExpressionNo
cf7d4c69 710 : "this" { $$ = $1; }
b1ff2d78 711 | Identifier { $$ = new(driver.pool_) CYVariable($1); }
cf7d4c69
JF
712 | Literal { $$ = $1; }
713 | ArrayLiteral { $$ = $1; }
36cd3cb9 714 | "(" Expression ")" { $$ = $2; }
693d501b
JF
715 ;
716
561ac418
JF
717PrimaryExpressionBF
718 : ObjectLiteral { $$ = $1; }
1dbba6cc
JF
719 ;
720/* }}} */
721/* 11.1.4 Array Initialiser {{{ */
36cd3cb9 722ArrayLiteral
d35a3b07 723 : "[" ElementListOpt "]" { $$ = new(driver.pool_) CYArray($2); }
1dbba6cc
JF
724 ;
725
36cd3cb9 726Element
cf7d4c69 727 : AssignmentExpression { $$ = $1; }
5befe15e
JF
728 ;
729
730ElementOpt
731 : Element { $$ = $1; }
691e4717 732 | LexSetRegExp { $$ = NULL; }
1dbba6cc
JF
733 ;
734
5befe15e
JF
735ElementListOpt
736 : ElementList { $$ = $1; }
691e4717 737 | LexSetRegExp { $$ = NULL; }
1dbba6cc
JF
738 ;
739
36cd3cb9 740ElementList
5befe15e
JF
741 : ElementOpt "," ElementListOpt { $$ = new(driver.pool_) CYElement($1, $3); }
742 | Element { $$ = new(driver.pool_) CYElement($1, NULL); }
1dbba6cc
JF
743 ;
744/* }}} */
745/* 11.1.5 Object Initialiser {{{ */
36cd3cb9 746ObjectLiteral
5befe15e 747 : "{" PropertyNameAndValueListOpt "}" { $$ = new(driver.pool_) CYObject($2); }
1dbba6cc
JF
748 ;
749
36cd3cb9 750PropertyNameAndValueList_
cf7d4c69 751 : "," PropertyNameAndValueList { $$ = $2; }
cac61857 752 | { $$ = NULL; }
1dbba6cc
JF
753 ;
754
36cd3cb9 755PropertyNameAndValueListOpt
cf7d4c69 756 : PropertyNameAndValueList { $$ = $1; }
36cd3cb9 757 | { $$ = NULL; }
1dbba6cc
JF
758 ;
759
36cd3cb9
JF
760PropertyNameAndValueList
761 : PropertyName ":" AssignmentExpression PropertyNameAndValueList_ { $$ = new(driver.pool_) CYProperty($1, $3, $4); }
1dbba6cc
JF
762 ;
763
b92ceddb 764PropertyName_
36cd3cb9
JF
765 : Identifier { $$ = $1; }
766 | StringLiteral { $$ = $1; }
767 | NumericLiteral { $$ = $1; }
1dbba6cc 768 ;
b92ceddb
JF
769
770PropertyName
771 : LexSetRegExp PropertyName_ { $$ = $2; }
772 ;
1dbba6cc
JF
773/* }}} */
774
63cd45c9 775/* 11.2 Left-Hand-Side Expressions {{{ */
693d501b
JF
776MemberExpression_
777 : "new" MemberExpression Arguments { $$ = new(driver.pool_) CYNew($2, $3); }
778 ;
779
9b5527f0
JF
780MemberAccess
781 : "[" Expression "]" { $$ = new(driver.pool_) CYDirectMember(NULL, $2); }
782 | "." Identifier { $$ = new(driver.pool_) CYDirectMember(NULL, new(driver.pool_) CYString($2)); }
783 ;
784
36cd3cb9 785MemberExpression
cf7d4c69 786 : PrimaryExpression { $$ = $1; }
b1589845 787 | LexSetRegExp FunctionExpression { $$ = $2; }
9b5527f0 788 | MemberExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
691e4717 789 | LexSetRegExp MemberExpression_ { $$ = $2; }
693d501b
JF
790 ;
791
792MemberExpressionNoBF
793 : PrimaryExpressionNoBF { $$ = $1; }
9b5527f0 794 | MemberExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
693d501b
JF
795 | MemberExpression_ { $$ = $1; }
796 ;
797
9cad30fa 798@begin C
b1589845
JF
799MemberExpressionNoRE
800 : PrimaryExpressionNoRE { $$ = $1; }
801 | FunctionExpression { $$ = $1; }
802 | MemberExpressionNoRE MemberAccess { $2->SetLeft($1); $$ = $2; }
803 | MemberExpression_ { $$ = $1; }
804 ;
9cad30fa 805@end
b1589845 806
693d501b
JF
807NewExpression_
808 : "new" NewExpression { $$ = new(driver.pool_) CYNew($2, NULL); }
1dbba6cc
JF
809 ;
810
36cd3cb9 811NewExpression
cf7d4c69 812 : MemberExpression { $$ = $1; }
691e4717 813 | LexSetRegExp NewExpression_ { $$ = $2; }
693d501b
JF
814 ;
815
816NewExpressionNoBF
817 : MemberExpressionNoBF { $$ = $1; }
818 | NewExpression_ { $$ = $1; }
1dbba6cc
JF
819 ;
820
9cad30fa 821@begin C
b1589845
JF
822NewExpressionNoRE
823 : MemberExpressionNoRE { $$ = $1; }
824 | NewExpression_ { $$ = $1; }
825 ;
9cad30fa 826@end
b1589845 827
36cd3cb9 828CallExpression
fdb013ca 829 : MemberExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
b1ff2d78 830 | CallExpression Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
9b5527f0 831 | CallExpression MemberAccess { $2->SetLeft($1); $$ = $2; }
1dbba6cc
JF
832 ;
833
693d501b
JF
834CallExpressionNoBF
835 : MemberExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
836 | CallExpressionNoBF Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
9b5527f0 837 | CallExpressionNoBF MemberAccess { $2->SetLeft($1); $$ = $2; }
693d501b
JF
838 ;
839
9cad30fa 840@begin C
b1589845 841CallExpressionNoRE
fdb013ca 842 : MemberExpressionNoRE Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
b1589845
JF
843 | CallExpressionNoRE Arguments { $$ = new(driver.pool_) CYCall($1, $2); }
844 | CallExpressionNoRE MemberAccess { $2->SetLeft($1); $$ = $2; }
845 ;
9cad30fa 846@end
b1589845 847
36cd3cb9 848ArgumentList_
cf7d4c69
JF
849 : "," ArgumentList { $$ = $2; }
850 | { $$ = NULL; }
1dbba6cc
JF
851 ;
852
36cd3cb9 853ArgumentListOpt
cf7d4c69 854 : ArgumentList { $$ = $1; }
691e4717 855 | LexSetRegExp { $$ = NULL; }
1dbba6cc
JF
856 ;
857
36cd3cb9
JF
858ArgumentList
859 : AssignmentExpression ArgumentList_ { $$ = new(driver.pool_) CYArgument(NULL, $1, $2); }
1dbba6cc
JF
860 ;
861
862Arguments
36cd3cb9 863 : "(" ArgumentListOpt ")" { $$ = $2; }
1dbba6cc
JF
864 ;
865
36cd3cb9 866LeftHandSideExpression
cf7d4c69
JF
867 : NewExpression { $$ = $1; }
868 | CallExpression { $$ = $1; }
693d501b
JF
869 ;
870
871LeftHandSideExpressionNoBF
872 : NewExpressionNoBF { $$ = $1; }
873 | CallExpressionNoBF { $$ = $1; }
1dbba6cc 874 ;
561ac418 875
9cad30fa 876@begin C
b1589845
JF
877LeftHandSideExpressionNoRE
878 : NewExpressionNoRE { $$ = $1; }
879 | CallExpressionNoRE { $$ = $1; }
880 ;
9cad30fa 881@end
63cd45c9
JF
882/* }}} */
883/* 11.3 Postfix Expressions {{{ */
36cd3cb9 884PostfixExpression
9b5527f0 885 : AssigneeExpression { $$ = $1; }
b1ff2d78
JF
886 | LeftHandSideExpression "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
887 | LeftHandSideExpression "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
1dbba6cc
JF
888 ;
889
693d501b 890PostfixExpressionNoBF
9b5527f0 891 : AssigneeExpressionNoBF { $$ = $1; }
693d501b
JF
892 | LeftHandSideExpressionNoBF "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
893 | LeftHandSideExpressionNoBF "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
894 ;
561ac418 895
9cad30fa 896@begin C
b1589845
JF
897PostfixExpressionNoRE
898 : AssigneeExpressionNoRE { $$ = $1; }
899 | LeftHandSideExpressionNoRE "++" { $$ = new(driver.pool_) CYPostIncrement($1); }
900 | LeftHandSideExpressionNoRE "--" { $$ = new(driver.pool_) CYPostDecrement($1); }
901 ;
9cad30fa 902@end
63cd45c9
JF
903/* }}} */
904/* 11.4 Unary Operators {{{ */
693d501b
JF
905UnaryExpression_
906 : "delete" UnaryExpression { $$ = new(driver.pool_) CYDelete($2); }
36cd3cb9
JF
907 | "void" UnaryExpression { $$ = new(driver.pool_) CYVoid($2); }
908 | "typeof" UnaryExpression { $$ = new(driver.pool_) CYTypeOf($2); }
909 | "++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
910 | "\n++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); }
911 | "--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
912 | "\n--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); }
c0bc320e 913 | "+" UnaryExpression { $$ = new(driver.pool_) CYAffirm($2); }
36cd3cb9
JF
914 | "-" UnaryExpression { $$ = new(driver.pool_) CYNegate($2); }
915 | "~" UnaryExpression { $$ = new(driver.pool_) CYBitwiseNot($2); }
916 | "!" UnaryExpression { $$ = new(driver.pool_) CYLogicalNot($2); }
693d501b
JF
917 ;
918
919UnaryExpression
920 : PostfixExpression { $$ = $1; }
691e4717 921 | LexSetRegExp UnaryExpression_ { $$ = $2; }
693d501b
JF
922 ;
923
924UnaryExpressionNoBF
925 : PostfixExpressionNoBF { $$ = $1; }
926 | UnaryExpression_ { $$ = $1; }
1dbba6cc 927 ;
561ac418 928
9cad30fa 929@begin C
b1589845
JF
930UnaryExpressionNoRE
931 : PostfixExpressionNoRE { $$ = $1; }
932 | UnaryExpression_ { $$ = $1; }
933 ;
9cad30fa 934@end
63cd45c9
JF
935/* }}} */
936/* 11.5 Multiplicative Operators {{{ */
36cd3cb9 937MultiplicativeExpression
cf7d4c69 938 : UnaryExpression { $$ = $1; }
36cd3cb9
JF
939 | MultiplicativeExpression "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
940 | MultiplicativeExpression "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
941 | MultiplicativeExpression "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
1dbba6cc
JF
942 ;
943
693d501b
JF
944MultiplicativeExpressionNoBF
945 : UnaryExpressionNoBF { $$ = $1; }
946 | MultiplicativeExpressionNoBF "*" UnaryExpression { $$ = new(driver.pool_) CYMultiply($1, $3); }
947 | MultiplicativeExpressionNoBF "/" UnaryExpression { $$ = new(driver.pool_) CYDivide($1, $3); }
948 | MultiplicativeExpressionNoBF "%" UnaryExpression { $$ = new(driver.pool_) CYModulus($1, $3); }
949 ;
63cd45c9
JF
950/* }}} */
951/* 11.6 Additive Operators {{{ */
36cd3cb9 952AdditiveExpression
cf7d4c69 953 : MultiplicativeExpression { $$ = $1; }
36cd3cb9
JF
954 | AdditiveExpression "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
955 | AdditiveExpression "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
1dbba6cc
JF
956 ;
957
693d501b
JF
958AdditiveExpressionNoBF
959 : MultiplicativeExpressionNoBF { $$ = $1; }
960 | AdditiveExpressionNoBF "+" MultiplicativeExpression { $$ = new(driver.pool_) CYAdd($1, $3); }
961 | AdditiveExpressionNoBF "-" MultiplicativeExpression { $$ = new(driver.pool_) CYSubtract($1, $3); }
962 ;
63cd45c9
JF
963/* }}} */
964/* 11.7 Bitwise Shift Operators {{{ */
36cd3cb9 965ShiftExpression
cf7d4c69 966 : AdditiveExpression { $$ = $1; }
36cd3cb9
JF
967 | ShiftExpression "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
968 | ShiftExpression ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
969 | ShiftExpression ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
1dbba6cc
JF
970 ;
971
693d501b
JF
972ShiftExpressionNoBF
973 : AdditiveExpressionNoBF { $$ = $1; }
974 | ShiftExpressionNoBF "<<" AdditiveExpression { $$ = new(driver.pool_) CYShiftLeft($1, $3); }
975 | ShiftExpressionNoBF ">>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightSigned($1, $3); }
976 | ShiftExpressionNoBF ">>>" AdditiveExpression { $$ = new(driver.pool_) CYShiftRightUnsigned($1, $3); }
977 ;
63cd45c9
JF
978/* }}} */
979/* 11.8 Relational Operators {{{ */
0ff9f149
JF
980RelationalExpressionNoIn_
981 : "<" ShiftExpression { $$ = new(driver.pool_) CYLess(NULL, $2); }
982 | ">" ShiftExpression { $$ = new(driver.pool_) CYGreater(NULL, $2); }
983 | "<=" ShiftExpression { $$ = new(driver.pool_) CYLessOrEqual(NULL, $2); }
984 | ">=" ShiftExpression { $$ = new(driver.pool_) CYGreaterOrEqual(NULL, $2); }
985 | "instanceof" ShiftExpression { $$ = new(driver.pool_) CYInstanceOf(NULL, $2); }
986 ;
987
988RelationalExpression_
989 : RelationalExpressionNoIn_ { $$ = $1; }
990 | "in" ShiftExpression { $$ = new(driver.pool_) CYIn(NULL, $2); }
991 ;
992
36cd3cb9 993RelationalExpression
cf7d4c69 994 : ShiftExpression { $$ = $1; }
0ff9f149 995 | RelationalExpression RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
1dbba6cc
JF
996 ;
997
693d501b
JF
998RelationalExpressionNoIn
999 : ShiftExpression { $$ = $1; }
0ff9f149 1000 | RelationalExpressionNoIn RelationalExpressionNoIn_ { $2->SetLeft($1); $$ = $2; }
693d501b
JF
1001 ;
1002
1003RelationalExpressionNoBF
1004 : ShiftExpressionNoBF { $$ = $1; }
0ff9f149 1005 | RelationalExpressionNoBF RelationalExpression_ { $2->SetLeft($1); $$ = $2; }
693d501b 1006 ;
63cd45c9
JF
1007/* }}} */
1008/* 11.9 Equality Operators {{{ */
36cd3cb9 1009EqualityExpression
cf7d4c69 1010 : RelationalExpression { $$ = $1; }
36cd3cb9
JF
1011 | EqualityExpression "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
1012 | EqualityExpression "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
1013 | EqualityExpression "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
1014 | EqualityExpression "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
1dbba6cc
JF
1015 ;
1016
693d501b
JF
1017EqualityExpressionNoIn
1018 : RelationalExpressionNoIn { $$ = $1; }
1019 | EqualityExpressionNoIn "==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYEqual($1, $3); }
1020 | EqualityExpressionNoIn "!=" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotEqual($1, $3); }
1021 | EqualityExpressionNoIn "===" RelationalExpressionNoIn { $$ = new(driver.pool_) CYIdentical($1, $3); }
1022 | EqualityExpressionNoIn "!==" RelationalExpressionNoIn { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
1023 ;
1024
1025EqualityExpressionNoBF
1026 : RelationalExpressionNoBF { $$ = $1; }
1027 | EqualityExpressionNoBF "==" RelationalExpression { $$ = new(driver.pool_) CYEqual($1, $3); }
1028 | EqualityExpressionNoBF "!=" RelationalExpression { $$ = new(driver.pool_) CYNotEqual($1, $3); }
1029 | EqualityExpressionNoBF "===" RelationalExpression { $$ = new(driver.pool_) CYIdentical($1, $3); }
1030 | EqualityExpressionNoBF "!==" RelationalExpression { $$ = new(driver.pool_) CYNotIdentical($1, $3); }
1031 ;
63cd45c9
JF
1032/* }}} */
1033/* 11.10 Binary Bitwise Operators {{{ */
36cd3cb9 1034BitwiseANDExpression
cf7d4c69 1035 : EqualityExpression { $$ = $1; }
36cd3cb9 1036 | BitwiseANDExpression "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
1dbba6cc
JF
1037 ;
1038
693d501b
JF
1039BitwiseANDExpressionNoIn
1040 : EqualityExpressionNoIn { $$ = $1; }
1041 | BitwiseANDExpressionNoIn "&" EqualityExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
1042 ;
1043
1044BitwiseANDExpressionNoBF
1045 : EqualityExpressionNoBF { $$ = $1; }
1046 | BitwiseANDExpressionNoBF "&" EqualityExpression { $$ = new(driver.pool_) CYBitwiseAnd($1, $3); }
1047 ;
1048
36cd3cb9 1049BitwiseXORExpression
cf7d4c69 1050 : BitwiseANDExpression { $$ = $1; }
36cd3cb9 1051 | BitwiseXORExpression "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
1dbba6cc
JF
1052 ;
1053
693d501b
JF
1054BitwiseXORExpressionNoIn
1055 : BitwiseANDExpressionNoIn { $$ = $1; }
1056 | BitwiseXORExpressionNoIn "^" BitwiseANDExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
1057 ;
1058
1059BitwiseXORExpressionNoBF
1060 : BitwiseANDExpressionNoBF { $$ = $1; }
1061 | BitwiseXORExpressionNoBF "^" BitwiseANDExpression { $$ = new(driver.pool_) CYBitwiseXOr($1, $3); }
1062 ;
1063
36cd3cb9 1064BitwiseORExpression
cf7d4c69 1065 : BitwiseXORExpression { $$ = $1; }
36cd3cb9 1066 | BitwiseORExpression "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
1dbba6cc
JF
1067 ;
1068
693d501b
JF
1069BitwiseORExpressionNoIn
1070 : BitwiseXORExpressionNoIn { $$ = $1; }
1071 | BitwiseORExpressionNoIn "|" BitwiseXORExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
1072 ;
1073
1074BitwiseORExpressionNoBF
1075 : BitwiseXORExpressionNoBF { $$ = $1; }
1076 | BitwiseORExpressionNoBF "|" BitwiseXORExpression { $$ = new(driver.pool_) CYBitwiseOr($1, $3); }
1077 ;
63cd45c9
JF
1078/* }}} */
1079/* 11.11 Binary Logical Operators {{{ */
36cd3cb9 1080LogicalANDExpression
cf7d4c69 1081 : BitwiseORExpression { $$ = $1; }
36cd3cb9 1082 | LogicalANDExpression "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
1dbba6cc
JF
1083 ;
1084
693d501b
JF
1085LogicalANDExpressionNoIn
1086 : BitwiseORExpressionNoIn { $$ = $1; }
1087 | LogicalANDExpressionNoIn "&&" BitwiseORExpressionNoIn { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
1088 ;
1089
1090LogicalANDExpressionNoBF
1091 : BitwiseORExpressionNoBF { $$ = $1; }
1092 | LogicalANDExpressionNoBF "&&" BitwiseORExpression { $$ = new(driver.pool_) CYLogicalAnd($1, $3); }
1093 ;
1094
36cd3cb9 1095LogicalORExpression
cf7d4c69 1096 : LogicalANDExpression { $$ = $1; }
36cd3cb9 1097 | LogicalORExpression "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
1dbba6cc
JF
1098 ;
1099
693d501b
JF
1100LogicalORExpressionNoIn
1101 : LogicalANDExpressionNoIn { $$ = $1; }
1102 | LogicalORExpressionNoIn "||" LogicalANDExpressionNoIn { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
1103 ;
1104
1105LogicalORExpressionNoBF
1106 : LogicalANDExpressionNoBF { $$ = $1; }
1107 | LogicalORExpressionNoBF "||" LogicalANDExpression { $$ = new(driver.pool_) CYLogicalOr($1, $3); }
1108 ;
63cd45c9
JF
1109/* }}} */
1110/* 11.12 Conditional Operator ( ? : ) {{{ */
36cd3cb9 1111ConditionalExpression
cf7d4c69 1112 : LogicalORExpression { $$ = $1; }
36cd3cb9 1113 | LogicalORExpression "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
1dbba6cc
JF
1114 ;
1115
693d501b
JF
1116ConditionalExpressionNoIn
1117 : LogicalORExpressionNoIn { $$ = $1; }
1118 | LogicalORExpressionNoIn "?" AssignmentExpression ":" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
1119 ;
1120
1121ConditionalExpressionNoBF
1122 : LogicalORExpressionNoBF { $$ = $1; }
1123 | LogicalORExpressionNoBF "?" AssignmentExpression ":" AssignmentExpression { $$ = new(driver.pool_) CYCondition($1, $3, $5); }
1124 ;
63cd45c9
JF
1125/* }}} */
1126/* 11.13 Assignment Operators {{{ */
0ff9f149
JF
1127AssignmentExpression_
1128 : "=" AssignmentExpression { $$ = new(driver.pool_) CYAssign(NULL, $2); }
1129 | "*=" AssignmentExpression { $$ = new(driver.pool_) CYMultiplyAssign(NULL, $2); }
1130 | "/=" AssignmentExpression { $$ = new(driver.pool_) CYDivideAssign(NULL, $2); }
1131 | "%=" AssignmentExpression { $$ = new(driver.pool_) CYModulusAssign(NULL, $2); }
1132 | "+=" AssignmentExpression { $$ = new(driver.pool_) CYAddAssign(NULL, $2); }
1133 | "-=" AssignmentExpression { $$ = new(driver.pool_) CYSubtractAssign(NULL, $2); }
1134 | "<<=" AssignmentExpression { $$ = new(driver.pool_) CYShiftLeftAssign(NULL, $2); }
1135 | ">>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightSignedAssign(NULL, $2); }
1136 | ">>>=" AssignmentExpression { $$ = new(driver.pool_) CYShiftRightUnsignedAssign(NULL, $2); }
1137 | "&=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseAndAssign(NULL, $2); }
1138 | "^=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseXOrAssign(NULL, $2); }
1139 | "|=" AssignmentExpression { $$ = new(driver.pool_) CYBitwiseOrAssign(NULL, $2); }
1140 ;
1141
9b5527f0
JF
1142AssigneeExpression
1143 : LeftHandSideExpression { $$ = $1; }
9cad30fa 1144@begin C
691e4717 1145 | LexSetRegExp UnaryAssigneeExpression { $$ = $2; }
9cad30fa 1146@end
9b5527f0
JF
1147 ;
1148
1149AssigneeExpressionNoBF
1150 : LeftHandSideExpressionNoBF { $$ = $1; }
9cad30fa 1151@begin C
697d6fd2 1152 | UnaryAssigneeExpression { $$ = $1; }
9cad30fa 1153@end
9b5527f0
JF
1154 ;
1155
9cad30fa 1156@begin C
b1589845
JF
1157AssigneeExpressionNoRE
1158 : LeftHandSideExpressionNoRE { $$ = $1; }
1159 | UnaryAssigneeExpression { $$ = $1; }
1160 ;
9cad30fa 1161@end
b1589845 1162
36cd3cb9 1163AssignmentExpression
cf7d4c69 1164 : ConditionalExpression { $$ = $1; }
9b5527f0 1165 | AssigneeExpression AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
36cd3cb9
JF
1166 ;
1167
693d501b
JF
1168AssignmentExpressionNoIn
1169 : ConditionalExpressionNoIn { $$ = $1; }
9b5527f0
JF
1170 | AssigneeExpression "=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAssign($1, $3); }
1171 | AssigneeExpression "*=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYMultiplyAssign($1, $3); }
1172 | AssigneeExpression "/=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYDivideAssign($1, $3); }
1173 | AssigneeExpression "%=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYModulusAssign($1, $3); }
1174 | AssigneeExpression "+=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYAddAssign($1, $3); }
1175 | AssigneeExpression "-=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYSubtractAssign($1, $3); }
1176 | AssigneeExpression "<<=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftLeftAssign($1, $3); }
1177 | AssigneeExpression ">>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightSignedAssign($1, $3); }
1178 | AssigneeExpression ">>>=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYShiftRightUnsignedAssign($1, $3); }
1179 | AssigneeExpression "&=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseAndAssign($1, $3); }
1180 | AssigneeExpression "^=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseXOrAssign($1, $3); }
1181 | AssigneeExpression "|=" AssignmentExpressionNoIn { $$ = new(driver.pool_) CYBitwiseOrAssign($1, $3); }
693d501b
JF
1182 ;
1183
1184AssignmentExpressionNoBF
1185 : ConditionalExpressionNoBF { $$ = $1; }
9b5527f0 1186 | AssigneeExpressionNoBF AssignmentExpression_ { $2->SetLeft($1); $$ = $2; }
693d501b 1187 ;
63cd45c9
JF
1188/* }}} */
1189/* 11.14 Comma Operator {{{ */
36cd3cb9 1190Expression_
d35a3b07 1191 : "," Expression { $$ = new(driver.pool_) CYCompound($2); }
cf7d4c69 1192 | { $$ = NULL; }
1dbba6cc
JF
1193 ;
1194
693d501b 1195ExpressionNoIn_
d35a3b07 1196 : "," ExpressionNoIn { $$ = new(driver.pool_) CYCompound($2); }
693d501b
JF
1197 | { $$ = NULL; }
1198 ;
1199
36cd3cb9 1200ExpressionOpt
cf7d4c69 1201 : Expression { $$ = $1; }
691e4717 1202 | LexSetRegExp { $$ = NULL; }
1dbba6cc
JF
1203 ;
1204
693d501b
JF
1205ExpressionNoInOpt
1206 : ExpressionNoIn { $$ = $1; }
691e4717 1207 | LexSetRegExp { $$ = NULL; }
693d501b
JF
1208 ;
1209
36cd3cb9 1210Expression
d35a3b07 1211 : AssignmentExpression Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
1dbba6cc
JF
1212 ;
1213
693d501b 1214ExpressionNoIn
d35a3b07 1215 : AssignmentExpressionNoIn ExpressionNoIn_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
693d501b
JF
1216 ;
1217
1218ExpressionNoBF
d35a3b07 1219 : AssignmentExpressionNoBF Expression_ { if ($2) { $2->AddPrev($1); $$ = $2; } else $$ = $1; }
693d501b 1220 ;
63cd45c9 1221/* }}} */
693d501b 1222
63cd45c9 1223/* 12 Statements {{{ */
b10bd496 1224Statement_
36cd3cb9
JF
1225 : Block { $$ = $1; }
1226 | VariableStatement { $$ = $1; }
1227 | EmptyStatement { $$ = $1; }
1228 | ExpressionStatement { $$ = $1; }
cf7d4c69
JF
1229 | IfStatement { $$ = $1; }
1230 | IterationStatement { $$ = $1; }
36cd3cb9
JF
1231 | ContinueStatement { $$ = $1; }
1232 | BreakStatement { $$ = $1; }
1233 | ReturnStatement { $$ = $1; }
cf7d4c69
JF
1234 | WithStatement { $$ = $1; }
1235 | LabelledStatement { $$ = $1; }
36cd3cb9
JF
1236 | SwitchStatement { $$ = $1; }
1237 | ThrowStatement { $$ = $1; }
1238 | TryStatement { $$ = $1; }
1dbba6cc 1239 ;
b10bd496
JF
1240
1241Statement
691e4717 1242 : LexSetRegExp Statement_ { $$ = $2; }
b10bd496 1243 ;
63cd45c9
JF
1244/* }}} */
1245/* 12.1 Block {{{ */
cac61857
JF
1246Block_
1247 : "{" StatementListOpt "}" { $$ = $2; }
1248 ;
1249
36cd3cb9 1250Block
cac61857 1251 : Block_ { if ($1) $$ = new(driver.pool_) CYBlock($1); else $$ = new(driver.pool_) CYEmpty(); }
1dbba6cc
JF
1252 ;
1253
693d501b 1254StatementList
cf7d4c69 1255 : Statement StatementListOpt { $1->SetNext($2); $$ = $1; }
693d501b
JF
1256 ;
1257
1258StatementListOpt
1259 : StatementList { $$ = $1; }
691e4717 1260 | LexSetRegExp { $$ = NULL; }
1dbba6cc 1261 ;
63cd45c9
JF
1262/* }}} */
1263/* 12.2 Variable Statement {{{ */
36cd3cb9 1264VariableStatement
cac61857 1265 : "var" VariableDeclarationList Terminator { $$ = new(driver.pool_) CYVar($2); }
1dbba6cc
JF
1266 ;
1267
36cd3cb9 1268VariableDeclarationList_
cf7d4c69
JF
1269 : "," VariableDeclarationList { $$ = $2; }
1270 | { $$ = NULL; }
1dbba6cc
JF
1271 ;
1272
693d501b
JF
1273VariableDeclarationListNoIn_
1274 : "," VariableDeclarationListNoIn { $$ = $2; }
1275 | { $$ = NULL; }
1276 ;
1277
36cd3cb9 1278VariableDeclarationList
b1ff2d78 1279 : VariableDeclaration VariableDeclarationList_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1dbba6cc
JF
1280 ;
1281
693d501b
JF
1282VariableDeclarationListNoIn
1283 : VariableDeclarationNoIn VariableDeclarationListNoIn_ { $$ = new(driver.pool_) CYDeclarations($1, $2); }
1284 ;
1285
36cd3cb9
JF
1286VariableDeclaration
1287 : Identifier InitialiserOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1dbba6cc
JF
1288 ;
1289
693d501b
JF
1290VariableDeclarationNoIn
1291 : Identifier InitialiserNoInOpt { $$ = new(driver.pool_) CYDeclaration($1, $2); }
1292 ;
1293
36cd3cb9 1294InitialiserOpt
cf7d4c69 1295 : Initialiser { $$ = $1; }
36cd3cb9 1296 | { $$ = NULL; }
1dbba6cc
JF
1297 ;
1298
693d501b
JF
1299InitialiserNoInOpt
1300 : InitialiserNoIn { $$ = $1; }
1301 | { $$ = NULL; }
1302 ;
1303
36cd3cb9
JF
1304Initialiser
1305 : "=" AssignmentExpression { $$ = $2; }
1dbba6cc
JF
1306 ;
1307
693d501b
JF
1308InitialiserNoIn
1309 : "=" AssignmentExpressionNoIn { $$ = $2; }
1310 ;
63cd45c9
JF
1311/* }}} */
1312/* 12.3 Empty Statement {{{ */
36cd3cb9 1313EmptyStatement
b1ff2d78 1314 : ";" { $$ = new(driver.pool_) CYEmpty(); }
1dbba6cc 1315 ;
63cd45c9
JF
1316/* }}} */
1317/* 12.4 Expression Statement {{{ */
36cd3cb9 1318ExpressionStatement
693d501b 1319 : ExpressionNoBF Terminator { $$ = new(driver.pool_) CYExpress($1); }
1dbba6cc 1320 ;
63cd45c9
JF
1321/* }}} */
1322/* 12.5 The if Statement {{{ */
36cd3cb9
JF
1323ElseStatementOpt
1324 : "else" Statement { $$ = $2; }
c3c20102 1325 | %prec "if" { $$ = NULL; }
1dbba6cc
JF
1326 ;
1327
36cd3cb9
JF
1328IfStatement
1329 : "if" "(" Expression ")" Statement ElseStatementOpt { $$ = new(driver.pool_) CYIf($3, $5, $6); }
1dbba6cc 1330 ;
63cd45c9 1331/* }}} */
1dbba6cc 1332
63cd45c9 1333/* 12.6 Iteration Statements {{{ */
36cd3cb9
JF
1334IterationStatement
1335 : DoWhileStatement { $$ = $1; }
cf7d4c69
JF
1336 | WhileStatement { $$ = $1; }
1337 | ForStatement { $$ = $1; }
1338 | ForInStatement { $$ = $1; }
1dbba6cc 1339 ;
63cd45c9
JF
1340/* }}} */
1341/* 12.6.1 The do-while Statement {{{ */
36cd3cb9
JF
1342DoWhileStatement
1343 : "do" Statement "while" "(" Expression ")" TerminatorOpt { $$ = new(driver.pool_) CYDoWhile($5, $2); }
1dbba6cc 1344 ;
63cd45c9
JF
1345/* }}} */
1346/* 12.6.2 The while Statement {{{ */
36cd3cb9
JF
1347WhileStatement
1348 : "while" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWhile($3, $5); }
1dbba6cc 1349 ;
63cd45c9
JF
1350/* }}} */
1351/* 12.6.3 The for Statement {{{ */
36cd3cb9
JF
1352ForStatement
1353 : "for" "(" ForStatementInitialiser ";" ExpressionOpt ";" ExpressionOpt ")" Statement { $$ = new(driver.pool_) CYFor($3, $5, $7, $9); }
1dbba6cc
JF
1354 ;
1355
36cd3cb9 1356ForStatementInitialiser
693d501b 1357 : ExpressionNoInOpt { $$ = $1; }
691e4717 1358 | LexSetRegExp "var" VariableDeclarationListNoIn { $$ = $3; }
1dbba6cc 1359 ;
63cd45c9
JF
1360/* }}} */
1361/* 12.6.4 The for-in Statement {{{ */
36cd3cb9
JF
1362ForInStatement
1363 : "for" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForIn($3, $5, $7); }
1dbba6cc
JF
1364 ;
1365
36cd3cb9
JF
1366ForInStatementInitialiser
1367 : LeftHandSideExpression { $$ = $1; }
691e4717 1368 | LexSetRegExp "var" VariableDeclarationNoIn { $$ = $3; }
1dbba6cc 1369 ;
63cd45c9 1370/* }}} */
1dbba6cc 1371
63cd45c9 1372/* 12.7 The continue Statement {{{ */
36cd3cb9
JF
1373ContinueStatement
1374 : "continue" IdentifierOpt Terminator { $$ = new(driver.pool_) CYContinue($2); }
1dbba6cc 1375 ;
63cd45c9
JF
1376/* }}} */
1377/* 12.8 The break Statement {{{ */
36cd3cb9
JF
1378BreakStatement
1379 : "break" IdentifierOpt Terminator { $$ = new(driver.pool_) CYBreak($2); }
1dbba6cc 1380 ;
63cd45c9
JF
1381/* }}} */
1382/* 12.9 The return Statement {{{ */
36cd3cb9 1383ReturnStatement
c3c20102 1384 : "return" ExpressionOpt Terminator { $$ = new(driver.pool_) CYReturn($2); }
1dbba6cc 1385 ;
63cd45c9
JF
1386/* }}} */
1387/* 12.10 The with Statement {{{ */
36cd3cb9
JF
1388WithStatement
1389 : "with" "(" Expression ")" Statement { $$ = new(driver.pool_) CYWith($3, $5); }
1dbba6cc 1390 ;
63cd45c9 1391/* }}} */
1dbba6cc 1392
63cd45c9 1393/* 12.11 The switch Statement {{{ */
36cd3cb9
JF
1394SwitchStatement
1395 : "switch" "(" Expression ")" CaseBlock { $$ = new(driver.pool_) CYSwitch($3, $5); }
1dbba6cc
JF
1396 ;
1397
1398CaseBlock
36cd3cb9 1399 : "{" CaseClausesOpt "}" { $$ = $2; }
1dbba6cc
JF
1400 ;
1401
36cd3cb9 1402CaseClausesOpt
cf7d4c69
JF
1403 : CaseClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1404 | DefaultClause CaseClausesOpt { $1->SetNext($2); $$ = $1; }
1405 | { $$ = NULL; }
1dbba6cc
JF
1406 ;
1407
36cd3cb9
JF
1408CaseClause
1409 : "case" Expression ":" StatementListOpt { $$ = new(driver.pool_) CYClause($2, $4); }
1dbba6cc
JF
1410 ;
1411
36cd3cb9
JF
1412DefaultClause
1413 : "default" ":" StatementListOpt { $$ = new(driver.pool_) CYClause(NULL, $3); }
1dbba6cc 1414 ;
63cd45c9
JF
1415/* }}} */
1416/* 12.12 Labelled Statements {{{ */
36cd3cb9 1417LabelledStatement
3b52fd1a 1418 : Identifier ":" Statement { $$ = new(driver.pool_) CYLabel($1, $3); }
1dbba6cc 1419 ;
63cd45c9
JF
1420/* }}} */
1421/* 12.13 The throw Statement {{{ */
36cd3cb9 1422ThrowStatement
37954781 1423 : "throw" Expression Terminator { $$ = new(driver.pool_) cy::Syntax::Throw($2); }
1dbba6cc 1424 ;
63cd45c9
JF
1425/* }}} */
1426/* 12.14 The try Statement {{{ */
36cd3cb9 1427TryStatement
37954781 1428 : "try" Block_ CatchOpt FinallyOpt { $$ = new(driver.pool_) cy::Syntax::Try($2, $3, $4); }
1dbba6cc
JF
1429 ;
1430
1431CatchOpt
37954781 1432 : "catch" "(" Identifier ")" Block_ { $$ = new(driver.pool_) cy::Syntax::Catch($3, $5); }
cf7d4c69 1433 | { $$ = NULL; }
1dbba6cc
JF
1434 ;
1435
1436FinallyOpt
b10bd496 1437 : "finally" Block_ { $$ = new(driver.pool_) CYFinally($2); }
cf7d4c69 1438 | { $$ = NULL; }
1dbba6cc 1439 ;
63cd45c9 1440/* }}} */
1dbba6cc 1441
63cd45c9 1442/* 13 Function Definition {{{ */
36cd3cb9 1443FunctionDeclaration
fb98ac0c 1444 : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionStatement($2, $4, $7); }
1dbba6cc
JF
1445 ;
1446
36cd3cb9 1447FunctionExpression
b1589845 1448 : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($2, $4, $7); }
1dbba6cc
JF
1449 ;
1450
1451FormalParameterList_
36cd3cb9 1452 : "," FormalParameterList { $$ = $2; }
cf7d4c69 1453 | { $$ = NULL; }
1dbba6cc
JF
1454 ;
1455
1456FormalParameterList
b09da87b 1457 : Identifier FormalParameterList_ { $$ = new(driver.pool_) CYFunctionParameter($1, $2); }
cf7d4c69 1458 | { $$ = NULL; }
1dbba6cc
JF
1459 ;
1460
36cd3cb9
JF
1461FunctionBody
1462 : SourceElements { $$ = $1; }
1dbba6cc 1463 ;
63cd45c9
JF
1464/* }}} */
1465/* 14 Program {{{ */
1dbba6cc 1466Program
3b52fd1a 1467 : SourceElements { driver.program_ = new(driver.pool_) CYProgram($1); }
1dbba6cc
JF
1468 ;
1469
36cd3cb9
JF
1470SourceElements
1471 : SourceElement SourceElements { $1->SetNext($2); $$ = $1; }
691e4717 1472 | LexSetRegExp { $$ = NULL; }
1dbba6cc
JF
1473 ;
1474
697d6fd2 1475SourceElement_
b10bd496 1476 : Statement_ { $$ = $1; }
36cd3cb9 1477 | FunctionDeclaration { $$ = $1; }
1dbba6cc 1478 ;
697d6fd2
JF
1479
1480SourceElement
691e4717 1481 : LexSetRegExp SourceElement_ { $$ = $2; }
697d6fd2 1482 ;
63cd45c9 1483/* }}} */
e5332278 1484
cbaa5f0f 1485@begin ObjectiveC
4de0686f 1486/* Cycript (Objective-C): @class Declaration {{{ */
b09da87b 1487ClassSuperOpt
697d6fd2 1488 /* XXX: why the hell did I choose MemberExpressionNoBF? */
691e4717 1489 : ":" LexSetRegExp MemberExpressionNoBF { $$ = $3; }
b09da87b
JF
1490 | { $$ = NULL; }
1491 ;
1492
1493ClassFieldList
1494 : "{" "}" { $$ = NULL; }
1495 ;
1496
1497MessageScope
1498 : "+" { $$ = false; }
1499 | "-" { $$ = true; }
1500 ;
1501
1502TypeOpt
1503 : "(" Expression ")" { $$ = $2; }
1504 | { $$ = NULL; }
1505 ;
1506
1507MessageParameter
75b0a457 1508 : Word ":" TypeOpt Identifier { $$ = new(driver.pool_) CYMessageParameter($1, $3, $4); }
b09da87b
JF
1509 ;
1510
1511MessageParameterListOpt
1512 : MessageParameterList { $$ = $1; }
1513 | { $$ = NULL; }
1514 ;
1515
1516MessageParameterList
1517 : MessageParameter MessageParameterListOpt { $1->SetNext($2); $$ = $1; }
1518 ;
1519
1520MessageParameters
1521 : MessageParameterList { $$ = $1; }
75b0a457 1522 | Word { $$ = new(driver.pool_) CYMessageParameter($1, NULL, NULL); }
b09da87b
JF
1523 ;
1524
1525ClassMessageDeclaration
75b0a457 1526 : MessageScope TypeOpt MessageParameters "{" FunctionBody "}" { $$ = new(driver.pool_) CYMessage($1, $2, $3, $5); }
b09da87b
JF
1527 ;
1528
1529ClassMessageDeclarationListOpt
4e8c99fb 1530 : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
b09da87b
JF
1531 | { $$ = NULL; }
1532 ;
1533
e5bc40db
JF
1534ClassName
1535 : Identifier { $$ = $1; }
1536 | "(" AssignmentExpression ")" { $$ = $2; }
1537 ;
1538
367eebb1
JF
1539ClassNameOpt
1540 : ClassName { $$ = $1; }
1541 | { $$ = NULL; }
b09da87b
JF
1542 ;
1543
fb98ac0c
JF
1544ClassExpression
1545 : "@class" ClassNameOpt ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassExpression($2, $3, $4, $5); }
1546 ;
1547
1548ClassStatement
1549 : "@class" ClassName ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassStatement($2, $3, $4, $5); }
367eebb1
JF
1550 ;
1551
1552CategoryStatement
75b0a457 1553 : "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); }
367eebb1
JF
1554 ;
1555
561ac418 1556PrimaryExpressionBF
fb98ac0c 1557 : ClassExpression { $$ = $1; }
367eebb1
JF
1558 ;
1559
b10bd496 1560Statement_
fb98ac0c 1561 : ClassStatement { $$ = $1; }
365abb0a 1562 | CategoryStatement { $$ = $1; }
b09da87b 1563 ;
cac61857 1564/* }}} */
4de0686f 1565/* Cycript (Objective-C): Send Message {{{ */
693d501b
JF
1566VariadicCall
1567 : "," AssignmentExpression VariadicCall { $$ = new(driver.pool_) CYArgument(NULL, $2, $3); }
1568 | { $$ = NULL; }
1569 ;
1570
1571SelectorCall_
1572 : SelectorCall { $$ = $1; }
1573 | VariadicCall { $$ = $1; }
1574 ;
1575
1576SelectorCall
1577 : WordOpt ":" AssignmentExpression SelectorCall_ { $$ = new(driver.pool_) CYArgument($1 ?: new(driver.pool_) CYBlank(), $3, $4); }
1578 ;
1579
1580SelectorList
1581 : SelectorCall { $$ = $1; }
1582 | Word { $$ = new(driver.pool_) CYArgument($1, NULL); }
1583 ;
1584
1585MessageExpression
fdb013ca 1586 : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYSendDirect($2, $3); }
691e4717 1587 | "[" LexSetRegExp "super" SelectorList "]" { $$ = new(driver.pool_) CYSendSuper($4); }
693d501b
JF
1588 ;
1589
e7ed5354
JF
1590SelectorExpressionOpt
1591 : SelectorExpression_ { $$ = $1; }
1592 | { $$ = NULL; }
1593 ;
1594
1595SelectorExpression_
62014ea9 1596 : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelectorPart($1, true, $3); }
e7ed5354
JF
1597 ;
1598
1599SelectorExpression
1600 : SelectorExpression_ { $$ = $1; }
62014ea9 1601 | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); }
e7ed5354
JF
1602 ;
1603
561ac418 1604PrimaryExpressionNo
693d501b 1605 : MessageExpression { $$ = $1; }
75b0a457 1606 | "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); }
693d501b
JF
1607 ;
1608/* }}} */
4de0686f
JF
1609@end
1610
1611@begin C
1612/* Cycript (C): Pointer Indirection/Addressing {{{ */
697d6fd2 1613UnaryAssigneeExpression
b1589845 1614 : "*" UnaryExpressionNoRE { $$ = new(driver.pool_) CYIndirect($2); }
693d501b
JF
1615 ;
1616
1617UnaryExpression_
1618 : "&" UnaryExpression { $$ = new(driver.pool_) CYAddressOf($2); }
1619 ;
1620
9b5527f0 1621MemberAccess
3b52fd1a
JF
1622 : "->" "[" Expression "]" { $$ = new(driver.pool_) CYIndirectMember(NULL, $3); }
1623 | "->" Identifier { $$ = new(driver.pool_) CYIndirectMember(NULL, new(driver.pool_) CYString($2)); }
9b5527f0 1624 ;
cac61857 1625/* }}} */
4de0686f
JF
1626@end
1627
320ce753
JF
1628/* YUI: Documentation Comments {{{ */
1629Statement_
1630 : Comment { $$ = $1; }
1631 ;
1632/* }}} */
1633
cb02f8ae 1634@begin E4X
691e4717
JF
1635/* Lexer State {{{ */
1636LexPushRegExp
1637 : { driver.PushCondition(CYDriver::RegExpCondition); }
1638 ;
1639
1640LexPushXMLContent
1641 : { driver.PushCondition(CYDriver::XMLContentCondition); }
1642 ;
1643
1644LexPushXMLTag
1645 : { driver.PushCondition(CYDriver::XMLTagCondition); }
1646 ;
1647
1648LexPop
1649 : { driver.PopCondition(); }
1650 ;
1651
1652LexSetXMLContent
1653 : { driver.SetCondition(CYDriver::XMLContentCondition); }
1654 ;
1655
1656LexSetXMLTag
1657 : { driver.SetCondition(CYDriver::XMLTagCondition); }
1658 ;
1659/* }}} */
1660
1661XMLWhitespaceOpt
1662 : XMLWhitespace
1663 |
1664 ;
1665
1666/* 8.1 Context Keywords {{{ */
1667Identifier
1668 : "namespace" { $$ = $1; }
1669 | "xml" { $$ = $1; }
1670 ;
1671/* }}} */
cb02f8ae
JF
1672/* 8.3 XML Initialiser Input Elements {{{ */
1673XMLMarkup
691e4717
JF
1674 : XMLComment { $$ = $1; }
1675 | XMLCDATA { $$ = $1; }
1676 | XMLPI { $$ = $1; }
cb02f8ae
JF
1677 ;
1678/* }}} */
1679/* 11.1 Primary Expressions {{{ */
fdb013ca 1680PrimaryExpressionNo
b92ceddb 1681 : PropertyIdentifier { $$ = new(driver.pool_) CYPropertyVariable($1); }
691e4717
JF
1682 | XMLInitialiser { $$ = $1; }
1683 | XMLListInitialiser { $$ = $1; }
cb02f8ae
JF
1684 ;
1685
1686PropertyIdentifier
691e4717
JF
1687 : AttributeIdentifier { $$ = $1; }
1688 | QualifiedIdentifier { $$ = $1; }
1689 | WildcardIdentifier { $$ = $1; }
cb02f8ae
JF
1690 ;
1691/* }}} */
1692/* 11.1.1 Attribute Identifiers {{{ */
1693AttributeIdentifier
691e4717
JF
1694 : "@" QualifiedIdentifier_ { $$ = new(driver.pool_) CYAttribute($2); }
1695 ;
1696
1697PropertySelector_
b92ceddb
JF
1698 : PropertySelector { $$ = $1; }
1699 | "[" Expression "]" { $$ = new(driver.pool_) CYSelector($2); }
cb02f8ae
JF
1700 ;
1701
1702PropertySelector
b92ceddb 1703 : Identifier { $$ = new(driver.pool_) CYSelector($1); }
691e4717 1704 | WildcardIdentifier { $$ = $1; }
cb02f8ae
JF
1705 ;
1706/* }}} */
1707/* 11.1.2 Qualified Identifiers {{{ */
691e4717 1708QualifiedIdentifier_
b92ceddb 1709 : PropertySelector_ { $$ = new(driver.pool_) CYQualified(NULL, $1); }
691e4717
JF
1710 | QualifiedIdentifier { $$ = $1; }
1711 ;
1712
cb02f8ae 1713QualifiedIdentifier
b92ceddb 1714 : PropertySelector "::" PropertySelector_ { $$ = new(driver.pool_) CYQualified($1, $3); }
cb02f8ae
JF
1715 ;
1716/* }}} */
1717/* 11.1.3 Wildcard Identifiers {{{ */
1718WildcardIdentifier
691e4717 1719 : "*" { $$ = new(driver.pool_) CYWildcard(); }
cb02f8ae
JF
1720 ;
1721/* }}} */
1722/* 11.1.4 XML Initialiser {{{ */
1723XMLInitialiser
691e4717
JF
1724 : XMLMarkup { $$ = $1; }
1725 | XMLElement { $$ = $1; }
cb02f8ae
JF
1726 ;
1727
1728XMLElement
0347fadf
JF
1729 : "<" XMLTagContent "/>" LexPop
1730 | "<" XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt ">" LexPop
cb02f8ae
JF
1731 ;
1732
1733XMLTagContent
0347fadf 1734 : LexPushXMLTag XMLTagName XMLAttributes
cb02f8ae
JF
1735 ;
1736
691e4717
JF
1737XMLExpression
1738 : "{" LexPushRegExp Expression "}" LexPop
1739 ;
1740
cb02f8ae 1741XMLTagName
691e4717 1742 : XMLExpression
cb02f8ae
JF
1743 | XMLName
1744 ;
1745
0347fadf
JF
1746XMLAttributes_
1747 : XMLAttributes_ XMLAttribute
1748 |
cb02f8ae
JF
1749 ;
1750
0347fadf
JF
1751XMLAttributes
1752 : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt
1753 | XMLAttributes_ XMLWhitespaceOpt
cb02f8ae
JF
1754 ;
1755
691e4717
JF
1756XMLAttributeValue_
1757 : XMLExpression
1758 | XMLAttributeValue
1759 ;
1760
cb02f8ae 1761XMLAttribute
691e4717 1762 : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_
cb02f8ae
JF
1763 ;
1764
cb02f8ae 1765XMLElementContent
691e4717 1766 : XMLExpression XMLElementContentOpt
cb02f8ae
JF
1767 | XMLMarkup XMLElementContentOpt
1768 | XMLText XMLElementContentOpt
1769 | XMLElement XMLElementContentOpt
1770 ;
1771
1772XMLElementContentOpt
1773 : XMLElementContent
1774 |
1775 ;
1776/* }}} */
1777/* 11.1.5 XMLList Initialiser {{{ */
1778XMLListInitialiser
691e4717
JF
1779 : "<>" LexPushXMLContent XMLElementContent "</>" LexPop { $$ = new(driver.pool_) CYXMLList($3); }
1780 ;
1781/* }}} */
1782/* 11.2 Left-Hand-Side Expressions {{{ */
1783PropertyIdentifier_
0347fadf 1784 : Identifier { $$ = $1; }
691e4717
JF
1785 | PropertyIdentifier { $$ = $1; }
1786 ;
1787
1788MemberAccess
1789 : "." PropertyIdentifier { $$ = new(driver.pool_) CYPropertyMember(NULL, $2); }
1790 | ".." PropertyIdentifier_ { $$ = new(driver.pool_) CYDescendantMember(NULL, $2); }
1791 | "." "(" Expression ")" { $$ = new(driver.pool_) CYFilteringPredicate(NULL, $3); }
1792 ;
1793/* }}} */
1794/* 12.1 The default xml namespace Statement {{{ */
b92ceddb 1795/* XXX: DefaultXMLNamespaceStatement
691e4717
JF
1796 : "default" "xml" "namespace" "=" Expression Terminator { $$ = new(driver.pool_) CYDefaultXMLNamespace($5); }
1797 ;
1798
1799Statement_
1800 : DefaultXMLNamespaceStatement { $$ = $1; }
b92ceddb 1801 ; */
cb02f8ae
JF
1802/* }}} */
1803@end
1804
cac61857
JF
1805/* ECMAScript5: Object Literal Trailing Comma {{{ */
1806PropertyNameAndValueList_
1807 : "," { $$ = NULL; }
1808 ;
1809/* }}} */
1810/* JavaScript 1.7: Array Comprehensions {{{ */
367eebb1 1811IfComprehension
75b0a457 1812 : "if" "(" Expression ")" { $$ = new(driver.pool_) CYIfComprehension($3); }
367eebb1
JF
1813 ;
1814
1815ForComprehension
75b0a457
JF
1816 : "for" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForInComprehension($3, $5); }
1817 | "for" "each" "(" Identifier "in" Expression ")" { $$ = new(driver.pool_) CYForEachInComprehension($4, $6); }
367eebb1
JF
1818 ;
1819
1820ComprehensionListOpt
75b0a457
JF
1821 : ComprehensionList { $$ = $1; }
1822 | IfComprehension { $$ = $1; }
1823 | { $$ = NULL; }
367eebb1
JF
1824 ;
1825
1826ComprehensionList
75b0a457 1827 : ForComprehension ComprehensionListOpt { $1->SetNext($2); $$ = $1; }
367eebb1
JF
1828 ;
1829
561ac418 1830PrimaryExpressionNo
75b0a457 1831 : "[" AssignmentExpression ComprehensionList "]" { $$ = new(driver.pool_) CYArrayComprehension($2, $3); }
367eebb1 1832 ;
cac61857
JF
1833/* }}} */
1834/* JavaScript 1.7: for each {{{ */
1835ForInStatement
1836 : "for" "each" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForEachIn($4, $6, $8); }
1837 ;
1838/* }}} */
b10bd496 1839/* JavaScript 1.7: let Statements {{{ *//*
cac61857
JF
1840LetStatement
1841 : "let" "(" VariableDeclarationList ")" Block_ { $$ = new(driver.pool_) CYLet($3, $5); }
1842 ;
1843
697d6fd2 1844Statement_
cac61857
JF
1845 : LetStatement
1846 ;
534fb6da 1847*//* }}} */
b10bd496
JF
1848/* JavaScript FTW: Function Statements {{{ */
1849Statement
691e4717 1850 : LexSetRegExp FunctionDeclaration { driver.Warning(yylloc, "warning, FunctionDeclaration is a SourceElement, not a Statement"); } { $$ = $2; }
b10bd496
JF
1851 ;
1852/* }}} */
367eebb1 1853
e5332278 1854%%