Premier exercice

This commit is contained in:
Yohann D'ANELLO
2020-05-16 01:51:08 +02:00
commit 2f18fb4e70
10 changed files with 409 additions and 0 deletions

34
lexical/flux.l Normal file
View File

@ -0,0 +1,34 @@
%option noyywrap
%{
enum { T_INT = 1, T_CHAR = 2 };
union {
int i;
char c;
} data;
%}
DIG [0-9]
%%
{DIG}+ { data.i = atoi(yytext); return T_INT; }
[+*()] { data.c = *yytext; return T_CHAR; }
[ \n] { /* ignore */ }
%%
int main (int argc, char **argv)
{
int token;
if (argc > 1) yyin = fopen(argv[1],"r");
while (token = yylex())
{
switch(token)
{
case T_INT: printf("int(%d) ",data.i); break;
case T_CHAR: printf("'%c' ",data.c); break;
}
}
puts("");
}