Java Reference
In-Depth Information
Name hiding and promotion
Modification of search rules
In each case, it is appropriate to rethink the symbol table design to arrive at
an e
cient, correct implementation of the desired features. In the following
sections, we discuss the essential issues associatedwith each feature. However,
we leave the details of the implementation as exercises.
8.4.1 Records and Typenames
Most languages allow aggregate data structures to be defined using the struct
and record type constructors. Because such structures can be nested, access
to a field may involve navigating through many containers before the field
canbereached.InC,Ada,andPascal,such fields are accessed by completely
specifying the containers and the field. Thus, the reference a.b.c.d accesses
field b of structure a,fieldc of structure designated by a.b, and finally field
d of structure a.b.c. COBOL and PL
I allow intermediate containers to be
omitted if the reference can be unambiguously resolved. In such languages,
a.b.c.dmight be abbreviated as a.c or c.d. This idea has not met with general
acceptance, partly because programs that use such abbreviations are di
/
cult
to read. It is also possible that a.d is amistake, but the compiler silently accepts
the reference by filling in missing containers.
Structures can be nested arbitrarily deeply. Thus, structures are typically
implemented using a tree. Each structure is represented as a node; its children
represent the structure's subfield. Alternatively, a structure can be represented
by a symbol table whose entries are the record's subfields. Exercise 15 consid-
ers the implementation of structures in symbol tables.
Co
ers the typedef construct, which establishes a name as an alias for
a type. As with record types, it is convenient to establish an entry in the
symbol table for the typedef. In fact, most C compilers use scanners that
must distinguish between ordinary names and typenames. This is typically
accomplished through a back door call to the symbol table to lookup each
identifier. If the symbol table shows that the name is an active typename, then
the scanner returns a typename token. Otherwise, an ordinary identifier token
is returned.
ff
8.4.2 Overloading and Type Hierarchies
The notion of an identifier has thus far been restricted to a string containing
the identifier's name. Situations can arise where the name alone is insu
cient
to locate a desired symbol. Object-oriented languages such as C
and Java
allowmethod overloading. Amethod can be definedmultiple times, provided
++
 
 
 
Search WWH ::




Custom Search