[問題] Compiler -LL(1) Grammar

作者: fbukevin (Veck)   2013-04-10 16:51:45
Compute the First and Follow sets for the following grammar.
S ← TS | a
T ← UVb | ε
U ← V | ca | ε
B ← aUb | c
已經知道:
First(S) = {a,c}
First(T) = {a,c,ε}
First(U) = {a,c,ε}
First(V) = {a,c}
Follow(S) = {$}
Follow(T) = {a,c,$}
Follow(U) = {a,c,b}
Follow(V) = {a,b,c}
我想問為什麼 Follow(V) 中有 a 和 c 呢?
我看 Aho 的 Compiler Principle.. 那本
他說 Follow set 的計算有三個規則:
1. 將 $ 放到 Follow(S) 中,其中 S 是 start symbol
2. 如果存在一個 production A→αBβ
則 First(β) 中除了ε之外的所有符號都在Follow(B)中
3. 如果存在一個 production A→αB
或 A→αBβ且 First(β)包含ε
則 Follow(A)中所有符號都在Follow(B)中
作者: LPH66 (-6.2598534e+18f)   2013-04-10 17:03:00
U ← V 所以 Follow(U) 會加進 Follow(V) 裡去(用的是第 3 條規則)
作者: fbukevin (Veck)   2013-04-10 17:12:00
謝謝大大! 是把 V 看作是B,α沒有,這樣嗎?

Links booklink

Contact Us: admin [ a t ] ucptt.com