From: Akim Demaille Date: Thu, 22 Nov 2012 14:49:18 +0000 (+0100) Subject: doc: one of the fixes for an ambiguous grammar was ambiguous too X-Git-Tag: v2.6.90~33^2~1 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/53e2cd1ebd0a99048610004ccb7ba11d351981bc 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. --- diff --git a/NEWS b/NEWS index 59549b59..2952b63d 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 conflicts resolution + have been fixed and extended. * Noteworthy changes in release 2.6.5 (2012-11-07) [stable] diff --git a/THANKS b/THANKS index e815f8ed..b12bb7e8 100644 --- a/THANKS +++ b/THANKS @@ -1,8 +1,9 @@ Bison was originally written by Robert Corbett. It would not be what it is today without the invaluable help of these people: +Аскар Сафин safinaskar@mail.ru Airy Andre Airy.Andre@edf.fr -Akim Demaille akim@freefriends.org +Akim Demaille akim@lrde.epita.fr Albert Chin-A-Young china@thewrittenword.com Alexander Belopolsky alexb@rentec.com Alexandre Duret-Lutz adl@lrde.epita.fr diff --git a/doc/bison.texi b/doc/bison.texi index bc3237ae..8e257a60 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 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 @section 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: Scannerless ispell american ChangeLog smallexample CSTYPE CLTYPE @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 ispell-dictionary: "american"