-
Notifications
You must be signed in to change notification settings - Fork 0
/
scanner.flex
60 lines (53 loc) · 1.32 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
%{
// HEADERS
#include <stdlib.h>
#include "parser.h"
#include <string.h>
// variables maintained by the lexical analyser
int yyline = 1;
%}
%option noyywrap
%%
[ \t]+ { }
#.*\n { yyline++; }
\n { yyline++; }
\-?[0-9]+ {
yylval.intValue = atoi(yytext);
return INT;
}
"+" { return PLUS; }
"-" { return LESS; }
"*" { return MULT; }
"/" { return DIV; }
"%" { return REST; }
"==" { return EQUAL; }
"&&" { return AND; }
"||" { return OR; }
"!=" { return NOTEQUAL; }
">=" { return GREATER_OR_EQUAL; }
"<=" { return LESSER_OR_EQUAL; }
">" { return GREATER; }
"<" { return LESSER; }
"=" { return ATRIB; }
"while" { return WHILE; }
"if" { return IF; }
"else" { return ELSE; }
"{" { return OPEN_BRACKETS; }
"}" { return CLOSE_BRACKETS; }
"func" { return FUNC; }
"main" { return MAIN; }
"(" { return OPEN_PARENTESIS; }
")" { return CLOSE_PARENTESIS; }
";" { return SEMICOLON; }
"int" { return INT_TYPE; }
"%d" { return INT_OP;}
"," { return COMMA;}
["] { return QUOTATION;}
"printf" { return PRINTF;}
"scanf" { return SCANF;}
[a-z][a-z0-9]* {
yylval.id = strdup(yytext);
return VAR;
}
. { yyerror("unexpectede character"); }
%%