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