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 consumer must divide $250 between the consumption of product X and product Y. The relevant market prices are Px = $5 and Py = $10. a. Write the equation for the consumers budget line. b. Illustrate...
-
BioMask Genetics is a biotechnology firm with only one patent to its name. The after-tax operating earnings in the current year are \($10\) million, and the firm has no reinvestment needs. The patent...
-
On December 31, 2010, Beckford Company issues 150,000 stock-appreciation rights to its officers entitling them to receive cash for the difference between the market price of its stock and a...
-
. Document4 - Word Search Ama References Mailings Review View Help A A Aa Ap EVENWENT AaBbCcDd |AaBbCcDd AaBbC( AaBbCct Ad B AaBbCCD AaBb A ~ DA 1 Normal 1 No Spac.. Heading 1 Heading 2 Title ...
-
McDonald's Corporation franchises and operates more than 36,000 fast-service restaurants around the world. Buffalo Wild Wings franchises and operates more than 1,000 restaurants in North America....
-
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?
-
A life insurance policy is a financial asset. The premiums paid represent the investments cost. a. How would you calculate the expected return on a life insurance policy? b. Suppose the owner of a...
-
Define chosen public health issue Tobacco use in New South Wales. This will require research on: current statistics on tobacco use, existing policies for tobacco use and evidence-based policy...
-
The company finances 20% of its assets with debt, 20% with preferred equity, and the rest with common equity. The cost of debt is 9%; the cost of preferred is 14%, and the cost of common equity is...
-
Read the articles: Kotter, J. P. (1998). Winning at changeLinks to an external site. . Leader to Leader , 1998 (10), 27-33. https://doi.org/10.1002/ltl.40619981009 Kotter. (n.d.). The 8 steps for...
-
A long vertical drain is going to be made in a soil. Assume the failure plane shown in the figure. The soil is fully saturated. Assume that the lining does not provide any resistance against failure....
-
The Black Forest Cake Company just paid an annual dividend of $3.98. If you expect a constant growth rate of 5.60 percent, and have a required rate of return of 13.60 percent, what is the current...
-
Discuss Caterpillar's future. What should it do next with its product line? Where is the future growth for this company?
-
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?
-
What is one benefit of participating in an employer-sponsored retirement plan? Group of answer choices Money is automatically deducted from your paycheck each month and invested for you. Some...
-
According to ICH Q3A(R2), how are specified impurities defined? Group of answer choices Impurities exceeding 0.1% Individually listed and limited with a specific acceptance criterion Identified...
-
In September and October 2008, financial markets around the world suffered a severe crash as Group of answer choices there was aggressive lending to subprime borrowers in a deregulated environment....
Study smarter with the SolutionInn App