[an error occurred while processing this directive]

SymbolTable Module Client Specifications


Purpose

A SymbolTable provides storage and random access retrieval of descriptors associated with identifiers in a block structured language.

Importing Information

Use of the SymbolTable class requires the following import.
import symtab.SymbolTable;
import symtab.Descriptor;

Client Data Model

This module provides standard table methods addDescriptor() for adding new Descriptors to the symbol table and descriptorFor() for retrieving Descriptors from the symbol table. Both of these methods have a parameter to specify the identifier used to identify the Descriptor.

For handling block structured languages, the symbol table is divided into levels, which correspond to blocks or scopes in a program. Each level can have its own Descriptor entries. When Descriptors are added, they are added to the highest level in the symbol table. Two Descriptors can be added with the same identifier as long as the entries are at different levels. When Descriptors are retrieved, they are retrieved from the highest level that contains an entry for the specified identifier.

Initially, the symbol table has a single level, identified as level 0. When enterScope() is called, a new level, with level number increased by 1, is added. When exitScope() is called, the highest level is removed, along with all of its Descriptor entries. The current level in the symbol table can be checked with a call to currentLevel().

The method level() returns the highest level that contains a Descriptor for its identifier argument, or -1 if there is no such level. The client should call this method prior to calling addDescriptor() or descriptorFor() to check if any Descriptor is defined for an identifier. A call to addDescriptor() should not be made if level() returns the current level. A call to descriptorFor() should not be made if level() returns -1.

Error handling policy
All precondition violations result in an error message followed by program termination.

Public Functions

Descriptor Retrieval
Data Modification
Level Control
[an error occurred while processing this directive]