mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-15 23:33:03 +00:00
* 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.
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,3 +1,15 @@
|
|||||||
|
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>
|
2001-11-19 Akim Demaille <akim@epita.fr>
|
||||||
|
|
||||||
* src/system.h (LIST_FREE, shortcpy): New.
|
* src/system.h (LIST_FREE, shortcpy): New.
|
||||||
|
|||||||
@@ -198,8 +198,8 @@ new_state (int symbol)
|
|||||||
core *p;
|
core *p;
|
||||||
|
|
||||||
#if TRACE
|
#if TRACE
|
||||||
fprintf (stderr, "Entering new_state, symbol = %d, state = %d\n",
|
fprintf (stderr, "Entering new_state, state = %d, symbol = %d\n",
|
||||||
symbol, nstates);
|
nstates, symbol);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (nstates >= MAXSHORT)
|
if (nstates >= MAXSHORT)
|
||||||
@@ -242,7 +242,8 @@ get_state (int symbol)
|
|||||||
int n;
|
int n;
|
||||||
|
|
||||||
#if TRACE
|
#if TRACE
|
||||||
fprintf (stderr, "Entering get_state, symbol = %d\n", symbol);
|
fprintf (stderr, "Entering get_state, state = %d, symbol = %d\n",
|
||||||
|
nstates, symbol);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
isp1 = kernel_base[symbol];
|
isp1 = kernel_base[symbol];
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* Subroutines for bison
|
/* 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.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
|
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "gram.h"
|
#include "gram.h"
|
||||||
|
#include "reader.h"
|
||||||
#include "closure.h"
|
#include "closure.h"
|
||||||
#include "derives.h"
|
#include "derives.h"
|
||||||
#include "warshall.h"
|
#include "warshall.h"
|
||||||
@@ -38,7 +39,7 @@ static int rulesetsize;
|
|||||||
/* number of words required to hold a bit for each variable */
|
/* number of words required to hold a bit for each variable */
|
||||||
static int varsetsize;
|
static int varsetsize;
|
||||||
|
|
||||||
#if DEBUG
|
#if TRACE
|
||||||
|
|
||||||
/*-----------------.
|
/*-----------------.
|
||||||
| Debugging code. |
|
| Debugging code. |
|
||||||
@@ -49,9 +50,9 @@ print_closure (int n)
|
|||||||
{
|
{
|
||||||
short *isp;
|
short *isp;
|
||||||
|
|
||||||
printf ("\n\nn = %d\n\n", n);
|
fprintf (stderr, "\n\nn = %d\n\n", n);
|
||||||
for (isp = itemset; isp < itemsetend; isp++)
|
for (isp = itemset; isp < itemsetend; isp++)
|
||||||
printf (" %d\n", *isp);
|
fprintf (stderr, " %d\n", *isp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -62,17 +63,17 @@ print_firsts (void)
|
|||||||
int j;
|
int j;
|
||||||
unsigned *rowp;
|
unsigned *rowp;
|
||||||
|
|
||||||
printf ("\n\n\nFIRSTS\n\n");
|
fprintf (stderr, "\n\n\nFIRSTS\n\n");
|
||||||
|
|
||||||
for (i = ntokens; i < nsyms; i++)
|
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);
|
rowp = firsts + ((i - ntokens) * varsetsize);
|
||||||
|
|
||||||
for (j = 0; j < nvars; j++)
|
for (j = 0; j < nvars; j++)
|
||||||
if (BITISSET (rowp, j))
|
if (BITISSET (rowp, j))
|
||||||
printf (" %s\n", tags[j + ntokens]);
|
fprintf (stderr, " %s\n", tags[j + ntokens]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,19 +85,17 @@ print_fderives (void)
|
|||||||
int j;
|
int j;
|
||||||
unsigned *rp;
|
unsigned *rp;
|
||||||
|
|
||||||
printf ("\n\n\nFDERIVES\n");
|
fprintf (stderr, "\n\n\nFDERIVES\n");
|
||||||
|
|
||||||
for (i = ntokens; i < nsyms; i++)
|
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;
|
rp = fderives + i * rulesetsize;
|
||||||
|
|
||||||
for (j = 0; j <= nrules; j++)
|
for (j = 0; j <= nrules; j++)
|
||||||
if (BITISSET (rp, j))
|
if (BITISSET (rp, j))
|
||||||
printf (" %d\n", j);
|
fprintf (stderr, " %d\n", j);
|
||||||
}
|
}
|
||||||
|
|
||||||
fflush (stdout);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -143,7 +142,7 @@ set_firsts (void)
|
|||||||
|
|
||||||
RTC (firsts, nvars);
|
RTC (firsts, nvars);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef TRACE
|
||||||
print_firsts ();
|
print_firsts ();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -204,7 +203,7 @@ set_fderives (void)
|
|||||||
rrow += rulesetsize;
|
rrow += rulesetsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef TRACE
|
||||||
print_fderives ();
|
print_fderives ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -301,7 +300,7 @@ closure (short *core, int n)
|
|||||||
while (csp < csend)
|
while (csp < csend)
|
||||||
*itemsetend++ = *csp++;
|
*itemsetend++ = *csp++;
|
||||||
|
|
||||||
#if DEBUG
|
#if TRACE
|
||||||
print_closure (n);
|
print_closure (n);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/* Match rules with nonterminals for bison,
|
/* 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.
|
This file is part of Bison, the GNU Compiler Compiler.
|
||||||
|
|
||||||
@@ -26,12 +26,13 @@
|
|||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "reader.h"
|
||||||
#include "gram.h"
|
#include "gram.h"
|
||||||
#include "derives.h"
|
#include "derives.h"
|
||||||
|
|
||||||
short **derives;
|
short **derives;
|
||||||
|
|
||||||
#if DEBUG
|
#if TRACE
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_derives (void)
|
print_derives (void)
|
||||||
@@ -39,21 +40,17 @@ print_derives (void)
|
|||||||
int i;
|
int i;
|
||||||
short *sp;
|
short *sp;
|
||||||
|
|
||||||
fputs ("\n\n\n", stdout);
|
fputs ("\n\n\nDERIVES\n\n", stderr);
|
||||||
printf (_("DERIVES"));
|
|
||||||
fputs ("\n\n", stdout);
|
|
||||||
|
|
||||||
for (i = ntokens; i < nsyms; i++)
|
for (i = ntokens; i < nsyms; i++)
|
||||||
{
|
{
|
||||||
printf (_("%s derives"), tags[i]);
|
fprintf (stderr, "%s derives", tags[i]);
|
||||||
for (sp = derives[i]; *sp > 0; sp++)
|
for (sp = derives[i]; *sp > 0; sp++)
|
||||||
{
|
fprintf (stderr, " %d", *sp);
|
||||||
printf (" %d", *sp);
|
putc ('\n', stderr);
|
||||||
}
|
|
||||||
putchar ('\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
putchar ('\n');
|
putc ('\n', stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -99,7 +96,7 @@ set_derives (void)
|
|||||||
*q++ = -1;
|
*q++ = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if TRACE
|
||||||
print_derives ();
|
print_derives ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
70
src/reduce.c
70
src/reduce.c
@@ -200,38 +200,33 @@ inaccessable_symbols (void)
|
|||||||
Pp = XCALLOC (unsigned, WORDSIZE (nrules + 1));
|
Pp = XCALLOC (unsigned, WORDSIZE (nrules + 1));
|
||||||
|
|
||||||
/* If the start symbol isn't useful, then nothing will be useful. */
|
/* If the start symbol isn't useful, then nothing will be useful. */
|
||||||
if (!BITISSET (N, start_symbol - ntokens))
|
if (BITISSET (N, start_symbol - ntokens))
|
||||||
goto end_iteration;
|
|
||||||
|
|
||||||
SETBIT (V, start_symbol);
|
|
||||||
|
|
||||||
while (1)
|
|
||||||
{
|
{
|
||||||
for (i = WORDSIZE (nsyms) - 1; i >= 0; i--)
|
SETBIT (V, start_symbol);
|
||||||
Vp[i] = V[i];
|
|
||||||
for (i = 1; i <= nrules; i++)
|
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 (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);
|
XFREE (V);
|
||||||
V = Vp;
|
V = Vp;
|
||||||
@@ -430,28 +425,27 @@ reduce_output (FILE *out)
|
|||||||
fprintf (out, _("Useless rules:"));
|
fprintf (out, _("Useless rules:"));
|
||||||
fprintf (out, "\n\n");
|
fprintf (out, "\n\n");
|
||||||
for (i = 1; i <= nrules; i++)
|
for (i = 1; i <= nrules; i++)
|
||||||
{
|
if (!BITISSET (P, i))
|
||||||
if (!BITISSET (P, i))
|
{
|
||||||
{
|
fprintf (out, "#%-4d ", i);
|
||||||
fprintf (out, "#%-4d ", i);
|
fprintf (out, "%s :\t", tags[rule_table[i].lhs]);
|
||||||
fprintf (out, "%s :\t", tags[rule_table[i].lhs]);
|
for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
|
||||||
for (r = &ritem[rule_table[i].rhs]; *r >= 0; r++)
|
fprintf (out, " %s", tags[*r]);
|
||||||
fprintf (out, " %s", tags[*r]);
|
fprintf (out, ";\n");
|
||||||
fprintf (out, ";\n");
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (nuseless_nonterminals > 0 || nuseless_productions > 0 || b)
|
if (nuseless_nonterminals > 0 || nuseless_productions > 0 || b)
|
||||||
fprintf (out, "\n\n");
|
fprintf (out, "\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 /* XXX currently unused. */
|
#if TRACE
|
||||||
static void
|
static void
|
||||||
dump_grammar (FILE *out)
|
dump_grammar (FILE *out)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
rule r;
|
rule r;
|
||||||
|
|
||||||
|
fprintf (out, "REDUCED GRAMMAR\n\n");
|
||||||
fprintf (out,
|
fprintf (out,
|
||||||
"ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n",
|
"ntokens = %d, nvars = %d, nsyms = %d, nrules = %d, nitems = %d\n\n",
|
||||||
ntokens, nvars, nsyms, nrules, nitems);
|
ntokens, nvars, nsyms, nrules, nitems);
|
||||||
@@ -545,12 +539,8 @@ reduce_grammar (void)
|
|||||||
tags[start_symbol]);
|
tags[start_symbol]);
|
||||||
|
|
||||||
reduce_grammar_tables ();
|
reduce_grammar_tables ();
|
||||||
#if 0
|
#if TRACE
|
||||||
if (verbose_flag)
|
dump_grammar (stderr);
|
||||||
{
|
|
||||||
fprintf (out, "REDUCED GRAMMAR\n\n");
|
|
||||||
dump_grammar ();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (statistics_flag)
|
if (statistics_flag)
|
||||||
|
|||||||
Reference in New Issue
Block a user