SLR(1) Parser and epsilon involved

Oscar Mederos picture Oscar Mederos · Jun 28, 2011 · Viewed 7.3k times · Source

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?

Answer

Rose Perrone picture Rose Perrone · Apr 28, 2012

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