TP de compilation : une solution de l'exercice 5 du TP 3
 
%{
int n=0;
int w=0;
%}
%s ERREUR
%%
^\n                {return 0;}
N                  {n++;}
S                  {n--;}
W                  {w++;}
E                  {w--;}
[A-DF-MP-RT-VX-Z]  ;
.                  {BEGIN(ERREUR);}
<ERREUR>\n         { printf("mot refusé\n"); BEGIN(INITIAL); }
<INITIAL>\n        { if ((n==0)&&(w==0))
                        printf("mot accepté\n");
                     else printf("mot refusé\n");
                     n=0; w=0; }

© 2000, 2017 – A. Sigayret