From 089e490c69071ecbe40492912070b7a7a891a8bb Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Sun, 25 Nov 2012 22:35:41 +0100 Subject: [PATCH] Allow float constants which start with a dot --- lexer.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lexer.c b/lexer.c index 6bd47b0..6fbe41d 100644 --- a/lexer.c +++ b/lexer.c @@ -800,7 +800,10 @@ static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch) int ch = lastch; /* parse a number... */ - lex->tok.ttype = TOKEN_INTCONST; + if (ch == '.') + lex->tok.ttype = TOKEN_FLOATCONST; + else + lex->tok.ttype = TOKEN_INTCONST; lex_tokench(lex, ch); @@ -833,7 +836,7 @@ static int GMQCC_WARN lex_finish_digit(lex_file *lex, int lastch) } } /* NOT else, '.' can come from above as well */ - if (ch == '.' && !ishex) + if (lex->tok.ttype != TOKEN_FLOATCONST && ch == '.' && !ishex) { /* Allow floating comma in non-hex mode */ lex->tok.ttype = TOKEN_FLOATCONST; @@ -1078,6 +1081,18 @@ int lex_do(lex_file *lex) break; } + if (ch == '.') { + nextch = lex_getch(lex); + /* digits starting with a dot */ + if (isdigit(nextch)) { + lex_ungetch(lex, nextch); + lex->tok.ttype = lex_finish_digit(lex, ch); + lex_endtoken(lex); + return lex->tok.ttype; + } + lex_ungetch(lex, nextch); + } + if (lex->flags.noops) { /* Detect characters early which are normally -- 2.39.2