vbscript: Added additive expressions parser/compiler implementation.

This commit is contained in:
Jacek Caban 2011-09-12 12:31:58 +02:00 committed by Alexandre Julliard
parent 8e1ccb8be6
commit 0ec9339533
5 changed files with 27 additions and 2 deletions

View File

@ -234,6 +234,8 @@ static HRESULT compile_binary_expression(compile_ctx_t *ctx, binary_expression_t
static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr)
{
switch(expr->type) {
case EXPR_ADD:
return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_add);
case EXPR_BOOL:
return push_instr_int(ctx, OP_bool, ((bool_expression_t*)expr)->value);
case EXPR_CONCAT:
@ -254,6 +256,8 @@ static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr)
return push_instr(ctx, OP_null) != -1 ? S_OK : E_OUTOFMEMORY;
case EXPR_STRING:
return push_instr_str(ctx, OP_string, ((string_expression_t*)expr)->value);
case EXPR_SUB:
return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_sub);
case EXPR_USHORT:
return push_instr_int(ctx, OP_short, ((int_expression_t*)expr)->value);
case EXPR_ULONG:

View File

@ -391,6 +391,18 @@ static HRESULT interp_concat(exec_ctx_t *ctx)
return stack_push(ctx, &v);
}
static HRESULT interp_add(exec_ctx_t *ctx)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT interp_sub(exec_ctx_t *ctx)
{
FIXME("\n");
return E_NOTIMPL;
}
static HRESULT interp_neg(exec_ctx_t *ctx)
{
variant_val_t val;

View File

@ -17,6 +17,7 @@
*/
typedef enum {
EXPR_ADD,
EXPR_BOOL,
EXPR_CONCAT,
EXPR_DOUBLE,
@ -27,6 +28,7 @@ typedef enum {
EXPR_NOT,
EXPR_NULL,
EXPR_STRING,
EXPR_SUB,
EXPR_ULONG,
EXPR_USHORT
} expression_type_t;

View File

@ -83,7 +83,7 @@ static statement_t *new_call_statement(parser_ctx_t*,member_expression_t*);
%type <statement> Statement StatementNl
%type <expression> Expression LiteralExpression PrimaryExpression EqualityExpression CallExpression
%type <expression> ConcatExpression AdditiveExpression
%type <expression> ConcatExpression AdditiveExpression ModExpression
%type <expression> NotExpression UnaryExpression
%type <member> MemberExpression
%type <expression> Arguments_opt ArgumentList_opt ArgumentList
@ -145,6 +145,11 @@ ConcatExpression
| ConcatExpression '&' AdditiveExpression { $$ = new_binary_expression(ctx, EXPR_CONCAT, $1, $3); CHECK_ERROR; }
AdditiveExpression
: 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
: UnaryExpression /* FIXME */ { $$ = $1; }

View File

@ -88,6 +88,7 @@ typedef enum {
} instr_arg_type_t;
#define OP_LIST \
X(add, 1, 0, 0) \
X(bool, 1, ARG_INT, 0) \
X(concat, 1, 0, 0) \
X(double, 1, ARG_DOUBLE, 0) \
@ -101,7 +102,8 @@ typedef enum {
X(null, 1, 0, 0) \
X(ret, 0, 0, 0) \
X(short, 1, ARG_INT, 0) \
X(string, 1, ARG_STR, 0)
X(string, 1, ARG_STR, 0) \
X(sub, 1, 0, 0)
typedef enum {
#define X(x,n,a,b) OP_##x,