I wonder what the FOLLOW set of a certain NonTerminal is, when the left-recursion of a grammar is eliminated, like in the following example grammar.
let's assume this grammar
1 E → T E’
2 E’→ + T E’
3 E’→ ε
4 T → F T’
5 T’→ * F T’
6 T’→ ε
7 F → ( E )
8 F → id
Let's first take a look at the part row 4 - row 8
4 T → F T’
5 T’→ * F T’
6 T’→ ε
7 F → ( E )
8 F → id
Is it correct, that FOLLOW(F) in this context is... ?
{*}
Explanation:
When we broaden the context and look at the whole grammar, is it correct, that the complete FOLLOW-Set of F for this grammar is... ?
-> {'+', '*', ')', '$'}
Explanation:
-> {'*'}
If T' in row 4 again expands to ε, then the rule is to add FOLLOW(T) to FOLLOW(F).
If E' in line 2 expands to T' again, then T is followed by +. If E' expands to ε, then T is followed by ε. Again the Rule "Add FOLLOW(E') to FOLLOW(T) applies
-> {'+'}
-> {')'}
Yours sincerely
von Spotz
EDIT:
Corrected according to the answer ot rici that FOLLOW-Sets do not contain 'ε'. That's what the rule
If A -> αB, add FOLLOW(A) to FOLLOW(B)
is for.
Also rici's hint, that Follow of T is E, as stated in Example 2: (4) and thus also the accepting symbol '$' belongs to Follow(F).
FOLLOW(F) is {'+', '*', ')', $}
(where $
is the end-marker).
Follow sets never include ε. You need to take ε into account when you compute FOLLOW, but you don't add it to any FOLLOW set.