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