aboutsummaryrefslogtreecommitdiff
path: root/src/tpc.lex
blob: eaeea89aff40c482a5d6098ea0de5b6fa42ebd0b (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
%{
/**
  * UPEM / Compilation / Projet
  * Pacien TRAN-GIRARD, Adam NAILI
  */

#include "tpc.tab.h"

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; }
int                     { strcpy(yylval.type, yytext); return TYPE; }
float                   { strcpy(yylval.type, yytext); return TYPE; }
double                  { strcpy(yylval.type, yytext); return TYPE; }
char                    { strcpy(yylval.type, yytext); return TYPE; }
void                    { return VOID; }
const                   { return CONST; }
if                      { return IF;}
else                    { return ELSE;}
while                   { return WHILE; }
return                  { return RETURN; }
[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>.              ;
%%