forked from netoax/gringo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lex_gringo.l
89 lines (75 loc) · 2.28 KB
/
lex_gringo.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
84
85
86
87
88
89
/*
Analisador Léxico do GRINGO (Linguagem C)
Flex Scanner of GRINGO (C Language)
Tokens sugeridos:
Suggested tokens:
CHAR, INT, FLOAT, DOUBLE, VOID, UNSIGNED, SIGNED, SHORT, LONG, CONST,
VOLATILE, EXTERN, STATIC, REGISTER, AUTO, SIZEOF,
EQUAL, SUBTRACT, ADD, MUL, DIV, REST, GREATER_THEN, LESS_THEN, NOT,
ECOMM, XOR, TILDE, MARK, COMMA, DOT, TWO_DOTS, DOT_COMMA, PAR_L,
PAR_R, COL_L, COL_R, BRA_L, BRA_R, QUOTE, DOUBLE_QUOTE,
IF, ELSE, SWITCH, CASE, BREAK, DEFAULT, FOR, WHILE, DO, RETURN, EXIT,
CONTINUE, NULL,
IDENTIFIER, LITERAL_INT, LITERAL_DOUBLE, HEXADECIMAL, OCTAL,
NEW_LINE, CARRIAGE_RETURN, TAB, BACKSLASH, BAR_ZERO
*/
%{
#include "bison_gringo.hpp"
%}
%option noyywrap nodefault
%%
"char" { return CHAR; }
"int" { yylval.type = 1;return INT;}
"float" { yylval.type = 2;return FLOAT; }
"double" { yylval.type = 3;return DOUBLE; }
"void" { yylval.type = 0;return VOID; }
"unsigned" { return UNSIGNED; }
"const" { return CONST; }
"static" { return STATIC; }
"log" {return LOG2;}
"exp" {return EXP;}
"=" { return EQUAL; }
"-" { return SUBTRACT; }
"+" { return ADD; }
"*" { return MUL; }
"/" { return DIV; }
"%" { return REST; }
"==" { return DOUBLE_EQUAL; }
"!=" { return DIFFERENT; }
">" { return GREATER_THEN; }
">=" { return GREATER_EQUAL_THEN; }
"<" { return LESS_THEN; }
"<=" { return LESS_EQUAL_THEN; }
"!" { return NOT; }
"^" { return XOR; }
"sizeof" { return SIZEOF; }
"," { return COMMA; }
"." { return DOT; }
":" { return TWO_DOTS; }
";" { return SEMICOLON; }
"(" { return PAR_L; }
")" { return PAR_R; }
"[" { return COL_L; }
"]" { return COL_R; }
"{" { return BRA_L; }
"}" { return BRA_R; }
\' { return QUOTE; }
\" { return DOUBLE_QUOTE; }
"if" { return IF; }
"else" { return ELSE; }
"break" { return BREAK; }
"for" { return FOR; }
"while" { return WHILE; }
"return" { return RETURN; }
"exit" { return EXIT; }
"continue" { return CONTINUE; }
[a-zA-Z_][a-zA-Z0-9_]* { yylval.id_value = strdup(yytext); return IDENTIFIER; }
[0-9]+ { yylval.int_value = atoi(yytext); return LITERAL_INT; }
[0-9]+[\.][0-9]+ { yylval.double_value = atof(yytext); return LITERAL_DOUBLE; }
"\r" { return CARRIAGE_RETURN; }
"\t" { return TAB; }
[\\] { return BACKSLASH; }
"\0" { return BAR_ZERO; }
[\n\r\t ]+ {}
. { printf("Caractere inválido: %s",yytext); exit(1); }
%%