+2001-12-27 Akim Demaille <akim@epita.fr>
+
+ Try to make the use of the eoftoken valid. Given that its value
+ is 0 which was also used as a sentinel in ritem, (i) make sure >= 0
+ is used instead of > 0 where appropriate, (ii), depend upon nritems
+ instead of the 0-sentinel.
+
+ * src/gram.h, src/gram.c (nritems): New.
+ Expected to be duplication of nitems, but for the time being...
+ * src/reader.c (packgram): Assert nritems and nitems are equal.
+ * src/LR0.c (allocate_itemsets, new_itemsets): Adjust.
+ * src/closure.c (print_closure, print_fderives): Likewise.
+ * src/gram.c (ritem_print): Likewise.
+ * src/print.c (print_core, print_grammar): Likewise.
+ * src/print_graph.c: Likewise.
+
2001-12-27 Akim Demaille <akim@epita.fr>
* src/main.c (main): If there are complains after grammar
int count = 0;
short *symbol_count = XCALLOC (short, nsyms + nuseless_nonterminals);
- for (i = 0; ritem[i]; ++i)
- if (ritem[i] > 0)
+ for (i = 0; i < nritems; ++i)
+ if (ritem[i] >= 0)
{
count++;
symbol_count[ritem[i]]++;
for (i = 0; i < nitemset; ++i)
{
int symbol = ritem[itemset[i]];
- if (symbol > 0)
+ if (symbol >= 0)
{
if (!kernel_size[symbol])
{
{
short *rp;
fprintf (stderr, " %2d: .", array[i]);
- for (rp = &ritem[array[i]]; *rp > 0; ++rp)
+ for (rp = &ritem[array[i]]; *rp >= 0; ++rp)
fprintf (stderr, " %s", tags[*rp]);
fprintf (stderr, " (rule %d)\n", -*rp);
}
{
short *rhsp;
fprintf (stderr, "\t\t%d:", j);
- for (rhsp = ritem + rule_table[j].rhs; *rhsp > 0; ++rhsp)
+ for (rhsp = ritem + rule_table[j].rhs; *rhsp >= 0; ++rhsp)
fprintf (stderr, " %s", tags[*rhsp]);
fputc ('\n', stderr);
}
int nvars;
short *ritem = NULL;
+int nritems;
+
rule_t *rule_table = NULL;
short *rprec = NULL;
short *rprecsym = NULL;
{
int i;
fputs ("RITEM\n", out);
- for (i = 0; ritem[i]; ++i)
- if (ritem[i] > 0)
+ for (i = 0; i < nritems; ++i)
+ if (ritem[i] >= 0)
fprintf (out, " %s", tags[ritem[i]]);
else
fprintf (out, " (rule %d)\n", -ritem[i]);
extern int nvars;
extern short *ritem;
+extern int nritems;
extern short *sprec;
extern short *sassoc;
yyrhs = XMALLOC (short, yyrhs_size);
for (sp = ritem + 1, i = 1; *sp; ++sp, ++i)
- yyrhs[i] = *sp > 0 ? *sp : 0;
+ yyrhs[i] = *sp >= 0 ? *sp : 0;
output_table_data (&format_obstack, yyrhs,
ritem[0], 1, yyrhs_size);
sp1 = sp = ritem + sitems[i];
- while (*sp > 0)
+ while (*sp >= 0)
sp++;
rule = -(*sp);
fputc ('.', out);
- for (/* Nothing */; *sp > 0; ++sp)
+ for (/* Nothing */; *sp >= 0; ++sp)
fprintf (out, " %s", escape (tags[*sp]));
fprintf (out, _(" (rule %d)"), rule);
fprintf (out, _(" %3d %3d %s ->"),
i, rule_table[i].line, escape (tags[rule_table[i].lhs]));
rule = &ritem[rule_table[i].rhs];
- if (*rule > 0)
- while (*rule > 0)
+ if (*rule >= 0)
+ while (*rule >= 0)
fprintf (out, " %s", escape (tags[*rule++]));
else
fprintf (out, " /* %s */", _("empty"));
sprintf (buffer, " (%d)", i);
for (j = 1; j <= nrules; j++)
- for (rule = &ritem[rule_table[j].rhs]; *rule > 0; rule++)
+ for (rule = &ritem[rule_table[j].rhs]; *rule >= 0; rule++)
if (*rule == token_translations[i])
{
END_TEST (65);
{
if (rule_table[j].lhs == i)
left_count++;
- for (rule = &ritem[rule_table[j].rhs]; *rule > 0; rule++)
+ for (rule = &ritem[rule_table[j].rhs]; *rule >= 0; rule++)
if (*rule == i)
{
right_count++;
sprintf (buffer + strlen (buffer), _(" on right:"));
for (j = 1; j <= nrules; j++)
{
- for (rule = &ritem[rule_table[j].rhs]; *rule > 0; rule++)
+ for (rule = &ritem[rule_table[j].rhs]; *rule >= 0; rule++)
if (*rule == i)
{
END_TEST (65);
sp1 = sp = ritem + sitems[i];
- while (*sp > 0)
+ while (*sp >= 0)
sp++;
rule = -(*sp);
obstack_1grow (node_obstack, '.');
- for (/* Nothing */; *sp > 0; ++sp)
+ for (/* Nothing */; *sp >= 0; ++sp)
obstack_fgrow1 (node_obstack, " %s", escape (tags[*sp]));
}
}
}
ritem[itemno] = 0;
+ nritems = itemno;
+ assert (nritems == nitems);
if (trace_flag)
ritem_print (stderr);