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));
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);
}
}
+/*---------------------------------------.
+| 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;