summaryrefslogtreecommitdiff
path: root/lex.l
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2022-12-06 13:34:33 +0100
committerDaniel Weipert <code@drogueronin.de>2022-12-06 13:34:33 +0100
commitf17b517e56503600355de910ce576efab56b1287 (patch)
tree48b3a03d0383bc1347d7a85b4f6bdc55f4b55e6b /lex.l
parent5b840fd4c56d835b067e4cf9a3e4af4442717d20 (diff)
Tried to create an AST
Diffstat (limited to 'lex.l')
-rw-r--r--lex.l10
1 files changed, 8 insertions, 2 deletions
diff --git a/lex.l b/lex.l
index 2f79474..64c3765 100644
--- a/lex.l
+++ b/lex.l
@@ -1,4 +1,5 @@
%{
+#include "ast.h"
#include "grammar.tab.h"
%}
@@ -14,6 +15,10 @@
"const" { return CONST; }
"var" { return VAR; }
+"integer" { return TYPE_INTEGER; }
+"string" { return TYPE_STRING; }
+"void" { return TYPE_VOID; }
+
"(" { return PARENTHESIS_LEFT; }
")" { return PARENTHESIS_RIGHT; }
"{" { return BRACE_LEFT; }
@@ -22,9 +27,10 @@
"]" { return BRACKET_RIGHT; }
"," { return COMMA; }
+":" { return COLON; }
-[0-9]+ { yylval = atoi(yytext); return NUMBER; }
-[a-zA-Z]+[a-zA-Z0-9]* { return IDENTIFIER; }
+[a-zA-Z][a-zA-Z0-9]* { yylval.string = yytext; return IDENTIFIER; }
+[0-9]+ { yylval.number = atoi(yytext); return NUMBER; }
"//".* { return COMMENT; }
\n { return END_OF_LINE; }