compiler construction - Computing the FOLLOW() set of a grammar -
i'm reading compilers: principles, techniques, , tools (2nd edition) , i'm trying compute follow() sets of following grammar:
s → ietss' | s' → es | ε e → b where s, s', e non-terminal symbols, s start symbol, i, t, a, e, b terminal symbols, , ε empty string.
what i've done far
follow(s) = {$} ∪ follow(s') follow(s') = follow(s) follow(e) = first(tss') - {ε} = first(t) - {ε} = {t} - {ε} = {t} where $ input right endmaker.
explanation
$ ∈ follow(s), since s start symbol. know s' → es, in follow(s') in follow(s). therefore, follow(s) = {$} ∪ follow(s').
we know s → ietss', in follow(s) in follow(s'). therefore, follow(s') = follow(s).
the problem can't compute follow(s), since don't know follow(s'). ideas?
the simple algorithm, described in text, least fixed-point computation. cycle through nonterminals, putting terminals follow sets, until through entire cycle without changes.
since nothing ever removed follow set, , number of terminals finite, algorithm must terminate. takes few cycles.
Comments
Post a Comment