ch6 - Simplification - of - CFGs - and - Normal - Forms
ch6 - Simplification - of - CFGs - and - Normal - Forms
Repeat
Mark non-terminal X for which there exists X → b and
all symbols in b have been marked as nullable
B→ aAb|… B→ ab|aAb|…
A→ e|… A→ …
Let G be
S → SaB | aB
B → bB | e
After removing e-productions, the new grammar
will be
S → SaB | Sa | aB | a
B → bB | b
We eliminate C → e by replacing:
B → CC into B → CC, B → C, and B → e
B → aAbC into B → aAbC and B → aAb
Since C → e is only C production
only B → e and B → aAb retained.
A → B A → a | ...
B → a | ... B → a | ...
GL: S → ACA | CA | AA | AC | A | C | e
A → aAa | aa | B | C
B → bB | b
C → cC | c
S→T|S+T
T → a | (S) | F * T
F → a | (S)
S → a | (S) | F * T | S + T
T → a | (S) | F * T
F → a | (S)
6.2: Chomsky Normal Form (1)
The Chomsky normal form places restrictions on
the length and the composition of the right-hand
side of a rule
Definition 6.4:
A CFG is in Chomsky normal form if each
production rule has one of the following forms:
A→a
A → BC
S→e
where B, C NT
Algorithm Step 1
Algorithm Step 2
Algorithm Step 3
Examples:
G1 = ({S, A}, {a, b}, S, {S → aSA | a, A → aA | b})
GNF
G2 = ({S, A}, {a, b}, S, {S → AS | AAS, A → SA | aa})
not GNF
This grammar S AB A aA | bB | b Bb
is not in GNF
This grammar S aAB | bBB | bB
A aA | bB | b Bb
is in GNF