Vous êtes sur la page 1sur 2

Formal Methods

Assignment 2
Deadline: 10 A.M. Tuesday April 1, 2014

Question 1. Consider the CFG G1: S aSbS | bSaS |
1) (2 marks) Which of the following statements about the language generated by a
grammar is SUFFICIENT for us to conclude that a grammar is ambiguous?
O Each string in the language has two distinct derivations
O Some string in the language has two distinct parse trees
O Some string in the language has a leftmost and a rightmost derivation
2) (2 marks) Prove your answer in (1) above.
3) (2 marks) Give a string which has two distinct parse trees for G1.
4) (2 marks) Give two distinct parse trees for the string in 3(b)
5) (2 marks) Give two distinct leftmost derivations for the string in 3(b)

Question 2. Write the resultant grammar in Chomsky Normal Form.(2 X 3 marks)
Remove productions, unit productions and useless symbols before you convert to CNF
a) S aA | aBB, A aaA | , B bB | bbC, C B
b) S aTVa
T aTa | bTb | | V
V cVc |

Question 3. (5 x 3 marks)
Construct a context-free grammar (3 x 3 marks)
a) L = {a
n
b
m
: m n, m-n is even, n 0}
b) L = {xc
n
: x {a, b}*, #
a
(x) = n or #
b
(x) = n, n 0}
c) L = {a
i
b
j
: 2i = 3j + 1, i 0, j 0}

Question 4.
(4 X 4 marks) In each case below, show the grammar for a language you consider to be
CFL. Similarly, for something you consider not to be in CFL, give the corresponding
proof.
a) Two examples of CFLs not being closed under complement
b) Two examples of pair of CFLs not being closed under intersection
c) Two examples of a CFL not being closed under difference.
d) Two examples of a CFL being closed under union.

Vous aimerez peut-être aussi