-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.l
77 lines (68 loc) · 1.99 KB
/
test.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
%{
#include "Module.hpp"
#include "test.tab.hpp"
#include <iostream>
#include <sstream>
#include <string>
#include <cstdlib>
%}
%option noyywrap
%option c++
DIGIT [0-9]
LETTER [a-zA-Z]+
ID {LETTER}({LETTER}|{DIGIT})*
DOUBLE ({DIGIT}+)"."({DIGIT}+)
BOOLEAN "TRUE"|"true"|"True"|"FALSE"|"False"|"false"
STRING "\""[^\"]*"\""
BLANK [ \t\n]
%%
":=" { return ASSGNOP; }
"<=" { return LE; }
">=" { return GE; }
"<>" { return NE; }
DIV { return DIV; }
MOD { return MOD; }
OR { return OR; }
{DIGIT}+ {
yylval.integer = new IntegerValue(atoi(yytext));
return INTEGER;
}
{BOOLEAN} {
if (tolower(*yytext) == 't')
yylval.boolean = new BooleanValue(1);
if (tolower(*yytext) == 'f')
yylval.boolean = new BooleanValue(0);
return BOOLEAN;
}
{STRING} {
std::string s(yytext);
yylval.string = new StringValue(s.substr(1, s.length() - 2));
return STRING;
}
{DOUBLE} {
yylval.double_ = new DoubleValue(atof(yytext));
return DOUBLE;
}
MODULE { return MODULE; }
PROCEDURE { return PROCEDURE; }
BEGIN { return BEGIN_; }
END { return END; }
CONST { return CONST; }
TYPE { return TYPE; }
VAR { return VAR; }
RECORD { return RECORD; }
ARRAY { return ARRAY; }
OF { return OF; }
WHILE { return WHILE; }
DO { return DO; }
ELSE { return ELSE; }
IF { return IF; }
ELSIF { return ELSIF; }
THEN { return THEN; }
{ID} {
yylval.identifier = new std::string(yytext, yyleng);
return IDENTIFIER;
}
{BLANK}+ /* blank, tab, newline */
. { return yytext[0]; }
%%