2008-09-03 00:25:21 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
%{
|
|
|
|
|
|
|
|
#include "jscript.h"
|
|
|
|
#include "engine.h"
|
2014-09-30 16:51:14 +02:00
|
|
|
#include "parser.h"
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2012-09-07 17:14:13 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(jscript);
|
|
|
|
|
2020-01-23 13:52:15 +01:00
|
|
|
static int parser_error(unsigned*,parser_ctx_t*,const char*);
|
2020-02-03 14:47:39 +01:00
|
|
|
static void set_error(parser_ctx_t*,unsigned,HRESULT);
|
2009-07-24 09:36:20 +02:00
|
|
|
static BOOL explicit_error(parser_ctx_t*,void*,WCHAR);
|
2008-09-03 00:25:21 +02:00
|
|
|
static BOOL allow_auto_semicolon(parser_ctx_t*);
|
|
|
|
|
2008-09-08 01:22:45 +02:00
|
|
|
typedef struct _statement_list_t {
|
2008-09-03 00:25:21 +02:00
|
|
|
statement_t *head;
|
|
|
|
statement_t *tail;
|
|
|
|
} statement_list_t;
|
|
|
|
|
2019-03-01 17:44:18 +01:00
|
|
|
static literal_t *new_string_literal(parser_ctx_t*,jsstr_t*);
|
2008-09-03 00:25:21 +02:00
|
|
|
static literal_t *new_null_literal(parser_ctx_t*);
|
|
|
|
|
2008-09-08 01:22:45 +02:00
|
|
|
typedef struct _property_list_t {
|
2018-11-30 22:44:07 +01:00
|
|
|
property_definition_t *head;
|
|
|
|
property_definition_t *tail;
|
2008-09-03 00:25:21 +02:00
|
|
|
} property_list_t;
|
|
|
|
|
2018-11-30 22:44:32 +01:00
|
|
|
static property_definition_t *new_property_definition(parser_ctx_t *ctx, property_definition_type_t,
|
|
|
|
literal_t *name, expression_t *value);
|
2018-11-30 22:44:14 +01:00
|
|
|
static property_list_t *new_property_list(parser_ctx_t*,property_definition_t*);
|
|
|
|
static property_list_t *property_list_add(parser_ctx_t*,property_list_t*,property_definition_t*);
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2008-09-08 01:22:45 +02:00
|
|
|
typedef struct _element_list_t {
|
2008-09-03 00:25:21 +02:00
|
|
|
array_element_t *head;
|
|
|
|
array_element_t *tail;
|
|
|
|
} element_list_t;
|
|
|
|
|
|
|
|
static element_list_t *new_element_list(parser_ctx_t*,int,expression_t*);
|
|
|
|
static element_list_t *element_list_add(parser_ctx_t*,element_list_t*,int,expression_t*);
|
|
|
|
|
2008-09-08 01:22:45 +02:00
|
|
|
typedef struct _argument_list_t {
|
2008-09-03 00:25:21 +02:00
|
|
|
argument_t *head;
|
|
|
|
argument_t *tail;
|
|
|
|
} argument_list_t;
|
|
|
|
|
|
|
|
static argument_list_t *new_argument_list(parser_ctx_t*,expression_t*);
|
|
|
|
static argument_list_t *argument_list_add(parser_ctx_t*,argument_list_t*,expression_t*);
|
|
|
|
|
2008-09-08 01:22:45 +02:00
|
|
|
typedef struct _case_list_t {
|
2008-09-03 00:25:21 +02:00
|
|
|
case_clausule_t *head;
|
|
|
|
case_clausule_t *tail;
|
|
|
|
} case_list_t;
|
|
|
|
|
|
|
|
static catch_block_t *new_catch_block(parser_ctx_t*,const WCHAR*,statement_t*);
|
2020-01-24 19:54:41 +01:00
|
|
|
static case_clausule_t *new_case_clausule(parser_ctx_t*,unsigned,expression_t*,statement_list_t*);
|
2008-09-03 00:25:21 +02:00
|
|
|
static case_list_t *new_case_list(parser_ctx_t*,case_clausule_t*);
|
|
|
|
static case_list_t *case_list_add(parser_ctx_t*,case_list_t*,case_clausule_t*);
|
|
|
|
static case_clausule_t *new_case_block(parser_ctx_t*,case_list_t*,case_clausule_t*,case_list_t*);
|
|
|
|
|
2008-09-08 01:22:45 +02:00
|
|
|
typedef struct _variable_list_t {
|
2008-09-03 00:25:21 +02:00
|
|
|
variable_declaration_t *head;
|
|
|
|
variable_declaration_t *tail;
|
|
|
|
} variable_list_t;
|
|
|
|
|
|
|
|
static variable_declaration_t *new_variable_declaration(parser_ctx_t*,const WCHAR*,expression_t*);
|
|
|
|
static variable_list_t *new_variable_list(parser_ctx_t*,variable_declaration_t*);
|
|
|
|
static variable_list_t *variable_list_add(parser_ctx_t*,variable_list_t*,variable_declaration_t*);
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static void *new_statement(parser_ctx_t*,statement_type_t,size_t,unsigned);
|
|
|
|
static statement_t *new_block_statement(parser_ctx_t*,unsigned,statement_list_t*);
|
|
|
|
static statement_t *new_var_statement(parser_ctx_t*,unsigned,variable_list_t*);
|
|
|
|
static statement_t *new_expression_statement(parser_ctx_t*,unsigned,expression_t*);
|
|
|
|
static statement_t *new_if_statement(parser_ctx_t*,unsigned,expression_t*,statement_t*,statement_t*);
|
|
|
|
static statement_t *new_while_statement(parser_ctx_t*,unsigned,BOOL,expression_t*,statement_t*);
|
2020-01-24 19:54:41 +01:00
|
|
|
static statement_t *new_for_statement(parser_ctx_t*,unsigned,variable_list_t*,expression_t*,expression_t*,unsigned,
|
|
|
|
expression_t*,unsigned,statement_t*);
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_forin_statement(parser_ctx_t*,unsigned,variable_declaration_t*,expression_t*,expression_t*,statement_t*);
|
|
|
|
static statement_t *new_continue_statement(parser_ctx_t*,unsigned,const WCHAR*);
|
|
|
|
static statement_t *new_break_statement(parser_ctx_t*,unsigned,const WCHAR*);
|
|
|
|
static statement_t *new_return_statement(parser_ctx_t*,unsigned,expression_t*);
|
|
|
|
static statement_t *new_with_statement(parser_ctx_t*,unsigned,expression_t*,statement_t*);
|
|
|
|
static statement_t *new_labelled_statement(parser_ctx_t*,unsigned,const WCHAR*,statement_t*);
|
|
|
|
static statement_t *new_switch_statement(parser_ctx_t*,unsigned,expression_t*,case_clausule_t*);
|
|
|
|
static statement_t *new_throw_statement(parser_ctx_t*,unsigned,expression_t*);
|
2020-01-24 19:54:41 +01:00
|
|
|
static statement_t *new_try_statement(parser_ctx_t*,statement_t*,catch_block_t*,statement_t*,unsigned);
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
struct statement_list_t {
|
|
|
|
statement_t *head;
|
|
|
|
statement_t *tail;
|
|
|
|
};
|
|
|
|
|
2008-12-02 15:26:49 +01:00
|
|
|
static statement_list_t *new_statement_list(parser_ctx_t*,statement_t*);
|
|
|
|
static statement_list_t *statement_list_add(statement_list_t*,statement_t*);
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2008-09-08 01:22:45 +02:00
|
|
|
typedef struct _parameter_list_t {
|
2008-09-03 00:25:21 +02:00
|
|
|
parameter_t *head;
|
|
|
|
parameter_t *tail;
|
|
|
|
} parameter_list_t;
|
|
|
|
|
|
|
|
static parameter_list_t *new_parameter_list(parser_ctx_t*,const WCHAR*);
|
|
|
|
static parameter_list_t *parameter_list_add(parser_ctx_t*,parameter_list_t*,const WCHAR*);
|
|
|
|
|
2011-11-18 14:05:33 +01:00
|
|
|
static void *new_expression(parser_ctx_t *ctx,expression_type_t,size_t);
|
2008-09-21 15:47:47 +02:00
|
|
|
static expression_t *new_function_expression(parser_ctx_t*,const WCHAR*,parameter_list_t*,
|
2015-06-02 14:45:10 +02:00
|
|
|
source_elements_t*,const WCHAR*,const WCHAR*,DWORD);
|
2008-09-03 00:25:21 +02:00
|
|
|
static expression_t *new_binary_expression(parser_ctx_t*,expression_type_t,expression_t*,expression_t*);
|
|
|
|
static expression_t *new_unary_expression(parser_ctx_t*,expression_type_t,expression_t*);
|
|
|
|
static expression_t *new_conditional_expression(parser_ctx_t*,expression_t*,expression_t*,expression_t*);
|
|
|
|
static expression_t *new_member_expression(parser_ctx_t*,expression_t*,const WCHAR*);
|
2008-09-17 23:29:58 +02:00
|
|
|
static expression_t *new_new_expression(parser_ctx_t*,expression_t*,argument_list_t*);
|
2008-09-03 00:25:21 +02:00
|
|
|
static expression_t *new_call_expression(parser_ctx_t*,expression_t*,argument_list_t*);
|
|
|
|
static expression_t *new_identifier_expression(parser_ctx_t*,const WCHAR*);
|
|
|
|
static expression_t *new_literal_expression(parser_ctx_t*,literal_t*);
|
|
|
|
static expression_t *new_array_literal_expression(parser_ctx_t*,element_list_t*,int);
|
|
|
|
static expression_t *new_prop_and_value_expression(parser_ctx_t*,property_list_t*);
|
|
|
|
|
|
|
|
static source_elements_t *new_source_elements(parser_ctx_t*);
|
|
|
|
static source_elements_t *source_elements_add_statement(source_elements_t*,statement_t*);
|
|
|
|
|
2020-01-23 13:52:15 +01:00
|
|
|
#define YYLTYPE unsigned
|
|
|
|
#define YYLLOC_DEFAULT(Cur, Rhs, N) Cur = YYRHSLOC((Rhs), (N) ? 1 : 0)
|
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
%}
|
|
|
|
|
2013-08-01 11:59:12 +02:00
|
|
|
%lex-param { parser_ctx_t *ctx }
|
|
|
|
%parse-param { parser_ctx_t *ctx }
|
2019-08-18 12:59:06 +02:00
|
|
|
%define api.pure
|
2008-09-03 00:25:21 +02:00
|
|
|
%start Program
|
|
|
|
|
|
|
|
%union {
|
|
|
|
int ival;
|
2019-03-01 17:44:18 +01:00
|
|
|
jsstr_t *str;
|
2008-09-03 00:25:21 +02:00
|
|
|
literal_t *literal;
|
2008-09-08 01:22:45 +02:00
|
|
|
struct _argument_list_t *argument_list;
|
2008-09-03 00:25:21 +02:00
|
|
|
case_clausule_t *case_clausule;
|
2008-09-08 01:22:45 +02:00
|
|
|
struct _case_list_t *case_list;
|
2008-09-03 00:25:21 +02:00
|
|
|
catch_block_t *catch_block;
|
2008-09-08 01:22:45 +02:00
|
|
|
struct _element_list_t *element_list;
|
2008-09-03 00:25:21 +02:00
|
|
|
expression_t *expr;
|
|
|
|
const WCHAR *identifier;
|
2008-09-08 01:22:45 +02:00
|
|
|
struct _parameter_list_t *parameter_list;
|
|
|
|
struct _property_list_t *property_list;
|
2018-11-30 22:44:14 +01:00
|
|
|
property_definition_t *property_definition;
|
2008-09-03 00:25:21 +02:00
|
|
|
source_elements_t *source_elements;
|
|
|
|
statement_t *statement;
|
2008-09-08 01:22:45 +02:00
|
|
|
struct _statement_list_t *statement_list;
|
|
|
|
struct _variable_list_t *variable_list;
|
2008-09-03 00:25:21 +02:00
|
|
|
variable_declaration_t *variable_declaration;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* keywords */
|
2018-11-30 22:44:32 +01:00
|
|
|
%token <identifier> kBREAK kCASE kCATCH kCONTINUE kDEFAULT kDELETE kDO kELSE kFUNCTION kIF kFINALLY kFOR kGET kIN kSET
|
2018-04-04 21:43:19 +02:00
|
|
|
%token <identifier> kINSTANCEOF kNEW kNULL kRETURN kSWITCH kTHIS kTHROW kTRUE kFALSE kTRY kTYPEOF kVAR kVOID kWHILE kWITH
|
2015-06-02 14:45:10 +02:00
|
|
|
%token tANDAND tOROR tINC tDEC tHTMLCOMMENT kDIVEQ kDCOL
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* tokens */
|
|
|
|
%token <identifier> tIdentifier
|
|
|
|
%token <ival> tAssignOper tEqOper tShiftOper tRelOper
|
2010-12-28 15:40:00 +01:00
|
|
|
%token <literal> tNumericLiteral tBooleanLiteral
|
2019-03-01 17:44:18 +01:00
|
|
|
%token <str> tStringLiteral
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
%type <source_elements> SourceElements
|
|
|
|
%type <source_elements> FunctionBody
|
|
|
|
%type <statement> Statement
|
|
|
|
%type <statement> Block
|
|
|
|
%type <statement> VariableStatement
|
|
|
|
%type <statement> EmptyStatement
|
|
|
|
%type <statement> ExpressionStatement
|
|
|
|
%type <statement> IfStatement
|
|
|
|
%type <statement> IterationStatement
|
|
|
|
%type <statement> ContinueStatement
|
|
|
|
%type <statement> BreakStatement
|
|
|
|
%type <statement> ReturnStatement
|
|
|
|
%type <statement> WithStatement
|
|
|
|
%type <statement> LabelledStatement
|
|
|
|
%type <statement> SwitchStatement
|
|
|
|
%type <statement> ThrowStatement
|
|
|
|
%type <statement> TryStatement
|
|
|
|
%type <statement> Finally
|
|
|
|
%type <statement_list> StatementList StatementList_opt
|
|
|
|
%type <parameter_list> FormalParameterList FormalParameterList_opt
|
2009-07-24 09:36:23 +02:00
|
|
|
%type <expr> Expression Expression_opt Expression_err
|
2008-09-03 00:25:21 +02:00
|
|
|
%type <expr> ExpressionNoIn ExpressionNoIn_opt
|
|
|
|
%type <expr> FunctionExpression
|
|
|
|
%type <expr> AssignmentExpression AssignmentExpressionNoIn
|
|
|
|
%type <expr> ConditionalExpression ConditionalExpressionNoIn
|
|
|
|
%type <expr> LeftHandSideExpression
|
|
|
|
%type <expr> LogicalORExpression LogicalORExpressionNoIn
|
|
|
|
%type <expr> LogicalANDExpression LogicalANDExpressionNoIn
|
|
|
|
%type <expr> BitwiseORExpression BitwiseORExpressionNoIn
|
|
|
|
%type <expr> BitwiseXORExpression BitwiseXORExpressionNoIn
|
|
|
|
%type <expr> BitwiseANDExpression BitwiseANDExpressionNoIn
|
|
|
|
%type <expr> EqualityExpression EqualityExpressionNoIn
|
|
|
|
%type <expr> RelationalExpression RelationalExpressionNoIn
|
|
|
|
%type <expr> ShiftExpression
|
|
|
|
%type <expr> AdditiveExpression
|
|
|
|
%type <expr> MultiplicativeExpression
|
|
|
|
%type <expr> Initialiser_opt Initialiser
|
|
|
|
%type <expr> InitialiserNoIn_opt InitialiserNoIn
|
|
|
|
%type <expr> UnaryExpression
|
|
|
|
%type <expr> PostfixExpression
|
|
|
|
%type <expr> NewExpression
|
|
|
|
%type <expr> CallExpression
|
|
|
|
%type <expr> MemberExpression
|
|
|
|
%type <expr> PrimaryExpression
|
2018-11-30 22:44:32 +01:00
|
|
|
%type <expr> GetterSetterMethod
|
2008-09-03 00:25:21 +02:00
|
|
|
%type <identifier> Identifier_opt
|
|
|
|
%type <variable_list> VariableDeclarationList
|
|
|
|
%type <variable_list> VariableDeclarationListNoIn
|
|
|
|
%type <variable_declaration> VariableDeclaration
|
|
|
|
%type <variable_declaration> VariableDeclarationNoIn
|
|
|
|
%type <case_list> CaseClausules CaseClausules_opt
|
|
|
|
%type <case_clausule> CaseClausule DefaultClausule CaseBlock
|
|
|
|
%type <catch_block> Catch
|
|
|
|
%type <argument_list> Arguments
|
|
|
|
%type <argument_list> ArgumentList
|
|
|
|
%type <literal> Literal
|
|
|
|
%type <expr> ArrayLiteral
|
|
|
|
%type <expr> ObjectLiteral
|
|
|
|
%type <ival> Elision Elision_opt
|
|
|
|
%type <element_list> ElementList
|
|
|
|
%type <property_list> PropertyNameAndValueList
|
2018-11-30 22:44:14 +01:00
|
|
|
%type <property_definition> PropertyDefinition
|
2008-09-03 00:25:21 +02:00
|
|
|
%type <literal> PropertyName
|
|
|
|
%type <literal> BooleanLiteral
|
2009-08-27 01:20:37 +02:00
|
|
|
%type <ival> AssignOper
|
2018-04-04 21:43:19 +02:00
|
|
|
%type <identifier> IdentifierName ReservedAsIdentifier
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2008-10-15 15:10:07 +02:00
|
|
|
%nonassoc LOWER_THAN_ELSE
|
|
|
|
%nonassoc kELSE
|
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
%%
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 14 */
|
|
|
|
Program
|
2020-01-23 13:52:22 +01:00
|
|
|
: SourceElements HtmlComment { ctx->source = $1; }
|
2009-04-09 23:34:26 +02:00
|
|
|
|
|
|
|
HtmlComment
|
2020-01-23 13:52:22 +01:00
|
|
|
: tHTMLCOMMENT
|
|
|
|
| /* empty */
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 14 */
|
|
|
|
SourceElements
|
|
|
|
: /* empty */ { $$ = new_source_elements(ctx); }
|
|
|
|
| SourceElements Statement
|
|
|
|
{ $$ = source_elements_add_statement($1, $2); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 13 */
|
|
|
|
FunctionExpression
|
2020-01-23 13:52:15 +01:00
|
|
|
: kFUNCTION left_bracket FormalParameterList_opt right_bracket '{' FunctionBody '}'
|
|
|
|
{ $$ = new_function_expression(ctx, NULL, $3, $6, NULL, ctx->begin + @1, @7 - @1 + 1); }
|
|
|
|
| kFUNCTION tIdentifier left_bracket FormalParameterList_opt right_bracket '{' FunctionBody '}'
|
|
|
|
{ $$ = new_function_expression(ctx, $2, $4, $7, NULL, ctx->begin + @1, @8 - @1 + 1); }
|
|
|
|
| kFUNCTION tIdentifier kDCOL tIdentifier left_bracket FormalParameterList_opt right_bracket '{' FunctionBody '}'
|
|
|
|
{ $$ = new_function_expression(ctx, $4, $6, $9, $2, ctx->begin + @1, @10 - @1 + 1); }
|
2008-09-30 17:47:40 +02:00
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
/* ECMA-262 3rd Edition 13 */
|
|
|
|
FunctionBody
|
2012-04-26 16:17:31 +02:00
|
|
|
: SourceElements { $$ = $1; }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 13 */
|
|
|
|
FormalParameterList
|
|
|
|
: tIdentifier { $$ = new_parameter_list(ctx, $1); }
|
|
|
|
| FormalParameterList ',' tIdentifier
|
|
|
|
{ $$ = parameter_list_add(ctx, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 13 */
|
|
|
|
FormalParameterList_opt
|
|
|
|
: /* empty */ { $$ = NULL; }
|
|
|
|
| FormalParameterList { $$ = $1; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12 */
|
|
|
|
Statement
|
|
|
|
: Block { $$ = $1; }
|
|
|
|
| VariableStatement { $$ = $1; }
|
|
|
|
| EmptyStatement { $$ = $1; }
|
2020-01-23 13:52:32 +01:00
|
|
|
| FunctionExpression { $$ = new_expression_statement(ctx, @$, $1); }
|
2008-09-03 00:25:21 +02:00
|
|
|
| ExpressionStatement { $$ = $1; }
|
|
|
|
| IfStatement { $$ = $1; }
|
|
|
|
| IterationStatement { $$ = $1; }
|
|
|
|
| ContinueStatement { $$ = $1; }
|
|
|
|
| BreakStatement { $$ = $1; }
|
|
|
|
| ReturnStatement { $$ = $1; }
|
|
|
|
| WithStatement { $$ = $1; }
|
|
|
|
| LabelledStatement { $$ = $1; }
|
|
|
|
| SwitchStatement { $$ = $1; }
|
|
|
|
| ThrowStatement { $$ = $1; }
|
|
|
|
| TryStatement { $$ = $1; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
|
|
|
StatementList
|
|
|
|
: Statement { $$ = new_statement_list(ctx, $1); }
|
|
|
|
| StatementList Statement
|
|
|
|
{ $$ = statement_list_add($1, $2); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
|
|
|
StatementList_opt
|
|
|
|
: /* empty */ { $$ = NULL; }
|
|
|
|
| StatementList { $$ = $1; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.1 */
|
|
|
|
Block
|
2020-01-23 13:52:32 +01:00
|
|
|
: '{' StatementList '}' { $$ = new_block_statement(ctx, @2, $2); }
|
|
|
|
| '{' '}' { $$ = new_block_statement(ctx, @$, NULL); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
|
|
|
VariableStatement
|
|
|
|
: kVAR VariableDeclarationList semicolon_opt
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_var_statement(ctx, @$, $2); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
|
|
|
VariableDeclarationList
|
|
|
|
: VariableDeclaration { $$ = new_variable_list(ctx, $1); }
|
|
|
|
| VariableDeclarationList ',' VariableDeclaration
|
|
|
|
{ $$ = variable_list_add(ctx, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
|
|
|
VariableDeclarationListNoIn
|
|
|
|
: VariableDeclarationNoIn
|
|
|
|
{ $$ = new_variable_list(ctx, $1); }
|
|
|
|
| VariableDeclarationListNoIn ',' VariableDeclarationNoIn
|
|
|
|
{ $$ = variable_list_add(ctx, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
|
|
|
VariableDeclaration
|
|
|
|
: tIdentifier Initialiser_opt
|
|
|
|
{ $$ = new_variable_declaration(ctx, $1, $2); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
|
|
|
VariableDeclarationNoIn
|
|
|
|
: tIdentifier InitialiserNoIn_opt
|
|
|
|
{ $$ = new_variable_declaration(ctx, $1, $2); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
|
|
|
Initialiser_opt
|
|
|
|
: /* empty */ { $$ = NULL; }
|
|
|
|
| Initialiser { $$ = $1; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
|
|
|
Initialiser
|
|
|
|
: '=' AssignmentExpression
|
|
|
|
{ $$ = $2; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
|
|
|
InitialiserNoIn_opt
|
|
|
|
: /* empty */ { $$ = NULL; }
|
|
|
|
| InitialiserNoIn { $$ = $1; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.2 */
|
|
|
|
InitialiserNoIn
|
|
|
|
: '=' AssignmentExpressionNoIn
|
|
|
|
{ $$ = $2; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.3 */
|
|
|
|
EmptyStatement
|
2020-01-23 13:52:32 +01:00
|
|
|
: ';' { $$ = new_statement(ctx, STAT_EMPTY, 0, @$); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.4 */
|
|
|
|
ExpressionStatement
|
|
|
|
: Expression semicolon_opt
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_expression_statement(ctx, @$, $1); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.5 */
|
|
|
|
IfStatement
|
2009-07-24 09:36:23 +02:00
|
|
|
: kIF left_bracket Expression_err right_bracket Statement kELSE Statement
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_if_statement(ctx, @$, $3, $5, $7); }
|
2009-07-24 09:36:23 +02:00
|
|
|
| kIF left_bracket Expression_err right_bracket Statement %prec LOWER_THAN_ELSE
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_if_statement(ctx, @$, $3, $5, NULL); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.6 */
|
|
|
|
IterationStatement
|
2009-07-24 09:36:23 +02:00
|
|
|
: kDO Statement kWHILE left_bracket Expression_err right_bracket semicolon_opt
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_while_statement(ctx, @3, TRUE, $5, $2); }
|
2009-07-24 09:36:23 +02:00
|
|
|
| kWHILE left_bracket Expression_err right_bracket Statement
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_while_statement(ctx, @$, FALSE, $3, $5); }
|
2009-07-24 09:36:20 +02:00
|
|
|
| kFOR left_bracket ExpressionNoIn_opt
|
|
|
|
{ if(!explicit_error(ctx, $3, ';')) YYABORT; }
|
2020-01-23 13:52:32 +01:00
|
|
|
semicolon Expression_opt
|
2009-07-24 09:36:20 +02:00
|
|
|
{ if(!explicit_error(ctx, $6, ';')) YYABORT; }
|
2020-01-23 13:52:32 +01:00
|
|
|
semicolon Expression_opt right_bracket Statement
|
2020-01-24 19:54:41 +01:00
|
|
|
{ $$ = new_for_statement(ctx, @3, NULL, $3, $6, @6, $9, @9, $11); }
|
2009-07-24 09:36:20 +02:00
|
|
|
| kFOR left_bracket kVAR VariableDeclarationListNoIn
|
|
|
|
{ if(!explicit_error(ctx, $4, ';')) YYABORT; }
|
2020-01-23 13:52:32 +01:00
|
|
|
semicolon Expression_opt
|
2009-07-24 09:36:20 +02:00
|
|
|
{ if(!explicit_error(ctx, $7, ';')) YYABORT; }
|
2020-01-23 13:52:32 +01:00
|
|
|
semicolon Expression_opt right_bracket Statement
|
2020-01-24 19:54:41 +01:00
|
|
|
{ $$ = new_for_statement(ctx, @3, $4, NULL, $7, @7, $10, @10, $12); }
|
2009-07-24 09:36:23 +02:00
|
|
|
| kFOR left_bracket LeftHandSideExpression kIN Expression_err right_bracket Statement
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_forin_statement(ctx, @$, NULL, $3, $5, $7); }
|
2009-07-24 09:36:23 +02:00
|
|
|
| kFOR left_bracket kVAR VariableDeclarationNoIn kIN Expression_err right_bracket Statement
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_forin_statement(ctx, @$, $4, NULL, $6, $8); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.7 */
|
|
|
|
ContinueStatement
|
|
|
|
: kCONTINUE /* NONL */ Identifier_opt semicolon_opt
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_continue_statement(ctx, @$, $2); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.8 */
|
|
|
|
BreakStatement
|
|
|
|
: kBREAK /* NONL */ Identifier_opt semicolon_opt
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_break_statement(ctx, @$, $2); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.9 */
|
|
|
|
ReturnStatement
|
|
|
|
: kRETURN /* NONL */ Expression_opt semicolon_opt
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_return_statement(ctx, @$, $2); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.10 */
|
|
|
|
WithStatement
|
2009-07-24 09:36:13 +02:00
|
|
|
: kWITH left_bracket Expression right_bracket Statement
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_with_statement(ctx, @$, $3, $5); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.12 */
|
|
|
|
LabelledStatement
|
|
|
|
: tIdentifier ':' Statement
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_labelled_statement(ctx, @$, $1, $3); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.11 */
|
|
|
|
SwitchStatement
|
2009-07-24 09:36:13 +02:00
|
|
|
: kSWITCH left_bracket Expression right_bracket CaseBlock
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_switch_statement(ctx, @$, $3, $5); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.11 */
|
|
|
|
CaseBlock
|
|
|
|
: '{' CaseClausules_opt '}'
|
|
|
|
{ $$ = new_case_block(ctx, $2, NULL, NULL); }
|
|
|
|
| '{' CaseClausules_opt DefaultClausule CaseClausules_opt '}'
|
|
|
|
{ $$ = new_case_block(ctx, $2, $3, $4); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.11 */
|
|
|
|
CaseClausules_opt
|
|
|
|
: /* empty */ { $$ = NULL; }
|
|
|
|
| CaseClausules { $$ = $1; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.11 */
|
|
|
|
CaseClausules
|
|
|
|
: CaseClausule { $$ = new_case_list(ctx, $1); }
|
|
|
|
| CaseClausules CaseClausule
|
|
|
|
{ $$ = case_list_add(ctx, $1, $2); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.11 */
|
|
|
|
CaseClausule
|
|
|
|
: kCASE Expression ':' StatementList_opt
|
2020-01-24 19:54:41 +01:00
|
|
|
{ $$ = new_case_clausule(ctx, @$, $2, $4); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.11 */
|
|
|
|
DefaultClausule
|
|
|
|
: kDEFAULT ':' StatementList_opt
|
2020-01-24 19:54:41 +01:00
|
|
|
{ $$ = new_case_clausule(ctx, @$, NULL, $3); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.13 */
|
|
|
|
ThrowStatement
|
|
|
|
: kTHROW /* NONL */ Expression semicolon_opt
|
2020-01-23 13:52:32 +01:00
|
|
|
{ $$ = new_throw_statement(ctx, @$, $2); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.14 */
|
|
|
|
TryStatement
|
2020-01-24 19:54:41 +01:00
|
|
|
: kTRY Block Catch { $$ = new_try_statement(ctx, $2, $3, NULL, 0); }
|
|
|
|
| kTRY Block Finally { $$ = new_try_statement(ctx, $2, NULL, $3, @3); }
|
2008-09-03 00:25:21 +02:00
|
|
|
| kTRY Block Catch Finally
|
2020-01-24 19:54:41 +01:00
|
|
|
{ $$ = new_try_statement(ctx, $2, $3, $4, @4); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.14 */
|
|
|
|
Catch
|
2009-07-24 09:36:13 +02:00
|
|
|
: kCATCH left_bracket tIdentifier right_bracket Block
|
2009-07-24 09:36:04 +02:00
|
|
|
{ $$ = new_catch_block(ctx, $3, $5); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 12.14 */
|
|
|
|
Finally
|
2020-01-24 19:54:41 +01:00
|
|
|
: kFINALLY Block { @$ = @2; $$ = $2; }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.14 */
|
|
|
|
Expression_opt
|
|
|
|
: /* empty */ { $$ = NULL; }
|
|
|
|
| Expression { $$ = $1; }
|
|
|
|
|
2009-07-24 09:36:23 +02:00
|
|
|
Expression_err
|
|
|
|
: Expression { $$ = $1; }
|
2020-02-03 14:47:39 +01:00
|
|
|
| error { set_error(ctx, @$, JS_E_SYNTAX); YYABORT; }
|
2009-07-24 09:36:23 +02:00
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.14 */
|
|
|
|
Expression
|
|
|
|
: AssignmentExpression { $$ = $1; }
|
|
|
|
| Expression ',' AssignmentExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_COMMA, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.14 */
|
|
|
|
ExpressionNoIn_opt
|
|
|
|
: /* empty */ { $$ = NULL; }
|
|
|
|
| ExpressionNoIn { $$ = $1; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.14 */
|
|
|
|
ExpressionNoIn
|
|
|
|
: AssignmentExpressionNoIn
|
|
|
|
{ $$ = $1; }
|
|
|
|
| ExpressionNoIn ',' AssignmentExpressionNoIn
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_COMMA, $1, $3); }
|
|
|
|
|
2009-08-27 01:20:37 +02:00
|
|
|
AssignOper
|
|
|
|
: tAssignOper { $$ = $1; }
|
|
|
|
| kDIVEQ { $$ = EXPR_ASSIGNDIV; }
|
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
/* ECMA-262 3rd Edition 11.13 */
|
|
|
|
AssignmentExpression
|
|
|
|
: ConditionalExpression { $$ = $1; }
|
|
|
|
| LeftHandSideExpression '=' AssignmentExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_ASSIGN, $1, $3); }
|
2009-08-27 01:20:37 +02:00
|
|
|
| LeftHandSideExpression AssignOper AssignmentExpression
|
2008-09-03 00:25:21 +02:00
|
|
|
{ $$ = new_binary_expression(ctx, $2, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.13 */
|
|
|
|
AssignmentExpressionNoIn
|
|
|
|
: ConditionalExpressionNoIn
|
|
|
|
{ $$ = $1; }
|
|
|
|
| LeftHandSideExpression '=' AssignmentExpressionNoIn
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_ASSIGN, $1, $3); }
|
2009-08-27 01:20:37 +02:00
|
|
|
| LeftHandSideExpression AssignOper AssignmentExpressionNoIn
|
2008-09-03 00:25:21 +02:00
|
|
|
{ $$ = new_binary_expression(ctx, $2, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.12 */
|
|
|
|
ConditionalExpression
|
|
|
|
: LogicalORExpression { $$ = $1; }
|
|
|
|
| LogicalORExpression '?' AssignmentExpression ':' AssignmentExpression
|
|
|
|
{ $$ = new_conditional_expression(ctx, $1, $3, $5); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.12 */
|
|
|
|
ConditionalExpressionNoIn
|
|
|
|
: LogicalORExpressionNoIn
|
|
|
|
{ $$ = $1; }
|
|
|
|
| LogicalORExpressionNoIn '?' AssignmentExpressionNoIn ':' AssignmentExpressionNoIn
|
|
|
|
{ $$ = new_conditional_expression(ctx, $1, $3, $5); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.11 */
|
|
|
|
LogicalORExpression
|
|
|
|
: LogicalANDExpression { $$ = $1; }
|
|
|
|
| LogicalORExpression tOROR LogicalANDExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.11 */
|
|
|
|
LogicalORExpressionNoIn
|
|
|
|
: LogicalANDExpressionNoIn
|
|
|
|
{ $$ = $1; }
|
|
|
|
| LogicalORExpressionNoIn tOROR LogicalANDExpressionNoIn
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.11 */
|
|
|
|
LogicalANDExpression
|
|
|
|
: BitwiseORExpression { $$ = $1; }
|
|
|
|
| LogicalANDExpression tANDAND BitwiseORExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.11 */
|
|
|
|
LogicalANDExpressionNoIn
|
|
|
|
: BitwiseORExpressionNoIn
|
|
|
|
{ $$ = $1; }
|
|
|
|
| LogicalANDExpressionNoIn tANDAND BitwiseORExpressionNoIn
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
|
|
|
BitwiseORExpression
|
|
|
|
: BitwiseXORExpression { $$ = $1; }
|
|
|
|
| BitwiseORExpression '|' BitwiseXORExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_BOR, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
|
|
|
BitwiseORExpressionNoIn
|
|
|
|
: BitwiseXORExpressionNoIn
|
|
|
|
{ $$ = $1; }
|
|
|
|
| BitwiseORExpressionNoIn '|' BitwiseXORExpressionNoIn
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_BOR, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
|
|
|
BitwiseXORExpression
|
|
|
|
: BitwiseANDExpression { $$ = $1; }
|
|
|
|
| BitwiseXORExpression '^' BitwiseANDExpression
|
2008-09-17 23:31:38 +02:00
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_BXOR, $1, $3); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
|
|
|
BitwiseXORExpressionNoIn
|
|
|
|
: BitwiseANDExpressionNoIn
|
|
|
|
{ $$ = $1; }
|
|
|
|
| BitwiseXORExpressionNoIn '^' BitwiseANDExpressionNoIn
|
2008-09-17 23:31:38 +02:00
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_BXOR, $1, $3); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
|
|
|
BitwiseANDExpression
|
|
|
|
: EqualityExpression { $$ = $1; }
|
|
|
|
| BitwiseANDExpression '&' EqualityExpression
|
2008-09-17 23:31:38 +02:00
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_BAND, $1, $3); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.10 */
|
|
|
|
BitwiseANDExpressionNoIn
|
|
|
|
: EqualityExpressionNoIn
|
|
|
|
{ $$ = $1; }
|
|
|
|
| BitwiseANDExpressionNoIn '&' EqualityExpressionNoIn
|
2008-09-17 23:31:38 +02:00
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_BAND, $1, $3); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.9 */
|
|
|
|
EqualityExpression
|
|
|
|
: RelationalExpression { $$ = $1; }
|
|
|
|
| EqualityExpression tEqOper RelationalExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, $2, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.9 */
|
|
|
|
EqualityExpressionNoIn
|
|
|
|
: RelationalExpressionNoIn { $$ = $1; }
|
|
|
|
| EqualityExpressionNoIn tEqOper RelationalExpressionNoIn
|
|
|
|
{ $$ = new_binary_expression(ctx, $2, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.8 */
|
|
|
|
RelationalExpression
|
|
|
|
: ShiftExpression { $$ = $1; }
|
|
|
|
| RelationalExpression tRelOper ShiftExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, $2, $1, $3); }
|
|
|
|
| RelationalExpression kINSTANCEOF ShiftExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_INSTANCEOF, $1, $3); }
|
|
|
|
| RelationalExpression kIN ShiftExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_IN, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.8 */
|
|
|
|
RelationalExpressionNoIn
|
|
|
|
: ShiftExpression { $$ = $1; }
|
|
|
|
| RelationalExpressionNoIn tRelOper ShiftExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, $2, $1, $3); }
|
|
|
|
| RelationalExpressionNoIn kINSTANCEOF ShiftExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_INSTANCEOF, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.7 */
|
|
|
|
ShiftExpression
|
|
|
|
: AdditiveExpression { $$ = $1; }
|
|
|
|
| ShiftExpression tShiftOper AdditiveExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, $2, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.6 */
|
|
|
|
AdditiveExpression
|
|
|
|
: MultiplicativeExpression
|
|
|
|
{ $$ = $1; }
|
|
|
|
| AdditiveExpression '+' MultiplicativeExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_ADD, $1, $3); }
|
|
|
|
| AdditiveExpression '-' MultiplicativeExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_SUB, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.5 */
|
|
|
|
MultiplicativeExpression
|
|
|
|
: UnaryExpression { $$ = $1; }
|
|
|
|
| MultiplicativeExpression '*' UnaryExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_MUL, $1, $3); }
|
|
|
|
| MultiplicativeExpression '/' UnaryExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_DIV, $1, $3); }
|
|
|
|
| MultiplicativeExpression '%' UnaryExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_MOD, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.4 */
|
|
|
|
UnaryExpression
|
|
|
|
: PostfixExpression { $$ = $1; }
|
|
|
|
| kDELETE UnaryExpression
|
|
|
|
{ $$ = new_unary_expression(ctx, EXPR_DELETE, $2); }
|
|
|
|
| kVOID UnaryExpression { $$ = new_unary_expression(ctx, EXPR_VOID, $2); }
|
|
|
|
| kTYPEOF UnaryExpression
|
|
|
|
{ $$ = new_unary_expression(ctx, EXPR_TYPEOF, $2); }
|
|
|
|
| tINC UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PREINC, $2); }
|
|
|
|
| tDEC UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PREDEC, $2); }
|
|
|
|
| '+' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_PLUS, $2); }
|
|
|
|
| '-' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_MINUS, $2); }
|
|
|
|
| '~' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_BITNEG, $2); }
|
|
|
|
| '!' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_LOGNEG, $2); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.2 */
|
|
|
|
PostfixExpression
|
|
|
|
: LeftHandSideExpression
|
|
|
|
{ $$ = $1; }
|
|
|
|
| LeftHandSideExpression /* NONL */ tINC
|
|
|
|
{ $$ = new_unary_expression(ctx, EXPR_POSTINC, $1); }
|
|
|
|
| LeftHandSideExpression /* NONL */ tDEC
|
|
|
|
{ $$ = new_unary_expression(ctx, EXPR_POSTDEC, $1); }
|
|
|
|
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.2 */
|
|
|
|
LeftHandSideExpression
|
|
|
|
: NewExpression { $$ = $1; }
|
|
|
|
| CallExpression { $$ = $1; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.2 */
|
|
|
|
NewExpression
|
|
|
|
: MemberExpression { $$ = $1; }
|
2008-09-17 23:29:58 +02:00
|
|
|
| kNEW NewExpression { $$ = new_new_expression(ctx, $2, NULL); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.2 */
|
|
|
|
MemberExpression
|
|
|
|
: PrimaryExpression { $$ = $1; }
|
|
|
|
| FunctionExpression { $$ = $1; }
|
|
|
|
| MemberExpression '[' Expression ']'
|
2011-12-07 11:01:40 +01:00
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_ARRAY, $1, $3); }
|
2018-04-04 21:43:19 +02:00
|
|
|
| MemberExpression '.' IdentifierName
|
2008-09-03 00:25:21 +02:00
|
|
|
{ $$ = new_member_expression(ctx, $1, $3); }
|
|
|
|
| kNEW MemberExpression Arguments
|
2008-09-17 23:29:58 +02:00
|
|
|
{ $$ = new_new_expression(ctx, $2, $3); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.2 */
|
|
|
|
CallExpression
|
|
|
|
: MemberExpression Arguments
|
|
|
|
{ $$ = new_call_expression(ctx, $1, $2); }
|
|
|
|
| CallExpression Arguments
|
|
|
|
{ $$ = new_call_expression(ctx, $1, $2); }
|
|
|
|
| CallExpression '[' Expression ']'
|
2011-12-07 11:01:40 +01:00
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_ARRAY, $1, $3); }
|
2018-04-04 21:43:19 +02:00
|
|
|
| CallExpression '.' IdentifierName
|
2008-09-03 00:25:21 +02:00
|
|
|
{ $$ = new_member_expression(ctx, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.2 */
|
|
|
|
Arguments
|
|
|
|
: '(' ')' { $$ = NULL; }
|
|
|
|
| '(' ArgumentList ')' { $$ = $2; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.2 */
|
|
|
|
ArgumentList
|
|
|
|
: AssignmentExpression { $$ = new_argument_list(ctx, $1); }
|
|
|
|
| ArgumentList ',' AssignmentExpression
|
|
|
|
{ $$ = argument_list_add(ctx, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.1 */
|
|
|
|
PrimaryExpression
|
2011-11-18 14:05:33 +01:00
|
|
|
: kTHIS { $$ = new_expression(ctx, EXPR_THIS, 0); }
|
2008-09-03 00:25:21 +02:00
|
|
|
| tIdentifier { $$ = new_identifier_expression(ctx, $1); }
|
|
|
|
| Literal { $$ = new_literal_expression(ctx, $1); }
|
|
|
|
| ArrayLiteral { $$ = $1; }
|
|
|
|
| ObjectLiteral { $$ = $1; }
|
|
|
|
| '(' Expression ')' { $$ = $2; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.1.4 */
|
|
|
|
ArrayLiteral
|
2008-10-07 19:01:06 +02:00
|
|
|
: '[' ']' { $$ = new_array_literal_expression(ctx, NULL, 0); }
|
2008-10-14 00:35:34 +02:00
|
|
|
| '[' Elision ']' { $$ = new_array_literal_expression(ctx, NULL, $2+1); }
|
2008-09-03 00:25:21 +02:00
|
|
|
| '[' ElementList ']' { $$ = new_array_literal_expression(ctx, $2, 0); }
|
|
|
|
| '[' ElementList ',' Elision_opt ']'
|
2008-09-21 15:38:52 +02:00
|
|
|
{ $$ = new_array_literal_expression(ctx, $2, $4+1); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.1.4 */
|
|
|
|
ElementList
|
|
|
|
: Elision_opt AssignmentExpression
|
|
|
|
{ $$ = new_element_list(ctx, $1, $2); }
|
|
|
|
| ElementList ',' Elision_opt AssignmentExpression
|
|
|
|
{ $$ = element_list_add(ctx, $1, $3, $4); }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.1.4 */
|
|
|
|
Elision
|
|
|
|
: ',' { $$ = 1; }
|
|
|
|
| Elision ',' { $$ = $1 + 1; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.1.4 */
|
|
|
|
Elision_opt
|
|
|
|
: /* empty */ { $$ = 0; }
|
|
|
|
| Elision { $$ = $1; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.1.5 */
|
|
|
|
ObjectLiteral
|
|
|
|
: '{' '}' { $$ = new_prop_and_value_expression(ctx, NULL); }
|
|
|
|
| '{' PropertyNameAndValueList '}'
|
|
|
|
{ $$ = new_prop_and_value_expression(ctx, $2); }
|
2018-10-16 17:22:03 +02:00
|
|
|
| '{' PropertyNameAndValueList ',' '}'
|
|
|
|
{
|
|
|
|
if(ctx->script->version < 2) {
|
|
|
|
WARN("Trailing comma in object literal is illegal in legacy mode.\n");
|
2020-01-23 13:52:22 +01:00
|
|
|
ctx->hres = JS_E_SYNTAX;
|
2018-10-16 17:22:03 +02:00
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
$$ = new_prop_and_value_expression(ctx, $2);
|
|
|
|
}
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 11.1.5 */
|
|
|
|
PropertyNameAndValueList
|
2018-11-30 22:44:14 +01:00
|
|
|
: PropertyDefinition { $$ = new_property_list(ctx, $1); }
|
|
|
|
| PropertyNameAndValueList ',' PropertyDefinition
|
|
|
|
{ $$ = property_list_add(ctx, $1, $3); }
|
|
|
|
|
|
|
|
/* ECMA-262 5.1 Edition 12.2.6 */
|
|
|
|
PropertyDefinition
|
2008-09-03 00:25:21 +02:00
|
|
|
: PropertyName ':' AssignmentExpression
|
2018-11-30 22:44:32 +01:00
|
|
|
{ $$ = new_property_definition(ctx, PROPERTY_DEFINITION_VALUE, $1, $3); }
|
|
|
|
| kGET PropertyName GetterSetterMethod
|
|
|
|
{ $$ = new_property_definition(ctx, PROPERTY_DEFINITION_GETTER, $2, $3); }
|
|
|
|
| kSET PropertyName GetterSetterMethod
|
|
|
|
{ $$ = new_property_definition(ctx, PROPERTY_DEFINITION_SETTER, $2, $3); }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2018-11-30 22:44:32 +01:00
|
|
|
GetterSetterMethod
|
|
|
|
: left_bracket FormalParameterList_opt right_bracket '{' FunctionBody '}'
|
2020-01-23 13:52:15 +01:00
|
|
|
{ $$ = new_function_expression(ctx, NULL, $2, $5, NULL, ctx->begin + @1, @6 - @1 + 1); }
|
2018-11-30 22:44:32 +01:00
|
|
|
|
|
|
|
/* Ecma-262 3rd Edition 11.1.5 */
|
2008-09-03 00:25:21 +02:00
|
|
|
PropertyName
|
2019-06-06 09:17:49 +02:00
|
|
|
: IdentifierName { $$ = new_string_literal(ctx, compiler_alloc_string_len(ctx->compiler, $1, lstrlenW($1))); }
|
2008-09-03 00:25:21 +02:00
|
|
|
| tStringLiteral { $$ = new_string_literal(ctx, $1); }
|
|
|
|
| tNumericLiteral { $$ = $1; }
|
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 7.6 */
|
|
|
|
Identifier_opt
|
|
|
|
: /* empty*/ { $$ = NULL; }
|
|
|
|
| tIdentifier { $$ = $1; }
|
|
|
|
|
2018-04-04 21:43:19 +02:00
|
|
|
/* ECMA-262 5.1 Edition 7.6 */
|
|
|
|
IdentifierName
|
|
|
|
: tIdentifier { $$ = $1; }
|
|
|
|
| ReservedAsIdentifier
|
|
|
|
{
|
|
|
|
if(ctx->script->version < SCRIPTLANGUAGEVERSION_ES5) {
|
|
|
|
WARN("%s keyword used as an identifier in legacy mode.\n",
|
|
|
|
debugstr_w($1));
|
2020-01-23 13:52:22 +01:00
|
|
|
ctx->hres = JS_E_SYNTAX;
|
2018-04-04 21:43:19 +02:00
|
|
|
YYABORT;
|
|
|
|
}
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReservedAsIdentifier
|
|
|
|
: kBREAK { $$ = $1; }
|
|
|
|
| kCASE { $$ = $1; }
|
|
|
|
| kCATCH { $$ = $1; }
|
|
|
|
| kCONTINUE { $$ = $1; }
|
|
|
|
| kDEFAULT { $$ = $1; }
|
|
|
|
| kDELETE { $$ = $1; }
|
|
|
|
| kDO { $$ = $1; }
|
|
|
|
| kELSE { $$ = $1; }
|
|
|
|
| kFALSE { $$ = $1; }
|
|
|
|
| kFINALLY { $$ = $1; }
|
|
|
|
| kFOR { $$ = $1; }
|
|
|
|
| kFUNCTION { $$ = $1; }
|
2018-11-30 22:44:32 +01:00
|
|
|
| kGET { $$ = $1; }
|
2018-04-04 21:43:19 +02:00
|
|
|
| kIF { $$ = $1; }
|
|
|
|
| kIN { $$ = $1; }
|
|
|
|
| kINSTANCEOF { $$ = $1; }
|
|
|
|
| kNEW { $$ = $1; }
|
|
|
|
| kNULL { $$ = $1; }
|
|
|
|
| kRETURN { $$ = $1; }
|
2018-11-30 22:44:32 +01:00
|
|
|
| kSET { $$ = $1; }
|
2018-04-04 21:43:19 +02:00
|
|
|
| kSWITCH { $$ = $1; }
|
|
|
|
| kTHIS { $$ = $1; }
|
|
|
|
| kTHROW { $$ = $1; }
|
|
|
|
| kTRUE { $$ = $1; }
|
|
|
|
| kTRY { $$ = $1; }
|
|
|
|
| kTYPEOF { $$ = $1; }
|
|
|
|
| kVAR { $$ = $1; }
|
|
|
|
| kVOID { $$ = $1; }
|
|
|
|
| kWHILE { $$ = $1; }
|
|
|
|
| kWITH { $$ = $1; }
|
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
/* ECMA-262 3rd Edition 7.8 */
|
|
|
|
Literal
|
|
|
|
: kNULL { $$ = new_null_literal(ctx); }
|
|
|
|
| BooleanLiteral { $$ = $1; }
|
|
|
|
| tNumericLiteral { $$ = $1; }
|
|
|
|
| tStringLiteral { $$ = new_string_literal(ctx, $1); }
|
2008-09-15 20:38:18 +02:00
|
|
|
| '/' { $$ = parse_regexp(ctx);
|
|
|
|
if(!$$) YYABORT; }
|
2009-08-27 01:20:37 +02:00
|
|
|
| kDIVEQ { $$ = parse_regexp(ctx);
|
|
|
|
if(!$$) YYABORT; }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
/* ECMA-262 3rd Edition 7.8.2 */
|
|
|
|
BooleanLiteral
|
2009-08-28 23:53:05 +02:00
|
|
|
: kTRUE { $$ = new_boolean_literal(ctx, VARIANT_TRUE); }
|
|
|
|
| kFALSE { $$ = new_boolean_literal(ctx, VARIANT_FALSE); }
|
2010-12-28 15:40:00 +01:00
|
|
|
| tBooleanLiteral { $$ = $1; }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
semicolon_opt
|
|
|
|
: ';'
|
2020-02-03 14:47:39 +01:00
|
|
|
| error { if(!allow_auto_semicolon(ctx)) {YYABORT;} else { ctx->hres = S_OK; ctx->error_loc = -1; } }
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2009-07-24 09:36:04 +02:00
|
|
|
left_bracket
|
2020-01-23 13:52:15 +01:00
|
|
|
: '('
|
2020-02-03 14:47:39 +01:00
|
|
|
| error { set_error(ctx, @$, JS_E_MISSING_LBRACKET); YYABORT; }
|
2009-07-24 09:36:04 +02:00
|
|
|
|
2009-07-24 09:36:13 +02:00
|
|
|
right_bracket
|
|
|
|
: ')'
|
2020-02-03 14:47:39 +01:00
|
|
|
| error { set_error(ctx, @$, JS_E_MISSING_RBRACKET); YYABORT; }
|
2009-07-24 09:36:13 +02:00
|
|
|
|
2009-07-24 09:36:20 +02:00
|
|
|
semicolon
|
|
|
|
: ';'
|
2020-02-03 14:47:39 +01:00
|
|
|
| error { set_error(ctx, @$, JS_E_MISSING_SEMICOLON); YYABORT; }
|
2009-07-24 09:36:20 +02:00
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
%%
|
|
|
|
|
|
|
|
static BOOL allow_auto_semicolon(parser_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
return ctx->nl || ctx->ptr == ctx->end || *(ctx->ptr-1) == '}';
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static void *new_statement(parser_ctx_t *ctx, statement_type_t type, size_t size, unsigned loc)
|
2011-12-19 14:58:19 +01:00
|
|
|
{
|
|
|
|
statement_t *stat;
|
|
|
|
|
|
|
|
stat = parser_alloc(ctx, size ? size : sizeof(*stat));
|
|
|
|
if(!stat)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stat->type = type;
|
2020-01-23 13:52:32 +01:00
|
|
|
stat->loc = loc;
|
2011-12-19 14:58:19 +01:00
|
|
|
stat->next = NULL;
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2019-03-01 17:44:18 +01:00
|
|
|
static literal_t *new_string_literal(parser_ctx_t *ctx, jsstr_t *str)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
|
|
|
literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
|
|
|
|
|
2009-10-14 14:41:50 +02:00
|
|
|
ret->type = LT_STRING;
|
2019-03-01 17:44:18 +01:00
|
|
|
ret->u.str = str;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static literal_t *new_null_literal(parser_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
literal_t *ret = parser_alloc(ctx, sizeof(literal_t));
|
|
|
|
|
2009-10-14 14:41:50 +02:00
|
|
|
ret->type = LT_NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-30 22:44:32 +01:00
|
|
|
static property_definition_t *new_property_definition(parser_ctx_t *ctx, property_definition_type_t type,
|
|
|
|
literal_t *name, expression_t *value)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2018-11-30 22:44:07 +01:00
|
|
|
property_definition_t *ret = parser_alloc(ctx, sizeof(property_definition_t));
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2018-11-30 22:44:32 +01:00
|
|
|
ret->type = type;
|
2008-09-03 00:25:21 +02:00
|
|
|
ret->name = name;
|
|
|
|
ret->value = value;
|
|
|
|
ret->next = NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-30 22:44:14 +01:00
|
|
|
static property_list_t *new_property_list(parser_ctx_t *ctx, property_definition_t *prop)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
|
|
|
property_list_t *ret = parser_alloc_tmp(ctx, sizeof(property_list_t));
|
2018-11-30 22:44:14 +01:00
|
|
|
ret->head = ret->tail = prop;
|
2008-09-03 00:25:21 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-30 22:44:14 +01:00
|
|
|
static property_list_t *property_list_add(parser_ctx_t *ctx, property_list_t *list, property_definition_t *prop)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2018-11-30 22:44:14 +01:00
|
|
|
list->tail = list->tail->next = prop;
|
2008-09-03 00:25:21 +02:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static array_element_t *new_array_element(parser_ctx_t *ctx, int elision, expression_t *expr)
|
|
|
|
{
|
|
|
|
array_element_t *ret = parser_alloc(ctx, sizeof(array_element_t));
|
|
|
|
|
|
|
|
ret->elision = elision;
|
|
|
|
ret->expr = expr;
|
|
|
|
ret->next = NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static element_list_t *new_element_list(parser_ctx_t *ctx, int elision, expression_t *expr)
|
|
|
|
{
|
|
|
|
element_list_t *ret = parser_alloc_tmp(ctx, sizeof(element_list_t));
|
|
|
|
|
|
|
|
ret->head = ret->tail = new_array_element(ctx, elision, expr);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static element_list_t *element_list_add(parser_ctx_t *ctx, element_list_t *list, int elision, expression_t *expr)
|
|
|
|
{
|
|
|
|
list->tail = list->tail->next = new_array_element(ctx, elision, expr);
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static argument_t *new_argument(parser_ctx_t *ctx, expression_t *expr)
|
|
|
|
{
|
|
|
|
argument_t *ret = parser_alloc(ctx, sizeof(argument_t));
|
|
|
|
|
|
|
|
ret->expr = expr;
|
|
|
|
ret->next = NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static argument_list_t *new_argument_list(parser_ctx_t *ctx, expression_t *expr)
|
|
|
|
{
|
|
|
|
argument_list_t *ret = parser_alloc_tmp(ctx, sizeof(argument_list_t));
|
|
|
|
|
|
|
|
ret->head = ret->tail = new_argument(ctx, expr);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static argument_list_t *argument_list_add(parser_ctx_t *ctx, argument_list_t *list, expression_t *expr)
|
|
|
|
{
|
|
|
|
list->tail = list->tail->next = new_argument(ctx, expr);
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static catch_block_t *new_catch_block(parser_ctx_t *ctx, const WCHAR *identifier, statement_t *statement)
|
|
|
|
{
|
|
|
|
catch_block_t *ret = parser_alloc(ctx, sizeof(catch_block_t));
|
|
|
|
|
|
|
|
ret->identifier = identifier;
|
|
|
|
ret->statement = statement;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-01-24 19:54:41 +01:00
|
|
|
static case_clausule_t *new_case_clausule(parser_ctx_t *ctx, unsigned loc, expression_t *expr, statement_list_t *stat_list)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
|
|
|
case_clausule_t *ret = parser_alloc(ctx, sizeof(case_clausule_t));
|
|
|
|
|
|
|
|
ret->expr = expr;
|
|
|
|
ret->stat = stat_list ? stat_list->head : NULL;
|
2020-01-24 19:54:41 +01:00
|
|
|
ret->loc = loc;
|
2008-09-03 00:25:21 +02:00
|
|
|
ret->next = NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static case_list_t *new_case_list(parser_ctx_t *ctx, case_clausule_t *case_clausule)
|
|
|
|
{
|
|
|
|
case_list_t *ret = parser_alloc_tmp(ctx, sizeof(case_list_t));
|
|
|
|
|
|
|
|
ret->head = ret->tail = case_clausule;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static case_list_t *case_list_add(parser_ctx_t *ctx, case_list_t *list, case_clausule_t *case_clausule)
|
|
|
|
{
|
|
|
|
list->tail = list->tail->next = case_clausule;
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static case_clausule_t *new_case_block(parser_ctx_t *ctx, case_list_t *case_list1,
|
|
|
|
case_clausule_t *default_clausule, case_list_t *case_list2)
|
|
|
|
{
|
2008-09-05 11:25:36 +02:00
|
|
|
case_clausule_t *ret = NULL, *iter = NULL, *iter2;
|
2008-09-03 00:25:21 +02:00
|
|
|
statement_t *stat = NULL;
|
|
|
|
|
|
|
|
if(case_list1) {
|
|
|
|
ret = case_list1->head;
|
|
|
|
iter = case_list1->tail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(default_clausule) {
|
|
|
|
if(ret)
|
|
|
|
iter = iter->next = default_clausule;
|
|
|
|
else
|
|
|
|
ret = iter = default_clausule;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(case_list2) {
|
|
|
|
if(ret)
|
|
|
|
iter->next = case_list2->head;
|
|
|
|
else
|
|
|
|
ret = case_list2->head;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
|
|
|
|
2008-09-17 23:30:20 +02:00
|
|
|
for(iter = ret; iter; iter = iter->next) {
|
|
|
|
for(iter2 = iter; iter2 && !iter2->stat; iter2 = iter2->next);
|
2008-09-03 00:25:21 +02:00
|
|
|
if(!iter2)
|
|
|
|
break;
|
|
|
|
|
|
|
|
while(iter != iter2) {
|
|
|
|
iter->stat = iter2->stat;
|
2008-09-17 23:30:20 +02:00
|
|
|
iter = iter->next;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(stat) {
|
|
|
|
while(stat->next)
|
|
|
|
stat = stat->next;
|
|
|
|
stat->next = iter->stat;
|
|
|
|
}else {
|
|
|
|
stat = iter->stat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_block_statement(parser_ctx_t *ctx, unsigned loc, statement_list_t *list)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
block_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_BLOCK, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->stat_list = list ? list->head : NULL;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static variable_declaration_t *new_variable_declaration(parser_ctx_t *ctx, const WCHAR *identifier, expression_t *expr)
|
|
|
|
{
|
|
|
|
variable_declaration_t *ret = parser_alloc(ctx, sizeof(variable_declaration_t));
|
|
|
|
|
|
|
|
ret->identifier = identifier;
|
|
|
|
ret->expr = expr;
|
|
|
|
ret->next = NULL;
|
2012-04-25 11:26:21 +02:00
|
|
|
ret->global_next = NULL;
|
2008-09-30 17:47:40 +02:00
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static variable_list_t *new_variable_list(parser_ctx_t *ctx, variable_declaration_t *decl)
|
|
|
|
{
|
|
|
|
variable_list_t *ret = parser_alloc_tmp(ctx, sizeof(variable_list_t));
|
|
|
|
|
|
|
|
ret->head = ret->tail = decl;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static variable_list_t *variable_list_add(parser_ctx_t *ctx, variable_list_t *list, variable_declaration_t *decl)
|
|
|
|
{
|
|
|
|
list->tail = list->tail->next = decl;
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_var_statement(parser_ctx_t *ctx, unsigned loc, variable_list_t *variable_list)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
var_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_VAR, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->variable_list = variable_list->head;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_expression_statement(parser_ctx_t *ctx, unsigned loc, expression_t *expr)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
expression_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_EXPR, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->expr = expr;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_if_statement(parser_ctx_t *ctx, unsigned loc, expression_t *expr,
|
|
|
|
statement_t *if_stat, statement_t *else_stat)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
if_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_IF, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->expr = expr;
|
|
|
|
ret->if_stat = if_stat;
|
|
|
|
ret->else_stat = else_stat;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_while_statement(parser_ctx_t *ctx, unsigned loc, BOOL dowhile, expression_t *expr, statement_t *stat)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
while_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_WHILE, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2008-09-17 23:35:38 +02:00
|
|
|
ret->do_while = dowhile;
|
2008-09-03 00:25:21 +02:00
|
|
|
ret->expr = expr;
|
|
|
|
ret->statement = stat;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_for_statement(parser_ctx_t *ctx, unsigned loc, variable_list_t *variable_list, expression_t *begin_expr,
|
2020-01-24 19:54:41 +01:00
|
|
|
expression_t *expr, unsigned expr_loc, expression_t *end_expr, unsigned end_loc, statement_t *statement)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
for_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_FOR, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->variable_list = variable_list ? variable_list->head : NULL;
|
|
|
|
ret->begin_expr = begin_expr;
|
|
|
|
ret->expr = expr;
|
2020-01-24 19:54:41 +01:00
|
|
|
ret->expr_loc = expr_loc;
|
2008-09-03 00:25:21 +02:00
|
|
|
ret->end_expr = end_expr;
|
2020-01-24 19:54:41 +01:00
|
|
|
ret->end_loc = end_loc;
|
2008-09-03 00:25:21 +02:00
|
|
|
ret->statement = statement;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_forin_statement(parser_ctx_t *ctx, unsigned loc, variable_declaration_t *variable, expression_t *expr,
|
2008-09-03 00:25:21 +02:00
|
|
|
expression_t *in_expr, statement_t *statement)
|
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
forin_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_FORIN, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->variable = variable;
|
|
|
|
ret->expr = expr;
|
|
|
|
ret->in_expr = in_expr;
|
|
|
|
ret->statement = statement;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_continue_statement(parser_ctx_t *ctx, unsigned loc, const WCHAR *identifier)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
branch_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_CONTINUE, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->identifier = identifier;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_break_statement(parser_ctx_t *ctx, unsigned loc, const WCHAR *identifier)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
branch_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_BREAK, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->identifier = identifier;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_return_statement(parser_ctx_t *ctx, unsigned loc, expression_t *expr)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
expression_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_RETURN, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->expr = expr;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_with_statement(parser_ctx_t *ctx, unsigned loc, expression_t *expr, statement_t *statement)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
with_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_WITH, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->expr = expr;
|
|
|
|
ret->statement = statement;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_labelled_statement(parser_ctx_t *ctx, unsigned loc, const WCHAR *identifier, statement_t *statement)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
labelled_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_LABEL, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->identifier = identifier;
|
|
|
|
ret->statement = statement;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_switch_statement(parser_ctx_t *ctx, unsigned loc, expression_t *expr, case_clausule_t *case_list)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
switch_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_SWITCH, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->expr = expr;
|
|
|
|
ret->case_list = case_list;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
static statement_t *new_throw_statement(parser_ctx_t *ctx, unsigned loc, expression_t *expr)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
expression_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_THROW, sizeof(*ret), loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->expr = expr;
|
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static statement_t *new_try_statement(parser_ctx_t *ctx, statement_t *try_statement,
|
2020-01-24 19:54:41 +01:00
|
|
|
catch_block_t *catch_block, statement_t *finally_statement, unsigned finally_loc)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-12-19 14:58:19 +01:00
|
|
|
try_statement_t *ret;
|
|
|
|
|
2020-01-23 13:52:32 +01:00
|
|
|
ret = new_statement(ctx, STAT_TRY, sizeof(*ret), try_statement->loc);
|
2011-12-19 14:58:19 +01:00
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->try_statement = try_statement;
|
|
|
|
ret->catch_block = catch_block;
|
|
|
|
ret->finally_statement = finally_statement;
|
2020-01-24 19:54:41 +01:00
|
|
|
ret->finally_loc = finally_loc;
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
return &ret->stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static parameter_t *new_parameter(parser_ctx_t *ctx, const WCHAR *identifier)
|
|
|
|
{
|
|
|
|
parameter_t *ret = parser_alloc(ctx, sizeof(parameter_t));
|
|
|
|
|
|
|
|
ret->identifier = identifier;
|
|
|
|
ret->next = NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static parameter_list_t *new_parameter_list(parser_ctx_t *ctx, const WCHAR *identifier)
|
|
|
|
{
|
|
|
|
parameter_list_t *ret = parser_alloc_tmp(ctx, sizeof(parameter_list_t));
|
|
|
|
|
|
|
|
ret->head = ret->tail = new_parameter(ctx, identifier);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static parameter_list_t *parameter_list_add(parser_ctx_t *ctx, parameter_list_t *list, const WCHAR *identifier)
|
|
|
|
{
|
|
|
|
list->tail = list->tail->next = new_parameter(ctx, identifier);
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
2015-06-02 14:45:10 +02:00
|
|
|
static expression_t *new_function_expression(parser_ctx_t *ctx, const WCHAR *identifier, parameter_list_t *parameter_list,
|
|
|
|
source_elements_t *source_elements, const WCHAR *event_target, const WCHAR *src_str, DWORD src_len)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-11-18 14:05:33 +01:00
|
|
|
function_expression_t *ret = new_expression(ctx, EXPR_FUNC, sizeof(*ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->identifier = identifier;
|
|
|
|
ret->parameter_list = parameter_list ? parameter_list->head : NULL;
|
|
|
|
ret->source_elements = source_elements;
|
2015-06-02 14:45:10 +02:00
|
|
|
ret->event_target = event_target;
|
2008-09-21 15:47:47 +02:00
|
|
|
ret->src_str = src_str;
|
|
|
|
ret->src_len = src_len;
|
2012-04-26 16:17:31 +02:00
|
|
|
ret->next = NULL;
|
2008-10-20 22:12:42 +02:00
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
return &ret->expr;
|
|
|
|
}
|
|
|
|
|
2011-11-18 14:05:33 +01:00
|
|
|
static void *new_expression(parser_ctx_t *ctx, expression_type_t type, size_t size)
|
|
|
|
{
|
|
|
|
expression_t *ret = parser_alloc(ctx, size ? size : sizeof(*ret));
|
|
|
|
|
2011-11-18 14:05:57 +01:00
|
|
|
ret->type = type;
|
2011-11-18 14:05:33 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
static expression_t *new_binary_expression(parser_ctx_t *ctx, expression_type_t type,
|
|
|
|
expression_t *expression1, expression_t *expression2)
|
|
|
|
{
|
2011-11-18 14:05:33 +01:00
|
|
|
binary_expression_t *ret = new_expression(ctx, type, sizeof(*ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->expression1 = expression1;
|
|
|
|
ret->expression2 = expression2;
|
|
|
|
|
|
|
|
return &ret->expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static expression_t *new_unary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *expression)
|
|
|
|
{
|
2011-11-18 14:05:33 +01:00
|
|
|
unary_expression_t *ret = new_expression(ctx, type, sizeof(*ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->expression = expression;
|
|
|
|
|
|
|
|
return &ret->expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static expression_t *new_conditional_expression(parser_ctx_t *ctx, expression_t *expression,
|
|
|
|
expression_t *true_expression, expression_t *false_expression)
|
|
|
|
{
|
2011-11-18 14:05:33 +01:00
|
|
|
conditional_expression_t *ret = new_expression(ctx, EXPR_COND, sizeof(*ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->expression = expression;
|
|
|
|
ret->true_expression = true_expression;
|
|
|
|
ret->false_expression = false_expression;
|
|
|
|
|
|
|
|
return &ret->expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static expression_t *new_member_expression(parser_ctx_t *ctx, expression_t *expression, const WCHAR *identifier)
|
|
|
|
{
|
2011-11-18 14:05:33 +01:00
|
|
|
member_expression_t *ret = new_expression(ctx, EXPR_MEMBER, sizeof(*ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->expression = expression;
|
|
|
|
ret->identifier = identifier;
|
|
|
|
|
|
|
|
return &ret->expr;
|
|
|
|
}
|
|
|
|
|
2008-09-17 23:29:58 +02:00
|
|
|
static expression_t *new_new_expression(parser_ctx_t *ctx, expression_t *expression, argument_list_t *argument_list)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2011-11-18 14:05:33 +01:00
|
|
|
call_expression_t *ret = new_expression(ctx, EXPR_NEW, sizeof(*ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->expression = expression;
|
|
|
|
ret->argument_list = argument_list ? argument_list->head : NULL;
|
|
|
|
|
|
|
|
return &ret->expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static expression_t *new_call_expression(parser_ctx_t *ctx, expression_t *expression, argument_list_t *argument_list)
|
|
|
|
{
|
2011-11-18 14:05:33 +01:00
|
|
|
call_expression_t *ret = new_expression(ctx, EXPR_CALL, sizeof(*ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->expression = expression;
|
|
|
|
ret->argument_list = argument_list ? argument_list->head : NULL;
|
|
|
|
|
|
|
|
return &ret->expr;
|
|
|
|
}
|
|
|
|
|
2020-01-23 13:52:15 +01:00
|
|
|
static int parser_error(unsigned *loc, parser_ctx_t *ctx, const char *str)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
2020-02-03 14:47:39 +01:00
|
|
|
if(ctx->error_loc == -1)
|
|
|
|
ctx->error_loc = *loc;
|
2020-01-23 13:52:22 +01:00
|
|
|
if(ctx->hres == S_OK)
|
|
|
|
ctx->hres = JS_E_SYNTAX;
|
|
|
|
WARN("%s: %s\n", debugstr_w(ctx->begin + *loc), str);
|
2008-09-03 00:25:21 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-03 14:47:39 +01:00
|
|
|
static void set_error(parser_ctx_t *ctx, unsigned loc, HRESULT error)
|
2009-07-24 09:36:04 +02:00
|
|
|
{
|
2010-12-28 15:05:13 +01:00
|
|
|
ctx->hres = error;
|
2020-02-03 14:47:39 +01:00
|
|
|
ctx->error_loc = loc;
|
2009-07-24 09:36:04 +02:00
|
|
|
}
|
|
|
|
|
2009-07-24 09:36:20 +02:00
|
|
|
static BOOL explicit_error(parser_ctx_t *ctx, void *obj, WCHAR next)
|
|
|
|
{
|
|
|
|
if(obj || *(ctx->ptr-1)==next) return TRUE;
|
|
|
|
|
2020-02-03 14:47:39 +01:00
|
|
|
set_error(ctx, ctx->ptr - ctx->begin /* FIXME */, JS_E_SYNTAX);
|
2009-07-24 09:36:20 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-07-24 09:36:04 +02:00
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
static expression_t *new_identifier_expression(parser_ctx_t *ctx, const WCHAR *identifier)
|
|
|
|
{
|
2011-11-18 14:05:33 +01:00
|
|
|
identifier_expression_t *ret = new_expression(ctx, EXPR_IDENT, sizeof(*ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->identifier = identifier;
|
|
|
|
|
|
|
|
return &ret->expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static expression_t *new_array_literal_expression(parser_ctx_t *ctx, element_list_t *element_list, int length)
|
|
|
|
{
|
2011-11-18 14:05:33 +01:00
|
|
|
array_literal_expression_t *ret = new_expression(ctx, EXPR_ARRAYLIT, sizeof(*ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->element_list = element_list ? element_list->head : NULL;
|
|
|
|
ret->length = length;
|
|
|
|
|
|
|
|
return &ret->expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static expression_t *new_prop_and_value_expression(parser_ctx_t *ctx, property_list_t *property_list)
|
|
|
|
{
|
2011-11-18 14:05:33 +01:00
|
|
|
property_value_expression_t *ret = new_expression(ctx, EXPR_PROPVAL, sizeof(*ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->property_list = property_list ? property_list->head : NULL;
|
|
|
|
|
|
|
|
return &ret->expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static expression_t *new_literal_expression(parser_ctx_t *ctx, literal_t *literal)
|
|
|
|
{
|
2011-11-18 14:05:33 +01:00
|
|
|
literal_expression_t *ret = new_expression(ctx, EXPR_LITERAL, sizeof(*ret));
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
ret->literal = literal;
|
|
|
|
|
|
|
|
return &ret->expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static source_elements_t *new_source_elements(parser_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
source_elements_t *ret = parser_alloc(ctx, sizeof(source_elements_t));
|
|
|
|
|
|
|
|
memset(ret, 0, sizeof(*ret));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static source_elements_t *source_elements_add_statement(source_elements_t *source_elements, statement_t *statement)
|
|
|
|
{
|
|
|
|
if(source_elements->statement_tail)
|
|
|
|
source_elements->statement_tail = source_elements->statement_tail->next = statement;
|
|
|
|
else
|
|
|
|
source_elements->statement = source_elements->statement_tail = statement;
|
|
|
|
|
|
|
|
return source_elements;
|
|
|
|
}
|
|
|
|
|
2008-12-02 15:26:49 +01:00
|
|
|
static statement_list_t *new_statement_list(parser_ctx_t *ctx, statement_t *statement)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
|
|
|
statement_list_t *ret = parser_alloc_tmp(ctx, sizeof(statement_list_t));
|
|
|
|
|
|
|
|
ret->head = ret->tail = statement;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-12-02 15:26:49 +01:00
|
|
|
static statement_list_t *statement_list_add(statement_list_t *list, statement_t *statement)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
|
|
|
list->tail = list->tail->next = statement;
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
void parser_release(parser_ctx_t *ctx)
|
|
|
|
{
|
2009-12-31 13:03:01 +01:00
|
|
|
script_release(ctx->script);
|
2013-02-15 14:04:14 +01:00
|
|
|
heap_pool_free(&ctx->heap);
|
2008-09-03 00:25:21 +02:00
|
|
|
heap_free(ctx);
|
|
|
|
}
|
|
|
|
|
2020-02-03 14:47:39 +01:00
|
|
|
HRESULT script_parse(script_ctx_t *ctx, struct _compiler_ctx_t *compiler, bytecode_t *code, const WCHAR *delimiter, BOOL from_eval,
|
2009-04-09 23:34:26 +02:00
|
|
|
parser_ctx_t **ret)
|
2008-09-03 00:25:21 +02:00
|
|
|
{
|
|
|
|
parser_ctx_t *parser_ctx;
|
2013-02-15 14:04:14 +01:00
|
|
|
heap_pool_t *mark;
|
2008-09-03 00:25:21 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2009-04-09 23:34:26 +02:00
|
|
|
const WCHAR html_tagW[] = {'<','/','s','c','r','i','p','t','>',0};
|
|
|
|
|
2008-09-03 00:25:21 +02:00
|
|
|
parser_ctx = heap_alloc_zero(sizeof(parser_ctx_t));
|
|
|
|
if(!parser_ctx)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2020-02-03 14:47:39 +01:00
|
|
|
parser_ctx->error_loc = -1;
|
2019-06-06 09:17:49 +02:00
|
|
|
parser_ctx->is_html = delimiter && !wcsicmp(delimiter, html_tagW);
|
2008-09-03 00:25:21 +02:00
|
|
|
|
2020-02-03 14:47:39 +01:00
|
|
|
parser_ctx->begin = parser_ctx->ptr = code->source;
|
2019-06-06 09:17:49 +02:00
|
|
|
parser_ctx->end = parser_ctx->begin + lstrlenW(parser_ctx->begin);
|
2008-09-03 00:25:21 +02:00
|
|
|
|
|
|
|
script_addref(ctx);
|
|
|
|
parser_ctx->script = ctx;
|
|
|
|
|
2013-02-15 14:04:14 +01:00
|
|
|
mark = heap_pool_mark(&ctx->tmp_heap);
|
|
|
|
heap_pool_init(&parser_ctx->heap);
|
2008-09-03 00:26:10 +02:00
|
|
|
|
2019-03-01 17:44:31 +01:00
|
|
|
parser_ctx->compiler = compiler;
|
2008-09-03 00:25:21 +02:00
|
|
|
parser_parse(parser_ctx);
|
2019-03-01 17:44:31 +01:00
|
|
|
parser_ctx->compiler = NULL;
|
|
|
|
|
2013-02-15 14:04:14 +01:00
|
|
|
heap_pool_clear(mark);
|
2012-03-12 19:22:36 +01:00
|
|
|
hres = parser_ctx->hres;
|
|
|
|
if(FAILED(hres)) {
|
2020-02-04 20:28:38 +01:00
|
|
|
const WCHAR *line_start = code->source + parser_ctx->error_loc, *line_end = line_start;
|
|
|
|
jsstr_t *line_str;
|
|
|
|
|
|
|
|
while(line_start > code->source && line_start[-1] != '\n')
|
|
|
|
line_start--;
|
|
|
|
while(*line_end && *line_end != '\n')
|
|
|
|
line_end++;
|
|
|
|
line_str = jsstr_alloc_len(line_start, line_end - line_start);
|
|
|
|
|
|
|
|
WARN("parser failed around %s in line %s\n",
|
|
|
|
debugstr_w(parser_ctx->begin+20 > parser_ctx->ptr ? parser_ctx->begin : parser_ctx->ptr-20),
|
|
|
|
debugstr_jsstr(line_str));
|
2020-02-03 14:47:39 +01:00
|
|
|
|
|
|
|
throw_error(ctx, hres, NULL);
|
2020-02-04 20:28:38 +01:00
|
|
|
set_error_location(ctx->ei, code, parser_ctx->error_loc, IDS_COMPILATION_ERROR, line_str);
|
2008-09-03 00:25:21 +02:00
|
|
|
parser_release(parser_ctx);
|
2020-02-04 20:28:38 +01:00
|
|
|
if(line_str)
|
|
|
|
jsstr_release(line_str);
|
2020-02-03 14:47:39 +01:00
|
|
|
return DISP_E_EXCEPTION;
|
2008-09-03 00:25:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*ret = parser_ctx;
|
|
|
|
return S_OK;
|
|
|
|
}
|