Commit 6c557029 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

vbscript: Added function call statement parsing beginning implementation.

parent 91cc7bd7
......@@ -53,13 +53,18 @@ static unsigned push_instr(compile_ctx_t *ctx, vbsop_t op)
return ctx->instr_cnt++;
}
static HRESULT compile_func(compile_ctx_t *ctx, function_t *func)
static HRESULT compile_func(compile_ctx_t *ctx, statement_t *stat, function_t *func)
{
func->code_off = ctx->instr_cnt;
if(push_instr(ctx, OP_ret) == -1)
return E_OUTOFMEMORY;
if(stat) {
FIXME("statements compilation not implemented\n");
return E_NOTIMPL;
}
return S_OK;
}
......@@ -113,7 +118,7 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, vbscode_t **ret)
if(!ctx.code)
return E_OUTOFMEMORY;
hres = compile_func(&ctx, &ctx.code->global_code);
hres = compile_func(&ctx, ctx.parser.stats, &ctx.code->global_code);
if(FAILED(hres)) {
release_vbscode(ctx.code);
return hres;
......
......@@ -16,6 +16,36 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
typedef enum {
EXPR_MEMBER
} expression_type_t;
typedef struct _expression_t {
expression_type_t type;
struct _expression_t *next;
} expression_t;
typedef struct {
expression_t expr;
expression_t *obj_expr;
const WCHAR *identifier;
expression_t *args;
} member_expression_t;
typedef enum {
STAT_CALL
} statement_type_t;
typedef struct _statement_t {
statement_type_t type;
struct _statement_t *next;
} statement_t;
typedef struct {
statement_t stat;
member_expression_t *expr;
} call_statement_t;
typedef struct {
const WCHAR *code;
const WCHAR *ptr;
......@@ -26,6 +56,9 @@ typedef struct {
int last_token;
unsigned last_nl;
statement_t *stats;
statement_t *stats_tail;
} parser_ctx_t;
HRESULT parse_script(parser_ctx_t*,const WCHAR*) DECLSPEC_HIDDEN;
......
......@@ -33,6 +33,12 @@ static int parser_error(const char*);
static void parse_complete(parser_ctx_t*);
static void source_add_statement(parser_ctx_t*,statement_t*);
static member_expression_t *new_member_expression(parser_ctx_t*,expression_t*,const WCHAR*);
static statement_t *new_call_statement(parser_ctx_t*,member_expression_t*);
%}
%pure_parser
......@@ -40,14 +46,34 @@ static void parse_complete(parser_ctx_t*);
%union {
const WCHAR *string;
statement_t *statement;
member_expression_t *member;
}
%token tEOF tNL
%token tEOF tNL blah
%token <string> tIdentifier
%type <statement> Statement StatementNl
%type <member> MemberExpression
%%
Program : tEOF { parse_complete(ctx); }
Program
: SourceElements tEOF { parse_complete(ctx); }
SourceElements
: /* empty */
| SourceElements StatementNl { source_add_statement(ctx, $2); }
StatementNl
: Statement tNL { $$ = $1; }
Statement
: MemberExpression /* FIXME: Arguments_opt */ { $$ = new_call_statement(ctx, $1); }
MemberExpression
: tIdentifier { $$ = new_member_expression(ctx, NULL, $1); }
/* FIXME: MemberExpressionArgs '.' tIdentifier */
%%
......@@ -56,11 +82,73 @@ static int parser_error(const char *str)
return 0;
}
static void source_add_statement(parser_ctx_t *ctx, statement_t *stat)
{
if(ctx->stats) {
ctx->stats_tail->next = stat;
ctx->stats_tail = stat;
}else {
ctx->stats = ctx->stats_tail = stat;
}
}
static void parse_complete(parser_ctx_t *ctx)
{
ctx->parse_complete = TRUE;
}
static void *new_expression(parser_ctx_t *ctx, expression_type_t type, unsigned size)
{
expression_t *expr;
expr = parser_alloc(ctx, size ? size : sizeof(*expr));
if(expr) {
expr->type = type;
expr->next = NULL;
}
return expr;
}
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;
}
static void *new_statement(parser_ctx_t *ctx, statement_type_t type, unsigned size)
{
statement_t *stat;
stat = parser_alloc(ctx, size);
if(stat) {
stat->type = type;
stat->next = NULL;
}
return stat;
}
static statement_t *new_call_statement(parser_ctx_t *ctx, member_expression_t *expr)
{
call_statement_t *stat;
stat = new_statement(ctx, STAT_CALL, sizeof(*stat));
if(!stat)
return NULL;
stat->expr = expr;
return &stat->stat;
}
void *parser_alloc(parser_ctx_t *ctx, size_t size)
{
void *ret;
......@@ -82,6 +170,7 @@ HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code)
ctx->last_token = tNL;
ctx->last_nl = 0;
ctx->stats = ctx->stats_tail = NULL;
parser_parse(ctx);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment