1,187 views
0 votes
0 votes
Remove Left Recursion from the following Context Free Grammar.

$S \rightarrow Aa| Sa|c$

$A \rightarrow Ab|Sd|e$

1 Answer

1 votes
1 votes
$S \rightarrow Aa \ | \ Sa \ | \ c$
$A \rightarrow Ab \ | \ Sd \ | \ e$

First we will remove direct recursion from $S \rightarrow Aa | Sa | c$,

$S \rightarrow AaS' \ | \ cS'$
$S' \rightarrow aS' \ | \ \epsilon $
$A \rightarrow Ab \ | \ Sd \ | \ e$

Then next we can replace productions of $S$ in $A$,

$S \rightarrow AaS' \ | \ cS'$
$S' \rightarrow aS' \ | \ \epsilon $
$A \rightarrow Ab \ | \ AaS'd \ | \  cS'd  \ | \ e$

Next we can remove direct recursion from A,

$S \rightarrow AaS' \ | \ cS'$
$S' \rightarrow aS' \ | \ \epsilon $
$A \rightarrow cS'dA' \ | \ eA'$
$A' \rightarrow bA' \ | \ aS'dA' \ | \ \epsilon$

Related questions

4 votes
4 votes
1 answer
1
0 votes
0 votes
0 answers
3
Na462 asked Sep 19, 2018
402 views
Remove the Left Recursion from it : A - B|a|CBDB - C|bC - A|cD - d
2 votes
2 votes
2 answers
4
saumya mishra asked Jun 11, 2018
1,725 views
In this question should we eliminate left recursion by putting values of S and A in the respective productions so answer will be c but if according to the given productio...