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 BOOL allow_auto_semicolon(parser_ctx_t*);
29 static void program_parsed(parser_ctx_t*,source_elements_t*);
30 static source_elements_t *function_body_parsed(parser_ctx_t*,source_elements_t*);
32 typedef struct _statement_list_t {
37 static literal_t *new_string_literal(parser_ctx_t*,const WCHAR*);
38 static literal_t *new_null_literal(parser_ctx_t*);
39 static literal_t *new_undefined_literal(parser_ctx_t*);
40 static literal_t *new_boolean_literal(parser_ctx_t*,VARIANT_BOOL);
42 typedef struct _property_list_t {
47 static property_list_t *new_property_list(parser_ctx_t*,literal_t*,expression_t*);
48 static property_list_t *property_list_add(parser_ctx_t*,property_list_t*,literal_t*,expression_t*);
50 typedef struct _element_list_t {
51 array_element_t *head;
52 array_element_t *tail;
55 static element_list_t *new_element_list(parser_ctx_t*,int,expression_t*);
56 static element_list_t *element_list_add(parser_ctx_t*,element_list_t*,int,expression_t*);
58 typedef struct _argument_list_t {
63 static argument_list_t *new_argument_list(parser_ctx_t*,expression_t*);
64 static argument_list_t *argument_list_add(parser_ctx_t*,argument_list_t*,expression_t*);
66 typedef struct _case_list_t {
67 case_clausule_t *head;
68 case_clausule_t *tail;
71 static catch_block_t *new_catch_block(parser_ctx_t*,const WCHAR*,statement_t*);
72 static case_clausule_t *new_case_clausule(parser_ctx_t*,expression_t*,statement_list_t*);
73 static case_list_t *new_case_list(parser_ctx_t*,case_clausule_t*);
74 static case_list_t *case_list_add(parser_ctx_t*,case_list_t*,case_clausule_t*);
75 static case_clausule_t *new_case_block(parser_ctx_t*,case_list_t*,case_clausule_t*,case_list_t*);
77 typedef struct _variable_list_t {
78 variable_declaration_t *head;
79 variable_declaration_t *tail;
82 static variable_declaration_t *new_variable_declaration(parser_ctx_t*,const WCHAR*,expression_t*);
83 static variable_list_t *new_variable_list(parser_ctx_t*,variable_declaration_t*);
84 static variable_list_t *variable_list_add(parser_ctx_t*,variable_list_t*,variable_declaration_t*);
86 static statement_t *new_block_statement(parser_ctx_t*,statement_list_t*);
87 static statement_t *new_var_statement(parser_ctx_t*,variable_list_t*);
88 static statement_t *new_empty_statement(parser_ctx_t*);
89 static statement_t *new_expression_statement(parser_ctx_t*,expression_t*);
90 static statement_t *new_if_statement(parser_ctx_t*,expression_t*,statement_t*,statement_t*);
91 static statement_t *new_while_statement(parser_ctx_t*,BOOL,expression_t*,statement_t*);
92 static statement_t *new_for_statement(parser_ctx_t*,variable_list_t*,expression_t*,expression_t*,
93 expression_t*,statement_t*);
94 static statement_t *new_forin_statement(parser_ctx_t*,variable_declaration_t*,expression_t*,expression_t*,statement_t*);
95 static statement_t *new_continue_statement(parser_ctx_t*,const WCHAR*);
96 static statement_t *new_break_statement(parser_ctx_t*,const WCHAR*);
97 static statement_t *new_return_statement(parser_ctx_t*,expression_t*);
98 static statement_t *new_with_statement(parser_ctx_t*,expression_t*,statement_t*);
99 static statement_t *new_labelled_statement(parser_ctx_t*,const WCHAR*,statement_t*);
100 static statement_t *new_switch_statement(parser_ctx_t*,expression_t*,case_clausule_t*);
101 static statement_t *new_throw_statement(parser_ctx_t*,expression_t*);
102 static statement_t *new_try_statement(parser_ctx_t*,statement_t*,catch_block_t*,statement_t*);
104 struct statement_list_t {
109 static statement_list_t *new_statement_list(parser_ctx_t*,statement_t*);
110 static statement_list_t *statement_list_add(statement_list_t*,statement_t*);
112 typedef struct _parameter_list_t {
117 static parameter_list_t *new_parameter_list(parser_ctx_t*,const WCHAR*);
118 static parameter_list_t *parameter_list_add(parser_ctx_t*,parameter_list_t*,const WCHAR*);
120 static void push_func(parser_ctx_t*);
121 static inline void pop_func(parser_ctx_t *ctx)
123 ctx->func_stack = ctx->func_stack->next;
126 static expression_t *new_function_expression(parser_ctx_t*,const WCHAR*,parameter_list_t*,
127 source_elements_t*,const WCHAR*,DWORD);
128 static expression_t *new_binary_expression(parser_ctx_t*,expression_type_t,expression_t*,expression_t*);
129 static expression_t *new_unary_expression(parser_ctx_t*,expression_type_t,expression_t*);
130 static expression_t *new_conditional_expression(parser_ctx_t*,expression_t*,expression_t*,expression_t*);
131 static expression_t *new_array_expression(parser_ctx_t*,expression_t*,expression_t*);
132 static expression_t *new_member_expression(parser_ctx_t*,expression_t*,const WCHAR*);
133 static expression_t *new_new_expression(parser_ctx_t*,expression_t*,argument_list_t*);
134 static expression_t *new_call_expression(parser_ctx_t*,expression_t*,argument_list_t*);
135 static expression_t *new_this_expression(parser_ctx_t*);
136 static expression_t *new_identifier_expression(parser_ctx_t*,const WCHAR*);
137 static expression_t *new_literal_expression(parser_ctx_t*,literal_t*);
138 static expression_t *new_array_literal_expression(parser_ctx_t*,element_list_t*,int);
139 static expression_t *new_prop_and_value_expression(parser_ctx_t*,property_list_t*);
141 static source_elements_t *new_source_elements(parser_ctx_t*);
142 static source_elements_t *source_elements_add_statement(source_elements_t*,statement_t*);
154 struct _argument_list_t *argument_list;
155 case_clausule_t *case_clausule;
156 struct _case_list_t *case_list;
157 catch_block_t *catch_block;
158 struct _element_list_t *element_list;
160 const WCHAR *identifier;
161 struct _parameter_list_t *parameter_list;
162 struct _property_list_t *property_list;
163 source_elements_t *source_elements;
164 statement_t *statement;
165 struct _statement_list_t *statement_list;
166 struct _variable_list_t *variable_list;
167 variable_declaration_t *variable_declaration;
171 %token kBREAK kCASE kCATCH kCONTINUE kDEFAULT kDELETE kDO kELSE kIF kFINALLY kFOR kIN
172 %token kINSTANCEOF kNEW kNULL kUNDEFINED kRETURN kSWITCH kTHIS kTHROW kTRUE kFALSE kTRY kTYPEOF kVAR kVOID kWHILE kWITH
173 %token tANDAND tOROR tINC tDEC tHTMLCOMMENT
175 %token <srcptr> kFUNCTION '}'
178 %token <identifier> tIdentifier
179 %token <ival> tAssignOper tEqOper tShiftOper tRelOper
180 %token <literal> tNumericLiteral
181 %token <wstr> tStringLiteral
183 %type <source_elements> SourceElements
184 %type <source_elements> FunctionBody
185 %type <statement> Statement
186 %type <statement> Block
187 %type <statement> VariableStatement
188 %type <statement> EmptyStatement
189 %type <statement> ExpressionStatement
190 %type <statement> IfStatement
191 %type <statement> IterationStatement
192 %type <statement> ContinueStatement
193 %type <statement> BreakStatement
194 %type <statement> ReturnStatement
195 %type <statement> WithStatement
196 %type <statement> LabelledStatement
197 %type <statement> SwitchStatement
198 %type <statement> ThrowStatement
199 %type <statement> TryStatement
200 %type <statement> Finally
201 %type <statement_list> StatementList StatementList_opt
202 %type <parameter_list> FormalParameterList FormalParameterList_opt
203 %type <expr> Expression Expression_opt
204 %type <expr> ExpressionNoIn ExpressionNoIn_opt
205 %type <expr> FunctionExpression
206 %type <expr> AssignmentExpression AssignmentExpressionNoIn
207 %type <expr> ConditionalExpression ConditionalExpressionNoIn
208 %type <expr> LeftHandSideExpression
209 %type <expr> LogicalORExpression LogicalORExpressionNoIn
210 %type <expr> LogicalANDExpression LogicalANDExpressionNoIn
211 %type <expr> BitwiseORExpression BitwiseORExpressionNoIn
212 %type <expr> BitwiseXORExpression BitwiseXORExpressionNoIn
213 %type <expr> BitwiseANDExpression BitwiseANDExpressionNoIn
214 %type <expr> EqualityExpression EqualityExpressionNoIn
215 %type <expr> RelationalExpression RelationalExpressionNoIn
216 %type <expr> ShiftExpression
217 %type <expr> AdditiveExpression
218 %type <expr> MultiplicativeExpression
219 %type <expr> Initialiser_opt Initialiser
220 %type <expr> InitialiserNoIn_opt InitialiserNoIn
221 %type <expr> UnaryExpression
222 %type <expr> PostfixExpression
223 %type <expr> NewExpression
224 %type <expr> CallExpression
225 %type <expr> MemberExpression
226 %type <expr> PrimaryExpression
227 %type <identifier> Identifier_opt
228 %type <variable_list> VariableDeclarationList
229 %type <variable_list> VariableDeclarationListNoIn
230 %type <variable_declaration> VariableDeclaration
231 %type <variable_declaration> VariableDeclarationNoIn
232 %type <case_list> CaseClausules CaseClausules_opt
233 %type <case_clausule> CaseClausule DefaultClausule CaseBlock
234 %type <catch_block> Catch
235 %type <argument_list> Arguments
236 %type <argument_list> ArgumentList
237 %type <literal> Literal
238 %type <expr> ArrayLiteral
239 %type <expr> ObjectLiteral
240 %type <ival> Elision Elision_opt
241 %type <element_list> ElementList
242 %type <property_list> PropertyNameAndValueList
243 %type <literal> PropertyName
244 %type <literal> BooleanLiteral
245 %type <srcptr> KFunction
247 %nonassoc LOWER_THAN_ELSE
252 /* ECMA-262 3rd Edition 14 */
254 : SourceElements HtmlComment
255 { program_parsed(ctx, $1); }
261 /* ECMA-262 3rd Edition 14 */
263 : /* empty */ { $$ = new_source_elements(ctx); }
264 | SourceElements Statement
265 { $$ = source_elements_add_statement($1, $2); }
267 /* ECMA-262 3rd Edition 13 */
269 : KFunction Identifier_opt '(' FormalParameterList_opt ')' '{' FunctionBody '}'
270 { $$ = new_function_expression(ctx, $2, $4, $7, $1, $8-$1+1); }
273 : kFUNCTION { push_func(ctx); $$ = $1; }
275 /* ECMA-262 3rd Edition 13 */
277 : SourceElements { $$ = function_body_parsed(ctx, $1); }
279 /* ECMA-262 3rd Edition 13 */
281 : tIdentifier { $$ = new_parameter_list(ctx, $1); }
282 | FormalParameterList ',' tIdentifier
283 { $$ = parameter_list_add(ctx, $1, $3); }
285 /* ECMA-262 3rd Edition 13 */
286 FormalParameterList_opt
287 : /* empty */ { $$ = NULL; }
288 | FormalParameterList { $$ = $1; }
290 /* ECMA-262 3rd Edition 12 */
293 | VariableStatement { $$ = $1; }
294 | EmptyStatement { $$ = $1; }
295 | ExpressionStatement { $$ = $1; }
296 | IfStatement { $$ = $1; }
297 | IterationStatement { $$ = $1; }
298 | ContinueStatement { $$ = $1; }
299 | BreakStatement { $$ = $1; }
300 | ReturnStatement { $$ = $1; }
301 | WithStatement { $$ = $1; }
302 | LabelledStatement { $$ = $1; }
303 | SwitchStatement { $$ = $1; }
304 | ThrowStatement { $$ = $1; }
305 | TryStatement { $$ = $1; }
307 /* ECMA-262 3rd Edition 12.2 */
309 : Statement { $$ = new_statement_list(ctx, $1); }
310 | StatementList Statement
311 { $$ = statement_list_add($1, $2); }
313 /* ECMA-262 3rd Edition 12.2 */
315 : /* empty */ { $$ = NULL; }
316 | StatementList { $$ = $1; }
318 /* ECMA-262 3rd Edition 12.1 */
320 : '{' StatementList '}' { $$ = new_block_statement(ctx, $2); }
321 | '{' '}' { $$ = new_block_statement(ctx, NULL); }
323 /* ECMA-262 3rd Edition 12.2 */
325 : kVAR VariableDeclarationList semicolon_opt
326 { $$ = new_var_statement(ctx, $2); }
328 /* ECMA-262 3rd Edition 12.2 */
329 VariableDeclarationList
330 : VariableDeclaration { $$ = new_variable_list(ctx, $1); }
331 | VariableDeclarationList ',' VariableDeclaration
332 { $$ = variable_list_add(ctx, $1, $3); }
334 /* ECMA-262 3rd Edition 12.2 */
335 VariableDeclarationListNoIn
336 : VariableDeclarationNoIn
337 { $$ = new_variable_list(ctx, $1); }
338 | VariableDeclarationListNoIn ',' VariableDeclarationNoIn
339 { $$ = variable_list_add(ctx, $1, $3); }
341 /* ECMA-262 3rd Edition 12.2 */
343 : tIdentifier Initialiser_opt
344 { $$ = new_variable_declaration(ctx, $1, $2); }
346 /* ECMA-262 3rd Edition 12.2 */
347 VariableDeclarationNoIn
348 : tIdentifier InitialiserNoIn_opt
349 { $$ = new_variable_declaration(ctx, $1, $2); }
351 /* ECMA-262 3rd Edition 12.2 */
353 : /* empty */ { $$ = NULL; }
354 | Initialiser { $$ = $1; }
356 /* ECMA-262 3rd Edition 12.2 */
358 : '=' AssignmentExpression
361 /* ECMA-262 3rd Edition 12.2 */
363 : /* empty */ { $$ = NULL; }
364 | InitialiserNoIn { $$ = $1; }
366 /* ECMA-262 3rd Edition 12.2 */
368 : '=' AssignmentExpressionNoIn
371 /* ECMA-262 3rd Edition 12.3 */
373 : ';' { $$ = new_empty_statement(ctx); }
375 /* ECMA-262 3rd Edition 12.4 */
377 : Expression semicolon_opt
378 { $$ = new_expression_statement(ctx, $1); }
380 /* ECMA-262 3rd Edition 12.5 */
382 : kIF '(' Expression ')' Statement kELSE Statement
383 { $$ = new_if_statement(ctx, $3, $5, $7); }
384 | kIF '(' Expression ')' Statement %prec LOWER_THAN_ELSE
385 { $$ = new_if_statement(ctx, $3, $5, NULL); }
387 /* ECMA-262 3rd Edition 12.6 */
389 : kDO Statement kWHILE '(' Expression ')' semicolon_opt
390 { $$ = new_while_statement(ctx, TRUE, $5, $2); }
391 | kWHILE '(' Expression ')' Statement
392 { $$ = new_while_statement(ctx, FALSE, $3, $5); }
393 | kFOR '(' ExpressionNoIn_opt ';' Expression_opt ';' Expression_opt ')' Statement
394 { $$ = new_for_statement(ctx, NULL, $3, $5, $7, $9); }
395 | kFOR '(' kVAR VariableDeclarationListNoIn ';' Expression_opt ';' Expression_opt ')' Statement
396 { $$ = new_for_statement(ctx, $4, NULL, $6, $8, $10); }
397 | kFOR '(' LeftHandSideExpression kIN Expression ')' Statement
398 { $$ = new_forin_statement(ctx, NULL, $3, $5, $7); }
399 | kFOR '(' kVAR VariableDeclarationNoIn kIN Expression ')' Statement
400 { $$ = new_forin_statement(ctx, $4, NULL, $6, $8); }
402 /* ECMA-262 3rd Edition 12.7 */
404 : kCONTINUE /* NONL */ Identifier_opt semicolon_opt
405 { $$ = new_continue_statement(ctx, $2); }
407 /* ECMA-262 3rd Edition 12.8 */
409 : kBREAK /* NONL */ Identifier_opt semicolon_opt
410 { $$ = new_break_statement(ctx, $2); }
412 /* ECMA-262 3rd Edition 12.9 */
414 : kRETURN /* NONL */ Expression_opt semicolon_opt
415 { $$ = new_return_statement(ctx, $2); }
417 /* ECMA-262 3rd Edition 12.10 */
419 : kWITH '(' Expression ')' Statement
420 { $$ = new_with_statement(ctx, $3, $5); }
422 /* ECMA-262 3rd Edition 12.12 */
424 : tIdentifier ':' Statement
425 { $$ = new_labelled_statement(ctx, $1, $3); }
427 /* ECMA-262 3rd Edition 12.11 */
429 : kSWITCH '(' Expression ')' CaseBlock
430 { $$ = new_switch_statement(ctx, $3, $5); }
432 /* ECMA-262 3rd Edition 12.11 */
434 : '{' CaseClausules_opt '}'
435 { $$ = new_case_block(ctx, $2, NULL, NULL); }
436 | '{' CaseClausules_opt DefaultClausule CaseClausules_opt '}'
437 { $$ = new_case_block(ctx, $2, $3, $4); }
439 /* ECMA-262 3rd Edition 12.11 */
441 : /* empty */ { $$ = NULL; }
442 | CaseClausules { $$ = $1; }
444 /* ECMA-262 3rd Edition 12.11 */
446 : CaseClausule { $$ = new_case_list(ctx, $1); }
447 | CaseClausules CaseClausule
448 { $$ = case_list_add(ctx, $1, $2); }
450 /* ECMA-262 3rd Edition 12.11 */
452 : kCASE Expression ':' StatementList_opt
453 { $$ = new_case_clausule(ctx, $2, $4); }
455 /* ECMA-262 3rd Edition 12.11 */
457 : kDEFAULT ':' StatementList_opt
458 { $$ = new_case_clausule(ctx, NULL, $3); }
460 /* ECMA-262 3rd Edition 12.13 */
462 : kTHROW /* NONL */ Expression semicolon_opt
463 { $$ = new_throw_statement(ctx, $2); }
465 /* ECMA-262 3rd Edition 12.14 */
467 : kTRY Block Catch { $$ = new_try_statement(ctx, $2, $3, NULL); }
468 | kTRY Block Finally { $$ = new_try_statement(ctx, $2, NULL, $3); }
469 | kTRY Block Catch Finally
470 { $$ = new_try_statement(ctx, $2, $3, $4); }
472 /* ECMA-262 3rd Edition 12.14 */
474 : kCATCH '(' tIdentifier ')' Block
475 { $$ = new_catch_block(ctx, $3, $5); }
477 /* ECMA-262 3rd Edition 12.14 */
479 : kFINALLY Block { $$ = $2; }
481 /* ECMA-262 3rd Edition 11.14 */
483 : /* empty */ { $$ = NULL; }
484 | Expression { $$ = $1; }
486 /* ECMA-262 3rd Edition 11.14 */
488 : AssignmentExpression { $$ = $1; }
489 | Expression ',' AssignmentExpression
490 { $$ = new_binary_expression(ctx, EXPR_COMMA, $1, $3); }
492 /* ECMA-262 3rd Edition 11.14 */
494 : /* empty */ { $$ = NULL; }
495 | ExpressionNoIn { $$ = $1; }
497 /* ECMA-262 3rd Edition 11.14 */
499 : AssignmentExpressionNoIn
501 | ExpressionNoIn ',' AssignmentExpressionNoIn
502 { $$ = new_binary_expression(ctx, EXPR_COMMA, $1, $3); }
504 /* ECMA-262 3rd Edition 11.13 */
506 : ConditionalExpression { $$ = $1; }
507 | LeftHandSideExpression '=' AssignmentExpression
508 { $$ = new_binary_expression(ctx, EXPR_ASSIGN, $1, $3); }
509 | LeftHandSideExpression tAssignOper AssignmentExpression
510 { $$ = new_binary_expression(ctx, $2, $1, $3); }
512 /* ECMA-262 3rd Edition 11.13 */
513 AssignmentExpressionNoIn
514 : ConditionalExpressionNoIn
516 | LeftHandSideExpression '=' AssignmentExpressionNoIn
517 { $$ = new_binary_expression(ctx, EXPR_ASSIGN, $1, $3); }
518 | LeftHandSideExpression tAssignOper AssignmentExpressionNoIn
519 { $$ = new_binary_expression(ctx, $2, $1, $3); }
521 /* ECMA-262 3rd Edition 11.12 */
522 ConditionalExpression
523 : LogicalORExpression { $$ = $1; }
524 | LogicalORExpression '?' AssignmentExpression ':' AssignmentExpression
525 { $$ = new_conditional_expression(ctx, $1, $3, $5); }
527 /* ECMA-262 3rd Edition 11.12 */
528 ConditionalExpressionNoIn
529 : LogicalORExpressionNoIn
531 | LogicalORExpressionNoIn '?' AssignmentExpressionNoIn ':' AssignmentExpressionNoIn
532 { $$ = new_conditional_expression(ctx, $1, $3, $5); }
534 /* ECMA-262 3rd Edition 11.11 */
536 : LogicalANDExpression { $$ = $1; }
537 | LogicalORExpression tOROR LogicalANDExpression
538 { $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); }
540 /* ECMA-262 3rd Edition 11.11 */
541 LogicalORExpressionNoIn
542 : LogicalANDExpressionNoIn
544 | LogicalORExpressionNoIn tOROR LogicalANDExpressionNoIn
545 { $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); }
547 /* ECMA-262 3rd Edition 11.11 */
549 : BitwiseORExpression { $$ = $1; }
550 | LogicalANDExpression tANDAND BitwiseORExpression
551 { $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); }
553 /* ECMA-262 3rd Edition 11.11 */
554 LogicalANDExpressionNoIn
555 : BitwiseORExpressionNoIn
557 | LogicalANDExpressionNoIn tANDAND BitwiseORExpressionNoIn
558 { $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); }
560 /* ECMA-262 3rd Edition 11.10 */
562 : BitwiseXORExpression { $$ = $1; }
563 | BitwiseORExpression '|' BitwiseXORExpression
564 { $$ = new_binary_expression(ctx, EXPR_BOR, $1, $3); }
566 /* ECMA-262 3rd Edition 11.10 */
567 BitwiseORExpressionNoIn
568 : BitwiseXORExpressionNoIn
570 | BitwiseORExpressionNoIn '|' BitwiseXORExpressionNoIn
571 { $$ = new_binary_expression(ctx, EXPR_BOR, $1, $3); }
573 /* ECMA-262 3rd Edition 11.10 */
575 : BitwiseANDExpression { $$ = $1; }
576 | BitwiseXORExpression '^' BitwiseANDExpression
577 { $$ = new_binary_expression(ctx, EXPR_BXOR, $1, $3); }
579 /* ECMA-262 3rd Edition 11.10 */
580 BitwiseXORExpressionNoIn
581 : BitwiseANDExpressionNoIn
583 | BitwiseXORExpressionNoIn '^' BitwiseANDExpressionNoIn
584 { $$ = new_binary_expression(ctx, EXPR_BXOR, $1, $3); }
586 /* ECMA-262 3rd Edition 11.10 */
588 : EqualityExpression { $$ = $1; }
589 | BitwiseANDExpression '&' EqualityExpression
590 { $$ = new_binary_expression(ctx, EXPR_BAND, $1, $3); }
592 /* ECMA-262 3rd Edition 11.10 */
593 BitwiseANDExpressionNoIn
594 : EqualityExpressionNoIn
596 | BitwiseANDExpressionNoIn '&' EqualityExpressionNoIn
597 { $$ = new_binary_expression(ctx, EXPR_BAND, $1, $3); }
599 /* ECMA-262 3rd Edition 11.9 */
601 : RelationalExpression { $$ = $1; }
602 | EqualityExpression tEqOper RelationalExpression
603 { $$ = new_binary_expression(ctx, $2, $1, $3); }
605 /* ECMA-262 3rd Edition 11.9 */
606 EqualityExpressionNoIn
607 : RelationalExpressionNoIn { $$ = $1; }
608 | EqualityExpressionNoIn tEqOper RelationalExpressionNoIn
609 { $$ = new_binary_expression(ctx, $2, $1, $3); }
611 /* ECMA-262 3rd Edition 11.8 */
613 : ShiftExpression { $$ = $1; }
614 | RelationalExpression tRelOper ShiftExpression
615 { $$ = new_binary_expression(ctx, $2, $1, $3); }
616 | RelationalExpression kINSTANCEOF ShiftExpression
617 { $$ = new_binary_expression(ctx, EXPR_INSTANCEOF, $1, $3); }
618 | RelationalExpression kIN ShiftExpression
619 { $$ = new_binary_expression(ctx, EXPR_IN, $1, $3); }
621 /* ECMA-262 3rd Edition 11.8 */
622 RelationalExpressionNoIn
623 : ShiftExpression { $$ = $1; }
624 | RelationalExpressionNoIn tRelOper ShiftExpression
625 { $$ = new_binary_expression(ctx, $2, $1, $3); }
626 | RelationalExpressionNoIn kINSTANCEOF ShiftExpression
627 { $$ = new_binary_expression(ctx, EXPR_INSTANCEOF, $1, $3); }
629 /* ECMA-262 3rd Edition 11.7 */
631 : AdditiveExpression { $$ = $1; }
632 | ShiftExpression tShiftOper AdditiveExpression
633 { $$ = new_binary_expression(ctx, $2, $1, $3); }
635 /* ECMA-262 3rd Edition 11.6 */
637 : MultiplicativeExpression
639 | AdditiveExpression '+' MultiplicativeExpression
640 { $$ = new_binary_expression(ctx, EXPR_ADD, $1, $3); }
641 | AdditiveExpression '-' MultiplicativeExpression
642 { $$ = new_binary_expression(ctx, EXPR_SUB, $1, $3); }
644 /* ECMA-262 3rd Edition 11.5 */
645 MultiplicativeExpression
646 : UnaryExpression { $$ = $1; }
647 | MultiplicativeExpression '*' UnaryExpression
648 { $$ = new_binary_expression(ctx, EXPR_MUL, $1, $3); }
649 | MultiplicativeExpression '/' UnaryExpression
650 { $$ = new_binary_expression(ctx, EXPR_DIV, $1, $3); }
651 | MultiplicativeExpression '%' UnaryExpression
652 { $$ = new_binary_expression(ctx, EXPR_MOD, $1, $3); }
654 /* ECMA-262 3rd Edition 11.4 */
656 : PostfixExpression { $$ = $1; }
657 | kDELETE UnaryExpression
658 { $$ = new_unary_expression(ctx, EXPR_DELETE, $2); }
659 | kVOID UnaryExpression { $$ = new_unary_expression(ctx, EXPR_VOID, $2); }
660 | kTYPEOF UnaryExpression
661 { $$ = new_unary_expression(ctx, EXPR_TYPEOF, $2); }
662 | tINC UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PREINC, $2); }
663 | tDEC UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PREDEC, $2); }
664 | '+' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PLUS, $2); }
665 | '-' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_MINUS, $2); }
666 | '~' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_BITNEG, $2); }
667 | '!' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_LOGNEG, $2); }
669 /* ECMA-262 3rd Edition 11.2 */
671 : LeftHandSideExpression
673 | LeftHandSideExpression /* NONL */ tINC
674 { $$ = new_unary_expression(ctx, EXPR_POSTINC, $1); }
675 | LeftHandSideExpression /* NONL */ tDEC
676 { $$ = new_unary_expression(ctx, EXPR_POSTDEC, $1); }
679 /* ECMA-262 3rd Edition 11.2 */
680 LeftHandSideExpression
681 : NewExpression { $$ = $1; }
682 | CallExpression { $$ = $1; }
684 /* ECMA-262 3rd Edition 11.2 */
686 : MemberExpression { $$ = $1; }
687 | kNEW NewExpression { $$ = new_new_expression(ctx, $2, NULL); }
689 /* ECMA-262 3rd Edition 11.2 */
691 : PrimaryExpression { $$ = $1; }
692 | FunctionExpression { $$ = $1; }
693 | MemberExpression '[' Expression ']'
694 { $$ = new_array_expression(ctx, $1, $3); }
695 | MemberExpression '.' tIdentifier
696 { $$ = new_member_expression(ctx, $1, $3); }
697 | kNEW MemberExpression Arguments
698 { $$ = new_new_expression(ctx, $2, $3); }
700 /* ECMA-262 3rd Edition 11.2 */
702 : MemberExpression Arguments
703 { $$ = new_call_expression(ctx, $1, $2); }
704 | CallExpression Arguments
705 { $$ = new_call_expression(ctx, $1, $2); }
706 | CallExpression '[' Expression ']'
707 { $$ = new_array_expression(ctx, $1, $3); }
708 | CallExpression '.' tIdentifier
709 { $$ = new_member_expression(ctx, $1, $3); }
711 /* ECMA-262 3rd Edition 11.2 */
713 : '(' ')' { $$ = NULL; }
714 | '(' ArgumentList ')' { $$ = $2; }
716 /* ECMA-262 3rd Edition 11.2 */
718 : AssignmentExpression { $$ = new_argument_list(ctx, $1); }
719 | ArgumentList ',' AssignmentExpression
720 { $$ = argument_list_add(ctx, $1, $3); }
722 /* ECMA-262 3rd Edition 11.1 */
724 : kTHIS { $$ = new_this_expression(ctx); }
725 | tIdentifier { $$ = new_identifier_expression(ctx, $1); }
726 | Literal { $$ = new_literal_expression(ctx, $1); }
727 | ArrayLiteral { $$ = $1; }
728 | ObjectLiteral { $$ = $1; }
729 | '(' Expression ')' { $$ = $2; }
731 /* ECMA-262 3rd Edition 11.1.4 */
733 : '[' ']' { $$ = new_array_literal_expression(ctx, NULL, 0); }
734 | '[' Elision ']' { $$ = new_array_literal_expression(ctx, NULL, $2+1); }
735 | '[' ElementList ']' { $$ = new_array_literal_expression(ctx, $2, 0); }
736 | '[' ElementList ',' Elision_opt ']'
737 { $$ = new_array_literal_expression(ctx, $2, $4+1); }
739 /* ECMA-262 3rd Edition 11.1.4 */
741 : Elision_opt AssignmentExpression
742 { $$ = new_element_list(ctx, $1, $2); }
743 | ElementList ',' Elision_opt AssignmentExpression
744 { $$ = element_list_add(ctx, $1, $3, $4); }
746 /* ECMA-262 3rd Edition 11.1.4 */
749 | Elision ',' { $$ = $1 + 1; }
751 /* ECMA-262 3rd Edition 11.1.4 */
753 : /* empty */ { $$ = 0; }
754 | Elision { $$ = $1; }
756 /* ECMA-262 3rd Edition 11.1.5 */
758 : '{' '}' { $$ = new_prop_and_value_expression(ctx, NULL); }
759 | '{' PropertyNameAndValueList '}'
760 { $$ = new_prop_and_value_expression(ctx, $2); }
762 /* ECMA-262 3rd Edition 11.1.5 */
763 PropertyNameAndValueList
764 : PropertyName ':' AssignmentExpression
765 { $$ = new_property_list(ctx, $1, $3); }
766 | PropertyNameAndValueList ',' PropertyName ':' AssignmentExpression
767 { $$ = property_list_add(ctx, $1, $3, $5); }
769 /* ECMA-262 3rd Edition 11.1.5 */
771 : tIdentifier { $$ = new_string_literal(ctx, $1); }
772 | tStringLiteral { $$ = new_string_literal(ctx, $1); }
773 | tNumericLiteral { $$ = $1; }
775 /* ECMA-262 3rd Edition 7.6 */
777 : /* empty*/ { $$ = NULL; }
778 | tIdentifier { $$ = $1; }
780 /* ECMA-262 3rd Edition 7.8 */
782 : kNULL { $$ = new_null_literal(ctx); }
783 | kUNDEFINED { $$ = new_undefined_literal(ctx); }
784 | BooleanLiteral { $$ = $1; }
785 | tNumericLiteral { $$ = $1; }
786 | tStringLiteral { $$ = new_string_literal(ctx, $1); }
787 | '/' { $$ = parse_regexp(ctx);
790 /* ECMA-262 3rd Edition 7.8.2 */
792 : kTRUE { $$ = new_boolean_literal(ctx, TRUE); }
793 | kFALSE { $$ = new_boolean_literal(ctx, FALSE); }
797 | error { if(!allow_auto_semicolon(ctx)) {YYABORT;} }
801 static BOOL allow_auto_semicolon(parser_ctx_t *ctx)
803 return ctx->nl || ctx->ptr == ctx->end || *(ctx->ptr-1) == '}';
806 static literal_t *new_string_literal(parser_ctx_t *ctx, const WCHAR *str)
808 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
816 static literal_t *new_null_literal(parser_ctx_t *ctx)
818 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
825 static literal_t *new_undefined_literal(parser_ctx_t *ctx)
827 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
834 static literal_t *new_boolean_literal(parser_ctx_t *ctx, VARIANT_BOOL bval)
836 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
844 static prop_val_t *new_prop_val(parser_ctx_t *ctx, literal_t *name, expression_t *value)
846 prop_val_t *ret = parser_alloc(ctx, sizeof(prop_val_t));
855 static property_list_t *new_property_list(parser_ctx_t *ctx, literal_t *name, expression_t *value)
857 property_list_t *ret = parser_alloc_tmp(ctx, sizeof(property_list_t));
859 ret->head = ret->tail = new_prop_val(ctx, name, value);
864 static property_list_t *property_list_add(parser_ctx_t *ctx, property_list_t *list, literal_t *name, expression_t *value)
866 list->tail = list->tail->next = new_prop_val(ctx, name, value);
871 static array_element_t *new_array_element(parser_ctx_t *ctx, int elision, expression_t *expr)
873 array_element_t *ret = parser_alloc(ctx, sizeof(array_element_t));
875 ret->elision = elision;
882 static element_list_t *new_element_list(parser_ctx_t *ctx, int elision, expression_t *expr)
884 element_list_t *ret = parser_alloc_tmp(ctx, sizeof(element_list_t));
886 ret->head = ret->tail = new_array_element(ctx, elision, expr);
891 static element_list_t *element_list_add(parser_ctx_t *ctx, element_list_t *list, int elision, expression_t *expr)
893 list->tail = list->tail->next = new_array_element(ctx, elision, expr);
898 static argument_t *new_argument(parser_ctx_t *ctx, expression_t *expr)
900 argument_t *ret = parser_alloc(ctx, sizeof(argument_t));
908 static argument_list_t *new_argument_list(parser_ctx_t *ctx, expression_t *expr)
910 argument_list_t *ret = parser_alloc_tmp(ctx, sizeof(argument_list_t));
912 ret->head = ret->tail = new_argument(ctx, expr);
917 static argument_list_t *argument_list_add(parser_ctx_t *ctx, argument_list_t *list, expression_t *expr)
919 list->tail = list->tail->next = new_argument(ctx, expr);
924 static catch_block_t *new_catch_block(parser_ctx_t *ctx, const WCHAR *identifier, statement_t *statement)
926 catch_block_t *ret = parser_alloc(ctx, sizeof(catch_block_t));
928 ret->identifier = identifier;
929 ret->statement = statement;
934 static case_clausule_t *new_case_clausule(parser_ctx_t *ctx, expression_t *expr, statement_list_t *stat_list)
936 case_clausule_t *ret = parser_alloc(ctx, sizeof(case_clausule_t));
939 ret->stat = stat_list ? stat_list->head : NULL;
945 static case_list_t *new_case_list(parser_ctx_t *ctx, case_clausule_t *case_clausule)
947 case_list_t *ret = parser_alloc_tmp(ctx, sizeof(case_list_t));
949 ret->head = ret->tail = case_clausule;
954 static case_list_t *case_list_add(parser_ctx_t *ctx, case_list_t *list, case_clausule_t *case_clausule)
956 list->tail = list->tail->next = case_clausule;
961 static case_clausule_t *new_case_block(parser_ctx_t *ctx, case_list_t *case_list1,
962 case_clausule_t *default_clausule, case_list_t *case_list2)
964 case_clausule_t *ret = NULL, *iter = NULL, *iter2;
965 statement_t *stat = NULL;
968 ret = case_list1->head;
969 iter = case_list1->tail;
972 if(default_clausule) {
974 iter = iter->next = default_clausule;
976 ret = iter = default_clausule;
981 iter->next = case_list2->head;
983 ret = case_list2->head;
989 for(iter = ret; iter; iter = iter->next) {
990 for(iter2 = iter; iter2 && !iter2->stat; iter2 = iter2->next);
994 while(iter != iter2) {
995 iter->stat = iter2->stat;
1002 stat->next = iter->stat;
1011 static statement_t *new_block_statement(parser_ctx_t *ctx, statement_list_t *list)
1013 block_statement_t *ret = parser_alloc(ctx, sizeof(block_statement_t));
1015 ret->stat.eval = block_statement_eval;
1016 ret->stat.next = NULL;
1017 ret->stat_list = list ? list->head : NULL;
1022 static variable_declaration_t *new_variable_declaration(parser_ctx_t *ctx, const WCHAR *identifier, expression_t *expr)
1024 variable_declaration_t *ret = parser_alloc(ctx, sizeof(variable_declaration_t));
1025 var_list_t *var_list = parser_alloc(ctx, sizeof(var_list_t));
1027 ret->identifier = identifier;
1031 var_list->identifier = identifier;
1032 var_list->next = NULL;
1034 if(ctx->func_stack->var_tail)
1035 ctx->func_stack->var_tail = ctx->func_stack->var_tail->next = var_list;
1037 ctx->func_stack->var_head = ctx->func_stack->var_tail = var_list;
1042 static variable_list_t *new_variable_list(parser_ctx_t *ctx, variable_declaration_t *decl)
1044 variable_list_t *ret = parser_alloc_tmp(ctx, sizeof(variable_list_t));
1046 ret->head = ret->tail = decl;
1051 static variable_list_t *variable_list_add(parser_ctx_t *ctx, variable_list_t *list, variable_declaration_t *decl)
1053 list->tail = list->tail->next = decl;
1058 static statement_t *new_var_statement(parser_ctx_t *ctx, variable_list_t *variable_list)
1060 var_statement_t *ret = parser_alloc(ctx, sizeof(var_statement_t));
1062 ret->stat.eval = var_statement_eval;
1063 ret->stat.next = NULL;
1064 ret->variable_list = variable_list->head;
1069 static statement_t *new_empty_statement(parser_ctx_t *ctx)
1071 statement_t *ret = parser_alloc(ctx, sizeof(statement_t));
1073 ret->eval = empty_statement_eval;
1079 static statement_t *new_expression_statement(parser_ctx_t *ctx, expression_t *expr)
1081 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1083 ret->stat.eval = expression_statement_eval;
1084 ret->stat.next = NULL;
1090 static statement_t *new_if_statement(parser_ctx_t *ctx, expression_t *expr, statement_t *if_stat, statement_t *else_stat)
1092 if_statement_t *ret = parser_alloc(ctx, sizeof(if_statement_t));
1094 ret->stat.eval = if_statement_eval;
1095 ret->stat.next = NULL;
1097 ret->if_stat = if_stat;
1098 ret->else_stat = else_stat;
1103 static statement_t *new_while_statement(parser_ctx_t *ctx, BOOL dowhile, expression_t *expr, statement_t *stat)
1105 while_statement_t *ret = parser_alloc(ctx, sizeof(while_statement_t));
1107 ret->stat.eval = while_statement_eval;
1108 ret->stat.next = NULL;
1109 ret->do_while = dowhile;
1111 ret->statement = stat;
1116 static statement_t *new_for_statement(parser_ctx_t *ctx, variable_list_t *variable_list, expression_t *begin_expr,
1117 expression_t *expr, expression_t *end_expr, statement_t *statement)
1119 for_statement_t *ret = parser_alloc(ctx, sizeof(for_statement_t));
1121 ret->stat.eval = for_statement_eval;
1122 ret->stat.next = NULL;
1123 ret->variable_list = variable_list ? variable_list->head : NULL;
1124 ret->begin_expr = begin_expr;
1126 ret->end_expr = end_expr;
1127 ret->statement = statement;
1132 static statement_t *new_forin_statement(parser_ctx_t *ctx, variable_declaration_t *variable, expression_t *expr,
1133 expression_t *in_expr, statement_t *statement)
1135 forin_statement_t *ret = parser_alloc(ctx, sizeof(forin_statement_t));
1137 ret->stat.eval = forin_statement_eval;
1138 ret->stat.next = NULL;
1139 ret->variable = variable;
1141 ret->in_expr = in_expr;
1142 ret->statement = statement;
1147 static statement_t *new_continue_statement(parser_ctx_t *ctx, const WCHAR *identifier)
1149 branch_statement_t *ret = parser_alloc(ctx, sizeof(branch_statement_t));
1151 ret->stat.eval = continue_statement_eval;
1152 ret->stat.next = NULL;
1153 ret->identifier = identifier;
1158 static statement_t *new_break_statement(parser_ctx_t *ctx, const WCHAR *identifier)
1160 branch_statement_t *ret = parser_alloc(ctx, sizeof(branch_statement_t));
1162 ret->stat.eval = break_statement_eval;
1163 ret->stat.next = NULL;
1164 ret->identifier = identifier;
1169 static statement_t *new_return_statement(parser_ctx_t *ctx, expression_t *expr)
1171 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1173 ret->stat.eval = return_statement_eval;
1174 ret->stat.next = NULL;
1180 static statement_t *new_with_statement(parser_ctx_t *ctx, expression_t *expr, statement_t *statement)
1182 with_statement_t *ret = parser_alloc(ctx, sizeof(with_statement_t));
1184 ret->stat.eval = with_statement_eval;
1185 ret->stat.next = NULL;
1187 ret->statement = statement;
1192 static statement_t *new_labelled_statement(parser_ctx_t *ctx, const WCHAR *identifier, statement_t *statement)
1194 labelled_statement_t *ret = parser_alloc(ctx, sizeof(labelled_statement_t));
1196 ret->stat.eval = labelled_statement_eval;
1197 ret->stat.next = NULL;
1198 ret->identifier = identifier;
1199 ret->statement = statement;
1204 static statement_t *new_switch_statement(parser_ctx_t *ctx, expression_t *expr, case_clausule_t *case_list)
1206 switch_statement_t *ret = parser_alloc(ctx, sizeof(switch_statement_t));
1208 ret->stat.eval = switch_statement_eval;
1209 ret->stat.next = NULL;
1211 ret->case_list = case_list;
1216 static statement_t *new_throw_statement(parser_ctx_t *ctx, expression_t *expr)
1218 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1220 ret->stat.eval = throw_statement_eval;
1221 ret->stat.next = NULL;
1227 static statement_t *new_try_statement(parser_ctx_t *ctx, statement_t *try_statement,
1228 catch_block_t *catch_block, statement_t *finally_statement)
1230 try_statement_t *ret = parser_alloc(ctx, sizeof(try_statement_t));
1232 ret->stat.eval = try_statement_eval;
1233 ret->stat.next = NULL;
1234 ret->try_statement = try_statement;
1235 ret->catch_block = catch_block;
1236 ret->finally_statement = finally_statement;
1241 static parameter_t *new_parameter(parser_ctx_t *ctx, const WCHAR *identifier)
1243 parameter_t *ret = parser_alloc(ctx, sizeof(parameter_t));
1245 ret->identifier = identifier;
1251 static parameter_list_t *new_parameter_list(parser_ctx_t *ctx, const WCHAR *identifier)
1253 parameter_list_t *ret = parser_alloc_tmp(ctx, sizeof(parameter_list_t));
1255 ret->head = ret->tail = new_parameter(ctx, identifier);
1260 static parameter_list_t *parameter_list_add(parser_ctx_t *ctx, parameter_list_t *list, const WCHAR *identifier)
1262 list->tail = list->tail->next = new_parameter(ctx, identifier);
1267 static expression_t *new_function_expression(parser_ctx_t *ctx, const WCHAR *identifier,
1268 parameter_list_t *parameter_list, source_elements_t *source_elements, const WCHAR *src_str, DWORD src_len)
1270 function_expression_t *ret = parser_alloc(ctx, sizeof(function_expression_t));
1272 ret->expr.eval = function_expression_eval;
1273 ret->identifier = identifier;
1274 ret->parameter_list = parameter_list ? parameter_list->head : NULL;
1275 ret->source_elements = source_elements;
1276 ret->src_str = src_str;
1277 ret->src_len = src_len;
1279 if(ret->identifier) {
1280 function_declaration_t *decl = parser_alloc(ctx, sizeof(function_declaration_t));
1285 if(ctx->func_stack->func_tail)
1286 ctx->func_stack->func_tail = ctx->func_stack->func_tail->next = decl;
1288 ctx->func_stack->func_head = ctx->func_stack->func_tail = decl;
1294 static const expression_eval_t expression_eval_table[] = {
1295 comma_expression_eval,
1296 logical_or_expression_eval,
1297 logical_and_expression_eval,
1298 binary_or_expression_eval,
1299 binary_xor_expression_eval,
1300 binary_and_expression_eval,
1301 instanceof_expression_eval,
1303 add_expression_eval,
1304 sub_expression_eval,
1305 mul_expression_eval,
1306 div_expression_eval,
1307 mod_expression_eval,
1308 delete_expression_eval,
1309 void_expression_eval,
1310 typeof_expression_eval,
1311 minus_expression_eval,
1312 plus_expression_eval,
1313 post_increment_expression_eval,
1314 post_decrement_expression_eval,
1315 pre_increment_expression_eval,
1316 pre_decrement_expression_eval,
1317 equal_expression_eval,
1318 equal2_expression_eval,
1319 not_equal_expression_eval,
1320 not_equal2_expression_eval,
1321 less_expression_eval,
1322 lesseq_expression_eval,
1323 greater_expression_eval,
1324 greatereq_expression_eval,
1325 binary_negation_expression_eval,
1326 logical_negation_expression_eval,
1327 left_shift_expression_eval,
1328 right_shift_expression_eval,
1329 right2_shift_expression_eval,
1330 assign_expression_eval,
1331 assign_lshift_expression_eval,
1332 assign_rshift_expression_eval,
1333 assign_rrshift_expression_eval,
1334 assign_add_expression_eval,
1335 assign_sub_expression_eval,
1336 assign_mul_expression_eval,
1337 assign_div_expression_eval,
1338 assign_mod_expression_eval,
1339 assign_and_expression_eval,
1340 assign_or_expression_eval,
1341 assign_xor_expression_eval,
1344 static expression_t *new_binary_expression(parser_ctx_t *ctx, expression_type_t type,
1345 expression_t *expression1, expression_t *expression2)
1347 binary_expression_t *ret = parser_alloc(ctx, sizeof(binary_expression_t));
1349 ret->expr.eval = expression_eval_table[type];
1350 ret->expression1 = expression1;
1351 ret->expression2 = expression2;
1356 static expression_t *new_unary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *expression)
1358 unary_expression_t *ret = parser_alloc(ctx, sizeof(unary_expression_t));
1360 ret->expr.eval = expression_eval_table[type];
1361 ret->expression = expression;
1366 static expression_t *new_conditional_expression(parser_ctx_t *ctx, expression_t *expression,
1367 expression_t *true_expression, expression_t *false_expression)
1369 conditional_expression_t *ret = parser_alloc(ctx, sizeof(conditional_expression_t));
1371 ret->expr.eval = conditional_expression_eval;
1372 ret->expression = expression;
1373 ret->true_expression = true_expression;
1374 ret->false_expression = false_expression;
1379 static expression_t *new_array_expression(parser_ctx_t *ctx, expression_t *member_expr, expression_t *expression)
1381 array_expression_t *ret = parser_alloc(ctx, sizeof(array_expression_t));
1383 ret->expr.eval = array_expression_eval;
1384 ret->member_expr = member_expr;
1385 ret->expression = expression;
1390 static expression_t *new_member_expression(parser_ctx_t *ctx, expression_t *expression, const WCHAR *identifier)
1392 member_expression_t *ret = parser_alloc(ctx, sizeof(member_expression_t));
1394 ret->expr.eval = member_expression_eval;
1395 ret->expression = expression;
1396 ret->identifier = identifier;
1401 static expression_t *new_new_expression(parser_ctx_t *ctx, expression_t *expression, argument_list_t *argument_list)
1403 call_expression_t *ret = parser_alloc(ctx, sizeof(call_expression_t));
1405 ret->expr.eval = new_expression_eval;
1406 ret->expression = expression;
1407 ret->argument_list = argument_list ? argument_list->head : NULL;
1412 static expression_t *new_call_expression(parser_ctx_t *ctx, expression_t *expression, argument_list_t *argument_list)
1414 call_expression_t *ret = parser_alloc(ctx, sizeof(call_expression_t));
1416 ret->expr.eval = call_expression_eval;
1417 ret->expression = expression;
1418 ret->argument_list = argument_list ? argument_list->head : NULL;
1423 static expression_t *new_this_expression(parser_ctx_t *ctx)
1425 expression_t *ret = parser_alloc(ctx, sizeof(expression_t));
1427 ret->eval = this_expression_eval;
1432 static int parser_error(const char *str)
1437 static expression_t *new_identifier_expression(parser_ctx_t *ctx, const WCHAR *identifier)
1439 identifier_expression_t *ret = parser_alloc(ctx, sizeof(identifier_expression_t));
1441 ret->expr.eval = identifier_expression_eval;
1442 ret->identifier = identifier;
1447 static expression_t *new_array_literal_expression(parser_ctx_t *ctx, element_list_t *element_list, int length)
1449 array_literal_expression_t *ret = parser_alloc(ctx, sizeof(array_literal_expression_t));
1451 ret->expr.eval = array_literal_expression_eval;
1452 ret->element_list = element_list ? element_list->head : NULL;
1453 ret->length = length;
1458 static expression_t *new_prop_and_value_expression(parser_ctx_t *ctx, property_list_t *property_list)
1460 property_value_expression_t *ret = parser_alloc(ctx, sizeof(property_value_expression_t));
1462 ret->expr.eval = property_value_expression_eval;
1463 ret->property_list = property_list ? property_list->head : NULL;
1468 static expression_t *new_literal_expression(parser_ctx_t *ctx, literal_t *literal)
1470 literal_expression_t *ret = parser_alloc(ctx, sizeof(literal_expression_t));
1472 ret->expr.eval = literal_expression_eval;
1473 ret->literal = literal;
1478 static source_elements_t *new_source_elements(parser_ctx_t *ctx)
1480 source_elements_t *ret = parser_alloc(ctx, sizeof(source_elements_t));
1482 memset(ret, 0, sizeof(*ret));
1487 static source_elements_t *source_elements_add_statement(source_elements_t *source_elements, statement_t *statement)
1489 if(source_elements->statement_tail)
1490 source_elements->statement_tail = source_elements->statement_tail->next = statement;
1492 source_elements->statement = source_elements->statement_tail = statement;
1494 return source_elements;
1497 static statement_list_t *new_statement_list(parser_ctx_t *ctx, statement_t *statement)
1499 statement_list_t *ret = parser_alloc_tmp(ctx, sizeof(statement_list_t));
1501 ret->head = ret->tail = statement;
1506 static statement_list_t *statement_list_add(statement_list_t *list, statement_t *statement)
1508 list->tail = list->tail->next = statement;
1513 static void push_func(parser_ctx_t *ctx)
1515 func_stack_t *new_func = parser_alloc_tmp(ctx, sizeof(func_stack_t));
1517 new_func->func_head = new_func->func_tail = NULL;
1518 new_func->var_head = new_func->var_tail = NULL;
1520 new_func->next = ctx->func_stack;
1521 ctx->func_stack = new_func;
1524 static source_elements_t *function_body_parsed(parser_ctx_t *ctx, source_elements_t *source)
1526 source->functions = ctx->func_stack->func_head;
1527 source->variables = ctx->func_stack->var_head;
1533 static void program_parsed(parser_ctx_t *ctx, source_elements_t *source)
1535 source->functions = ctx->func_stack->func_head;
1536 source->variables = ctx->func_stack->var_head;
1539 ctx->source = source;
1543 void parser_release(parser_ctx_t *ctx)
1545 obj_literal_t *iter;
1550 for(iter = ctx->obj_literals; iter; iter = iter->next)
1551 jsdisp_release(iter->obj);
1553 jsheap_free(&ctx->heap);
1557 HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, const WCHAR *delimiter,
1560 parser_ctx_t *parser_ctx;
1564 const WCHAR html_tagW[] = {'<','/','s','c','r','i','p','t','>',0};
1566 parser_ctx = heap_alloc_zero(sizeof(parser_ctx_t));
1568 return E_OUTOFMEMORY;
1570 parser_ctx->ref = 1;
1571 parser_ctx->hres = E_FAIL;
1572 parser_ctx->is_html = delimiter && !strcmpiW(delimiter, html_tagW);
1574 parser_ctx->begin = parser_ctx->ptr = code;
1575 parser_ctx->end = code + strlenW(code);
1578 parser_ctx->script = ctx;
1580 mark = jsheap_mark(&ctx->tmp_heap);
1581 jsheap_init(&parser_ctx->heap);
1583 push_func(parser_ctx);
1585 parser_parse(parser_ctx);
1587 if(FAILED(parser_ctx->hres)) {
1588 hres = parser_ctx->hres;
1589 parser_release(parser_ctx);