Please help me with this Principles of Programming Languages homework. The question is attached along with Example 1.25. Thanks!

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please help me with this Principles of Programming Languages homework.

The question is attached along with Example 1.25.

Thanks!

Expanding on Example 1.25, trace an interpretation of the gcd program on
the inputs 12 and 8. Which syntax tree nodes are visited, in which order?
Transcribed Image Text:Expanding on Example 1.25, trace an interpretation of the gcd program on the inputs 12 and 8. Which syntax tree nodes are visited, in which order?
EXAMPLE 1.25
Interpreting the syntax
tree
34
Many interpreters use an annotated syntax tree to represent the running pro-
gram: "execution" then amounts to tree traversal. In our GCD program, an inter-
preter would start at the root of Figure 1.6 and visit, in order, the statements on
the main spine of the tree. At the first ":="node, the interpreter would notice that
the right child is a call: it would therefore call the getint routine (found in slot
3 of the symbol table) and assign the result into i (found in slot 5 of the symbol
table). At the second ":=" node the interpreter would similarly assign the result
of getint into j. At the while node it would repeatedly evaluate the left ("#")
child and, if the result was true, recursively walk the tree under the right (if) child.
Finally, once the while node's left child evaluated to false, the interpreter would
move on to the final call node, and output its result.
In many compilers, the annotated syntax tree constitutes the intermediate
form that is passed from the front end to the back end. In other compilers, se-
mantic analysis ends with a traversal of the tree (typically single pass) that gener-
ates some other intermediate form. One common such form consists of a control
flow graph whose nodes resemble fragments of assembly language for a simple
10 As we shall see in Section 6.1.3, Java and C# actually do enforce initialization compile time,
but only by adopting a conservative set of rules for "definite assignment, outlawing programs
for which correctness is difficult or impossible to verify at compile time.
Chapter 1 Introduction
3
4
5
6
program
(5)
Index Symbol
1 void
2
int
i
j
(=
getint
putint
call
(3)
(6) call
I
(3)
(2)
(2)
(5)
Type
type
type
func: (1)→ (2)
func: (2)→ (1)
(6)
while
(5) (6)
if
(5)
E
(5)
call
(4) (5)
(6)
(6) (6) (5)
Figure 1.6 Syntax tree and symbol table for the GCD program. Note the contrast to Fig-
ure 1.5: the syntax tree retains just the essential structure of the program, omitting details that
were needed only to drive the parsing algorithm.
idealized machine. We will consider this option further in Chapter 15, where a
control flow graph for our GCD program appears in Figure 15.3. In a suite of re-
lated compilers, the front ends for several languages and the back ends for several
machines would share a common intermediate form.
Transcribed Image Text:EXAMPLE 1.25 Interpreting the syntax tree 34 Many interpreters use an annotated syntax tree to represent the running pro- gram: "execution" then amounts to tree traversal. In our GCD program, an inter- preter would start at the root of Figure 1.6 and visit, in order, the statements on the main spine of the tree. At the first ":="node, the interpreter would notice that the right child is a call: it would therefore call the getint routine (found in slot 3 of the symbol table) and assign the result into i (found in slot 5 of the symbol table). At the second ":=" node the interpreter would similarly assign the result of getint into j. At the while node it would repeatedly evaluate the left ("#") child and, if the result was true, recursively walk the tree under the right (if) child. Finally, once the while node's left child evaluated to false, the interpreter would move on to the final call node, and output its result. In many compilers, the annotated syntax tree constitutes the intermediate form that is passed from the front end to the back end. In other compilers, se- mantic analysis ends with a traversal of the tree (typically single pass) that gener- ates some other intermediate form. One common such form consists of a control flow graph whose nodes resemble fragments of assembly language for a simple 10 As we shall see in Section 6.1.3, Java and C# actually do enforce initialization compile time, but only by adopting a conservative set of rules for "definite assignment, outlawing programs for which correctness is difficult or impossible to verify at compile time. Chapter 1 Introduction 3 4 5 6 program (5) Index Symbol 1 void 2 int i j (= getint putint call (3) (6) call I (3) (2) (2) (5) Type type type func: (1)→ (2) func: (2)→ (1) (6) while (5) (6) if (5) E (5) call (4) (5) (6) (6) (6) (5) Figure 1.6 Syntax tree and symbol table for the GCD program. Note the contrast to Fig- ure 1.5: the syntax tree retains just the essential structure of the program, omitting details that were needed only to drive the parsing algorithm. idealized machine. We will consider this option further in Chapter 15, where a control flow graph for our GCD program appears in Figure 15.3. In a suite of re- lated compilers, the front ends for several languages and the back ends for several machines would share a common intermediate form.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Managing System
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education