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