Premier exercice
This commit is contained in:
29
lexical/example.l
Normal file
29
lexical/example.l
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user