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);
int i;
short *values = (short *) alloca (sizeof (short) * nstates);
for (i = 0; i < nstates; ++i)
- values[i] = state_table[i]->accessing_symbol;
+ values[i] = states[i]->accessing_symbol;
output_table_data (&format_obstack, values,
0, 1, nstates);
muscle_insert ("stos", obstack_finish (&format_obstack));
{
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));
{
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));
/* 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));
if (!shift_state)
continue;
- symbol = state_table[shift_state]->accessing_symbol;
+ symbol = states[shift_state]->accessing_symbol;
if (ISVAR (symbol))
break;
actrow = XCALLOC (short, ntokens);
for (i = 0; i < nstates; ++i)
{
- yydefact[i] = action_row (state_table[i]);
+ yydefact[i] = action_row (states[i]);
save_row (i);
}
{
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. */
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);
}
}
{
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;
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);
}
}
+/*---------------------------------------.
+| Output the tokens definition to OOUT. |
+`---------------------------------------*/
+
+static void
+token_definitions_output (FILE *out, size_t *line)
+{
+ int i;
+ for (i = 0; i < ntokens; ++i)
+ {
+ bucket *symbol = symbols[i];
+ int number = symbol->user_token_number;
+
+ if (number == SALIAS)
+ continue;
+ /* Skip error token. */
+ if (symbol->value == error_token_number)
+ continue;
+ if (symbol->tag[0] == '\'')
+ continue; /* skip literal character */
+ if (symbol->tag[0] == '\"')
+ {
+ /* use literal string only if given a symbol with an alias */
+ if (symbol->alias)
+ symbol = symbol->alias;
+ else
+ continue;
+ }
+
+ /* Don't #define nonliteral tokens whose names contain periods
+ or '$' (as does the default value of the EOF token). */
+ if (strchr (symbol->tag, '.') || strchr (symbol->tag, '$'))
+ continue;
+
+ fprintf (out, "# define %s\t%d\n",
+ symbol->tag, number);
+ ++*line;
+ if (semantic_parser)
+ {
+ /* FIXME: This is probably wrong, and should be just as
+ above. --akim. */
+ fprintf (out, "# define T%s\t%d\n", symbol->tag, symbol->value);
+ ++*line;
+ }
+ }
+}
+
+
static void
save_column (int symbol, int default_state)
{
for (i = 0; i < nstates; ++i)
{
- free (state_table[i]->shifts);
- XFREE (state_table[i]->reductions);
- free (state_table[i]->errs);
- free (state_table[i]);
+ free (states[i]->shifts);
+ XFREE (states[i]->reductions);
+ free (states[i]->errs);
+ free (states[i]);
}
- XFREE (state_table);
+ XFREE (states);
}
\f
guards_output (out, &output_line);
else if (!strcmp (muscle_key, "line"))
fprintf (out, "%d", output_line);
+ else if (!strcmp (muscle_key, "tokendef"))
+ token_definitions_output (out, &output_line);
else if (!strcmp (muscle_key, "skeleton-line"))
fprintf (out, "%d", skeleton_line);
else if (muscle_value)
#define MUSCLE_INSERT_PREFIX(Key, Value) \
{ \
- obstack_fgrow2 (&muscle_obstack, "%s%s", spec_name_prefix, Value); \
+ obstack_fgrow2 (&muscle_obstack, "%s%s", \
+ spec_name_prefix ? spec_name_prefix : "yy", Value); \
obstack_1grow (&muscle_obstack, 0); \
muscle_insert (Key, obstack_finish (&muscle_obstack)); \
}
MUSCLE_INSERT_INT ("final", final_state);
MUSCLE_INSERT_INT ("maxtok", max_user_token_number);
MUSCLE_INSERT_INT ("error-verbose", error_verbose);
- MUSCLE_INSERT_STRING ("prefix", spec_name_prefix);
+ MUSCLE_INSERT_STRING ("prefix", spec_name_prefix ? spec_name_prefix : "yy");
MUSCLE_INSERT_INT ("nnts", nvars);
MUSCLE_INSERT_INT ("nrules", nrules);
static void
header_output (void)
{
+ size_t dummy_line;
FILE *out = xfopen (spec_defines_file, "w");
char *macro_name = compute_header_macro ();
fprintf (out, "#ifndef %s\n", macro_name);
fprintf (out, "# define %s\n\n", macro_name);
- fputs (muscle_find ("tokendef"), out);
+ token_definitions_output (out, &dummy_line);
fprintf (out, "\
#ifndef YYSTYPE\n\
typedef %s
if (!pure_parser)
fprintf (out, "\nextern YYSTYPE %slval;\n",
- spec_name_prefix);
+ spec_name_prefix ? spec_name_prefix : "yy");
+
+ if (locations_flag)
+ {
+ fputs ("\n\n", out);
+ fprintf (out, "\
+#ifndef YYLTYPE\n\
+typedef struct yyltype\n\
+{\n\
+ int first_line;\n\
+ int first_column;\n\
+ int last_line;\n\
+ int last_column;\n\
+} yyltype;\n\
+# define YYLTYPE yyltype\n\
+#endif\n");
+ if (!pure_parser)
+ fprintf (out, "\nextern YYLTYPE %slloc;\n",
+ spec_name_prefix ? spec_name_prefix : "yy");
+ }
+
if (semantic_parser)
{
int i;
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);