Professional Documents
Culture Documents
Symbol Table
Symbol Table
Topic
Symbol Table
Members
Sajid Kiani
Symbol Table
After syntax tree have been constructed, the compiler must check whether the input program is type-correct (called type checking and part of the semantic analysis). During type checking, a compiler checks whether the use of names (such as variables, functions, type names) is consistent with their definition in the program. Consequently, it is necessary to remember declarations so that we can detect inconsistencies and misuses during type checking. This is the task of a symbol table.
Symbol Table
A data structure used to store information on declared objects Supports insertions and deletions of declarations and opening and closing of scopes
Data type
When it is used?
Scope
Where it is stored?
Storage address
Search Insert
Delete
*Reserved word *Variable name *Type name *Procedure name *Constant name
Cont.
Approach 1: multiple symbol tables in one stack. Approach 2: one symbol table with chaining
Approach 1
Multiple symbol tables in one stack
Note: a popped scope can be destroyed in a one-pass compiler, but it must be saved in a multi-pass compiler.
Approach 2
One symbol table with chaining
A single global table marked with the scope information. Each scope is given a unique scope number.