17

Let's suppose I have the following grammar:

S → X  
X → a | ϵ

If that grammar wouldn't have ϵ involved, I would construct the first state like:

S' → .S
S → .X
X → .a

but what about the ϵ symbol? Should I include:

X → .ϵ

too?

If so... when creating the next states... should I do GOTO(Io,ϵ), being Io that first state?

Oscar Mederos
  • 29,016
  • 22
  • 84
  • 124

2 Answers2

17

I agree with Howard. Your state in the DFA should contain the item: x → . Here's a DFA I drew for an SLR(1) parser that recognizes a grammar that uses two epsilon productions:SLR(1) DFA

Rose Perrone
  • 61,572
  • 58
  • 208
  • 243
  • I have a problem with this scanned example. Let's have a look at T(n): T -> .(E) goto(T(n), () = { [T->(.E)], [E->.TX], [T->.(E)] , [T->.intY]} if so, then consequently, for T(n+1): X->.+E should I not have: goto(T(n+1), +) = {[X->+.E], [E->.TX], [T->.(E)] , [T-> .intY]} ? Instead in the example I have: goto(T(n+1), +) = {[X->+.E], [E->.TX]} Why we are not including in goto(T(n+1), +) productions for T? – Joanna Jun 22 '17 at 11:23
  • You are correct @joanna. While I do not understand what you mean by T(n) and T(n+1), the LR state you are referring to, namely {[X->+.E], [E->.TX]} should include productions for T via prediction. In the current formulation there is no way to progress from the given state since there are no terminals to the right of the dot. – corwin.amber Aug 14 '17 at 17:36
11

Since ϵ is not a terminal itself you have to remove it from your rule which gives you

X → .

Then later you won't have any strange GOTO with "symbol" ϵ but instead your state

S' → S.

is an accepting state in your graph.

Howard
  • 38,639
  • 9
  • 64
  • 83