I am trying to remove left recusion from a grammar, and I can do this SOMETIEMES. I obviously don't know the rules, because I only know how to do it by trial and error. The rules I see are like this: The rules that I found on Wikipedia
S --> SX | SSb | XS | a
X --> Xb | Sa | b
So, I know in this particular example, that I can first remove immediate left recursion from the S rule and then after that I get this:
S --> XSS' | aS'
S' --> XS' | SbS' | epsilon
X --> Xb | Sa | b
Then, from here I can merge the S production into the X production to get:
X --> Xb | XSS' | aS'a | b
and then I can remove immediate left recursion from there to get my final answer. BUT, can someone please explain the rules to me, because I did not follow them to arrive at my final answer. I kind of got lucky. I need to know how to remove left recursion from any given grammar. Any help would be greatly appreciated. Thank you.