Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Usability

Authors: Jakob Nielsen, Raluca Budiu

1st Edition

0133122131, 9780133122138

More Books

Students also viewed these Programming questions

Question

3. Deal with less-severe problems later.

Answered: 1 week ago

Question

=+a. Calculate and interpret the sample mean and median.

Answered: 1 week ago