summaryrefslogtreecommitdiff
path: root/lisp.l
diff options
context:
space:
mode:
authorFelix Perktold <Felix.Perktold@student.uibk.ac.at>2025-12-20 21:59:28 +0100
committerFelix Perktold <Felix.Perktold@student.uibk.ac.at>2025-12-20 21:59:28 +0100
commit5eeb355805e0d5d91981dbe7eacb078f41da0437 (patch)
treed4d2a76e7988cf63aa9438d2b42d0a4a4656ee42 /lisp.l
init commit
Diffstat (limited to 'lisp.l')
-rw-r--r--lisp.l25
1 files changed, 25 insertions, 0 deletions
diff --git a/lisp.l b/lisp.l
new file mode 100644
index 0000000..329fc0f
--- /dev/null
+++ b/lisp.l
@@ -0,0 +1,25 @@
+%{
+#include <stdlib.h>
+#include "lisp.h"
+#include "lisp.tab.h"
+
+int tcnt = 0;
+%}
+
+%%
+[+-]?([0-9]+|([0-9]*\.[0-9]+))([eE][-+]?[0-9]+)? {
+ yylval.dval = atof(yytext);
+ printf("%d: NUMBER: %f\n", ++tcnt, yylval.dval);
+ return NUMBER;
+ }
+[ \t\n]+ { printf("%d: WHITESPACE\n", tcnt); return WHITESPACE; }
+"(" { printf("%d: LPAREN\n", ++tcnt); return LPAREN; }
+")" { printf("%d: RPAREN\n", ++tcnt); return RPAREN; }
+"\." { printf("%d: DOT\n", ++tcnt); return DOT; }
+"+" { printf("%d: PLUS\n", ++tcnt); return PLUS; }
+"-" { printf("%d: MINUS\n", ++tcnt); return MINUS; }
+"*" { printf("%d: MULT\n", ++tcnt); return MULT; }
+"/" { printf("%d: DIV\n", ++tcnt); return DIV; }
+\".*\" { printf("%d: STRING\n", ++tcnt); return STRING; }
+. ; // do nothing
+%%