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: 62% (8 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.
-
show working no excel answer Question 3 a) A firm has determined its optimal structure which is composed of the following sources and target market value proportions. Long-term_debt 30%...
-
Conserving energy. Example 5 describes an experiment to learn whether providing households with electronic meters or with charts will reduce their electricity consumption. An executive of the...
-
Suppose you are the victim of an identity thief who continues to use your identity and to ruin your credit rating after you have discovered the problem. What problems do you have in clearing your...
-
1. What is a relevant range? 2. Give two examples of costs that are variable costs and two examples of fixed costs.
-
Mr B aged 52 years, has earned rupees 75,00,000 out of his business. His ex-wife gifted him a car worth rupees 8 lakh. He spent a total of rupees 20 lakh during a family trip. He won a lottery of 16...
-
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:...
-
What is cause-and-effect analysis and how is it used within the context of quality control?
-
A large-sized chemical company is considering investing in a project that costs `5,00,000. The estimated salvage value is zero; tax rate is 35 per cent. The company uses straight line method of...
-
From the following budgeted and actual figures, calculate and present the variances in respect of profit on sales and cost of sales. Budget: Sales, 2,000 units @ 15 each Cost of sales @ 12 each...
-
(a) From the following data of a manufacturing unit, find out (i) sales to break-even and (ii) sales to earn a profit of 8,000. (b) The following information is available for companies A and B. (i)...
-
Wowem Corporation manufactures a wide range of clothing apparel. It is a decentralized organization in which different divisions have responsibility for the manufacture and distribution of major...
-
(a) Use a molecular orbital program or input and output from software supplied by your instructor to construct a molecular orbital energy-level diagram to correlate the MO (from the output) and AO...
-
When 11.1 g of marble chips (calcium carbonate) is treated with 54.3 mL of hydrochloric acid (density 1.096 g/mL), the marble dissolves, giving a solution and releasing carbon dioxide gas. The...
-
After graduating from college and working a few years at a small technology firm. Preet scored a high-level job in the logistics department at Amex Corporation. Amex sells high-quality electronic...
-
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?
-
In 2019, Sunland Company had a break-even point of $388,000 based on a selling price of $5 per unit and fixed costs of $155,200. In 2020, the selling price and the variable costs per unit did not...
-
11. String Conversion Given a binary string consisting of characters '0's and '1', the following operation can be performed it: Choose two adjacent characters, and replace both the characters with...
-
Consider the table shown below to answer the question posed in part a. Parts b and c are independent of the given table. Callaway Golf (ELY) Alaska Air Group (ALK) Yum! Brands (YUM) Caterpillar...
Study smarter with the SolutionInn App