/* les identificateurs d'un programme java classés alphabétiquement */ %option noyywrap %{ int niveauComment = 0; char **idents; int nbIdents = 0; %} %x COMMENTLIGNE COMMENTIMBRIQUE KEYWORDS abstract|boolean|break|byte|case|catch|char|class|continue|default|do|double|else|extends|false|final|finally|float|for|if|implements|import|instanceof|int|interface|long|native|new|null|package|private|protected|public|return|short|static|super|switch|synchronized|this|throw|throws|transient|true|try|void|volatile|while NEWLINE "\n" DIGIT [0-9] ENTIER {DIGIT}+ DECIMALE "."{DIGIT}* SUFFIXE E{ENTIER} REEL {ENTIER}{DECIMALE}?{SUFFIXE}? IDENT [a-zA-Z$]([a-zA-Z$_0-9]*("."))*[a-zA-Z$_0-9]* COMMENTLIGNEDEBUT "//" COMMENTIMBRIQUEDEBUT "/*" COMMENTIMBRIQUEFIN "*/" %% {KEYWORDS}|{NEWLINE}|{DIGIT}|{ENTIER}|{REEL} {} {IDENT} { nbIdents++; idents = realloc(idents,nbIdents*(sizeof (char *))); idents[nbIdents-1]=strcpy(malloc(strlen(yytext)),yytext); } {COMMENTLIGNEDEBUT} {BEGIN(COMMENTLIGNE);} {COMMENTIMBRIQUEDEBUT} {niveauComment++;BEGIN(COMMENTIMBRIQUE);} {NEWLINE} {BEGIN(INITIAL);} {COMMENTIMBRIQUEDEBUT} {niveauComment++;} {NEWLINE} {} {COMMENTIMBRIQUEFIN} { niveauComment--; if (niveauComment==0){ BEGIN(INITIAL); } } <*>. {} %% void afficher(char **liste, int taille) { char **aux; for (aux=liste; aux < liste + taille; aux++) printf("%s\n",*aux); } int compare(void **ch1, void **ch2){ return strcmp(*ch1,*ch2); } main () { yylex(); qsort(idents, nbIdents, sizeof (char *), (int (*)(const void *, const void *))compare); afficher(idents,nbIdents); }