always put end_token in the start symbol's follow set
This commit is contained in:
parent
f33390a510
commit
b488e5485f
1 changed files with 5 additions and 0 deletions
|
|
@ -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)
|
||||||
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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue