简体   繁体   English

建立一个语法的跟随集

[英]Building a FOLLOW set of a grammar

I have a grammar which has the left recursion removed and it is left factored also. 我有一个语法,该语法除去了左递归,并且也将其分解为左因子。

I created FIRST sets already, that was quite simple task, but constructing the FOLLOW sets is problematic. 我已经创建了FIRST集,这是非常简单的任务,但是构造FOLLOW集是有问题的。 I tried to find helpful examples but failed to find any that would help me. 我试图找到有用的示例,但没有找到任何可以帮助我的示例。

Here is the grammar: 这是语法:

St is the start symbol. St是开始符号。

St -> St'
St' -> i S'
E -> i E'
E' -> [ E ] E'
E' -> ε
S' -> = E
S' -> [ E ] = E

And the corresponding FIRST sets are 对应的FIRST集是

E = { i }
E' = { [, ε }
S' = { [, = }
St = { i }
St' = { i }

Now, the rules for building the follow sets are from http://www.jambe.co.nz/UNI/FirstAndFollowSets.html are quite simple and yet i do not know how to apply them correctly. 现在,构建跟随集的规则来自http://www.jambe.co.nz/UNI/FirstAndFollowSets.html ,非常简单,但我不知道如何正确应用它们。

Follow sets i have constructed so far are: 到目前为止,我已经构建了以下集合:

E = {}
E' = {}
S' = {}
St = {$}
St' {$}

but after this i have no clue how to proceed. 但是在此之后我不知道如何进行。 Some tips would be most welcome, i'm not expecting to get complete solution to this problem, just some tips so i can understand how building follow sets work. 一些技巧将是最受欢迎的,我不希望获得此问题的完整解决方案,只是一些技巧,这样我就可以了解构建跟踪集的工作方式。

Rules for Follow Sets 跟随集规则

  • First put $ (the end of input marker) in Follow(S) (S is the start symbol) If there is a production A → aBb, (where a can be a whole string) then everything in FIRST(b) except for ε is placed in FOLLOW(B). 首先将$(输入标记的末尾)放在Follow(S)中(S是开始符号)。如果存在乘积A→aBb(其中a可以是整个字符串),则FIRST(b)中的所有内容(除ε外)放在FOLLOW(B)中。

  • If there is a production A → aB, then everything in FOLLOW(A) is in FOLLOW(B) 如果产生A→aB,则FOLLOW(A)中的所有内容都在FOLLOW(B)中

  • if there is a production A → aBb, where FIRST(b) contains ε, then everything in FOLLOW(A) is in FOLLOW(B) According To Above Rules Your Answer is : 如果有产品A→aBb,且FIRST(b)包含ε,则FOLLOW(A)中的所有内容都在FOLLOW(B)中。根据上述规则,您的答案是:

     E = { ] } E' = { ] } S' = { $ } St = { $ } St'= { $ } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM