Assignment2 CD PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Sibnah Compilev Desigr

Cahos h Assig nment -2 B.ech


CSe 7thSen
17305

Ambiguou arammay With Fxemple


Dependinq upon the nmber of Derivaticn
Tree _ , Context r e e qramma sS are dividedL
into tWD typei

Ambiguous gra mmar


Vnambiguo'uS gremmay
2 kammaY' A c fo said to be
Ambigu ambiguous
S
if for any strin

genesated by it it pvoduce_ m o r e than me


Leftmo_t Devivation o,
Derivaion or,
Ricght most
Parse tree o,
Syntax tree o r
Deri vaion tre e
said to
Definaion' a (V,T, P,S) is a Cf i_ exist
=
a
fF there
be am biguous than one
t h a t has more

Strin9
is T
paYse tree (
inite set of variable
where V, a

finite set ot terminals


TIS a
of the form
finite s e t ot Producions
PIS
PIs a
Qasiqble and
where A1
A a, adesignated
variable

a E V UT)* S iS

the staxt symbol


.

Called
Example Let us consider the 1olloLirg
a mna

A AtAAKAa
L e t us considey a string W geneYate d by
the q ra mmnar

W = ata x oa

Let teftm os.t de7ivations fo +Ai3


NCS see

sting)
A AtA A A x A
7atA AtAxA

h ax a atAxA
a t AxA a t a xA
i
t a xA
ata xa
ata x
Wecan see +hat there exi_t more t h a n
one lettmo_tderivation forthee Strin.
He nce we can say t h t the 9ramm i
a m biguous.

e + u_ c om sider a: strin,
at a x a
W
Now, Lets see the right most deTivatim_
Y

A A +A A AxA
AtAxA Axa
At A xa
Atax 1 Ata xq
) a t ax q at a x

he r e ex ist mnore than rihtme


Again-,
moSt derivatims tor the
9 iven

Sting
nce, E ambiguous 9rammar
L e t us cm sider a striny W

W=at a xa,
Lets dYaw Paise tree for the giver

Stin9

X A

7 a t a xaA

A
A

at axq
CA A

ree exit
AS we c a n See fWD paYSe
for the givenStrin
hence, the gYa mmar mbiguOuS

Let strinq W
gain uS Cmsider q

W =ataxq
dras Sy ntax tree fo +he
NoW, te tS
given String
ee TYee R
ee alyo we Can See tuo trees
exist fox
Syntax
the qivem strin9
hence we Can Say +hat qra mma i
ambiguou
ierentiate
Tee
arse thee ond Sxntay

Topie farse
Tree
Synt
Tree

DefinatioeADasse
an
tree I A syntax istree
oxdeved, 8osfed| a tree Te prese nt-
tree that xepse -
atim of h e ab-
Sents the syntac-Stact syntacti
hc sfvucture sF StYuctuYe ot
source
q string ac¢oding|code written i n
to Some comtexE |a p o9rammng
Free qramma anguaqe

Passe t ree is oa soSyntax l basically


a gsaph.ical
the com pact for
kepre'senta Hum of a
of-the Yeplace paTSe tree
m e n t PrOCess|i n

a der vati on

SynonymParSing free Syntax tseei hia s


derivaim tree me qLOthernam
Con_CYee syntaxAStYCCt Synta
Topic Parse Tsee syntax Tree

Tvee aYe Somne Tree


other nomeS of
Parse iee

Node Fach intexior |fath intevlor


Re present nodè of Parse node of Syntóy
atim|hee re present TYee epye jenta
a qrammas Kule an operator.
Each leaf node Pach le t node
e presents a e pvesen an

ferminal Operand.

Tuncti Parse +ree contains Syntax tree


onalit record s of the Contain re Gords
tokens to match of the Syntax
input of proyramming
anguge.
Cormelu- Parse Hree is a Syntax ee i G
siom hieYarchical stru-| Way of representine
cture that Ye
-

deri-
the Syn_tax of a
resents the PYO9ram m i n g lan-
v a t i o n ot the
obtai9uaga asa hiera-
Jva mm ay to rchica l tie e Sim:le
1nput stYings Structure
E
£xompe
for
String )
W= id tid
Xid
9 rGmmar id E

id id
id
Comsky. Hierdvchy
Chom.sky Hierarchy represents tha closs
of
O anguage_ that re accepte d by the
a

erent machine .
fhe types ot lGnguage
Ch.omskys Hiercchy i&
p e O knourn as Unnsestricted C2ra mmay

Tpe knam as Cn text sensitive


C amma Y

Type 2 knum as Con text fre a Cararmor


yPe 3 knoum as Reqular aiammay

Here is ailluStratior of c chomsky


Hierarchy
Unsesricted

pe0- C2ammay

pe Context sens
e r a mmaY

> Com text frea


9ra mmaY

RequlaY
YaYnimar

Type0 Unse.stricted arammar,


Type vamma is kawn_a_ Unrestrit
ed r a mmas. here is no re strictim
an(the grammaY ulesof these ty ps
of language
h e s e language_ can be ettjciently
pode le d by Tuinq Machine
knoWT2aSthe
These languages QYe alsob
e,
Recuxsively Enumè vable languag
of
a t a m m a y p Oductiom in the for m

Where *
i( VtT)* v (vt T)
V =Vayiable
TTeY minals
*
Bi (v+ T)
atleast one
In type o there m u s t be
on LeFE si de ot p roduction
vaviable

Example
Aa ag

S A
heve, vaviabl es
are
S, A ,

are a, b
Terminal_

ype aammar
6 0 CSC

kngwn as Comtest
1S
- l qra mmmax
I y pSee n sitive m C2rammav

Sensifive qrammar
iS sed
s ed
The con tex t
sensitive (nguage.
to yepYesents conte xt
nerated by +he
T h e lanq uage ge
arerec OYnised by lihe ar
gYamnmar
BGund Automata

sensitive q ram may may


he Comtext the
have more than
one. Sy n bol on
theiv prod ucfim
eft hand side ot
ules
The number of syabols o the lef&7
t h e numn
hand3
2and nmust not er Ce ed
Side
hand
ber. of sym bols e m t h e righ
Side
nbe
"he rule of the form A g iS
allowed unless A I5 a staxt symbo. 1 t

a oes not occ uy O the ighb h a n d


Side ot any xul
is i n the
pe qramma Prod uctim
Foym of V - T
foY Examlpla f5 5
S AT
AB abc
A a

pe e
2 aammaY CFG
2 Cs ammar iskrumuas Comfert
pe Tree lang-
free Caammay e m t e x t b
uage_ hch can be repreSented
Context Tree 2sammay.
The lanq uage qenevated, by. the qram-
2a S recognied, by Pushdown
qutomat a i

e Ypel 2g va mm.aY Shuld bypeL.


Le fe hand'side' lof produatimGan
have
one
cmly vayia ble i
9
noes trictiom m .
There S
soductior ule iS in h e toY m
-7B
/
and i
i s sinqle nom -teiminal
C o m b i n a t i m 0t Terminqls and no
terminal&.
For example
A a Bb
A b
B
zpe Cnrommay
RequlaY
knoumm as

WPe 3 q r a m m a s i
CnsammaY
language_ a r e thOSe lang uag
Requlay YegulaRr
which Can be described using
ex pre sSi on s
are ex actly call ang uag
h e s e langage_ finite S t a t c
+hat can be aCcepted by a

qutmmainn

can be modelled by
Jhese lang u g e
NFA Or DPAL.
formr o
the most restricted
ype3 i
rammar

YQmmaY Should be Type 2 and

ype L

should be inthe 9iven form


ype
V VT*/T*
OY, V T*v/T*
ExampLe
A mn

S ab

You might also like