Chapter 7: Syntax-Directed Translation
Overview
The parsers discussed in
Chapter 5
and
Chapter 6
can recognize syntactically
valid inputs. However,
compilers are typically required to perform some translation
of the input source into a target representation, as discussed
in
Chapter 2.
Some compilers are completely syntax-directed
translating programs in a single phase without
taking any intermediate steps. Most compilers accomplish translation
using multiple phases. Instead of repeatedly scanning the input program,
compilers typically create an intermediate structure
called the Abstract Syntax Tree (AST) as a by-product of the parse. The AST then serves
as a mechanism for conveying information between compiler phases.
In this chapter we study how to formulate grammars and production-triggered
code sequences to enable syntax-directed translation or to create an
AST for subsequent phases.