Java Reference
In-Depth Information
Name Type Var Level Hash Depth
Figure 8.6: A symbol table entry
In Figure 8.5, each string is referenced by a pair of fields. One field
specifies the string's origin in the string bu
er, and the other field specifies the
string's length. If the names are managed so that the bu
ff
er contains at most
one occurrence of any name, then the equality of two strings can be tested
by comparing the strings' references. If they di
ff
er in origin or length, then
the strings cannot be the same. The Java class String contains the method
intern that maps any string to a unique reference for the string. The strings in
Figure 8.5 do not share any common characters. Exercise 11 considers string
spaces , which store shared substrings more compactly.
ff
In some languages,
the su
ce to locate the name. For example, a reference of
String in a Java programdefaults to java.lang.String.Exercise12considers
the organization of name spaces to accommodate such access.
xofanamecansu
8.3.3 An Efficient Symbol Table Implementation
We have examined issues of symbol management and representation. Based
on the discussion up to this point, we next present an e
cient symbol table
implementation. Figure 8.6 shows the layout of a symbol table entry containing
the following fields:
Name is a reference to the symbol name space, organized as described in
Section 8.3.2. The name is required to locate the symbol in a chain of
symbols with the same hash table location.
Type is a reference to the type information associated with the symbol's dec-
laration. Such information is processed as described in Section 8.6.
Hash threads symbols whose names hash to the same value. In practice, such
symbols are doubly linked to facilitate symbol deletion.
Va r
is a reference to the next outer declaration of this same name. When the
scope containing this declaration is abandoned, the referenced declara-
tion becomes the currently active declaration for the name. Thus, this
field essentially represents a stack of scope declarations for its symbol
name.
Level threads symbols declared in the same scope. This field facilitates symbol
deletion when a scope is abandoned.
 
 
Search WWH ::




Custom Search