mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-13 22:33:03 +00:00
Fix a longstanding bug uncovered by bro-0.9a9/src/parse.y, which I
got from <http://bro-ids.org/download.html>. The bug is that when two actions appeared in succession, the second one was scanned before the first one was added to the grammar rule as a midrule action. Bison then output the incorrect warning "parse.y:905.17-906.36: warning: unused value: $3". * src/parse-gram.y (BRACED_CODE, action): These are no longer associated with a value. (rhs): Don't invoke grammar_current_rule_action_append. (action): Invoke it here instead. * src/reader.c (grammar_midrule_action): Now extern. (grammar_current_rule_action_append): Don't invoke grammar_midrule_action; that is now the scanner's job. * src/reader.h (last_string, last_braced_code_loc): (grammar_midrule_action): New decls. * src/scan-gram.l (last_string): Now extern, sigh. (last_braced_code_loc): New extern variable. (<INITIAL>"{"): Invoke grammar_midrule_action if the current rule already has an action. (<SC_BRACED_CODE>"}"): Set last_braced_code_loc before returning. * tests/input.at (AT_CHECK_UNUSED_VALUES): Add some tests to check that the above changes fixed the bug.
This commit is contained in:
@@ -176,7 +176,6 @@ static int current_prec = 0;
|
||||
"%parse-param {...}"
|
||||
"%printer {...}"
|
||||
"%union {...}"
|
||||
BRACED_CODE action
|
||||
PROLOGUE EPILOGUE
|
||||
%printer { fprintf (stderr, "\"%s\"", $$); }
|
||||
STRING string_content
|
||||
@@ -187,7 +186,6 @@ static int current_prec = 0;
|
||||
"%parse-param {...}"
|
||||
"%printer {...}"
|
||||
"%union {...}"
|
||||
BRACED_CODE action
|
||||
PROLOGUE EPILOGUE
|
||||
%type <uniqstr> TYPE
|
||||
%printer { fprintf (stderr, "<%s>", $$); } TYPE
|
||||
@@ -430,7 +428,6 @@ rhs:
|
||||
| rhs symbol
|
||||
{ grammar_current_rule_symbol_append ($2, @2); }
|
||||
| rhs action
|
||||
{ grammar_current_rule_action_append ($2, @2); }
|
||||
| rhs "%prec" symbol
|
||||
{ grammar_current_rule_prec_set ($3, @3); }
|
||||
| rhs "%dprec" INT
|
||||
@@ -444,9 +441,21 @@ symbol:
|
||||
| string_as_id { $$ = $1; }
|
||||
;
|
||||
|
||||
/* Handle the semantics of an action specially, with a mid-rule
|
||||
action, so that grammar_current_rule_action_append is invoked
|
||||
immediately after the braced code is read by the scanner.
|
||||
|
||||
This implementation relies on the LALR(1) parsing algorithm.
|
||||
If grammar_current_rule_action_append were executed in a normal
|
||||
action for this rule, then when the input grammar contains two
|
||||
successive actions, the scanner would have to read both actions
|
||||
before reducing this rule. That wouldn't work, since the scanner
|
||||
relies on all preceding input actions being processed by
|
||||
grammar_current_rule_action_append before it scans the next
|
||||
action. */
|
||||
action:
|
||||
{ grammar_current_rule_action_append (last_string, last_braced_code_loc); }
|
||||
BRACED_CODE
|
||||
{ $$ = $1; }
|
||||
;
|
||||
|
||||
/* A string used as an ID: quote it. */
|
||||
|
||||
Reference in New Issue
Block a user