From cc498848b36b347aa9b710ab55c1fcc8643a4633 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 26 Jan 2014 02:21:57 +0100 Subject: lex: add support for octal and hexadecimal integer literals --- src/lex.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lex.c b/src/lex.c index 9fbab9e..b22bf40 100644 --- a/src/lex.c +++ b/src/lex.c @@ -318,21 +318,27 @@ static int parse_ipv4_address(YYSTYPE *yylval, YYLTYPE *yylloc, fastd_lex_t *lex } static int parse_number(YYSTYPE *yylval, YYLTYPE *yylloc, fastd_lex_t *lex) { + bool digitonly = true; + if (lex->needspace) return syntax_error(yylval, lex); while (next(yylloc, lex, false)) { char cur = current(lex); - if (cur == '.') + if (cur == '.' && digitonly) return parse_ipv4_address(yylval, yylloc, lex); - if (!(cur >= '0' && cur <= '9')) - break; + if (!(cur >= '0' && cur <= '9')) { + if ((cur >= 'a' && cur <= 'z') || (cur >= 'A' && cur <= 'Z')) + digitonly = false; + else + break; + } } char *endptr, *token = get_token(lex); - yylval->uint64 = strtoull(token, &endptr, 10); + yylval->uint64 = strtoull(token, &endptr, 0); bool ok = !*endptr; free(token); -- cgit v1.2.3