Be sure never to walk through RITEMS, but use only data related to

the rules themselves. RITEMS should be banished.
* src/output.c (output_token_translations): Rename as...
(prepare_tokens): this.
In addition to `translate', prepare the muscles `tname' and
`toknum', which were handled by...
(output_rule_data): this.
Remove, and move the remainder of its outputs into...
(prepare_rules): this new routines, which also merges content from
(output_gram): this.
(prepare_rules): Be sure never to walk through RITEMS.
(output_stos): Rename as...
(prepare_stos): this.
(output): Always invoke prepare_states, after all, just don't use it
in the output if you don't need it.
This commit is contained in:
Akim Demaille
2002-04-07 17:40:56 +00:00
parent 643a599471
commit b0940840ac
2 changed files with 130 additions and 126 deletions

View File

@@ -1,3 +1,22 @@
2002-04-07 Akim Demaille <akim@epita.fr>
Be sure never to walk through RITEMS, but use only data related to
the rules themselves. RITEMS should be banished.
* src/output.c (output_token_translations): Rename as...
(prepare_tokens): this.
In addition to `translate', prepare the muscles `tname' and
`toknum', which were handled by...
(output_rule_data): this.
Remove, and move the remainder of its outputs into...
(prepare_rules): this new routines, which also merges content from
(output_gram): this.
(prepare_rules): Be sure never to walk through RITEMS.
(output_stos): Rename as...
(prepare_stos): this.
(output): Always invoke prepare_states, after all, just don't use it
in the output if you don't need it.
2002-04-07 Akim Demaille <akim@epita.fr> 2002-04-07 Akim Demaille <akim@epita.fr>
* src/LR0.c (new_state): Display `nstates' as the name of the * src/LR0.c (new_state): Display `nstates' as the name of the

View File

@@ -176,96 +176,29 @@ output_table_data (struct obstack *oout,
} }
/*-----------------------------------------------------------------.
| Prepare the muscles related to the tokens: translate, tname, and |
| toknum. |
`-----------------------------------------------------------------*/
static void static void
output_token_translations (void) prepare_tokens (void)
{ {
output_table_data (&format_obstack, token_translations, output_table_data (&format_obstack, token_translations,
0, 1, max_user_token_number + 1); 0, 1, max_user_token_number + 1);
muscle_insert ("translate", obstack_finish (&format_obstack)); muscle_insert ("translate", obstack_finish (&format_obstack));
XFREE (token_translations); XFREE (token_translations);
}
static void
output_gram (void)
{
{ {
int i; int i;
short *values = XCALLOC (short, nrules + 1); int j = 0;
for (i = 1; i < nrules + 1; ++i)
values[i] = rules[i].rhs - ritem;
output_table_data (&format_obstack, values,
0, 1, nrules + 1);
XFREE (values);
}
muscle_insert ("prhs", obstack_finish (&format_obstack));
{
short *rhsp;
int r;
int i = 0;
short *yyrhs = XMALLOC (short, nritems);
for (r = 1; r < nrules + 1; ++r)
{
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
yyrhs[i++] = *rhsp;
yyrhs[i++] = -1;
}
assert (i == nritems);
output_table_data (&format_obstack, yyrhs,
ritem[0], 1, nritems);
muscle_insert ("rhs", obstack_finish (&format_obstack));
XFREE (yyrhs);
}
#if 0
if (!semantic_parser)
obstack_sgrow (&table_obstack, "\n#endif\n");
#endif
}
static void
output_stos (void)
{
size_t i;
short *values = (short *) alloca (sizeof (short) * nstates);
for (i = 0; i < nstates; ++i)
values[i] = states[i]->accessing_symbol;
output_table_data (&format_obstack, values,
0, 1, nstates);
muscle_insert ("stos", obstack_finish (&format_obstack));
}
static void
output_rule_data (void)
{
int i;
int j;
short *short_tab = NULL;
{
short *values = XCALLOC (short, nrules + 1);
for (i = 1; i < nrules + 1; ++i)
values[i] = rules[i].line;
output_table_data (&format_obstack, values,
0, 1, nrules + 1);
muscle_insert ("rline", obstack_finish (&format_obstack));
XFREE (values);
}
j = 0;
for (i = 0; i < nsyms; i++) for (i = 0; i < nsyms; i++)
{ {
/* Be sure not to use twice the same quotearg slot. */ /* Be sure not to use twice the same quotearg slot. */
const char *cp = const char *cp =
quotearg_n_style (1, c_quoting_style, quotearg_n_style (1, c_quoting_style,
quotearg_style (escape_quoting_style, symbols[i]->tag)); quotearg_style (escape_quoting_style,
symbols[i]->tag));
/* Width of the next token, including the two quotes, the coma /* Width of the next token, including the two quotes, the coma
and the space. */ and the space. */
int strsize = strlen (cp) + 2; int strsize = strlen (cp) + 2;
@@ -287,41 +220,94 @@ output_rule_data (void)
/* Finish table and store. */ /* Finish table and store. */
obstack_1grow (&format_obstack, 0); obstack_1grow (&format_obstack, 0);
muscle_insert ("tname", obstack_finish (&format_obstack)); muscle_insert ("tname", obstack_finish (&format_obstack));
}
/* Output YYTOKNUM. */ /* Output YYTOKNUM. */
{ {
int i;
short *values = XCALLOC (short, ntokens + 1); short *values = XCALLOC (short, ntokens + 1);
for (i = 0; i < ntokens + 1; ++i) for (i = 0; i < ntokens + 1; ++i)
values[i] = symbols[i]->user_token_number; values[i] = symbols[i]->user_token_number;
output_table_data (&format_obstack, values, output_table_data (&format_obstack, values,
0, 1, ntokens + 1); 0, 1, ntokens + 1);
muscle_insert ("toknum", obstack_finish (&format_obstack)); muscle_insert ("toknum", obstack_finish (&format_obstack));
XFREE (values); free (values);
}
} }
/* Output YYR1. */ /*-------------------------------------------------------------.
| Prepare the muscles related to the rules: rhs, prhs, r1, r2, |
| rline. |
`-------------------------------------------------------------*/
static void
prepare_rules (void)
{ {
short *values = XCALLOC (short, nrules + 1); short *rhsp;
for (i = 1; i < nrules + 1; ++i) int r;
values[i] = rules[i].lhs->number; int i = 0;
output_table_data (&format_obstack, values, short *rhs = XMALLOC (short, nritems);
0, 1, nrules + 1); short *prhs = XMALLOC (short, nrules + 1);
short *r1 = XMALLOC (short, nrules + 1);
short *r2 = XMALLOC (short, nrules + 1);
short *rline = XMALLOC (short, nrules + 1);
for (r = 1; r < nrules + 1; ++r)
{
/* Index of rule R in RHS. */
prhs[r] = i;
/* RHS of the rule R. */
for (rhsp = rules[r].rhs; *rhsp >= 0; ++rhsp)
rhs[i++] = *rhsp;
/* LHS of the rule R. */
r1[r] = rules[r].lhs->number;
/* Length of rule R's RHS. */
r2[r] = i - prhs[r];
/* Separator in RHS. */
rhs[i++] = -1;
/* Line where rule was defined. */
rline[r] = rules[r].line;
}
assert (i == nritems);
output_table_data (&format_obstack, rhs, ritem[0], 1, nritems);
muscle_insert ("rhs", obstack_finish (&format_obstack));
output_table_data (&format_obstack, prhs, 0, 1, nrules + 1);
muscle_insert ("prhs", obstack_finish (&format_obstack));
output_table_data (&format_obstack, rline, 0, 1, nrules + 1);
muscle_insert ("rline", obstack_finish (&format_obstack));
output_table_data (&format_obstack, r1, 0, 1, nrules + 1);
muscle_insert ("r1", obstack_finish (&format_obstack)); muscle_insert ("r1", obstack_finish (&format_obstack));
XFREE (values);
output_table_data (&format_obstack, r2, 0, 1, nrules + 1);
muscle_insert ("r2", obstack_finish (&format_obstack));
free (rhs);
free (prhs);
free (r2);
} }
/* Output YYR2. */ /*--------------------------------------------.
short_tab = XMALLOC (short, nrules + 1); | Prepare the muscles related to the states. |
for (i = 1; i < nrules; i++) `--------------------------------------------*/
short_tab[i] = rules[i + 1].rhs - rules[i].rhs - 1;
short_tab[nrules] = nritems - (rules[nrules].rhs - ritem) - 1; static void
output_table_data (&format_obstack, short_tab, prepare_states (void)
0, 1, nrules + 1); {
muscle_insert ("r2", obstack_finish (&format_obstack)); size_t i;
XFREE (short_tab); short *values = (short *) alloca (sizeof (short) * nstates);
for (i = 0; i < nstates; ++i)
values[i] = states[i]->accessing_symbol;
output_table_data (&format_obstack, values,
0, 1, nstates);
muscle_insert ("stos", obstack_finish (&format_obstack));
} }
/*------------------------------------------------------------------. /*------------------------------------------------------------------.
| Decide what to do for each type of token if seen as the lookahead | | Decide what to do for each type of token if seen as the lookahead |
| token in specified state. The value returned is used as the | | token in specified state. The value returned is used as the |
@@ -914,8 +900,10 @@ output_check (void)
XFREE (check); XFREE (check);
} }
/* compute and output yydefact, yydefgoto, yypact, yypgoto, yytable /*-----------------------------------------------------------------.
and yycheck. */ | Compute and output yydefact, yydefgoto, yypact, yypgoto, yytable |
| and yycheck. |
`-----------------------------------------------------------------*/
static void static void
output_actions (void) output_actions (void)
@@ -1087,12 +1075,9 @@ output (void)
{ {
obstack_init (&format_obstack); obstack_init (&format_obstack);
output_token_translations (); prepare_tokens ();
output_gram (); prepare_rules ();
prepare_states ();
if (semantic_parser)
output_stos ();
output_rule_data ();
output_actions (); output_actions ();
prepare (); prepare ();