Standard or normal forms are canonical representations for context-free grammars (CFGs). Any CFG can be converted into these forms. The principal advantages of representing a CFG in a normal form are:
Two commonly used normal forms for CFGs are:
A context-free grammar G is in Chomsky Normal Form (CNF) if every production of G is one of the following forms:
Thus, in CNF every right-hand side (RHS) is either a single terminal or exactly two non-terminals (except for the permitted start-symbol ε production).
Every CFG can be converted into an equivalent grammar in CNF (that is, a grammar that generates the same language, possibly except for the empty string which needs special care). The usual ordered steps are:
Given CFG:
S → bA | aB A → bAA | aS | a B → aBB | bS | b
Conversion steps (summary):
S → P A | Q B P → b Q → a A → P A A | Q S | a B → Q B B | P S | b
A → P R | Q S | a B → Q T | P S | b R → A A T → B B
Given CFG:
S → 1A | 0B A → 1AA | 0S | 0 B → 0BB | 1
Conversion summary:
S → P A | Q B P → 1 Q → 0 A → P A A | Q S | 0 B → Q B B | 1
A → P R | Q S | 0 B → Q T | 1 R → A A T → B B
Given CFG:
S → a | b | C S S
Conversion summary:
S → a | b | C P P → S S
Given CFG:
S → abSb | a | aAb A → bS | aAAb
Conversion steps (carefully):
S → V W S W | a | V A W A → W S | V A A W V → a W → b
(Keep S → a unchanged because CNF allows A → a.)U1 → V W U2 → U1 S U3 → V A U5 → A A U6 → V U5
Now rewrite S and A:S → U2 W | a | U3 W A → W S | U6 W
S → U2 W | a | U3 W A → W S | U6 W U1 → V W U2 → U1 S U3 → V A U5 → A A U6 → V U5 V → a W → b
S → bA | aB A → bAA | aS | a B → aBB | bS | b
where S is the start symbol.S → a A D A → a B | b A B B → b D → d
where S is the start symbol.S → a A b B A → a A | a B → b B | b
where S is the start symbol.S → a A b B A → A b | b B → B a | a
where S is the start symbol.S → a A | b B A → b A A | a B → B B a | b
where S is the start symbol.S → a b S b | a b
where S is the start symbol.A context-free grammar G is in Greibach Normal Form (GNF) if every production has the form:
In other words, in GNF each production must begin with exactly one terminal, optionally followed by zero or more non-terminals. GNF is particularly useful for constructing top-down parsers and for proving properties that rely on a terminal leading each derivation step.
Every CFG can be converted into an equivalent grammar in GNF. The standard procedure is as follows:
Substitution: when a production Ai → Aj γ has j < i (that is, it begins with a lower-indexed non-terminal), replace the occurrence of Aj by each RHS of Aj. Repeat until every production for Ai begins with a terminal or with a non-terminal with index greater than i.
Eliminating left recursion: if after substitution some productions for a non-terminal A have the form A → A α | β where β are productions that do not begin with A, then introduce a new non-terminal Z and rewrite as:
A → β Z Z → α Z | ε
Then ensure β (and subsequently Z's productions) start with terminals by further substitution as necessary.
Given CFG:
S → A B | B C A → a B | b A | a B → b B | c C | b C → c
Procedure and result (summary):
S → a B B | b A B | a B | b B C | c C C | b C A → a B | b A | a B → b B | c C | b C → c
Given CFG:
S → aba S a | aba
Conversion summary:
S → A B A S A | A B A A → a B → b
Given CFG:
S → A B A → a A | b B | b B → b
Substitute A's productions into S so that S productions begin with terminals:
S → a A B | b B B | b B A → a A | b B | b B → b
All productions start with a terminal; the grammar is in GNF.
Given CFG:
S → a b S b | a a
Introduce A → a and B → b, then rewrite:
S → a B S B | a A A → a B → b
After substitution the productions begin with terminals; the grammar is in GNF.
Given CFG:
S → a S a | b S b | a a | b b
Introduce A → a and B → b and transform so that each production begins with a terminal. One possible GNF form is:
S → a S P | b S Q | a P | b Q P → a Q → b P → a Q → b
All productions start with terminals; the grammar is in GNF.
Given CFG:
S → A A | a A → S S | b
Conversion outline:
Given CFG:
S → A B A → B S | a B → S A | b
Conversion steps (sketch):
A → a B D | b D B | c | A B | A D
Convert this grammar to Greibach normal form (GNF).S → A B A → B S | b B → S A | a
Convert this grammar to GNF.E → E + T | T T → T * F | F F → ( E ) | a
Convert this grammar (an expression grammar) to GNF.S → Y Y | 0 Y → S S | 1
Convert this grammar to GNF.S → X Y X → Y S | 1 Y → S X | 0
Convert this grammar to GNF.S → X Y X → 0 X | 1 Y | 1 Y → 1
Convert this grammar to GNF.S → 0 1 S 1 | 1 1
Convert this grammar to GNF.Both CNF and GNF are standard normal forms that make CFGs easier to analyse and process. CNF limits productions to single terminals or pairs of non-terminals and is essential for algorithms such as CYK. GNF requires that every production begin with a terminal and is helpful for constructing certain top-down parsing procedures and for formal proofs about derivation lengths. Conversion procedures exist for both normal forms: conversion to CNF follows a fixed sequence of simplifying steps, and conversion to GNF typically proceeds from an already simplified grammar (often CNF) and then uses substitution and left-recursion elimination to ensure every production begins with a single terminal.
| 1. What's the difference between Chomsky Normal Form and Greibach Normal Form? | ![]() |
| 2. How do I convert a CFG into Chomsky Normal Form step by step? | ![]() |
| 3. Why do we need normal forms for context-free grammars in exams? | ![]() |
| 4. Can every context-free grammar be converted to Chomsky Normal Form? | ![]() |
| 5. What are ε-productions and why must they be removed for normal forms? | ![]() |
![]() | Explore Courses for Computer Science Engineering (CSE) exam |
![]() | Get EduRev Notes directly in your Google search |