-
Notifications
You must be signed in to change notification settings - Fork 6
/
ce.lex
58 lines (42 loc) · 1.11 KB
/
ce.lex
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
%option noyywrap
%{
#include "ast.h"
#include "ce.tab.h"
%}
NUMERO [0-9]*
LETRA [A-Za-z_]
VARIAVEL [A-z_][0-9A-z_]*
SEPARADOR [ \t]+
NL ("\n"|"\r"|"\t")*
TIPO (int|char|long|void|short)
ATRIBUICAO "="
MAIOR ">"
MENOR "<"
IGUAL "=="
MAIOR_IGUAL ">="
MENOR_IGUAL "<="
DIFERENTE "!="
SOMA "+"
SUBTRACAO "-"
DIVISAO "/"
MULTIPLICACAO "*"
%%
{NL}";"{NL} {return SEPARADOR;}
"(" {return L_PAREN;}
")" {return R_PAREN;}
"{" {return L_COLCH;}
"}" {return R_COLCH;}
"+" {yylval.string = strdup(yytext); return SOMA;}
"-" {yylval.string = strdup(yytext); return SUBTRACAO;}
"*" {yylval.string = strdup(yytext); return MULTIPLICACAO;}
"/" {yylval.string = strdup(yytext); return DIVISAO;}
{NUMERO} {yylval.number = atof(yytext); return NUMERO;}
{TIPO} {yylval.string = strdup(yytext); return TIPO;}
{VARIAVEL} {yylval.string = strdup(yytext); return VARIAVEL;}
{ATRIBUICAO} {yylval.caracter = yytext[0]; return ATRIBUICAO;}
%%
/**
main(int argc, char* argv[])
{
yylex();
}*/