0% found this document useful (0 votes)
13 views15 pages

CD ShortNotes

The document outlines the phases of a compiler, including lexical analysis, syntax analysis, and semantic analysis, detailing the processes involved in token generation, parsing, and error detection. It discusses various parsing techniques, including top-down and bottom-up parsing, and the construction of parsing tables using deterministic finite automata (DFA). Additionally, it addresses optimization strategies and the handling of conflicts in grammar during compilation.

Uploaded by

Pradeep Pandey
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)
13 views15 pages

CD ShortNotes

The document outlines the phases of a compiler, including lexical analysis, syntax analysis, and semantic analysis, detailing the processes involved in token generation, parsing, and error detection. It discusses various parsing techniques, including top-down and bottom-up parsing, and the construction of parsing tables using deterministic finite automata (DFA). Additionally, it addresses optimization strategies and the handling of conflicts in grammar during compilation.

Uploaded by

Pradeep Pandey
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/ 15

C/ctt

Complkcty Bytc code


DENSt (ompiler - 1) Msr time consUming phase.
fæs tran 2) ROL!
Cempies " Re acd poam Cho by CAar.calledSUIICA
7lanr (HC (Ons Jencrate toKens 8cnd to pCsCs:
3) Tas transltion nto LAh lang) RUmove White sPau ComYn ,n, \t
"Eos dettchn CQrst rUct pay tial SymbOL tabl (scm)
(Xemcinlng Part S Createol ln Scmcnne Aalys)
4) 3) DFA Wscol tO lesín.
Compu time Run time
Jclentifes
Öyntax Stmnbc
5) Cempilex detects my special symbel
compiu tim (or5)main a denGfre
6) ThL CUe 6 phse
Compiles. 6) Jn c, 32 Ieyw0Td Prstntnot 4Kcyword
mak
RA/ DEA
AcaicQl Analy3es 1) TYp’ Token Lky worcl)
Analysis Rn CAGIDPDA TOKens
(int)
Hntanatycr
detcchon Parse tree 9) dn c, uni ficr
CSGhlLBA must staTt with
Symb Stmantie Analyger Ersor
Tabl CSG1 Annotatcd paroe Hordliny o) Patteon - uler tokin
3ntrmdrat coce Jepresented b e ar tapYesiCn
cntrahÛn.
Three add sex ) Token not Scheratd fur Comment
SHnthesu Codle \n' 1tThcsc aL HmOVcal.
PoTt
-TIansahên Opimisex |R) identihcE/ Keyord
9ptimiscd
TAC other RE: 2ta )*
SneratiÚn 3) C9mmnt nything
A45embly long/
Macn larg |4) Afttr Heacng final tate'Othcr' u
SymbOL tuble Contain infos about CAlucud from ton.
identifeTs 4 Constont. IS) * Comme nt
Variabls
3) A»embly long ç maOin
depencunt.
9) Front Cnd:
indpencent tarjt ong
cdepc ncunt 9n soUrL in (exical anatysa
-hesical Syntok 6tmanhc, Jntermeaiate 11) "H" is a constant phase.
lone.
toKen,
Coe itnv ahon phar Stving
lo) Back endi inclepenclunt
6Ouie lonp
Clepencunt on torgtk lon 19) Opesato t9un,
Constant- intSc Ycal,
Taprct Cide stnratus to CAoracHs,
)) Codu opti misty oes not dupnd On striny
sOUTU lary ner targct (ang. NOTE 3 is ngt a speial
a0)1 CAOTate Ycacl
symbA.
la) PurpOSe to gcncrate
gntrahng nttrmediae speial sgmbel toKen.
COdu ’ Ophmi3ah9n Poslabilit 2U
13) Compilahon - ErTOS letechont Translation bo deyie' id not a tSlan . Is takn
prprocesO nOt compiler.
SyOtax Analy3er CRorse) HOnde tcpt acmint shoul d
eAlE in staThing ymbol
70Kng Pirsc trec4) BOHom up parsing cso known
Syntox eror. 5) sOperShit Reduce passer.
ahtns in vÙtvd in shftReduu
" Shijt RedUCL
6) At end lp if
o = (V, IPS) *voOnasi thTmaL
POwtr stahn" ào"n stack ,meansstothng sMbaI
tt acccpttd.
Ex:- B’bC VfB, Cy,Tby |DConglica B- Shjt Redue conlict
Reauce Recluu Congiiu
B) RPaT8tY CS mar
)
pOwrfu.
3) Passc trec / De nvanon trec:seprestntny,leyt to POrsing
> Rigr mst cesivahon
deivahn in trecs.
Ait LeOf nodes o paTAe trce is )LR PO0%4ing tabu u a DEA, wscd
called Hida PasAe tree. to sesolve conflit.
a) LR pOTSCY = DPDA t DFA
strin mgt thon POrse tree pessjbley ASO:
s4 T[S,a] - Accept : Parsing SUcces,
design Parse. :SyntaX erTor
6) Dtechon 4 eiminonon f omsGUiy o31 TCS,aJ- Shitti
ib undeidobla. Push a,jon staK , incYemun
) Par&tr : mumbership Queo. E:CYK algo LOOrahtacd pnttr.
TC-O)
PassC (DPDA) prodchnn
A’B
Shft sduc POp 2*B|
A) 3ymbeu, PUsL A, Duh
Passcr
Top down parsr Bottom- up ParSCI Soto
en) on njd 3)
Inihially
Brtc
forca
Ressíve LLI) LR SpeYatot DPA PUsL
Onn9 tach &taThng state oy
desut Parse prccaclenee
Pasíg -Parser NOTE: EVery tok1n s a tesminal.
LRLO) SLR) LALRU) R t EX: SacK 1nput A
chion
T[O,QJ= S3

" Parse tree is C1Catdo from (eO ves to 00t A’a


from HOOr tO caves $OA2
POstOrder tíoVetae
Ie/tmeH tn vevecse
|4)AR Pati ne table construChOn:
Tacing CApOngisst
lqtmost "TSaing ightm%E LRIO) SLRLI) LALR ) CLRU)
S r d deivaton in cvcle Pur
(leyr senrenhal fOsm) Order/ igAt sentniau fan) ng 4 grCunmaTA alceptol.
# LR(O) tabu ConstrChon:
BOtUOm Up PorsI
) construct Aupmnted 8/ammor
)Bottom up psing s detccing kondlu CBing stuihing 3ymbel t RHS by
in scltntial doïm A seploig it with adci ng a new preduchen )
Vaniabu. S'’S
) EA SAB
sttp n povC trce sentnhaabmfomj)) conArruct LRIO)
3) Hand eiHarchiS, SUSrins in seacniet tm DFA using
fnom LHS hat matcho RHS prcdhon
lat PicduIn
)Consrucr parsing table om DÉA.4) ArSt sCt: Stt indins Tem
le inA Stale DrA
1)ZRi0) itm s has clot on RHS fsorlA) - ay
DOt E placd t0 mata Aondl. B>E lixecti# OinisecH5
2cossuneL): any non tcrinal exiSE AystlA) = Fist L8)
o A’BKy
firstA)
ArstleyuBHYAt(X) -E yu
Brepaccl by e
) qoto):meV ot onu pOiONpreduchon54Y86
igAt& 3t may indudee.
4) Mare stak navêng aupmentcd B’a/e ArstLB) =a,ey
Accept tn to. S’s. (it not sedua )
Tt8 acCepF
JACHOn tab Contains al ternina EX: S’ ABC 4 A,B,C att prodUles E
with $, GOT0 tabu contains Cle non first(3) =YA16tA)-cuifB) -GY A
B
ttrmin aUs.
6) FOllOuw sct does not contain G.
6)Censtruchng parsng tab rom DFA 6 PollO SCt6 find Jrom RHS Proluchn
NOn termenal tsansition: GOD entoy A
" rerminaL tíansition :Shit
ahon o fOLlOw (Stort symbt) -t$y
o o A’ aBX
COmputdd LRIO) ittm it cdoF at
JUghE Most enl i Rduu aChien. FollOw LB)- AiGt (x)
" Stait havingSs n 8 Cs N
AcCep:
) TO tau no shijt table entnes = NO: FOuow(8) fOLOLwLA)
terminal transiion. X’
- No 9 COT0 table entne = N: 9) foltowlB) =<firstlx)-eyUfolauCA)
nGn ttrminal trangihn.
- NO 9 aCcept cnty ! |8) Puthing MedueL achon in tblus
I3 state has a achon(Aa)
with COYNplete LRIO) tm +(NO. 9 Take fu of LHS dct followA)-B,
Feyminals tI jr$) thes T[Lbib]= te.
3 Shijt-Rtduc of Rdue-Rduce con |lit
piescnt then iB noF LRO) ngY SLR) Clsc tOLKCID
teminct
se iU LRO
A’ xax)4ttr det A’ax A’ X
A’X wniaB’y. B’Y
B’y.
orla nordug ac FOllWLB)
Shgt Rduce conflict Reduca Rduca CnjltkShi{t Reduce conjiCt h e omcthin commion
R-R COnñi
9) Replae E preduchÜn A’E wÍth A6 NOTE: BlanK 'n
tabu i
Dort apply gotO0. Reduc o) NÔ
Io) NO eduu in SLR) < LRIo)
NOTE E sastnne not a teíminae
No error ín SLRl) LRCO)
0) Ambí fuous 8Yammor wl LRO) Aave
8Y Unomisu0a# congnical LR) LKUDJ
conglic in tabu Amoi6uW’ AIOn LRo)

) Tabu Construchions
# Simpu LRI) [SLRUJ: " COnstrUct aumented gramm0.
) SLRU) = LRD) + Arst POlUOw " CenstYUCH CR) m DEA
NO O reouccd achGn is less cOmpQTed 2)Const ruct porsing tablu.
LRLI) (tem= LRLO itm+ LOOkahd
t9 LRo).
3)TAbu construtin sam Us LRlo), SUsH NOTE: FirsF) =t
achon.
dos1sn.
S’ A(B$
A’ a Tmatning
string SLRU) CLRL)S LALR)
4) S’AB,$ ono S ’AB. (LRLO SLRUO D LRO)
5) A0GKche ad dor LALRU) NO 3tates :
Cuyment td produion CLRI) rom ambinubv)
unombiaubus
LRCO) =SLRLI) =LALRly
<CLRL)
6) Pit HCduu in tabu at
lO9KCUhcod
thn put Ha ct Set a ètmyi states
A’ 'cX,ti} TCI4,QJ,T[I4,]yACC
A’x tet
(Yeranother compiler cerpiei
used t0 desisn LRcmpiti
u
B’Y, Ytay Jt uses
O.
LALR() tabu
Fa c tay
SR CSnyict. then
it NO Jhitt achon in LRU) SR
then RR congiit FORIAtos psc cdenci poACis
(tM DEA ,then (H CLRO .
2)) Shit cdua pOTsinQ.
9Tabu ConstsuChon: 3)Suitabu g Only per aty
gíammOs. may bt Qmbi5uL
Aupmntcd 8rammor cniruchien)
oCenstruct LRCI)
4) ©ptvator
Cpt qrammor is a cfG
- rinimi
ttms DeA.
D¾A b mursin statel. hO cajacant non ttrmtnal at RHS
Contrch porsig tab 5) a zb a is higher preUcdtnce
3 Stats with
AOm LRIO) Port ord
difteunt OoIcGheod au ab

3) (A’ a-aX,ti) AX:,t


murga.’ALSos
XstOpmOSt cominal on staK
B4 t2y Y: LOSKaheacl pointt.

thtn SR Confut
4) No RR on Pit in
iftisauy0
then RR Conylia Push n stacIk ,incemu pointo
iRecluce
Chane g thing RRCLR)’
COngli in
Replau honclu in stalc.
NO SR Cenf lict in cLRU) ’ NO SRLALR S4 CX9]-Acccpt SUCce
Conglict in LALRU).
Conyir öh ciRU) cônpich in lALRJ6) TCUbu hes ho tcrminal t J
TOws A COlUmn
’ COnitUchnep0T6ing tabui
Construct LRi) tms DFA.
oCheot for conyict sta 9 LR0) lowr (Cvce peY ator has hig hc
ochecr fur coylit stae G SLRU) prorÍty
|° ConNtruct paY6'ng tabu.

3tate CR) dur ALR), A’A*B B’CtB


NOTE: Rdyatt LR co) (RU)
8) $ is (CSSC prcci dunC OVOY ale

Id (denhfir) Aas higheY pCciclence ecovcA.


then cl opatTS ANd $. 2) Jt UseA LeytmoA detivHoN.
) (Id, Id) = BIank TOP dOwn pasei
CS,3]- Acpt (E’EtE)
with witht ucki00ing
aNOÜaHve tt ambigUOUs iecracKing
Ppré0ch Reussivé Non RCCUTZiVe
Dreciolence Descent docunt (2LC))
) E’ E*E /FtE Dchallenge to TOpcloun porser u1
ChOSe COrrect PY0duch n f mulhpL
tms present n RHS (ke To*FT/E
(at sme leVL in POYAe tee)
EX: PcCCdncs $>#
a Pwlg/e
Associavity: $ ’ let happens then ty 2nd 9ne
Right stt duitable Jor al
e
* In praihive Pansing,
Hánd ing ambiguA gaMmos in LR COrsCcr produChOn) EX$LL) Praici posses

)
Pavsing?
w give
L) Parsing
Parscr ,it ambiguous ammor t9 L
witl Aave ConlicK. wt on a CuYnt aymbt n ip
Jumgvc Conflit fom the table. buffey
EX: EEtE + Accept, SICCOS
E’ E*e Is|s31H)| PP X Om aCk
E’(d tnCrement LoOKCh Cad
int stak AShift ints io
burfc. Rcplace by prduchn (Ct TLX,a])
RHS in steVese .
in &ioC JAt do Syntax enOY
Jt u nt to do Redulc. * The
pcrctY in p pPrOduchins wwhick ace tecl
Cn par4ín
bulea foÜm tlble Ce useal
to csnStuct
Parse tce.
hnce umove Jnitially
gammCr pusk
S
NOTE : Ambiguo
mT[S,+]. in stcTbng
stak. aymbol ef
CLR), LALRU)ramm0r au ng
,SLRU) LRIO)
NOTE: Prachcoly cALR is scd. (f anyhOw PCUse trCe posible
vIab preix = Stack Content Bhjt nedue then
LSeKchcad lengt
E: S’ AB ; 4 (BQHOm up forS)Parsin*
a: B’b LA),etmost clesivatiVe
Stuck !p Actint yt to Jight
Perfosm BOttOm Up posi ng abs Shifl
wnt prcix upto londnic A Reoluca COtlechOn cl viabu retixes for l
AB EA, MB Shift strings n gramor is allvays a
A bC, AAb Ab Redua * OFA which we scSulo
AB) Reduu is thu DFA f this esOr sei
" Tare (Teminas t $) n ColUmn, Let ReCUTsi n s Prblm ony to
non-ttmine n Tow. [A»B tOPdLUn p01K0 ,not te batt)
AIgO: henl in
Ar(0)-eJu[fircc) A’ AXIAKal Ads l BilB2
For CaCh Pruchan eotown
A’X
)Acdd AN to TEA, FuNSL(X)J by S!.
) D9 S' plduCe! JucrAiVL PUTt
Add Ax t0
to TCA, FS(u Usiny usht sucursion (put
for ttminahGn).
*LLL) Grammar: muttipe produchir A B1A'|BH
Presen in | bOx in paTsing table
thn itt ngt LLLI) otherwike cLU)
o eyt tecerssi en my be
unombigueus
(LL))ommg
Direct gndirect
(Ambiguou A’ A&/B ABalb
BOth Ou
B-Ab/a
LU).
checking or L) AYammgr witha ElminahÛn qindirece LcqE MECUS
tabu: by One veify PYOcchOns
RLlle 1: Sinsu prsducion that dnt hQve ecyt CLYsI0n
Srammor LLU).
Rula2: 4n Cae g muuthpe B’6 tesminaL cOn be replCCAC by
Onducbion venia pYOCluchen thn Yplace
t any two Gr More Thn eiminate clircc lelt sCUT
semething in COmmn frrstlai) fave A’Balb
then ngt LLU) a A’ Balb v
B’ Abla BBab| bbla
NOW eminate

E(: something in commOn


S’ aSa lbSb IE
thn not Ll)
* Lelt facH97tag Grgmmar:
Clic lyt res

CRemoving cemmon prefi)


Fouow(S) -{aib, s3 S’ ab|cladle Tala Our Comm on
Havc CmMon tis : not LLU) S’aS'lc
Kulct: Ambi_uous SUamnG i net LLU)
Rules: Lyt Recus%i 9n g1ammor is net°2LD
DPDA
grammor is DCFL 4 poTsco is
LLu)but elimínaien & ceqt
HecUssin may Hest LLI) g$amDdS AMbi
RulC6: ComMon preyik gammor tsngt ) LR)OrCLRU)
but liminatins t LALRL) cURU
may eslt LLC1). SLRU)
(LRLO ) (L)
Produhenro] hOve
a non
COnmen Prefik
EA: S «Si/aSz/B ttyminal
PUCs thLPaSAC nCSasCs. ij write prOgTom diretly {G6
Cy nOn tesmi nals poduin

LLLA) CLRK)
LLo) LlK) TC 0(n) (f(A:-b)
3)9t is nor suitabb dOs leqt
YccusÍNe 8r Gmmar bease
Parser fals iotd n{ init iOop
EvyLcK) is LRK). Ex: E’EtT E)
3) TO hech fy CLRU), (6t Gheck f r LI)
9Aess pewesful thCn LLS
I4 ngt LL) thn consruct DFA 4ChCkS) Simples t implemet ttonttN
NOTE: ReSlar 9Tommng may be DoWbOr POYSC Y : cont
ambiguGUs but Heguor eonsUase
UnamosuGus (LeCs On3The delewing aemantic errOS e
not aetcctcà by paSCTi
4)For every DCL .LR) exAt but LL) 0n8 a ariablu withut decloáto
Mltiple timo dtcaaho ame
for evCIy
Vamiable in Same sCope.
5) o áncempatabl type expycsOn
HeIlGx Lang LRLDexut,
grommor
LLli) exit.
LRU)Ur
:EvexY efuuor gYammos u,cL) Fole PanamercY
Cm·y be cmbi6UOUA) Anay ndex ELt G 6Ound.

’ LRU)
oñamb(5UOUS gomm06 )For LL
gromHnot
6) 34 mlhiple prOducios atu th cu fosa 3) Fox LR
non tesmnaL then its nOt L2O) SLRU) C LALRC)CLR)CLRU)E
g5ammar: LRLO)
.cLRK)
Vfos L2) check a lenet 0kahecd 3) LLCK) cLRI)
Common net LLa) 4) Efrce LLU) grammor SLRCI)
not generating e
3) FUs LL3) CacCK 3 lcnsth AO0Kahec
S’ cal cco NO COmmon ': Lll3) 1)foT LR
o LR)= DCEL
OTE C I (ang ’ Hony grammoo LRLO) = DCFL with prix pYpTy
|Gommor’ (org. (e ang2 8trings not p h h
= LALR) =LRI) = SLRK)
GTommor
not LLC) 4
thunLLUk)fr SOm Ke2bUt LRIo)C SLRU)
has LALR(K) =LRCK)
= D=FL
LL) but nor LLID2) foY LL

3) LLC)C LRU )= DCFL


LL) c DCE-LRU)
k Reslos c
Scmantic Analysis R)PCsfOSm pasine, Aen a pSCAUChHon
U) context
to desianSensitive GYamm æ d* COnstsuccror CXCCut d.
this phase, thcqor its
QUSe Call cd Cs conttXt SDT 3
anlysis phase. senßitive )) Const ruct pose tsee fUs anyt
CAGmpe.
2) LBA is sed (O HCCANN tha Somma"COnStyUct
3
Cinnotated passe t .
<- ntax = Styuctu TC
flar COTSCSpendin prodution.
3) 4n ques to compk Valu attr.
)

X,BE(VtT)T COnstruct parse tsec from top to


bOttOmn
S)Smpl Cst
JOmat y cS Gh calecd
Attribute nrammor is Ustol in |14)otput is samu gor a Gven
whether SDT Ús c o icd U wit
p
6)semanhic analysis ph se.
a= int inryPes
tCtypes
int in a ala
attyibutee alled
S) I4 SDr s orsied Out
deon PasCY then Bemantc
with top
7) Attrblte arammar : SDT in whica Tles ae exeted in DFS
Smanic vulc cont iovc Bide tsavesal Gdes
eftet ie A noce vclu is colcuattd oncL
3) Syntan DirCctcl TSanslatoni
SOT CFCG t Stmantio sles. when ci vaniable
is Visittd twice
5) SDT w with any parsei c the thu ity Vali
tsp dewn er bettom,p pasCT.
SyntaanalySs AI jY Mantic on)
ENOTE ACxical oncyss R8 DPA
) SYnthcAiged att : ato vClue at
Stmanic 1 SDT Pas&CY
Intcrnmediatt codL acn
SOT
1) Ip ts Semantic analysis 3 PoTBe tree hildrn A’ BC

Olp : Anngtated par8e Fsee LDccoYAted INheo ttdattT: atr value ata de
Par&e toce)
U)AnnSratcd Porse tec: gn passe A’
Cach Sgmbe is asCiated with tree
GttibHe ino SDT
7 Advantass flled in symb9t tabe in scnanhi)
anal34 PhasC
) usd to design Scmanhit analysis phcse, 4nheritcd
(nttomciat coce generatiOn phase. ato is usCd
) scd for detciGn g semnhc eTUSS. NOTE: we may hove a set f Yles
Symb table. even nS SUle fUr a POduch
Jn) wscd for construch On
i) s d fos impitit typc Cnvosion. |*Based On types atrributes, SD* EX
|v) uscd for syntax toce/ DAG CoNstsuhin
|S-attributed : uses nly synthcsizd aH A
2
i)2- atibredi WSes beOIh Synthcsizd
Cnrl n C t d Cttyibí ites.
-attbibutca dt Satt butCd thn * NOt in exam point fviCw
5-attvibuted lefini tely L TYanstahon Scheme with bttom up
Qttribdal9. PaNsest we need to nmodify
in midole asnheriird a) ynthes i3d)
NOTE: Jn SDT thete mest bc at (CQSE I E'’+TY praHl t)} E'|E EtTMEIe
SHnthCsid t ibue Only syntAeAizd attr
NOTE: acdtypelid nom,tpe
typoingo -Static Stmanhc Dynamic Seman tig
(t a fu to Qdd
Symbot toble. ype inyo into
int sing
Using undecloned
Vosiable Of bUnd.
’ Tranblaien SCheme :(SyntaK oMuipte
Of om deciarahen
o
vonable. Division by O.
aiscctcd tsansLatin 8hcm) Incompathible data
,o TYans LaH n Scheme ès a SDT in ohich
SemantiC tles may presen in thul SDT 4uitablu |SDT NOt sui tabla
miadtc prductisn. * SDT (Ont be wntn dus
ýnhcited atribute shaud be placc semanhc cOI8 dynamic
.: (tr alo aled
at prepr p itin. Runtime error Þr excaptin.
*ConstUchoni |* EVen yttr compilanOn, esoY Cxst
i) AW ynthesizd atoibuter uues au (YUnhnu emoA), hondld by
plaud at igthtmsst end CXcuptiOn hanadlin.
procuchOn. enhnce portabilíry,
i1) Snheittd attnibutt
manic les is JrOntcnd
o Conpile
p(aud byr that non t(mínal whe
Valu is calClated. nttrmcdi cte CLe GeneYahon
Ilp: Annotatd pae tsee
* Evaluahen: Olp: Three adodiC cde.
) Construct arse tsee and atrach |2) HLL s COnvCYttd into intmdiccte
semanttc tules to the tree by COcu tS perfom Sptimizaien.
Coidering it s gTOmmor smbe, ) SOT iS Uscd to clesign thç phase.
i) Pexm DES tiovesal Intermcdiate COdu
ights When TWle comcsjom tet te
, exeute.
NOTE: t olp SDT 00 tronslaHOn TYCe form Lencar form
Shee
Parse tree a peyfUrm DFS Lng trce
Dirccted
Qcyciccpl
*TAC
Cole

NOTE: 14 g1ammor ü Gmbiguos then Syntax tree . concYehAINtan tre


SDT alA0 ambigUOUs All non tlominas Y emved
frm
HuLtipl Prse trces pMible. heoPOC tiec.
myuhpl GUpur PSMible. ) SHntA toee s
ConstrUCred ON4
fUs expresin stattment.
t1anstahon s0htme s 3ame as
i) All 9peranos ae at leo 4 Cll
opeNatun a internal node
has hightr pe Cudence
U*VNOTDE AuowED
(abu!temporOy
va new a n tdstes
P=a-b
Ex: alwas thing
is between
tw Operahon 4)
LHS.
uwd
On not variables
is S
ing Assi_nmnt SingLe stah ’ X2am Par
(ssA)
L2:
POOOm
XI funchSns:
X)
PX, Vi)
Logoto
t ( PointeIs: V)
it| t
4Z ti L1:
-\00 if Lo: POP PUsk StOcK: iü)
i«/00;itt) forlel;
tsp& fo' for TAC Sperator selchOnal Flow : ij)
*
L3:
Le' pZ X=
TACi (omStandrd
4La>6) *
enti Cese f for TAC funchom
p) *
nes X
a in
it RHS np(ace tákes
binorsOelunory!
Sperahorn Any NOTE X
Op Ip
,
ExpresOn
V
DecLaaion
Stmt
ti=-c X=-C trec/|SHntax DA, TAC
GncYat
ed. VOTiablu anUage. aMembiy
Unp also9perahôn UnaNy Fs 5)
te ncor TAC
i )
Tles.smanhc evalutt and ctmSst oddreSes 3
PCrfom
DES trec Censtrct
pas siepresented
ng is HL J)
S0T3 CEnstruchon
om *TAC
titt ty- DAG tYce Syntax
ti X= G*b ta:
titt ta- tiakb
b tË-tb
a tre in
tatb X=d*b Ycpcatec
:
(eRcept
=) bewiu
poraTyt
vos. new Opcind NO
tree,a (n b*c tbc Ex
o cacA deYing consi eliminatcd.
byTAC Ci) ç subxpy COmmon
dirccHy DACT, Climinattd
in ntsC stntcix çc pAG
y subexpCieN Common i)
DAGi COnsruchon
rm TAC k ’DAG:
Climinated. Jupeateclly LsUsCxprSiGns
Ue
bx0Teion
nGt is CommOn
ConstshOn
Om TACCSmÚn k treei SyntaK DICUwbacc vi)
NOTE: PseCtatnc: (*, /) > ( , ) (100) b C
ti 0tli o) ioo)
’ Back Patchini- FSt TAC ès geneNatd, efhuent
(4)
,nner
"Jitling e labely happens later.
in gote
o RrquirU tes) spu thon qucdíupu alo
g9t0 23
’TAC for aray o Used fUr ONy exprSsirn stmt
IDaTay saACc)- base t ((-tOo) W o Same s what we 8tudicd in Ds,
Run Tim Evisonmnt
’AivGtisn
base -Clow, *nt lOw]W Suope aLcaton
stahc nemOy, Pasiny tehnique
Dynamic
W>Sic ld. LHLL oAfter genTaiOn
n2 ne. ceumns machinu ccle
PreprocessOS
writt TAC fr Qbsve expresIGn. PrepYSed HLL t vunhiu ompi t
Compíles | PerfoTmd s9me
LASSimo lans
memÜTy manafcment,
|Linke/ time envireMment
Machinu ade con be loadc inanywher
memry
*By cault,al fOmuas ae as peo oCOmpiler QsKs for memôy to OS,Cs
R s majT nder Qlocats 'Runim mumOy'. cemA ie7
TAC fOT funchon; monape (t.
* Runt'me MemGTY :-Dnamic memory aloe)
Varible
eipresion thln conVot into Memy
monayemunt
Heop Dynomic dara
Srueumc
then writt. ti=l Some for clonby us ReCuTAiOn,
Stack ACHVahen secO
Ex: Bumll,2) ta-2 psintf, san menialy Data
Posom ti
POSOm ta
{ncHSn: aitSmohitey COcle
Sechon 8tahic Vonabes
(au Sum, StchOn >tacin Code
ÔUadi uple prdcntahon: time
1)Code,dota rchon ’ Static memgy
teps Cstntation H TAC.
o 4t is prachcal QlCOh On at Compile time.

Ex: X= a#b) b 4)sn ed cempi lers, oS


tË= -b
tl
ta t|
allOCatd
ta- at ti
X t
X- ta ausca9n.
>DrabacK : Rest ficla cSntaine bSth Prblm: ReCUSsOn, dynamic datc
tcmpuaTy pesmoncnt Viables, compiler Sruchnt cont be impementd
unablL to differantiateSpoc
0NGnaL
cFPIOcnt
vTIabe3) 4n dynamic memory cleocanÛn,
0S allSCate SOmu rancm amount
TrpLs TePrsCLanon : hm incthUnt mengReCuT810n Dyncmic doa
Jnsttod e tempIasy Voiablcs, we Tles| rUchUT allSw cd.
addres by pointcis ’ liffult to
recTÝang4
4) Aeader locs progrOm in
ayesent sechs e memoH
Gnd CcodL, cloHa &echon, stak, heop)
DyauwbaUc: Agay w staic ín natuTe
Lät dnt RnOw si3 TAC PrOuCccd
advane
’ Stach QcohOn: Fyctunnc POstOrdeo*ACtivahon Can have s
ifchime in Stahc aWOCahon
+ C(Iy fu Call, QtívahOn CCONd -Peomanent
S Cvcatcd and pushcd inta stack. - NeAttd ifeime in sta allcatin
when futetuns, QChvathn COYd -AabitrayRONdom) cime in Heap
Llocahion
Dynomi Sope
Activaion RCArdi "COmpils fisst Check"Compile fiSst heck
nailtans nO Qb cVC Y fu' (au. CussCnt blk thcn Urnt blO0 then
ACONtoains stuta glObal Vonables. O the caling fu.
Retum addrcs
Actual POametts
machne Dependd on dyntax "Depends en fu
Just bejOrt fu' co prrm(Knn Caling seqtna
L9Ccl Vaiablc (Rn9wn ar rUnHMo
CSnOl nK ’ Polnt to achivahon at compiu tim)
ACCes link °ACces ink Rneon, " RNOUn
SCvca mnachine stan ru catling at Connpiu time.
at snhíne
points to
Voiabl. gi9b°C0ntse linC Rnun RNOLUn Cit tUntim(
NOTE: KOCal VOniables a tu is stoT Cd at sn time.
in itt QChvahon rcord toCk Stic 8cepéng Chexial Scepin) s
vecßTd (in stacy
EA n ) a achvahon record cxrotd LiKaUscot in mas pTramming (on
C, Ctt, JCVCL beCaUsL vaviabk
Ifur manyk Ifor f0. Con be cetcemined by poaiom ttxt
tccs énK: psints to sltbal Voiabe.
Cou stao. )
in prasTamming anguage. Pimization
’Cont link: Ponts t achYahon
TCCOrd C Caling funchon.
Uuing it, Dynamic SCOping is impltmented
Stait f |Hachine indepenodent NC Dependent
maine )
SCePiDynamic
ng optimizCition
9pt. Pefosma 9n Optimigatton
pt pe formd
prinrf(xX); (ntsm ediate Code
2Sptimiahon is performta on
Conhre dtOw gYaph
a fun MtUTn.
* Sno LiKe s4Mbet tabl which is nccded pl: Idenify leades starements
to be maintain cd threuAhot the got stmt A ltader
Praram ustoscd in Hcap nt stacK.1Ht
* Heop arca ia maintoined by user by
writhy extia picce Code lMalec, free) Sttp: Make basi dCrcs 0m One
*Co fat r thon JOva be caUse in JUVa Leader stmt to I sttp btfUe
SbjecH Y CUarcd in hcop, co hional an9thCr dcades stmt.
prgran nteded to manaje Aeop. |Stp3: Tàke Istarting ± | erding bl0K
NOTE Dynamic memory allscahon a and drow edecs Cr pex conteL
Performed Ct unime not cuning
COmpiahon. NOrE: NUmber NOdes = NO Gbesic
Java Aau Goroage csuechOn proYam blocks t2
fos deall9Can ON Memory cn heop t for starting t
Grea. ending biooe
ALACOSaiC Simp'fiCoioN: Peofoim
*Basic blKG ScqucnCL Q nc hOVinc iMu 6)apebiaic
entsy single Cxit pOPr ty. rules to simpify ep
X=ytA
Sror)
Oif i<n s0to 8}B1 (B)
LOop Opttmigaon:
induchn vor’ deperds On 100p
St =tt YB invarient var’ dos ngr depend on laP
@COde Moion: gnvarint prt is
takcn SUt GH lop.
thu
ND CNOdel:G (B4 forlioi Kn;ltt)
forlio i<n;it1)
-move
NO bic ciher b
G5 50 thot Lôic dos
hor cAong
ho
’aChiie `ndCpndtnt opt
1) Constant foding: tthniqUnduction
, ’invari ant vamiabu
vomi abu
Repl0ce CxpsOsi On decacicu
byna ittconvalue.
be compurcd at compietimiNOTE forli-o, j:<n,j<m, itj)
only ast condition wiu b
X=2t3+y Cant doas signihcont 4 l0op dep erds onit
X= S*Y NIOTE: fo (i 0) j=l; (<n,
btcog preadenus ¿tt, 1tt)
OsCIativity
a) Copy Prerogahon Here / u nor invoient VOri Ubu
@constant
Corutant proPatin:
te Capern.PropogO
X= |0 Fg-10ta
Indutin vari abu cllminahni
6 vamabu
forl'=1,j=!; <n;itt,ítt) x4y, Lj
X =e Propgahon: 2=ti; for (= kn, (t t)
yet Z VCriabu wil
printl 1y);
Once itr uatalosp Merging / Cembinng/
3) COmmon Tamning:
DAG Coan be suberprein
uscol fo it. liminahon forli=0;i<niitt)
x-xti,ynt(nst forli0;i<n :it)
forli- jk2 .) X-J* 2
fo c(-A)
furcj-0: j<^3jtt) ’4nt2

4 Strength Reducin
oe cheaper cn ttns Speratiôns ohicafrli0 i i<4n; itt)
ay 0nplementoHo,
forliO, i<aniit)
will Mpace Ompux oPeraSns. Printf (H/)
PrintlHi)
(ndt
5) De Cad code eliminahn: Remve fur li-0; C<99; (tt) fr li0i
OmcaChcble 4 nevCsWsed codes. i<49;in
X2
constant
dead ce pYintLH)
Print CHi)
pst(Hi)
ebe
PrtlHi) eiminanUn
Cse
PsttHt) printl Hi)
pstlBy) PrtByc) NOTE LOttia prOfrom i wscd tos
Pninr (eye) Ophmi3ahon.
In
a,Cid, n,9,Z oUt
1) Resats allNCUIOn (56apR Coloin) atz

3) FCphoe eptimizaton t -Union


-<dy
X=dt|
Us. Code lense Printx)
@RedUndan
mOv A, B
Csde cimination:
mOV B,A RCdUntant ,YemoVe Pt JOd byorc wsittn.
5 Dad Code
iminahon:
AlSbY aic si mpifiCaiGn : writn in the blO.
ADD A,.o
e-Redun tant | Gen 4 Ki| U POund fur a blOk,
Live vonabu s feund for enthir prem
d) FlsU cSntOl 9pti misathi on
*Avsid jump oEliminate dcad
E: a=btc Gen= b,C,d y
Li jumpys Z-yt4 b=Q¥d kill=a, b4
L2:
Loi
TUmpL3 eReduntant ’iflond)
X=a1b : -tQ
sofL nothis

if we eptat, n9thing iu CAange.


2 wil bc * Anding IN,OUT Using KILL, GEN :
e use propt instruchn exeufed -INK= (OUTK- KIlLK)U GENK
K
Aad Ro, I oUTK =INiUINj

LOoing
at
* Gl0bal Sptim: is aOnu by LSoicin at NOTE: iVC VOTiCblu t ttahing dinatio
whoe contGt flOw qapk" Ex: ltadcodal ae Path baccl ohcseas Gtnd iU
eiminanGn, Spy propagahon.
degnihÔn Anatysu: Tep
|2) ReachingX-?
J) Jt is a machi ne deoendent phase. bttOm
a) IIp : Inttrmediat CCod
Pitx
Op : Asembly code
3) COdu generahgn rquires i
X=2
.o Resistea MeSis ttr clcanon ttca hique
macin adores
AadícMins moous
* De< -Use cAan : For a wr te find
’ DCa fIOw Analysis
)ite NOTíQb ANalyss i (BOttom to tep)* we- D Chaini Fos a Lad, find
At any Peint (n PrTam, varíables WeA all posibu wite.
cy tts it withLt bung writ) cve NOTE: ElLMents live at a stmnt/blOck
ive vaTicables. Unt writtcn means ive fust beort that stm(bck
a iv bforc thç
not tiv cyter thustmt.
nen(M-n0)
Herc bt ) u ng
Propoatt consont o
hose VOY that ha bç cacnse
Ony I dle|inition a NOTC Expy Cionu
means QvailabluavaiIabli
last
Btmt S
y03y3ta jUst by0TL Btmt S.
Diuploy sa global array pointe r
to al achivaion sors
Jst acce to nen 9cal voriables.
Zi7-yta Caling a subprof rom cn 1ami teve
print a ýn higher l(vee adol an tntry.
’ tive Vaniable analySn Jeston it whn SubprorGm retUon
Con be

Re achins
dyinitiOn anolysA Con
|*Snstrut
) T3
OAG for TË=atb
Basic

NO' nod e = 6

* RelOcahon: 0%igning lOad cddres t9


VomOs part o Prsrom k aojushing
the CodA dara in the Program t9
Jyle the assigned adseses.
4 a pas Compiloe on 18t pa chccky
2nd pas it tions lats prT0m stmt
into machinu Long.

DSymbOl table construchn

(3) AddCs es9tuion g toCal symb

’ Avaitabu expI SiGN anolyss:


APPu Cahon: omion sU6upr eliminahoh
copy pnpO gaiON.
P: Compuk d (at6) ybtc
C= atC’bt)}
c is changdk
<- Her (atb) u Gvail. 60 neither
( 9 C d t b 't on no pan a,s at) avcailo blu
is hongcd noT (bt)

You might also like