0% found this document useful (0 votes)
647 views5 pages

Context Free Grammar

The document contains 5 problems involving context-free grammars (CFGs). Problem 1 asks to prove that a given CFG generates the regular expression a*bb. Problem 2 generates the language a(a+b)* + b(a+b)*. Problem 3 asks the language generated by a CFG with productions S->XaXaX. Problems 4 and 5 give CFGs and ask about the languages they generate. The document then provides additional practice problems involving constructing CFGs for various languages.

Uploaded by

fakhra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
647 views5 pages

Context Free Grammar

The document contains 5 problems involving context-free grammars (CFGs). Problem 1 asks to prove that a given CFG generates the regular expression a*bb. Problem 2 generates the language a(a+b)* + b(a+b)*. Problem 3 asks the language generated by a CFG with productions S->XaXaX. Problems 4 and 5 give CFGs and ask about the languages they generate. The document then provides additional practice problems involving constructing CFGs for various languages.

Uploaded by

fakhra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

problems

1. Consider the CFG:


S-- aS Ibb
Prove that this generates the language defined by the regular expression
a*bb
Solution:-
s-> as
s-> aas
s->aaas
s-> aaaas
a->aaaabb
problem 2:-
s-> XYX
s-> ax bbb bx
s-> abx bbb bax
s-> abax bbb babx
s-> aba^ bbb bab ^
ababbb bab

problem 3

s-> aX
s-> a bx
s-> a b ax
s-> abanull
aba
or
s-> bX
s-> b bx
s-> b b ax
s-> bbanull
bba
this CFG generates a(a+b)* + b(a+b)*

problem 4
s->XaXaX
s->axaaxaax
s->a ax aa axaabx
s-> aanullaaanullaabnull
[a*(a (a+b)*a)a*]+ [ b*(a (a+b)*a)b*]

Problem 5
X->bX
X-> bbX
X->bbbX
X->bbbbX
X->bbbbb null
bbbbb ………..> b*
problem :-
Consider the CFG:
S -XbaaX IaX
X -Xa IXb I A
What is the language this generates? Find a word in this language that can
be generated in two substantially different ways.

s-> aX
s-> a Xa
S-> a Xb a
S-> aAba

s-> XbaaX
s->XabaaXb
s->AabaaXab
s->AabaaAab
…. Wait it will continue
Left this
New question

Q no 11
Ab*
Make its CFG

Expression would be
ab*
Word would be
Abbbbb
Terminal = a,b
Non terminal S,X
Production:-
S->aX
X->bX | ^
Prove:-
S->aX
S->abX
S->abbX
S->abbbX
S->abbbbX
S->abbbb ^
abbbbb
Ab*

Q no 12
Language in which letter b is never triple

Non terminal S,X


Terminal a,b

Production
S->sXY
S->xy
x->bb | b | ^
y-> aY | ^
prove
S->SXY
S->xybbay
s->nullaybbay
s->anullanullbbanull
aabba

Slide example
= {a,b}

productions:
1. S SS
2. S XS
3. S Λ
4. S YSY
5. X aa
6. X bb
7. Y ab
8. Y ba
This grammar generates EVEN-EVEN language.

S->ss
S->sxs
s->saaxs
S->abaabbXS
s->abaabbbanull
abaabbba
Q num 2
= {a,b}
productions:
1. S aB
2. S bA
3. A a
4. A aS
5. A bAA
6. B b
7. B bS
8. B aBB
This grammar generates the language EQUAL(The language of strings, with number of a’s equal
to number of b’s)..com

S->bA
s->bbAA
OR
S->bA
S->bbAA
Q num 3
It will generate palindrome?

S aSa|bSb|a|b|Λ
s-> asa
S->absba
s->ababa

task
Construct CFG that generates the language L = {w {a,b}*: length(w) >= 2 and second letter of w from
right is a}
Its expression will be as
(a+b)*a(a+b)
Its word will be as
Abababbbaaabab or ababa aa
Terminal = a,b
Non terminal= S , x ,^

s->saXX
s->saXX
S->as|bs|,6
X->ab
X->aa

s-> xaxX
s->abaxaX
S->ababaaab

You might also like