0

Using any of the techniques (substitution, factoring, left-recursion removal), construct an LL(1) grammar accepting the same language as G.

G over Σ = {0, 1, 2}:
    S → Y | 1X
    X → 1X | 0
    Y → Y0 | 1X1 | 2X2

I did this so far:

X is left recursive so:

X -> 1F | 0F
F -> 1F | e

What else would i need to do to construct an LL(1), could i factor Y?

user207421
  • 305,947
  • 44
  • 307
  • 483
user3166873
  • 85
  • 3
  • 10

1 Answers1

0

First, X is not left recursive, as its RHS doesn't begin with X. Rather it's tail-recursive and it's all right. However Y -> Y0 tells you that Y is left-recursive. In this case you do the following:

S -> Y | 1X
X -> 1X | 0
Y -> 1X1F | 2X2F
F -> 0F | e

You may also want to add and epsilon rule to X as well making it

X -> 1X | 0 | e

just to make sure you'll never end up with infinite sentences.

András Hummer
  • 960
  • 1
  • 17
  • 35