Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

6.a. Draw dependency graphs corresponding to each grammar
rule of Example 6.14(page 283) and for expression 7/4/3.0


6.b. Describe the two passes needed to compute the attributes on
the syntax tree of 7/4/3.0, including a possible order in which the
nodes could be visited and the attribute values computed at each
point.

 

and 6.14(page 283) is in the photo

 

 

Example 6.14
Consider the following simple version of an expression grammar:
еxp — ехp / еxp | num| num. num
This grammar has a single operation, division, indicated by the token /. It also has two
versions of numbers: integer numbers consisting of sequences of digits, which we indi-
cate by the token num, and floating-point numbers, which we indicate by the token
num.num. The idea of this grammar is that operations may be interpreted differently,
depending on whether they are floating-point or strictly integer operations. Division, in
particular, is quite different, depending on whether fractions are allowed. If not, divi-
sion is often called a div operation, and the value of 5/4 is 5 div 4 = 1. If floating-
point division is meant, then 5/4 has value 1.2.
Suppose now that a programming language requires mixed expressions to be pro-
moted to floating-point expressions throughout, and the appropriate operations to be
used in their semantics. Thus, the meaning of the expression 5/2/2.0 (assuming left
284
CHAPTER 6 / SEMANTIC ANALYSIS
associativity of division) is 1.25, while the meaning of 5/2/2 is 1.' To describe these
semantics requires three attributes: a synthesized Boolean attribute isFloat which indi-
cates if any part of an expression has a floating-point value; an inherited attribute etype,
with two values int and float, which gives the type of each subexpression and which
depends on isFloat; and, finally, the computed val of each subexpression, which
depends on the inherited etype. This situation also requires that the top-level expression
be identified (so that we know there are no more subexpressions to be considered). We
do this by augmenting the grammar with a start symbol:
S- exp
The attribute equations are given in Table 6.7. In the equations for the grammar rule
exp → num, we have used Float (num.val) to indicate a function that converts the inte-
ger value num.val into a floating-point value. We have also used / for floating-point
division and div for integer division.
The isFloat, etype, and val attributes in this example can be computed by two passes
over the parse or syntax tree. The first pass computes the synthesized attribute isFloat
by a postorder traversal. The second pass computes both the inherited attribute etype
and the synthesized attribute val in a combined preorder/postorder traversal. We leave
the description of these passes and the corresponding attribute computations for the
expression 5/2/2.0 to the exercises, as well as the construction of pseudocode or C code
to perform the successive passes on the syntax tree.
Transcribed Image Text:Example 6.14 Consider the following simple version of an expression grammar: еxp — ехp / еxp | num| num. num This grammar has a single operation, division, indicated by the token /. It also has two versions of numbers: integer numbers consisting of sequences of digits, which we indi- cate by the token num, and floating-point numbers, which we indicate by the token num.num. The idea of this grammar is that operations may be interpreted differently, depending on whether they are floating-point or strictly integer operations. Division, in particular, is quite different, depending on whether fractions are allowed. If not, divi- sion is often called a div operation, and the value of 5/4 is 5 div 4 = 1. If floating- point division is meant, then 5/4 has value 1.2. Suppose now that a programming language requires mixed expressions to be pro- moted to floating-point expressions throughout, and the appropriate operations to be used in their semantics. Thus, the meaning of the expression 5/2/2.0 (assuming left 284 CHAPTER 6 / SEMANTIC ANALYSIS associativity of division) is 1.25, while the meaning of 5/2/2 is 1.' To describe these semantics requires three attributes: a synthesized Boolean attribute isFloat which indi- cates if any part of an expression has a floating-point value; an inherited attribute etype, with two values int and float, which gives the type of each subexpression and which depends on isFloat; and, finally, the computed val of each subexpression, which depends on the inherited etype. This situation also requires that the top-level expression be identified (so that we know there are no more subexpressions to be considered). We do this by augmenting the grammar with a start symbol: S- exp The attribute equations are given in Table 6.7. In the equations for the grammar rule exp → num, we have used Float (num.val) to indicate a function that converts the inte- ger value num.val into a floating-point value. We have also used / for floating-point division and div for integer division. The isFloat, etype, and val attributes in this example can be computed by two passes over the parse or syntax tree. The first pass computes the synthesized attribute isFloat by a postorder traversal. The second pass computes both the inherited attribute etype and the synthesized attribute val in a combined preorder/postorder traversal. We leave the description of these passes and the corresponding attribute computations for the expression 5/2/2.0 to the exercises, as well as the construction of pseudocode or C code to perform the successive passes on the syntax tree.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY