in Compiler Design retagged by
1,675 views
2 votes
2 votes

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 production than answer will be a how to solve?

in Compiler Design retagged by
1.7k views

2 Answers

2 votes
2 votes

In your question, it's not only have left recursion but also have loop...

in loop cases first you have break the loop, for that change any one variable of them then another variable doesn't lead to loop

1) change A

                 A-> Sca/Ada/b

                 S->Sc/Ad

it looping again and again...... therefore don't change A

2) Change S

           S->Sc/Sad/bd

          A-> Sa/b

it's does not looping but have left recursion.... now eliminate the left recursion..

E-> Eα1/ Eα2/.../Eαn12/.../βm 
is changed as
E -> β1E'/β2E'/.../βmE' 
E' -> α1E'/ α2E'/.../αnE' / ∈

According to the formula...

          S -> bdS'

         S' -> cS' / adS' /  ∈

          A-> Sa/b

3 Comments

edited by

Shaik Masthan how to know that in question that which production we need to change.?

0
0
i tried with A production, it didn't work... Then i tried with S production... Like that we have to check... If both work then it's our choice to change any production
0
0
Sir please explain one more time...i have a doubt here...

If grammar (from dragon book e.g. )

S-> Aa | b

A->Ac | Sd | €    (€=epsilon)

Then can we eliminate left recursion...?

Because they say in left recursion  algorithm :- input grammar must have  no cycle  or € productions.

They also mentioned " this procedure eliminates all immediate let recursion but it doesn't eliminate left recursion involving derivations of two or more steps."

Please explain this what they says...
0
0
2 votes
2 votes

In given question indirect recursion is present . So at first convert into direct recursion.