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