aboutsummaryrefslogtreecommitdiff
path: root/compile-principle-experiment/3/lex.l
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-11-24 20:43:52 +0800
committercrupest <crupest@outlook.com>2021-11-24 20:43:52 +0800
commit04cfc657115bb0f9b26b1b59fcb956fe3abb83d7 (patch)
tree78fe10fb9db60952b89e889aef056c706620322d /compile-principle-experiment/3/lex.l
parentd08a3a340a42bbd9616ea910fbad020d7aac212d (diff)
downloadlife-04cfc657115bb0f9b26b1b59fcb956fe3abb83d7.tar.gz
life-04cfc657115bb0f9b26b1b59fcb956fe3abb83d7.tar.bz2
life-04cfc657115bb0f9b26b1b59fcb956fe3abb83d7.zip
Add compile principle experiment 3.
Diffstat (limited to 'compile-principle-experiment/3/lex.l')
-rw-r--r--compile-principle-experiment/3/lex.l17
1 files changed, 17 insertions, 0 deletions
diff --git a/compile-principle-experiment/3/lex.l b/compile-principle-experiment/3/lex.l
new file mode 100644
index 0000000..ddea92d
--- /dev/null
+++ b/compile-principle-experiment/3/lex.l
@@ -0,0 +1,17 @@
+%{
+#include "main.h"
+#include "syn.h"
+%}
+%option noyywrap
+%%
+[ \t] { ; } /* skip blanks and tabs */
+[0-9]+\.?|[0-9]*\.[0-9]+ {
+ sscanf(yytext, "%lf", &yylval.val); return NUMBER; }
+[a-zA-Z][a-zA-Z0-9]* {
+ Symbol *s;
+ if ((s=cru_symbol_lookup(yytext)) == 0)
+ s = cru_symbol_install(yytext, UNDEF, (SymbolValue)0.0);
+ yylval.sym = s;
+ return s->type == UNDEF ? VAR : s->type; }
+\n { lineno++; return '\n'; } /* everything else */
+. { return yytext[0]; }