diff options
Diffstat (limited to 'lexer.l')
-rw-r--r-- | lexer.l | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -1,9 +1,19 @@ %{ +#include <errno.h> +#include <stdlib.h> + #include "parser.h" #define SETVALUE(v) yylval.arg = (struct argument) { .value = (v) } +static int intlit(const char *s, int base, long *out) +{ + errno = 0; + *out = strtol(s, NULL, base); + return errno == ERANGE ? T_BADINT : T_INT; +} + %} %option outfile="lexer.c" header-file="lexer.h" @@ -16,6 +26,8 @@ COMMENT #[^\n]* SP [ \t] EOI [ \t\n#] REGNUM [0-7] +DEC [0-9] +HEX [0-9a-f] %% @@ -59,6 +71,8 @@ REGNUM [0-7] <args>r{REGNUM} { SETVALUE(yytext[1]-'0'); return T_REG; } <args>@r{REGNUM} { SETVALUE(yytext[2]-'0'); return T_REGPTR; } +<args>[-+]?{DEC}+ { return intlit(yytext, 10, &yylval.lval); } +<args>0x{HEX}+ { return intlit(yytext+2, 16, &yylval.lval); } <args>{SP}*,{SP}* { return T_COMMA; } {SP}*{COMMENT}?\n { BEGIN(INITIAL); return T_EOL; } |