-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcal.l
50 lines (44 loc) · 1.04 KB
/
cal.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
50
%{
#include <stdlib.h>
#include "cal.h"
#include "y.tab.h"
void yyerror(char *);
%}
%%
\/\*.*([\n])([^*]|\*+[^*/])*\*+\/ {printf("Commented Detected\n");}
[a-z] {
yylval.sIndex = *yytext - 'a';
return VARIABLE;
}
0[.]?[0-9]* {
yylval.iValue = atof(yytext);
return INTEGER;
}
[1-9][0-9]*[.]?[0-9]* {
yylval.iValue = atof(yytext);
return INTEGER;
}
[-()<>=+*/;{}.] {
return *yytext;
}
"&&" return AND;
"||" return OR;
"!" return NOT;
"++" return INC;
"--" return DEC;
">=" return GE;
"<=" return LE;
"==" return EQ;
"!=" return NE;
"while" return WHILE;
"for" return FOR;
"if" return IF;
"else" return ELSE;
"print" return PRINT;
"scan" return SCAN;
[ \t\n]+ ; /* ignore whitespace */
. yyerror("Unknown character");
%%
int yywrap(void) {
return 1;
}