1

I've a problem in understanding left recursion. I know that this is a left recursion: A->Aa Can you tell me if this is left recursion? A->aA

And can you explain me why this is an indirect left recursion?

  • D ---> dcD' | SD'
  • D' --> DbaD' | DcD' | e

Thanks for any help!

testermaster
  • 1,031
  • 6
  • 21
  • 40

1 Answers1

1

A grammar is left recursive if starting from a non terminal E and applying rules you find a string which start with E itself. If its a direct rule then it's direct left recursive as it A- > Aa. If you have to apply more rule then it's indirect.

I'm assuming you grammar is

- `D ---> dcD' | D'`
- `D' --> DbaD' | DcD' | e`

Then you have the derivation

 D -> D' -> DbaD'

So this in an indirect left recursion.

Now, if you are sure that there is an S, then it depends of what you can derive from S. But if there is no D at the beginning of any word deriving from S, then it is non left recursive.

By the way, this is better to ask those kind of question on https://cs.stackexchange.com/

Community
  • 1
  • 1
hivert
  • 10,579
  • 3
  • 31
  • 56
  • Hi, I'm sure that there's a "S". My friend told me that he was sure that it was a type of indirect left recursion, but I've studied a little more and now I'm almost sure that he's wrong. Can you confirm that if there's an "S" in the second rule of D (like in my text) we DON'T have indirect left recursion? PS: thanks for the tip about stackexchange! – testermaster Feb 07 '14 at 02:17