From 1e224b4e09e25192d8c80d90c9208497c7a694fe Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 12 Sep 2011 12:29:43 +0200 Subject: [PATCH] vbscript: Added lexer support for numeric literals. --- dlls/vbscript/lex.c | 30 ++++++++++++++++++++++++++++++ dlls/vbscript/parser.y | 2 ++ 2 files changed, 32 insertions(+) diff --git a/dlls/vbscript/lex.c b/dlls/vbscript/lex.c index 4c78b420685..ddafee9b188 100644 --- a/dlls/vbscript/lex.c +++ b/dlls/vbscript/lex.c @@ -240,6 +240,33 @@ static int parse_string_literal(parser_ctx_t *ctx, const WCHAR **ret) return tString; } +static int parse_numeric_literal(parser_ctx_t *ctx, void **ret) +{ + double n = 0; + + if(*ctx->ptr == '0' && !('0' <= ctx->ptr[1] && ctx->ptr[1] <= '9') && ctx->ptr[1] != '.') + return *ctx->ptr++; + + do { + n = n*10 + *ctx->ptr++ - '0'; + }while('0' <= *ctx->ptr && *ctx->ptr <= '9'); + + if(*ctx->ptr != '.') { + if((LONG)n == n) { + LONG l = n; + *(LONG*)ret = l; + return (short)l == l ? tShort : tLong; + } + }else { + double e = 1.0; + while('0' <= *++ctx->ptr && *ctx->ptr <= '9') + n += (e /= 10.0)*(*ctx->ptr-'0'); + } + + *(double*)ret = n; + return tDouble; +} + static void skip_spaces(parser_ctx_t *ctx) { while(*ctx->ptr == ' ' || *ctx->ptr == '\t' || *ctx->ptr == '\r') @@ -256,6 +283,9 @@ static int parse_next_token(void *lval, parser_ctx_t *ctx) c = *ctx->ptr; + if('0' <= c && c <= '9') + return parse_numeric_literal(ctx, lval); + if(isalphaW(c)) { int ret = check_keywords(ctx); if(!ret) diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y index 607fcb66dfd..a5fff60633c 100644 --- a/dlls/vbscript/parser.y +++ b/dlls/vbscript/parser.y @@ -74,6 +74,8 @@ static statement_t *new_call_statement(parser_ctx_t*,member_expression_t*); %token tCLASS tSET tNEW tPUBLIC tPRIVATE tDEFAULT tME %token tERROR tNEXT tON tRESUME tGOTO %token tIdentifier tString +%token tLong tShort +%token tDouble %type Statement StatementNl %type Expression LiteralExpression PrimaryExpression EqualityExpression CallExpression