diff options
| author | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-03-14 18:44:18 -0400 |
|---|---|---|
| committer | Jacob McDonnell <jacob@jacobmcdonnell.com> | 2026-03-14 18:44:18 -0400 |
| commit | 0c81ee06d19d1d7f67dab3c2c9da268b0c55e3c0 (patch) | |
| tree | 9a10aae3c5de847ca1235c048d886c5b64929d80 /src/lexer.l | |
| parent | ecffc124bbc5d6c9c089eb6d914565119d254a4d (diff) | |
feat: Initial parsing of instructions
Initial ability to parse basic instructions. Currently hex numbers are
broken and immediates with labels (movl $str, %ecx) are broken.
Diffstat (limited to 'src/lexer.l')
| -rw-r--r-- | src/lexer.l | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/lexer.l b/src/lexer.l new file mode 100644 index 0000000..46f6bc6 --- /dev/null +++ b/src/lexer.l @@ -0,0 +1,28 @@ +%{ +#include <string.h> +#include <stdlib.h> +#include "parser.tab.h" +extern int yylex(); +extern size_t line_number; +%} +%option noyywrap +%% +^[a-zA-Z]+ { yylval.symbol = strdup(yytext); return T_INSTRUCTION; } +%*[a-zA-Z\_\-]+[a-zA-Z0-9\_\-]* { yylval.symbol = strdup(yytext); return T_LABEL; } +0x[0-9A-Fa-f]+ { yylval.i_val = atoi(yytext); return T_INTEGER; } +[0-9]+ { yylval.i_val = atoi(yytext); return T_INTEGER; } +-*[0-9]*\.*[0-9]* { yylval.i_val = atof(yytext); return T_FLOAT; } +\".*\" { + yylval.s_val = strdup(yytext+1); + char *const close_paren = strrchr(yylval.s_val, '"'); + if (close_paren != NULL) { + *close_paren = '\0'; + } + return T_STRING; +} +, { return T_COMMA; } +\$ { return T_IMMEDIATE; } +[ \t] ; +\n { ++line_number; return T_ENDL; } +. ; +%% |
