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

Error Handling

The document discusses error handling in compiler design, emphasizing the importance of detecting and reporting errors at various stages of compilation, including lexical, syntactic, and semantic errors. It outlines the error detection and recovery process, detailing methods such as panic mode recovery for handling lexical errors. Additionally, it provides examples of common errors and their recovery strategies, highlighting the role of the error handler in ensuring accurate compilation.

Uploaded by

ji0400623
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)
6 views

Error Handling

The document discusses error handling in compiler design, emphasizing the importance of detecting and reporting errors at various stages of compilation, including lexical, syntactic, and semantic errors. It outlines the error detection and recovery process, detailing methods such as panic mode recovery for handling lexical errors. Additionally, it provides examples of common errors and their recovery strategies, highlighting the role of the error handler in ensuring accurate compilation.

Uploaded by

ji0400623
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/ 3

1.

Error Handling in Compiler Design


Detection and reporting of errors in the source program is the main function of the compiler.
An error can occur at any phase of compilation. A good compiler must determine the line
number of the program exactly, where the errors have occurred.
Various errors that can occur at a different level of compilation are as follows:
1. The first of these are lexical (scanner) errors
2. The second class of error is syntactic
3. The third type of error is semantic
4. The fourth type of error may encounter during code optimization
5. The fifth type of error may occur during code generation
6. The sixth type of error may encounter when the compiler tries to make symbol table
entries

2. Error Detection and Recovery


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
i. 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("Geeksforgeeks");$
This is a lexical error since an illegal character $ appears at the end of statement.
Example 2 : This is a comment */
This is a 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

ii. 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.
iii. 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