610 likes | 950 Views
Chapter 2 A Simple Syntax-Directed Translator. Figure 2.1: A code fragment to be translated. Figure 2.2: Simplified intermediate code for the program fragment in Fig. 2.1. Figure 2.3: A model of a compiler front end. Figure 2.4: Intermediate code for "do i = i + 1 ; while ( a [il < v) ; ".
E N D
Figure 2.2: Simplified intermediate code for the program fragment in Fig. 2.1
Figure 2.4: Intermediate code for "do i = i + 1 ; while ( a [il < v) ; "
Figure 2.5: Parse tree for 9-5+2 according to the grammar in Example 2.1
Figure 2.7: Parse trees for left- and right-associative grammars
Figure 2.10: Syntax-directed definition for infix to postfix translation
Figure 2.13: An extra leaf is constructed for a semantic action
Figure 2.17: A parse tree according to the grammar in Fig. 2.16
Figure 2.18: Top-down parsing while scanning the input from left to right
Figure 2.20: Left- and right-recursive ways of generating a string
Figure 2.23: Translation scheme after left-recursion elimination
Figure 2.25: Pseudocode for non-terminals expr, rest, and term
Figure 2.26: Eliminating tail recursion in the procedure rest of Fig. 2.25
Figure 2.27: Java program to translate infix expressions into postfix form
Figure 2.38: The use of symbol tables for translating a language with blocks
Figure 2.39: Construction of syntax trees for expressions and statements
Figure 2.40: Part of a syntax tree for a statement list consisting of an ifstatementand a while-statement
Figure 2.41: Concrete and abstract syntax for several Java operators
Figure 2.43: Function gen in class If generates three-address code