1

This is the original grammar:

S -> ABe
A -> ab | a | ϵ
B -> b

I did try left factoring and this is what I got:

S -> ABe
A -> aX | ϵ
X -> b | ϵ
B -> b 

But it still is not LL(1).

Asnira
  • 111
  • 1
  • Why don't you inline A, B and X? Are you following some fixed procedure? – reinierpost Nov 09 '16 at 16:14
  • Why is this not an LL(1)? What definition of LL(1) are you using? – randomsurfer_123 Nov 09 '16 at 16:16
  • @randomsurfer_123 there are conflicts in parsing table. – Asnira Nov 09 '16 at 16:18
  • @reinierpost sorry, I dont get what you are saying. – Asnira Nov 09 '16 at 16:19
  • I mean you can transform the grammar by substituting right hand sides for nonterminals in right hand sides. But have you applied the definition of LL(1) you've been given? – reinierpost Nov 09 '16 at 16:21
  • @reinierpost I was told to eliminate left recursion if there are any, then use left factoring if needed, and the result should be LL(1). but I find conflicts between rules in the parsing table. – Asnira Nov 09 '16 at 16:26
  • Which conflicts? See also http://cs.stackexchange.com/questions/4862/left-factoring-a-grammar-into-ll1 – reinierpost Nov 09 '16 at 17:34
  • @randomsurfer_123 the first sets of nonterminals are not disjoint which proves this is not LL1. It is bound to have conflicts in the parsing table. – Shubham Singh rawat Nov 09 '16 at 17:56
  • 1
    Do you have to follow those instructions, or do you just need to find an equivalent LL(1) form? In general, if you have a rule of the form $S \to A\alpha$ where $A$ is nullable, then just eliminating left-recursion and left-factoring is not enough. There's two things you can do: 1. either inline A and B, or 2. eliminate the $\epsilon$ from $A$ so that $S \to ABe \mid Be; A \to a \mid ab$. Either of these options will allow you to finish off your grammar using just recursion elimination and factoring; but without doing at least one of these, you can't get to an amenable form. – Lee Nov 09 '16 at 18:25
  • Also for reference, the conflict occurs at the $X$ nonterminal at the word $b$; ${\rm follow}(X) = {\rm follow}(A) = {\rm first}(B) = {b}$, so both the $X \to b$ and $X \to \epsilon$ rules shift on $b$. – Lee Nov 09 '16 at 18:27

0 Answers0