]> git.saurik.com Git - apple/javascriptcore.git/blob - parser/Grammar.y
JavaScriptCore-525.tar.gz
[apple/javascriptcore.git] / parser / Grammar.y
1 %pure_parser
2
3 %{
4
5 /*
6 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
7 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
8 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 *
24 */
25
26 #include "config.h"
27
28 #include <string.h>
29 #include <stdlib.h>
30 #include "JSValue.h"
31 #include "JSObject.h"
32 #include "Nodes.h"
33 #include "Lexer.h"
34 #include "JSString.h"
35 #include "JSGlobalData.h"
36 #include "CommonIdentifiers.h"
37 #include "NodeInfo.h"
38 #include "Parser.h"
39 #include <wtf/MathExtras.h>
40
41 #define YYMAXDEPTH 10000
42 #define YYENABLE_NLS 0
43
44 /* default values for bison */
45 #define YYDEBUG 0 // Set to 1 to debug a parse error.
46 #define jscyydebug 0 // Set to 1 to debug a parse error.
47 #if !PLATFORM(DARWIN)
48 // avoid triggering warnings in older bison
49 #define YYERROR_VERBOSE
50 #endif
51
52 int jscyylex(void* lvalp, void* llocp, void* globalPtr);
53 int jscyyerror(const char*);
54 static inline bool allowAutomaticSemicolon(JSC::Lexer&, int);
55
56 #define GLOBAL_DATA static_cast<JSGlobalData*>(globalPtr)
57 #define LEXER (GLOBAL_DATA->lexer)
58
59 #define AUTO_SEMICOLON do { if (!allowAutomaticSemicolon(*LEXER, yychar)) YYABORT; } while (0)
60 #define SET_EXCEPTION_LOCATION(node, start, divot, end) node->setExceptionSourceCode((divot), (divot) - (start), (end) - (divot))
61 #define DBG(l, s, e) (l)->setLoc((s).first_line, (e).last_line)
62
63 using namespace JSC;
64 using namespace std;
65
66 static ExpressionNode* makeAssignNode(void*, ExpressionNode* loc, Operator, ExpressionNode* expr, bool locHasAssignments, bool exprHasAssignments, int start, int divot, int end);
67 static ExpressionNode* makePrefixNode(void*, ExpressionNode* expr, Operator, int start, int divot, int end);
68 static ExpressionNode* makePostfixNode(void*, ExpressionNode* expr, Operator, int start, int divot, int end);
69 static PropertyNode* makeGetterOrSetterPropertyNode(void*, const Identifier &getOrSet, const Identifier& name, ParameterNode*, FunctionBodyNode*, const SourceCode&);
70 static ExpressionNodeInfo makeFunctionCallNode(void*, ExpressionNodeInfo func, ArgumentsNodeInfo, int start, int divot, int end);
71 static ExpressionNode* makeTypeOfNode(void*, ExpressionNode*);
72 static ExpressionNode* makeDeleteNode(void*, ExpressionNode*, int start, int divot, int end);
73 static ExpressionNode* makeNegateNode(void*, ExpressionNode*);
74 static NumberNode* makeNumberNode(void*, double);
75 static ExpressionNode* makeBitwiseNotNode(void*, ExpressionNode*);
76 static ExpressionNode* makeMultNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);
77 static ExpressionNode* makeDivNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);
78 static ExpressionNode* makeAddNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);
79 static ExpressionNode* makeSubNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);
80 static ExpressionNode* makeLeftShiftNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);
81 static ExpressionNode* makeRightShiftNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);
82 static StatementNode* makeVarStatementNode(void*, ExpressionNode*);
83 static ExpressionNode* combineVarInitializers(void*, ExpressionNode* list, AssignResolveNode* init);
84
85 #if COMPILER(MSVC)
86
87 #pragma warning(disable: 4065)
88 #pragma warning(disable: 4244)
89 #pragma warning(disable: 4702)
90
91 // At least some of the time, the declarations of malloc and free that bison
92 // generates are causing warnings. A way to avoid this is to explicitly define
93 // the macros so that bison doesn't try to declare malloc and free.
94 #define YYMALLOC malloc
95 #define YYFREE free
96
97 #endif
98
99 #define YYPARSE_PARAM globalPtr
100 #define YYLEX_PARAM globalPtr
101
102 template <typename T> NodeDeclarationInfo<T> createNodeDeclarationInfo(T node, ParserRefCountedData<DeclarationStacks::VarStack>* varDecls,
103 ParserRefCountedData<DeclarationStacks::FunctionStack>* funcDecls,
104 CodeFeatures info,
105 int numConstants)
106 {
107 ASSERT((info & ~AllFeatures) == 0);
108 NodeDeclarationInfo<T> result = {node, varDecls, funcDecls, info, numConstants};
109 return result;
110 }
111
112 template <typename T> NodeInfo<T> createNodeInfo(T node, CodeFeatures info, int numConstants)
113 {
114 ASSERT((info & ~AllFeatures) == 0);
115 NodeInfo<T> result = {node, info, numConstants};
116 return result;
117 }
118
119 template <typename T> T mergeDeclarationLists(T decls1, T decls2)
120 {
121 // decls1 or both are null
122 if (!decls1)
123 return decls2;
124 // only decls1 is non-null
125 if (!decls2)
126 return decls1;
127
128 // Both are non-null
129 decls1->data.append(decls2->data);
130
131 // We manually release the declaration lists to avoid accumulating many many
132 // unused heap allocated vectors
133 decls2->ref();
134 decls2->deref();
135 return decls1;
136 }
137
138 static void appendToVarDeclarationList(void* globalPtr, ParserRefCountedData<DeclarationStacks::VarStack>*& varDecls, const Identifier& ident, unsigned attrs)
139 {
140 if (!varDecls)
141 varDecls = new ParserRefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);
142
143 varDecls->data.append(make_pair(ident, attrs));
144
145 }
146
147 static inline void appendToVarDeclarationList(void* globalPtr, ParserRefCountedData<DeclarationStacks::VarStack>*& varDecls, ConstDeclNode* decl)
148 {
149 unsigned attrs = DeclarationStacks::IsConstant;
150 if (decl->m_init)
151 attrs |= DeclarationStacks::HasInitializer;
152 appendToVarDeclarationList(globalPtr, varDecls, decl->m_ident, attrs);
153 }
154
155 %}
156
157 %union {
158 int intValue;
159 double doubleValue;
160 Identifier* ident;
161
162 // expression subtrees
163 ExpressionNodeInfo expressionNode;
164 FuncDeclNodeInfo funcDeclNode;
165 PropertyNodeInfo propertyNode;
166 ArgumentsNodeInfo argumentsNode;
167 ConstDeclNodeInfo constDeclNode;
168 CaseBlockNodeInfo caseBlockNode;
169 CaseClauseNodeInfo caseClauseNode;
170 FuncExprNodeInfo funcExprNode;
171
172 // statement nodes
173 StatementNodeInfo statementNode;
174 FunctionBodyNode* functionBodyNode;
175 ProgramNode* programNode;
176
177 SourceElementsInfo sourceElements;
178 PropertyListInfo propertyList;
179 ArgumentListInfo argumentList;
180 VarDeclListInfo varDeclList;
181 ConstDeclListInfo constDeclList;
182 ClauseListInfo clauseList;
183 ElementListInfo elementList;
184 ParameterListInfo parameterList;
185
186 Operator op;
187 }
188
189 %start Program
190
191 /* literals */
192 %token NULLTOKEN TRUETOKEN FALSETOKEN
193
194 /* keywords */
195 %token BREAK CASE DEFAULT FOR NEW VAR CONSTTOKEN CONTINUE
196 %token FUNCTION RETURN VOIDTOKEN DELETETOKEN
197 %token IF THISTOKEN DO WHILE INTOKEN INSTANCEOF TYPEOF
198 %token SWITCH WITH RESERVED
199 %token THROW TRY CATCH FINALLY
200 %token DEBUGGER
201
202 /* give an if without an else higher precedence than an else to resolve the ambiguity */
203 %nonassoc IF_WITHOUT_ELSE
204 %nonassoc ELSE
205
206 /* punctuators */
207 %token EQEQ NE /* == and != */
208 %token STREQ STRNEQ /* === and !== */
209 %token LE GE /* < and > */
210 %token OR AND /* || and && */
211 %token PLUSPLUS MINUSMINUS /* ++ and -- */
212 %token LSHIFT /* << */
213 %token RSHIFT URSHIFT /* >> and >>> */
214 %token PLUSEQUAL MINUSEQUAL /* += and -= */
215 %token MULTEQUAL DIVEQUAL /* *= and /= */
216 %token LSHIFTEQUAL /* <<= */
217 %token RSHIFTEQUAL URSHIFTEQUAL /* >>= and >>>= */
218 %token ANDEQUAL MODEQUAL /* &= and %= */
219 %token XOREQUAL OREQUAL /* ^= and |= */
220 %token <intValue> OPENBRACE /* { (with char offset) */
221 %token <intValue> CLOSEBRACE /* { (with char offset) */
222
223 /* terminal types */
224 %token <doubleValue> NUMBER
225 %token <ident> IDENT STRING
226
227 /* automatically inserted semicolon */
228 %token AUTOPLUSPLUS AUTOMINUSMINUS
229
230 /* non-terminal types */
231 %type <expressionNode> Literal ArrayLiteral
232
233 %type <expressionNode> PrimaryExpr PrimaryExprNoBrace
234 %type <expressionNode> MemberExpr MemberExprNoBF /* BF => brace or function */
235 %type <expressionNode> NewExpr NewExprNoBF
236 %type <expressionNode> CallExpr CallExprNoBF
237 %type <expressionNode> LeftHandSideExpr LeftHandSideExprNoBF
238 %type <expressionNode> PostfixExpr PostfixExprNoBF
239 %type <expressionNode> UnaryExpr UnaryExprNoBF UnaryExprCommon
240 %type <expressionNode> MultiplicativeExpr MultiplicativeExprNoBF
241 %type <expressionNode> AdditiveExpr AdditiveExprNoBF
242 %type <expressionNode> ShiftExpr ShiftExprNoBF
243 %type <expressionNode> RelationalExpr RelationalExprNoIn RelationalExprNoBF
244 %type <expressionNode> EqualityExpr EqualityExprNoIn EqualityExprNoBF
245 %type <expressionNode> BitwiseANDExpr BitwiseANDExprNoIn BitwiseANDExprNoBF
246 %type <expressionNode> BitwiseXORExpr BitwiseXORExprNoIn BitwiseXORExprNoBF
247 %type <expressionNode> BitwiseORExpr BitwiseORExprNoIn BitwiseORExprNoBF
248 %type <expressionNode> LogicalANDExpr LogicalANDExprNoIn LogicalANDExprNoBF
249 %type <expressionNode> LogicalORExpr LogicalORExprNoIn LogicalORExprNoBF
250 %type <expressionNode> ConditionalExpr ConditionalExprNoIn ConditionalExprNoBF
251 %type <expressionNode> AssignmentExpr AssignmentExprNoIn AssignmentExprNoBF
252 %type <expressionNode> Expr ExprNoIn ExprNoBF
253
254 %type <expressionNode> ExprOpt ExprNoInOpt
255
256 %type <statementNode> Statement Block
257 %type <statementNode> VariableStatement ConstStatement EmptyStatement ExprStatement
258 %type <statementNode> IfStatement IterationStatement ContinueStatement
259 %type <statementNode> BreakStatement ReturnStatement WithStatement
260 %type <statementNode> SwitchStatement LabelledStatement
261 %type <statementNode> ThrowStatement TryStatement
262 %type <statementNode> DebuggerStatement
263
264 %type <expressionNode> Initializer InitializerNoIn
265 %type <statementNode> FunctionDeclaration
266 %type <funcExprNode> FunctionExpr
267 %type <functionBodyNode> FunctionBody
268 %type <sourceElements> SourceElements
269 %type <parameterList> FormalParameterList
270 %type <op> AssignmentOperator
271 %type <argumentsNode> Arguments
272 %type <argumentList> ArgumentList
273 %type <varDeclList> VariableDeclarationList VariableDeclarationListNoIn
274 %type <constDeclList> ConstDeclarationList
275 %type <constDeclNode> ConstDeclaration
276 %type <caseBlockNode> CaseBlock
277 %type <caseClauseNode> CaseClause DefaultClause
278 %type <clauseList> CaseClauses CaseClausesOpt
279 %type <intValue> Elision ElisionOpt
280 %type <elementList> ElementList
281 %type <propertyNode> Property
282 %type <propertyList> PropertyList
283 %%
284
285 // FIXME: There are currently two versions of the grammar in this file, the normal one, and the NoNodes version used for
286 // lazy recompilation of FunctionBodyNodes. We should move to generating the two versions from a script to avoid bugs.
287 // In the mean time, make sure to make any changes to the grammar in both versions.
288
289 Literal:
290 NULLTOKEN { $$ = createNodeInfo<ExpressionNode*>(new NullNode(GLOBAL_DATA), 0, 1); }
291 | TRUETOKEN { $$ = createNodeInfo<ExpressionNode*>(new BooleanNode(GLOBAL_DATA, true), 0, 1); }
292 | FALSETOKEN { $$ = createNodeInfo<ExpressionNode*>(new BooleanNode(GLOBAL_DATA, false), 0, 1); }
293 | NUMBER { $$ = createNodeInfo<ExpressionNode*>(makeNumberNode(GLOBAL_DATA, $1), 0, 1); }
294 | STRING { $$ = createNodeInfo<ExpressionNode*>(new StringNode(GLOBAL_DATA, *$1), 0, 1); }
295 | '/' /* regexp */ {
296 Lexer& l = *LEXER;
297 if (!l.scanRegExp())
298 YYABORT;
299 RegExpNode* node = new RegExpNode(GLOBAL_DATA, l.pattern(), l.flags());
300 int size = l.pattern().size() + 2; // + 2 for the two /'s
301 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.first_column + size, @1.first_column + size);
302 $$ = createNodeInfo<ExpressionNode*>(node, 0, 0);
303 }
304 | DIVEQUAL /* regexp with /= */ {
305 Lexer& l = *LEXER;
306 if (!l.scanRegExp())
307 YYABORT;
308 RegExpNode* node = new RegExpNode(GLOBAL_DATA, "=" + l.pattern(), l.flags());
309 int size = l.pattern().size() + 2; // + 2 for the two /'s
310 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.first_column + size, @1.first_column + size);
311 $$ = createNodeInfo<ExpressionNode*>(node, 0, 0);
312 }
313 ;
314
315 Property:
316 IDENT ':' AssignmentExpr { $$ = createNodeInfo<PropertyNode*>(new PropertyNode(GLOBAL_DATA, *$1, $3.m_node, PropertyNode::Constant), $3.m_features, $3.m_numConstants); }
317 | STRING ':' AssignmentExpr { $$ = createNodeInfo<PropertyNode*>(new PropertyNode(GLOBAL_DATA, *$1, $3.m_node, PropertyNode::Constant), $3.m_features, $3.m_numConstants); }
318 | NUMBER ':' AssignmentExpr { $$ = createNodeInfo<PropertyNode*>(new PropertyNode(GLOBAL_DATA, Identifier(GLOBAL_DATA, UString::from($1)), $3.m_node, PropertyNode::Constant), $3.m_features, $3.m_numConstants); }
319 | IDENT IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeInfo<PropertyNode*>(makeGetterOrSetterPropertyNode(globalPtr, *$1, *$2, 0, $6, LEXER->sourceCode($5, $7, @5.first_line)), ClosureFeature, 0); DBG($6, @5, @7); if (!$$.m_node) YYABORT; }
320 | IDENT IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE
321 {
322 $$ = createNodeInfo<PropertyNode*>(makeGetterOrSetterPropertyNode(globalPtr, *$1, *$2, $4.m_node.head, $7, LEXER->sourceCode($6, $8, @6.first_line)), $4.m_features | ClosureFeature, 0);
323 if ($4.m_features & ArgumentsFeature)
324 $7->setUsesArguments();
325 DBG($7, @6, @8);
326 if (!$$.m_node)
327 YYABORT;
328 }
329 ;
330
331 PropertyList:
332 Property { $$.m_node.head = new PropertyListNode(GLOBAL_DATA, $1.m_node);
333 $$.m_node.tail = $$.m_node.head;
334 $$.m_features = $1.m_features;
335 $$.m_numConstants = $1.m_numConstants; }
336 | PropertyList ',' Property { $$.m_node.head = $1.m_node.head;
337 $$.m_node.tail = new PropertyListNode(GLOBAL_DATA, $3.m_node, $1.m_node.tail);
338 $$.m_features = $1.m_features | $3.m_features;
339 $$.m_numConstants = $1.m_numConstants + $3.m_numConstants; }
340 ;
341
342 PrimaryExpr:
343 PrimaryExprNoBrace
344 | OPENBRACE CLOSEBRACE { $$ = createNodeInfo<ExpressionNode*>(new ObjectLiteralNode(GLOBAL_DATA), 0, 0); }
345 | OPENBRACE PropertyList CLOSEBRACE { $$ = createNodeInfo<ExpressionNode*>(new ObjectLiteralNode(GLOBAL_DATA, $2.m_node.head), $2.m_features, $2.m_numConstants); }
346 /* allow extra comma, see http://bugs.webkit.org/show_bug.cgi?id=5939 */
347 | OPENBRACE PropertyList ',' CLOSEBRACE { $$ = createNodeInfo<ExpressionNode*>(new ObjectLiteralNode(GLOBAL_DATA, $2.m_node.head), $2.m_features, $2.m_numConstants); }
348 ;
349
350 PrimaryExprNoBrace:
351 THISTOKEN { $$ = createNodeInfo<ExpressionNode*>(new ThisNode(GLOBAL_DATA), ThisFeature, 0); }
352 | Literal
353 | ArrayLiteral
354 | IDENT { $$ = createNodeInfo<ExpressionNode*>(new ResolveNode(GLOBAL_DATA, *$1, @1.first_column), (*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0, 0); }
355 | '(' Expr ')' { $$ = $2; }
356 ;
357
358 ArrayLiteral:
359 '[' ElisionOpt ']' { $$ = createNodeInfo<ExpressionNode*>(new ArrayNode(GLOBAL_DATA, $2), 0, $2 ? 1 : 0); }
360 | '[' ElementList ']' { $$ = createNodeInfo<ExpressionNode*>(new ArrayNode(GLOBAL_DATA, $2.m_node.head), $2.m_features, $2.m_numConstants); }
361 | '[' ElementList ',' ElisionOpt ']' { $$ = createNodeInfo<ExpressionNode*>(new ArrayNode(GLOBAL_DATA, $4, $2.m_node.head), $2.m_features, $4 ? $2.m_numConstants + 1 : $2.m_numConstants); }
362 ;
363
364 ElementList:
365 ElisionOpt AssignmentExpr { $$.m_node.head = new ElementNode(GLOBAL_DATA, $1, $2.m_node);
366 $$.m_node.tail = $$.m_node.head;
367 $$.m_features = $2.m_features;
368 $$.m_numConstants = $2.m_numConstants; }
369 | ElementList ',' ElisionOpt AssignmentExpr
370 { $$.m_node.head = $1.m_node.head;
371 $$.m_node.tail = new ElementNode(GLOBAL_DATA, $1.m_node.tail, $3, $4.m_node);
372 $$.m_features = $1.m_features | $4.m_features;
373 $$.m_numConstants = $1.m_numConstants + $4.m_numConstants; }
374 ;
375
376 ElisionOpt:
377 /* nothing */ { $$ = 0; }
378 | Elision
379 ;
380
381 Elision:
382 ',' { $$ = 1; }
383 | Elision ',' { $$ = $1 + 1; }
384 ;
385
386 MemberExpr:
387 PrimaryExpr
388 | FunctionExpr { $$ = createNodeInfo<ExpressionNode*>($1.m_node, $1.m_features, $1.m_numConstants); }
389 | MemberExpr '[' Expr ']' { BracketAccessorNode* node = new BracketAccessorNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
390 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @4.last_column);
391 $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants);
392 }
393 | MemberExpr '.' IDENT { DotAccessorNode* node = new DotAccessorNode(GLOBAL_DATA, $1.m_node, *$3);
394 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @3.last_column);
395 $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features, $1.m_numConstants);
396 }
397 | NEW MemberExpr Arguments { NewExprNode* node = new NewExprNode(GLOBAL_DATA, $2.m_node, $3.m_node);
398 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @3.last_column);
399 $$ = createNodeInfo<ExpressionNode*>(node, $2.m_features | $3.m_features, $2.m_numConstants + $3.m_numConstants);
400 }
401 ;
402
403 MemberExprNoBF:
404 PrimaryExprNoBrace
405 | MemberExprNoBF '[' Expr ']' { BracketAccessorNode* node = new BracketAccessorNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
406 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @4.last_column);
407 $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants);
408 }
409 | MemberExprNoBF '.' IDENT { DotAccessorNode* node = new DotAccessorNode(GLOBAL_DATA, $1.m_node, *$3);
410 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @3.last_column);
411 $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features, $1.m_numConstants);
412 }
413 | NEW MemberExpr Arguments { NewExprNode* node = new NewExprNode(GLOBAL_DATA, $2.m_node, $3.m_node);
414 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @3.last_column);
415 $$ = createNodeInfo<ExpressionNode*>(node, $2.m_features | $3.m_features, $2.m_numConstants + $3.m_numConstants);
416 }
417 ;
418
419 NewExpr:
420 MemberExpr
421 | NEW NewExpr { NewExprNode* node = new NewExprNode(GLOBAL_DATA, $2.m_node);
422 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
423 $$ = createNodeInfo<ExpressionNode*>(node, $2.m_features, $2.m_numConstants);
424 }
425 ;
426
427 NewExprNoBF:
428 MemberExprNoBF
429 | NEW NewExpr { NewExprNode* node = new NewExprNode(GLOBAL_DATA, $2.m_node);
430 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
431 $$ = createNodeInfo<ExpressionNode*>(node, $2.m_features, $2.m_numConstants);
432 }
433 ;
434
435 CallExpr:
436 MemberExpr Arguments { $$ = makeFunctionCallNode(globalPtr, $1, $2, @1.first_column, @1.last_column, @2.last_column); }
437 | CallExpr Arguments { $$ = makeFunctionCallNode(globalPtr, $1, $2, @1.first_column, @1.last_column, @2.last_column); }
438 | CallExpr '[' Expr ']' { BracketAccessorNode* node = new BracketAccessorNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
439 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @4.last_column);
440 $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants);
441 }
442 | CallExpr '.' IDENT { DotAccessorNode* node = new DotAccessorNode(GLOBAL_DATA, $1.m_node, *$3);
443 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @3.last_column);
444 $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features, $1.m_numConstants); }
445 ;
446
447 CallExprNoBF:
448 MemberExprNoBF Arguments { $$ = makeFunctionCallNode(globalPtr, $1, $2, @1.first_column, @1.last_column, @2.last_column); }
449 | CallExprNoBF Arguments { $$ = makeFunctionCallNode(globalPtr, $1, $2, @1.first_column, @1.last_column, @2.last_column); }
450 | CallExprNoBF '[' Expr ']' { BracketAccessorNode* node = new BracketAccessorNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
451 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @4.last_column);
452 $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants);
453 }
454 | CallExprNoBF '.' IDENT { DotAccessorNode* node = new DotAccessorNode(GLOBAL_DATA, $1.m_node, *$3);
455 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @3.last_column);
456 $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features, $1.m_numConstants);
457 }
458 ;
459
460 Arguments:
461 '(' ')' { $$ = createNodeInfo<ArgumentsNode*>(new ArgumentsNode(GLOBAL_DATA), 0, 0); }
462 | '(' ArgumentList ')' { $$ = createNodeInfo<ArgumentsNode*>(new ArgumentsNode(GLOBAL_DATA, $2.m_node.head), $2.m_features, $2.m_numConstants); }
463 ;
464
465 ArgumentList:
466 AssignmentExpr { $$.m_node.head = new ArgumentListNode(GLOBAL_DATA, $1.m_node);
467 $$.m_node.tail = $$.m_node.head;
468 $$.m_features = $1.m_features;
469 $$.m_numConstants = $1.m_numConstants; }
470 | ArgumentList ',' AssignmentExpr { $$.m_node.head = $1.m_node.head;
471 $$.m_node.tail = new ArgumentListNode(GLOBAL_DATA, $1.m_node.tail, $3.m_node);
472 $$.m_features = $1.m_features | $3.m_features;
473 $$.m_numConstants = $1.m_numConstants + $3.m_numConstants; }
474 ;
475
476 LeftHandSideExpr:
477 NewExpr
478 | CallExpr
479 ;
480
481 LeftHandSideExprNoBF:
482 NewExprNoBF
483 | CallExprNoBF
484 ;
485
486 PostfixExpr:
487 LeftHandSideExpr
488 | LeftHandSideExpr PLUSPLUS { $$ = createNodeInfo<ExpressionNode*>(makePostfixNode(GLOBAL_DATA, $1.m_node, OpPlusPlus, @1.first_column, @1.last_column, @2.last_column), $1.m_features | AssignFeature, $1.m_numConstants); }
489 | LeftHandSideExpr MINUSMINUS { $$ = createNodeInfo<ExpressionNode*>(makePostfixNode(GLOBAL_DATA, $1.m_node, OpMinusMinus, @1.first_column, @1.last_column, @2.last_column), $1.m_features | AssignFeature, $1.m_numConstants); }
490 ;
491
492 PostfixExprNoBF:
493 LeftHandSideExprNoBF
494 | LeftHandSideExprNoBF PLUSPLUS { $$ = createNodeInfo<ExpressionNode*>(makePostfixNode(GLOBAL_DATA, $1.m_node, OpPlusPlus, @1.first_column, @1.last_column, @2.last_column), $1.m_features | AssignFeature, $1.m_numConstants); }
495 | LeftHandSideExprNoBF MINUSMINUS { $$ = createNodeInfo<ExpressionNode*>(makePostfixNode(GLOBAL_DATA, $1.m_node, OpMinusMinus, @1.first_column, @1.last_column, @2.last_column), $1.m_features | AssignFeature, $1.m_numConstants); }
496 ;
497
498 UnaryExprCommon:
499 DELETETOKEN UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(makeDeleteNode(GLOBAL_DATA, $2.m_node, @1.first_column, @2.last_column, @2.last_column), $2.m_features, $2.m_numConstants); }
500 | VOIDTOKEN UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(new VoidNode(GLOBAL_DATA, $2.m_node), $2.m_features, $2.m_numConstants + 1); }
501 | TYPEOF UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(makeTypeOfNode(GLOBAL_DATA, $2.m_node), $2.m_features, $2.m_numConstants); }
502 | PLUSPLUS UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(makePrefixNode(GLOBAL_DATA, $2.m_node, OpPlusPlus, @1.first_column, @2.first_column + 1, @2.last_column), $2.m_features | AssignFeature, $2.m_numConstants); }
503 | AUTOPLUSPLUS UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(makePrefixNode(GLOBAL_DATA, $2.m_node, OpPlusPlus, @1.first_column, @2.first_column + 1, @2.last_column), $2.m_features | AssignFeature, $2.m_numConstants); }
504 | MINUSMINUS UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(makePrefixNode(GLOBAL_DATA, $2.m_node, OpMinusMinus, @1.first_column, @2.first_column + 1, @2.last_column), $2.m_features | AssignFeature, $2.m_numConstants); }
505 | AUTOMINUSMINUS UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(makePrefixNode(GLOBAL_DATA, $2.m_node, OpMinusMinus, @1.first_column, @2.first_column + 1, @2.last_column), $2.m_features | AssignFeature, $2.m_numConstants); }
506 | '+' UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(new UnaryPlusNode(GLOBAL_DATA, $2.m_node), $2.m_features, $2.m_numConstants); }
507 | '-' UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(makeNegateNode(GLOBAL_DATA, $2.m_node), $2.m_features, $2.m_numConstants); }
508 | '~' UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(makeBitwiseNotNode(GLOBAL_DATA, $2.m_node), $2.m_features, $2.m_numConstants); }
509 | '!' UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(new LogicalNotNode(GLOBAL_DATA, $2.m_node), $2.m_features, $2.m_numConstants); }
510
511 UnaryExpr:
512 PostfixExpr
513 | UnaryExprCommon
514 ;
515
516 UnaryExprNoBF:
517 PostfixExprNoBF
518 | UnaryExprCommon
519 ;
520
521 MultiplicativeExpr:
522 UnaryExpr
523 | MultiplicativeExpr '*' UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(makeMultNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
524 | MultiplicativeExpr '/' UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(makeDivNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
525 | MultiplicativeExpr '%' UnaryExpr { $$ = createNodeInfo<ExpressionNode*>(new ModNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
526 ;
527
528 MultiplicativeExprNoBF:
529 UnaryExprNoBF
530 | MultiplicativeExprNoBF '*' UnaryExpr
531 { $$ = createNodeInfo<ExpressionNode*>(makeMultNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
532 | MultiplicativeExprNoBF '/' UnaryExpr
533 { $$ = createNodeInfo<ExpressionNode*>(makeDivNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
534 | MultiplicativeExprNoBF '%' UnaryExpr
535 { $$ = createNodeInfo<ExpressionNode*>(new ModNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
536 ;
537
538 AdditiveExpr:
539 MultiplicativeExpr
540 | AdditiveExpr '+' MultiplicativeExpr { $$ = createNodeInfo<ExpressionNode*>(makeAddNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
541 | AdditiveExpr '-' MultiplicativeExpr { $$ = createNodeInfo<ExpressionNode*>(makeSubNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
542 ;
543
544 AdditiveExprNoBF:
545 MultiplicativeExprNoBF
546 | AdditiveExprNoBF '+' MultiplicativeExpr
547 { $$ = createNodeInfo<ExpressionNode*>(makeAddNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
548 | AdditiveExprNoBF '-' MultiplicativeExpr
549 { $$ = createNodeInfo<ExpressionNode*>(makeSubNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
550 ;
551
552 ShiftExpr:
553 AdditiveExpr
554 | ShiftExpr LSHIFT AdditiveExpr { $$ = createNodeInfo<ExpressionNode*>(makeLeftShiftNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
555 | ShiftExpr RSHIFT AdditiveExpr { $$ = createNodeInfo<ExpressionNode*>(makeRightShiftNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
556 | ShiftExpr URSHIFT AdditiveExpr { $$ = createNodeInfo<ExpressionNode*>(new UnsignedRightShiftNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
557 ;
558
559 ShiftExprNoBF:
560 AdditiveExprNoBF
561 | ShiftExprNoBF LSHIFT AdditiveExpr { $$ = createNodeInfo<ExpressionNode*>(makeLeftShiftNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
562 | ShiftExprNoBF RSHIFT AdditiveExpr { $$ = createNodeInfo<ExpressionNode*>(makeRightShiftNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
563 | ShiftExprNoBF URSHIFT AdditiveExpr { $$ = createNodeInfo<ExpressionNode*>(new UnsignedRightShiftNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
564 ;
565
566 RelationalExpr:
567 ShiftExpr
568 | RelationalExpr '<' ShiftExpr { $$ = createNodeInfo<ExpressionNode*>(new LessNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
569 | RelationalExpr '>' ShiftExpr { $$ = createNodeInfo<ExpressionNode*>(new GreaterNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
570 | RelationalExpr LE ShiftExpr { $$ = createNodeInfo<ExpressionNode*>(new LessEqNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
571 | RelationalExpr GE ShiftExpr { $$ = createNodeInfo<ExpressionNode*>(new GreaterEqNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
572 | RelationalExpr INSTANCEOF ShiftExpr { InstanceOfNode* node = new InstanceOfNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
573 SET_EXCEPTION_LOCATION(node, @1.first_column, @3.first_column, @3.last_column);
574 $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
575 | RelationalExpr INTOKEN ShiftExpr { InNode* node = new InNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
576 SET_EXCEPTION_LOCATION(node, @1.first_column, @3.first_column, @3.last_column);
577 $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
578 ;
579
580 RelationalExprNoIn:
581 ShiftExpr
582 | RelationalExprNoIn '<' ShiftExpr { $$ = createNodeInfo<ExpressionNode*>(new LessNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
583 | RelationalExprNoIn '>' ShiftExpr { $$ = createNodeInfo<ExpressionNode*>(new GreaterNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
584 | RelationalExprNoIn LE ShiftExpr { $$ = createNodeInfo<ExpressionNode*>(new LessEqNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
585 | RelationalExprNoIn GE ShiftExpr { $$ = createNodeInfo<ExpressionNode*>(new GreaterEqNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
586 | RelationalExprNoIn INSTANCEOF ShiftExpr
587 { InstanceOfNode* node = new InstanceOfNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
588 SET_EXCEPTION_LOCATION(node, @1.first_column, @3.first_column, @3.last_column);
589 $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
590 ;
591
592 RelationalExprNoBF:
593 ShiftExprNoBF
594 | RelationalExprNoBF '<' ShiftExpr { $$ = createNodeInfo<ExpressionNode*>(new LessNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
595 | RelationalExprNoBF '>' ShiftExpr { $$ = createNodeInfo<ExpressionNode*>(new GreaterNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
596 | RelationalExprNoBF LE ShiftExpr { $$ = createNodeInfo<ExpressionNode*>(new LessEqNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
597 | RelationalExprNoBF GE ShiftExpr { $$ = createNodeInfo<ExpressionNode*>(new GreaterEqNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
598 | RelationalExprNoBF INSTANCEOF ShiftExpr
599 { InstanceOfNode* node = new InstanceOfNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
600 SET_EXCEPTION_LOCATION(node, @1.first_column, @3.first_column, @3.last_column);
601 $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
602 | RelationalExprNoBF INTOKEN ShiftExpr
603 { InNode* node = new InNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
604 SET_EXCEPTION_LOCATION(node, @1.first_column, @3.first_column, @3.last_column);
605 $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
606 ;
607
608 EqualityExpr:
609 RelationalExpr
610 | EqualityExpr EQEQ RelationalExpr { $$ = createNodeInfo<ExpressionNode*>(new EqualNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
611 | EqualityExpr NE RelationalExpr { $$ = createNodeInfo<ExpressionNode*>(new NotEqualNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
612 | EqualityExpr STREQ RelationalExpr { $$ = createNodeInfo<ExpressionNode*>(new StrictEqualNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
613 | EqualityExpr STRNEQ RelationalExpr { $$ = createNodeInfo<ExpressionNode*>(new NotStrictEqualNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
614 ;
615
616 EqualityExprNoIn:
617 RelationalExprNoIn
618 | EqualityExprNoIn EQEQ RelationalExprNoIn
619 { $$ = createNodeInfo<ExpressionNode*>(new EqualNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
620 | EqualityExprNoIn NE RelationalExprNoIn
621 { $$ = createNodeInfo<ExpressionNode*>(new NotEqualNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
622 | EqualityExprNoIn STREQ RelationalExprNoIn
623 { $$ = createNodeInfo<ExpressionNode*>(new StrictEqualNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
624 | EqualityExprNoIn STRNEQ RelationalExprNoIn
625 { $$ = createNodeInfo<ExpressionNode*>(new NotStrictEqualNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
626 ;
627
628 EqualityExprNoBF:
629 RelationalExprNoBF
630 | EqualityExprNoBF EQEQ RelationalExpr
631 { $$ = createNodeInfo<ExpressionNode*>(new EqualNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
632 | EqualityExprNoBF NE RelationalExpr { $$ = createNodeInfo<ExpressionNode*>(new NotEqualNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
633 | EqualityExprNoBF STREQ RelationalExpr
634 { $$ = createNodeInfo<ExpressionNode*>(new StrictEqualNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
635 | EqualityExprNoBF STRNEQ RelationalExpr
636 { $$ = createNodeInfo<ExpressionNode*>(new NotStrictEqualNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
637 ;
638
639 BitwiseANDExpr:
640 EqualityExpr
641 | BitwiseANDExpr '&' EqualityExpr { $$ = createNodeInfo<ExpressionNode*>(new BitAndNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
642 ;
643
644 BitwiseANDExprNoIn:
645 EqualityExprNoIn
646 | BitwiseANDExprNoIn '&' EqualityExprNoIn
647 { $$ = createNodeInfo<ExpressionNode*>(new BitAndNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
648 ;
649
650 BitwiseANDExprNoBF:
651 EqualityExprNoBF
652 | BitwiseANDExprNoBF '&' EqualityExpr { $$ = createNodeInfo<ExpressionNode*>(new BitAndNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
653 ;
654
655 BitwiseXORExpr:
656 BitwiseANDExpr
657 | BitwiseXORExpr '^' BitwiseANDExpr { $$ = createNodeInfo<ExpressionNode*>(new BitXOrNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
658 ;
659
660 BitwiseXORExprNoIn:
661 BitwiseANDExprNoIn
662 | BitwiseXORExprNoIn '^' BitwiseANDExprNoIn
663 { $$ = createNodeInfo<ExpressionNode*>(new BitXOrNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
664 ;
665
666 BitwiseXORExprNoBF:
667 BitwiseANDExprNoBF
668 | BitwiseXORExprNoBF '^' BitwiseANDExpr
669 { $$ = createNodeInfo<ExpressionNode*>(new BitXOrNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
670 ;
671
672 BitwiseORExpr:
673 BitwiseXORExpr
674 | BitwiseORExpr '|' BitwiseXORExpr { $$ = createNodeInfo<ExpressionNode*>(new BitOrNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
675 ;
676
677 BitwiseORExprNoIn:
678 BitwiseXORExprNoIn
679 | BitwiseORExprNoIn '|' BitwiseXORExprNoIn
680 { $$ = createNodeInfo<ExpressionNode*>(new BitOrNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
681 ;
682
683 BitwiseORExprNoBF:
684 BitwiseXORExprNoBF
685 | BitwiseORExprNoBF '|' BitwiseXORExpr
686 { $$ = createNodeInfo<ExpressionNode*>(new BitOrNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
687 ;
688
689 LogicalANDExpr:
690 BitwiseORExpr
691 | LogicalANDExpr AND BitwiseORExpr { $$ = createNodeInfo<ExpressionNode*>(new LogicalOpNode(GLOBAL_DATA, $1.m_node, $3.m_node, OpLogicalAnd), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
692 ;
693
694 LogicalANDExprNoIn:
695 BitwiseORExprNoIn
696 | LogicalANDExprNoIn AND BitwiseORExprNoIn
697 { $$ = createNodeInfo<ExpressionNode*>(new LogicalOpNode(GLOBAL_DATA, $1.m_node, $3.m_node, OpLogicalAnd), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
698 ;
699
700 LogicalANDExprNoBF:
701 BitwiseORExprNoBF
702 | LogicalANDExprNoBF AND BitwiseORExpr
703 { $$ = createNodeInfo<ExpressionNode*>(new LogicalOpNode(GLOBAL_DATA, $1.m_node, $3.m_node, OpLogicalAnd), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
704 ;
705
706 LogicalORExpr:
707 LogicalANDExpr
708 | LogicalORExpr OR LogicalANDExpr { $$ = createNodeInfo<ExpressionNode*>(new LogicalOpNode(GLOBAL_DATA, $1.m_node, $3.m_node, OpLogicalOr), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
709 ;
710
711 LogicalORExprNoIn:
712 LogicalANDExprNoIn
713 | LogicalORExprNoIn OR LogicalANDExprNoIn
714 { $$ = createNodeInfo<ExpressionNode*>(new LogicalOpNode(GLOBAL_DATA, $1.m_node, $3.m_node, OpLogicalOr), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
715 ;
716
717 LogicalORExprNoBF:
718 LogicalANDExprNoBF
719 | LogicalORExprNoBF OR LogicalANDExpr { $$ = createNodeInfo<ExpressionNode*>(new LogicalOpNode(GLOBAL_DATA, $1.m_node, $3.m_node, OpLogicalOr), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
720 ;
721
722 ConditionalExpr:
723 LogicalORExpr
724 | LogicalORExpr '?' AssignmentExpr ':' AssignmentExpr
725 { $$ = createNodeInfo<ExpressionNode*>(new ConditionalNode(GLOBAL_DATA, $1.m_node, $3.m_node, $5.m_node), $1.m_features | $3.m_features | $5.m_features, $1.m_numConstants + $3.m_numConstants + $5.m_numConstants); }
726 ;
727
728 ConditionalExprNoIn:
729 LogicalORExprNoIn
730 | LogicalORExprNoIn '?' AssignmentExprNoIn ':' AssignmentExprNoIn
731 { $$ = createNodeInfo<ExpressionNode*>(new ConditionalNode(GLOBAL_DATA, $1.m_node, $3.m_node, $5.m_node), $1.m_features | $3.m_features | $5.m_features, $1.m_numConstants + $3.m_numConstants + $5.m_numConstants); }
732 ;
733
734 ConditionalExprNoBF:
735 LogicalORExprNoBF
736 | LogicalORExprNoBF '?' AssignmentExpr ':' AssignmentExpr
737 { $$ = createNodeInfo<ExpressionNode*>(new ConditionalNode(GLOBAL_DATA, $1.m_node, $3.m_node, $5.m_node), $1.m_features | $3.m_features | $5.m_features, $1.m_numConstants + $3.m_numConstants + $5.m_numConstants); }
738 ;
739
740 AssignmentExpr:
741 ConditionalExpr
742 | LeftHandSideExpr AssignmentOperator AssignmentExpr
743 { $$ = createNodeInfo<ExpressionNode*>(makeAssignNode(GLOBAL_DATA, $1.m_node, $2, $3.m_node, $1.m_features & AssignFeature, $3.m_features & AssignFeature,
744 @1.first_column, @2.first_column + 1, @3.last_column), $1.m_features | $3.m_features | AssignFeature, $1.m_numConstants + $3.m_numConstants);
745 }
746 ;
747
748 AssignmentExprNoIn:
749 ConditionalExprNoIn
750 | LeftHandSideExpr AssignmentOperator AssignmentExprNoIn
751 { $$ = createNodeInfo<ExpressionNode*>(makeAssignNode(GLOBAL_DATA, $1.m_node, $2, $3.m_node, $1.m_features & AssignFeature, $3.m_features & AssignFeature,
752 @1.first_column, @2.first_column + 1, @3.last_column), $1.m_features | $3.m_features | AssignFeature, $1.m_numConstants + $3.m_numConstants);
753 }
754 ;
755
756 AssignmentExprNoBF:
757 ConditionalExprNoBF
758 | LeftHandSideExprNoBF AssignmentOperator AssignmentExpr
759 { $$ = createNodeInfo<ExpressionNode*>(makeAssignNode(GLOBAL_DATA, $1.m_node, $2, $3.m_node, $1.m_features & AssignFeature, $3.m_features & AssignFeature,
760 @1.first_column, @2.first_column + 1, @3.last_column), $1.m_features | $3.m_features | AssignFeature, $1.m_numConstants + $3.m_numConstants);
761 }
762 ;
763
764 AssignmentOperator:
765 '=' { $$ = OpEqual; }
766 | PLUSEQUAL { $$ = OpPlusEq; }
767 | MINUSEQUAL { $$ = OpMinusEq; }
768 | MULTEQUAL { $$ = OpMultEq; }
769 | DIVEQUAL { $$ = OpDivEq; }
770 | LSHIFTEQUAL { $$ = OpLShift; }
771 | RSHIFTEQUAL { $$ = OpRShift; }
772 | URSHIFTEQUAL { $$ = OpURShift; }
773 | ANDEQUAL { $$ = OpAndEq; }
774 | XOREQUAL { $$ = OpXOrEq; }
775 | OREQUAL { $$ = OpOrEq; }
776 | MODEQUAL { $$ = OpModEq; }
777 ;
778
779 Expr:
780 AssignmentExpr
781 | Expr ',' AssignmentExpr { $$ = createNodeInfo<ExpressionNode*>(new CommaNode(GLOBAL_DATA, $1.m_node, $3.m_node), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
782 ;
783
784 ExprNoIn:
785 AssignmentExprNoIn
786 | ExprNoIn ',' AssignmentExprNoIn { $$ = createNodeInfo<ExpressionNode*>(new CommaNode(GLOBAL_DATA, $1.m_node, $3.m_node), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
787 ;
788
789 ExprNoBF:
790 AssignmentExprNoBF
791 | ExprNoBF ',' AssignmentExpr { $$ = createNodeInfo<ExpressionNode*>(new CommaNode(GLOBAL_DATA, $1.m_node, $3.m_node), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
792 ;
793
794 Statement:
795 Block
796 | VariableStatement
797 | ConstStatement
798 | FunctionDeclaration
799 | EmptyStatement
800 | ExprStatement
801 | IfStatement
802 | IterationStatement
803 | ContinueStatement
804 | BreakStatement
805 | ReturnStatement
806 | WithStatement
807 | SwitchStatement
808 | LabelledStatement
809 | ThrowStatement
810 | TryStatement
811 | DebuggerStatement
812 ;
813
814 Block:
815 OPENBRACE CLOSEBRACE { $$ = createNodeDeclarationInfo<StatementNode*>(new BlockNode(GLOBAL_DATA, 0), 0, 0, 0, 0);
816 DBG($$.m_node, @1, @2); }
817 | OPENBRACE SourceElements CLOSEBRACE { $$ = createNodeDeclarationInfo<StatementNode*>(new BlockNode(GLOBAL_DATA, $2.m_node), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features, $2.m_numConstants);
818 DBG($$.m_node, @1, @3); }
819 ;
820
821 VariableStatement:
822 VAR VariableDeclarationList ';' { $$ = createNodeDeclarationInfo<StatementNode*>(makeVarStatementNode(GLOBAL_DATA, $2.m_node), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features, $2.m_numConstants);
823 DBG($$.m_node, @1, @3); }
824 | VAR VariableDeclarationList error { $$ = createNodeDeclarationInfo<StatementNode*>(makeVarStatementNode(GLOBAL_DATA, $2.m_node), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features, $2.m_numConstants);
825 DBG($$.m_node, @1, @2);
826 AUTO_SEMICOLON; }
827 ;
828
829 VariableDeclarationList:
830 IDENT { $$.m_node = 0;
831 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);
832 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$1, 0);
833 $$.m_funcDeclarations = 0;
834 $$.m_features = (*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0;
835 $$.m_numConstants = 0;
836 }
837 | IDENT Initializer { AssignResolveNode* node = new AssignResolveNode(GLOBAL_DATA, *$1, $2.m_node, $2.m_features & AssignFeature);
838 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.first_column + 1, @2.last_column);
839 $$.m_node = node;
840 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);
841 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$1, DeclarationStacks::HasInitializer);
842 $$.m_funcDeclarations = 0;
843 $$.m_features = ((*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $2.m_features;
844 $$.m_numConstants = $2.m_numConstants;
845 }
846 | VariableDeclarationList ',' IDENT
847 { $$.m_node = $1.m_node;
848 $$.m_varDeclarations = $1.m_varDeclarations;
849 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$3, 0);
850 $$.m_funcDeclarations = 0;
851 $$.m_features = $1.m_features | ((*$3 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0);
852 $$.m_numConstants = $1.m_numConstants;
853 }
854 | VariableDeclarationList ',' IDENT Initializer
855 { AssignResolveNode* node = new AssignResolveNode(GLOBAL_DATA, *$3, $4.m_node, $4.m_features & AssignFeature);
856 SET_EXCEPTION_LOCATION(node, @3.first_column, @4.first_column + 1, @4.last_column);
857 $$.m_node = combineVarInitializers(GLOBAL_DATA, $1.m_node, node);
858 $$.m_varDeclarations = $1.m_varDeclarations;
859 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$3, DeclarationStacks::HasInitializer);
860 $$.m_funcDeclarations = 0;
861 $$.m_features = $1.m_features | ((*$3 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $4.m_features;
862 $$.m_numConstants = $1.m_numConstants + $4.m_numConstants;
863 }
864 ;
865
866 VariableDeclarationListNoIn:
867 IDENT { $$.m_node = 0;
868 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);
869 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$1, 0);
870 $$.m_funcDeclarations = 0;
871 $$.m_features = (*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0;
872 $$.m_numConstants = 0;
873 }
874 | IDENT InitializerNoIn { AssignResolveNode* node = new AssignResolveNode(GLOBAL_DATA, *$1, $2.m_node, $2.m_features & AssignFeature);
875 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.first_column + 1, @2.last_column);
876 $$.m_node = node;
877 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);
878 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$1, DeclarationStacks::HasInitializer);
879 $$.m_funcDeclarations = 0;
880 $$.m_features = ((*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $2.m_features;
881 $$.m_numConstants = $2.m_numConstants;
882 }
883 | VariableDeclarationListNoIn ',' IDENT
884 { $$.m_node = $1.m_node;
885 $$.m_varDeclarations = $1.m_varDeclarations;
886 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$3, 0);
887 $$.m_funcDeclarations = 0;
888 $$.m_features = $1.m_features | ((*$3 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0);
889 $$.m_numConstants = $1.m_numConstants;
890 }
891 | VariableDeclarationListNoIn ',' IDENT InitializerNoIn
892 { AssignResolveNode* node = new AssignResolveNode(GLOBAL_DATA, *$3, $4.m_node, $4.m_features & AssignFeature);
893 SET_EXCEPTION_LOCATION(node, @3.first_column, @4.first_column + 1, @4.last_column);
894 $$.m_node = combineVarInitializers(GLOBAL_DATA, $1.m_node, node);
895 $$.m_varDeclarations = $1.m_varDeclarations;
896 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$3, DeclarationStacks::HasInitializer);
897 $$.m_funcDeclarations = 0;
898 $$.m_features = $1.m_features | ((*$3 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $4.m_features;
899 $$.m_numConstants = $1.m_numConstants + $4.m_numConstants;
900 }
901 ;
902
903 ConstStatement:
904 CONSTTOKEN ConstDeclarationList ';' { $$ = createNodeDeclarationInfo<StatementNode*>(new ConstStatementNode(GLOBAL_DATA, $2.m_node.head), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features, $2.m_numConstants);
905 DBG($$.m_node, @1, @3); }
906 | CONSTTOKEN ConstDeclarationList error
907 { $$ = createNodeDeclarationInfo<StatementNode*>(new ConstStatementNode(GLOBAL_DATA, $2.m_node.head), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features, $2.m_numConstants);
908 DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
909 ;
910
911 ConstDeclarationList:
912 ConstDeclaration { $$.m_node.head = $1.m_node;
913 $$.m_node.tail = $$.m_node.head;
914 $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);
915 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, $1.m_node);
916 $$.m_funcDeclarations = 0;
917 $$.m_features = $1.m_features;
918 $$.m_numConstants = $1.m_numConstants;
919 }
920 | ConstDeclarationList ',' ConstDeclaration
921 { $$.m_node.head = $1.m_node.head;
922 $1.m_node.tail->m_next = $3.m_node;
923 $$.m_node.tail = $3.m_node;
924 $$.m_varDeclarations = $1.m_varDeclarations;
925 appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, $3.m_node);
926 $$.m_funcDeclarations = 0;
927 $$.m_features = $1.m_features | $3.m_features;
928 $$.m_numConstants = $1.m_numConstants + $3.m_numConstants; }
929 ;
930
931 ConstDeclaration:
932 IDENT { $$ = createNodeInfo<ConstDeclNode*>(new ConstDeclNode(GLOBAL_DATA, *$1, 0), (*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0, 0); }
933 | IDENT Initializer { $$ = createNodeInfo<ConstDeclNode*>(new ConstDeclNode(GLOBAL_DATA, *$1, $2.m_node), ((*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $2.m_features, $2.m_numConstants); }
934 ;
935
936 Initializer:
937 '=' AssignmentExpr { $$ = $2; }
938 ;
939
940 InitializerNoIn:
941 '=' AssignmentExprNoIn { $$ = $2; }
942 ;
943
944 EmptyStatement:
945 ';' { $$ = createNodeDeclarationInfo<StatementNode*>(new EmptyStatementNode(GLOBAL_DATA), 0, 0, 0, 0); }
946 ;
947
948 ExprStatement:
949 ExprNoBF ';' { $$ = createNodeDeclarationInfo<StatementNode*>(new ExprStatementNode(GLOBAL_DATA, $1.m_node), 0, 0, $1.m_features, $1.m_numConstants);
950 DBG($$.m_node, @1, @2); }
951 | ExprNoBF error { $$ = createNodeDeclarationInfo<StatementNode*>(new ExprStatementNode(GLOBAL_DATA, $1.m_node), 0, 0, $1.m_features, $1.m_numConstants);
952 DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
953 ;
954
955 IfStatement:
956 IF '(' Expr ')' Statement %prec IF_WITHOUT_ELSE
957 { $$ = createNodeDeclarationInfo<StatementNode*>(new IfNode(GLOBAL_DATA, $3.m_node, $5.m_node), $5.m_varDeclarations, $5.m_funcDeclarations, $3.m_features | $5.m_features, $3.m_numConstants + $5.m_numConstants);
958 DBG($$.m_node, @1, @4); }
959 | IF '(' Expr ')' Statement ELSE Statement
960 { $$ = createNodeDeclarationInfo<StatementNode*>(new IfElseNode(GLOBAL_DATA, $3.m_node, $5.m_node, $7.m_node),
961 mergeDeclarationLists($5.m_varDeclarations, $7.m_varDeclarations), mergeDeclarationLists($5.m_funcDeclarations, $7.m_funcDeclarations),
962 $3.m_features | $5.m_features | $7.m_features,
963 $3.m_numConstants + $5.m_numConstants + $7.m_numConstants);
964 DBG($$.m_node, @1, @4); }
965 ;
966
967 IterationStatement:
968 DO Statement WHILE '(' Expr ')' ';' { $$ = createNodeDeclarationInfo<StatementNode*>(new DoWhileNode(GLOBAL_DATA, $2.m_node, $5.m_node), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features | $5.m_features, $2.m_numConstants + $5.m_numConstants);
969 DBG($$.m_node, @1, @3); }
970 | DO Statement WHILE '(' Expr ')' error { $$ = createNodeDeclarationInfo<StatementNode*>(new DoWhileNode(GLOBAL_DATA, $2.m_node, $5.m_node), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features | $5.m_features, $2.m_numConstants + $5.m_numConstants);
971 DBG($$.m_node, @1, @3); } // Always performs automatic semicolon insertion.
972 | WHILE '(' Expr ')' Statement { $$ = createNodeDeclarationInfo<StatementNode*>(new WhileNode(GLOBAL_DATA, $3.m_node, $5.m_node), $5.m_varDeclarations, $5.m_funcDeclarations, $3.m_features | $5.m_features, $3.m_numConstants + $5.m_numConstants);
973 DBG($$.m_node, @1, @4); }
974 | FOR '(' ExprNoInOpt ';' ExprOpt ';' ExprOpt ')' Statement
975 { $$ = createNodeDeclarationInfo<StatementNode*>(new ForNode(GLOBAL_DATA, $3.m_node, $5.m_node, $7.m_node, $9.m_node, false), $9.m_varDeclarations, $9.m_funcDeclarations,
976 $3.m_features | $5.m_features | $7.m_features | $9.m_features,
977 $3.m_numConstants + $5.m_numConstants + $7.m_numConstants + $9.m_numConstants);
978 DBG($$.m_node, @1, @8);
979 }
980 | FOR '(' VAR VariableDeclarationListNoIn ';' ExprOpt ';' ExprOpt ')' Statement
981 { $$ = createNodeDeclarationInfo<StatementNode*>(new ForNode(GLOBAL_DATA, $4.m_node, $6.m_node, $8.m_node, $10.m_node, true),
982 mergeDeclarationLists($4.m_varDeclarations, $10.m_varDeclarations),
983 mergeDeclarationLists($4.m_funcDeclarations, $10.m_funcDeclarations),
984 $4.m_features | $6.m_features | $8.m_features | $10.m_features,
985 $4.m_numConstants + $6.m_numConstants + $8.m_numConstants + $10.m_numConstants);
986 DBG($$.m_node, @1, @9); }
987 | FOR '(' LeftHandSideExpr INTOKEN Expr ')' Statement
988 {
989 ForInNode* node = new ForInNode(GLOBAL_DATA, $3.m_node, $5.m_node, $7.m_node);
990 SET_EXCEPTION_LOCATION(node, @3.first_column, @3.last_column, @5.last_column);
991 $$ = createNodeDeclarationInfo<StatementNode*>(node, $7.m_varDeclarations, $7.m_funcDeclarations,
992 $3.m_features | $5.m_features | $7.m_features,
993 $3.m_numConstants + $5.m_numConstants + $7.m_numConstants);
994 DBG($$.m_node, @1, @6);
995 }
996 | FOR '(' VAR IDENT INTOKEN Expr ')' Statement
997 { ForInNode *forIn = new ForInNode(GLOBAL_DATA, *$4, 0, $6.m_node, $8.m_node, @5.first_column, @5.first_column - @4.first_column, @6.last_column - @5.first_column);
998 SET_EXCEPTION_LOCATION(forIn, @4.first_column, @5.first_column + 1, @6.last_column);
999 appendToVarDeclarationList(GLOBAL_DATA, $8.m_varDeclarations, *$4, DeclarationStacks::HasInitializer);
1000 $$ = createNodeDeclarationInfo<StatementNode*>(forIn, $8.m_varDeclarations, $8.m_funcDeclarations, ((*$4 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $6.m_features | $8.m_features, $6.m_numConstants + $8.m_numConstants);
1001 DBG($$.m_node, @1, @7); }
1002 | FOR '(' VAR IDENT InitializerNoIn INTOKEN Expr ')' Statement
1003 { ForInNode *forIn = new ForInNode(GLOBAL_DATA, *$4, $5.m_node, $7.m_node, $9.m_node, @5.first_column, @5.first_column - @4.first_column, @5.last_column - @5.first_column);
1004 SET_EXCEPTION_LOCATION(forIn, @4.first_column, @6.first_column + 1, @7.last_column);
1005 appendToVarDeclarationList(GLOBAL_DATA, $9.m_varDeclarations, *$4, DeclarationStacks::HasInitializer);
1006 $$ = createNodeDeclarationInfo<StatementNode*>(forIn, $9.m_varDeclarations, $9.m_funcDeclarations,
1007 ((*$4 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $5.m_features | $7.m_features | $9.m_features,
1008 $5.m_numConstants + $7.m_numConstants + $9.m_numConstants);
1009 DBG($$.m_node, @1, @8); }
1010 ;
1011
1012 ExprOpt:
1013 /* nothing */ { $$ = createNodeInfo<ExpressionNode*>(0, 0, 0); }
1014 | Expr
1015 ;
1016
1017 ExprNoInOpt:
1018 /* nothing */ { $$ = createNodeInfo<ExpressionNode*>(0, 0, 0); }
1019 | ExprNoIn
1020 ;
1021
1022 ContinueStatement:
1023 CONTINUE ';' { ContinueNode* node = new ContinueNode(GLOBAL_DATA);
1024 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @1.last_column);
1025 $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0);
1026 DBG($$.m_node, @1, @2); }
1027 | CONTINUE error { ContinueNode* node = new ContinueNode(GLOBAL_DATA);
1028 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @1.last_column);
1029 $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0);
1030 DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
1031 | CONTINUE IDENT ';' { ContinueNode* node = new ContinueNode(GLOBAL_DATA, *$2);
1032 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1033 $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0);
1034 DBG($$.m_node, @1, @3); }
1035 | CONTINUE IDENT error { ContinueNode* node = new ContinueNode(GLOBAL_DATA, *$2);
1036 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1037 $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0);
1038 DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
1039 ;
1040
1041 BreakStatement:
1042 BREAK ';' { BreakNode* node = new BreakNode(GLOBAL_DATA);
1043 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @1.last_column);
1044 $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0); DBG($$.m_node, @1, @2); }
1045 | BREAK error { BreakNode* node = new BreakNode(GLOBAL_DATA);
1046 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @1.last_column);
1047 $$ = createNodeDeclarationInfo<StatementNode*>(new BreakNode(GLOBAL_DATA), 0, 0, 0, 0); DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
1048 | BREAK IDENT ';' { BreakNode* node = new BreakNode(GLOBAL_DATA, *$2);
1049 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1050 $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0); DBG($$.m_node, @1, @3); }
1051 | BREAK IDENT error { BreakNode* node = new BreakNode(GLOBAL_DATA, *$2);
1052 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1053 $$ = createNodeDeclarationInfo<StatementNode*>(new BreakNode(GLOBAL_DATA, *$2), 0, 0, 0, 0); DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
1054 ;
1055
1056 ReturnStatement:
1057 RETURN ';' { ReturnNode* node = new ReturnNode(GLOBAL_DATA, 0);
1058 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @1.last_column);
1059 $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0); DBG($$.m_node, @1, @2); }
1060 | RETURN error { ReturnNode* node = new ReturnNode(GLOBAL_DATA, 0);
1061 SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @1.last_column);
1062 $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0); DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
1063 | RETURN Expr ';' { ReturnNode* node = new ReturnNode(GLOBAL_DATA, $2.m_node);
1064 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1065 $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, $2.m_features, $2.m_numConstants); DBG($$.m_node, @1, @3); }
1066 | RETURN Expr error { ReturnNode* node = new ReturnNode(GLOBAL_DATA, $2.m_node);
1067 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1068 $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, $2.m_features, $2.m_numConstants); DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
1069 ;
1070
1071 WithStatement:
1072 WITH '(' Expr ')' Statement { $$ = createNodeDeclarationInfo<StatementNode*>(new WithNode(GLOBAL_DATA, $3.m_node, $5.m_node, @3.last_column, @3.last_column - @3.first_column),
1073 $5.m_varDeclarations, $5.m_funcDeclarations, $3.m_features | $5.m_features | WithFeature, $3.m_numConstants + $5.m_numConstants);
1074 DBG($$.m_node, @1, @4); }
1075 ;
1076
1077 SwitchStatement:
1078 SWITCH '(' Expr ')' CaseBlock { $$ = createNodeDeclarationInfo<StatementNode*>(new SwitchNode(GLOBAL_DATA, $3.m_node, $5.m_node), $5.m_varDeclarations, $5.m_funcDeclarations,
1079 $3.m_features | $5.m_features, $3.m_numConstants + $5.m_numConstants);
1080 DBG($$.m_node, @1, @4); }
1081 ;
1082
1083 CaseBlock:
1084 OPENBRACE CaseClausesOpt CLOSEBRACE { $$ = createNodeDeclarationInfo<CaseBlockNode*>(new CaseBlockNode(GLOBAL_DATA, $2.m_node.head, 0, 0), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features, $2.m_numConstants); }
1085 | OPENBRACE CaseClausesOpt DefaultClause CaseClausesOpt CLOSEBRACE
1086 { $$ = createNodeDeclarationInfo<CaseBlockNode*>(new CaseBlockNode(GLOBAL_DATA, $2.m_node.head, $3.m_node, $4.m_node.head),
1087 mergeDeclarationLists(mergeDeclarationLists($2.m_varDeclarations, $3.m_varDeclarations), $4.m_varDeclarations),
1088 mergeDeclarationLists(mergeDeclarationLists($2.m_funcDeclarations, $3.m_funcDeclarations), $4.m_funcDeclarations),
1089 $2.m_features | $3.m_features | $4.m_features,
1090 $2.m_numConstants + $3.m_numConstants + $4.m_numConstants); }
1091 ;
1092
1093 CaseClausesOpt:
1094 /* nothing */ { $$.m_node.head = 0; $$.m_node.tail = 0; $$.m_varDeclarations = 0; $$.m_funcDeclarations = 0; $$.m_features = 0; $$.m_numConstants = 0; }
1095 | CaseClauses
1096 ;
1097
1098 CaseClauses:
1099 CaseClause { $$.m_node.head = new ClauseListNode(GLOBAL_DATA, $1.m_node);
1100 $$.m_node.tail = $$.m_node.head;
1101 $$.m_varDeclarations = $1.m_varDeclarations;
1102 $$.m_funcDeclarations = $1.m_funcDeclarations;
1103 $$.m_features = $1.m_features;
1104 $$.m_numConstants = $1.m_numConstants; }
1105 | CaseClauses CaseClause { $$.m_node.head = $1.m_node.head;
1106 $$.m_node.tail = new ClauseListNode(GLOBAL_DATA, $1.m_node.tail, $2.m_node);
1107 $$.m_varDeclarations = mergeDeclarationLists($1.m_varDeclarations, $2.m_varDeclarations);
1108 $$.m_funcDeclarations = mergeDeclarationLists($1.m_funcDeclarations, $2.m_funcDeclarations);
1109 $$.m_features = $1.m_features | $2.m_features;
1110 $$.m_numConstants = $1.m_numConstants + $2.m_numConstants;
1111 }
1112 ;
1113
1114 CaseClause:
1115 CASE Expr ':' { $$ = createNodeDeclarationInfo<CaseClauseNode*>(new CaseClauseNode(GLOBAL_DATA, $2.m_node), 0, 0, $2.m_features, $2.m_numConstants); }
1116 | CASE Expr ':' SourceElements { $$ = createNodeDeclarationInfo<CaseClauseNode*>(new CaseClauseNode(GLOBAL_DATA, $2.m_node, $4.m_node), $4.m_varDeclarations, $4.m_funcDeclarations, $2.m_features | $4.m_features, $2.m_numConstants + $4.m_numConstants); }
1117 ;
1118
1119 DefaultClause:
1120 DEFAULT ':' { $$ = createNodeDeclarationInfo<CaseClauseNode*>(new CaseClauseNode(GLOBAL_DATA, 0), 0, 0, 0, 0); }
1121 | DEFAULT ':' SourceElements { $$ = createNodeDeclarationInfo<CaseClauseNode*>(new CaseClauseNode(GLOBAL_DATA, 0, $3.m_node), $3.m_varDeclarations, $3.m_funcDeclarations, $3.m_features, $3.m_numConstants); }
1122 ;
1123
1124 LabelledStatement:
1125 IDENT ':' Statement { LabelNode* node = new LabelNode(GLOBAL_DATA, *$1, $3.m_node);
1126 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1127 $$ = createNodeDeclarationInfo<StatementNode*>(node, $3.m_varDeclarations, $3.m_funcDeclarations, $3.m_features, $3.m_numConstants); }
1128 ;
1129
1130 ThrowStatement:
1131 THROW Expr ';' { ThrowNode* node = new ThrowNode(GLOBAL_DATA, $2.m_node);
1132 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1133 $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, $2.m_features, $2.m_numConstants); DBG($$.m_node, @1, @2);
1134 }
1135 | THROW Expr error { ThrowNode* node = new ThrowNode(GLOBAL_DATA, $2.m_node);
1136 SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1137 $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, $2.m_features, $2.m_numConstants); DBG($$.m_node, @1, @2); AUTO_SEMICOLON;
1138 }
1139 ;
1140
1141 TryStatement:
1142 TRY Block FINALLY Block { $$ = createNodeDeclarationInfo<StatementNode*>(new TryNode(GLOBAL_DATA, $2.m_node, GLOBAL_DATA->propertyNames->nullIdentifier, false, 0, $4.m_node),
1143 mergeDeclarationLists($2.m_varDeclarations, $4.m_varDeclarations),
1144 mergeDeclarationLists($2.m_funcDeclarations, $4.m_funcDeclarations),
1145 $2.m_features | $4.m_features,
1146 $2.m_numConstants + $4.m_numConstants);
1147 DBG($$.m_node, @1, @2); }
1148 | TRY Block CATCH '(' IDENT ')' Block { $$ = createNodeDeclarationInfo<StatementNode*>(new TryNode(GLOBAL_DATA, $2.m_node, *$5, ($7.m_features & EvalFeature) != 0, $7.m_node, 0),
1149 mergeDeclarationLists($2.m_varDeclarations, $7.m_varDeclarations),
1150 mergeDeclarationLists($2.m_funcDeclarations, $7.m_funcDeclarations),
1151 $2.m_features | $7.m_features | CatchFeature,
1152 $2.m_numConstants + $7.m_numConstants);
1153 DBG($$.m_node, @1, @2); }
1154 | TRY Block CATCH '(' IDENT ')' Block FINALLY Block
1155 { $$ = createNodeDeclarationInfo<StatementNode*>(new TryNode(GLOBAL_DATA, $2.m_node, *$5, ($7.m_features & EvalFeature) != 0, $7.m_node, $9.m_node),
1156 mergeDeclarationLists(mergeDeclarationLists($2.m_varDeclarations, $7.m_varDeclarations), $9.m_varDeclarations),
1157 mergeDeclarationLists(mergeDeclarationLists($2.m_funcDeclarations, $7.m_funcDeclarations), $9.m_funcDeclarations),
1158 $2.m_features | $7.m_features | $9.m_features | CatchFeature,
1159 $2.m_numConstants + $7.m_numConstants + $9.m_numConstants);
1160 DBG($$.m_node, @1, @2); }
1161 ;
1162
1163 DebuggerStatement:
1164 DEBUGGER ';' { $$ = createNodeDeclarationInfo<StatementNode*>(new DebuggerStatementNode(GLOBAL_DATA), 0, 0, 0, 0);
1165 DBG($$.m_node, @1, @2); }
1166 | DEBUGGER error { $$ = createNodeDeclarationInfo<StatementNode*>(new DebuggerStatementNode(GLOBAL_DATA), 0, 0, 0, 0);
1167 DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
1168 ;
1169
1170 FunctionDeclaration:
1171 FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeDeclarationInfo<StatementNode*>(new FuncDeclNode(GLOBAL_DATA, *$2, $6, LEXER->sourceCode($5, $7, @5.first_line)), 0, new ParserRefCountedData<DeclarationStacks::FunctionStack>(GLOBAL_DATA), ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | ClosureFeature, 0); DBG($6, @5, @7); $$.m_funcDeclarations->data.append(static_cast<FuncDeclNode*>($$.m_node)); }
1172 | FUNCTION IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE
1173 {
1174 $$ = createNodeDeclarationInfo<StatementNode*>(new FuncDeclNode(GLOBAL_DATA, *$2, $7, LEXER->sourceCode($6, $8, @6.first_line), $4.m_node.head), 0, new ParserRefCountedData<DeclarationStacks::FunctionStack>(GLOBAL_DATA), ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $4.m_features | ClosureFeature, 0);
1175 if ($4.m_features & ArgumentsFeature)
1176 $7->setUsesArguments();
1177 DBG($7, @6, @8);
1178 $$.m_funcDeclarations->data.append(static_cast<FuncDeclNode*>($$.m_node));
1179 }
1180 ;
1181
1182 FunctionExpr:
1183 FUNCTION '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeInfo(new FuncExprNode(GLOBAL_DATA, GLOBAL_DATA->propertyNames->nullIdentifier, $5, LEXER->sourceCode($4, $6, @4.first_line)), ClosureFeature, 0); DBG($5, @4, @6); }
1184 | FUNCTION '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE
1185 {
1186 $$ = createNodeInfo(new FuncExprNode(GLOBAL_DATA, GLOBAL_DATA->propertyNames->nullIdentifier, $6, LEXER->sourceCode($5, $7, @5.first_line), $3.m_node.head), $3.m_features | ClosureFeature, 0);
1187 if ($3.m_features & ArgumentsFeature)
1188 $6->setUsesArguments();
1189 DBG($6, @5, @7);
1190 }
1191 | FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeInfo(new FuncExprNode(GLOBAL_DATA, *$2, $6, LEXER->sourceCode($5, $7, @5.first_line)), ClosureFeature, 0); DBG($6, @5, @7); }
1192 | FUNCTION IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE
1193 {
1194 $$ = createNodeInfo(new FuncExprNode(GLOBAL_DATA, *$2, $7, LEXER->sourceCode($6, $8, @6.first_line), $4.m_node.head), $4.m_features | ClosureFeature, 0);
1195 if ($4.m_features & ArgumentsFeature)
1196 $7->setUsesArguments();
1197 DBG($7, @6, @8);
1198 }
1199 ;
1200
1201 FormalParameterList:
1202 IDENT { $$.m_node.head = new ParameterNode(GLOBAL_DATA, *$1);
1203 $$.m_features = (*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0;
1204 $$.m_node.tail = $$.m_node.head; }
1205 | FormalParameterList ',' IDENT { $$.m_node.head = $1.m_node.head;
1206 $$.m_features = $1.m_features | ((*$3 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0);
1207 $$.m_node.tail = new ParameterNode(GLOBAL_DATA, $1.m_node.tail, *$3); }
1208 ;
1209
1210 FunctionBody:
1211 /* not in spec */ { $$ = FunctionBodyNode::create(GLOBAL_DATA); }
1212 | SourceElements_NoNode { $$ = FunctionBodyNode::create(GLOBAL_DATA); }
1213 ;
1214
1215 Program:
1216 /* not in spec */ { GLOBAL_DATA->parser->didFinishParsing(new SourceElements(GLOBAL_DATA), 0, 0, NoFeatures, @0.last_line, 0); }
1217 | SourceElements { GLOBAL_DATA->parser->didFinishParsing($1.m_node, $1.m_varDeclarations, $1.m_funcDeclarations, $1.m_features,
1218 @1.last_line, $1.m_numConstants); }
1219 ;
1220
1221 SourceElements:
1222 Statement { $$.m_node = new SourceElements(GLOBAL_DATA);
1223 $$.m_node->append($1.m_node);
1224 $$.m_varDeclarations = $1.m_varDeclarations;
1225 $$.m_funcDeclarations = $1.m_funcDeclarations;
1226 $$.m_features = $1.m_features;
1227 $$.m_numConstants = $1.m_numConstants;
1228 }
1229 | SourceElements Statement { $$.m_node->append($2.m_node);
1230 $$.m_varDeclarations = mergeDeclarationLists($1.m_varDeclarations, $2.m_varDeclarations);
1231 $$.m_funcDeclarations = mergeDeclarationLists($1.m_funcDeclarations, $2.m_funcDeclarations);
1232 $$.m_features = $1.m_features | $2.m_features;
1233 $$.m_numConstants = $1.m_numConstants + $2.m_numConstants;
1234 }
1235 ;
1236
1237 // Start NoNodes
1238
1239 Literal_NoNode:
1240 NULLTOKEN
1241 | TRUETOKEN
1242 | FALSETOKEN
1243 | NUMBER { }
1244 | STRING { }
1245 | '/' /* regexp */ { Lexer& l = *LEXER; if (!l.scanRegExp()) YYABORT; }
1246 | DIVEQUAL /* regexp with /= */ { Lexer& l = *LEXER; if (!l.scanRegExp()) YYABORT; }
1247 ;
1248
1249 Property_NoNode:
1250 IDENT ':' AssignmentExpr_NoNode { }
1251 | STRING ':' AssignmentExpr_NoNode { }
1252 | NUMBER ':' AssignmentExpr_NoNode { }
1253 | IDENT IDENT '(' ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE { if (*$1 != "get" && *$1 != "set") YYABORT; }
1254 | IDENT IDENT '(' FormalParameterList_NoNode ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE { if (*$1 != "get" && *$1 != "set") YYABORT; }
1255 ;
1256
1257 PropertyList_NoNode:
1258 Property_NoNode
1259 | PropertyList_NoNode ',' Property_NoNode
1260 ;
1261
1262 PrimaryExpr_NoNode:
1263 PrimaryExprNoBrace_NoNode
1264 | OPENBRACE CLOSEBRACE { }
1265 | OPENBRACE PropertyList_NoNode CLOSEBRACE { }
1266 /* allow extra comma, see http://bugs.webkit.org/show_bug.cgi?id=5939 */
1267 | OPENBRACE PropertyList_NoNode ',' CLOSEBRACE { }
1268 ;
1269
1270 PrimaryExprNoBrace_NoNode:
1271 THISTOKEN
1272 | Literal_NoNode
1273 | ArrayLiteral_NoNode
1274 | IDENT { }
1275 | '(' Expr_NoNode ')'
1276 ;
1277
1278 ArrayLiteral_NoNode:
1279 '[' ElisionOpt_NoNode ']'
1280 | '[' ElementList_NoNode ']'
1281 | '[' ElementList_NoNode ',' ElisionOpt_NoNode ']'
1282 ;
1283
1284 ElementList_NoNode:
1285 ElisionOpt_NoNode AssignmentExpr_NoNode
1286 | ElementList_NoNode ',' ElisionOpt_NoNode AssignmentExpr_NoNode
1287 ;
1288
1289 ElisionOpt_NoNode:
1290 /* nothing */
1291 | Elision_NoNode
1292 ;
1293
1294 Elision_NoNode:
1295 ','
1296 | Elision_NoNode ','
1297 ;
1298
1299 MemberExpr_NoNode:
1300 PrimaryExpr_NoNode
1301 | FunctionExpr_NoNode
1302 | MemberExpr_NoNode '[' Expr_NoNode ']'
1303 | MemberExpr_NoNode '.' IDENT
1304 | NEW MemberExpr_NoNode Arguments_NoNode
1305 ;
1306
1307 MemberExprNoBF_NoNode:
1308 PrimaryExprNoBrace_NoNode
1309 | MemberExprNoBF_NoNode '[' Expr_NoNode ']'
1310 | MemberExprNoBF_NoNode '.' IDENT
1311 | NEW MemberExpr_NoNode Arguments_NoNode
1312 ;
1313
1314 NewExpr_NoNode:
1315 MemberExpr_NoNode
1316 | NEW NewExpr_NoNode
1317 ;
1318
1319 NewExprNoBF_NoNode:
1320 MemberExprNoBF_NoNode
1321 | NEW NewExpr_NoNode
1322 ;
1323
1324 CallExpr_NoNode:
1325 MemberExpr_NoNode Arguments_NoNode
1326 | CallExpr_NoNode Arguments_NoNode
1327 | CallExpr_NoNode '[' Expr_NoNode ']'
1328 | CallExpr_NoNode '.' IDENT
1329 ;
1330
1331 CallExprNoBF_NoNode:
1332 MemberExprNoBF_NoNode Arguments_NoNode
1333 | CallExprNoBF_NoNode Arguments_NoNode
1334 | CallExprNoBF_NoNode '[' Expr_NoNode ']'
1335 | CallExprNoBF_NoNode '.' IDENT
1336 ;
1337
1338 Arguments_NoNode:
1339 '(' ')'
1340 | '(' ArgumentList_NoNode ')'
1341 ;
1342
1343 ArgumentList_NoNode:
1344 AssignmentExpr_NoNode
1345 | ArgumentList_NoNode ',' AssignmentExpr_NoNode
1346 ;
1347
1348 LeftHandSideExpr_NoNode:
1349 NewExpr_NoNode
1350 | CallExpr_NoNode
1351 ;
1352
1353 LeftHandSideExprNoBF_NoNode:
1354 NewExprNoBF_NoNode
1355 | CallExprNoBF_NoNode
1356 ;
1357
1358 PostfixExpr_NoNode:
1359 LeftHandSideExpr_NoNode
1360 | LeftHandSideExpr_NoNode PLUSPLUS
1361 | LeftHandSideExpr_NoNode MINUSMINUS
1362 ;
1363
1364 PostfixExprNoBF_NoNode:
1365 LeftHandSideExprNoBF_NoNode
1366 | LeftHandSideExprNoBF_NoNode PLUSPLUS
1367 | LeftHandSideExprNoBF_NoNode MINUSMINUS
1368 ;
1369
1370 UnaryExprCommon_NoNode:
1371 DELETETOKEN UnaryExpr_NoNode
1372 | VOIDTOKEN UnaryExpr_NoNode
1373 | TYPEOF UnaryExpr_NoNode
1374 | PLUSPLUS UnaryExpr_NoNode
1375 | AUTOPLUSPLUS UnaryExpr_NoNode
1376 | MINUSMINUS UnaryExpr_NoNode
1377 | AUTOMINUSMINUS UnaryExpr_NoNode
1378 | '+' UnaryExpr_NoNode
1379 | '-' UnaryExpr_NoNode
1380 | '~' UnaryExpr_NoNode
1381 | '!' UnaryExpr_NoNode
1382
1383 UnaryExpr_NoNode:
1384 PostfixExpr_NoNode
1385 | UnaryExprCommon_NoNode
1386 ;
1387
1388 UnaryExprNoBF_NoNode:
1389 PostfixExprNoBF_NoNode
1390 | UnaryExprCommon_NoNode
1391 ;
1392
1393 MultiplicativeExpr_NoNode:
1394 UnaryExpr_NoNode
1395 | MultiplicativeExpr_NoNode '*' UnaryExpr_NoNode
1396 | MultiplicativeExpr_NoNode '/' UnaryExpr_NoNode
1397 | MultiplicativeExpr_NoNode '%' UnaryExpr_NoNode
1398 ;
1399
1400 MultiplicativeExprNoBF_NoNode:
1401 UnaryExprNoBF_NoNode
1402 | MultiplicativeExprNoBF_NoNode '*' UnaryExpr_NoNode
1403 | MultiplicativeExprNoBF_NoNode '/' UnaryExpr_NoNode
1404 | MultiplicativeExprNoBF_NoNode '%' UnaryExpr_NoNode
1405 ;
1406
1407 AdditiveExpr_NoNode:
1408 MultiplicativeExpr_NoNode
1409 | AdditiveExpr_NoNode '+' MultiplicativeExpr_NoNode
1410 | AdditiveExpr_NoNode '-' MultiplicativeExpr_NoNode
1411 ;
1412
1413 AdditiveExprNoBF_NoNode:
1414 MultiplicativeExprNoBF_NoNode
1415 | AdditiveExprNoBF_NoNode '+' MultiplicativeExpr_NoNode
1416 | AdditiveExprNoBF_NoNode '-' MultiplicativeExpr_NoNode
1417 ;
1418
1419 ShiftExpr_NoNode:
1420 AdditiveExpr_NoNode
1421 | ShiftExpr_NoNode LSHIFT AdditiveExpr_NoNode
1422 | ShiftExpr_NoNode RSHIFT AdditiveExpr_NoNode
1423 | ShiftExpr_NoNode URSHIFT AdditiveExpr_NoNode
1424 ;
1425
1426 ShiftExprNoBF_NoNode:
1427 AdditiveExprNoBF_NoNode
1428 | ShiftExprNoBF_NoNode LSHIFT AdditiveExpr_NoNode
1429 | ShiftExprNoBF_NoNode RSHIFT AdditiveExpr_NoNode
1430 | ShiftExprNoBF_NoNode URSHIFT AdditiveExpr_NoNode
1431 ;
1432
1433 RelationalExpr_NoNode:
1434 ShiftExpr_NoNode
1435 | RelationalExpr_NoNode '<' ShiftExpr_NoNode
1436 | RelationalExpr_NoNode '>' ShiftExpr_NoNode
1437 | RelationalExpr_NoNode LE ShiftExpr_NoNode
1438 | RelationalExpr_NoNode GE ShiftExpr_NoNode
1439 | RelationalExpr_NoNode INSTANCEOF ShiftExpr_NoNode
1440 | RelationalExpr_NoNode INTOKEN ShiftExpr_NoNode
1441 ;
1442
1443 RelationalExprNoIn_NoNode:
1444 ShiftExpr_NoNode
1445 | RelationalExprNoIn_NoNode '<' ShiftExpr_NoNode
1446 | RelationalExprNoIn_NoNode '>' ShiftExpr_NoNode
1447 | RelationalExprNoIn_NoNode LE ShiftExpr_NoNode
1448 | RelationalExprNoIn_NoNode GE ShiftExpr_NoNode
1449 | RelationalExprNoIn_NoNode INSTANCEOF ShiftExpr_NoNode
1450 ;
1451
1452 RelationalExprNoBF_NoNode:
1453 ShiftExprNoBF_NoNode
1454 | RelationalExprNoBF_NoNode '<' ShiftExpr_NoNode
1455 | RelationalExprNoBF_NoNode '>' ShiftExpr_NoNode
1456 | RelationalExprNoBF_NoNode LE ShiftExpr_NoNode
1457 | RelationalExprNoBF_NoNode GE ShiftExpr_NoNode
1458 | RelationalExprNoBF_NoNode INSTANCEOF ShiftExpr_NoNode
1459 | RelationalExprNoBF_NoNode INTOKEN ShiftExpr_NoNode
1460 ;
1461
1462 EqualityExpr_NoNode:
1463 RelationalExpr_NoNode
1464 | EqualityExpr_NoNode EQEQ RelationalExpr_NoNode
1465 | EqualityExpr_NoNode NE RelationalExpr_NoNode
1466 | EqualityExpr_NoNode STREQ RelationalExpr_NoNode
1467 | EqualityExpr_NoNode STRNEQ RelationalExpr_NoNode
1468 ;
1469
1470 EqualityExprNoIn_NoNode:
1471 RelationalExprNoIn_NoNode
1472 | EqualityExprNoIn_NoNode EQEQ RelationalExprNoIn_NoNode
1473 | EqualityExprNoIn_NoNode NE RelationalExprNoIn_NoNode
1474 | EqualityExprNoIn_NoNode STREQ RelationalExprNoIn_NoNode
1475 | EqualityExprNoIn_NoNode STRNEQ RelationalExprNoIn_NoNode
1476 ;
1477
1478 EqualityExprNoBF_NoNode:
1479 RelationalExprNoBF_NoNode
1480 | EqualityExprNoBF_NoNode EQEQ RelationalExpr_NoNode
1481 | EqualityExprNoBF_NoNode NE RelationalExpr_NoNode
1482 | EqualityExprNoBF_NoNode STREQ RelationalExpr_NoNode
1483 | EqualityExprNoBF_NoNode STRNEQ RelationalExpr_NoNode
1484 ;
1485
1486 BitwiseANDExpr_NoNode:
1487 EqualityExpr_NoNode
1488 | BitwiseANDExpr_NoNode '&' EqualityExpr_NoNode
1489 ;
1490
1491 BitwiseANDExprNoIn_NoNode:
1492 EqualityExprNoIn_NoNode
1493 | BitwiseANDExprNoIn_NoNode '&' EqualityExprNoIn_NoNode
1494 ;
1495
1496 BitwiseANDExprNoBF_NoNode:
1497 EqualityExprNoBF_NoNode
1498 | BitwiseANDExprNoBF_NoNode '&' EqualityExpr_NoNode
1499 ;
1500
1501 BitwiseXORExpr_NoNode:
1502 BitwiseANDExpr_NoNode
1503 | BitwiseXORExpr_NoNode '^' BitwiseANDExpr_NoNode
1504 ;
1505
1506 BitwiseXORExprNoIn_NoNode:
1507 BitwiseANDExprNoIn_NoNode
1508 | BitwiseXORExprNoIn_NoNode '^' BitwiseANDExprNoIn_NoNode
1509 ;
1510
1511 BitwiseXORExprNoBF_NoNode:
1512 BitwiseANDExprNoBF_NoNode
1513 | BitwiseXORExprNoBF_NoNode '^' BitwiseANDExpr_NoNode
1514 ;
1515
1516 BitwiseORExpr_NoNode:
1517 BitwiseXORExpr_NoNode
1518 | BitwiseORExpr_NoNode '|' BitwiseXORExpr_NoNode
1519 ;
1520
1521 BitwiseORExprNoIn_NoNode:
1522 BitwiseXORExprNoIn_NoNode
1523 | BitwiseORExprNoIn_NoNode '|' BitwiseXORExprNoIn_NoNode
1524 ;
1525
1526 BitwiseORExprNoBF_NoNode:
1527 BitwiseXORExprNoBF_NoNode
1528 | BitwiseORExprNoBF_NoNode '|' BitwiseXORExpr_NoNode
1529 ;
1530
1531 LogicalANDExpr_NoNode:
1532 BitwiseORExpr_NoNode
1533 | LogicalANDExpr_NoNode AND BitwiseORExpr_NoNode
1534 ;
1535
1536 LogicalANDExprNoIn_NoNode:
1537 BitwiseORExprNoIn_NoNode
1538 | LogicalANDExprNoIn_NoNode AND BitwiseORExprNoIn_NoNode
1539 ;
1540
1541 LogicalANDExprNoBF_NoNode:
1542 BitwiseORExprNoBF_NoNode
1543 | LogicalANDExprNoBF_NoNode AND BitwiseORExpr_NoNode
1544 ;
1545
1546 LogicalORExpr_NoNode:
1547 LogicalANDExpr_NoNode
1548 | LogicalORExpr_NoNode OR LogicalANDExpr_NoNode
1549 ;
1550
1551 LogicalORExprNoIn_NoNode:
1552 LogicalANDExprNoIn_NoNode
1553 | LogicalORExprNoIn_NoNode OR LogicalANDExprNoIn_NoNode
1554 ;
1555
1556 LogicalORExprNoBF_NoNode:
1557 LogicalANDExprNoBF_NoNode
1558 | LogicalORExprNoBF_NoNode OR LogicalANDExpr_NoNode
1559 ;
1560
1561 ConditionalExpr_NoNode:
1562 LogicalORExpr_NoNode
1563 | LogicalORExpr_NoNode '?' AssignmentExpr_NoNode ':' AssignmentExpr_NoNode
1564 ;
1565
1566 ConditionalExprNoIn_NoNode:
1567 LogicalORExprNoIn_NoNode
1568 | LogicalORExprNoIn_NoNode '?' AssignmentExprNoIn_NoNode ':' AssignmentExprNoIn_NoNode
1569 ;
1570
1571 ConditionalExprNoBF_NoNode:
1572 LogicalORExprNoBF_NoNode
1573 | LogicalORExprNoBF_NoNode '?' AssignmentExpr_NoNode ':' AssignmentExpr_NoNode
1574 ;
1575
1576 AssignmentExpr_NoNode:
1577 ConditionalExpr_NoNode
1578 | LeftHandSideExpr_NoNode AssignmentOperator_NoNode AssignmentExpr_NoNode
1579 ;
1580
1581 AssignmentExprNoIn_NoNode:
1582 ConditionalExprNoIn_NoNode
1583 | LeftHandSideExpr_NoNode AssignmentOperator_NoNode AssignmentExprNoIn_NoNode
1584 ;
1585
1586 AssignmentExprNoBF_NoNode:
1587 ConditionalExprNoBF_NoNode
1588 | LeftHandSideExprNoBF_NoNode AssignmentOperator_NoNode AssignmentExpr_NoNode
1589 ;
1590
1591 AssignmentOperator_NoNode:
1592 '='
1593 | PLUSEQUAL
1594 | MINUSEQUAL
1595 | MULTEQUAL
1596 | DIVEQUAL
1597 | LSHIFTEQUAL
1598 | RSHIFTEQUAL
1599 | URSHIFTEQUAL
1600 | ANDEQUAL
1601 | XOREQUAL
1602 | OREQUAL
1603 | MODEQUAL
1604 ;
1605
1606 Expr_NoNode:
1607 AssignmentExpr_NoNode
1608 | Expr_NoNode ',' AssignmentExpr_NoNode
1609 ;
1610
1611 ExprNoIn_NoNode:
1612 AssignmentExprNoIn_NoNode
1613 | ExprNoIn_NoNode ',' AssignmentExprNoIn_NoNode
1614 ;
1615
1616 ExprNoBF_NoNode:
1617 AssignmentExprNoBF_NoNode
1618 | ExprNoBF_NoNode ',' AssignmentExpr_NoNode
1619 ;
1620
1621 Statement_NoNode:
1622 Block_NoNode
1623 | VariableStatement_NoNode
1624 | ConstStatement_NoNode
1625 | FunctionDeclaration_NoNode
1626 | EmptyStatement_NoNode
1627 | ExprStatement_NoNode
1628 | IfStatement_NoNode
1629 | IterationStatement_NoNode
1630 | ContinueStatement_NoNode
1631 | BreakStatement_NoNode
1632 | ReturnStatement_NoNode
1633 | WithStatement_NoNode
1634 | SwitchStatement_NoNode
1635 | LabelledStatement_NoNode
1636 | ThrowStatement_NoNode
1637 | TryStatement_NoNode
1638 | DebuggerStatement_NoNode
1639 ;
1640
1641 Block_NoNode:
1642 OPENBRACE CLOSEBRACE { }
1643 | OPENBRACE SourceElements_NoNode CLOSEBRACE { }
1644 ;
1645
1646 VariableStatement_NoNode:
1647 VAR VariableDeclarationList_NoNode ';'
1648 | VAR VariableDeclarationList_NoNode error { AUTO_SEMICOLON; }
1649 ;
1650
1651 VariableDeclarationList_NoNode:
1652 IDENT { }
1653 | IDENT Initializer_NoNode { }
1654 | VariableDeclarationList_NoNode ',' IDENT
1655 | VariableDeclarationList_NoNode ',' IDENT Initializer_NoNode
1656 ;
1657
1658 VariableDeclarationListNoIn_NoNode:
1659 IDENT { }
1660 | IDENT InitializerNoIn_NoNode { }
1661 | VariableDeclarationListNoIn_NoNode ',' IDENT
1662 | VariableDeclarationListNoIn_NoNode ',' IDENT InitializerNoIn_NoNode
1663 ;
1664
1665 ConstStatement_NoNode:
1666 CONSTTOKEN ConstDeclarationList_NoNode ';'
1667 | CONSTTOKEN ConstDeclarationList_NoNode error { AUTO_SEMICOLON; }
1668 ;
1669
1670 ConstDeclarationList_NoNode:
1671 ConstDeclaration_NoNode
1672 | ConstDeclarationList_NoNode ',' ConstDeclaration_NoNode
1673 ;
1674
1675 ConstDeclaration_NoNode:
1676 IDENT { }
1677 | IDENT Initializer_NoNode { }
1678 ;
1679
1680 Initializer_NoNode:
1681 '=' AssignmentExpr_NoNode
1682 ;
1683
1684 InitializerNoIn_NoNode:
1685 '=' AssignmentExprNoIn_NoNode
1686 ;
1687
1688 EmptyStatement_NoNode:
1689 ';'
1690 ;
1691
1692 ExprStatement_NoNode:
1693 ExprNoBF_NoNode ';'
1694 | ExprNoBF_NoNode error { AUTO_SEMICOLON; }
1695 ;
1696
1697 IfStatement_NoNode:
1698 IF '(' Expr_NoNode ')' Statement_NoNode %prec IF_WITHOUT_ELSE
1699 | IF '(' Expr_NoNode ')' Statement_NoNode ELSE Statement_NoNode
1700 ;
1701
1702 IterationStatement_NoNode:
1703 DO Statement_NoNode WHILE '(' Expr_NoNode ')' ';'
1704 | DO Statement_NoNode WHILE '(' Expr_NoNode ')' error // Always performs automatic semicolon insertion
1705 | WHILE '(' Expr_NoNode ')' Statement_NoNode
1706 | FOR '(' ExprNoInOpt_NoNode ';' ExprOpt_NoNode ';' ExprOpt_NoNode ')' Statement_NoNode
1707 | FOR '(' VAR VariableDeclarationListNoIn_NoNode ';' ExprOpt_NoNode ';' ExprOpt_NoNode ')' Statement_NoNode
1708 | FOR '(' LeftHandSideExpr_NoNode INTOKEN Expr_NoNode ')' Statement_NoNode
1709 | FOR '(' VAR IDENT INTOKEN Expr_NoNode ')' Statement_NoNode
1710 | FOR '(' VAR IDENT InitializerNoIn_NoNode INTOKEN Expr_NoNode ')' Statement_NoNode
1711 ;
1712
1713 ExprOpt_NoNode:
1714 /* nothing */
1715 | Expr_NoNode
1716 ;
1717
1718 ExprNoInOpt_NoNode:
1719 /* nothing */
1720 | ExprNoIn_NoNode
1721 ;
1722
1723 ContinueStatement_NoNode:
1724 CONTINUE ';'
1725 | CONTINUE error { AUTO_SEMICOLON; }
1726 | CONTINUE IDENT ';'
1727 | CONTINUE IDENT error { AUTO_SEMICOLON; }
1728 ;
1729
1730 BreakStatement_NoNode:
1731 BREAK ';'
1732 | BREAK error { AUTO_SEMICOLON; }
1733 | BREAK IDENT ';'
1734 | BREAK IDENT error { AUTO_SEMICOLON; }
1735 ;
1736
1737 ReturnStatement_NoNode:
1738 RETURN ';'
1739 | RETURN error { AUTO_SEMICOLON; }
1740 | RETURN Expr_NoNode ';'
1741 | RETURN Expr_NoNode error { AUTO_SEMICOLON; }
1742 ;
1743
1744 WithStatement_NoNode:
1745 WITH '(' Expr_NoNode ')' Statement_NoNode
1746 ;
1747
1748 SwitchStatement_NoNode:
1749 SWITCH '(' Expr_NoNode ')' CaseBlock_NoNode
1750 ;
1751
1752 CaseBlock_NoNode:
1753 OPENBRACE CaseClausesOpt_NoNode CLOSEBRACE { }
1754 | OPENBRACE CaseClausesOpt_NoNode DefaultClause_NoNode CaseClausesOpt_NoNode CLOSEBRACE { }
1755 ;
1756
1757 CaseClausesOpt_NoNode:
1758 /* nothing */
1759 | CaseClauses_NoNode
1760 ;
1761
1762 CaseClauses_NoNode:
1763 CaseClause_NoNode
1764 | CaseClauses_NoNode CaseClause_NoNode
1765 ;
1766
1767 CaseClause_NoNode:
1768 CASE Expr_NoNode ':'
1769 | CASE Expr_NoNode ':' SourceElements_NoNode
1770 ;
1771
1772 DefaultClause_NoNode:
1773 DEFAULT ':'
1774 | DEFAULT ':' SourceElements_NoNode
1775 ;
1776
1777 LabelledStatement_NoNode:
1778 IDENT ':' Statement_NoNode { }
1779 ;
1780
1781 ThrowStatement_NoNode:
1782 THROW Expr_NoNode ';'
1783 | THROW Expr_NoNode error { AUTO_SEMICOLON; }
1784 ;
1785
1786 TryStatement_NoNode:
1787 TRY Block_NoNode FINALLY Block_NoNode
1788 | TRY Block_NoNode CATCH '(' IDENT ')' Block_NoNode
1789 | TRY Block_NoNode CATCH '(' IDENT ')' Block_NoNode FINALLY Block_NoNode
1790 ;
1791
1792 DebuggerStatement_NoNode:
1793 DEBUGGER ';'
1794 | DEBUGGER error { AUTO_SEMICOLON; }
1795 ;
1796
1797 FunctionDeclaration_NoNode:
1798 FUNCTION IDENT '(' ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE
1799 | FUNCTION IDENT '(' FormalParameterList_NoNode ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE
1800 ;
1801
1802 FunctionExpr_NoNode:
1803 FUNCTION '(' ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE
1804 | FUNCTION '(' FormalParameterList_NoNode ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE
1805 | FUNCTION IDENT '(' ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE
1806 | FUNCTION IDENT '(' FormalParameterList_NoNode ')' OPENBRACE FunctionBody_NoNode CLOSEBRACE
1807 ;
1808
1809 FormalParameterList_NoNode:
1810 IDENT { }
1811 | FormalParameterList_NoNode ',' IDENT
1812 ;
1813
1814 FunctionBody_NoNode:
1815 /* not in spec */
1816 | SourceElements_NoNode
1817 ;
1818
1819 SourceElements_NoNode:
1820 Statement_NoNode
1821 | SourceElements_NoNode Statement_NoNode
1822 ;
1823
1824 // End NoNodes
1825
1826 %%
1827
1828 static ExpressionNode* makeAssignNode(void* globalPtr, ExpressionNode* loc, Operator op, ExpressionNode* expr, bool locHasAssignments, bool exprHasAssignments, int start, int divot, int end)
1829 {
1830 if (!loc->isLocation())
1831 return new AssignErrorNode(GLOBAL_DATA, loc, op, expr, divot, divot - start, end - divot);
1832
1833 if (loc->isResolveNode()) {
1834 ResolveNode* resolve = static_cast<ResolveNode*>(loc);
1835 if (op == OpEqual) {
1836 AssignResolveNode* node = new AssignResolveNode(GLOBAL_DATA, resolve->identifier(), expr, exprHasAssignments);
1837 SET_EXCEPTION_LOCATION(node, start, divot, end);
1838 return node;
1839 } else
1840 return new ReadModifyResolveNode(GLOBAL_DATA, resolve->identifier(), op, expr, exprHasAssignments, divot, divot - start, end - divot);
1841 }
1842 if (loc->isBracketAccessorNode()) {
1843 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(loc);
1844 if (op == OpEqual)
1845 return new AssignBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), expr, locHasAssignments, exprHasAssignments, bracket->divot(), bracket->divot() - start, end - bracket->divot());
1846 else {
1847 ReadModifyBracketNode* node = new ReadModifyBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), op, expr, locHasAssignments, exprHasAssignments, divot, divot - start, end - divot);
1848 node->setSubexpressionInfo(bracket->divot(), bracket->endOffset());
1849 return node;
1850 }
1851 }
1852 ASSERT(loc->isDotAccessorNode());
1853 DotAccessorNode* dot = static_cast<DotAccessorNode*>(loc);
1854 if (op == OpEqual)
1855 return new AssignDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), expr, exprHasAssignments, dot->divot(), dot->divot() - start, end - dot->divot());
1856
1857 ReadModifyDotNode* node = new ReadModifyDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), op, expr, exprHasAssignments, divot, divot - start, end - divot);
1858 node->setSubexpressionInfo(dot->divot(), dot->endOffset());
1859 return node;
1860 }
1861
1862 static ExpressionNode* makePrefixNode(void* globalPtr, ExpressionNode* expr, Operator op, int start, int divot, int end)
1863 {
1864 if (!expr->isLocation())
1865 return new PrefixErrorNode(GLOBAL_DATA, expr, op, divot, divot - start, end - divot);
1866
1867 if (expr->isResolveNode()) {
1868 ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1869 return new PrefixResolveNode(GLOBAL_DATA, resolve->identifier(), op, divot, divot - start, end - divot);
1870 }
1871 if (expr->isBracketAccessorNode()) {
1872 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr);
1873 PrefixBracketNode* node = new PrefixBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), op, divot, divot - start, end - divot);
1874 node->setSubexpressionInfo(bracket->divot(), bracket->startOffset());
1875 return node;
1876 }
1877 ASSERT(expr->isDotAccessorNode());
1878 DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr);
1879 PrefixDotNode* node = new PrefixDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), op, divot, divot - start, end - divot);
1880 node->setSubexpressionInfo(dot->divot(), dot->startOffset());
1881 return node;
1882 }
1883
1884 static ExpressionNode* makePostfixNode(void* globalPtr, ExpressionNode* expr, Operator op, int start, int divot, int end)
1885 {
1886 if (!expr->isLocation())
1887 return new PostfixErrorNode(GLOBAL_DATA, expr, op, divot, divot - start, end - divot);
1888
1889 if (expr->isResolveNode()) {
1890 ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1891 return new PostfixResolveNode(GLOBAL_DATA, resolve->identifier(), op, divot, divot - start, end - divot);
1892 }
1893 if (expr->isBracketAccessorNode()) {
1894 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr);
1895 PostfixBracketNode* node = new PostfixBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), op, divot, divot - start, end - divot);
1896 node->setSubexpressionInfo(bracket->divot(), bracket->endOffset());
1897 return node;
1898
1899 }
1900 ASSERT(expr->isDotAccessorNode());
1901 DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr);
1902 PostfixDotNode* node = new PostfixDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), op, divot, divot - start, end - divot);
1903 node->setSubexpressionInfo(dot->divot(), dot->endOffset());
1904 return node;
1905 }
1906
1907 static ExpressionNodeInfo makeFunctionCallNode(void* globalPtr, ExpressionNodeInfo func, ArgumentsNodeInfo args, int start, int divot, int end)
1908 {
1909 CodeFeatures features = func.m_features | args.m_features;
1910 int numConstants = func.m_numConstants + args.m_numConstants;
1911 if (!func.m_node->isLocation())
1912 return createNodeInfo<ExpressionNode*>(new FunctionCallValueNode(GLOBAL_DATA, func.m_node, args.m_node, divot, divot - start, end - divot), features, numConstants);
1913 if (func.m_node->isResolveNode()) {
1914 ResolveNode* resolve = static_cast<ResolveNode*>(func.m_node);
1915 const Identifier& identifier = resolve->identifier();
1916 if (identifier == GLOBAL_DATA->propertyNames->eval)
1917 return createNodeInfo<ExpressionNode*>(new EvalFunctionCallNode(GLOBAL_DATA, args.m_node, divot, divot - start, end - divot), EvalFeature | features, numConstants);
1918 return createNodeInfo<ExpressionNode*>(new FunctionCallResolveNode(GLOBAL_DATA, identifier, args.m_node, divot, divot - start, end - divot), features, numConstants);
1919 }
1920 if (func.m_node->isBracketAccessorNode()) {
1921 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(func.m_node);
1922 FunctionCallBracketNode* node = new FunctionCallBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), args.m_node, divot, divot - start, end - divot);
1923 node->setSubexpressionInfo(bracket->divot(), bracket->endOffset());
1924 return createNodeInfo<ExpressionNode*>(node, features, numConstants);
1925 }
1926 ASSERT(func.m_node->isDotAccessorNode());
1927 DotAccessorNode* dot = static_cast<DotAccessorNode*>(func.m_node);
1928 FunctionCallDotNode* node = new FunctionCallDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), args.m_node, divot, divot - start, end - divot);
1929 node->setSubexpressionInfo(dot->divot(), dot->endOffset());
1930 return createNodeInfo<ExpressionNode*>(node, features, numConstants);
1931 }
1932
1933 static ExpressionNode* makeTypeOfNode(void* globalPtr, ExpressionNode* expr)
1934 {
1935 if (expr->isResolveNode()) {
1936 ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1937 return new TypeOfResolveNode(GLOBAL_DATA, resolve->identifier());
1938 }
1939 return new TypeOfValueNode(GLOBAL_DATA, expr);
1940 }
1941
1942 static ExpressionNode* makeDeleteNode(void* globalPtr, ExpressionNode* expr, int start, int divot, int end)
1943 {
1944 if (!expr->isLocation())
1945 return new DeleteValueNode(GLOBAL_DATA, expr);
1946 if (expr->isResolveNode()) {
1947 ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1948 return new DeleteResolveNode(GLOBAL_DATA, resolve->identifier(), divot, divot - start, end - divot);
1949 }
1950 if (expr->isBracketAccessorNode()) {
1951 BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr);
1952 return new DeleteBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), divot, divot - start, end - divot);
1953 }
1954 ASSERT(expr->isDotAccessorNode());
1955 DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr);
1956 return new DeleteDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), divot, divot - start, end - divot);
1957 }
1958
1959 static PropertyNode* makeGetterOrSetterPropertyNode(void* globalPtr, const Identifier& getOrSet, const Identifier& name, ParameterNode* params, FunctionBodyNode* body, const SourceCode& source)
1960 {
1961 PropertyNode::Type type;
1962 if (getOrSet == "get")
1963 type = PropertyNode::Getter;
1964 else if (getOrSet == "set")
1965 type = PropertyNode::Setter;
1966 else
1967 return 0;
1968 return new PropertyNode(GLOBAL_DATA, name, new FuncExprNode(GLOBAL_DATA, GLOBAL_DATA->propertyNames->nullIdentifier, body, source, params), type);
1969 }
1970
1971 static ExpressionNode* makeNegateNode(void* globalPtr, ExpressionNode* n)
1972 {
1973 if (n->isNumber()) {
1974 NumberNode* number = static_cast<NumberNode*>(n);
1975
1976 if (number->value() > 0.0) {
1977 number->setValue(-number->value());
1978 return number;
1979 }
1980 }
1981
1982 return new NegateNode(GLOBAL_DATA, n);
1983 }
1984
1985 static NumberNode* makeNumberNode(void* globalPtr, double d)
1986 {
1987 return new NumberNode(GLOBAL_DATA, d);
1988 }
1989
1990 static ExpressionNode* makeBitwiseNotNode(void* globalPtr, ExpressionNode* expr)
1991 {
1992 if (expr->isNumber())
1993 return makeNumberNode(globalPtr, ~toInt32(static_cast<NumberNode*>(expr)->value()));
1994 return new BitwiseNotNode(GLOBAL_DATA, expr);
1995 }
1996
1997 static ExpressionNode* makeMultNode(void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
1998 {
1999 expr1 = expr1->stripUnaryPlus();
2000 expr2 = expr2->stripUnaryPlus();
2001
2002 if (expr1->isNumber() && expr2->isNumber())
2003 return makeNumberNode(globalPtr, static_cast<NumberNode*>(expr1)->value() * static_cast<NumberNode*>(expr2)->value());
2004
2005 if (expr1->isNumber() && static_cast<NumberNode*>(expr1)->value() == 1)
2006 return new UnaryPlusNode(GLOBAL_DATA, expr2);
2007
2008 if (expr2->isNumber() && static_cast<NumberNode*>(expr2)->value() == 1)
2009 return new UnaryPlusNode(GLOBAL_DATA, expr1);
2010
2011 return new MultNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);
2012 }
2013
2014 static ExpressionNode* makeDivNode(void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
2015 {
2016 expr1 = expr1->stripUnaryPlus();
2017 expr2 = expr2->stripUnaryPlus();
2018
2019 if (expr1->isNumber() && expr2->isNumber())
2020 return makeNumberNode(globalPtr, static_cast<NumberNode*>(expr1)->value() / static_cast<NumberNode*>(expr2)->value());
2021 return new DivNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);
2022 }
2023
2024 static ExpressionNode* makeAddNode(void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
2025 {
2026 if (expr1->isNumber() && expr2->isNumber())
2027 return makeNumberNode(globalPtr, static_cast<NumberNode*>(expr1)->value() + static_cast<NumberNode*>(expr2)->value());
2028 return new AddNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);
2029 }
2030
2031 static ExpressionNode* makeSubNode(void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
2032 {
2033 expr1 = expr1->stripUnaryPlus();
2034 expr2 = expr2->stripUnaryPlus();
2035
2036 if (expr1->isNumber() && expr2->isNumber())
2037 return makeNumberNode(globalPtr, static_cast<NumberNode*>(expr1)->value() - static_cast<NumberNode*>(expr2)->value());
2038 return new SubNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);
2039 }
2040
2041 static ExpressionNode* makeLeftShiftNode(void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
2042 {
2043 if (expr1->isNumber() && expr2->isNumber())
2044 return makeNumberNode(globalPtr, toInt32(static_cast<NumberNode*>(expr1)->value()) << (toUInt32(static_cast<NumberNode*>(expr2)->value()) & 0x1f));
2045 return new LeftShiftNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);
2046 }
2047
2048 static ExpressionNode* makeRightShiftNode(void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
2049 {
2050 if (expr1->isNumber() && expr2->isNumber())
2051 return makeNumberNode(globalPtr, toInt32(static_cast<NumberNode*>(expr1)->value()) >> (toUInt32(static_cast<NumberNode*>(expr2)->value()) & 0x1f));
2052 return new RightShiftNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);
2053 }
2054
2055 /* called by yyparse on error */
2056 int yyerror(const char *)
2057 {
2058 return 1;
2059 }
2060
2061 /* may we automatically insert a semicolon ? */
2062 static bool allowAutomaticSemicolon(Lexer& lexer, int yychar)
2063 {
2064 return yychar == CLOSEBRACE || yychar == 0 || lexer.prevTerminator();
2065 }
2066
2067 static ExpressionNode* combineVarInitializers(void* globalPtr, ExpressionNode* list, AssignResolveNode* init)
2068 {
2069 if (!list)
2070 return init;
2071 return new VarDeclCommaNode(GLOBAL_DATA, list, init);
2072 }
2073
2074 // We turn variable declarations into either assignments or empty
2075 // statements (which later get stripped out), because the actual
2076 // declaration work is hoisted up to the start of the function body
2077 static StatementNode* makeVarStatementNode(void* globalPtr, ExpressionNode* expr)
2078 {
2079 if (!expr)
2080 return new EmptyStatementNode(GLOBAL_DATA);
2081 return new VarStatementNode(GLOBAL_DATA, expr);
2082 }
2083
2084 #undef GLOBAL_DATA