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 problem use Theorem 7.1.1 to find [1]{f(t)}. f(t) = (1 + e 2t ) 2 Theorem 7.1.1 1 (a) L{1} = - n! n = 1, 2, 3, ... =-- s - a (b) L{t"} (c) L{e"} k (d) L{sin kt} (e) L{cos kt} 5? + k? s? + k? k...
-
Compare gas turbines with I.C. engines.
-
Dillard Travey receives 5,000 tripods annually from Quality Suppliers to meet his annual demand. Dillard runs a large photographic outlet, and the tripods are used primarily with 35-mm cameras. The...
-
Read the passage below. Based on your reading assignment, please answer the two-tiered question below. Incorporate your academic opinion, which should be supported by your research findings rather a...
-
The following is a series of annual sales (in $ millions) over an 11- year period ( 2003 to 2013): a. Construct a time- series plot. b. Does there appear to be any change in annual sales over time?...
-
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:...
-
For each of the following, either construct a formal proof of its validity or prove it invalid, in each case using the suggested notation: No employee who is either slovenly or discourteous can be...
-
Explain three consequences of deflation.
-
Explain three different, market-based, supply-side policies.
-
For years, observers and analysts of the debt market believed that municipal securities were free of any risk of default. Why do most people now believe that municipal debt can carry a substantial...
-
Explain three potential benefits from international trade.
-
Explain two factors that limit the effectiveness of the World Trade Organization in achieving its objectives.
-
A beam of polarized light with an average intensity of 15 W/m2 is sent through a polarizer. The transmission axis makes an angle of 25 with respect to the direction of polarization. Determine the rms...
-
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?
-
The Moon's diameter is 3.5x10 km, and its distance from Earth is 3.8x10 5 km. The image is formed by the Hale Telescope reflecting mirror, which has a focal length of +16.9 m. A. Determine the...
-
How does the position of the storm relative to the land influence the area with the fastest wind speeds?
-
An object moving on the x axis with a constant acceleration increases its x coordinate by 191 m in a time of 7.94 s and has a velocity of 20 m/s at the end of this time. Determine the acceleration of...
Study smarter with the SolutionInn App