Professional Documents
Culture Documents
Reduced Grammars
Reduced Grammars
Def: An active nonterminal symbol is a nonterminal symbol that can generate at least one terminal string.
Algorithm
1. 1 = {A|A P, Vt*}
4. The active nonterminal symbols are those nonterminal symbols that are in n. Delete all
productions that contain nonterminal symbols that are not in n.
e.g.
S a A a
A S b
| b B B
B a b b
| a C
C a C A
Algorithm
1. 0 = {S}
4. The reachable nonterminal symbols are those nonterminal symbols that are in n. Delete all
productions that contain nonterminal symbols that are not in n.
e.g.
S a S b
| b A B
| a
A a A c
B d
C a S b S
| a b a
Note: The appropriate order to apply the two above algorithms to a grammar is to first apply the algorithm for
active symbols and then the algorithm for reachable symbols. What could happen if you first did the
reachable algorithm and then the active algorithm?
Productions
Def: A production is a production whose right hand side is empty or , i.e. where A .
An algorithm to eliminate from the right hand side of all productions except the start symbol when is in the
language of the grammar is given below.
Algorithm
+
1. Construct N = { A | A Vn and A }
G -free = ( Vn {S'}, Vt, P -free P', S' ) where P -free is P with all productions whose RHS is removed.
e.g.
S A S S a S b S
| b C | b S a S
A a |
|
C a C
| a
|
1 = { B }
2 = { B, A }
3 = { B, A, S }
4 = { B, A, S }
S a A a
A S b
|b B B
B a b b
|a C
C a C A
Return
0 = { S }
1 = { S, A, B }
2 = { S, A, B }
S a S b
| b A B
| a
A a A c
B d
C a S b S
| a b a
Return
-free Productions Answers
S A S N = { A, C }
| b C
A a
|
C a C
| a
|
-free Productions
S A S
b C
b
A a
C a C
a
S a S b S N = {S}
| b S a S
|
-free Productions
S a S b S
a b S
a S b
a b
| b S a S
b a S
b S a
b a
|
Return