From: NeilBrown Date: Tue, 6 Oct 2020 07:11:15 +0000 (+1100) Subject: parsergen: sort virtual symbols to send of list X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=2594d150e123c29949493c37c8b9c14aa6abe5a4 parsergen: sort virtual symbols to send of list virtual symbols are used internally to parsergen and of no interest to the parser. So they shouldn't appear in the non_term[] array. So assign them higher numbers so the nonterminals are dense, and only include non-virtual non-terminals in the non_term[] array. Signed-off-by: NeilBrown --- diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index 5bf413d..13b946f 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -1545,6 +1545,11 @@ changeover point in `first_nonterm`. snum++; } g->first_nonterm = snum; + for (s = g->syms; s; s = s->next) + if (s->num < 0 && s->type != Virtual) { + s->num = snum; + snum++; + } for (s = g->syms; s; s = s->next) if (s->num < 0) { s->num = snum; @@ -2011,7 +2016,7 @@ numbers right. for (i = TK_reserved; i < g->num_syms; i++) - if (g->symtab[i]->type != Terminal) + if (g->symtab[i]->type == Nonterminal) fprintf(f, "\t\"%.*s\",\n", g->symtab[i]->name.len, g->symtab[i]->name.txt); fprintf(f, "};\n\n");