blob: bdf6bb5ced9ecf1284b43094eb05b2ced5eb56b5 (
plain)
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
|
%{
/**
* UPEM / Compilation / Projet
* Pacien TRAN-GIRARD, Adam NAILI
*/
#include "tpc.tab.h"
#define INT 0
#define CHAR 1
int lineno = 1;
%}
%option noinput nounput noyywrap
%x COMMENT
%%
[ \t\r]+ ;
\n { lineno++; }
"/*" { BEGIN COMMENT; }
"&&" { return AND; }
"||" { return OR; }
"*"|"/"|% { yylval.divstar=yytext[0]; return DIVSTAR; }
"+"|- { yylval.addsub=yytext[0]; return ADDSUB; }
"<"|"<="|">"|">=" { strcpy(yylval.comp, yytext); return ORDER; }
==|!= { strcpy(yylval.comp, yytext); return EQ; }
entier { yylval.type = INT; return TYPE; }
caractere { yylval.type = CHAR; return TYPE; }
void { return VOID; }
const { return CONST; }
if { return IF; }
else { return ELSE; }
while { return WHILE; }
return { return RETURN; }
print { return PRINT; }
readc { return READC; }
reade { return READE; }
[a-zA-Z_][a-zA-Z0-9_]* { strcpy(yylval.ident, yytext); return IDENT; }
[0-9]+ { sscanf(yytext, "%d", &(yylval.num)); return NUM; }
'\\?.' { if (strlen(yytext)==3)
yylval.caractere=yytext[1];
else switch(yytext[2]) {
case 'n': yylval.caractere='\n'; break;
case 't': yylval.caractere='\t'; break;
case '\'': yylval.caractere='\''; break;
}
return CARACTERE; }
. { return yytext[0]; }
<COMMENT>"*/" { BEGIN INITIAL; }
<COMMENT>\n { lineno++; }
<COMMENT>. ;
%%
|