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