%{ #include #include "proto-color.h" extern int yylex(); int yyerror (char const *message) { fprintf(stderr,RED("<%s>")"\n", message); return 0; } void Prompt(){ printf("yash> "); } /* Yet Another Shell */ %} %error-verbose %token HELLO THANKS FUCK BYE %token NEWLINE CMD_SEP %% Shell : {Prompt();} | Shell Line NEWLINE {Prompt();} | Shell error NEWLINE {yyerrok; printf(BLUE("Ligne invalide")"\n"); Prompt();} ; Line : Command | Line CMD_SEP Command | error CMD_SEP /* Action a l'interieur d'une regle pour avoir le printf dans l'ordre */ {yyerrok; printf(BLUE("Command invalide: \n"));} Command ; Command : | Builtin // | Others ; Builtin : HELLO {printf("Nice to meet you\n");} | THANKS {printf("You are welcome\n");} | FUCK {yyerror("Semantic Error : Censored !"); YYERROR;} | BYE {printf("See you\n"); return(0);} ; %% int main(void) { return yyparse(); }