Question: 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
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:
![reg_names : array [0..k-1] of register.name := [](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1606/3/7/9/0815fbf6649629f41606379081110.jpg)
![reg_names : array [0..k-1] of register.name := ["r1, "r2" .., "rk"] --](https://dsd5zvtm8ll6.cloudfront.net/si.question.images/images/question_images/1606/3/7/9/2165fbf66d0729a61606379215394.jpg)
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 := stmtj.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 stmt2 stmtz stmt 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 ":"] + stmt2.code + [L2 ":"] + stmt.code assign : stmt - id expr stmtz expr.next.free_reg := stmt2.next.freereg := stmtj.next.free.reg stmt.code := expr.code + [id.stpname ":=" expr.reg] + stmt2.code read : stmt + id, idz stmt2 stmtj.code := ["a1 := &" id.stpname] + ["call" if id2.stp>type = int then "readint" else ...] + [idz.stpname ":= rv"] + stmt2.code %3D -- file write : stmt id expr stmt2 expr.next_free_reg := stmt2.next.freereg := stmtj.next.free.reg stmtj.code := ["a1 := &" id.stpname] + ["a2 :=" expr.reg] + ["call" if id.stp type = int then "writeint" else ..] + stmt2.code -- file -- value writeln : stmti + id stmtz stmtj.code := ["a1 := &" id.stpname] + ["call writeln"] + stmt2.code null : stmt
Step by Step Solution
3.38 Rating (170 Votes )
There are 3 Steps involved in it
ANSWER The modified grammar of Figure 156 to generate jump code for Boolean expressions can be repre... View full answer
Get step-by-step solutions from verified subject matter experts
