|
|
Hints on Error Recovery in YACC Parsers
To control error recovery, you may use:
- The error symbol.
The error symbol may be included on the right-hand-side of a production. In
case of a syntax error, the parser generates an error token,
discards the stack until a state with the error token is found
and then it shifts the error token onto the stack. Eventually,
if the current lookahead token is not possible (in the new state), the
parser skips the input tokens until a legal token is found. Afterwards,
the parsing resumes.
- The yyerrok action.
The yyerrok action places the YACC-generated parser back into
its "normal" state. Issuing of error messages resumes immediately afterwards.
Without the yyerrok call, the error messages are suppressed
until three tokens are properly shifted and the parser resets itself
back to narmal state.
- The yyclearin action.
The yyclearin action discards the current lookeahed symbol.
Without the yyclearin call, the token is reused.
- The macro YYRECOVERING
The YYRECOVERING macro indicates (when non-zere) that the parser
is currently recovering from an error (no errors messages are issued).
Consult the section on error recovery
in Bison (replacement of YACC) in the on-line manual.
Small examples are available:
- A small grammar with several error-recovery
steps. The associated Lex specification
is also available.
|