Jacek Caban : vbscript: Added lexer support for numeric literals.

Alexandre Julliard julliard at winehq.org
Mon Sep 12 11:42:59 CDT 2011


Module: wine
Branch: master
Commit: 1e224b4e09e25192d8c80d90c9208497c7a694fe
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=1e224b4e09e25192d8c80d90c9208497c7a694fe

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Sep 12 12:29:43 2011 +0200

vbscript: Added lexer support for numeric literals.

---

 dlls/vbscript/lex.c    |   30 ++++++++++++++++++++++++++++++
 dlls/vbscript/parser.y |    2 ++
 2 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/dlls/vbscript/lex.c b/dlls/vbscript/lex.c
index 4c78b42..ddafee9 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 607fcb6..a5fff60 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 <string> tIdentifier tString
+%token <lng> tLong tShort
+%token <dbl> tDouble
 
 %type <statement> Statement StatementNl
 %type <expression> Expression LiteralExpression PrimaryExpression EqualityExpression CallExpression




More information about the wine-cvs mailing list