From c26d5c114a13eaea07b80e61e51c2b8f78caf6b7 Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" Date: Sun, 5 May 2013 11:17:57 +0200 Subject: [PATCH] totally forgot to record the start symbol of the grammar --- src/backends/ll.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/backends/ll.c b/src/backends/ll.c index 86f6411..3c8d5c9 100644 --- a/src/backends/ll.c +++ b/src/backends/ll.c @@ -7,6 +7,7 @@ /* Grammar representation and analysis */ typedef struct HCFGrammar_ { + HCFChoice *start; // start symbol (nonterminal) HHashSet *nts; // HCFChoices, each representing the alternative // productions for one nonterminal HHashSet *geneps; // set of NTs that can generate the empty string @@ -56,7 +57,7 @@ HCFGrammar *h_grammar(HAllocator* mm__, const HParser *parser) // represent a nonterminal (type HCF_CHOICE or HCF_CHARSET). collect_nts(g, desugared); if(h_hashset_empty(g->nts)) { - // desugared is a single terminal. wrap it in a singleton HCF_CHOICE. + // desugared is a terminal. wrap it in a singleton HCF_CHOICE. HCFChoice *nt = h_new(HCFChoice, 1); nt->type = HCF_CHOICE; nt->seq = h_new(HCFSequence *, 2); @@ -66,6 +67,9 @@ HCFGrammar *h_grammar(HAllocator* mm__, const HParser *parser) nt->seq[0]->items[1] = NULL; nt->seq[1] = NULL; h_hashset_put(g->nts, nt); + g->start = nt; + } else { + g->start = desugared; } // XXX call collect_geneps here?