Add productions and attribute rules to the grammar of Figure 15.6 to handle Ada-style for loops. Using
Question:
Add productions and attribute rules to the grammar of Figure 15.6 to handle Ada-style for loops. Using your modified grammar, hand-translate the syntax tree of Figure 15.10 into pseudo assembly notation. Keep the index variable and the upper loop bound in registers.
Figure 15.6:
Figure 15.10:
Transcribed Image Text:
reg_names : array [0..k-1] of register_name := ["r1", "r2" ..., "rk"] -- ordered set of temporaries program - stmt stmt.next.free_reg := 0 program.code := ["main:"] + stmt.code + ["goto exit"] while : stmt → expr stmtz stmtz expr.next.free_reg := stmt2.next.freereg := stmt.next.free_reg := stmtj.next.free_reg L1:= new.label(); L2 := new Jabel() stmtj.code := ["goto" L1] + [L2 ":"] + stmt2.code + [L1 ":"] + expr.code + ["if" expr.reg "goto" L2] + stmt3.code if : stmti → expr stmt2 stmt3 stmtą expr.next_free_reg := stmt2.next.free reg := stmt3.next.free_reg := stmtą.next_free_reg := stmtj.next-free-reg L1:= new.label(); L2 := newJabel() stmtj.code := expr.code + ["if" expr.reg "goto" L1] + stmtz.code + ["goto" L2] + [L1 ":"] + stmt2.code + [L2 ":"] + stmt4.code assign : stmtj → id expr stmtz expr.next.free_reg := stmt,.next.free. reg := stmtj.next.free_reg stmti.code := expr.code + [id.stpname ":=" expr.reg] + stmt2.code read : stmt → id, idz stmtz stmtj.code := ["al := &" id,.stp→name] + ["call" if id2.stp→type = int then "readint" else...] + [id2.stp-→name ":= rv"] + stmt2.code -- file write : stmtį + id expr stmt2 expr.next.free_reg := stmt2.next.free reg := stmtj.next.free_reg stmtj.code := ["a1 := &" id.stp→name] + ["a2 :=" expr.reg) + ["call" if id.stp→type int then "writeint" else..] + stmt2.code %3D -- file -- value writeln : stmtį + id stmtz stmtj.code := ["a1 := &" id.stpname] + ["call writeln"] + stmt2.code
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 71% (7 reviews)
To address the question we need to 1 Add productions and attribute rules to the existing grammar to handle Adastyle for loops 2 Use the modified gramm...View the full answer
Answered By
Sandip Agarwal
I have an experience of over 4 years in tutoring. I have solved more than 2100 assignments and I am comfortable with all levels of writing and referencing.
4.70+
19+ Reviews
29+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
The grammar of Figure 15.6 assumes that all variables are global. In the presence of subroutines, we should need to generate different code (with fp-relative displacement mode addressing) to access...
-
Our GCD program did not employ subroutines. Extend the grammar of Figure 15.6 to handle procedures without parameters (feel free to adopt any reasonable conventions on the structure of the syntax...
-
Modify the grammar of Figure 2.25 so that it accepts only programs that contain at least one write statement. Make the same change in the solution to Exercise 2.17. Based on your experience, what do...
-
Draw with Ruler Touch Touch 4x For each of the three simple circuit boards you will need to calculate the total resistance, Req, for the entire circuit board by using the measured resistances of each...
-
A heat engine that receives heat from a furnace at 1200C and rejects waste heat to a river at 20C has a thermal efficiency of 40 percent. Determine the second-law efficiency of this power plant.
-
In the cost equation Y = a + bx, Y represents which of the following? A. Fixed costs B. Variable costs C. Total costs D. Units of production
-
Which conditions for the binomial distribution, if any, fail to hold in the following situations? (a) The number of persons having a cold at a family reunion attended by 30 persons. (b) Among 8...
-
Which cost component can be found in a downstream department of a multidepartment production process that will not be present in the first upstream department? Discuss.
-
How do charismatic leadership attributes influence organizational culture and employee motivation, and what potential pitfalls should leaders be mindful of when exercising charismatic influence ?...
-
Should it be permitted to add, delete, and change requirements after they have been approved up to the time a contract has been signed with a service provider? Should it even be possible to add,...
-
One problem (of many) with the code we generated in Section 15.3 is that it computes at run time the value of expressions that could have been computed at compile time. Modify the grammar of Figure...
-
Modify the attribute grammar of Figure 15.6 in such a way that it will generate the control flow graph of Figure 15.3 instead of the linear assembly code of Figure 15.7. Figure 15.3: Figure 15.6:...
-
Use rectangles to find the exact area under the graph of y=3x2 from x=0 to x=1. Use n equal subintervals.
-
Think about ways to prevent discrimination (blatant or not) during the hiring process. If you had to provide advice to those in your organization conducting the interviews, what would it be regarding...
-
How do you think business owners deal with this in their contracts?
-
Katrina, a risk manager for State Farm Insurance, filed a petition in bankruptcy, seeking to discharge $55,000 in credit-card debts and $35,000 in student loans. Katrina's husband died and left her...
-
CMS declined to create a rebuttable presumption that a transaction is fair market value. CMS's conclusion? What are the practical and policy implications of CMS's decision in this regard?
-
What are Document existing and developing threats related to Artificial Intelligence. Which one are you the most concerned about and why?
-
The prepaid insurance account had a balance of $7,000 at the beginning of the year. The account was debited for $24,000 for premiums on policies purchased during the year. Journalize the adjusting...
-
Briefly discuss the implications of the financial statement presentation project for the reporting of stockholders equity.
-
We want to transmit 1000 characters with each character encoded as 8 bits. a. Find the number of transmitted bits for synchronous transmission. b. Find the number of transmitted bits for asynchronous...
-
We need a three-stage space-division switch with N = 100. We use 10 crossbars at the first and third stages and 4 crossbars at the middle stage. a. Draw the configuration diagram. b. Calculate the...
-
Consider an n k crossbar switch with n inputs and k outputs. a. Can we say that the switch acts as a multiplexer if n > k? b. Can we say that the switch acts as a demultiplexer if n < k?
-
Recently, there has been a resurgence in labor union organization and a subsequent increase in union membership across the United States. What can today's labor unions learn from their past 140-year...
-
). Prove by contraposition: "Vm, ne Z, if m -n is even, then m - n is even (15 points)
-
The production function is Y = AKL-a (1) where L is labor at time t, K, is capital at time t, A, is TFP at time t and a (0, 1). The law of motion for capital is K = 8Y-8K Assume that TFP evolves...
Study smarter with the SolutionInn App