What is the different error recovery technique used in parsing? Explain them in brief.

There is three type of error recovery technique used in parsing

  • Panic-Mode Recovery
  • Phrase-Level Recovery
  • Error Productions

Panic-Mode Recovery:

With this method, on discovering an error, the parser discards input symbols one at a time until one of a designated set of synchronizing tokens is found. The synchronizing tokens are usually delimiters, such as a semicolon or }, whose role in the source program is clear and unambiguous. The compiler designer must select the synchronizing tokens appropriate for the source language. While panic-mode correction often skips a considerable amount of input without checking it for additional errors, it has the advantage of simplicity.

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 with some string that allows the parser to continue. A typical local correction is to replace a comma with a semicolon, delete an extraneous semicolon, or insert a missing semicolon.

The choice of the local correction is left to the compiler designer. We must be careful to choose replacements that do not lead to infinite loops, as would be the case, for example, if we always inserted something on the input ahead of the current input symbol.

A phrase-level replacement has been used in several error-repairing compilers, as it can correct any input string. Its major drawback is the difficulty it has in coping with situations in which the actual error has occurred before the point of detection.

Error Productions:

By anticipating common errors that might be encountered, we can augment the grammar for the language at hand with productions that generate the erroneous constructs. A parser constructed from a grammar augmented by these error productions detects the anticipated errors when an error production is used during parsing. The parser can then generate appropriate error diagnostics about the erroneous construct that has been recognized in the input.

Leave a Reply