Cancel

LL and LR

Language

·

May 08, 2021

First Sets and Follow Sets

To compute FIRST(X) for all grammar symbols X, apply the following rules until no more terminals or ε can be added to any FIRST set:

1.If Xis terminal, then FIRST(X) is {X}.
2.If X →ε is a production, then add ε to FIRST(X).
3.If X is nonterminal and X →Y1 Y2 ... Yk. 
从求取First(Y1)开始,如果Y1的某个产生式有ε,就继续求取First(Y2)......,
如果整个串都已经耗尽了,就把ε也加入

To compute FOLLOW(A) for all nonterminals A, apply the following rules until nothing can be added to any FOLLOW set:

Follow集合是扫描每个产生式的串上的每个非终结符,迭代方式主要是First(下一个字母)和Follow(所在产生式所属的非终结符)

1. Place $ in FOLLOW(S), where S is the start symbol and $ is the input right endmarker.
2. If there is a production A ⇒αΒC, then everything in FIRST(C), except for ε, is placed in FOLLOW(B).
3. If there is a production A ⇒αΒ, or a production A ⇒αΒβ where FIRST(β) contains ε then everything in FOLLOW(A) is in FOLLOW(B).如同计算First一样迭代,如果整个串都已经耗尽了,就把ε也加入Follow(B)

© minghu6

·

theme

Simplex theme logo

by golas