0% found this document useful (0 votes)
4 views

unit3 (1)

The document discusses error detection and recovery in compilers, outlining the error handling process which includes detection, reporting, and recovery. It classifies compile-time errors into lexical, syntactic, and semantic errors, providing examples and recovery methods for each type. Various recovery techniques such as Panic Mode Recovery, Statement Mode Recovery, Error Production, and Global Correction are explained, highlighting their advantages and disadvantages.

Uploaded by

chodanker15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

unit3 (1)

The document discusses error detection and recovery in compilers, outlining the error handling process which includes detection, reporting, and recovery. It classifies compile-time errors into lexical, syntactic, and semantic errors, providing examples and recovery methods for each type. Various recovery techniques such as Panic Mode Recovery, Statement Mode Recovery, Error Production, and Global Correction are explained, highlighting their advantages and disadvantages.

Uploaded by

chodanker15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

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 it to user is called Error Handling process.
Functions of Error handler

 Detection
 Reporting
 Recovery

Classification of Errors

Compile time errors are of three types:-

Lexical phase errors

These errors are detected during the lexical analysis phase. Typical lexical errors are

 Exceeding length of identifier or numeric constants.


 Appearance of illegal characters
 Unmatched string
Example 1 : printf(" ");$
This is a lexical error since an illegal character $ appears at the end of
statement.

Example 2 : This is a comment */


This is an lexical error since end of comment is present but beginning is not
present.

Error recovery:
Panic Mode Recovery

 In this method, successive characters from the input are removed one at a time
until a designated set of synchronizing tokens is found. Synchronizing tokens are
delimiters such as; or }
 Advantage is that it is easy to implement and guarantees not to go to infinite
loop
 Disadvantage is that a considerable amount of input is skipped without
checking it for additional errors

Syntactic phase errors

These errors are detected during syntax analysis phase. Typical syntax errors are

 Errors in structure
 Missing operator
 Misspelled keywords
 Unbalanced parenthesis
Example : swicth(ch)
{
.......
.......
}
The keyword switch is incorrectly written as swicth. Hence, “Unidentified
keyword/identifier” error occurs.

Error recovery:

1. Panic Mode Recovery


o In this method, successive characters from input are removed one at a
time until a designated set of synchronizing tokens is found. Synchronizing
tokens are deli-meters such as ; or }
o Advantage is that its easy to implement and guarantees not to go to
infinite loop
o Disadvantage is that a considerable amount of input is skipped without
checking it for additional errors
2. Statement Mode recovery
o In this method, when a parser encounters an error, it performs necessary
correction on remaining input so that the rest of input statement allow the parser
to parse ahead.
o The correction can be deletion of extra semicolons, replacing comma by
semicolon or inserting missing semicolon.
o While performing correction, atmost care should be taken for not going
in infinite loop.
o Disadvantage is that it finds difficult to handle situations where actual
error occured before point of detection.
3. Error production
o If user has knowledge of common errors that can be encountered then,
these errors can be incorporated by augmenting the grammar with error
productions that generate erroneous constructs.
o If this is used then, during parsing appropriate error messages can be
generated and parsing can be continued.
o Disadvantage is that its difficult to maintain.
4. Global Correction
o The parser examines the whole program and tries to find out the closest
match for it which is error free.
o The closest match program has less number of insertions, deletions and
changes of tokens to recover from erroneous input.
o Due to high time and space complexity, this method is not implemented
practically.

Semantic errors
These errors are detected during semantic analysis phase. Typical semantic errors are

 Incompatible type of operands


 Undeclared variables
 Not matching of actual arguments with formal one
Example : int a[10], b;
.......
.......
a = b;
It generates a semantic error because of an incompatible type of a and b.

Error recovery
 If error “Undeclared Identifier” is encountered then, to recover from this a
symbol table entry for corresponding identifier is made.
 If data types of two operands are incompatible then, automatic type conversion
is done by the compiler.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy