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
*);
34 static source_elements_t
*function_body_parsed
(parser_ctx_t
*,source_elements_t
*);
36 typedef
struct _statement_list_t
{
41 static literal_t
*new_string_literal
(parser_ctx_t
*,const WCHAR
*);
42 static literal_t
*new_null_literal
(parser_ctx_t
*);
43 static literal_t
*new_undefined_literal
(parser_ctx_t
*);
44 static literal_t
*new_boolean_literal
(parser_ctx_t
*,VARIANT_BOOL
);
46 typedef
struct _property_list_t
{
51 static property_list_t
*new_property_list
(parser_ctx_t
*,literal_t
*,expression_t
*);
52 static property_list_t
*property_list_add
(parser_ctx_t
*,property_list_t
*,literal_t
*,expression_t
*);
54 typedef
struct _element_list_t
{
55 array_element_t
*head
;
56 array_element_t
*tail
;
59 static element_list_t
*new_element_list
(parser_ctx_t
*,int,expression_t
*);
60 static element_list_t
*element_list_add
(parser_ctx_t
*,element_list_t
*,int,expression_t
*);
62 typedef
struct _argument_list_t
{
67 static argument_list_t
*new_argument_list
(parser_ctx_t
*,expression_t
*);
68 static argument_list_t
*argument_list_add
(parser_ctx_t
*,argument_list_t
*,expression_t
*);
70 typedef
struct _case_list_t
{
71 case_clausule_t
*head
;
72 case_clausule_t
*tail
;
75 static catch_block_t
*new_catch_block
(parser_ctx_t
*,const WCHAR
*,statement_t
*);
76 static case_clausule_t
*new_case_clausule
(parser_ctx_t
*,expression_t
*,statement_list_t
*);
77 static case_list_t
*new_case_list
(parser_ctx_t
*,case_clausule_t
*);
78 static case_list_t
*case_list_add
(parser_ctx_t
*,case_list_t
*,case_clausule_t
*);
79 static case_clausule_t
*new_case_block
(parser_ctx_t
*,case_list_t
*,case_clausule_t
*,case_list_t
*);
81 typedef
struct _variable_list_t
{
82 variable_declaration_t
*head
;
83 variable_declaration_t
*tail
;
86 static variable_declaration_t
*new_variable_declaration
(parser_ctx_t
*,const WCHAR
*,expression_t
*);
87 static variable_list_t
*new_variable_list
(parser_ctx_t
*,variable_declaration_t
*);
88 static variable_list_t
*variable_list_add
(parser_ctx_t
*,variable_list_t
*,variable_declaration_t
*);
90 static statement_t
*new_block_statement
(parser_ctx_t
*,statement_list_t
*);
91 static statement_t
*new_var_statement
(parser_ctx_t
*,variable_list_t
*);
92 static statement_t
*new_empty_statement
(parser_ctx_t
*);
93 static statement_t
*new_expression_statement
(parser_ctx_t
*,expression_t
*);
94 static statement_t
*new_if_statement
(parser_ctx_t
*,expression_t
*,statement_t
*,statement_t
*);
95 static statement_t
*new_while_statement
(parser_ctx_t
*,BOOL
,expression_t
*,statement_t
*);
96 static statement_t
*new_for_statement
(parser_ctx_t
*,variable_list_t
*,expression_t
*,expression_t
*,
97 expression_t
*,statement_t
*);
98 static statement_t
*new_forin_statement
(parser_ctx_t
*,variable_declaration_t
*,expression_t
*,expression_t
*,statement_t
*);
99 static statement_t
*new_continue_statement
(parser_ctx_t
*,const WCHAR
*);
100 static statement_t
*new_break_statement
(parser_ctx_t
*,const WCHAR
*);
101 static statement_t
*new_return_statement
(parser_ctx_t
*,expression_t
*);
102 static statement_t
*new_with_statement
(parser_ctx_t
*,expression_t
*,statement_t
*);
103 static statement_t
*new_labelled_statement
(parser_ctx_t
*,const WCHAR
*,statement_t
*);
104 static statement_t
*new_switch_statement
(parser_ctx_t
*,expression_t
*,case_clausule_t
*);
105 static statement_t
*new_throw_statement
(parser_ctx_t
*,expression_t
*);
106 static statement_t
*new_try_statement
(parser_ctx_t
*,statement_t
*,catch_block_t
*,statement_t
*);
108 struct statement_list_t
{
113 statement_list_t
*new_statement_list
(parser_ctx_t
*,statement_t
*);
114 statement_list_t
*statement_list_add
(statement_list_t
*,statement_t
*);
116 typedef
struct _parameter_list_t
{
121 static parameter_list_t
*new_parameter_list
(parser_ctx_t
*,const WCHAR
*);
122 static parameter_list_t
*parameter_list_add
(parser_ctx_t
*,parameter_list_t
*,const WCHAR
*);
124 static void push_func
(parser_ctx_t
*);
125 static inline
void pop_func
(parser_ctx_t
*ctx
)
127 ctx
->func_stack
= ctx
->func_stack
->next
;
130 static expression_t
*new_function_expression
(parser_ctx_t
*,const WCHAR
*,parameter_list_t
*,
131 source_elements_t
*,const WCHAR
*,DWORD
);
132 static expression_t
*new_binary_expression
(parser_ctx_t
*,expression_type_t
,expression_t
*,expression_t
*);
133 static expression_t
*new_unary_expression
(parser_ctx_t
*,expression_type_t
,expression_t
*);
134 static expression_t
*new_conditional_expression
(parser_ctx_t
*,expression_t
*,expression_t
*,expression_t
*);
135 static expression_t
*new_array_expression
(parser_ctx_t
*,expression_t
*,expression_t
*);
136 static expression_t
*new_member_expression
(parser_ctx_t
*,expression_t
*,const WCHAR
*);
137 static expression_t
*new_new_expression
(parser_ctx_t
*,expression_t
*,argument_list_t
*);
138 static expression_t
*new_call_expression
(parser_ctx_t
*,expression_t
*,argument_list_t
*);
139 static expression_t
*new_this_expression
(parser_ctx_t
*);
140 static expression_t
*new_identifier_expression
(parser_ctx_t
*,const WCHAR
*);
141 static expression_t
*new_literal_expression
(parser_ctx_t
*,literal_t
*);
142 static expression_t
*new_array_literal_expression
(parser_ctx_t
*,element_list_t
*,int);
143 static expression_t
*new_prop_and_value_expression
(parser_ctx_t
*,property_list_t
*);
145 static function_declaration_t
*new_function_declaration
(parser_ctx_t
*,const WCHAR
*,parameter_list_t
*,
146 source_elements_t
*,const WCHAR
*,DWORD
);
147 static source_elements_t
*new_source_elements
(parser_ctx_t
*);
148 static source_elements_t
*source_elements_add_statement
(source_elements_t
*,statement_t
*);
149 static source_elements_t
*source_elements_add_function
(source_elements_t
*,function_declaration_t
*);
161 struct _argument_list_t
*argument_list
;
162 case_clausule_t
*case_clausule
;
163 struct _case_list_t
*case_list
;
164 catch_block_t
*catch_block
;
165 struct _element_list_t
*element_list
;
167 const WCHAR
*identifier
;
168 function_declaration_t
*function_declaration
;
169 struct _parameter_list_t
*parameter_list
;
170 struct _property_list_t
*property_list
;
171 source_elements_t
*source_elements
;
172 statement_t
*statement
;
173 struct _statement_list_t
*statement_list
;
174 struct _variable_list_t
*variable_list
;
175 variable_declaration_t
*variable_declaration
;
179 %token kBREAK kCASE kCATCH kCONTINUE kDEFAULT kDELETE kDO kELSE kIF kFINALLY kFOR kIN
180 %token kINSTANCEOF kNEW kNULL kUNDEFINED kRETURN kSWITCH kTHIS kTHROW kTRUE kFALSE kTRY kTYPEOF kVAR kVOID kWHILE kWITH
181 %token tANDAND tOROR tINC tDEC
183 %token
<srcptr
> kFUNCTION
'}'
186 %token
<identifier
> tIdentifier
187 %token
<ival
> tAssignOper tEqOper tShiftOper tRelOper
188 %token
<literal
> tNumericLiteral
189 %token
<wstr
> tStringLiteral
191 %type
<source_elements
> SourceElements
192 %type
<source_elements
> FunctionBody
193 %type
<statement
> Statement
194 %type
<statement
> Block
195 %type
<statement
> VariableStatement
196 %type
<statement
> EmptyStatement
197 %type
<statement
> ExpressionStatement
198 %type
<statement
> IfStatement
199 %type
<statement
> IterationStatement
200 %type
<statement
> ContinueStatement
201 %type
<statement
> BreakStatement
202 %type
<statement
> ReturnStatement
203 %type
<statement
> WithStatement
204 %type
<statement
> LabelledStatement
205 %type
<statement
> SwitchStatement
206 %type
<statement
> ThrowStatement
207 %type
<statement
> TryStatement
208 %type
<statement
> Finally
209 %type
<statement_list
> StatementList StatementList_opt
210 %type
<function_declaration
> FunctionDeclaration
211 %type
<parameter_list
> FormalParameterList FormalParameterList_opt
212 %type
<expr
> Expression Expression_opt
213 %type
<expr
> ExpressionNoIn ExpressionNoIn_opt
214 %type
<expr
> FunctionExpression
215 %type
<expr
> AssignmentExpression AssignmentExpressionNoIn
216 %type
<expr
> ConditionalExpression ConditionalExpressionNoIn
217 %type
<expr
> LeftHandSideExpression
218 %type
<expr
> LogicalORExpression LogicalORExpressionNoIn
219 %type
<expr
> LogicalANDExpression LogicalANDExpressionNoIn
220 %type
<expr
> BitwiseORExpression BitwiseORExpressionNoIn
221 %type
<expr
> BitwiseXORExpression BitwiseXORExpressionNoIn
222 %type
<expr
> BitwiseANDExpression BitwiseANDExpressionNoIn
223 %type
<expr
> EqualityExpression EqualityExpressionNoIn
224 %type
<expr
> RelationalExpression RelationalExpressionNoIn
225 %type
<expr
> ShiftExpression
226 %type
<expr
> AdditiveExpression
227 %type
<expr
> MultiplicativeExpression
228 %type
<expr
> Initialiser_opt Initialiser
229 %type
<expr
> InitialiserNoIn_opt InitialiserNoIn
230 %type
<expr
> UnaryExpression
231 %type
<expr
> PostfixExpression
232 %type
<expr
> NewExpression
233 %type
<expr
> CallExpression
234 %type
<expr
> MemberExpression
235 %type
<expr
> PrimaryExpression
236 %type
<identifier
> Identifier_opt
237 %type
<variable_list
> VariableDeclarationList
238 %type
<variable_list
> VariableDeclarationListNoIn
239 %type
<variable_declaration
> VariableDeclaration
240 %type
<variable_declaration
> VariableDeclarationNoIn
241 %type
<case_list
> CaseClausules CaseClausules_opt
242 %type
<case_clausule
> CaseClausule DefaultClausule CaseBlock
243 %type
<catch_block
> Catch
244 %type
<argument_list
> Arguments
245 %type
<argument_list
> ArgumentList
246 %type
<literal
> Literal
247 %type
<expr
> ArrayLiteral
248 %type
<expr
> ObjectLiteral
249 %type
<ival
> Elision Elision_opt
250 %type
<element_list
> ElementList
251 %type
<property_list
> PropertyNameAndValueList
252 %type
<literal
> PropertyName
253 %type
<literal
> BooleanLiteral
254 %type
<srcptr
> KFunction
258 /* ECMA-262 3rd Edition 14 */
260 : SourceElements
{ program_parsed
(ctx
, $1); }
262 /* ECMA-262 3rd Edition 14 */
264 : /* empty */ { $$
= new_source_elements
(ctx
); }
265 | SourceElements Statement
266 { $$
= source_elements_add_statement
($1, $2); }
267 | SourceElements FunctionDeclaration
268 { $$
= source_elements_add_function
($1, $2); }
270 /* ECMA-262 3rd Edition 13 */
272 : KFunction tIdentifier
'(' FormalParameterList_opt
')' '{' FunctionBody
'}'
273 { $$
= new_function_declaration
(ctx
, $2, $4, $7, $1, $8-$1+1); }
275 /* ECMA-262 3rd Edition 13 */
277 : KFunction Identifier_opt
'(' FormalParameterList_opt
')' '{' FunctionBody
'}'
278 { $$
= new_function_expression
(ctx
, $2, $4, $7, $1, $8-$1+1); }
281 : kFUNCTION
{ push_func
(ctx
); $$
= $1; }
283 /* ECMA-262 3rd Edition 13 */
285 : SourceElements
{ $$
= function_body_parsed
(ctx
, $1); }
287 /* ECMA-262 3rd Edition 13 */
289 : tIdentifier
{ $$
= new_parameter_list
(ctx
, $1); }
290 | FormalParameterList
',' tIdentifier
291 { $$
= parameter_list_add
(ctx
, $1, $3); }
293 /* ECMA-262 3rd Edition 13 */
294 FormalParameterList_opt
295 : /* empty */ { $$
= NULL
; }
296 | FormalParameterList
{ $$
= $1; }
298 /* ECMA-262 3rd Edition 12 */
301 | VariableStatement
{ $$
= $1; }
302 | EmptyStatement
{ $$
= $1; }
303 | ExpressionStatement
{ $$
= $1; }
304 | IfStatement
{ $$
= $1; }
305 | IterationStatement
{ $$
= $1; }
306 | ContinueStatement
{ $$
= $1; }
307 | BreakStatement
{ $$
= $1; }
308 | ReturnStatement
{ $$
= $1; }
309 | WithStatement
{ $$
= $1; }
310 | LabelledStatement
{ $$
= $1; }
311 | SwitchStatement
{ $$
= $1; }
312 | ThrowStatement
{ $$
= $1; }
313 | TryStatement
{ $$
= $1; }
315 /* ECMA-262 3rd Edition 12.2 */
317 : Statement
{ $$
= new_statement_list
(ctx
, $1); }
318 | StatementList Statement
319 { $$
= statement_list_add
($1, $2); }
321 /* ECMA-262 3rd Edition 12.2 */
323 : /* empty */ { $$
= NULL
; }
324 | StatementList
{ $$
= $1; }
326 /* ECMA-262 3rd Edition 12.1 */
328 : '{' StatementList
'}' { $$
= new_block_statement
(ctx
, $2); }
329 |
'{' '}' { $$
= new_block_statement
(ctx
, NULL
) }
331 /* ECMA-262 3rd Edition 12.2 */
333 : kVAR VariableDeclarationList semicolon_opt
334 { $$
= new_var_statement
(ctx
, $2); }
336 /* ECMA-262 3rd Edition 12.2 */
337 VariableDeclarationList
338 : VariableDeclaration
{ $$
= new_variable_list
(ctx
, $1); }
339 | VariableDeclarationList
',' VariableDeclaration
340 { $$
= variable_list_add
(ctx
, $1, $3); }
342 /* ECMA-262 3rd Edition 12.2 */
343 VariableDeclarationListNoIn
344 : VariableDeclarationNoIn
345 { $$
= new_variable_list
(ctx
, $1); }
346 | VariableDeclarationListNoIn
',' VariableDeclarationNoIn
347 { $$
= variable_list_add
(ctx
, $1, $3); }
349 /* ECMA-262 3rd Edition 12.2 */
351 : tIdentifier Initialiser_opt
352 { $$
= new_variable_declaration
(ctx
, $1, $2); }
354 /* ECMA-262 3rd Edition 12.2 */
355 VariableDeclarationNoIn
356 : tIdentifier InitialiserNoIn_opt
357 { $$
= new_variable_declaration
(ctx
, $1, $2); }
359 /* ECMA-262 3rd Edition 12.2 */
361 : /* empty */ { $$
= NULL
; }
362 | Initialiser
{ $$
= $1; }
364 /* ECMA-262 3rd Edition 12.2 */
366 : '=' AssignmentExpression
369 /* ECMA-262 3rd Edition 12.2 */
371 : /* empty */ { $$
= NULL
; }
372 | InitialiserNoIn
{ $$
= $1; }
374 /* ECMA-262 3rd Edition 12.2 */
376 : '=' AssignmentExpressionNoIn
379 /* ECMA-262 3rd Edition 12.3 */
381 : ';' { $$
= new_empty_statement
(ctx
); }
383 /* ECMA-262 3rd Edition 12.4 */
385 : Expression semicolon_opt
386 { $$
= new_expression_statement
(ctx
, $1); }
388 /* ECMA-262 3rd Edition 12.5 */
390 : kIF
'(' Expression
')' Statement kELSE Statement
391 { $$
= new_if_statement
(ctx
, $3, $5, $7); }
392 | kIF
'(' Expression
')' Statement
393 { $$
= new_if_statement
(ctx
, $3, $5, NULL
); }
395 /* ECMA-262 3rd Edition 12.6 */
397 : kDO Statement kWHILE
'(' Expression
')' ';'
398 { $$
= new_while_statement
(ctx
, TRUE
, $5, $2); }
399 | kWHILE
'(' Expression
')' Statement
400 { $$
= new_while_statement
(ctx
, FALSE
, $3, $5); }
401 | kFOR
'(' ExpressionNoIn_opt
';' Expression_opt
';' Expression_opt
')' Statement
402 { $$
= new_for_statement
(ctx
, NULL
, $3, $5, $7, $9); }
403 | kFOR
'(' kVAR VariableDeclarationListNoIn
';' Expression_opt
';' Expression_opt
')' Statement
404 { $$
= new_for_statement
(ctx
, $4, NULL
, $6, $8, $10); }
405 | kFOR
'(' LeftHandSideExpression kIN Expression
')' Statement
406 { $$
= new_forin_statement
(ctx
, NULL
, $3, $5, $7); }
407 | kFOR
'(' kVAR VariableDeclarationNoIn kIN Expression
')' Statement
408 { $$
= new_forin_statement
(ctx
, $4, NULL
, $6, $8); }
410 /* ECMA-262 3rd Edition 12.7 */
412 : kCONTINUE
/* NONL */ Identifier_opt semicolon_opt
413 { $$
= new_continue_statement
(ctx
, $2); }
415 /* ECMA-262 3rd Edition 12.8 */
417 : kBREAK
/* NONL */ Identifier_opt semicolon_opt
418 { $$
= new_break_statement
(ctx
, $2); }
420 /* ECMA-262 3rd Edition 12.9 */
422 : kRETURN
/* NONL */ Expression_opt semicolon_opt
423 { $$
= new_return_statement
(ctx
, $2); }
425 /* ECMA-262 3rd Edition 12.10 */
427 : kWITH
'(' Expression
')' Statement
428 { $$
= new_with_statement
(ctx
, $3, $5); }
430 /* ECMA-262 3rd Edition 12.12 */
432 : tIdentifier
':' Statement
433 { $$
= new_labelled_statement
(ctx
, $1, $3); }
435 /* ECMA-262 3rd Edition 12.11 */
437 : kSWITCH
'(' Expression
')' CaseBlock
438 { $$
= new_switch_statement
(ctx
, $3, $5); }
440 /* ECMA-262 3rd Edition 12.11 */
442 : '{' CaseClausules_opt
'}'
443 { $$
= new_case_block
(ctx
, $2, NULL
, NULL
); }
444 |
'{' CaseClausules_opt DefaultClausule CaseClausules_opt
'}'
445 { $$
= new_case_block
(ctx
, $2, $3, $4); }
447 /* ECMA-262 3rd Edition 12.11 */
449 : /* empty */ { $$
= NULL
; }
450 | CaseClausules
{ $$
= $1; }
452 /* ECMA-262 3rd Edition 12.11 */
454 : CaseClausule
{ $$
= new_case_list
(ctx
, $1); }
455 | CaseClausules CaseClausule
456 { $$
= case_list_add
(ctx
, $1, $2); }
458 /* ECMA-262 3rd Edition 12.11 */
460 : kCASE Expression
':' StatementList_opt
461 { $$
= new_case_clausule
(ctx
, $2, $4); }
463 /* ECMA-262 3rd Edition 12.11 */
465 : kDEFAULT
':' StatementList_opt
466 { $$
= new_case_clausule
(ctx
, NULL
, $3); }
468 /* ECMA-262 3rd Edition 12.13 */
470 : kTHROW
/* NONL */ Expression semicolon_opt
471 { $$
= new_throw_statement
(ctx
, $2); }
473 /* ECMA-262 3rd Edition 12.14 */
475 : kTRY Block Catch
{ $$
= new_try_statement
(ctx
, $2, $3, NULL
); }
476 | kTRY Block Finally
{ $$
= new_try_statement
(ctx
, $2, NULL
, $3); }
477 | kTRY Block Catch Finally
478 { $$
= new_try_statement
(ctx
, $2, $3, $4); }
480 /* ECMA-262 3rd Edition 12.14 */
482 : kCATCH
'(' tIdentifier
')' Block
483 { $$
= new_catch_block
(ctx
, $3, $5); }
485 /* ECMA-262 3rd Edition 12.14 */
487 : kFINALLY Block
{ $$
= $2; }
489 /* ECMA-262 3rd Edition 11.14 */
491 : /* empty */ { $$
= NULL
; }
492 | Expression
{ $$
= $1; }
494 /* ECMA-262 3rd Edition 11.14 */
496 : AssignmentExpression
{ $$
= $1; }
497 | Expression
',' AssignmentExpression
498 { $$
= new_binary_expression
(ctx
, EXPR_COMMA
, $1, $3); }
500 /* ECMA-262 3rd Edition 11.14 */
502 : /* empty */ { $$
= NULL
; }
503 | ExpressionNoIn
{ $$
= $1; }
505 /* ECMA-262 3rd Edition 11.14 */
507 : AssignmentExpressionNoIn
509 | ExpressionNoIn
',' AssignmentExpressionNoIn
510 { $$
= new_binary_expression
(ctx
, EXPR_COMMA
, $1, $3); }
512 /* ECMA-262 3rd Edition 11.13 */
514 : ConditionalExpression
{ $$
= $1; }
515 | LeftHandSideExpression
'=' AssignmentExpression
516 { $$
= new_binary_expression
(ctx
, EXPR_ASSIGN
, $1, $3); }
517 | LeftHandSideExpression tAssignOper AssignmentExpression
518 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
520 /* ECMA-262 3rd Edition 11.13 */
521 AssignmentExpressionNoIn
522 : ConditionalExpressionNoIn
524 | LeftHandSideExpression
'=' AssignmentExpressionNoIn
525 { $$
= new_binary_expression
(ctx
, EXPR_ASSIGN
, $1, $3); }
526 | LeftHandSideExpression tAssignOper AssignmentExpressionNoIn
527 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
529 /* ECMA-262 3rd Edition 11.12 */
530 ConditionalExpression
531 : LogicalORExpression
{ $$
= $1; }
532 | LogicalORExpression
'?' AssignmentExpression
':' AssignmentExpression
533 { $$
= new_conditional_expression
(ctx
, $1, $3, $5); }
535 /* ECMA-262 3rd Edition 11.12 */
536 ConditionalExpressionNoIn
537 : LogicalORExpressionNoIn
539 | LogicalORExpressionNoIn
'?' AssignmentExpressionNoIn
':' AssignmentExpressionNoIn
540 { $$
= new_conditional_expression
(ctx
, $1, $3, $5); }
542 /* ECMA-262 3rd Edition 11.11 */
544 : LogicalANDExpression
{ $$
= $1; }
545 | LogicalORExpression tOROR LogicalANDExpression
546 { $$
= new_binary_expression
(ctx
, EXPR_OR
, $1, $3); }
548 /* ECMA-262 3rd Edition 11.11 */
549 LogicalORExpressionNoIn
550 : LogicalANDExpressionNoIn
552 | LogicalORExpressionNoIn tOROR LogicalANDExpressionNoIn
553 { $$
= new_binary_expression
(ctx
, EXPR_OR
, $1, $3); }
555 /* ECMA-262 3rd Edition 11.11 */
557 : BitwiseORExpression
{ $$
= $1; }
558 | LogicalANDExpression tANDAND BitwiseORExpression
559 { $$
= new_binary_expression
(ctx
, EXPR_AND
, $1, $3); }
561 /* ECMA-262 3rd Edition 11.11 */
562 LogicalANDExpressionNoIn
563 : BitwiseORExpressionNoIn
565 | LogicalANDExpressionNoIn tANDAND BitwiseORExpressionNoIn
566 { $$
= new_binary_expression
(ctx
, EXPR_AND
, $1, $3); }
568 /* ECMA-262 3rd Edition 11.10 */
570 : BitwiseXORExpression
{ $$
= $1; }
571 | BitwiseORExpression
'|' BitwiseXORExpression
572 { $$
= new_binary_expression
(ctx
, EXPR_BOR
, $1, $3); }
574 /* ECMA-262 3rd Edition 11.10 */
575 BitwiseORExpressionNoIn
576 : BitwiseXORExpressionNoIn
578 | BitwiseORExpressionNoIn
'|' BitwiseXORExpressionNoIn
579 { $$
= new_binary_expression
(ctx
, EXPR_BOR
, $1, $3); }
581 /* ECMA-262 3rd Edition 11.10 */
583 : BitwiseANDExpression
{ $$
= $1; }
584 | BitwiseXORExpression
'^' BitwiseANDExpression
585 { $$
= new_binary_expression
(ctx
, EXPR_BXOR
, $1, $3); }
587 /* ECMA-262 3rd Edition 11.10 */
588 BitwiseXORExpressionNoIn
589 : BitwiseANDExpressionNoIn
591 | BitwiseXORExpressionNoIn
'^' BitwiseANDExpressionNoIn
592 { $$
= new_binary_expression
(ctx
, EXPR_BXOR
, $1, $3); }
594 /* ECMA-262 3rd Edition 11.10 */
596 : EqualityExpression
{ $$
= $1; }
597 | BitwiseANDExpression
'&' EqualityExpression
598 { $$
= new_binary_expression
(ctx
, EXPR_BAND
, $1, $3); }
600 /* ECMA-262 3rd Edition 11.10 */
601 BitwiseANDExpressionNoIn
602 : EqualityExpressionNoIn
604 | BitwiseANDExpressionNoIn
'&' EqualityExpressionNoIn
605 { $$
= new_binary_expression
(ctx
, EXPR_BAND
, $1, $3); }
607 /* ECMA-262 3rd Edition 11.9 */
609 : RelationalExpression
{ $$
= $1; }
610 | EqualityExpression tEqOper RelationalExpression
611 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
613 /* ECMA-262 3rd Edition 11.9 */
614 EqualityExpressionNoIn
615 : RelationalExpressionNoIn
{ $$
= $1; }
616 | EqualityExpressionNoIn tEqOper RelationalExpressionNoIn
617 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
619 /* ECMA-262 3rd Edition 11.8 */
621 : ShiftExpression
{ $$
= $1; }
622 | RelationalExpression tRelOper ShiftExpression
623 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
624 | RelationalExpression kINSTANCEOF ShiftExpression
625 { $$
= new_binary_expression
(ctx
, EXPR_INSTANCEOF
, $1, $3); }
626 | RelationalExpression kIN ShiftExpression
627 { $$
= new_binary_expression
(ctx
, EXPR_IN
, $1, $3); }
629 /* ECMA-262 3rd Edition 11.8 */
630 RelationalExpressionNoIn
631 : ShiftExpression
{ $$
= $1; }
632 | RelationalExpressionNoIn tRelOper ShiftExpression
633 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
634 | RelationalExpressionNoIn kINSTANCEOF ShiftExpression
635 { $$
= new_binary_expression
(ctx
, EXPR_INSTANCEOF
, $1, $3); }
637 /* ECMA-262 3rd Edition 11.7 */
639 : AdditiveExpression
{ $$
= $1; }
640 | ShiftExpression tShiftOper AdditiveExpression
641 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
643 /* ECMA-262 3rd Edition 11.6 */
645 : MultiplicativeExpression
647 | AdditiveExpression
'+' MultiplicativeExpression
648 { $$
= new_binary_expression
(ctx
, EXPR_ADD
, $1, $3); }
649 | AdditiveExpression
'-' MultiplicativeExpression
650 { $$
= new_binary_expression
(ctx
, EXPR_SUB
, $1, $3); }
652 /* ECMA-262 3rd Edition 11.5 */
653 MultiplicativeExpression
654 : UnaryExpression
{ $$
= $1; }
655 | MultiplicativeExpression
'*' UnaryExpression
656 { $$
= new_binary_expression
(ctx
, EXPR_MUL
, $1, $3); }
657 | MultiplicativeExpression
'/' UnaryExpression
658 { $$
= new_binary_expression
(ctx
, EXPR_DIV
, $1, $3); }
659 | MultiplicativeExpression
'%' UnaryExpression
660 { $$
= new_binary_expression
(ctx
, EXPR_MOD
, $1, $3); }
662 /* ECMA-262 3rd Edition 11.4 */
664 : PostfixExpression
{ $$
= $1; }
665 | kDELETE UnaryExpression
666 { $$
= new_unary_expression
(ctx
, EXPR_DELETE
, $2); }
667 | kVOID UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_VOID
, $2); }
668 | kTYPEOF UnaryExpression
669 { $$
= new_unary_expression
(ctx
, EXPR_TYPEOF
, $2); }
670 | tINC UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_PREINC
, $2); }
671 | tDEC UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_PREDEC
, $2); }
672 |
'+' UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_PLUS
, $2); }
673 |
'-' UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_MINUS
, $2); }
674 |
'~' UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_BITNEG
, $2); }
675 |
'!' UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_LOGNEG
, $2); }
677 /* ECMA-262 3rd Edition 11.2 */
679 : LeftHandSideExpression
681 | LeftHandSideExpression
/* NONL */ tINC
682 { $$
= new_unary_expression
(ctx
, EXPR_POSTINC
, $1); }
683 | LeftHandSideExpression
/* NONL */ tDEC
684 { $$
= new_unary_expression
(ctx
, EXPR_POSTDEC
, $1); }
687 /* ECMA-262 3rd Edition 11.2 */
688 LeftHandSideExpression
689 : NewExpression
{ $$
= $1; }
690 | CallExpression
{ $$
= $1; }
692 /* ECMA-262 3rd Edition 11.2 */
694 : MemberExpression
{ $$
= $1; }
695 | kNEW NewExpression
{ $$
= new_new_expression
(ctx
, $2, NULL
); }
697 /* ECMA-262 3rd Edition 11.2 */
699 : PrimaryExpression
{ $$
= $1; }
700 | FunctionExpression
{ $$
= $1; }
701 | MemberExpression
'[' Expression
']'
702 { $$
= new_array_expression
(ctx
, $1, $3); }
703 | MemberExpression
'.' tIdentifier
704 { $$
= new_member_expression
(ctx
, $1, $3); }
705 | kNEW MemberExpression Arguments
706 { $$
= new_new_expression
(ctx
, $2, $3); }
708 /* ECMA-262 3rd Edition 11.2 */
710 : MemberExpression Arguments
711 { $$
= new_call_expression
(ctx
, $1, $2); }
712 | CallExpression Arguments
713 { $$
= new_call_expression
(ctx
, $1, $2); }
714 | CallExpression
'[' Expression
']'
715 { $$
= new_array_expression
(ctx
, $1, $3); }
716 | CallExpression
'.' tIdentifier
717 { $$
= new_member_expression
(ctx
, $1, $3); }
719 /* ECMA-262 3rd Edition 11.2 */
721 : '(' ')' { $$
= NULL
; }
722 |
'(' ArgumentList
')' { $$
= $2; }
724 /* ECMA-262 3rd Edition 11.2 */
726 : AssignmentExpression
{ $$
= new_argument_list
(ctx
, $1); }
727 | ArgumentList
',' AssignmentExpression
728 { $$
= argument_list_add
(ctx
, $1, $3); }
730 /* ECMA-262 3rd Edition 11.1 */
732 : kTHIS
{ $$
= new_this_expression
(ctx
); }
733 | tIdentifier
{ $$
= new_identifier_expression
(ctx
, $1); }
734 | Literal
{ $$
= new_literal_expression
(ctx
, $1); }
735 | ArrayLiteral
{ $$
= $1; }
736 | ObjectLiteral
{ $$
= $1; }
737 |
'(' Expression
')' { $$
= $2; }
739 /* ECMA-262 3rd Edition 11.1.4 */
741 : '[' ']' { $$
= new_array_literal_expression
(ctx
, NULL
, 0); }
742 |
'[' Elision_opt
']' { $$
= new_array_literal_expression
(ctx
, NULL
, $2+1); }
743 |
'[' ElementList
']' { $$
= new_array_literal_expression
(ctx
, $2, 0); }
744 |
'[' ElementList
',' Elision_opt
']'
745 { $$
= new_array_literal_expression
(ctx
, $2, $4+1); }
747 /* ECMA-262 3rd Edition 11.1.4 */
749 : Elision_opt AssignmentExpression
750 { $$
= new_element_list
(ctx
, $1, $2); }
751 | ElementList
',' Elision_opt AssignmentExpression
752 { $$
= element_list_add
(ctx
, $1, $3, $4); }
754 /* ECMA-262 3rd Edition 11.1.4 */
757 | Elision
',' { $$
= $1 + 1; }
759 /* ECMA-262 3rd Edition 11.1.4 */
761 : /* empty */ { $$
= 0; }
762 | Elision
{ $$
= $1; }
764 /* ECMA-262 3rd Edition 11.1.5 */
766 : '{' '}' { $$
= new_prop_and_value_expression
(ctx
, NULL
); }
767 |
'{' PropertyNameAndValueList
'}'
768 { $$
= new_prop_and_value_expression
(ctx
, $2); }
770 /* ECMA-262 3rd Edition 11.1.5 */
771 PropertyNameAndValueList
772 : PropertyName
':' AssignmentExpression
773 { $$
= new_property_list
(ctx
, $1, $3); }
774 | PropertyNameAndValueList
',' PropertyName
':' AssignmentExpression
775 { $$
= property_list_add
(ctx
, $1, $3, $5); }
777 /* ECMA-262 3rd Edition 11.1.5 */
779 : tIdentifier
{ $$
= new_string_literal
(ctx
, $1); }
780 | tStringLiteral
{ $$
= new_string_literal
(ctx
, $1); }
781 | tNumericLiteral
{ $$
= $1; }
783 /* ECMA-262 3rd Edition 7.6 */
785 : /* empty*/ { $$
= NULL
; }
786 | tIdentifier
{ $$
= $1; }
788 /* ECMA-262 3rd Edition 7.8 */
790 : kNULL
{ $$
= new_null_literal
(ctx
); }
791 | kUNDEFINED
{ $$
= new_undefined_literal
(ctx
); }
792 | BooleanLiteral
{ $$
= $1; }
793 | tNumericLiteral
{ $$
= $1; }
794 | tStringLiteral
{ $$
= new_string_literal
(ctx
, $1); }
795 |
'/' { $$
= parse_regexp
(ctx
);
798 /* ECMA-262 3rd Edition 7.8.2 */
800 : kTRUE
{ $$
= new_boolean_literal
(ctx
, TRUE
); }
801 | kFALSE
{ $$
= new_boolean_literal
(ctx
, FALSE
); }
805 |
error { if
(!allow_auto_semicolon
(ctx
)) {YYABORT;} }
809 static BOOL allow_auto_semicolon
(parser_ctx_t
*ctx
)
811 return ctx
->nl || ctx
->ptr
== ctx
->end ||
*(ctx
->ptr
-1) == '}';
814 static literal_t
*new_string_literal
(parser_ctx_t
*ctx
, const WCHAR
*str
)
816 literal_t
*ret
= parser_alloc
(ctx
, sizeof
(literal_t
));
824 static literal_t
*new_null_literal
(parser_ctx_t
*ctx
)
826 literal_t
*ret
= parser_alloc
(ctx
, sizeof
(literal_t
));
833 static literal_t
*new_undefined_literal
(parser_ctx_t
*ctx
)
835 literal_t
*ret
= parser_alloc
(ctx
, sizeof
(literal_t
));
842 static literal_t
*new_boolean_literal
(parser_ctx_t
*ctx
, VARIANT_BOOL bval
)
844 literal_t
*ret
= parser_alloc
(ctx
, sizeof
(literal_t
));
852 static prop_val_t
*new_prop_val
(parser_ctx_t
*ctx
, literal_t
*name
, expression_t
*value
)
854 prop_val_t
*ret
= parser_alloc
(ctx
, sizeof
(prop_val_t
));
863 static property_list_t
*new_property_list
(parser_ctx_t
*ctx
, literal_t
*name
, expression_t
*value
)
865 property_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(property_list_t
));
867 ret
->head
= ret
->tail
= new_prop_val
(ctx
, name
, value
);
872 static property_list_t
*property_list_add
(parser_ctx_t
*ctx
, property_list_t
*list
, literal_t
*name
, expression_t
*value
)
874 list
->tail
= list
->tail
->next
= new_prop_val
(ctx
, name
, value
);
879 static array_element_t
*new_array_element
(parser_ctx_t
*ctx
, int elision
, expression_t
*expr
)
881 array_element_t
*ret
= parser_alloc
(ctx
, sizeof
(array_element_t
));
883 ret
->elision
= elision
;
890 static element_list_t
*new_element_list
(parser_ctx_t
*ctx
, int elision
, expression_t
*expr
)
892 element_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(element_list_t
));
894 ret
->head
= ret
->tail
= new_array_element
(ctx
, elision
, expr
);
899 static element_list_t
*element_list_add
(parser_ctx_t
*ctx
, element_list_t
*list
, int elision
, expression_t
*expr
)
901 list
->tail
= list
->tail
->next
= new_array_element
(ctx
, elision
, expr
);
906 static argument_t
*new_argument
(parser_ctx_t
*ctx
, expression_t
*expr
)
908 argument_t
*ret
= parser_alloc
(ctx
, sizeof
(argument_t
));
916 static argument_list_t
*new_argument_list
(parser_ctx_t
*ctx
, expression_t
*expr
)
918 argument_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(argument_list_t
));
920 ret
->head
= ret
->tail
= new_argument
(ctx
, expr
);
925 static argument_list_t
*argument_list_add
(parser_ctx_t
*ctx
, argument_list_t
*list
, expression_t
*expr
)
927 list
->tail
= list
->tail
->next
= new_argument
(ctx
, expr
);
932 static catch_block_t
*new_catch_block
(parser_ctx_t
*ctx
, const WCHAR
*identifier
, statement_t
*statement
)
934 catch_block_t
*ret
= parser_alloc
(ctx
, sizeof
(catch_block_t
));
936 ret
->identifier
= identifier
;
937 ret
->statement
= statement
;
942 static case_clausule_t
*new_case_clausule
(parser_ctx_t
*ctx
, expression_t
*expr
, statement_list_t
*stat_list
)
944 case_clausule_t
*ret
= parser_alloc
(ctx
, sizeof
(case_clausule_t
));
947 ret
->stat
= stat_list ? stat_list
->head
: NULL
;
953 static case_list_t
*new_case_list
(parser_ctx_t
*ctx
, case_clausule_t
*case_clausule
)
955 case_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(case_list_t
));
957 ret
->head
= ret
->tail
= case_clausule
;
962 static case_list_t
*case_list_add
(parser_ctx_t
*ctx
, case_list_t
*list
, case_clausule_t
*case_clausule
)
964 list
->tail
= list
->tail
->next
= case_clausule
;
969 static case_clausule_t
*new_case_block
(parser_ctx_t
*ctx
, case_list_t
*case_list1
,
970 case_clausule_t
*default_clausule
, case_list_t
*case_list2
)
972 case_clausule_t
*ret
= NULL
, *iter
= NULL
, *iter2
;
973 statement_t
*stat
= NULL
;
976 ret
= case_list1
->head
;
977 iter
= case_list1
->tail
;
980 if
(default_clausule
) {
982 iter
= iter
->next
= default_clausule
;
984 ret
= iter
= default_clausule
;
989 iter
->next
= case_list2
->head
;
991 ret
= case_list2
->head
;
997 for
(iter
= ret
; iter
; iter
= iter
->next
) {
998 for
(iter2
= iter
; iter2
&& !iter2
->stat
; iter2
= iter2
->next
);
1002 while
(iter
!= iter2
) {
1003 iter
->stat
= iter2
->stat
;
1010 stat
->next
= iter
->stat
;
1019 static statement_t
*new_block_statement
(parser_ctx_t
*ctx
, statement_list_t
*list
)
1021 block_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(block_statement_t
));
1023 ret
->stat.eval
= block_statement_eval
;
1024 ret
->stat.next
= NULL
;
1025 ret
->stat_list
= list ? list
->head
: NULL
;
1030 static variable_declaration_t
*new_variable_declaration
(parser_ctx_t
*ctx
, const WCHAR
*identifier
, expression_t
*expr
)
1032 variable_declaration_t
*ret
= parser_alloc
(ctx
, sizeof
(variable_declaration_t
));
1033 var_list_t
*var_list
= parser_alloc
(ctx
, sizeof
(var_list_t
));
1035 ret
->identifier
= identifier
;
1039 var_list
->identifier
= identifier
;
1040 var_list
->next
= NULL
;
1042 if
(ctx
->func_stack
->var_tail
)
1043 ctx
->func_stack
->var_tail
= ctx
->func_stack
->var_tail
->next
= var_list
;
1045 ctx
->func_stack
->var_head
= ctx
->func_stack
->var_tail
= var_list
;
1050 static variable_list_t
*new_variable_list
(parser_ctx_t
*ctx
, variable_declaration_t
*decl
)
1052 variable_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(variable_list_t
));
1054 ret
->head
= ret
->tail
= decl
;
1059 static variable_list_t
*variable_list_add
(parser_ctx_t
*ctx
, variable_list_t
*list
, variable_declaration_t
*decl
)
1061 list
->tail
= list
->tail
->next
= decl
;
1066 static statement_t
*new_var_statement
(parser_ctx_t
*ctx
, variable_list_t
*variable_list
)
1068 var_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(var_statement_t
));
1070 ret
->stat.eval
= var_statement_eval
;
1071 ret
->stat.next
= NULL
;
1072 ret
->variable_list
= variable_list
->head
;
1077 static statement_t
*new_empty_statement
(parser_ctx_t
*ctx
)
1079 statement_t
*ret
= parser_alloc
(ctx
, sizeof
(statement_t
));
1081 ret
->eval
= empty_statement_eval
;
1087 static statement_t
*new_expression_statement
(parser_ctx_t
*ctx
, expression_t
*expr
)
1089 expression_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(expression_statement_t
));
1091 ret
->stat.eval
= expression_statement_eval
;
1092 ret
->stat.next
= NULL
;
1098 static statement_t
*new_if_statement
(parser_ctx_t
*ctx
, expression_t
*expr
, statement_t
*if_stat
, statement_t
*else_stat
)
1100 if_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(if_statement_t
));
1102 ret
->stat.eval
= if_statement_eval
;
1103 ret
->stat.next
= NULL
;
1105 ret
->if_stat
= if_stat
;
1106 ret
->else_stat
= else_stat
;
1111 static statement_t
*new_while_statement
(parser_ctx_t
*ctx
, BOOL dowhile
, expression_t
*expr
, statement_t
*stat
)
1113 while_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(while_statement_t
));
1115 ret
->stat.eval
= while_statement_eval
;
1116 ret
->stat.next
= NULL
;
1117 ret
->do_while
= dowhile
;
1119 ret
->statement
= stat
;
1124 static statement_t
*new_for_statement
(parser_ctx_t
*ctx
, variable_list_t
*variable_list
, expression_t
*begin_expr
,
1125 expression_t
*expr
, expression_t
*end_expr
, statement_t
*statement
)
1127 for_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(for_statement_t
));
1129 ret
->stat.eval
= for_statement_eval
;
1130 ret
->stat.next
= NULL
;
1131 ret
->variable_list
= variable_list ? variable_list
->head
: NULL
;
1132 ret
->begin_expr
= begin_expr
;
1134 ret
->end_expr
= end_expr
;
1135 ret
->statement
= statement
;
1140 static statement_t
*new_forin_statement
(parser_ctx_t
*ctx
, variable_declaration_t
*variable
, expression_t
*expr
,
1141 expression_t
*in_expr
, statement_t
*statement
)
1143 forin_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(forin_statement_t
));
1145 ret
->stat.eval
= forin_statement_eval
;
1146 ret
->stat.next
= NULL
;
1147 ret
->variable
= variable
;
1149 ret
->in_expr
= in_expr
;
1150 ret
->statement
= statement
;
1155 static statement_t
*new_continue_statement
(parser_ctx_t
*ctx
, const WCHAR
*identifier
)
1157 branch_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(branch_statement_t
));
1159 ret
->stat.eval
= continue_statement_eval
;
1160 ret
->stat.next
= NULL
;
1161 ret
->identifier
= identifier
;
1166 static statement_t
*new_break_statement
(parser_ctx_t
*ctx
, const WCHAR
*identifier
)
1168 branch_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(branch_statement_t
));
1170 ret
->stat.eval
= break_statement_eval
;
1171 ret
->stat.next
= NULL
;
1172 ret
->identifier
= identifier
;
1177 static statement_t
*new_return_statement
(parser_ctx_t
*ctx
, expression_t
*expr
)
1179 expression_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(expression_statement_t
));
1181 ret
->stat.eval
= return_statement_eval
;
1182 ret
->stat.next
= NULL
;
1188 static statement_t
*new_with_statement
(parser_ctx_t
*ctx
, expression_t
*expr
, statement_t
*statement
)
1190 with_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(with_statement_t
));
1192 ret
->stat.eval
= with_statement_eval
;
1193 ret
->stat.next
= NULL
;
1195 ret
->statement
= statement
;
1200 static statement_t
*new_labelled_statement
(parser_ctx_t
*ctx
, const WCHAR
*identifier
, statement_t
*statement
)
1202 labelled_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(labelled_statement_t
));
1204 ret
->stat.eval
= labelled_statement_eval
;
1205 ret
->stat.next
= NULL
;
1206 ret
->identifier
= identifier
;
1207 ret
->statement
= statement
;
1212 static statement_t
*new_switch_statement
(parser_ctx_t
*ctx
, expression_t
*expr
, case_clausule_t
*case_list
)
1214 switch_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(switch_statement_t
));
1216 ret
->stat.eval
= switch_statement_eval
;
1217 ret
->stat.next
= NULL
;
1219 ret
->case_list
= case_list
;
1224 static statement_t
*new_throw_statement
(parser_ctx_t
*ctx
, expression_t
*expr
)
1226 expression_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(expression_statement_t
));
1228 ret
->stat.eval
= throw_statement_eval
;
1229 ret
->stat.next
= NULL
;
1235 static statement_t
*new_try_statement
(parser_ctx_t
*ctx
, statement_t
*try_statement
,
1236 catch_block_t
*catch_block
, statement_t
*finally_statement
)
1238 try_statement_t
*ret
= parser_alloc
(ctx
, sizeof
(try_statement_t
));
1240 ret
->stat.eval
= try_statement_eval
;
1241 ret
->stat.next
= NULL
;
1242 ret
->try_statement
= try_statement
;
1243 ret
->catch_block
= catch_block
;
1244 ret
->finally_statement
= finally_statement
;
1249 static parameter_t
*new_parameter
(parser_ctx_t
*ctx
, const WCHAR
*identifier
)
1251 parameter_t
*ret
= parser_alloc
(ctx
, sizeof
(parameter_t
));
1253 ret
->identifier
= identifier
;
1259 static parameter_list_t
*new_parameter_list
(parser_ctx_t
*ctx
, const WCHAR
*identifier
)
1261 parameter_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(parameter_list_t
));
1263 ret
->head
= ret
->tail
= new_parameter
(ctx
, identifier
);
1268 static parameter_list_t
*parameter_list_add
(parser_ctx_t
*ctx
, parameter_list_t
*list
, const WCHAR
*identifier
)
1270 list
->tail
= list
->tail
->next
= new_parameter
(ctx
, identifier
);
1275 static expression_t
*new_function_expression
(parser_ctx_t
*ctx
, const WCHAR
*identifier
,
1276 parameter_list_t
*parameter_list
, source_elements_t
*source_elements
, const WCHAR
*src_str
, DWORD src_len
)
1278 function_expression_t
*ret
= parser_alloc
(ctx
, sizeof
(function_expression_t
));
1280 ret
->expr.eval
= function_expression_eval
;
1281 ret
->identifier
= identifier
;
1282 ret
->parameter_list
= parameter_list ? parameter_list
->head
: NULL
;
1283 ret
->source_elements
= source_elements
;
1284 ret
->src_str
= src_str
;
1285 ret
->src_len
= src_len
;
1290 static const expression_eval_t expression_eval_table
[] = {
1291 comma_expression_eval
,
1292 logical_or_expression_eval
,
1293 logical_and_expression_eval
,
1294 binary_or_expression_eval
,
1295 binary_xor_expression_eval
,
1296 binary_and_expression_eval
,
1297 instanceof_expression_eval
,
1299 add_expression_eval
,
1300 sub_expression_eval
,
1301 mul_expression_eval
,
1302 div_expression_eval
,
1303 mod_expression_eval
,
1304 delete_expression_eval
,
1305 void_expression_eval
,
1306 typeof_expression_eval
,
1307 minus_expression_eval
,
1308 plus_expression_eval
,
1309 post_increment_expression_eval
,
1310 post_decrement_expression_eval
,
1311 pre_increment_expression_eval
,
1312 pre_decrement_expression_eval
,
1313 equal_expression_eval
,
1314 equal2_expression_eval
,
1315 not_equal_expression_eval
,
1316 not_equal2_expression_eval
,
1317 less_expression_eval
,
1318 lesseq_expression_eval
,
1319 greater_expression_eval
,
1320 greatereq_expression_eval
,
1321 binary_negation_expression_eval
,
1322 logical_negation_expression_eval
,
1323 left_shift_expression_eval
,
1324 right_shift_expression_eval
,
1325 right2_shift_expression_eval
,
1326 assign_expression_eval
,
1327 assign_lshift_expression_eval
,
1328 assign_rshift_expression_eval
,
1329 assign_rrshift_expression_eval
,
1330 assign_add_expression_eval
,
1331 assign_sub_expression_eval
,
1332 assign_mul_expression_eval
,
1333 assign_div_expression_eval
,
1334 assign_mod_expression_eval
,
1335 assign_and_expression_eval
,
1336 assign_or_expression_eval
,
1337 assign_xor_expression_eval
,
1340 static expression_t
*new_binary_expression
(parser_ctx_t
*ctx
, expression_type_t type
,
1341 expression_t
*expression1
, expression_t
*expression2
)
1343 binary_expression_t
*ret
= parser_alloc
(ctx
, sizeof
(binary_expression_t
));
1345 ret
->expr.eval
= expression_eval_table
[type
];
1346 ret
->expression1
= expression1
;
1347 ret
->expression2
= expression2
;
1352 static expression_t
*new_unary_expression
(parser_ctx_t
*ctx
, expression_type_t type
, expression_t
*expression
)
1354 unary_expression_t
*ret
= parser_alloc
(ctx
, sizeof
(unary_expression_t
));
1356 ret
->expr.eval
= expression_eval_table
[type
];
1357 ret
->expression
= expression
;
1362 static expression_t
*new_conditional_expression
(parser_ctx_t
*ctx
, expression_t
*expression
,
1363 expression_t
*true_expression
, expression_t
*false_expression
)
1365 conditional_expression_t
*ret
= parser_alloc
(ctx
, sizeof
(conditional_expression_t
));
1367 ret
->expr.eval
= conditional_expression_eval
;
1368 ret
->expression
= expression
;
1369 ret
->true_expression
= true_expression
;
1370 ret
->false_expression
= false_expression
;
1375 static expression_t
*new_array_expression
(parser_ctx_t
*ctx
, expression_t
*member_expr
, expression_t
*expression
)
1377 array_expression_t
*ret
= parser_alloc
(ctx
, sizeof
(array_expression_t
));
1379 ret
->expr.eval
= array_expression_eval
;
1380 ret
->member_expr
= member_expr
;
1381 ret
->expression
= expression
;
1386 static expression_t
*new_member_expression
(parser_ctx_t
*ctx
, expression_t
*expression
, const WCHAR
*identifier
)
1388 member_expression_t
*ret
= parser_alloc
(ctx
, sizeof
(member_expression_t
));
1390 ret
->expr.eval
= member_expression_eval
;
1391 ret
->expression
= expression
;
1392 ret
->identifier
= identifier
;
1397 static expression_t
*new_new_expression
(parser_ctx_t
*ctx
, expression_t
*expression
, argument_list_t
*argument_list
)
1399 call_expression_t
*ret
= parser_alloc
(ctx
, sizeof
(call_expression_t
));
1401 ret
->expr.eval
= new_expression_eval
;
1402 ret
->expression
= expression
;
1403 ret
->argument_list
= argument_list ? argument_list
->head
: NULL
;
1408 static expression_t
*new_call_expression
(parser_ctx_t
*ctx
, expression_t
*expression
, argument_list_t
*argument_list
)
1410 call_expression_t
*ret
= parser_alloc
(ctx
, sizeof
(call_expression_t
));
1412 ret
->expr.eval
= call_expression_eval
;
1413 ret
->expression
= expression
;
1414 ret
->argument_list
= argument_list ? argument_list
->head
: NULL
;
1419 static expression_t
*new_this_expression
(parser_ctx_t
*ctx
)
1421 expression_t
*ret
= parser_alloc
(ctx
, sizeof
(expression_t
));
1423 ret
->eval
= this_expression_eval
;
1428 static int parser_error
(const char *str
)
1433 static expression_t
*new_identifier_expression
(parser_ctx_t
*ctx
, const WCHAR
*identifier
)
1435 identifier_expression_t
*ret
= parser_alloc
(ctx
, sizeof
(identifier_expression_t
));
1437 ret
->expr.eval
= identifier_expression_eval
;
1438 ret
->identifier
= identifier
;
1443 static expression_t
*new_array_literal_expression
(parser_ctx_t
*ctx
, element_list_t
*element_list
, int length
)
1445 array_literal_expression_t
*ret
= parser_alloc
(ctx
, sizeof
(array_literal_expression_t
));
1447 ret
->expr.eval
= array_literal_expression_eval
;
1448 ret
->element_list
= element_list ? element_list
->head
: NULL
;
1449 ret
->length
= length
;
1454 static expression_t
*new_prop_and_value_expression
(parser_ctx_t
*ctx
, property_list_t
*property_list
)
1456 property_value_expression_t
*ret
= parser_alloc
(ctx
, sizeof
(property_value_expression_t
));
1458 ret
->expr.eval
= property_value_expression_eval
;
1459 ret
->property_list
= property_list ? property_list
->head
: NULL
;
1464 static expression_t
*new_literal_expression
(parser_ctx_t
*ctx
, literal_t
*literal
)
1466 literal_expression_t
*ret
= parser_alloc
(ctx
, sizeof
(literal_expression_t
));
1468 ret
->expr.eval
= literal_expression_eval
;
1469 ret
->literal
= literal
;
1474 static function_declaration_t
*new_function_declaration
(parser_ctx_t
*ctx
, const WCHAR
*identifier
,
1475 parameter_list_t
*parameter_list
, source_elements_t
*source_elements
, const WCHAR
*src_str
, DWORD src_len
)
1477 function_declaration_t
*ret
= parser_alloc
(ctx
, sizeof
(function_declaration_t
));
1479 ret
->identifier
= identifier
;
1480 ret
->parameter_list
= parameter_list ? parameter_list
->head
: NULL
;
1481 ret
->source_elements
= source_elements
;
1482 ret
->src_str
= src_str
;
1483 ret
->src_len
= src_len
;
1489 static source_elements_t
*new_source_elements
(parser_ctx_t
*ctx
)
1491 source_elements_t
*ret
= parser_alloc
(ctx
, sizeof
(source_elements_t
));
1493 memset
(ret
, 0, sizeof
(*ret
));
1498 static source_elements_t
*source_elements_add_statement
(source_elements_t
*source_elements
, statement_t
*statement
)
1500 if
(source_elements
->statement_tail
)
1501 source_elements
->statement_tail
= source_elements
->statement_tail
->next
= statement
;
1503 source_elements
->statement
= source_elements
->statement_tail
= statement
;
1505 return source_elements
;
1508 static source_elements_t
*source_elements_add_function
(source_elements_t
*source_elements
,
1509 function_declaration_t
*function_declaration
)
1511 if
(source_elements
->functions_tail
)
1512 source_elements
->functions_tail
= source_elements
->functions_tail
->next
= function_declaration
;
1514 source_elements
->functions
= source_elements
->functions_tail
= function_declaration
;
1516 return source_elements
;
1519 statement_list_t
*new_statement_list
(parser_ctx_t
*ctx
, statement_t
*statement
)
1521 statement_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(statement_list_t
));
1523 ret
->head
= ret
->tail
= statement
;
1528 statement_list_t
*statement_list_add
(statement_list_t
*list
, statement_t
*statement
)
1530 list
->tail
= list
->tail
->next
= statement
;
1535 static void push_func
(parser_ctx_t
*ctx
)
1537 func_stack_t
*new_func
= parser_alloc_tmp
(ctx
, sizeof
(func_stack_t
));
1539 new_func
->var_head
= new_func
->var_tail
= NULL
;
1541 new_func
->next
= ctx
->func_stack
;
1542 ctx
->func_stack
= new_func
;
1545 static source_elements_t
*function_body_parsed
(parser_ctx_t
*ctx
, source_elements_t
*source
)
1547 source
->variables
= ctx
->func_stack
->var_head
;
1553 static void program_parsed
(parser_ctx_t
*ctx
, source_elements_t
*source
)
1555 source
->variables
= ctx
->func_stack
->var_head
;
1558 ctx
->source
= source
;
1562 void parser_release
(parser_ctx_t
*ctx
)
1564 obj_literal_t
*iter
;
1569 for
(iter
= ctx
->obj_literals
; iter
; iter
= iter
->next
)
1570 jsdisp_release
(iter
->obj
);
1572 jsheap_free
(&ctx
->heap
);
1576 HRESULT script_parse
(script_ctx_t
*ctx
, const WCHAR
*code
, parser_ctx_t
**ret
)
1578 parser_ctx_t
*parser_ctx
;
1582 parser_ctx
= heap_alloc_zero
(sizeof
(parser_ctx_t
));
1584 return E_OUTOFMEMORY
;
1586 parser_ctx
->ref
= 1;
1587 parser_ctx
->hres
= E_FAIL
;
1589 parser_ctx
->begin
= parser_ctx
->ptr
= code
;
1590 parser_ctx
->end
= code
+ strlenW
(code
);
1593 parser_ctx
->script
= ctx
;
1595 mark
= jsheap_mark
(&ctx
->tmp_heap
);
1596 jsheap_init
(&parser_ctx
->heap
);
1598 push_func
(parser_ctx
);
1600 parser_parse
(parser_ctx
);
1602 if
(FAILED
(parser_ctx
->hres
)) {
1603 hres
= parser_ctx
->hres
;
1604 parser_release
(parser_ctx
);