3.设有文法G[A] A→BCc|gDB B→bCDE|ε C→DaB|ca D→dD|ε E→gAf|c 计算该文法的每一个非终结符的FIRST集和FOLLOW集。
时间: 2024-01-05 10:58:45 浏览: 75
求非终结符的first集和follow集
4星 · 用户满意度95%
首先,给出该文法的非终结符集合和终结符集合:
非终结符集合:{A, B, C, D, E}
终结符集合:{a, b, c, d, f, g}
接下来,计算每个非终结符的FIRST集和FOLLOW集:
1. 非终结符A的FIRST集和FOLLOW集:
FIRST(A) = FIRST(BCc) ∪ FIRST(gDB) = {g}
FOLLOW(A) = {$}
2. 非终结符B的FIRST集和FOLLOW集:
FIRST(B) = FIRST(bCDE) ∪ {ε} = {b, ε}
FOLLOW(B) = FIRST(c) ∪ FOLLOW(A) = {c, $}
3. 非终结符C的FIRST集和FOLLOW集:
FIRST(C) = FIRST(DaB) ∪ FIRST(ca) = {c, d, g}
FOLLOW(C) = FIRST(c) ∪ FOLLOW(B) ∪ FOLLOW(A) = {c, $}
4. 非终结符D的FIRST集和FOLLOW集:
FIRST(D) = {d, ε}
FOLLOW(D) = FIRST(aB) ∪ FOLLOW(C) = {a, c, $}
5. 非终结符E的FIRST集和FOLLOW集:
FIRST(E) = FIRST(gAf) ∪ FIRST(c) = {c, g}
FOLLOW(E) = FIRST(c) ∪ FOLLOW(A) = {c, $}
阅读全文