* 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:
Akim Demaille
2002-04-07 17:42:12 +00:00
parent e601aa1d35
commit 8b3df748a3
7 changed files with 55 additions and 29 deletions

View File

@@ -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> 2002-04-07 Akim Demaille <akim@epita.fr>
* src/lalr.h (LA): Is a bitsetv, not bitset*. * src/lalr.h (LA): Is a bitsetv, not bitset*.

View File

@@ -24,6 +24,7 @@
#include "system.h" #include "system.h"
#include "bitset.h" #include "bitset.h"
#include "quotearg.h"
#include "symtab.h" #include "symtab.h"
#include "getargs.h" #include "getargs.h"
#include "reader.h" #include "reader.h"
@@ -190,7 +191,8 @@ new_state (int symbol)
if (trace_flag) if (trace_flag)
fprintf (stderr, "Entering new_state, state = %d, symbol = %d (%s)\n", 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) if (nstates >= MAXSHORT)
fatal (_("too many states (max %d)"), MAXSHORT); fatal (_("too many states (max %d)"), MAXSHORT);
@@ -234,7 +236,8 @@ get_state (int symbol)
if (trace_flag) if (trace_flag)
fprintf (stderr, "Entering get_state, state = %d, symbol = %d (%s)\n", 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. /* Add up the target state's active item numbers to get a hash key.
*/ */
@@ -416,7 +419,8 @@ generate_states (void)
if (trace_flag) if (trace_flag)
fprintf (stderr, "Processing state %d (reached by %s)\n", fprintf (stderr, "Processing state %d (reached by %s)\n",
this_state->number, 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 /* Set up ruleset and itemset for the transitions out of this
state. ruleset gets a 1 bit for each rule that could reduce state. ruleset gets a 1 bit for each rule that could reduce
now. itemset gets a vector of all the items that could be now. itemset gets a vector of all the items that could be

View File

@@ -19,6 +19,7 @@
02111-1307, USA. */ 02111-1307, USA. */
#include "system.h" #include "system.h"
#include "quotearg.h"
#include "bitset.h" #include "bitset.h"
#include "bitsetv.h" #include "bitsetv.h"
#include "getargs.h" #include "getargs.h"
@@ -57,7 +58,8 @@ print_closure (const char *title, short *array, size_t size)
short *rp; short *rp;
fprintf (stderr, " %2d: .", array[i]); fprintf (stderr, " %2d: .", array[i]);
for (rp = &ritem[array[i]]; *rp >= 0; ++rp) 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); fprintf (stderr, " (rule %d)\n", -*rp - 1);
} }
fputs ("\n\n", stderr); fputs ("\n\n", stderr);
@@ -72,11 +74,14 @@ print_firsts (void)
fprintf (stderr, "FIRSTS\n"); fprintf (stderr, "FIRSTS\n");
for (i = ntokens; i < nsyms; i++) 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++) for (j = 0; j < nvars; j++)
if (bitset_test (FIRSTS (i), j)) if (bitset_test (FIRSTS (i), j))
fprintf (stderr, "\t\t%d (%s)\n", 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"); fprintf (stderr, "\n\n");
} }
@@ -90,14 +95,17 @@ print_fderives (void)
fprintf (stderr, "FDERIVES\n"); fprintf (stderr, "FDERIVES\n");
for (i = ntokens; i < nsyms; i++) 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++) for (j = 0; j < nrules + 1; j++)
if (bitset_test (FDERIVES (i), j)) if (bitset_test (FDERIVES (i), j))
{ {
short *rhsp; short *rhsp;
fprintf (stderr, "\t\t%d:", j - 1); fprintf (stderr, "\t\t%d:", j - 1);
for (rhsp = rules[j].rhs; *rhsp >= 0; ++rhsp) 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); fputc ('\n', stderr);
} }
} }

View File

@@ -1,5 +1,5 @@
/* Subroutines for bison /* 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. This file is part of Bison, the GNU Compiler Compiler.
@@ -21,8 +21,6 @@
#ifndef CLOSURE_H_ #ifndef CLOSURE_H_
# define CLOSURE_H_ # define CLOSURE_H_
/* Subroutines of file LR0.c. */
/* Allocates the itemset and ruleset vectors, and precomputes useful /* Allocates the itemset and ruleset vectors, and precomputes useful
data so that closure can be called. n is the number of elements to data so that closure can be called. n is the number of elements to
allocate for itemset. */ 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 /* 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 rules could be run and which items could be accepted when those
items are the active ones. 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 all rules which could potentially describe the next input to be
read. read.
ITEMSET is a vector of item numbers; NITEMSET is its size 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 (actually, points to just beyond the end of the part of it that is
significant). closure places there the indices of all items which significant). CLOSURE places there the indices of all items which
represent units of input that could arrive next. */ represent units of input that could arrive next. */
void closure PARAMS ((short *items, int n)); void closure PARAMS ((short *items, int n));
/* Frees itemset, ruleset and internal data. */ /* Frees ITEMSET, RULESET and internal data. */
void free_closure PARAMS ((void)); void free_closure PARAMS ((void));

View File

@@ -1,5 +1,5 @@
/* Allocate input grammar variables for bison, /* 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. This file is part of Bison, the GNU Compiler Compiler.
@@ -20,6 +20,7 @@
#include "system.h" #include "system.h"
#include "quotearg.h"
#include "gram.h" #include "gram.h"
#include "symtab.h" #include "symtab.h"
#include "reader.h" #include "reader.h"
@@ -77,7 +78,8 @@ ritem_print (FILE *out)
fputs ("RITEM\n", out); fputs ("RITEM\n", out);
for (i = 0; i < nritems; ++i) for (i = 0; i < nritems; ++i)
if (ritem[i] >= 0) if (ritem[i] >= 0)
fprintf (out, " %s", symbols[ritem[i]]->tag); fprintf (out, " %s", quotearg_style (escape_quoting_style,
symbols[ritem[i]]->tag));
else else
fprintf (out, " (rule %d)\n", -ritem[i] - 1); fprintf (out, " (rule %d)\n", -ritem[i] - 1);
fputs ("\n\n", out); fputs ("\n\n", out);

View File

@@ -27,6 +27,7 @@
#include "system.h" #include "system.h"
#include "bitset.h" #include "bitset.h"
#include "bitsetv.h" #include "bitsetv.h"
#include "quotearg.h"
#include "reader.h" #include "reader.h"
#include "types.h" #include "types.h"
#include "LR0.h" #include "LR0.h"
@@ -559,9 +560,9 @@ lookaheads_print (FILE *out)
for (j = 0; j < states[i]->nlookaheads; ++j) for (j = 0; j < states[i]->nlookaheads; ++j)
for (k = 0; k < ntokens; ++k) 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", 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); LArule[states[i]->lookaheadsp + j]->number - 1);
} }
fprintf (out, "Lookaheads: END\n"); fprintf (out, "Lookaheads: END\n");

View File

@@ -1,5 +1,5 @@
/* Grammar reduction for Bison. /* 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. This file is part of Bison, the GNU Compiler Compiler.
@@ -26,6 +26,7 @@
user's parser. */ user's parser. */
#include "system.h" #include "system.h"
#include "quotearg.h"
#include "getargs.h" #include "getargs.h"
#include "files.h" #include "files.h"
#include "symtab.h" #include "symtab.h"
@@ -343,7 +344,8 @@ reduce_output (FILE *out)
int i; int i;
fprintf (out, "%s\n\n", _("Useless nonterminals:")); fprintf (out, "%s\n\n", _("Useless nonterminals:"));
for (i = 0; i < nuseless_nonterminals; ++i) 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); fputs ("\n\n", out);
} }
@@ -356,7 +358,8 @@ reduce_output (FILE *out)
if (!b) if (!b)
fprintf (out, "%s\n\n", _("Terminals which are not used:")); fprintf (out, "%s\n\n", _("Terminals which are not used:"));
b = TRUE; b = TRUE;
fprintf (out, " %s\n", symbols[i]->tag); fprintf (out, " %s\n", quotearg_style (escape_quoting_style,
symbols[i]->tag));
} }
if (b) if (b)
fputs ("\n\n", out); fputs ("\n\n", out);
@@ -370,9 +373,11 @@ reduce_output (FILE *out)
{ {
rule r; rule r;
fprintf (out, "#%-4d ", rules[i].user_number - 1); 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++) 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", out);
} }
fputs ("\n\n", out); fputs ("\n\n", out);
@@ -394,7 +399,8 @@ dump_grammar (FILE *out)
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
fprintf (out, "%5d %5d %5d %s\n", fprintf (out, "%5d %5d %5d %s\n",
i, 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, "\n\n");
fprintf (out, "Rules\n-----\n\n"); fprintf (out, "Rules\n-----\n\n");
fprintf (out, "Num (Prec, Assoc, Useful, Ritem Range) Lhs -> Rhs (Ritem range) [Num]\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"); fprintf (out, "Rules interpreted\n-----------------\n\n");
for (i = 1; i < nrules + nuseless_productions + 1; i++) 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++) 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); fputc ('\n', out);
} }
fprintf (out, "\n\n"); fprintf (out, "\n\n");
@@ -484,7 +492,7 @@ reduce_grammar (void)
if (!bitset_test (N, start_symbol - ntokens)) if (!bitset_test (N, start_symbol - ntokens))
fatal (_("Start symbol %s does not derive any sentence"), 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) if (nuseless_productions > 0)
reduce_grammar_tables (); reduce_grammar_tables ();