From: Jacek Caban Subject: vbscript: Added support for negative constants Message-Id: <508E5FEF.10800@codeweavers.com> Date: Mon, 29 Oct 2012 11:52:31 +0100 --- dlls/vbscript/parser.y | 19 ++++++++++++++----- dlls/vbscript/tests/lang.vbs | 12 +++++++++++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y index 8a2a9e3..45f9169 100644 --- a/dlls/vbscript/parser.y +++ b/dlls/vbscript/parser.y @@ -125,6 +125,7 @@ static const WCHAR propertyW[] = {'p','r','o','p','e','r','t','y',0}; %type Expression LiteralExpression PrimaryExpression EqualityExpression CallExpression %type ConcatExpression AdditiveExpression ModExpression IntdivExpression MultiplicativeExpression ExpExpression %type NotExpression UnaryExpression AndExpression OrExpression XorExpression EqvExpression +%type ConstExpression NumericLiteralExpression %type MemberExpression %type Arguments_opt ArgumentList_opt Step_opt ExpressionList %type OptionExplicit_opt DoType @@ -218,7 +219,11 @@ ConstDeclList | ConstDecl ',' ConstDeclList { $1->next = $3; $$ = $1; } ConstDecl - : Identifier '=' LiteralExpression { $$ = new_const_decl(ctx, $1, $3); CHECK_ERROR; } + : Identifier '=' ConstExpression { $$ = new_const_decl(ctx, $1, $3); CHECK_ERROR; } + +ConstExpression + : LiteralExpression { $$ = $1; } + | '-' NumericLiteralExpression { $$ = new_unary_expression(ctx, EXPR_NEG, $2); CHECK_ERROR; } DoType : tWHILE { $$ = TRUE; } @@ -354,14 +359,18 @@ LiteralExpression : tTRUE { $$ = new_bool_expression(ctx, VARIANT_TRUE); CHECK_ERROR; } | tFALSE { $$ = new_bool_expression(ctx, VARIANT_FALSE); CHECK_ERROR; } | tString { $$ = new_string_expression(ctx, $1); CHECK_ERROR; } - | 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; } + | NumericLiteralExpression { $$ = $1; } | tEMPTY { $$ = new_expression(ctx, EXPR_EMPTY, 0); CHECK_ERROR; } | tNULL { $$ = new_expression(ctx, EXPR_NULL, 0); CHECK_ERROR; } | tNOTHING { $$ = new_expression(ctx, EXPR_NOTHING, 0); CHECK_ERROR; } +NumericLiteralExpression + : 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; } + + PrimaryExpression : '(' Expression ')' { $$ = new_unary_expression(ctx, EXPR_BRACKETS, $2); } | tME { $$ = new_expression(ctx, EXPR_ME, 0); CHECK_ERROR; } diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs index 76f4003..8cffc7f 100644 --- a/dlls/vbscript/tests/lang.vbs +++ b/dlls/vbscript/tests/lang.vbs @@ -912,9 +912,19 @@ Call obj.test(obj) Call ok(getVT(test) = "VT_DISPATCH", "getVT(test) = " & getVT(test)) Call ok(Me is Test, "Me is not Test") -Const c1 = 1, c2 = 2 +Const c1 = 1, c2 = 2, c3 = -3 Call ok(c1 = 1, "c1 = " & c1) Call ok(getVT(c1) = "VT_I2", "getVT(c1) = " & getVT(c1)) +Call ok(c3 = -3, "c3 = " & c3) +Call ok(getVT(c3) = "VT_I2", "getVT(c3) = " & getVT(c3)) + +Const cb = True, cs = "test", cnull = null +Call ok(cb, "cb = " & cb) +Call ok(getVT(cb) = "VT_BOOL", "getVT(cb) = " & getVT(cb)) +Call ok(cs = "test", "cs = " & cs) +Call ok(getVT(cs) = "VT_BSTR", "getVT(cs) = " & getVT(cs)) +Call ok(isNull(cnull), "cnull = " & cnull) +Call ok(getVT(cnull) = "VT_NULL", "getVT(cnull) = " & getVT(cnull)) if false then Const conststr = "str" Call ok(conststr = "str", "conststr = " & conststr)