Preview

Tutorial answer

Good Essays
Open Document
Open Document
3288 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Tutorial answer
3 Context-Free
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
SA
 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
 aabbSB
A
 aabbB
S
 aabbba
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
 AASbabbaa
B
 AAASBbabbaa
S  ASB
 AAASbabbaa
B
 AAAbabbaa
S
 AAaAbbabbaa
A  aAb
 AAaaAbbbabbaa
A  aAb
 AAaabbbabbaa
A
 AaAbaabbbabbaa A  aAb
 Aabaabbbabbaa A  
 abaabbbabbaa 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

You May Also Find These Documents Helpful

Related Topics