Compiler Design Notes - 2
Compiler Design Notes - 2
qis a
qrawna with terbt symbol S,hen, te agmeufe
Tamma -fok G is G o t a e sa symbol s anoa
preeueon S s in be includea
CLR
LorAgo
LRIO) SLRT LALRLD
SAack
AaAb anfolloO.
L9e
o e moe
produeftb stslarly inLR(O) Postih
cS-s e Augmeuded peu.] Mawa suye d goo
cto
S-AA
Augmenled
qyomaro
A-aAb
LRCO) iems Amy procucton with he do ) the 2HS"
S-AA This eanA hak RHS We hawe nols
Seen anytld"
oe have geen A
SA.A
A. A
SAA. we have &een eveduAhant avd E 4na
to ecduea AAtoS. S AA
Preluetiem
S S SS-Tkisis 4 e esti
Shove taken he LR(0) ila-pr 1pde
closure Whekevethee i a-d ed l v to eppg the closufa
a dot ts he eb h e maiable
we eed ta add
all the þiaduetieus
hahiablet oth dots (:) the besiisy
ss -clasureS
SAA
A aAb
Aler elosure we Lave ts Applydo) 9oto
vasietles on tezmals
pto-Avi the dot (:) Ptorn Lebt ef the
e t o s u e henawe you a n e pp &oto
t5
3hl i : App
LRLO) Tble
LEO) lable
sys ats A
AA
C
sA GatAesA.A \| Action- A
A .aA ab
AaA gots 2
A.b S3 S4
Ab
|b
el A-aA Actee
As aA
7 A 4 b
A Sz
(A-b S4
(A-aA
S3 Sa 6
Canneica
SAA-
Cobecten
A- aA-
LR()Te Ab - 3
Lhemeue a t e i havi a tn ts uE rdute e lol
taparHada Rew Lam aei
LALACI) and cLR()
Lookuheac LR Parting
LALRI) -
CLACI)- Cannonical
LR (brser.
Aeble LALRcI) ancl euRI),
e Tn crder to coutouct he parsing
e required LRU)_its
Lookahead
LRCI) e LR(D) t e +
RHS
poductien oth the dot (:) w he
LRLo)a ) - Any
E S AA
SA A
S AA4
raine
,oheneueuwe
Adlding loekalrted is o
1he Imporamce f eduee move w t h e enAire
dlon't place h e symbes.
nal [Link] iE iu he Lookahead
LHS nslead Hlate
bT the tollo detaimne
sheve We
norder t s
s utehul
7 Ihaefre Lookoahead
Qfe
1tern
the tnal (Plnel AMate).
t slace
Fa
coustnuehe CLARI) Parsimy Table
S AA Hovo ts
A aA the Leokahecd i alaya_
prduetis doesnot chaae
for the mal
we applj-4andtion
(golo-the Lookahecel
Lookaheed
Ab LAkeneue Applyiothe closue
ole
s S,4
SAA, ASA.A,$A AA
Aa.A,SA»AaA$)
A aA,a|b AaA $
Ab,ab Ab, AaA,
b Ab,$
[Link]
A-b4 b AaA alb (Aby
Ab,ab
A aA.a
Nole For and 6
T eothave kavySavne LRLO)
but differeul
ter
Lookahecd bul e e u l
both kaving Ramme LRl)le
Stales Sa and I4
are
LoOkahead
o Ns and g AlcO
CLR) Paig"Table
GOTO
Acion
T sA
Shlab tSome LRto)
O S Sq 3, T lens bul
Atept Lookahendd
2S S7 38,14418
3 S S4 8 SAA O
AaA 2
Ab 3
6 S S No3aleg
CLRII) LRCO)=SLRO)=
LALRU)
The No-fqej
Therefoe
AHhPaded
L R L R l e ) = S L R I H - L A L R A
ExTo check olether 4he aannar 1s LLO), LRLO) SLRU) LRU)and
LALR(I) OR
met Y Thave
adythinglite et
t f (ame
Nole A E AJ
S Aa Ab A E
SBbBa
Ae
LL) V fes.
&lals No c t a w 2 final itern.e
LRto) x Because The Therehore mot LRo).
SS eduee reduce. coutel- -
ilem
) CLRL cLRCD a A a A b A A a A . b ,
SAaAb,
[Link], [Link].B4,s AB.a$)
A 4,
(SBbBaf )
Ths Grammar IS
LLI) Yes
LRO) > No
(3) CLR)> No
S-R Cotbc
RR Coklct
LRUD lem s AB.a P,alb
- a|bRedue [A, 4
bupucd -d,
Ad SB.a
Tc The gfomnaris e t
LALRO) cieti penit kdetuell
InLRID A-b net LALR0)
Nate: T he gsam mar k cLR(1) iE
ma
CSAa|bAcldo|bda not LALR0) AlLys
Ad +(lostaler2
LLO) x
Even ere are no cR eR Conhltel
LRID)Xx CLRC) Dee Could Le chanee
SLRI) etti conus LALRO)
CLR()
LALR)V
Ex tu LLRCI)
E>
EETIT LLU)
A-d.a A d b
TTl LRO) C,a
Fid SLRU
AkzMergig
A-d,ab Rutice
SA
S bhc
BC,b LAUE
Aad.
A
ATE -cs-oDos
Ques- Cousderthe qsammax
S>Cs)|a
Lel-he number oAtes in SLRL), LR), and LALe(1) parers
4oR h e
qoammar be ni, n ancn3 resbecti velt The toloO1r{
relataonship holds good
LineaY om TReefem
Tree addreucale
fosthx DAG
abtabtC+*
t : atb Syoksy TRee
t-tt X
tt*
eq-a46)s (atd+e)
b
- Astigwet openlir
a(relatiomal Kelop
ofpern)2ots L eelafional opelato ago
TfAslrdrtio
R) Ceuditional zots: ( get iastied)
t a4b
t2 -t
Ly C*a Three Add
Manual Three Code
4) ta- t2+t3 Addrencocle
t -a t
6) t tytc
t a = t4 +t6
plemeulatiu -Add cod
here are 3 vepreseutaeinA ef thre.e acdd vu Cede nmame
wth
pr ag ag2 vesu
tA aren
cede forqlooal opti iueveale eficieue
Eeatosae
moVed eround
s P e l e m e u - can be
Advaubges
is Wasled
ttomuch s p a t e
is-ad va- tembdooie
Coulain lot f
mple This
represedtabion doesnt make ufe exta tenpora
iable to epreseut a Sinmle opevation wstead whenq
eevence to anothev Rpes value s needed a polrter to tha
pe ii used. So,1t Censistof oThee fields
wawey cforziad
deparately ad tored
a be moued
1) Adyales Staemenlz
accen s equirga
T o o memon
a) Bsadyaw
4) poinlers. Evey
uhe t a
artrue tien
Lrops Hod to oairt Loeopig lrmneuly tite foi, ohile a
de shile bop iulo o addeu code:
andrtn "R
shfëmu-
sthtemn
True S
Gols L
L
RL:fCE) %Thueol L
2ots Last 4ere, Pisty
we ae checking he Coudit ow.
execule
E i 4rue shen we a e qog to
H:S 4hen qoto+he
LevelLi: S and
Ateration
gol L Couditen Port fou the mexb
w attilë loop
ex okile (a<b) do 1 .
The is a ckauee
a l y o u AAA
nee chs
aule (azb) is
r e a o is
Thee
I t i Jusl o an exanpk
(wtony &4kemen-)
Three Add Coode .
pt Last
Cowiihbn
he
Again checkin
iw three adedeL
Code 1
deutity the wops
Hoo t
Nee
Une
Lagt iis a Poi aler o 4e o4her
(1aligatin Coditian, 1ncement/pec)6
Fo Leopei
Ttalrgatit (-fok
Coudoha
a for loop Cow de e pretente Using
Ho
a Three add:
Code2
S
eaa+b;
OTE, m~fialigahin
Condutiou
oLeee
5 stalemenl
L t : a+b Three Add
codefoa
Stm a+
a : ta= Q+R
P-4a
goto last
t
e t sgo to la
cower ray to iulsr ttee odd re cone
5 Army Houd ls dn
0AC{).
m t ta accew A-E faom A:L 0;20
eq I
A:l0,2o) elomen AL4Z
Son to accou
A CZJ e
ffse
+3) * Sine eikhelemest
20
Bale Add1ey
cach eleman
15 2ie
Thee Add t3 t*a Le dhe
Coce to
Actessi an t4ateaddreu ef A acddrm andl add uoh the
Xat4Ct3)Ttke
Ahe Base
seE
*he d p
1 2 12 13
33 athe
30 31 32 Roos nea l T t e
î have p u l - h e
Have,
erderfeMo)
O Kev Major
aßetheetk
ene
u t - t h e colun
Do have ts
Here, D
Column mar
ercder(cmo)
12223 13233
2 3 elemenk A,3)
0o102030o sant ta t e r he
[Rme).2
RoMajos
order
n g
ancd aglä
Rouds
o 02 o3 kave ts Crosethe -the 3
elemenls.
Heve, to
cresS
13
A 2 , 3 1
Roas
Lave
cossi a
23 [2x4+3)
: 8+3 1leleneu
to c S
31 32 33 A2,3] = rol
Rouds anc
P
30 ts
Lhave elemeu
Ly Heve, te eosa
haue
each o 0
eath element + Base Adreu
A2,3)-(ax4
+3)* Size f
A
TI
isa tabe is
symbol Tble eufies
Sqrnbol Tale_>As4mbel -te
o imt gi te boe
use cincd e e oloLve
partic-Sal
"The in vdhich tat ne.
ne Declaration-
it imporBon phud
beclaeatien hen u
whyhi Line genevale am eTby
haue
Iu Cabe. yeu
eor as
oecumed. ( Line no)
wnere Hha
Cno
has uad
posrhieso vaakle
should knoa Ldhee
a
Jou
L e susaqe
»
m Lecical Aalysis
E o s ard
theiv ecove GletKS
utaragHa
a r e Too leu numeriel
Numenial not a
votd
( 1234Sh789
e A 3Siey
Mecimum sie 6S
i d e a a r e y nt- abedefhijelmnopdrt
(3l-fomednumeic ulérals
td atb)
a - b+C
O44i
b b-d
C c+d t : 4*
ee (PR
t
e e b+ 4btg)
t - t,4
( Prd +
C 9it
ea
e-Cousider +he follooiyr block ad Congtruea DAG foe i t
abxxC
db
edtc
bee (a,e,b
btC
e d-b -b+q+od b+
a e +b
The mMnimum mo n S and edqes
presenm tha DAG epregeudenon [Link]= 6
t h e albove baste dock respecdivelyare [Link]-