0% found this document useful (0 votes)
4 views7 pages

Let

Uploaded by

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

Let

Uploaded by

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

Let’s go step-by-step for converting each CFG into **Chomsky Normal Form (CNF)**, starting with

the first question and continuing through the others. CNF requires that all rules must either be of the
form \( A \rightarrow BC \) (where \( B \) and \( C \) are non-terminal variables) or \( A \rightarrow
a \) (where \( a \) is a terminal), with no epsilon (ε) rules except for the start variable, and no unit
productions.

---

### Question 1: CFG

```

S → ASB

A → aASA | a | ε

B → SbS | A | bb

```

#### Step 1: Eliminate ε-productions

- \( A \rightarrow \epsilon \) is an ε-production. We need to eliminate it by substituting \( A \) in


other rules:

- \( S \rightarrow ASB \) gives \( S \rightarrow SB \) when \( A = \epsilon \).

- \( A \rightarrow aASA \) gives \( A \rightarrow aSA \) and \( A \rightarrow aA \) when one or


more \( A \)'s are replaced by ε.

- \( B \rightarrow A \) gives \( B \rightarrow \epsilon \), but we leave this as we will handle it after ε-
removal is done.

Updated grammar after ε-production removal:

```

S → ASB | SB

A → aASA | aSA | aA | a

B → SbS | ASB | SB | bb

```

#### Step 2: Eliminate unit productions


- A unit production is of the form \( A \rightarrow B \), where both \( A \) and \( B \) are non-
terminals. The grammar has the following unit productions:

- \( B \rightarrow A \). Replace \( B \) with the productions of \( A \):

- \( B \rightarrow aASA | aSA | aA | a \).

- \( S \rightarrow A \). Replace \( S \) with productions of \( A \):

- \( S \rightarrow aASA | aSA | aA | a \).

The updated grammar becomes:

```

S → ASB | SB | aASA | aSA | aA | a

A → aASA | aSA | aA | a

B → SbS | ASB | SB | bb | aASA | aSA | aA | a

```

#### Step 3: Convert to binary rules

- Convert long right-hand sides into two non-terminal symbols:

- \( S \rightarrow ASB \) becomes \( S \rightarrow AX_1 \), with \( X_1 \rightarrow SB \).

- \( S \rightarrow aASA \) becomes \( S \rightarrow aX_2 \), with \( X_2 \rightarrow SA \).

- Similarly for other rules.

Final CNF after converting to binary rules:

```

S → AX_1 | SB | aX_2 | aSA | aA | a

A → aX_2 | aSA | aA | a

B → SbS | AX_1 | SB | bb | aX_2 | aSA | aA | a

X_1 → SB

X_2 → SA

```
---

### Question 2: CFG

```

A → BAB | B | ε

B → 00 | ε

```

#### Step 1: Eliminate ε-productions

- Both \( A \rightarrow \epsilon \) and \( B \rightarrow \epsilon \) are ε-productions:

- Replace \( A \) and \( B \) in other rules:

- \( A \rightarrow BAB \) becomes \( A \rightarrow BA \), \( A \rightarrow AB \), and \( A \


rightarrow B \) after removing the ε's from \( B \).

- \( B \rightarrow 00 \) remains unchanged.

Updated grammar:

```

A → BAB | BA | AB | B

B → 00

```

#### Step 2: Eliminate unit productions

- Unit production \( A \rightarrow B \) can be replaced by \( B \)'s production:

- \( A \rightarrow 00 \).

Updated grammar:

```

A → BAB | BA | AB | 00
B → 00

```

#### Step 3: Convert to binary rules

- Split any longer productions:

- \( A \rightarrow BAB \) becomes \( A \rightarrow BX_1 \), where \( X_1 \rightarrow AB \).

Final CNF:

```

A → BX_1 | BA | AB | 00

B → 00

X_1 → AB

```

---

### Question 3: CFG

```

S → AA

A → B | BB

B → abB | b | bb

```

#### Step 1: Eliminate unit productions

- \( A \rightarrow B \) and \( B \rightarrow b \) are unit productions:

- Replace \( A \rightarrow B \) by all of \( B \)'s productions:

- \( A \rightarrow abB | b | bb \).

Updated grammar:
```

S → AA

A → abB | b | bb | BB

B → abB | b | bb

```

#### Step 2: Convert to binary rules

- Split longer right-hand sides:

- \( B \rightarrow abB \) becomes \( B \rightarrow aX_1 \), \( X_1 \rightarrow bB \).

Final CNF:

```

S → AA

A → abX_1 | b | bb | BB

B → aX_1 | b | bb

X_1 → bB

```

---

### Question 4: CFG

```

S → TaT

T → aTb | bTa | TT | ε

```

#### Step 1: Eliminate ε-productions

- \( T \rightarrow \epsilon \) is an ε-production:

- Replace \( T \) with appropriate alternatives in other rules.


Updated grammar:

```

S → TaT | aT | Ta | aa

T → aTb | bTa | TT

```

#### Step 2: Convert to binary rules

- Split longer productions:

- \( T \rightarrow aTb \) becomes \( T \rightarrow aX_1 \), \( X_1 \rightarrow Tb \).

Final CNF:

```

S → TX_2 | aT | Ta | aa

T → aX_1 | bX_2 | TT

X_1 → Tb

X_2 → aT

```

---

### Question 5: CFG

```

S → BSB | B | λ

B → bb | λ

```

#### Step 1: Eliminate ε-productions

- Both \( S \rightarrow \epsilon \) and \( B \rightarrow \epsilon \) are ε-productions:


- Replace \( S \) and \( B \) in other rules.

Updated grammar:

```

S → BSB | BS | SB | B

B → bb

```

#### Step 2: Convert to binary rules

- Convert longer productions into binary rules:

- \( S \rightarrow BSB \) becomes \( S \rightarrow BX_1 \), \( X_1 \rightarrow SB \).

Final CNF:

```

S → BX_1 | BS | SB | B

B → bb

X_1 → SB

```

---

These are the detailed steps for converting each CFG into **Chomsky Normal Form (CNF)**. Let me
know if you need further clarifications!

You might also like