5. Consider the following syntax-directed translation scheme. (1) P→ P:MS (2) PS (3) S begin Pend (4) S→ while M E do M2
Posted: Sat May 14, 2022 4:56 pm
5. Consider the following syntax-directed translation scheme. (1) P→ P:MS (2) PS (3) S begin Pend (4) S→ while M E do M2 Si { backpatch (P1 . nextlist, M. quad) P. nextlist := S. nextlist {P. nextlist := S. nextlist } { S. nextlist :=Pnextlist } (5) SL:=E (6) N → (7) M → (8) E E relop E2 (9) E E, arith-op E2 (10) E (E) (11) Enum (12) EL { backpatch (Si . nextlist, M . quad); backpatch (E. truelist, M. quad); S. nextlist := E. falselist; emit ("goto' M . quad) } { S. nextlist := null; if L . offset = null then emit (L . place := E. place) else emit (L . place '' L . offset '=' E. place) } {N. nextlist := makelist (nextquad); emit ('goto-') } {M. quad := nextquad } { E. truelist := makelist (nextquad); E. falselist := makelist (nextquad + 1); emit (if Ei place relop E2 · place 'goto -); emit ("goto -') } { E. place := newtemp; emit (E. place := Ei place arith-op E, . place) } { E. place := Ej . place } {E. place := num. lexval } { if L . offset = null then E.place := L .place else begin E place := newtemp: emit (E. place :=' L . place [' L . offset 1) end {L. place := newtemp; L. offset := newtemp; emit (L. place='c (Elist . array)); emit (L. offset :=' Elist. place *** width (Elist. array)) } {L. place := id. place; L. offset := null } { t = newtemp; t2 := newtemp: m:= Elisti . ndim + 1; emit (t1 :=' Elist, place "*" limit (Elist, array, m)); emit (t2 ":='t'+'E. place); Elist array := Elist1 . array; Elist place := t2: Elist . ndim :=m} { Elist array := id. place; Elist. place := E. place: Elist . ndim := 1) (13) L → Elist] (14) Lid (15) Elist → Elisti , E (16) Elist →id [E
Show the intermediate code which is generated for the program below. I := 1; while I <= N do begin J: = 1; while J <= N do begin C[I, J] := A (I, J] + B [I, J]; J := J + 1 end; I := I + 1 end Arrays A, B and C are dimensioned at (1..100, 1..100). Each element should be considered as a 4-byte integer. Note that you are asked only to give the code and need not give the attributed parse tree unless it is helpful to you in computing the solution.
Show the intermediate code which is generated for the program below. I := 1; while I <= N do begin J: = 1; while J <= N do begin C[I, J] := A (I, J] + B [I, J]; J := J + 1 end; I := I + 1 end Arrays A, B and C are dimensioned at (1..100, 1..100). Each element should be considered as a 4-byte integer. Note that you are asked only to give the code and need not give the attributed parse tree unless it is helpful to you in computing the solution.