E → E + T | T * F | ( E ) | a
T &rarr T * F | ( E ) | a
F &rarr ( E ) | a
6. Putting a CFG into Chomsky Normal Form
- A grammar G is in Chomsky normal form if each production in G is
one of two forms:
- A → BC where A, B, and C are nonterminals, or
- A → a where a is a terminal.
- We will further assume G has no useless symbols.
- Every context-free language without ε can be generated by
a Chomsky normal form grammar.
- Let us assume we have a CFG G with no useless symbols, ε-productions,
or unit productions. We can transform G into an equivalent Chomsky normal
form grammar as follows:
- Arrange that all bodies of length two or more consist only of nonterminals.
- Replace bodies of length three or more with a cascade of productions, each with
a body of two nonterminals.
- Applying these two transformations to the grammar H above, we get:
E → EA | TB | LC | a
A → PT
P → +
B → MF
M → *
L → (
C → ER
R → )
T &rarr TB | LC | a
F &rarr LC | a
7. Practice Problems
- HMU, Ex. 7.1.1.
- HMU, Ex. 7.1.2.
- Put the standard arithmetic expression grammar in Section (5) into
Greibach Normal Form.
8. Reading Assignment
aho@cs.columbia.edu