From 99e2e923d0c77b02f3fb4ff648ea916954868606 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Fri, 28 Feb 2025 23:13:39 +0800 Subject: chore(store): move everything to store. --- .../works/life/compile-principle-experiment/4/lex.l | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 store/works/life/compile-principle-experiment/4/lex.l (limited to 'store/works/life/compile-principle-experiment/4/lex.l') diff --git a/store/works/life/compile-principle-experiment/4/lex.l b/store/works/life/compile-principle-experiment/4/lex.l new file mode 100644 index 0000000..e7731ca --- /dev/null +++ b/store/works/life/compile-principle-experiment/4/lex.l @@ -0,0 +1,20 @@ +%{ +#include "main.h" +#include "syn.h" +%} +%option noyywrap +%% +[ \t] { ; } /* skip blanks and tabs */ +[0-9]+\.?|[0-9]*\.[0-9]+ { + Symbol *s = cru_symbol_install("", UNDEF, (SymbolValue)0.0); + sscanf(yytext, "%lf", &s->value.val); + yylval.sym = s; + 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]; } -- cgit v1.2.3