# What is the Symbol Table?

Compiler DesignProgramming LanguagesComputer Programming

Symbol Table is a data structure that supports an effective and efficient way of storing data about various names occurring in the source code. These names are used in the source code to identify the different program elements, like a variable, constants, procedures, and the labels of statements.

The symbol table is searched each time a name is encountered in the source text. When a new name or new data about an existing name is found, the content of the symbol table modifies.

Thus, the symbol table should have an effective structure for creating the data held in the table also for inserting new entries to the symbol table.

In any case, the symbol table is an effective abstraction to support the compiler to determine and check the semantics, or definitions, of a piece of program. It will maintain track of the names, types, locations, and properties of the symbols encountered in the program.

The type system and the code generation system rely on the symbol table to provide them with information about symbols located elsewhere in the code.

It can produce the compiler more effective because the file does not require to be re-parsed to find previously processed data.

For effectiveness, our option of implementing data structure for the symbol table and the organization of its contents must emphasize minimal value when inserting new entries or creating the data of current entries.

For example, if defining a variable like

int x

then the name of the variable, along with its type, is inserted in the symbol table.

The diagram is given below−

The form of the symbol table to analyze the C function is straightforward. Consider the following outline of a C function−

void scopes ( )
{
int a, b, c; /* level 1 */
……………..
{
int a, b; /* level 2 */
……….
}
float c, d; /* level 3 */
{
int m; /* level 4 */
……….
}
}
}

An upwards growing stack could represent the symbol table. We can have a look at the symbol table as given below−

• Initially the table is empty

• After the first three declarations, the symbol table will be

• After the second declaration of Level 2.

• As the control come out from Level 2.

• When control will enter into Level 3.

• After Entering Level 4.

• On leaving the control from Level 4.

• On leaving the control from Level 3.

• On leaving the function entirely, the symbol table will be again empty.

Published on 05-Nov-2021 12:17:59