Allow float constants which start with a dot

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-11-25 22:35:41 +01:00
parent 42bd37a2e8
commit 089e490c69

19
lexer.c
View file

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