0% found this document useful (0 votes)
5 views40 pages

Module 3

The document provides an overview of Context-Free Grammar (CFG), defining its components such as terminal and non-terminal symbols, production rules, and the start symbol. It includes examples of CFGs for various languages, illustrating how to generate strings based on specific patterns of characters. Additionally, it discusses the construction of grammars for languages with constraints on the number of specific characters.

Uploaded by

ignisace09
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)
5 views40 pages

Module 3

The document provides an overview of Context-Free Grammar (CFG), defining its components such as terminal and non-terminal symbols, production rules, and the start symbol. It includes examples of CFGs for various languages, illustrating how to generate strings based on specific patterns of characters. Additionally, it discusses the construction of grammars for languages with constraints on the number of specific characters.

Uploaded by

ignisace09
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

Modulе 3 [Link].

5
Assst. professor
[Link]
Pesitin
Context free Graел
Definition Grammer (CFG).
of context tree

nal grammar, which consists of


It is a formal

a set of production rules. Thee production


ru ee s ar e us ed to ge né ra te te string of
a languagé.
q be defined by a sf suples afe
CFG can

G= (V,T, P, S)
set ofz seminals symbors Clower case)
T
set of non terminal symbols (uppercase)
v
S Start symbol (from v)
used
of production rilles. wwhich
are
p set
to replace non-terminals symbols En a

String cuith other terminal or nen


terminal rymbas.
problees

constrrict eanguage havừng


CFG for the i
ary number of a's
L={E,a, aa aaa, aaaa--3
a
(S 353=v
G= (V,T, P, S)
T={a 3
8(s, a) =S
producion rure p=ss=as - Rules
Rule2

S is Start Syтвое.
iet us dreve one example String "aaaal
EL using productioan Rule,

Begin cuith start syтьол


as Rule 1

aas Ruшeя

aaas Rulея
S

aaaaG Rule2 Replace s by e


=

= 'aaaa'5String derived finally


is correct.
grammer is
So ummer

io the I
th language haning
2 construct for
a's & b's
any number
ab, 6b, ba, b66---3
L=ge, a aa

sas
7as|bs/ES }
or
8>95
ajb
S) SE

CFG. G = {SV,T, P.S)


9= (853, 8a,63, [s7as|bsle},s}
3 Design CFG for the language having
ereh mumter of a's
a
S
a

G= (VIT, Pis)
V= &S, A3
T= {a 3
P= S SaAlE
A zas }
S is Start symbol
24 obtais a

2 gra mer to generate strong can

of allease a 1
a
a

G=(VIT, P, S)
v= {S, A }
T={a3
P={sA
SaA E
aA/
S is start symbel
5
ebtain a gim err
mmme
raam to
to ge reracce
gene string
consting of iple
mult of 3 a's
s>aaas/E
aaa

or
a a
a
A
a

G=(V, T, P,S)
V= SS A

T={a16
P= S
saA
Aa
jB B
as
SE

5 is start gymbal
6
obtain gram mer
ramm er to generate string
consisting of atleast. towo a's.
a
a a
YA ((3}

G= (V, T, P, s)
V=ES, A, B3
T= {a3
P= SSap
A B a

BaB/E 3
旦 s if Start symbol
obtain grammer so generate string
consistile of a's & b's atreast one a.
a
La,b
A

G=CViTI P,S)
V= {S, A 3
T={a,6з
P= {S→bs
SaA
A 7E/aA 16A 3
S is symbol
Start

obtain grammer to generate stringis of a's


multepl
& b's Such that string eength
0f 3
SEIAAAS
A ral6
G=CVIT, P,S)
V= SS,A3
3
P=SB7EAAAS
Aalb 3
S is Start symbel
imer st0

languge :ful mod370 where wefa,

as
a a
(B) or s7a/aa/aa
A

G=CVIT, PiS)
V= {S, A,B3
T={a3
aA
P=$Sza BE A
Bas|e3
S if start
symbal
te the following
grammer
rammer t
o generate
) obltaanigouaage
bb --3
4={ ab, aаbь , ааав

G=(VT, PIS)
V= 85 3
J= {a,63
P= {S7E Jasb 3
S ig Start syabol.
① Obtarin a grammer to. generate the fowaw
language

b , a a b b , a a a 666--3
L= {a
G=(VIT, PrS)

T=$a1b
p=$s+ab/asb3
S is start symbol

(12) oblain a er
grammne r to generato the

feeaming language
L= gw: 101 mod 3=0, wetere wesa
a a
A B

S)
G=,T, P.
V=&S, A,83
T={a }
zanIE
p=SSA aB
1
Bas
t /кут ье
5 is star
(13 obtain a g r a m m e r lo ge ne ra ts the follovie

language 7=304+1 9: пх
03
L=faE, aab, aaabb, aaaа6666
G=V,T, P,s)
v=s 3
T=sa,63
P=isalasb3 sis Start symbо
1
e the
obtain a gra mmer
prammer to generate
folowing. Lanaguage

B=(V,T, P.S)
v={s3
J={a,63
p=55+b/asb3
S is start symbel
the followuing
obtain a grammer to generate
ate

L= fanont2n703

Iwo extra 6's shoed be generated so she

fin?asl grammar to generate. güven lanb

G=CVIT, P.S)
v=&S 3
T={a,63
P=$S7bb/asb3
& is Start symbol

obtain grammer- to generate :n


the
3
follawing language L={anьan з0
a

9=CV,T, P.S)
V=&S3
J={a163
p=8S→6/a5663
2.
S is Start symbal
17
obtain grammer 9. & gererating
a set ofe
all palindirome ever {=fa,63
G=(VIT, P,S)
V= {S }
Τ = ξαι63
SSE
P={a16
Sasa16563
S is start Symbol.
81

obtris a grammer to generale the


ferlaning
L= &MR where wE {a163a
L={aa, 6b, abba, baab --3
GECUITI P.s)
V= {S 3
T={a163
P= {S→6 /asa/6563
s is start symbol
obtain a grammer to generate a language
consisting of ale non -palindrome erer saiti
G=CV,T, P.5)
V=GS,A,B)
T=şa,ь3

P= sasalbst
SA
A → aB616вa
В ав6816 3
sis tarr symbel
20
obtnin grammer to generate the langua
L=fom smen /myt 8 пх03
L={ong
1 e
A

S A B
no

Ihe variable sharp roduce mors


A a oд
0's and falawed by ew uo ot 5,5
B should produce any no of 25
BG/2B
SA B

A02/OA 1
B E/2B
G=CViT P.S)
V=&S, A,83
T=50,1,23
PZ SS→AВ,
/0A A701
BE12B3
S
is Start Symbol the

ebtais the grammer to generale


eanguage L= w /hw) = 6(w)
eg: abba, baab
9=(V.J, P. S)
v=&S 3
T={a163
P= {S7E /asbl 6sa /ssS
Start Smool.

You might also like