%{ /* yacc program for CS4905, Lab 2, balanced */ /* parentheses and square brackets. */ /* First cut. */ #include #include #define YYSTYPE double /* double type for yacc stack */ %} %% lines : lines S '\n' { printf("OK \n"); } | lines '\n' | /* empty */ | error '\n' {yyerror("Error: reenter last line:"); yyerrok; } ; S : S '(' S ')' S | S '[' S ']' S | ; %% #include "lex.yy.c" void yyerror(char * s) /* yacc error handler */ { fprintf (stderr, "%s\n", s); } int main(void) {return yyparse();}