. Compute FOLLOW sets for the following grammar: S => aAB | CD A => CD | SE | e
ID: 669943 • Letter: #
Question
. Compute FOLLOW sets for the following grammar:
S => aAB | CD
A => CD | SE | e
B => aSB | DS
C => cC | e
D => DdC | e
E => eFg
F => Fg | e
I've calculated the FIRST sets which are:
FIRST(S) = { a , c, epsilon , d }
FIRST(A) = { a , epsilon , c , e , d }
FIRST(B) = {a, c , e , epsilon , d }
FIRST(C) = {c, epsilon}
FIRST(D) = {c, epsilon, d}
FIRST(E) = {e, g, epsilon}
FIRST(F) = {epsilon, g}
Please explain the steps to me. Thanks!
Explanation / Answer
The FOLLOW set for non-terminal symbols consists of set of terminals that appear after the non-terminal symbol, which is derived from the grammar’s start symbol.
The end of the input string is represented by, which is automatically included to the input string.
The non-terminal S does not appear in any productions including its own production. So,.
The follows are:
FOLLOWS(S) = {d, $, e, g}
FOLLOWS(A) = {d, a,$}
FOLLOWS(B) = {d, a,$}
FOLLOWS(C) = {d, c, e, $}
FOLLOWS(D) = { d, c, e, $}
FOLLOWS(E) = {g, $}
FOLLOWS(F) = { g, $}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.