0
$\begingroup$

I want to remove indirect left recursion from these rules:

    S-->TU,
    T-->US|b,
    U-->ST|a

I don't know if I can implement the algorithm correctly. My assumption is to make it like this:

S-->TU, T-->U'b, U'b-->U'a

Is this correct?

$\endgroup$

2 Answers 2

0
$\begingroup$

It's tedious... I hope I didn't make a mistake...

S->TU
T->US|b
U->ST|a

1.
S->TU
T->U(TU)|b 
U->(TU)T|a

2.
S->TU
T->aTU|(TUT)TU|b 
U->bUT|(UTU)UT|a

3. * is regex for "repeated 0 or more times"
S->TU
T->aTU|T(UTTU)*|b 
U->bUT|U(TUUT)*|a

4.
S->TU
T->aTU|aTUX|bX|b 
U->bUT|bUTY|aY|a

X->UTTUX|UTTU
Y->TUUTY|TUUT

By substitution of all possibilities of T and U you can remove the non-Terminals at the front of the expressions for X, Y and S.

$\endgroup$
1
  • $\begingroup$ Thank zou very much! $\endgroup$
    – Katerina
    Commented Jul 10, 2020 at 10:51
0
$\begingroup$

No. The first language is non empty (e.g., it contains the word "ba"), while the second language is empty.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.