Error recovery techniques used by compiler
The error recovery techniques used by the compiler are as follows:
- Panic Mode Recovery
- This is the simplest method to implement and can be used by most parsing methods.
- On discovering an error, the parser discards the input symbol one at a time. until one of the designated set of synchronizing token is found.
- The synchronizing tokens are usually delimiters, such as semicolon or end, whose role in the source program is clear.
- Phrase-Level Recovery
- On discovering an error, a parser may perform local correction on the remaining input, that is it may replace a prefix of the remaining input by some string that allows the parser to continue.
- A typical local correction would be to replace a comma by a semicolon, delete an extraneous semicolon or insert a missing semicolon.
- It is implemented by filling in the blank entries with the pointers to error routines.
- These routines may,
- change, insert or delete symbols on the input.
- pop from the stack, and issue appropriate error messages.
- Error Productions
- If we have a good idea that the common errors that might be encountered, we can augment the grammar for the language at hand with productions that generate the erroneous constructs.
- We then use the grammar augmented by these errors productions to construct a parser.
- If an error production is used by the parser, we can generate appropriate diagnostics to indicate the erroneous construct that has been recognized in the input.
- Global Corrections
- In this compiler will make few changes (insertions, deletions, and changes of tokens) as possible in processing an incorrect input string.