-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.flex
61 lines (52 loc) · 1.4 KB
/
scanner.flex
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
%{
// HEADERS
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "parser.h"
#define SAVE_TOKEN yylval.string = new std::string(yytext, yyleng)
#define TOKEN(t) (yylval.token = t)
// variables maintained by the lexical analyser
int yyline = 1;
%}
%option noyywrap
VAR [a-zA-Z_]
DIGIT \-?[0-9]+
%%
#.*\n { yyline++;}
[ \t]+ { }
\n { yyline++;}
"func main()" { return FMAIN; }
"{" { return LBRACKET; }
"}" { return RBRACKET; }
"+" {return SUM;}
"-" {return SUB;}
"*" {return MUL;}
"/" {return DIV;}
"%" {return MODUL;}
"true" {return TRUE;}
"false" {return FALSE;}
"<" {return LT;}
">" {return GT;}
"<=" {return LET;}
">=" {return GET;}
"==" {return COMP;}
"~=" {return DIF;}
"&&" {return AND;}
"||" {return OR;}
"!" {return NOT;}
"if" {return IF;}
"else" {return ELSE;}
"elseif" {return ELSEIF;}
"for" {return FOR;}
":=" {return ATRIB;}
";" {return DOTCOMA;}
"(" {return LPARENTH;}
")" {return RPARENTH;}
"Sprint(\"\%d\"," {return SPRINT;}
"Sscan(\"\%d\"," { return SSCAN; }
{DIGIT}+ {yylval.INT=atoi(yytext);return INT;}
{VAR}+ {yylval.identifier=strdup(yytext);return VARIABLE;} /* nao pode haver palavras (ie: if) abaixo desta regra ou nao encaixam, porque encaixam sempre nesta */
. { yyerror("unexpected character"); }
%%