[an error occurred while processing this directive]

SymbolTable Module Client Specifications


Purpose

The SymbolTable module provides storage and random access retrieval of descriptors associated with identifiers in a block structured language. This module is not suitable if more than one symbol table is required.

Client Data Model

The SymbolTable module uses a static data structure declared in its source code file to implement a single symbol table refered to as "the symbol table". This module provides standard table functions addDescriptor() for adding new Descriptors to the symbol table and descriptorFor() for retrieving Descriptors from the symbol table. Both of these functions 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 function 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 function 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.

Importing Information

Use of the SymbolTable module requires the following includes, in order.
#include "Descriptor.h"
#include "SymbolTable.h"

Public Data Types

The SymbolTable module does not export any data types.

Public Functions

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