-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokens.l
49 lines (42 loc) · 1.15 KB
/
tokens.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 "defs.h"
#include "y.tab.h"
extern int yylex();
extern int yychar;
%}
%%
"const" {return CONST;}
"var" {return VAR;}
"array" {return ARRAY;}
"procedure" {return PROCEDURE;}
"function" {return FUNCTION;}
"call" {return CALL;}
"begin" {return BEGN;}
"end" {return END;}
"if" {return IF;}
"then" {return THEN;}
"else" {return ELSE;}
"while" {return WHILE;}
"do" {return DO;}
"for" {return FOR;}
"up to" {return UPTO;}
"down to" {return DOWNTO;}
"break" {return BREAK;}
"return" {return RETURN;}
"odd" {return ODD;}
"read" {return READ;}
"write" {return WRITE;}
"writeline" {return WRITELINE;}
[a-zA-Z][a-zA-Z0-9]* {return IDENTIFIER; } // identifier terminal
[0-9]+ {return NUMBER;} // Number terminal
"=" {return EQ;}
"<>" {return IDK;}
">" {return GT;}
"<" {return LT;}
"<=" {return LEQ;}
">=" {return GEQ;}
":=" {return ASGN;}
[ \t]+ ;
[\n] {yylineno++;}
. {return yytext[0];}
%%