Generate a CNF for a given context free grammar


Problem

Generate a Chomsky normal form (CNF) for the following context free grammar (CFG).

S->aAa|bBb|e

A->C|a

B->C|b

C->CDE|e

D->A|B|ab

Solution

Follow the steps mentioned below to generate a CNF for the given CFG

Step 1 − Eliminate ∧ -productions

We can delete, erase or ∧ -productions double time repeated.

S --> aAa | bBb | ∧

A --> a | ∧

B --> b | ∧

D --> A | B | ab

Step 2 − Eliminate unit productions in above grammar

Eliminate R.H.S one symbol productions

S --> aDa | bDb

D --> a | b | ab

Step 3 − Eliminate useless symbols

E is a useless symbol from given grammar since it is not derivative in RHS.

S --> aDa | bDb

D --> a | b | ab

Step 4 − Chomsky normal form (CNF)

Get productions whose bodies are mixes of terminals and variables, or consists of more than one terminal

Break up productions in short form as shown below

S --> XYX | ZYZ

S --> XP | ZQ

P --> YX

Q --> YZ

X --> a

Y --> a | b | ab

Z --> b

Updated on: 12-Jun-2021

825 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements