我有以下语法
E -> TX
X -> +E
|epsilon
T -> intY
| (E)
Y -> *T
| epsilon
以下跟随设置对于上述语法是否正确?
E = {$, )}
X = {$, )}
T = {int, (, $}
Y = {int, (, $}
答案 0 :(得分:1)
<强> 第一 强>
First(E) -> {int, (}
First(X) -> {+, epl}
First(T) -> {int, (}
First(Y) -> {*, epl}
<强> 关注 强>
Follow(E) -> {$, )}
Follow(X) -> {Follow(E)}
Follow(T) -> {First(X) - epl, Follow(E)} -> {+, $, )}
Follow(Y) -> {Follow(T)}
为什么跟随(E)跟随(T)?因为First(X)有epsilon - &gt;给我们E - &gt; T生产
答案 1 :(得分:0)
对于以下语法:
E -> TX
X -> +E |epsilon
T -> intY| (E)
Y -> *T| epsilon
计算第一组
FIRST(E)= FIRST(T) - epsilon U FIRST(X)
= {int,(,+,epsilon}
FIRST(X)= FIRST(+ E) - epsilon U epsilon
= {+,epsilon}
FIRST(T)= FIRST(intY) - epsilon U FIRST((E))
= {int,(}
FIRST(Y)= FIRST(* T) - epsilon U epsilon
= {*,epsilon}
计算FOLLOW set
关注(E) - &gt; {$,)}
跟随(X) - &gt; {$,)}
关注(T) - &gt; {+,$,)}
关注(Y) - &gt; {+,$,)}