From 5281589bf4d9a66ce106b160e1272f1c51d7ac15 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 10 Jun 2019 08:35:36 +1000 Subject: [PATCH] parsergen: include virtual symbols in table of non-terminals Symbol numbers assigned in grammar_analyse are in three groups: - predefined (NUMBER, STRING, etc) - Terminals - everything else: non-terminals and virtual. When creating the non_term[] list of names, we need to include virtual symbols in there, otherwise lookup by symbol-number might find the wrong value - or might reach beyond end of array. Signed-off-by: NeilBrown --- csrc/parsergen.mdc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/csrc/parsergen.mdc b/csrc/parsergen.mdc index 478482e..d2ff898 100644 --- a/csrc/parsergen.mdc +++ b/csrc/parsergen.mdc @@ -1900,7 +1900,9 @@ pieces of code provided in the grammar file, so they are generated first. ### Known words table The known words table is simply an array of terminal symbols. -The table of nonterminals used for tracing is a similar array. +The table of nonterminals used for tracing is a similar array. We +include virtual symbols in the table of non_terminals to keep the +numbers right. ###### functions @@ -1925,7 +1927,7 @@ The table of nonterminals used for tracing is a similar array. for (i = TK_reserved; i < g->num_syms; i++) - if (g->symtab[i]->type == Nonterminal) + if (g->symtab[i]->type != Terminal) fprintf(f, "\t\"%.*s\",\n", g->symtab[i]->name.len, g->symtab[i]->name.txt); fprintf(f, "};\n\n"); -- 2.43.0