Attach actions to rules, instead of pre-outputting them to

actions_obstack.
* src/gram.h (rule_t): action and action_line are new members.
* src/reader.c (symbol_list): Likewise.
(copy_action): Save the actions within the rule.
(packgram): Save them in rule_table.
* src/output.c (actions_output): New.
(output_parser): Use it on `%%actions'.
(output_rule_data): Don't free rule_table.
(output): Do it.
(prepare): Don't save the `action' muscle.
* src/bison.simple: s/%%action/%%actions/.
This commit is contained in:
Akim Demaille
2001-12-15 14:14:30 +00:00
parent 51576fb3c6
commit 3f96f4dc41
6 changed files with 62 additions and 29 deletions

View File

@@ -41,6 +41,9 @@ typedef struct symbol_list
struct symbol_list *next;
bucket *sym;
int line;
/* The action is attached to the LHS of a rule. */
const char *action;
int action_line;
bucket *ruleprec;
}
symbol_list;
@@ -1131,16 +1134,6 @@ copy_action (symbol_list *rule, int stack_offset)
if (semantic_parser)
stack_offset = 0;
obstack_fgrow1 (&action_obstack, "\ncase %d:\n", nrules);
if (!no_lines_flag)
{
obstack_fgrow2 (&action_obstack, muscle_find ("linef"),
lineno, quotearg_style (c_quoting_style,
muscle_find ("filename")));
}
obstack_1grow (&action_obstack, '{');
count = 1;
c = getc (finput);
@@ -1198,13 +1191,9 @@ copy_action (symbol_list *rule, int stack_offset)
}
}
/* As a Bison extension, add the ending semicolon. Since some Yacc
don't do that, help people using bison as a Yacc finding their
missing semicolons. */
if (yacc_flag)
obstack_sgrow (&action_obstack, "}\n break;");
else
obstack_sgrow (&action_obstack, ";\n break;}");
obstack_1grow (&action_obstack, '\0');
rule->action = obstack_finish (&action_obstack);
rule->action_line = lineno;
}
/*-------------------------------------------------------------------.
@@ -1879,6 +1868,8 @@ packgram (void)
rule_table[ruleno].rhs = itemno;
rule_table[ruleno].line = p->line;
rule_table[ruleno].useful = TRUE;
rule_table[ruleno].action = p->action;
rule_table[ruleno].action_line = p->action_line;
p = p->next;
while (p && p->sym)