X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/9bfe901c33190b9726bddabf8f192ad0c3a25500..43168960182a2537605d6a1262a39e4e43c57d98:/src/derives.c diff --git a/src/derives.c b/src/derives.c index 7b862d82..ab7cc326 100644 --- a/src/derives.c +++ b/src/derives.c @@ -19,11 +19,6 @@ Boston, MA 02111-1307, USA. */ -/* set_derives finds, for each variable (nonterminal), which rules can - derive it. It sets up the value of derives so that derives[i - - ntokens] points to a vector of rule numbers, terminated with -1. - */ - #include "system.h" #include "getargs.h" #include "types.h" @@ -31,26 +26,30 @@ #include "gram.h" #include "derives.h" -short **derives; - +short **derives = NULL; static void print_derives (void) { int i; - short *sp; - fputs ("\n\n\nDERIVES\n\n", stderr); + fputs ("DERIVES\n", stderr); for (i = ntokens; i < nsyms; i++) { - fprintf (stderr, "%s derives", tags[i]); + short *sp; + fprintf (stderr, "\t%s derives\n", tags[i]); for (sp = derives[i]; *sp > 0; sp++) - fprintf (stderr, " %d", *sp); - putc ('\n', stderr); + { + short *rhsp; + fprintf (stderr, "\t\t%d:", *sp); + for (rhsp = ritem + rule_table[*sp].rhs; *rhsp > 0; ++rhsp) + fprintf (stderr, " %s", tags[*rhsp]); + fprintf (stderr, " (rule %d)\n", -*rhsp); + } } - putc ('\n', stderr); + fputs ("\n\n", stderr); } @@ -58,7 +57,6 @@ void set_derives (void) { int i; - int lhs; shorts *p; short *q; shorts **dset; @@ -69,16 +67,14 @@ set_derives (void) p = delts; for (i = nrules; i > 0; i--) - { - lhs = rule_table[i].lhs; - if (lhs >= 0) - { - p->next = dset[lhs]; - p->value = i; - dset[lhs] = p; - p++; - } - } + if (rule_table[i].useful) + { + int lhs = rule_table[i].lhs; + p->next = dset[lhs]; + p->value = i; + dset[lhs] = p; + p++; + } derives = XCALLOC (short *, nvars) - ntokens; q = XCALLOC (short, nvars + nrules);