From: NeilBrown Date: Sun, 9 Jun 2019 22:35:36 +0000 (+1000) Subject: parsergen: include virtual symbols in table of non-terminals X-Git-Url: https://ocean-lang.org/code/?p=ocean;a=commitdiff_plain;h=5281589bf4d9a66ce106b160e1272f1c51d7ac15 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 --- 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");