parsingtheorygrammarcompiler-theorylanguage-theory

SLR(1) Parser and epsilon involved


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?


Solution

  • 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.