The document discusses Chomsky normal form and Greibach normal form, which are simplified forms of context-free grammars (CFGs). It explains that any CFG can be converted into Chomsky normal form through a series of transformations. Greibach normal form further restricts the form of rules so that they start with a terminal symbol. The document provides an example of converting a CFG into Greibach normal form through multiple steps.
3. Simplifying a CFG
Chomsky and Greibach Normal Forms β p.2/2
It is often convenient to simplify CFG
One of the simplest and most useful simplified forms of
CFG is called the Chomsky normal form
4. Simplifying a CFG
Chomsky and Greibach Normal Forms β p.2/2
It is often convenient to simplify CFG
One of the simplest and most useful simplified forms of
CFG is called the Chomsky normal form
Another normal form usually used in algebraic
specifications is Greibach normal form
5. Simplifying a CFG
Chomsky and Greibach Normal Forms β p.2/2
It is often convenient to simplify CFG
One of the simplest and most useful simplified forms of
CFG is called the Chomsky normal form
Another normal form usually used in algebraic
specifications is Greibach normal form
Note the difference between grammar cleaning and simplifi cation
6. Note
Chomsky and Greibach Normal Forms β p.3/2
Normal forms are useful when more advanced topics in
computation theory are approached, as we shall see further
7. Definition
Chomsky and Greibach Normal Forms β p.4/2
is in Chomsky normal form ifA context-free grammar
every rule is of the form:
where is a terminal, are nonterminals, and
may not be the start variable (the axiom)
8. Note
Chomsky and Greibach Normal Forms β p.5/2
The rule , where is the start variable, is not ex-
cluded from a CFG in Chomsky normal form.
9. Theorem 2.9
Chomsky and Greibach Normal Forms β p.6/2
Any context-free language is generated by a context-free
grammar in Chomsky normal form.
10. Theorem 2.9
Chomsky and Greibach Normal Forms β p.6/2
Any context-free language is generated by a context-free
grammar in Chomsky normal form.
Proof idea:
11. Theorem 2.9
Chomsky and Greibach Normal Forms β p.6/2
Any context-free language is generated by a context-free
grammar in Chomsky normal form.
Proof idea:
Show that any CFG can be converted into a CFG in
Chomsky normal form
12. Theorem 2.9
Chomsky and Greibach Normal Forms β p.6/2
Any context-free language is generated by a context-free
grammar in Chomsky normal form.
Proof idea:
Show that any CFG can be converted into a CFG in
Chomsky normal form
Conversion procedure has several stages where the rules that
violate Chomsky normal form conditions are replaced with
equivalent rules that satisfy these conditions
13. Theorem 2.9
Chomsky and Greibach Normal Forms β p.6/2
Any context-free language is generated by a context-free
grammar in Chomsky normal form.
Proof idea:
Show that any CFG can be converted into a CFG in
Chomsky normal form
Conversion procedure has several stages where the rules that
violate Chomsky normal form conditions are replaced with
equivalent rules that satisfy these conditions
Order of transformations: (1) add a new start variable, (2)
eliminate all-rules, (3) eliminate unit-rules, (4) convert other rules
14. Theorem 2.9
Chomsky and Greibach Normal Forms β p.6/2
Any context-free language is generated by a context-free
grammar in Chomsky normal form.
Proof idea:
Show that any CFG can be converted into a CFG in
Chomsky normal form
Conversion procedure has several stages where the rules that
violate Chomsky normal form conditions are replaced with
equivalent rules that satisfy these conditions
Order of transformations: (1) add a new start variable, (2)
eliminate all-rules, (3) eliminate unit-rules, (4) convert other rules
Check that the obtained CFG defi nes the same language
16. Proof
Chomsky and Greibach Normal Forms β p.7/2
Let be the original CFG.
Step 1: add a new start symbol to , and the rule to
17. Proof
Chomsky and Greibach Normal Forms β p.7/2
Let be the original CFG.
to
does not occur
Step 1: add a new start symbol to , and the rule
Note: this change guarantees that the startsymbol of
on the of any rule
18. Step 2: eliminate
Chomsky and Greibach Normal Forms β p.8/2
-rules
Repeat
1. Eliminate the rule from where is not the start symbol
2. For each occurrence of on the of a rule, add a new rule to
with that occurrence of deleted
Example: replace by ;
unless the
replace by
3. Replace the rule , (if it is present) by
rule has been previously eliminated
until all rules are eliminated
19. Step 3: remove unit rules
Chomsky and Greibach Normal Forms β p.9/2
Repeat
1. Remove a unit rule
2. For each rule , add the rule to , unless
was a unit rule previously removed
until all unit rules are eliminated
Note: is a string of variables and terminals
20. Convert all remaining rules
Repeat
, , where each , ,1. Replace a rule
is a variable or a terminal, by:
, , ,
are new variables
replace any terminal with a new variable and add the
where , , ,
2. If
rule
withuntil no rules of the form
remain
Chomsky and Greibach Normal Forms β p.10/2
21. Convert all remaining rules
Repeat
, , where each , ,1. Replace a rule
is a variable or a terminal, by:
, , ,
are new variables
replace any terminal with a new variable and add the
where , , ,
2. If
rule
withuntil no rules of the form
remain
Chomsky and Greibach Normal Forms β p.10/2
22. Convert all remaining rules
Repeat
, , where each , ,1. Replace a rule
is a variable or a terminal, by:
, , ,
are new variables
replace any terminal with a new variable and add the
where , , ,
2. If
rule
withuntil no rules of the form
remain
Chomsky and Greibach Normal Forms β p.10/2
23. Example CFG conversion
Chomsky and Greibach Normal Forms β p.11/2
Consider the grammar whose rules are:
Notation: symbols removed are green and those added are red.
After fi rst step of transformation we get:
24. Example CFG conversion
Chomsky and Greibach Normal Forms β p.11/2
Consider the grammar whose rules are:
Notation: symbols removed are green and those added are red.
After fi rst step of transformation we get:
25. Example CFG conversion
Chomsky and Greibach Normal Forms β p.11/2
Consider the grammar whose rules are:
Notation: symbols removed are green and those added are red.
After fi rst step of transformation we get:
38. Note
The conversion procedure produces several
variables along with several rules .
Since all these represent the same rule, we
may simplify the result using a single variable
and a single rule
Chomsky and Greibach Normal Forms β p.16/2
39. Note
The conversion procedure produces several
variables along with several rules .
Since all these represent the same rule, we
may simplify the result using a single variable
and a single rule
Chomsky and Greibach Normal Forms β p.16/2
40. Note
The conversion procedure produces several
variables along with several rules .
Since all these represent the same rule, we
may simplify the result using a single variable
and a single rule
Chomsky and Greibach Normal Forms β p.16/2
41. Greibach Normal Form
is in
has the
and
A context-free grammar
Greibach normal form if each rule
property: , ,
.
Chomsky and Greibach Normal Forms β p.17/2
Note: Greibach normal form provides a justifi ca-
tion of operator prefi x-notation usually employed
in algebra.
42. Greibach Normal Form
is in
has the
and
A context-free grammar
Greibach normal form if each rule
property: , ,
.
Chomsky and Greibach Normal Forms β p.17/2
Note: Greibach normal form provides a justifi ca-
tion of operator prefi x-notation usually employed
in algebra.
43. Greibach Normal Form
is in
has the
and
A context-free grammar
Greibach normal form if each rule
property: , ,
.
Chomsky and Greibach Normal Forms β p.17/2
Note: Greibach normal form provides a justifi ca-
tion of operator prefi x-notation usually employed
in algebra.
44. Greibach Theorem
Every CFL where can be generated by a
CFG in Greibach normal form.
Chomsky and Greibach Normal Forms β p.18/2
be a CFG generating . Assume thatProof idea: Let
is in Chomsky normal form
Let be an ordering of nonterminals.
Construct the Greibach normal form from Chomsky normal form
45. Greibach Theorem
Every CFL where can be generated by a
CFG in Greibach normal form.
Chomsky and Greibach Normal Forms β p.18/2
be a CFG generating . Assume thatProof idea: Let
is in Chomsky normal form
Let be an ordering of nonterminals.
Construct the Greibach normal form from Chomsky normal form
46. Greibach Theorem
Every CFL where can be generated by a
CFG in Greibach normal form.
Chomsky and Greibach Normal Forms β p.18/2
be a CFG generating . Assume thatProof idea: Let
is in Chomsky normal form
Let be an ordering of nonterminals.
Construct the Greibach normal form from Chomsky normal form
47. Construction
Chomsky and Greibach Normal Forms β p.19/2
so that if1. Modify the rules in
2. Starting with and proceeding to
then
this is done as follows:
(a) Assume that productions have been modifi ed so that for
,
(b) If
only if
is a production with , generate a new set of
the rhs of eachproductions substituting for the
production
times we obtain rules of the form(c) Repeating (b) at most
,
(d) Replace rules by removing left-recursive rules
48. Construction
Chomsky and Greibach Normal Forms β p.19/2
so that if1. Modify the rules in
2. Starting with and proceeding to
then
this is done as follows:
(a) Assume that productions have been modifi ed so that for
,
(b) If
only if
is a production with , generate a new set of
the rhs of eachproductions substituting for the
production
times we obtain rules of the form(c) Repeating (b) at most
,
(d) Replace rules by removing left-recursive rules
49. Construction
Chomsky and Greibach Normal Forms β p.19/2
so that if1. Modify the rules in
2. Starting with and proceeding to
then
this is done as follows:
(a) Assume that productions have been modifi ed so that for
,
(b) If
only if
is a production with , generate a new set of
the rhs of eachproductions substituting for the
production
times we obtain rules of the form(c) Repeating (b) at most
,
(d) Replace rules by removing left-recursive rules
50. Removing left-recursion
Chomsky and Greibach Normal Forms β p.20/2
Left-recursion can be eliminated by the following
scheme:
If are all left recursive rules, and
are all remaining -rules then chose a
new
nonterminal, sayAdd the new
Replace the
-rules ,
-rules by ,
This construction preserve the language .
51. Removing left-recursion
Chomsky and Greibach Normal Forms β p.20/2
Left-recursion can be eliminated by the following
scheme:
If are all left recursive rules, and
are all remaining -rules then chose a
new
nonterminal, sayAdd the new
Replace the
-rules ,
-rules by ,
This construction preserve the language .
52. Removing left-recursion
Chomsky and Greibach Normal Forms β p.20/2
Left-recursion can be eliminated by the following
scheme:
If are all left recursive rules, and
are all remaining -rules then chose a
new
nonterminal, sayAdd the new
Replace the
-rules ,
-rules by ,
This construction preserve the language .
54. More on Greibach NF
Chomsky and Greibach Normal Forms β p.22/2
See Introduction to Automata Theory, Languages,
and Computation, J.E, Hopcroft and J.D Ullman,
Addison-Wesley 1979, p. 94β96
58. Solution
Chomsky and Greibach Normal Forms β p.24/2
1. Step 1: ordering the rules: (Only rules violate ordering
conditions, hence only rules need to be changed).
Following the procedure we replace rules by:
2. Eliminating left-recursion we get: ,
3. All rules start with a terminal. We use them to replace
. This introduces the rules
4. Use production to make them start with a terminal
59. Solution
Chomsky and Greibach Normal Forms β p.24/2
1. Step 1: ordering the rules: (Only rules violate ordering
conditions, hence only rules need to be changed).
Following the procedure we replace rules by:
2. Eliminating left-recursion we get: ,
3. All rules start with a terminal. We use them to replace
. This introduces the rules
4. Use production to make them start with a terminal
60. Solution
Chomsky and Greibach Normal Forms β p.24/2
1. Step 1: ordering the rules: (Only rules violate ordering
conditions, hence only rules need to be changed).
Following the procedure we replace rules by:
2. Eliminating left-recursion we get: ,
3. All rules start with a terminal. We use them to replace
. This introduces the rules
4. Use production to make them start with a terminal