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