summaryrefslogtreecommitdiff
path: root/lex.l
diff options
context:
space:
mode:
Diffstat (limited to 'lex.l')
-rw-r--r--lex.l38
1 files changed, 38 insertions, 0 deletions
diff --git a/lex.l b/lex.l
new file mode 100644
index 0000000..e7591d4
--- /dev/null
+++ b/lex.l
@@ -0,0 +1,38 @@
+%option noyywrap
+%option nodefault
+%option yylineno
+%option noinput nounput
+
+%{
+
+#include <string.h>
+
+#include "basic.h"
+#include "parse.h"
+
+void yyerror(const char *s, ...);
+
+%}
+
+ID [-A-Za-z_+*!/][-A-Za-z0-9_+*!]*
+FLOAT [+-]?([0-9]+[.][0-9]*([Ee][+-]?[0-9]+)?|[.][0-9]+([Ee][+-]?[0-9]+)?)
+INT [+-]?[0-9]+
+
+%%
+
+"(" |
+")" |
+";" { return yytext[0]; }
+
+"()" { return NIL; }
+
+{ID} { /* TODO: strdup allocates memory! */
+ yylval.s = strdup(yytext); return ID; }
+
+{INT} { yylval.i = atoi(yytext); return INT; }
+
+{FLOAT} { yylval.f = atof(yytext); return FLOAT; }
+
+[ \t\n] /* ignore whitespace */
+
+. { yyerror("Unexpected character %c\n", yytext[0]); }