0

Here's the problem:

A -> A*B | A+CDE | Aab

All of the productions start with A. I guess that satisfies the rule? As you can see, it is missing beta. How do I perform left recursion on it? Can left recursion be even performed on it?

What I have learned so far is that if it was like this: A -> A*B | A+CDE | Aab | b

Then I would consider b as beta and solve as:

A -> bA'

A' -> *BA' | +CDEA' | abA' | ϵ

Without beta, I am confused. What do I consider as beta?

Sakib Arifin
  • 255
  • 2
  • 13
  • 2
    The one whose right-recursion you are trying to eliminate (A). "All the productions start with A" --> there is no way to terminate the recursion. It's like writing a recursive function without a base condition. The only place it can go is stack overflow and I'm not talking about this site. – rici Dec 16 '22 at 21:12

2 Answers2

1

You need to reduce the grammar by removing all useless and non-productive non-terminals before you try to remove right-recursion. Since A is non-productive (it has no non-recursive production), it will get eliminated along with any production which uses it. That certainly gets rid of the left-recursion :-).

rici
  • 234,347
  • 28
  • 237
  • 341
1

I think firstly it is needed to add new rule to A production to stop recursion. Something like b in your example.

A -> A*B | A+CDE | Aab | b

If this is not possible I guess production will looks like this:

A -> A*B | A+CDE | Aab | e

So, first step will be left factoring:

A -> AT | e
T -> *B | +CDE | ab

And then remove left recursion:

A -> A'
A' -> TA' | e
T -> *B | +CDE | ab
Larty
  • 26
  • 1
  • @SakibArifin yes, but e is used only for stopping infinite recursion, it means empty string. You can use without it and there will be no left recursion as well. –  Larty Feb 23 '23 at 13:53