edited by
2,677 views
1 votes
1 votes

Consider the following context free grammar:

$S \rightarrow ASA | aB$

$A \rightarrow B | S$

$B \rightarrow b |  \epsilon$

How many productions will be there in the modified grammar if we remove null-productions and unit-productions from this grammar? 

My Solution:
Step 1: Remove epsilon transitions
Nullable variables = $ \big\{A,B\big\} $

Modified grammar after removal of null productions:
$S \rightarrow ASA | aB | a | AS | SA | S$
$A \rightarrow B | S $
$B \rightarrow b$

Step 2: Remove Unit Productions
$S \rightarrow ASA |aB |a | AS | SA | \mathbf{S}$
$A \rightarrow \mathbf {B} | \mathbf{S}$ 
$B  \rightarrow b$

Modified grammar after the removal of the unit productions:
$S \rightarrow ASA |aB |a | AS | SA$
$A \rightarrow b | ASA |aB |a | AS | SA$   
$B  \rightarrow b$

I am getting 12 productions. can someone please confirm if it's correct?
 

edited by

Please log in or register to answer this question.

Related questions

1 votes
1 votes
0 answers
2
2 votes
2 votes
7 answers
3
KISHALAY DAS asked Jan 11, 2017
10,337 views
0 votes
0 votes
0 answers
4
Shubhanshu asked Aug 29, 2017
3,068 views
Consider the following grammar :S- Aa / BB - a / bCC - a / epsilonThe number of productions in simplified CFG is_________.I am getting 3. As S - Aa / a / b.