%{ #include using namespace std; /* This is a nonsense grammar from a programming contest: the lowercase words are non-terminals, the uppercase characters are the terminals of this language. slurpy -> slimp slump slimp -> A H | A B slimp C | A slump C slump -> d_or_e f_string end d_or_e -> D d_or_e -> E f_string -> F f_string | F end -> slump end -> G Some strings in the language: AHDFG, ADFGCDFFFFFG, ABAEFGCCDFEFFFFFFG Some strings NOT in the lanuage: AHDFGA, DFGAH, ABABCC */ extern int lineno; void yyerror(char *); int yylex(); %} %token EOLN %% slurpy_language : slurpy_language slurpy | slurpy ; slurpy : slimp slump EOLN ; slimp : 'A' 'H' | 'A' 'B' slimp 'C' | 'A' slump 'C' ; slump : d_or_e f_string end ; d_or_e : 'D' | 'E' ; f_string: f_string 'F' | 'F' ; end : slump | 'G' ; %% void yyerror(char *s) { cout << "Syntax error on line " << lineno << endl; }