1

So I have this left recursive grammar

E → E Op1 E2 | E2

As it stand, it is left recursion, so I eliminated the left recursion by putting in another step:

E → X E2
X → E Op1 E2 | ε

I have a sinking feeling however that I eliminated it wrongly, because if I trace it then the FIRST set of E is still going to be starting with E. Am I correct? Or am I missing something? This question is a part of a bigger grammar set, FYI.

Alexey Malev
  • 6,408
  • 4
  • 34
  • 52
Doh
  • 113
  • 1
  • 2
  • 6
  • Are you implementing some kind of compiler? Or it's just a generic question? – rpax May 05 '14 at 12:04
  • Your reasoning seems correct; however, I would consider the question as off-topic as it is primarily about theoretical computer science, not programming-related in a strict sense. – Codor May 05 '14 at 12:06
  • I will eventually have to implement these sets of grammar into a parser and then write a program implement those parser, so i thought it was appropriate. – Doh May 05 '14 at 12:08

1 Answers1

1

What you're missing is the second part of recursion elimination: instead of

X → E Op1 E2 | ε

you need

X → Op1 E2 X | ε
András Hummer
  • 960
  • 1
  • 17
  • 35