doc: one of the fixes for an ambiguous grammar was ambiguous too

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.
This commit is contained in:
Akim Demaille
2012-11-22 15:49:18 +01:00
parent c28cd5dc5a
commit 53e2cd1ebd
3 changed files with 62 additions and 1 deletions

4
NEWS
View File

@@ -2,6 +2,10 @@ GNU Bison NEWS
* Noteworthy changes in release ?.? (????-??-??) [?] * Noteworthy changes in release ?.? (????-??-??) [?]
** Documentation
The sections about shift/reduce and reduce/reduce conflicts resolution
have been fixed and extended.
* Noteworthy changes in release 2.6.5 (2012-11-07) [stable] * Noteworthy changes in release 2.6.5 (2012-11-07) [stable]

3
THANKS
View File

@@ -1,8 +1,9 @@
Bison was originally written by Robert Corbett. It would not be what Bison was originally written by Robert Corbett. It would not be what
it is today without the invaluable help of these people: it is today without the invaluable help of these people:
Аскар Сафин safinaskar@mail.ru
Airy Andre Airy.Andre@edf.fr Airy Andre Airy.Andre@edf.fr
Akim Demaille akim@freefriends.org Akim Demaille akim@lrde.epita.fr
Albert Chin-A-Young china@thewrittenword.com Albert Chin-A-Young china@thewrittenword.com
Alexander Belopolsky alexb@rentec.com Alexander Belopolsky alexb@rentec.com
Alexandre Duret-Lutz adl@lrde.epita.fr Alexandre Duret-Lutz adl@lrde.epita.fr

View File

@@ -7117,6 +7117,58 @@ redirects:
@end group @end group
@end example @end example
Yet this proposal introduces another kind of ambiguity! 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 proceed 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 @node Mysterious Conflicts
@section Mysterious Conflicts @section Mysterious Conflicts
@cindex Mysterious Conflicts @cindex Mysterious Conflicts
@@ -11835,6 +11887,10 @@ London, Department of Computer Science, TR-00-12 (December 2000).
@c LocalWords: subdirectory Solaris nonassociativity perror schemas Malloy ints @c LocalWords: subdirectory Solaris nonassociativity perror schemas Malloy ints
@c LocalWords: Scannerless ispell american ChangeLog smallexample CSTYPE CLTYPE @c LocalWords: Scannerless ispell american ChangeLog smallexample CSTYPE CLTYPE
@c LocalWords: clval CDEBUG cdebug deftypeopx yyterminate @c LocalWords: clval CDEBUG cdebug deftypeopx yyterminate
@c LocalWords: parsers parser's
@c LocalWords: associativity subclasses precedences unresolvable runnable
@c LocalWords: allocators subunit initializations unreferenced untyped
@c LocalWords: errorVerbose subtype subtypes
@c Local Variables: @c Local Variables:
@c ispell-dictionary: "american" @c ispell-dictionary: "american"