Compiler Design and Construction - Old Questions

Question Answer Details

10.  Discuss the importance of error handler in compiler. How is it manipulated in the different phases of compilation?

6 marks
Asked in 2076

Answer

AI Generated Answer

AI is thinking...

Official Answer

Error detection and reporting of errors are important functions of the compiler. Whenever an error is encountered during the compilation of the source program, an error handler is invoked. Error handler generates a suitable error reporting message regarding the error encountered. The error reporting message allows the programmer to find out the exact location of the error. Errors can be encountered at any phase of the compiler during compilation of the source program for several reasons such as:

  • In lexical analysis phase, errors can occur due to misspelled tokens, unrecognized characters, etc. These errors are mostly the typing errors.
  • In syntax analysis phase, errors can occur due to the syntactic violation of the language.
  • In intermediate code generation phase, errors can occur due to incompatibility of operands type for an operator.
  • In code optimization phase, errors can occur during the control flow analysis due to some unreachable statements.
  • In code generation phase, errors can occurs due to the incompatibility with the computer architecture during the generation of machine code. For example, a constant created by compiler may be too large to fit in the word of the target machine.
  • In symbol table, errors can occur during the bookkeeping routine, due to the multiple declaration of an identifier with ambiguous attributes.

After detecting an error, a phase must somehow deal with that error, so that compilation can proceed, allowing further errors in the source program to be detected.

Error handler contains a set of routines for handling error encountered in any phase of the compiler. Every phase of compiler will call an appropriate routine of the error handler as per their specifications.