From ad949da96bf5621185a28f354c08f4595bc42952 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sat, 29 Dec 2001 14:18:52 +0000 Subject: [PATCH] * src/reader.c, src/reader.h (tags): Remove. Adjust all users to use symbols[i]->tag. --- ChangeLog | 6 ++++++ src/LR0.c | 7 ++++--- src/closure.c | 12 +++++++----- src/conflicts.c | 3 ++- src/derives.c | 5 +++-- src/gram.c | 2 +- src/lalr.c | 3 ++- src/nullable.c | 4 ++-- src/output.c | 7 ++++--- src/print.c | 47 ++++++++++++++++++++++++----------------------- src/print_graph.c | 9 +++++---- src/reader.c | 5 +---- src/reader.h | 1 - 13 files changed, 61 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6d3ba670..d1da8f2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2001-12-29 Akim Demaille + + * src/reader.c, src/reader.h (tags): Remove. + Adjust all users to use symbols[i]->tag. + + 2001-12-29 Akim Demaille * src/gram.h, src/gram.c (symbols): New, similar to state_table diff --git a/src/LR0.c b/src/LR0.c index 47ce6dd2..2b78dd03 100644 --- a/src/LR0.c +++ b/src/LR0.c @@ -188,7 +188,7 @@ new_state (int symbol) if (trace_flag) 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) fatal (_("too many states (max %d)"), MAXSHORT); @@ -227,7 +227,7 @@ get_state (int symbol) if (trace_flag) 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. */ @@ -406,7 +406,8 @@ generate_states (void) { if (trace_flag) 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 state. ruleset gets a 1 bit for each rule that could reduce now. itemset gets a vector of all the items that could be diff --git a/src/closure.c b/src/closure.c index 4c8fcda7..61a111be 100644 --- a/src/closure.c +++ b/src/closure.c @@ -20,6 +20,7 @@ #include "system.h" #include "getargs.h" +#include "symtab.h" #include "gram.h" #include "reader.h" #include "closure.h" @@ -61,7 +62,7 @@ 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", tags[*rp]); + fprintf (stderr, " %s", symbols[*rp]->tag); fprintf (stderr, " (rule %d)\n", -*rp - 1); } fputs ("\n\n", stderr); @@ -76,10 +77,11 @@ print_firsts (void) fprintf (stderr, "FIRSTS\n"); 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++) 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"); } @@ -95,14 +97,14 @@ print_fderives (void) 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++) if (BITISSET (FDERIVES (i), j)) { short *rhsp; fprintf (stderr, "\t\t%d:", j - 1); for (rhsp = &ritem[rule_table[j].rhs]; *rhsp >= 0; ++rhsp) - fprintf (stderr, " %s", tags[*rhsp]); + fprintf (stderr, " %s", symbols[*rhsp]->tag); fputc ('\n', stderr); } } diff --git a/src/conflicts.c b/src/conflicts.c index a17157a6..05f37bd1 100644 --- a/src/conflicts.c +++ b/src/conflicts.c @@ -45,7 +45,8 @@ log_resolution (state_t *state, int LAno, int token, char *resolution) obstack_fgrow4 (&output_obstack, _("\ 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); } diff --git a/src/derives.c b/src/derives.c index 80e430bf..479a3551 100644 --- a/src/derives.c +++ b/src/derives.c @@ -21,6 +21,7 @@ #include "system.h" #include "getargs.h" +#include "symtab.h" #include "types.h" #include "reader.h" #include "gram.h" @@ -38,13 +39,13 @@ print_derives (void) for (i = ntokens; i < nsyms; i++) { 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++) { short *rhsp; fprintf (stderr, "\t\t%d:", *sp); 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); } } diff --git a/src/gram.c b/src/gram.c index ffab36d3..c901c0be 100644 --- a/src/gram.c +++ b/src/gram.c @@ -67,7 +67,7 @@ ritem_print (FILE *out) fputs ("RITEM\n", out); for (i = 0; i < nritems; ++i) if (ritem[i] >= 0) - fprintf (out, " %s", tags[ritem[i]]); + fprintf (out, " %s", symbols[ritem[i]]->tag); else fprintf (out, " (rule %d)\n", -ritem[i] - 1); fputs ("\n\n", out); diff --git a/src/lalr.c b/src/lalr.c index 36a8607c..f7fead37 100644 --- a/src/lalr.c +++ b/src/lalr.c @@ -27,6 +27,7 @@ #include "reader.h" #include "types.h" #include "LR0.h" +#include "symtab.h" #include "gram.h" #include "complain.h" #include "lalr.h" @@ -566,7 +567,7 @@ lookaheads_print (FILE *out) for (k = 0; k < ntokens; ++k) if (BITISSET (LA (state_table[i]->lookaheadsp + j), j)) fprintf (out, " on %d (%s) -> rule %d\n", - k, tags[k], + k, symbols[k]->tag, -LAruleno[state_table[i]->lookaheadsp + j] - 1); } fprintf (out, "Lookaheads: END\n"); diff --git a/src/nullable.c b/src/nullable.c index 0b6d614f..082f2b32 100644 --- a/src/nullable.c +++ b/src/nullable.c @@ -25,7 +25,7 @@ #include "system.h" #include "getargs.h" -#include "reader.h" +#include "symtab.h" #include "types.h" #include "gram.h" #include "reduce.h" @@ -39,7 +39,7 @@ nullable_print (FILE *out) int i; fputs ("NULLABLE\n", out); 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); } diff --git a/src/output.c b/src/output.c index 94ad4256..fe029d41 100644 --- a/src/output.c +++ b/src/output.c @@ -98,6 +98,7 @@ #include "output.h" #include "lalr.h" #include "reader.h" +#include "symtab.h" #include "conflicts.h" #include "muscle_tab.h" @@ -252,7 +253,7 @@ output_rule_data (void) /* Be sure not to use twice the same quotearg slot. */ const char *cp = 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 and the space. */ int strsize = strlen (cp) + 2; @@ -1075,8 +1076,8 @@ yystype;\n\ for (i = ntokens; i < nsyms; i++) /* don't make these for dummy nonterminals made by gensym. */ - if (*tags[i] != '@') - fprintf (out, "# define NT%s\t%d\n", tags[i], i); + if (*symbols[i]->tag != '@') + fprintf (out, "# define NT%s\t%d\n", symbols[i]->tag, i); } fprintf (out, "\n#endif /* not %s */\n", macro_name); diff --git a/src/print.c b/src/print.c index 90685ba0..96c59fc7 100644 --- a/src/print.c +++ b/src/print.c @@ -22,6 +22,7 @@ #include "system.h" #include "quotearg.h" #include "files.h" +#include "symtab.h" #include "gram.h" #include "LR0.h" #include "lalr.h" @@ -92,15 +93,15 @@ print_core (FILE *out, state_t *state) 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++) - fprintf (out, "%s ", escape (tags[*sp])); + fprintf (out, "%s ", escape (symbols[*sp]->tag)); fputc ('.', out); for (/* Nothing */; *sp >= 0; ++sp) - fprintf (out, " %s", escape (tags[*sp])); + fprintf (out, " %s", escape (symbols[*sp]->tag)); fprintf (out, _(" (rule %d)"), rule - 1); fputc ('\n', out); @@ -124,7 +125,7 @@ print_shifts (FILE *out, state_t *state) int symbol = state_table[state1]->accessing_symbol; fprintf (out, _(" %-4s\tshift, and go to state %d\n"), - escape (tags[symbol]), state1); + escape (symbols[symbol]->tag), state1); } if (i > 0) @@ -141,7 +142,7 @@ print_errs (FILE *out, state_t *state) for (i = 0; i < errp->nerrs; ++i) if (errp->errs[i]) fprintf (out, _(" %-4s\terror (nonassociative)\n"), - escape (tags[errp->errs[i]])); + escape (symbols[errp->errs[i]]->tag)); if (i > 0) fputc ('\n', out); @@ -165,7 +166,7 @@ print_gotos (FILE *out, state_t *state) int state1 = shiftp->shifts[i]; int symbol = state_table[state1]->accessing_symbol; fprintf (out, _(" %-4s\tgo to state %d\n"), - escape (tags[symbol]), state1); + escape (symbols[symbol]->tag), state1); } fputc ('\n', out); @@ -189,7 +190,7 @@ print_reductions (FILE *out, state_t *state) int rule = redp->rules[0]; int symbol = rule_table[rule].lhs; fprintf (out, _(" $default\treduce using rule %d (%s)\n\n"), - rule - 1, escape (tags[symbol])); + rule - 1, escape (symbols[symbol]->tag)); return; } @@ -221,11 +222,11 @@ print_reductions (FILE *out, state_t *state) for (i = 0; i < ntokens; i++) if (BITISSET (lookaheadset, i)) fprintf (out, _(" %-4s\t[reduce using rule %d (%s)]\n"), - escape (tags[i]), default_rule - 1, - escape2 (tags[rule_table[default_rule].lhs])); + escape (symbols[i]->tag), default_rule - 1, + escape2 (symbols[rule_table[default_rule].lhs]->tag)); 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) { @@ -279,9 +280,9 @@ print_reductions (FILE *out, state_t *state) if (state->lookaheadsp + j != default_LA) fprintf (out, _(" %-4s\treduce using rule %d (%s)\n"), - escape (tags[i]), + escape (symbols[i]->tag), 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 defaulted = 1; @@ -292,15 +293,15 @@ print_reductions (FILE *out, state_t *state) if (defaulted) fprintf (out, _(" %-4s\treduce using rule %d (%s)\n"), - escape (tags[i]), + escape (symbols[i]->tag), LAruleno[default_LA] - 1, - escape2 (tags[rule_table[LAruleno[default_LA]].lhs])); + escape2 (symbols[rule_table[LAruleno[default_LA]].lhs]->tag)); defaulted = 0; fprintf (out, _(" %-4s\t[reduce using rule %d (%s)]\n"), - escape (tags[i]), + escape (symbols[i]->tag), 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) fprintf (out, _(" $default\treduce using rule %d (%s)\n"), 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) { 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]; if (*rule >= 0) while (*rule >= 0) - fprintf (out, " %s", escape (tags[*rule++])); + fprintf (out, " %s", escape (symbols[*rule++]->tag)); else fprintf (out, " /* %s */", _("empty")); fputc ('\n', out); @@ -394,8 +395,8 @@ print_grammar (FILE *out) if (token_translations[i] != 2) { buffer[0] = 0; - column = strlen (escape (tags[token_translations[i]])); - fputs (escape (tags[token_translations[i]]), out); + column = strlen (escape (symbols[token_translations[i]]->tag)); + fputs (escape (symbols[token_translations[i]]->tag), out); END_TEST (50); sprintf (buffer, " (%d)", i); @@ -430,8 +431,8 @@ print_grammar (FILE *out) } buffer[0] = 0; - fputs (escape (tags[i]), out); - column = strlen (escape (tags[i])); + fputs (escape (symbols[i]->tag), out); + column = strlen (escape (symbols[i]->tag)); sprintf (buffer, " (%d)", i); END_TEST (0); diff --git a/src/print_graph.c b/src/print_graph.c index 506d2113..dd271d78 100644 --- a/src/print_graph.c +++ b/src/print_graph.c @@ -21,6 +21,7 @@ #include "system.h" #include "quotearg.h" #include "files.h" +#include "symtab.h" #include "gram.h" #include "LR0.h" #include "lalr.h" @@ -77,15 +78,15 @@ print_core (state_t *state, struct obstack *node_obstack) if (i) obstack_1grow (node_obstack, '\n'); 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++) - obstack_fgrow1 (node_obstack, "%s ", escape (tags[*sp])); + obstack_fgrow1 (node_obstack, "%s ", escape (symbols[*sp]->tag)); obstack_1grow (node_obstack, '.'); 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; else edge.color = SHIFT_IS_SHIFT(shiftp, i) ? blue : green; - edge.label = escape (tags[symbol]); + edge.label = escape (symbols[symbol]->tag); output_edge (&edge, fgraph); close_edge (fgraph); } diff --git a/src/reader.c b/src/reader.c index c1cbb097..45b3eb73 100644 --- a/src/reader.c +++ b/src/reader.c @@ -52,7 +52,6 @@ typedef struct symbol_list } symbol_list; int lineno; -char **tags; short *user_toknums; static symbol_list *grammar; static int start_flag; @@ -1549,7 +1548,7 @@ token_translations_init (void) /* A token which translation has already been set? */ if (token_translations[bp->user_token_number] != 2) 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); token_translations[bp->user_token_number] = bp->value; } @@ -1568,7 +1567,6 @@ packsymbols (void) int tokno = 1; int last_user_token_number; - tags = XCALLOC (char *, nsyms + 1); user_toknums = XCALLOC (short, nsyms + 1); symbols = XCALLOC (bucket *, nsyms); @@ -1644,7 +1642,6 @@ packsymbols (void) } symbols[bp->value] = bp; - tags[bp->value] = bp->tag; user_toknums[bp->value] = bp->user_token_number; sassoc[bp->value] = bp->assoc; } diff --git a/src/reader.h b/src/reader.h index 3a0b4284..e4c77c2f 100644 --- a/src/reader.h +++ b/src/reader.h @@ -31,7 +31,6 @@ extern void reader PARAMS ((void)); extern int lineno; -extern char **tags; extern short *user_toknums; #endif /* !READER_H_ */ -- 2.45.2