Purpose of the Symbol Table

The Compiler must be able to store information about symbols found within a C program. Symbols can include variables, function names, other objects and more. Information of these symbols must be stored as it allows the Complier to generate assembly code and the information can be used for semantic analysis.

For example, say a function call is performed with the parameters val1, val2, and val3. These parameters will be stored in a stack frame in a relative location to the base pointer for that stack frame. These relative location allow the Complier to access the parameters in the function call. These relative locations that are vital to the Complier being able to access parameters and are just one of the details stored in the symbol table.

Other details stored in the symbol table include:

  • Symbol Name
  • Symbol Scope
  • Symbol Type (i.e., variable or function name)
  • Symbol Variable Type
  • Symbol Value
  • Symbol Address
  • Symbol Base Pointer Offset (mainly used for variables)
  • Symbol Parameters Count (mainly used for functions)