#include "obstack.h"
#include "quotearg.h"
#include "getargs.h"
-#include "xalloc.h"
#include "files.h"
#include "gram.h"
#include "LR0.h"
#include "lalr.h"
#include "reader.h"
#include "conflicts.h"
-#include "macrotab.h"
+#include "muscle_tab.h"
extern void berror PARAMS((const char *));
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;
-struct obstack macro_obstack;
+struct obstack muscle_obstack;
struct obstack output_obstack;
/* 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);
- macro_insert ("translate", obstack_finish (&output_obstack));
+ 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);
- macro_insert ("prhs", obstack_finish (&output_obstack));
-
+ 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);
- macro_insert ("rhs", obstack_finish (&output_obstack));
+ muscle_insert ("rhs", obstack_finish (&output_obstack));
XFREE (yyrhs);
}
static void
output_stos (void)
{
- output_table_data (&output_obstack, accessing_symbol,
+ output_table_data (&output_obstack, accessing_symbol,
0, 1, nstates);
- macro_insert ("stos", obstack_finish (&output_obstack));
+ muscle_insert ("stos", obstack_finish (&output_obstack));
}
output_table_data (&output_obstack, rline,
0, 1, nrules + 1);
- macro_insert ("rline", obstack_finish (&output_obstack));
+ muscle_insert ("rline", obstack_finish (&output_obstack));
j = 0;
for (i = 0; i < nsyms; i++)
/* Finish table and store. */
obstack_1grow (&output_obstack, 0);
- macro_insert ("tname", obstack_finish (&output_obstack));
+ muscle_insert ("tname", obstack_finish (&output_obstack));
/* Output YYTOKNUM. */
output_table_data (&output_obstack, user_toknums,
0, 1, ntokens + 1);
- macro_insert ("toknum", 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);
- macro_insert ("r1", obstack_finish (&output_obstack));
+ muscle_insert ("r1", obstack_finish (&output_obstack));
XFREE (rlhs + 1);
/* Output YYR2. */
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);
- macro_insert ("r2", obstack_finish (&output_obstack));
+ muscle_insert ("r2", obstack_finish (&output_obstack));
XFREE (short_tab);
XFREE (rrhs + 1);
save_row (i);
}
- output_table_data (&output_obstack, yydefact,
+ output_table_data (&output_obstack, yydefact,
yydefact[0], 1, nstates);
- macro_insert ("defact", obstack_finish (&output_obstack));
-
+ 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);
- macro_insert ("defgoto", obstack_finish (&output_obstack));
+ muscle_insert ("defgoto", obstack_finish (&output_obstack));
XFREE (state_count);
XFREE (yydefgoto);
output_base (void)
{
/* Output pact. */
- output_table_data (&output_obstack, base,
+ output_table_data (&output_obstack, base,
base[0], 1, nstates);
- macro_insert ("pact", obstack_finish (&output_obstack));
+ 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);
- macro_insert ("pgoto", obstack_finish (&output_obstack));
+ muscle_insert ("pgoto", obstack_finish (&output_obstack));
XFREE (base);
}
static void
output_table (void)
{
- output_table_data (&output_obstack, table,
+ output_table_data (&output_obstack, table,
table[0], 1, high + 1);
- macro_insert ("table", obstack_finish (&output_obstack));
+ 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);
- macro_insert ("check", obstack_finish (&output_obstack));
+ 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;
- int actions_dumped = 0;
- /* 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 macro. */
- const char *macro_key = 0;
- const char *macro_value = 0;
+ /* Read the muscle. */
+ const char *muscle_key = 0;
+ const char *muscle_value = 0;
+
while (isalnum (c = getc (fskel)) || c == '_')
- obstack_1grow (¯o_obstack, c);
- obstack_1grow (¯o_obstack, 0);
+ obstack_1grow (&muscle_obstack, c);
+ obstack_1grow (&muscle_obstack, 0);
/* Output the right value, or see if it's something special. */
- macro_key = obstack_finish (¯o_obstack);
- macro_value = macro_find (macro_key);
- if (macro_value)
- obstack_sgrow (&table_obstack, macro_value);
- else if (!strcmp (macro_key, "line"))
- obstack_fgrow1 (&table_obstack, "%d", line + 1);
- else if (!strcmp (macro_key, "action"))
- {
- size_t size = obstack_object_size (&action_obstack);
- obstack_grow (&table_obstack,
- obstack_finish (&action_obstack), size);
- }
+ muscle_key = obstack_finish (&muscle_obstack);
+ muscle_value = muscle_find (muscle_key);
+ if (muscle_value)
+ obstack_sgrow (oout, muscle_value);
+ else if (!strcmp (muscle_key, "line"))
+ 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, macro_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)
{
/* FIXME. */
-#define MACRO_INSERT_INT(Key, Value) \
-{ \
- obstack_fgrow1 (¯o_obstack, "%d", Value); \
- obstack_1grow (¯o_obstack, 0); \
- macro_insert (Key, obstack_finish (¯o_obstack)); \
+#define MUSCLE_INSERT_INT(Key, Value) \
+{ \
+ obstack_fgrow1 (&muscle_obstack, "%d", Value); \
+ obstack_1grow (&muscle_obstack, 0); \
+ muscle_insert (Key, obstack_finish (&muscle_obstack)); \
}
-#define MACRO_INSERT_STRING(Key, Value) \
-{ \
- obstack_sgrow (¯o_obstack, Value); \
- obstack_1grow (¯o_obstack, 0); \
- macro_insert (Key, obstack_finish (¯o_obstack)); \
+#define MUSCLE_INSERT_STRING(Key, Value) \
+{ \
+ obstack_sgrow (&muscle_obstack, Value); \
+ obstack_1grow (&muscle_obstack, 0); \
+ muscle_insert (Key, obstack_finish (&muscle_obstack)); \
}
-#define MACRO_INSERT_PREFIX(Key, Value) \
+#define MUSCLE_INSERT_PREFIX(Key, Value) \
{ \
- obstack_fgrow2 (¯o_obstack, "%s%s", spec_name_prefix, Value); \
- obstack_1grow (¯o_obstack, 0); \
- macro_insert (Key, obstack_finish (¯o_obstack)); \
+ obstack_fgrow2 (&muscle_obstack, "%s%s", spec_name_prefix, Value); \
+ obstack_1grow (&muscle_obstack, 0); \
+ muscle_insert (Key, obstack_finish (&muscle_obstack)); \
}
static void
prepare (void)
{
- MACRO_INSERT_INT ("last", high);
- MACRO_INSERT_INT ("flag", MINSHORT);
- MACRO_INSERT_INT ("pure", pure_parser);
- MACRO_INSERT_INT ("nsym", nsyms);
- MACRO_INSERT_INT ("debug", debug_flag);
- MACRO_INSERT_INT ("final", final_state);
- MACRO_INSERT_INT ("maxtok", max_user_token_number);
- MACRO_INSERT_INT ("ntbase", ntokens);
- MACRO_INSERT_INT ("verbose", 0);
-
- MACRO_INSERT_INT ("nnts", nvars);
- MACRO_INSERT_INT ("nrules", nrules);
- MACRO_INSERT_INT ("nstates", nstates);
- MACRO_INSERT_INT ("ntokens", ntokens);
-
- MACRO_INSERT_INT ("locations_flag", locations_flag);
+ MUSCLE_INSERT_INT ("last", high);
+ MUSCLE_INSERT_INT ("flag", MINSHORT);
+ MUSCLE_INSERT_INT ("pure", pure_parser);
+ MUSCLE_INSERT_INT ("nsym", nsyms);
+ MUSCLE_INSERT_INT ("debug", debug_flag);
+ MUSCLE_INSERT_INT ("final", final_state);
+ MUSCLE_INSERT_INT ("maxtok", max_user_token_number);
+ MUSCLE_INSERT_INT ("ntbase", ntokens);
+ MUSCLE_INSERT_INT ("verbose", 0);
+
+ MUSCLE_INSERT_INT ("nnts", nvars);
+ MUSCLE_INSERT_INT ("nrules", nrules);
+ MUSCLE_INSERT_INT ("nstates", nstates);
+ MUSCLE_INSERT_INT ("ntokens", ntokens);
+
+ 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)
- MACRO_INSERT_STRING ("prefix", spec_name_prefix);
+ MUSCLE_INSERT_STRING ("prefix", spec_name_prefix);
}
/*----------------------------------------------------------.
{
obstack_init (&output_obstack);
-#if 0
- reader_output_yylsp (&table_obstack); */
-#endif
free_itemsets ();
output_token_translations ();
output_stos ();
output_rule_data ();
output_actions ();
-
+
#if 0
if (!no_parser_flag) */
#endif
prepare ();
/* Copy definitions in directive. */
- macro_insert ("prologue", obstack_finish (&attrs_obstack));
- output_parser ();
+ muscle_insert ("prologue", obstack_finish (&attrs_obstack));
+
+ output_master_parser ();
- obstack_free (¯o_obstack, 0);
+ obstack_free (&muscle_obstack, 0);
obstack_free (&output_obstack, 0);
+ obstack_free (&action_obstack, 0);
}