summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <demaille@gostai.com>2012-02-21 11:51:37 +0100
committerAkim Demaille <demaille@gostai.com>2012-02-21 14:44:15 +0100
commit71cbc1ac1a0b35b2488b109b031685b641868846 (patch)
tree951428c6b42bbf32dedd98f1daef7789374a64b4
parent98842516e138136a3af03f5b2347690124fbaf31 (diff)
downloadbison-71cbc1ac1a0b35b2488b109b031685b641868846.tar.gz
glr: fix ambiguity reports.
* tests/glr-regression.at (Ambiguity reports): New. (cherry picked from commit a6b2f4fc020fe6e464f4a445a7851825d3d57e4d)
-rw-r--r--tests/glr-regression.at117
1 files changed, 117 insertions, 0 deletions
diff --git a/tests/glr-regression.at b/tests/glr-regression.at
index 34e71105..d1d0b878 100644
--- a/tests/glr-regression.at
+++ b/tests/glr-regression.at
@@ -1788,3 +1788,120 @@ glr-regr18.y:26.18-24: previous declaration
])
AT_CLEANUP
+
+
+## ------------------- ##
+## Ambiguity reports. ##
+## ------------------- ##
+
+AT_SETUP([Ambiguity reports])
+
+AT_DATA_GRAMMAR([input.y],
+[[
+%{
+ #include <stdio.h>
+ #include <stdlib.h>
+ static void yyerror (char const *);
+ static int yylex (void);
+%}
+
+%debug
+%glr-parser
+
+%%
+start:
+ 'a' b 'c' d
+| 'a' b 'c' d
+;
+b: 'b';
+d: /* nada. */;
+%%
+
+static int
+yylex (void)
+{
+ static char const input[] = "abc";
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
+ return input[toknum++];
+}
+
+static void
+yyerror (char const *msg)
+{
+ fprintf (stderr, "%s\n", msg);
+}
+
+int
+main (void)
+{
+ yydebug = 1;
+ return !!yyparse ();
+}
+]])
+
+AT_BISON_CHECK([[-o input.c input.y]], 0, [],
+[input.y: conflicts: 1 reduce/reduce
+])
+AT_COMPILE([input])
+
+AT_PARSER_CHECK([[./input]], 1, [],
+[Starting parse
+Entering state 0
+Reading a token: Next token is token 'a' ()
+Shifting token 'a' ()
+Entering state 1
+Reading a token: Next token is token 'b' ()
+Shifting token 'b' ()
+Entering state 3
+Reducing stack 0 by rule 3 (line 25):
+ $1 = token 'b' ()
+-> $$ = nterm b ()
+Entering state 4
+Reading a token: Next token is token 'c' ()
+Shifting token 'c' ()
+Entering state 6
+Reducing stack 0 by rule 4 (line 26):
+-> $$ = nterm d ()
+Entering state 7
+Reading a token: Now at end of input.
+Stack 0 Entering state 7
+Now at end of input.
+Splitting off stack 1 from 0.
+Reduced stack 1 by rule #2; action deferred. Now in state 2.
+Stack 1 Entering state 2
+Now at end of input.
+Reduced stack 0 by rule #1; action deferred. Now in state 2.
+Merging stack 0 into stack 1.
+Stack 1 Entering state 2
+Now at end of input.
+Removing dead stacks.
+Rename stack 1 -> 0.
+On stack 0, shifting token $end ()
+Stack 0 now in state #5
+Ambiguity detected.
+Option 1,
+ start -> <Rule 1, tokens 1 .. 3>
+ 'a' <tokens 1 .. 1>
+ b <tokens 2 .. 2>
+ 'c' <tokens 3 .. 3>
+ d <empty>
+
+Option 2,
+ start -> <Rule 2, tokens 1 .. 3>
+ 'a' <tokens 1 .. 1>
+ b <tokens 2 .. 2>
+ 'c' <tokens 3 .. 3>
+ d <empty>
+
+syntax is ambiguous
+Cleanup: popping token $end ()
+Cleanup: popping unresolved nterm start ()
+Cleanup: popping nterm d ()
+Cleanup: popping token 'c' ()
+Cleanup: popping nterm b ()
+Cleanup: popping token 'a' ()
+])
+
+AT_CLEANUP