vbscript: Added lexer support for numeric literals.

oldstable
Jacek Caban 2011-09-12 12:29:43 +02:00 committed by Alexandre Julliard
parent bb80eaa492
commit 1e224b4e09
2 changed files with 32 additions and 0 deletions

View File

@ -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)

View File

@ -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