- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

A Context Free Grammar (CFG) is said to be in Greibach Normal Form(GNF), if production rules satisfy one of the following criteria −

Only a start symbol can generate ε. For example, if S is the start symbol then S → ε is in GNF.

A non-terminal can generate a terminal. For example, if A is Non terminal and a is terminal then, A → a is in GNF.

A non-terminal can generate a terminal followed by any number of non-terminals. For Example, S → aAS is in GNF.

G1 = {S → aAB | aB, A → aA| a, B → bB | b}

The production rules of G1 satisfy the rules specified for GNF, then the grammar G1 is in GNF.

G2 = {S → aAB | aB, A → aA | ε, B → bB | ε}

The production rule of G2 is not satisfying the rules specified for GNF as

A → ε and B → ε contain ε(only the start symbol can generate ε).

So, the grammar G2 is not in GNF.

**Step 1**− Convert the grammar into CNF. If the given grammar is not in CNF, convert it into CNF.**Step 2**− If the grammar consists of left recursion, eliminate it. If the context free grammar contains any left recursion, eliminate it.**Step 3**− In the grammar, convert the given production rule into GNF form. If any production rule in the grammar is not in GNF form, convert it.

**Example**

Consider the context free grammar

S→SS|(S)|a

Convert this grammar to Greibach Normal Form.

**Solution**

Given below is an explanation for conversion of CFG to GNF −

Step 1: Converting to CNF: S->SS|XSY|a X->( Y->) Step 2: Remove left recursion from S->SS S->XSYP/aP P->SP/ε X->( Y->) Step 3: Remove null production P->ε S->XSYP/aP P->SP/S X->( Y->) Step 4: Convert to GNF as S->XSYP is not in GNF, Replace X with ( S->(SYP/aP P->SP/S X->( Y->) Step 5: Convert to GNF as P->SP is not in GNF, Replace S with (SYP/aP S->(SYP/aP P->(SYPP/aPP/(SYP/aP X->( Y->)

- Related Questions & Answers
- Explain the Greibach Normal Form (GNF)
- Explain how to convert CFG to CNF
- First Normal Form (1NF)
- Second Normal Form (2NF)
- Fifth Normal Form (5NF)
- Third Normal Form (3NF)
- Domain-Key Normal Form
- Fourth Normal Form (4NF)
- Sixth Normal Form (6NF)
- How to convert JSON Array to normal Java Array?
- Boyce–Codd Normal Form (BCNF)
- Explain Chomsky normal form in TOC
- Program to encode a string in normal form to its run-length form in Python
- Program to decode a run-length form of string into normal form in Python
- Convert a normal BST to Balanced BST in C++

Advertisements