Assignment 3
Assignment 3
S → XY | Xn | p
X → mX | m
Y → Xn | o
S → ASA | aB, A → B | S, B → b | ε
S → AA | a, A → SS | b.
5. (a) Discuss inherent ambiguity of context free languages with BCS 402.3 K3
suitable example.
Construct the context free grammar that accepts language
L={aibjck| i = j or j =k; i, j, k are positive integers}.
(b) Define parse tree. Find parse tree for the string abbcde
considering the productions-
S → aAcBe
A → Ab
A→b
B→d
Is this ambiguous? Justify.
(c) Prove that the following grammar of arithmetic a
expressions is ambiguous
E → E+E / E* E / (E) / id
6. (a) Design the CFG for the following language: BCS 402.3 K3
● L = {0m1n | m ≠ n & m,n ≥ 1}
● L = {albmcn | l + m = n & l,m ≥ 1}
● L = {a2nbn |n>=3}.
(b) Prove that the following Language L = {anbncn} is not
Context Free.
7. a. Describe the language generated by the following grammar : BCS 402.3 K3
S → bS/aA/ε
A → aA/bB/b
B → bS
b. Show that the given grammar is ambiguous. Also find an
equivalent unambiguous grammar.
S → ABA
A → aA/ε
B → bB/ε
8. a. Define Chomsky hierarchy. BCS 402.3 K2
b. Is context free language closed under union? If yes, give an
example.
9. a. Remove useless productions from the given productions: BCS 402.3 K3
S → AB|ab,
A → aA|B|a,
B → D|E
b. Find a CFG with no useless symbols equivalent to the
following grammar:
S → AB / CA
A→a
B → BC / AB
C→ AB / b
c. Reduce the given grammar G=({S,A,B},{a,b},P,S) to
Chomsky Normal Form. Where P is defined as:
S→ bA | aB
A→ bAA | aS | a
B → aBB | bS | b
10. (a) Consider the CFG with the following production rules: BCS 402.3 K3
S → aB / bA
A → bAA / aS / a
B → aBB / bS / b
(a) Give a right most derivation and draw the derivation tree for
the string “bbaab”.
(b) Convert the grammar into chomsky normal form (CNF).