One problem (of many) with the code we generated in Section 15.3 is that it computes at
Question:
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 15.6 to perform a simple form of constant folding: whenever both operands of an operator are compile-time constants, we should compute the value at compile time and then generate code that uses the value directly. Be sure to consider how to handle overflow.
Figure 15.6:
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.free_reg := stmt3.next_free_reg := stmt.next.free_reg L1:= new.label(); L2 := newJabel() stmtj.code := ["goto" L1] + [L2 ":"] + stmt2.code + [L1 ":"] + expr.code + ["if" expr.reg "goto" L2] + stmt3.code if : stmti expr stmtz stmt3 stmt4 expr.next.free_reg := stmt2.next_free_reg := stmt3.next_free_reg := stmt4.next_free_reg := stmtj.next-free-reg L1:= new.label(); L2 := newJabel() stmtj.code := expr.code + ["if" expr.reg "goto" L1] + stmt3.code + ["goto" L2] + [L1 ":"] + stmtz.code + [L2 ":"] + stmtą.code assign : stmt → id expr stmtz expr.next.free_reg := stmt,.next.free. reg := stmtj.next.free.reg stmti.code := expr.code + [id.stp→name ":=" expr.reg] + stmt2.code read : stmtį + id, idz stmt2 stmtj.code := ["a1 := &" idj.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 -- file -- value %3D writeln : stmt id stmtz stmtj.code := ["a1 := &" id.stpname] + ["call writeln"] + stmt2.code null : stmt
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 44% (9 reviews)
ANSWER regnames array 0k1 of registername r1 r2 rk ordered set of temporaries program stmt stmtnextf...View the full answer
Answered By
Churchil Mino
I have been a tutor for 2 years and have experience working with students of all ages and abilities. I am comfortable working with students one-on-one or in small groups, and am able to adapt my teaching style to meet the needs of each individual. I am patient and supportive, and my goal is to help my students succeed.
I have a strong background in math and science, and have tutored students in these subjects at all levels, from elementary school to college. I have also helped students prepare for standardized tests such as the SAT and ACT. In addition to academic tutoring, I have also worked as a swim coach and a camp counselor, and have experience working with children with special needs.
0.00
0 Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
Eight people were asked to perform a simple puzzle-assembly task under normal conditions and under stressful conditions. During the stressful time, a stimulus was delivered to subjects 3 minutes...
-
How many time constants will it take for a charged capacitor to be discharged to one-fourth of its initial stored energy?
-
Generate equilibrium constant expressions for the following reactions. Calculate numerical values for Keq.
-
In a popular carnival ride called The Centrifuge, shown above, riders stand against the inside wall of a large cylinder, which starts spinning. The radius of the circle traveled by the riders is 4 ....
-
Consider a thermal energy reservoir at 1500 K that can supply heat at a rate of 150,000 kJ/h. Determine the exergy of this supplied energy, assuming an environmental temperature of 25C.
-
How marketers use advertising media to achieve specific marketing and communications objectives. Of this three of the Media Types below. Identify examples of advertisements placed in each of the...
-
How gas turbines are classified ?
-
The Salida Salt Company is considering making a bid to supply the highway department with rock salt to drop on roads in the county during the winter. The contract will guarantee a minimum of 25,000...
-
The statement describes the speaker's activities throughout the day. They got up at 8 o'clock and got themselves and their children dressed before packing up the car and heading to a restaurant for...
-
A store maintains data on customers, products and purchase records in three tables: CUSTOMER, PRODUCT, PURCHASE. The store manager wants to know which product is on its maximum discount for each...
-
Modify the grammar of Figure 15.6 to generate jump code for Boolean expressions, as described in Section 6.4.1. You should assume short circuit evaluation. Figure 15.6 : type = int then "readint"...
-
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...
-
Dirk SA reported the following balances at December 31, 2019: share capitalordinary 500,000, share premiumordinary 100,000, and retained earnings 250,000. During 2020, the following transactions...
-
Explain how a reduction in taxes may be considered as both a demand-side policy and a supply-side policy.
-
Why isn't the Treasury yield curve used as a benchmark in measuring yield spreads between different sectors of the municipal bond market?
-
Explain three arguments in favour of trade protection.
-
Indicate whether you agree or disagree with the following statements: a. "To determine the theoretical value of an option, we will need some measure of the price volatility of the underlying asset....
-
Explain three arguments against trade protection.
-
An argon-ion laser produces a cylindrical beam of light whose average power is 0.750 W. How much energy is contained in a 2.50-m length of the beam?
-
1. True or False. Pitfalls to consider in a statistical test include nonrandom samples, small sample size, and lack of causal links. 2. Because 25 percent of the students in my morning statistics...
-
Define carrier signal and explain its role in analog transmission.
-
Calculate the baud rate for the given bit rate and type of modulation. a. 2000 bps, FSK b. 4000 bps, ASK c. 6000 bps, QPSK d. 36,000 bps, 64-QAM
-
Define analog transmission.
-
A 3.0 resistor is connected across the terminals of a 100 V battery. If 0.50 A of current flows, what is the internal resistance of the battery?
-
The rate of blood flow through the aorta is Q = 100 cm/s. A capillary has an average cross sectional area of Acap = 3 x10 -11 m and supports a blood speed of cap = 1 mm/s. From this information, what...
-
A particle is trapped in a potential well described by U(x)=16-b where U is in joules, x is in meters, and b= 4.0 J. Find the force on the particle when it's at a) x=2.2m and b) x=-1.7m.
Study smarter with the SolutionInn App