0% found this document useful (0 votes)
49 views3 pages

TUTORIAL 6 Solved

The document provides examples of context-free grammars (CFG) for generating specific types of strings, including strings of the form aⁿbᵐcᵐdⁿ, palindromes over {0,1}, and strings with at least one 'a' followed by equal numbers of 'b's and 'c's. Each example includes a derivation process and a visual representation of the parse tree. The document serves as a tutorial for understanding CFGs and their applications in string generation.

Uploaded by

Marwah Al-Helali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views3 pages

TUTORIAL 6 Solved

The document provides examples of context-free grammars (CFG) for generating specific types of strings, including strings of the form aⁿbᵐcᵐdⁿ, palindromes over {0,1}, and strings with at least one 'a' followed by equal numbers of 'b's and 'c's. Each example includes a derivation process and a visual representation of the parse tree. The document serves as a tutorial for understanding CFGs and their applications in string generation.

Uploaded by

Marwah Al-Helali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

TUTORIAL 6: SOLVED

CFG

EXAMPLE 1: Strings of the form aⁿbᵐcᵐdⁿ

S → aSd | T

T → bTc | ε

String: abbccd

Derivation:

S → aSd

→ aTd

→ abTcd

→ abbTccd

→ abbεccd

→ abbccd

/|\

a S d

/|\

b T c

bTc

EXAMPLE 2: Palindromes over {0,1}

S → 0S0 | 1S1 | 0 | 1 | ε

String: 0110
S → 0S0

→ 01S10

→ 0110

/|\

0 S 0

/|\

1S1

EXAMPLE 3: Strings with at least one a, followed by equal number of bs and cs

S → aT

T → bTc | bc

String: abbcc

S → aT

→ abTc

→ abbc

/ \

a T

/|\

b T c

bc

EXAMPLE 4: Strings that start and end with same symbol over {a, b}

S → aXa | bXb | a | b

X → aX | bX | ε

String: ababa
S → aXa

→ a bX a

→ a b aX a

→ a b abX a

→ a b ab a

EXAMPLE 5: aⁿbᵐ where n ≥ 1, m ≥ 1

S → AB

A → aA | a

B → bB | b

String: aaabb

S → AB

A → aA → aaA → aaa

B → bB → bb

→ aaabb

/ \

A B

/| |\

a A b B

| |

a A b

You might also like