%{ #include extern void yyerror(const char *); extern int yylex(void); %} %token BEGAN CANDY ROUND SEMICOLON TRICK TREAT COLON WORD WENT HOME %define parse.error verbose %start candy_round %% candy_round : BEGAN CANDY ROUND SEMICOLON trick_or_treat_list WENT HOME SEMICOLON ; trick_or_treat_list: trick_or_treat trick_or_treat_list | /* empty */ ; trick_or_treat : TRICK COLON word_list SEMICOLON | TREAT COLON word_list SEMICOLON ; word_list : WORD | WORD word_list ; %% int main() { printf("Enter a complete candy round. Finsih with EOF.\n"); yyparse(); printf("Done!\n"); return 0; } void yyerror(const char *s) { printf("Invalid candy round! Error message: %s\n", s); } int yywrap(void) { return 1; }