Joey Paquet,ĬOMP 442/6421 – Compiler Design Error Recovery Strategies Phrase-Level Correction On discovering an error, the parser performs a local correction on the remaining input, e.g. A change in the grammar implies a change of the corresponding error productions. Error productions are specific to the rules in the grammar. One error production is needed for each possible error. Assumes that all specific errors are known in advance. An error is trapped when an error production is used. For each possible error, an error production is added. Joey Paquet,ĬOMP 442/6421 – Compiler Design Error Recovery Strategies Error Productions The grammar is augmented with “error productions”. Can be integrated in most parsing methods.
![first and follow in compiler design first and follow in compiler design](https://sourabhgupta.com/admin/img/cd/ll1parsingtable1.png)
Choosing the right set of synchronizing tokens is of prime importance. Skipping tokens often has a side-effect of skipping other errors. A systematic and general approach is to use the FIRST and FOLLOW sets as synchronizing tokens. Synchronizing tokens are typically delimiters such as semicolons or end of block delimiters. Panic mode, or don’t panic (Nicklaus Wirth) Error productions Phrase level correction Global correction Joey Paquet,ĬOMP 442/6421 – Compiler Design Error Recovery Strategies Panic Mode On discovering an error, the parser discards input tokens until an element of a designated set of synchronizing tokens is found. Although some are better than others, none of these methods provide a universal solution. Joey Paquet,ĬOMP 442/6421 – Compiler Design Error recovery strategies There are many different strategies that a parser can employ to recover from syntactic errors. Should avoid to report other errors that are consequences of the application of error recovery, e.g. Error recovery should induce processing overhead only when errors are encountered. Should give meaningful information about the errors, while avoiding to give erroneous information. Cascades of errors that result from token skipping should be avoided. Should not identify more errors than there really is. Error recovery should skip as less tokens as possible.
![first and follow in compiler design first and follow in compiler design](https://gateknowledge.in/wp-content/uploads/2021/05/Code-optimizer-Target-Code-Generator.jpg)
Should recover from each error quickly enough to be able to detect subsequent errors. Top-down parsers generally detect errors quicker than top-down parsers. It will then be more difficult to achieve good error reporting, as well as good error recovery. Often, an error will be detected only after the faulty token has passed. Good error recovery Good error recovery highly depends on how quickly the error is detected. The compiler should not provide erroneous information about the nature of errors. doy.cpp: In function `int main()': doy.cpp:25: `DayOfYear' undeclared (first use this function) doy.cpp:25: DayOfYear birthday ^ If the nature of the error is easily identifiable, give a meaningful error message. Reporting errors Give the position of the error in the source file, maybe print the offending line and point at the error location.
![first and follow in compiler design first and follow in compiler design](https://i.ytimg.com/vi/T7twzNPspTg/maxresdefault.jpg)
Joey Paquet,ĬOMP 442/6421 – Compiler Design Goals of error recovery Detect all compile-time errors Report the presence of errors clearly and accurately Recover from each error quickly enough to be able to detect subsequent errors Should not slow down the processing of correct programs Avoid spurious errors that are just a consequence of an earlier error Joey Paquet, One of the main roles of a compiler is to identify all programming errors and give meaningful indications about the location and nature of errors in the input program. The next token in input is not expected according to the syntactic definition of the language. Syntax error recovery A syntax error happens when the stream of tokens coming from the lexical analyzer does not comply with the grammatical rules defining the programming language. Presentation on theme: "Compiler design Error recovery in top-down predictive parsing"- Presentation transcript:ġ Compiler design Error recovery in top-down predictive parsingĬOMP 442/6421 – Compiler Design Compiler design Error recovery in top-down predictive parsing Joey Paquet,