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
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
249 %nonassoc LOWER_THAN_ELSE
254 /* ECMA-262 3rd Edition 14 */
256 : SourceElements HtmlComment
257 { program_parsed(ctx, $1); }
263 /* ECMA-262 3rd Edition 14 */
265 : /* empty */ { $$ = new_source_elements(ctx); }
266 | SourceElements Statement
267 { $$ = source_elements_add_statement($1, $2); }
269 /* ECMA-262 3rd Edition 13 */
271 : KFunction Identifier_opt left_bracket FormalParameterList_opt right_bracket '{' FunctionBody '}'
272 { $$ = new_function_expression(ctx, $2, $4, $7, $1, $8-$1+1); }
275 : kFUNCTION { push_func(ctx); $$ = $1; }
277 /* ECMA-262 3rd Edition 13 */
279 : SourceElements { $$ = function_body_parsed(ctx, $1); }
281 /* ECMA-262 3rd Edition 13 */
283 : tIdentifier { $$ = new_parameter_list(ctx, $1); }
284 | FormalParameterList ',' tIdentifier
285 { $$ = parameter_list_add(ctx, $1, $3); }
287 /* ECMA-262 3rd Edition 13 */
288 FormalParameterList_opt
289 : /* empty */ { $$ = NULL; }
290 | FormalParameterList { $$ = $1; }
292 /* ECMA-262 3rd Edition 12 */
295 | VariableStatement { $$ = $1; }
296 | EmptyStatement { $$ = $1; }
297 | ExpressionStatement { $$ = $1; }
298 | IfStatement { $$ = $1; }
299 | IterationStatement { $$ = $1; }
300 | ContinueStatement { $$ = $1; }
301 | BreakStatement { $$ = $1; }
302 | ReturnStatement { $$ = $1; }
303 | WithStatement { $$ = $1; }
304 | LabelledStatement { $$ = $1; }
305 | SwitchStatement { $$ = $1; }
306 | ThrowStatement { $$ = $1; }
307 | TryStatement { $$ = $1; }
309 /* ECMA-262 3rd Edition 12.2 */
311 : Statement { $$ = new_statement_list(ctx, $1); }
312 | StatementList Statement
313 { $$ = statement_list_add($1, $2); }
315 /* ECMA-262 3rd Edition 12.2 */
317 : /* empty */ { $$ = NULL; }
318 | StatementList { $$ = $1; }
320 /* ECMA-262 3rd Edition 12.1 */
322 : '{' StatementList '}' { $$ = new_block_statement(ctx, $2); }
323 | '{' '}' { $$ = new_block_statement(ctx, NULL); }
325 /* ECMA-262 3rd Edition 12.2 */
327 : kVAR VariableDeclarationList semicolon_opt
328 { $$ = new_var_statement(ctx, $2); }
330 /* ECMA-262 3rd Edition 12.2 */
331 VariableDeclarationList
332 : VariableDeclaration { $$ = new_variable_list(ctx, $1); }
333 | VariableDeclarationList ',' VariableDeclaration
334 { $$ = variable_list_add(ctx, $1, $3); }
336 /* ECMA-262 3rd Edition 12.2 */
337 VariableDeclarationListNoIn
338 : VariableDeclarationNoIn
339 { $$ = new_variable_list(ctx, $1); }
340 | VariableDeclarationListNoIn ',' VariableDeclarationNoIn
341 { $$ = variable_list_add(ctx, $1, $3); }
343 /* ECMA-262 3rd Edition 12.2 */
345 : tIdentifier Initialiser_opt
346 { $$ = new_variable_declaration(ctx, $1, $2); }
348 /* ECMA-262 3rd Edition 12.2 */
349 VariableDeclarationNoIn
350 : tIdentifier InitialiserNoIn_opt
351 { $$ = new_variable_declaration(ctx, $1, $2); }
353 /* ECMA-262 3rd Edition 12.2 */
355 : /* empty */ { $$ = NULL; }
356 | Initialiser { $$ = $1; }
358 /* ECMA-262 3rd Edition 12.2 */
360 : '=' AssignmentExpression
363 /* ECMA-262 3rd Edition 12.2 */
365 : /* empty */ { $$ = NULL; }
366 | InitialiserNoIn { $$ = $1; }
368 /* ECMA-262 3rd Edition 12.2 */
370 : '=' AssignmentExpressionNoIn
373 /* ECMA-262 3rd Edition 12.3 */
375 : ';' { $$ = new_empty_statement(ctx); }
377 /* ECMA-262 3rd Edition 12.4 */
379 : Expression semicolon_opt
380 { $$ = new_expression_statement(ctx, $1); }
382 /* ECMA-262 3rd Edition 12.5 */
384 : kIF left_bracket Expression_err right_bracket Statement kELSE Statement
385 { $$ = new_if_statement(ctx, $3, $5, $7); }
386 | kIF left_bracket Expression_err right_bracket Statement %prec LOWER_THAN_ELSE
387 { $$ = new_if_statement(ctx, $3, $5, NULL); }
389 /* ECMA-262 3rd Edition 12.6 */
391 : kDO Statement kWHILE left_bracket Expression_err right_bracket semicolon_opt
392 { $$ = new_while_statement(ctx, TRUE, $5, $2); }
393 | kWHILE left_bracket Expression_err right_bracket Statement
394 { $$ = new_while_statement(ctx, FALSE, $3, $5); }
395 | kFOR left_bracket ExpressionNoIn_opt
396 { if(!explicit_error(ctx, $3, ';')) YYABORT; }
397 semicolon Expression_opt
398 { if(!explicit_error(ctx, $6, ';')) YYABORT; }
399 semicolon Expression_opt right_bracket Statement
400 { $$ = new_for_statement(ctx, NULL, $3, $6, $9, $11); }
401 | kFOR left_bracket kVAR VariableDeclarationListNoIn
402 { if(!explicit_error(ctx, $4, ';')) YYABORT; }
403 semicolon Expression_opt
404 { if(!explicit_error(ctx, $7, ';')) YYABORT; }
405 semicolon Expression_opt right_bracket Statement
406 { $$ = new_for_statement(ctx, $4, NULL, $7, $10, $12); }
407 | kFOR left_bracket LeftHandSideExpression kIN Expression_err right_bracket Statement
408 { $$ = new_forin_statement(ctx, NULL, $3, $5, $7); }
409 | kFOR left_bracket kVAR VariableDeclarationNoIn kIN Expression_err right_bracket Statement
410 { $$ = new_forin_statement(ctx, $4, NULL, $6, $8); }
412 /* ECMA-262 3rd Edition 12.7 */
414 : kCONTINUE /* NONL */ Identifier_opt semicolon_opt
415 { $$ = new_continue_statement(ctx, $2); }
417 /* ECMA-262 3rd Edition 12.8 */
419 : kBREAK /* NONL */ Identifier_opt semicolon_opt
420 { $$ = new_break_statement(ctx, $2); }
422 /* ECMA-262 3rd Edition 12.9 */
424 : kRETURN /* NONL */ Expression_opt semicolon_opt
425 { $$ = new_return_statement(ctx, $2); }
427 /* ECMA-262 3rd Edition 12.10 */
429 : kWITH left_bracket Expression right_bracket Statement
430 { $$ = new_with_statement(ctx, $3, $5); }
432 /* ECMA-262 3rd Edition 12.12 */
434 : tIdentifier ':' Statement
435 { $$ = new_labelled_statement(ctx, $1, $3); }
437 /* ECMA-262 3rd Edition 12.11 */
439 : kSWITCH left_bracket Expression right_bracket CaseBlock
440 { $$ = new_switch_statement(ctx, $3, $5); }
442 /* ECMA-262 3rd Edition 12.11 */
444 : '{' CaseClausules_opt '}'
445 { $$ = new_case_block(ctx, $2, NULL, NULL); }
446 | '{' CaseClausules_opt DefaultClausule CaseClausules_opt '}'
447 { $$ = new_case_block(ctx, $2, $3, $4); }
449 /* ECMA-262 3rd Edition 12.11 */
451 : /* empty */ { $$ = NULL; }
452 | CaseClausules { $$ = $1; }
454 /* ECMA-262 3rd Edition 12.11 */
456 : CaseClausule { $$ = new_case_list(ctx, $1); }
457 | CaseClausules CaseClausule
458 { $$ = case_list_add(ctx, $1, $2); }
460 /* ECMA-262 3rd Edition 12.11 */
462 : kCASE Expression ':' StatementList_opt
463 { $$ = new_case_clausule(ctx, $2, $4); }
465 /* ECMA-262 3rd Edition 12.11 */
467 : kDEFAULT ':' StatementList_opt
468 { $$ = new_case_clausule(ctx, NULL, $3); }
470 /* ECMA-262 3rd Edition 12.13 */
472 : kTHROW /* NONL */ Expression semicolon_opt
473 { $$ = new_throw_statement(ctx, $2); }
475 /* ECMA-262 3rd Edition 12.14 */
477 : kTRY Block Catch { $$ = new_try_statement(ctx, $2, $3, NULL); }
478 | kTRY Block Finally { $$ = new_try_statement(ctx, $2, NULL, $3); }
479 | kTRY Block Catch Finally
480 { $$ = new_try_statement(ctx, $2, $3, $4); }
482 /* ECMA-262 3rd Edition 12.14 */
484 : kCATCH left_bracket tIdentifier right_bracket Block
485 { $$ = new_catch_block(ctx, $3, $5); }
487 /* ECMA-262 3rd Edition 12.14 */
489 : kFINALLY Block { $$ = $2; }
491 /* ECMA-262 3rd Edition 11.14 */
493 : /* empty */ { $$ = NULL; }
494 | Expression { $$ = $1; }
497 : Expression { $$ = $1; }
498 | error { set_error(ctx, IDS_SYNTAX_ERROR); YYABORT; }
500 /* ECMA-262 3rd Edition 11.14 */
502 : AssignmentExpression { $$ = $1; }
503 | Expression ',' AssignmentExpression
504 { $$ = new_binary_expression(ctx, EXPR_COMMA, $1, $3); }
506 /* ECMA-262 3rd Edition 11.14 */
508 : /* empty */ { $$ = NULL; }
509 | ExpressionNoIn { $$ = $1; }
511 /* ECMA-262 3rd Edition 11.14 */
513 : AssignmentExpressionNoIn
515 | ExpressionNoIn ',' AssignmentExpressionNoIn
516 { $$ = new_binary_expression(ctx, EXPR_COMMA, $1, $3); }
518 /* ECMA-262 3rd Edition 11.13 */
520 : ConditionalExpression { $$ = $1; }
521 | LeftHandSideExpression '=' AssignmentExpression
522 { $$ = new_binary_expression(ctx, EXPR_ASSIGN, $1, $3); }
523 | LeftHandSideExpression tAssignOper AssignmentExpression
524 { $$ = new_binary_expression(ctx, $2, $1, $3); }
526 /* ECMA-262 3rd Edition 11.13 */
527 AssignmentExpressionNoIn
528 : ConditionalExpressionNoIn
530 | LeftHandSideExpression '=' AssignmentExpressionNoIn
531 { $$ = new_binary_expression(ctx, EXPR_ASSIGN, $1, $3); }
532 | LeftHandSideExpression tAssignOper AssignmentExpressionNoIn
533 { $$ = new_binary_expression(ctx, $2, $1, $3); }
535 /* ECMA-262 3rd Edition 11.12 */
536 ConditionalExpression
537 : LogicalORExpression { $$ = $1; }
538 | LogicalORExpression '?' AssignmentExpression ':' AssignmentExpression
539 { $$ = new_conditional_expression(ctx, $1, $3, $5); }
541 /* ECMA-262 3rd Edition 11.12 */
542 ConditionalExpressionNoIn
543 : LogicalORExpressionNoIn
545 | LogicalORExpressionNoIn '?' AssignmentExpressionNoIn ':' AssignmentExpressionNoIn
546 { $$ = new_conditional_expression(ctx, $1, $3, $5); }
548 /* ECMA-262 3rd Edition 11.11 */
550 : LogicalANDExpression { $$ = $1; }
551 | LogicalORExpression tOROR LogicalANDExpression
552 { $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); }
554 /* ECMA-262 3rd Edition 11.11 */
555 LogicalORExpressionNoIn
556 : LogicalANDExpressionNoIn
558 | LogicalORExpressionNoIn tOROR LogicalANDExpressionNoIn
559 { $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); }
561 /* ECMA-262 3rd Edition 11.11 */
563 : BitwiseORExpression { $$ = $1; }
564 | LogicalANDExpression tANDAND BitwiseORExpression
565 { $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); }
567 /* ECMA-262 3rd Edition 11.11 */
568 LogicalANDExpressionNoIn
569 : BitwiseORExpressionNoIn
571 | LogicalANDExpressionNoIn tANDAND BitwiseORExpressionNoIn
572 { $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); }
574 /* ECMA-262 3rd Edition 11.10 */
576 : BitwiseXORExpression { $$ = $1; }
577 | BitwiseORExpression '|' BitwiseXORExpression
578 { $$ = new_binary_expression(ctx, EXPR_BOR, $1, $3); }
580 /* ECMA-262 3rd Edition 11.10 */
581 BitwiseORExpressionNoIn
582 : BitwiseXORExpressionNoIn
584 | BitwiseORExpressionNoIn '|' BitwiseXORExpressionNoIn
585 { $$ = new_binary_expression(ctx, EXPR_BOR, $1, $3); }
587 /* ECMA-262 3rd Edition 11.10 */
589 : BitwiseANDExpression { $$ = $1; }
590 | BitwiseXORExpression '^' BitwiseANDExpression
591 { $$ = new_binary_expression(ctx, EXPR_BXOR, $1, $3); }
593 /* ECMA-262 3rd Edition 11.10 */
594 BitwiseXORExpressionNoIn
595 : BitwiseANDExpressionNoIn
597 | BitwiseXORExpressionNoIn '^' BitwiseANDExpressionNoIn
598 { $$ = new_binary_expression(ctx, EXPR_BXOR, $1, $3); }
600 /* ECMA-262 3rd Edition 11.10 */
602 : EqualityExpression { $$ = $1; }
603 | BitwiseANDExpression '&' EqualityExpression
604 { $$ = new_binary_expression(ctx, EXPR_BAND, $1, $3); }
606 /* ECMA-262 3rd Edition 11.10 */
607 BitwiseANDExpressionNoIn
608 : EqualityExpressionNoIn
610 | BitwiseANDExpressionNoIn '&' EqualityExpressionNoIn
611 { $$ = new_binary_expression(ctx, EXPR_BAND, $1, $3); }
613 /* ECMA-262 3rd Edition 11.9 */
615 : RelationalExpression { $$ = $1; }
616 | EqualityExpression tEqOper RelationalExpression
617 { $$ = new_binary_expression(ctx, $2, $1, $3); }
619 /* ECMA-262 3rd Edition 11.9 */
620 EqualityExpressionNoIn
621 : RelationalExpressionNoIn { $$ = $1; }
622 | EqualityExpressionNoIn tEqOper RelationalExpressionNoIn
623 { $$ = new_binary_expression(ctx, $2, $1, $3); }
625 /* ECMA-262 3rd Edition 11.8 */
627 : ShiftExpression { $$ = $1; }
628 | RelationalExpression tRelOper ShiftExpression
629 { $$ = new_binary_expression(ctx, $2, $1, $3); }
630 | RelationalExpression kINSTANCEOF ShiftExpression
631 { $$ = new_binary_expression(ctx, EXPR_INSTANCEOF, $1, $3); }
632 | RelationalExpression kIN ShiftExpression
633 { $$ = new_binary_expression(ctx, EXPR_IN, $1, $3); }
635 /* ECMA-262 3rd Edition 11.8 */
636 RelationalExpressionNoIn
637 : ShiftExpression { $$ = $1; }
638 | RelationalExpressionNoIn tRelOper ShiftExpression
639 { $$ = new_binary_expression(ctx, $2, $1, $3); }
640 | RelationalExpressionNoIn kINSTANCEOF ShiftExpression
641 { $$ = new_binary_expression(ctx, EXPR_INSTANCEOF, $1, $3); }
643 /* ECMA-262 3rd Edition 11.7 */
645 : AdditiveExpression { $$ = $1; }
646 | ShiftExpression tShiftOper AdditiveExpression
647 { $$ = new_binary_expression(ctx, $2, $1, $3); }
649 /* ECMA-262 3rd Edition 11.6 */
651 : MultiplicativeExpression
653 | AdditiveExpression '+' MultiplicativeExpression
654 { $$ = new_binary_expression(ctx, EXPR_ADD, $1, $3); }
655 | AdditiveExpression '-' MultiplicativeExpression
656 { $$ = new_binary_expression(ctx, EXPR_SUB, $1, $3); }
658 /* ECMA-262 3rd Edition 11.5 */
659 MultiplicativeExpression
660 : UnaryExpression { $$ = $1; }
661 | MultiplicativeExpression '*' UnaryExpression
662 { $$ = new_binary_expression(ctx, EXPR_MUL, $1, $3); }
663 | MultiplicativeExpression '/' UnaryExpression
664 { $$ = new_binary_expression(ctx, EXPR_DIV, $1, $3); }
665 | MultiplicativeExpression '%' UnaryExpression
666 { $$ = new_binary_expression(ctx, EXPR_MOD, $1, $3); }
668 /* ECMA-262 3rd Edition 11.4 */
670 : PostfixExpression { $$ = $1; }
671 | kDELETE UnaryExpression
672 { $$ = new_unary_expression(ctx, EXPR_DELETE, $2); }
673 | kVOID UnaryExpression { $$ = new_unary_expression(ctx, EXPR_VOID, $2); }
674 | kTYPEOF UnaryExpression
675 { $$ = new_unary_expression(ctx, EXPR_TYPEOF, $2); }
676 | tINC UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PREINC, $2); }
677 | tDEC UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PREDEC, $2); }
678 | '+' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PLUS, $2); }
679 | '-' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_MINUS, $2); }
680 | '~' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_BITNEG, $2); }
681 | '!' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_LOGNEG, $2); }
683 /* ECMA-262 3rd Edition 11.2 */
685 : LeftHandSideExpression
687 | LeftHandSideExpression /* NONL */ tINC
688 { $$ = new_unary_expression(ctx, EXPR_POSTINC, $1); }
689 | LeftHandSideExpression /* NONL */ tDEC
690 { $$ = new_unary_expression(ctx, EXPR_POSTDEC, $1); }
693 /* ECMA-262 3rd Edition 11.2 */
694 LeftHandSideExpression
695 : NewExpression { $$ = $1; }
696 | CallExpression { $$ = $1; }
698 /* ECMA-262 3rd Edition 11.2 */
700 : MemberExpression { $$ = $1; }
701 | kNEW NewExpression { $$ = new_new_expression(ctx, $2, NULL); }
703 /* ECMA-262 3rd Edition 11.2 */
705 : PrimaryExpression { $$ = $1; }
706 | FunctionExpression { $$ = $1; }
707 | MemberExpression '[' Expression ']'
708 { $$ = new_array_expression(ctx, $1, $3); }
709 | MemberExpression '.' tIdentifier
710 { $$ = new_member_expression(ctx, $1, $3); }
711 | kNEW MemberExpression Arguments
712 { $$ = new_new_expression(ctx, $2, $3); }
714 /* ECMA-262 3rd Edition 11.2 */
716 : MemberExpression Arguments
717 { $$ = new_call_expression(ctx, $1, $2); }
718 | CallExpression Arguments
719 { $$ = new_call_expression(ctx, $1, $2); }
720 | CallExpression '[' Expression ']'
721 { $$ = new_array_expression(ctx, $1, $3); }
722 | CallExpression '.' tIdentifier
723 { $$ = new_member_expression(ctx, $1, $3); }
725 /* ECMA-262 3rd Edition 11.2 */
727 : '(' ')' { $$ = NULL; }
728 | '(' ArgumentList ')' { $$ = $2; }
730 /* ECMA-262 3rd Edition 11.2 */
732 : AssignmentExpression { $$ = new_argument_list(ctx, $1); }
733 | ArgumentList ',' AssignmentExpression
734 { $$ = argument_list_add(ctx, $1, $3); }
736 /* ECMA-262 3rd Edition 11.1 */
738 : kTHIS { $$ = new_this_expression(ctx); }
739 | tIdentifier { $$ = new_identifier_expression(ctx, $1); }
740 | Literal { $$ = new_literal_expression(ctx, $1); }
741 | ArrayLiteral { $$ = $1; }
742 | ObjectLiteral { $$ = $1; }
743 | '(' Expression ')' { $$ = $2; }
745 /* ECMA-262 3rd Edition 11.1.4 */
747 : '[' ']' { $$ = new_array_literal_expression(ctx, NULL, 0); }
748 | '[' Elision ']' { $$ = new_array_literal_expression(ctx, NULL, $2+1); }
749 | '[' ElementList ']' { $$ = new_array_literal_expression(ctx, $2, 0); }
750 | '[' ElementList ',' Elision_opt ']'
751 { $$ = new_array_literal_expression(ctx, $2, $4+1); }
753 /* ECMA-262 3rd Edition 11.1.4 */
755 : Elision_opt AssignmentExpression
756 { $$ = new_element_list(ctx, $1, $2); }
757 | ElementList ',' Elision_opt AssignmentExpression
758 { $$ = element_list_add(ctx, $1, $3, $4); }
760 /* ECMA-262 3rd Edition 11.1.4 */
763 | Elision ',' { $$ = $1 + 1; }
765 /* ECMA-262 3rd Edition 11.1.4 */
767 : /* empty */ { $$ = 0; }
768 | Elision { $$ = $1; }
770 /* ECMA-262 3rd Edition 11.1.5 */
772 : '{' '}' { $$ = new_prop_and_value_expression(ctx, NULL); }
773 | '{' PropertyNameAndValueList '}'
774 { $$ = new_prop_and_value_expression(ctx, $2); }
776 /* ECMA-262 3rd Edition 11.1.5 */
777 PropertyNameAndValueList
778 : PropertyName ':' AssignmentExpression
779 { $$ = new_property_list(ctx, $1, $3); }
780 | PropertyNameAndValueList ',' PropertyName ':' AssignmentExpression
781 { $$ = property_list_add(ctx, $1, $3, $5); }
783 /* ECMA-262 3rd Edition 11.1.5 */
785 : tIdentifier { $$ = new_string_literal(ctx, $1); }
786 | tStringLiteral { $$ = new_string_literal(ctx, $1); }
787 | tNumericLiteral { $$ = $1; }
789 /* ECMA-262 3rd Edition 7.6 */
791 : /* empty*/ { $$ = NULL; }
792 | tIdentifier { $$ = $1; }
794 /* ECMA-262 3rd Edition 7.8 */
796 : kNULL { $$ = new_null_literal(ctx); }
797 | kUNDEFINED { $$ = new_undefined_literal(ctx); }
798 | BooleanLiteral { $$ = $1; }
799 | tNumericLiteral { $$ = $1; }
800 | tStringLiteral { $$ = new_string_literal(ctx, $1); }
801 | '/' { $$ = parse_regexp(ctx);
804 /* ECMA-262 3rd Edition 7.8.2 */
806 : kTRUE { $$ = new_boolean_literal(ctx, TRUE); }
807 | kFALSE { $$ = new_boolean_literal(ctx, FALSE); }
811 | error { if(!allow_auto_semicolon(ctx)) {YYABORT;} }
815 | error { set_error(ctx, IDS_LBRACKET); YYABORT; }
819 | error { set_error(ctx, IDS_RBRACKET); YYABORT; }
823 | error { set_error(ctx, IDS_SEMICOLON); YYABORT; }
827 static BOOL allow_auto_semicolon(parser_ctx_t *ctx)
829 return ctx->nl || ctx->ptr == ctx->end || *(ctx->ptr-1) == '}';
832 static literal_t *new_string_literal(parser_ctx_t *ctx, const WCHAR *str)
834 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
842 static literal_t *new_null_literal(parser_ctx_t *ctx)
844 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
851 static literal_t *new_undefined_literal(parser_ctx_t *ctx)
853 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
860 static literal_t *new_boolean_literal(parser_ctx_t *ctx, VARIANT_BOOL bval)
862 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
870 static prop_val_t *new_prop_val(parser_ctx_t *ctx, literal_t *name, expression_t *value)
872 prop_val_t *ret = parser_alloc(ctx, sizeof(prop_val_t));
881 static property_list_t *new_property_list(parser_ctx_t *ctx, literal_t *name, expression_t *value)
883 property_list_t *ret = parser_alloc_tmp(ctx, sizeof(property_list_t));
885 ret->head = ret->tail = new_prop_val(ctx, name, value);
890 static property_list_t *property_list_add(parser_ctx_t *ctx, property_list_t *list, literal_t *name, expression_t *value)
892 list->tail = list->tail->next = new_prop_val(ctx, name, value);
897 static array_element_t *new_array_element(parser_ctx_t *ctx, int elision, expression_t *expr)
899 array_element_t *ret = parser_alloc(ctx, sizeof(array_element_t));
901 ret->elision = elision;
908 static element_list_t *new_element_list(parser_ctx_t *ctx, int elision, expression_t *expr)
910 element_list_t *ret = parser_alloc_tmp(ctx, sizeof(element_list_t));
912 ret->head = ret->tail = new_array_element(ctx, elision, expr);
917 static element_list_t *element_list_add(parser_ctx_t *ctx, element_list_t *list, int elision, expression_t *expr)
919 list->tail = list->tail->next = new_array_element(ctx, elision, expr);
924 static argument_t *new_argument(parser_ctx_t *ctx, expression_t *expr)
926 argument_t *ret = parser_alloc(ctx, sizeof(argument_t));
934 static argument_list_t *new_argument_list(parser_ctx_t *ctx, expression_t *expr)
936 argument_list_t *ret = parser_alloc_tmp(ctx, sizeof(argument_list_t));
938 ret->head = ret->tail = new_argument(ctx, expr);
943 static argument_list_t *argument_list_add(parser_ctx_t *ctx, argument_list_t *list, expression_t *expr)
945 list->tail = list->tail->next = new_argument(ctx, expr);
950 static catch_block_t *new_catch_block(parser_ctx_t *ctx, const WCHAR *identifier, statement_t *statement)
952 catch_block_t *ret = parser_alloc(ctx, sizeof(catch_block_t));
954 ret->identifier = identifier;
955 ret->statement = statement;
960 static case_clausule_t *new_case_clausule(parser_ctx_t *ctx, expression_t *expr, statement_list_t *stat_list)
962 case_clausule_t *ret = parser_alloc(ctx, sizeof(case_clausule_t));
965 ret->stat = stat_list ? stat_list->head : NULL;
971 static case_list_t *new_case_list(parser_ctx_t *ctx, case_clausule_t *case_clausule)
973 case_list_t *ret = parser_alloc_tmp(ctx, sizeof(case_list_t));
975 ret->head = ret->tail = case_clausule;
980 static case_list_t *case_list_add(parser_ctx_t *ctx, case_list_t *list, case_clausule_t *case_clausule)
982 list->tail = list->tail->next = case_clausule;
987 static case_clausule_t *new_case_block(parser_ctx_t *ctx, case_list_t *case_list1,
988 case_clausule_t *default_clausule, case_list_t *case_list2)
990 case_clausule_t *ret = NULL, *iter = NULL, *iter2;
991 statement_t *stat = NULL;
994 ret = case_list1->head;
995 iter = case_list1->tail;
998 if(default_clausule) {
1000 iter = iter->next = default_clausule;
1002 ret = iter = default_clausule;
1007 iter->next = case_list2->head;
1009 ret = case_list2->head;
1015 for(iter = ret; iter; iter = iter->next) {
1016 for(iter2 = iter; iter2 && !iter2->stat; iter2 = iter2->next);
1020 while(iter != iter2) {
1021 iter->stat = iter2->stat;
1028 stat->next = iter->stat;
1037 static statement_t *new_block_statement(parser_ctx_t *ctx, statement_list_t *list)
1039 block_statement_t *ret = parser_alloc(ctx, sizeof(block_statement_t));
1041 ret->stat.eval = block_statement_eval;
1042 ret->stat.next = NULL;
1043 ret->stat_list = list ? list->head : NULL;
1048 static variable_declaration_t *new_variable_declaration(parser_ctx_t *ctx, const WCHAR *identifier, expression_t *expr)
1050 variable_declaration_t *ret = parser_alloc(ctx, sizeof(variable_declaration_t));
1051 var_list_t *var_list = parser_alloc(ctx, sizeof(var_list_t));
1053 ret->identifier = identifier;
1057 var_list->identifier = identifier;
1058 var_list->next = NULL;
1060 if(ctx->func_stack->var_tail)
1061 ctx->func_stack->var_tail = ctx->func_stack->var_tail->next = var_list;
1063 ctx->func_stack->var_head = ctx->func_stack->var_tail = var_list;
1068 static variable_list_t *new_variable_list(parser_ctx_t *ctx, variable_declaration_t *decl)
1070 variable_list_t *ret = parser_alloc_tmp(ctx, sizeof(variable_list_t));
1072 ret->head = ret->tail = decl;
1077 static variable_list_t *variable_list_add(parser_ctx_t *ctx, variable_list_t *list, variable_declaration_t *decl)
1079 list->tail = list->tail->next = decl;
1084 static statement_t *new_var_statement(parser_ctx_t *ctx, variable_list_t *variable_list)
1086 var_statement_t *ret = parser_alloc(ctx, sizeof(var_statement_t));
1088 ret->stat.eval = var_statement_eval;
1089 ret->stat.next = NULL;
1090 ret->variable_list = variable_list->head;
1095 static statement_t *new_empty_statement(parser_ctx_t *ctx)
1097 statement_t *ret = parser_alloc(ctx, sizeof(statement_t));
1099 ret->eval = empty_statement_eval;
1105 static statement_t *new_expression_statement(parser_ctx_t *ctx, expression_t *expr)
1107 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1109 ret->stat.eval = expression_statement_eval;
1110 ret->stat.next = NULL;
1116 static statement_t *new_if_statement(parser_ctx_t *ctx, expression_t *expr, statement_t *if_stat, statement_t *else_stat)
1118 if_statement_t *ret = parser_alloc(ctx, sizeof(if_statement_t));
1120 ret->stat.eval = if_statement_eval;
1121 ret->stat.next = NULL;
1123 ret->if_stat = if_stat;
1124 ret->else_stat = else_stat;
1129 static statement_t *new_while_statement(parser_ctx_t *ctx, BOOL dowhile, expression_t *expr, statement_t *stat)
1131 while_statement_t *ret = parser_alloc(ctx, sizeof(while_statement_t));
1133 ret->stat.eval = while_statement_eval;
1134 ret->stat.next = NULL;
1135 ret->do_while = dowhile;
1137 ret->statement = stat;
1142 static statement_t *new_for_statement(parser_ctx_t *ctx, variable_list_t *variable_list, expression_t *begin_expr,
1143 expression_t *expr, expression_t *end_expr, statement_t *statement)
1145 for_statement_t *ret = parser_alloc(ctx, sizeof(for_statement_t));
1147 ret->stat.eval = for_statement_eval;
1148 ret->stat.next = NULL;
1149 ret->variable_list = variable_list ? variable_list->head : NULL;
1150 ret->begin_expr = begin_expr;
1152 ret->end_expr = end_expr;
1153 ret->statement = statement;
1158 static statement_t *new_forin_statement(parser_ctx_t *ctx, variable_declaration_t *variable, expression_t *expr,
1159 expression_t *in_expr, statement_t *statement)
1161 forin_statement_t *ret = parser_alloc(ctx, sizeof(forin_statement_t));
1163 ret->stat.eval = forin_statement_eval;
1164 ret->stat.next = NULL;
1165 ret->variable = variable;
1167 ret->in_expr = in_expr;
1168 ret->statement = statement;
1173 static statement_t *new_continue_statement(parser_ctx_t *ctx, const WCHAR *identifier)
1175 branch_statement_t *ret = parser_alloc(ctx, sizeof(branch_statement_t));
1177 ret->stat.eval = continue_statement_eval;
1178 ret->stat.next = NULL;
1179 ret->identifier = identifier;
1184 static statement_t *new_break_statement(parser_ctx_t *ctx, const WCHAR *identifier)
1186 branch_statement_t *ret = parser_alloc(ctx, sizeof(branch_statement_t));
1188 ret->stat.eval = break_statement_eval;
1189 ret->stat.next = NULL;
1190 ret->identifier = identifier;
1195 static statement_t *new_return_statement(parser_ctx_t *ctx, expression_t *expr)
1197 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1199 ret->stat.eval = return_statement_eval;
1200 ret->stat.next = NULL;
1206 static statement_t *new_with_statement(parser_ctx_t *ctx, expression_t *expr, statement_t *statement)
1208 with_statement_t *ret = parser_alloc(ctx, sizeof(with_statement_t));
1210 ret->stat.eval = with_statement_eval;
1211 ret->stat.next = NULL;
1213 ret->statement = statement;
1218 static statement_t *new_labelled_statement(parser_ctx_t *ctx, const WCHAR *identifier, statement_t *statement)
1220 labelled_statement_t *ret = parser_alloc(ctx, sizeof(labelled_statement_t));
1222 ret->stat.eval = labelled_statement_eval;
1223 ret->stat.next = NULL;
1224 ret->identifier = identifier;
1225 ret->statement = statement;
1230 static statement_t *new_switch_statement(parser_ctx_t *ctx, expression_t *expr, case_clausule_t *case_list)
1232 switch_statement_t *ret = parser_alloc(ctx, sizeof(switch_statement_t));
1234 ret->stat.eval = switch_statement_eval;
1235 ret->stat.next = NULL;
1237 ret->case_list = case_list;
1242 static statement_t *new_throw_statement(parser_ctx_t *ctx, expression_t *expr)
1244 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1246 ret->stat.eval = throw_statement_eval;
1247 ret->stat.next = NULL;
1253 static statement_t *new_try_statement(parser_ctx_t *ctx, statement_t *try_statement,
1254 catch_block_t *catch_block, statement_t *finally_statement)
1256 try_statement_t *ret = parser_alloc(ctx, sizeof(try_statement_t));
1258 ret->stat.eval = try_statement_eval;
1259 ret->stat.next = NULL;
1260 ret->try_statement = try_statement;
1261 ret->catch_block = catch_block;
1262 ret->finally_statement = finally_statement;
1267 static parameter_t *new_parameter(parser_ctx_t *ctx, const WCHAR *identifier)
1269 parameter_t *ret = parser_alloc(ctx, sizeof(parameter_t));
1271 ret->identifier = identifier;
1277 static parameter_list_t *new_parameter_list(parser_ctx_t *ctx, const WCHAR *identifier)
1279 parameter_list_t *ret = parser_alloc_tmp(ctx, sizeof(parameter_list_t));
1281 ret->head = ret->tail = new_parameter(ctx, identifier);
1286 static parameter_list_t *parameter_list_add(parser_ctx_t *ctx, parameter_list_t *list, const WCHAR *identifier)
1288 list->tail = list->tail->next = new_parameter(ctx, identifier);
1293 static expression_t *new_function_expression(parser_ctx_t *ctx, const WCHAR *identifier,
1294 parameter_list_t *parameter_list, source_elements_t *source_elements, const WCHAR *src_str, DWORD src_len)
1296 function_expression_t *ret = parser_alloc(ctx, sizeof(function_expression_t));
1298 ret->expr.eval = function_expression_eval;
1299 ret->identifier = identifier;
1300 ret->parameter_list = parameter_list ? parameter_list->head : NULL;
1301 ret->source_elements = source_elements;
1302 ret->src_str = src_str;
1303 ret->src_len = src_len;
1305 if(ret->identifier) {
1306 function_declaration_t *decl = parser_alloc(ctx, sizeof(function_declaration_t));
1311 if(ctx->func_stack->func_tail)
1312 ctx->func_stack->func_tail = ctx->func_stack->func_tail->next = decl;
1314 ctx->func_stack->func_head = ctx->func_stack->func_tail = decl;
1320 static const expression_eval_t expression_eval_table[] = {
1321 comma_expression_eval,
1322 logical_or_expression_eval,
1323 logical_and_expression_eval,
1324 binary_or_expression_eval,
1325 binary_xor_expression_eval,
1326 binary_and_expression_eval,
1327 instanceof_expression_eval,
1329 add_expression_eval,
1330 sub_expression_eval,
1331 mul_expression_eval,
1332 div_expression_eval,
1333 mod_expression_eval,
1334 delete_expression_eval,
1335 void_expression_eval,
1336 typeof_expression_eval,
1337 minus_expression_eval,
1338 plus_expression_eval,
1339 post_increment_expression_eval,
1340 post_decrement_expression_eval,
1341 pre_increment_expression_eval,
1342 pre_decrement_expression_eval,
1343 equal_expression_eval,
1344 equal2_expression_eval,
1345 not_equal_expression_eval,
1346 not_equal2_expression_eval,
1347 less_expression_eval,
1348 lesseq_expression_eval,
1349 greater_expression_eval,
1350 greatereq_expression_eval,
1351 binary_negation_expression_eval,
1352 logical_negation_expression_eval,
1353 left_shift_expression_eval,
1354 right_shift_expression_eval,
1355 right2_shift_expression_eval,
1356 assign_expression_eval,
1357 assign_lshift_expression_eval,
1358 assign_rshift_expression_eval,
1359 assign_rrshift_expression_eval,
1360 assign_add_expression_eval,
1361 assign_sub_expression_eval,
1362 assign_mul_expression_eval,
1363 assign_div_expression_eval,
1364 assign_mod_expression_eval,
1365 assign_and_expression_eval,
1366 assign_or_expression_eval,
1367 assign_xor_expression_eval,
1370 static expression_t *new_binary_expression(parser_ctx_t *ctx, expression_type_t type,
1371 expression_t *expression1, expression_t *expression2)
1373 binary_expression_t *ret = parser_alloc(ctx, sizeof(binary_expression_t));
1375 ret->expr.eval = expression_eval_table[type];
1376 ret->expression1 = expression1;
1377 ret->expression2 = expression2;
1382 static expression_t *new_unary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *expression)
1384 unary_expression_t *ret = parser_alloc(ctx, sizeof(unary_expression_t));
1386 ret->expr.eval = expression_eval_table[type];
1387 ret->expression = expression;
1392 static expression_t *new_conditional_expression(parser_ctx_t *ctx, expression_t *expression,
1393 expression_t *true_expression, expression_t *false_expression)
1395 conditional_expression_t *ret = parser_alloc(ctx, sizeof(conditional_expression_t));
1397 ret->expr.eval = conditional_expression_eval;
1398 ret->expression = expression;
1399 ret->true_expression = true_expression;
1400 ret->false_expression = false_expression;
1405 static expression_t *new_array_expression(parser_ctx_t *ctx, expression_t *member_expr, expression_t *expression)
1407 array_expression_t *ret = parser_alloc(ctx, sizeof(array_expression_t));
1409 ret->expr.eval = array_expression_eval;
1410 ret->member_expr = member_expr;
1411 ret->expression = expression;
1416 static expression_t *new_member_expression(parser_ctx_t *ctx, expression_t *expression, const WCHAR *identifier)
1418 member_expression_t *ret = parser_alloc(ctx, sizeof(member_expression_t));
1420 ret->expr.eval = member_expression_eval;
1421 ret->expression = expression;
1422 ret->identifier = identifier;
1427 static expression_t *new_new_expression(parser_ctx_t *ctx, expression_t *expression, argument_list_t *argument_list)
1429 call_expression_t *ret = parser_alloc(ctx, sizeof(call_expression_t));
1431 ret->expr.eval = new_expression_eval;
1432 ret->expression = expression;
1433 ret->argument_list = argument_list ? argument_list->head : NULL;
1438 static expression_t *new_call_expression(parser_ctx_t *ctx, expression_t *expression, argument_list_t *argument_list)
1440 call_expression_t *ret = parser_alloc(ctx, sizeof(call_expression_t));
1442 ret->expr.eval = call_expression_eval;
1443 ret->expression = expression;
1444 ret->argument_list = argument_list ? argument_list->head : NULL;
1449 static expression_t *new_this_expression(parser_ctx_t *ctx)
1451 expression_t *ret = parser_alloc(ctx, sizeof(expression_t));
1453 ret->eval = this_expression_eval;
1458 static int parser_error(const char *str)
1463 static void set_error(parser_ctx_t *ctx, UINT error)
1465 ctx->hres = JSCRIPT_ERROR|error;
1468 static BOOL explicit_error(parser_ctx_t *ctx, void *obj, WCHAR next)
1470 if(obj || *(ctx->ptr-1)==next) return TRUE;
1472 set_error(ctx, IDS_SYNTAX_ERROR);
1477 static expression_t *new_identifier_expression(parser_ctx_t *ctx, const WCHAR *identifier)
1479 identifier_expression_t *ret = parser_alloc(ctx, sizeof(identifier_expression_t));
1481 ret->expr.eval = identifier_expression_eval;
1482 ret->identifier = identifier;
1487 static expression_t *new_array_literal_expression(parser_ctx_t *ctx, element_list_t *element_list, int length)
1489 array_literal_expression_t *ret = parser_alloc(ctx, sizeof(array_literal_expression_t));
1491 ret->expr.eval = array_literal_expression_eval;
1492 ret->element_list = element_list ? element_list->head : NULL;
1493 ret->length = length;
1498 static expression_t *new_prop_and_value_expression(parser_ctx_t *ctx, property_list_t *property_list)
1500 property_value_expression_t *ret = parser_alloc(ctx, sizeof(property_value_expression_t));
1502 ret->expr.eval = property_value_expression_eval;
1503 ret->property_list = property_list ? property_list->head : NULL;
1508 static expression_t *new_literal_expression(parser_ctx_t *ctx, literal_t *literal)
1510 literal_expression_t *ret = parser_alloc(ctx, sizeof(literal_expression_t));
1512 ret->expr.eval = literal_expression_eval;
1513 ret->literal = literal;
1518 static source_elements_t *new_source_elements(parser_ctx_t *ctx)
1520 source_elements_t *ret = parser_alloc(ctx, sizeof(source_elements_t));
1522 memset(ret, 0, sizeof(*ret));
1527 static source_elements_t *source_elements_add_statement(source_elements_t *source_elements, statement_t *statement)
1529 if(source_elements->statement_tail)
1530 source_elements->statement_tail = source_elements->statement_tail->next = statement;
1532 source_elements->statement = source_elements->statement_tail = statement;
1534 return source_elements;
1537 static statement_list_t *new_statement_list(parser_ctx_t *ctx, statement_t *statement)
1539 statement_list_t *ret = parser_alloc_tmp(ctx, sizeof(statement_list_t));
1541 ret->head = ret->tail = statement;
1546 static statement_list_t *statement_list_add(statement_list_t *list, statement_t *statement)
1548 list->tail = list->tail->next = statement;
1553 static void push_func(parser_ctx_t *ctx)
1555 func_stack_t *new_func = parser_alloc_tmp(ctx, sizeof(func_stack_t));
1557 new_func->func_head = new_func->func_tail = NULL;
1558 new_func->var_head = new_func->var_tail = NULL;
1560 new_func->next = ctx->func_stack;
1561 ctx->func_stack = new_func;
1564 static source_elements_t *function_body_parsed(parser_ctx_t *ctx, source_elements_t *source)
1566 source->functions = ctx->func_stack->func_head;
1567 source->variables = ctx->func_stack->var_head;
1573 static void program_parsed(parser_ctx_t *ctx, source_elements_t *source)
1575 source->functions = ctx->func_stack->func_head;
1576 source->variables = ctx->func_stack->var_head;
1579 ctx->source = source;
1580 if(!ctx->lexer_error)
1584 void parser_release(parser_ctx_t *ctx)
1586 obj_literal_t *iter;
1591 for(iter = ctx->obj_literals; iter; iter = iter->next)
1592 jsdisp_release(iter->obj);
1594 jsheap_free(&ctx->heap);
1598 HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimiter,
1601 parser_ctx_t *parser_ctx;
1605 const WCHAR html_tagW[] = {'<','/','s','c','r','i','p','t','>',0};
1607 parser_ctx = heap_alloc_zero(sizeof(parser_ctx_t));
1609 return E_OUTOFMEMORY;
1611 parser_ctx->ref = 1;
1612 parser_ctx->hres = JSCRIPT_ERROR|IDS_SYNTAX_ERROR;
1613 parser_ctx->is_html = delimiter && !strcmpiW(delimiter, html_tagW);
1615 parser_ctx->begin = parser_ctx->ptr = code;
1616 parser_ctx->end = code + strlenW(code);
1619 parser_ctx->script = ctx;
1621 mark = jsheap_mark(&ctx->tmp_heap);
1622 jsheap_init(&parser_ctx->heap);
1624 push_func(parser_ctx);
1626 parser_parse(parser_ctx);
1628 if(FAILED(parser_ctx->hres)) {
1629 hres = parser_ctx->hres;
1630 parser_release(parser_ctx);