%{ extern int yylex(); #include #include "proto-color.h" int yyerror (char const *message) { fprintf(stderr,RED("<%s>")"\n", message); return 0; } void print(char * msg) { fprintf(stdout,BLUE("%s"),msg); } %} %error-verbose %token MAJWORD MINWORD QUOTED '.' ',' %% Text: Sentence | Text Sentence Sentence: MAJWORD Words '.' { print("SENTENCE1"); } | QUOTED Words '.' { print("SENTENCE2"); } Words : /* eventuellement vide */ | Words Word Word : MINWORD { print("min"); } | MAJWORD { print("maj"); } | QUOTED { print("quoted"); } | ',' { print(","); } ; %% int main(void) { return yyparse(); }