Chapter 8: Symbol Tables and Declaration Processing
Overview
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. The second half of the
chapter examines techniques for processing declarations and then goes
on to show how the information derived from declarations is used to do
type checking on assignments and expressions.