-- Mar 18 In-Class Exercise
We want to convert the context-free grammar S -> SS | (S) | a into Chomsky Normal Form.
First, we add a new start variable S_0.
The context-free grammar now looks like this. S_0 -> S, S -> SS | (S) | a.
Second, we take care of all epsilon-rules. This context-free grammar has none, so we move onward!
Third, we handle all unit rules. Again, this language does not have any, so we move forward.
Fourth, we convert all remaining rules to Chomsky Normal Form, except for the rules S -> a, and S -> SS, because those are already in the correct forms for Chomsky Normal Form.
Let's convert the rule S -> (S). This yields the rules S -> (A_1 and A_1 -> S).
Now, we want to "clean up" the rules S -> (A_1 and A_1 -> S) so that they are in the correct form for Chomsky Normal Form.
To do this, we replace the terminal symbols in the previous two, newly created rules with new variables and create two more rules like so:
S -> P_1 A_ 1 and A_1 -> SP_2.
We also want to add rules P_1 -> ( and P_2 -> ).
After combining all of these new rules, which I have grouped together below for your convenience, and removing all the rules that are not in the correct form for Chomsky Normal Form, i.e., the rules S -> (S), S -> (A_1, and A_1 -> S), we can say that we have converted the original context-free grammar S -> SS | (S) | a into Chomsky Normal Form.
S_0 -> S
S -> SS
S -> P_1 A_1
A_1 -> SP_2
S -> a
P_1 -> (
P_2 -> ).
(
Edited: 2020-03-18)
We want to convert the context-free grammar S -> SS | (S) | a into Chomsky Normal Form.
First, we add a new start variable S_0.
The context-free grammar now looks like this. S_0 -> S, S -> SS | (S) | a.
Second, we take care of all epsilon-rules. This context-free grammar has none, so we move onward!
Third, we handle all unit rules. Again, this language does not have any, so we move forward.
Fourth, we convert all remaining rules to Chomsky Normal Form, except for the rules S -> a, and S -> SS, because those are already in the correct forms for Chomsky Normal Form.
Let's convert the rule S -> (S). This yields the rules S -> (A_1 and A_1 -> S).
Now, we want to "clean up" the rules S -> (A_1 and A_1 -> S) so that they are in the correct form for Chomsky Normal Form.
To do this, we replace the terminal symbols in the previous two, newly created rules with new variables and create two more rules like so:
S -> P_1 A_ 1 and A_1 -> SP_2.
We also want to add rules P_1 -> ( and P_2 -> ).
After combining all of these new rules, which I have grouped together below for your convenience, and removing all the rules that are not in the correct form for Chomsky Normal Form, i.e., the rules S -> (S), S -> (A_1, and A_1 -> S), we can say that we have converted the original context-free grammar S -> SS | (S) | a into Chomsky Normal Form.
S_0 -> S
S -> SS
S -> P_1 A_1
A_1 -> SP_2
S -> a
P_1 -> (
P_2 -> ).