* src/reader.c, src/reader.h (tags): Remove.

Adjust all users to use symbols[i]->tag.
This commit is contained in:
Akim Demaille
2001-12-29 14:18:52 +00:00
parent 0e78e603f6
commit ad949da96b
13 changed files with 61 additions and 50 deletions

View File

@@ -1,3 +1,9 @@
2001-12-29 Akim Demaille <akim@epita.fr>
* src/reader.c, src/reader.h (tags): Remove.
Adjust all users to use symbols[i]->tag.
2001-12-29 Akim Demaille <akim@epita.fr> 2001-12-29 Akim Demaille <akim@epita.fr>
* src/gram.h, src/gram.c (symbols): New, similar to state_table * src/gram.h, src/gram.c (symbols): New, similar to state_table

View File

@@ -188,7 +188,7 @@ 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",
this_state->number, symbol, tags[symbol]); this_state->number, symbol, symbols[symbol]->tag);
if (nstates >= MAXSHORT) if (nstates >= MAXSHORT)
fatal (_("too many states (max %d)"), MAXSHORT); fatal (_("too many states (max %d)"), MAXSHORT);
@@ -227,7 +227,7 @@ 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, tags[symbol]); this_state->number, symbol, 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.
*/ */
@@ -406,7 +406,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, tags[this_state->accessing_symbol]); this_state->number,
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

@@ -20,6 +20,7 @@
#include "system.h" #include "system.h"
#include "getargs.h" #include "getargs.h"
#include "symtab.h"
#include "gram.h" #include "gram.h"
#include "reader.h" #include "reader.h"
#include "closure.h" #include "closure.h"
@@ -61,7 +62,7 @@ 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", tags[*rp]); fprintf (stderr, " %s", 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);
@@ -76,10 +77,11 @@ 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", tags[i]); fprintf (stderr, "\t%s firsts\n", symbols[i]->tag);
for (j = 0; j < nvars; j++) for (j = 0; j < nvars; j++)
if (BITISSET (FIRSTS (i), j)) if (BITISSET (FIRSTS (i), j))
fprintf (stderr, "\t\t%d (%s)\n", j + ntokens, tags[j + ntokens]); fprintf (stderr, "\t\t%d (%s)\n",
j + ntokens, symbols[j + ntokens]->tag);
} }
fprintf (stderr, "\n\n"); fprintf (stderr, "\n\n");
} }
@@ -95,14 +97,14 @@ print_fderives (void)
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
{ {
fprintf (stderr, "\t%s derives\n", tags[i]); fprintf (stderr, "\t%s derives\n", symbols[i]->tag);
for (j = 0; j <= nrules; j++) for (j = 0; j <= nrules; j++)
if (BITISSET (FDERIVES (i), j)) if (BITISSET (FDERIVES (i), j))
{ {
short *rhsp; short *rhsp;
fprintf (stderr, "\t\t%d:", j - 1); fprintf (stderr, "\t\t%d:", j - 1);
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]); fprintf (stderr, " %s", symbols[*rhsp]->tag);
fputc ('\n', stderr); fputc ('\n', stderr);
} }
} }

View File

@@ -45,7 +45,8 @@ log_resolution (state_t *state, int LAno, int token, char *resolution)
obstack_fgrow4 (&output_obstack, obstack_fgrow4 (&output_obstack,
_("\ _("\
Conflict in state %d between rule %d and token %s resolved as %s.\n"), Conflict in state %d between rule %d and token %s resolved as %s.\n"),
state->number, LAruleno[LAno], tags[token], resolution); state->number, LAruleno[LAno], symbols[token]->tag,
resolution);
} }

View File

@@ -21,6 +21,7 @@
#include "system.h" #include "system.h"
#include "getargs.h" #include "getargs.h"
#include "symtab.h"
#include "types.h" #include "types.h"
#include "reader.h" #include "reader.h"
#include "gram.h" #include "gram.h"
@@ -38,13 +39,13 @@ print_derives (void)
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
{ {
short *sp; short *sp;
fprintf (stderr, "\t%s derives\n", tags[i]); fprintf (stderr, "\t%s derives\n", symbols[i]->tag);
for (sp = derives[i]; *sp > 0; sp++) for (sp = derives[i]; *sp > 0; sp++)
{ {
short *rhsp; short *rhsp;
fprintf (stderr, "\t\t%d:", *sp); fprintf (stderr, "\t\t%d:", *sp);
for (rhsp = &ritem[rule_table[*sp].rhs]; *rhsp >= 0; ++rhsp) for (rhsp = &ritem[rule_table[*sp].rhs]; *rhsp >= 0; ++rhsp)
fprintf (stderr, " %s", tags[*rhsp]); fprintf (stderr, " %s", symbols[*rhsp]->tag);
fprintf (stderr, " (rule %d)\n", -*rhsp - 1); fprintf (stderr, " (rule %d)\n", -*rhsp - 1);
} }
} }

View File

@@ -67,7 +67,7 @@ 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", tags[ritem[i]]); fprintf (out, " %s", 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 "reader.h" #include "reader.h"
#include "types.h" #include "types.h"
#include "LR0.h" #include "LR0.h"
#include "symtab.h"
#include "gram.h" #include "gram.h"
#include "complain.h" #include "complain.h"
#include "lalr.h" #include "lalr.h"
@@ -566,7 +567,7 @@ lookaheads_print (FILE *out)
for (k = 0; k < ntokens; ++k) for (k = 0; k < ntokens; ++k)
if (BITISSET (LA (state_table[i]->lookaheadsp + j), j)) if (BITISSET (LA (state_table[i]->lookaheadsp + j), j))
fprintf (out, " on %d (%s) -> rule %d\n", fprintf (out, " on %d (%s) -> rule %d\n",
k, tags[k], k, symbols[k]->tag,
-LAruleno[state_table[i]->lookaheadsp + j] - 1); -LAruleno[state_table[i]->lookaheadsp + j] - 1);
} }
fprintf (out, "Lookaheads: END\n"); fprintf (out, "Lookaheads: END\n");

View File

@@ -25,7 +25,7 @@
#include "system.h" #include "system.h"
#include "getargs.h" #include "getargs.h"
#include "reader.h" #include "symtab.h"
#include "types.h" #include "types.h"
#include "gram.h" #include "gram.h"
#include "reduce.h" #include "reduce.h"
@@ -39,7 +39,7 @@ nullable_print (FILE *out)
int i; int i;
fputs ("NULLABLE\n", out); fputs ("NULLABLE\n", out);
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
fprintf (out, "\t%s: %s\n", tags[i], nullable[i] ? "yes" : "no"); fprintf (out, "\t%s: %s\n", symbols[i]->tag, nullable[i] ? "yes" : "no");
fputs ("\n\n", out); fputs ("\n\n", out);
} }

View File

@@ -98,6 +98,7 @@
#include "output.h" #include "output.h"
#include "lalr.h" #include "lalr.h"
#include "reader.h" #include "reader.h"
#include "symtab.h"
#include "conflicts.h" #include "conflicts.h"
#include "muscle_tab.h" #include "muscle_tab.h"
@@ -252,7 +253,7 @@ output_rule_data (void)
/* Be sure not to use twice the same quotearg slot. */ /* Be sure not to use twice the same quotearg slot. */
const char *cp = const char *cp =
quotearg_n_style (1, c_quoting_style, quotearg_n_style (1, c_quoting_style,
quotearg_style (escape_quoting_style, tags[i])); quotearg_style (escape_quoting_style, symbols[i]->tag));
/* Width of the next token, including the two quotes, the coma /* Width of the next token, including the two quotes, the coma
and the space. */ and the space. */
int strsize = strlen (cp) + 2; int strsize = strlen (cp) + 2;
@@ -1075,8 +1076,8 @@ yystype;\n\
for (i = ntokens; i < nsyms; i++) for (i = ntokens; i < nsyms; i++)
/* don't make these for dummy nonterminals made by gensym. */ /* don't make these for dummy nonterminals made by gensym. */
if (*tags[i] != '@') if (*symbols[i]->tag != '@')
fprintf (out, "# define NT%s\t%d\n", tags[i], i); fprintf (out, "# define NT%s\t%d\n", symbols[i]->tag, i);
} }
fprintf (out, "\n#endif /* not %s */\n", macro_name); fprintf (out, "\n#endif /* not %s */\n", macro_name);

View File

@@ -22,6 +22,7 @@
#include "system.h" #include "system.h"
#include "quotearg.h" #include "quotearg.h"
#include "files.h" #include "files.h"
#include "symtab.h"
#include "gram.h" #include "gram.h"
#include "LR0.h" #include "LR0.h"
#include "lalr.h" #include "lalr.h"
@@ -92,15 +93,15 @@ print_core (FILE *out, state_t *state)
sp++; sp++;
rule = -(*sp); rule = -(*sp);
fprintf (out, " %s -> ", escape (tags[rule_table[rule].lhs])); fprintf (out, " %s -> ", escape (symbols[rule_table[rule].lhs]->tag));
for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++) for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++)
fprintf (out, "%s ", escape (tags[*sp])); fprintf (out, "%s ", escape (symbols[*sp]->tag));
fputc ('.', out); fputc ('.', out);
for (/* Nothing */; *sp >= 0; ++sp) for (/* Nothing */; *sp >= 0; ++sp)
fprintf (out, " %s", escape (tags[*sp])); fprintf (out, " %s", escape (symbols[*sp]->tag));
fprintf (out, _(" (rule %d)"), rule - 1); fprintf (out, _(" (rule %d)"), rule - 1);
fputc ('\n', out); fputc ('\n', out);
@@ -124,7 +125,7 @@ print_shifts (FILE *out, state_t *state)
int symbol = state_table[state1]->accessing_symbol; int symbol = state_table[state1]->accessing_symbol;
fprintf (out, fprintf (out,
_(" %-4s\tshift, and go to state %d\n"), _(" %-4s\tshift, and go to state %d\n"),
escape (tags[symbol]), state1); escape (symbols[symbol]->tag), state1);
} }
if (i > 0) if (i > 0)
@@ -141,7 +142,7 @@ print_errs (FILE *out, state_t *state)
for (i = 0; i < errp->nerrs; ++i) for (i = 0; i < errp->nerrs; ++i)
if (errp->errs[i]) if (errp->errs[i])
fprintf (out, _(" %-4s\terror (nonassociative)\n"), fprintf (out, _(" %-4s\terror (nonassociative)\n"),
escape (tags[errp->errs[i]])); escape (symbols[errp->errs[i]]->tag));
if (i > 0) if (i > 0)
fputc ('\n', out); fputc ('\n', out);
@@ -165,7 +166,7 @@ print_gotos (FILE *out, state_t *state)
int state1 = shiftp->shifts[i]; int state1 = shiftp->shifts[i];
int symbol = state_table[state1]->accessing_symbol; int symbol = state_table[state1]->accessing_symbol;
fprintf (out, _(" %-4s\tgo to state %d\n"), fprintf (out, _(" %-4s\tgo to state %d\n"),
escape (tags[symbol]), state1); escape (symbols[symbol]->tag), state1);
} }
fputc ('\n', out); fputc ('\n', out);
@@ -189,7 +190,7 @@ print_reductions (FILE *out, state_t *state)
int rule = redp->rules[0]; int rule = redp->rules[0];
int symbol = rule_table[rule].lhs; int symbol = rule_table[rule].lhs;
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"), fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
rule - 1, escape (tags[symbol])); rule - 1, escape (symbols[symbol]->tag));
return; return;
} }
@@ -221,11 +222,11 @@ print_reductions (FILE *out, state_t *state)
for (i = 0; i < ntokens; i++) for (i = 0; i < ntokens; i++)
if (BITISSET (lookaheadset, i)) if (BITISSET (lookaheadset, i))
fprintf (out, _(" %-4s\t[reduce using rule %d (%s)]\n"), fprintf (out, _(" %-4s\t[reduce using rule %d (%s)]\n"),
escape (tags[i]), default_rule - 1, escape (symbols[i]->tag), default_rule - 1,
escape2 (tags[rule_table[default_rule].lhs])); escape2 (symbols[rule_table[default_rule].lhs]->tag));
fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"), fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"),
default_rule - 1, escape (tags[rule_table[default_rule].lhs])); default_rule - 1, escape (symbols[rule_table[default_rule].lhs]->tag));
} }
else if (state->nlookaheads >= 1) else if (state->nlookaheads >= 1)
{ {
@@ -279,9 +280,9 @@ print_reductions (FILE *out, state_t *state)
if (state->lookaheadsp + j != default_LA) if (state->lookaheadsp + j != default_LA)
fprintf (out, fprintf (out,
_(" %-4s\treduce using rule %d (%s)\n"), _(" %-4s\treduce using rule %d (%s)\n"),
escape (tags[i]), escape (symbols[i]->tag),
LAruleno[state->lookaheadsp + j] - 1, LAruleno[state->lookaheadsp + j] - 1,
escape2 (tags[rule_table[LAruleno[state->lookaheadsp + j]].lhs])); escape2 (symbols[rule_table[LAruleno[state->lookaheadsp + j]].lhs]->tag));
else else
defaulted = 1; defaulted = 1;
@@ -292,15 +293,15 @@ print_reductions (FILE *out, state_t *state)
if (defaulted) if (defaulted)
fprintf (out, fprintf (out,
_(" %-4s\treduce using rule %d (%s)\n"), _(" %-4s\treduce using rule %d (%s)\n"),
escape (tags[i]), escape (symbols[i]->tag),
LAruleno[default_LA] - 1, LAruleno[default_LA] - 1,
escape2 (tags[rule_table[LAruleno[default_LA]].lhs])); escape2 (symbols[rule_table[LAruleno[default_LA]].lhs]->tag));
defaulted = 0; defaulted = 0;
fprintf (out, fprintf (out,
_(" %-4s\t[reduce using rule %d (%s)]\n"), _(" %-4s\t[reduce using rule %d (%s)]\n"),
escape (tags[i]), escape (symbols[i]->tag),
LAruleno[state->lookaheadsp + j] - 1, LAruleno[state->lookaheadsp + j] - 1,
escape2 (tags[rule_table[LAruleno[state->lookaheadsp + j]].lhs])); escape2 (symbols[rule_table[LAruleno[state->lookaheadsp + j]].lhs]->tag));
} }
} }
} }
@@ -309,7 +310,7 @@ print_reductions (FILE *out, state_t *state)
if (default_LA >= 0) if (default_LA >= 0)
fprintf (out, _(" $default\treduce using rule %d (%s)\n"), fprintf (out, _(" $default\treduce using rule %d (%s)\n"),
default_rule - 1, default_rule - 1,
escape (tags[rule_table[default_rule].lhs])); escape (symbols[rule_table[default_rule].lhs]->tag));
} }
} }
@@ -376,11 +377,11 @@ print_grammar (FILE *out)
if (rule_table[i].useful) if (rule_table[i].useful)
{ {
fprintf (out, _(" %3d %3d %s ->"), fprintf (out, _(" %3d %3d %s ->"),
i - 1, rule_table[i].line, escape (tags[rule_table[i].lhs])); i - 1, rule_table[i].line, escape (symbols[rule_table[i].lhs]->tag));
rule = &ritem[rule_table[i].rhs]; rule = &ritem[rule_table[i].rhs];
if (*rule >= 0) if (*rule >= 0)
while (*rule >= 0) while (*rule >= 0)
fprintf (out, " %s", escape (tags[*rule++])); fprintf (out, " %s", escape (symbols[*rule++]->tag));
else else
fprintf (out, " /* %s */", _("empty")); fprintf (out, " /* %s */", _("empty"));
fputc ('\n', out); fputc ('\n', out);
@@ -394,8 +395,8 @@ print_grammar (FILE *out)
if (token_translations[i] != 2) if (token_translations[i] != 2)
{ {
buffer[0] = 0; buffer[0] = 0;
column = strlen (escape (tags[token_translations[i]])); column = strlen (escape (symbols[token_translations[i]]->tag));
fputs (escape (tags[token_translations[i]]), out); fputs (escape (symbols[token_translations[i]]->tag), out);
END_TEST (50); END_TEST (50);
sprintf (buffer, " (%d)", i); sprintf (buffer, " (%d)", i);
@@ -430,8 +431,8 @@ print_grammar (FILE *out)
} }
buffer[0] = 0; buffer[0] = 0;
fputs (escape (tags[i]), out); fputs (escape (symbols[i]->tag), out);
column = strlen (escape (tags[i])); column = strlen (escape (symbols[i]->tag));
sprintf (buffer, " (%d)", i); sprintf (buffer, " (%d)", i);
END_TEST (0); END_TEST (0);

View File

@@ -21,6 +21,7 @@
#include "system.h" #include "system.h"
#include "quotearg.h" #include "quotearg.h"
#include "files.h" #include "files.h"
#include "symtab.h"
#include "gram.h" #include "gram.h"
#include "LR0.h" #include "LR0.h"
#include "lalr.h" #include "lalr.h"
@@ -77,15 +78,15 @@ print_core (state_t *state, struct obstack *node_obstack)
if (i) if (i)
obstack_1grow (node_obstack, '\n'); obstack_1grow (node_obstack, '\n');
obstack_fgrow1 (node_obstack, " %s -> ", obstack_fgrow1 (node_obstack, " %s -> ",
escape (tags[rule_table[rule].lhs])); escape (symbols[rule_table[rule].lhs]->tag));
for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++) for (sp = ritem + rule_table[rule].rhs; sp < sp1; sp++)
obstack_fgrow1 (node_obstack, "%s ", escape (tags[*sp])); obstack_fgrow1 (node_obstack, "%s ", escape (symbols[*sp]->tag));
obstack_1grow (node_obstack, '.'); obstack_1grow (node_obstack, '.');
for (/* Nothing */; *sp >= 0; ++sp) for (/* Nothing */; *sp >= 0; ++sp)
obstack_fgrow1 (node_obstack, " %s", escape (tags[*sp])); obstack_fgrow1 (node_obstack, " %s", escape (symbols[*sp]->tag));
} }
} }
@@ -129,7 +130,7 @@ print_actions (state_t *state, const char *node_name)
edge.color = red; edge.color = red;
else else
edge.color = SHIFT_IS_SHIFT(shiftp, i) ? blue : green; edge.color = SHIFT_IS_SHIFT(shiftp, i) ? blue : green;
edge.label = escape (tags[symbol]); edge.label = escape (symbols[symbol]->tag);
output_edge (&edge, fgraph); output_edge (&edge, fgraph);
close_edge (fgraph); close_edge (fgraph);
} }

View File

@@ -52,7 +52,6 @@ typedef struct symbol_list
} symbol_list; } symbol_list;
int lineno; int lineno;
char **tags;
short *user_toknums; short *user_toknums;
static symbol_list *grammar; static symbol_list *grammar;
static int start_flag; static int start_flag;
@@ -1549,7 +1548,7 @@ token_translations_init (void)
/* A token which translation has already been set? */ /* A token which translation has already been set? */
if (token_translations[bp->user_token_number] != 2) if (token_translations[bp->user_token_number] != 2)
complain (_("tokens %s and %s both assigned number %d"), complain (_("tokens %s and %s both assigned number %d"),
tags[token_translations[bp->user_token_number]], symbols[token_translations[bp->user_token_number]]->tag,
bp->tag, bp->user_token_number); bp->tag, bp->user_token_number);
token_translations[bp->user_token_number] = bp->value; token_translations[bp->user_token_number] = bp->value;
} }
@@ -1568,7 +1567,6 @@ packsymbols (void)
int tokno = 1; int tokno = 1;
int last_user_token_number; int last_user_token_number;
tags = XCALLOC (char *, nsyms + 1);
user_toknums = XCALLOC (short, nsyms + 1); user_toknums = XCALLOC (short, nsyms + 1);
symbols = XCALLOC (bucket *, nsyms); symbols = XCALLOC (bucket *, nsyms);
@@ -1644,7 +1642,6 @@ packsymbols (void)
} }
symbols[bp->value] = bp; symbols[bp->value] = bp;
tags[bp->value] = bp->tag;
user_toknums[bp->value] = bp->user_token_number; user_toknums[bp->value] = bp->user_token_number;
sassoc[bp->value] = bp->assoc; sassoc[bp->value] = bp->assoc;
} }

View File

@@ -31,7 +31,6 @@ extern void reader PARAMS ((void));
extern int lineno; extern int lineno;
extern char **tags;
extern short *user_toknums; extern short *user_toknums;
#endif /* !READER_H_ */ #endif /* !READER_H_ */