Skip to main content
1 of 2
fade2black
  • 9.9k
  • 2
  • 25
  • 36

In which phases of the compiler, is symbol table used and updated?

Symbol table are interacted during all phases of a compiler.

Basically, a compiler operates in phases which are grouped as backend and frontend. The front end deals with those part of code which is independent of the target platform and mainly depends on the language structure, while backend does not depend on the structure of the language but depend on the target platform.

Essentially, a symbol table is a data structure (usually a hash table) containing information about identifiers. Identifiers are detected and stored in the symbol table by the lexical analyzer. During the analysis phase (frontend) the compiler collects various information about identifiers (scope, type, size, etc.), stores it into the symbol table, and later this information are used in various ways in remaining phases, for example by code generator and optimizer. The symbol table are used and updated as necessary and for the most part depends on what kind of compiler you are writing (target platform, architecture, structure of language, etc.).

For example, initially the symbol table may store keywords. The syntax analyzer may store information about types of identifiers, and semantic analyzer may use this information to check semantics of expressions. The code generator uses types of identifiers and store the information about the storage assigned to identifiers.

fade2black
  • 9.9k
  • 2
  • 25
  • 36