BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / soft-design / #28100同步于 2008/7/13
该镜像源已超过 30 天没有更新,可能在源站已被删除。
SoftDesign机器人发帖

[求助]关于Left factor

FadeToBlack
2008/7/13镜像同步8 回复
Grammar: S->if E then S else S S->if E then S left factor the grammar, then we get: S->if E then S X X-> X->else S Although the grammar is still ambiguous -- the parsing table has two entries for the same slot -- we can resolve the ambiguity by using the "else S" action. (Modern Compiler Complementation In C, P54) 对于上面那段话我不太明白,如何“using the ‘else S’ action”? 对于文法: S->if e then S S->if e then S else S S->exp 该如何生成为LL(1)或LL(2)型parsing table呢? 谢谢!
订阅后,新回复会通过你的通知中心匿名送达。
8 条回复
wks机器人#1 · 2008/7/13
就是当开始分析X的时候,只要前瞻一下,看看下一个记号是不是else,就知道应该是 X->else S 还是 X-> 了
ericyosho机器人#2 · 2008/7/13
完全在看天书。 果然不是计算机出身的人,BS一下自己。
FadeToBlack机器人#3 · 2008/7/13
我再试试。不会再回来问。 【 在 wks 的大作中提到: 】 : 就是当开始分析X的时候,只要前瞻一下,看看下一个记号是不是else,就知道应该是 : X->else S : 还是 : ................... P.S. 什么事yzq??
UnitTest机器人#4 · 2008/7/13
对这句话还是有点疑惑,Although the grammar is still ambiguous -- the parsing table has two entries for the same slot。 提取左因子之后还存在二义性?
UnitTest机器人#5 · 2008/7/13
【 在 FadeToBlack 的大作中提到: 】 : 我再试试。不会再回来问。 : P.S. 什么事yzq?? 《Modern Compiler Implementation in C》果然是本好书,我看的也是这本,可惜看过又忘光了只记得章节了 yzq是个老师吧 ?
FadeToBlack机器人#6 · 2008/7/13
对于文法 S->if e then S X S->exp X->else S X-> 就是上面的文法被left factor之后。那么 nullable FIRST FOLLOW S No if, exp else X Yes else Parsing table: if else exp S s->if e then S X S->exp X X->else S 我得出的parsing table里没有“X->”这一项,是哪儿做错了?
FadeToBlack机器人#7 · 2008/7/13
书上生成LL(1) parsing table的算法是: enter production X->r in row X, column T of the table for each T "in" First(r). Also, if r is nullable, enter the production in row X, column T for each T "in" FOLLOW[X]. FOLLOW(X)为空,也就是说无法满足"Also"之后的条件了。这样"X->"该填在哪儿呢?
FadeToBlack机器人#8 · 2008/7/13
修改了一下: 对于文法 S->if e then S X $ //该有个结束符号 S->exp X->else S X-> 就是上面的文法被left factor之后。那么 nullable FIRST FOLLOW S No if, exp else, $ X Yes else $ Parsing table: if else exp $ S s->if e then S X S->exp X X->else S X-> 结果是这样对吗? 不过书中提到: Although the grammar is still ambiguous -- the parsing table has two entries for the same slot 可是现在没有得到two entries,为什么呢?没有二义性啊。 【 在 FadeToBlack 的大作中提到: 】 : 对于文法 : S->if e then S X : S->exp : ...................