From 2594d150e123c29949493c37c8b9c14aa6abe5a4 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 6 Oct 2020 18:11:15 +1100 Subject: [PATCH] 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 --- csrc/parsergen.mdc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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"); -- 2.43.0