-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.l
49 lines (39 loc) · 1.01 KB
/
calc.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
%{
#include <stdlib.h>
#include "calc.h"
#include "y.tab.h"
void yyerror(char *);
%}
%%
"while" return WHILE;
"if" return IF;
"print" return PRINT;
"def" return FNDEF;
"call" return FNCALL;
"+" { return ADD; }
"*" { return MUL; }
"-" { return SUB; }
"/" { return DIV; }
"=" { return SET; }
"?=" { return EQ; }
"!=" { return NEQ; }
"<" { return LT; }
">" { return GT; }
"(" { return LPAREN; }
")" { return RPAREN; }
[a-zA-Z]+ { yylval.sPos = yytext[0]; return VARIABLE;}
[0-9]+ { yylval.num = atoi(yytext); return INTEGER; }
"//".* ; /* ignore comments */
"\""[^"]*"\"" { yylval.strin = yytext; return STRING; }
[ \t\n]+ ; /* ignore whitespace */
. yyerror("Unknown character");
%%
int yywrap(void) {
return 1;
}
/* (def f (
(= x (+ x 1))
(print x)
(if (< x 10) (call f))
(if (?= x 10) (= x 0))
)) */