Search code examples
bisonreduce-reduce-conflict

How do i tell bison there is a syntax error?


What happen is there is a specific case where after analyzing the AST i will know if there is an error or not when the rule is finished. I tried yyerror("blah") with no luck.

Because i cant tell it there is an error it finishes another rule and now has a reduce/reduce conflict. This is annoying because i KNOW when one of them is invalid without looking at the other but the user has to suffer bc i dont know how to say ignore this branch bc its invalid

How do i fix this problem?


Solution

  • You want YYERROR not yyerror -- putting YYERROR in an action causes the parser to make the action a syntax error, and go into error recovery mode (if you have any error recovery actions in your parser -- otherwise this is more or less equivalent to YYABORT). yyerror is a routine that bison calls with error messages -- the default implementation is to print the error message -- but is has nothing (specifically) to do with parsing or syntax errors.

    Note that this has no relation to any reduce-reduce (or shift-reduce) conflicts -- conflicts are not errors, they are things in your grammar that make it not-LALR(1), so that the bison generated parser can't reliably recognize it.