- 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
Explain removing unit productions in context free grammar
All grammars are not always optimized, which means the grammar may consist of some extra symbols (non-terminals) which increase the length of grammar.
So, we have to reduce the grammar by removing the useless symbols.
Properties
The properties to reduce grammar are explained below −
- Each non-terminal and terminal of G appears in the derivation of some word in L.
- There should not be any production as X->Y where X and Y are non-terminals.
- If epsilon is not in language L then there need not be in the production X-> ε.
The diagram given herewith describe the properties to reduce grammar −
The unit productions are the productions in which one non-terminal gives another nonterminal
Remove unit production
The steps to remove the unit production are given below −
- Step 1 − To remove X->Y add production X->a to the grammar rule whenever Y->a occurs in the grammar.
- Step 2 − Now delete X->Y from the grammar
- Step 3 − Repeat Step 1 and 2 until all unit productions are removed
Example
Consider the context free grammar given below and remove unit production for the same.
S->0A|1B|C
A->0S|00
B->1|A
C->01
Explanation
Step 1
S->C is unit production but while removing S->C we have to consider what C gives so we can add a rule to S.
S->0A|1B|01
Step 2
B->A is also unit production
B->1|0S|00
Finally, we can write CFG without unit production as follows −
S->0A|1B|01
A->0S|00
B->1|0S|00
C->01
- Related Articles
- What is context free grammar? Explain with examples
- Explain about CYK Algorithm for Context Free Grammar
- Explain the simplification of context free grammar in TOC
- What is Context-Free Grammar?
- Convert the given Context free grammar to CNF
- How to generate the language for context free grammar?
- Generate a CNF for a given context free grammar
- How to convert context free grammar to push down automata?
- Generate a Context-free grammar for the language L = {anbm| m≠n}?
- Explain Pumping lemma for context free language
- Explain the context free language closure under concatenation?
- Explain about pumping lemma for context free language?
- Explain the context free language closure under union operation?
- What is Context-sensitive Grammar?
- Explain the elimination of epsilon productions in CFG
