next up previous
Next: Command line analysis Up: Describing a Complete Compiler Previous: Describing a Complete Compiler

Definition table

The definition table is a data base that the compiler uses to store arbitrary information about entities of interest. Typical entities are user-defined variables, types, and labels. Because many of these entities are represented in the source program by symbols, the definition table is sometimes called a ``symbol table'' and its role restricted to storing information about such entities. This restriction is a mistake, because it forces the compiler designer to devise other mechanisms for storing information about entities that are not represented by program symbols.

A general definition table module represents each entity by a definition table key. It exports a function NewKey() that delivers a new, unique definition table key at each invocation, and a distinguished value NoKey to represent no entity. The module is capable of storing an arbitrary number of named properties for each key. It exports a query operation and an update operation for each property. The query operation takes two arguments, the definition table key for the entity whose property is being queried and a default value of that property to return if the property is not defined for that key [WC93].

To describe a general definition table module of this kind, all that is required is a list of the names and types of the properties that the module must support. A simple declarative specification of the following form suffices:

Size: int;
Type: DefTableKey;
Grump: grumptype; "grumpmod.h"

Here int is a primitive C type and DefTableKey is the type of a definition table key, so that neither requires further specification. A grumptype, on the other hand, is exported by the user-defined grump module and therefore the interface for that module (grumpmod.h) must be supplied as part of the specification.

The obvious translation of such a specification into a definition table module is performed by the PDL tool.


next up previous
Next: Command line analysis Up: Describing a Complete Compiler Previous: Describing a Complete Compiler
2007-05-18