Normalize loops to using `< nrules + 1', not `<= nrules'.
+2002-04-07 Akim Demaille <akim@epita.fr>
+
+ * src/closure.c, src/print.c, src/reader.c, src/reduce.c:
+ Normalize loops to using `< nrules + 1', not `<= nrules'.
+
+
2002-04-07 Akim Demaille <akim@epita.fr>
* TODO: Update.
2002-04-07 Akim Demaille <akim@epita.fr>
* TODO: Update.
for (i = ntokens; i < nsyms; i++)
{
fprintf (stderr, "\t%s derives\n", symbols[i]->tag);
for (i = ntokens; i < nsyms; i++)
{
fprintf (stderr, "\t%s derives\n", symbols[i]->tag);
- for (j = 0; j <= nrules; j++)
+ for (j = 0; j < nrules + 1; j++)
if (bitset_test (FDERIVES (i), j))
{
short *rhsp;
if (bitset_test (FDERIVES (i), j))
{
short *rhsp;
/* rule # : LHS -> RHS */
fprintf (out, "%s\n\n", _("Grammar"));
fprintf (out, " %s\n", _("Number, Line, Rule"));
/* rule # : LHS -> RHS */
fprintf (out, "%s\n\n", _("Grammar"));
fprintf (out, " %s\n", _("Number, Line, Rule"));
- for (i = 1; i <= nrules; i++)
+ for (i = 1; i < nrules + 1; i++)
/* Don't print rules disabled in reduce_grammar_tables. */
if (rules[i].useful)
{
/* Don't print rules disabled in reduce_grammar_tables. */
if (rules[i].useful)
{
/* TERMINAL (type #) : rule #s terminal is on RHS */
fprintf (out, "%s\n\n", _("Terminals, with rules where they appear"));
/* TERMINAL (type #) : rule #s terminal is on RHS */
fprintf (out, "%s\n\n", _("Terminals, with rules where they appear"));
- for (i = 0; i <= max_user_token_number; i++)
+ for (i = 0; i < max_user_token_number + 1; i++)
if (token_translations[i] != 2)
{
buffer[0] = 0;
if (token_translations[i] != 2)
{
buffer[0] = 0;
END_TEST (50);
sprintf (buffer, " (%d)", i);
END_TEST (50);
sprintf (buffer, " (%d)", i);
- for (j = 1; j <= nrules; j++)
+ for (j = 1; j < nrules + 1; j++)
for (rule = rules[j].rhs; *rule >= 0; rule++)
if (*rule == token_translations[i])
{
for (rule = rules[j].rhs; *rule >= 0; rule++)
if (*rule == token_translations[i])
{
fprintf (out, "%s\n\n", _("Nonterminals, with rules where they appear"));
fprintf (out, "%s\n\n", _("Nonterminals, with rules where they appear"));
- for (i = ntokens; i <= nsyms - 1; i++)
+ for (i = ntokens; i < nsyms; i++)
{
int left_count = 0, right_count = 0;
{
int left_count = 0, right_count = 0;
- for (j = 1; j <= nrules; j++)
+ for (j = 1; j < nrules + 1; j++)
{
if (rules[j].lhs == i)
left_count++;
{
if (rules[j].lhs == i)
left_count++;
END_TEST (50);
sprintf (buffer + strlen (buffer), _(" on left:"));
END_TEST (50);
sprintf (buffer + strlen (buffer), _(" on left:"));
- for (j = 1; j <= nrules; j++)
+ for (j = 1; j < nrules + 1; j++)
{
END_TEST (65);
if (rules[j].lhs == i)
{
END_TEST (65);
if (rules[j].lhs == i)
sprintf (buffer + strlen (buffer), ",");
END_TEST (50);
sprintf (buffer + strlen (buffer), _(" on right:"));
sprintf (buffer + strlen (buffer), ",");
END_TEST (50);
sprintf (buffer + strlen (buffer), _(" on right:"));
- for (j = 1; j <= nrules; j++)
+ for (j = 1; j < nrules + 1; j++)
{
for (rule = rules[j].rhs; *rule >= 0; rule++)
if (*rule == i)
{
for (rule = rules[j].rhs; *rule >= 0; rule++)
if (*rule == i)
/* Initialize all entries for literal tokens to 2, the internal
token number for $undefined., which represents all invalid
inputs. */
/* Initialize all entries for literal tokens to 2, the internal
token number for $undefined., which represents all invalid
inputs. */
- for (i = 0; i <= max_user_token_number; i++)
+ for (i = 0; i < max_user_token_number + 1; i++)
token_translations[i] = 2;
for (bp = firstsymbol; bp; bp = bp->next)
token_translations[i] = 2;
for (bp = firstsymbol; bp; bp = bp->next)
while (1)
{
bitset_copy (Np, N);
while (1)
{
bitset_copy (Np, N);
- for (i = 1; i <= nrules; i++)
+ for (i = 1; i < nrules + 1; i++)
if (!bitset_test (P, i)
&& useful_production (i, N))
{
if (!bitset_test (P, i)
&& useful_production (i, N))
{
while (1)
{
bitset_copy (Vp, V);
while (1)
{
bitset_copy (Vp, V);
- for (i = 1; i <= nrules; i++)
+ for (i = 1; i < nrules + 1; i++)
{
if (!bitset_test (Pp, i)
&& bitset_test (P, i)
{
if (!bitset_test (Pp, i)
&& bitset_test (P, i)
- for (pn = 1; pn <= nrules; pn++)
+ for (pn = 1; pn < nrules + 1; pn++)
if (bitset_test (P, pn))
{
np++;
if (bitset_test (P, pn))
{
np++;
if (nuseless_productions > 0)
{
int pn;
if (nuseless_productions > 0)
{
int pn;
- for (pn = 1; pn <= nrules; pn++)
+ for (pn = 1; pn < nrules + 1; pn++)
rules[pn].useful = bitset_test (P, pn);
}
}
rules[pn].useful = bitset_test (P, pn);
}
}
/* Replace all symbol numbers in valid data structures. */
/* Replace all symbol numbers in valid data structures. */
- for (i = 1; i <= nrules; i++)
+ for (i = 1; i < nrules + 1; i++)
{
rules[i].lhs = nontermmap[rules[i].lhs];
if (ISVAR (rules[i].precsym))
{
rules[i].lhs = nontermmap[rules[i].lhs];
if (ISVAR (rules[i].precsym))
{
int i;
fprintf (out, "%s\n\n", _("Useless rules:"));
{
int i;
fprintf (out, "%s\n\n", _("Useless rules:"));
- for (i = 1; i <= nrules; i++)
+ for (i = 1; i < nrules + 1; i++)
if (!rules[i].useful)
{
rule r;
if (!rules[i].useful)
{
rule r;
fprintf (out, "\n\n");
fprintf (out, "Rules\n-----\n\n");
fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\n");
fprintf (out, "\n\n");
fprintf (out, "Rules\n-----\n\n");
fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\n");
- for (i = 1; i <= nrules; i++)
+ for (i = 1; i < nrules + 1; i++)
{
int rhs_count = 0;
/* Find the last RHS index in ritems. */
{
int rhs_count = 0;
/* Find the last RHS index in ritems. */
}
fprintf (out, "\n\n");
fprintf (out, "Rules interpreted\n-----------------\n\n");
}
fprintf (out, "\n\n");
fprintf (out, "Rules interpreted\n-----------------\n\n");
- for (i = 1; i <= nrules; i++)
+ for (i = 1; i < nrules + 1; i++)
{
fprintf (out, "%-5d %s :", i, symbols[rules[i].lhs]->tag);
for (r = rules[i].rhs; *r >= 0; r++)
{
fprintf (out, "%-5d %s :", i, symbols[rules[i].lhs]->tag);
for (r = rules[i].rhs; *r >= 0; r++)