]> ocean-lang.org Git - ocean/commitdiff
parsergen: sort virtual symbols to send of list
authorNeilBrown <neil@brown.name>
Tue, 6 Oct 2020 07:11:15 +0000 (18:11 +1100)
committerNeilBrown <neil@brown.name>
Tue, 6 Oct 2020 07:11:15 +0000 (18:11 +1100)
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 <neil@brown.name>
csrc/parsergen.mdc

index 5bf413de01b0f8bf19a44375ae23f8b1f7086790..13b946fb0e992580c8c7b2d410a003415bb3eea3 100644 (file)
@@ -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");