Uploaded by Muhammad Abul Hassan

ToC Assignment #6

advertisement
CS602-Advance Theory of Computation
Dr. Abdus Salam
Assignment # 6
1. Which language generates the grammar G given by the following productions?
S → aSa | aBa
B → bB | b
2. Find a CFG that generates the language:
L(G) = { an bm cm d2n | n ≥ 0, m > 0}.
3. Find a CFG that generates the language
L(G) = { an bm | 0 ≤ n ≤ m ≤ 2n}.
4. Consider the grammar
S → abScB | λ
B → bB | b
What language does it generate?
5. Construct context free grammars to accept the following languages.
a. {w | w starts and ends with the same symbol}
b. {w | |w| is odd}
c. {w | |w| is odd and its middle symbol is 0}
d. {w#x | wR is a substring of x, where w, x ∈ {a, b}*}
e. {0n1n | n>0} U {0n12n | n>0}
f. Binary strings with twice as many 1s as 0s.
6. Explain why the grammar below is ambiguous.
S → 0A | 1B
A → 0AA | 1S | 1
B → 1BB | 0S | 0
7. Given the following ambiguous context free grammar
S → Ab | aaB
A → a | Aa
B→b
a) Find the string w generated by the grammar that has two leftmost derivations. Show
the derivations.
b) Show the two derivation trees for the strings.
c) Find an equivalent unambiguous context-free grammar.
d) Give the unique leftmost derivation and derivation tree for the string s generated
from the unambiguous grammar above
Download