-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscanner.l
More file actions
69 lines (53 loc) · 1.94 KB
/
scanner.l
File metadata and controls
69 lines (53 loc) · 1.94 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
%{
#include "y.tab.h"
#include "hash.h"
int lineNumber = 1;
int running = 1;
%}
%x LINE_COMMENT
%x BLOCK_COMMENT
%%
"cara" { return KW_CARA; }
"inte" { return KW_INTE; }
"real" { return KW_REAL; }
"se" { return KW_SE; }
"entaum" { return KW_ENTAUM; }
"senaum" { return KW_SENAUM; }
"enquanto" { return KW_ENQUANTO; }
"entrada" { return KW_ENTRADA; }
"escreva" { return KW_ESCREVA; }
"retorne" { return KW_RETORNE; }
"<=" { return OPERATOR_LE; }
">=" { return OPERATOR_GE; }
"==" { return OPERATOR_EQ; }
"!=" { return OPERATOR_DIF; }
\"(\\\"|[^"])*\" { yylval.symbol = insertHash(SYMBOL_LIT_STRING, yytext); return LIT_STRING; }
'(.|\\[a-z0-9])' { yylval.symbol = insertHash(SYMBOL_LIT_CARA, yytext); return LIT_CHAR; }
(\+|-)?[0-9]*\.[0-9]+ { yylval.symbol = insertHash(SYMBOL_LIT_REAL, yytext); return LIT_FLOAT; }
(\+|-)?[0-9]+ { yylval.symbol = insertHash(SYMBOL_LIT_INTE, yytext); return LIT_INTEIRO; }
[a-z._][a-z0-9._]* { yylval.symbol = insertHash(SYMBOL_IDENTIFIER, yytext); return TK_IDENTIFIER; }
[;()\[\]{}=+\-*/<>&|~] { return yytext[0]; }
[ \t,]
"\n" { ++lineNumber; }
"//" { BEGIN(LINE_COMMENT); }
"///" { BEGIN(BLOCK_COMMENT); }
. { return TOKEN_ERROR; }
<LINE_COMMENT>"\n" { ++lineNumber; BEGIN(INITIAL); }
<LINE_COMMENT>.
<BLOCK_COMMENT>"\n" { ++lineNumber; }
<BLOCK_COMMENT>.
<BLOCK_COMMENT>"\\\\\\" { BEGIN(INITIAL); }
%%
void initMe() {
initHash();
}
int isRunning() {
return running;
}
int getLineNumber() {
return lineNumber;
}
int yywrap() {
running = 0;
return 1;
}