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
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL
(jscript
);
29 static int parser_error
(parser_ctx_t
*,const char*);
30 static void set_error
(parser_ctx_t
*,UINT
);
31 static BOOL explicit_error
(parser_ctx_t
*,void*,WCHAR
);
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
*);
43 typedef
struct _property_list_t
{
48 static property_list_t
*new_property_list
(parser_ctx_t
*,literal_t
*,expression_t
*);
49 static property_list_t
*property_list_add
(parser_ctx_t
*,property_list_t
*,literal_t
*,expression_t
*);
51 typedef
struct _element_list_t
{
52 array_element_t
*head
;
53 array_element_t
*tail
;
56 static element_list_t
*new_element_list
(parser_ctx_t
*,int,expression_t
*);
57 static element_list_t
*element_list_add
(parser_ctx_t
*,element_list_t
*,int,expression_t
*);
59 typedef
struct _argument_list_t
{
64 static argument_list_t
*new_argument_list
(parser_ctx_t
*,expression_t
*);
65 static argument_list_t
*argument_list_add
(parser_ctx_t
*,argument_list_t
*,expression_t
*);
67 typedef
struct _case_list_t
{
68 case_clausule_t
*head
;
69 case_clausule_t
*tail
;
72 static catch_block_t
*new_catch_block
(parser_ctx_t
*,const WCHAR
*,statement_t
*);
73 static case_clausule_t
*new_case_clausule
(parser_ctx_t
*,expression_t
*,statement_list_t
*);
74 static case_list_t
*new_case_list
(parser_ctx_t
*,case_clausule_t
*);
75 static case_list_t
*case_list_add
(parser_ctx_t
*,case_list_t
*,case_clausule_t
*);
76 static case_clausule_t
*new_case_block
(parser_ctx_t
*,case_list_t
*,case_clausule_t
*,case_list_t
*);
78 typedef
struct _variable_list_t
{
79 variable_declaration_t
*head
;
80 variable_declaration_t
*tail
;
83 static variable_declaration_t
*new_variable_declaration
(parser_ctx_t
*,const WCHAR
*,expression_t
*);
84 static variable_list_t
*new_variable_list
(parser_ctx_t
*,variable_declaration_t
*);
85 static variable_list_t
*variable_list_add
(parser_ctx_t
*,variable_list_t
*,variable_declaration_t
*);
87 static void *new_statement
(parser_ctx_t
*,statement_type_t
,size_t);
88 static statement_t
*new_block_statement
(parser_ctx_t
*,statement_list_t
*);
89 static statement_t
*new_var_statement
(parser_ctx_t
*,variable_list_t
*);
90 static statement_t
*new_expression_statement
(parser_ctx_t
*,expression_t
*);
91 static statement_t
*new_if_statement
(parser_ctx_t
*,expression_t
*,statement_t
*,statement_t
*);
92 static statement_t
*new_while_statement
(parser_ctx_t
*,BOOL
,expression_t
*,statement_t
*);
93 static statement_t
*new_for_statement
(parser_ctx_t
*,variable_list_t
*,expression_t
*,expression_t
*,
94 expression_t
*,statement_t
*);
95 static statement_t
*new_forin_statement
(parser_ctx_t
*,variable_declaration_t
*,expression_t
*,expression_t
*,statement_t
*);
96 static statement_t
*new_continue_statement
(parser_ctx_t
*,const WCHAR
*);
97 static statement_t
*new_break_statement
(parser_ctx_t
*,const WCHAR
*);
98 static statement_t
*new_return_statement
(parser_ctx_t
*,expression_t
*);
99 static statement_t
*new_with_statement
(parser_ctx_t
*,expression_t
*,statement_t
*);
100 static statement_t
*new_labelled_statement
(parser_ctx_t
*,const WCHAR
*,statement_t
*);
101 static statement_t
*new_switch_statement
(parser_ctx_t
*,expression_t
*,case_clausule_t
*);
102 static statement_t
*new_throw_statement
(parser_ctx_t
*,expression_t
*);
103 static statement_t
*new_try_statement
(parser_ctx_t
*,statement_t
*,catch_block_t
*,statement_t
*);
105 struct statement_list_t
{
110 static statement_list_t
*new_statement_list
(parser_ctx_t
*,statement_t
*);
111 static statement_list_t
*statement_list_add
(statement_list_t
*,statement_t
*);
113 typedef
struct _parameter_list_t
{
118 static parameter_list_t
*new_parameter_list
(parser_ctx_t
*,const WCHAR
*);
119 static parameter_list_t
*parameter_list_add
(parser_ctx_t
*,parameter_list_t
*,const WCHAR
*);
121 static void *new_expression
(parser_ctx_t
*ctx
,expression_type_t
,size_t);
122 static expression_t
*new_function_expression
(parser_ctx_t
*,const WCHAR
*,parameter_list_t
*,
123 source_elements_t
*,const WCHAR
*,DWORD
);
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_member_expression
(parser_ctx_t
*,expression_t
*,const WCHAR
*);
128 static expression_t
*new_new_expression
(parser_ctx_t
*,expression_t
*,argument_list_t
*);
129 static expression_t
*new_call_expression
(parser_ctx_t
*,expression_t
*,argument_list_t
*);
130 static expression_t
*new_identifier_expression
(parser_ctx_t
*,const WCHAR
*);
131 static expression_t
*new_literal_expression
(parser_ctx_t
*,literal_t
*);
132 static expression_t
*new_array_literal_expression
(parser_ctx_t
*,element_list_t
*,int);
133 static expression_t
*new_prop_and_value_expression
(parser_ctx_t
*,property_list_t
*);
135 static source_elements_t
*new_source_elements
(parser_ctx_t
*);
136 static source_elements_t
*source_elements_add_statement
(source_elements_t
*,statement_t
*);
140 %lex
-param
{ parser_ctx_t
*ctx
}
141 %parse
-param
{ parser_ctx_t
*ctx
}
150 struct _argument_list_t
*argument_list
;
151 case_clausule_t
*case_clausule
;
152 struct _case_list_t
*case_list
;
153 catch_block_t
*catch_block
;
154 struct _element_list_t
*element_list
;
156 const WCHAR
*identifier
;
157 struct _parameter_list_t
*parameter_list
;
158 struct _property_list_t
*property_list
;
159 source_elements_t
*source_elements
;
160 statement_t
*statement
;
161 struct _statement_list_t
*statement_list
;
162 struct _variable_list_t
*variable_list
;
163 variable_declaration_t
*variable_declaration
;
167 %token kBREAK kCASE kCATCH kCONTINUE kDEFAULT kDELETE kDO kELSE kIF kFINALLY kFOR kIN
168 %token kINSTANCEOF kNEW kNULL kRETURN kSWITCH kTHIS kTHROW kTRUE kFALSE kTRY kTYPEOF kVAR kVOID kWHILE kWITH
169 %token tANDAND tOROR tINC tDEC tHTMLCOMMENT kDIVEQ
171 %token
<srcptr
> kFUNCTION
'}'
174 %token
<identifier
> tIdentifier
175 %token
<ival
> tAssignOper tEqOper tShiftOper tRelOper
176 %token
<literal
> tNumericLiteral tBooleanLiteral
177 %token
<wstr
> tStringLiteral
180 %type
<source_elements
> SourceElements
181 %type
<source_elements
> FunctionBody
182 %type
<statement
> Statement
183 %type
<statement
> Block
184 %type
<statement
> VariableStatement
185 %type
<statement
> EmptyStatement
186 %type
<statement
> ExpressionStatement
187 %type
<statement
> IfStatement
188 %type
<statement
> IterationStatement
189 %type
<statement
> ContinueStatement
190 %type
<statement
> BreakStatement
191 %type
<statement
> ReturnStatement
192 %type
<statement
> WithStatement
193 %type
<statement
> LabelledStatement
194 %type
<statement
> SwitchStatement
195 %type
<statement
> ThrowStatement
196 %type
<statement
> TryStatement
197 %type
<statement
> Finally
198 %type
<statement_list
> StatementList StatementList_opt
199 %type
<parameter_list
> FormalParameterList FormalParameterList_opt
200 %type
<expr
> Expression Expression_opt Expression_err
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
242 %type
<srcptr
> KFunction
243 %type
<ival
> AssignOper
245 %nonassoc LOWER_THAN_ELSE
250 /* ECMA-262 3rd Edition 14 */
252 : SourceElements HtmlComment tEOF
253 { program_parsed
(ctx
, $1); }
259 /* ECMA-262 3rd Edition 14 */
261 : /* empty */ { $$
= new_source_elements
(ctx
); }
262 | SourceElements Statement
263 { $$
= source_elements_add_statement
($1, $2); }
265 /* ECMA-262 3rd Edition 13 */
267 : KFunction Identifier_opt left_bracket FormalParameterList_opt right_bracket
'{' FunctionBody
'}'
268 { $$
= new_function_expression
(ctx
, $2, $4, $7, $1, $8-$1+1); }
271 : kFUNCTION
{ $$
= $1; }
273 /* ECMA-262 3rd Edition 13 */
275 : SourceElements
{ $$
= $1; }
277 /* ECMA-262 3rd Edition 13 */
279 : tIdentifier
{ $$
= new_parameter_list
(ctx
, $1); }
280 | FormalParameterList
',' tIdentifier
281 { $$
= parameter_list_add
(ctx
, $1, $3); }
283 /* ECMA-262 3rd Edition 13 */
284 FormalParameterList_opt
285 : /* empty */ { $$
= NULL
; }
286 | FormalParameterList
{ $$
= $1; }
288 /* ECMA-262 3rd Edition 12 */
291 | VariableStatement
{ $$
= $1; }
292 | EmptyStatement
{ $$
= $1; }
293 | FunctionExpression
{ $$
= new_expression_statement
(ctx
, $1); }
294 | ExpressionStatement
{ $$
= $1; }
295 | IfStatement
{ $$
= $1; }
296 | IterationStatement
{ $$
= $1; }
297 | ContinueStatement
{ $$
= $1; }
298 | BreakStatement
{ $$
= $1; }
299 | ReturnStatement
{ $$
= $1; }
300 | WithStatement
{ $$
= $1; }
301 | LabelledStatement
{ $$
= $1; }
302 | SwitchStatement
{ $$
= $1; }
303 | ThrowStatement
{ $$
= $1; }
304 | TryStatement
{ $$
= $1; }
306 /* ECMA-262 3rd Edition 12.2 */
308 : Statement
{ $$
= new_statement_list
(ctx
, $1); }
309 | StatementList Statement
310 { $$
= statement_list_add
($1, $2); }
312 /* ECMA-262 3rd Edition 12.2 */
314 : /* empty */ { $$
= NULL
; }
315 | StatementList
{ $$
= $1; }
317 /* ECMA-262 3rd Edition 12.1 */
319 : '{' StatementList
'}' { $$
= new_block_statement
(ctx
, $2); }
320 |
'{' '}' { $$
= new_block_statement
(ctx
, NULL
); }
322 /* ECMA-262 3rd Edition 12.2 */
324 : kVAR VariableDeclarationList semicolon_opt
325 { $$
= new_var_statement
(ctx
, $2); }
327 /* ECMA-262 3rd Edition 12.2 */
328 VariableDeclarationList
329 : VariableDeclaration
{ $$
= new_variable_list
(ctx
, $1); }
330 | VariableDeclarationList
',' VariableDeclaration
331 { $$
= variable_list_add
(ctx
, $1, $3); }
333 /* ECMA-262 3rd Edition 12.2 */
334 VariableDeclarationListNoIn
335 : VariableDeclarationNoIn
336 { $$
= new_variable_list
(ctx
, $1); }
337 | VariableDeclarationListNoIn
',' VariableDeclarationNoIn
338 { $$
= variable_list_add
(ctx
, $1, $3); }
340 /* ECMA-262 3rd Edition 12.2 */
342 : tIdentifier Initialiser_opt
343 { $$
= new_variable_declaration
(ctx
, $1, $2); }
345 /* ECMA-262 3rd Edition 12.2 */
346 VariableDeclarationNoIn
347 : tIdentifier InitialiserNoIn_opt
348 { $$
= new_variable_declaration
(ctx
, $1, $2); }
350 /* ECMA-262 3rd Edition 12.2 */
352 : /* empty */ { $$
= NULL
; }
353 | Initialiser
{ $$
= $1; }
355 /* ECMA-262 3rd Edition 12.2 */
357 : '=' AssignmentExpression
360 /* ECMA-262 3rd Edition 12.2 */
362 : /* empty */ { $$
= NULL
; }
363 | InitialiserNoIn
{ $$
= $1; }
365 /* ECMA-262 3rd Edition 12.2 */
367 : '=' AssignmentExpressionNoIn
370 /* ECMA-262 3rd Edition 12.3 */
372 : ';' { $$
= new_statement
(ctx
, STAT_EMPTY
, 0); }
374 /* ECMA-262 3rd Edition 12.4 */
376 : Expression semicolon_opt
377 { $$
= new_expression_statement
(ctx
, $1); }
379 /* ECMA-262 3rd Edition 12.5 */
381 : kIF left_bracket Expression_err right_bracket Statement kELSE Statement
382 { $$
= new_if_statement
(ctx
, $3, $5, $7); }
383 | kIF left_bracket Expression_err right_bracket Statement %prec LOWER_THAN_ELSE
384 { $$
= new_if_statement
(ctx
, $3, $5, NULL
); }
386 /* ECMA-262 3rd Edition 12.6 */
388 : kDO Statement kWHILE left_bracket Expression_err right_bracket semicolon_opt
389 { $$
= new_while_statement
(ctx
, TRUE
, $5, $2); }
390 | kWHILE left_bracket Expression_err right_bracket Statement
391 { $$
= new_while_statement
(ctx
, FALSE
, $3, $5); }
392 | kFOR left_bracket ExpressionNoIn_opt
393 { if
(!explicit_error
(ctx
, $3, ';')) YYABORT; }
394 semicolon Expression_opt
395 { if
(!explicit_error
(ctx
, $6, ';')) YYABORT; }
396 semicolon Expression_opt right_bracket Statement
397 { $$
= new_for_statement
(ctx
, NULL
, $3, $6, $9, $11); }
398 | kFOR left_bracket kVAR VariableDeclarationListNoIn
399 { if
(!explicit_error
(ctx
, $4, ';')) YYABORT; }
400 semicolon Expression_opt
401 { if
(!explicit_error
(ctx
, $7, ';')) YYABORT; }
402 semicolon Expression_opt right_bracket Statement
403 { $$
= new_for_statement
(ctx
, $4, NULL
, $7, $10, $12); }
404 | kFOR left_bracket LeftHandSideExpression kIN Expression_err right_bracket Statement
405 { $$
= new_forin_statement
(ctx
, NULL
, $3, $5, $7); }
406 | kFOR left_bracket kVAR VariableDeclarationNoIn kIN Expression_err right_bracket Statement
407 { $$
= new_forin_statement
(ctx
, $4, NULL
, $6, $8); }
409 /* ECMA-262 3rd Edition 12.7 */
411 : kCONTINUE
/* NONL */ Identifier_opt semicolon_opt
412 { $$
= new_continue_statement
(ctx
, $2); }
414 /* ECMA-262 3rd Edition 12.8 */
416 : kBREAK
/* NONL */ Identifier_opt semicolon_opt
417 { $$
= new_break_statement
(ctx
, $2); }
419 /* ECMA-262 3rd Edition 12.9 */
421 : kRETURN
/* NONL */ Expression_opt semicolon_opt
422 { $$
= new_return_statement
(ctx
, $2); }
424 /* ECMA-262 3rd Edition 12.10 */
426 : kWITH left_bracket Expression right_bracket Statement
427 { $$
= new_with_statement
(ctx
, $3, $5); }
429 /* ECMA-262 3rd Edition 12.12 */
431 : tIdentifier
':' Statement
432 { $$
= new_labelled_statement
(ctx
, $1, $3); }
434 /* ECMA-262 3rd Edition 12.11 */
436 : kSWITCH left_bracket Expression right_bracket CaseBlock
437 { $$
= new_switch_statement
(ctx
, $3, $5); }
439 /* ECMA-262 3rd Edition 12.11 */
441 : '{' CaseClausules_opt
'}'
442 { $$
= new_case_block
(ctx
, $2, NULL
, NULL
); }
443 |
'{' CaseClausules_opt DefaultClausule CaseClausules_opt
'}'
444 { $$
= new_case_block
(ctx
, $2, $3, $4); }
446 /* ECMA-262 3rd Edition 12.11 */
448 : /* empty */ { $$
= NULL
; }
449 | CaseClausules
{ $$
= $1; }
451 /* ECMA-262 3rd Edition 12.11 */
453 : CaseClausule
{ $$
= new_case_list
(ctx
, $1); }
454 | CaseClausules CaseClausule
455 { $$
= case_list_add
(ctx
, $1, $2); }
457 /* ECMA-262 3rd Edition 12.11 */
459 : kCASE Expression
':' StatementList_opt
460 { $$
= new_case_clausule
(ctx
, $2, $4); }
462 /* ECMA-262 3rd Edition 12.11 */
464 : kDEFAULT
':' StatementList_opt
465 { $$
= new_case_clausule
(ctx
, NULL
, $3); }
467 /* ECMA-262 3rd Edition 12.13 */
469 : kTHROW
/* NONL */ Expression semicolon_opt
470 { $$
= new_throw_statement
(ctx
, $2); }
472 /* ECMA-262 3rd Edition 12.14 */
474 : kTRY Block Catch
{ $$
= new_try_statement
(ctx
, $2, $3, NULL
); }
475 | kTRY Block Finally
{ $$
= new_try_statement
(ctx
, $2, NULL
, $3); }
476 | kTRY Block Catch Finally
477 { $$
= new_try_statement
(ctx
, $2, $3, $4); }
479 /* ECMA-262 3rd Edition 12.14 */
481 : kCATCH left_bracket tIdentifier right_bracket Block
482 { $$
= new_catch_block
(ctx
, $3, $5); }
484 /* ECMA-262 3rd Edition 12.14 */
486 : kFINALLY Block
{ $$
= $2; }
488 /* ECMA-262 3rd Edition 11.14 */
490 : /* empty */ { $$
= NULL
; }
491 | Expression
{ $$
= $1; }
494 : Expression
{ $$
= $1; }
495 |
error { set_error
(ctx
, JS_E_SYNTAX
); YYABORT; }
497 /* ECMA-262 3rd Edition 11.14 */
499 : AssignmentExpression
{ $$
= $1; }
500 | Expression
',' AssignmentExpression
501 { $$
= new_binary_expression
(ctx
, EXPR_COMMA
, $1, $3); }
503 /* ECMA-262 3rd Edition 11.14 */
505 : /* empty */ { $$
= NULL
; }
506 | ExpressionNoIn
{ $$
= $1; }
508 /* ECMA-262 3rd Edition 11.14 */
510 : AssignmentExpressionNoIn
512 | ExpressionNoIn
',' AssignmentExpressionNoIn
513 { $$
= new_binary_expression
(ctx
, EXPR_COMMA
, $1, $3); }
516 : tAssignOper
{ $$
= $1; }
517 | kDIVEQ
{ $$
= EXPR_ASSIGNDIV
; }
519 /* ECMA-262 3rd Edition 11.13 */
521 : ConditionalExpression
{ $$
= $1; }
522 | LeftHandSideExpression
'=' AssignmentExpression
523 { $$
= new_binary_expression
(ctx
, EXPR_ASSIGN
, $1, $3); }
524 | LeftHandSideExpression AssignOper AssignmentExpression
525 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
527 /* ECMA-262 3rd Edition 11.13 */
528 AssignmentExpressionNoIn
529 : ConditionalExpressionNoIn
531 | LeftHandSideExpression
'=' AssignmentExpressionNoIn
532 { $$
= new_binary_expression
(ctx
, EXPR_ASSIGN
, $1, $3); }
533 | LeftHandSideExpression AssignOper AssignmentExpressionNoIn
534 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
536 /* ECMA-262 3rd Edition 11.12 */
537 ConditionalExpression
538 : LogicalORExpression
{ $$
= $1; }
539 | LogicalORExpression
'?' AssignmentExpression
':' AssignmentExpression
540 { $$
= new_conditional_expression
(ctx
, $1, $3, $5); }
542 /* ECMA-262 3rd Edition 11.12 */
543 ConditionalExpressionNoIn
544 : LogicalORExpressionNoIn
546 | LogicalORExpressionNoIn
'?' AssignmentExpressionNoIn
':' AssignmentExpressionNoIn
547 { $$
= new_conditional_expression
(ctx
, $1, $3, $5); }
549 /* ECMA-262 3rd Edition 11.11 */
551 : LogicalANDExpression
{ $$
= $1; }
552 | LogicalORExpression tOROR LogicalANDExpression
553 { $$
= new_binary_expression
(ctx
, EXPR_OR
, $1, $3); }
555 /* ECMA-262 3rd Edition 11.11 */
556 LogicalORExpressionNoIn
557 : LogicalANDExpressionNoIn
559 | LogicalORExpressionNoIn tOROR LogicalANDExpressionNoIn
560 { $$
= new_binary_expression
(ctx
, EXPR_OR
, $1, $3); }
562 /* ECMA-262 3rd Edition 11.11 */
564 : BitwiseORExpression
{ $$
= $1; }
565 | LogicalANDExpression tANDAND BitwiseORExpression
566 { $$
= new_binary_expression
(ctx
, EXPR_AND
, $1, $3); }
568 /* ECMA-262 3rd Edition 11.11 */
569 LogicalANDExpressionNoIn
570 : BitwiseORExpressionNoIn
572 | LogicalANDExpressionNoIn tANDAND BitwiseORExpressionNoIn
573 { $$
= new_binary_expression
(ctx
, EXPR_AND
, $1, $3); }
575 /* ECMA-262 3rd Edition 11.10 */
577 : BitwiseXORExpression
{ $$
= $1; }
578 | BitwiseORExpression
'|' BitwiseXORExpression
579 { $$
= new_binary_expression
(ctx
, EXPR_BOR
, $1, $3); }
581 /* ECMA-262 3rd Edition 11.10 */
582 BitwiseORExpressionNoIn
583 : BitwiseXORExpressionNoIn
585 | BitwiseORExpressionNoIn
'|' BitwiseXORExpressionNoIn
586 { $$
= new_binary_expression
(ctx
, EXPR_BOR
, $1, $3); }
588 /* ECMA-262 3rd Edition 11.10 */
590 : BitwiseANDExpression
{ $$
= $1; }
591 | BitwiseXORExpression
'^' BitwiseANDExpression
592 { $$
= new_binary_expression
(ctx
, EXPR_BXOR
, $1, $3); }
594 /* ECMA-262 3rd Edition 11.10 */
595 BitwiseXORExpressionNoIn
596 : BitwiseANDExpressionNoIn
598 | BitwiseXORExpressionNoIn
'^' BitwiseANDExpressionNoIn
599 { $$
= new_binary_expression
(ctx
, EXPR_BXOR
, $1, $3); }
601 /* ECMA-262 3rd Edition 11.10 */
603 : EqualityExpression
{ $$
= $1; }
604 | BitwiseANDExpression
'&' EqualityExpression
605 { $$
= new_binary_expression
(ctx
, EXPR_BAND
, $1, $3); }
607 /* ECMA-262 3rd Edition 11.10 */
608 BitwiseANDExpressionNoIn
609 : EqualityExpressionNoIn
611 | BitwiseANDExpressionNoIn
'&' EqualityExpressionNoIn
612 { $$
= new_binary_expression
(ctx
, EXPR_BAND
, $1, $3); }
614 /* ECMA-262 3rd Edition 11.9 */
616 : RelationalExpression
{ $$
= $1; }
617 | EqualityExpression tEqOper RelationalExpression
618 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
620 /* ECMA-262 3rd Edition 11.9 */
621 EqualityExpressionNoIn
622 : RelationalExpressionNoIn
{ $$
= $1; }
623 | EqualityExpressionNoIn tEqOper RelationalExpressionNoIn
624 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
626 /* ECMA-262 3rd Edition 11.8 */
628 : ShiftExpression
{ $$
= $1; }
629 | RelationalExpression tRelOper ShiftExpression
630 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
631 | RelationalExpression kINSTANCEOF ShiftExpression
632 { $$
= new_binary_expression
(ctx
, EXPR_INSTANCEOF
, $1, $3); }
633 | RelationalExpression kIN ShiftExpression
634 { $$
= new_binary_expression
(ctx
, EXPR_IN
, $1, $3); }
636 /* ECMA-262 3rd Edition 11.8 */
637 RelationalExpressionNoIn
638 : ShiftExpression
{ $$
= $1; }
639 | RelationalExpressionNoIn tRelOper ShiftExpression
640 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
641 | RelationalExpressionNoIn kINSTANCEOF ShiftExpression
642 { $$
= new_binary_expression
(ctx
, EXPR_INSTANCEOF
, $1, $3); }
644 /* ECMA-262 3rd Edition 11.7 */
646 : AdditiveExpression
{ $$
= $1; }
647 | ShiftExpression tShiftOper AdditiveExpression
648 { $$
= new_binary_expression
(ctx
, $2, $1, $3); }
650 /* ECMA-262 3rd Edition 11.6 */
652 : MultiplicativeExpression
654 | AdditiveExpression
'+' MultiplicativeExpression
655 { $$
= new_binary_expression
(ctx
, EXPR_ADD
, $1, $3); }
656 | AdditiveExpression
'-' MultiplicativeExpression
657 { $$
= new_binary_expression
(ctx
, EXPR_SUB
, $1, $3); }
659 /* ECMA-262 3rd Edition 11.5 */
660 MultiplicativeExpression
661 : UnaryExpression
{ $$
= $1; }
662 | MultiplicativeExpression
'*' UnaryExpression
663 { $$
= new_binary_expression
(ctx
, EXPR_MUL
, $1, $3); }
664 | MultiplicativeExpression
'/' UnaryExpression
665 { $$
= new_binary_expression
(ctx
, EXPR_DIV
, $1, $3); }
666 | MultiplicativeExpression
'%' UnaryExpression
667 { $$
= new_binary_expression
(ctx
, EXPR_MOD
, $1, $3); }
669 /* ECMA-262 3rd Edition 11.4 */
671 : PostfixExpression
{ $$
= $1; }
672 | kDELETE UnaryExpression
673 { $$
= new_unary_expression
(ctx
, EXPR_DELETE
, $2); }
674 | kVOID UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_VOID
, $2); }
675 | kTYPEOF UnaryExpression
676 { $$
= new_unary_expression
(ctx
, EXPR_TYPEOF
, $2); }
677 | tINC UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_PREINC
, $2); }
678 | tDEC UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_PREDEC
, $2); }
679 |
'+' UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_PLUS
, $2); }
680 |
'-' UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_MINUS
, $2); }
681 |
'~' UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_BITNEG
, $2); }
682 |
'!' UnaryExpression
{ $$
= new_unary_expression
(ctx
, EXPR_LOGNEG
, $2); }
684 /* ECMA-262 3rd Edition 11.2 */
686 : LeftHandSideExpression
688 | LeftHandSideExpression
/* NONL */ tINC
689 { $$
= new_unary_expression
(ctx
, EXPR_POSTINC
, $1); }
690 | LeftHandSideExpression
/* NONL */ tDEC
691 { $$
= new_unary_expression
(ctx
, EXPR_POSTDEC
, $1); }
694 /* ECMA-262 3rd Edition 11.2 */
695 LeftHandSideExpression
696 : NewExpression
{ $$
= $1; }
697 | CallExpression
{ $$
= $1; }
699 /* ECMA-262 3rd Edition 11.2 */
701 : MemberExpression
{ $$
= $1; }
702 | kNEW NewExpression
{ $$
= new_new_expression
(ctx
, $2, NULL
); }
704 /* ECMA-262 3rd Edition 11.2 */
706 : PrimaryExpression
{ $$
= $1; }
707 | FunctionExpression
{ $$
= $1; }
708 | MemberExpression
'[' Expression
']'
709 { $$
= new_binary_expression
(ctx
, EXPR_ARRAY
, $1, $3); }
710 | MemberExpression
'.' tIdentifier
711 { $$
= new_member_expression
(ctx
, $1, $3); }
712 | kNEW MemberExpression Arguments
713 { $$
= new_new_expression
(ctx
, $2, $3); }
715 /* ECMA-262 3rd Edition 11.2 */
717 : MemberExpression Arguments
718 { $$
= new_call_expression
(ctx
, $1, $2); }
719 | CallExpression Arguments
720 { $$
= new_call_expression
(ctx
, $1, $2); }
721 | CallExpression
'[' Expression
']'
722 { $$
= new_binary_expression
(ctx
, EXPR_ARRAY
, $1, $3); }
723 | CallExpression
'.' tIdentifier
724 { $$
= new_member_expression
(ctx
, $1, $3); }
726 /* ECMA-262 3rd Edition 11.2 */
728 : '(' ')' { $$
= NULL
; }
729 |
'(' ArgumentList
')' { $$
= $2; }
731 /* ECMA-262 3rd Edition 11.2 */
733 : AssignmentExpression
{ $$
= new_argument_list
(ctx
, $1); }
734 | ArgumentList
',' AssignmentExpression
735 { $$
= argument_list_add
(ctx
, $1, $3); }
737 /* ECMA-262 3rd Edition 11.1 */
739 : kTHIS
{ $$
= new_expression
(ctx
, EXPR_THIS
, 0); }
740 | tIdentifier
{ $$
= new_identifier_expression
(ctx
, $1); }
741 | Literal
{ $$
= new_literal_expression
(ctx
, $1); }
742 | ArrayLiteral
{ $$
= $1; }
743 | ObjectLiteral
{ $$
= $1; }
744 |
'(' Expression
')' { $$
= $2; }
746 /* ECMA-262 3rd Edition 11.1.4 */
748 : '[' ']' { $$
= new_array_literal_expression
(ctx
, NULL
, 0); }
749 |
'[' Elision
']' { $$
= new_array_literal_expression
(ctx
, NULL
, $2+1); }
750 |
'[' ElementList
']' { $$
= new_array_literal_expression
(ctx
, $2, 0); }
751 |
'[' ElementList
',' Elision_opt
']'
752 { $$
= new_array_literal_expression
(ctx
, $2, $4+1); }
754 /* ECMA-262 3rd Edition 11.1.4 */
756 : Elision_opt AssignmentExpression
757 { $$
= new_element_list
(ctx
, $1, $2); }
758 | ElementList
',' Elision_opt AssignmentExpression
759 { $$
= element_list_add
(ctx
, $1, $3, $4); }
761 /* ECMA-262 3rd Edition 11.1.4 */
764 | Elision
',' { $$
= $1 + 1; }
766 /* ECMA-262 3rd Edition 11.1.4 */
768 : /* empty */ { $$
= 0; }
769 | Elision
{ $$
= $1; }
771 /* ECMA-262 3rd Edition 11.1.5 */
773 : '{' '}' { $$
= new_prop_and_value_expression
(ctx
, NULL
); }
774 |
'{' PropertyNameAndValueList
'}'
775 { $$
= new_prop_and_value_expression
(ctx
, $2); }
777 /* ECMA-262 3rd Edition 11.1.5 */
778 PropertyNameAndValueList
779 : PropertyName
':' AssignmentExpression
780 { $$
= new_property_list
(ctx
, $1, $3); }
781 | PropertyNameAndValueList
',' PropertyName
':' AssignmentExpression
782 { $$
= property_list_add
(ctx
, $1, $3, $5); }
784 /* ECMA-262 3rd Edition 11.1.5 */
786 : tIdentifier
{ $$
= new_string_literal
(ctx
, $1); }
787 | tStringLiteral
{ $$
= new_string_literal
(ctx
, $1); }
788 | tNumericLiteral
{ $$
= $1; }
790 /* ECMA-262 3rd Edition 7.6 */
792 : /* empty*/ { $$
= NULL
; }
793 | tIdentifier
{ $$
= $1; }
795 /* ECMA-262 3rd Edition 7.8 */
797 : kNULL
{ $$
= new_null_literal
(ctx
); }
798 | BooleanLiteral
{ $$
= $1; }
799 | tNumericLiteral
{ $$
= $1; }
800 | tStringLiteral
{ $$
= new_string_literal
(ctx
, $1); }
801 |
'/' { $$
= parse_regexp
(ctx
);
803 | kDIVEQ
{ $$
= parse_regexp
(ctx
);
806 /* ECMA-262 3rd Edition 7.8.2 */
808 : kTRUE
{ $$
= new_boolean_literal
(ctx
, VARIANT_TRUE
); }
809 | kFALSE
{ $$
= new_boolean_literal
(ctx
, VARIANT_FALSE
); }
810 | tBooleanLiteral
{ $$
= $1; }
814 |
error { if
(!allow_auto_semicolon
(ctx
)) {YYABORT;} }
818 |
error { set_error
(ctx
, JS_E_MISSING_LBRACKET
); YYABORT; }
822 |
error { set_error
(ctx
, JS_E_MISSING_RBRACKET
); YYABORT; }
826 |
error { set_error
(ctx
, JS_E_MISSING_SEMICOLON
); YYABORT; }
830 static BOOL allow_auto_semicolon
(parser_ctx_t
*ctx
)
832 return ctx
->nl || ctx
->ptr
== ctx
->end ||
*(ctx
->ptr
-1) == '}';
835 static void *new_statement
(parser_ctx_t
*ctx
, statement_type_t type
, size_t size
)
839 stat
= parser_alloc
(ctx
, size ? size
: sizeof
(*stat
));
849 static literal_t
*new_string_literal
(parser_ctx_t
*ctx
, const WCHAR
*str
)
851 literal_t
*ret
= parser_alloc
(ctx
, sizeof
(literal_t
));
853 ret
->type
= LT_STRING
;
859 static literal_t
*new_null_literal
(parser_ctx_t
*ctx
)
861 literal_t
*ret
= parser_alloc
(ctx
, sizeof
(literal_t
));
868 static prop_val_t
*new_prop_val
(parser_ctx_t
*ctx
, literal_t
*name
, expression_t
*value
)
870 prop_val_t
*ret
= parser_alloc
(ctx
, sizeof
(prop_val_t
));
879 static property_list_t
*new_property_list
(parser_ctx_t
*ctx
, literal_t
*name
, expression_t
*value
)
881 property_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(property_list_t
));
883 ret
->head
= ret
->tail
= new_prop_val
(ctx
, name
, value
);
888 static property_list_t
*property_list_add
(parser_ctx_t
*ctx
, property_list_t
*list
, literal_t
*name
, expression_t
*value
)
890 list
->tail
= list
->tail
->next
= new_prop_val
(ctx
, name
, value
);
895 static array_element_t
*new_array_element
(parser_ctx_t
*ctx
, int elision
, expression_t
*expr
)
897 array_element_t
*ret
= parser_alloc
(ctx
, sizeof
(array_element_t
));
899 ret
->elision
= elision
;
906 static element_list_t
*new_element_list
(parser_ctx_t
*ctx
, int elision
, expression_t
*expr
)
908 element_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(element_list_t
));
910 ret
->head
= ret
->tail
= new_array_element
(ctx
, elision
, expr
);
915 static element_list_t
*element_list_add
(parser_ctx_t
*ctx
, element_list_t
*list
, int elision
, expression_t
*expr
)
917 list
->tail
= list
->tail
->next
= new_array_element
(ctx
, elision
, expr
);
922 static argument_t
*new_argument
(parser_ctx_t
*ctx
, expression_t
*expr
)
924 argument_t
*ret
= parser_alloc
(ctx
, sizeof
(argument_t
));
932 static argument_list_t
*new_argument_list
(parser_ctx_t
*ctx
, expression_t
*expr
)
934 argument_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(argument_list_t
));
936 ret
->head
= ret
->tail
= new_argument
(ctx
, expr
);
941 static argument_list_t
*argument_list_add
(parser_ctx_t
*ctx
, argument_list_t
*list
, expression_t
*expr
)
943 list
->tail
= list
->tail
->next
= new_argument
(ctx
, expr
);
948 static catch_block_t
*new_catch_block
(parser_ctx_t
*ctx
, const WCHAR
*identifier
, statement_t
*statement
)
950 catch_block_t
*ret
= parser_alloc
(ctx
, sizeof
(catch_block_t
));
952 ret
->identifier
= identifier
;
953 ret
->statement
= statement
;
958 static case_clausule_t
*new_case_clausule
(parser_ctx_t
*ctx
, expression_t
*expr
, statement_list_t
*stat_list
)
960 case_clausule_t
*ret
= parser_alloc
(ctx
, sizeof
(case_clausule_t
));
963 ret
->stat
= stat_list ? stat_list
->head
: NULL
;
969 static case_list_t
*new_case_list
(parser_ctx_t
*ctx
, case_clausule_t
*case_clausule
)
971 case_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(case_list_t
));
973 ret
->head
= ret
->tail
= case_clausule
;
978 static case_list_t
*case_list_add
(parser_ctx_t
*ctx
, case_list_t
*list
, case_clausule_t
*case_clausule
)
980 list
->tail
= list
->tail
->next
= case_clausule
;
985 static case_clausule_t
*new_case_block
(parser_ctx_t
*ctx
, case_list_t
*case_list1
,
986 case_clausule_t
*default_clausule
, case_list_t
*case_list2
)
988 case_clausule_t
*ret
= NULL
, *iter
= NULL
, *iter2
;
989 statement_t
*stat
= NULL
;
992 ret
= case_list1
->head
;
993 iter
= case_list1
->tail
;
996 if
(default_clausule
) {
998 iter
= iter
->next
= default_clausule
;
1000 ret
= iter
= default_clausule
;
1005 iter
->next
= case_list2
->head
;
1007 ret
= case_list2
->head
;
1013 for
(iter
= ret
; iter
; iter
= iter
->next
) {
1014 for
(iter2
= iter
; iter2
&& !iter2
->stat
; iter2
= iter2
->next
);
1018 while
(iter
!= iter2
) {
1019 iter
->stat
= iter2
->stat
;
1026 stat
->next
= iter
->stat
;
1035 static statement_t
*new_block_statement
(parser_ctx_t
*ctx
, statement_list_t
*list
)
1037 block_statement_t
*ret
;
1039 ret
= new_statement
(ctx
, STAT_BLOCK
, sizeof
(*ret
));
1043 ret
->stat_list
= list ? list
->head
: NULL
;
1048 static variable_declaration_t
*new_variable_declaration
(parser_ctx_t
*ctx
, const WCHAR
*identifier
, expression_t
*expr
)
1050 variable_declaration_t
*ret
= parser_alloc
(ctx
, sizeof
(variable_declaration_t
));
1052 ret
->identifier
= identifier
;
1055 ret
->global_next
= NULL
;
1060 static variable_list_t
*new_variable_list
(parser_ctx_t
*ctx
, variable_declaration_t
*decl
)
1062 variable_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(variable_list_t
));
1064 ret
->head
= ret
->tail
= decl
;
1069 static variable_list_t
*variable_list_add
(parser_ctx_t
*ctx
, variable_list_t
*list
, variable_declaration_t
*decl
)
1071 list
->tail
= list
->tail
->next
= decl
;
1076 static statement_t
*new_var_statement
(parser_ctx_t
*ctx
, variable_list_t
*variable_list
)
1078 var_statement_t
*ret
;
1080 ret
= new_statement
(ctx
, STAT_VAR
, sizeof
(*ret
));
1084 ret
->variable_list
= variable_list
->head
;
1089 static statement_t
*new_expression_statement
(parser_ctx_t
*ctx
, expression_t
*expr
)
1091 expression_statement_t
*ret
;
1093 ret
= new_statement
(ctx
, STAT_EXPR
, sizeof
(*ret
));
1102 static statement_t
*new_if_statement
(parser_ctx_t
*ctx
, expression_t
*expr
, statement_t
*if_stat
, statement_t
*else_stat
)
1104 if_statement_t
*ret
;
1106 ret
= new_statement
(ctx
, STAT_IF
, sizeof
(*ret
));
1111 ret
->if_stat
= if_stat
;
1112 ret
->else_stat
= else_stat
;
1117 static statement_t
*new_while_statement
(parser_ctx_t
*ctx
, BOOL dowhile
, expression_t
*expr
, statement_t
*stat
)
1119 while_statement_t
*ret
;
1121 ret
= new_statement
(ctx
, STAT_WHILE
, sizeof
(*ret
));
1125 ret
->do_while
= dowhile
;
1127 ret
->statement
= stat
;
1132 static statement_t
*new_for_statement
(parser_ctx_t
*ctx
, variable_list_t
*variable_list
, expression_t
*begin_expr
,
1133 expression_t
*expr
, expression_t
*end_expr
, statement_t
*statement
)
1135 for_statement_t
*ret
;
1137 ret
= new_statement
(ctx
, STAT_FOR
, sizeof
(*ret
));
1141 ret
->variable_list
= variable_list ? variable_list
->head
: NULL
;
1142 ret
->begin_expr
= begin_expr
;
1144 ret
->end_expr
= end_expr
;
1145 ret
->statement
= statement
;
1150 static statement_t
*new_forin_statement
(parser_ctx_t
*ctx
, variable_declaration_t
*variable
, expression_t
*expr
,
1151 expression_t
*in_expr
, statement_t
*statement
)
1153 forin_statement_t
*ret
;
1155 ret
= new_statement
(ctx
, STAT_FORIN
, sizeof
(*ret
));
1159 ret
->variable
= variable
;
1161 ret
->in_expr
= in_expr
;
1162 ret
->statement
= statement
;
1167 static statement_t
*new_continue_statement
(parser_ctx_t
*ctx
, const WCHAR
*identifier
)
1169 branch_statement_t
*ret
;
1171 ret
= new_statement
(ctx
, STAT_CONTINUE
, sizeof
(*ret
));
1175 ret
->identifier
= identifier
;
1180 static statement_t
*new_break_statement
(parser_ctx_t
*ctx
, const WCHAR
*identifier
)
1182 branch_statement_t
*ret
;
1184 ret
= new_statement
(ctx
, STAT_BREAK
, sizeof
(*ret
));
1188 ret
->identifier
= identifier
;
1193 static statement_t
*new_return_statement
(parser_ctx_t
*ctx
, expression_t
*expr
)
1195 expression_statement_t
*ret
;
1197 ret
= new_statement
(ctx
, STAT_RETURN
, sizeof
(*ret
));
1206 static statement_t
*new_with_statement
(parser_ctx_t
*ctx
, expression_t
*expr
, statement_t
*statement
)
1208 with_statement_t
*ret
;
1210 ret
= new_statement
(ctx
, STAT_WITH
, sizeof
(*ret
));
1215 ret
->statement
= statement
;
1220 static statement_t
*new_labelled_statement
(parser_ctx_t
*ctx
, const WCHAR
*identifier
, statement_t
*statement
)
1222 labelled_statement_t
*ret
;
1224 ret
= new_statement
(ctx
, STAT_LABEL
, sizeof
(*ret
));
1228 ret
->identifier
= identifier
;
1229 ret
->statement
= statement
;
1234 static statement_t
*new_switch_statement
(parser_ctx_t
*ctx
, expression_t
*expr
, case_clausule_t
*case_list
)
1236 switch_statement_t
*ret
;
1238 ret
= new_statement
(ctx
, STAT_SWITCH
, sizeof
(*ret
));
1243 ret
->case_list
= case_list
;
1248 static statement_t
*new_throw_statement
(parser_ctx_t
*ctx
, expression_t
*expr
)
1250 expression_statement_t
*ret
;
1252 ret
= new_statement
(ctx
, STAT_THROW
, sizeof
(*ret
));
1261 static statement_t
*new_try_statement
(parser_ctx_t
*ctx
, statement_t
*try_statement
,
1262 catch_block_t
*catch_block
, statement_t
*finally_statement
)
1264 try_statement_t
*ret
;
1266 ret
= new_statement
(ctx
, STAT_TRY
, sizeof
(*ret
));
1270 ret
->try_statement
= try_statement
;
1271 ret
->catch_block
= catch_block
;
1272 ret
->finally_statement
= finally_statement
;
1277 static parameter_t
*new_parameter
(parser_ctx_t
*ctx
, const WCHAR
*identifier
)
1279 parameter_t
*ret
= parser_alloc
(ctx
, sizeof
(parameter_t
));
1281 ret
->identifier
= identifier
;
1287 static parameter_list_t
*new_parameter_list
(parser_ctx_t
*ctx
, const WCHAR
*identifier
)
1289 parameter_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(parameter_list_t
));
1291 ret
->head
= ret
->tail
= new_parameter
(ctx
, identifier
);
1296 static parameter_list_t
*parameter_list_add
(parser_ctx_t
*ctx
, parameter_list_t
*list
, const WCHAR
*identifier
)
1298 list
->tail
= list
->tail
->next
= new_parameter
(ctx
, identifier
);
1303 static expression_t
*new_function_expression
(parser_ctx_t
*ctx
, const WCHAR
*identifier
,
1304 parameter_list_t
*parameter_list
, source_elements_t
*source_elements
, const WCHAR
*src_str
, DWORD src_len
)
1306 function_expression_t
*ret
= new_expression
(ctx
, EXPR_FUNC
, sizeof
(*ret
));
1308 ret
->identifier
= identifier
;
1309 ret
->parameter_list
= parameter_list ? parameter_list
->head
: NULL
;
1310 ret
->source_elements
= source_elements
;
1311 ret
->src_str
= src_str
;
1312 ret
->src_len
= src_len
;
1318 static void *new_expression
(parser_ctx_t
*ctx
, expression_type_t type
, size_t size
)
1320 expression_t
*ret
= parser_alloc
(ctx
, size ? size
: sizeof
(*ret
));
1327 static expression_t
*new_binary_expression
(parser_ctx_t
*ctx
, expression_type_t type
,
1328 expression_t
*expression1
, expression_t
*expression2
)
1330 binary_expression_t
*ret
= new_expression
(ctx
, type
, sizeof
(*ret
));
1332 ret
->expression1
= expression1
;
1333 ret
->expression2
= expression2
;
1338 static expression_t
*new_unary_expression
(parser_ctx_t
*ctx
, expression_type_t type
, expression_t
*expression
)
1340 unary_expression_t
*ret
= new_expression
(ctx
, type
, sizeof
(*ret
));
1342 ret
->expression
= expression
;
1347 static expression_t
*new_conditional_expression
(parser_ctx_t
*ctx
, expression_t
*expression
,
1348 expression_t
*true_expression
, expression_t
*false_expression
)
1350 conditional_expression_t
*ret
= new_expression
(ctx
, EXPR_COND
, sizeof
(*ret
));
1352 ret
->expression
= expression
;
1353 ret
->true_expression
= true_expression
;
1354 ret
->false_expression
= false_expression
;
1359 static expression_t
*new_member_expression
(parser_ctx_t
*ctx
, expression_t
*expression
, const WCHAR
*identifier
)
1361 member_expression_t
*ret
= new_expression
(ctx
, EXPR_MEMBER
, sizeof
(*ret
));
1363 ret
->expression
= expression
;
1364 ret
->identifier
= identifier
;
1369 static expression_t
*new_new_expression
(parser_ctx_t
*ctx
, expression_t
*expression
, argument_list_t
*argument_list
)
1371 call_expression_t
*ret
= new_expression
(ctx
, EXPR_NEW
, sizeof
(*ret
));
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
= new_expression
(ctx
, EXPR_CALL
, sizeof
(*ret
));
1383 ret
->expression
= expression
;
1384 ret
->argument_list
= argument_list ? argument_list
->head
: NULL
;
1389 static int parser_error
(parser_ctx_t
*ctx
, const char *str
)
1394 static void set_error
(parser_ctx_t
*ctx
, UINT
error)
1399 static BOOL explicit_error
(parser_ctx_t
*ctx
, void *obj
, WCHAR next
)
1401 if
(obj ||
*(ctx
->ptr
-1)==next
) return TRUE
;
1403 set_error
(ctx
, JS_E_SYNTAX
);
1408 static expression_t
*new_identifier_expression
(parser_ctx_t
*ctx
, const WCHAR
*identifier
)
1410 identifier_expression_t
*ret
= new_expression
(ctx
, EXPR_IDENT
, sizeof
(*ret
));
1412 ret
->identifier
= identifier
;
1417 static expression_t
*new_array_literal_expression
(parser_ctx_t
*ctx
, element_list_t
*element_list
, int length
)
1419 array_literal_expression_t
*ret
= new_expression
(ctx
, EXPR_ARRAYLIT
, sizeof
(*ret
));
1421 ret
->element_list
= element_list ? element_list
->head
: NULL
;
1422 ret
->length
= length
;
1427 static expression_t
*new_prop_and_value_expression
(parser_ctx_t
*ctx
, property_list_t
*property_list
)
1429 property_value_expression_t
*ret
= new_expression
(ctx
, EXPR_PROPVAL
, sizeof
(*ret
));
1431 ret
->property_list
= property_list ? property_list
->head
: NULL
;
1436 static expression_t
*new_literal_expression
(parser_ctx_t
*ctx
, literal_t
*literal
)
1438 literal_expression_t
*ret
= new_expression
(ctx
, EXPR_LITERAL
, sizeof
(*ret
));
1440 ret
->literal
= literal
;
1445 static source_elements_t
*new_source_elements
(parser_ctx_t
*ctx
)
1447 source_elements_t
*ret
= parser_alloc
(ctx
, sizeof
(source_elements_t
));
1449 memset
(ret
, 0, sizeof
(*ret
));
1454 static source_elements_t
*source_elements_add_statement
(source_elements_t
*source_elements
, statement_t
*statement
)
1456 if
(source_elements
->statement_tail
)
1457 source_elements
->statement_tail
= source_elements
->statement_tail
->next
= statement
;
1459 source_elements
->statement
= source_elements
->statement_tail
= statement
;
1461 return source_elements
;
1464 static statement_list_t
*new_statement_list
(parser_ctx_t
*ctx
, statement_t
*statement
)
1466 statement_list_t
*ret
= parser_alloc_tmp
(ctx
, sizeof
(statement_list_t
));
1468 ret
->head
= ret
->tail
= statement
;
1473 static statement_list_t
*statement_list_add
(statement_list_t
*list
, statement_t
*statement
)
1475 list
->tail
= list
->tail
->next
= statement
;
1480 static void program_parsed
(parser_ctx_t
*ctx
, source_elements_t
*source
)
1482 ctx
->source
= source
;
1483 if
(!ctx
->lexer_error
)
1487 void parser_release
(parser_ctx_t
*ctx
)
1489 script_release
(ctx
->script
);
1490 heap_pool_free
(&ctx
->heap
);
1494 HRESULT script_parse
(script_ctx_t
*ctx
, const WCHAR
*code
, const WCHAR
*delimiter
, BOOL from_eval
,
1497 parser_ctx_t
*parser_ctx
;
1501 const WCHAR html_tagW
[] = {'<','/','s','c','r','i','p','t','>',0};
1503 parser_ctx
= heap_alloc_zero
(sizeof
(parser_ctx_t
));
1505 return E_OUTOFMEMORY
;
1507 parser_ctx
->hres
= JS_E_SYNTAX
;
1508 parser_ctx
->is_html
= delimiter
&& !strcmpiW
(delimiter
, html_tagW
);
1510 parser_ctx
->begin
= parser_ctx
->ptr
= code
;
1511 parser_ctx
->end
= parser_ctx
->begin
+ strlenW
(parser_ctx
->begin
);
1514 parser_ctx
->script
= ctx
;
1516 mark
= heap_pool_mark
(&ctx
->tmp_heap
);
1517 heap_pool_init
(&parser_ctx
->heap
);
1519 parser_parse
(parser_ctx
);
1520 heap_pool_clear
(mark
);
1521 hres
= parser_ctx
->hres
;
1523 WARN
("parser failed around %s\n",
1524 debugstr_w
(parser_ctx
->begin
+20 > parser_ctx
->ptr ? parser_ctx
->begin
: parser_ctx
->ptr
-20));
1525 parser_release
(parser_ctx
);