我正在尝试计算以下语法的FOLLOW集:
E -> TX
T -> int Y | ( E )
X -> + E | ε
Y -> * T | ε
到目前为止,我已经计算了以下FOLLOW设置:
follow (E) = {$} U {)}
follow (Y) = follow (T)
follow (T) = follow (Y)
follow (X) = follow (E) = {$, )}
follow (E) = first ()) = {)}
我知道跟随(T)/跟随(Y)包含{+,$,)}但我很难达到这一点。
在这里解释方法的任何帮助都会非常有帮助。
注意:我遵守了这些规则
1) If A is the start symbol put $ in Follow (A)
2) If there is a production B -> αAb, then Follow (A) = First (b)
3) If there is a production B -> aA or B -> αAb where First (b) is ε, add Follow (A) = Follow (B)
答案 0 :(得分:0)
我已经明白了(并且花了下午的大部分时间)!
因此,我发现这个的规则是:
follow(E) = follow(T)
follow(E) = first ())
follow(X) = follow(E)
follow(Y) = follow(T)
**follow(T) = first(X)** //the important one!
遵循这些规则,您可以构建集合:
follow(E) = {$, )}
follow(T) = {$, ), +}
follow(X) = {$, )}
follow(Y) = {$, ), +}
结论语法的后续集合结束了!