-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalc.l
executable file
·43 lines (39 loc) · 983 Bytes
/
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
%{
#include <stdlib.h>
#include "calc.h"
#include "y.tab.h"
void yyerror(char *);
%}
%%
[a-z,A-Z] { yylval.sIndex = *yytext - 'a'; return VARIABLE;};
"print" return PRINT;
"begin" return START;
"if" return IF;
"then" return THEN;
"else" return ELSE;
"while" return WHILE;
"do" return DO;
"and" return AND;
"or" return OR;
"true" {yylval.bValue = 1; return TRUE;};
"false" {yylval.bValue = 0; return FALSE;};
[1-9][0-9]* {yylval.iValue = atoi(yytext); return NUMBER;};
"+" return PLUS;
"-" return MINUS;
"*" return MULTI;
"/" return OVER;
";" return SEMI;
"<" return LESS;
">" return BIGGER;
"=" return EQUAL;
"(" return LAPREN;
")" return RPAREN;
":=" return ASSIGN;
"<=" return LESSEQ;
">=" return BIGEQ;
[ \t\n]+;
.
%%
int yywrap(void) {
return 1;
}