Grammar
Answer for Exercises of Chapter 3 (Questions at Page 75, Module:
Introduction to Theory Of Computer Science: Definitions And Examples)
1.
a)
Give a derivation of string ababccddcc.
Derivation
Rule
S abSc
S abSc
ababScc
S abSc
ababAcc
SA
ababcAdcc
A cAd
ababccddcc
A cd
b)
Build the derivation tree for the derivation in part (a).
The derivation tree corresponding to the preceding derivation is
S
a
b
S a b
c
S
c
A c c
A
d
d
c)
Use set notations of (V, , P, S) to define L(G).
L(G) = ({S, A}, {a, b, c, d},{ S → abSc | A; A → cAd | cd}, S}
L(G) = {(ab)ncmdmcn | n 0; m > 0}
a)
Give a leftmost derivation of string aabbba.
Derivation
Rule
S ASB
S ASB
aAbSB
A aAb
aaAbbSB
A aAb
aabbSB
A
aabbB
S
aabbba
B ba
2.
1|P a g e
3 Context-Free
Grammar
aabbba
b)
Give a rightmost derivation of string abaabbbabbaa.
Derivation
Rule
S ASB
S ASB
ASbBa
B bBa
ASbbaa
B ba
AASBbbaa
S ASB
AASbBabbaa
B bBa
AASbabbaa
B
AAASBbabbaa
S ASB
AAASbabbaa
B
AAAbabbaa
S
AAaAbbabbaa
A aAb
AAaaAbbbabbaa
A aAb
AAaabbbabbaa
A
AaAbaabbbabbaa A aAb
Aabaabbbabbaa A
abaabbbabbaa A
abaabbbabbaa
c)
Build the derivation tree for the derivations in parts (a) and (b).
S
A
S
a
A
a
A
b
B b a
b
S
A
S
A a B
S
A
b
a
A
S Bb
A b B
B a
b
b
B
a a 2|P a g e
3 Context-Free
Grammar
a A
b
d)
Use set notations of (V, , P, S) to define L(G).
L(G) = ({S, A, B}, {a, b},{ S ASB | ; A aAb | ; B bBa | ba}, S}
L(G) = {an1bn1 … ankbnk bm1am1 … bmlaml | ni, mi > 0; k, l 0; k l}
a)
Give a leftmost derivation of string abbaab.
3.
S SAB
SABAB
λABAB
λaBAB
λabBAB