Compiler Design and Construction - Old Questions

2.  Discuss the role of symbol table in compiler design.

6 marks | Asked in 2068

Symbol Table is an important data structure created and maintained by the compiler in order to keep track of semantics of variable i.e. it stores information about scope and binding information about names, information about instances of various entities such as variable and function names, classes, objects, etc. It is built in lexical and syntax analysis phases. The information is collected by the analysis phases (front end) of compiler and is used by synthesis phases (back end) of compiler to generate code. It is used by compiler to achieve compile time efficiency.

A symbol table may have the following roles/functions depending upon the language in hand:

  • To store the names of all entities in a structured form at one place.
  • To verify if a variable has been declared or not.
  • To determine the scope of a name (scope resolution).
  • To access information associated with a given name.
  • To add new information with a given name.
  • To delete a name or group of names from the table.
  • To implement type checking, by verifying assignments and expressions in the source code are semantically correct.