Error recovery techniques used by compiler

 

The error recovery techniques used by the compiler are as follows:
  1. Panic Mode Recovery
    1. This is the simplest method to implement and can be used by most parsing methods.
    2. 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.
    3. The synchronizing tokens are usually delimiters, such as semicolon or end, whose role in the source program is clear.
  2. Phrase-Level Recovery
    1. 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.
    2. A typical local correction would be to replace a comma by a semicolon, delete an extraneous semicolon or insert a missing semicolon.
    3. It is implemented by filling in the blank entries with the pointers to error routines.
    4. These routines may,
      • change, insert or delete symbols on the input.
      • pop from the stack, and issue appropriate error messages.
  3. Error Productions
    1. 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.
    2. We then use the grammar augmented by these errors productions to construct a parser.
    3. 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.
  4. Global Corrections
    1. In this compiler will make few changes (insertions, deletions, and changes of tokens) as possible in processing an incorrect input string.