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

29
lexical/example.l Normal file
View File

@ -0,0 +1,29 @@
%option noyywrap
%{
int lines = 1; // On compte la première ligne
%}
DIG [0-9]
HEX 0x[0-9A-Fa-f]+
%%
{HEX} { printf("hex(%d)", strtol(yytext, NULL, 16)); }
{DIG}+ { printf("int(%d)", atoi(yytext)); }
"if" { printf("IF"); }
"then" { printf("THEN"); }
"else" { printf("ELSE"); }
\n { lines++; }
. { /* Pour tous les autres caractères, on ne fait rien */ }
%%
int main (int argc, char **argv)
{
if (argc > 1) yyin = fopen(argv[1], "r");
yylex();
puts("");
printf("%d lignes\n", lines);
return 0;
}