0% found this document useful (0 votes)
77 views5 pages

Symbol Table Management13

The document discusses symbol table management. A symbol table stores semantic information about variables and identifiers, including name, data type, block level, and scope. It also tracks function and method names, return types, parameters, and whether functions are recursive. Symbol tables can be implemented as unordered lists, ordered linear lists, binary search trees, or hash tables. Hash tables provide the most efficient implementation with average O(1) time complexity for search and insert operations.

Uploaded by

moix khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views5 pages

Symbol Table Management13

The document discusses symbol table management. A symbol table stores semantic information about variables and identifiers, including name, data type, block level, and scope. It also tracks function and method names, return types, parameters, and whether functions are recursive. Symbol tables can be implemented as unordered lists, ordered linear lists, binary search trees, or hash tables. Hash tables provide the most efficient implementation with average O(1) time complexity for search and insert operations.

Uploaded by

moix khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Symbol table management

By Muhammad Moiz
Symbol tble managmement by Muhammad Moiz

1. What is a Symbol Table?

Symbol table is a data structure used by a compiler to keep track of semantic of variables and
identifiers. This information will be used later on by the semantic analyzer and code generator.
The symbol table stores the following information about identifiers and variable:

• The name as an array of characters


• The data type (int, float, double, long, bool)
• The block level
o The block level in modern language is determined by the opening and closing of
angle brackets { }
• The scope
o Global
o Local
o Parameter
• The offset from the base pointer (local variables and parameters)\
• Function and methods name
o Its return type (void, int, double, long etc…)
o Number of formal parameters
o Whether the function is calling itself (recursive)
2. Symbol table implementations

2.1 Unordered list

Searching is very expensive since we have to scan on average half of the list to find
the key element. It is mainly used for very small set of variables.

2.2 Ordered linear list

Insertion is expensive since we have to scan for the proper location inside the list to
keep the array sorted.

We can use binary search for searching since the list is sorted as an average of log2 n.

2.3 Binary search tree

As long as we have none amortized tree, the average of searching and sorting is
logarithmic.

2.4 Hash table

Hash table is the most efficient implementation of symbol table. It has two operations
GET and PUT and performs well while having memory space adequately larger than
the number of variables and identifiers
• Hash function h(n) returns a value between 0 and m-1, where n is the
input and m is the hash table size.

Performance of Hash Table:

1. Performance depends on collision resolution schemes


2. Hashtable size must be large enough than the number of entries
3. Keys should be distinct to avoid large collisions
4. Hashtable must be uniformly distributed

Structure of the Symbol Table:


We will implement the symbol table as a linked list of hash tables, one hash
table for each block level.

You might also like