
CMSC330: CFG Practice Problems
1) What language does the following grammar generate?
S→aaSbb |
2) Given the language L={aibjc2i+1dk|i, j, k ≥0}:
a) Design an unambiguous grammar that generates L.
b) Give the leftmost and rightmost derivations of the string abbcccd using the grammar from part a).
c) Give the parse trees for the string abbcccd based on the grammar of part a).
3) Given the language L={anbman−m|n≥m≥0}
a) Design an unambiguous grammar that generates L.
b) Give the leftmost and rightmost derivations of the string aaabba using the grammar from part a).
c) Give the parse trees for the string aaabba based on the grammar of part a).
4) Given the regular expression R= (a|b)+b∗ab∗:
a) Design a grammar for R.
b) Give the leftmost and rightmost derivations of the string aaabba using the grammar from part a).
c) Give the parse trees for the string aaabba based on the grammar of part a).
5) Draw a NFA/DFA that represents the same language as the following grammar:
S→01R|
R→0R|T|
T→0T|0
6) Given the language L={w∈ {a, b}∗|whas the same number of a’s and b’s}:
a) Give an unambiguous grammar describing L.
Edit: the grammar you write can be ambiguous. It’s pretty hard to write an unambiguous one for this
problem.
Note: Remember, the a’s and b’s can be in any order, as long as there are the same number of each.
b) Give a derivation for the string aabb using your grammar from a) and draw the corresponding parse
tree.
1