Backpatching
Backpatching
(2)
E.fobelut:= E,falselist 4
E’E, and MEZ { back patch (E,.tuettst , Mquad);
Eteuetst ! = E.tueltst i
E.falset : merge
(3) E-’not E (Efalschst,Efalselut)
E.tueltst : =Efalselist ;
E falselut : E truetst ; ?
(4) E (e)
E.truelist =E trueltst;
EfalselSt : = Etfalseltst i?
5) E’id, relop id,
EEhuelst : = makdut (nextquad);
Efalselist=makelist (nertquad +);
emit ("f"id,-place relop.op tda-ploae
qoto-)
emit ('gdto-)
(6)
E’true S Etruetst : = makel st (netquad);
emt ("goto?
) E false
FE.falsetst : = makeltst (net quod)
emt ("goto)}
() ME fM.quad: neztquad ?
Scheme to tmplement the Translatton:
The semantic rules tor the revised gramman
follouas:
() S if Ethen M,S, N else M262
backpatch (E:truel:st, M,.quad):
backpatch (E-fasc ltst , Ma.qod);
S.neittist : =merge (S1-nezt t:st, merge
(N.neatlist ,Sz .nettltst)
We backpatch the lums wohen E is true to the
Quadruple Mi-quad,ohich is the begtnin1 of the Code
for Si- Stm1laaly, oe backpatch iumps uohen E ts fase
to go to the begnin1 of the Code for S2. The (1st
S.necttist incude all iumps out ot S and S as
loell as the ump generated N.
(2) N ’e $ N.nezttst : -makelat (nertquad) ;
emt ('goto-)3
(3) M e M.quad :=nextaod
(2) S’fE then Ms, backpatch (Etrueltst, M. quad);
S-nextlist : =merge (Efalse list,
(5) S ’hele ME do M,S, SiDerttist)y
lbackpatoh (S1-nextst ,;'
Mi-quad);
backpaBeh (Etrueltst , M uad);
S"nexttst : = E.faekst
emt ( goto' Miquad)3
(6) S’beg1n end FS.nettist : = L.nextlist
() s’A
fS.nexttist
The ass1gnmet 6-nexttst = nd inttalizes Snexthst to
an empty hst.
(8) L 4 ; MS backpatch (4.hexttst ,M.quad)/
Linextltst : = S.nexttst ?
The statement follouotng L in ordey of ereatton a the
beginming of S. thus the LI. nexttst ltst ts backpatched
to the
beginng of the code for S, ohch is gven by
Mquad
(4) L’S
fL.netltst : S.ne tltst
Example;
if (<Do || 7 200 && -4) 10;