+2001-11-19 Akim Demaille <akim@epita.fr>
+
+ * src/LR0.c (new_state, get_state): Complete TRACE code.
+ * src/closure.c: Include `reader.h' to get `tags', needed by the
+ trace code.
+ Rename the conditional DEBUG as TRACE.
+ Output consistently TRACEs to stderr, not stdout.
+ * src/derives.c: Likewise.
+ * src/reduce.c: (inaccessable_symbols): Using if is better style
+ than goto.
+ Use `#if TRACE' instead of `#if 0' for tracing code.
+
2001-11-19 Akim Demaille <akim@epita.fr>
* src/system.h (LIST_FREE, shortcpy): New.
core *p;
#if TRACE
- fprintf (stderr, "Entering new_state, symbol = %d, state = %d\n",
- symbol, nstates);
+ fprintf (stderr, "Entering new_state, state = %d, symbol = %d\n",
+ nstates, symbol);
#endif
if (nstates >= MAXSHORT)
int n;
#if TRACE
- fprintf (stderr, "Entering get_state, symbol = %d\n", symbol);
+ fprintf (stderr, "Entering get_state, state = %d, symbol = %d\n",
+ nstates, symbol);
#endif
isp1 = kernel_base[symbol];
/* Subroutines for bison
- Copyright 1984, 1989, 2000 Free Software Foundation, Inc.
+ Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
#include "system.h"
#include "gram.h"
+#include "reader.h"
#include "closure.h"
#include "derives.h"
#include "warshall.h"
/* number of words required to hold a bit for each variable */
static int varsetsize;
\f
-#if DEBUG
+#if TRACE
/*-----------------.
| Debugging code. |
{
short *isp;
- printf ("\n\nn = %d\n\n", n);
+ fprintf (stderr, "\n\nn = %d\n\n", n);
for (isp = itemset; isp < itemsetend; isp++)
- printf (" %d\n", *isp);
+ fprintf (stderr, " %d\n", *isp);
}
int j;
unsigned *rowp;
- printf ("\n\n\nFIRSTS\n\n");
+ fprintf (stderr, "\n\n\nFIRSTS\n\n");
for (i = ntokens; i < nsyms; i++)
{
- printf ("\n\n%s firsts\n\n", tags[i]);
+ fprintf (stderr, "\n\n%s firsts\n\n", tags[i]);
rowp = firsts + ((i - ntokens) * varsetsize);
for (j = 0; j < nvars; j++)
if (BITISSET (rowp, j))
- printf (" %s\n", tags[j + ntokens]);
+ fprintf (stderr, " %s\n", tags[j + ntokens]);
}
}
int j;
unsigned *rp;
- printf ("\n\n\nFDERIVES\n");
+ fprintf (stderr, "\n\n\nFDERIVES\n");
for (i = ntokens; i < nsyms; i++)
{
- printf ("\n\n%s derives\n\n", tags[i]);
+ fprintf (stderr, "\n\n%s derives\n\n", tags[i]);
rp = fderives + i * rulesetsize;
for (j = 0; j <= nrules; j++)
if (BITISSET (rp, j))
- printf (" %d\n", j);
+ fprintf (stderr, " %d\n", j);
}
-
- fflush (stdout);
}
#endif
\f
RTC (firsts, nvars);
-#ifdef DEBUG
+#ifdef TRACE
print_firsts ();
#endif
}
rrow += rulesetsize;
}
-#ifdef DEBUG
+#ifdef TRACE
print_fderives ();
#endif
while (csp < csend)
*itemsetend++ = *csp++;
-#if DEBUG
+#if TRACE
print_closure (n);
#endif
}
/* Match rules with nonterminals for bison,
- Copyright 1984, 1989, 2000 Free Software Foundation, Inc.
+ Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc.
This file is part of Bison, the GNU Compiler Compiler.
#include "system.h"
#include "types.h"
+#include "reader.h"
#include "gram.h"
#include "derives.h"
short **derives;
-#if DEBUG
+#if TRACE
static void
print_derives (void)
int i;
short *sp;
- fputs ("\n\n\n", stdout);
- printf (_("DERIVES"));
- fputs ("\n\n", stdout);
+ fputs ("\n\n\nDERIVES\n\n", stderr);
for (i = ntokens; i < nsyms; i++)
{
- printf (_("%s derives"), tags[i]);
+ fprintf (stderr, "%s derives", tags[i]);
for (sp = derives[i]; *sp > 0; sp++)
- {
- printf (" %d", *sp);
- }
- putchar ('\n');
+ fprintf (stderr, " %d", *sp);
+ putc ('\n', stderr);
}
- putchar ('\n');
+ putc ('\n', stderr);
}
#endif
*q++ = -1;
}
-#if DEBUG
+#if TRACE
print_derives ();
#endif
Pp = XCALLOC (unsigned, WORDSIZE (nrules + 1));
/* If the start symbol isn't useful, then nothing will be useful. */
- if (!BITISSET (N, start_symbol - ntokens))
- goto end_iteration;
-
- SETBIT (V, start_symbol);
-
- while (1)
+ if (BITISSET (N, start_symbol - ntokens))
{
- for (i = WORDSIZE (nsyms) - 1; i >= 0; i--)
- Vp[i] = V[i];
- for (i = 1; i <= nrules; i++)
+ SETBIT (V, start_symbol);
+
+ while (1)
{
- if (!BITISSET (Pp, i) && BITISSET (P, i) && BITISSET (V, rule_table[i].lhs))
+ for (i = WORDSIZE (nsyms) - 1; i >= 0; i--)
+ Vp[i] = V[i];
+ for (i = 1; i <= nrules; i++)
{
- for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
+ if (!BITISSET (Pp, i)
+ && BITISSET (P, i)
+ && BITISSET (V, rule_table[i].lhs))
{
- if (ISTOKEN (t = *r) || BITISSET (N, t - ntokens))
- {
+ for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
+ if (ISTOKEN (t = *r) || BITISSET (N, t - ntokens))
SETBIT (Vp, t);
- }
+ SETBIT (Pp, i);
}
- SETBIT (Pp, i);
}
+ if (bits_equal (V, Vp, WORDSIZE (nsyms)))
+ break;
+ Vs = Vp;
+ Vp = V;
+ V = Vs;
}
- if (bits_equal (V, Vp, WORDSIZE (nsyms)))
- {
- break;
- }
- Vs = Vp;
- Vp = V;
- V = Vs;
}
-end_iteration:
XFREE (V);
V = Vp;
fprintf (out, _("Useless rules:"));
fprintf (out, "\n\n");
for (i = 1; i <= nrules; i++)
- {
- if (!BITISSET (P, i))
- {
- fprintf (out, "#%-4d ", i);
- fprintf (out, "%s :\t", tags[rule_table[i].lhs]);
- for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
- fprintf (out, " %s", tags[*r]);
- fprintf (out, ";\n");
- }
- }
+ if (!BITISSET (P, i))
+ {
+ fprintf (out, "#%-4d ", i);
+ fprintf (out, "%s :\t", tags[rule_table[i].lhs]);
+ for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
+ fprintf (out, " %s", tags[*r]);
+ fprintf (out, ";\n");
+ }
}
if (nuseless_nonterminals > 0 || nuseless_productions > 0 || b)
fprintf (out, "\n\n");
}
\f
-#if 0 /* XXX currently unused. */
+#if TRACE
static void
dump_grammar (FILE *out)
{
int i;
rule r;
+ fprintf (out, "REDUCED GRAMMAR\n\n");
fprintf (out,
"ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n",
ntokens, nvars, nsyms, nrules, nitems);
tags[start_symbol]);
reduce_grammar_tables ();
-#if 0
- if (verbose_flag)
- {
- fprintf (out, "REDUCED GRAMMAR\n\n");
- dump_grammar ();
- }
+#if TRACE
+ dump_grammar (stderr);
#endif
if (statistics_flag)