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

This doc is part of
26 videos|67 docs|30 tests
Join course for free

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.

Download the notes
Error detection & Recovery in Compiler
Download as PDF
Download as PDF

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. 

Take a Practice Test
Test yourself on topics from Computer Science Engineering (CSE) exam
Practice Now
Practice Now

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)
Are you preparing for Computer Science Engineering (CSE) Exam? Then you should check out the best video lectures, notes, free mock test series, crash course and much more provided by EduRev. You also get your detailed analysis and report cards along with 24x7 doubt solving for you to excel in Computer Science Engineering (CSE) exam. So join EduRev now and revolutionise the way you learn!
Sign up for Free Download App for Free
26 videos|67 docs|30 tests

Up next

26 videos|67 docs|30 tests
Download as PDF

Up next

Explore Courses for Computer Science Engineering (CSE) exam
Related Searches

MCQs

,

pdf

,

Summary

,

ppt

,

Semester Notes

,

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

,

Important questions

,

practice quizzes

,

study material

,

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

,

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

,

Extra Questions

,

Viva Questions

,

video lectures

,

Free

,

Objective type Questions

,

past year papers

,

mock tests for examination

,

Previous Year Questions with Solutions

,

shortcuts and tricks

,

Exam

,

Sample Paper

;