-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscanner.flex
84 lines (59 loc) · 1.24 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
%{
// HEADERS
#include <stdlib.h>
#include "parser.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;
}
([0-9]+([.][0-9]*)?|[.][0-9]+) {
yylval.floatValue = atof(yytext);
return FLOAT;
}
"main" { return MAIN; }
"if" { return IF; }
"else" { return ELSE; }
"int" { return INTD; }
"float" { return FLOATD; }
"printf" { return PRINT; }
"scanf" { return SCAN; }
"while" { return WHILE; }
";" { return SEMICOLON; }
"=" { return EQUAL; }
"(" { return OPENPARENTHESIS; }
")" { return CLOSEPARENTHESIS; }
"{" { return OPENCURLYBRACKETS; }
"}" { return CLOSECURLYBRACKETS; }
"," { return COMMA; }
"&" { return '&'; }
"+" { return PLUS; }
"-" { return SUB; }
"*" { return MUL; }
"/" { return DIV; }
"%" { return MOD; }
"||" { return OR; }
"&&" { return AND; }
"==" { return IGU; }
"!=" { return DIF; }
"<" { return LES; }
"<=" { return LOQ; }
">" { return GRE; }
">=" { return GOQ; }
\".*?[^\\]\" {
yylval.typesValue = strdup(yytext);
return TYPES;
}
[a-zA-Z_][a-zA-Z0-9]* {
yylval.stringValue = strdup(yytext);
return VAR;
}
. { yyerror("unexpected character"); }
%%