diff --git a/src/cfgrammar.c b/src/cfgrammar.c index eb3239d2cbf30f5e3f3dbf66f447be01e1d8db7e..a9005e9bafd787d19b5394561ed771b93be9d086 100644 --- a/src/cfgrammar.c +++ b/src/cfgrammar.c @@ -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;