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 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(jscript);
28 #define YYLEX_PARAM ctx
29 #define YYPARSE_PARAM ctx
31 static int parser_error(const char*);
32 static BOOL allow_auto_semicolon(parser_ctx_t*);
33 static void program_parsed(parser_ctx_t*,source_elements_t*);
35 typedef struct _statement_list_t {
40 static literal_t *new_string_literal(parser_ctx_t*,const WCHAR*);
41 static literal_t *new_null_literal(parser_ctx_t*);
42 static literal_t *new_undefined_literal(parser_ctx_t*);
43 static literal_t *new_boolean_literal(parser_ctx_t*,VARIANT_BOOL);
45 typedef struct _property_list_t {
50 static property_list_t *new_property_list(parser_ctx_t*,literal_t*,expression_t*);
51 static property_list_t *property_list_add(parser_ctx_t*,property_list_t*,literal_t*,expression_t*);
53 typedef struct _element_list_t {
54 array_element_t *head;
55 array_element_t *tail;
58 static element_list_t *new_element_list(parser_ctx_t*,int,expression_t*);
59 static element_list_t *element_list_add(parser_ctx_t*,element_list_t*,int,expression_t*);
61 typedef struct _argument_list_t {
66 static argument_list_t *new_argument_list(parser_ctx_t*,expression_t*);
67 static argument_list_t *argument_list_add(parser_ctx_t*,argument_list_t*,expression_t*);
69 typedef struct _case_list_t {
70 case_clausule_t *head;
71 case_clausule_t *tail;
74 static catch_block_t *new_catch_block(parser_ctx_t*,const WCHAR*,statement_t*);
75 static case_clausule_t *new_case_clausule(parser_ctx_t*,expression_t*,statement_list_t*);
76 static case_list_t *new_case_list(parser_ctx_t*,case_clausule_t*);
77 static case_list_t *case_list_add(parser_ctx_t*,case_list_t*,case_clausule_t*);
78 static case_clausule_t *new_case_block(parser_ctx_t*,case_list_t*,case_clausule_t*,case_list_t*);
80 typedef struct _variable_list_t {
81 variable_declaration_t *head;
82 variable_declaration_t *tail;
85 static variable_declaration_t *new_variable_declaration(parser_ctx_t*,const WCHAR*,expression_t*);
86 static variable_list_t *new_variable_list(parser_ctx_t*,variable_declaration_t*);
87 static variable_list_t *variable_list_add(parser_ctx_t*,variable_list_t*,variable_declaration_t*);
89 static statement_t *new_block_statement(parser_ctx_t*,statement_list_t*);
90 static statement_t *new_var_statement(parser_ctx_t*,variable_list_t*);
91 static statement_t *new_empty_statement(parser_ctx_t*);
92 static statement_t *new_expression_statement(parser_ctx_t*,expression_t*);
93 static statement_t *new_if_statement(parser_ctx_t*,expression_t*,statement_t*,statement_t*);
94 static statement_t *new_while_statement(parser_ctx_t*,BOOL,expression_t*,statement_t*);
95 static statement_t *new_for_statement(parser_ctx_t*,variable_list_t*,expression_t*,expression_t*,
96 expression_t*,statement_t*);
97 static statement_t *new_forin_statement(parser_ctx_t*,variable_declaration_t*,expression_t*,expression_t*,statement_t*);
98 static statement_t *new_continue_statement(parser_ctx_t*,const WCHAR*);
99 static statement_t *new_break_statement(parser_ctx_t*,const WCHAR*);
100 static statement_t *new_return_statement(parser_ctx_t*,expression_t*);
101 static statement_t *new_with_statement(parser_ctx_t*,expression_t*,statement_t*);
102 static statement_t *new_labelled_statement(parser_ctx_t*,const WCHAR*,statement_t*);
103 static statement_t *new_switch_statement(parser_ctx_t*,expression_t*,case_clausule_t*);
104 static statement_t *new_throw_statement(parser_ctx_t*,expression_t*);
105 static statement_t *new_try_statement(parser_ctx_t*,statement_t*,catch_block_t*,statement_t*);
107 struct statement_list_t {
112 statement_list_t *new_statement_list(parser_ctx_t*,statement_t*);
113 statement_list_t *statement_list_add(statement_list_t*,statement_t*);
115 typedef struct _parameter_list_t {
120 static parameter_list_t *new_parameter_list(parser_ctx_t*,const WCHAR*);
121 static parameter_list_t *parameter_list_add(parser_ctx_t*,parameter_list_t*,const WCHAR*);
123 static expression_t *new_function_expression(parser_ctx_t*,const WCHAR*,parameter_list_t*,source_elements_t*);
124 static expression_t *new_binary_expression(parser_ctx_t*,expression_type_t,expression_t*,expression_t*);
125 static expression_t *new_unary_expression(parser_ctx_t*,expression_type_t,expression_t*);
126 static expression_t *new_conditional_expression(parser_ctx_t*,expression_t*,expression_t*,expression_t*);
127 static expression_t *new_array_expression(parser_ctx_t*,expression_t*,expression_t*);
128 static expression_t *new_member_expression(parser_ctx_t*,expression_t*,const WCHAR*);
129 static expression_t *new_member_new_expression(parser_ctx_t*,expression_t*,argument_list_t*);
130 static expression_t *new_call_expression(parser_ctx_t*,expression_t*,argument_list_t*);
131 static expression_t *new_this_expression(parser_ctx_t*);
132 static expression_t *new_identifier_expression(parser_ctx_t*,const WCHAR*);
133 static expression_t *new_literal_expression(parser_ctx_t*,literal_t*);
134 static expression_t *new_array_literal_expression(parser_ctx_t*,element_list_t*,int);
135 static expression_t *new_prop_and_value_expression(parser_ctx_t*,property_list_t*);
137 static function_declaration_t *new_function_declaration(parser_ctx_t*,const WCHAR*,parameter_list_t*,source_elements_t*);
138 static source_elements_t *new_source_elements(parser_ctx_t*);
139 static source_elements_t *source_elements_add_statement(source_elements_t*,statement_t*);
140 static source_elements_t *source_elements_add_function(source_elements_t*,function_declaration_t*);
151 struct _argument_list_t *argument_list;
152 case_clausule_t *case_clausule;
153 struct _case_list_t *case_list;
154 catch_block_t *catch_block;
155 struct _element_list_t *element_list;
157 const WCHAR *identifier;
158 function_declaration_t *function_declaration;
159 struct _parameter_list_t *parameter_list;
160 struct _property_list_t *property_list;
161 source_elements_t *source_elements;
162 statement_t *statement;
163 struct _statement_list_t *statement_list;
164 struct _variable_list_t *variable_list;
165 variable_declaration_t *variable_declaration;
169 %token kBREAK kCASE kCATCH kCONTINUE kDEFAULT kDELETE kDO kELSE kIF kFINALLY kFOR kFUNCTION kIN
170 %token kINSTANCEOF kNEW kNULL kUNDEFINED kRETURN kSWITCH kTHIS kTHROW kTRUE kFALSE kTRY kTYPEOF kVAR kVOID kWHILE kWITH
171 %token tANDAND tOROR tINC tDEC
174 %token <identifier> tIdentifier
175 %token <ival> tAssignOper tEqOper tShiftOper tRelOper
176 %token <literal> tNumericLiteral
177 %token <wstr> tStringLiteral
179 %type <source_elements> SourceElements
180 %type <source_elements> FunctionBody
181 %type <statement> Statement
182 %type <statement> Block
183 %type <statement> VariableStatement
184 %type <statement> EmptyStatement
185 %type <statement> ExpressionStatement
186 %type <statement> IfStatement
187 %type <statement> IterationStatement
188 %type <statement> ContinueStatement
189 %type <statement> BreakStatement
190 %type <statement> ReturnStatement
191 %type <statement> WithStatement
192 %type <statement> LabelledStatement
193 %type <statement> SwitchStatement
194 %type <statement> ThrowStatement
195 %type <statement> TryStatement
196 %type <statement> Finally
197 %type <statement_list> StatementList StatementList_opt
198 %type <function_declaration> FunctionDeclaration
199 %type <parameter_list> FormalParameterList FormalParameterList_opt
200 %type <expr> Expression Expression_opt
201 %type <expr> ExpressionNoIn ExpressionNoIn_opt
202 %type <expr> FunctionExpression
203 %type <expr> AssignmentExpression AssignmentExpressionNoIn
204 %type <expr> ConditionalExpression ConditionalExpressionNoIn
205 %type <expr> LeftHandSideExpression
206 %type <expr> LogicalORExpression LogicalORExpressionNoIn
207 %type <expr> LogicalANDExpression LogicalANDExpressionNoIn
208 %type <expr> BitwiseORExpression BitwiseORExpressionNoIn
209 %type <expr> BitwiseXORExpression BitwiseXORExpressionNoIn
210 %type <expr> BitwiseANDExpression BitwiseANDExpressionNoIn
211 %type <expr> EqualityExpression EqualityExpressionNoIn
212 %type <expr> RelationalExpression RelationalExpressionNoIn
213 %type <expr> ShiftExpression
214 %type <expr> AdditiveExpression
215 %type <expr> MultiplicativeExpression
216 %type <expr> Initialiser_opt Initialiser
217 %type <expr> InitialiserNoIn_opt InitialiserNoIn
218 %type <expr> UnaryExpression
219 %type <expr> PostfixExpression
220 %type <expr> NewExpression
221 %type <expr> CallExpression
222 %type <expr> MemberExpression
223 %type <expr> PrimaryExpression
224 %type <identifier> Identifier_opt
225 %type <variable_list> VariableDeclarationList
226 %type <variable_list> VariableDeclarationListNoIn
227 %type <variable_declaration> VariableDeclaration
228 %type <variable_declaration> VariableDeclarationNoIn
229 %type <case_list> CaseClausules CaseClausules_opt
230 %type <case_clausule> CaseClausule DefaultClausule CaseBlock
231 %type <catch_block> Catch
232 %type <argument_list> Arguments
233 %type <argument_list> ArgumentList
234 %type <literal> Literal
235 %type <expr> ArrayLiteral
236 %type <expr> ObjectLiteral
237 %type <ival> Elision Elision_opt
238 %type <element_list> ElementList
239 %type <property_list> PropertyNameAndValueList
240 %type <literal> PropertyName
241 %type <literal> BooleanLiteral
245 /* ECMA-262 3rd Edition 14 */
247 : SourceElements { program_parsed(ctx, $1); }
249 /* ECMA-262 3rd Edition 14 */
251 : /* empty */ { $$ = new_source_elements(ctx); }
252 | SourceElements Statement
253 { $$ = source_elements_add_statement($1, $2); }
254 | SourceElements FunctionDeclaration
255 { $$ = source_elements_add_function($1, $2); }
257 /* ECMA-262 3rd Edition 13 */
259 : kFUNCTION tIdentifier '(' FormalParameterList_opt ')' '{' FunctionBody '}'
260 { $$ = new_function_declaration(ctx, $2, $4, $7); }
262 /* ECMA-262 3rd Edition 13 */
264 : kFUNCTION Identifier_opt '(' FormalParameterList_opt ')' '{' FunctionBody '}'
265 { $$ = new_function_expression(ctx, $2, $4, $7); }
267 /* ECMA-262 3rd Edition 13 */
269 : SourceElements { $$ = $1; }
271 /* ECMA-262 3rd Edition 13 */
273 : tIdentifier { $$ = new_parameter_list(ctx, $1); }
274 | FormalParameterList ',' tIdentifier
275 { $$ = parameter_list_add(ctx, $1, $3); }
277 /* ECMA-262 3rd Edition 13 */
278 FormalParameterList_opt
279 : /* empty */ { $$ = NULL; }
280 | FormalParameterList { $$ = $1; }
282 /* ECMA-262 3rd Edition 12 */
285 | VariableStatement { $$ = $1; }
286 | EmptyStatement { $$ = $1; }
287 | ExpressionStatement { $$ = $1; }
288 | IfStatement { $$ = $1; }
289 | IterationStatement { $$ = $1; }
290 | ContinueStatement { $$ = $1; }
291 | BreakStatement { $$ = $1; }
292 | ReturnStatement { $$ = $1; }
293 | WithStatement { $$ = $1; }
294 | LabelledStatement { $$ = $1; }
295 | SwitchStatement { $$ = $1; }
296 | ThrowStatement { $$ = $1; }
297 | TryStatement { $$ = $1; }
299 /* ECMA-262 3rd Edition 12.2 */
301 : Statement { $$ = new_statement_list(ctx, $1); }
302 | StatementList Statement
303 { $$ = statement_list_add($1, $2); }
305 /* ECMA-262 3rd Edition 12.2 */
307 : /* empty */ { $$ = NULL; }
308 | StatementList { $$ = $1; }
310 /* ECMA-262 3rd Edition 12.1 */
312 : '{' StatementList_opt '}'
313 { $$ = new_block_statement(ctx, $2); }
315 /* ECMA-262 3rd Edition 12.2 */
317 : kVAR VariableDeclarationList semicolon_opt
318 { $$ = new_var_statement(ctx, $2); }
320 /* ECMA-262 3rd Edition 12.2 */
321 VariableDeclarationList
322 : VariableDeclaration { $$ = new_variable_list(ctx, $1); }
323 | VariableDeclarationList ',' VariableDeclaration
324 { $$ = variable_list_add(ctx, $1, $3); }
326 /* ECMA-262 3rd Edition 12.2 */
327 VariableDeclarationListNoIn
328 : VariableDeclarationNoIn
329 { $$ = new_variable_list(ctx, $1); }
330 | VariableDeclarationListNoIn ',' VariableDeclarationNoIn
331 { $$ = variable_list_add(ctx, $1, $3); }
333 /* ECMA-262 3rd Edition 12.2 */
335 : tIdentifier Initialiser_opt
336 { $$ = new_variable_declaration(ctx, $1, $2); }
338 /* ECMA-262 3rd Edition 12.2 */
339 VariableDeclarationNoIn
340 : tIdentifier InitialiserNoIn_opt
341 { $$ = new_variable_declaration(ctx, $1, $2); }
343 /* ECMA-262 3rd Edition 12.2 */
345 : /* empty */ { $$ = NULL; }
346 | Initialiser { $$ = $1; }
348 /* ECMA-262 3rd Edition 12.2 */
350 : '=' AssignmentExpression
353 /* ECMA-262 3rd Edition 12.2 */
355 : /* empty */ { $$ = NULL; }
356 | InitialiserNoIn { $$ = $1; }
358 /* ECMA-262 3rd Edition 12.2 */
360 : '=' AssignmentExpressionNoIn
363 /* ECMA-262 3rd Edition 12.3 */
365 : ';' { $$ = new_empty_statement(ctx); }
367 /* ECMA-262 3rd Edition 12.4 */
369 : Expression semicolon_opt
370 { $$ = new_expression_statement(ctx, $1); }
372 /* ECMA-262 3rd Edition 12.5 */
374 : kIF '(' Expression ')' Statement kELSE Statement
375 { $$ = new_if_statement(ctx, $3, $5, $7); }
376 | kIF '(' Expression ')' Statement
377 { $$ = new_if_statement(ctx, $3, $5, NULL); }
379 /* ECMA-262 3rd Edition 12.6 */
381 : kDO Statement kWHILE '(' Expression ')' ';'
382 { $$ = new_while_statement(ctx, TRUE, $5, $2); }
383 | kWHILE '(' Expression ')' Statement
384 { $$ = new_while_statement(ctx, FALSE, $3, $5); }
385 | kFOR '(' ExpressionNoIn_opt ';' Expression_opt ';' Expression_opt ')' Statement
386 { $$ = new_for_statement(ctx, NULL, $3, $5, $7, $9); }
387 | kFOR '(' kVAR VariableDeclarationListNoIn ';' Expression_opt ';' Expression_opt ')' Statement
388 { $$ = new_for_statement(ctx, $4, NULL, $6, $8, $10); }
389 | kFOR '(' LeftHandSideExpression kIN Expression ')' Statement
390 { $$ = new_forin_statement(ctx, NULL, $3, $5, $7); }
391 | kFOR '(' kVAR VariableDeclarationNoIn kIN Expression ')' Statement
392 { $$ = new_forin_statement(ctx, $4, NULL, $6, $8); }
394 /* ECMA-262 3rd Edition 12.7 */
396 : kCONTINUE /* NONL */ Identifier_opt semicolon_opt
397 { $$ = new_continue_statement(ctx, $2); }
399 /* ECMA-262 3rd Edition 12.8 */
401 : kBREAK /* NONL */ Identifier_opt semicolon_opt
402 { $$ = new_break_statement(ctx, $2); }
404 /* ECMA-262 3rd Edition 12.9 */
406 : kRETURN /* NONL */ Expression_opt semicolon_opt
407 { $$ = new_return_statement(ctx, $2); }
409 /* ECMA-262 3rd Edition 12.10 */
411 : kWITH '(' Expression ')' Statement
412 { $$ = new_with_statement(ctx, $3, $5); }
414 /* ECMA-262 3rd Edition 12.12 */
416 : tIdentifier ':' Statement
417 { $$ = new_labelled_statement(ctx, $1, $3); }
419 /* ECMA-262 3rd Edition 12.11 */
421 : kSWITCH '(' Expression ')' CaseBlock
422 { $$ = new_switch_statement(ctx, $3, $5); }
424 /* ECMA-262 3rd Edition 12.11 */
426 : '{' CaseClausules_opt '}'
427 { $$ = new_case_block(ctx, $2, NULL, NULL); }
428 | '{' CaseClausules_opt DefaultClausule CaseClausules_opt '}'
429 { $$ = new_case_block(ctx, $2, $3, $4); }
431 /* ECMA-262 3rd Edition 12.11 */
433 : /* empty */ { $$ = NULL; }
434 | CaseClausules { $$ = $1; }
436 /* ECMA-262 3rd Edition 12.11 */
438 : CaseClausule { $$ = new_case_list(ctx, $1); }
439 | CaseClausules CaseClausule
440 { $$ = case_list_add(ctx, $1, $2); }
442 /* ECMA-262 3rd Edition 12.11 */
444 : kCASE Expression ':' StatementList_opt
445 { $$ = new_case_clausule(ctx, $2, $4); }
447 /* ECMA-262 3rd Edition 12.11 */
449 : kDEFAULT ':' StatementList_opt
450 { $$ = new_case_clausule(ctx, NULL, $3); }
452 /* ECMA-262 3rd Edition 12.13 */
454 : kTHROW /* NONL */ Expression semicolon_opt
455 { $$ = new_throw_statement(ctx, $2); }
457 /* ECMA-262 3rd Edition 12.14 */
459 : kTRY Block Catch { $$ = new_try_statement(ctx, $2, $3, NULL); }
460 | kTRY Block Finally { $$ = new_try_statement(ctx, $2, NULL, $3); }
461 | kTRY Block Catch Finally
462 { $$ = new_try_statement(ctx, $2, $3, $4); }
464 /* ECMA-262 3rd Edition 12.14 */
466 : kCATCH '(' tIdentifier ')' Block
467 { $$ = new_catch_block(ctx, $3, $5); }
469 /* ECMA-262 3rd Edition 12.14 */
471 : kFINALLY Block { $$ = $2; }
473 /* ECMA-262 3rd Edition 11.14 */
475 : /* empty */ { $$ = NULL; }
476 | Expression { $$ = $1; }
478 /* ECMA-262 3rd Edition 11.14 */
480 : AssignmentExpression { $$ = $1; }
481 | Expression ',' AssignmentExpression
482 { $$ = new_binary_expression(ctx, EXPR_COMMA, $1, $3); }
484 /* ECMA-262 3rd Edition 11.14 */
486 : /* empty */ { $$ = NULL; }
487 | ExpressionNoIn { $$ = $1; }
489 /* ECMA-262 3rd Edition 11.14 */
491 : AssignmentExpressionNoIn
493 | ExpressionNoIn ',' AssignmentExpressionNoIn
494 { $$ = new_binary_expression(ctx, EXPR_COMMA, $1, $3); }
496 /* ECMA-262 3rd Edition 11.13 */
498 : ConditionalExpression { $$ = $1; }
499 | LeftHandSideExpression '=' AssignmentExpression
500 { $$ = new_binary_expression(ctx, EXPR_ASSIGN, $1, $3); }
501 | LeftHandSideExpression tAssignOper AssignmentExpression
502 { $$ = new_binary_expression(ctx, $2, $1, $3); }
504 /* ECMA-262 3rd Edition 11.13 */
505 AssignmentExpressionNoIn
506 : ConditionalExpressionNoIn
508 | LeftHandSideExpression '=' AssignmentExpressionNoIn
509 { $$ = new_binary_expression(ctx, EXPR_ASSIGN, $1, $3); }
510 | LeftHandSideExpression tAssignOper AssignmentExpressionNoIn
511 { $$ = new_binary_expression(ctx, $2, $1, $3); }
513 /* ECMA-262 3rd Edition 11.12 */
514 ConditionalExpression
515 : LogicalORExpression { $$ = $1; }
516 | LogicalORExpression '?' AssignmentExpression ':' AssignmentExpression
517 { $$ = new_conditional_expression(ctx, $1, $3, $5); }
519 /* ECMA-262 3rd Edition 11.12 */
520 ConditionalExpressionNoIn
521 : LogicalORExpressionNoIn
523 | LogicalORExpressionNoIn '?' AssignmentExpressionNoIn ':' AssignmentExpressionNoIn
524 { $$ = new_conditional_expression(ctx, $1, $3, $5); }
526 /* ECMA-262 3rd Edition 11.11 */
528 : LogicalANDExpression { $$ = $1; }
529 | LogicalORExpression tOROR LogicalANDExpression
530 { $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); }
532 /* ECMA-262 3rd Edition 11.11 */
533 LogicalORExpressionNoIn
534 : LogicalANDExpressionNoIn
536 | LogicalORExpressionNoIn tOROR LogicalANDExpressionNoIn
537 { $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); }
539 /* ECMA-262 3rd Edition 11.11 */
541 : BitwiseORExpression { $$ = $1; }
542 | LogicalANDExpression tANDAND BitwiseORExpression
543 { $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); }
545 /* ECMA-262 3rd Edition 11.11 */
546 LogicalANDExpressionNoIn
547 : BitwiseORExpressionNoIn
549 | LogicalANDExpressionNoIn tANDAND BitwiseORExpressionNoIn
550 { $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); }
552 /* ECMA-262 3rd Edition 11.10 */
554 : BitwiseXORExpression { $$ = $1; }
555 | BitwiseORExpression '|' BitwiseXORExpression
556 { $$ = new_binary_expression(ctx, EXPR_BOR, $1, $3); }
558 /* ECMA-262 3rd Edition 11.10 */
559 BitwiseORExpressionNoIn
560 : BitwiseXORExpressionNoIn
562 | BitwiseORExpressionNoIn '|' BitwiseXORExpressionNoIn
563 { $$ = new_binary_expression(ctx, EXPR_BOR, $1, $3); }
565 /* ECMA-262 3rd Edition 11.10 */
567 : BitwiseANDExpression { $$ = $1; }
568 | BitwiseXORExpression '^' BitwiseANDExpression
569 { new_binary_expression(ctx, EXPR_BXOR, $1, $3); }
571 /* ECMA-262 3rd Edition 11.10 */
572 BitwiseXORExpressionNoIn
573 : BitwiseANDExpressionNoIn
575 | BitwiseXORExpressionNoIn '^' BitwiseANDExpressionNoIn
576 { new_binary_expression(ctx, EXPR_BXOR, $1, $3); }
578 /* ECMA-262 3rd Edition 11.10 */
580 : EqualityExpression { $$ = $1; }
581 | BitwiseANDExpression '&' EqualityExpression
582 { new_binary_expression(ctx, EXPR_BAND, $1, $3); }
584 /* ECMA-262 3rd Edition 11.10 */
585 BitwiseANDExpressionNoIn
586 : EqualityExpressionNoIn
588 | BitwiseANDExpressionNoIn '&' EqualityExpressionNoIn
589 { new_binary_expression(ctx, EXPR_BAND, $1, $3); }
591 /* ECMA-262 3rd Edition 11.9 */
593 : RelationalExpression { $$ = $1; }
594 | EqualityExpression tEqOper RelationalExpression
595 { $$ = new_binary_expression(ctx, $2, $1, $3); }
597 /* ECMA-262 3rd Edition 11.9 */
598 EqualityExpressionNoIn
599 : RelationalExpressionNoIn { $$ = $1; }
600 | EqualityExpressionNoIn tEqOper RelationalExpressionNoIn
601 { $$ = new_binary_expression(ctx, $2, $1, $3); }
603 /* ECMA-262 3rd Edition 11.8 */
605 : ShiftExpression { $$ = $1; }
606 | RelationalExpression tRelOper ShiftExpression
607 { $$ = new_binary_expression(ctx, $2, $1, $3); }
608 | RelationalExpression kINSTANCEOF ShiftExpression
609 { $$ = new_binary_expression(ctx, EXPR_INSTANCEOF, $1, $3); }
610 | RelationalExpression kIN ShiftExpression
611 { $$ = new_binary_expression(ctx, EXPR_IN, $1, $3); }
613 /* ECMA-262 3rd Edition 11.8 */
614 RelationalExpressionNoIn
615 : ShiftExpression { $$ = $1; }
616 | RelationalExpressionNoIn tRelOper ShiftExpression
617 { $$ = new_binary_expression(ctx, $2, $1, $3); }
618 | RelationalExpressionNoIn kINSTANCEOF ShiftExpression
619 { $$ = new_binary_expression(ctx, EXPR_INSTANCEOF, $1, $3); }
621 /* ECMA-262 3rd Edition 11.7 */
623 : AdditiveExpression { $$ = $1; }
624 | ShiftExpression tShiftOper AdditiveExpression
625 { $$ = new_binary_expression(ctx, $2, $1, $3); }
627 /* ECMA-262 3rd Edition 11.6 */
629 : MultiplicativeExpression
631 | AdditiveExpression '+' MultiplicativeExpression
632 { $$ = new_binary_expression(ctx, EXPR_ADD, $1, $3); }
633 | AdditiveExpression '-' MultiplicativeExpression
634 { $$ = new_binary_expression(ctx, EXPR_SUB, $1, $3); }
636 /* ECMA-262 3rd Edition 11.5 */
637 MultiplicativeExpression
638 : UnaryExpression { $$ = $1; }
639 | MultiplicativeExpression '*' UnaryExpression
640 { $$ = new_binary_expression(ctx, EXPR_MUL, $1, $3); }
641 | MultiplicativeExpression '/' UnaryExpression
642 { $$ = new_binary_expression(ctx, EXPR_DIV, $1, $3); }
643 | MultiplicativeExpression '%' UnaryExpression
644 { $$ = new_binary_expression(ctx, EXPR_MOD, $1, $3); }
646 /* ECMA-262 3rd Edition 11.4 */
648 : PostfixExpression { $$ = $1; }
649 | kDELETE UnaryExpression
650 { $$ = new_unary_expression(ctx, EXPR_DELETE, $2); }
651 | kVOID UnaryExpression { $$ = new_unary_expression(ctx, EXPR_VOID, $2); }
652 | kTYPEOF UnaryExpression
653 { $$ = new_unary_expression(ctx, EXPR_TYPEOF, $2); }
654 | tINC UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PREINC, $2); }
655 | tDEC UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PREDEC, $2); }
656 | '+' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PLUS, $2); }
657 | '-' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_MINUS, $2); }
658 | '~' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_BITNEG, $2); }
659 | '!' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_LOGNEG, $2); }
661 /* ECMA-262 3rd Edition 11.2 */
663 : LeftHandSideExpression
665 | LeftHandSideExpression /* NONL */ tINC
666 { $$ = new_unary_expression(ctx, EXPR_POSTINC, $1); }
667 | LeftHandSideExpression /* NONL */ tDEC
668 { $$ = new_unary_expression(ctx, EXPR_POSTDEC, $1); }
671 /* ECMA-262 3rd Edition 11.2 */
672 LeftHandSideExpression
673 : NewExpression { $$ = $1; }
674 | CallExpression { $$ = $1; }
676 /* ECMA-262 3rd Edition 11.2 */
678 : MemberExpression { $$ = $1; }
679 | kNEW NewExpression { $$ = new_unary_expression(ctx, EXPR_NEW, $2); }
681 /* ECMA-262 3rd Edition 11.2 */
683 : PrimaryExpression { $$ = $1; }
684 | FunctionExpression { $$ = $1; }
685 | MemberExpression '[' Expression ']'
686 { $$ = new_array_expression(ctx, $1, $3); }
687 | MemberExpression '.' tIdentifier
688 { $$ = new_member_expression(ctx, $1, $3); }
689 | kNEW MemberExpression Arguments
690 { $$ = new_member_new_expression(ctx, $2, $3); }
692 /* ECMA-262 3rd Edition 11.2 */
694 : MemberExpression Arguments
695 { $$ = new_call_expression(ctx, $1, $2); }
696 | CallExpression Arguments
697 { $$ = new_call_expression(ctx, $1, $2); }
698 | CallExpression '[' Expression ']'
699 { $$ = new_array_expression(ctx, $1, $3); }
700 | CallExpression '.' tIdentifier
701 { $$ = new_member_expression(ctx, $1, $3); }
703 /* ECMA-262 3rd Edition 11.2 */
705 : '(' ')' { $$ = NULL; }
706 | '(' ArgumentList ')' { $$ = $2; }
708 /* ECMA-262 3rd Edition 11.2 */
710 : AssignmentExpression { $$ = new_argument_list(ctx, $1); }
711 | ArgumentList ',' AssignmentExpression
712 { $$ = argument_list_add(ctx, $1, $3); }
714 /* ECMA-262 3rd Edition 11.1 */
716 : kTHIS { $$ = new_this_expression(ctx); }
717 | tIdentifier { $$ = new_identifier_expression(ctx, $1); }
718 | Literal { $$ = new_literal_expression(ctx, $1); }
719 | ArrayLiteral { $$ = $1; }
720 | ObjectLiteral { $$ = $1; }
721 | '(' Expression ')' { $$ = $2; }
723 /* ECMA-262 3rd Edition 11.1.4 */
725 : '[' Elision_opt ']' { $$ = new_array_literal_expression(ctx, NULL, $2); }
726 | '[' ElementList ']' { $$ = new_array_literal_expression(ctx, $2, 0); }
727 | '[' ElementList ',' Elision_opt ']'
728 { $$ = new_array_literal_expression(ctx, $2, $4); }
730 /* ECMA-262 3rd Edition 11.1.4 */
732 : Elision_opt AssignmentExpression
733 { $$ = new_element_list(ctx, $1, $2); }
734 | ElementList ',' Elision_opt AssignmentExpression
735 { $$ = element_list_add(ctx, $1, $3, $4); }
737 /* ECMA-262 3rd Edition 11.1.4 */
740 | Elision ',' { $$ = $1 + 1; }
742 /* ECMA-262 3rd Edition 11.1.4 */
744 : /* empty */ { $$ = 0; }
745 | Elision { $$ = $1; }
747 /* ECMA-262 3rd Edition 11.1.5 */
749 : '{' '}' { $$ = new_prop_and_value_expression(ctx, NULL); }
750 | '{' PropertyNameAndValueList '}'
751 { $$ = new_prop_and_value_expression(ctx, $2); }
753 /* ECMA-262 3rd Edition 11.1.5 */
754 PropertyNameAndValueList
755 : PropertyName ':' AssignmentExpression
756 { $$ = new_property_list(ctx, $1, $3); }
757 | PropertyNameAndValueList ',' PropertyName ':' AssignmentExpression
758 { $$ = property_list_add(ctx, $1, $3, $5); }
760 /* ECMA-262 3rd Edition 11.1.5 */
762 : tIdentifier { $$ = new_string_literal(ctx, $1); }
763 | tStringLiteral { $$ = new_string_literal(ctx, $1); }
764 | tNumericLiteral { $$ = $1; }
766 /* ECMA-262 3rd Edition 7.6 */
768 : /* empty*/ { $$ = NULL; }
769 | tIdentifier { $$ = $1; }
771 /* ECMA-262 3rd Edition 7.8 */
773 : kNULL { $$ = new_null_literal(ctx); }
774 | kUNDEFINED { $$ = new_undefined_literal(ctx); }
775 | BooleanLiteral { $$ = $1; }
776 | tNumericLiteral { $$ = $1; }
777 | tStringLiteral { $$ = new_string_literal(ctx, $1); }
778 | '/' { $$ = parse_regexp(ctx);
781 /* ECMA-262 3rd Edition 7.8.2 */
783 : kTRUE { $$ = new_boolean_literal(ctx, TRUE); }
784 | kFALSE { $$ = new_boolean_literal(ctx, FALSE); }
788 | error { if(!allow_auto_semicolon(ctx)) {YYABORT;} }
792 static BOOL allow_auto_semicolon(parser_ctx_t *ctx)
794 return ctx->nl || ctx->ptr == ctx->end || *(ctx->ptr-1) == '}';
797 static literal_t *new_string_literal(parser_ctx_t *ctx, const WCHAR *str)
799 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
807 static literal_t *new_null_literal(parser_ctx_t *ctx)
809 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
816 static literal_t *new_undefined_literal(parser_ctx_t *ctx)
818 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
825 static literal_t *new_boolean_literal(parser_ctx_t *ctx, VARIANT_BOOL bval)
827 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
835 static prop_val_t *new_prop_val(parser_ctx_t *ctx, literal_t *name, expression_t *value)
837 prop_val_t *ret = parser_alloc(ctx, sizeof(prop_val_t));
846 static property_list_t *new_property_list(parser_ctx_t *ctx, literal_t *name, expression_t *value)
848 property_list_t *ret = parser_alloc_tmp(ctx, sizeof(property_list_t));
850 ret->head = ret->tail = new_prop_val(ctx, name, value);
855 static property_list_t *property_list_add(parser_ctx_t *ctx, property_list_t *list, literal_t *name, expression_t *value)
857 list->tail = list->tail->next = new_prop_val(ctx, name, value);
862 static array_element_t *new_array_element(parser_ctx_t *ctx, int elision, expression_t *expr)
864 array_element_t *ret = parser_alloc(ctx, sizeof(array_element_t));
866 ret->elision = elision;
873 static element_list_t *new_element_list(parser_ctx_t *ctx, int elision, expression_t *expr)
875 element_list_t *ret = parser_alloc_tmp(ctx, sizeof(element_list_t));
877 ret->head = ret->tail = new_array_element(ctx, elision, expr);
882 static element_list_t *element_list_add(parser_ctx_t *ctx, element_list_t *list, int elision, expression_t *expr)
884 list->tail = list->tail->next = new_array_element(ctx, elision, expr);
889 static argument_t *new_argument(parser_ctx_t *ctx, expression_t *expr)
891 argument_t *ret = parser_alloc(ctx, sizeof(argument_t));
899 static argument_list_t *new_argument_list(parser_ctx_t *ctx, expression_t *expr)
901 argument_list_t *ret = parser_alloc_tmp(ctx, sizeof(argument_list_t));
903 ret->head = ret->tail = new_argument(ctx, expr);
908 static argument_list_t *argument_list_add(parser_ctx_t *ctx, argument_list_t *list, expression_t *expr)
910 list->tail = list->tail->next = new_argument(ctx, expr);
915 static catch_block_t *new_catch_block(parser_ctx_t *ctx, const WCHAR *identifier, statement_t *statement)
917 catch_block_t *ret = parser_alloc(ctx, sizeof(catch_block_t));
919 ret->identifier = identifier;
920 ret->statement = statement;
925 static case_clausule_t *new_case_clausule(parser_ctx_t *ctx, expression_t *expr, statement_list_t *stat_list)
927 case_clausule_t *ret = parser_alloc(ctx, sizeof(case_clausule_t));
930 ret->stat = stat_list ? stat_list->head : NULL;
936 static case_list_t *new_case_list(parser_ctx_t *ctx, case_clausule_t *case_clausule)
938 case_list_t *ret = parser_alloc_tmp(ctx, sizeof(case_list_t));
940 ret->head = ret->tail = case_clausule;
945 static case_list_t *case_list_add(parser_ctx_t *ctx, case_list_t *list, case_clausule_t *case_clausule)
947 list->tail = list->tail->next = case_clausule;
952 static case_clausule_t *new_case_block(parser_ctx_t *ctx, case_list_t *case_list1,
953 case_clausule_t *default_clausule, case_list_t *case_list2)
955 case_clausule_t *ret = NULL, *iter = NULL, *iter2;
956 statement_t *stat = NULL;
959 ret = case_list1->head;
960 iter = case_list1->tail;
963 if(default_clausule) {
965 iter = iter->next = default_clausule;
967 ret = iter = default_clausule;
972 iter->next = case_list2->head;
974 ret = case_list2->head;
980 for(iter = ret->next; iter->next; iter = iter->next) {
981 for(iter2 = iter; iter2 && !iter2->expr; iter2 = iter2->next);
985 while(iter != iter2) {
986 iter->stat = iter2->stat;
993 stat->next = iter->stat;
1002 static statement_t *new_block_statement(parser_ctx_t *ctx, statement_list_t *list)
1004 block_statement_t *ret = parser_alloc(ctx, sizeof(block_statement_t));
1006 ret->stat.eval = block_statement_eval;
1007 ret->stat.next = NULL;
1008 ret->stat_list = list ? list->head : NULL;
1013 static variable_declaration_t *new_variable_declaration(parser_ctx_t *ctx, const WCHAR *identifier, expression_t *expr)
1015 variable_declaration_t *ret = parser_alloc(ctx, sizeof(variable_declaration_t));
1017 ret->identifier = identifier;
1024 static variable_list_t *new_variable_list(parser_ctx_t *ctx, variable_declaration_t *decl)
1026 variable_list_t *ret = parser_alloc_tmp(ctx, sizeof(variable_list_t));
1028 ret->head = ret->tail = decl;
1033 static variable_list_t *variable_list_add(parser_ctx_t *ctx, variable_list_t *list, variable_declaration_t *decl)
1035 list->tail = list->tail->next = decl;
1040 static statement_t *new_var_statement(parser_ctx_t *ctx, variable_list_t *variable_list)
1042 var_statement_t *ret = parser_alloc(ctx, sizeof(var_statement_t));
1044 ret->stat.eval = var_statement_eval;
1045 ret->stat.next = NULL;
1046 ret->variable_list = variable_list->head;
1051 static statement_t *new_empty_statement(parser_ctx_t *ctx)
1053 statement_t *ret = parser_alloc(ctx, sizeof(statement_t));
1055 ret->eval = empty_statement_eval;
1061 static statement_t *new_expression_statement(parser_ctx_t *ctx, expression_t *expr)
1063 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1065 ret->stat.eval = expression_statement_eval;
1066 ret->stat.next = NULL;
1072 static statement_t *new_if_statement(parser_ctx_t *ctx, expression_t *expr, statement_t *if_stat, statement_t *else_stat)
1074 if_statement_t *ret = parser_alloc(ctx, sizeof(if_statement_t));
1076 ret->stat.eval = if_statement_eval;
1077 ret->stat.next = NULL;
1079 ret->if_stat = if_stat;
1080 ret->else_stat = else_stat;
1085 static statement_t *new_while_statement(parser_ctx_t *ctx, BOOL dowhile, expression_t *expr, statement_t *stat)
1087 while_statement_t *ret = parser_alloc(ctx, sizeof(while_statement_t));
1089 ret->stat.eval = dowhile ? dowhile_statement_eval : while_statement_eval;
1090 ret->stat.next = NULL;
1092 ret->statement = stat;
1097 static statement_t *new_for_statement(parser_ctx_t *ctx, variable_list_t *variable_list, expression_t *begin_expr,
1098 expression_t *expr, expression_t *end_expr, statement_t *statement)
1100 for_statement_t *ret = parser_alloc(ctx, sizeof(for_statement_t));
1102 ret->stat.eval = for_statement_eval;
1103 ret->stat.next = NULL;
1104 ret->variable_list = variable_list ? variable_list->head : NULL;
1105 ret->begin_expr = begin_expr;
1107 ret->end_expr = end_expr;
1108 ret->statement = statement;
1113 static statement_t *new_forin_statement(parser_ctx_t *ctx, variable_declaration_t *variable, expression_t *expr,
1114 expression_t *in_expr, statement_t *statement)
1116 forin_statement_t *ret = parser_alloc(ctx, sizeof(forin_statement_t));
1118 ret->stat.eval = forin_statement_eval;
1119 ret->stat.next = NULL;
1120 ret->variable = variable;
1122 ret->in_expr = in_expr;
1123 ret->statement = statement;
1128 static statement_t *new_continue_statement(parser_ctx_t *ctx, const WCHAR *identifier)
1130 branch_statement_t *ret = parser_alloc(ctx, sizeof(branch_statement_t));
1132 ret->stat.eval = continue_statement_eval;
1133 ret->stat.next = NULL;
1134 ret->identifier = identifier;
1139 static statement_t *new_break_statement(parser_ctx_t *ctx, const WCHAR *identifier)
1141 branch_statement_t *ret = parser_alloc(ctx, sizeof(branch_statement_t));
1143 ret->stat.eval = break_statement_eval;
1144 ret->stat.next = NULL;
1145 ret->identifier = identifier;
1150 static statement_t *new_return_statement(parser_ctx_t *ctx, expression_t *expr)
1152 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1154 ret->stat.eval = return_statement_eval;
1155 ret->stat.next = NULL;
1161 static statement_t *new_with_statement(parser_ctx_t *ctx, expression_t *expr, statement_t *statement)
1163 with_statement_t *ret = parser_alloc(ctx, sizeof(with_statement_t));
1165 ret->stat.eval = with_statement_eval;
1166 ret->stat.next = NULL;
1168 ret->statement = statement;
1173 static statement_t *new_labelled_statement(parser_ctx_t *ctx, const WCHAR *identifier, statement_t *statement)
1175 labelled_statement_t *ret = parser_alloc(ctx, sizeof(labelled_statement_t));
1177 ret->stat.eval = labelled_statement_eval;
1178 ret->stat.next = NULL;
1179 ret->identifier = identifier;
1180 ret->statement = statement;
1185 static statement_t *new_switch_statement(parser_ctx_t *ctx, expression_t *expr, case_clausule_t *case_list)
1187 switch_statement_t *ret = parser_alloc(ctx, sizeof(switch_statement_t));
1189 ret->stat.eval = switch_statement_eval;
1190 ret->stat.next = NULL;
1192 ret->case_list = case_list;
1197 static statement_t *new_throw_statement(parser_ctx_t *ctx, expression_t *expr)
1199 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1201 ret->stat.eval = throw_statement_eval;
1202 ret->stat.next = NULL;
1208 static statement_t *new_try_statement(parser_ctx_t *ctx, statement_t *try_statement,
1209 catch_block_t *catch_block, statement_t *finally_statement)
1211 try_statement_t *ret = parser_alloc(ctx, sizeof(try_statement_t));
1213 ret->stat.eval = try_statement_eval;
1214 ret->stat.next = NULL;
1215 ret->try_statement = try_statement;
1216 ret->catch_block = catch_block;
1217 ret->finally_statement = finally_statement;
1222 static parameter_t *new_parameter(parser_ctx_t *ctx, const WCHAR *identifier)
1224 parameter_t *ret = parser_alloc(ctx, sizeof(parameter_t));
1226 ret->identifier = identifier;
1232 static parameter_list_t *new_parameter_list(parser_ctx_t *ctx, const WCHAR *identifier)
1234 parameter_list_t *ret = parser_alloc_tmp(ctx, sizeof(parameter_list_t));
1236 ret->head = ret->tail = new_parameter(ctx, identifier);
1241 static parameter_list_t *parameter_list_add(parser_ctx_t *ctx, parameter_list_t *list, const WCHAR *identifier)
1243 list->tail = list->tail->next = new_parameter(ctx, identifier);
1248 static expression_t *new_function_expression(parser_ctx_t *ctx, const WCHAR *identifier,
1249 parameter_list_t *parameter_list, source_elements_t *source_elements)
1251 function_expression_t *ret = parser_alloc(ctx, sizeof(function_expression_t));
1253 ret->expr.eval = function_expression_eval;
1254 ret->identifier = identifier;
1255 ret->parameter_list = parameter_list ? parameter_list->head : NULL;
1256 ret->source_elements = source_elements;
1261 static const expression_eval_t expression_eval_table[] = {
1262 comma_expression_eval,
1263 logical_or_expression_eval,
1264 logical_and_expression_eval,
1265 binary_or_expression_eval,
1266 binary_xor_expression_eval,
1267 binary_and_expression_eval,
1268 instanceof_expression_eval,
1270 add_expression_eval,
1271 sub_expression_eval,
1272 mul_expression_eval,
1273 div_expression_eval,
1274 mod_expression_eval,
1275 delete_expression_eval,
1276 void_expression_eval,
1277 typeof_expression_eval,
1278 minus_expression_eval,
1279 plus_expression_eval,
1280 post_increment_expression_eval,
1281 post_decrement_expression_eval,
1282 pre_increment_expression_eval,
1283 pre_decrement_expression_eval,
1284 new_expression_eval,
1285 equal_expression_eval,
1286 equal2_expression_eval,
1287 not_equal_expression_eval,
1288 not_equal2_expression_eval,
1289 less_expression_eval,
1290 lesseq_expression_eval,
1291 greater_expression_eval,
1292 greatereq_expression_eval,
1293 binary_negation_expression_eval,
1294 logical_negation_expression_eval,
1295 left_shift_expression_eval,
1296 right_shift_expression_eval,
1297 right2_shift_expression_eval,
1298 assign_expression_eval,
1299 assign_lshift_expression_eval,
1300 assign_rshift_expression_eval,
1301 assign_rrshift_expression_eval,
1302 assign_add_expression_eval,
1303 assign_sub_expression_eval,
1304 assign_mul_expression_eval,
1305 assign_div_expression_eval,
1306 assign_mod_expression_eval,
1307 assign_and_expression_eval,
1308 assign_or_expression_eval,
1309 assign_xor_expression_eval,
1312 static expression_t *new_binary_expression(parser_ctx_t *ctx, expression_type_t type,
1313 expression_t *expression1, expression_t *expression2)
1315 binary_expression_t *ret = parser_alloc(ctx, sizeof(binary_expression_t));
1317 ret->expr.eval = expression_eval_table[type];
1318 ret->expression1 = expression1;
1319 ret->expression2 = expression2;
1324 static expression_t *new_unary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *expression)
1326 unary_expression_t *ret = parser_alloc(ctx, sizeof(unary_expression_t));
1328 ret->expr.eval = expression_eval_table[type];
1329 ret->expression = expression;
1334 static expression_t *new_conditional_expression(parser_ctx_t *ctx, expression_t *expression,
1335 expression_t *true_expression, expression_t *false_expression)
1337 conditional_expression_t *ret = parser_alloc(ctx, sizeof(conditional_expression_t));
1339 ret->expr.eval = conditional_expression_eval;
1340 ret->expression = expression;
1341 ret->true_expression = true_expression;
1342 ret->false_expression = false_expression;
1347 static expression_t *new_array_expression(parser_ctx_t *ctx, expression_t *member_expr, expression_t *expression)
1349 array_expression_t *ret = parser_alloc(ctx, sizeof(array_expression_t));
1351 ret->expr.eval = array_expression_eval;
1352 ret->member_expr = member_expr;
1353 ret->expression = expression;
1358 static expression_t *new_member_expression(parser_ctx_t *ctx, expression_t *expression, const WCHAR *identifier)
1360 member_expression_t *ret = parser_alloc(ctx, sizeof(member_expression_t));
1362 ret->expr.eval = member_expression_eval;
1363 ret->expression = expression;
1364 ret->identifier = identifier;
1369 static expression_t *new_member_new_expression(parser_ctx_t *ctx, expression_t *expression, argument_list_t *argument_list)
1371 call_expression_t *ret = parser_alloc(ctx, sizeof(call_expression_t));
1373 ret->expr.eval = member_new_expression_eval;
1374 ret->expression = expression;
1375 ret->argument_list = argument_list ? argument_list->head : NULL;
1380 static expression_t *new_call_expression(parser_ctx_t *ctx, expression_t *expression, argument_list_t *argument_list)
1382 call_expression_t *ret = parser_alloc(ctx, sizeof(call_expression_t));
1384 ret->expr.eval = call_expression_eval;
1385 ret->expression = expression;
1386 ret->argument_list = argument_list ? argument_list->head : NULL;
1391 static expression_t *new_this_expression(parser_ctx_t *ctx)
1393 expression_t *ret = parser_alloc(ctx, sizeof(expression_t));
1395 ret->eval = this_expression_eval;
1400 static int parser_error(const char *str)
1405 static expression_t *new_identifier_expression(parser_ctx_t *ctx, const WCHAR *identifier)
1407 identifier_expression_t *ret = parser_alloc(ctx, sizeof(identifier_expression_t));
1409 ret->expr.eval = identifier_expression_eval;
1410 ret->identifier = identifier;
1415 static expression_t *new_array_literal_expression(parser_ctx_t *ctx, element_list_t *element_list, int length)
1417 array_literal_expression_t *ret = parser_alloc(ctx, sizeof(array_literal_expression_t));
1419 ret->expr.eval = array_literal_expression_eval;
1420 ret->element_list = element_list ? element_list->head : NULL;
1421 ret->length = length;
1426 static expression_t *new_prop_and_value_expression(parser_ctx_t *ctx, property_list_t *property_list)
1428 property_value_expression_t *ret = parser_alloc(ctx, sizeof(property_value_expression_t));
1430 ret->expr.eval = property_value_expression_eval;
1431 ret->property_list = property_list ? property_list->head : NULL;
1436 static expression_t *new_literal_expression(parser_ctx_t *ctx, literal_t *literal)
1438 literal_expression_t *ret = parser_alloc(ctx, sizeof(literal_expression_t));
1440 ret->expr.eval = literal_expression_eval;
1441 ret->literal = literal;
1446 static function_declaration_t *new_function_declaration(parser_ctx_t *ctx, const WCHAR *identifier,
1447 parameter_list_t *parameter_list, source_elements_t *source_elements)
1449 function_declaration_t *ret = parser_alloc(ctx, sizeof(function_declaration_t));
1451 ret->identifier = identifier;
1452 ret->parameter_list = parameter_list ? parameter_list->head : NULL;
1453 ret->source_elements = source_elements;
1459 static source_elements_t *new_source_elements(parser_ctx_t *ctx)
1461 source_elements_t *ret = parser_alloc(ctx, sizeof(source_elements_t));
1463 memset(ret, 0, sizeof(*ret));
1468 static source_elements_t *source_elements_add_statement(source_elements_t *source_elements, statement_t *statement)
1470 if(source_elements->statement_tail)
1471 source_elements->statement_tail = source_elements->statement_tail->next = statement;
1473 source_elements->statement = source_elements->statement_tail = statement;
1475 return source_elements;
1478 static source_elements_t *source_elements_add_function(source_elements_t *source_elements,
1479 function_declaration_t *function_declaration)
1481 if(source_elements->functions_tail)
1482 source_elements->functions_tail = source_elements->functions_tail->next = function_declaration;
1484 source_elements->functions = source_elements->functions_tail = function_declaration;
1486 return source_elements;
1489 statement_list_t *new_statement_list(parser_ctx_t *ctx, statement_t *statement)
1491 statement_list_t *ret = parser_alloc_tmp(ctx, sizeof(statement_list_t));
1493 ret->head = ret->tail = statement;
1498 statement_list_t *statement_list_add(statement_list_t *list, statement_t *statement)
1500 list->tail = list->tail->next = statement;
1505 static void program_parsed(parser_ctx_t *ctx, source_elements_t *source)
1507 ctx->source = source;
1511 void parser_release(parser_ctx_t *ctx)
1513 obj_literal_t *iter;
1518 for(iter = ctx->obj_literals; iter; iter = iter->next)
1519 jsdisp_release(iter->obj);
1521 jsheap_free(&ctx->heap);
1525 HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, parser_ctx_t **ret)
1527 parser_ctx_t *parser_ctx;
1530 parser_ctx = heap_alloc_zero(sizeof(parser_ctx_t));
1532 return E_OUTOFMEMORY;
1534 parser_ctx->ref = 1;
1535 parser_ctx->hres = E_FAIL;
1537 parser_ctx->begin = parser_ctx->ptr = code;
1538 parser_ctx->end = code + strlenW(code);
1541 parser_ctx->script = ctx;
1543 jsheap_init(&parser_ctx->tmp_heap);
1544 jsheap_init(&parser_ctx->heap);
1546 parser_parse(parser_ctx);
1547 jsheap_free(&parser_ctx->tmp_heap);
1548 if(FAILED(parser_ctx->hres)) {
1549 hres = parser_ctx->hres;
1550 parser_release(parser_ctx);