From 4b3d3a8e4629cc3b0a6d011d80e1997f8306c304 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 25 Jul 2002 21:21:02 +0000 Subject: [PATCH] Stop storing rules from 1 to nrules + 1. * src/LR0.c, src/closure.c, src/derives.c, src/gram.c, src/lalr.c * src/nullable.c, src/output.c, src/print.c, src/reader.c * src/reduce.c: Allocate and free from &rules[0], not &rules[1]. Iterate from 0 to nrules. Use rule_number_as_item_number and item_number_as_rule_number. Adjust to `derive' now containing possibly 0. * src/gram.h (rule_number_as_item_number, item_number_as_rule_number): Handle the `- 1' part in rule numbers from/to item numbers. * src/conflicts.c (log_resolution): Fix the message which reversed shift and reduce. * src/output.c (action_row): Initialize default_rule to -1. (token_actions): Adjust. * tests/sets.at (Nullable, Firsts): Fix the previously bogus expected output. * tests/conflicts.at (Resolved SR Conflicts): Likewise. --- ChangeLog | 20 ++++++++++++++++++++ src/LR0.c | 8 ++++---- src/closure.c | 6 +++--- src/conflicts.c | 4 ++-- src/derives.c | 10 +++++----- src/gram.c | 18 +++++++++--------- src/gram.h | 6 +++--- src/lalr.c | 4 ++-- src/nullable.c | 4 ++-- src/output.c | 46 +++++++++++++++++++++++----------------------- src/print.c | 18 +++++++++--------- src/reader.c | 6 +++--- src/reduce.c | 38 +++++++++++++++++++------------------- tests/conflicts.at | 2 +- tests/sets.at | 40 ++++++++++++++++++++-------------------- 15 files changed, 125 insertions(+), 105 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2313d099..2f34da0b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2002-07-25 Akim Demaille + + Stop storing rules from 1 to nrules + 1. + + * src/LR0.c, src/closure.c, src/derives.c, src/gram.c, src/lalr.c + * src/nullable.c, src/output.c, src/print.c, src/reader.c + * src/reduce.c: Allocate and free from &rules[0], not &rules[1]. + Iterate from 0 to nrules. + Use rule_number_as_item_number and item_number_as_rule_number. + Adjust to `derive' now containing possibly 0. + * src/gram.h (rule_number_as_item_number, item_number_as_rule_number): + Handle the `- 1' part in rule numbers from/to item numbers. + * src/conflicts.c (log_resolution): Fix the message which reversed + shift and reduce. + * src/output.c (action_row): Initialize default_rule to -1. + (token_actions): Adjust. + * tests/sets.at (Nullable, Firsts): Fix the previously bogus + expected output. + * tests/conflicts.at (Resolved SR Conflicts): Likewise. + 2002-07-25 Akim Demaille * data/c.m4 (b4_c_function, b4_c_ansi_args, b4_c_ansi_arg) diff --git a/src/LR0.c b/src/LR0.c index a7a62e59..80f69a9e 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -105,7 +105,7 @@ allocate_itemsets (void) int count = 0; short *symbol_count = XCALLOC (short, nsyms + nuseless_nonterminals); - for (r = 1; r < nrules + 1; ++r) + for (r = 0; r < nrules; ++r) for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) { count++; @@ -140,7 +140,7 @@ allocate_storage (void) allocate_itemsets (); shiftset = XCALLOC (state_number_t, nsyms); - redset = XCALLOC (short, nrules + 1); + redset = XCALLOC (short, nrules); state_hash_new (); shift_symbol = XCALLOC (symbol_number_t, nsyms); } @@ -233,7 +233,7 @@ get_state (symbol_number_t symbol, size_t core_size, item_number_t *core) | Use the information computed by new_itemsets to find the state | | numbers reached by each shift transition from STATE. | | | -| TRANSITIONSET is set up as a vector of state numbers of those states. | +| SHIFTSET is set up as a vector of state numbers of those states. | `------------------------------------------------------------------*/ static void @@ -292,7 +292,7 @@ save_reductions (state_t *state) { int item = ritem[itemset[i]]; if (item < 0) - redset[count++] = -item; + redset[count++] = item_number_as_rule_number (item); } /* Make a reductions structure and copy the data into it. */ diff --git a/src/closure.c b/src/closure.c index 33dd9b7a..70ecab11 100644 --- a/src/closure.c +++ b/src/closure.c @@ -158,14 +158,14 @@ 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) + for (k = 0; derives[j][k] >= 0; ++k) bitset_set (FDERIVES (i), derives[j][k]); if (trace_flag) @@ -181,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 (); } diff --git a/src/conflicts.c b/src/conflicts.c index 825f7640..55468fd2 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -67,7 +67,7 @@ log_resolution (rule_t *rule, symbol_number_t token, switch (resolution) { case shift_resolution: - case left_resolution: + case right_resolution: obstack_fgrow2 (&solved_conflicts_obstack, _("\ Conflict between rule %d and token %s resolved as shift"), @@ -75,7 +75,7 @@ log_resolution (rule_t *rule, symbol_number_t token, symbols[token]->tag); break; case reduce_resolution: - case right_resolution: + case left_resolution: obstack_fgrow2 (&solved_conflicts_obstack, _("\ Conflict between rule %d and token %s resolved as reduce"), diff --git a/src/derives.c b/src/derives.c index 456dfb22..f88b7002 100644 --- a/src/derives.c +++ b/src/derives.c @@ -46,9 +46,9 @@ print_derives (void) { rule_number_t *rp; fprintf (stderr, "\t%s derives\n", symbols[i]->tag); - for (rp = derives[i]; *rp > 0; rp++) + for (rp = derives[i]; *rp >= 0; rp++) { - fprintf (stderr, "\t\t%3d ", *rp - 1); + fprintf (stderr, "\t\t%3d ", *rp); rule_rhs_print (&rules[*rp], stderr); } } @@ -61,7 +61,7 @@ void set_derives (void) { symbol_number_t i; - rule_number_t r; + int r; rule_number_t *q; /* DSET[NTERM] -- A linked list of the numbers of the rules whose @@ -71,9 +71,9 @@ set_derives (void) /* DELTS[RULE] -- There are NRULES rule number to attach to nterms. Instead of performing NRULES allocations for each, have an array indexed by rule numbers. */ - rule_list_t *delts = XCALLOC (rule_list_t, nrules + 1); + rule_list_t *delts = XCALLOC (rule_list_t, nrules); - for (r = nrules; r > 0; r--) + for (r = nrules - 1; r >= 0; --r) { symbol_number_t lhs = rules[r].lhs->number; rule_list_t *p = &delts[r]; diff --git a/src/gram.c b/src/gram.c index 51aa9484..c28f5b5e 100644 --- a/src/gram.c +++ b/src/gram.c @@ -56,7 +56,7 @@ int pure_parser = 0; void rule_lhs_print (rule_t *rule, symbol_t *previous_lhs, FILE *out) { - fprintf (out, " %3d ", rule->number - 1); + fprintf (out, " %3d ", rule->number); if (previous_lhs != rule->lhs) { fprintf (out, "%s:", rule->lhs->tag); @@ -132,7 +132,7 @@ ritem_print (FILE *out) if (ritem[i] >= 0) fprintf (out, " %s", symbols[ritem[i]]->tag); else - fprintf (out, " (rule %d)\n", -ritem[i] - 1); + fprintf (out, " (rule %d)\n", item_number_as_rule_number (ritem[i])); fputs ("\n\n", out); } @@ -147,7 +147,7 @@ ritem_longest_rhs (void) int max = 0; rule_number_t r; - for (r = 1; r < nrules + 1; ++r) + for (r = 0; r < nrules; ++r) { int length = rule_rhs_length (&rules[r]); if (length > max) @@ -191,7 +191,7 @@ grammar_rules_partial_print (FILE *out, const char *title, void grammar_rules_print (FILE *out) { - grammar_rules_partial_print (out, _("Grammar"), 1, nrules + 1); + grammar_rules_partial_print (out, _("Grammar"), 0, nrules); } @@ -225,7 +225,7 @@ grammar_dump (FILE *out, const char *title) { rule_number_t i; fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\n"); - for (i = 1; i < nrules + nuseless_productions + 1; i++) + for (i = 0; i < nrules + nuseless_productions; i++) { rule_t *rule = &rules[i]; item_number_t *r = NULL; @@ -234,7 +234,7 @@ grammar_dump (FILE *out, const char *title) for (r = rule->rhs; *r >= 0; ++r) ++rhs_count; fprintf (out, "%3d (%2d, %2d, %2d, %2d-%2d) %2d ->", - i - 1, + i, rule->prec ? rule->prec->prec : 0, rule->prec ? rule->prec->assoc : 0, rule->useful, @@ -244,7 +244,7 @@ grammar_dump (FILE *out, const char *title) /* Dumped the RHS. */ for (r = rule->rhs; *r >= 0; r++) fprintf (out, " %3d", *r); - fprintf (out, " [%d]\n", -(*r) - 1); + fprintf (out, " [%d]\n", item_number_as_rule_number (*r)); } } fprintf (out, "\n\n"); @@ -252,7 +252,7 @@ grammar_dump (FILE *out, const char *title) fprintf (out, "Rules interpreted\n-----------------\n\n"); { rule_number_t r; - for (r = 1; r < nrules + nuseless_productions + 1; r++) + for (r = 0; r < nrules + nuseless_productions; r++) { fprintf (out, "%-5d ", r); rule_print (&rules[r], out); @@ -266,7 +266,7 @@ void grammar_free (void) { XFREE (ritem); - free (rules + 1); + free (rules); XFREE (token_translations); /* Free the symbol table data structure. */ symbols_free (); diff --git a/src/gram.h b/src/gram.h index 36b19c1b..fc827ee4 100644 --- a/src/gram.h +++ b/src/gram.h @@ -120,7 +120,7 @@ extern unsigned int nritems; /* There is weird relationship between OT1H item_number_t and OTOH symbol_number_t and rule_number_t: we store the latter in item_number_t. symbol_number_t are stored as are, while - the negation of rule_number_t are stored. + the negation of (rule_number_t + 1) are stored. Therefore, an symbol_number_t must be a valid item_number_t, and we sometimes have to perform the converse transformation. */ @@ -134,8 +134,8 @@ typedef short rule_number_t; # define RULE_NUMBER_MAX ((rule_number_t) SHRT_MAX) extern rule_number_t nrules; # define int_of_rule_number(RNum) ((int) (RNum)) -# define rule_number_as_item_number(RNum) ((item_number_t) (- RNum)) -# define item_number_as_rule_number(INum) ((rule_number_t) (- INum)) +# define rule_number_as_item_number(RNum) ((item_number_t) (- RNum - 1)) +# define item_number_as_rule_number(INum) ((rule_number_t) (- INum - 1)) /*--------. diff --git a/src/lalr.c b/src/lalr.c index d07f19bb..6d4a431a 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -264,7 +264,7 @@ build_relations (void) symbol_number_t symbol1 = states[to_state[i]]->accessing_symbol; rule_number_t *rulep; - for (rulep = derives[symbol1]; *rulep > 0; rulep++) + for (rulep = derives[symbol1]; *rulep >= 0; rulep++) { int done; int length = 1; @@ -438,7 +438,7 @@ lookaheads_print (FILE *out) { fprintf (out, " on %d (%s) -> rule %d\n", k, symbols[k]->tag, - states[i]->lookaheads_rule[j]->number - 1); + states[i]->lookaheads_rule[j]->number); }; } fprintf (out, "Lookaheads: END\n"); diff --git a/src/nullable.c b/src/nullable.c index c8b0b7d6..6a70fa57 100644 --- a/src/nullable.c +++ b/src/nullable.c @@ -58,7 +58,7 @@ set_nullable (void) rule_list_t *p; symbol_number_t *squeue = XCALLOC (symbol_number_t, nvars); - short *rcount = XCALLOC (short, nrules + 1); + short *rcount = XCALLOC (short, nrules); /* RITEM contains all the rules, including useless productions. Hence we must allocate room for useless nonterminals too. */ rule_list_t **rsets = XCALLOC (rule_list_t *, nvars) - ntokens; @@ -74,7 +74,7 @@ set_nullable (void) s1 = s2 = squeue; p = relts; - for (ruleno = 1; ruleno < nrules + 1; ++ruleno) + for (ruleno = 0; ruleno < nrules; ++ruleno) if (rules[ruleno].useful) { rule_t *rule = &rules[ruleno]; diff --git a/src/output.c b/src/output.c index 735ef33a..127950f2 100644 --- a/src/output.c +++ b/src/output.c @@ -365,14 +365,14 @@ prepare_rules (void) rule_number_t r; unsigned int i = 0; item_number_t *rhs = XMALLOC (item_number_t, nritems); - unsigned int *prhs = XMALLOC (unsigned int, nrules + 1); - unsigned int *rline = XMALLOC (unsigned int, nrules + 1); - symbol_number_t *r1 = XMALLOC (symbol_number_t, nrules + 1); - unsigned int *r2 = XMALLOC (unsigned int, nrules + 1); - short *dprec = XMALLOC (short, nrules + 1); - short *merger = XMALLOC (short, nrules + 1); - - for (r = 1; r < nrules + 1; ++r) + unsigned int *prhs = XMALLOC (unsigned int, nrules); + unsigned int *rline = XMALLOC (unsigned int, nrules); + symbol_number_t *r1 = XMALLOC (symbol_number_t, nrules); + unsigned int *r2 = XMALLOC (unsigned int, nrules); + short *dprec = XMALLOC (short, nrules); + short *merger = XMALLOC (short, nrules); + + for (r = 0; r < nrules; ++r) { item_number_t *rhsp = NULL; /* Index of rule R in RHS. */ @@ -396,12 +396,12 @@ prepare_rules (void) assert (i == nritems); muscle_insert_item_number_table ("rhs", rhs, ritem[0], 1, nritems); - muscle_insert_unsigned_int_table ("prhs", prhs, 0, 1, nrules + 1); - muscle_insert_unsigned_int_table ("rline", rline, 0, 1, nrules + 1); - muscle_insert_symbol_number_table ("r1", r1, 0, 1, nrules + 1); - muscle_insert_unsigned_int_table ("r2", r2, 0, 1, nrules + 1); - muscle_insert_short_table ("dprec", dprec, 0, 1, nrules + 1); - muscle_insert_short_table ("merger", merger, 0, 1, nrules + 1); + muscle_insert_unsigned_int_table ("prhs", prhs, 0, 0, nrules); + muscle_insert_unsigned_int_table ("rline", rline, 0, 0, nrules); + muscle_insert_symbol_number_table ("r1", r1, 0, 0, nrules); + muscle_insert_unsigned_int_table ("r2", r2, 0, 0, nrules); + muscle_insert_short_table ("dprec", dprec, 0, 0, nrules); + muscle_insert_short_table ("merger", merger, 0, 0, nrules); free (rhs); free (prhs); @@ -434,8 +434,8 @@ prepare_states (void) | by non-zero entries in CONFLROW, create a list of possible | | reductions that are alternatives to the shift or reduction | | currently recorded for that token in STATE. Store the alternative | -| reductions followed by a 0 in conflict_list, updating | -| conflict_list_cnt, and storing an index to the start of the list | +| reductions followed by a 0 in CONFLICT_LIST, updating | +| CONFLICT_LIST_CNT, and storing an index to the start of the list | | back into CONFLROW. | `-------------------------------------------------------------------*/ @@ -461,7 +461,7 @@ conflict_row (state_t *state) { assert (conflict_list_free > 0); conflict_list[conflict_list_cnt] - = state->lookaheads_rule[i]->number; + = state->lookaheads_rule[i]->number + 1; conflict_list_cnt += 1; conflict_list_free -= 1; } @@ -488,7 +488,7 @@ conflict_row (state_t *state) | considered that likes a token gets to handle it. | | | | For GLR parsers, also sets CONFLROW[SYM] to an index into | -| conflict_list iff there is an unresolved conflict (s/r or r/r) | +| CONFLICT_LIST iff there is an unresolved conflict (s/r or r/r) | | with symbol SYM. The default reduction is not used for a symbol | | that has any such conflicts. | `------------------------------------------------------------------*/ @@ -497,7 +497,7 @@ static rule_number_t action_row (state_t *state) { int i; - rule_number_t default_rule = 0; + rule_number_t default_rule = -1; reductions_t *redp = state->reductions; transitions_t *transitions = state->transitions; errs_t *errp = state->errs; @@ -601,7 +601,7 @@ action_row (state_t *state) /* If have no default rule, the default is an error. So replace any action which says "error" with "use default". */ - if (default_rule == 0) + if (default_rule == -1) for (i = 0; i < ntokens; i++) if (actrow[i] == ACTION_MIN) actrow[i] = 0; @@ -689,7 +689,7 @@ token_actions (void) for (i = 0; i < nstates; ++i) { - yydefact[i] = action_row (states[i]); + yydefact[i] = action_row (states[i]) + 1; save_row (i); } @@ -711,10 +711,10 @@ actions_output (FILE *out) rule_number_t r; fputs ("m4_define([b4_actions], \n[[", out); - for (r = 1; r < nrules + 1; ++r) + for (r = 0; r < nrules; ++r) if (rules[r].action) { - fprintf (out, " case %d:\n", r); + fprintf (out, " case %d:\n", r + 1); if (!no_lines_flag) fprintf (out, muscle_find ("linef"), diff --git a/src/print.c b/src/print.c index 7adb51b0..67490875 100644 --- a/src/print.c +++ b/src/print.c @@ -97,7 +97,7 @@ print_core (FILE *out, state_t *state) while (*sp >= 0) sp++; - rule = -(*sp); + rule = item_number_as_rule_number (*sp); rule_lhs_print (&rules[rule], previous_lhs, out); previous_lhs = rules[rule].lhs; @@ -288,7 +288,7 @@ print_reduction (FILE *out, size_t width, if (!enabled) fputc ('[', out); fprintf (out, _("reduce using rule %d (%s)"), - rule->number - 1, rule->lhs->tag); + rule->number, rule->lhs->tag); if (!enabled) fputc (']', out); fputc ('\n', out); @@ -473,12 +473,12 @@ print_grammar (FILE *out) END_TEST (50); sprintf (buffer, " (%d)", i); - for (r = 1; r < nrules + 1; r++) + for (r = 0; r < nrules; r++) for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) if (item_number_as_symbol_number (*rhsp) == token_translations[i]) { END_TEST (65); - sprintf (buffer + strlen (buffer), " %d", r - 1); + sprintf (buffer + strlen (buffer), " %d", r); break; } fprintf (out, "%s\n", buffer); @@ -493,7 +493,7 @@ print_grammar (FILE *out) rule_number_t r; const char *tag = symbols[i]->tag; - for (r = 1; r < nrules + 1; r++) + for (r = 0; r < nrules; r++) { item_number_t *rhsp; if (rules[r].lhs->number == i) @@ -517,11 +517,11 @@ print_grammar (FILE *out) END_TEST (50); sprintf (buffer + strlen (buffer), _(" on left:")); - for (r = 1; r < nrules + 1; r++) + for (r = 0; r < nrules; r++) { END_TEST (65); if (rules[r].lhs->number == i) - sprintf (buffer + strlen (buffer), " %d", r - 1); + sprintf (buffer + strlen (buffer), " %d", r); } } @@ -531,14 +531,14 @@ print_grammar (FILE *out) sprintf (buffer + strlen (buffer), ","); END_TEST (50); sprintf (buffer + strlen (buffer), _(" on right:")); - for (r = 1; r < nrules + 1; r++) + for (r = 0; r < nrules; r++) { item_number_t *rhsp; for (rhsp = rules[r].rhs; *rhsp >= 0; rhsp++) if (item_number_as_symbol_number (*rhsp) == i) { END_TEST (65); - sprintf (buffer + strlen (buffer), " %d", r - 1); + sprintf (buffer + strlen (buffer), " %d", r); break; } } diff --git a/src/reader.c b/src/reader.c index 86f3adf4..a029b671 100644 --- a/src/reader.c +++ b/src/reader.c @@ -406,11 +406,11 @@ static void packgram (void) { unsigned int itemno = 0; - rule_number_t ruleno = 1; + rule_number_t ruleno = 0; symbol_list_t *p = grammar; ritem = XCALLOC (item_number_t, nritems); - rules = XCALLOC (rule_t, nrules) - 1; + rules = XCALLOC (rule_t, nrules); while (p) { @@ -447,7 +447,7 @@ packgram (void) rules[ruleno].precsym = ruleprec; rules[ruleno].prec = ruleprec; } - ritem[itemno++] = -ruleno; + ritem[itemno++] = rule_number_as_item_number (ruleno); ++ruleno; if (p) diff --git a/src/reduce.c b/src/reduce.c index fb975972..154e63bf 100644 --- a/src/reduce.c +++ b/src/reduce.c @@ -111,7 +111,7 @@ useless_nonterminals (void) while (1) { bitset_copy (Np, N); - for (r = 1; r < nrules + 1; r++) + for (r = 0; r < nrules; r++) if (!bitset_test (P, r) && useful_production (r, N)) { @@ -158,7 +158,7 @@ inaccessable_symbols (void) user can know. */ Vp = bitset_create (nsyms, BITSET_FIXED); - Pp = bitset_create (nrules + 1, BITSET_FIXED); + Pp = bitset_create (nrules, BITSET_FIXED); /* If the start symbol isn't useful, then nothing will be useful. */ if (bitset_test (N, axiom->number - ntokens)) @@ -169,7 +169,7 @@ inaccessable_symbols (void) { rule_number_t r; bitset_copy (Vp, V); - for (r = 1; r < nrules + 1; r++) + for (r = 0; r < nrules; r++) { if (!bitset_test (Pp, r) && bitset_test (P, r) @@ -215,10 +215,10 @@ inaccessable_symbols (void) /* A token that was used in %prec should not be warned about. */ { - rule_number_t i; - for (i = 1; i < nrules + 1; i++) - if (rules[i].precsym != 0) - bitset_set (V1, rules[i].precsym->number); + rule_number_t r; + for (r = 0; r < nrules; ++r) + if (rules[r].precsym != 0) + bitset_set (V1, rules[r].precsym->number); } } @@ -234,7 +234,7 @@ reduce_grammar_tables (void) /* Report and flag useless productions. */ { rule_number_t r; - for (r = 1; r < nrules + 1; r++) + for (r = 0; r < nrules; r++) { rules[r].useful = bitset_test (P, r); if (!rules[r].useful) @@ -249,17 +249,17 @@ reduce_grammar_tables (void) /* Map the nonterminals to their new index: useful first, useless afterwards. Kept for later report. */ { - int useful = 1; - int useless = nrules + 1 - nuseless_productions; - rule_t *rules_sorted = XMALLOC (rule_t, nrules + 1) - 1; + int useful = 0; + int useless = nrules - nuseless_productions; + rule_t *rules_sorted = XMALLOC (rule_t, nrules); rule_number_t r; - for (r = 1; r < nrules + 1; ++r) + for (r = 0; r < nrules; ++r) rules_sorted[rules[r].useful ? useful++ : useless++] = rules[r]; - free (rules + 1); + free (rules); rules = rules_sorted; /* Renumber the rules markers in RITEMS. */ - for (r = 1; r < nrules + 1; ++r) + for (r = 0; r < nrules; ++r) { item_number_t *rhsp = rules[r].rhs; for (/* Nothing. */; *rhsp >= 0; ++rhsp) @@ -274,7 +274,7 @@ reduce_grammar_tables (void) { int r; int length; - for (r = nrules + 1; r < nrules + 1 + nuseless_productions; ++r) + for (r = nrules; r < nrules + nuseless_productions; ++r) { length = rule_rhs_length (&rules[r]); nritems -= length + 1; @@ -326,7 +326,7 @@ nonterminals_reduce (void) { rule_number_t r; - for (r = 1; r < nrules + 1; ++r) + for (r = 0; r < nrules; ++r) { item_number_t *rhsp; for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp) @@ -376,8 +376,8 @@ reduce_output (FILE *out) if (nuseless_productions > 0) grammar_rules_partial_print (out, _("Useless rules"), - nrules + 1, - nuseless_productions + nrules + 1); + nrules, + nrules + nuseless_productions); } @@ -425,7 +425,7 @@ reduce_grammar (void) /* Allocate the global sets used to compute the reduced grammar */ N = bitset_create (nvars, BITSET_FIXED); - P = bitset_create (nrules + 1, BITSET_FIXED); + P = bitset_create (nrules, BITSET_FIXED); V = bitset_create (nsyms, BITSET_FIXED); V1 = bitset_create (nsyms, BITSET_FIXED); diff --git a/tests/conflicts.at b/tests/conflicts.at index 46940149..43b37dfc 100644 --- a/tests/conflicts.at +++ b/tests/conflicts.at @@ -326,7 +326,7 @@ state 5 1 | exp OP exp . [$, OP] $default reduce using rule 1 (exp) - Conflict between rule 2 and token OP resolved as shift (%left OP). + Conflict between rule 1 and token OP resolved as reduce (%left OP). ]]) AT_CLEANUP diff --git a/tests/sets.at b/tests/sets.at index e1cf3ff6..28c58249 100644 --- a/tests/sets.at +++ b/tests/sets.at @@ -98,12 +98,12 @@ FIRSTS e FDERIVES $axiom derives - 1 e $ - 2 'e' - 3 /* empty */ + 0 e $ + 1 'e' + 2 /* empty */ e derives - 2 'e' - 3 /* empty */ + 1 'e' + 2 /* empty */ ]]) AT_CLEANUP @@ -233,22 +233,22 @@ FIRSTS exp FDERIVES $axiom derives - 1 exp $ - 2 exp '<' exp - 3 exp '>' exp - 4 exp '+' exp - 5 exp '-' exp - 6 exp '^' exp - 7 exp '=' exp - 8 "exp" + 0 exp $ + 1 exp '<' exp + 2 exp '>' exp + 3 exp '+' exp + 4 exp '-' exp + 5 exp '^' exp + 6 exp '=' exp + 7 "exp" exp derives - 2 exp '<' exp - 3 exp '>' exp - 4 exp '+' exp - 5 exp '-' exp - 6 exp '^' exp - 7 exp '=' exp - 8 "exp" + 1 exp '<' exp + 2 exp '>' exp + 3 exp '+' exp + 4 exp '-' exp + 5 exp '^' exp + 6 exp '=' exp + 7 "exp" ]]) AT_CLEANUP -- 2.45.2