-
Notifications
You must be signed in to change notification settings - Fork 0
/
expr.l
executable file
·45 lines (44 loc) · 1.21 KB
/
expr.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
delim [ \t]
ws {delim}+
digito [0-9]
caracterMinusculo [a-z]
simbolo [-_]
caracterMaiusculo [A-Z]
numInt {digito}{digito}*
numFloat ({digito}+\.{digito}*)|({digito}*\.{digito}+)
literal \".*\"
id (({caracterMinusculo}+)|({caracterMaiusculo}+))({digito}*|{simbolo}*|{caracterMaiusculo}*|{caracterMinusculo}*)*
%%
{ws} {}
"\n" {linha++;}
"+" {return TADD;}
"-" {return TSUB;}
"*" {return TMUL;}
"/" {return TDIV;}
"(" {return TAPAR;}
")" {return TFPAR;}
"{" {return TACH;}
"}" {return TFCH;}
";" {return TPONTVIR;}
"=" {return TATRI;}
"<" {return TMENOR;}
">" {return TMAIOR;}
"&" {return TE;}
"!" {return TNEG;}
"|" {return TOU;}
"," {return TVIR;}
"while" {return TWHILE;}
"if" {return TIF;}
"else" {return TELSE;}
"print" {return TPRINT;}
"read" {return TREAD;}
"int" {return TINT;}
"String" {return TSTRING;}
"float" {return TFLOAT;}
"return" {return TRETURN;}
"void" {return TVOID;}
{literal} {strncpy(yylval.string, yytext, 10000); return TLITERAL;}
{id} {strncpy(yylval.id, yytext, MAX_ID-1); return TID;}
{numFloat} {yylval.numFloat = atof(yytext); return TNUMFLOAT;}
{numInt} {yylval.numInt = atoi(yytext); return TNUMINT;}
. {printf("ERROR: Erro léxico na linha %d.\n", linha);}