summaryrefslogtreecommitdiff
path: root/src/lexer.l
diff options
context:
space:
mode:
Diffstat (limited to 'src/lexer.l')
-rw-r--r--src/lexer.l28
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; }
+. ;
+%%