Skip to content
Snippets Groups Projects
Commit b488e548 authored by Sven M. Hallberg's avatar Sven M. Hallberg
Browse files

always put end_token in the start symbol's follow set

parent f33390a5
No related branches found
No related tags found
No related merge requests found
...@@ -258,6 +258,7 @@ HHashSet *h_follow(HCFGrammar *g, const HCFChoice *x) ...@@ -258,6 +258,7 @@ HHashSet *h_follow(HCFGrammar *g, const HCFChoice *x)
{ {
// consider all occurances of X in g // consider all occurances of X in g
// the follow set of X is the union of: // the follow set of X is the union of:
// {$} if X is the start symbol
// given a production "A -> alpha X tail": // given a production "A -> alpha X tail":
// if tail derives epsilon: // if tail derives epsilon:
// first(tail) u follow(A) // first(tail) u follow(A)
...@@ -275,6 +276,10 @@ HHashSet *h_follow(HCFGrammar *g, const HCFChoice *x) ...@@ -275,6 +276,10 @@ HHashSet *h_follow(HCFGrammar *g, const HCFChoice *x)
assert(ret != NULL); assert(ret != NULL);
h_hashtable_put(g->follow, x, ret); 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 // iterate over g->nts
size_t i; size_t i;
HHashTableEntry *hte; HHashTableEntry *hte;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment