Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Compiler Design  >  Error detection & Recovery in Compiler

Error detection & Recovery in Compiler | Compiler Design - Computer Science Engineering (CSE) PDF Download

Introduction

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

  • Detection
  • Reporting
  • Recovery

Classification of Errors

Error detection & Recovery in Compiler | Compiler Design - Computer Science Engineering (CSE)

Compile-time 

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.
  • The 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 an lexical error since end of comment is present but beginning is not present

Error recovery for lexical

Errors


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 }
  • The advantage is that it is easy to implement and guarantees not to go into an infinite loop
  • The disadvantage is that a considerable amount of input is skipped without checking it for additional errors

Syntactic phase

Errors


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

  • Errors in structure
  • Missing operator
  • Misspelled keywords
  • Unbalanced parenthesis

Example: switch(ch)

              {

                 .......

                 .......

              }

The keyword switch is incorrectly written as a switch. Hence, an “Unidentified keyword/identifier” error occurs. 

Error recovery for syntactic phase recovery

1. 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 deli-meters such as; or }
  • The advantage is that it’s easy to implement and guarantees not to go into an infinite loop
  • The disadvantage is that a considerable amount of input is skipped without checking it for additional errors

2. Statement Mode recovery 

  • In this method, when a parser encounters an error, it performs the necessary correction on the remaining input so that the rest of the input statement allows the parser to parse ahead.
  • The correction can be deletion of extra semicolons, replacing the comma with semicolons, or inserting a missing semicolon.
  • While performing correction, utmost care should be taken for not going in an infinite loop.
  • A disadvantage is that it finds it difficult to handle situations where the actual error occurred before pointing of detection.

3. Error production 

  • If a 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.
  • If this is used then, during parsing appropriate error messages can be generated and parsing can be continued.
  • The disadvantage is that it’s difficult to maintain.

4. Global Correction 

  • The parser examines the whole program and tries to find out the closest match for it which is error-free.
  • The closest match program has less number of insertions, deletions, and changes of tokens to recover from erroneous input.
  • Due to high time and space complexity, this method is not implemented practically.

Semantic

Errors


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

  • Incompatible type of operands
  • Undeclared variables
  • Not matching of actual arguments with a 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 for Semantic

Errors


  • If the error “Undeclared Identifier” is encountered then, to recover from this a symbol table entry for the corresponding identifier is made.
  • If data types of two operands are incompatible then, automatic type conversion is done by the compiler.
The document Error detection & Recovery in Compiler | Compiler Design - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Compiler Design.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
26 videos|66 docs|30 tests

Top Courses for Computer Science Engineering (CSE)

26 videos|66 docs|30 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Previous Year Questions with Solutions

,

shortcuts and tricks

,

Sample Paper

,

past year papers

,

Extra Questions

,

Error detection & Recovery in Compiler | Compiler Design - Computer Science Engineering (CSE)

,

video lectures

,

study material

,

Objective type Questions

,

Important questions

,

Summary

,

Error detection & Recovery in Compiler | Compiler Design - Computer Science Engineering (CSE)

,

Semester Notes

,

mock tests for examination

,

Viva Questions

,

Free

,

practice quizzes

,

pdf

,

Error detection & Recovery in Compiler | Compiler Design - Computer Science Engineering (CSE)

,

Exam

,

MCQs

,

ppt

;