Professional Documents
Culture Documents
CD Unit - Ii Part-1
CD Unit - Ii Part-1
CD Unit - Ii Part-1
KoutLeattal
pr0
Avaly34 70E SyolarardPa emenltc
nalyae
Intesmeae
Tvee
SeNectotd parse CRec tomepresenle
Spmbo)
Tae
Repsesenlakve 6rammatl =
tE+TT
TT*F|F Expsettion
TTeme, F> Facs ha- com be
LE d
eHhe paaBheized expsxt)
Thece qammas belorge to Le CA) id
qraomais haave cuflade fos
betom-uP passina.Thie ara Tmanol comotbe uced for top-doun Pachg
Tbe foll owng non-le-VeCUT STVe qvqmmo wfl be uced
T FT
T *FT'JE
F )id
r r Hamdles i Parce
opos
shouldhe Precence erTa< clealy md aurately.
chould
chould secovey r o each crTA qufckty enougb to detec
he Subsrgaent errds
do he poocescing vemaintn9 Pogaenn
should ro doo
T Recovey tralegiex
Eaot. a,b 2
panic Mode Reovay
h e paYse dicards. /p sqmbolk ata time unkl one 4a deciad
Too
Costy to mplemen
CoNTEXT FREE GRAMMAR=
Contez Frec arammas
consiss 4-tupks
CFG-(V,T PS)
VSel4
variabes lb) NonHerminals
T e Herminak
P ed Produckon Rules
C tast Synbol.
D Non-terminal=
Renotes et rngs.
UPPertase letlerx easy n aphabet A,B,C,.
SSlast symbo
E,T, F Ezpreseton -E, Term-T, Pacts-F)
Tesnial=
TETmiak ase the base
symbde foon whch sBigp ar forred
TD ken -name ialko called ae femoîna)
The tollo using ae eminal symbds.
aloweltaee letterg fn the alphabels sch a a,b,e.
opesah ymbok uch a + *
PUneuakons "
n1 Prpducfn Concisk 4
"3"C,"D,,".-} &dgik o,.- 9
Non termna) (all hed s side he praducHo).
Thic prducto
dejinec Come d the 4mbds denotd yhehad
bdy ahci de > consicrg 4 3ero move -termn
and Non termingk.
uestate letlene lale to alphabeh X, Y,2 repvecent 6pamma
ynbde ehe da Henna NonHerminals.
, B , . . epreseo ching gsammo Symbo
Sekd produchons A , , ASd Aak alko wrtHen as
hepd
prvdutt ..k
N
NonTemina erhestevmina4 Nonleming (voT
id
4iedpazzetree
Ambiqury CFG G=ViTRS)
7 a Tamas Produtes more-hon one paTse-tree,e9ha
aTqmma i called a
ambju
E)more hom LMD
one
(diherent)
C) m01e hon RMD
one
(dib}eres.
EEEl E*el teid ng d+id kid
LMD atrE
PMDEtE E
Td+E
E+E*E
+Ekd
1d+TdE Etid¥rd td
Ttd+id *Td. Td-+tdid
d
EtE
opath is
Thic valid Pake tree, benuse the
ig the
Ci)
id
Too fadhs hal-ase necded to be Haber
Precedente
need
Let AcoCtakvttyTo encuse lek aceocratNit, we
opeLaiew îL EKaHug
T F
ounambiguoug Grammas
The Fina
T T F/F
F d
Bang= ling elke)- Tn progam { there a're mose han one 1f-
a
elke íz
E then Si eke 14 t -then S
elkr okE
4
S 14 p hen Sm eke
stnE
p ing iP E HMen 1 hen 9
=
elke C
here aict too pqree treee the
hos fiven Ci
ShmE Pas. 1 paxeTe».! StmE
bme entg .
handle thi gsamma,io
TOP-don parerng methods camot
eed to eliminale leht vecuvsion
AA Clelt secuscive) ,BE (VUT
Lib iS i egual to the tektmDst Non-emina
RH
The shing detved Prom he above Jrama
A
eingg*
B (ay produdion shauro-
B Costatht mbol)
Produchbo AB Couldbe eplated by theko|lowîng
non-let-seurcive ProducH».
BA
qEEAT/T
TTYF/T
Fltd Cleretuveive9vommai)
SO We need tv elimtnale lett-recurcion -/oom he above
Tomma
E
E TEe
=+T
B=T E +Tele
TT¥FF op A A
>FT A A«e
S ts) ojs
T *PTle
doS1ss|e
F>Ð )id (non le}t reuxsie)
Ea3Sl/a-No lebtvecneit
Aeselminating the let veewTsPo) Lyss
oom he 91ammas
ETE
E+Te|e
T-PT
T FT'le
F-lEidle
Elfminatfon lett recuTSFon Fo6 mulple produchon
| Fp
|9 elle
pr zpr+E2pExp Epi4
A A
Ezpridezp
Eap +eprexpr| texprexpr/e
eqpsx|ssbl*la
A
sAsd|las
sxc sbsle
3 >Aalb
A-cat
| B) ,
Then that grammas ConBains lek-taclaNg
TDP faeve comt hancde lefocg -he gscmna Comains lgt
e t a m elimnale -the leJ- factovfng y replatng wththe -folloucfng
Pooduckon
6 3= 8sbB/
A = s , d=itts Bre B,=es SF9
B bB
Sietss lg
BBlgE
dees
>anelanl
B-bBb
AA9Plaela
A aA
A Ae ale
sE T+EIT
T t /ioh Tle) T-nt *T /
T-nt 7'it)
6T+E./T
Top. aum pacing-
is Conctrucled rom
Top doun paxcihg,The Pavce tvee
oDot node to child ndde.
lelt-mat erialton to de tve he fnpu
T0P-duwon Paxccs utee
S h yom he grammaj
dat symbol t qramona
ond veackq thep
Shoahng trom
Shing W= fd+id*id
Rere an p
T-T
F(hd
dep +
T
id e
jd
T id
id
id
id e
Top-doun Pavcs fos u=id+idId
Recusive Recten pazeing= (wHh back toacking)
The concBrucktm Paree tree èlalte foom soot' psuteel to chndrete
Recursm)- A funclion cohrch
is called by Hsel
Recuscive Rectespasesz=
Seps fos COnstruckng
he is non-termnal, hen Call Corvee ponding krerin
C) i/p a
oth ip Symbel
termfnal, hen Compavetermfnal
( )7 he p ic
fncon
Coput== "P)
1oput++
FPRIMË C)S
EPRIMEC)
1-6sammal E>TE E TEl|E
PT>*F1le F>(D
Liop input+* EC) TL
Cinput =- \i') FO
TO
ioput++ EPRIMEL
TPRIML)
EPRIM DS TPRIMEl)
EPRIMEC),
elee Tinput=-'*)
delun nput== Tnpy+
tinput++
TL)
FLO
P Ching: t+74 EPRIME
TPRIMEU
Selee
Tetun
elke
Teu
FL
4nput={)
input +
4Coput=s)
aba iopul+
Vpng w-(od
N elke tt (inpt=-'id')
fnput t
Gactctactng
Ca None -he Product Jo ic
akeyng the conArhio
inputo-'rd>
fnput + TPRimEL
PRImE)
Tnput-++
elee APpmElOS mput»)
Telers 3 pu+t
tpIRIMEX)
TPRIMEO)
Pnput+)
1thputt Telusn
Sced ab =Cadd
tos A 1 ahstyng
( Non h e prrcluc
shoulo checie o
d AL Conlon hen w en
posbiliy for 8
Backacde
FollooLB)-FIRSI (B2
FIRSTLB) Contain E or A B he
add Follow (A) to follttwCE
Eg= aiVen Gramma i
E E+T/T -lept reursiun imfnat leh
T T+F/E (et reuSion ) 7euuTEnletfa cona
fom thera prteluuy
F -
F) lid
E->TE
+TEe
T F
T *Pe
F LE) lid
FIRST tE) = FIRST (T) = FIRST ( = 2 id)
Follbo E) = i Fo
FLE)id
follooce)= Js, FIRST()} 2&,)
Follow tE) 2Follouo lE)+ FolloaCEDI
ETE
e+Tel}le
Follouo ) = Fall®LeLElD}
FollowCT)=ARST (El) 4 Pollbo tE)
ETEl
+TEl/E 2+s,>3
Folloo CT)
PollowT)+ Follbo(T))
TLSFrH
T E'le
FollDw LE) Follow C)+- PIRST+Folbualt)
T-PT s+1s,)
predtcHve passing lable
id C
E7E 6TE
Else ele
T
T-FT
T
T
FFid
d+rd
Stack
fnpu
tdtid Te The p S passed
TE TFT ERS(/
Td +ids h= (a)
AT'el idttd
Tlel +id
TE -anbe
+id BbBle
-"aabb'
rdlf
#Tel id TFT
TEtsietsesla
b Non-Litr))
Pre d Fd
Ente' MBcbrA
Tles T dalE
CLCtepkg
>he
Bcttom-up pavses Con&truct pParke tree from chtld tbottm) ndde
S>AABE
AAbelb
B-d
Tput chivg we abbtde abbede
aAbcde (A->b)
aAde (A>Abc)
age CBd) aAde
S atbede
CCaAe) abbde
t o prdueken.
Tk d T F
Sepr dx id F*id
prvdu ction it
matehes wtth
te
sighCide prrduthm,4hm
Hmdle
whleb howo rde Non -teyminal
iseplated
S>aABe ) a b b lde
A Abc b
B d
0Ade Sa9Le
aABe
ABe
2 E+T/T - r d , * id2
TT*F/F
FlEYid
orde.
GShiht-Redute paes )=
Shibl Reduce pate use tuoo Rata drueler clatkph
OStack - is ugestore the aoma_Sypnmoc
TF Redure TST*F
$T Redute EST
Hrepheod
0ntfck urng shibt-Relute parnA
shrht- Redure conhlrck: Cannd dectde ahethes to chrht a bsalue
&ubhira),
ChH -Redute
L)/a
LSsS paYse he Shing la, l a )ucing sR-paue
L,L shit
Recdute S3L)
Redute LsLS
(L
Peduce s U
S
ACept