For this grammar:
A -> B a | A a | c
B -> B b | A b | d
How to remove the left recursion?
====== My attempts ======
- Eliminate direct left_rec first.
A -> (B a | c) A' A' -> a A' | ε B -> (A b | d) B' B' -> b B' | ε
- Then indirect. Put B into A.
A -> A b B' a A ' | d B' A' | c A'
And then I got:
A -> (d B A' | c A') A''
A' -> a A' | ε
A'' -> b B' a A' A'' | ε
This result is quite complicated. How can I use only one A' to represent this?