Compiler construction 为以下语法计算自顶向下解析的FIRST和FOLLOW集
对于下面的语法,我已经计算了第一组和第二组 S->a++(T) T->T.S | S 解决方案: 消除左递归后,语法为:Compiler construction 为以下语法计算自顶向下解析的FIRST和FOLLOW集,compiler-construction,Compiler Construction,对于下面的语法,我已经计算了第一组和第二组 S->a++(T) T->T.S | S 解决方案: 消除左递归后,语法为: S->a|+|(T) T->aT'|+T'|(T)T' T'->.ST'|epsilon 现在,第一组是: 第一(S)={a,+,(} 第一(T)={a,+,(} 第一(T')={,ε} 以下几组是: 跟随={,$} 跟随(T)={} 跟随(T')={} 非左递归语法和FOLLOW集合正确吗?那么有人能告诉我我是否找到了正确的解决方案吗。我不知道是否将$添
S->a|+|(T)
T->aT'|+T'|(T)T'
T'->.ST'|epsilon
现在,第一组是:
第一(S)={a,+,(}
第一(T)={a,+,(}
第一(T')={,ε}
以下几组是:
跟随={,$}
跟随(T)={}
跟随(T')={}
非左递归语法和FOLLOW集合正确吗?那么有人能告诉我我是否找到了正确的解决方案吗。我不知道是否将$
添加到T
和T'
的以下集合中。。。
请帮帮我
First sets, Straight forward:
S = { a, +, ( }
T = { a, +, ( }
T' = {epsilon, .}
Follow Sets:
S = { ), ., $ }
T = { ) }
T' = { ) }
As per the definition of follow from dragon book:
1. Place $ in FOLLOW(S) , where S is the start symbol, and $ is the input
right end marker .
2. If there is a production A -> aBβ, then everything in FIRST(β) except ε
is in FOLLOW(B) .
3. If there is a production A -> aB, or a production A -> aBβ, where
FIRST(β) contains ε, then everything in FOLLOW(A) is in FOLLOW(B) .
Follow of S contains ')' if we apply the rule 3:
T' -> .ST'
As per rule 3: a = . , B = S , T' = β and FIRST(T') contains 'ε', everything in Follow of T' is in Follow of S. Since follow of T' contains ')' it also becomes member of S.