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...
-
record the journal entries required for the following 1. The company purchased a building December 1, 2017 with a LT Mortgage Payable of $300,000 at 8% interest. (Record the purchase of the...
-
Sale prices of apartments. A Minneapolis, Minnesota, real-estate appraiser used regression analysis to explore the relationship between the sale prices of apartment buildings sold in Minneapolis and...
-
One item is omitted from each of the following computations of the rate of return on investment: Determine the missing items, identifying each by the appropriateletter. Rate of Return on Investment...
-
A partnership of attorneys in the St. Louis, Missouri, area has the following balance sheet accounts as of January 1, 2021: Assets $ 338,000 Liabilities $ 108,000 Athos, capital 90,000 Porthos,...
-
Given a database of the results of an election, find the number of seats won by each party. There are some rules to going about this: There are many constituencies in a state and many candidates who...
-
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 converging lens with a focal length of 15.0 cm and a diverging lens are placed 25.0 cm apart, with the converging lens on the left. A 2.00-cm-high object is placed 22.0 cm to the left of the...
-
1- What is the chairman of the Texas State Board of Education's primary occupation? 2- Why are the decisions the Texas State Board of Education make about their high school science standards so...
-
SECTION 7 KEEPING ENTIRE STRUCTURES IN EQUILIBRIUM ASSIGNMENT #2 1. Find the reactions at A and C. A 2. Find the reactions at A and C. 60.0 kN B 3.00 9.00 4.00 6.00 5.00 kN 3.00 B 1.00 2.00 10.0 kN...
-
The year-end financial statements of Python Tax Services are provided below. Service revenue Expenses: Salaries Utilities Insurance Supplies Net income PYTHORT TAX SERVICES Income Statement $ 68,500...
-
a. Calculate the volume of the solid of revolution created by rotating the curve y=2+4 exp(-5 x) about the x-axis, for x between 2 and 4. Volume: b. The equation of a circle of radius r, centered at...
-
The simply supported timber beam of Figure 1 is made-up by gluing together three 300 mm by 150 mm planks as shown. The beam has to carry a uniformly distributed vertically downward load of 8 kN/m for...
-
In Problems, use technology to graph the functions. y = ln (0.5x)
-
Suppose the index goes to 18 percent in year 5. What is the effective cost of the unrestricted ARM?
-
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?
-
7 . 4 3 Buy - side vs . sell - side analysts' earnings forecasts. Refer to the Financial Analysts Journal ( July / August 2 0 0 8 ) study of earnings forecasts of buy - side and sell - side analysts,...
-
Bond P is a premium bond with a coupon of 8.6 percent , a YTM of 7.35 percent, and 15 years to maturity. Bond D is a discount bond with a coupon of 8.6 percent, a YTM of 10.35 percent, and also 15...
-
QUESTION 2 (25 MARKS) The draft financial statements of Sirius Bhd, Vega Bhd, Rigel Bhd and Capella for the year ended 31 December 2018 are as follows: Statement of Profit or Loss for the year ended...
Study smarter with the SolutionInn App