The Wayback Machine - https://web.archive.org/web/20240722223642/https://www.geeksforgeeks.org/what-is-error-recovery/
Open In App

What is Error recovery

Last Updated : 01 Sep, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report

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.


Similar Reads

Error detection and Recovery in Compiler
In this phase of compilation, all possible errors made by the user are detected and reported to the user in form of error messages. This process of locating errors and reporting them to users is called the Error Handling process. Functions of an Error handler. DetectionReportingRecoveryClassification of Errors Compile-time errorsCompile-time errors
6 min read
Error Recovery Strategies in Compiler Design
The error may occur at various levels of compilation, so error handling is important for the correct execution of code. There are mainly five error recovery strategies, which are as follows: Panic modePhrase level recoveryError productionGlobal correctionSymbol tablePanic Mode:This strategy is used by most parsing methods. In this method of discove
4 min read
Error Recovery in LR Parsing
LR parser is a bottom-up parser. It is always used to deal with context-free Grammar (CFGs). It is generally used by computer programming language compilers as well as other associated tools also. LR parser produces leftmost derivation while using the input taking from left to right. By building up from the leaves, it helps to reduce the top-level
3 min read
Error Recovery in Predictive Parsing
We know that the Predictive parser performs Left most derivative while parsing the given sentence. Now the given sentence may be a valid sentence or an invalid sentence with respect to the specified grammar. An error is detected during the predictive parsing when the terminal on top of the stack does not match the next input symbol, or when nonterm
4 min read
Database Recovery Models
Every database require a recovery model which signifies that what sort of backup is required or can be perform by the user to restore the data which could be lost due to any hardware failure or other issue. There are generally three types of recovery models of database, these are explained as following below. 1. Simple Recovery : In this model, the
3 min read
Error Handling in Compiler Design
The tasks of the Error Handling process are to detect each error, report it to the user, and then make some recovery strategy and implement them to handle the error. During this whole process processing time of the program should not be slow. Functions of Error Handler: Error DetectionError ReportError RecoveryError handler=Error Detection+Error Re
7 min read
Lexical Error
When the token pattern does not match the prefix of the remaining input, the lexical analyzer gets stuck and has to recover from this state to analyze the remaining input. In simple words, a lexical error occurs when a sequence of characters does not match the pattern of any token. It typically happens during the execution of a program. Types of Le
3 min read
Error Handling in YACC in Compiler Design
A compiler is a computer program that translates code written in one programming language (the source language) into another programming language (the target language). The process of compiling involves several stages, including lexical analysis, syntax analysis, semantic analysis, code generation, and code optimization. The first stage of the comp
9 min read
Floating point error in Python
Python, a widely used programming language, excels in numerical computing tasks, yet it is not immune to the challenges posed by floating-point arithmetic. Floating-point numbers in Python are approximations of real numbers, leading to rounding errors, loss of precision, and cancellations that can throw off calculations. We can spot these errors by
8 min read
Article Tags :
three90RightbarBannerImg