summaryrefslogtreecommitdiff
path: root/yacclex/calclexret/calc.l
diff options
context:
space:
mode:
Diffstat (limited to 'yacclex/calclexret/calc.l')
-rw-r--r--yacclex/calclexret/calc.l39
1 files changed, 39 insertions, 0 deletions
diff --git a/yacclex/calclexret/calc.l b/yacclex/calclexret/calc.l
new file mode 100644
index 0000000..f681fa5
--- /dev/null
+++ b/yacclex/calclexret/calc.l
@@ -0,0 +1,39 @@
+%{
+enum yytokentype {
+ NUMBER = 258,
+ ADD = 259,
+ SUB = 260,
+ MUL = 261,
+ DIV = 262,
+ ABS = 263,
+ EOL = 264
+};
+
+int yylval;
+%}
+
+%%
+"+" { return ADD; }
+"-" { return SUB; }
+"*" { return MUL; }
+"/" { return DIV; }
+"|" { return ABS; }
+[0-9]+ { yylval = atoi(yytext); return NUMBER; }
+\n { return EOL; }
+[ \t] { /* ignore whitespace */ }
+. { printf("Mystery character %c\n", *yytext); }
+%%
+
+int yywrap() {
+ return 1;
+}
+
+int main(void) {
+ int tok;
+ while((tok = yylex())) {
+ printf("%d", tok);
+ if(tok == NUMBER)
+ printf(" = %d\n", yylval);
+ else printf("\n");
+ }
+}