Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 13

Introduction

Topic

Symbol Table

Members

Syed Humair Shah


Abdul Qadeer

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

Supports efficient search for a declaration

Some Question Which a Symbol Table can answer

What is its type?

Data type

When it is used?

Scope

Where it is stored?

Storage address

Implemention Of Symbol Table

Operations Of Symbol Table

Search Insert
Delete

Possible Implementation Of Symbol Table

Unordered List Ordered List


Tree Hash Table

Contents in a Symbol Table

Name: a string. Attribute:

*Reserved word *Variable name *Type name *Procedure name *Constant name

Cont.

Data type. Storage allocation, size,


Scope information: where and when it can be used

Major ways for Implementation


Two major ways for implementation:

Approach 1: multiple symbol tables in one stack. Approach 2: one symbol table with chaining

Approach 1
Multiple symbol tables in one stack

An individual symbol table for each scope.

Use a stack to maintain the current scope.


Search top of stack first. If not found, search the next one in the stack. Use the first one matched.

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.

Incorporate the scope number into the symbol table.

Thanks for your Time

You might also like