You are on page 1of 2

CS5104 Assignment 4

Due: Wednesday, April 7


1. Consider the CFG
S ~ aX
X ~ aX,bX,
What is the language this CFG generates?
Solution:
a(ab)*
2. Consider the CFG
S ~ XaXaX
X ~ aX,bX,
What is the language this CFG generates?
Solution:
(ab)*a(ab)*a(ab)*
3. Find a CFG Ior each oI the languages deIined by the Iollowing regular expressions:
a. ab*
b. a*b*
c. (baa abb)*
Solutions:
a) S -~ a , Sb
b) S -~ XY
X -~ aX ,
Y -~ bY ,
c) S -~ SS , baa , abb ,
4. Write a CFG to generate the language MOREA oI all strings that have more a`s than
b`s.
Solution:
S -~ SS , EXE
X -~ aX , a
E -~ aB , bA
A -~ a , aS , bAA
B -~ b , bS , aBB
5. Show that the Iollowing CFGs are ambiguous by Iinding a word with two distinct
parse trees.
i. S ~ SaSaS,b
ii. S ~ aSb,Sb,Sa,a.
Solution:
i) babababab
ii) aab
6. Build a PDA Ior the language a
n
b
m
a
m
b
n
, n ~ 0 and m ~ 0}
7. Build a PDA Ior the language a
2n
b
n
, n ~ 0}
8. Build a PDA Ior the language a
l
b
m
c
n
, l, m, n ~ 0 and l m n}

You might also like