0% found this document useful (0 votes)
20 views9 pages

Chapter-5 - Intermediate Code Generationfsjfksjkfjsdjfdkjf

Uploaded by

Dhiraj Udhani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views9 pages

Chapter-5 - Intermediate Code Generationfsjfksjkfjsdjfdkjf

Uploaded by

Dhiraj Udhani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Chs5 Tntermediate Code

Cenerotion

Intesmediate Code:
ComPiles ConvestS ehe SoUdce
mto ecsy to P am
dePresemt cmuage
lamguoge
eTmediate Called
CeCC
+ho
directYlungucge in+o
befos
befotee trans lcatI
latin2
macwne
mucne uvuage
The dePre S
avauce Prorm.
rjam,
entction of Hhe
ngucge Caum be
Classilies jntesmedi ate
(1) Hiah level as:
KePres entadt ion:
T + is closesto h e
Souce
T etang Progam
T + is hePaogaUm 9¥TuCture
easy togenesate rom Hhe
u t in
He, Code P he 1]p
ilp Paq1a,
Paejra
zatiom is n ot
S+Saight toTOaTd.
Ex Syn+ax tree
Pos+fix ExPTessioM,
DA
Lo vel ePresentatoL
3T4 is C os es fo h e
T+ 7s ecsy to taxa eA mactinee
fvom fis,
3enerote tara
tasa et Code
et Code
I+ Tequres mo e
1ow ew el effor+S o
En
t e r mediate Code enerete
Cede aom
>om
Three - addreSs Source Code.
Code.
Code.
Sumtax Iec :
T+ S S C ComPact oTm of PaTse
tee +het
ePesenE
he ieracica
S+TUCAUTe o h e PoUA
I n SvmtcAx m.
tre e
Imterio odebaamch
+he OPeCHOD S, nodeg TePTesents
LeLeef nodel Tevmimcd node
+he OPedAndS. de Presents

DA COire cted Acc1ic CraPh):


T+ s
but in moz SimilA o
Sy Cx t e e
CemPeAct foTm. Thot is
DA Common in
SubexPTessionS C e dePresen}td
bysnale mode.
Example a= b*-c+b-c

CL

Umimuß b Uminus
Umins
C

Svntax Tree oAK


*Postfix Notusions /ExPressitns:
T+ s aineaization of c Svn tax tsee.
Tn Pos4ix motation, the opeTcmdS occurs
first Cmd hen OPeTatoss are arremgd,
T 4 is m e ComfACA oTm ofSynie
tree

Example (A + B) *CC+D)
Pos+tix motC+ion : AB CDt*
hsee Address Code
The 4esm }hree Odddess Code" Conains
+hree
And
addesses,fwo toa +Hhe oPerandS
Ome o r h e desult.

Thre e
addre ss Code is a Sequemce ot
Statememt of +he. o t r :
a : b OP C
here, CL,b and C the ae
het Com be names OPeTand s
o r Consaunt=
OP StamdS t o r amy
SPeTtoT.
Ex a =b+ C+d X X *Y +
z-X
Thsee address Code 1s:
ti X*Y
t i = b +c
t2 t1+ Z
ta t1+d t3 t2 -X
a t2 X t3B

tz d 3 CTe h e tem PoTuy


Hee, ti ,
he ComfSler
enerated by
mames
Oifferent Ke PTe senta+ion of hree
Address Code
( Quad uple
Tri Ples
( Tndirect iPle

xamPle 3 X = -

CL* b t - al*b
t CL
t2 t1 *b Three Address Code
t3-CL
t4 t3 * b
ts t z t t y
X
t5

Qucdurle
T+ is
Repesentathom 2
Such as
aSHucAUre c h
cUim ct most
OP, CAsg1 , mos t
ars2 and zesult.tou
tour tieds
tieds
OPerator Asgi Ay2 Result
(oUminus a t1
C * ti b t2
(Uminus aL t
(3 Lab
C + t ty ts
G5)= ts
Tirle RePresentation
not used
Im riple, temPoraries are
SYmo)
nsed of h c t Pointers i n he

able ade used direc+|Y.


T7iples OC Poesentatio is the 6TuCAuTE

COith at moSt three ields CA1,aa32


CAmd OPesCHOr CoP)

OP A Ars2
(o Umimus a

C1 (0)
Cz mimus a

(3 (2
C4 C1 C3)
CS (4)

Indtrec+ iPle RePresentaution


mHis,
+His, h e listin o¥ toiples has been dome
Omd US+ing Pointexs a r e used imSteà oP
usins Statement.

SHatemet OP A1 Aaj2
Co14) Co minus CL
CIS Ct C14D b
C1
C2 mimus C
(2 (16
C3C17D C3 C16) b
(4 + C15) C14
(4 C18)
CsC11
C C18)
*Cons+Tuttion tSyntux Tee DAG

S4ePS
exPression into P0SttiX
Comvert he
0 4 C+ion
Cseate modes vntax t c e
3Coms+a t SynCIX ree.

Cseate 7odes o of DA,


(S) Cons4uct DAC.

tuc+ions to Cvecte he modes o t


Hhe SYmtCAXte e and DAG,

Mkmode CoP, eft, riiht) :


OPeTa+0r node coi+ label OP Ond
swo ieldS Containing Pointers +o left
igt.
(MKleaf Cid,entrr)
Tdentifier node wit label id and
a field Comt ainin
entrY fa Pointer to
h e Gmbol a b l e entry
for the id)
mKleaf Cnum, val):
Numbes nod e with lalbel nym and a
ield Con a i
Valli:HheValue
number).
of the
CXamPle onstTuct SymAx tree tor;
Ca+b* C) ^ Cb* C)/ bfC
B1e 1 Posfix Noctio
abc + bck^blc*
tsee.
of SYmaax
SAeP 2: Cocate modes

Pi:mkleas Cid,entvy tox a);


?2:mKleaf ( 1d, en+Yy tor b)s
P: mkleaf Cid, entry
fo C)3
PA:mKmode C'*', f2, Pa):
Ps: e
C'+', Pa,
PD3
b*C
P6:mklecaf id,entry for
P: b)j
mk leat Cid, emtry for C)
Ps mKmode C"*,
PG, PT);
f mKmode ( , Ps, Ps)
PiomKleuf (id, entry fov
b)
fnmKmode ( /', Pa, Pao)
Pi2mKleaf Cid, entry for
c);
PismKmode * ' , Pu , Pi2);
S+ep 3: ComS4Tu C+ Syn1ex tree

Pa
P6

41Pa
SteP 4
ConstTMCE odes ot DACT.
T TDAG, nodes are
manmes as
onstTuCted in Samne
Symtax tree ex Cept +het modess
O Common odes
Subex PTESs\on are Csecut ed
nce Only
S o 4em the Set of
mod es Ot Svntex tYee of
ven cxPTessiOn, m odes
P6, PT and P% r e
Avoided in DA and
Amd fA are uced insted modeS:
P2, P
TePre sent he
TesPec4ivey
Same
as ey
+hey
Cmd PS. OPeaetlonL as P6, P+
See 5:
Cos+Tu c4 DAGT

idb

You might also like