-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractica.l
More file actions
86 lines (55 loc) · 1.2 KB
/
practica.l
File metadata and controls
86 lines (55 loc) · 1.2 KB
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
78
79
80
81
82
83
84
85
86
%{
#include "y.tab.h"
int nLineas=1;
%}
entero [0-9]+
letra [a-zA-Z]
real {entero}+[.]{entero}([eE][-+]?{entero})?
iden [a-zA-Z][a-zA-Z0-9]*
caracter '(.|\\{letra})'
cadena \"[^\"]*\"
bool true|false|TRUE|FALSE
comentarioSimple (\/)(\/).*
linea \n
%%
define { return DEFINE;}
int { yylval.tipo = 1;
return INT;}
float { yylval.tipo = 2;
return FLOAT;}
char { yylval.tipo = 3;
return CHAR;}
string { yylval.tipo = 4;
return STRING;}
boolean {yylval.tipo = 5;
return BOOLEAN;}
main {return MAIN;}
printf {return PRINTF;}
scanf {return SCANF;}
if {return IF;}
else {return ELSE;}
while {return WHILE;}
for {return FOR;}
"||"|"&&" {return OPBOOLEANO;}
"!" {return OPNOT;}
"<"|">"|(">"|"<"|"="|"!")"=" {return COMPARADORES;}
{entero} {yylval.tipo = 1;
return NUM;}
{real} {yylval.tipo = 2;
return NUM;}
{caracter} {yylval.tipo = 3;
return CARACTER;}
{cadena} {yylval.tipo = 4;
return CADENA;}
{bool} {yylval.tipo = 5;
return BOOL;}
{iden} { strcpy(yylval.nombreId,yytext);
return ID;}
{comentarioSimple} ;
{linea} { nLineas++;}
[ \t] ;
. {return yytext[0];}
%%
int yywrap(){
return 1;
}