开发者

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:

SLR(1) Parser and epsilon involved


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜