From b488e5485f4dcb24c0df5bb49d3acdb69f75920e Mon Sep 17 00:00:00 2001
From: "Sven M. Hallberg" <pesco@khjk.org>
Date: Sun, 12 May 2013 16:51:35 +0200
Subject: [PATCH] always put end_token in the start symbol's follow set

---
 src/cfgrammar.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/cfgrammar.c b/src/cfgrammar.c
index eb3239d2..a9005e9b 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;
-- 
GitLab