-
Notifications
You must be signed in to change notification settings - Fork 0
/
flex.l
executable file
·68 lines (56 loc) · 1.96 KB
/
flex.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
%option header-file="flex.lex.h"
%option noyywrap
%{
#include "bison.tab.h"
#include "dichiarazioni.h"
%}
%%
"global_variables" { return VAR; }
"events" { return EVENT; }
"commands" { return COMMAND; }
"state" { return STATE; }
"actions" { return ACTION; }
"char" { yylval.fn = 10; return TYPE; }
"int" { yylval.fn = 11; return TYPE; }
"float" { yylval.fn = 12; return TYPE; }
"double" { yylval.fn = 13; return TYPE; }
"void" { yylval.fn = 14; return TYPE; }
"if"|"IF" { return IF; }
"elif"|"ELIF" { return ELIF; }
"else"|"ELSE" { return ELSE; }
"for"|"FOR" { return FOR; }
"while"|"WHILE" { return WHILE; }
"inc" { yylval.fn = 24; return OPERATORE; }
"dec" { yylval.fn = 25; return OPERATORE; }
"set" { yylval.fn = 26; return OPERATORE; }
print_schermo_message { yylval.fn = 40; return PRINT; }
[0-9]+ { yylval.fn = atof(yytext);return NUMBER; }
([a-z]+['_a-z0-9]*) { yylval.c = lookup(yytext); return ALPHA; }
"+" { yylval.fn = 20; return OPERATORE; }
"-" { yylval.fn = 21; return OPERATORE; }
"*" { yylval.fn = 22; return OPERATORE; }
"/" { yylval.fn = 23; return OPERATORE; }
">" { yylval.fn = 1; return CMP; }
"<" { yylval.fn = 2; return CMP; }
"!=" { yylval.fn = 3; return CMP; }
"==" { yylval.fn = 4; return CMP; }
">=" { yylval.fn = 5; return CMP; }
"<=" { yylval.fn = 6; return CMP; }
"&&" { yylval.fn = 7; return CMP; }
"||" { yylval.fn = 8; return CMP; }
"(" { return LPAREN; }
")" { return RPAREN; }
"{" { return LBRACE; }
"}" { return RBRACE; }
";" { return SEMI; }
"," { return COMMA; }
"=" { return ASSIGN; }
"//".*
[ \t ]
\\\n
"\r"
"#" { return COMMENT; }
"=>" { return CHANGESTATE; }
. { yyerror("Mystery character %c\n", *yytext); printf("Unknown token!\n"); yyterminate();}
<<EOF>> {return 1;}
%%