according rules paper :
- if start nonterminal, put eof in follow(a)
find productions on right-hand-side:- for each production x → αaβ, put first(β) − {epsilon } in follow(a)
- if epsilon in first(β) put follow(x) follow(a)
- for each production x → αa, put follow(x) follow(a)
i have next piece in grammar:
... -> c b b -> , c -> epsilon c -> = b -> ; ...
when try calculate follow(b) according rule 4 have calculate follow(a) , vice versa. have stackoverflowexception because of self-recursion.
what should do?
you don't use recursion. iterate, calculating follow
set based on calculated on previous iteration:
if start nonterminal, put eof (a new terminal indicating end of input) in f[0](a).
for each production x → αaβ, put first(β) − {epsilon} in f[n](a),
and if epsilon in first(β) put f[n-1](x) f[n](a)
for each production x → αa, put f[n-1](x) f[n](a).
stop when f[n](*) == f[n-1](*)
follow(*) == f[n](*)
Comments
Post a Comment