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 student solved the following inequality incorrectly as shown. Give the correct solution set. 4x = -64 4x 4 -64 4 x < -16 Solution set: (-, -16]
-
Choose a product and sell it using the FAB methodology.
-
Ellis issues 6.5%, five-year bonds dated January 1, 2015, with a $250,000 par value. The bonds pay interest on June 30 and December 31 and are issued at a price of $255,333. The annual market rate is...
-
Write a program named Admission for a college's admissions office. The user enters a numeric high school grade point average (0.00-4.00) and an admission test score (0-100). Display the message...
-
Which of the graphs in Fig. Q25.12 best illustrates the current I in a real resistor as a function of the potential difference V across it? Explain. Figure Q25.12 (a) (b) (c) (d)
-
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?
-
Specify whether the following statement is true or false. Justify your answer, if the bilinear transformation is used to transform a continuous-time all-pass system to discrete-time system, the...
-
Today, you deposit the first of five annual payments into an account. Each payment is $4,000 and occurs at the beginning of each year. You earn 10%, annual compounding. The future value of this...
-
The cost of debt for firm XYZ is 6%.It's tax rate is 40%. The cost of retained earnings is 12% and the cost of external common equity is 14%. Retained earnings is $5000. The target capital structure...
-
Your firm has total debt of $4, 180 and debt equity ratio 0.79. What is the amount of total assets? Round your answer to the nearest number, no percentage sign. Answer
-
Money Bags Increases capital by selling a financial security that promises to pay investors cash flows of $300 next year, $400 in year 2, and $500 in year 3, with no risk. According to the Law of One...
-
The Marty's buy a house and borrow $350,000 from Rocket Mortgage Company. The mortgage carries an interest rate of 6% and is guaranteed for five years. After exactly two years of making monthly...
-
Golda Inc. has the following shareholders' equity: Preferred shares, $0.025, cumulative, liquidation value $0.50, 50,000 shares authorized, 45,000 shares issued and...
-
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?
-
Company name is Walmart, Inc. here is the link https://www.sec.gov/ix?doc=/Archives/edgar/data/104169/000010416923000020/wmt-20230131.htm Overview 1. The financial statements for your company are...
-
Congress would like to increase tax revenues by 19 percent. Assume that the average taxpayer in the United States earns $54,000 and pays an average tax rate of 15 percent. Required: a. If the income...
-
Best Solutions is a retail merchandiser selling computer equipment. Best uses the gross method of accounting for inventory purchases and sales, a perpetual inventory system with LIFO inventory...
Study smarter with the SolutionInn App