%option nounput noinput %{ #include "proto-color.h" void echo(char *lex_cat) { fprintf(stdout,GREEN("[%s:%s]"), lex_cat, yytext); } void echo2(char *lex_cat) { fprintf(stdout,RED("[%s:%s]"), lex_cat, yytext); } int nb_v = 0, nb_mots = 0, nb_lignes = 0, nb_punct = 0; %} /* Accents : a partir des presents dans fichiers de test */ ACC_latin1 [\340\351\364] ACC_latin1bis [àéô] ACC_latin15 [\275]|{ACC_latin1} ACC_utf8 (\303\240|\303\251|\303\264|\305\223) ACC_utf8bis (à|é|ô|Å“) CAR [[:alpha:]]|{ACC_latin15}|{ACC_utf8} /*autre approche par negation ou separateur : */ CARbis [^ \n\t[:punct:]] MOT {CAR}* MOT_COMP {MOT}(-{MOT})* %% [vV]{MOT} {echo2("VMot"); nb_mots ++; nb_v ++;} {MOT} {echo("MOT"); nb_mots ++;} [[:punct:]] {nb_punct ++;} /* les - ou ' interne au mot ne sont pas compté */ \n nb_lignes++; ECHO; [ \t] . echo("UNK"); %% int yywrap(void) { printf("\n nb_v = %d, nb_mots = %d, nb_punct = %d, nb_lignes = %d\n", nb_v, nb_mots, nb_punct, nb_lignes); return 1; } int main(int argc, char *argv[]) { while (yylex()!=0) ; return 0; }