I can't tell if I'm misunderstanding what's going on, or if Wikipedia's explanation is incorrect.
FOLLOW(k,B)
of an item setk
and an nonterminalB
is the union of the follow sets of all items inK
where'•'
is followed byB
.
Their example grammar looks like this:
S → E
E → T
E → ( E )
T → n
T → + T
T → T + n
where they found the LR(0) item set 0 to be:
[S → • E]
[E → • T]
[E → • ( E )]
[T → • n]
[T → • + T]
[T → • T + n]
That means, then, that FOLLOW(0,T)
is the union of the follow sets of all items in item set 0 where '•' is followed by T
.
Applying their logic, we get that "items in item set 0 where '•' is followed by T
" are in fact these two items:
[E → • T]
[T → • T + n]
However, this is where I get stuck:
The follow set of the second one includes the symbol )
, because the item [E → • ( E )]
can produce [E → • ( T )]
, which means a )
must be in the follow set.
However, Wikipedia says that FOLLOW(0,T) = { $, '+' }
.
What am I doing wrong?