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?
SLR (1) refers to simple LR Parsing. It is same as LR(0) parsing. The only difference is in the parsing table.To construct SLR (1) parsing table, we use canonical collection of LR (0) item. In the SLR (1) parsing, we place the reduce move only in the follow of left hand side.
SLR Parser The SLR parser is similar to LR(0) parser except that the reduced entry. The reduced productions are written only in the FOLLOW of the variable whose production is reduced. Construct C = { I0, I1, ……. In}, the collection of sets of LR(0) items for G'.
The only difference between LR(0) and SLR(1) is this extra ability to help decide what action to take when there are conflicts. Because of this, any grammar that can be parsed by an LR(0) parser can be parsed by an SLR(1) parser. However, SLR(1) parsers can parse a larger number of grammars than LR(0).
If you can construct a parsing table and there are no conflicts, it's SLR(1). (It certainly looks like it should be; if you left-factor C, then it's LL(1).)
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With