always put end_token in the start symbol's follow set

This commit is contained in:
Sven M. Hallberg 2013-05-12 16:51:35 +02:00
parent f33390a510
commit b488e5485f

View file

@ -258,6 +258,7 @@ HHashSet *h_follow(HCFGrammar *g, const HCFChoice *x)
{
// consider all occurances of X in g
// the follow set of X is the union of:
// {$} if X is the start symbol
// given a production "A -> alpha X tail":
// if tail derives epsilon:
// first(tail) u follow(A)
@ -275,6 +276,10 @@ HHashSet *h_follow(HCFGrammar *g, const HCFChoice *x)
assert(ret != NULL);
h_hashtable_put(g->follow, x, ret);
// if X is the start symbol, the end token is in its follow set
if(x == g->start)
h_hashset_put(ret, (void *)end_token);
// iterate over g->nts
size_t i;
HHashTableEntry *hte;