2011-09-06 15:18:40 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2011 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 "vbscript.h"
|
|
|
|
#include "parse.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
|
|
|
|
|
|
|
|
#define YYLEX_PARAM ctx
|
|
|
|
#define YYPARSE_PARAM ctx
|
|
|
|
|
|
|
|
static int parser_error(const char*);
|
|
|
|
|
2011-09-15 14:20:05 +02:00
|
|
|
static void parse_complete(parser_ctx_t*,BOOL);
|
2011-09-06 15:18:40 +02:00
|
|
|
|
2011-09-07 14:08:21 +02:00
|
|
|
static void source_add_statement(parser_ctx_t*,statement_t*);
|
2011-09-15 14:16:47 +02:00
|
|
|
static void source_add_class(parser_ctx_t*,class_decl_t*);
|
2011-09-07 14:08:21 +02:00
|
|
|
|
2011-09-09 14:49:26 +02:00
|
|
|
static void *new_expression(parser_ctx_t*,expression_type_t,size_t);
|
2011-09-08 14:56:36 +02:00
|
|
|
static expression_t *new_bool_expression(parser_ctx_t*,VARIANT_BOOL);
|
2011-09-08 14:56:58 +02:00
|
|
|
static expression_t *new_string_expression(parser_ctx_t*,const WCHAR*);
|
2011-09-12 12:29:59 +02:00
|
|
|
static expression_t *new_long_expression(parser_ctx_t*,expression_type_t,LONG);
|
|
|
|
static expression_t *new_double_expression(parser_ctx_t*,double);
|
2011-09-09 14:47:32 +02:00
|
|
|
static expression_t *new_unary_expression(parser_ctx_t*,expression_type_t,expression_t*);
|
2011-09-09 14:48:13 +02:00
|
|
|
static expression_t *new_binary_expression(parser_ctx_t*,expression_type_t,expression_t*,expression_t*);
|
2011-09-15 14:18:12 +02:00
|
|
|
static expression_t *new_new_expression(parser_ctx_t*,const WCHAR*);
|
2011-09-08 14:56:36 +02:00
|
|
|
|
2011-09-07 14:08:21 +02:00
|
|
|
static member_expression_t *new_member_expression(parser_ctx_t*,expression_t*,const WCHAR*);
|
|
|
|
|
2011-09-14 12:57:27 +02:00
|
|
|
static void *new_statement(parser_ctx_t*,statement_type_t,size_t);
|
2012-07-03 17:04:51 +02:00
|
|
|
static statement_t *new_call_statement(parser_ctx_t*,BOOL,member_expression_t*);
|
2011-09-13 11:36:26 +02:00
|
|
|
static statement_t *new_assign_statement(parser_ctx_t*,member_expression_t*,expression_t*);
|
2011-09-15 14:17:38 +02:00
|
|
|
static statement_t *new_set_statement(parser_ctx_t*,member_expression_t*,expression_t*);
|
2011-09-13 11:36:26 +02:00
|
|
|
static statement_t *new_dim_statement(parser_ctx_t*,dim_decl_t*);
|
2011-09-16 13:29:59 +02:00
|
|
|
static statement_t *new_while_statement(parser_ctx_t*,statement_type_t,expression_t*,statement_t*);
|
2011-09-22 14:22:40 +02:00
|
|
|
static statement_t *new_forto_statement(parser_ctx_t*,const WCHAR*,expression_t*,expression_t*,expression_t*,statement_t*);
|
2012-01-04 11:50:29 +01:00
|
|
|
static statement_t *new_foreach_statement(parser_ctx_t*,const WCHAR*,expression_t*,statement_t*);
|
2011-09-14 12:54:50 +02:00
|
|
|
static statement_t *new_if_statement(parser_ctx_t*,expression_t*,statement_t*,elseif_decl_t*,statement_t*);
|
|
|
|
static statement_t *new_function_statement(parser_ctx_t*,function_decl_t*);
|
2011-09-19 14:10:19 +02:00
|
|
|
static statement_t *new_onerror_statement(parser_ctx_t*,BOOL);
|
2011-09-21 14:03:18 +02:00
|
|
|
static statement_t *new_const_statement(parser_ctx_t*,const_decl_t*);
|
2012-07-20 16:28:32 +02:00
|
|
|
static statement_t *new_select_statement(parser_ctx_t*,expression_t*,case_clausule_t*);
|
2011-09-13 11:36:26 +02:00
|
|
|
|
|
|
|
static dim_decl_t *new_dim_decl(parser_ctx_t*,const WCHAR*,dim_decl_t*);
|
2011-09-13 11:38:04 +02:00
|
|
|
static elseif_decl_t *new_elseif_decl(parser_ctx_t*,expression_t*,statement_t*);
|
2011-09-15 14:20:05 +02:00
|
|
|
static function_decl_t *new_function_decl(parser_ctx_t*,const WCHAR*,function_type_t,unsigned,arg_decl_t*,statement_t*);
|
2011-09-14 12:54:50 +02:00
|
|
|
static arg_decl_t *new_argument_decl(parser_ctx_t*,const WCHAR*,BOOL);
|
2011-09-21 14:03:18 +02:00
|
|
|
static const_decl_t *new_const_decl(parser_ctx_t*,const WCHAR*,expression_t*);
|
2012-07-20 16:28:32 +02:00
|
|
|
static case_clausule_t *new_case_clausule(parser_ctx_t*,expression_t*,statement_t*,case_clausule_t*);
|
2011-09-15 19:04:43 +02:00
|
|
|
|
2011-09-15 14:16:47 +02:00
|
|
|
static class_decl_t *new_class_decl(parser_ctx_t*);
|
2011-09-15 19:04:43 +02:00
|
|
|
static class_decl_t *add_class_function(parser_ctx_t*,class_decl_t*,function_decl_t*);
|
2011-09-16 13:27:11 +02:00
|
|
|
static class_decl_t *add_variant_prop(parser_ctx_t*,class_decl_t*,const WCHAR*,unsigned);
|
2011-09-07 14:08:21 +02:00
|
|
|
|
2011-09-20 14:58:53 +02:00
|
|
|
static statement_t *link_statements(statement_t*,statement_t*);
|
|
|
|
|
2012-04-25 11:26:34 +02:00
|
|
|
static const WCHAR propertyW[] = {'p','r','o','p','e','r','t','y',0};
|
|
|
|
|
2011-09-15 14:20:05 +02:00
|
|
|
#define STORAGE_IS_PRIVATE 1
|
|
|
|
#define STORAGE_IS_DEFAULT 2
|
|
|
|
|
2011-09-08 14:55:35 +02:00
|
|
|
#define CHECK_ERROR if(((parser_ctx_t*)ctx)->hres != S_OK) YYABORT
|
|
|
|
|
2011-09-06 15:18:40 +02:00
|
|
|
%}
|
|
|
|
|
|
|
|
%pure_parser
|
|
|
|
%start Program
|
|
|
|
|
|
|
|
%union {
|
|
|
|
const WCHAR *string;
|
2011-09-07 14:08:21 +02:00
|
|
|
statement_t *statement;
|
2011-09-08 14:55:35 +02:00
|
|
|
expression_t *expression;
|
2011-09-07 14:08:21 +02:00
|
|
|
member_expression_t *member;
|
2011-09-13 11:38:04 +02:00
|
|
|
elseif_decl_t *elseif;
|
2011-09-13 11:36:26 +02:00
|
|
|
dim_decl_t *dim_decl;
|
2011-09-14 12:54:50 +02:00
|
|
|
function_decl_t *func_decl;
|
|
|
|
arg_decl_t *arg_decl;
|
2011-09-15 14:16:47 +02:00
|
|
|
class_decl_t *class_decl;
|
2011-09-21 14:03:18 +02:00
|
|
|
const_decl_t *const_decl;
|
2012-07-20 16:28:32 +02:00
|
|
|
case_clausule_t *case_clausule;
|
2011-09-15 14:20:05 +02:00
|
|
|
unsigned uint;
|
2011-09-12 12:29:59 +02:00
|
|
|
LONG lng;
|
2011-09-09 14:47:00 +02:00
|
|
|
BOOL bool;
|
2011-09-12 12:29:59 +02:00
|
|
|
double dbl;
|
2011-09-06 15:18:40 +02:00
|
|
|
}
|
|
|
|
|
2011-09-09 14:46:46 +02:00
|
|
|
%token tEOF tNL tREM tEMPTYBRACKETS
|
2011-09-08 14:56:18 +02:00
|
|
|
%token tTRUE tFALSE
|
|
|
|
%token tNOT tAND tOR tXOR tEQV tIMP tNEQ
|
|
|
|
%token tIS tLTEQ tGTEQ tMOD
|
2011-09-21 14:03:18 +02:00
|
|
|
%token tCALL tDIM tSUB tFUNCTION tPROPERTY tGET tLET tCONST
|
2011-09-08 14:56:18 +02:00
|
|
|
%token tIF tELSE tELSEIF tEND tTHEN tEXIT
|
2012-01-04 11:50:29 +01:00
|
|
|
%token tWHILE tWEND tDO tLOOP tUNTIL tFOR tTO tSTEP tEACH tIN
|
2012-07-20 16:28:32 +02:00
|
|
|
%token tSELECT tCASE
|
2011-09-08 14:56:18 +02:00
|
|
|
%token tBYREF tBYVAL
|
|
|
|
%token tOPTION tEXPLICIT
|
|
|
|
%token tSTOP
|
|
|
|
%token tNOTHING tEMPTY tNULL
|
|
|
|
%token tCLASS tSET tNEW tPUBLIC tPRIVATE tDEFAULT tME
|
|
|
|
%token tERROR tNEXT tON tRESUME tGOTO
|
2011-09-08 14:56:48 +02:00
|
|
|
%token <string> tIdentifier tString
|
2011-09-12 12:29:43 +02:00
|
|
|
%token <lng> tLong tShort
|
|
|
|
%token <dbl> tDouble
|
2011-09-06 15:18:55 +02:00
|
|
|
|
2011-09-20 14:58:53 +02:00
|
|
|
%type <statement> Statement SimpleStatement StatementNl StatementsNl StatementsNl_opt IfStatement Else_opt
|
2011-09-09 14:48:48 +02:00
|
|
|
%type <expression> Expression LiteralExpression PrimaryExpression EqualityExpression CallExpression
|
2011-09-13 11:40:39 +02:00
|
|
|
%type <expression> ConcatExpression AdditiveExpression ModExpression IntdivExpression MultiplicativeExpression ExpExpression
|
2011-09-14 12:59:49 +02:00
|
|
|
%type <expression> NotExpression UnaryExpression AndExpression OrExpression XorExpression EqvExpression
|
2011-09-07 14:08:21 +02:00
|
|
|
%type <member> MemberExpression
|
2012-07-20 16:28:32 +02:00
|
|
|
%type <expression> Arguments_opt ArgumentList_opt Step_opt ExpressionList
|
2011-09-16 13:30:31 +02:00
|
|
|
%type <bool> OptionExplicit_opt DoType
|
2011-09-14 12:54:50 +02:00
|
|
|
%type <arg_decl> ArgumentsDecl_opt ArgumentDeclList ArgumentDecl
|
2011-09-16 13:28:00 +02:00
|
|
|
%type <func_decl> FunctionDecl PropertyDecl
|
2011-09-13 11:38:04 +02:00
|
|
|
%type <elseif> ElseIfs_opt ElseIfs ElseIf
|
2011-09-15 14:16:47 +02:00
|
|
|
%type <class_decl> ClassDeclaration ClassBody
|
2011-09-15 14:20:05 +02:00
|
|
|
%type <uint> Storage Storage_opt
|
2011-09-13 11:36:26 +02:00
|
|
|
%type <dim_decl> DimDeclList
|
2011-09-21 14:03:18 +02:00
|
|
|
%type <const_decl> ConstDecl ConstDeclList
|
2012-04-25 11:26:34 +02:00
|
|
|
%type <string> Identifier
|
2012-07-20 16:28:32 +02:00
|
|
|
%type <case_clausule> CaseClausules
|
2011-09-07 14:08:21 +02:00
|
|
|
|
2011-09-06 15:18:40 +02:00
|
|
|
%%
|
|
|
|
|
2011-09-07 14:08:21 +02:00
|
|
|
Program
|
2011-09-09 14:47:00 +02:00
|
|
|
: OptionExplicit_opt SourceElements tEOF { parse_complete(ctx, $1); }
|
|
|
|
|
|
|
|
OptionExplicit_opt
|
|
|
|
: /* empty */ { $$ = FALSE; }
|
|
|
|
| tOPTION tEXPLICIT tNL { $$ = TRUE; }
|
2011-09-07 14:08:21 +02:00
|
|
|
|
|
|
|
SourceElements
|
|
|
|
: /* empty */
|
2011-09-15 14:16:47 +02:00
|
|
|
| SourceElements StatementNl { source_add_statement(ctx, $2); }
|
|
|
|
| SourceElements ClassDeclaration { source_add_class(ctx, $2); }
|
2011-09-07 14:08:21 +02:00
|
|
|
|
2011-09-14 12:54:50 +02:00
|
|
|
StatementsNl_opt
|
|
|
|
: /* empty */ { $$ = NULL; }
|
|
|
|
| StatementsNl { $$ = $1; }
|
|
|
|
|
2011-09-13 11:38:04 +02:00
|
|
|
StatementsNl
|
|
|
|
: StatementNl { $$ = $1; }
|
2011-09-20 14:58:53 +02:00
|
|
|
| StatementNl StatementsNl { $$ = link_statements($1, $2); }
|
2011-09-13 11:38:04 +02:00
|
|
|
|
2011-09-07 14:08:21 +02:00
|
|
|
StatementNl
|
|
|
|
: Statement tNL { $$ = $1; }
|
|
|
|
|
|
|
|
Statement
|
2011-09-20 14:58:53 +02:00
|
|
|
: ':' { $$ = NULL; }
|
|
|
|
| ':' Statement { $$ = $2; }
|
|
|
|
| SimpleStatement { $$ = $1; }
|
|
|
|
| SimpleStatement ':' Statement { $1->next = $3; $$ = $1; }
|
|
|
|
| SimpleStatement ':' { $$ = $1; }
|
|
|
|
|
|
|
|
SimpleStatement
|
2012-07-03 17:04:51 +02:00
|
|
|
: MemberExpression ArgumentList_opt { $1->args = $2; $$ = new_call_statement(ctx, FALSE, $1); CHECK_ERROR; }
|
|
|
|
| tCALL MemberExpression Arguments_opt { $2->args = $3; $$ = new_call_statement(ctx, TRUE, $2); CHECK_ERROR; }
|
2011-09-12 12:32:38 +02:00
|
|
|
| MemberExpression Arguments_opt '=' Expression
|
|
|
|
{ $1->args = $2; $$ = new_assign_statement(ctx, $1, $4); CHECK_ERROR; }
|
2011-09-13 11:36:26 +02:00
|
|
|
| tDIM DimDeclList { $$ = new_dim_statement(ctx, $2); CHECK_ERROR; }
|
2011-09-13 11:38:04 +02:00
|
|
|
| IfStatement { $$ = $1; }
|
2011-09-16 13:29:59 +02:00
|
|
|
| tWHILE Expression tNL StatementsNl_opt tWEND
|
|
|
|
{ $$ = new_while_statement(ctx, STAT_WHILE, $2, $4); CHECK_ERROR; }
|
2011-09-16 13:30:31 +02:00
|
|
|
| tDO DoType Expression tNL StatementsNl_opt tLOOP
|
|
|
|
{ $$ = new_while_statement(ctx, $2 ? STAT_WHILELOOP : STAT_UNTIL, $3, $5);
|
|
|
|
CHECK_ERROR; }
|
2011-09-16 13:30:39 +02:00
|
|
|
| tDO tNL StatementsNl_opt tLOOP DoType Expression
|
|
|
|
{ $$ = new_while_statement(ctx, $5 ? STAT_DOWHILE : STAT_DOUNTIL, $6, $3);
|
|
|
|
CHECK_ERROR; }
|
2011-09-14 12:54:50 +02:00
|
|
|
| FunctionDecl { $$ = new_function_statement(ctx, $1); CHECK_ERROR; }
|
2011-09-16 13:30:20 +02:00
|
|
|
| tEXIT tDO { $$ = new_statement(ctx, STAT_EXITDO, 0); CHECK_ERROR; }
|
2011-09-22 14:24:44 +02:00
|
|
|
| tEXIT tFOR { $$ = new_statement(ctx, STAT_EXITFOR, 0); CHECK_ERROR; }
|
2011-09-14 12:58:10 +02:00
|
|
|
| tEXIT tFUNCTION { $$ = new_statement(ctx, STAT_EXITFUNC, 0); CHECK_ERROR; }
|
2011-09-16 13:28:29 +02:00
|
|
|
| tEXIT tPROPERTY { $$ = new_statement(ctx, STAT_EXITPROP, 0); CHECK_ERROR; }
|
2011-09-14 12:57:27 +02:00
|
|
|
| tEXIT tSUB { $$ = new_statement(ctx, STAT_EXITSUB, 0); CHECK_ERROR; }
|
2011-09-15 14:17:38 +02:00
|
|
|
| tSET MemberExpression Arguments_opt '=' Expression
|
|
|
|
{ $2->args = $3; $$ = new_set_statement(ctx, $2, $5); CHECK_ERROR; }
|
2011-09-15 14:22:27 +02:00
|
|
|
| tSTOP { $$ = new_statement(ctx, STAT_STOP, 0); CHECK_ERROR; }
|
2011-09-19 14:10:19 +02:00
|
|
|
| tON tERROR tRESUME tNEXT { $$ = new_onerror_statement(ctx, TRUE); CHECK_ERROR; }
|
|
|
|
| tON tERROR tGOTO '0' { $$ = new_onerror_statement(ctx, FALSE); CHECK_ERROR; }
|
2011-09-21 14:03:18 +02:00
|
|
|
| tCONST ConstDeclList { $$ = new_const_statement(ctx, $2); CHECK_ERROR; }
|
2012-04-25 11:26:34 +02:00
|
|
|
| tFOR Identifier '=' Expression tTO Expression Step_opt tNL StatementsNl_opt tNEXT
|
2011-09-22 14:22:40 +02:00
|
|
|
{ $$ = new_forto_statement(ctx, $2, $4, $6, $7, $9); CHECK_ERROR; }
|
2012-04-25 11:26:34 +02:00
|
|
|
| tFOR tEACH Identifier tIN Expression tNL StatementsNl_opt tNEXT
|
2012-01-04 11:50:29 +01:00
|
|
|
{ $$ = new_foreach_statement(ctx, $3, $5, $7); }
|
2012-07-20 16:28:32 +02:00
|
|
|
| tSELECT tCASE Expression tNL CaseClausules tEND tSELECT
|
|
|
|
{ $$ = new_select_statement(ctx, $3, $5); }
|
2011-09-07 14:08:21 +02:00
|
|
|
|
|
|
|
MemberExpression
|
2012-04-25 11:26:34 +02:00
|
|
|
: Identifier { $$ = new_member_expression(ctx, NULL, $1); CHECK_ERROR; }
|
|
|
|
| CallExpression '.' Identifier { $$ = new_member_expression(ctx, $1, $3); CHECK_ERROR; }
|
2011-09-06 15:18:40 +02:00
|
|
|
|
2011-09-13 11:36:26 +02:00
|
|
|
DimDeclList /* FIXME: Support arrays */
|
2012-04-25 11:26:34 +02:00
|
|
|
: Identifier { $$ = new_dim_decl(ctx, $1, NULL); CHECK_ERROR; }
|
|
|
|
| Identifier ',' DimDeclList { $$ = new_dim_decl(ctx, $1, $3); CHECK_ERROR; }
|
2011-09-13 11:36:26 +02:00
|
|
|
|
2011-09-21 14:03:18 +02:00
|
|
|
ConstDeclList
|
|
|
|
: ConstDecl { $$ = $1; }
|
|
|
|
| ConstDecl ',' ConstDeclList { $1->next = $3; $$ = $1; }
|
|
|
|
|
|
|
|
ConstDecl
|
2012-04-25 11:26:34 +02:00
|
|
|
: Identifier '=' LiteralExpression { $$ = new_const_decl(ctx, $1, $3); CHECK_ERROR; }
|
2011-09-21 14:03:18 +02:00
|
|
|
|
2011-09-16 13:30:31 +02:00
|
|
|
DoType
|
|
|
|
: tWHILE { $$ = TRUE; }
|
|
|
|
| tUNTIL { $$ = FALSE; }
|
|
|
|
|
2011-09-22 14:22:40 +02:00
|
|
|
Step_opt
|
|
|
|
: /* empty */ { $$ = NULL;}
|
|
|
|
| tSTEP Expression { $$ = $2; }
|
|
|
|
|
2011-09-13 11:38:04 +02:00
|
|
|
IfStatement
|
|
|
|
: tIF Expression tTHEN tNL StatementsNl ElseIfs_opt Else_opt tEND tIF
|
|
|
|
{ $$ = new_if_statement(ctx, $2, $5, $6, $7); CHECK_ERROR; }
|
2011-09-20 14:59:21 +02:00
|
|
|
| tIF Expression tTHEN Statement { $$ = new_if_statement(ctx, $2, $4, NULL, NULL); CHECK_ERROR; }
|
2012-04-13 17:40:40 +02:00
|
|
|
| tIF Expression tTHEN Statement tELSE Statement EndIf_opt
|
2011-09-20 14:59:21 +02:00
|
|
|
{ $$ = new_if_statement(ctx, $2, $4, NULL, $6); CHECK_ERROR; }
|
2011-09-13 11:38:04 +02:00
|
|
|
|
2012-04-13 17:40:40 +02:00
|
|
|
EndIf_opt
|
|
|
|
: /* empty */
|
|
|
|
| tEND tIF
|
|
|
|
|
2011-09-13 11:38:04 +02:00
|
|
|
ElseIfs_opt
|
|
|
|
: /* empty */ { $$ = NULL; }
|
|
|
|
| ElseIfs { $$ = $1; }
|
|
|
|
|
|
|
|
ElseIfs
|
|
|
|
: ElseIf { $$ = $1; }
|
|
|
|
| ElseIf ElseIfs { $1->next = $2; $$ = $1; }
|
|
|
|
|
|
|
|
ElseIf
|
|
|
|
: tELSEIF Expression tTHEN tNL StatementsNl
|
|
|
|
{ $$ = new_elseif_decl(ctx, $2, $5); }
|
|
|
|
|
|
|
|
Else_opt
|
|
|
|
: /* empty */ { $$ = NULL; }
|
|
|
|
| tELSE tNL StatementsNl { $$ = $3; }
|
|
|
|
|
2012-07-20 16:28:32 +02:00
|
|
|
CaseClausules
|
|
|
|
: /* empty */ { $$ = NULL; }
|
|
|
|
| tCASE tELSE tNL StatementsNl { $$ = new_case_clausule(ctx, NULL, $4, NULL); }
|
|
|
|
| tCASE ExpressionList tNL StatementsNl_opt CaseClausules
|
|
|
|
{ $$ = new_case_clausule(ctx, $2, $4, $5); }
|
|
|
|
|
2011-09-08 14:55:35 +02:00
|
|
|
Arguments_opt
|
2011-09-09 14:46:46 +02:00
|
|
|
: EmptyBrackets_opt { $$ = NULL; }
|
2012-07-20 16:28:32 +02:00
|
|
|
| '(' ExpressionList ')' { $$ = $2; }
|
2011-09-08 14:55:35 +02:00
|
|
|
|
|
|
|
ArgumentList_opt
|
2011-09-09 14:46:46 +02:00
|
|
|
: EmptyBrackets_opt { $$ = NULL; }
|
2012-07-20 16:28:32 +02:00
|
|
|
| ExpressionList { $$ = $1; }
|
2011-09-08 14:56:36 +02:00
|
|
|
|
2011-09-09 14:46:46 +02:00
|
|
|
EmptyBrackets_opt
|
|
|
|
: /* empty */
|
|
|
|
| tEMPTYBRACKETS
|
|
|
|
|
2012-07-20 16:28:32 +02:00
|
|
|
ExpressionList
|
|
|
|
: Expression { $$ = $1; }
|
|
|
|
| Expression ',' ExpressionList { $1->next = $3; $$ = $1; }
|
|
|
|
|
2011-09-08 14:56:36 +02:00
|
|
|
Expression
|
2011-09-14 12:59:49 +02:00
|
|
|
: EqvExpression { $$ = $1; }
|
|
|
|
| Expression tIMP EqvExpression { $$ = new_binary_expression(ctx, EXPR_IMP, $1, $3); CHECK_ERROR; }
|
|
|
|
|
|
|
|
EqvExpression
|
|
|
|
: XorExpression { $$ = $1; }
|
|
|
|
| EqvExpression tEQV XorExpression { $$ = new_binary_expression(ctx, EXPR_EQV, $1, $3); CHECK_ERROR; }
|
|
|
|
|
|
|
|
XorExpression
|
2011-09-14 12:59:26 +02:00
|
|
|
: OrExpression { $$ = $1; }
|
2011-09-14 12:59:49 +02:00
|
|
|
| XorExpression tXOR OrExpression { $$ = new_binary_expression(ctx, EXPR_XOR, $1, $3); CHECK_ERROR; }
|
2011-09-14 12:59:26 +02:00
|
|
|
|
|
|
|
OrExpression
|
2011-09-14 12:59:02 +02:00
|
|
|
: AndExpression { $$ = $1; }
|
2011-09-14 12:59:26 +02:00
|
|
|
| OrExpression tOR AndExpression { $$ = new_binary_expression(ctx, EXPR_OR, $1, $3); CHECK_ERROR; }
|
2011-09-14 12:59:02 +02:00
|
|
|
|
|
|
|
AndExpression
|
|
|
|
: NotExpression { $$ = $1; }
|
|
|
|
| AndExpression tAND NotExpression { $$ = new_binary_expression(ctx, EXPR_AND, $1, $3); CHECK_ERROR; }
|
2011-09-09 14:47:32 +02:00
|
|
|
|
|
|
|
NotExpression
|
2011-09-09 14:48:13 +02:00
|
|
|
: EqualityExpression { $$ = $1; }
|
|
|
|
| tNOT NotExpression { $$ = new_unary_expression(ctx, EXPR_NOT, $2); CHECK_ERROR; }
|
|
|
|
|
|
|
|
EqualityExpression
|
|
|
|
: ConcatExpression { $$ = $1; }
|
|
|
|
| EqualityExpression '=' ConcatExpression { $$ = new_binary_expression(ctx, EXPR_EQUAL, $1, $3); CHECK_ERROR; }
|
2011-09-12 12:32:27 +02:00
|
|
|
| EqualityExpression tNEQ ConcatExpression { $$ = new_binary_expression(ctx, EXPR_NEQUAL, $1, $3); CHECK_ERROR; }
|
2011-09-19 14:07:12 +02:00
|
|
|
| EqualityExpression '>' ConcatExpression { $$ = new_binary_expression(ctx, EXPR_GT, $1, $3); CHECK_ERROR; }
|
|
|
|
| EqualityExpression '<' ConcatExpression { $$ = new_binary_expression(ctx, EXPR_LT, $1, $3); CHECK_ERROR; }
|
|
|
|
| EqualityExpression tGTEQ ConcatExpression { $$ = new_binary_expression(ctx, EXPR_GTEQ, $1, $3); CHECK_ERROR; }
|
|
|
|
| EqualityExpression tLTEQ ConcatExpression { $$ = new_binary_expression(ctx, EXPR_LTEQ, $1, $3); CHECK_ERROR; }
|
2011-09-19 14:08:02 +02:00
|
|
|
| EqualityExpression tIS ConcatExpression { $$ = new_binary_expression(ctx, EXPR_IS, $1, $3); CHECK_ERROR; }
|
2011-09-09 14:48:13 +02:00
|
|
|
|
|
|
|
ConcatExpression
|
2011-09-12 12:30:47 +02:00
|
|
|
: AdditiveExpression { $$ = $1; }
|
|
|
|
| ConcatExpression '&' AdditiveExpression { $$ = new_binary_expression(ctx, EXPR_CONCAT, $1, $3); CHECK_ERROR; }
|
|
|
|
|
|
|
|
AdditiveExpression
|
2011-09-12 12:31:58 +02:00
|
|
|
: ModExpression { $$ = $1; }
|
|
|
|
| AdditiveExpression '+' ModExpression { $$ = new_binary_expression(ctx, EXPR_ADD, $1, $3); CHECK_ERROR; }
|
|
|
|
| AdditiveExpression '-' ModExpression { $$ = new_binary_expression(ctx, EXPR_SUB, $1, $3); CHECK_ERROR; }
|
|
|
|
|
|
|
|
ModExpression
|
2011-09-13 11:39:53 +02:00
|
|
|
: IntdivExpression { $$ = $1; }
|
|
|
|
| ModExpression tMOD IntdivExpression { $$ = new_binary_expression(ctx, EXPR_MOD, $1, $3); CHECK_ERROR; }
|
|
|
|
|
|
|
|
IntdivExpression
|
2011-09-13 11:40:14 +02:00
|
|
|
: MultiplicativeExpression { $$ = $1; }
|
|
|
|
| IntdivExpression '\\' MultiplicativeExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_IDIV, $1, $3); CHECK_ERROR; }
|
2011-09-12 12:31:37 +02:00
|
|
|
|
2011-09-13 11:40:14 +02:00
|
|
|
MultiplicativeExpression
|
2011-09-13 11:40:39 +02:00
|
|
|
: ExpExpression { $$ = $1; }
|
|
|
|
| MultiplicativeExpression '*' ExpExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_MUL, $1, $3); CHECK_ERROR; }
|
|
|
|
| MultiplicativeExpression '/' ExpExpression
|
|
|
|
{ $$ = new_binary_expression(ctx, EXPR_DIV, $1, $3); CHECK_ERROR; }
|
|
|
|
|
|
|
|
ExpExpression
|
2011-09-13 11:41:15 +02:00
|
|
|
: UnaryExpression { $$ = $1; }
|
|
|
|
| ExpExpression '^' UnaryExpression { $$ = new_binary_expression(ctx, EXPR_EXP, $1, $3); CHECK_ERROR; }
|
2011-09-12 12:31:37 +02:00
|
|
|
|
|
|
|
UnaryExpression
|
|
|
|
: LiteralExpression { $$ = $1; }
|
|
|
|
| CallExpression { $$ = $1; }
|
2012-04-25 11:26:34 +02:00
|
|
|
| tNEW Identifier { $$ = new_new_expression(ctx, $2); CHECK_ERROR; }
|
2011-09-12 12:31:37 +02:00
|
|
|
| '-' UnaryExpression { $$ = new_unary_expression(ctx, EXPR_NEG, $2); CHECK_ERROR; }
|
2011-09-09 14:48:48 +02:00
|
|
|
|
|
|
|
CallExpression
|
|
|
|
: PrimaryExpression { $$ = $1; }
|
|
|
|
| MemberExpression Arguments_opt { $1->args = $2; $$ = &$1->expr; }
|
2011-09-08 14:56:36 +02:00
|
|
|
|
|
|
|
LiteralExpression
|
|
|
|
: tTRUE { $$ = new_bool_expression(ctx, VARIANT_TRUE); CHECK_ERROR; }
|
|
|
|
| tFALSE { $$ = new_bool_expression(ctx, VARIANT_FALSE); CHECK_ERROR; }
|
2011-09-08 14:56:58 +02:00
|
|
|
| tString { $$ = new_string_expression(ctx, $1); CHECK_ERROR; }
|
2011-09-12 12:29:59 +02:00
|
|
|
| tShort { $$ = new_long_expression(ctx, EXPR_USHORT, $1); CHECK_ERROR; }
|
|
|
|
| '0' { $$ = new_long_expression(ctx, EXPR_USHORT, 0); CHECK_ERROR; }
|
|
|
|
| tLong { $$ = new_long_expression(ctx, EXPR_ULONG, $1); CHECK_ERROR; }
|
|
|
|
| tDouble { $$ = new_double_expression(ctx, $1); CHECK_ERROR; }
|
2011-09-09 14:49:26 +02:00
|
|
|
| tEMPTY { $$ = new_expression(ctx, EXPR_EMPTY, 0); CHECK_ERROR; }
|
2011-09-09 14:49:36 +02:00
|
|
|
| tNULL { $$ = new_expression(ctx, EXPR_NULL, 0); CHECK_ERROR; }
|
2011-09-15 14:18:56 +02:00
|
|
|
| tNOTHING { $$ = new_expression(ctx, EXPR_NOTHING, 0); CHECK_ERROR; }
|
2011-09-08 14:55:35 +02:00
|
|
|
|
2011-09-09 14:47:21 +02:00
|
|
|
PrimaryExpression
|
2012-07-03 17:04:51 +02:00
|
|
|
: '(' Expression ')' { $$ = new_unary_expression(ctx, EXPR_BRACKETS, $2); }
|
2011-09-19 14:09:57 +02:00
|
|
|
| tME { $$ = new_expression(ctx, EXPR_ME, 0); CHECK_ERROR; }
|
2011-09-09 14:47:21 +02:00
|
|
|
|
2011-09-15 14:16:47 +02:00
|
|
|
ClassDeclaration
|
2012-04-25 11:26:34 +02:00
|
|
|
: tCLASS Identifier tNL ClassBody tEND tCLASS tNL { $4->name = $2; $$ = $4; }
|
2011-09-15 14:16:47 +02:00
|
|
|
|
|
|
|
ClassBody
|
|
|
|
: /* empty */ { $$ = new_class_decl(ctx); }
|
2011-09-15 19:04:43 +02:00
|
|
|
| FunctionDecl tNL ClassBody { $$ = add_class_function(ctx, $3, $1); CHECK_ERROR; }
|
2011-09-16 13:27:11 +02:00
|
|
|
| Storage tIdentifier tNL ClassBody { $$ = add_variant_prop(ctx, $4, $2, $1); CHECK_ERROR; }
|
2011-09-16 13:28:00 +02:00
|
|
|
| PropertyDecl tNL ClassBody { $$ = add_class_function(ctx, $3, $1); CHECK_ERROR; }
|
|
|
|
|
|
|
|
PropertyDecl
|
|
|
|
: Storage_opt tPROPERTY tGET tIdentifier EmptyBrackets_opt tNL StatementsNl_opt tEND tPROPERTY
|
|
|
|
{ $$ = new_function_decl(ctx, $4, FUNC_PROPGET, $1, NULL, $7); CHECK_ERROR; }
|
|
|
|
| Storage_opt tPROPERTY tLET tIdentifier '(' ArgumentDecl ')' tNL StatementsNl_opt tEND tPROPERTY
|
|
|
|
{ $$ = new_function_decl(ctx, $4, FUNC_PROPLET, $1, $6, $9); CHECK_ERROR; }
|
|
|
|
| Storage_opt tPROPERTY tSET tIdentifier '(' ArgumentDecl ')' tNL StatementsNl_opt tEND tPROPERTY
|
|
|
|
{ $$ = new_function_decl(ctx, $4, FUNC_PROPSET, $1, $6, $9); CHECK_ERROR; }
|
2011-09-15 14:16:47 +02:00
|
|
|
|
2011-09-14 12:54:50 +02:00
|
|
|
FunctionDecl
|
2012-04-25 11:26:34 +02:00
|
|
|
: Storage_opt tSUB Identifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tSUB
|
2011-09-15 14:20:05 +02:00
|
|
|
{ $$ = new_function_decl(ctx, $3, FUNC_SUB, $1, $4, $6); CHECK_ERROR; }
|
2012-04-25 11:26:34 +02:00
|
|
|
| Storage_opt tFUNCTION Identifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tFUNCTION
|
2011-09-15 14:20:05 +02:00
|
|
|
{ $$ = new_function_decl(ctx, $3, FUNC_FUNCTION, $1, $4, $6); CHECK_ERROR; }
|
|
|
|
|
|
|
|
Storage_opt
|
|
|
|
: /* empty*/ { $$ = 0; }
|
|
|
|
| Storage { $$ = $1; }
|
|
|
|
|
|
|
|
Storage
|
|
|
|
: tPUBLIC tDEFAULT { $$ = STORAGE_IS_DEFAULT; }
|
|
|
|
| tPUBLIC { $$ = 0; }
|
|
|
|
| tPRIVATE { $$ = STORAGE_IS_PRIVATE; }
|
2011-09-14 12:54:50 +02:00
|
|
|
|
|
|
|
ArgumentsDecl_opt
|
|
|
|
: EmptyBrackets_opt { $$ = NULL; }
|
|
|
|
| '(' ArgumentDeclList ')' { $$ = $2; }
|
|
|
|
|
|
|
|
ArgumentDeclList
|
|
|
|
: ArgumentDecl { $$ = $1; }
|
|
|
|
| ArgumentDecl ',' ArgumentDeclList { $1->next = $3; $$ = $1; }
|
|
|
|
|
|
|
|
ArgumentDecl
|
2012-04-25 11:26:34 +02:00
|
|
|
: Identifier { $$ = new_argument_decl(ctx, $1, TRUE); }
|
|
|
|
| tBYREF Identifier { $$ = new_argument_decl(ctx, $2, TRUE); }
|
|
|
|
| tBYVAL Identifier { $$ = new_argument_decl(ctx, $2, FALSE); }
|
|
|
|
|
|
|
|
/* 'property' may be both keyword and identifier, depending on context */
|
|
|
|
Identifier
|
|
|
|
: tIdentifier { $$ = $1; }
|
|
|
|
| tPROPERTY { $$ = propertyW; }
|
2011-09-06 15:18:40 +02:00
|
|
|
%%
|
|
|
|
|
|
|
|
static int parser_error(const char *str)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-07 14:08:21 +02:00
|
|
|
static void source_add_statement(parser_ctx_t *ctx, statement_t *stat)
|
|
|
|
{
|
2011-09-20 14:58:53 +02:00
|
|
|
if(!stat)
|
|
|
|
return;
|
|
|
|
|
2011-09-07 14:08:21 +02:00
|
|
|
if(ctx->stats) {
|
|
|
|
ctx->stats_tail->next = stat;
|
|
|
|
ctx->stats_tail = stat;
|
|
|
|
}else {
|
|
|
|
ctx->stats = ctx->stats_tail = stat;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-15 14:16:47 +02:00
|
|
|
static void source_add_class(parser_ctx_t *ctx, class_decl_t *class_decl)
|
|
|
|
{
|
|
|
|
class_decl->next = ctx->class_decls;
|
|
|
|
ctx->class_decls = class_decl;
|
|
|
|
}
|
|
|
|
|
2011-09-09 14:47:00 +02:00
|
|
|
static void parse_complete(parser_ctx_t *ctx, BOOL option_explicit)
|
2011-09-06 15:18:40 +02:00
|
|
|
{
|
|
|
|
ctx->parse_complete = TRUE;
|
2011-09-09 14:47:00 +02:00
|
|
|
ctx->option_explicit = option_explicit;
|
2011-09-06 15:18:40 +02:00
|
|
|
}
|
|
|
|
|
2011-09-09 14:49:26 +02:00
|
|
|
static void *new_expression(parser_ctx_t *ctx, expression_type_t type, size_t size)
|
2011-09-07 14:08:21 +02:00
|
|
|
{
|
|
|
|
expression_t *expr;
|
|
|
|
|
|
|
|
expr = parser_alloc(ctx, size ? size : sizeof(*expr));
|
|
|
|
if(expr) {
|
|
|
|
expr->type = type;
|
|
|
|
expr->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return expr;
|
|
|
|
}
|
|
|
|
|
2011-09-08 14:56:36 +02:00
|
|
|
static expression_t *new_bool_expression(parser_ctx_t *ctx, VARIANT_BOOL value)
|
|
|
|
{
|
|
|
|
bool_expression_t *expr;
|
|
|
|
|
|
|
|
expr = new_expression(ctx, EXPR_BOOL, sizeof(*expr));
|
|
|
|
if(!expr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
expr->value = value;
|
|
|
|
return &expr->expr;
|
|
|
|
}
|
|
|
|
|
2011-09-08 14:56:58 +02:00
|
|
|
static expression_t *new_string_expression(parser_ctx_t *ctx, const WCHAR *value)
|
|
|
|
{
|
|
|
|
string_expression_t *expr;
|
|
|
|
|
|
|
|
expr = new_expression(ctx, EXPR_STRING, sizeof(*expr));
|
|
|
|
if(!expr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
expr->value = value;
|
|
|
|
return &expr->expr;
|
|
|
|
}
|
|
|
|
|
2011-09-12 12:29:59 +02:00
|
|
|
static expression_t *new_long_expression(parser_ctx_t *ctx, expression_type_t type, LONG value)
|
|
|
|
{
|
|
|
|
int_expression_t *expr;
|
|
|
|
|
|
|
|
expr = new_expression(ctx, type, sizeof(*expr));
|
|
|
|
if(!expr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
expr->value = value;
|
|
|
|
return &expr->expr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static expression_t *new_double_expression(parser_ctx_t *ctx, double value)
|
|
|
|
{
|
|
|
|
double_expression_t *expr;
|
|
|
|
|
|
|
|
expr = new_expression(ctx, EXPR_DOUBLE, sizeof(*expr));
|
|
|
|
if(!expr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
expr->value = value;
|
|
|
|
return &expr->expr;
|
|
|
|
}
|
|
|
|
|
2011-09-09 14:47:32 +02:00
|
|
|
static expression_t *new_unary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *subexpr)
|
|
|
|
{
|
|
|
|
unary_expression_t *expr;
|
|
|
|
|
|
|
|
expr = new_expression(ctx, type, sizeof(*expr));
|
|
|
|
if(!expr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
expr->subexpr = subexpr;
|
|
|
|
return &expr->expr;
|
|
|
|
}
|
|
|
|
|
2011-09-09 14:48:13 +02:00
|
|
|
static expression_t *new_binary_expression(parser_ctx_t *ctx, expression_type_t type, expression_t *left, expression_t *right)
|
|
|
|
{
|
|
|
|
binary_expression_t *expr;
|
|
|
|
|
|
|
|
expr = new_expression(ctx, type, sizeof(*expr));
|
|
|
|
if(!expr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
expr->left = left;
|
|
|
|
expr->right = right;
|
|
|
|
return &expr->expr;
|
|
|
|
}
|
|
|
|
|
2011-09-07 14:08:21 +02:00
|
|
|
static member_expression_t *new_member_expression(parser_ctx_t *ctx, expression_t *obj_expr, const WCHAR *identifier)
|
|
|
|
{
|
|
|
|
member_expression_t *expr;
|
|
|
|
|
|
|
|
expr = new_expression(ctx, EXPR_MEMBER, sizeof(*expr));
|
|
|
|
if(!expr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
expr->obj_expr = obj_expr;
|
|
|
|
expr->identifier = identifier;
|
|
|
|
expr->args = NULL;
|
|
|
|
return expr;
|
|
|
|
}
|
|
|
|
|
2011-09-15 14:18:12 +02:00
|
|
|
static expression_t *new_new_expression(parser_ctx_t *ctx, const WCHAR *identifier)
|
|
|
|
{
|
|
|
|
string_expression_t *expr;
|
|
|
|
|
|
|
|
expr = new_expression(ctx, EXPR_NEW, sizeof(*expr));
|
|
|
|
if(!expr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
expr->value = identifier;
|
|
|
|
return &expr->expr;
|
|
|
|
}
|
|
|
|
|
2011-09-14 12:57:27 +02:00
|
|
|
static void *new_statement(parser_ctx_t *ctx, statement_type_t type, size_t size)
|
2011-09-07 14:08:21 +02:00
|
|
|
{
|
|
|
|
statement_t *stat;
|
|
|
|
|
2011-09-14 12:57:27 +02:00
|
|
|
stat = parser_alloc(ctx, size ? size : sizeof(*stat));
|
2011-09-07 14:08:21 +02:00
|
|
|
if(stat) {
|
|
|
|
stat->type = type;
|
|
|
|
stat->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2012-07-03 17:04:51 +02:00
|
|
|
static statement_t *new_call_statement(parser_ctx_t *ctx, BOOL is_strict, member_expression_t *expr)
|
2011-09-07 14:08:21 +02:00
|
|
|
{
|
|
|
|
call_statement_t *stat;
|
|
|
|
|
|
|
|
stat = new_statement(ctx, STAT_CALL, sizeof(*stat));
|
|
|
|
if(!stat)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stat->expr = expr;
|
2012-07-03 17:04:51 +02:00
|
|
|
stat->is_strict = is_strict;
|
2011-09-07 14:08:21 +02:00
|
|
|
return &stat->stat;
|
|
|
|
}
|
|
|
|
|
2011-09-12 12:32:38 +02:00
|
|
|
static statement_t *new_assign_statement(parser_ctx_t *ctx, member_expression_t *left, expression_t *right)
|
|
|
|
{
|
|
|
|
assign_statement_t *stat;
|
|
|
|
|
|
|
|
stat = new_statement(ctx, STAT_ASSIGN, sizeof(*stat));
|
|
|
|
if(!stat)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stat->member_expr = left;
|
|
|
|
stat->value_expr = right;
|
|
|
|
return &stat->stat;
|
|
|
|
}
|
|
|
|
|
2011-09-15 14:17:38 +02:00
|
|
|
static statement_t *new_set_statement(parser_ctx_t *ctx, member_expression_t *left, expression_t *right)
|
|
|
|
{
|
|
|
|
assign_statement_t *stat;
|
|
|
|
|
|
|
|
stat = new_statement(ctx, STAT_SET, sizeof(*stat));
|
|
|
|
if(!stat)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stat->member_expr = left;
|
|
|
|
stat->value_expr = right;
|
|
|
|
return &stat->stat;
|
|
|
|
}
|
|
|
|
|
2011-09-13 11:36:26 +02:00
|
|
|
static dim_decl_t *new_dim_decl(parser_ctx_t *ctx, const WCHAR *name, dim_decl_t *next)
|
|
|
|
{
|
|
|
|
dim_decl_t *decl;
|
|
|
|
|
|
|
|
decl = parser_alloc(ctx, sizeof(*decl));
|
|
|
|
if(!decl)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
decl->name = name;
|
|
|
|
decl->next = next;
|
|
|
|
return decl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static statement_t *new_dim_statement(parser_ctx_t *ctx, dim_decl_t *decls)
|
|
|
|
{
|
|
|
|
dim_statement_t *stat;
|
|
|
|
|
|
|
|
stat = new_statement(ctx, STAT_DIM, sizeof(*stat));
|
|
|
|
if(!stat)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stat->dim_decls = decls;
|
|
|
|
return &stat->stat;
|
|
|
|
}
|
|
|
|
|
2011-09-13 11:38:04 +02:00
|
|
|
static elseif_decl_t *new_elseif_decl(parser_ctx_t *ctx, expression_t *expr, statement_t *stat)
|
|
|
|
{
|
|
|
|
elseif_decl_t *decl;
|
|
|
|
|
|
|
|
decl = parser_alloc(ctx, sizeof(*decl));
|
|
|
|
if(!decl)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
decl->expr = expr;
|
|
|
|
decl->stat = stat;
|
|
|
|
decl->next = NULL;
|
|
|
|
return decl;
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:29:59 +02:00
|
|
|
static statement_t *new_while_statement(parser_ctx_t *ctx, statement_type_t type, expression_t *expr, statement_t *body)
|
|
|
|
{
|
|
|
|
while_statement_t *stat;
|
|
|
|
|
|
|
|
stat = new_statement(ctx, type, sizeof(*stat));
|
|
|
|
if(!stat)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stat->expr = expr;
|
|
|
|
stat->body = body;
|
|
|
|
return &stat->stat;
|
|
|
|
}
|
|
|
|
|
2011-09-22 14:22:40 +02:00
|
|
|
static statement_t *new_forto_statement(parser_ctx_t *ctx, const WCHAR *identifier, expression_t *from_expr,
|
|
|
|
expression_t *to_expr, expression_t *step_expr, statement_t *body)
|
|
|
|
{
|
|
|
|
forto_statement_t *stat;
|
|
|
|
|
|
|
|
stat = new_statement(ctx, STAT_FORTO, sizeof(*stat));
|
|
|
|
if(!stat)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stat->identifier = identifier;
|
|
|
|
stat->from_expr = from_expr;
|
|
|
|
stat->to_expr = to_expr;
|
|
|
|
stat->step_expr = step_expr;
|
|
|
|
stat->body = body;
|
|
|
|
return &stat->stat;
|
|
|
|
}
|
|
|
|
|
2012-01-04 11:50:29 +01:00
|
|
|
static statement_t *new_foreach_statement(parser_ctx_t *ctx, const WCHAR *identifier, expression_t *group_expr,
|
|
|
|
statement_t *body)
|
|
|
|
{
|
|
|
|
foreach_statement_t *stat;
|
|
|
|
|
|
|
|
stat = new_statement(ctx, STAT_FOREACH, sizeof(*stat));
|
|
|
|
if(!stat)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stat->identifier = identifier;
|
|
|
|
stat->group_expr = group_expr;
|
|
|
|
stat->body = body;
|
|
|
|
return &stat->stat;
|
|
|
|
}
|
|
|
|
|
2011-09-13 11:38:04 +02:00
|
|
|
static statement_t *new_if_statement(parser_ctx_t *ctx, expression_t *expr, statement_t *if_stat, elseif_decl_t *elseif_decl,
|
|
|
|
statement_t *else_stat)
|
|
|
|
{
|
|
|
|
if_statement_t *stat;
|
|
|
|
|
|
|
|
stat = new_statement(ctx, STAT_IF, sizeof(*stat));
|
|
|
|
if(!stat)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stat->expr = expr;
|
|
|
|
stat->if_stat = if_stat;
|
|
|
|
stat->elseifs = elseif_decl;
|
|
|
|
stat->else_stat = else_stat;
|
|
|
|
return &stat->stat;
|
|
|
|
}
|
|
|
|
|
2012-07-20 16:28:32 +02:00
|
|
|
static statement_t *new_select_statement(parser_ctx_t *ctx, expression_t *expr, case_clausule_t *case_clausules)
|
|
|
|
{
|
|
|
|
select_statement_t *stat;
|
|
|
|
|
|
|
|
stat = new_statement(ctx, STAT_SELECT, sizeof(*stat));
|
|
|
|
if(!stat)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stat->expr = expr;
|
|
|
|
stat->case_clausules = case_clausules;
|
|
|
|
return &stat->stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static case_clausule_t *new_case_clausule(parser_ctx_t *ctx, expression_t *expr, statement_t *stat, case_clausule_t *next)
|
|
|
|
{
|
|
|
|
case_clausule_t *ret;
|
|
|
|
|
|
|
|
ret = parser_alloc(ctx, sizeof(*ret));
|
|
|
|
if(!ret)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret->expr = expr;
|
|
|
|
ret->stat = stat;
|
|
|
|
ret->next = next;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-19 14:10:19 +02:00
|
|
|
static statement_t *new_onerror_statement(parser_ctx_t *ctx, BOOL resume_next)
|
|
|
|
{
|
|
|
|
onerror_statement_t *stat;
|
|
|
|
|
|
|
|
stat = new_statement(ctx, STAT_ONERROR, sizeof(*stat));
|
|
|
|
if(!stat)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stat->resume_next = resume_next;
|
|
|
|
return &stat->stat;
|
|
|
|
}
|
|
|
|
|
2011-09-14 12:54:50 +02:00
|
|
|
static arg_decl_t *new_argument_decl(parser_ctx_t *ctx, const WCHAR *name, BOOL by_ref)
|
|
|
|
{
|
|
|
|
arg_decl_t *arg_decl;
|
|
|
|
|
|
|
|
arg_decl = parser_alloc(ctx, sizeof(*arg_decl));
|
|
|
|
if(!arg_decl)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
arg_decl->name = name;
|
|
|
|
arg_decl->by_ref = by_ref;
|
|
|
|
arg_decl->next = NULL;
|
|
|
|
return arg_decl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static function_decl_t *new_function_decl(parser_ctx_t *ctx, const WCHAR *name, function_type_t type,
|
2011-09-15 14:20:05 +02:00
|
|
|
unsigned storage_flags, arg_decl_t *arg_decl, statement_t *body)
|
2011-09-14 12:54:50 +02:00
|
|
|
{
|
|
|
|
function_decl_t *decl;
|
|
|
|
|
2011-09-15 14:20:05 +02:00
|
|
|
if(storage_flags & STORAGE_IS_DEFAULT) {
|
2011-09-16 13:28:00 +02:00
|
|
|
if(type == FUNC_PROPGET) {
|
2011-09-16 13:28:52 +02:00
|
|
|
type = FUNC_DEFGET;
|
2011-09-16 13:28:00 +02:00
|
|
|
}else {
|
|
|
|
FIXME("Invalid default property\n");
|
|
|
|
ctx->hres = E_FAIL;
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-09-15 14:20:05 +02:00
|
|
|
}
|
|
|
|
|
2011-09-14 12:54:50 +02:00
|
|
|
decl = parser_alloc(ctx, sizeof(*decl));
|
|
|
|
if(!decl)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
decl->name = name;
|
|
|
|
decl->type = type;
|
2011-09-15 14:20:05 +02:00
|
|
|
decl->is_public = !(storage_flags & STORAGE_IS_PRIVATE);
|
2011-09-14 12:54:50 +02:00
|
|
|
decl->args = arg_decl;
|
|
|
|
decl->body = body;
|
2011-09-15 19:04:43 +02:00
|
|
|
decl->next = NULL;
|
2011-09-16 13:28:00 +02:00
|
|
|
decl->next_prop_func = NULL;
|
2011-09-14 12:54:50 +02:00
|
|
|
return decl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static statement_t *new_function_statement(parser_ctx_t *ctx, function_decl_t *decl)
|
|
|
|
{
|
|
|
|
function_statement_t *stat;
|
|
|
|
|
|
|
|
stat = new_statement(ctx, STAT_FUNC, sizeof(*stat));
|
|
|
|
if(!stat)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stat->func_decl = decl;
|
|
|
|
return &stat->stat;
|
|
|
|
}
|
|
|
|
|
2011-09-15 14:16:47 +02:00
|
|
|
static class_decl_t *new_class_decl(parser_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
class_decl_t *class_decl;
|
|
|
|
|
|
|
|
class_decl = parser_alloc(ctx, sizeof(*class_decl));
|
|
|
|
if(!class_decl)
|
|
|
|
return NULL;
|
|
|
|
|
2011-09-15 19:04:43 +02:00
|
|
|
class_decl->funcs = NULL;
|
2011-09-16 13:27:11 +02:00
|
|
|
class_decl->props = NULL;
|
2011-09-15 14:16:47 +02:00
|
|
|
class_decl->next = NULL;
|
|
|
|
return class_decl;
|
|
|
|
}
|
|
|
|
|
2011-09-15 19:04:43 +02:00
|
|
|
static class_decl_t *add_class_function(parser_ctx_t *ctx, class_decl_t *class_decl, function_decl_t *decl)
|
|
|
|
{
|
|
|
|
function_decl_t *iter;
|
|
|
|
|
|
|
|
for(iter = class_decl->funcs; iter; iter = iter->next) {
|
|
|
|
if(!strcmpiW(iter->name, decl->name)) {
|
|
|
|
if(decl->type == FUNC_SUB || decl->type == FUNC_FUNCTION) {
|
|
|
|
FIXME("Redefinition of %s::%s\n", debugstr_w(class_decl->name), debugstr_w(decl->name));
|
|
|
|
ctx->hres = E_FAIL;
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-09-16 13:28:00 +02:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
if(iter->type == decl->type) {
|
|
|
|
FIXME("Redefinition of %s::%s\n", debugstr_w(class_decl->name), debugstr_w(decl->name));
|
|
|
|
ctx->hres = E_FAIL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if(!iter->next_prop_func)
|
|
|
|
break;
|
|
|
|
iter = iter->next_prop_func;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter->next_prop_func = decl;
|
|
|
|
return class_decl;
|
2011-09-15 19:04:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
decl->next = class_decl->funcs;
|
|
|
|
class_decl->funcs = decl;
|
|
|
|
return class_decl;
|
|
|
|
}
|
|
|
|
|
2011-09-16 13:27:11 +02:00
|
|
|
static class_decl_t *add_variant_prop(parser_ctx_t *ctx, class_decl_t *class_decl, const WCHAR *identifier, unsigned storage_flags)
|
|
|
|
{
|
|
|
|
class_prop_decl_t *prop;
|
|
|
|
|
|
|
|
if(storage_flags & STORAGE_IS_DEFAULT) {
|
|
|
|
FIXME("variant prop van't be default value\n");
|
|
|
|
ctx->hres = E_FAIL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = parser_alloc(ctx, sizeof(*prop));
|
|
|
|
if(!prop)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
prop->name = identifier;
|
|
|
|
prop->is_public = !(storage_flags & STORAGE_IS_PRIVATE);
|
|
|
|
prop->next = class_decl->props;
|
|
|
|
class_decl->props = prop;
|
|
|
|
return class_decl;
|
|
|
|
}
|
|
|
|
|
2011-09-21 14:03:18 +02:00
|
|
|
static const_decl_t *new_const_decl(parser_ctx_t *ctx, const WCHAR *name, expression_t *expr)
|
|
|
|
{
|
|
|
|
const_decl_t *decl;
|
|
|
|
|
|
|
|
decl = parser_alloc(ctx, sizeof(*decl));
|
|
|
|
if(!decl)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
decl->name = name;
|
|
|
|
decl->value_expr = expr;
|
|
|
|
decl->next = NULL;
|
|
|
|
return decl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static statement_t *new_const_statement(parser_ctx_t *ctx, const_decl_t *decls)
|
|
|
|
{
|
|
|
|
const_statement_t *stat;
|
|
|
|
|
|
|
|
stat = new_statement(ctx, STAT_CONST, sizeof(*stat));
|
|
|
|
if(!stat)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stat->decls = decls;
|
|
|
|
return &stat->stat;
|
|
|
|
}
|
|
|
|
|
2011-09-20 14:58:53 +02:00
|
|
|
static statement_t *link_statements(statement_t *head, statement_t *tail)
|
|
|
|
{
|
|
|
|
statement_t *iter;
|
|
|
|
|
|
|
|
for(iter = head; iter->next; iter = iter->next);
|
|
|
|
iter->next = tail;
|
|
|
|
|
|
|
|
return head;
|
|
|
|
}
|
|
|
|
|
2011-09-07 14:08:07 +02:00
|
|
|
void *parser_alloc(parser_ctx_t *ctx, size_t size)
|
|
|
|
{
|
|
|
|
void *ret;
|
|
|
|
|
2011-09-12 12:29:31 +02:00
|
|
|
ret = vbsheap_alloc(&ctx->heap, size);
|
2011-09-07 14:08:07 +02:00
|
|
|
if(!ret)
|
|
|
|
ctx->hres = E_OUTOFMEMORY;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-06 15:18:40 +02:00
|
|
|
HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code)
|
|
|
|
{
|
|
|
|
ctx->code = ctx->ptr = code;
|
|
|
|
ctx->end = ctx->code + strlenW(ctx->code);
|
|
|
|
|
2011-09-12 12:29:31 +02:00
|
|
|
vbsheap_init(&ctx->heap);
|
|
|
|
|
2011-09-06 15:18:40 +02:00
|
|
|
ctx->parse_complete = FALSE;
|
|
|
|
ctx->hres = S_OK;
|
|
|
|
|
2011-09-06 15:18:55 +02:00
|
|
|
ctx->last_token = tNL;
|
|
|
|
ctx->last_nl = 0;
|
2011-09-07 14:08:21 +02:00
|
|
|
ctx->stats = ctx->stats_tail = NULL;
|
2011-09-15 14:16:47 +02:00
|
|
|
ctx->class_decls = NULL;
|
2011-09-09 14:47:00 +02:00
|
|
|
ctx->option_explicit = FALSE;
|
2011-09-06 15:18:55 +02:00
|
|
|
|
2011-09-06 15:18:40 +02:00
|
|
|
parser_parse(ctx);
|
|
|
|
|
|
|
|
if(FAILED(ctx->hres))
|
|
|
|
return ctx->hres;
|
|
|
|
if(!ctx->parse_complete) {
|
|
|
|
FIXME("parser failed on parsing %s\n", debugstr_w(ctx->ptr));
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
2011-09-12 12:29:31 +02:00
|
|
|
|
|
|
|
void parser_release(parser_ctx_t *ctx)
|
|
|
|
{
|
|
|
|
vbsheap_free(&ctx->heap);
|
|
|
|
}
|