Java Reference
In-Depth Information
To process the export and import directives, the compiler typically exam-
ines the import directives to obtain a list of potentially external references.
These references are then examined by the compiler to determine their valid-
ity, to the extent that is possible at compile time. In Java, the import directives
servetoinitializethesymboltablesothat references to abbreviated classes
(String for java.lang.String)canberesolved.
8.4.5 Altered Search Rules
Pascal's with statement is a good example of a feature that alters the way in
which symbols are found in the symbol table. If a Pascal program contains
the phrase with R do S, then within the statements in S, the compiler must
first try to resolve an identifier reference as a field of the record R. If no valid
reference is found in record R, then the symbol table is searched as usual. This
feature allows the programmer to avoid frequently restating R inside S,which
is advantageous if R is actually a complex name. Moreover, in such a case,
the compiler can usually generate faster code, since it is likely that there are
multiple references to fields of the record R within S.
Forward references also a
ect a symbol table's search rules. Consider a set
of recursive data structures or methods. In the program, the set of definitions
must be presented in some linear order. It is inevitable that a portion of the
program will reference a definition that has not yet been processed. Forward
references suspend the compiler's skepticism concerning undeclared symbols.
A forward reference is essentially a promise that a complete definition will
eventually be provided.
Some languages require that forward references be announced. In C, it is
considered good style to declare an as-yet-undefined function so that its types
are known at all call points. In fact, some compilers require such declarations.
On the other hand, a C structure may contain a field that is a pointer to itself.
For example, each element in a linked list contains a pointer to another element.
It is customary to process such forward references in two passes. The first pass
makes note of type references that should be checked in the second pass.
ff
Symbol Table Summary
Although the interface for a symbol table is quite simple, the details underlying
a symbol table's implementation play a significant role in the performance of
the symbol table. Most modern programming languages are statically scoped.
The symbol table organization presented in this chapter e
ciently represents
scope-declared symbols in a block-structured language. Each language places
its own requirements on how symbols can be declared and used. Most lan-
guages include rules for symbol promotion to a global scope. Issues such as
 
 
Search WWH ::




Custom Search