X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/613f5e1a895b0742c9b6c5e9461e4cf3f7389d7e..f377f69fec28013c79db4efe12bbb9d48987fb2c:/src/closure.c?ds=sidebyside diff --git a/src/closure.c b/src/closure.c index 02d275a7..3d5ac28d 100644 --- a/src/closure.c +++ b/src/closure.c @@ -99,11 +99,8 @@ print_fderives (void) fprintf (stderr, "\t%s derives\n", symbols[i]->tag); BITSET_FOR_EACH (iter, FDERIVES (i), r, 0) { - item_number_t *rhsp = NULL; - fprintf (stderr, "\t\t%d:", r - 1); - for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) - fprintf (stderr, " %s", symbols[*rhsp]->tag); - fputc ('\n', stderr); + fprintf (stderr, "\t\t%3d ", r); + rule_rhs_print (&rules[r], stderr); } } fprintf (stderr, "\n\n"); @@ -128,20 +125,20 @@ set_firsts (void) firsts = bitsetv_create (nvars, nvars, BITSET_FIXED); for (i = ntokens; i < nsyms; i++) - for (j = 0; derives[i][j] >= 0; ++j) + for (j = 0; derives[i][j]; ++j) { - int symbol = rules[derives[i][j]].rhs[0]; + int symbol = derives[i][j]->rhs[0]; if (ISVAR (symbol)) bitset_set (FIRSTS (i), symbol - ntokens); } - if (trace_flag) + if (trace_flag & trace_sets) bitsetv_matrix_dump (stderr, "RTC: Firsts Input", firsts); bitsetv_reflexive_transitive_closure (firsts); - if (trace_flag) + if (trace_flag & trace_sets) bitsetv_matrix_dump (stderr, "RTC: Firsts Output", firsts); - if (trace_flag) + if (trace_flag & trace_sets) print_firsts (); } @@ -161,17 +158,17 @@ set_fderives (void) symbol_number_t i, j; rule_number_t k; - fderives = bitsetv_create (nvars, nrules + 1, BITSET_FIXED); + fderives = bitsetv_create (nvars, nrules, BITSET_FIXED); set_firsts (); for (i = ntokens; i < nsyms; ++i) for (j = ntokens; j < nsyms; ++j) if (bitset_test (FIRSTS (i), j - ntokens)) - for (k = 0; derives[j][k] > 0; ++k) - bitset_set (FDERIVES (i), derives[j][k]); + for (k = 0; derives[j][k]; ++k) + bitset_set (FDERIVES (i), derives[j][k]->number); - if (trace_flag) + if (trace_flag & trace_sets) print_fderives (); bitsetv_free (firsts); @@ -184,7 +181,7 @@ new_closure (int n) { itemset = XCALLOC (item_number_t, n); - ruleset = bitset_create (nrules + 1, BITSET_FIXED); + ruleset = bitset_create (nrules, BITSET_FIXED); set_fderives (); } @@ -202,7 +199,7 @@ closure (item_number_t *core, int n) bitset_iterator iter; - if (trace_flag) + if (trace_flag & trace_sets) print_closure ("input", core, n); bitset_zero (ruleset); @@ -233,7 +230,7 @@ closure (item_number_t *core, int n) c++; } - if (trace_flag) + if (trace_flag & trace_sets) print_closure ("output", itemset, nritemset); }