// bisongrammar-1.y %{ #include #include #include extern int yylex(void); extern void yyerror(const char *message); %} %define parse.error verbose %% S : 'a' T | 'a' 'b' T ; T : T 'a' | 'c' | U ; U : 'c' ; %% void yyerror(const char *message) { printf("The Bison-generated parser found an error: %s\n", message); exit(EXIT_FAILURE); } // A simple scanner. // Returns one of the tokens 'a', 'b' or 'c', or EOF. Other input is ignored. int yylex(void) { int input; while ((input = getchar()) != 'a' && input != 'b' && input != 'c' && input != EOF) ; return input; } int main(void) { printf("Bisongrammar-1. Enter input. End with EOF (CTRL-D on Linux).\n"); yyparse(); printf("Done!\n"); return EXIT_SUCCESS; }