-
Notifications
You must be signed in to change notification settings - Fork 2
/
allonsy.l
84 lines (65 loc) · 1.3 KB
/
allonsy.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
78
79
80
81
82
83
%{
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "nodes.h"
#include "y.tab.h"
char buffer_str[200];
%}
CHARACTERS [a-zA-Z_]
DIGITS [0-9]
IDENTIFIER {CHARACTERS}({CHARACTERS}|{DIGITS})*
SIGN (\-|\+){0,1}
INTEGER {DIGITS}+
REAL {INTEGER}\.{INTEGER}
STRING \".*\"
COMMENT \/\/.*\n
TRASH [ \t\n]+
%%
{INTEGER} {
yylval.lval=atol(yytext);
return LONG;
}
{REAL} {
yylval.dval=atof(yytext);
return DOUBLE;
}
"if" return IF;
"else" return ELSE;
"while" return WHILE;
"for" return FOR;
":" return IN;
"++" return INCREMENT;
"--" return DECREMENT;
";" return END;
[-()=+*/\%;{}.,!^\[\]] return *yytext;
"&&" return AND;
"||" return OR;
">" return GREATER;
"<" return LOWER;
">=" return GEQ;
"<=" return LEQ;
"==" return EQ;
"!=" return NEQ;
"add" return ADD;
"pop" return POP;
"read" return READ;
"print" return PRINT;
"nl" return NL;
{IDENTIFIER} {
yylval.sval=(char *)malloc(yyleng*sizeof(char));
strcpy(yylval.sval,yytext);
return VARIABLE;
}
{STRING} {
yytext++;
yyleng--;
yytext[yyleng-1] = '\0';
yylval.sval=(char*)malloc(yyleng*sizeof(char));
strcpy(yylval.sval, yytext);
return STR;
}
{COMMENT} ;
{TRASH} ;
. printf("Carácter inválido: %s\n",yytext);
%%