For simplification of the original problem, supposed I wanted to parse a string of left and right parentheses. The flex file would have the tokens
"(" return LPAREN
")" return RPAREN
and the bison file would have the productions
completedparse: pair {printf("Success!\n");}
;
pair: LPAREN pair RPAREN
| LPAREN RPAREN pair
| LPAREN RPAREN
;
IF given the string "(()()(()))" or "()()(())" It would succeed.
The problem I have is that "(()()))" would print the success statement, immediately before failure. I know that bison creates the production
$accept: completedparse $end
which is how bison accepts or rejects the string. All my problems would go away if I could write my own $accept production and include any print statements in that production. But according to the 3.0.2 manual $accept cannot be used in the grammar.
My problems would also go away if I could modify the return value of yyparse() (assume that I need more information than just 0 => success, 1 => failure). I don't think this is possible though.
If you have any insight please respond, and thanks for any help!