Make bison reduce to start symbol only if EOF is found
I am using Bison with Flex. I have the following rule in my Yacc input file: program : PROGRAM m2 declarations m0 block {cout << "Success\n"} ; The problem is that if I have a program that is partially correct, but then there is some "garbage" before EOF, it will reduce according to the previous rule, report "success" and only then report an error. I want to include EOF at the end of the rule above, but then, Flex would have to return EOF when it read <<EOF>> , and how would Bison know when to end the program? Now, I have this in Flex: <<EOF>> {return 0;} Here is an example that would do that: