#include "obstack.h"
#include "quotearg.h"
#include "getargs.h"
-#include "xalloc.h"
#include "files.h"
#include "gram.h"
#include "LR0.h"
static int nvectors;
static int nentries;
-static short **froms;
-static short **tos;
-static short *tally;
-static short *width;
-static short *actrow;
-static short *state_count;
-static short *order;
-static short *base;
-static short *pos;
-static short *table;
-static short *check;
+static short **froms = NULL;
+static short **tos = NULL;
+static short *tally = NULL;
+static short *width = NULL;
+static short *actrow = NULL;
+static short *state_count = NULL;
+static short *order = NULL;
+static short *base = NULL;
+static short *pos = NULL;
+static short *table = NULL;
+static short *check = NULL;
static int lowzero;
static int high;
/* FIXME. */
static inline void
-output_table_data (struct obstack *oout,
- short *table_data,
- short first,
- short begin,
+output_table_data (struct obstack *oout,
+ short *table_data,
+ short first,
+ short begin,
short end)
{
int i;
int j = 1;
-
+
obstack_fgrow1 (oout, "%6d", first);
for (i = begin; i < end; ++i)
{
static void
output_token_translations (void)
{
- output_table_data (&output_obstack, token_translations,
+ output_table_data (&output_obstack, token_translations,
0, 1, max_user_token_number + 1);
muscle_insert ("translate", obstack_finish (&output_obstack));
+ XFREE (token_translations);
}
static void
output_gram (void)
{
- output_table_data (&output_obstack, rrhs,
+ output_table_data (&output_obstack, rrhs,
0, 1, nrules + 1);
muscle_insert ("prhs", obstack_finish (&output_obstack));
-
+
{
size_t yyrhs_size = 1;
short *yyrhs, *sp;
for (sp = ritem + 1, i = 1; *sp; ++sp, ++i)
yyrhs[i] = *sp > 0 ? *sp : 0;
- output_table_data (&output_obstack, yyrhs,
+ output_table_data (&output_obstack, yyrhs,
ritem[0], 1, yyrhs_size);
muscle_insert ("rhs", obstack_finish (&output_obstack));
static void
output_stos (void)
{
- output_table_data (&output_obstack, accessing_symbol,
+ output_table_data (&output_obstack, accessing_symbol,
0, 1, nstates);
muscle_insert ("stos", obstack_finish (&output_obstack));
}
muscle_insert ("toknum", obstack_finish (&output_obstack));
/* Output YYR1. */
- output_table_data (&output_obstack, rlhs,
+ output_table_data (&output_obstack, rlhs,
0, 1, nrules + 1);
muscle_insert ("r1", obstack_finish (&output_obstack));
XFREE (rlhs + 1);
for (i = 1; i < nrules; i++)
short_tab[i] = rrhs[i + 1] - rrhs[i] - 1;
short_tab[nrules] = nitems - rrhs[nrules] - 1;
- output_table_data (&output_obstack, short_tab,
+ output_table_data (&output_obstack, short_tab,
0, 1, nrules + 1);
muscle_insert ("r2", obstack_finish (&output_obstack));
XFREE (short_tab);
save_row (i);
}
- output_table_data (&output_obstack, yydefact,
+ output_table_data (&output_obstack, yydefact,
yydefact[0], 1, nstates);
muscle_insert ("defact", obstack_finish (&output_obstack));
-
+
XFREE (actrow);
XFREE (yydefact);
}
yydefgoto[i - ntokens] = default_state;
}
- output_table_data (&output_obstack, yydefgoto,
+ output_table_data (&output_obstack, yydefgoto,
yydefgoto[0], 1, nsyms - ntokens);
muscle_insert ("defgoto", obstack_finish (&output_obstack));
output_base (void)
{
/* Output pact. */
- output_table_data (&output_obstack, base,
+ output_table_data (&output_obstack, base,
base[0], 1, nstates);
muscle_insert ("pact", obstack_finish (&output_obstack));
/* Output pgoto. */
- output_table_data (&output_obstack, base,
+ output_table_data (&output_obstack, base,
base[nstates], nstates + 1, nvectors);
muscle_insert ("pgoto", obstack_finish (&output_obstack));
static void
output_table (void)
{
- output_table_data (&output_obstack, table,
+ output_table_data (&output_obstack, table,
table[0], 1, high + 1);
muscle_insert ("table", obstack_finish (&output_obstack));
XFREE (table);
static void
output_check (void)
{
- output_table_data (&output_obstack, check,
+ output_table_data (&output_obstack, check,
check[0], 1, high + 1);
muscle_insert ("check", obstack_finish (&output_obstack));
XFREE (check);
output_check ();
}
-/*------------------------------------------.
-| Copy the parser code into TABLE_OBSTACK. |
-`------------------------------------------*/
+\f
+/*------------------------------------------------------------.
+| Copy the parser code from SKEL_FILENAME into OOUT obstack. |
+| and do the muscle substitution. |
+`------------------------------------------------------------*/
static void
-output_parser (void)
+output_parser (const char *skel_filename, struct obstack *oout)
{
int c;
FILE *fskel;
size_t line;
- /* Loop over lines in the standard parser file. */
- if (!skeleton)
- {
- if (semantic_parser)
- skeleton = skeleton_find ("BISON_HAIRY", BISON_HAIRY);
- else
- skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE);
- }
- fskel = xfopen (skeleton, "r");
+ fskel = xfopen (skel_filename, "r");
/* New output code. */
line = 1;
{
if (c == '\n')
++line;
- obstack_1grow (&table_obstack, c);
+ obstack_1grow (oout, c);
c = getc (fskel);
}
else if ((c = getc (fskel)) == '%')
/* Read the muscle. */
const char *muscle_key = 0;
const char *muscle_value = 0;
+
while (isalnum (c = getc (fskel)) || c == '_')
obstack_1grow (&muscle_obstack, c);
obstack_1grow (&muscle_obstack, 0);
muscle_key = obstack_finish (&muscle_obstack);
muscle_value = muscle_find (muscle_key);
if (muscle_value)
- obstack_sgrow (&table_obstack, muscle_value);
+ obstack_sgrow (oout, muscle_value);
else if (!strcmp (muscle_key, "line"))
- obstack_fgrow1 (&table_obstack, "%d", line + 1);
- else if (!strcmp (muscle_key, "action"))
- {
- size_t size = obstack_object_size (&action_obstack);
- obstack_grow (&table_obstack,
- obstack_finish (&action_obstack), size);
- }
+ obstack_fgrow1 (oout, "%d", line + 1);
+ else if (!strcmp (muscle_key, "input_line"))
+ obstack_fgrow1 (oout, "%d", lineno);
+ /* FIXME: Insert the code to recognize %%sub-skeleton for exemple. */
else
{
- obstack_sgrow (&table_obstack, "%%");
- obstack_sgrow (&table_obstack, muscle_key);
+ obstack_sgrow (oout, "%%");
+ obstack_sgrow (oout, muscle_key);
}
}
else
- obstack_1grow (&table_obstack, '%');
+ obstack_1grow (oout, '%');
}
/* End. */
xfclose (fskel);
}
+/*----------------------------------------.
+| Prepare the master parser to be output |
+`----------------------------------------*/
+
+static void
+output_master_parser (void)
+{
+ if (!skeleton)
+ {
+ if (semantic_parser)
+ skeleton = skeleton_find ("BISON_HAIRY", BISON_HAIRY);
+ else
+ skeleton = skeleton_find ("BISON_SIMPLE", BISON_SIMPLE);
+ }
+ output_parser (skeleton, &table_obstack);
+}
+
+
static void
free_itemsets (void)
{
MUSCLE_INSERT_INT ("locations_flag", locations_flag);
+ /* We need to save the actions in the muscle %%action. */
+ muscle_insert ("action", obstack_finish (&action_obstack));
+
if (spec_name_prefix)
MUSCLE_INSERT_STRING ("prefix", spec_name_prefix);
}
output_stos ();
output_rule_data ();
output_actions ();
-
+
#if 0
if (!no_parser_flag) */
#endif
prepare ();
/* Copy definitions in directive. */
muscle_insert ("prologue", obstack_finish (&attrs_obstack));
- output_parser ();
+
+ output_master_parser ();
obstack_free (&muscle_obstack, 0);
obstack_free (&output_obstack, 0);
+ obstack_free (&action_obstack, 0);
}