bison

How to determine if yyerror() was called while recovering from an error?


How can I determine, from inside yyerror(), whether the error message was issued during error recovery? YYRECOVERING() can only be used in actions, but not within yyerror().


Solution

  • From Bison manual:

    After yyerror returns to yyparse, the latter will attempt error recovery if you have written suitable error recovery grammar rules (see Error Recovery). If recovery is impossible, yyparse will immediately return 1.

    When yyerror runs, the parser didn't attempted the recovery yet. It happens after the function returns.