-
Notifications
You must be signed in to change notification settings - Fork 0
/
lexique.l
executable file
·60 lines (50 loc) · 1.16 KB
/
lexique.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
%option yylineno
%{
#include <stdio.h>
#include "y.tab.h"
%}
blancs [ \n\t]+
letter [a-zA-Z]
digit [0-9]
integer {digit}+
exposant [eE][+-]?{integer}
%%
"main" {return tMAIN;}
"printf" {return tPRINTF;}
"{" {return tOPENED_BRACKET;}
"}" {return tCLOSED_BRACKET;}
"void" {return tVOID;}
"return" {return tRETURN;}
"const" {return tCONST;}
"if" {return tIF;}
"else" {return tELSE;}
"while" {return tWHILE;}
"int" {return tINT;}
"!" {return tNOT;}
">" {return tGREATERTHAN;}
"<" {return tLOWERTHAN;}
"+" {return tADD;}
"-" {return tMINUS;}
"*" {return tMUL;}
"/" {return tDIV;}
"=" {return tEQUAL;}
"(" {return tOPENED_PARENTHESIS;}
")" {return tCLOSED_PARENTHESIS;}
"," {return tCOMMA;}
"\\n" {return tNEWLINE;}
";" {return tSEMICOLON;}
{integer}{exposant} {
yylval.nb = (int) atof(yytext);
return tINTEGER_EXP_FORM;
}
{integer} {
yylval.nb = atoi(yytext);
return tINTEGER_DEC_FORM;
}
{letter}[a-zA-Z0-9_]* {
yylval.var = strdup(yytext);
return tID;
}
{blancs} {};
. {return tERROR;}
%%