[英]Compiler Design First and follow
I have i doubt in a problem,trying to calculate FOLLOW(S) which needs FOLLOW(A) in it,but as A production is after S production,we have not calculated FOLLOW(A) yet.So,should we add FOLLOW(A) too inf FOLLOW(S)??? 我怀疑一个问题,试图计算其中需要FOLLOW(A)的FOLLOW(S),但是由于A生产在S生产之后,我们还没有计算FOLLOW(A)。因此,我们应该添加FOLLOW( A)太喜欢了吗????
To compute FOLLOW(S) for any non-terminal S, apply the followwing rules until nothing can be added to any FOLLOW set. 要为任何非终端S计算FOLLOW(S),请应用跟随翼规则,直到不能将任何内容添加到任何FOLLOW集合中为止。
Place $ in FOLLOW(S), where S is the start symbol. 将$放在FOLLOW(S)中,其中S是开始符号。
If there is a production S -> CBD, then everything in FIRST(D) except epsilon is in FOLLOW(B). 如果存在生产S-> CBD,则FIRST(D)中除epsilon之外的所有内容都在FOLLOW(B)中。
If there is a proudction S -> CB, or a production S -> CBD, where FIRST(D) contains epsilon, then everything in FOLLOW(S) is in FOLLOW(B). 如果有一个S-> CB或生产S-> CBD,其中FIRST(D)包含epsilon,则FOLLOW(S)中的所有内容都在FOLLOW(B)中。
Trying to calculate FOLLOW(S) which needs FOLLOW(A) in it,but as A production is after S production,we have not calculated FOLLOW(A) yet.So,should we add FOLLOW(A) too inf FOLLOW(S)??? 尝试计算其中需要FOLLOW(A)的FOLLOW(S),但是由于A生产在S生产之后,我们还没有计算FOLLOW(A)。因此,我们也应该在FOLLOW(S)中也添加FOLLOW(A) ???
SO, as you can see from the given grammar, 所以,正如您从给定的语法中看到的那样,
as per rule 1, the follow(S) will contains $. 根据规则1,follow(S)将包含$。
Also, as per rule 2, S appears in bodies only followed by D( non-terminal ), thus, everything except epsilon that is in FIRST(D) must be in FOLLOW(S). 同样,根据规则2,S仅出现在主体中,之后是D( 非终结点 ),因此,除了FIRST(D)中的epsilon外,其他所有内容都必须位于FOLLOW(S)中。 So, FOLLOW(S) must contain a. 因此,FOLLOW(S)必须包含a。
Also,as per rule 3, considering the production A->ASD |epsilon and FIRST(D) contains epsilon, we should get FOLLOW(S) = FOLLOW(A). 同样,按照规则3,考虑到生产A-> ASD |ε,并且FIRST(D)包含ε,我们应该得到FOLLOW(S)= FOLLOW(A)。
So, yes you need to calculate FOLLOW(A) before FOLLOW(S). 因此,是的,您需要在FOLLOW(S)之前计算FOLLOW(A)。
And, FOLLOW(A) = everything in FIRST(S) except epsilon + b = {a,b}. 并且,FOLLOW(A)= FIRST(S)中的所有内容,除了epsilon + b = {a,b}。
Hence, FOLLOW(S) = {a,b,f,$}. 因此,FOLLOW(S)= {a,b,f,$}。
I don't know how you come to calculate that FOLLOW(A) is required for calculating FOLLOW(S). 我不知道您如何计算FOLLOW(A)是计算FOLLOW(S)所必需的。 It is not the case. 事实并非如此。 Please again go through the rules 1 to 3 mentioned in the starting of this answer. 请再次按照此答案开头提到的规则1至3进行操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.