Java Reference
In-Depth Information
8
Symbol Tables and
Declaration Processing
Chapter 7 considered the construction of an abstract syntax tree (AST) as an
artifact of a top-down or bottom-up parse. On its own, a top-down or bottom-
up parser cannot fully accomplish the compilation of modern programming
languages. The AST serves to represent the source program and to coordinate
information contributed by the various passes of a compiler. This chapter
begins with a presentation of one such pass—the harvesting of symbols from
an AST. Most programming languages allow the declaration, definition, and
use of symbolic names to represent constants, variables, methods, types, and
objects. The compiler checks that such names are used correctly, based on the
programming language's definition.
The first half of this chapter describes the organization and implementation
of a symbol table. This structure records the names and important attributes
of a program's names. Examples of such attributes include a name's type,
scope, and accessibility. We are interested in two aspects of a symbol table: its
use and its organization. Section 8.1 defines a simple symbol table interface
and shows how to use this interface to manage symbols for a block-structured
language. Section 8.2 explains the e
ects of program scopes on symbol table
management. Section 8.3 examines various implementations of a symbol table.
Advanced topics, such as type definitions, inheritance, and overloading are
considered in Section 8.4.
ff
279
 
 
Search WWH ::




Custom Search