Normal Forms For Context Free Grammars
Normal Forms For Context Free Grammars
Normal Forms For Context Free Grammars
Free Grammars
Context-Free Grammar
In linguistics and computer science, a context-free grammar
(CFG) is a formal grammar in which every production rule is of
the form
V→w
S → b S bb | A
A→aA|ε
Normal forms
Every context-free grammar that does not generate the empty
string can be transformed into an equivalent one in Chomsky
normal form or Greibach normal form. "Equivalent" here means
that the two grammars generate the same language.
X є V or X є T
Example 7.1
If we have the following grammar:
Eliminating useless symbols
Example 7.1
Notice that a and b generate themselves
“terminals”, S generates a, and A
generates b. B is not generating.
After eliminating B:
Eliminating useless symbols
Example 7.1
Notice that only S and a are reachable after
eliminating the non-generating B.
A is not reachable; so it should be eliminated.
The result :
Example 7.12
Eliminating unit productions
Example 7.12
Eliminating unit productions
Example 7.12
After eliminating the unit productions, the generated
grammar is:
Example 7.15
Chomsky Normal Form
Example 7.15
First: we introduce new variables to represent
terminals:
Chomsky Normal Form
Example 7.15
Second: We make all bodies either a single
terminal or multiple variables:
Chomsky Normal Form
Example 7.15
Last step: we make all bodies either a single
terminal or two variables: