Roll out r37391 as it appears to have broken 40+ regression tests.
[WebKit.git] / JavaScriptCore / kjs / 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 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 kjsyydebug 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 kjsyylex(void* lvalp, void* llocp, void* globalPtr);
53 int kjsyyerror(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->setExceptionSourceRange((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* makeLeftShiftNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);
80 static ExpressionNode* makeRightShiftNode(void*, ExpressionNode*, ExpressionNode*, bool rightHasAssignments);
81 static StatementNode* makeVarStatementNode(void*, ExpressionNode*);
82 static ExpressionNode* combineVarInitializers(void*, ExpressionNode* list, AssignResolveNode* init);
83
84 #if COMPILER(MSVC)
85
86 #pragma warning(disable: 4065)
87 #pragma warning(disable: 4244)
88 #pragma warning(disable: 4702)
89
90 // At least some of the time, the declarations of malloc and free that bison
91 // generates are causing warnings. A way to avoid this is to explicitly define
92 // the macros so that bison doesn't try to declare malloc and free.
93 #define YYMALLOC malloc
94 #define YYFREE free
95
96 #endif
97
98 #define YYPARSE_PARAM globalPtr
99 #define YYLEX_PARAM globalPtr
100
101 template <typename T> NodeDeclarationInfo<T> createNodeDeclarationInfo(T node, ParserRefCountedData<DeclarationStacks::VarStack>* varDecls, 
102                                                                        ParserRefCountedData<DeclarationStacks::FunctionStack>* funcDecls,
103                                                                        CodeFeatures info,
104                                                                        int numConstants) 
105 {
106     ASSERT((info & ~AllFeatures) == 0);
107     NodeDeclarationInfo<T> result = {node, varDecls, funcDecls, info, numConstants};
108     return result;
109 }
110
111 template <typename T> NodeInfo<T> createNodeInfo(T node, CodeFeatures info, int numConstants)
112 {
113     ASSERT((info & ~AllFeatures) == 0);
114     NodeInfo<T> result = {node, info, numConstants};
115     return result;
116 }
117
118 template <typename T> T mergeDeclarationLists(T decls1, T decls2) 
119 {
120     // decls1 or both are null
121     if (!decls1)
122         return decls2;
123     // only decls1 is non-null
124     if (!decls2)
125         return decls1;
126
127     // Both are non-null
128     decls1->data.append(decls2->data);
129     
130     // We manually release the declaration lists to avoid accumulating many many
131     // unused heap allocated vectors
132     decls2->ref();
133     decls2->deref();
134     return decls1;
135 }
136
137 static void appendToVarDeclarationList(void* globalPtr, ParserRefCountedData<DeclarationStacks::VarStack>*& varDecls, const Identifier& ident, unsigned attrs)
138 {
139     if (!varDecls)
140         varDecls = new ParserRefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);
141
142     varDecls->data.append(make_pair(ident, attrs));
143
144 }
145
146 static inline void appendToVarDeclarationList(void* globalPtr, ParserRefCountedData<DeclarationStacks::VarStack>*& varDecls, ConstDeclNode* decl)
147 {
148     unsigned attrs = DeclarationStacks::IsConstant;
149     if (decl->m_init)
150         attrs |= DeclarationStacks::HasInitializer;        
151     appendToVarDeclarationList(globalPtr, varDecls, decl->m_ident, attrs);
152 }
153
154 %}
155
156 %union {
157     int                 intValue;
158     double              doubleValue;
159     Identifier*         ident;
160
161     // expression subtrees
162     ExpressionNodeInfo  expressionNode;
163     FuncDeclNodeInfo    funcDeclNode;
164     PropertyNodeInfo    propertyNode;
165     ArgumentsNodeInfo   argumentsNode;
166     ConstDeclNodeInfo   constDeclNode;
167     CaseBlockNodeInfo   caseBlockNode;
168     CaseClauseNodeInfo  caseClauseNode;
169     FuncExprNodeInfo    funcExprNode;
170
171     // statement nodes
172     StatementNodeInfo   statementNode;
173     FunctionBodyNode*   functionBodyNode;
174     ProgramNode*        programNode;
175
176     SourceElementsInfo  sourceElements;
177     PropertyListInfo    propertyList;
178     ArgumentListInfo    argumentList;
179     VarDeclListInfo     varDeclList;
180     ConstDeclListInfo   constDeclList;
181     ClauseListInfo      clauseList;
182     ElementListInfo     elementList;
183     ParameterListInfo   parameterList;
184
185     Operator            op;
186 }
187
188 %start Program
189
190 /* literals */
191 %token NULLTOKEN TRUETOKEN FALSETOKEN
192
193 /* keywords */
194 %token BREAK CASE DEFAULT FOR NEW VAR CONSTTOKEN CONTINUE
195 %token FUNCTION RETURN VOIDTOKEN DELETETOKEN
196 %token IF THISTOKEN DO WHILE INTOKEN INSTANCEOF TYPEOF
197 %token SWITCH WITH RESERVED
198 %token THROW TRY CATCH FINALLY
199 %token DEBUGGER
200
201 /* give an if without an else higher precedence than an else to resolve the ambiguity */
202 %nonassoc IF_WITHOUT_ELSE
203 %nonassoc ELSE
204
205 /* punctuators */
206 %token EQEQ NE                     /* == and != */
207 %token STREQ STRNEQ                /* === and !== */
208 %token LE GE                       /* < and > */
209 %token OR AND                      /* || and && */
210 %token PLUSPLUS MINUSMINUS         /* ++ and --  */
211 %token LSHIFT                      /* << */
212 %token RSHIFT URSHIFT              /* >> and >>> */
213 %token PLUSEQUAL MINUSEQUAL        /* += and -= */
214 %token MULTEQUAL DIVEQUAL          /* *= and /= */
215 %token LSHIFTEQUAL                 /* <<= */
216 %token RSHIFTEQUAL URSHIFTEQUAL    /* >>= and >>>= */
217 %token ANDEQUAL MODEQUAL           /* &= and %= */
218 %token XOREQUAL OREQUAL            /* ^= and |= */
219 %token <intValue> OPENBRACE        /* { (with char offset) */
220 %token <intValue> CLOSEBRACE        /* { (with char offset) */
221
222 /* terminal types */
223 %token <doubleValue> NUMBER
224 %token <ident> IDENT STRING
225
226 /* automatically inserted semicolon */
227 %token AUTOPLUSPLUS AUTOMINUSMINUS
228
229 /* non-terminal types */
230 %type <expressionNode>  Literal ArrayLiteral
231
232 %type <expressionNode>  PrimaryExpr PrimaryExprNoBrace
233 %type <expressionNode>  MemberExpr MemberExprNoBF /* BF => brace or function */
234 %type <expressionNode>  NewExpr NewExprNoBF
235 %type <expressionNode>  CallExpr CallExprNoBF
236 %type <expressionNode>  LeftHandSideExpr LeftHandSideExprNoBF
237 %type <expressionNode>  PostfixExpr PostfixExprNoBF
238 %type <expressionNode>  UnaryExpr UnaryExprNoBF UnaryExprCommon
239 %type <expressionNode>  MultiplicativeExpr MultiplicativeExprNoBF
240 %type <expressionNode>  AdditiveExpr AdditiveExprNoBF
241 %type <expressionNode>  ShiftExpr ShiftExprNoBF
242 %type <expressionNode>  RelationalExpr RelationalExprNoIn RelationalExprNoBF
243 %type <expressionNode>  EqualityExpr EqualityExprNoIn EqualityExprNoBF
244 %type <expressionNode>  BitwiseANDExpr BitwiseANDExprNoIn BitwiseANDExprNoBF
245 %type <expressionNode>  BitwiseXORExpr BitwiseXORExprNoIn BitwiseXORExprNoBF
246 %type <expressionNode>  BitwiseORExpr BitwiseORExprNoIn BitwiseORExprNoBF
247 %type <expressionNode>  LogicalANDExpr LogicalANDExprNoIn LogicalANDExprNoBF
248 %type <expressionNode>  LogicalORExpr LogicalORExprNoIn LogicalORExprNoBF
249 %type <expressionNode>  ConditionalExpr ConditionalExprNoIn ConditionalExprNoBF
250 %type <expressionNode>  AssignmentExpr AssignmentExprNoIn AssignmentExprNoBF
251 %type <expressionNode>  Expr ExprNoIn ExprNoBF
252
253 %type <expressionNode>  ExprOpt ExprNoInOpt
254
255 %type <statementNode>   Statement Block
256 %type <statementNode>   VariableStatement ConstStatement EmptyStatement ExprStatement
257 %type <statementNode>   IfStatement IterationStatement ContinueStatement
258 %type <statementNode>   BreakStatement ReturnStatement WithStatement
259 %type <statementNode>   SwitchStatement LabelledStatement
260 %type <statementNode>   ThrowStatement TryStatement
261 %type <statementNode>   DebuggerStatement
262 %type <statementNode>   SourceElement
263
264 %type <expressionNode>  Initializer InitializerNoIn
265 %type <funcDeclNode>    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 Literal:
286     NULLTOKEN                           { $$ = createNodeInfo<ExpressionNode*>(new NullNode(GLOBAL_DATA), 0, 1); }
287   | TRUETOKEN                           { $$ = createNodeInfo<ExpressionNode*>(new BooleanNode(GLOBAL_DATA, true), 0, 1); }
288   | FALSETOKEN                          { $$ = createNodeInfo<ExpressionNode*>(new BooleanNode(GLOBAL_DATA, false), 0, 1); }
289   | NUMBER                              { $$ = createNodeInfo<ExpressionNode*>(makeNumberNode(GLOBAL_DATA, $1), 0, 1); }
290   | STRING                              { $$ = createNodeInfo<ExpressionNode*>(new StringNode(GLOBAL_DATA, *$1), 0, 1); }
291   | '/' /* regexp */                    {
292                                             Lexer& l = *LEXER;
293                                             if (!l.scanRegExp())
294                                                 YYABORT;
295                                             RegExpNode* node = new RegExpNode(GLOBAL_DATA, l.pattern(), l.flags());
296                                             int size = l.pattern().size() + 2; // + 2 for the two /'s
297                                             SET_EXCEPTION_LOCATION(node, @1.first_column, @1.first_column + size, @1.first_column + size);
298                                             $$ = createNodeInfo<ExpressionNode*>(node, 0, 0);
299                                         }
300   | DIVEQUAL /* regexp with /= */       {
301                                             Lexer& l = *LEXER;
302                                             if (!l.scanRegExp())
303                                                 YYABORT;
304                                             RegExpNode* node = new RegExpNode(GLOBAL_DATA, "=" + l.pattern(), l.flags());
305                                             int size = l.pattern().size() + 2; // + 2 for the two /'s
306                                             SET_EXCEPTION_LOCATION(node, @1.first_column, @1.first_column + size, @1.first_column + size);
307                                             $$ = createNodeInfo<ExpressionNode*>(node, 0, 0);
308                                         }
309 ;
310
311 Property:
312     IDENT ':' AssignmentExpr            { $$ = createNodeInfo<PropertyNode*>(new PropertyNode(GLOBAL_DATA, *$1, $3.m_node, PropertyNode::Constant), $3.m_features, $3.m_numConstants); }
313   | STRING ':' AssignmentExpr           { $$ = createNodeInfo<PropertyNode*>(new PropertyNode(GLOBAL_DATA, *$1, $3.m_node, PropertyNode::Constant), $3.m_features, $3.m_numConstants); }
314   | 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); }
315   | 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; }
316   | IDENT IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE
317                                                              {
318                                                                  $$ = createNodeInfo<PropertyNode*>(makeGetterOrSetterPropertyNode(globalPtr, *$1, *$2, $4.m_node.head, $7, LEXER->sourceCode($6, $8, @6.first_line)), $4.m_features | ClosureFeature, 0); 
319                                                                  if ($4.m_features & ArgumentsFeature)
320                                                                      $7->setUsesArguments(); 
321                                                                  DBG($7, @6, @8); 
322                                                                  if (!$$.m_node) 
323                                                                      YYABORT; 
324                                                              }
325 ;
326
327 PropertyList:
328     Property                            { $$.m_node.head = new PropertyListNode(GLOBAL_DATA, $1.m_node); 
329                                           $$.m_node.tail = $$.m_node.head;
330                                           $$.m_features = $1.m_features;
331                                           $$.m_numConstants = $1.m_numConstants; }
332   | PropertyList ',' Property           { $$.m_node.head = $1.m_node.head;
333                                           $$.m_node.tail = new PropertyListNode(GLOBAL_DATA, $3.m_node, $1.m_node.tail);
334                                           $$.m_features = $1.m_features | $3.m_features;
335                                           $$.m_numConstants = $1.m_numConstants + $3.m_numConstants; }
336 ;
337
338 PrimaryExpr:
339     PrimaryExprNoBrace
340   | OPENBRACE CLOSEBRACE                             { $$ = createNodeInfo<ExpressionNode*>(new ObjectLiteralNode(GLOBAL_DATA), 0, 0); }
341   | OPENBRACE PropertyList CLOSEBRACE                { $$ = createNodeInfo<ExpressionNode*>(new ObjectLiteralNode(GLOBAL_DATA, $2.m_node.head), $2.m_features, $2.m_numConstants); }
342   /* allow extra comma, see http://bugs.webkit.org/show_bug.cgi?id=5939 */
343   | OPENBRACE PropertyList ',' CLOSEBRACE            { $$ = createNodeInfo<ExpressionNode*>(new ObjectLiteralNode(GLOBAL_DATA, $2.m_node.head), $2.m_features, $2.m_numConstants); }
344 ;
345
346 PrimaryExprNoBrace:
347     THISTOKEN                           { $$ = createNodeInfo<ExpressionNode*>(new ThisNode(GLOBAL_DATA), ThisFeature, 0); }
348   | Literal
349   | ArrayLiteral
350   | IDENT                               { $$ = createNodeInfo<ExpressionNode*>(new ResolveNode(GLOBAL_DATA, *$1, @1.first_column), (*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0, 0); }
351   | '(' Expr ')'                        { $$ = $2; }
352 ;
353
354 ArrayLiteral:
355     '[' ElisionOpt ']'                  { $$ = createNodeInfo<ExpressionNode*>(new ArrayNode(GLOBAL_DATA, $2), 0, $2 ? 1 : 0); }
356   | '[' ElementList ']'                 { $$ = createNodeInfo<ExpressionNode*>(new ArrayNode(GLOBAL_DATA, $2.m_node.head), $2.m_features, $2.m_numConstants); }
357   | '[' ElementList ',' ElisionOpt ']'  { $$ = createNodeInfo<ExpressionNode*>(new ArrayNode(GLOBAL_DATA, $4, $2.m_node.head), $2.m_features, $4 ? $2.m_numConstants + 1 : $2.m_numConstants); }
358 ;
359
360 ElementList:
361     ElisionOpt AssignmentExpr           { $$.m_node.head = new ElementNode(GLOBAL_DATA, $1, $2.m_node);
362                                           $$.m_node.tail = $$.m_node.head;
363                                           $$.m_features = $2.m_features;
364                                           $$.m_numConstants = $2.m_numConstants; }
365   | ElementList ',' ElisionOpt AssignmentExpr
366                                         { $$.m_node.head = $1.m_node.head;
367                                           $$.m_node.tail = new ElementNode(GLOBAL_DATA, $1.m_node.tail, $3, $4.m_node);
368                                           $$.m_features = $1.m_features | $4.m_features;
369                                           $$.m_numConstants = $1.m_numConstants + $4.m_numConstants; }
370 ;
371
372 ElisionOpt:
373     /* nothing */                       { $$ = 0; }
374   | Elision
375 ;
376
377 Elision:
378     ','                                 { $$ = 1; }
379   | Elision ','                         { $$ = $1 + 1; }
380 ;
381
382 MemberExpr:
383     PrimaryExpr
384   | FunctionExpr                        { $$ = createNodeInfo<ExpressionNode*>($1.m_node, $1.m_features, $1.m_numConstants); }
385   | MemberExpr '[' Expr ']'             { BracketAccessorNode* node = new BracketAccessorNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
386                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @4.last_column);
387                                           $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); 
388                                         }
389   | MemberExpr '.' IDENT                { DotAccessorNode* node = new DotAccessorNode(GLOBAL_DATA, $1.m_node, *$3);
390                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @3.last_column);
391                                           $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features, $1.m_numConstants);
392                                         }
393   | NEW MemberExpr Arguments            { NewExprNode* node = new NewExprNode(GLOBAL_DATA, $2.m_node, $3.m_node);
394                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @3.last_column);
395                                           $$ = createNodeInfo<ExpressionNode*>(node, $2.m_features | $3.m_features, $2.m_numConstants + $3.m_numConstants);
396                                         }
397 ;
398
399 MemberExprNoBF:
400     PrimaryExprNoBrace
401   | MemberExprNoBF '[' Expr ']'         { BracketAccessorNode* node = new BracketAccessorNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
402                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @4.last_column);
403                                           $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); 
404                                         }
405   | MemberExprNoBF '.' IDENT            { DotAccessorNode* node = new DotAccessorNode(GLOBAL_DATA, $1.m_node, *$3);
406                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @3.last_column);
407                                           $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features, $1.m_numConstants);
408                                         }
409   | NEW MemberExpr Arguments            { NewExprNode* node = new NewExprNode(GLOBAL_DATA, $2.m_node, $3.m_node);
410                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @3.last_column);
411                                           $$ = createNodeInfo<ExpressionNode*>(node, $2.m_features | $3.m_features, $2.m_numConstants + $3.m_numConstants);
412                                         }
413 ;
414
415 NewExpr:
416     MemberExpr
417   | NEW NewExpr                         { NewExprNode* node = new NewExprNode(GLOBAL_DATA, $2.m_node);
418                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
419                                           $$ = createNodeInfo<ExpressionNode*>(node, $2.m_features, $2.m_numConstants); 
420                                         }
421 ;
422
423 NewExprNoBF:
424     MemberExprNoBF
425   | NEW NewExpr                         { NewExprNode* node = new NewExprNode(GLOBAL_DATA, $2.m_node);
426                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
427                                           $$ = createNodeInfo<ExpressionNode*>(node, $2.m_features, $2.m_numConstants);
428                                         }
429 ;
430
431 CallExpr:
432     MemberExpr Arguments                { $$ = makeFunctionCallNode(globalPtr, $1, $2, @1.first_column, @1.last_column, @2.last_column); }
433   | CallExpr Arguments                  { $$ = makeFunctionCallNode(globalPtr, $1, $2, @1.first_column, @1.last_column, @2.last_column); }
434   | CallExpr '[' Expr ']'               { BracketAccessorNode* node = new BracketAccessorNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
435                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @4.last_column);
436                                           $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); 
437                                         }
438   | CallExpr '.' IDENT                  { DotAccessorNode* node = new DotAccessorNode(GLOBAL_DATA, $1.m_node, *$3);
439                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @3.last_column);
440                                           $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features, $1.m_numConstants); }
441 ;
442
443 CallExprNoBF:
444     MemberExprNoBF Arguments            { $$ = makeFunctionCallNode(globalPtr, $1, $2, @1.first_column, @1.last_column, @2.last_column); }
445   | CallExprNoBF Arguments              { $$ = makeFunctionCallNode(globalPtr, $1, $2, @1.first_column, @1.last_column, @2.last_column); }
446   | CallExprNoBF '[' Expr ']'           { BracketAccessorNode* node = new BracketAccessorNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
447                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @4.last_column);
448                                           $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); 
449                                         }
450   | CallExprNoBF '.' IDENT              { DotAccessorNode* node = new DotAccessorNode(GLOBAL_DATA, $1.m_node, *$3);
451                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @3.last_column);
452                                           $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features, $1.m_numConstants); 
453                                         }
454 ;
455
456 Arguments:
457     '(' ')'                             { $$ = createNodeInfo<ArgumentsNode*>(new ArgumentsNode(GLOBAL_DATA), 0, 0); }
458   | '(' ArgumentList ')'                { $$ = createNodeInfo<ArgumentsNode*>(new ArgumentsNode(GLOBAL_DATA, $2.m_node.head), $2.m_features, $2.m_numConstants); }
459 ;
460
461 ArgumentList:
462     AssignmentExpr                      { $$.m_node.head = new ArgumentListNode(GLOBAL_DATA, $1.m_node);
463                                           $$.m_node.tail = $$.m_node.head;
464                                           $$.m_features = $1.m_features;
465                                           $$.m_numConstants = $1.m_numConstants; }
466   | ArgumentList ',' AssignmentExpr     { $$.m_node.head = $1.m_node.head;
467                                           $$.m_node.tail = new ArgumentListNode(GLOBAL_DATA, $1.m_node.tail, $3.m_node);
468                                           $$.m_features = $1.m_features | $3.m_features;
469                                           $$.m_numConstants = $1.m_numConstants + $3.m_numConstants; }
470 ;
471
472 LeftHandSideExpr:
473     NewExpr
474   | CallExpr
475 ;
476
477 LeftHandSideExprNoBF:
478     NewExprNoBF
479   | CallExprNoBF
480 ;
481
482 PostfixExpr:
483     LeftHandSideExpr
484   | 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); }
485   | 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); }
486 ;
487
488 PostfixExprNoBF:
489     LeftHandSideExprNoBF
490   | 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); }
491   | 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); }
492 ;
493
494 UnaryExprCommon:
495     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); }
496   | VOIDTOKEN UnaryExpr                 { $$ = createNodeInfo<ExpressionNode*>(new VoidNode(GLOBAL_DATA, $2.m_node), $2.m_features, $2.m_numConstants + 1); }
497   | TYPEOF UnaryExpr                    { $$ = createNodeInfo<ExpressionNode*>(makeTypeOfNode(GLOBAL_DATA, $2.m_node), $2.m_features, $2.m_numConstants); }
498   | 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); }
499   | 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); }
500   | 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); }
501   | 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); }
502   | '+' UnaryExpr                       { $$ = createNodeInfo<ExpressionNode*>(new UnaryPlusNode(GLOBAL_DATA, $2.m_node), $2.m_features, $2.m_numConstants); }
503   | '-' UnaryExpr                       { $$ = createNodeInfo<ExpressionNode*>(makeNegateNode(GLOBAL_DATA, $2.m_node), $2.m_features, $2.m_numConstants); }
504   | '~' UnaryExpr                       { $$ = createNodeInfo<ExpressionNode*>(makeBitwiseNotNode(GLOBAL_DATA, $2.m_node), $2.m_features, $2.m_numConstants); }
505   | '!' UnaryExpr                       { $$ = createNodeInfo<ExpressionNode*>(new LogicalNotNode(GLOBAL_DATA, $2.m_node), $2.m_features, $2.m_numConstants); }
506
507 UnaryExpr:
508     PostfixExpr
509   | UnaryExprCommon
510 ;
511
512 UnaryExprNoBF:
513     PostfixExprNoBF
514   | UnaryExprCommon
515 ;
516
517 MultiplicativeExpr:
518     UnaryExpr
519   | 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); }
520   | 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); }
521   | 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); }
522 ;
523
524 MultiplicativeExprNoBF:
525     UnaryExprNoBF
526   | MultiplicativeExprNoBF '*' UnaryExpr
527                                         { $$ = createNodeInfo<ExpressionNode*>(new MultNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
528   | MultiplicativeExprNoBF '/' UnaryExpr
529                                         { $$ = createNodeInfo<ExpressionNode*>(new DivNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
530   | MultiplicativeExprNoBF '%' UnaryExpr
531                                         { $$ = 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); }
532 ;
533
534 AdditiveExpr:
535     MultiplicativeExpr
536   | 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); }
537   | AdditiveExpr '-' MultiplicativeExpr { $$ = createNodeInfo<ExpressionNode*>(new SubNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
538 ;
539
540 AdditiveExprNoBF:
541     MultiplicativeExprNoBF
542   | AdditiveExprNoBF '+' MultiplicativeExpr
543                                         { $$ = createNodeInfo<ExpressionNode*>(new AddNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
544   | AdditiveExprNoBF '-' MultiplicativeExpr
545                                         { $$ = createNodeInfo<ExpressionNode*>(new SubNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
546 ;
547
548 ShiftExpr:
549     AdditiveExpr
550   | 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); }
551   | 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); }
552   | 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); }
553 ;
554
555 ShiftExprNoBF:
556     AdditiveExprNoBF
557   | ShiftExprNoBF LSHIFT AdditiveExpr   { $$ = createNodeInfo<ExpressionNode*>(new LeftShiftNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
558   | ShiftExprNoBF RSHIFT AdditiveExpr   { $$ = createNodeInfo<ExpressionNode*>(new RightShiftNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature), $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
559   | 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); }
560 ;
561
562 RelationalExpr:
563     ShiftExpr
564   | 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); }
565   | 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); }
566   | 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); }
567   | 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); }
568   | RelationalExpr INSTANCEOF ShiftExpr { InstanceOfNode* node = new InstanceOfNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
569                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @3.first_column, @3.last_column);  
570                                           $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
571   | RelationalExpr INTOKEN ShiftExpr    { InNode* node = new InNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
572                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @3.first_column, @3.last_column);  
573                                           $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
574 ;
575
576 RelationalExprNoIn:
577     ShiftExpr
578   | 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); }
579   | 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); }
580   | 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); }
581   | 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); }
582   | RelationalExprNoIn INSTANCEOF ShiftExpr
583                                         { InstanceOfNode* node = new InstanceOfNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
584                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @3.first_column, @3.last_column);  
585                                           $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
586 ;
587
588 RelationalExprNoBF:
589     ShiftExprNoBF
590   | 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); }
591   | 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); }
592   | 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); }
593   | 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); }
594   | RelationalExprNoBF INSTANCEOF ShiftExpr
595                                         { InstanceOfNode* node = new InstanceOfNode(GLOBAL_DATA, $1.m_node, $3.m_node, $3.m_features & AssignFeature);
596                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @3.first_column, @3.last_column);  
597                                           $$ = createNodeInfo<ExpressionNode*>(node, $1.m_features | $3.m_features, $1.m_numConstants + $3.m_numConstants); }
598   | RelationalExprNoBF INTOKEN ShiftExpr 
599                                         { InNode* node = new InNode(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 ;
603
604 EqualityExpr:
605     RelationalExpr
606   | 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); }
607   | 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); }
608   | 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); }
609   | 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); }
610 ;
611
612 EqualityExprNoIn:
613     RelationalExprNoIn
614   | EqualityExprNoIn EQEQ RelationalExprNoIn
615                                         { $$ = 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); }
616   | EqualityExprNoIn NE RelationalExprNoIn
617                                         { $$ = 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); }
618   | EqualityExprNoIn STREQ RelationalExprNoIn
619                                         { $$ = 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); }
620   | EqualityExprNoIn STRNEQ RelationalExprNoIn
621                                         { $$ = 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); }
622 ;
623
624 EqualityExprNoBF:
625     RelationalExprNoBF
626   | EqualityExprNoBF EQEQ RelationalExpr
627                                         { $$ = 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); }
628   | 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); }
629   | EqualityExprNoBF STREQ RelationalExpr
630                                         { $$ = 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); }
631   | EqualityExprNoBF STRNEQ RelationalExpr
632                                         { $$ = 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); }
633 ;
634
635 BitwiseANDExpr:
636     EqualityExpr
637   | 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); }
638 ;
639
640 BitwiseANDExprNoIn:
641     EqualityExprNoIn
642   | BitwiseANDExprNoIn '&' EqualityExprNoIn
643                                         { $$ = 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); }
644 ;
645
646 BitwiseANDExprNoBF:
647     EqualityExprNoBF
648   | 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); }
649 ;
650
651 BitwiseXORExpr:
652     BitwiseANDExpr
653   | 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); }
654 ;
655
656 BitwiseXORExprNoIn:
657     BitwiseANDExprNoIn
658   | BitwiseXORExprNoIn '^' BitwiseANDExprNoIn
659                                         { $$ = 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); }
660 ;
661
662 BitwiseXORExprNoBF:
663     BitwiseANDExprNoBF
664   | BitwiseXORExprNoBF '^' BitwiseANDExpr
665                                         { $$ = 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); }
666 ;
667
668 BitwiseORExpr:
669     BitwiseXORExpr
670   | 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); }
671 ;
672
673 BitwiseORExprNoIn:
674     BitwiseXORExprNoIn
675   | BitwiseORExprNoIn '|' BitwiseXORExprNoIn
676                                         { $$ = 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); }
677 ;
678
679 BitwiseORExprNoBF:
680     BitwiseXORExprNoBF
681   | BitwiseORExprNoBF '|' BitwiseXORExpr
682                                         { $$ = 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); }
683 ;
684
685 LogicalANDExpr:
686     BitwiseORExpr
687   | 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); }
688 ;
689
690 LogicalANDExprNoIn:
691     BitwiseORExprNoIn
692   | LogicalANDExprNoIn AND BitwiseORExprNoIn
693                                         { $$ = 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); }
694 ;
695
696 LogicalANDExprNoBF:
697     BitwiseORExprNoBF
698   | LogicalANDExprNoBF AND BitwiseORExpr
699                                         { $$ = 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); }
700 ;
701
702 LogicalORExpr:
703     LogicalANDExpr
704   | 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); }
705 ;
706
707 LogicalORExprNoIn:
708     LogicalANDExprNoIn
709   | LogicalORExprNoIn OR LogicalANDExprNoIn
710                                         { $$ = 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); }
711 ;
712
713 LogicalORExprNoBF:
714     LogicalANDExprNoBF
715   | 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); }
716 ;
717
718 ConditionalExpr:
719     LogicalORExpr
720   | LogicalORExpr '?' AssignmentExpr ':' AssignmentExpr
721                                         { $$ = 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); }
722 ;
723
724 ConditionalExprNoIn:
725     LogicalORExprNoIn
726   | LogicalORExprNoIn '?' AssignmentExprNoIn ':' AssignmentExprNoIn
727                                         { $$ = 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); }
728 ;
729
730 ConditionalExprNoBF:
731     LogicalORExprNoBF
732   | LogicalORExprNoBF '?' AssignmentExpr ':' AssignmentExpr
733                                         { $$ = 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); }
734 ;
735
736 AssignmentExpr:
737     ConditionalExpr
738   | LeftHandSideExpr AssignmentOperator AssignmentExpr
739                                         { $$ = createNodeInfo<ExpressionNode*>(makeAssignNode(GLOBAL_DATA, $1.m_node, $2, $3.m_node, $1.m_features & AssignFeature, $3.m_features & AssignFeature, 
740                                                                                                      @1.first_column, @2.first_column + 1, @3.last_column), $1.m_features | $3.m_features | AssignFeature, $1.m_numConstants + $3.m_numConstants); 
741                                         }
742 ;
743
744 AssignmentExprNoIn:
745     ConditionalExprNoIn
746   | LeftHandSideExpr AssignmentOperator AssignmentExprNoIn
747                                         { $$ = createNodeInfo<ExpressionNode*>(makeAssignNode(GLOBAL_DATA, $1.m_node, $2, $3.m_node, $1.m_features & AssignFeature, $3.m_features & AssignFeature, 
748                                                                                                      @1.first_column, @2.first_column + 1, @3.last_column), $1.m_features | $3.m_features | AssignFeature, $1.m_numConstants + $3.m_numConstants);
749                                         }
750 ;
751
752 AssignmentExprNoBF:
753     ConditionalExprNoBF
754   | LeftHandSideExprNoBF AssignmentOperator AssignmentExpr
755                                         { $$ = createNodeInfo<ExpressionNode*>(makeAssignNode(GLOBAL_DATA, $1.m_node, $2, $3.m_node, $1.m_features & AssignFeature, $3.m_features & AssignFeature,
756                                                                                                      @1.first_column, @2.first_column + 1, @3.last_column), $1.m_features | $3.m_features | AssignFeature, $1.m_numConstants + $3.m_numConstants); 
757                                         }
758 ;
759
760 AssignmentOperator:
761     '='                                 { $$ = OpEqual; }
762   | PLUSEQUAL                           { $$ = OpPlusEq; }
763   | MINUSEQUAL                          { $$ = OpMinusEq; }
764   | MULTEQUAL                           { $$ = OpMultEq; }
765   | DIVEQUAL                            { $$ = OpDivEq; }
766   | LSHIFTEQUAL                         { $$ = OpLShift; }
767   | RSHIFTEQUAL                         { $$ = OpRShift; }
768   | URSHIFTEQUAL                        { $$ = OpURShift; }
769   | ANDEQUAL                            { $$ = OpAndEq; }
770   | XOREQUAL                            { $$ = OpXOrEq; }
771   | OREQUAL                             { $$ = OpOrEq; }
772   | MODEQUAL                            { $$ = OpModEq; }
773 ;
774
775 Expr:
776     AssignmentExpr
777   | 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); }
778 ;
779
780 ExprNoIn:
781     AssignmentExprNoIn
782   | 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); }
783 ;
784
785 ExprNoBF:
786     AssignmentExprNoBF
787   | 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); }
788 ;
789
790 Statement:
791     Block
792   | VariableStatement
793   | ConstStatement
794   | EmptyStatement
795   | ExprStatement
796   | IfStatement
797   | IterationStatement
798   | ContinueStatement
799   | BreakStatement
800   | ReturnStatement
801   | WithStatement
802   | SwitchStatement
803   | LabelledStatement
804   | ThrowStatement
805   | TryStatement
806   | DebuggerStatement
807 ;
808
809 Block:
810     OPENBRACE CLOSEBRACE                             { $$ = createNodeDeclarationInfo<StatementNode*>(new BlockNode(GLOBAL_DATA, 0), 0, 0, 0, 0);
811                                           DBG($$.m_node, @1, @2); }
812   | OPENBRACE SourceElements CLOSEBRACE              { $$ = createNodeDeclarationInfo<StatementNode*>(new BlockNode(GLOBAL_DATA, $2.m_node), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features, $2.m_numConstants);
813                                           DBG($$.m_node, @1, @3); }
814 ;
815
816 VariableStatement:
817     VAR VariableDeclarationList ';'     { $$ = createNodeDeclarationInfo<StatementNode*>(makeVarStatementNode(GLOBAL_DATA, $2.m_node), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features, $2.m_numConstants);
818                                           DBG($$.m_node, @1, @3); }
819   | VAR VariableDeclarationList error   { $$ = createNodeDeclarationInfo<StatementNode*>(makeVarStatementNode(GLOBAL_DATA, $2.m_node), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features, $2.m_numConstants);
820                                           DBG($$.m_node, @1, @2);
821                                           AUTO_SEMICOLON; }
822 ;
823
824 VariableDeclarationList:
825     IDENT                               { $$.m_node = 0;
826                                           $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);
827                                           appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$1, 0);
828                                           $$.m_funcDeclarations = 0;
829                                           $$.m_features = (*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0;
830                                           $$.m_numConstants = 0;
831                                         }
832   | IDENT Initializer                   { AssignResolveNode* node = new AssignResolveNode(GLOBAL_DATA, *$1, $2.m_node, $2.m_features & AssignFeature);
833                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.first_column + 1, @2.last_column);
834                                           $$.m_node = node;
835                                           $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);
836                                           appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$1, DeclarationStacks::HasInitializer);
837                                           $$.m_funcDeclarations = 0;
838                                           $$.m_features = ((*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $2.m_features;
839                                           $$.m_numConstants = $2.m_numConstants;
840                                         }
841   | VariableDeclarationList ',' IDENT
842                                         { $$.m_node = $1.m_node;
843                                           $$.m_varDeclarations = $1.m_varDeclarations;
844                                           appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$3, 0);
845                                           $$.m_funcDeclarations = 0;
846                                           $$.m_features = $1.m_features | ((*$3 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0);
847                                           $$.m_numConstants = $1.m_numConstants;
848                                         }
849   | VariableDeclarationList ',' IDENT Initializer
850                                         { AssignResolveNode* node = new AssignResolveNode(GLOBAL_DATA, *$3, $4.m_node, $4.m_features & AssignFeature);
851                                           SET_EXCEPTION_LOCATION(node, @3.first_column, @4.first_column + 1, @4.last_column);
852                                           $$.m_node = combineVarInitializers(GLOBAL_DATA, $1.m_node, node);
853                                           $$.m_varDeclarations = $1.m_varDeclarations;
854                                           appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$3, DeclarationStacks::HasInitializer);
855                                           $$.m_funcDeclarations = 0;
856                                           $$.m_features = $1.m_features | ((*$3 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $4.m_features;
857                                           $$.m_numConstants = $1.m_numConstants + $4.m_numConstants;
858                                         }
859 ;
860
861 VariableDeclarationListNoIn:
862     IDENT                               { $$.m_node = 0;
863                                           $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);
864                                           appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$1, 0);
865                                           $$.m_funcDeclarations = 0;
866                                           $$.m_features = (*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0;
867                                           $$.m_numConstants = 0;
868                                         }
869   | IDENT InitializerNoIn               { AssignResolveNode* node = new AssignResolveNode(GLOBAL_DATA, *$1, $2.m_node, $2.m_features & AssignFeature);
870                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.first_column + 1, @2.last_column);
871                                           $$.m_node = node;
872                                           $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);
873                                           appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$1, DeclarationStacks::HasInitializer);
874                                           $$.m_funcDeclarations = 0;
875                                           $$.m_features = ((*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $2.m_features;
876                                           $$.m_numConstants = $2.m_numConstants;
877                                         }
878   | VariableDeclarationListNoIn ',' IDENT
879                                         { $$.m_node = $1.m_node;
880                                           $$.m_varDeclarations = $1.m_varDeclarations;
881                                           appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$3, 0);
882                                           $$.m_funcDeclarations = 0;
883                                           $$.m_features = $1.m_features | ((*$3 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0);
884                                           $$.m_numConstants = $1.m_numConstants;
885                                         }
886   | VariableDeclarationListNoIn ',' IDENT InitializerNoIn
887                                         { AssignResolveNode* node = new AssignResolveNode(GLOBAL_DATA, *$3, $4.m_node, $4.m_features & AssignFeature);
888                                           SET_EXCEPTION_LOCATION(node, @3.first_column, @4.first_column + 1, @4.last_column);
889                                           $$.m_node = combineVarInitializers(GLOBAL_DATA, $1.m_node, node);
890                                           $$.m_varDeclarations = $1.m_varDeclarations;
891                                           appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, *$3, DeclarationStacks::HasInitializer);
892                                           $$.m_funcDeclarations = 0;
893                                           $$.m_features = $1.m_features | ((*$3 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $4.m_features;
894                                           $$.m_numConstants = $1.m_numConstants + $4.m_numConstants;
895                                         }
896 ;
897
898 ConstStatement:
899     CONSTTOKEN ConstDeclarationList ';' { $$ = createNodeDeclarationInfo<StatementNode*>(new ConstStatementNode(GLOBAL_DATA, $2.m_node.head), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features, $2.m_numConstants);
900                                           DBG($$.m_node, @1, @3); }
901   | CONSTTOKEN ConstDeclarationList error
902                                         { $$ = createNodeDeclarationInfo<StatementNode*>(new ConstStatementNode(GLOBAL_DATA, $2.m_node.head), $2.m_varDeclarations, $2.m_funcDeclarations, $2.m_features, $2.m_numConstants);
903                                           DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
904 ;
905
906 ConstDeclarationList:
907     ConstDeclaration                    { $$.m_node.head = $1.m_node;
908                                           $$.m_node.tail = $$.m_node.head;
909                                           $$.m_varDeclarations = new ParserRefCountedData<DeclarationStacks::VarStack>(GLOBAL_DATA);
910                                           appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, $1.m_node);
911                                           $$.m_funcDeclarations = 0; 
912                                           $$.m_features = $1.m_features;
913                                           $$.m_numConstants = $1.m_numConstants;
914     }
915   | ConstDeclarationList ',' ConstDeclaration
916                                         {  $$.m_node.head = $1.m_node.head;
917                                           $1.m_node.tail->m_next = $3.m_node;
918                                           $$.m_node.tail = $3.m_node;
919                                           $$.m_varDeclarations = $1.m_varDeclarations;
920                                           appendToVarDeclarationList(GLOBAL_DATA, $$.m_varDeclarations, $3.m_node);
921                                           $$.m_funcDeclarations = 0;
922                                           $$.m_features = $1.m_features | $3.m_features;
923                                           $$.m_numConstants = $1.m_numConstants + $3.m_numConstants; }
924 ;
925
926 ConstDeclaration:
927     IDENT                               { $$ = createNodeInfo<ConstDeclNode*>(new ConstDeclNode(GLOBAL_DATA, *$1, 0), (*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0, 0); }
928   | 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); }
929 ;
930
931 Initializer:
932     '=' AssignmentExpr                  { $$ = $2; }
933 ;
934
935 InitializerNoIn:
936     '=' AssignmentExprNoIn              { $$ = $2; }
937 ;
938
939 EmptyStatement:
940     ';'                                 { $$ = createNodeDeclarationInfo<StatementNode*>(new EmptyStatementNode(GLOBAL_DATA), 0, 0, 0, 0); }
941 ;
942
943 ExprStatement:
944     ExprNoBF ';'                        { $$ = createNodeDeclarationInfo<StatementNode*>(new ExprStatementNode(GLOBAL_DATA, $1.m_node), 0, 0, $1.m_features, $1.m_numConstants);
945                                           DBG($$.m_node, @1, @2); }
946   | ExprNoBF error                      { $$ = createNodeDeclarationInfo<StatementNode*>(new ExprStatementNode(GLOBAL_DATA, $1.m_node), 0, 0, $1.m_features, $1.m_numConstants);
947                                           DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
948 ;
949
950 IfStatement:
951     IF '(' Expr ')' Statement %prec IF_WITHOUT_ELSE
952                                         { $$ = 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);
953                                           DBG($$.m_node, @1, @4); }
954   | IF '(' Expr ')' Statement ELSE Statement
955                                         { $$ = createNodeDeclarationInfo<StatementNode*>(new IfElseNode(GLOBAL_DATA, $3.m_node, $5.m_node, $7.m_node), 
956                                                                                          mergeDeclarationLists($5.m_varDeclarations, $7.m_varDeclarations), mergeDeclarationLists($5.m_funcDeclarations, $7.m_funcDeclarations),
957                                                                                          $3.m_features | $5.m_features | $7.m_features,
958                                                                                          $3.m_numConstants + $5.m_numConstants + $7.m_numConstants); 
959                                           DBG($$.m_node, @1, @4); }
960 ;
961
962 IterationStatement:
963     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);
964                                              DBG($$.m_node, @1, @3); }
965   | 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);
966                                              DBG($$.m_node, @1, @3); } // Always performs automatic semicolon insertion.
967   | 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);
968                                           DBG($$.m_node, @1, @4); }
969   | FOR '(' ExprNoInOpt ';' ExprOpt ';' ExprOpt ')' Statement
970                                         { $$ = 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, 
971                                                                                          $3.m_features | $5.m_features | $7.m_features | $9.m_features,
972                                                                                          $3.m_numConstants + $5.m_numConstants + $7.m_numConstants + $9.m_numConstants);
973                                           DBG($$.m_node, @1, @8); 
974                                         }
975   | FOR '(' VAR VariableDeclarationListNoIn ';' ExprOpt ';' ExprOpt ')' Statement
976                                         { $$ = createNodeDeclarationInfo<StatementNode*>(new ForNode(GLOBAL_DATA, $4.m_node, $6.m_node, $8.m_node, $10.m_node, true),
977                                                                                          mergeDeclarationLists($4.m_varDeclarations, $10.m_varDeclarations),
978                                                                                          mergeDeclarationLists($4.m_funcDeclarations, $10.m_funcDeclarations),
979                                                                                          $4.m_features | $6.m_features | $8.m_features | $10.m_features,
980                                                                                          $4.m_numConstants + $6.m_numConstants + $8.m_numConstants + $10.m_numConstants);
981                                           DBG($$.m_node, @1, @9); }
982   | FOR '(' LeftHandSideExpr INTOKEN Expr ')' Statement
983                                         {
984                                             ForInNode* node = new ForInNode(GLOBAL_DATA, $3.m_node, $5.m_node, $7.m_node);
985                                             SET_EXCEPTION_LOCATION(node, @3.first_column, @3.last_column, @5.last_column);
986                                             $$ = createNodeDeclarationInfo<StatementNode*>(node, $7.m_varDeclarations, $7.m_funcDeclarations,
987                                                                                            $3.m_features | $5.m_features | $7.m_features,
988                                                                                            $3.m_numConstants + $5.m_numConstants + $7.m_numConstants);
989                                             DBG($$.m_node, @1, @6);
990                                         }
991   | FOR '(' VAR IDENT INTOKEN Expr ')' Statement
992                                         { 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);
993                                           SET_EXCEPTION_LOCATION(forIn, @4.first_column, @5.first_column + 1, @6.last_column);
994                                           appendToVarDeclarationList(GLOBAL_DATA, $8.m_varDeclarations, *$4, DeclarationStacks::HasInitializer);
995                                           $$ = 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);
996                                           DBG($$.m_node, @1, @7); }
997   | FOR '(' VAR IDENT InitializerNoIn INTOKEN Expr ')' Statement
998                                         { 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);
999                                           SET_EXCEPTION_LOCATION(forIn, @4.first_column, @6.first_column + 1, @7.last_column);
1000                                           appendToVarDeclarationList(GLOBAL_DATA, $9.m_varDeclarations, *$4, DeclarationStacks::HasInitializer);
1001                                           $$ = createNodeDeclarationInfo<StatementNode*>(forIn, $9.m_varDeclarations, $9.m_funcDeclarations,
1002                                                                                          ((*$4 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $5.m_features | $7.m_features | $9.m_features,
1003                                                                                          $5.m_numConstants + $7.m_numConstants + $9.m_numConstants);
1004                                           DBG($$.m_node, @1, @8); }
1005 ;
1006
1007 ExprOpt:
1008     /* nothing */                       { $$ = createNodeInfo<ExpressionNode*>(0, 0, 0); }
1009   | Expr
1010 ;
1011
1012 ExprNoInOpt:
1013     /* nothing */                       { $$ = createNodeInfo<ExpressionNode*>(0, 0, 0); }
1014   | ExprNoIn
1015 ;
1016
1017 ContinueStatement:
1018     CONTINUE ';'                        { ContinueNode* node = new ContinueNode(GLOBAL_DATA);
1019                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @1.last_column); 
1020                                           $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0);
1021                                           DBG($$.m_node, @1, @2); }
1022   | CONTINUE error                      { ContinueNode* node = new ContinueNode(GLOBAL_DATA);
1023                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @1.last_column); 
1024                                           $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0);
1025                                           DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
1026   | CONTINUE IDENT ';'                  { ContinueNode* node = new ContinueNode(GLOBAL_DATA, *$2);
1027                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column); 
1028                                           $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0);
1029                                           DBG($$.m_node, @1, @3); }
1030   | CONTINUE IDENT error                { ContinueNode* node = new ContinueNode(GLOBAL_DATA, *$2);
1031                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column); 
1032                                           $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0);
1033                                           DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
1034 ;
1035
1036 BreakStatement:
1037     BREAK ';'                           { BreakNode* node = new BreakNode(GLOBAL_DATA);
1038                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @1.last_column);
1039                                           $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0); DBG($$.m_node, @1, @2); }
1040   | BREAK error                         { BreakNode* node = new BreakNode(GLOBAL_DATA);
1041                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @1.last_column);
1042                                           $$ = createNodeDeclarationInfo<StatementNode*>(new BreakNode(GLOBAL_DATA), 0, 0, 0, 0); DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
1043   | BREAK IDENT ';'                     { BreakNode* node = new BreakNode(GLOBAL_DATA, *$2);
1044                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1045                                           $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0); DBG($$.m_node, @1, @3); }
1046   | BREAK IDENT error                   { BreakNode* node = new BreakNode(GLOBAL_DATA, *$2);
1047                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1048                                           $$ = createNodeDeclarationInfo<StatementNode*>(new BreakNode(GLOBAL_DATA, *$2), 0, 0, 0, 0); DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
1049 ;
1050
1051 ReturnStatement:
1052     RETURN ';'                          { ReturnNode* node = new ReturnNode(GLOBAL_DATA, 0); 
1053                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @1.last_column); 
1054                                           $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0); DBG($$.m_node, @1, @2); }
1055   | RETURN error                        { ReturnNode* node = new ReturnNode(GLOBAL_DATA, 0); 
1056                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @1.last_column, @1.last_column); 
1057                                           $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, 0, 0); DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
1058   | RETURN Expr ';'                     { ReturnNode* node = new ReturnNode(GLOBAL_DATA, $2.m_node); 
1059                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1060                                           $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, $2.m_features, $2.m_numConstants); DBG($$.m_node, @1, @3); }
1061   | RETURN Expr error                   { ReturnNode* node = new ReturnNode(GLOBAL_DATA, $2.m_node); 
1062                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column); 
1063                                           $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, $2.m_features, $2.m_numConstants); DBG($$.m_node, @1, @2); AUTO_SEMICOLON; }
1064 ;
1065
1066 WithStatement:
1067     WITH '(' Expr ')' Statement         { $$ = createNodeDeclarationInfo<StatementNode*>(new WithNode(GLOBAL_DATA, $3.m_node, $5.m_node, @3.last_column, @3.last_column - @3.first_column),
1068                                                                                          $5.m_varDeclarations, $5.m_funcDeclarations, $3.m_features | $5.m_features | WithFeature, $3.m_numConstants + $5.m_numConstants);
1069                                           DBG($$.m_node, @1, @4); }
1070 ;
1071
1072 SwitchStatement:
1073     SWITCH '(' Expr ')' CaseBlock       { $$ = createNodeDeclarationInfo<StatementNode*>(new SwitchNode(GLOBAL_DATA, $3.m_node, $5.m_node), $5.m_varDeclarations, $5.m_funcDeclarations,
1074                                                                                          $3.m_features | $5.m_features, $3.m_numConstants + $5.m_numConstants);
1075                                           DBG($$.m_node, @1, @4); }
1076 ;
1077
1078 CaseBlock:
1079     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); }
1080   | OPENBRACE CaseClausesOpt DefaultClause CaseClausesOpt CLOSEBRACE
1081                                         { $$ = createNodeDeclarationInfo<CaseBlockNode*>(new CaseBlockNode(GLOBAL_DATA, $2.m_node.head, $3.m_node, $4.m_node.head),
1082                                                                                          mergeDeclarationLists(mergeDeclarationLists($2.m_varDeclarations, $3.m_varDeclarations), $4.m_varDeclarations),
1083                                                                                          mergeDeclarationLists(mergeDeclarationLists($2.m_funcDeclarations, $3.m_funcDeclarations), $4.m_funcDeclarations),
1084                                                                                          $2.m_features | $3.m_features | $4.m_features,
1085                                                                                          $2.m_numConstants + $3.m_numConstants + $4.m_numConstants); }
1086 ;
1087
1088 CaseClausesOpt:
1089 /* nothing */                       { $$.m_node.head = 0; $$.m_node.tail = 0; $$.m_varDeclarations = 0; $$.m_funcDeclarations = 0; $$.m_features = 0; $$.m_numConstants = 0; }
1090   | CaseClauses
1091 ;
1092
1093 CaseClauses:
1094     CaseClause                          { $$.m_node.head = new ClauseListNode(GLOBAL_DATA, $1.m_node);
1095                                           $$.m_node.tail = $$.m_node.head;
1096                                           $$.m_varDeclarations = $1.m_varDeclarations;
1097                                           $$.m_funcDeclarations = $1.m_funcDeclarations; 
1098                                           $$.m_features = $1.m_features;
1099                                           $$.m_numConstants = $1.m_numConstants; }
1100   | CaseClauses CaseClause              { $$.m_node.head = $1.m_node.head;
1101                                           $$.m_node.tail = new ClauseListNode(GLOBAL_DATA, $1.m_node.tail, $2.m_node);
1102                                           $$.m_varDeclarations = mergeDeclarationLists($1.m_varDeclarations, $2.m_varDeclarations);
1103                                           $$.m_funcDeclarations = mergeDeclarationLists($1.m_funcDeclarations, $2.m_funcDeclarations);
1104                                           $$.m_features = $1.m_features | $2.m_features;
1105                                           $$.m_numConstants = $1.m_numConstants + $2.m_numConstants;
1106                                         }
1107 ;
1108
1109 CaseClause:
1110     CASE Expr ':'                       { $$ = createNodeDeclarationInfo<CaseClauseNode*>(new CaseClauseNode(GLOBAL_DATA, $2.m_node), 0, 0, $2.m_features, $2.m_numConstants); }
1111   | 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); }
1112 ;
1113
1114 DefaultClause:
1115     DEFAULT ':'                         { $$ = createNodeDeclarationInfo<CaseClauseNode*>(new CaseClauseNode(GLOBAL_DATA, 0), 0, 0, 0, 0); }
1116   | DEFAULT ':' SourceElements          { $$ = createNodeDeclarationInfo<CaseClauseNode*>(new CaseClauseNode(GLOBAL_DATA, 0, $3.m_node), $3.m_varDeclarations, $3.m_funcDeclarations, $3.m_features, $3.m_numConstants); }
1117 ;
1118
1119 LabelledStatement:
1120     IDENT ':' Statement                 { $3.m_node->pushLabel(*$1);
1121                                           LabelNode* node = new LabelNode(GLOBAL_DATA, *$1, $3.m_node);
1122                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1123                                           $$ = createNodeDeclarationInfo<StatementNode*>(node, $3.m_varDeclarations, $3.m_funcDeclarations, $3.m_features, $3.m_numConstants); }
1124 ;
1125
1126 ThrowStatement:
1127     THROW Expr ';'                      { ThrowNode* node = new ThrowNode(GLOBAL_DATA, $2.m_node);
1128                                           SET_EXCEPTION_LOCATION(node, @1.first_column, @2.last_column, @2.last_column);
1129                                           $$ = createNodeDeclarationInfo<StatementNode*>(node, 0, 0, $2.m_features, $2.m_numConstants); DBG($$.m_node, @1, @2);
1130                                         }
1131   | THROW Expr error                    { 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); AUTO_SEMICOLON; 
1134                                         }
1135 ;
1136
1137 TryStatement:
1138     TRY Block FINALLY Block             { $$ = createNodeDeclarationInfo<StatementNode*>(new TryNode(GLOBAL_DATA, $2.m_node, GLOBAL_DATA->propertyNames->nullIdentifier, 0, $4.m_node),
1139                                                                                          mergeDeclarationLists($2.m_varDeclarations, $4.m_varDeclarations),
1140                                                                                          mergeDeclarationLists($2.m_funcDeclarations, $4.m_funcDeclarations),
1141                                                                                          $2.m_features | $4.m_features,
1142                                                                                          $2.m_numConstants + $4.m_numConstants);
1143                                           DBG($$.m_node, @1, @2); }
1144   | TRY Block CATCH '(' IDENT ')' Block { $$ = createNodeDeclarationInfo<StatementNode*>(new TryNode(GLOBAL_DATA, $2.m_node, *$5, $7.m_node, 0),
1145                                                                                          mergeDeclarationLists($2.m_varDeclarations, $7.m_varDeclarations),
1146                                                                                          mergeDeclarationLists($2.m_funcDeclarations, $7.m_funcDeclarations),
1147                                                                                          $2.m_features | $7.m_features | CatchFeature,
1148                                                                                          $2.m_numConstants + $7.m_numConstants);
1149                                           DBG($$.m_node, @1, @2); }
1150   | TRY Block CATCH '(' IDENT ')' Block FINALLY Block
1151                                         { $$ = createNodeDeclarationInfo<StatementNode*>(new TryNode(GLOBAL_DATA, $2.m_node, *$5, $7.m_node, $9.m_node),
1152                                                                                          mergeDeclarationLists(mergeDeclarationLists($2.m_varDeclarations, $7.m_varDeclarations), $9.m_varDeclarations),
1153                                                                                          mergeDeclarationLists(mergeDeclarationLists($2.m_funcDeclarations, $7.m_funcDeclarations), $9.m_funcDeclarations),
1154                                                                                          $2.m_features | $7.m_features | $9.m_features | CatchFeature,
1155                                                                                          $2.m_numConstants + $7.m_numConstants + $9.m_numConstants);
1156                                           DBG($$.m_node, @1, @2); }
1157 ;
1158
1159 DebuggerStatement:
1160     DEBUGGER ';'                        { $$ = createNodeDeclarationInfo<StatementNode*>(new DebuggerStatementNode(GLOBAL_DATA), 0, 0, 0, 0);
1161                                           DBG($$.m_node, @1, @2); }
1162   | DEBUGGER error                      { $$ = createNodeDeclarationInfo<StatementNode*>(new DebuggerStatementNode(GLOBAL_DATA), 0, 0, 0, 0);
1163                                           DBG($$.m_node, @1, @1); AUTO_SEMICOLON; }
1164 ;
1165
1166 FunctionDeclaration:
1167     FUNCTION IDENT '(' ')' OPENBRACE FunctionBody CLOSEBRACE { $$ = createNodeInfo(new FuncDeclNode(GLOBAL_DATA, *$2, $6, LEXER->sourceCode($5, $7, @5.first_line)), ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | ClosureFeature, 0); DBG($6, @5, @7); }
1168   | FUNCTION IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE
1169       { 
1170           $$ = createNodeInfo(new FuncDeclNode(GLOBAL_DATA, *$2, $7, LEXER->sourceCode($6, $8, @6.first_line), $4.m_node.head), ((*$2 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0) | $4.m_features | ClosureFeature, 0); 
1171           if ($4.m_features & ArgumentsFeature)
1172               $7->setUsesArguments(); 
1173           DBG($7, @6, @8); 
1174       }
1175 ;
1176
1177 FunctionExpr:
1178     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); }
1179     | FUNCTION '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE 
1180       { 
1181           $$ = 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); 
1182           if ($3.m_features & ArgumentsFeature) 
1183               $6->setUsesArguments();
1184           DBG($6, @5, @7); 
1185       }
1186   | 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); }
1187   | FUNCTION IDENT '(' FormalParameterList ')' OPENBRACE FunctionBody CLOSEBRACE 
1188       { 
1189           $$ = createNodeInfo(new FuncExprNode(GLOBAL_DATA, *$2, $7, LEXER->sourceCode($6, $8, @6.first_line), $4.m_node.head), $4.m_features | ClosureFeature, 0); 
1190           if ($4.m_features & ArgumentsFeature)
1191               $7->setUsesArguments();
1192           DBG($7, @6, @8); 
1193       }
1194 ;
1195
1196 FormalParameterList:
1197     IDENT                               { $$.m_node.head = new ParameterNode(GLOBAL_DATA, *$1);
1198                                           $$.m_features = (*$1 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0;
1199                                           $$.m_node.tail = $$.m_node.head; }
1200   | FormalParameterList ',' IDENT       { $$.m_node.head = $1.m_node.head;
1201                                           $$.m_features = $1.m_features | ((*$3 == GLOBAL_DATA->propertyNames->arguments) ? ArgumentsFeature : 0);
1202                                           $$.m_node.tail = new ParameterNode(GLOBAL_DATA, $1.m_node.tail, *$3);  }
1203 ;
1204
1205 FunctionBody:
1206     /* not in spec */           { $$ = FunctionBodyNode::create(GLOBAL_DATA, 0, 0, 0, NoFeatures, 0); }
1207   | SourceElements              { $$ = FunctionBodyNode::create(GLOBAL_DATA, $1.m_node, $1.m_varDeclarations ? &$1.m_varDeclarations->data : 0, 
1208                                                                 $1.m_funcDeclarations ? &$1.m_funcDeclarations->data : 0,
1209                                                                 $1.m_features, $1.m_numConstants);
1210                                   // As in mergeDeclarationLists() we have to ref/deref to safely get rid of
1211                                   // the declaration lists.
1212                                   if ($1.m_varDeclarations) {
1213                                       $1.m_varDeclarations->ref();
1214                                       $1.m_varDeclarations->deref();
1215                                   }
1216                                   if ($1.m_funcDeclarations) {
1217                                       $1.m_funcDeclarations->ref();
1218                                       $1.m_funcDeclarations->deref();
1219                                   }
1220                                 }
1221 ;
1222
1223 Program:
1224     /* not in spec */                   { GLOBAL_DATA->parser->didFinishParsing(new SourceElements(GLOBAL_DATA), 0, 0, NoFeatures, @0.last_line, 0); }
1225     | SourceElements                    { GLOBAL_DATA->parser->didFinishParsing($1.m_node, $1.m_varDeclarations, $1.m_funcDeclarations, $1.m_features, 
1226                                                                                 @1.last_line, $1.m_numConstants); }
1227 ;
1228
1229 SourceElements:
1230     SourceElement                       { $$.m_node = new SourceElements(GLOBAL_DATA);
1231                                           $$.m_node->append($1.m_node);
1232                                           $$.m_varDeclarations = $1.m_varDeclarations;
1233                                           $$.m_funcDeclarations = $1.m_funcDeclarations;
1234                                           $$.m_features = $1.m_features;
1235                                           $$.m_numConstants = $1.m_numConstants;
1236                                         }
1237   | SourceElements SourceElement        { $$.m_node->append($2.m_node);
1238                                           $$.m_varDeclarations = mergeDeclarationLists($1.m_varDeclarations, $2.m_varDeclarations);
1239                                           $$.m_funcDeclarations = mergeDeclarationLists($1.m_funcDeclarations, $2.m_funcDeclarations);
1240                                           $$.m_features = $1.m_features | $2.m_features;
1241                                           $$.m_numConstants = $1.m_numConstants + $2.m_numConstants;
1242                                         }
1243 ;
1244
1245 SourceElement:
1246     FunctionDeclaration                 { $$ = createNodeDeclarationInfo<StatementNode*>($1.m_node, 0, new ParserRefCountedData<DeclarationStacks::FunctionStack>(GLOBAL_DATA), $1.m_features, 0); $$.m_funcDeclarations->data.append($1.m_node); }
1247   | Statement                           { $$ = $1; }
1248 ;
1249  
1250 %%
1251
1252 static ExpressionNode* makeAssignNode(void* globalPtr, ExpressionNode* loc, Operator op, ExpressionNode* expr, bool locHasAssignments, bool exprHasAssignments, int start, int divot, int end)
1253 {
1254     if (!loc->isLocation())
1255         return new AssignErrorNode(GLOBAL_DATA, loc, op, expr, divot, divot - start, end - divot);
1256
1257     if (loc->isResolveNode()) {
1258         ResolveNode* resolve = static_cast<ResolveNode*>(loc);
1259         if (op == OpEqual) {
1260             AssignResolveNode* node = new AssignResolveNode(GLOBAL_DATA, resolve->identifier(), expr, exprHasAssignments);
1261             SET_EXCEPTION_LOCATION(node, start, divot, end);
1262             return node;
1263         } else
1264             return new ReadModifyResolveNode(GLOBAL_DATA, resolve->identifier(), op, expr, exprHasAssignments, divot, divot - start, end - divot);
1265     }
1266     if (loc->isBracketAccessorNode()) {
1267         BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(loc);
1268         if (op == OpEqual)
1269             return new AssignBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), expr, locHasAssignments, exprHasAssignments, bracket->divot(), bracket->divot() - start, end - bracket->divot());
1270         else {
1271             ReadModifyBracketNode* node = new ReadModifyBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), op, expr, locHasAssignments, exprHasAssignments, divot, divot - start, end - divot);
1272             node->setSubexpressionInfo(bracket->divot(), bracket->endOffset());
1273             return node;
1274         }
1275     }
1276     ASSERT(loc->isDotAccessorNode());
1277     DotAccessorNode* dot = static_cast<DotAccessorNode*>(loc);
1278     if (op == OpEqual)
1279         return new AssignDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), expr, exprHasAssignments, dot->divot(), dot->divot() - start, end - dot->divot());
1280
1281     ReadModifyDotNode* node = new ReadModifyDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), op, expr, exprHasAssignments, divot, divot - start, end - divot);
1282     node->setSubexpressionInfo(dot->divot(), dot->endOffset());
1283     return node;
1284 }
1285
1286 static ExpressionNode* makePrefixNode(void* globalPtr, ExpressionNode* expr, Operator op, int start, int divot, int end)
1287 {
1288     if (!expr->isLocation())
1289         return new PrefixErrorNode(GLOBAL_DATA, expr, op, divot, divot - start, end - divot);
1290     
1291     if (expr->isResolveNode()) {
1292         ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1293         return new PrefixResolveNode(GLOBAL_DATA, resolve->identifier(), op, divot, divot - start, end - divot);
1294     }
1295     if (expr->isBracketAccessorNode()) {
1296         BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr);
1297         PrefixBracketNode* node = new PrefixBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), op, divot, divot - start, end - divot);
1298         node->setSubexpressionInfo(bracket->divot(), bracket->startOffset());
1299         return node;
1300     }
1301     ASSERT(expr->isDotAccessorNode());
1302     DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr);
1303     PrefixDotNode* node = new PrefixDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), op, divot, divot - start, end - divot);
1304     node->setSubexpressionInfo(dot->divot(), dot->startOffset());
1305     return node;
1306 }
1307
1308 static ExpressionNode* makePostfixNode(void* globalPtr, ExpressionNode* expr, Operator op, int start, int divot, int end)
1309
1310     if (!expr->isLocation())
1311         return new PostfixErrorNode(GLOBAL_DATA, expr, op, divot, divot - start, end - divot);
1312     
1313     if (expr->isResolveNode()) {
1314         ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1315         return new PostfixResolveNode(GLOBAL_DATA, resolve->identifier(), op, divot, divot - start, end - divot);
1316     }
1317     if (expr->isBracketAccessorNode()) {
1318         BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr);
1319         PostfixBracketNode* node = new PostfixBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), op, divot, divot - start, end - divot);
1320         node->setSubexpressionInfo(bracket->divot(), bracket->endOffset());
1321         return node;
1322         
1323     }
1324     ASSERT(expr->isDotAccessorNode());
1325     DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr);
1326     PostfixDotNode* node = new PostfixDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), op, divot, divot - start, end - divot);
1327     node->setSubexpressionInfo(dot->divot(), dot->endOffset());
1328     return node;
1329 }
1330
1331 static ExpressionNodeInfo makeFunctionCallNode(void* globalPtr, ExpressionNodeInfo func, ArgumentsNodeInfo args, int start, int divot, int end)
1332 {
1333     CodeFeatures features = func.m_features | args.m_features;
1334     int numConstants = func.m_numConstants + args.m_numConstants;
1335     if (!func.m_node->isLocation())
1336         return createNodeInfo<ExpressionNode*>(new FunctionCallValueNode(GLOBAL_DATA, func.m_node, args.m_node, divot, divot - start, end - divot), features, numConstants);
1337     if (func.m_node->isResolveNode()) {
1338         ResolveNode* resolve = static_cast<ResolveNode*>(func.m_node);
1339         const Identifier& identifier = resolve->identifier();
1340         if (identifier == GLOBAL_DATA->propertyNames->eval)
1341             return createNodeInfo<ExpressionNode*>(new EvalFunctionCallNode(GLOBAL_DATA, args.m_node, divot, divot - start, end - divot), EvalFeature | features, numConstants);
1342         return createNodeInfo<ExpressionNode*>(new FunctionCallResolveNode(GLOBAL_DATA, identifier, args.m_node, divot, divot - start, end - divot), features, numConstants);
1343     }
1344     if (func.m_node->isBracketAccessorNode()) {
1345         BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(func.m_node);
1346         FunctionCallBracketNode* node = new FunctionCallBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), args.m_node, divot, divot - start, end - divot);
1347         node->setSubexpressionInfo(bracket->divot(), bracket->endOffset());
1348         return createNodeInfo<ExpressionNode*>(node, features, numConstants);
1349     }
1350     ASSERT(func.m_node->isDotAccessorNode());
1351     DotAccessorNode* dot = static_cast<DotAccessorNode*>(func.m_node);
1352     FunctionCallDotNode* node = new FunctionCallDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), args.m_node, divot, divot - start, end - divot);
1353     node->setSubexpressionInfo(dot->divot(), dot->endOffset());
1354     return createNodeInfo<ExpressionNode*>(node, features, numConstants);
1355 }
1356
1357 static ExpressionNode* makeTypeOfNode(void* globalPtr, ExpressionNode* expr)
1358 {
1359     if (expr->isResolveNode()) {
1360         ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1361         return new TypeOfResolveNode(GLOBAL_DATA, resolve->identifier());
1362     }
1363     return new TypeOfValueNode(GLOBAL_DATA, expr);
1364 }
1365
1366 static ExpressionNode* makeDeleteNode(void* globalPtr, ExpressionNode* expr, int start, int divot, int end)
1367 {
1368     if (!expr->isLocation())
1369         return new DeleteValueNode(GLOBAL_DATA, expr);
1370     if (expr->isResolveNode()) {
1371         ResolveNode* resolve = static_cast<ResolveNode*>(expr);
1372         return new DeleteResolveNode(GLOBAL_DATA, resolve->identifier(), divot, divot - start, end - divot);
1373     }
1374     if (expr->isBracketAccessorNode()) {
1375         BracketAccessorNode* bracket = static_cast<BracketAccessorNode*>(expr);
1376         return new DeleteBracketNode(GLOBAL_DATA, bracket->base(), bracket->subscript(), divot, divot - start, end - divot);
1377     }
1378     ASSERT(expr->isDotAccessorNode());
1379     DotAccessorNode* dot = static_cast<DotAccessorNode*>(expr);
1380     return new DeleteDotNode(GLOBAL_DATA, dot->base(), dot->identifier(), divot, divot - start, end - divot);
1381 }
1382
1383 static PropertyNode* makeGetterOrSetterPropertyNode(void* globalPtr, const Identifier& getOrSet, const Identifier& name, ParameterNode* params, FunctionBodyNode* body, const SourceCode& source)
1384 {
1385     PropertyNode::Type type;
1386     if (getOrSet == "get")
1387         type = PropertyNode::Getter;
1388     else if (getOrSet == "set")
1389         type = PropertyNode::Setter;
1390     else
1391         return 0;
1392     return new PropertyNode(GLOBAL_DATA, name, new FuncExprNode(GLOBAL_DATA, GLOBAL_DATA->propertyNames->nullIdentifier, body, source, params), type);
1393 }
1394
1395 static ExpressionNode* makeNegateNode(void* globalPtr, ExpressionNode* n)
1396 {
1397     if (n->isNumber()) {
1398         NumberNode* number = static_cast<NumberNode*>(n);
1399
1400         if (number->value() > 0.0) {
1401             number->setValue(-number->value());
1402             return number;
1403         }
1404     }
1405
1406     return new NegateNode(GLOBAL_DATA, n);
1407 }
1408
1409 static NumberNode* makeNumberNode(void* globalPtr, double d)
1410 {
1411     JSValue* value = JSImmediate::from(d);
1412     if (value)
1413         return new ImmediateNumberNode(GLOBAL_DATA, value, d);
1414     return new NumberNode(GLOBAL_DATA, d);
1415 }
1416
1417 static ExpressionNode* makeBitwiseNotNode(void* globalPtr, ExpressionNode* expr)
1418 {
1419     if (expr->isNumber())
1420         return makeNumberNode(globalPtr, ~JSValue::toInt32(static_cast<NumberNode*>(expr)->value()));
1421     return new BitwiseNotNode(GLOBAL_DATA, expr);
1422 }
1423
1424 static ExpressionNode* makeMultNode(void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
1425 {
1426     if (expr1->isNumber() && expr2->isNumber())
1427         return makeNumberNode(globalPtr, static_cast<NumberNode*>(expr1)->value() * static_cast<NumberNode*>(expr2)->value());
1428     return new MultNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);
1429 }
1430
1431 static ExpressionNode* makeDivNode(void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
1432 {
1433     if (expr1->isNumber() && expr2->isNumber())
1434         return makeNumberNode(globalPtr, static_cast<NumberNode*>(expr1)->value() / static_cast<NumberNode*>(expr2)->value());
1435     return new DivNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);
1436 }
1437
1438 static ExpressionNode* makeAddNode(void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
1439 {
1440     if (expr1->isNumber() && expr2->isNumber())
1441         return makeNumberNode(globalPtr, static_cast<NumberNode*>(expr1)->value() + static_cast<NumberNode*>(expr2)->value());
1442     return new AddNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);
1443 }
1444
1445 static ExpressionNode* makeLeftShiftNode(void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
1446 {
1447     if (expr1->isNumber() && expr2->isNumber())
1448         return makeNumberNode(globalPtr, JSValue::toInt32(static_cast<NumberNode*>(expr1)->value()) << (JSValue::toUInt32(static_cast<NumberNode*>(expr2)->value()) & 0x1f));
1449     return new LeftShiftNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);
1450 }
1451
1452 static ExpressionNode* makeRightShiftNode(void* globalPtr, ExpressionNode* expr1, ExpressionNode* expr2, bool rightHasAssignments)
1453 {
1454     if (expr1->isNumber() && expr2->isNumber())
1455         return makeNumberNode(globalPtr, JSValue::toInt32(static_cast<NumberNode*>(expr1)->value()) >> (JSValue::toUInt32(static_cast<NumberNode*>(expr2)->value()) & 0x1f));
1456     return new RightShiftNode(GLOBAL_DATA, expr1, expr2, rightHasAssignments);
1457 }
1458
1459 /* called by yyparse on error */
1460 int yyerror(const char *)
1461 {
1462     return 1;
1463 }
1464
1465 /* may we automatically insert a semicolon ? */
1466 static bool allowAutomaticSemicolon(Lexer& lexer, int yychar)
1467 {
1468     return yychar == CLOSEBRACE || yychar == 0 || lexer.prevTerminator();
1469 }
1470
1471 static ExpressionNode* combineVarInitializers(void* globalPtr, ExpressionNode* list, AssignResolveNode* init)
1472 {
1473     if (!list)
1474         return init;
1475     return new VarDeclCommaNode(GLOBAL_DATA, list, init);
1476 }
1477
1478 // We turn variable declarations into either assignments or empty
1479 // statements (which later get stripped out), because the actual
1480 // declaration work is hoisted up to the start of the function body
1481 static StatementNode* makeVarStatementNode(void* globalPtr, ExpressionNode* expr)
1482 {
1483     if (!expr)
1484         return new EmptyStatementNode(GLOBAL_DATA);
1485     return new VarStatementNode(GLOBAL_DATA, expr);
1486 }
1487
1488 #undef GLOBAL_DATA