mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-11 13:23:04 +00:00
* src/gram.h (rule_t): guard' and guard_line' are new members.
* src/reader.c (symbol_list): `guard' and `guard_line' are new members. (symbol_list_new): Adjust. (copy_action): action_line is the first line, not the last. (copy_guard): Just as for actions, store the `action' only, not the switch/case/break flesh. Don't parse the user action that might follow the guard, let... (readgram): do it, i.e., now, there can be an action after a guard. In other words the guard is just explicitly optional. (packgram): Adjust. * src/output.c (guards_output): New. (output_parser): Call it when needed. (output): Also free the guard and attrs obstacks. * src/files.c, src/files.h (obstack_save): Remove. (output_files): Remove. As a result, if one needs the former `.act' file, using an appropriate skeleton which requires actions and guards is now required. * src/main.c (main): Adjust. * tests/semantic.at: New. * tests/regression.at: Use `input.y' as input file name. Avoid 8+3 problems by requiring input.c when the test needs the parser.
This commit is contained in:
38
src/reader.c
38
src/reader.c
@@ -40,9 +40,14 @@ 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;
|
||||
|
||||
/* The guard is attached to the LHS of a rule. */
|
||||
const char *guard;
|
||||
int guard_line;
|
||||
bucket *ruleprec;
|
||||
} symbol_list;
|
||||
|
||||
@@ -76,6 +81,8 @@ symbol_list_new (bucket *sym)
|
||||
res->line = lineno;
|
||||
res->action = NULL;
|
||||
res->action_line = 0;
|
||||
res->guard = NULL;
|
||||
res->guard_line = 0;
|
||||
res->ruleprec = NULL;
|
||||
return res;
|
||||
}
|
||||
@@ -1088,6 +1095,8 @@ copy_action (symbol_list *rule, int stack_offset)
|
||||
count = 1;
|
||||
c = getc (finput);
|
||||
|
||||
rule->action_line = lineno;
|
||||
|
||||
while (count > 0)
|
||||
{
|
||||
while (c != '}')
|
||||
@@ -1144,7 +1153,6 @@ copy_action (symbol_list *rule, int stack_offset)
|
||||
|
||||
obstack_1grow (&action_obstack, '\0');
|
||||
rule->action = obstack_finish (&action_obstack);
|
||||
rule->action_line = lineno;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------.
|
||||
@@ -1167,12 +1175,7 @@ copy_guard (symbol_list *rule, int stack_offset)
|
||||
if (semantic_parser)
|
||||
stack_offset = 0;
|
||||
|
||||
obstack_fgrow1 (&guard_obstack, "\ncase %d:\n", nrules);
|
||||
if (!no_lines_flag)
|
||||
obstack_fgrow2 (&guard_obstack, muscle_find ("linef"),
|
||||
lineno, quotearg_style (c_quoting_style,
|
||||
muscle_find ("filename")));
|
||||
obstack_1grow (&guard_obstack, '{');
|
||||
rule->guard_line = lineno;
|
||||
|
||||
count = 0;
|
||||
c = getc (finput);
|
||||
@@ -1231,19 +1234,8 @@ copy_guard (symbol_list *rule, int stack_offset)
|
||||
c = getc (finput);
|
||||
}
|
||||
|
||||
c = skip_white_space ();
|
||||
|
||||
obstack_sgrow (&guard_obstack, ";\n break;}");
|
||||
if (c == '{')
|
||||
copy_action (rule, stack_offset);
|
||||
else if (c == '=')
|
||||
{
|
||||
c = getc (finput); /* why not skip_white_space -wjh */
|
||||
if (c == '{')
|
||||
copy_action (rule, stack_offset);
|
||||
}
|
||||
else
|
||||
ungetc (c, finput);
|
||||
obstack_1grow (&guard_obstack, '\0');
|
||||
rule->guard = obstack_finish (&guard_obstack);
|
||||
}
|
||||
|
||||
|
||||
@@ -1466,6 +1458,7 @@ readgram (void)
|
||||
crule->ruleprec = symval;
|
||||
t = lex ();
|
||||
}
|
||||
|
||||
if (t == tok_guard)
|
||||
{
|
||||
if (!semantic_parser)
|
||||
@@ -1474,7 +1467,8 @@ readgram (void)
|
||||
copy_guard (crule, rulelength);
|
||||
t = lex ();
|
||||
}
|
||||
else if (t == tok_left_curly)
|
||||
|
||||
if (t == tok_left_curly)
|
||||
{
|
||||
/* This case never occurs -wjh */
|
||||
if (action_flag)
|
||||
@@ -1781,6 +1775,8 @@ packgram (void)
|
||||
rule_table[ruleno].useful = TRUE;
|
||||
rule_table[ruleno].action = p->action;
|
||||
rule_table[ruleno].action_line = p->action_line;
|
||||
rule_table[ruleno].guard = p->guard;
|
||||
rule_table[ruleno].guard_line = p->guard_line;
|
||||
|
||||
p = p->next;
|
||||
while (p && p->sym)
|
||||
|
||||
Reference in New Issue
Block a user