mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
* src/lalr.c, src/LR0.c, src/closure.c, src/gram.c, src/reduce.c:
Properly escape the symbols' TAG when outputting them.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
2002-04-07 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* src/lalr.c, src/LR0.c, src/closure.c, src/gram.c, src/reduce.c:
|
||||
Properly escape the symbols' TAG when outputting them.
|
||||
|
||||
2002-04-07 Akim Demaille <akim@epita.fr>
|
||||
|
||||
* src/lalr.h (LA): Is a bitsetv, not bitset*.
|
||||
|
||||
10
src/LR0.c
10
src/LR0.c
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "system.h"
|
||||
#include "bitset.h"
|
||||
#include "quotearg.h"
|
||||
#include "symtab.h"
|
||||
#include "getargs.h"
|
||||
#include "reader.h"
|
||||
@@ -190,7 +191,8 @@ new_state (int symbol)
|
||||
|
||||
if (trace_flag)
|
||||
fprintf (stderr, "Entering new_state, state = %d, symbol = %d (%s)\n",
|
||||
nstates, symbol, symbols[symbol]->tag);
|
||||
nstates, symbol, quotearg_style (escape_quoting_style,
|
||||
symbols[symbol]->tag));
|
||||
|
||||
if (nstates >= MAXSHORT)
|
||||
fatal (_("too many states (max %d)"), MAXSHORT);
|
||||
@@ -234,7 +236,8 @@ get_state (int symbol)
|
||||
|
||||
if (trace_flag)
|
||||
fprintf (stderr, "Entering get_state, state = %d, symbol = %d (%s)\n",
|
||||
this_state->number, symbol, symbols[symbol]->tag);
|
||||
this_state->number, symbol, quotearg_style (escape_quoting_style,
|
||||
symbols[symbol]->tag));
|
||||
|
||||
/* Add up the target state's active item numbers to get a hash key.
|
||||
*/
|
||||
@@ -416,7 +419,8 @@ generate_states (void)
|
||||
if (trace_flag)
|
||||
fprintf (stderr, "Processing state %d (reached by %s)\n",
|
||||
this_state->number,
|
||||
symbols[this_state->accessing_symbol]->tag);
|
||||
quotearg_style (escape_quoting_style,
|
||||
symbols[this_state->accessing_symbol]->tag));
|
||||
/* Set up ruleset and itemset for the transitions out of this
|
||||
state. ruleset gets a 1 bit for each rule that could reduce
|
||||
now. itemset gets a vector of all the items that could be
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
02111-1307, USA. */
|
||||
|
||||
#include "system.h"
|
||||
#include "quotearg.h"
|
||||
#include "bitset.h"
|
||||
#include "bitsetv.h"
|
||||
#include "getargs.h"
|
||||
@@ -57,7 +58,8 @@ print_closure (const char *title, short *array, size_t size)
|
||||
short *rp;
|
||||
fprintf (stderr, " %2d: .", array[i]);
|
||||
for (rp = &ritem[array[i]]; *rp >= 0; ++rp)
|
||||
fprintf (stderr, " %s", symbols[*rp]->tag);
|
||||
fprintf (stderr, " %s",
|
||||
quotearg_style (escape_quoting_style, symbols[*rp]->tag));
|
||||
fprintf (stderr, " (rule %d)\n", -*rp - 1);
|
||||
}
|
||||
fputs ("\n\n", stderr);
|
||||
@@ -72,11 +74,14 @@ print_firsts (void)
|
||||
fprintf (stderr, "FIRSTS\n");
|
||||
for (i = ntokens; i < nsyms; i++)
|
||||
{
|
||||
fprintf (stderr, "\t%s firsts\n", symbols[i]->tag);
|
||||
fprintf (stderr, "\t%s firsts\n",
|
||||
quotearg_style (escape_quoting_style, symbols[i]->tag));
|
||||
for (j = 0; j < nvars; j++)
|
||||
if (bitset_test (FIRSTS (i), j))
|
||||
fprintf (stderr, "\t\t%d (%s)\n",
|
||||
j + ntokens, symbols[j + ntokens]->tag);
|
||||
j + ntokens,
|
||||
quotearg_style (escape_quoting_style,
|
||||
symbols[j + ntokens]->tag));
|
||||
}
|
||||
fprintf (stderr, "\n\n");
|
||||
}
|
||||
@@ -90,14 +95,17 @@ print_fderives (void)
|
||||
fprintf (stderr, "FDERIVES\n");
|
||||
for (i = ntokens; i < nsyms; i++)
|
||||
{
|
||||
fprintf (stderr, "\t%s derives\n", symbols[i]->tag);
|
||||
fprintf (stderr, "\t%s derives\n",
|
||||
quotearg_style (escape_quoting_style, symbols[i]->tag));
|
||||
for (j = 0; j < nrules + 1; j++)
|
||||
if (bitset_test (FDERIVES (i), j))
|
||||
{
|
||||
short *rhsp;
|
||||
fprintf (stderr, "\t\t%d:", j - 1);
|
||||
for (rhsp = rules[j].rhs; *rhsp >= 0; ++rhsp)
|
||||
fprintf (stderr, " %s", symbols[*rhsp]->tag);
|
||||
fprintf (stderr, " %s",
|
||||
quotearg_style (escape_quoting_style,
|
||||
symbols[*rhsp]->tag));
|
||||
fputc ('\n', stderr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Subroutines for bison
|
||||
Copyright 1984, 1989, 2000, 2001 Free Software Foundation, Inc.
|
||||
Copyright (C) 1984, 1989, 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
#ifndef CLOSURE_H_
|
||||
# define CLOSURE_H_
|
||||
|
||||
/* Subroutines of file LR0.c. */
|
||||
|
||||
/* Allocates the itemset and ruleset vectors, and precomputes useful
|
||||
data so that closure can be called. n is the number of elements to
|
||||
allocate for itemset. */
|
||||
@@ -31,23 +29,23 @@ void new_closure PARAMS ((int n));
|
||||
|
||||
|
||||
/* Given the kernel (aka core) of a state (a vector of item numbers
|
||||
ITEMS, of length N), set up ruleset and itemset to indicate what
|
||||
ITEMS, of length N), set up RULESET and ITEMSET to indicate what
|
||||
rules could be run and which items could be accepted when those
|
||||
items are the active ones.
|
||||
|
||||
ruleset contains a bit for each rule. closure sets the bits for
|
||||
RULESET contains a bit for each rule. CLOSURE sets the bits for
|
||||
all rules which could potentially describe the next input to be
|
||||
read.
|
||||
|
||||
ITEMSET is a vector of item numbers; NITEMSET is its size
|
||||
9actually, points to just beyond the end of the part of it that is
|
||||
significant). closure places there the indices of all items which
|
||||
(actually, points to just beyond the end of the part of it that is
|
||||
significant). CLOSURE places there the indices of all items which
|
||||
represent units of input that could arrive next. */
|
||||
|
||||
void closure PARAMS ((short *items, int n));
|
||||
|
||||
|
||||
/* Frees itemset, ruleset and internal data. */
|
||||
/* Frees ITEMSET, RULESET and internal data. */
|
||||
|
||||
void free_closure PARAMS ((void));
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Allocate input grammar variables for bison,
|
||||
Copyright 1984, 1986, 1989, 2001, 2002 Free Software Foundation, Inc.
|
||||
Copyright (C) 1984, 1986, 1989, 2001, 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
|
||||
#include "system.h"
|
||||
#include "quotearg.h"
|
||||
#include "gram.h"
|
||||
#include "symtab.h"
|
||||
#include "reader.h"
|
||||
@@ -77,7 +78,8 @@ ritem_print (FILE *out)
|
||||
fputs ("RITEM\n", out);
|
||||
for (i = 0; i < nritems; ++i)
|
||||
if (ritem[i] >= 0)
|
||||
fprintf (out, " %s", symbols[ritem[i]]->tag);
|
||||
fprintf (out, " %s", quotearg_style (escape_quoting_style,
|
||||
symbols[ritem[i]]->tag));
|
||||
else
|
||||
fprintf (out, " (rule %d)\n", -ritem[i] - 1);
|
||||
fputs ("\n\n", out);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "system.h"
|
||||
#include "bitset.h"
|
||||
#include "bitsetv.h"
|
||||
#include "quotearg.h"
|
||||
#include "reader.h"
|
||||
#include "types.h"
|
||||
#include "LR0.h"
|
||||
@@ -559,9 +560,9 @@ lookaheads_print (FILE *out)
|
||||
|
||||
for (j = 0; j < states[i]->nlookaheads; ++j)
|
||||
for (k = 0; k < ntokens; ++k)
|
||||
if (bitset_test (LA[states[i]->lookaheadsp + j], j))
|
||||
if (bitset_test (LA[states[i]->lookaheadsp + j], k))
|
||||
fprintf (out, " on %d (%s) -> rule %d\n",
|
||||
k, symbols[k]->tag,
|
||||
k, quotearg_style (escape_quoting_style, symbols[k]->tag),
|
||||
LArule[states[i]->lookaheadsp + j]->number - 1);
|
||||
}
|
||||
fprintf (out, "Lookaheads: END\n");
|
||||
|
||||
26
src/reduce.c
26
src/reduce.c
@@ -1,5 +1,5 @@
|
||||
/* Grammar reduction for Bison.
|
||||
Copyright 1988, 1989, 2000, 2001 Free Software Foundation, Inc.
|
||||
Copyright (C) 1988, 1989, 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of Bison, the GNU Compiler Compiler.
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
user's parser. */
|
||||
|
||||
#include "system.h"
|
||||
#include "quotearg.h"
|
||||
#include "getargs.h"
|
||||
#include "files.h"
|
||||
#include "symtab.h"
|
||||
@@ -343,7 +344,8 @@ reduce_output (FILE *out)
|
||||
int i;
|
||||
fprintf (out, "%s\n\n", _("Useless nonterminals:"));
|
||||
for (i = 0; i < nuseless_nonterminals; ++i)
|
||||
fprintf (out, " %s\n", symbols[nsyms + i]->tag);
|
||||
fprintf (out, " %s\n", quotearg_style (escape_quoting_style,
|
||||
symbols[nsyms + i]->tag));
|
||||
fputs ("\n\n", out);
|
||||
}
|
||||
|
||||
@@ -356,7 +358,8 @@ reduce_output (FILE *out)
|
||||
if (!b)
|
||||
fprintf (out, "%s\n\n", _("Terminals which are not used:"));
|
||||
b = TRUE;
|
||||
fprintf (out, " %s\n", symbols[i]->tag);
|
||||
fprintf (out, " %s\n", quotearg_style (escape_quoting_style,
|
||||
symbols[i]->tag));
|
||||
}
|
||||
if (b)
|
||||
fputs ("\n\n", out);
|
||||
@@ -370,9 +373,11 @@ reduce_output (FILE *out)
|
||||
{
|
||||
rule r;
|
||||
fprintf (out, "#%-4d ", rules[i].user_number - 1);
|
||||
fprintf (out, "%s:", rules[i].lhs->tag);
|
||||
fprintf (out, "%s:", quotearg_style (escape_quoting_style,
|
||||
rules[i].lhs->tag));
|
||||
for (r = rules[i].rhs; *r >= 0; r++)
|
||||
fprintf (out, " %s", symbols[*r]->tag);
|
||||
fprintf (out, " %s", quotearg_style (escape_quoting_style,
|
||||
symbols[*r]->tag));
|
||||
fputs (";\n", out);
|
||||
}
|
||||
fputs ("\n\n", out);
|
||||
@@ -394,7 +399,8 @@ dump_grammar (FILE *out)
|
||||
for (i = ntokens; i < nsyms; i++)
|
||||
fprintf (out, "%5d %5d %5d %s\n",
|
||||
i,
|
||||
symbols[i]->prec, symbols[i]->assoc, symbols[i]->tag);
|
||||
symbols[i]->prec, symbols[i]->assoc,
|
||||
quotearg_style (escape_quoting_style, symbols[i]->tag));
|
||||
fprintf (out, "\n\n");
|
||||
fprintf (out, "Rules\n-----\n\n");
|
||||
fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\n");
|
||||
@@ -418,9 +424,11 @@ dump_grammar (FILE *out)
|
||||
fprintf (out, "Rules interpreted\n-----------------\n\n");
|
||||
for (i = 1; i < nrules + nuseless_productions + 1; i++)
|
||||
{
|
||||
fprintf (out, "%-5d %s :", i, rules[i].lhs->tag);
|
||||
fprintf (out, "%-5d %s :",
|
||||
i, quotearg_style (escape_quoting_style, rules[i].lhs->tag));
|
||||
for (r = rules[i].rhs; *r >= 0; r++)
|
||||
fprintf (out, " %s", symbols[*r]->tag);
|
||||
fprintf (out, " %s",
|
||||
quotearg_style (escape_quoting_style, symbols[*r]->tag));
|
||||
fputc ('\n', out);
|
||||
}
|
||||
fprintf (out, "\n\n");
|
||||
@@ -484,7 +492,7 @@ reduce_grammar (void)
|
||||
|
||||
if (!bitset_test (N, start_symbol - ntokens))
|
||||
fatal (_("Start symbol %s does not derive any sentence"),
|
||||
symbols[start_symbol]->tag);
|
||||
quotearg_style (escape_quoting_style, symbols[start_symbol]->tag));
|
||||
|
||||
if (nuseless_productions > 0)
|
||||
reduce_grammar_tables ();
|
||||
|
||||
Reference in New Issue
Block a user