-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler.l
executable file
·45 lines (35 loc) · 911 Bytes
/
compiler.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
%{
#include "compil.tab.h"
#include "tabStruct.h"
#include "tabInstruct.h"
%}
%%
"int main()" { return tMAIN;}
"const" { return tCONST;}
"int" { return tINT;}
"==" { return tEGAL_EGAL;}
">=" { return tSUP_EGAL;}
"<=" { return tINF_EGAL;}
"=" { return tEGAL;}
"!=" { return tNEGAL;}
"-" { return tSOUSTR;}
"+" { return tADD;}
"*" { return tMUL;}
"/" { return tDIV;}
"(" { return tPO;}
")" { return tPF;}
"}" { return tAF;}
"{" { return tAO;}
">" { return tSUP;}
"<" { return tINF;}
"printf" { return tPRINT;}
"if" { return tIF;}
"else" { return tELSE;}
"while" { return tWHILE;}
[a-zA-Z]+[a-zA-Z0-9_]* { yylval.str = strdup(yytext);return tVAR;}
[-]?[0-9]+([.][0-9]+)? {yylval.nb = atoi(yytext);return tDEC;}
[-]?[0-9]+([.][0-9]+)?([e][-]?[1-9][0-9]*) { yylval.nb = atoi(yytext);return tEXP;}
";" { return tEND;}
"," { return tVIRG;}
[ \t\n] ;
%%