%% %include Jflex.include %{ /* code dans la classe : attributs et méthodes utiles pour les actions */ int nbmot=0, nbcar=0, nbligne=0; %} %init{ /* code dans le constructeur : action initiale */ System.out.println("Entete mail RFC822 , Super-etats, et WC"); %init} %eof{ /* code en action final */ System.out.println("CORPS-WC : "+(nbligne+1)+" " + nbmot+ " " + nbcar); System.out.println("Bye!"); %eof} %state CORPS %s HEAD ASCII7 = [\x00-\x7F] /* == printable - " "(\x20) - ":"(\x3A) */ HEADCAR = [\x21-\x39\x3B-\x7E] /* titre de header */ HNAME = {HEADCAR}+ /*contenu de header jusqu'a la fin de ligne*/ HLINE = .* /*continuation de header multiligne*/ HCONT = \R[ \t] MOT = [a-zA-Z]+ SEP = [^a-zA-Z\n] /* definition simpliste pour les mots, alphabetique only */ /* de facon generale on doit avoir MOT + SEP + '\n' == ASCII7 */ /* mais on peut aussi utiliser une regle balai pour se passer de SEP+ */ %% ^{HNAME} { yybegin(HEAD); ECHO("NOM-CHAMPS"); } {MOT} { nbcar+=yylength(); nbmot++; } {SEP}+ { nbcar+=yylength(); } {HCONT} { nbcar+=yylength(); nbligne++;} \R\R { yybegin(CORPS); System.out.println(" WC : "+(nbligne+1) +" " + nbmot + " " + nbcar); nbligne=nbmot=nbcar=0; } \R { yybegin(YYINITIAL); /*next header*/ System.out.println(" WC : "+(nbligne+1) +" " + nbmot + " " + nbcar); nbligne=nbmot=nbcar=0; } {MOT} {nbcar+=yylength(); nbmot++;} {SEP}+ {nbcar+=yylength();} \R {nbcar+=yylength();nbligne++;} [^] { WARN("Invalid char '"+yytext()+"'"); }