`------------------------------------------------------------------*/
static int
-action_row (int state)
+action_row (state_t *state)
{
int i;
- int m = 0;
- int n = 0;
int default_rule = 0;
- reductions *redp = state_table[state]->reductions;
+ reductions *redp = state->reductions;
int nreds = redp ? redp->nreds : 0;
- shifts *shiftp = state_table[state]->shifts;
- errs *errp = state_table[state]->errs;
+ shifts *shiftp = state->shifts;
+ errs *errp = state->errs;
/* set nonzero to inhibit having any default reduction */
int nodefault = 0;
int j;
/* loop over all the rules available here which require
lookahead */
- m = state_table[state]->lookaheadsp;
- n = state_table[state + 1]->lookaheadsp;
-
- for (i = n - 1; i >= m; i--)
+ for (i = state->nlookaheads - 1; i >= 0; --i)
/* and find each token which the rule finds acceptable
to come next */
for (j = 0; j < ntokens; j++)
/* and record this rule as the rule to use if that
token follows. */
- if (BITISSET (LA (i), j))
- actrow[j] = -LAruleno[i];
+ if (BITISSET (LA (state->lookaheadsp + i), j))
+ actrow[j] = -LAruleno[state->lookaheadsp + i];
}
/* Now see which tokens are allowed for shifts in this state. For
if (nreds >= 1 && !nodefault)
{
- if (state_table[state]->consistent)
+ if (state->consistent)
default_rule = redp->rules[0];
else
{
int max = 0;
- for (i = m; i < n; i++)
+ for (i = 0; i < state->nlookaheads; i++)
{
int count = 0;
- int rule = -LAruleno[i];
+ int rule = -LAruleno[state->lookaheadsp + i];
int j;
for (j = 0; j < ntokens; j++)
actrow = XCALLOC (short, ntokens);
for (i = 0; i < nstates; ++i)
{
- yydefact[i] = action_row (i);
+ yydefact[i] = action_row (state_table[i]);
save_row (i);
}
}
+/*----------------------------.
+| Output the guards to OOUT. |
+`----------------------------*/
+
+static void
+guards_output (FILE *out, size_t *line)
+{
+ int rule;
+ for (rule = 1; rule < nrules + 1; ++rule)
+ if (rule_table[rule].action)
+ {
+ fprintf (out, " case %d:\n", rule);
+
+ if (!no_lines_flag)
+ fprintf (out, muscle_find ("linef"),
+ rule_table[rule].guard_line,
+ quotearg_style (c_quoting_style,
+ muscle_find ("filename")));
+ fprintf (out, "{ %s; }\n break;\n\n",
+ rule_table[rule].guard);
+
+ /* We always output 4 '\n' per action. */
+ *line += 4;
+ /* Plus one if !no_lines_flag. */
+ if (!no_lines_flag)
+ ++*line;
+ /* Get the number of lines written by the user. */
+ *line += get_lines_number (rule_table[rule].guard);
+ }
+}
+
+
static void
save_column (int symbol, int default_state)
{
muscle_value = muscle_find (muscle_key);
if (!strcmp (muscle_key, "actions"))
actions_output (out, &output_line);
+ else if (!strcmp (muscle_key, "guards"))
+ guards_output (out, &output_line);
else if (!strcmp (muscle_key, "line"))
fprintf (out, "%d", output_line);
else if (!strcmp (muscle_key, "skeleton-line"))
header_output ();
free (rule_table + 1);
- obstack_free (&muscle_obstack, 0);
- obstack_free (&format_obstack, 0);
- obstack_free (&action_obstack, 0);
+ obstack_free (&muscle_obstack, NULL);
+ obstack_free (&format_obstack, NULL);
+ obstack_free (&action_obstack, NULL);
+ obstack_free (&attrs_obstack, NULL);
}