Error Detection and Recovery in Compiler




Error encountered in different phases

  • An important role of the compiler is to report any errors in the source program that it detects during the entire translation process.
  • Each phases of compiler can encounter errors, after detecting errors, must be corrected to precede compilation process.
  • The syntax and semantic phases handle large number of errors in compilation process.
  • Error handler handles all types of errors like lexical errors, syntax errors, semantic errors and logical errors.
Classification of errors

Classification of errors

Lexical phase errors

  • These errors are detected during the lexical analysis phase.
  • Exceeding length of identifier or numeric constants.
Lexical Phase Errors

Lexical Phase Errors

1xab is neither a number nor an identifier. So this code will show the lexical error

  • Appearance of illegal characters printf Wikitechy("");$

This is a lexical error since an illegal character $ appears at the end of statement.
Example: switch is written as swich.

Panic mode Error 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:

  • It is easy to implement and guarantees not to go to infinite loop.

Disadvantage:

  • Some inputs are skipped without checking it for additional errors.

Syntactic phase errors

  • These errors are detected during the syntax analysis phase
  • Errors like semicolon missing or unbalanced parenthesis.
  • Example: ((a+b* (c-d)). In this statement ) missing after b.
Syntactic Phase Errors

Syntactic Phase Errors

Statement mode Error Recovery:

  • 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.
  • It finds difficult to handle situations where actual error occurred before point of detection.

Semantic errors

  • These errors are detected during the semantic analysis phase.
  • Data type mismatch errors handled by semantic analyzer.
  • Incompatible data type value assignment.
  • Example: Assigning a string value to integer.
Statement mode error recovery

Semantic Errors



Related Searches to Error Detection and Recovery in Compiler