-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.l
51 lines (42 loc) · 949 Bytes
/
lexer.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
51
%option noyywrap nodefault yylineno
%{
# include "interface.h"
# include "y.tab.h"
%}
%%
/* single character ops */
"+" |
"-" |
"*" |
"/" |
"," |
";" |
":" |
"(" |
")" { return yytext[0]; }
":=" { return ASSIGN; }
/* comparison ops */
">" { yylval.fn = 1; return CMP; }
"<" { yylval.fn = 2; return CMP; }
"==" { yylval.fn = 3; return CMP; }
/* logic ops */
".AND." { return '&'; }
".OR." { return '|'; }
".XOR." { return '^'; }
".NOT." { return '!'; }
/* keywords */
"Var" { return VAR; }
"Boolean" {return BOOL;}
"Decimal" {return DEC;}
"Begin" { return BN; }
"End" { return ED; }
"FOR" { return FOR; }
"TO" { return TO; }
"DO" { return DO; }
/* names */
[a-zA-Z]+ { yylval.ch = strdup(yytext); return NAME; }
[0-9]+ { yylval.d = atoi(yytext); return NUMBER; }
"{"(.|\n)*"}"
[ \t\r\n]
. { yyerror("Mystery character '%c'\n", *yytext); }
%%