m4_pushdef([AT_CONSISTENT_ERRORS_CHECK], [
-AT_BISON_CHECK([$1[ -o input.c input.y]])
-AT_COMPILE([[input]])
-
-m4_pushdef([AT_EXPECTING], [m4_if($3, [ab], [[, expecting 'a' or 'b']],
- $3, [a], [[, expecting 'a']],
- $3, [b], [[, expecting 'b']])])
-
-AT_PARSER_CHECK([[./input]], [[1]], [],
-[[syntax error, unexpected ]$2[]AT_EXPECTING[
-]])
-
-m4_popdef([AT_EXPECTING])
-
-])
-
AT_DATA_GRAMMAR([input.y],
[[%code {
#include <assert.h>
#define USE(Var)
}
+]$1[
+
%error-verbose
-// The point isn't to test IELR here, but state merging happens to
-// complicate the example.
-%define lr.type ielr
+%%
+
+]$2[
+
+%%
+
+int
+yylex (void)
+{
+ static char const *input = "]$3[";
+ yylval = 1;
+ return *input++;
+}
+
+void
+yyerror (char const *msg)
+{
+ fprintf (stderr, "%s\n", msg);
+}
+
+int
+main (void)
+{
+ return yyparse ();
+}
+]])
+AT_BISON_CHECK([[-o input.c input.y]])
+AT_COMPILE([[input]])
+
+m4_pushdef([AT_EXPECTING], [m4_if($5, [ab], [[, expecting 'a' or 'b']],
+ $5, [a], [[, expecting 'a']],
+ $5, [b], [[, expecting 'b']])])
-%nonassoc 'a'
+AT_PARSER_CHECK([[./input]], [[1]], [[]],
+[[syntax error, unexpected ]$4[]AT_EXPECTING[
+]])
+
+m4_popdef([AT_EXPECTING])
+
+])
+
+m4_pushdef([AT_USER_ACTION_GRAMMAR],
+[[%nonassoc 'a';
// If yylval=0 here, then we know that the 'a' destructor is being
// invoked incorrectly for the 'b' set in the semantic action below.
%destructor {
if (!$$)
fprintf (stderr, "Wrong destructor.\n");
-} 'a'
-
-%%
+} 'a';
// The lookahead assigned by the semantic action isn't needed before
// either error action is encountered. In a previous version of Bison,
// except that, due to another bug, the unexpected token is not reported
// at all because the error action is the default action in a consistent
// state. That bug still needs to be fixed.
-start: error-reduce consistent-error 'a' { USE ($3); } ;
+start: error-reduce consistent-error 'a' { USE ($][3); } ;
error-reduce:
'a' 'a' consistent-reduction consistent-error 'a'
- { USE (($1, $2, $5)); }
+ { USE (($][1, $][2, $][5)); }
| 'a' error
- { USE ($1); }
+ { USE ($][1); }
;
consistent-reduction: /*empty*/ {
} ;
consistent-error:
- 'a' { USE ($1); }
+ 'a' { USE ($][1); }
| /*empty*/ %prec 'a'
;
// Provide another context in which all rules are useful so that this
// test case looks a little more realistic.
start: 'b' consistent-error 'b' ;
-
-%%
-
-int
-yylex (void)
-{
- static char const *input = "aa";
- yylval = 1;
- return *input++;
-}
-
-void
-yyerror (char const *msg)
-{
- fprintf (stderr, "%s\n", msg);
-}
-
-int
-main (void)
-{
- return yyparse ();
-}
]])
+m4_pushdef([AT_USER_ACTION_INPUT], [[aa]])
# See comments in grammar for why this test doesn't succeed.
AT_XFAIL_IF([[:]])
-AT_CONSISTENT_ERRORS_CHECK([], [['b']], [[none]])
-AT_CONSISTENT_ERRORS_CHECK([[-Dlr.default-reductions=consistent]],
+AT_CONSISTENT_ERRORS_CHECK([[]],
+ [AT_USER_ACTION_GRAMMAR],
+ [AT_USER_ACTION_INPUT],
+ [['b']], [[none]])
+AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reductions consistent]],
+ [AT_USER_ACTION_GRAMMAR],
+ [AT_USER_ACTION_INPUT],
[['b']], [[none]])
# Canonical LR doesn't foresee the error for 'a'!
-AT_CONSISTENT_ERRORS_CHECK([[-Dlr.default-reductions=accepting]],
+AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reductions accepting]],
+ [AT_USER_ACTION_GRAMMAR],
+ [AT_USER_ACTION_INPUT],
[[$end]], [[a]])
-AT_CONSISTENT_ERRORS_CHECK([[-Flr.type=canonical-lr]], [[$end]], [[a]])
+AT_CONSISTENT_ERRORS_CHECK([[%define lr.type canonical-lr]],
+ [AT_USER_ACTION_GRAMMAR],
+ [AT_USER_ACTION_INPUT],
+ [[$end]], [[a]])
+
+m4_popdef([AT_USER_ACTION_GRAMMAR])
+m4_popdef([AT_USER_ACTION_INPUT])
m4_popdef([AT_CONSISTENT_ERRORS_CHECK])