diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2017-01-17 20:14:45 -0600 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2017-01-17 23:00:52 -0600 |
commit | 9244eacb5ab0b9a11480d1ad40d4720575676877 (patch) | |
tree | c49c20b4c693c6676d49f35b6c1217131dd4c0da /lexer.l | |
parent | bb7ae08ee638cf9b88a69ca89c5b6b12401c37f5 (diff) |
nqasm: parse labels
Diffstat (limited to 'lexer.l')
-rw-r--r-- | lexer.l | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -2,10 +2,12 @@ #include <errno.h> #include <stdlib.h> +#include <string.h> #include "parser.h" #define SETVALUE(v) yylval.arg = (struct argument) { .value = (v) } +#define SETSTR(s) yylval.str = strdup(s) static int intlit(const char *s, int base, long *out) { @@ -22,6 +24,7 @@ static int intlit(const char *s, int base, long *out) %s inst %s args +LABEL [_a-zA-Z][_a-zA-Z0-9]* COMMENT #[^\n]* SP [ \t] EOI [ \t\n#] @@ -32,6 +35,8 @@ HEX [0-9a-f] %% <INITIAL>{SP}+ { BEGIN(inst); return T_SPACE; } +<INITIAL>{LABEL} { SETSTR(yytext); return T_LABEL; } +<INITIAL>:{SP}* { BEGIN(inst); return T_COLON; } <inst>add/{EOI} { BEGIN(args); return T_ADD; } <inst>sub/{EOI} { BEGIN(args); return T_SUB; } |