totally forgot to record the start symbol of the grammar

This commit is contained in:
Sven M. Hallberg 2013-05-05 11:17:57 +02:00
parent 2ce5d1129c
commit c26d5c114a

View file

@ -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?