*83*

# Greibach Normal Form (GNF)

GNF stands for Greibach normal form. A CFG(context free grammar) is in GNF(Greibach normal form) if all the production rules satisfy one of the following conditions:

- A start symbol generating Îµ. For example, S â†’ Îµ.
- A non-terminal generating a terminal. For example, A â†’ a.
- A non-terminal generating a terminal which is followed by any number of non-terminals. For example, S â†’ aASB.

**For example:**

The production rules of Grammar G1 satisfy the rules specified for GNF, so the grammar G1 is in GNF. However, the production rule of Grammar G2 does not satisfy the rules specified for GNF as A â†’ Îµ and B â†’ Îµ contains Îµ(only start symbol can generate Îµ). So the grammar G2 is not in GNF.

## Steps for converting CFG into GNF

**Step 1:** Convert the grammar into CNF.

If the given grammar is not in CNF, convert it into CNF. You can refer the following topic to convert the CFG into CNF: Chomsky normal form

**Step 2:** If the grammar exists left recursion, eliminate it.

If the context free grammar contains left recursion, eliminate it. You can refer the following topic to eliminate left recursion: Left Recursion

**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:

**Solution:**

As the given grammar G is already in CNF and there is no left recursion, so we can skip step 1 and step 2 and directly go to step 3.

The production rule A â†’ SA is not in GNF, so we substitute S â†’ XB | AA in the production rule A â†’ SA as:

The production rule S â†’ XB and B â†’ XBA is not in GNF, so we substitute X â†’ a in the production rule S â†’ XB and B â†’ XBA as:

Now we will remove left recursion (A â†’ AAA), we get:

Now we will remove null production C â†’ Îµ, we get:

The production rule S â†’ AA is not in GNF, so we substitute A â†’ aC | aBAC | a | aBA in production rule S â†’ AA as:

The production rule C â†’ AAC is not in GNF, so we substitute A â†’ aC | aBAC | a | aBA in production rule C â†’ AAC as:

Hence, this is the GNF form for the grammar G.