From a16e66d338902e320f8acf1b34b3e37e1c5f001b Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" <pesco@khjk.org> Date: Thu, 13 Feb 2020 10:12:35 +0100 Subject: [PATCH] add an assert to h_follow() --- src/cfgrammar.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cfgrammar.c b/src/cfgrammar.c index 77e7eca..1d80712 100644 --- a/src/cfgrammar.c +++ b/src/cfgrammar.c @@ -586,6 +586,7 @@ const HStringMap *h_follow(size_t k, HCFGrammar *g, const HCFChoice *x) // iterate over g->nts size_t i; HHashTableEntry *hte; + int x_found=0; for (i=0; i < g->nts->capacity; i++) { for (hte = &g->nts->contents[i]; hte; hte = hte->next) { if (hte->key == NULL) { @@ -600,7 +601,8 @@ const HStringMap *h_follow(size_t k, HCFGrammar *g, const HCFChoice *x) HCFChoice **s = (*p)->items; // production's right-hand side for (; *s; s++) { - if (*s == x) { // occurance found + if (*s == x) { // occurrence found + x_found=1; HCFChoice **tail = s+1; const HStringMap *first_tail = h_first_seq(k, g, tail); @@ -612,6 +614,7 @@ const HStringMap *h_follow(size_t k, HCFGrammar *g, const HCFChoice *x) } } } + assert(x_found || x == g->start); // no orphan non-terminals return ret; } -- GitLab