%{ #include extern void yyerror(char*); %} %token SPECIES DECLARATIONS DONE NAME OBSERVATION OBSERVATIONS NUMBER %define parse.error verbose %start input %% input : manydeclarations DECLARATIONS DONE manyobservations OBSERVATIONS DONE { printf("Done!\n"); } ; manydeclarations : onedeclaration manydeclarations | /* empty */ ; onedeclaration : SPECIES NAME ; manyobservations : oneobservation manyobservations | /* empty */ ; oneobservation : OBSERVATION NAME NUMBER ; %% int main() { printf("Enter a complete animal input. End with the keyword \"done\" and EOF.\n"); yyparse(); printf("Ok!\n"); return 0; } void yyerror(char *s) { printf("Incorrect animal input! Error message: %s\n", s); } int yywrap(void) { return 1; }