diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-01-26 02:21:57 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-01-26 02:21:57 +0100 |
commit | cc498848b36b347aa9b710ab55c1fcc8643a4633 (patch) | |
tree | 316675cd0ab0aae180b2e8313ef621acb6c8c0c5 | |
parent | 17019f0db3c0def60f50de62693c507c624e67a8 (diff) | |
download | fastd-cc498848b36b347aa9b710ab55c1fcc8643a4633.tar fastd-cc498848b36b347aa9b710ab55c1fcc8643a4633.zip |
lex: add support for octal and hexadecimal integer literals
-rw-r--r-- | src/lex.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -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); |