简体   繁体   中英

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?

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:单反(1) DFA

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM