]> ocean-lang.org Git - ocean/commitdiff
parsergen: include virtual symbols in table of non-terminals
authorNeilBrown <neil@brown.name>
Sun, 9 Jun 2019 22:35:36 +0000 (08:35 +1000)
committerNeilBrown <neil@brown.name>
Sun, 9 Jun 2019 22:35:36 +0000 (08:35 +1000)
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 <neil@brown.name>
csrc/parsergen.mdc

index 478482e0f6b0512b9fc09946b4b1b5ead04fe7fd..d2ff89844d2e616e0f10e470c0a7dbffde9492a7 100644 (file)
@@ -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.
 ### 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
 
 
 ###### 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++)
                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");
                                fprintf(f, "\t\"%.*s\",\n", g->symtab[i]->name.len,
                                        g->symtab[i]->name.txt);
                fprintf(f, "};\n\n");