0% found this document useful (0 votes)
2 views17 pages

Compiler Design Notes - 2

The document discusses the construction of parsing tables for various types of grammars, including LR(0), SLR(1), and LALR(1). It outlines the processes for closure and lookahead in parsing, as well as the significance of canonical collections. Additionally, it compares the number of states in different parsing techniques and their implications for grammar analysis.
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)
2 views17 pages

Compiler Design Notes - 2

The document discusses the construction of parsing tables for various types of grammars, including LR(0), SLR(1), and LALR(1). It outlines the processes for closure and lookahead in parsing, as well as the significance of canonical collections. Additionally, it compares the number of states in different parsing techniques and their implications for grammar analysis.
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

Augmened aramma

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

i s ed sori pvoduetin s to iudiale


hc
pu pe
tohe panáer wken it shold stoe porkin a anneuso
acceptace pl
EE
foex: e E+T (T
EF*|T
T T FF TT+FIF
F id CE)
P- id (E)
LR Paek
1nputS

CLR
LorAgo
LRIO) SLRT LALRLD
SAack

I n ordev ts Coutuct the pakng Tasle LRO) nd SLRu) Aeir °


ude Cannonleet collectio f LAto) ifems
S order Coutnt 4he pging ToleLALRCI) emd cLRI)>
We se Caunonita eolledkion f LR)'Ems
E Ho t coustomuud He Leto) Parti akle
fRIT
SAA T o this Tammo Lite i L(1) Pa«[Link] have

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

n l itmAngtem vsith dot


t h althe and,

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

LAU) \len LRIO)_iter +ookheael Some


lem L a v e added
tUYE SaA, ajb T b4he LRO called a lookalhed
mboL
Le. alb

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)

LALRCD arsing Table TncLRCD, THeubiy HLose safes havi


s u t diffeve Lookaheoe Stovbol an
Same LRLO) ilen
t a a k e w LALRAI) Pakn Toble
hen Conubine Hhee Gales
to Comsine Hoce alohih
of LALRI faking Thse T a gei-q
Ptems bul- iffereu- LotKaheed syrnels
&hawinq lame LèLoy
Gols
Actiun foy this Crammar
Sate S A
ab SS
S36 SaT 2 SAA
Aceept AGA
S36 SAT A b
36 Sg6 8 The Mumber of sales
S47 we Lave sbleine
i
LRteds
Ro) 7 , LRI)=7
89
LALRLI)=7 bu foa
CLRLI) H +0
LOas 10 stales
m

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

SAaAb n suRU) Hhe a d


>LRO) xNot SLR) LH-S
kollbf
SBbea ta lace Under
OY Yeduce entiy has
A
SLRCI) Table SAaAb-*
B
Achen Coolo
A E . 3
a b
follad (A) -{a,b o3
fol()ba Mutpe
e n e t r e s . N o tS L R U )

) CLRL cLRCD a A a A b A A a A . b ,

ss, A [Link] A b SAaAbf)

SAaAb,
[Link], [Link].B4,s AB.a$)

A 4,

(SBbBaf )
Ths Grammar IS
LLI) Yes
LRO) > No
(3) CLR)> No

4) CLRI) > Yes


LALR)>Me
(
Coukicl& g o l oa (A
Cofr

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

CAn4n2n3 So Tor SLR) = nn cLRE SLR()-LAPD


1ngn2 LAbr cLRC) 2 =
n3<
LALRU) 3
m2n2z n
Explainatiu)> LALRCI) Ts formed bymerng sAates LR0)
od CcLRCI)
seles m LALRU) lethan
Alse called cLRUU) ) henee no

no. ates in LRU) , terefore mg n z anc sLRUI) a«cLALR)


hove &ame no
&utes (i.e ng)
Inlimedialé cade i
Tatetwedialecede yenendtien ed not cloge Evegli.
SemeAe ALile acle
E: kou Lhaue alrada ecoile Tntegmecliale wlal theld e chauge ody te
Hoc oidowacline and you want ust 2 piale (Lack end*J Compl)
defin c Copil A linum

LineaY om TReefem

Tree addreucale
fosthx DAG
abtabtC+*
t : atb Syoksy TRee

t-tt X
tt*
eq-a46)s (atd+e)
b

y a Tee t is a kind=f loxe Ree vdiel ic dandeujed. (shorkivertin


Pavke ee
hateve we havie iveu mthe HLL PRoam, we
a e convert hem to
pe 3-Addreu code instructiong oe
fHese
statemeu(S)
z atb war opetal; andthe anmeul-

like = - * Ungmy operalr

- Astigwet openlir
a(relatiomal Kelop
ofpern)2ots L eelafional opelato ago
TfAslrdrtio
R) Ceuditional zots: ( get iastied)

goto L This t unconditinml cowditon


oHkoukcheckin a
we Ca Jump ls deme &talemen
Used f
Atiz, Aa meexing
ACi
Here, u a valua Poiated by a poiaei pP

Adden t a vanabe u askignec to dome Othei


aneud ways ohich we Ca repYeAet tree addreu Code
CAn stelemeul -(at6)
(Hd) + (a4tott Stalemeulga*b)+{Chd)

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

&uacdsuples ItK Stueture cosst 4fidds


lanltoP a,0jand
veiult. q slere op denol the

eperands avd resulEis


ealerand aq,asq denales he ttoo
Uied to Gtere 4he relull-the epressje)

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

Advawlages Spate s not vwasla;


b SAAlemel- canno be
Dis Ad
moved aYOund
)
3)
A) (3) Tblcehe ves- B 2 and
Chlemel- and multiply 4hcn
a
tore resultaupouere
Tape we need mot
the esislea
vething Cam be ddoe
naiabe «fs n o t
Temporary
C4 ( 2quived)

3Tndivec kipleThis aae reprekeutatien makes use ppeiaa


t h e istinz a l ferences to compdations skieh is mede

deparately ad tored
a be moued
1) Adyales Staemenlz

accen s equirga
T o o memon
a) Bsadyaw

-We are motdirectly


(akin) the
Pudiveul Tiple
ececiting bhen;
4) uLtetius and
w h e memory
ad
mstuctens

We are Savias the ase uting


ustuetny de
foa e e mema Poiner to
o

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

WIele (Coudlitin) wile E do S


Salse
Slalemeu A ulof

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

not tiue nitly


Last
eu 4he condlitien u
hen we ere aong to'7eto LastMaad,
O e ohile Loep)
lce -

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

Meand corr out of the 94ilo


Las:>

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

false <10) gols L4


L
Es True gels Last
M c e m e u t

oLeee
5 stalemenl
L t : a+b Three Add
codefoa

Stm a+

Soite -Case stalemeu


t 1+|[Link]-Aok
Sulteh C) i-ta
Case 1: a-b+c Jol Agaln checknt+h
swditonv
beak Last
Coming outhefeltoep
Caje 2: P =Q+R
bealk vska ú h e value of
-We should ndoul

default; a-+3 o2 t= test: (t==) Jola L


bíeak gots test ( t 2 ) jels La
:tib+ 3ots L3defautl
a-t Las:

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

addo-o ary Let's see ke


eTe
Caleulati
nq |Desiqning Three
aytayt ae e ackaly Hored im-to thhe memes
4x4 ACAJ4
eg-&Dasta
AT40324 037+0geexek

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

Nane hal-1 Ahe nane aw eub tiseeq

Sige Stgeam 1nd,chor,flead- elo


Dionensin- oLd n caje
Anaf.
h e r inteqer, charauler, edc is drelood
At cau be vatialdlo
T4be -

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
»

Acddve hal- orticudas exdtid


Addeun

Operadtien the Sqmbol-table

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

ex ml- Az $i2s'- *i not alloded

nolw 4he Lurre laguegc


(4)npd- eharaclecs hal
are
ckarecley 1 C Pr9rammu
yov mje'ay ehinese
e
&peUin ndslate
DAG DAG Yeprelevtatiom a a t Block

ER to-a4b ttott dett+t,


t a+
to

td atb)

Applicatien s DeleRmdninq Common sub expresSun)


he
blck
ahich names ore u{d inside. the
Defetminn
conped outSide. she block
Detaminienq vohidh &tm- of bek Goutd aue her
Vaconpled valuO Bulsde h e blotk

Ctuetin DAG fal BAsic slet


ak(lc) +{b-c) * d / ab++e
a-bd
(9 d--

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

S : ousruct a bAG fok the -follo@ing three Addru tode


-0
a*a
b t+a

e GATE 2 Coaicdorthe baic block aive be


aet
C a +d a d-+

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]-

You might also like