%{ /* * Example 1-7: Simple yacc sentence parser ch1-05.byacc * * A lexer for the basic grammer to use for recognizing English sentences. */ #include %} %token NOUN PRONOUN VERB ADVERB ADJECTIVE PREPOSITION CONJUNCTION %% sentence: subject VERB object { printf("Sentence is valid.\n"); } ; subject: NOUN | PRONOUN ; object: NOUN ; %% extern FILE *yyin; main() { while(!feof(yyin)) { yyparse(); } } yyerror(s) char *s; { fprintf(stderr, "%s\n", s); }