2 * Copyright 2008 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define YYLEX_PARAM ctx
25 #define YYPARSE_PARAM ctx
27 static int parser_error(const char*);
28 static void set_error(parser_ctx_t*,UINT);
29 static BOOL explicit_error(parser_ctx_t*,void*,WCHAR);
30 static BOOL allow_auto_semicolon(parser_ctx_t*);
31 static void program_parsed(parser_ctx_t*,source_elements_t*);
32 static source_elements_t *function_body_parsed(parser_ctx_t*,source_elements_t*);
34 typedef struct _statement_list_t {
39 static literal_t *new_string_literal(parser_ctx_t*,const WCHAR*);
40 static literal_t *new_null_literal(parser_ctx_t*);
41 static literal_t *new_undefined_literal(parser_ctx_t*);
42 static literal_t *new_boolean_literal(parser_ctx_t*,VARIANT_BOOL);
44 typedef struct _property_list_t {
49 static property_list_t *new_property_list(parser_ctx_t*,literal_t*,expression_t*);
50 static property_list_t *property_list_add(parser_ctx_t*,property_list_t*,literal_t*,expression_t*);
52 typedef struct _element_list_t {
53 array_element_t *head;
54 array_element_t *tail;
57 static element_list_t *new_element_list(parser_ctx_t*,int,expression_t*);
58 static element_list_t *element_list_add(parser_ctx_t*,element_list_t*,int,expression_t*);
60 typedef struct _argument_list_t {
65 static argument_list_t *new_argument_list(parser_ctx_t*,expression_t*);
66 static argument_list_t *argument_list_add(parser_ctx_t*,argument_list_t*,expression_t*);
68 typedef struct _case_list_t {
69 case_clausule_t *head;
70 case_clausule_t *tail;
73 static catch_block_t *new_catch_block(parser_ctx_t*,const WCHAR*,statement_t*);
74 static case_clausule_t *new_case_clausule(parser_ctx_t*,expression_t*,statement_list_t*);
75 static case_list_t *new_case_list(parser_ctx_t*,case_clausule_t*);
76 static case_list_t *case_list_add(parser_ctx_t*,case_list_t*,case_clausule_t*);
77 static case_clausule_t *new_case_block(parser_ctx_t*,case_list_t*,case_clausule_t*,case_list_t*);
79 typedef struct _variable_list_t {
80 variable_declaration_t *head;
81 variable_declaration_t *tail;
84 static variable_declaration_t *new_variable_declaration(parser_ctx_t*,const WCHAR*,expression_t*);
85 static variable_list_t *new_variable_list(parser_ctx_t*,variable_declaration_t*);
86 static variable_list_t *variable_list_add(parser_ctx_t*,variable_list_t*,variable_declaration_t*);
88 static statement_t *new_block_statement(parser_ctx_t*,statement_list_t*);
89 static statement_t *new_var_statement(parser_ctx_t*,variable_list_t*);
90 static statement_t *new_empty_statement(parser_ctx_t*);
91 static statement_t *new_expression_statement(parser_ctx_t*,expression_t*);
92 static statement_t *new_if_statement(parser_ctx_t*,expression_t*,statement_t*,statement_t*);
93 static statement_t *new_while_statement(parser_ctx_t*,BOOL,expression_t*,statement_t*);
94 static statement_t *new_for_statement(parser_ctx_t*,variable_list_t*,expression_t*,expression_t*,
95 expression_t*,statement_t*);
96 static statement_t *new_forin_statement(parser_ctx_t*,variable_declaration_t*,expression_t*,expression_t*,statement_t*);
97 static statement_t *new_continue_statement(parser_ctx_t*,const WCHAR*);
98 static statement_t *new_break_statement(parser_ctx_t*,const WCHAR*);
99 static statement_t *new_return_statement(parser_ctx_t*,expression_t*);
100 static statement_t *new_with_statement(parser_ctx_t*,expression_t*,statement_t*);
101 static statement_t *new_labelled_statement(parser_ctx_t*,const WCHAR*,statement_t*);
102 static statement_t *new_switch_statement(parser_ctx_t*,expression_t*,case_clausule_t*);
103 static statement_t *new_throw_statement(parser_ctx_t*,expression_t*);
104 static statement_t *new_try_statement(parser_ctx_t*,statement_t*,catch_block_t*,statement_t*);
106 struct statement_list_t {
111 static statement_list_t *new_statement_list(parser_ctx_t*,statement_t*);
112 static statement_list_t *statement_list_add(statement_list_t*,statement_t*);
114 typedef struct _parameter_list_t {
119 static parameter_list_t *new_parameter_list(parser_ctx_t*,const WCHAR*);
120 static parameter_list_t *parameter_list_add(parser_ctx_t*,parameter_list_t*,const WCHAR*);
122 static void push_func(parser_ctx_t*);
123 static inline void pop_func(parser_ctx_t *ctx)
125 ctx->func_stack = ctx->func_stack->next;
128 static expression_t *new_function_expression(parser_ctx_t*,const WCHAR*,parameter_list_t*,
129 source_elements_t*,const WCHAR*,DWORD);
130 static expression_t *new_binary_expression(parser_ctx_t*,expression_type_t,expression_t*,expression_t*);
131 static expression_t *new_unary_expression(parser_ctx_t*,expression_type_t,expression_t*);
132 static expression_t *new_conditional_expression(parser_ctx_t*,expression_t*,expression_t*,expression_t*);
133 static expression_t *new_array_expression(parser_ctx_t*,expression_t*,expression_t*);
134 static expression_t *new_member_expression(parser_ctx_t*,expression_t*,const WCHAR*);
135 static expression_t *new_new_expression(parser_ctx_t*,expression_t*,argument_list_t*);
136 static expression_t *new_call_expression(parser_ctx_t*,expression_t*,argument_list_t*);
137 static expression_t *new_this_expression(parser_ctx_t*);
138 static expression_t *new_identifier_expression(parser_ctx_t*,const WCHAR*);
139 static expression_t *new_literal_expression(parser_ctx_t*,literal_t*);
140 static expression_t *new_array_literal_expression(parser_ctx_t*,element_list_t*,int);
141 static expression_t *new_prop_and_value_expression(parser_ctx_t*,property_list_t*);
143 static source_elements_t *new_source_elements(parser_ctx_t*);
144 static source_elements_t *source_elements_add_statement(source_elements_t*,statement_t*);
156 struct _argument_list_t *argument_list;
157 case_clausule_t *case_clausule;
158 struct _case_list_t *case_list;
159 catch_block_t *catch_block;
160 struct _element_list_t *element_list;
162 const WCHAR *identifier;
163 struct _parameter_list_t *parameter_list;
164 struct _property_list_t *property_list;
165 source_elements_t *source_elements;
166 statement_t *statement;
167 struct _statement_list_t *statement_list;
168 struct _variable_list_t *variable_list;
169 variable_declaration_t *variable_declaration;
173 %token kBREAK kCASE kCATCH kCONTINUE kDEFAULT kDELETE kDO kELSE kIF kFINALLY kFOR kIN
174 %token kINSTANCEOF kNEW kNULL kUNDEFINED kRETURN kSWITCH kTHIS kTHROW kTRUE kFALSE kTRY kTYPEOF kVAR kVOID kWHILE kWITH
175 %token tANDAND tOROR tINC tDEC tHTMLCOMMENT kDIVEQ
177 %token <srcptr> kFUNCTION '}'
180 %token <identifier> tIdentifier
181 %token <ival> tAssignOper tEqOper tShiftOper tRelOper
182 %token <literal> tNumericLiteral
183 %token <wstr> tStringLiteral
185 %type <source_elements> SourceElements
186 %type <source_elements> FunctionBody
187 %type <statement> Statement
188 %type <statement> Block
189 %type <statement> VariableStatement
190 %type <statement> EmptyStatement
191 %type <statement> ExpressionStatement
192 %type <statement> IfStatement
193 %type <statement> IterationStatement
194 %type <statement> ContinueStatement
195 %type <statement> BreakStatement
196 %type <statement> ReturnStatement
197 %type <statement> WithStatement
198 %type <statement> LabelledStatement
199 %type <statement> SwitchStatement
200 %type <statement> ThrowStatement
201 %type <statement> TryStatement
202 %type <statement> Finally
203 %type <statement_list> StatementList StatementList_opt
204 %type <parameter_list> FormalParameterList FormalParameterList_opt
205 %type <expr> Expression Expression_opt Expression_err
206 %type <expr> ExpressionNoIn ExpressionNoIn_opt
207 %type <expr> FunctionExpression
208 %type <expr> AssignmentExpression AssignmentExpressionNoIn
209 %type <expr> ConditionalExpression ConditionalExpressionNoIn
210 %type <expr> LeftHandSideExpression
211 %type <expr> LogicalORExpression LogicalORExpressionNoIn
212 %type <expr> LogicalANDExpression LogicalANDExpressionNoIn
213 %type <expr> BitwiseORExpression BitwiseORExpressionNoIn
214 %type <expr> BitwiseXORExpression BitwiseXORExpressionNoIn
215 %type <expr> BitwiseANDExpression BitwiseANDExpressionNoIn
216 %type <expr> EqualityExpression EqualityExpressionNoIn
217 %type <expr> RelationalExpression RelationalExpressionNoIn
218 %type <expr> ShiftExpression
219 %type <expr> AdditiveExpression
220 %type <expr> MultiplicativeExpression
221 %type <expr> Initialiser_opt Initialiser
222 %type <expr> InitialiserNoIn_opt InitialiserNoIn
223 %type <expr> UnaryExpression
224 %type <expr> PostfixExpression
225 %type <expr> NewExpression
226 %type <expr> CallExpression
227 %type <expr> MemberExpression
228 %type <expr> PrimaryExpression
229 %type <identifier> Identifier_opt
230 %type <variable_list> VariableDeclarationList
231 %type <variable_list> VariableDeclarationListNoIn
232 %type <variable_declaration> VariableDeclaration
233 %type <variable_declaration> VariableDeclarationNoIn
234 %type <case_list> CaseClausules CaseClausules_opt
235 %type <case_clausule> CaseClausule DefaultClausule CaseBlock
236 %type <catch_block> Catch
237 %type <argument_list> Arguments
238 %type <argument_list> ArgumentList
239 %type <literal> Literal
240 %type <expr> ArrayLiteral
241 %type <expr> ObjectLiteral
242 %type <ival> Elision Elision_opt
243 %type <element_list> ElementList
244 %type <property_list> PropertyNameAndValueList
245 %type <literal> PropertyName
246 %type <literal> BooleanLiteral
247 %type <srcptr> KFunction
248 %type <ival> AssignOper
250 %nonassoc LOWER_THAN_ELSE
255 /* ECMA-262 3rd Edition 14 */
257 : SourceElements HtmlComment
258 { program_parsed(ctx, $1); }
264 /* ECMA-262 3rd Edition 14 */
266 : /* empty */ { $$ = new_source_elements(ctx); }
267 | SourceElements Statement
268 { $$ = source_elements_add_statement($1, $2); }
270 /* ECMA-262 3rd Edition 13 */
272 : KFunction Identifier_opt left_bracket FormalParameterList_opt right_bracket '{' FunctionBody '}'
273 { $$ = new_function_expression(ctx, $2, $4, $7, $1, $8-$1+1); }
276 : kFUNCTION { push_func(ctx); $$ = $1; }
278 /* ECMA-262 3rd Edition 13 */
280 : SourceElements { $$ = function_body_parsed(ctx, $1); }
282 /* ECMA-262 3rd Edition 13 */
284 : tIdentifier { $$ = new_parameter_list(ctx, $1); }
285 | FormalParameterList ',' tIdentifier
286 { $$ = parameter_list_add(ctx, $1, $3); }
288 /* ECMA-262 3rd Edition 13 */
289 FormalParameterList_opt
290 : /* empty */ { $$ = NULL; }
291 | FormalParameterList { $$ = $1; }
293 /* ECMA-262 3rd Edition 12 */
296 | VariableStatement { $$ = $1; }
297 | EmptyStatement { $$ = $1; }
298 | FunctionExpression { $$ = new_empty_statement(ctx); } /* FIXME: return NULL */
299 | ExpressionStatement { $$ = $1; }
300 | IfStatement { $$ = $1; }
301 | IterationStatement { $$ = $1; }
302 | ContinueStatement { $$ = $1; }
303 | BreakStatement { $$ = $1; }
304 | ReturnStatement { $$ = $1; }
305 | WithStatement { $$ = $1; }
306 | LabelledStatement { $$ = $1; }
307 | SwitchStatement { $$ = $1; }
308 | ThrowStatement { $$ = $1; }
309 | TryStatement { $$ = $1; }
311 /* ECMA-262 3rd Edition 12.2 */
313 : Statement { $$ = new_statement_list(ctx, $1); }
314 | StatementList Statement
315 { $$ = statement_list_add($1, $2); }
317 /* ECMA-262 3rd Edition 12.2 */
319 : /* empty */ { $$ = NULL; }
320 | StatementList { $$ = $1; }
322 /* ECMA-262 3rd Edition 12.1 */
324 : '{' StatementList '}' { $$ = new_block_statement(ctx, $2); }
325 | '{' '}' { $$ = new_block_statement(ctx, NULL); }
327 /* ECMA-262 3rd Edition 12.2 */
329 : kVAR VariableDeclarationList semicolon_opt
330 { $$ = new_var_statement(ctx, $2); }
332 /* ECMA-262 3rd Edition 12.2 */
333 VariableDeclarationList
334 : VariableDeclaration { $$ = new_variable_list(ctx, $1); }
335 | VariableDeclarationList ',' VariableDeclaration
336 { $$ = variable_list_add(ctx, $1, $3); }
338 /* ECMA-262 3rd Edition 12.2 */
339 VariableDeclarationListNoIn
340 : VariableDeclarationNoIn
341 { $$ = new_variable_list(ctx, $1); }
342 | VariableDeclarationListNoIn ',' VariableDeclarationNoIn
343 { $$ = variable_list_add(ctx, $1, $3); }
345 /* ECMA-262 3rd Edition 12.2 */
347 : tIdentifier Initialiser_opt
348 { $$ = new_variable_declaration(ctx, $1, $2); }
350 /* ECMA-262 3rd Edition 12.2 */
351 VariableDeclarationNoIn
352 : tIdentifier InitialiserNoIn_opt
353 { $$ = new_variable_declaration(ctx, $1, $2); }
355 /* ECMA-262 3rd Edition 12.2 */
357 : /* empty */ { $$ = NULL; }
358 | Initialiser { $$ = $1; }
360 /* ECMA-262 3rd Edition 12.2 */
362 : '=' AssignmentExpression
365 /* ECMA-262 3rd Edition 12.2 */
367 : /* empty */ { $$ = NULL; }
368 | InitialiserNoIn { $$ = $1; }
370 /* ECMA-262 3rd Edition 12.2 */
372 : '=' AssignmentExpressionNoIn
375 /* ECMA-262 3rd Edition 12.3 */
377 : ';' { $$ = new_empty_statement(ctx); }
379 /* ECMA-262 3rd Edition 12.4 */
381 : Expression semicolon_opt
382 { $$ = new_expression_statement(ctx, $1); }
384 /* ECMA-262 3rd Edition 12.5 */
386 : kIF left_bracket Expression_err right_bracket Statement kELSE Statement
387 { $$ = new_if_statement(ctx, $3, $5, $7); }
388 | kIF left_bracket Expression_err right_bracket Statement %prec LOWER_THAN_ELSE
389 { $$ = new_if_statement(ctx, $3, $5, NULL); }
391 /* ECMA-262 3rd Edition 12.6 */
393 : kDO Statement kWHILE left_bracket Expression_err right_bracket semicolon_opt
394 { $$ = new_while_statement(ctx, TRUE, $5, $2); }
395 | kWHILE left_bracket Expression_err right_bracket Statement
396 { $$ = new_while_statement(ctx, FALSE, $3, $5); }
397 | kFOR left_bracket ExpressionNoIn_opt
398 { if(!explicit_error(ctx, $3, ';')) YYABORT; }
399 semicolon Expression_opt
400 { if(!explicit_error(ctx, $6, ';')) YYABORT; }
401 semicolon Expression_opt right_bracket Statement
402 { $$ = new_for_statement(ctx, NULL, $3, $6, $9, $11); }
403 | kFOR left_bracket kVAR VariableDeclarationListNoIn
404 { if(!explicit_error(ctx, $4, ';')) YYABORT; }
405 semicolon Expression_opt
406 { if(!explicit_error(ctx, $7, ';')) YYABORT; }
407 semicolon Expression_opt right_bracket Statement
408 { $$ = new_for_statement(ctx, $4, NULL, $7, $10, $12); }
409 | kFOR left_bracket LeftHandSideExpression kIN Expression_err right_bracket Statement
410 { $$ = new_forin_statement(ctx, NULL, $3, $5, $7); }
411 | kFOR left_bracket kVAR VariableDeclarationNoIn kIN Expression_err right_bracket Statement
412 { $$ = new_forin_statement(ctx, $4, NULL, $6, $8); }
414 /* ECMA-262 3rd Edition 12.7 */
416 : kCONTINUE /* NONL */ Identifier_opt semicolon_opt
417 { $$ = new_continue_statement(ctx, $2); }
419 /* ECMA-262 3rd Edition 12.8 */
421 : kBREAK /* NONL */ Identifier_opt semicolon_opt
422 { $$ = new_break_statement(ctx, $2); }
424 /* ECMA-262 3rd Edition 12.9 */
426 : kRETURN /* NONL */ Expression_opt semicolon_opt
427 { $$ = new_return_statement(ctx, $2); }
429 /* ECMA-262 3rd Edition 12.10 */
431 : kWITH left_bracket Expression right_bracket Statement
432 { $$ = new_with_statement(ctx, $3, $5); }
434 /* ECMA-262 3rd Edition 12.12 */
436 : tIdentifier ':' Statement
437 { $$ = new_labelled_statement(ctx, $1, $3); }
439 /* ECMA-262 3rd Edition 12.11 */
441 : kSWITCH left_bracket Expression right_bracket CaseBlock
442 { $$ = new_switch_statement(ctx, $3, $5); }
444 /* ECMA-262 3rd Edition 12.11 */
446 : '{' CaseClausules_opt '}'
447 { $$ = new_case_block(ctx, $2, NULL, NULL); }
448 | '{' CaseClausules_opt DefaultClausule CaseClausules_opt '}'
449 { $$ = new_case_block(ctx, $2, $3, $4); }
451 /* ECMA-262 3rd Edition 12.11 */
453 : /* empty */ { $$ = NULL; }
454 | CaseClausules { $$ = $1; }
456 /* ECMA-262 3rd Edition 12.11 */
458 : CaseClausule { $$ = new_case_list(ctx, $1); }
459 | CaseClausules CaseClausule
460 { $$ = case_list_add(ctx, $1, $2); }
462 /* ECMA-262 3rd Edition 12.11 */
464 : kCASE Expression ':' StatementList_opt
465 { $$ = new_case_clausule(ctx, $2, $4); }
467 /* ECMA-262 3rd Edition 12.11 */
469 : kDEFAULT ':' StatementList_opt
470 { $$ = new_case_clausule(ctx, NULL, $3); }
472 /* ECMA-262 3rd Edition 12.13 */
474 : kTHROW /* NONL */ Expression semicolon_opt
475 { $$ = new_throw_statement(ctx, $2); }
477 /* ECMA-262 3rd Edition 12.14 */
479 : kTRY Block Catch { $$ = new_try_statement(ctx, $2, $3, NULL); }
480 | kTRY Block Finally { $$ = new_try_statement(ctx, $2, NULL, $3); }
481 | kTRY Block Catch Finally
482 { $$ = new_try_statement(ctx, $2, $3, $4); }
484 /* ECMA-262 3rd Edition 12.14 */
486 : kCATCH left_bracket tIdentifier right_bracket Block
487 { $$ = new_catch_block(ctx, $3, $5); }
489 /* ECMA-262 3rd Edition 12.14 */
491 : kFINALLY Block { $$ = $2; }
493 /* ECMA-262 3rd Edition 11.14 */
495 : /* empty */ { $$ = NULL; }
496 | Expression { $$ = $1; }
499 : Expression { $$ = $1; }
500 | error { set_error(ctx, IDS_SYNTAX_ERROR); YYABORT; }
502 /* ECMA-262 3rd Edition 11.14 */
504 : AssignmentExpression { $$ = $1; }
505 | Expression ',' AssignmentExpression
506 { $$ = new_binary_expression(ctx, EXPR_COMMA, $1, $3); }
508 /* ECMA-262 3rd Edition 11.14 */
510 : /* empty */ { $$ = NULL; }
511 | ExpressionNoIn { $$ = $1; }
513 /* ECMA-262 3rd Edition 11.14 */
515 : AssignmentExpressionNoIn
517 | ExpressionNoIn ',' AssignmentExpressionNoIn
518 { $$ = new_binary_expression(ctx, EXPR_COMMA, $1, $3); }
521 : tAssignOper { $$ = $1; }
522 | kDIVEQ { $$ = EXPR_ASSIGNDIV; }
524 /* ECMA-262 3rd Edition 11.13 */
526 : ConditionalExpression { $$ = $1; }
527 | LeftHandSideExpression '=' AssignmentExpression
528 { $$ = new_binary_expression(ctx, EXPR_ASSIGN, $1, $3); }
529 | LeftHandSideExpression AssignOper AssignmentExpression
530 { $$ = new_binary_expression(ctx, $2, $1, $3); }
532 /* ECMA-262 3rd Edition 11.13 */
533 AssignmentExpressionNoIn
534 : ConditionalExpressionNoIn
536 | LeftHandSideExpression '=' AssignmentExpressionNoIn
537 { $$ = new_binary_expression(ctx, EXPR_ASSIGN, $1, $3); }
538 | LeftHandSideExpression AssignOper AssignmentExpressionNoIn
539 { $$ = new_binary_expression(ctx, $2, $1, $3); }
541 /* ECMA-262 3rd Edition 11.12 */
542 ConditionalExpression
543 : LogicalORExpression { $$ = $1; }
544 | LogicalORExpression '?' AssignmentExpression ':' AssignmentExpression
545 { $$ = new_conditional_expression(ctx, $1, $3, $5); }
547 /* ECMA-262 3rd Edition 11.12 */
548 ConditionalExpressionNoIn
549 : LogicalORExpressionNoIn
551 | LogicalORExpressionNoIn '?' AssignmentExpressionNoIn ':' AssignmentExpressionNoIn
552 { $$ = new_conditional_expression(ctx, $1, $3, $5); }
554 /* ECMA-262 3rd Edition 11.11 */
556 : LogicalANDExpression { $$ = $1; }
557 | LogicalORExpression tOROR LogicalANDExpression
558 { $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); }
560 /* ECMA-262 3rd Edition 11.11 */
561 LogicalORExpressionNoIn
562 : LogicalANDExpressionNoIn
564 | LogicalORExpressionNoIn tOROR LogicalANDExpressionNoIn
565 { $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); }
567 /* ECMA-262 3rd Edition 11.11 */
569 : BitwiseORExpression { $$ = $1; }
570 | LogicalANDExpression tANDAND BitwiseORExpression
571 { $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); }
573 /* ECMA-262 3rd Edition 11.11 */
574 LogicalANDExpressionNoIn
575 : BitwiseORExpressionNoIn
577 | LogicalANDExpressionNoIn tANDAND BitwiseORExpressionNoIn
578 { $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); }
580 /* ECMA-262 3rd Edition 11.10 */
582 : BitwiseXORExpression { $$ = $1; }
583 | BitwiseORExpression '|' BitwiseXORExpression
584 { $$ = new_binary_expression(ctx, EXPR_BOR, $1, $3); }
586 /* ECMA-262 3rd Edition 11.10 */
587 BitwiseORExpressionNoIn
588 : BitwiseXORExpressionNoIn
590 | BitwiseORExpressionNoIn '|' BitwiseXORExpressionNoIn
591 { $$ = new_binary_expression(ctx, EXPR_BOR, $1, $3); }
593 /* ECMA-262 3rd Edition 11.10 */
595 : BitwiseANDExpression { $$ = $1; }
596 | BitwiseXORExpression '^' BitwiseANDExpression
597 { $$ = new_binary_expression(ctx, EXPR_BXOR, $1, $3); }
599 /* ECMA-262 3rd Edition 11.10 */
600 BitwiseXORExpressionNoIn
601 : BitwiseANDExpressionNoIn
603 | BitwiseXORExpressionNoIn '^' BitwiseANDExpressionNoIn
604 { $$ = new_binary_expression(ctx, EXPR_BXOR, $1, $3); }
606 /* ECMA-262 3rd Edition 11.10 */
608 : EqualityExpression { $$ = $1; }
609 | BitwiseANDExpression '&' EqualityExpression
610 { $$ = new_binary_expression(ctx, EXPR_BAND, $1, $3); }
612 /* ECMA-262 3rd Edition 11.10 */
613 BitwiseANDExpressionNoIn
614 : EqualityExpressionNoIn
616 | BitwiseANDExpressionNoIn '&' EqualityExpressionNoIn
617 { $$ = new_binary_expression(ctx, EXPR_BAND, $1, $3); }
619 /* ECMA-262 3rd Edition 11.9 */
621 : RelationalExpression { $$ = $1; }
622 | EqualityExpression tEqOper RelationalExpression
623 { $$ = new_binary_expression(ctx, $2, $1, $3); }
625 /* ECMA-262 3rd Edition 11.9 */
626 EqualityExpressionNoIn
627 : RelationalExpressionNoIn { $$ = $1; }
628 | EqualityExpressionNoIn tEqOper RelationalExpressionNoIn
629 { $$ = new_binary_expression(ctx, $2, $1, $3); }
631 /* ECMA-262 3rd Edition 11.8 */
633 : ShiftExpression { $$ = $1; }
634 | RelationalExpression tRelOper ShiftExpression
635 { $$ = new_binary_expression(ctx, $2, $1, $3); }
636 | RelationalExpression kINSTANCEOF ShiftExpression
637 { $$ = new_binary_expression(ctx, EXPR_INSTANCEOF, $1, $3); }
638 | RelationalExpression kIN ShiftExpression
639 { $$ = new_binary_expression(ctx, EXPR_IN, $1, $3); }
641 /* ECMA-262 3rd Edition 11.8 */
642 RelationalExpressionNoIn
643 : ShiftExpression { $$ = $1; }
644 | RelationalExpressionNoIn tRelOper ShiftExpression
645 { $$ = new_binary_expression(ctx, $2, $1, $3); }
646 | RelationalExpressionNoIn kINSTANCEOF ShiftExpression
647 { $$ = new_binary_expression(ctx, EXPR_INSTANCEOF, $1, $3); }
649 /* ECMA-262 3rd Edition 11.7 */
651 : AdditiveExpression { $$ = $1; }
652 | ShiftExpression tShiftOper AdditiveExpression
653 { $$ = new_binary_expression(ctx, $2, $1, $3); }
655 /* ECMA-262 3rd Edition 11.6 */
657 : MultiplicativeExpression
659 | AdditiveExpression '+' MultiplicativeExpression
660 { $$ = new_binary_expression(ctx, EXPR_ADD, $1, $3); }
661 | AdditiveExpression '-' MultiplicativeExpression
662 { $$ = new_binary_expression(ctx, EXPR_SUB, $1, $3); }
664 /* ECMA-262 3rd Edition 11.5 */
665 MultiplicativeExpression
666 : UnaryExpression { $$ = $1; }
667 | MultiplicativeExpression '*' UnaryExpression
668 { $$ = new_binary_expression(ctx, EXPR_MUL, $1, $3); }
669 | MultiplicativeExpression '/' UnaryExpression
670 { $$ = new_binary_expression(ctx, EXPR_DIV, $1, $3); }
671 | MultiplicativeExpression '%' UnaryExpression
672 { $$ = new_binary_expression(ctx, EXPR_MOD, $1, $3); }
674 /* ECMA-262 3rd Edition 11.4 */
676 : PostfixExpression { $$ = $1; }
677 | kDELETE UnaryExpression
678 { $$ = new_unary_expression(ctx, EXPR_DELETE, $2); }
679 | kVOID UnaryExpression { $$ = new_unary_expression(ctx, EXPR_VOID, $2); }
680 | kTYPEOF UnaryExpression
681 { $$ = new_unary_expression(ctx, EXPR_TYPEOF, $2); }
682 | tINC UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PREINC, $2); }
683 | tDEC UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PREDEC, $2); }
684 | '+' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PLUS, $2); }
685 | '-' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_MINUS, $2); }
686 | '~' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_BITNEG, $2); }
687 | '!' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_LOGNEG, $2); }
689 /* ECMA-262 3rd Edition 11.2 */
691 : LeftHandSideExpression
693 | LeftHandSideExpression /* NONL */ tINC
694 { $$ = new_unary_expression(ctx, EXPR_POSTINC, $1); }
695 | LeftHandSideExpression /* NONL */ tDEC
696 { $$ = new_unary_expression(ctx, EXPR_POSTDEC, $1); }
699 /* ECMA-262 3rd Edition 11.2 */
700 LeftHandSideExpression
701 : NewExpression { $$ = $1; }
702 | CallExpression { $$ = $1; }
704 /* ECMA-262 3rd Edition 11.2 */
706 : MemberExpression { $$ = $1; }
707 | kNEW NewExpression { $$ = new_new_expression(ctx, $2, NULL); }
709 /* ECMA-262 3rd Edition 11.2 */
711 : PrimaryExpression { $$ = $1; }
712 | FunctionExpression { $$ = $1; }
713 | MemberExpression '[' Expression ']'
714 { $$ = new_array_expression(ctx, $1, $3); }
715 | MemberExpression '.' tIdentifier
716 { $$ = new_member_expression(ctx, $1, $3); }
717 | kNEW MemberExpression Arguments
718 { $$ = new_new_expression(ctx, $2, $3); }
720 /* ECMA-262 3rd Edition 11.2 */
722 : MemberExpression Arguments
723 { $$ = new_call_expression(ctx, $1, $2); }
724 | CallExpression Arguments
725 { $$ = new_call_expression(ctx, $1, $2); }
726 | CallExpression '[' Expression ']'
727 { $$ = new_array_expression(ctx, $1, $3); }
728 | CallExpression '.' tIdentifier
729 { $$ = new_member_expression(ctx, $1, $3); }
731 /* ECMA-262 3rd Edition 11.2 */
733 : '(' ')' { $$ = NULL; }
734 | '(' ArgumentList ')' { $$ = $2; }
736 /* ECMA-262 3rd Edition 11.2 */
738 : AssignmentExpression { $$ = new_argument_list(ctx, $1); }
739 | ArgumentList ',' AssignmentExpression
740 { $$ = argument_list_add(ctx, $1, $3); }
742 /* ECMA-262 3rd Edition 11.1 */
744 : kTHIS { $$ = new_this_expression(ctx); }
745 | tIdentifier { $$ = new_identifier_expression(ctx, $1); }
746 | Literal { $$ = new_literal_expression(ctx, $1); }
747 | ArrayLiteral { $$ = $1; }
748 | ObjectLiteral { $$ = $1; }
749 | '(' Expression ')' { $$ = $2; }
751 /* ECMA-262 3rd Edition 11.1.4 */
753 : '[' ']' { $$ = new_array_literal_expression(ctx, NULL, 0); }
754 | '[' Elision ']' { $$ = new_array_literal_expression(ctx, NULL, $2+1); }
755 | '[' ElementList ']' { $$ = new_array_literal_expression(ctx, $2, 0); }
756 | '[' ElementList ',' Elision_opt ']'
757 { $$ = new_array_literal_expression(ctx, $2, $4+1); }
759 /* ECMA-262 3rd Edition 11.1.4 */
761 : Elision_opt AssignmentExpression
762 { $$ = new_element_list(ctx, $1, $2); }
763 | ElementList ',' Elision_opt AssignmentExpression
764 { $$ = element_list_add(ctx, $1, $3, $4); }
766 /* ECMA-262 3rd Edition 11.1.4 */
769 | Elision ',' { $$ = $1 + 1; }
771 /* ECMA-262 3rd Edition 11.1.4 */
773 : /* empty */ { $$ = 0; }
774 | Elision { $$ = $1; }
776 /* ECMA-262 3rd Edition 11.1.5 */
778 : '{' '}' { $$ = new_prop_and_value_expression(ctx, NULL); }
779 | '{' PropertyNameAndValueList '}'
780 { $$ = new_prop_and_value_expression(ctx, $2); }
782 /* ECMA-262 3rd Edition 11.1.5 */
783 PropertyNameAndValueList
784 : PropertyName ':' AssignmentExpression
785 { $$ = new_property_list(ctx, $1, $3); }
786 | PropertyNameAndValueList ',' PropertyName ':' AssignmentExpression
787 { $$ = property_list_add(ctx, $1, $3, $5); }
789 /* ECMA-262 3rd Edition 11.1.5 */
791 : tIdentifier { $$ = new_string_literal(ctx, $1); }
792 | tStringLiteral { $$ = new_string_literal(ctx, $1); }
793 | tNumericLiteral { $$ = $1; }
795 /* ECMA-262 3rd Edition 7.6 */
797 : /* empty*/ { $$ = NULL; }
798 | tIdentifier { $$ = $1; }
800 /* ECMA-262 3rd Edition 7.8 */
802 : kNULL { $$ = new_null_literal(ctx); }
803 | kUNDEFINED { $$ = new_undefined_literal(ctx); }
804 | BooleanLiteral { $$ = $1; }
805 | tNumericLiteral { $$ = $1; }
806 | tStringLiteral { $$ = new_string_literal(ctx, $1); }
807 | '/' { $$ = parse_regexp(ctx);
809 | kDIVEQ { $$ = parse_regexp(ctx);
812 /* ECMA-262 3rd Edition 7.8.2 */
814 : kTRUE { $$ = new_boolean_literal(ctx, VARIANT_TRUE); }
815 | kFALSE { $$ = new_boolean_literal(ctx, VARIANT_FALSE); }
819 | error { if(!allow_auto_semicolon(ctx)) {YYABORT;} }
823 | error { set_error(ctx, IDS_LBRACKET); YYABORT; }
827 | error { set_error(ctx, IDS_RBRACKET); YYABORT; }
831 | error { set_error(ctx, IDS_SEMICOLON); YYABORT; }
835 static BOOL allow_auto_semicolon(parser_ctx_t *ctx)
837 return ctx->nl || ctx->ptr == ctx->end || *(ctx->ptr-1) == '}';
840 static literal_t *new_string_literal(parser_ctx_t *ctx, const WCHAR *str)
842 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
844 ret->type = LT_STRING;
850 static literal_t *new_null_literal(parser_ctx_t *ctx)
852 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
859 static literal_t *new_undefined_literal(parser_ctx_t *ctx)
861 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
863 ret->type = LT_UNDEFINED;
868 static literal_t *new_boolean_literal(parser_ctx_t *ctx, VARIANT_BOOL bval)
870 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
878 static prop_val_t *new_prop_val(parser_ctx_t *ctx, literal_t *name, expression_t *value)
880 prop_val_t *ret = parser_alloc(ctx, sizeof(prop_val_t));
889 static property_list_t *new_property_list(parser_ctx_t *ctx, literal_t *name, expression_t *value)
891 property_list_t *ret = parser_alloc_tmp(ctx, sizeof(property_list_t));
893 ret->head = ret->tail = new_prop_val(ctx, name, value);
898 static property_list_t *property_list_add(parser_ctx_t *ctx, property_list_t *list, literal_t *name, expression_t *value)
900 list->tail = list->tail->next = new_prop_val(ctx, name, value);
905 static array_element_t *new_array_element(parser_ctx_t *ctx, int elision, expression_t *expr)
907 array_element_t *ret = parser_alloc(ctx, sizeof(array_element_t));
909 ret->elision = elision;
916 static element_list_t *new_element_list(parser_ctx_t *ctx, int elision, expression_t *expr)
918 element_list_t *ret = parser_alloc_tmp(ctx, sizeof(element_list_t));
920 ret->head = ret->tail = new_array_element(ctx, elision, expr);
925 static element_list_t *element_list_add(parser_ctx_t *ctx, element_list_t *list, int elision, expression_t *expr)
927 list->tail = list->tail->next = new_array_element(ctx, elision, expr);
932 static argument_t *new_argument(parser_ctx_t *ctx, expression_t *expr)
934 argument_t *ret = parser_alloc(ctx, sizeof(argument_t));
942 static argument_list_t *new_argument_list(parser_ctx_t *ctx, expression_t *expr)
944 argument_list_t *ret = parser_alloc_tmp(ctx, sizeof(argument_list_t));
946 ret->head = ret->tail = new_argument(ctx, expr);
951 static argument_list_t *argument_list_add(parser_ctx_t *ctx, argument_list_t *list, expression_t *expr)
953 list->tail = list->tail->next = new_argument(ctx, expr);
958 static catch_block_t *new_catch_block(parser_ctx_t *ctx, const WCHAR *identifier, statement_t *statement)
960 catch_block_t *ret = parser_alloc(ctx, sizeof(catch_block_t));
962 ret->identifier = identifier;
963 ret->statement = statement;
968 static case_clausule_t *new_case_clausule(parser_ctx_t *ctx, expression_t *expr, statement_list_t *stat_list)
970 case_clausule_t *ret = parser_alloc(ctx, sizeof(case_clausule_t));
973 ret->stat = stat_list ? stat_list->head : NULL;
979 static case_list_t *new_case_list(parser_ctx_t *ctx, case_clausule_t *case_clausule)
981 case_list_t *ret = parser_alloc_tmp(ctx, sizeof(case_list_t));
983 ret->head = ret->tail = case_clausule;
988 static case_list_t *case_list_add(parser_ctx_t *ctx, case_list_t *list, case_clausule_t *case_clausule)
990 list->tail = list->tail->next = case_clausule;
995 static case_clausule_t *new_case_block(parser_ctx_t *ctx, case_list_t *case_list1,
996 case_clausule_t *default_clausule, case_list_t *case_list2)
998 case_clausule_t *ret = NULL, *iter = NULL, *iter2;
999 statement_t *stat = NULL;
1002 ret = case_list1->head;
1003 iter = case_list1->tail;
1006 if(default_clausule) {
1008 iter = iter->next = default_clausule;
1010 ret = iter = default_clausule;
1015 iter->next = case_list2->head;
1017 ret = case_list2->head;
1023 for(iter = ret; iter; iter = iter->next) {
1024 for(iter2 = iter; iter2 && !iter2->stat; iter2 = iter2->next);
1028 while(iter != iter2) {
1029 iter->stat = iter2->stat;
1036 stat->next = iter->stat;
1045 static statement_t *new_block_statement(parser_ctx_t *ctx, statement_list_t *list)
1047 block_statement_t *ret = parser_alloc(ctx, sizeof(block_statement_t));
1049 ret->stat.eval = block_statement_eval;
1050 ret->stat.next = NULL;
1051 ret->stat_list = list ? list->head : NULL;
1056 static variable_declaration_t *new_variable_declaration(parser_ctx_t *ctx, const WCHAR *identifier, expression_t *expr)
1058 variable_declaration_t *ret = parser_alloc(ctx, sizeof(variable_declaration_t));
1059 var_list_t *var_list = parser_alloc(ctx, sizeof(var_list_t));
1061 ret->identifier = identifier;
1065 var_list->identifier = identifier;
1066 var_list->next = NULL;
1068 if(ctx->func_stack->var_tail)
1069 ctx->func_stack->var_tail = ctx->func_stack->var_tail->next = var_list;
1071 ctx->func_stack->var_head = ctx->func_stack->var_tail = var_list;
1076 static variable_list_t *new_variable_list(parser_ctx_t *ctx, variable_declaration_t *decl)
1078 variable_list_t *ret = parser_alloc_tmp(ctx, sizeof(variable_list_t));
1080 ret->head = ret->tail = decl;
1085 static variable_list_t *variable_list_add(parser_ctx_t *ctx, variable_list_t *list, variable_declaration_t *decl)
1087 list->tail = list->tail->next = decl;
1092 static statement_t *new_var_statement(parser_ctx_t *ctx, variable_list_t *variable_list)
1094 var_statement_t *ret = parser_alloc(ctx, sizeof(var_statement_t));
1096 ret->stat.eval = var_statement_eval;
1097 ret->stat.next = NULL;
1098 ret->variable_list = variable_list->head;
1103 static statement_t *new_empty_statement(parser_ctx_t *ctx)
1105 statement_t *ret = parser_alloc(ctx, sizeof(statement_t));
1107 ret->eval = empty_statement_eval;
1113 static statement_t *new_expression_statement(parser_ctx_t *ctx, expression_t *expr)
1115 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1117 ret->stat.eval = expression_statement_eval;
1118 ret->stat.next = NULL;
1124 static statement_t *new_if_statement(parser_ctx_t *ctx, expression_t *expr, statement_t *if_stat, statement_t *else_stat)
1126 if_statement_t *ret = parser_alloc(ctx, sizeof(if_statement_t));
1128 ret->stat.eval = if_statement_eval;
1129 ret->stat.next = NULL;
1131 ret->if_stat = if_stat;
1132 ret->else_stat = else_stat;
1137 static statement_t *new_while_statement(parser_ctx_t *ctx, BOOL dowhile, expression_t *expr, statement_t *stat)
1139 while_statement_t *ret = parser_alloc(ctx, sizeof(while_statement_t));
1141 ret->stat.eval = while_statement_eval;
1142 ret->stat.next = NULL;
1143 ret->do_while = dowhile;
1145 ret->statement = stat;
1150 static statement_t *new_for_statement(parser_ctx_t *ctx, variable_list_t *variable_list, expression_t *begin_expr,
1151 expression_t *expr, expression_t *end_expr, statement_t *statement)
1153 for_statement_t *ret = parser_alloc(ctx, sizeof(for_statement_t));
1155 ret->stat.eval = for_statement_eval;
1156 ret->stat.next = NULL;
1157 ret->variable_list = variable_list ? variable_list->head : NULL;
1158 ret->begin_expr = begin_expr;
1160 ret->end_expr = end_expr;
1161 ret->statement = statement;
1166 static statement_t *new_forin_statement(parser_ctx_t *ctx, variable_declaration_t *variable, expression_t *expr,
1167 expression_t *in_expr, statement_t *statement)
1169 forin_statement_t *ret = parser_alloc(ctx, sizeof(forin_statement_t));
1171 ret->stat.eval = forin_statement_eval;
1172 ret->stat.next = NULL;
1173 ret->variable = variable;
1175 ret->in_expr = in_expr;
1176 ret->statement = statement;
1181 static statement_t *new_continue_statement(parser_ctx_t *ctx, const WCHAR *identifier)
1183 branch_statement_t *ret = parser_alloc(ctx, sizeof(branch_statement_t));
1185 ret->stat.eval = continue_statement_eval;
1186 ret->stat.next = NULL;
1187 ret->identifier = identifier;
1192 static statement_t *new_break_statement(parser_ctx_t *ctx, const WCHAR *identifier)
1194 branch_statement_t *ret = parser_alloc(ctx, sizeof(branch_statement_t));
1196 ret->stat.eval = break_statement_eval;
1197 ret->stat.next = NULL;
1198 ret->identifier = identifier;
1203 static statement_t *new_return_statement(parser_ctx_t *ctx, expression_t *expr)
1205 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1207 ret->stat.eval = return_statement_eval;
1208 ret->stat.next = NULL;
1214 static statement_t *new_with_statement(parser_ctx_t *ctx, expression_t *expr, statement_t *statement)
1216 with_statement_t *ret = parser_alloc(ctx, sizeof(with_statement_t));
1218 ret->stat.eval = with_statement_eval;
1219 ret->stat.next = NULL;
1221 ret->statement = statement;
1226 static statement_t *new_labelled_statement(parser_ctx_t *ctx, const WCHAR *identifier, statement_t *statement)
1228 labelled_statement_t *ret = parser_alloc(ctx, sizeof(labelled_statement_t));
1230 ret->stat.eval = labelled_statement_eval;
1231 ret->stat.next = NULL;
1232 ret->identifier = identifier;
1233 ret->statement = statement;
1238 static statement_t *new_switch_statement(parser_ctx_t *ctx, expression_t *expr, case_clausule_t *case_list)
1240 switch_statement_t *ret = parser_alloc(ctx, sizeof(switch_statement_t));
1242 ret->stat.eval = switch_statement_eval;
1243 ret->stat.next = NULL;
1245 ret->case_list = case_list;
1250 static statement_t *new_throw_statement(parser_ctx_t *ctx, expression_t *expr)
1252 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1254 ret->stat.eval = throw_statement_eval;
1255 ret->stat.next = NULL;
1261 static statement_t *new_try_statement(parser_ctx_t *ctx, statement_t *try_statement,
1262 catch_block_t *catch_block, statement_t *finally_statement)
1264 try_statement_t *ret = parser_alloc(ctx, sizeof(try_statement_t));
1266 ret->stat.eval = try_statement_eval;
1267 ret->stat.next = NULL;
1268 ret->try_statement = try_statement;
1269 ret->catch_block = catch_block;
1270 ret->finally_statement = finally_statement;
1275 static parameter_t *new_parameter(parser_ctx_t *ctx, const WCHAR *identifier)
1277 parameter_t *ret = parser_alloc(ctx, sizeof(parameter_t));
1279 ret->identifier = identifier;
1285 static parameter_list_t *new_parameter_list(parser_ctx_t *ctx, const WCHAR *identifier)
1287 parameter_list_t *ret = parser_alloc_tmp(ctx, sizeof(parameter_list_t));
1289 ret->head = ret->tail = new_parameter(ctx, identifier);
1294 static parameter_list_t *parameter_list_add(parser_ctx_t *ctx, parameter_list_t *list, const WCHAR *identifier)
1296 list->tail = list->tail->next = new_parameter(ctx, identifier);
1301 static expression_t *new_function_expression(parser_ctx_t *ctx, const WCHAR *identifier,
1302 parameter_list_t *parameter_list, source_elements_t *source_elements, const WCHAR *src_str, DWORD src_len)
1304 function_expression_t *ret = parser_alloc(ctx, sizeof(function_expression_t));
1306 ret->expr.eval = function_expression_eval;
1307 ret->identifier = identifier;
1308 ret->parameter_list = parameter_list ? parameter_list->head : NULL;
1309 ret->source_elements = source_elements;
1310 ret->src_str = src_str;
1311 ret->src_len = src_len;
1313 if(ret->identifier) {
1314 function_declaration_t *decl = parser_alloc(ctx, sizeof(function_declaration_t));
1319 if(ctx->func_stack->func_tail)
1320 ctx->func_stack->func_tail = ctx->func_stack->func_tail->next = decl;
1322 ctx->func_stack->func_head = ctx->func_stack->func_tail = decl;
1328 static const expression_eval_t expression_eval_table[] = {
1329 comma_expression_eval,
1330 logical_or_expression_eval,
1331 logical_and_expression_eval,
1332 binary_or_expression_eval,
1333 binary_xor_expression_eval,
1334 binary_and_expression_eval,
1335 instanceof_expression_eval,
1337 add_expression_eval,
1338 sub_expression_eval,
1339 mul_expression_eval,
1340 div_expression_eval,
1341 mod_expression_eval,
1342 delete_expression_eval,
1343 void_expression_eval,
1344 typeof_expression_eval,
1345 minus_expression_eval,
1346 plus_expression_eval,
1347 post_increment_expression_eval,
1348 post_decrement_expression_eval,
1349 pre_increment_expression_eval,
1350 pre_decrement_expression_eval,
1351 equal_expression_eval,
1352 equal2_expression_eval,
1353 not_equal_expression_eval,
1354 not_equal2_expression_eval,
1355 less_expression_eval,
1356 lesseq_expression_eval,
1357 greater_expression_eval,
1358 greatereq_expression_eval,
1359 binary_negation_expression_eval,
1360 logical_negation_expression_eval,
1361 left_shift_expression_eval,
1362 right_shift_expression_eval,
1363 right2_shift_expression_eval,
1364 assign_expression_eval,
1365 assign_lshift_expression_eval,
1366 assign_rshift_expression_eval,
1367 assign_rrshift_expression_eval,
1368 assign_add_expression_eval,
1369 assign_sub_expression_eval,
1370 assign_mul_expression_eval,
1371 assign_div_expression_eval,
1372 assign_mod_expression_eval,
1373 assign_and_expression_eval,
1374 assign_or_expression_eval,
1375 assign_xor_expression_eval,
1378 static expression_t *new_binary_expression(parser_ctx_t *ctx, expression_type_t type,
1379 expression_t *expression1, expression_t *expression2)
1381 binary_expression_t *ret = parser_alloc(ctx, sizeof(binary_expression_t));
1383 ret->expr.eval = expression_eval_table[type];
1384 ret->expression1 = expression1;
1385 ret->expression2 = expression2;
1390 static expression_t *new_unary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *expression)
1392 unary_expression_t *ret = parser_alloc(ctx, sizeof(unary_expression_t));
1394 ret->expr.eval = expression_eval_table[type];
1395 ret->expression = expression;
1400 static expression_t *new_conditional_expression(parser_ctx_t *ctx, expression_t *expression,
1401 expression_t *true_expression, expression_t *false_expression)
1403 conditional_expression_t *ret = parser_alloc(ctx, sizeof(conditional_expression_t));
1405 ret->expr.eval = conditional_expression_eval;
1406 ret->expression = expression;
1407 ret->true_expression = true_expression;
1408 ret->false_expression = false_expression;
1413 static expression_t *new_array_expression(parser_ctx_t *ctx, expression_t *member_expr, expression_t *expression)
1415 array_expression_t *ret = parser_alloc(ctx, sizeof(array_expression_t));
1417 ret->expr.eval = array_expression_eval;
1418 ret->member_expr = member_expr;
1419 ret->expression = expression;
1424 static expression_t *new_member_expression(parser_ctx_t *ctx, expression_t *expression, const WCHAR *identifier)
1426 member_expression_t *ret = parser_alloc(ctx, sizeof(member_expression_t));
1428 ret->expr.eval = member_expression_eval;
1429 ret->expression = expression;
1430 ret->identifier = identifier;
1435 static expression_t *new_new_expression(parser_ctx_t *ctx, expression_t *expression, argument_list_t *argument_list)
1437 call_expression_t *ret = parser_alloc(ctx, sizeof(call_expression_t));
1439 ret->expr.eval = new_expression_eval;
1440 ret->expression = expression;
1441 ret->argument_list = argument_list ? argument_list->head : NULL;
1446 static expression_t *new_call_expression(parser_ctx_t *ctx, expression_t *expression, argument_list_t *argument_list)
1448 call_expression_t *ret = parser_alloc(ctx, sizeof(call_expression_t));
1450 ret->expr.eval = call_expression_eval;
1451 ret->expression = expression;
1452 ret->argument_list = argument_list ? argument_list->head : NULL;
1457 static expression_t *new_this_expression(parser_ctx_t *ctx)
1459 expression_t *ret = parser_alloc(ctx, sizeof(expression_t));
1461 ret->eval = this_expression_eval;
1466 static int parser_error(const char *str)
1471 static void set_error(parser_ctx_t *ctx, UINT error)
1473 ctx->hres = JSCRIPT_ERROR|error;
1476 static BOOL explicit_error(parser_ctx_t *ctx, void *obj, WCHAR next)
1478 if(obj || *(ctx->ptr-1)==next) return TRUE;
1480 set_error(ctx, IDS_SYNTAX_ERROR);
1485 static expression_t *new_identifier_expression(parser_ctx_t *ctx, const WCHAR *identifier)
1487 identifier_expression_t *ret = parser_alloc(ctx, sizeof(identifier_expression_t));
1489 ret->expr.eval = identifier_expression_eval;
1490 ret->identifier = identifier;
1495 static expression_t *new_array_literal_expression(parser_ctx_t *ctx, element_list_t *element_list, int length)
1497 array_literal_expression_t *ret = parser_alloc(ctx, sizeof(array_literal_expression_t));
1499 ret->expr.eval = array_literal_expression_eval;
1500 ret->element_list = element_list ? element_list->head : NULL;
1501 ret->length = length;
1506 static expression_t *new_prop_and_value_expression(parser_ctx_t *ctx, property_list_t *property_list)
1508 property_value_expression_t *ret = parser_alloc(ctx, sizeof(property_value_expression_t));
1510 ret->expr.eval = property_value_expression_eval;
1511 ret->property_list = property_list ? property_list->head : NULL;
1516 static expression_t *new_literal_expression(parser_ctx_t *ctx, literal_t *literal)
1518 literal_expression_t *ret = parser_alloc(ctx, sizeof(literal_expression_t));
1520 ret->expr.eval = literal_expression_eval;
1521 ret->literal = literal;
1526 static source_elements_t *new_source_elements(parser_ctx_t *ctx)
1528 source_elements_t *ret = parser_alloc(ctx, sizeof(source_elements_t));
1530 memset(ret, 0, sizeof(*ret));
1535 static source_elements_t *source_elements_add_statement(source_elements_t *source_elements, statement_t *statement)
1537 if(source_elements->statement_tail)
1538 source_elements->statement_tail = source_elements->statement_tail->next = statement;
1540 source_elements->statement = source_elements->statement_tail = statement;
1542 return source_elements;
1545 static statement_list_t *new_statement_list(parser_ctx_t *ctx, statement_t *statement)
1547 statement_list_t *ret = parser_alloc_tmp(ctx, sizeof(statement_list_t));
1549 ret->head = ret->tail = statement;
1554 static statement_list_t *statement_list_add(statement_list_t *list, statement_t *statement)
1556 list->tail = list->tail->next = statement;
1561 static void push_func(parser_ctx_t *ctx)
1563 func_stack_t *new_func = parser_alloc_tmp(ctx, sizeof(func_stack_t));
1565 new_func->func_head = new_func->func_tail = NULL;
1566 new_func->var_head = new_func->var_tail = NULL;
1568 new_func->next = ctx->func_stack;
1569 ctx->func_stack = new_func;
1572 static source_elements_t *function_body_parsed(parser_ctx_t *ctx, source_elements_t *source)
1574 source->functions = ctx->func_stack->func_head;
1575 source->variables = ctx->func_stack->var_head;
1581 static void program_parsed(parser_ctx_t *ctx, source_elements_t *source)
1583 source->functions = ctx->func_stack->func_head;
1584 source->variables = ctx->func_stack->var_head;
1587 ctx->source = source;
1588 if(!ctx->lexer_error)
1592 void parser_release(parser_ctx_t *ctx)
1597 heap_free(ctx->begin);
1598 jsheap_free(&ctx->heap);
1602 HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimiter,
1605 parser_ctx_t *parser_ctx;
1609 const WCHAR html_tagW[] = {'<','/','s','c','r','i','p','t','>',0};
1611 parser_ctx = heap_alloc_zero(sizeof(parser_ctx_t));
1613 return E_OUTOFMEMORY;
1615 parser_ctx->ref = 1;
1616 parser_ctx->hres = JSCRIPT_ERROR|IDS_SYNTAX_ERROR;
1617 parser_ctx->is_html = delimiter && !strcmpiW(delimiter, html_tagW);
1619 parser_ctx->begin = heap_strdupW(code);
1620 if(!parser_ctx->begin) {
1621 heap_free(parser_ctx);
1622 return E_OUTOFMEMORY;
1625 parser_ctx->ptr = parser_ctx->begin;
1626 parser_ctx->end = parser_ctx->begin + strlenW(parser_ctx->begin);
1629 parser_ctx->script = ctx;
1631 mark = jsheap_mark(&ctx->tmp_heap);
1632 jsheap_init(&parser_ctx->heap);
1634 push_func(parser_ctx);
1636 parser_parse(parser_ctx);
1638 if(FAILED(parser_ctx->hres)) {
1639 hres = parser_ctx->hres;
1640 parser_release(parser_ctx);