[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/4] doc: one of the fixes for an ambiguous grammar was ambiguous
From: |
Akim Demaille |
Subject: |
[PATCH 4/4] doc: one of the fixes for an ambiguous grammar was ambiguous too |
Date: |
Thu, 22 Nov 2012 16:10:30 +0100 |
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:
+Аскар Сафин address@hidden
Airy Andre address@hidden
Akim Demaille address@hidden
Albert Chin-A-Young address@hidden
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
address@hidden word} can be parsed as a single @code{words} composed of two
address@hidden, or as two address@hidden @code{words} (and likewise for
address@hidden/@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
address@hidden"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
address@hidden Operators,, Using Precedence For Non Operators}. One solution
+relies on precedences: use @code{%prec} to give a lower precedence to the
+rule:
+
address@hidden
+%nonassoc "word"
+%nonassoc "sequence"
+%%
address@hidden
+sequence:
+ /* empty */
+| sequence word %prec "sequence"
+| sequence redirect %prec "sequence"
+;
address@hidden group
+
address@hidden
+words:
+ word
+| words "word"
+;
address@hidden group
address@hidden example
+
+Another solution relies on associativity: provide both the token and the
+rule with the same precedence, but make them right-associative:
+
address@hidden
+%right "word" "redirect"
+%%
address@hidden
+sequence:
+ /* empty */
+| sequence word %prec "word"
+| sequence redirect %prec "redirect"
+;
address@hidden group
address@hidden example
+
@node Mysterious Conflicts
@section Mysterious Conflicts
@cindex Mysterious Conflicts
--
1.8.0