size_t i;
for (i = 0; s[i]; ++i)
- {
- if (s[i] == '\n')
- ++lines;
- }
+ if (s[i] == '\n')
+ ++lines;
return lines;
}
`------------------------------------------------------------------*/
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;
- int nreds = redp ? redp->nreds : 0;
- shifts *shiftp = state_table[state]->shifts;
- errs *errp = state_table[state]->errs;
+ reductions *redp = state->reductions;
+ shifts *shiftp = state->shifts;
+ errs *errp = state->errs;
/* set nonzero to inhibit having any default reduction */
int nodefault = 0;
for (i = 0; i < ntokens; i++)
actrow[i] = 0;
- if (nreds >= 1)
+ if (redp->nreds >= 1)
{
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
/* See which tokens are an explicit error in this state (due to
%nonassoc). For them, record MINSHORT as the action. */
- if (errp)
- for (i = 0; i < errp->nerrs; i++)
- {
- int symbol = errp->errs[i];
- actrow[symbol] = MINSHORT;
- }
+ for (i = 0; i < errp->nerrs; i++)
+ {
+ int symbol = errp->errs[i];
+ actrow[symbol] = MINSHORT;
+ }
/* Now find the most common reduction and make it the default action
for this state. */
- if (nreds >= 1 && !nodefault)
+ if (redp->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)
{
for (i = 0; i < nstates; ++i)
{
- XFREE (state_table[i]->shifts);
+ free (state_table[i]->shifts);
XFREE (state_table[i]->reductions);
- XFREE (state_table[i]->errs);
+ free (state_table[i]->errs);
free (state_table[i]);
}
XFREE (state_table);
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"))
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 ("error-verbose", error_verbose);
MUSCLE_INSERT_STRING ("prefix", spec_name_prefix);
for (i = ntokens; i < nsyms; i++)
/* don't make these for dummy nonterminals made by gensym. */
if (*tags[i] != '@')
- fprintf (out, "# define\tNT%s\t%d\n", tags[i], i);
+ fprintf (out, "# define NT%s\t%d\n", tags[i], i);
}
fprintf (out, "\n#endif /* not %s */\n", macro_name);
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);
}