%{ #include extern void yyerror(const char *); extern int yylex(void); %} %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(const char *s) { printf("Incorrect animal input! Error message: %s\n", s); } int yywrap(void) { return 1; }