如何删除 FOLLOW 集中的循环依赖
考虑一个简短的语法,
S -> Bc | DB
B -> ab | cS
D -> d | epsilon
第一组就
FIRST(S) ={a,c,d}
FIRST(B) = { a,c }
FIRST(D)= { d, epsilon }
在其中
Follow(S)={ Follow(B) }
,
Follow(B) ={ c , Follow(S) }
我的问题是如何解决这种循环依赖?
Consider a short gramma bellow
S -> Bc | DB
B -> ab | cS
D -> d | epsilon
The FIRST set is
FIRST(S) ={a,c,d}
FIRST(B) = { a,c }
FIRST(D)= { d, epsilon }
in it the
Follow(S)={ Follow(B) }
and
Follow(B) ={ c , Follow(S) }
my question is that how to resolve this circular dependency ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这种循环依赖一开始就不应该存在。这是查找“follow”的算法:
将所有关注组初始化为 {},但 S 除外,它初始化为 {$}。
虽然有变化,但对于每个 A∈V 做:
对于每个 Y → αAβ 执行:
跟随(A) = 跟随(A) ∪ 首先(β)
如果 β ⇒* ε,也做: follow(A) = follow(A) ∪ follow(Y)
所以在你的情况下,你应该得到:
跟随(S)={c,$}
跟随(B)={c,$}
遵循(D)={a,c}
This circular dependency shouldn't be there to start with. this is the algorithm for finding 'follow's:
Init all follow groups to {}, except S which is init to {$}.
While there are changes, for each A∈V do:
For each Y → αAβ do:
follow(A) = follow(A) ∪ first(β)
If β ⇒* ε, also do: follow(A) = follow(A) ∪ follow(Y)
So in your case, you should get:
Follow(S)={c,$}
Follow(B)={c,$}
Follow(D)={a,c}