Java Reference
In-Depth Information
inheritance, overloading, and aggregate data types must be considered when
designing a symbol table.
8.5 Declaration Processing Fundamentals
This section presents the approach we use to represent the information that
must be associated with identifiers in the symbol table and begins our discus-
sion of the techniques used to process declarations and do type checking on
an abstract syntax tree (AST) representation of a program.
8.5.1 Attributes in the Symbol Table
In the discussion in Section 8.1.2, symbol tables were presented as a means
for associating identifiers with some attribute information. We did not specify
what kind of information was included in the attributes associated with an
identifier or how it was represented. These topics are considered in this
section.
The attributes of an identifier generally include anything the compiler
knows about it. Because a compiler's main source of information about iden-
tifiers is declarations, attributes can be thought of as internal representations
of declarations. Compilers do generate some attribute information internally,
typically from the context in which the declaration of an identifier appears.
Some languages define use of an identifier as an implicit declaration, in which
case all of the attribute information must be constructed by the compiler when
a first use is encountered.
erent ways in
a modern programming language, including as variables, constants, types,
procedures, classes, and fields. Every identifier, therefore, will not have the
same set of attributes associated with it. Rather, it will have a set of attributes
corresponding to its usage and thus to its declaration.
We need a data structure to store the variety of information necessary
to represent the attributes associated with the many di
Identifiers are used in many di
ff
erent uses of names
that occur in a program. This capability can be achieved by using a struct
that contains a tag indicating the kind of attributes being stored and a union
with one alternative corresponding to each possible value of the tag. Using
an object-based approach, we could define an abstract class named Attributes
and an appropriate subclass to represent the information that must be stored
to describe each kind of declaration.
In the pseudocode that follows, we will use the struct approach, since
that will allow us to keep the code a bit simpler. The tag will be named kind
and names for members will be introduced as needed. Translation to an object-
based approach should be obvious, with each distinct tag value indicating the
need for a corresponding subclass of Attributes.
ff
 
 
 
Search WWH ::




Custom Search