Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Reduced Grammars

Def: A grammar is said to be reduced if

a. there are no productions of the form A A,


+
b. for all nonterminals A, A where A Vn and Vt*
+
c. S Vi Vi Vn.

Def: An active nonterminal symbol is a nonterminal symbol that can generate at least one terminal string.

Algorithm

1. 1 = {A|A P, Vt*}

2. n = n-1 {A|A P, (Vt n-1)*}

3. repeat 2 until n = n-1

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

Click here for answers


Def: A reachable symbol is a symbol that is in a sentential form.

Algorithm

1. 0 = {S}

2. n = n-1 {A|B A ,B n-1, , V*, A Vn }

3. repeat step 2 until n = n-1

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

Click here for answers

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 }

2. Construct a new set of productions P' such that


if A 0B1 1B2 …Bk k P, then
for 1 i k
if Bi N and no symbol in j N 0 j i, then
add A 0B1 … Bi-1 i-1 iBi+1 …Bk k to P'.
do not add A to P'.

3. Add S' S to P'.

4. If L(G), then add S' to P'.

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
|

Click here for answers.

Construct an algorithm for N


ANSWERS

Active Nonterminal Symbols Answer

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

Reachable Nonterminal Symbols Answer

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

You might also like