Homework 6
Homework 6
Homework 6
S → AX | Y C
A → aA | ϵ
B → bB | ϵ
C → cC | ϵ
X → bXc | bB | cC
Y → aY b | aA | bB
(b) We can construct this context-free grammars for it. Then G = (V, P, T, S),
V = {S, A, B}, where S is the start variable; set of terminal is T = {a, b}, and
rules
S → AB | BA | A | B
A → aAa | aAb | bAa | bAb | a
B → aBa | aBb | bBa | bBb | b
(c) We can construct this context-free grammars for it. Then G = (V, P, T, S),
V = {S, A}, where S is the start variable; set of terminal is T = {a, b}, and
rules
S→A
A → aAbbb | aAbb | ϵ
(d) We can construct this context-free grammars for it. Then G = (V, P, T, S),
V = {S, A, B, C, D}, where S is the start variable; set of terminal is T =
1
Homework 6 Ren Shixin
(e) We can construct this context-free grammars for it. Then G = (V, P, T, S),
V = {S, A, B, C, D, E, F }, where S is the start variable; set of terminal is
T = {a, b, c, d}, and rules
S → AB | CD | ϵ
A → aAb | ϵ
B → bBd | Eϵ
C → aCc | F ϵ
D → cDd | ϵ
E → cEd | ϵ
F → aF b | ϵ
2
Homework 6 Ren Shixin
(a) Find leftmost and rightmost derivations, and a derivation tree for the
string +∗−xyxy.
(b) Prove that this grammar is unambiguous.
Solution. (a)
E ==⇒ +EE ==⇒ +∗EEE ==⇒ +∗−EEEE ==⇒ + ∗ −xEEE ==⇒ +∗−xyEE
lm lm lm lm lm
+ E E
* E E y
- E E x
x y
(b)
We put the operator on their father node, just like below, we call them
operator tree. It clearly that them form parse trees double mapping.
+
* E
- E y
E E x
x y
3
Homework 6 Ren Shixin
S → ϵ | aS | aaSb
the unambiguous:
We can construct this context-free grammars for it. Then G = (V, P, T, S),
V = {S, B}, where S is the start variable; set of terminal is T = {a, b}, and
rules
S → ϵ | aB | aaSb
B → ϵ | aB