Design a class hierarchy to represent syntax trees for the CFG of Figure 4.5. Provide a method
Question:
Design a class hierarchy to represent syntax trees for the CFG of Figure 4.5. Provide a method in each class to return the value of a node. Provide constructors that play the role of the make_leaf, make_un_op, and make_bin_op subroutines.
Figure 4.5:
Transcribed Image Text:
+ E2 + T E1.ptr := make bin_op("+", E2.ptr, T.ptr) E1 E + E2 - T E1.ptr := make bin_op("-", E2.ptr, T.ptr) E → T E.ptr := T.ptr T + T2 * F T1.ptr := make bin_op("x", T2.ptr, F.ptr) T - T2 / F T1.ptr := make bin_op(":", T2.ptr, F.ptr) T + F T.ptr := F.ptr - F2 F1.ptr := make.un.op("+/", F2.ptr) F (E ) Fptr := E.ptr F + const F.ptr := make leaf(const.val)
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 50% (6 reviews)
Here is one possible solution in C Alternative formulations are possible ...View the full answer
Answered By
GERALD KAMAU
non-plagiarism work, timely work and A++ work
4.40+
6+ Reviews
11+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
Augment the attribute grammar of Figure 4.5, Figure 4.6, or Exercise 4.21 to initialize a synthesized attribute in every syntax tree node that indicates the location (line and column) at which the...
-
Write an attribute grammar based on the CFG of Figure 4.11 that will build a syntax tree with the structure described in Figure 4.14. Figure 4.11: Figure 4.14: program stmt list $$ stmt list + stmt...
-
Project: Expression Trees This project is adapted from Project 1 of Chapter 9 of the textbook. It deals with a simple kind of expression trees, in which there are two kinds of nodes: (a) Leaf nodes,...
-
Research diversity expert Martin Davidson, author of The End of Diversity as We Know It: Why Diversity Efforts Fail and How Leveraging Difference Can Succeed. What is his direction for how you adopt...
-
Determine the outflow hydrograph given the inflow hydrograph below. Use Muskingum routing, taking K = 2 hr, x = 0.2, and t = 1 hour. Time (hr)Inflow (m3/s) 1.....................100...
-
(a) What percentage of individuals who strongly disagree that there should be a gas tax are older than 60? (b) What percentage of individuals who agree that there should be a new gas tax are aged 18...
-
How helpful is it that jurisdiction of the International Court of Justice is voluntary? Does this completely undermine the credibility or usefulness of the court? What are the advantages and...
-
Consider the following June actual ending balances and July 31, 2012, budgeted amounts for Oleans.com: a. June 30 inventory balance, $17,750 b. July payments for inventory, $4,300 c. July payments of...
-
(a) A company has an EPS of Rs. 2.5 for the last year and the DPS of Rs. 1. The earnings is expected to grow at 2% a year in long run. Currently it is trading at 7 times its earnings. If the required...
-
A 30-m steel tape measured 29.991 m when standardized fully supported under a 5.500-kg pull at a temperature of 20C. The tape weighed 1.22 kg and had a cross-sectional area of 0.016 cm2. What is the...
-
Repeat the previous exercise, but using a variant record (union) type to represent syntax tree nodes. Repeat again using type extensions. Compare the three solutions in terms of clarity, abstraction,...
-
Some language designers argue that object orientation eliminates the need for nested subroutines. Do you agree? Why or why not?
-
Arjun, will you please hold this so we can get it straight and finish the job? Identify the form of communication flow occurring for each statement. A. Vertical downward B. Vertical upward C....
-
In a subsonic wind tunnel, one side of a mercury manometer is connected to the settling chamber and the other side is connected to the test section. The contraction ratio of the nozzle A2/A equals...
-
Describe each step of the Database System Life Cycle and describe how they work together. Explain how the cycle can use in another context. For example, how can these steps be used when buying a car...
-
What type of investment would be low risk for beginners?
-
What is calculated by finding the net profit as a percentage of the total revenue? a.) Asset turnover b.) Profit margin c.) Return on equity d.) Financial leverage
-
Raner, Harris & Chan is a consulting firm that specializes in information systems for medical and dental clinics. The firm has two officesone in Chicago and one in Minneapolis. The firm classifies...
-
On December 31, 2016, Dana Darrius and Lou Gardner agree to combine their sole proprietorships into a partnership. Their balance sheets on December 31 are shown as follows. Requirements 1. Journalize...
-
Imagine a sound wave with a frequency of 1.10 kHz propagating with a speed of 330 m/s. Determine the phase difference in radians between any two points on the wave separated by 10.0 cm.
-
What is the worst-case time for putting n entries in an initially empty hash table, with collisions resolved by chaining? What is the best case?
-
Show the result of Exercise R-10.6, assuming collisions are handled by quadratic probing, up to the point where the method fails.
-
What would be a good hash code for a vehicle identification number that is a string of numbers and letters of the form 9X9XX99X9XX999999,where a 9 represents a digit and an X represents a letter?
-
please find 8-10 sources about the following topics -monetary policy -fiscal policy -supply-side policy -inflation -how inflation has been tackled in the past? -Applications in banks for monetary,...
-
Output Total Cost 0 4000 20 4500 40 4850 60 5150 80 5400 100 5700 120 6100 140 6600 160 7150 180 7750 200 8500 Question 1 What is the profit-margin quantity if p=25 Question 2 What do you predict...
-
Gold Standard System & Stability-Continuity of World Payments. Give quantitative data examples with references to explain the concepts.
Study smarter with the SolutionInn App