What is Greibach's normal form?

Overview

We use normal forms in advanced topics of computation theory. Greibach's normal form and Chomsky's normal form are two methods of simplifying context-free grammar.

Greibach's normal form (GNF)

Grammar is in GNF if all the productions follow either of the following set of rules:

  • A nonterminal produces a terminal.
  • A nonterminal produces a terminal with a string of nonterminal symbols.

Steps to convert grammar to GNF

The following steps convert context-free grammar into Greibach's normal form.

  1. Convert CFG to CNF.
  2. Remove all the indirect and direct left recursions that occur in the productions, if they exist.
  3. Convert all production rules into the GNF form. This is usually done by changing the names of the nonterminal symbols into AiA_i form, in ascending order of ii.

Recursion may also occur after step 3; regardless, it must be removed.

Note: To learn more about CNF, visit here.

Example

Let's consider the following grammar:

  • This grammar is already in CNF.
  • After converting the nonterminals in the AiA_i form, grammar becomes:

We'll appoint the values in order of the occurrence of the nonterminals. In this grammar SA1S \equiv A_1, BA2B \equiv A_2, AA3A \equiv A_3, and TA4T \equiv A_4.

  • We'll adjust the rules so that the nonterminals are now in ascending order. This is done when the production is in the form of AiAjxA_i \rightarrow A_j x, where xx is a terminal or a nonterminal and i<ji<j and should not be iji \ge j.
  • The first production follows this property as A1<A2A_1 < A_2 and A1<A4A_1 < A_4.
  • In the second production A4>A1A_4 > A_1. We will replace A1A_1 with the rules it produces.
  • We'll check again if A4>A2A_4 > A_2 in the new step. Since iji \ge j, we will replace the rules produced by A2A_2.

  The production A4bA3A4A_4 \rightarrow bA_3A_4 is valid in GNF.

  • Now we check again if A4A4A_4 \ge A_4. Again iji \ge j as well as an occurrence of left recursion since A4A4xA_4 \rightarrow A_4 x. We'll now remove the left recursion from this production.

  The grammar now becomes:

Note: To learn how to remove left recursion, visit here.

  • Now the entire grammar looks like this:
  • Now we know that in GNF, we need to have a terminal at the beginning of a rule, not a nonterminal, and a nonterminal exists only after a terminal. So we replace A2A_2, and A4A_4 by the rules, they produce for the first production, i.e., A1A_1.
  • Now, A1A_1 and A4A_4 are in GNF. We'll now convert RR to GNF.

Now we have finally converted a CFG to GNF.

In conclusion,

Every grammar in GNF is context-free, and every CFG can be converted into GNF.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved