Compiler Design (2170701)

BE | Semester-7   Winter-2018 | 15/11/2018

Q2) (b)

Explain all error recovery strategies used by parser.

There are mainly four error recovery strategies :

  • Panic mode
  • Phrase level recovery
  • Error production
  • Global generation

Panic Mode

  • In this method on discovering error, the parser discards input symbol one at a time.
  • This process is continued until one of a designated set of synchronizing tokens is found.
  • Synchronizing tokens are delimiters such as semicolon or end.
  • These tokens indicate an end of the statement.
  • If there is less number of errors in the same statement then this strategy is best choice.

Phase Level Recovery

  • In this method, on discovering an error parser performs local correction on remaining input.
  • The local correction can be replacing comma by semicolon, deletion of semicolons or inserting missing semicolon.
  • This type of local correction is decided by compiler designer.
  • This method is used in many error-repairing compilers.
  • Error Production

  • If we have good knowledge of common errors that might be encountered, then we can augment the grammar for the corresponding language with error productions that generate the erroneous constructs.
  • Then we use the grammar augmented by these error production to construct a parser.
  • If error production is used then, during parsing we can generate appropriate error message and parsing can be continued.
  • Global Correction

  • Given an incorrect input string x and grammar G, the algorithm will find a parse tree for a related string y, such that number of insertions, deletions and changes of token require to transform x into y is as small as possible.
  • Such methods increase time and space requirements at parsing time.
  • Global correction is thus simply a theoretical concept.