Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Compiler construction 为以下语法计算自顶向下解析的FIRST和FOLLOW集_Compiler Construction - Fatal编程技术网

Compiler construction 为以下语法计算自顶向下解析的FIRST和FOLLOW集

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->T.S | S 解决方案: 消除左递归后,语法为:

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.