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.
-
Which of the following is the primary source of revenue for a service business? A. The production of products from raw materials B. The purchase and resale of finished products C. Providing...
-
Use Table 1, or software, to find (a) \(B(7 ; 18,0.45)\); (b) \(b(7 ; 18,0.45)\); (c) \(B(8 ; 11,0.95)\); (d) \(b(8 ; 11,0.95)\); (e) \(\sum_{k=4}^{11} b(k ; 11,0.35)\); (f) \(\sum_{k=2}^{4} b(k ;...
-
Norsums Department Store sells gift certificates that are redeemable in merchandise. During 2011, Norsums sold gift certificates for $88,000. Merchandise with the total price of $52,000 was redeemed...
-
Context: Flex seal, a family owned business, in Weston Florida was founded in 2011. It is a known American brand that specializes in adhesive bonding products. The start of their product line was the...
-
During 2016, Fitness Equipment Doctor made the following purchases: On March 3, Fitness Equipment Doctor, Inc., purchased equipment for $3,600 cash. The equipment has an estimated useful life of...
-
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...
-
The following data relate to notes receivable and interest for Vidovich Co Mar. 3. Received a $72,000, 9%, 60-day note on account. 25. Received a $10,000, 8%, 90-day note on account. May 2. Received...
-
Discuss the rediscovery of the victim. How far should victims have rights in the criminal justice process? Can these conflict with the offenders' rights?
-
Paul Grant, a 40-year-old resident of Florida, was referred by his regular physician in Florida to Dr. Michael Galloway at his specialty clinic in Atlanta, Georgia. Dr. Galloway recommended surgery...
-
Go to three of the e-discovery websites in the "Internet Sites" and compare and contrast the services of the vendors. Which one would you use? Why?
-
Why do you think states have laws requiring that contracting parties have capacity to enter into a contract? Do you these laws are beneficial? Do you know anyone who has been unable to enter into a...
-
You are the facility services director for a small, but important, nonprofit organization that helps protect and relocate spouses who are the victims of abuse. Wanting to make an improvement to its...
-
The balance in the unearned fees account, before adjustment at the end of the year, is $36,950. Journalize the adjusting entry required if the amount of unearned fees at the end of the year is...
-
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.
-
You are working in a clinic and have just roomed a patient. When you come out of the room, you overhear me complaining to two co-workers about you and how slow you are. [Take the role of the other...
-
What are the advantages and pitfalls of the media's appetite for telling and selling stories? As we reach the point where almost all media exist on the Internet in some form, how have our culture and...
-
When looking at a project to convert data into information, data analysis is the methodology thatshould be used to accomplish the output. When reviewing the tools used in the course and the data that...
Study smarter with the SolutionInn App