Java Reference
In-Depth Information
7
Syntax-Directed
Translation
The parsers discussed in Chapters 5 and 6 can recognize syntactically valid
inputs. However, compilers are typically required to perform some transla-
tion of the input source into a target representation, as discussed in Chapter 2.
Some compilers are completely syntax-directed , translating programs in a sin-
gle 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 ab-
stract 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.
7.1 Overview
The work performed by a compiler while parsing is generally termed syntax-
directed translation . The grammar on which the parser is based causes a specific
sequence of derivation steps to be taken for a given input program. In con-
structing the derivation, a parser performs a sequence of syntactic actions as
235
 
 
 
Search WWH ::




Custom Search