4 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
5 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "CommonIdentifiers.h"
37 #include <wtf/MathExtras.h>
39 // Not sure why, but yacc doesn't add this define along with the others.
40 #define yylloc kjsyylloc
42 #define YYMAXDEPTH 10000
43 #define YYENABLE_NLS 0
45 /* default values for bison */
46 #define YYDEBUG 0 // Set to 1 to debug a parse error.
47 #define kjsyydebug 0 // Set to 1 to debug a parse error.
49 // avoid triggering warnings in older bison
50 #define YYERROR_VERBOSE
53 extern int kjsyylex();
54 int kjsyyerror(const char *);
55 static bool allowAutomaticSemicolon();
57 #define AUTO_SEMICOLON do { if (!allowAutomaticSemicolon()) YYABORT; } while (0)
58 #define DBG(l, s, e) (l)->setLoc((s).first_line, (e).last_line)
63 static AddNode* makeAddNode(ExpressionNode*, ExpressionNode*);
64 static LessNode* makeLessNode(ExpressionNode*, ExpressionNode*);
65 static ExpressionNode* makeAssignNode(ExpressionNode* loc, Operator, ExpressionNode* expr);
66 static ExpressionNode* makePrefixNode(ExpressionNode* expr, Operator);
67 static ExpressionNode* makePostfixNode(ExpressionNode* expr, Operator);
68 static PropertyNode* makeGetterOrSetterPropertyNode(const Identifier &getOrSet, const Identifier& name, ParameterNode*, FunctionBodyNode*, const SourceCode&);
69 static ExpressionNode* makeFunctionCallNode(ExpressionNode* func, ArgumentsNode*);
70 static ExpressionNode* makeTypeOfNode(ExpressionNode*);
71 static ExpressionNode* makeDeleteNode(ExpressionNode*);
72 static ExpressionNode* makeNegateNode(ExpressionNode*);
73 static NumberNode* makeNumberNode(double);
74 static StatementNode* makeVarStatementNode(ExpressionNode*);
75 static ExpressionNode* combineVarInitializers(ExpressionNode* list, AssignResolveNode* init);
80 #pragma warning(disable: 4065)
81 #pragma warning(disable: 4244)
82 #pragma warning(disable: 4702)
84 // At least some of the time, the declarations of malloc and free that bison
85 // generates are causing warnings. A way to avoid this is to explicitly define
86 // the macros so that bison doesn't try to declare malloc and free.
87 #define YYMALLOC malloc
92 template <typename T> NodeInfo<T> createNodeInfo(T node, ParserRefCountedData<DeclarationStacks::VarStack>* varDecls,
93 ParserRefCountedData<DeclarationStacks::FunctionStack>* funcDecls)
95 NodeInfo<T> result = {node, varDecls, funcDecls};
99 template <typename T> T mergeDeclarationLists(T decls1, T decls2)
101 // decls1 or both are null
104 // only decls1 is non-null
109 decls1->data.append(decls2->data);
111 // We manually release the declaration lists to avoid accumulating many many
112 // unused heap allocated vectors
118 static void appendToVarDeclarationList(ParserRefCountedData<DeclarationStacks::VarStack>*& varDecls, const Identifier& ident, unsigned attrs)
121 varDecls = new ParserRefCountedData<DeclarationStacks::VarStack>;
123 varDecls->data.append(make_pair(ident, attrs));
127 static inline void appendToVarDeclarationList(ParserRefCountedData<DeclarationStacks::VarStack>*& varDecls, ConstDeclNode* decl)
129 unsigned attrs = DeclarationStacks::IsConstant;
131 attrs |= DeclarationStacks::HasInitializer;
132 appendToVarDeclarationList(varDecls, decl->m_ident, attrs);
143 // expression subtrees
144 ExpressionNode* expressionNode;
145 FuncDeclNode* funcDeclNode;
146 PropertyNode* propertyNode;
147 ArgumentsNode* argumentsNode;
148 ConstDeclNode* constDeclNode;
149 CaseBlockNodeInfo caseBlockNode;
150 CaseClauseNodeInfo caseClauseNode;
151 FuncExprNode* funcExprNode;
154 StatementNodeInfo statementNode;
155 FunctionBodyNode* functionBodyNode;
156 ProgramNode* programNode;
158 SourceElementsInfo sourceElements;
159 PropertyList propertyList;
160 ArgumentList argumentList;
161 VarDeclListInfo varDeclList;
162 ConstDeclListInfo constDeclList;
163 ClauseListInfo clauseList;
164 ElementList elementList;
165 ParameterList parameterList;
173 %token NULLTOKEN TRUETOKEN FALSETOKEN
176 %token BREAK CASE DEFAULT FOR NEW VAR CONSTTOKEN CONTINUE
177 %token FUNCTION RETURN VOIDTOKEN DELETETOKEN
178 %token IF THISTOKEN DO WHILE INTOKEN INSTANCEOF TYPEOF
179 %token SWITCH WITH RESERVED
180 %token THROW TRY CATCH FINALLY
183 /* give an if without an else higher precedence than an else to resolve the ambiguity */
184 %nonassoc IF_WITHOUT_ELSE
188 %token EQEQ NE /* == and != */
189 %token STREQ STRNEQ /* === and !== */
190 %token LE GE /* < and > */
191 %token OR AND /* || and && */
192 %token PLUSPLUS MINUSMINUS /* ++ and -- */
193 %token LSHIFT /* << */
194 %token RSHIFT URSHIFT /* >> and >>> */
195 %token PLUSEQUAL MINUSEQUAL /* += and -= */
196 %token MULTEQUAL DIVEQUAL /* *= and /= */
197 %token LSHIFTEQUAL /* <<= */
198 %token RSHIFTEQUAL URSHIFTEQUAL /* >>= and >>>= */
199 %token ANDEQUAL MODEQUAL /* &= and %= */
200 %token XOREQUAL OREQUAL /* ^= and |= */
201 %token <intValue> OPENBRACE /* { (with char offset) */
202 %token <intValue> CLOSEBRACE /* { (with char offset) */
205 %token <doubleValue> NUMBER
206 %token <string> STRING
209 /* automatically inserted semicolon */
210 %token AUTOPLUSPLUS AUTOMINUSMINUS
212 /* non-terminal types */
213 %type <expressionNode> Literal ArrayLiteral
215 %type <expressionNode> PrimaryExpr PrimaryExprNoBrace
216 %type <expressionNode> MemberExpr MemberExprNoBF /* BF => brace or function */
217 %type <expressionNode> NewExpr NewExprNoBF
218 %type <expressionNode> CallExpr CallExprNoBF
219 %type <expressionNode> LeftHandSideExpr LeftHandSideExprNoBF
220 %type <expressionNode> PostfixExpr PostfixExprNoBF
221 %type <expressionNode> UnaryExpr UnaryExprNoBF UnaryExprCommon
222 %type <expressionNode> MultiplicativeExpr MultiplicativeExprNoBF
223 %type <expressionNode> AdditiveExpr AdditiveExprNoBF
224 %type <expressionNode> ShiftExpr ShiftExprNoBF
225 %type <expressionNode> RelationalExpr RelationalExprNoIn RelationalExprNoBF
226 %type <expressionNode> EqualityExpr EqualityExprNoIn EqualityExprNoBF
227 %type <expressionNode> BitwiseANDExpr BitwiseANDExprNoIn BitwiseANDExprNoBF
228 %type <expressionNode> BitwiseXORExpr BitwiseXORExprNoIn BitwiseXORExprNoBF
229 %type <expressionNode> BitwiseORExpr BitwiseORExprNoIn BitwiseORExprNoBF
230 %type <expressionNode> LogicalANDExpr LogicalANDExprNoIn LogicalANDExprNoBF
231 %type <expressionNode> LogicalORExpr LogicalORExprNoIn LogicalORExprNoBF
232 %type <expressionNode> ConditionalExpr ConditionalExprNoIn ConditionalExprNoBF
233 %type <expressionNode> AssignmentExpr AssignmentExprNoIn AssignmentExprNoBF
234 %type <expressionNode> Expr ExprNoIn ExprNoBF
236 %type <expressionNode> ExprOpt ExprNoInOpt
238 %type <statementNode> Statement Block
239 %type <statementNode> VariableStatement ConstStatement EmptyStatement ExprStatement
240 %type <statementNode> IfStatement IterationStatement ContinueStatement
241 %type <statementNode> BreakStatement ReturnStatement WithStatement
242 %type <statementNode> SwitchStatement LabelledStatement
243 %type <statementNode> ThrowStatement TryStatement
244 %type <statementNode> DebuggerStatement
245 %type <statementNode> SourceElement
247 %type <expressionNode> Initializer InitializerNoIn
248 %type <funcDeclNode> FunctionDeclaration
249 %type <funcExprNode> FunctionExpr
250 %type <functionBodyNode> FunctionBody
251 %type <sourceElements> SourceElements
252 %type <parameterList> FormalParameterList
253 %type <op> AssignmentOperator
254 %type <argumentsNode> Arguments
255 %type <argumentList> ArgumentList
256 %type <varDeclList> VariableDeclarationList VariableDeclarationListNoIn
257 %type <constDeclList> ConstDeclarationList
258 %type <constDeclNode> ConstDeclaration
259 %type <caseBlockNode> CaseBlock
260 %type <caseClauseNode> CaseClause DefaultClause
261 %type <clauseList> CaseClauses CaseClausesOpt
262 %type <intValue> Elision ElisionOpt
263 %type <elementList> ElementList
264 %type <propertyNode> Property
265 %type <propertyList> PropertyList
269 NULLTOKEN { $$ = new NullNode; }
270 | TRUETOKEN { $$ = new TrueNode; }
271 | FALSETOKEN { $$ = new FalseNode; }
272 | NUMBER { $$ = makeNumberNode($1); }
273 | STRING { $$ = new StringNode($1); }
278 $$ = new RegExpNode(l.pattern(), l.flags());
280 | DIVEQUAL /* regexp with /= */ {
284 $$ = new RegExpNode("=" + l.pattern(), l.flags());
289 IDENT ':' AssignmentExpr { $$ = new PropertyNode(*$1, $3, PropertyNode::Constant); }
290 | STRING ':' AssignmentExpr { $$ = new PropertyNode(Identifier(*$1), $3, PropertyNode::Constant); }
291 | NUMBER ':' AssignmentExpr { $$ = new PropertyNode(Identifier(UString::from($1)), $3, PropertyNode::Constant); }
292 | IDENT IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = makeGetterOrSetterPropertyNode(*$1, *$2, 0, $6, lexer().sourceCode($5, $7, @5.first_line)); DBG($6, @5, @7); if (!$$) YYABORT; }
293 | IDENT IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE
294 { $$ = makeGetterOrSetterPropertyNode(*$1, *$2, $4.head, $7, lexer().sourceCode($6, $8, @6.first_line)); DBG($7, @6, @8); if (!$$) YYABORT; }
298 Property { $$.head = new PropertyListNode($1);
300 | PropertyList ',' Property { $$.head = $1.head;
301 $$.tail = new PropertyListNode($3, $1.tail); }
306 | OPENBRACE CLOSEBRACE { $$ = new ObjectLiteralNode(); }
307 | OPENBRACE PropertyList CLOSEBRACE { $$ = new ObjectLiteralNode($2.head); }
308 /* allow extra comma, see http://bugs.webkit.org/show_bug.cgi?id=5939 */
309 | OPENBRACE PropertyList ',' CLOSEBRACE { $$ = new ObjectLiteralNode($2.head); }
313 THISTOKEN { $$ = new ThisNode(); }
316 | IDENT { $$ = new ResolveNode(*$1); }
317 | '(' Expr ')' { $$ = $2; }
321 '[' ElisionOpt ']' { $$ = new ArrayNode($2); }
322 | '[' ElementList ']' { $$ = new ArrayNode($2.head); }
323 | '[' ElementList ',' ElisionOpt ']' { $$ = new ArrayNode($4, $2.head); }
327 ElisionOpt AssignmentExpr { $$.head = new ElementNode($1, $2);
329 | ElementList ',' ElisionOpt AssignmentExpr
331 $$.tail = new ElementNode($1.tail, $3, $4); }
335 /* nothing */ { $$ = 0; }
341 | Elision ',' { $$ = $1 + 1; }
346 | FunctionExpr { $$ = $1; }
347 | MemberExpr '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); }
348 | MemberExpr '.' IDENT { $$ = new DotAccessorNode($1, *$3); }
349 | NEW MemberExpr Arguments { $$ = new NewExprNode($2, $3); }
354 | MemberExprNoBF '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); }
355 | MemberExprNoBF '.' IDENT { $$ = new DotAccessorNode($1, *$3); }
356 | NEW MemberExpr Arguments { $$ = new NewExprNode($2, $3); }
361 | NEW NewExpr { $$ = new NewExprNode($2); }
366 | NEW NewExpr { $$ = new NewExprNode($2); }
370 MemberExpr Arguments { $$ = makeFunctionCallNode($1, $2); }
371 | CallExpr Arguments { $$ = makeFunctionCallNode($1, $2); }
372 | CallExpr '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); }
373 | CallExpr '.' IDENT { $$ = new DotAccessorNode($1, *$3); }
377 MemberExprNoBF Arguments { $$ = makeFunctionCallNode($1, $2); }
378 | CallExprNoBF Arguments { $$ = makeFunctionCallNode($1, $2); }
379 | CallExprNoBF '[' Expr ']' { $$ = new BracketAccessorNode($1, $3); }
380 | CallExprNoBF '.' IDENT { $$ = new DotAccessorNode($1, *$3); }
384 '(' ')' { $$ = new ArgumentsNode(); }
385 | '(' ArgumentList ')' { $$ = new ArgumentsNode($2.head); }
389 AssignmentExpr { $$.head = new ArgumentListNode($1);
391 | ArgumentList ',' AssignmentExpr { $$.head = $1.head;
392 $$.tail = new ArgumentListNode($1.tail, $3); }
400 LeftHandSideExprNoBF:
407 | LeftHandSideExpr PLUSPLUS { $$ = makePostfixNode($1, OpPlusPlus); }
408 | LeftHandSideExpr MINUSMINUS { $$ = makePostfixNode($1, OpMinusMinus); }
413 | LeftHandSideExprNoBF PLUSPLUS { $$ = makePostfixNode($1, OpPlusPlus); }
414 | LeftHandSideExprNoBF MINUSMINUS { $$ = makePostfixNode($1, OpMinusMinus); }
418 DELETETOKEN UnaryExpr { $$ = makeDeleteNode($2); }
419 | VOIDTOKEN UnaryExpr { $$ = new VoidNode($2); }
420 | TYPEOF UnaryExpr { $$ = makeTypeOfNode($2); }
421 | PLUSPLUS UnaryExpr { $$ = makePrefixNode($2, OpPlusPlus); }
422 | AUTOPLUSPLUS UnaryExpr { $$ = makePrefixNode($2, OpPlusPlus); }
423 | MINUSMINUS UnaryExpr { $$ = makePrefixNode($2, OpMinusMinus); }
424 | AUTOMINUSMINUS UnaryExpr { $$ = makePrefixNode($2, OpMinusMinus); }
425 | '+' UnaryExpr { $$ = new UnaryPlusNode($2); }
426 | '-' UnaryExpr { $$ = makeNegateNode($2); }
427 | '~' UnaryExpr { $$ = new BitwiseNotNode($2); }
428 | '!' UnaryExpr { $$ = new LogicalNotNode($2); }
442 | MultiplicativeExpr '*' UnaryExpr { $$ = new MultNode($1, $3); }
443 | MultiplicativeExpr '/' UnaryExpr { $$ = new DivNode($1, $3); }
444 | MultiplicativeExpr '%' UnaryExpr { $$ = new ModNode($1, $3); }
447 MultiplicativeExprNoBF:
449 | MultiplicativeExprNoBF '*' UnaryExpr
450 { $$ = new MultNode($1, $3); }
451 | MultiplicativeExprNoBF '/' UnaryExpr
452 { $$ = new DivNode($1, $3); }
453 | MultiplicativeExprNoBF '%' UnaryExpr
454 { $$ = new ModNode($1, $3); }
459 | AdditiveExpr '+' MultiplicativeExpr { $$ = makeAddNode($1, $3); }
460 | AdditiveExpr '-' MultiplicativeExpr { $$ = new SubNode($1, $3); }
464 MultiplicativeExprNoBF
465 | AdditiveExprNoBF '+' MultiplicativeExpr
466 { $$ = makeAddNode($1, $3); }
467 | AdditiveExprNoBF '-' MultiplicativeExpr
468 { $$ = new SubNode($1, $3); }
473 | ShiftExpr LSHIFT AdditiveExpr { $$ = new LeftShiftNode($1, $3); }
474 | ShiftExpr RSHIFT AdditiveExpr { $$ = new RightShiftNode($1, $3); }
475 | ShiftExpr URSHIFT AdditiveExpr { $$ = new UnsignedRightShiftNode($1, $3); }
480 | ShiftExprNoBF LSHIFT AdditiveExpr { $$ = new LeftShiftNode($1, $3); }
481 | ShiftExprNoBF RSHIFT AdditiveExpr { $$ = new RightShiftNode($1, $3); }
482 | ShiftExprNoBF URSHIFT AdditiveExpr { $$ = new UnsignedRightShiftNode($1, $3); }
487 | RelationalExpr '<' ShiftExpr { $$ = makeLessNode($1, $3); }
488 | RelationalExpr '>' ShiftExpr { $$ = new GreaterNode($1, $3); }
489 | RelationalExpr LE ShiftExpr { $$ = new LessEqNode($1, $3); }
490 | RelationalExpr GE ShiftExpr { $$ = new GreaterEqNode($1, $3); }
491 | RelationalExpr INSTANCEOF ShiftExpr { $$ = new InstanceOfNode($1, $3); }
492 | RelationalExpr INTOKEN ShiftExpr { $$ = new InNode($1, $3); }
497 | RelationalExprNoIn '<' ShiftExpr { $$ = makeLessNode($1, $3); }
498 | RelationalExprNoIn '>' ShiftExpr { $$ = new GreaterNode($1, $3); }
499 | RelationalExprNoIn LE ShiftExpr { $$ = new LessEqNode($1, $3); }
500 | RelationalExprNoIn GE ShiftExpr { $$ = new GreaterEqNode($1, $3); }
501 | RelationalExprNoIn INSTANCEOF ShiftExpr
502 { $$ = new InstanceOfNode($1, $3); }
507 | RelationalExprNoBF '<' ShiftExpr { $$ = makeLessNode($1, $3); }
508 | RelationalExprNoBF '>' ShiftExpr { $$ = new GreaterNode($1, $3); }
509 | RelationalExprNoBF LE ShiftExpr { $$ = new LessEqNode($1, $3); }
510 | RelationalExprNoBF GE ShiftExpr { $$ = new GreaterEqNode($1, $3); }
511 | RelationalExprNoBF INSTANCEOF ShiftExpr
512 { $$ = new InstanceOfNode($1, $3); }
513 | RelationalExprNoBF INTOKEN ShiftExpr { $$ = new InNode($1, $3); }
518 | EqualityExpr EQEQ RelationalExpr { $$ = new EqualNode($1, $3); }
519 | EqualityExpr NE RelationalExpr { $$ = new NotEqualNode($1, $3); }
520 | EqualityExpr STREQ RelationalExpr { $$ = new StrictEqualNode($1, $3); }
521 | EqualityExpr STRNEQ RelationalExpr { $$ = new NotStrictEqualNode($1, $3); }
526 | EqualityExprNoIn EQEQ RelationalExprNoIn
527 { $$ = new EqualNode($1, $3); }
528 | EqualityExprNoIn NE RelationalExprNoIn
529 { $$ = new NotEqualNode($1, $3); }
530 | EqualityExprNoIn STREQ RelationalExprNoIn
531 { $$ = new StrictEqualNode($1, $3); }
532 | EqualityExprNoIn STRNEQ RelationalExprNoIn
533 { $$ = new NotStrictEqualNode($1, $3); }
538 | EqualityExprNoBF EQEQ RelationalExpr
539 { $$ = new EqualNode($1, $3); }
540 | EqualityExprNoBF NE RelationalExpr { $$ = new NotEqualNode($1, $3); }
541 | EqualityExprNoBF STREQ RelationalExpr
542 { $$ = new StrictEqualNode($1, $3); }
543 | EqualityExprNoBF STRNEQ RelationalExpr
544 { $$ = new NotStrictEqualNode($1, $3); }
549 | BitwiseANDExpr '&' EqualityExpr { $$ = new BitAndNode($1, $3); }
554 | BitwiseANDExprNoIn '&' EqualityExprNoIn
555 { $$ = new BitAndNode($1, $3); }
560 | BitwiseANDExprNoBF '&' EqualityExpr { $$ = new BitAndNode($1, $3); }
565 | BitwiseXORExpr '^' BitwiseANDExpr { $$ = new BitXOrNode($1, $3); }
570 | BitwiseXORExprNoIn '^' BitwiseANDExprNoIn
571 { $$ = new BitXOrNode($1, $3); }
576 | BitwiseXORExprNoBF '^' BitwiseANDExpr
577 { $$ = new BitXOrNode($1, $3); }
582 | BitwiseORExpr '|' BitwiseXORExpr { $$ = new BitOrNode($1, $3); }
587 | BitwiseORExprNoIn '|' BitwiseXORExprNoIn
588 { $$ = new BitOrNode($1, $3); }
593 | BitwiseORExprNoBF '|' BitwiseXORExpr
594 { $$ = new BitOrNode($1, $3); }
599 | LogicalANDExpr AND BitwiseORExpr { $$ = new LogicalAndNode($1, $3); }
604 | LogicalANDExprNoIn AND BitwiseORExprNoIn
605 { $$ = new LogicalAndNode($1, $3); }
610 | LogicalANDExprNoBF AND BitwiseORExpr
611 { $$ = new LogicalAndNode($1, $3); }
616 | LogicalORExpr OR LogicalANDExpr { $$ = new LogicalOrNode($1, $3); }
621 | LogicalORExprNoIn OR LogicalANDExprNoIn
622 { $$ = new LogicalOrNode($1, $3); }
627 | LogicalORExprNoBF OR LogicalANDExpr { $$ = new LogicalOrNode($1, $3); }
632 | LogicalORExpr '?' AssignmentExpr ':' AssignmentExpr
633 { $$ = new ConditionalNode($1, $3, $5); }
638 | LogicalORExprNoIn '?' AssignmentExprNoIn ':' AssignmentExprNoIn
639 { $$ = new ConditionalNode($1, $3, $5); }
644 | LogicalORExprNoBF '?' AssignmentExpr ':' AssignmentExpr
645 { $$ = new ConditionalNode($1, $3, $5); }
650 | LeftHandSideExpr AssignmentOperator AssignmentExpr
651 { $$ = makeAssignNode($1, $2, $3); }
656 | LeftHandSideExpr AssignmentOperator AssignmentExprNoIn
657 { $$ = makeAssignNode($1, $2, $3); }
662 | LeftHandSideExprNoBF AssignmentOperator AssignmentExpr
663 { $$ = makeAssignNode($1, $2, $3); }
667 '=' { $$ = OpEqual; }
668 | PLUSEQUAL { $$ = OpPlusEq; }
669 | MINUSEQUAL { $$ = OpMinusEq; }
670 | MULTEQUAL { $$ = OpMultEq; }
671 | DIVEQUAL { $$ = OpDivEq; }
672 | LSHIFTEQUAL { $$ = OpLShift; }
673 | RSHIFTEQUAL { $$ = OpRShift; }
674 | URSHIFTEQUAL { $$ = OpURShift; }
675 | ANDEQUAL { $$ = OpAndEq; }
676 | XOREQUAL { $$ = OpXOrEq; }
677 | OREQUAL { $$ = OpOrEq; }
678 | MODEQUAL { $$ = OpModEq; }
683 | Expr ',' AssignmentExpr { $$ = new CommaNode($1, $3); }
688 | ExprNoIn ',' AssignmentExprNoIn { $$ = new CommaNode($1, $3); }
693 | ExprNoBF ',' AssignmentExpr { $$ = new CommaNode($1, $3); }
716 OPENBRACE CLOSEBRACE { $$ = createNodeInfo<StatementNode*>(new BlockNode(0), 0, 0);
717 DBG($$.m_node, @1, @2); }
718 | OPENBRACE SourceElements CLOSEBRACE { $$ = createNodeInfo<StatementNode*>(new BlockNode($2.m_node), $2.m_varDeclarations, $2.m_funcDeclarations);
719 DBG($$.m_node, @1, @3); }
723 VAR VariableDeclarationList ';' { $$ = createNodeInfo<StatementNode*>(makeVarStatementNode($2.m_node), $2.m_varDeclarations, $2.m_funcDeclarations);
724 DBG($$.m_node, @1, @3); }
725 | VAR VariableDeclarationList error { $$ = createNodeInfo<StatementNode*>(makeVarStatementNode($2.m_node), $2.m_varDeclarations, $2.m_funcDeclarations);
726 DBG($$.m_node, @1, @2);
730 VariableDeclarationList:
731 IDENT { $$.m_node = 0;
732 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>;
733 appendToVarDeclarationList($$.m_varDeclarations, *$1, 0);
734 $$.m_funcDeclarations = 0;
736 | IDENT Initializer { $$.m_node = new AssignResolveNode(*$1, $2);
737 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>;
738 appendToVarDeclarationList($$.m_varDeclarations, *$1, DeclarationStacks::HasInitializer);
739 $$.m_funcDeclarations = 0;
741 | VariableDeclarationList ',' IDENT
742 { $$.m_node = $1.m_node;
743 $$.m_varDeclarations = $1.m_varDeclarations;
744 appendToVarDeclarationList($$.m_varDeclarations, *$3, 0);
745 $$.m_funcDeclarations = 0;
747 | VariableDeclarationList ',' IDENT Initializer
748 { $$.m_node = combineVarInitializers($1.m_node, new AssignResolveNode(*$3, $4));
749 $$.m_varDeclarations = $1.m_varDeclarations;
750 appendToVarDeclarationList($$.m_varDeclarations, *$3, DeclarationStacks::HasInitializer);
751 $$.m_funcDeclarations = 0;
755 VariableDeclarationListNoIn:
756 IDENT { $$.m_node = 0;
757 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>;
758 appendToVarDeclarationList($$.m_varDeclarations, *$1, 0);
759 $$.m_funcDeclarations = 0;
761 | IDENT InitializerNoIn { $$.m_node = new AssignResolveNode(*$1, $2);
762 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>;
763 appendToVarDeclarationList($$.m_varDeclarations, *$1, DeclarationStacks::HasInitializer);
764 $$.m_funcDeclarations = 0;
766 | VariableDeclarationListNoIn ',' IDENT
767 { $$.m_node = $1.m_node;
768 $$.m_varDeclarations = $1.m_varDeclarations;
769 appendToVarDeclarationList($$.m_varDeclarations, *$3, 0);
770 $$.m_funcDeclarations = 0;
772 | VariableDeclarationListNoIn ',' IDENT InitializerNoIn
773 { $$.m_node = combineVarInitializers($1.m_node, new AssignResolveNode(*$3, $4));
774 $$.m_varDeclarations = $1.m_varDeclarations;
775 appendToVarDeclarationList($$.m_varDeclarations, *$3, DeclarationStacks::HasInitializer);
776 $$.m_funcDeclarations = 0;
781 CONSTTOKEN ConstDeclarationList ';' { $$ = createNodeInfo<StatementNode*>(new ConstStatementNode($2.m_node.head), $2.m_varDeclarations, $2.m_funcDeclarations);
782 DBG($$.m_node, @1, @3); }
783 | CONSTTOKEN ConstDeclarationList error
784 { $$ = createNodeInfo<StatementNode*>(new ConstStatementNode($2.m_node.head), $2.m_varDeclarations, $2.m_funcDeclarations);
785 DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
788 ConstDeclarationList:
789 ConstDeclaration { $$.m_node.head = $1;
790 $$.m_node.tail = $$.m_node.head;
791 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>;
792 appendToVarDeclarationList($$.m_varDeclarations, $1);
793 $$.m_funcDeclarations = 0; }
794 | ConstDeclarationList ',' ConstDeclaration
795 { $$.m_node.head = $1.m_node.head;
796 $1.m_node.tail->m_next = $3;
798 $$.m_varDeclarations = $1.m_varDeclarations;
799 appendToVarDeclarationList($$.m_varDeclarations, $3);
800 $$.m_funcDeclarations = 0; }
804 IDENT { $$ = new ConstDeclNode(*$1, 0); }
805 | IDENT Initializer { $$ = new ConstDeclNode(*$1, $2); }
809 '=' AssignmentExpr { $$ = $2; }
813 '=' AssignmentExprNoIn { $$ = $2; }
817 ';' { $$ = createNodeInfo<StatementNode*>(new EmptyStatementNode(), 0, 0); }
821 ExprNoBF ';' { $$ = createNodeInfo<StatementNode*>(new ExprStatementNode($1), 0, 0);
822 DBG($$.m_node, @1, @2); }
823 | ExprNoBF error { $$ = createNodeInfo<StatementNode*>(new ExprStatementNode($1), 0, 0);
824 DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
828 IF '(' Expr ')' Statement %prec IF_WITHOUT_ELSE
829 { $$ = createNodeInfo<StatementNode*>(new IfNode($3, $5.m_node), $5.m_varDeclarations, $5.m_funcDeclarations);
830 DBG($$.m_node, @1, @4); }
831 | IF '(' Expr ')' Statement ELSE Statement
832 { $$ = createNodeInfo<StatementNode*>(new IfElseNode($3, $5.m_node, $7.m_node), mergeDeclarationLists($5.m_varDeclarations, $7.m_varDeclarations), mergeDeclarationLists($5.m_funcDeclarations, $7.m_funcDeclarations));
833 DBG($$.m_node, @1, @4); }
837 DO Statement WHILE '(' Expr ')' ';' { $$ = createNodeInfo<StatementNode*>(new DoWhileNode($2.m_node, $5), $2.m_varDeclarations, $2.m_funcDeclarations);
838 DBG($$.m_node, @1, @3); }
839 | DO Statement WHILE '(' Expr ')' error { $$ = createNodeInfo<StatementNode*>(new DoWhileNode($2.m_node, $5), $2.m_varDeclarations, $2.m_funcDeclarations);
840 DBG($$.m_node, @1, @3); } // Always performs automatic semicolon insertion.
841 | WHILE '(' Expr ')' Statement { $$ = createNodeInfo<StatementNode*>(new WhileNode($3, $5.m_node), $5.m_varDeclarations, $5.m_funcDeclarations);
842 DBG($$.m_node, @1, @4); }
843 | FOR '(' ExprNoInOpt ';' ExprOpt ';' ExprOpt ')' Statement
844 { $$ = createNodeInfo<StatementNode*>(new ForNode($3, $5, $7, $9.m_node, false), $9.m_varDeclarations, $9.m_funcDeclarations);
845 DBG($$.m_node, @1, @8);
847 | FOR '(' VAR VariableDeclarationListNoIn ';' ExprOpt ';' ExprOpt ')' Statement
848 { $$ = createNodeInfo<StatementNode*>(new ForNode($4.m_node, $6, $8, $10.m_node, true),
849 mergeDeclarationLists($4.m_varDeclarations, $10.m_varDeclarations),
850 mergeDeclarationLists($4.m_funcDeclarations, $10.m_funcDeclarations));
851 DBG($$.m_node, @1, @9); }
852 | FOR '(' LeftHandSideExpr INTOKEN Expr ')' Statement
854 ExpressionNode* n = $3;
855 if (!n->isLocation())
857 $$ = createNodeInfo<StatementNode*>(new ForInNode(n, $5, $7.m_node), $7.m_varDeclarations, $7.m_funcDeclarations);
858 DBG($$.m_node, @1, @6);
860 | FOR '(' VAR IDENT INTOKEN Expr ')' Statement
861 { ForInNode *forIn = new ForInNode(*$4, 0, $6, $8.m_node);
862 appendToVarDeclarationList($8.m_varDeclarations, *$4, DeclarationStacks::HasInitializer);
863 $$ = createNodeInfo<StatementNode*>(forIn, $8.m_varDeclarations, $8.m_funcDeclarations);
864 DBG($$.m_node, @1, @7); }
865 | FOR '(' VAR IDENT InitializerNoIn INTOKEN Expr ')' Statement
866 { ForInNode *forIn = new ForInNode(*$4, $5, $7, $9.m_node);
867 appendToVarDeclarationList($9.m_varDeclarations, *$4, DeclarationStacks::HasInitializer);
868 $$ = createNodeInfo<StatementNode*>(forIn, $9.m_varDeclarations, $9.m_funcDeclarations);
869 DBG($$.m_node, @1, @8); }
873 /* nothing */ { $$ = 0; }
878 /* nothing */ { $$ = 0; }
883 CONTINUE ';' { $$ = createNodeInfo<StatementNode*>(new ContinueNode(), 0, 0);
884 DBG($$.m_node, @1, @2); }
885 | CONTINUE error { $$ = createNodeInfo<StatementNode*>(new ContinueNode(), 0, 0);
886 DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
887 | CONTINUE IDENT ';' { $$ = createNodeInfo<StatementNode*>(new ContinueNode(*$2), 0, 0);
888 DBG($$.m_node, @1, @3); }
889 | CONTINUE IDENT error { $$ = createNodeInfo<StatementNode*>(new ContinueNode(*$2), 0, 0);
890 DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
894 BREAK ';' { $$ = createNodeInfo<StatementNode*>(new BreakNode(), 0, 0); DBG($$.m_node, @1, @2); }
895 | BREAK error { $$ = createNodeInfo<StatementNode*>(new BreakNode(), 0, 0); DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
896 | BREAK IDENT ';' { $$ = createNodeInfo<StatementNode*>(new BreakNode(*$2), 0, 0); DBG($$.m_node, @1, @3); }
897 | BREAK IDENT error { $$ = createNodeInfo<StatementNode*>(new BreakNode(*$2), 0, 0); DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
901 RETURN ';' { $$ = createNodeInfo<StatementNode*>(new ReturnNode(0), 0, 0); DBG($$.m_node, @1, @2); }
902 | RETURN error { $$ = createNodeInfo<StatementNode*>(new ReturnNode(0), 0, 0); DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
903 | RETURN Expr ';' { $$ = createNodeInfo<StatementNode*>(new ReturnNode($2), 0, 0); DBG($$.m_node, @1, @3); }
904 | RETURN Expr error { $$ = createNodeInfo<StatementNode*>(new ReturnNode($2), 0, 0); DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
908 WITH '(' Expr ')' Statement { $$ = createNodeInfo<StatementNode*>(new WithNode($3, $5.m_node), $5.m_varDeclarations, $5.m_funcDeclarations);
909 DBG($$.m_node, @1, @4); }
913 SWITCH '(' Expr ')' CaseBlock { $$ = createNodeInfo<StatementNode*>(new SwitchNode($3, $5.m_node), $5.m_varDeclarations, $5.m_funcDeclarations);
914 DBG($$.m_node, @1, @4); }
918 OPENBRACE CaseClausesOpt CLOSEBRACE { $$ = createNodeInfo<CaseBlockNode*>(new CaseBlockNode($2.m_node.head, 0, 0), $2.m_varDeclarations, $2.m_funcDeclarations); }
919 | OPENBRACE CaseClausesOpt DefaultClause CaseClausesOpt CLOSEBRACE
920 { $$ = createNodeInfo<CaseBlockNode*>(new CaseBlockNode($2.m_node.head, $3.m_node, $4.m_node.head),
921 mergeDeclarationLists(mergeDeclarationLists($2.m_varDeclarations, $3.m_varDeclarations), $4.m_varDeclarations),
922 mergeDeclarationLists(mergeDeclarationLists($2.m_funcDeclarations, $3.m_funcDeclarations), $4.m_funcDeclarations)); }
926 /* nothing */ { $$.m_node.head = 0; $$.m_node.tail = 0; $$.m_varDeclarations = 0; $$.m_funcDeclarations = 0; }
931 CaseClause { $$.m_node.head = new ClauseListNode($1.m_node);
932 $$.m_node.tail = $$.m_node.head;
933 $$.m_varDeclarations = $1.m_varDeclarations;
934 $$.m_funcDeclarations = $1.m_funcDeclarations; }
935 | CaseClauses CaseClause { $$.m_node.head = $1.m_node.head;
936 $$.m_node.tail = new ClauseListNode($1.m_node.tail, $2.m_node);
937 $$.m_varDeclarations = mergeDeclarationLists($1.m_varDeclarations, $2.m_varDeclarations);
938 $$.m_funcDeclarations = mergeDeclarationLists($1.m_funcDeclarations, $2.m_funcDeclarations);
943 CASE Expr ':' { $$ = createNodeInfo<CaseClauseNode*>(new CaseClauseNode($2), 0, 0); }
944 | CASE Expr ':' SourceElements { $$ = createNodeInfo<CaseClauseNode*>(new CaseClauseNode($2, $4.m_node), $4.m_varDeclarations, $4.m_funcDeclarations); }
948 DEFAULT ':' { $$ = createNodeInfo<CaseClauseNode*>(new CaseClauseNode(0), 0, 0); }
949 | DEFAULT ':' SourceElements { $$ = createNodeInfo<CaseClauseNode*>(new CaseClauseNode(0, $3.m_node), $3.m_varDeclarations, $3.m_funcDeclarations); }
953 IDENT ':' Statement { $3.m_node->pushLabel(*$1);
954 $$ = createNodeInfo<StatementNode*>(new LabelNode(*$1, $3.m_node), $3.m_varDeclarations, $3.m_funcDeclarations); }
958 THROW Expr ';' { $$ = createNodeInfo<StatementNode*>(new ThrowNode($2), 0, 0); DBG($$.m_node, @1, @3); }
959 | THROW Expr error { $$ = createNodeInfo<StatementNode*>(new ThrowNode($2), 0, 0); DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
963 TRY Block FINALLY Block { $$ = createNodeInfo<StatementNode*>(new TryNode($2.m_node, CommonIdentifiers::shared()->nullIdentifier, 0, $4.m_node),
964 mergeDeclarationLists($2.m_varDeclarations, $4.m_varDeclarations),
965 mergeDeclarationLists($2.m_funcDeclarations, $4.m_funcDeclarations));
966 DBG($$.m_node, @1, @2); }
967 | TRY Block CATCH '(' IDENT ')' Block { $$ = createNodeInfo<StatementNode*>(new TryNode($2.m_node, *$5, $7.m_node, 0),
968 mergeDeclarationLists($2.m_varDeclarations, $7.m_varDeclarations),
969 mergeDeclarationLists($2.m_funcDeclarations, $7.m_funcDeclarations));
970 DBG($$.m_node, @1, @2); }
971 | TRY Block CATCH '(' IDENT ')' Block FINALLY Block
972 { $$ = createNodeInfo<StatementNode*>(new TryNode($2.m_node, *$5, $7.m_node, $9.m_node),
973 mergeDeclarationLists(mergeDeclarationLists($2.m_varDeclarations, $7.m_varDeclarations), $9.m_varDeclarations),
974 mergeDeclarationLists(mergeDeclarationLists($2.m_funcDeclarations, $7.m_funcDeclarations), $9.m_funcDeclarations));
975 DBG($$.m_node, @1, @2); }
979 DEBUGGER ';' { $$ = createNodeInfo<StatementNode*>(new EmptyStatementNode(), 0, 0);
980 DBG($$.m_node, @1, @2); }
981 | DEBUGGER error { $$ = createNodeInfo<StatementNode*>(new EmptyStatementNode(), 0, 0);
982 DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
986 FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = new FuncDeclNode(*$2, $6, lexer().sourceCode($5, $7, @5.first_line)); DBG($6, @5, @7); }
987 | FUNCTION IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE
988 { $$ = new FuncDeclNode(*$2, $7, lexer().sourceCode($6, $8, @6.first_line), $4.head); DBG($7, @6, @8); }
992 FUNCTION '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = new FuncExprNode(CommonIdentifiers::shared()->nullIdentifier, $5, lexer().sourceCode($4, $6, @4.first_line)); DBG($5, @4, @6); }
993 | FUNCTION '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = new FuncExprNode(CommonIdentifiers::shared()->nullIdentifier, $6, lexer().sourceCode($5, $7, @5.first_line), $3.head); DBG($6, @5, @7); }
994 | FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = new FuncExprNode(*$2, $6, lexer().sourceCode($5, $7, @5.first_line)); DBG($6, @5, @7); }
995 | FUNCTION IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = new FuncExprNode(*$2, $7, lexer().sourceCode($6, $8, @6.first_line), $4.head); DBG($7, @6, @8); }
999 IDENT { $$.head = new ParameterNode(*$1);
1000 $$.tail = $$.head; }
1001 | FormalParameterList ',' IDENT { $$.head = $1.head;
1002 $$.tail = new ParameterNode($1.tail, *$3); }
1006 /* not in spec */ { $$ = FunctionBodyNode::create(); }
1007 | SourceElements_NoNode { $$ = FunctionBodyNode::create(); }
1011 /* not in spec */ { parser().didFinishParsing(0, 0, 0, @0.last_line); }
1012 | SourceElements { parser().didFinishParsing($1.m_node, $1.m_varDeclarations, $1.m_funcDeclarations, @1.last_line); }
1016 SourceElement { $$.m_node = new SourceElements;
1017 $$.m_node->append($1.m_node);
1018 $$.m_varDeclarations = $1.m_varDeclarations;
1019 $$.m_funcDeclarations = $1.m_funcDeclarations;
1021 | SourceElements SourceElement { $$.m_node->append($2.m_node);
1022 $$.m_varDeclarations = mergeDeclarationLists($1.m_varDeclarations, $2.m_varDeclarations);
1023 $$.m_funcDeclarations = mergeDeclarationLists($1.m_funcDeclarations, $2.m_funcDeclarations);
1028 FunctionDeclaration { $$ = createNodeInfo<StatementNode*>($1, 0, new ParserRefCountedData<DeclarationStacks::FunctionStack>); $$.m_funcDeclarations->data.append($1); }
1029 | Statement { $$ = $1; }
1040 | '/' /* regexp */ { Lexer& l = lexer(); if (!l.scanRegExp()) YYABORT; }
1041 | DIVEQUAL /* regexp with /= */ { Lexer& l = lexer(); if (!l.scanRegExp()) YYABORT; }
1045 IDENT ':' AssignmentExpr_NoNode { }
1046 | STRING ':' AssignmentExpr_NoNode { }
1047 | NUMBER ':' AssignmentExpr_NoNode { }
1048 | IDENT IDENT '(' ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE { if (*$1 != "get" && *$1 != "set") YYABORT; }
1049 | IDENT IDENT '(' FormalParameterList_NoNode ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE { if (*$1 != "get" && *$1 != "set") YYABORT; }
1052 PropertyList_NoNode:
1054 | PropertyList_NoNode ',' Property_NoNode
1058 PrimaryExprNoBrace_NoNode
1059 | OPENBRACE CLOSEBRACE { }
1060 | OPENBRACE PropertyList_NoNode CLOSEBRACE { }
1061 /* allow extra comma, see http://bugs.webkit.org/show_bug.cgi?id=5939 */
1062 | OPENBRACE PropertyList_NoNode ',' CLOSEBRACE { }
1065 PrimaryExprNoBrace_NoNode:
1068 | ArrayLiteral_NoNode
1070 | '(' Expr_NoNode ')'
1073 ArrayLiteral_NoNode:
1074 '[' ElisionOpt_NoNode ']'
1075 | '[' ElementList_NoNode ']'
1076 | '[' ElementList_NoNode ',' ElisionOpt_NoNode ']'
1080 ElisionOpt_NoNode AssignmentExpr_NoNode
1081 | ElementList_NoNode ',' ElisionOpt_NoNode AssignmentExpr_NoNode
1091 | Elision_NoNode ','
1096 | FunctionExpr_NoNode
1097 | MemberExpr_NoNode '[' Expr_NoNode ']'
1098 | MemberExpr_NoNode '.' IDENT
1099 | NEW MemberExpr_NoNode Arguments_NoNode
1102 MemberExprNoBF_NoNode:
1103 PrimaryExprNoBrace_NoNode
1104 | MemberExprNoBF_NoNode '[' Expr_NoNode ']'
1105 | MemberExprNoBF_NoNode '.' IDENT
1106 | NEW MemberExpr_NoNode Arguments_NoNode
1111 | NEW NewExpr_NoNode
1115 MemberExprNoBF_NoNode
1116 | NEW NewExpr_NoNode
1120 MemberExpr_NoNode Arguments_NoNode
1121 | CallExpr_NoNode Arguments_NoNode
1122 | CallExpr_NoNode '[' Expr_NoNode ']'
1123 | CallExpr_NoNode '.' IDENT
1126 CallExprNoBF_NoNode:
1127 MemberExprNoBF_NoNode Arguments_NoNode
1128 | CallExprNoBF_NoNode Arguments_NoNode
1129 | CallExprNoBF_NoNode '[' Expr_NoNode ']'
1130 | CallExprNoBF_NoNode '.' IDENT
1135 | '(' ArgumentList_NoNode ')'
1138 ArgumentList_NoNode:
1139 AssignmentExpr_NoNode
1140 | ArgumentList_NoNode ',' AssignmentExpr_NoNode
1143 LeftHandSideExpr_NoNode:
1148 LeftHandSideExprNoBF_NoNode:
1150 | CallExprNoBF_NoNode
1154 LeftHandSideExpr_NoNode
1155 | LeftHandSideExpr_NoNode PLUSPLUS
1156 | LeftHandSideExpr_NoNode MINUSMINUS
1159 PostfixExprNoBF_NoNode:
1160 LeftHandSideExprNoBF_NoNode
1161 | LeftHandSideExprNoBF_NoNode PLUSPLUS
1162 | LeftHandSideExprNoBF_NoNode MINUSMINUS
1165 UnaryExprCommon_NoNode:
1166 DELETETOKEN UnaryExpr_NoNode
1167 | VOIDTOKEN UnaryExpr_NoNode
1168 | TYPEOF UnaryExpr_NoNode
1169 | PLUSPLUS UnaryExpr_NoNode
1170 | AUTOPLUSPLUS UnaryExpr_NoNode
1171 | MINUSMINUS UnaryExpr_NoNode
1172 | AUTOMINUSMINUS UnaryExpr_NoNode
1173 | '+' UnaryExpr_NoNode
1174 | '-' UnaryExpr_NoNode
1175 | '~' UnaryExpr_NoNode
1176 | '!' UnaryExpr_NoNode
1180 | UnaryExprCommon_NoNode
1183 UnaryExprNoBF_NoNode:
1184 PostfixExprNoBF_NoNode
1185 | UnaryExprCommon_NoNode
1188 MultiplicativeExpr_NoNode:
1190 | MultiplicativeExpr_NoNode '*' UnaryExpr_NoNode
1191 | MultiplicativeExpr_NoNode '/' UnaryExpr_NoNode
1192 | MultiplicativeExpr_NoNode '%' UnaryExpr_NoNode
1195 MultiplicativeExprNoBF_NoNode:
1196 UnaryExprNoBF_NoNode
1197 | MultiplicativeExprNoBF_NoNode '*' UnaryExpr_NoNode
1198 | MultiplicativeExprNoBF_NoNode '/' UnaryExpr_NoNode
1199 | MultiplicativeExprNoBF_NoNode '%' UnaryExpr_NoNode
1202 AdditiveExpr_NoNode:
1203 MultiplicativeExpr_NoNode
1204 | AdditiveExpr_NoNode '+' MultiplicativeExpr_NoNode
1205 | AdditiveExpr_NoNode '-' MultiplicativeExpr_NoNode
1208 AdditiveExprNoBF_NoNode:
1209 MultiplicativeExprNoBF_NoNode
1210 | AdditiveExprNoBF_NoNode '+' MultiplicativeExpr_NoNode
1211 | AdditiveExprNoBF_NoNode '-' MultiplicativeExpr_NoNode
1216 | ShiftExpr_NoNode LSHIFT AdditiveExpr_NoNode
1217 | ShiftExpr_NoNode RSHIFT AdditiveExpr_NoNode
1218 | ShiftExpr_NoNode URSHIFT AdditiveExpr_NoNode
1221 ShiftExprNoBF_NoNode:
1222 AdditiveExprNoBF_NoNode
1223 | ShiftExprNoBF_NoNode LSHIFT AdditiveExpr_NoNode
1224 | ShiftExprNoBF_NoNode RSHIFT AdditiveExpr_NoNode
1225 | ShiftExprNoBF_NoNode URSHIFT AdditiveExpr_NoNode
1228 RelationalExpr_NoNode:
1230 | RelationalExpr_NoNode '<' ShiftExpr_NoNode
1231 | RelationalExpr_NoNode '>' ShiftExpr_NoNode
1232 | RelationalExpr_NoNode LE ShiftExpr_NoNode
1233 | RelationalExpr_NoNode GE ShiftExpr_NoNode
1234 | RelationalExpr_NoNode INSTANCEOF ShiftExpr_NoNode
1235 | RelationalExpr_NoNode INTOKEN ShiftExpr_NoNode
1238 RelationalExprNoIn_NoNode:
1240 | RelationalExprNoIn_NoNode '<' ShiftExpr_NoNode
1241 | RelationalExprNoIn_NoNode '>' ShiftExpr_NoNode
1242 | RelationalExprNoIn_NoNode LE ShiftExpr_NoNode
1243 | RelationalExprNoIn_NoNode GE ShiftExpr_NoNode
1244 | RelationalExprNoIn_NoNode INSTANCEOF ShiftExpr_NoNode
1247 RelationalExprNoBF_NoNode:
1248 ShiftExprNoBF_NoNode
1249 | RelationalExprNoBF_NoNode '<' ShiftExpr_NoNode
1250 | RelationalExprNoBF_NoNode '>' ShiftExpr_NoNode
1251 | RelationalExprNoBF_NoNode LE ShiftExpr_NoNode
1252 | RelationalExprNoBF_NoNode GE ShiftExpr_NoNode
1253 | RelationalExprNoBF_NoNode INSTANCEOF ShiftExpr_NoNode
1254 | RelationalExprNoBF_NoNode INTOKEN ShiftExpr_NoNode
1257 EqualityExpr_NoNode:
1258 RelationalExpr_NoNode
1259 | EqualityExpr_NoNode EQEQ RelationalExpr_NoNode
1260 | EqualityExpr_NoNode NE RelationalExpr_NoNode
1261 | EqualityExpr_NoNode STREQ RelationalExpr_NoNode
1262 | EqualityExpr_NoNode STRNEQ RelationalExpr_NoNode
1265 EqualityExprNoIn_NoNode:
1266 RelationalExprNoIn_NoNode
1267 | EqualityExprNoIn_NoNode EQEQ RelationalExprNoIn_NoNode
1268 | EqualityExprNoIn_NoNode NE RelationalExprNoIn_NoNode
1269 | EqualityExprNoIn_NoNode STREQ RelationalExprNoIn_NoNode
1270 | EqualityExprNoIn_NoNode STRNEQ RelationalExprNoIn_NoNode
1273 EqualityExprNoBF_NoNode:
1274 RelationalExprNoBF_NoNode
1275 | EqualityExprNoBF_NoNode EQEQ RelationalExpr_NoNode
1276 | EqualityExprNoBF_NoNode NE RelationalExpr_NoNode
1277 | EqualityExprNoBF_NoNode STREQ RelationalExpr_NoNode
1278 | EqualityExprNoBF_NoNode STRNEQ RelationalExpr_NoNode
1281 BitwiseANDExpr_NoNode:
1283 | BitwiseANDExpr_NoNode '&' EqualityExpr_NoNode
1286 BitwiseANDExprNoIn_NoNode:
1287 EqualityExprNoIn_NoNode
1288 | BitwiseANDExprNoIn_NoNode '&' EqualityExprNoIn_NoNode
1291 BitwiseANDExprNoBF_NoNode:
1292 EqualityExprNoBF_NoNode
1293 | BitwiseANDExprNoBF_NoNode '&' EqualityExpr_NoNode
1296 BitwiseXORExpr_NoNode:
1297 BitwiseANDExpr_NoNode
1298 | BitwiseXORExpr_NoNode '^' BitwiseANDExpr_NoNode
1301 BitwiseXORExprNoIn_NoNode:
1302 BitwiseANDExprNoIn_NoNode
1303 | BitwiseXORExprNoIn_NoNode '^' BitwiseANDExprNoIn_NoNode
1306 BitwiseXORExprNoBF_NoNode:
1307 BitwiseANDExprNoBF_NoNode
1308 | BitwiseXORExprNoBF_NoNode '^' BitwiseANDExpr_NoNode
1311 BitwiseORExpr_NoNode:
1312 BitwiseXORExpr_NoNode
1313 | BitwiseORExpr_NoNode '|' BitwiseXORExpr_NoNode
1316 BitwiseORExprNoIn_NoNode:
1317 BitwiseXORExprNoIn_NoNode
1318 | BitwiseORExprNoIn_NoNode '|' BitwiseXORExprNoIn_NoNode
1321 BitwiseORExprNoBF_NoNode:
1322 BitwiseXORExprNoBF_NoNode
1323 | BitwiseORExprNoBF_NoNode '|' BitwiseXORExpr_NoNode
1326 LogicalANDExpr_NoNode:
1327 BitwiseORExpr_NoNode
1328 | LogicalANDExpr_NoNode AND BitwiseORExpr_NoNode
1331 LogicalANDExprNoIn_NoNode:
1332 BitwiseORExprNoIn_NoNode
1333 | LogicalANDExprNoIn_NoNode AND BitwiseORExprNoIn_NoNode
1336 LogicalANDExprNoBF_NoNode:
1337 BitwiseORExprNoBF_NoNode
1338 | LogicalANDExprNoBF_NoNode AND BitwiseORExpr_NoNode
1341 LogicalORExpr_NoNode:
1342 LogicalANDExpr_NoNode
1343 | LogicalORExpr_NoNode OR LogicalANDExpr_NoNode
1346 LogicalORExprNoIn_NoNode:
1347 LogicalANDExprNoIn_NoNode
1348 | LogicalORExprNoIn_NoNode OR LogicalANDExprNoIn_NoNode
1351 LogicalORExprNoBF_NoNode:
1352 LogicalANDExprNoBF_NoNode
1353 | LogicalORExprNoBF_NoNode OR LogicalANDExpr_NoNode
1356 ConditionalExpr_NoNode:
1357 LogicalORExpr_NoNode
1358 | LogicalORExpr_NoNode '?' AssignmentExpr_NoNode ':' AssignmentExpr_NoNode
1361 ConditionalExprNoIn_NoNode:
1362 LogicalORExprNoIn_NoNode
1363 | LogicalORExprNoIn_NoNode '?' AssignmentExprNoIn_NoNode ':' AssignmentExprNoIn_NoNode
1366 ConditionalExprNoBF_NoNode:
1367 LogicalORExprNoBF_NoNode
1368 | LogicalORExprNoBF_NoNode '?' AssignmentExpr_NoNode ':' AssignmentExpr_NoNode
1371 AssignmentExpr_NoNode:
1372 ConditionalExpr_NoNode
1373 | LeftHandSideExpr_NoNode AssignmentOperator_NoNode AssignmentExpr_NoNode
1376 AssignmentExprNoIn_NoNode:
1377 ConditionalExprNoIn_NoNode
1378 | LeftHandSideExpr_NoNode AssignmentOperator_NoNode AssignmentExprNoIn_NoNode
1381 AssignmentExprNoBF_NoNode:
1382 ConditionalExprNoBF_NoNode
1383 | LeftHandSideExprNoBF_NoNode AssignmentOperator_NoNode AssignmentExpr_NoNode
1386 AssignmentOperator_NoNode:
1402 AssignmentExpr_NoNode
1403 | Expr_NoNode ',' AssignmentExpr_NoNode
1407 AssignmentExprNoIn_NoNode
1408 | ExprNoIn_NoNode ',' AssignmentExprNoIn_NoNode
1412 AssignmentExprNoBF_NoNode
1413 | ExprNoBF_NoNode ',' AssignmentExpr_NoNode
1418 | VariableStatement_NoNode
1419 | ConstStatement_NoNode
1420 | EmptyStatement_NoNode
1421 | ExprStatement_NoNode
1422 | IfStatement_NoNode
1423 | IterationStatement_NoNode
1424 | ContinueStatement_NoNode
1425 | BreakStatement_NoNode
1426 | ReturnStatement_NoNode
1427 | WithStatement_NoNode
1428 | SwitchStatement_NoNode
1429 | LabelledStatement_NoNode
1430 | ThrowStatement_NoNode
1431 | TryStatement_NoNode
1432 | DebuggerStatement_NoNode
1436 OPENBRACE CLOSEBRACE { }
1437 | OPENBRACE SourceElements_NoNode CLOSEBRACE { }
1440 VariableStatement_NoNode:
1441 VAR VariableDeclarationList_NoNode ';'
1442 | VAR VariableDeclarationList_NoNode error { AUTO_SEMICOLON; }
1445 VariableDeclarationList_NoNode:
1447 | IDENT Initializer_NoNode { }
1448 | VariableDeclarationList_NoNode ',' IDENT
1449 | VariableDeclarationList_NoNode ',' IDENT Initializer_NoNode
1452 VariableDeclarationListNoIn_NoNode:
1454 | IDENT InitializerNoIn_NoNode { }
1455 | VariableDeclarationListNoIn_NoNode ',' IDENT
1456 | VariableDeclarationListNoIn_NoNode ',' IDENT InitializerNoIn_NoNode
1459 ConstStatement_NoNode:
1460 CONSTTOKEN ConstDeclarationList_NoNode ';'
1461 | CONSTTOKEN ConstDeclarationList_NoNode error { AUTO_SEMICOLON; }
1464 ConstDeclarationList_NoNode:
1465 ConstDeclaration_NoNode
1466 | ConstDeclarationList_NoNode ',' ConstDeclaration_NoNode
1469 ConstDeclaration_NoNode:
1471 | IDENT Initializer_NoNode { }
1475 '=' AssignmentExpr_NoNode
1478 InitializerNoIn_NoNode:
1479 '=' AssignmentExprNoIn_NoNode
1482 EmptyStatement_NoNode:
1486 ExprStatement_NoNode:
1488 | ExprNoBF_NoNode error { AUTO_SEMICOLON; }
1492 IF '(' Expr_NoNode ')' Statement_NoNode %prec IF_WITHOUT_ELSE
1493 | IF '(' Expr_NoNode ')' Statement_NoNode ELSE Statement_NoNode
1496 IterationStatement_NoNode:
1497 DO Statement_NoNode WHILE '(' Expr_NoNode ')' ';'
1498 | DO Statement_NoNode WHILE '(' Expr_NoNode ')' error // Always performs automatic semicolon insertion
1499 | WHILE '(' Expr_NoNode ')' Statement_NoNode
1500 | FOR '(' ExprNoInOpt_NoNode ';' ExprOpt_NoNode ';' ExprOpt_NoNode ')' Statement_NoNode
1501 | FOR '(' VAR VariableDeclarationListNoIn_NoNode ';' ExprOpt_NoNode ';' ExprOpt_NoNode ')' Statement_NoNode
1502 | FOR '(' LeftHandSideExpr_NoNode INTOKEN Expr_NoNode ')' Statement_NoNode
1503 | FOR '(' VAR IDENT INTOKEN Expr_NoNode ')' Statement_NoNode
1504 | FOR '(' VAR IDENT InitializerNoIn_NoNode INTOKEN Expr_NoNode ')' Statement_NoNode
1517 ContinueStatement_NoNode:
1519 | CONTINUE error { AUTO_SEMICOLON; }
1520 | CONTINUE IDENT ';'
1521 | CONTINUE IDENT error { AUTO_SEMICOLON; }
1524 BreakStatement_NoNode:
1526 | BREAK error { AUTO_SEMICOLON; }
1528 | BREAK IDENT error { AUTO_SEMICOLON; }
1531 ReturnStatement_NoNode:
1533 | RETURN error { AUTO_SEMICOLON; }
1534 | RETURN Expr_NoNode ';'
1535 | RETURN Expr_NoNode error { AUTO_SEMICOLON; }
1538 WithStatement_NoNode:
1539 WITH '(' Expr_NoNode ')' Statement_NoNode
1542 SwitchStatement_NoNode:
1543 SWITCH '(' Expr_NoNode ')' CaseBlock_NoNode
1547 OPENBRACE CaseClausesOpt_NoNode CLOSEBRACE { }
1548 | OPENBRACE CaseClausesOpt_NoNode DefaultClause_NoNode CaseClausesOpt_NoNode CLOSEBRACE { }
1551 CaseClausesOpt_NoNode:
1553 | CaseClauses_NoNode
1558 | CaseClauses_NoNode CaseClause_NoNode
1562 CASE Expr_NoNode ':'
1563 | CASE Expr_NoNode ':' SourceElements_NoNode
1566 DefaultClause_NoNode:
1568 | DEFAULT ':' SourceElements_NoNode
1571 LabelledStatement_NoNode:
1572 IDENT ':' Statement_NoNode { }
1575 ThrowStatement_NoNode:
1576 THROW Expr_NoNode ';'
1577 | THROW Expr_NoNode error { AUTO_SEMICOLON; }
1580 TryStatement_NoNode:
1581 TRY Block_NoNode FINALLY Block_NoNode
1582 | TRY Block_NoNode CATCH '(' IDENT ')' Block_NoNode
1583 | TRY Block_NoNode CATCH '(' IDENT ')' Block_NoNode FINALLY Block_NoNode
1586 DebuggerStatement_NoNode:
1588 | DEBUGGER error { AUTO_SEMICOLON; }
1591 FunctionDeclaration_NoNode:
1592 FUNCTION IDENT '(' ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE
1593 | FUNCTION IDENT '(' FormalParameterList_NoNode ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE
1596 FunctionExpr_NoNode:
1597 FUNCTION '(' ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE
1598 | FUNCTION '(' FormalParameterList_NoNode ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE
1599 | FUNCTION IDENT '(' ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE
1600 | FUNCTION IDENT '(' FormalParameterList_NoNode ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE
1603 FormalParameterList_NoNode:
1605 | FormalParameterList_NoNode ',' IDENT
1608 FunctionBody_NoNode:
1610 | SourceElements_NoNode
1613 SourceElements_NoNode:
1614 SourceElement_NoNode
1615 | SourceElements_NoNode SourceElement_NoNode
1618 SourceElement_NoNode:
1619 FunctionDeclaration_NoNode
1627 static AddNode* makeAddNode(ExpressionNode* left, ExpressionNode* right)
1629 JSType t1 = left->expectedReturnType();
1630 JSType t2 = right->expectedReturnType();
1632 if (t1 == NumberType && t2 == NumberType)
1633 return new AddNumbersNode(left, right);
1634 if (t1 == StringType && t2 == StringType)
1635 return new AddStringsNode(left, right);
1636 if (t1 == StringType)
1637 return new AddStringLeftNode(left, right);
1638 if (t2 == StringType)
1639 return new AddStringRightNode(left, right);
1640 return new AddNode(left, right);
1643 static LessNode* makeLessNode(ExpressionNode* left, ExpressionNode* right)
1645 JSType t1 = left->expectedReturnType();
1646 JSType t2 = right->expectedReturnType();
1648 if (t1 == StringType && t2 == StringType)
1649 return new LessStringsNode(left, right);
1651 // There are certainly more efficient ways to do this type check if necessary
1652 if (t1 == NumberType || t1 == BooleanType || t1 == UndefinedType || t1 == NullType ||
1653 t2 == NumberType || t2 == BooleanType || t2 == UndefinedType || t2 == NullType)
1654 return new LessNumbersNode(left, right);
1656 // Neither is certain to be a number, nor were both certain to be strings, so we use the default (slow) implementation.
1657 return new LessNode(left, right);
1660 static ExpressionNode* makeAssignNode(ExpressionNode* loc, Operator op, ExpressionNode* expr)
1662 if (!loc->isLocation())
1663 return new AssignErrorNode(loc, op, expr);
1665 if (loc->isResolveNode()) {
1666 ResolveNode* resolve = static_cast<ResolveNode*>(loc);
1668 return new AssignResolveNode(resolve->identifier(), expr);
1670 return new ReadModifyResolveNode(resolve->identifier(), op, expr);
1672 if (loc->isBracketAccessorNode()) {
1673 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(loc);
1675 return new AssignBracketNode(bracket->base(), bracket->subscript(), expr);
1677 return new ReadModifyBracketNode(bracket->base(), bracket->subscript(), op, expr);
1679 ASSERT(loc->isDotAccessorNode());
1680 DotAccessorNode* dot = static_cast<DotAccessorNode*>(loc);
1682 return new AssignDotNode(dot->base(), dot->identifier(), expr);
1683 return new ReadModifyDotNode(dot->base(), dot->identifier(), op, expr);
1686 static ExpressionNode* makePrefixNode(ExpressionNode* expr, Operator op)
1688 if (!expr->isLocation())
1689 return new PrefixErrorNode(expr, op);
1691 if (expr->isResolveNode()) {
1692 ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1693 if (op == OpPlusPlus)
1694 return new PreIncResolveNode(resolve->identifier());
1696 return new PreDecResolveNode(resolve->identifier());
1698 if (expr->isBracketAccessorNode()) {
1699 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr);
1700 if (op == OpPlusPlus)
1701 return new PreIncBracketNode(bracket->base(), bracket->subscript());
1703 return new PreDecBracketNode(bracket->base(), bracket->subscript());
1705 ASSERT(expr->isDotAccessorNode());
1706 DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr);
1707 if (op == OpPlusPlus)
1708 return new PreIncDotNode(dot->base(), dot->identifier());
1709 return new PreDecDotNode(dot->base(), dot->identifier());
1712 static ExpressionNode* makePostfixNode(ExpressionNode* expr, Operator op)
1714 if (!expr->isLocation())
1715 return new PostfixErrorNode(expr, op);
1717 if (expr->isResolveNode()) {
1718 ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1719 if (op == OpPlusPlus)
1720 return new PostIncResolveNode(resolve->identifier());
1722 return new PostDecResolveNode(resolve->identifier());
1724 if (expr->isBracketAccessorNode()) {
1725 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr);
1726 if (op == OpPlusPlus)
1727 return new PostIncBracketNode(bracket->base(), bracket->subscript());
1729 return new PostDecBracketNode(bracket->base(), bracket->subscript());
1731 ASSERT(expr->isDotAccessorNode());
1732 DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr);
1734 if (op == OpPlusPlus)
1735 return new PostIncDotNode(dot->base(), dot->identifier());
1736 return new PostDecDotNode(dot->base(), dot->identifier());
1739 static ExpressionNode* makeFunctionCallNode(ExpressionNode* func, ArgumentsNode* args)
1741 if (!func->isLocation())
1742 return new FunctionCallValueNode(func, args);
1743 if (func->isResolveNode()) {
1744 ResolveNode* resolve = static_cast<ResolveNode*>(func);
1745 return new FunctionCallResolveNode(resolve->identifier(), args);
1747 if (func->isBracketAccessorNode()) {
1748 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(func);
1749 return new FunctionCallBracketNode(bracket->base(), bracket->subscript(), args);
1751 ASSERT(func->isDotAccessorNode());
1752 DotAccessorNode* dot = static_cast<DotAccessorNode*>(func);
1753 return new FunctionCallDotNode(dot->base(), dot->identifier(), args);
1756 static ExpressionNode* makeTypeOfNode(ExpressionNode* expr)
1758 if (expr->isResolveNode()) {
1759 ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1760 return new TypeOfResolveNode(resolve->identifier());
1762 return new TypeOfValueNode(expr);
1765 static ExpressionNode* makeDeleteNode(ExpressionNode* expr)
1767 if (!expr->isLocation())
1768 return new DeleteValueNode(expr);
1769 if (expr->isResolveNode()) {
1770 ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1771 return new DeleteResolveNode(resolve->identifier());
1773 if (expr->isBracketAccessorNode()) {
1774 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr);
1775 return new DeleteBracketNode(bracket->base(), bracket->subscript());
1777 ASSERT(expr->isDotAccessorNode());
1778 DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr);
1779 return new DeleteDotNode(dot->base(), dot->identifier());
1782 static PropertyNode* makeGetterOrSetterPropertyNode(const Identifier& getOrSet, const Identifier& name, ParameterNode* params, FunctionBodyNode* body, const SourceCode& source)
1784 PropertyNode::Type type;
1785 if (getOrSet == "get")
1786 type = PropertyNode::Getter;
1787 else if (getOrSet == "set")
1788 type = PropertyNode::Setter;
1791 return new PropertyNode(name, new FuncExprNode(CommonIdentifiers::shared()->nullIdentifier, body, source, params), type);
1794 static ExpressionNode* makeNegateNode(ExpressionNode* n)
1796 if (n->isNumber()) {
1797 NumberNode* number = static_cast<NumberNode*>(n);
1799 if (number->value() > 0.0) {
1800 number->setValue(-number->value());
1805 return new NegateNode(n);
1808 static NumberNode* makeNumberNode(double d)
1810 JSValue* value = JSImmediate::from(d);
1812 return new ImmediateNumberNode(value, d);
1813 return new NumberNode(d);
1816 /* called by yyparse on error */
1817 int yyerror(const char *)
1822 /* may we automatically insert a semicolon ? */
1823 static bool allowAutomaticSemicolon()
1825 return yychar == CLOSEBRACE || yychar == 0 || lexer().prevTerminator();
1828 static ExpressionNode* combineVarInitializers(ExpressionNode* list, AssignResolveNode* init)
1832 return new VarDeclCommaNode(list, init);
1835 // We turn variable declarations into either assignments or empty
1836 // statements (which later get stripped out), because the actual
1837 // declaration work is hoisted up to the start of the function body
1838 static StatementNode* makeVarStatementNode(ExpressionNode* expr)
1841 return new EmptyStatementNode();
1842 return new VarStatementNode(expr);