1. (25 marks) Provide the rules for context-free grammars that generate the following languages.
(a) L1 = {w in {a, b}
∗
| w starts and ends with ba and contains at least one other occurrence of
ba somewhere in between}
(b) L2 = {a
pb
qc
rd
s
| p, q, r, s in Z
nonneg, p = 4s, q > r}
(c) L3 = {w in {0, 1}
∗
| n0(w) >= 2 and n1(w) >= 1}
(d) L4 = {a
nx | n in Z
nonneg, x in {b, c}
∗
, |x| >= n + 2}
[For example, the strings aaabccbc and cbc are in L4, but the strings aacbc, aaabbc and
aabacccc are not.]
(e) L5 = {a
ib
jc
k
| i = j or j = k; i, j, k in Z
nonneg}
[For example, the strings aabbcccc, aaaaabc, abc, ccc and ǫ are in L5, but the strings
abbccc and abacc are not.]