Java Reference
In-Depth Information
integerTypeDescriptor
arrayTypeDescriptor
elementType : a type reference
bounds : a range descriptor
recordTypeDescriptor
fields : a symbol table
Figure 8.10: Type Descriptor Structures
references to other type descriptors or anything else necessary, even a sym-
bol table. Such a representation is crucial in handling virtually all modern
programming languages, which allow types to be constructed using power-
ful composition rules. Using this technique rather than some kind of fixed
tabular representation also makes the compiler much more flexible in what it
can allow a programmer to declare. For example, using this approach, there
is no reason to have an upper bound on the number of dimensions allowed
for an array or the number of fields allowed in a structure. Such limitations
in early languages like Fortran stem purely from implementation considera-
tions. We generally favor techniques that enable a compiler to avoid rejecting
a legal program because of the size of the program or some part of it. Dynamic
linked structures such as the type descriptor structure are the basis of such
techniques.
8.5.3 Type Checking Using an Abstract Syntax Tree
We will use the visitor pattern described in Chapter 7 to implement a semantic
processing pass over an AST. The primary activities of this pass will be con-
structing a symbol table structure that represents all of the declarations in the
tree and preforming type checks as necessary throughout the tree. As pointed
out when this visitor approach was introduced, it allows us to group all of
the actions for this pass within a single class, SemanticsVisitor, a subclass of
Visitor. Since the declaration processing involves specialized actions for build-
ing the symbol table structure that is the basis of the type checking to be done
by SemanticsVisitor, the declaration processing actions will be implemented
by a more specialized visitor, called TopDeclVisitor.
 
 
Search WWH ::




Custom Search