X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/9e7f6bbd5930d4d7365f65d33721cfbf651ca487..b9f71f19cc20de68101ba1a9ae60753558247eca:/src/output.c diff --git a/src/output.c b/src/output.c index 94ad4256..3a8bc994 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" @@ -184,7 +185,7 @@ output_gram (void) int i; short *values = XCALLOC (short, nrules + 1); for (i = 0; i < nrules + 1; ++i) - values[i] = rule_table[i].rhs; + values[i] = rules[i].rhs; output_table_data (&format_obstack, values, 0, 1, nrules + 1); XFREE (values); @@ -238,7 +239,7 @@ output_rule_data (void) { short *values = XCALLOC (short, nrules + 1); for (i = 0; i < nrules + 1; ++i) - values[i] = rule_table[i].line; + values[i] = rules[i].line; output_table_data (&format_obstack, values, 0, 1, nrules + 1); muscle_insert ("rline", obstack_finish (&format_obstack)); @@ -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; @@ -275,15 +276,22 @@ output_rule_data (void) muscle_insert ("tname", obstack_finish (&format_obstack)); /* Output YYTOKNUM. */ - output_table_data (&format_obstack, user_toknums, - 0, 1, ntokens + 1); - muscle_insert ("toknum", obstack_finish (&format_obstack)); + { + short *values = XCALLOC (short, ntokens + 1); + for (i = 0; i < ntokens + 1; ++i) + values[i] = symbols[i]->user_token_number; + output_table_data (&format_obstack, values, + 0, 1, ntokens + 1); + muscle_insert ("toknum", obstack_finish (&format_obstack)); + XFREE (values); + } + /* Output YYR1. */ { short *values = XCALLOC (short, nrules + 1); for (i = 0; i < nrules + 1; ++i) - values[i] = rule_table[i].lhs; + values[i] = rules[i].lhs; output_table_data (&format_obstack, values, 0, 1, nrules + 1); muscle_insert ("r1", obstack_finish (&format_obstack)); @@ -293,8 +301,8 @@ output_rule_data (void) /* Output YYR2. */ short_tab = XMALLOC (short, nrules + 1); for (i = 1; i < nrules; i++) - short_tab[i] = rule_table[i + 1].rhs - rule_table[i].rhs - 1; - short_tab[nrules] = nritems - rule_table[nrules].rhs - 1; + short_tab[i] = rules[i + 1].rhs - rules[i].rhs - 1; + short_tab[nrules] = nritems - rules[nrules].rhs - 1; output_table_data (&format_obstack, short_tab, 0, 1, nrules + 1); muscle_insert ("r2", obstack_finish (&format_obstack)); @@ -500,20 +508,20 @@ actions_output (FILE *out, size_t *line) { int rule; for (rule = 1; rule < nrules + 1; ++rule) - if (rule_table[rule].action) + if (rules[rule].action) { fprintf (out, " case %d:\n", rule); if (!no_lines_flag) fprintf (out, muscle_find ("linef"), - rule_table[rule].action_line, + rules[rule].action_line, quotearg_style (c_quoting_style, muscle_find ("filename"))); /* As a Bison extension, add the ending semicolon. Since some Yacc don't do that, help people using bison as a Yacc finding their missing semicolons. */ fprintf (out, "{ %s%s }\n break;\n\n", - rule_table[rule].action, + rules[rule].action, yacc_flag ? ";" : ""); /* We always output 4 '\n' per action. */ @@ -522,7 +530,7 @@ actions_output (FILE *out, size_t *line) if (!no_lines_flag) ++*line; /* Get the number of lines written by the user. */ - *line += get_lines_number (rule_table[rule].action); + *line += get_lines_number (rules[rule].action); } } @@ -536,17 +544,17 @@ guards_output (FILE *out, size_t *line) { int rule; for (rule = 1; rule < nrules + 1; ++rule) - if (rule_table[rule].action) + if (rules[rule].action) { fprintf (out, " case %d:\n", rule); if (!no_lines_flag) fprintf (out, muscle_find ("linef"), - rule_table[rule].guard_line, + rules[rule].guard_line, quotearg_style (c_quoting_style, muscle_find ("filename"))); fprintf (out, "{ %s; }\n break;\n\n", - rule_table[rule].guard); + rules[rule].guard); /* We always output 4 '\n' per action. */ *line += 4; @@ -554,7 +562,7 @@ guards_output (FILE *out, size_t *line) if (!no_lines_flag) ++*line; /* Get the number of lines written by the user. */ - *line += get_lines_number (rule_table[rule].guard); + *line += get_lines_number (rules[rule].guard); } } @@ -1075,8 +1083,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); @@ -1101,7 +1109,6 @@ output (void) if (semantic_parser) output_stos (); output_rule_data (); - XFREE (user_toknums); output_actions (); prepare (); @@ -1115,7 +1122,7 @@ output (void) if (defines_flag) header_output (); - free (rule_table + 1); + free (rules + 1); obstack_free (&muscle_obstack, NULL); obstack_free (&format_obstack, NULL); obstack_free (&action_obstack, NULL);