Question: A C++ compiler uses a symbol table to keep track of the identifiers that a program uses. When the compiler encounters an identifier, it searches

A C++ compiler uses asymbol tableto keep track of the identifiers that a program uses. When the compiler encounters an identifier, it searches the symbol table to see whether that identifier has already been encountered. If the identifier is new, it is inserted into the table. Thus, the symbol table needs onlyinsertionandretrievaloperations.

Symbol tables are mostly implemented as hash tables, where an identifier is treated as a key for the hash function and the return value is the information about the identifier, such as its type and scope.

Consider the following function:

int sum(int a, int b) { return a + b; }

Symbol Table for the Sum() function

NAME

TYPE

SCOPE

sum

function

global

a

variable

local

b

variable

local

Write a class called SymbolTable and implement it as a hash table, using chaining to resolve collisions. Use the hash functionh(x) =xmodtableSizeand the algorithm that involveshashing string with ordinal values, as described in the class to convert a variable into an integerx. Write a program to demonstrate your SymbolTable.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!