- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
- Related Articles
- Convert the given Context free grammar to CNF
- How to generate the language for context free grammar?
- Generate a Context-free grammar for the language L = {anbm| m≠n}?
- Explain about CYK Algorithm for Context Free Grammar
- What is Context-Free Grammar?
- Explain removing unit productions in context free grammar
- What is context free grammar? Explain with examples
- Explain the simplification of context free grammar in TOC
- How to convert context free grammar to push down automata?
- Explain Pumping lemma for context free language
- Explain about pumping lemma for context free language?
- What is Context-sensitive Grammar?
- What are the closure properties for context free language?
- Give the examples of a context free language that are not regular?
- Explain the context free language closure under concatenation?
