Skip to content
Related Articles
Open in App
Not now

Related Articles

What is Error recovery

Improve Article
Save Article
  • Last Updated : 01 Sep, 2021
Improve Article
Save Article

Error Recovery :
This is a process that takes action against the error to get the negative effects reductions as much as possible, also known as the ability of the compiler in which it takes action and resumes parsing after taking an action over syntactical error if required. When we are talking about Error Recovery we must take about first Error Detection.

Error Detection :

  • All the possible errors that are detected by the compilers are directly been reported to the user in form of error messages this detection of errors is called error detection.
  • Now if we talk about the error detection relation to error recovery then, when we get such an error from the compiler we have to write the error recovery for that to check the code that is also known as error correction.
  • For getting into deep we have to understand the types of errors and their recovery at various stages.
  • Firstly, the parser in the compiler must be able to detect and report to the user any error in the program while the compilation process, when an error is encountered, the parser present should be able to handle it and pass it to carry on parsing the rest of the input.

Types of Error :
There are four types of errors that can be encountered at various stages during the compilation are as follows.

  1. Lexical Error: when some of the identifier names are misspelled or not detected then this error occurs.
  2. Syntactical Error: When their semicolon or any kind of unbalanced parenthesis is there
  3. Semantical Error: Incompatible assignment for the values assigned.
  4. Logical Error: infinite loop or the code can’t be executable.

Error Recovery :
Following this, there are three kinds of error recovery that can be implemented in the parser to deal with the errors in the code.

  1. Panic mode Error-recovery – 
    It is the easiest way to error recovery preventing parser to develop infinitely loops, it works is that when a parser encounters an error anywhere in the statement, it ignores the rest statement by not processing input, such as a “;” semicolon. 
  2. Statement mode error-recovery – 
    When the parser encounters an error it tries to add that particle of error virtually keeping in the box that also one wrong correction can result in the infinite loop, just for example if there is a missing semicolon in a compilation statement it introduces a virtual semicolon and check for the rest of the statement or check for some word which can be replaced by other to get the code run smoothly.
  3. Global correction error-recovery – 
    The parser considers the program in the compiler as a whole product with an intention to figuring out what the program trying to do and it tries to find out the closes match possible for what the program has been intended and it founds the error this way and tries to correct its step at the possible way so that it doesn’t have any wrong step while implementing the search.
  4. Phrase-Level Recovery – 
    It performs local correction on the remaining input, this typical correction is to replace with a semicolon by inserting and deleting an extraneous semicolon, having a disadvantage in copying with situations in which the actual error has occurred before the point of detection.

Classes of Recovery :
There are two classes of recovery are as follows.

  1. Local Recovery – 
    Wherever the error is detected it adjust the input at a single point of the error.
  2. Global Recovery – 
    Wherever the error is detected it adjust the input before the point of the error.

Note –
Both the things applied at LL and LR parsing techniques.

Conclusion :
Error recovery is the ability of the compiler to resume parsing of a program after detecting such errors while the compilation process. The parser obtains a string of tokens from the lexical analyzer and verifies and then it returns if any syntax error is detected. In this, it checks the token structure and produces a parse tree to check the syntax-related error called syntactic error is detected.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!