0

I have a CFG in the form

PB := PB | R | R
R := s

I have tried to make it ll(1) by removing the left recursion resulting in

 PB := R PB' | R PB'
 PB' := PB'| ϵ
 R := s

However, I believe, removing the left recursion is making the grammar now ambiguous.

How can this be fixed?

Kneelac
  • 15
  • 1
  • 5

1 Answers1

0

The original grammar is ambiguous. Elimination of left-recursion neither creates nor removes ambiguity.

Ambiguities:

PB := PB

This production does nothing, but it can be applied any number of times

PB := R
PB := R

These two productions are identical, so anywhere one might apply, the other one might be used instead.

When you remove the pointless productions, you are left with

PB := R
R := s

Which is unambiguous and non-recursive. Since it is not recursive, there is no left recursion to remove.

rici
  • 234,347
  • 28
  • 237
  • 341