-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.l
103 lines (82 loc) · 2.35 KB
/
scanner.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
%{
/*
Etapa 4 do trabalho de Compiladores (2017/1)
Professor: Marcelo Johann
Grupo:
Delton Vaz (00229779) (nick: ~davaz)
Flávio Keglevich (00229724)
*/
#include <stdio.h>
#include "semantic.h"
#include "y.tab.h"
int running = 1;
int contadorLinhas = 1;
int getLineNumber(void);
int isRunning(void);
void initMe();
#include "main.c"
%}
DIGITO [0-9]
CARACTERE [_a-zA-Z]
%x COMENTARIO
%%
"byte" {return KW_BYTE;}
"short" {return KW_SHORT;}
"long" {return KW_LONG;}
"float" {return KW_FLOAT;}
"double" {return KW_DOUBLE;}
"bool" {return KW_BOOL;} //Booleano da etapa 4
"when" {return KW_WHEN;}
"then" {return KW_THEN;}
"else" {return KW_ELSE;}
"while" {return KW_WHILE;}
"for" {return KW_FOR;}
"read" {return KW_READ;}
"print" {return KW_PRINT;}
"return" {return KW_RETURN;}
"to" {return KW_TO;}
"<=" {return OPERATOR_LE;}
">=" {return OPERATOR_GE;}
"==" {return OPERATOR_EQ;}
"!=" {return OPERATOR_NE;}
"&&" {return OPERATOR_AND;}
"||" {return OPERATOR_OR;}
true {hash_insert(SYMBOL_LIT_TRUE, yytext); return LIT_TRUE;}
TRUE {hash_insert(SYMBOL_LIT_TRUE, yytext); return LIT_TRUE;}
false {hash_insert(SYMBOL_LIT_FALSE, yytext); return LIT_FALSE;}
FALSE {hash_insert(SYMBOL_LIT_FALSE, yytext); return LIT_FALSE;}
[-;:,(){}+*/<>=!&$#]|"]"|"[" {return yytext[0];}
{CARACTERE}({CARACTERE}|{DIGITO})* {hash_insert(SYMBOL_IDENTIFIER, yytext);return TK_IDENTIFIER;}
{DIGITO}+ {hash_insert(SYMBOL_LIT_INT, yytext);return LIT_INTEGER;}
{DIGITO}+\.{DIGITO}+ {hash_insert(SYMBOL_LIT_REAL, yytext);return LIT_REAL;}
\"(\\.|[^\\"|^\n])*\" {hash_insert(SYMBOL_LIT_STRING, yytext);return LIT_STRING;}
"'"("\\".|[^'\n])"'" {hash_insert(SYMBOL_LIT_CHAR, yytext);return LIT_CHAR;}
\/\/.*
\n {contadorLinhas++;}
[ \t\v\f]
"/*" BEGIN(COMENTARIO);
<COMENTARIO>. ;
<COMENTARIO>\n {contadorLinhas++;}
<COMENTARIO>"*/" BEGIN(INITIAL);
. {return TOKEN_ERROR;}
%%
int getLineNumber(void)
{
return contadorLinhas;
}
int isRunning(void)
{
return running;
}
int yywrap(void)
{
if (!feof(yyin))
running = 1;
else
running = 0;
return 1;
}
void initMe()
{
hashStart();
}