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 | '/' { FIXME("RegExp literal\n"); YYABORT; }
780 /* ECMA-262 3rd Edition 7.8.2 */
782 : kTRUE { $$ = new_boolean_literal(ctx, TRUE); }
783 | kFALSE { $$ = new_boolean_literal(ctx, FALSE); }
787 | error { if(!allow_auto_semicolon(ctx)) {YYABORT;} }
791 static BOOL allow_auto_semicolon(parser_ctx_t *ctx)
793 return ctx->nl || ctx->ptr == ctx->end || *(ctx->ptr-1) == '}';
796 static literal_t *new_string_literal(parser_ctx_t *ctx, const WCHAR *str)
798 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
806 static literal_t *new_null_literal(parser_ctx_t *ctx)
808 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
815 static literal_t *new_undefined_literal(parser_ctx_t *ctx)
817 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
824 static literal_t *new_boolean_literal(parser_ctx_t *ctx, VARIANT_BOOL bval)
826 literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
834 static prop_val_t *new_prop_val(parser_ctx_t *ctx, literal_t *name, expression_t *value)
836 prop_val_t *ret = parser_alloc(ctx, sizeof(prop_val_t));
845 static property_list_t *new_property_list(parser_ctx_t *ctx, literal_t *name, expression_t *value)
847 property_list_t *ret = parser_alloc_tmp(ctx, sizeof(property_list_t));
849 ret->head = ret->tail = new_prop_val(ctx, name, value);
854 static property_list_t *property_list_add(parser_ctx_t *ctx, property_list_t *list, literal_t *name, expression_t *value)
856 list->tail = list->tail->next = new_prop_val(ctx, name, value);
861 static array_element_t *new_array_element(parser_ctx_t *ctx, int elision, expression_t *expr)
863 array_element_t *ret = parser_alloc(ctx, sizeof(array_element_t));
865 ret->elision = elision;
872 static element_list_t *new_element_list(parser_ctx_t *ctx, int elision, expression_t *expr)
874 element_list_t *ret = parser_alloc_tmp(ctx, sizeof(element_list_t));
876 ret->head = ret->tail = new_array_element(ctx, elision, expr);
881 static element_list_t *element_list_add(parser_ctx_t *ctx, element_list_t *list, int elision, expression_t *expr)
883 list->tail = list->tail->next = new_array_element(ctx, elision, expr);
888 static argument_t *new_argument(parser_ctx_t *ctx, expression_t *expr)
890 argument_t *ret = parser_alloc(ctx, sizeof(argument_t));
898 static argument_list_t *new_argument_list(parser_ctx_t *ctx, expression_t *expr)
900 argument_list_t *ret = parser_alloc_tmp(ctx, sizeof(argument_list_t));
902 ret->head = ret->tail = new_argument(ctx, expr);
907 static argument_list_t *argument_list_add(parser_ctx_t *ctx, argument_list_t *list, expression_t *expr)
909 list->tail = list->tail->next = new_argument(ctx, expr);
914 static catch_block_t *new_catch_block(parser_ctx_t *ctx, const WCHAR *identifier, statement_t *statement)
916 catch_block_t *ret = parser_alloc(ctx, sizeof(catch_block_t));
918 ret->identifier = identifier;
919 ret->statement = statement;
924 static case_clausule_t *new_case_clausule(parser_ctx_t *ctx, expression_t *expr, statement_list_t *stat_list)
926 case_clausule_t *ret = parser_alloc(ctx, sizeof(case_clausule_t));
929 ret->stat = stat_list ? stat_list->head : NULL;
935 static case_list_t *new_case_list(parser_ctx_t *ctx, case_clausule_t *case_clausule)
937 case_list_t *ret = parser_alloc_tmp(ctx, sizeof(case_list_t));
939 ret->head = ret->tail = case_clausule;
944 static case_list_t *case_list_add(parser_ctx_t *ctx, case_list_t *list, case_clausule_t *case_clausule)
946 list->tail = list->tail->next = case_clausule;
951 static case_clausule_t *new_case_block(parser_ctx_t *ctx, case_list_t *case_list1,
952 case_clausule_t *default_clausule, case_list_t *case_list2)
954 case_clausule_t *ret = NULL, *iter = NULL, *iter2;
955 statement_t *stat = NULL;
958 ret = case_list1->head;
959 iter = case_list1->tail;
962 if(default_clausule) {
964 iter = iter->next = default_clausule;
966 ret = iter = default_clausule;
971 iter->next = case_list2->head;
973 ret = case_list2->head;
979 for(iter = ret->next; iter->next; iter = iter->next) {
980 for(iter2 = iter; iter2 && !iter2->expr; iter2 = iter2->next);
984 while(iter != iter2) {
985 iter->stat = iter2->stat;
992 stat->next = iter->stat;
1001 static statement_t *new_block_statement(parser_ctx_t *ctx, statement_list_t *list)
1003 block_statement_t *ret = parser_alloc(ctx, sizeof(block_statement_t));
1005 ret->stat.eval = block_statement_eval;
1006 ret->stat.next = NULL;
1007 ret->stat_list = list ? list->head : NULL;
1012 static variable_declaration_t *new_variable_declaration(parser_ctx_t *ctx, const WCHAR *identifier, expression_t *expr)
1014 variable_declaration_t *ret = parser_alloc(ctx, sizeof(variable_declaration_t));
1016 ret->identifier = identifier;
1023 static variable_list_t *new_variable_list(parser_ctx_t *ctx, variable_declaration_t *decl)
1025 variable_list_t *ret = parser_alloc_tmp(ctx, sizeof(variable_list_t));
1027 ret->head = ret->tail = decl;
1032 static variable_list_t *variable_list_add(parser_ctx_t *ctx, variable_list_t *list, variable_declaration_t *decl)
1034 list->tail = list->tail->next = decl;
1039 static statement_t *new_var_statement(parser_ctx_t *ctx, variable_list_t *variable_list)
1041 var_statement_t *ret = parser_alloc(ctx, sizeof(var_statement_t));
1043 ret->stat.eval = var_statement_eval;
1044 ret->stat.next = NULL;
1045 ret->variable_list = variable_list->head;
1050 static statement_t *new_empty_statement(parser_ctx_t *ctx)
1052 statement_t *ret = parser_alloc(ctx, sizeof(statement_t));
1054 ret->eval = empty_statement_eval;
1060 static statement_t *new_expression_statement(parser_ctx_t *ctx, expression_t *expr)
1062 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1064 ret->stat.eval = expression_statement_eval;
1065 ret->stat.next = NULL;
1071 static statement_t *new_if_statement(parser_ctx_t *ctx, expression_t *expr, statement_t *if_stat, statement_t *else_stat)
1073 if_statement_t *ret = parser_alloc(ctx, sizeof(if_statement_t));
1075 ret->stat.eval = if_statement_eval;
1076 ret->stat.next = NULL;
1078 ret->if_stat = if_stat;
1079 ret->else_stat = else_stat;
1084 static statement_t *new_while_statement(parser_ctx_t *ctx, BOOL dowhile, expression_t *expr, statement_t *stat)
1086 while_statement_t *ret = parser_alloc(ctx, sizeof(while_statement_t));
1088 ret->stat.eval = dowhile ? dowhile_statement_eval : while_statement_eval;
1089 ret->stat.next = NULL;
1091 ret->statement = stat;
1096 static statement_t *new_for_statement(parser_ctx_t *ctx, variable_list_t *variable_list, expression_t *begin_expr,
1097 expression_t *expr, expression_t *end_expr, statement_t *statement)
1099 for_statement_t *ret = parser_alloc(ctx, sizeof(for_statement_t));
1101 ret->stat.eval = for_statement_eval;
1102 ret->stat.next = NULL;
1103 ret->variable_list = variable_list ? variable_list->head : NULL;
1104 ret->begin_expr = begin_expr;
1106 ret->end_expr = end_expr;
1107 ret->statement = statement;
1112 static statement_t *new_forin_statement(parser_ctx_t *ctx, variable_declaration_t *variable, expression_t *expr,
1113 expression_t *in_expr, statement_t *statement)
1115 forin_statement_t *ret = parser_alloc(ctx, sizeof(forin_statement_t));
1117 ret->stat.eval = forin_statement_eval;
1118 ret->stat.next = NULL;
1119 ret->variable = variable;
1121 ret->in_expr = in_expr;
1122 ret->statement = statement;
1127 static statement_t *new_continue_statement(parser_ctx_t *ctx, const WCHAR *identifier)
1129 branch_statement_t *ret = parser_alloc(ctx, sizeof(branch_statement_t));
1131 ret->stat.eval = continue_statement_eval;
1132 ret->stat.next = NULL;
1133 ret->identifier = identifier;
1138 static statement_t *new_break_statement(parser_ctx_t *ctx, const WCHAR *identifier)
1140 branch_statement_t *ret = parser_alloc(ctx, sizeof(branch_statement_t));
1142 ret->stat.eval = break_statement_eval;
1143 ret->stat.next = NULL;
1144 ret->identifier = identifier;
1149 static statement_t *new_return_statement(parser_ctx_t *ctx, expression_t *expr)
1151 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1153 ret->stat.eval = return_statement_eval;
1154 ret->stat.next = NULL;
1160 static statement_t *new_with_statement(parser_ctx_t *ctx, expression_t *expr, statement_t *statement)
1162 with_statement_t *ret = parser_alloc(ctx, sizeof(with_statement_t));
1164 ret->stat.eval = with_statement_eval;
1165 ret->stat.next = NULL;
1167 ret->statement = statement;
1172 static statement_t *new_labelled_statement(parser_ctx_t *ctx, const WCHAR *identifier, statement_t *statement)
1174 labelled_statement_t *ret = parser_alloc(ctx, sizeof(labelled_statement_t));
1176 ret->stat.eval = labelled_statement_eval;
1177 ret->stat.next = NULL;
1178 ret->identifier = identifier;
1179 ret->statement = statement;
1184 static statement_t *new_switch_statement(parser_ctx_t *ctx, expression_t *expr, case_clausule_t *case_list)
1186 switch_statement_t *ret = parser_alloc(ctx, sizeof(switch_statement_t));
1188 ret->stat.eval = switch_statement_eval;
1189 ret->stat.next = NULL;
1191 ret->case_list = case_list;
1196 static statement_t *new_throw_statement(parser_ctx_t *ctx, expression_t *expr)
1198 expression_statement_t *ret = parser_alloc(ctx, sizeof(expression_statement_t));
1200 ret->stat.eval = throw_statement_eval;
1201 ret->stat.next = NULL;
1207 static statement_t *new_try_statement(parser_ctx_t *ctx, statement_t *try_statement,
1208 catch_block_t *catch_block, statement_t *finally_statement)
1210 try_statement_t *ret = parser_alloc(ctx, sizeof(try_statement_t));
1212 ret->stat.eval = try_statement_eval;
1213 ret->stat.next = NULL;
1214 ret->try_statement = try_statement;
1215 ret->catch_block = catch_block;
1216 ret->finally_statement = finally_statement;
1221 static parameter_t *new_parameter(parser_ctx_t *ctx, const WCHAR *identifier)
1223 parameter_t *ret = parser_alloc(ctx, sizeof(parameter_t));
1225 ret->identifier = identifier;
1231 static parameter_list_t *new_parameter_list(parser_ctx_t *ctx, const WCHAR *identifier)
1233 parameter_list_t *ret = parser_alloc_tmp(ctx, sizeof(parameter_list_t));
1235 ret->head = ret->tail = new_parameter(ctx, identifier);
1240 static parameter_list_t *parameter_list_add(parser_ctx_t *ctx, parameter_list_t *list, const WCHAR *identifier)
1242 list->tail = list->tail->next = new_parameter(ctx, identifier);
1247 static expression_t *new_function_expression(parser_ctx_t *ctx, const WCHAR *identifier,
1248 parameter_list_t *parameter_list, source_elements_t *source_elements)
1250 function_expression_t *ret = parser_alloc(ctx, sizeof(function_expression_t));
1252 ret->expr.eval = function_expression_eval;
1253 ret->identifier = identifier;
1254 ret->parameter_list = parameter_list ? parameter_list->head : NULL;
1255 ret->source_elements = source_elements;
1260 static const expression_eval_t expression_eval_table[] = {
1261 comma_expression_eval,
1262 logical_or_expression_eval,
1263 logical_and_expression_eval,
1264 binary_or_expression_eval,
1265 binary_xor_expression_eval,
1266 binary_and_expression_eval,
1267 instanceof_expression_eval,
1269 add_expression_eval,
1270 sub_expression_eval,
1271 mul_expression_eval,
1272 div_expression_eval,
1273 mod_expression_eval,
1274 delete_expression_eval,
1275 void_expression_eval,
1276 typeof_expression_eval,
1277 minus_expression_eval,
1278 plus_expression_eval,
1279 post_increment_expression_eval,
1280 post_decrement_expression_eval,
1281 pre_increment_expression_eval,
1282 pre_decrement_expression_eval,
1283 new_expression_eval,
1284 equal_expression_eval,
1285 equal2_expression_eval,
1286 not_equal_expression_eval,
1287 not_equal2_expression_eval,
1288 less_expression_eval,
1289 lesseq_expression_eval,
1290 greater_expression_eval,
1291 greatereq_expression_eval,
1292 binary_negation_expression_eval,
1293 logical_negation_expression_eval,
1294 left_shift_expression_eval,
1295 right_shift_expression_eval,
1296 right2_shift_expression_eval,
1297 assign_expression_eval,
1298 assign_lshift_expression_eval,
1299 assign_rshift_expression_eval,
1300 assign_rrshift_expression_eval,
1301 assign_add_expression_eval,
1302 assign_sub_expression_eval,
1303 assign_mul_expression_eval,
1304 assign_div_expression_eval,
1305 assign_mod_expression_eval,
1306 assign_and_expression_eval,
1307 assign_or_expression_eval,
1308 assign_xor_expression_eval,
1311 static expression_t *new_binary_expression(parser_ctx_t *ctx, expression_type_t type,
1312 expression_t *expression1, expression_t *expression2)
1314 binary_expression_t *ret = parser_alloc(ctx, sizeof(binary_expression_t));
1316 ret->expr.eval = expression_eval_table[type];
1317 ret->expression1 = expression1;
1318 ret->expression2 = expression2;
1323 static expression_t *new_unary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *expression)
1325 unary_expression_t *ret = parser_alloc(ctx, sizeof(unary_expression_t));
1327 ret->expr.eval = expression_eval_table[type];
1328 ret->expression = expression;
1333 static expression_t *new_conditional_expression(parser_ctx_t *ctx, expression_t *expression,
1334 expression_t *true_expression, expression_t *false_expression)
1336 conditional_expression_t *ret = parser_alloc(ctx, sizeof(conditional_expression_t));
1338 ret->expr.eval = conditional_expression_eval;
1339 ret->expression = expression;
1340 ret->true_expression = true_expression;
1341 ret->false_expression = false_expression;
1346 static expression_t *new_array_expression(parser_ctx_t *ctx, expression_t *member_expr, expression_t *expression)
1348 array_expression_t *ret = parser_alloc(ctx, sizeof(array_expression_t));
1350 ret->expr.eval = array_expression_eval;
1351 ret->member_expr = member_expr;
1352 ret->expression = expression;
1357 static expression_t *new_member_expression(parser_ctx_t *ctx, expression_t *expression, const WCHAR *identifier)
1359 member_expression_t *ret = parser_alloc(ctx, sizeof(member_expression_t));
1361 ret->expr.eval = member_expression_eval;
1362 ret->expression = expression;
1363 ret->identifier = identifier;
1368 static expression_t *new_member_new_expression(parser_ctx_t *ctx, expression_t *expression, argument_list_t *argument_list)
1370 call_expression_t *ret = parser_alloc(ctx, sizeof(call_expression_t));
1372 ret->expr.eval = member_new_expression_eval;
1373 ret->expression = expression;
1374 ret->argument_list = argument_list ? argument_list->head : NULL;
1379 static expression_t *new_call_expression(parser_ctx_t *ctx, expression_t *expression, argument_list_t *argument_list)
1381 call_expression_t *ret = parser_alloc(ctx, sizeof(call_expression_t));
1383 ret->expr.eval = call_expression_eval;
1384 ret->expression = expression;
1385 ret->argument_list = argument_list ? argument_list->head : NULL;
1390 static expression_t *new_this_expression(parser_ctx_t *ctx)
1392 expression_t *ret = parser_alloc(ctx, sizeof(expression_t));
1394 ret->eval = this_expression_eval;
1399 static int parser_error(const char *str)
1404 static expression_t *new_identifier_expression(parser_ctx_t *ctx, const WCHAR *identifier)
1406 identifier_expression_t *ret = parser_alloc(ctx, sizeof(identifier_expression_t));
1408 ret->expr.eval = identifier_expression_eval;
1409 ret->identifier = identifier;
1414 static expression_t *new_array_literal_expression(parser_ctx_t *ctx, element_list_t *element_list, int length)
1416 array_literal_expression_t *ret = parser_alloc(ctx, sizeof(array_literal_expression_t));
1418 ret->expr.eval = array_literal_expression_eval;
1419 ret->element_list = element_list ? element_list->head : NULL;
1420 ret->length = length;
1425 static expression_t *new_prop_and_value_expression(parser_ctx_t *ctx, property_list_t *property_list)
1427 property_value_expression_t *ret = parser_alloc(ctx, sizeof(property_value_expression_t));
1429 ret->expr.eval = property_value_expression_eval;
1430 ret->property_list = property_list ? property_list->head : NULL;
1435 static expression_t *new_literal_expression(parser_ctx_t *ctx, literal_t *literal)
1437 literal_expression_t *ret = parser_alloc(ctx, sizeof(literal_expression_t));
1439 ret->expr.eval = literal_expression_eval;
1440 ret->literal = literal;
1445 static function_declaration_t *new_function_declaration(parser_ctx_t *ctx, const WCHAR *identifier,
1446 parameter_list_t *parameter_list, source_elements_t *source_elements)
1448 function_declaration_t *ret = parser_alloc(ctx, sizeof(function_declaration_t));
1450 ret->identifier = identifier;
1451 ret->parameter_list = parameter_list ? parameter_list->head : NULL;
1452 ret->source_elements = source_elements;
1458 static source_elements_t *new_source_elements(parser_ctx_t *ctx)
1460 source_elements_t *ret = parser_alloc(ctx, sizeof(source_elements_t));
1462 memset(ret, 0, sizeof(*ret));
1467 static source_elements_t *source_elements_add_statement(source_elements_t *source_elements, statement_t *statement)
1469 if(source_elements->statement_tail)
1470 source_elements->statement_tail = source_elements->statement_tail->next = statement;
1472 source_elements->statement = source_elements->statement_tail = statement;
1474 return source_elements;
1477 static source_elements_t *source_elements_add_function(source_elements_t *source_elements,
1478 function_declaration_t *function_declaration)
1480 if(source_elements->functions_tail)
1481 source_elements->functions_tail = source_elements->functions_tail->next = function_declaration;
1483 source_elements->functions = source_elements->functions_tail = function_declaration;
1485 return source_elements;
1488 statement_list_t *new_statement_list(parser_ctx_t *ctx, statement_t *statement)
1490 statement_list_t *ret = parser_alloc_tmp(ctx, sizeof(statement_list_t));
1492 ret->head = ret->tail = statement;
1497 statement_list_t *statement_list_add(statement_list_t *list, statement_t *statement)
1499 list->tail = list->tail->next = statement;
1504 static void program_parsed(parser_ctx_t *ctx, source_elements_t *source)
1506 ctx->source = source;
1510 void parser_release(parser_ctx_t *ctx)
1515 jsheap_free(&ctx->heap);
1519 HRESULT script_parse(script_ctx_t *ctx, const WCHAR *code, parser_ctx_t **ret)
1521 parser_ctx_t *parser_ctx;
1524 parser_ctx = heap_alloc_zero(sizeof(parser_ctx_t));
1526 return E_OUTOFMEMORY;
1528 parser_ctx->ref = 1;
1529 parser_ctx->hres = E_FAIL;
1531 parser_ctx->begin = parser_ctx->ptr = code;
1532 parser_ctx->end = code + strlenW(code);
1535 parser_ctx->script = ctx;
1537 jsheap_init(&parser_ctx->tmp_heap);
1538 jsheap_init(&parser_ctx->heap);
1540 parser_parse(parser_ctx);
1541 jsheap_free(&parser_ctx->tmp_heap);
1542 if(FAILED(parser_ctx->hres)) {
1543 hres = parser_ctx->hres;
1544 parser_release(parser_ctx);