get_lines_number (const char *s)
{
size_t lines = 0;
-
+
size_t i;
for (i = 0; s[i]; ++i)
{
if (s[i] == '\n')
++lines;
- }
-
+ }
+
return lines;
}
output_table_data (struct obstack *oout,
short *table_data,
short first,
- short begin,
- short end)
+ int begin,
+ int end)
{
int i;
int j = 1;
`------------------------------------------------------------------*/
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]->lookaheads;
- n = state_table[state + 1]->lookaheads;
-
- 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)
{
return j;
}
}
-
- assert (!"pack_vector");
+#define pack_vector_succeeded 0
+ assert (pack_vector_succeeded);
return 0;
}
{
int c;
FILE *fskel;
- size_t line;
+ size_t output_line;
+ size_t skeleton_line;
fskel = xfopen (skel_filename, "r");
/* New output code. */
- line = 1;
+ output_line = 1;
+ skeleton_line = 1;
c = getc (fskel);
while (c != EOF)
{
if (c != '%')
{
if (c == '\n')
- ++line;
+ {
+ ++output_line;
+ ++skeleton_line;
+ }
putc (c, out);
c = getc (fskel);
}
muscle_key = obstack_finish (&muscle_obstack);
muscle_value = muscle_find (muscle_key);
if (!strcmp (muscle_key, "actions"))
- actions_output (out, &line);
+ 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", line);
+ fprintf (out, "%d", output_line);
+ else if (!strcmp (muscle_key, "skeleton-line"))
+ fprintf (out, "%d", skeleton_line);
else if (muscle_value)
{
fputs (muscle_value, out);
- line += get_lines_number (muscle_value);
- }
+ output_line += get_lines_number (muscle_value);
+ }
else
{
fputs ("%%", out);
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);
}