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