Reported by Аскар Сафин.
http://lists.gnu.org/archive/html/bug-bison/2012-11/msg00024.html

* doc/bison.texi (Reduce/Reduce): Fix the resulting ambiguity using
precedence/associativity directives.
---
 NEWS           |  4 ++++
 THANKS         |  1 +
 doc/bison.texi | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)

diff --git a/NEWS b/NEWS
index 59549b5..b7b0a22 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ GNU Bison NEWS
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Documentation
+
+  The sections about Shift/Reduce and Reduce/Reduce conflict resolution have
+  been fixed and extended.
 
 * Noteworthy changes in release 2.6.5 (2012-11-07) [stable]
 
diff --git a/THANKS b/THANKS
index e815f8e..b355b57 100644
--- a/THANKS
+++ b/THANKS
@@ -1,6 +1,7 @@
 Bison was originally written by Robert Corbett.  It would not be what
 it is today without the invaluable help of these people:
 
+Аскар Сафин              [email protected]
 Airy Andre                [email protected]
 Akim Demaille             [email protected]
 Albert Chin-A-Young       [email protected]
diff --git a/doc/bison.texi b/doc/bison.texi
index bc3237a..e2e6a81 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -7117,6 +7117,58 @@ redirects:
 @end group
 @end example
 
+Yet this proposal introduces another kind of ambuguity!  The input
+@samp{word word} can be parsed as a single @code{words} composed of two
+@samp{word}s, or as two one-@code{word} @code{words} (and likewise for
+@code{redirect}/@code{redirects}).  However this ambiguity is now a
+shift/reduce conflict, and therefore it can now be addressed with precedence
+directives.
+
+To simplify the matter, we will procede with @code{word} and @code{redirect}
+being tokens: @code{"word"} and @code{"redirect"}.
+
+To prefer the longest @code{words}, the conflict between the token
+@code{"word"} and the rule @samp{sequence: sequence words} must be resolved
+as a shift.  To this end, we use the same techniques as exposed above, see
+@ref{Non Operators,, Using Precedence For Non Operators}.  One solution
+relies on precedences: use @code{%prec} to give a lower precedence to the
+rule:
+
+@example
+%nonassoc "word"
+%nonassoc "sequence"
+%%
+@group
+sequence:
+  /* empty */
+| sequence word      %prec "sequence"
+| sequence redirect  %prec "sequence"
+;
+@end group
+
+@group
+words:
+  word
+| words "word"
+;
+@end group
+@end example
+
+Another solution relies on associativity: provide both the token and the
+rule with the same precedence, but make them right-associative:
+
+@example
+%right "word" "redirect"
+%%
+@group
+sequence:
+  /* empty */
+| sequence word      %prec "word"
+| sequence redirect  %prec "redirect"
+;
+@end group
+@end example
+
 @node Mysterious Conflicts
 @section Mysterious Conflicts
 @cindex Mysterious Conflicts
-- 
1.8.0


Reply via email to