Introduction
GNF (Greibach Normal Form) is a specialized form of Context-Free Grammar (CFG) where each production rule begins with a terminal symbol, followed by optional variables.
A CFG (Context-Free Grammar) is a Greibach Normal Form(GNF) if all of its production rules satisfy one of the following conditions:
- A non-terminal generating terminal. For example, B -> b.
- Start symbol generating Ξ΅. For example, S β Ξ΅.
- A non-terminal generates a terminal followed by any number of non-terminals. For example, A -> aBCβ¦N.

Also read about - Chomsky Hierarchy
For example:
G1 = {S β aAB | bBA, A β aA | a, B β bB | b}
G2 = {S β aAB | aBA, A β aA | Ξ΅, B β bB | Ξ΅}
- The production rules of Grammar G1 satisfy the above rules specified for GNF. Therefore, G1 is in GNF.
- However, the production rule of G2 does not satisfy the rules specified for GNF as A β Ξ΅ and B β Ξ΅ contains Ξ΅, but only the start symbol can generate Ξ΅. So the grammar G2 is not in GNF.
Also read, Arden's theorem
Notes:
- There can be more than one GNF for a given grammar.
-
GNF produces the same language as CFG produces.
Also see, Turing Machine in TOC.
Steps for Converting CFG into GNF
Step 1 - Convert the Grammar into Chomsky Normal Form(CNF): If the given Grammar is not in CNF, convert it.
Step 2 - If the grammar contains left recursion, remove it.
Step 3 - Convert the production rule into GNF form in the grammar.
Read About - Simplification of CFG
Letβs understand with an example,
Question: Consider the following Grammar G. Convert it into GNF.
S β AA | BC
A β a|SA
B β a
C β c
Solution:
We can skip steps 1 and 2 and move directly to step 3 because the given grammar G is already in CNF, and there is no left recursion.
- The production rule A β SA is not in GNF, so we substitute S -> AA | BC in the production rule A β SA as
S β AA | BC
A β a | AAA | BCA
B β a
C β c
2. The production rule S β BC and A β BCA is not in GNF, so we substitute B β a in the production rule S β BC and A β BCA as
S β AA | aC
A β a | AAA | aCA
B β a
C β c
3. Next, we will remove the left recursion (A β AAA), we get
S β AA | aC
A β aX | aCAX
X β AAX | Ξ΅
B β a
C β c
4. Now remove the null production X β Ξ΅, we get
S β AA | aC
A β aX | aCAX | a | aCA
X β AAX | AA
B β a
C β c
5. Now, S β AA and X β AA are not in GNF, so we substitute A β aX | aCAX | a | aCA in production rule S β AA and X β AA as
S β aXA | aCAXA | aA | aCAA | aC
A β aX | aCAX | a | aCA
X β AAX
X β aXA | aCAXA | aA | aCAA
B β a
C β c
6. Lastly, X β AAX is not in GNF, so we substitute A β aX | aCAX | a | aCA in production rule X β AAX as
S β aXA | aCAXA | aA | aCAA | aC
A β aX | aCAX | a | aCA
X β aXAX | aCAXAX | aAX | aCAAX
X β aXA | aCAXA | aA | aCAA
B β a
C β c
Hence, it is the GNF of Grammar G, as all the production rules follow one of the rules mentioned above.
Also read - Theory of Computation







