Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 233
Oscar Mederos Avatar asked Jun 28 '11 04:06

Oscar Mederos


People also ask

What is SLR 1 parser describe the steps for the SLR parser?

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.

What are the types of parsers How does SLR parser work?

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

What is the difference between SLR and LR 1 parsing?

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

How do you know if a grammar is SLR 1?

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


2 Answers

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.

like image 30
Howard Avatar answered Sep 20 '22 13:09

Howard


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

like image 105
Rose Perrone Avatar answered Sep 16 '22 13:09

Rose Perrone