# Exercising Bison on conflicts. -*- Autotest -*-
-# Copyright (C) 2002-2005, 2007, 2009-2012 Free Software Foundation,
-# Inc.
+# Copyright (C) 2002-2005, 2007-2012 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
]])
AT_BISON_CHECK([-o input.c input.y], 0, [],
-[[input.y:4.9: warning: rule useless in parser due to conflicts: e: /* empty */
+[[input.y:4.9: warning: rule useless in parser due to conflicts: e: /* empty */ [-Wother]
]])
AT_CLEANUP
-## -------------------------------------- ##
-## %error-verbose and consistent errors. ##
-## -------------------------------------- ##
+## ------------------------------------------- ##
+## parse.error=verbose and consistent errors. ##
+## ------------------------------------------- ##
-AT_SETUP([[%error-verbose and consistent errors]])
+AT_SETUP([[parse.error=verbose and consistent errors]])
m4_pushdef([AT_CONSISTENT_ERRORS_CHECK], [
}]], [[
%code {]AT_SKEL_CC_IF([[
- #include <cassert>
#include <string>]], [[
#include <assert.h>
#include <stdio.h>
]$1[
-%error-verbose
+%define parse.error verbose
%%
;
consistent-reduction: /*empty*/ {
- assert (yychar == ]AT_SKEL_CC_IF([[yyempty_]], [[YYEMPTY]])[);
+ assert (yychar == YYEMPTY);
yylval = 0;
yychar = 'b';
} ;
[AT_USER_ACTION_GRAMMAR],
[AT_USER_ACTION_INPUT],
[['b']], [[none]])
-AT_CONSISTENT_ERRORS_CHECK([[%language "c++"]],
- [AT_USER_ACTION_GRAMMAR],
- [AT_USER_ACTION_INPUT],
- [['b']], [[none]])
-# No Java test because yychar cannot be manipulated by users.
+# No C++ or Java test because yychar cannot be manipulated by users.
AT_CONSISTENT_ERRORS_CHECK([[%define lr.default-reductions consistent]],
[AT_USER_ACTION_GRAMMAR],
AT_CLEANUP
+## ---------------------- ##
+## %precedence suffices. ##
+## ---------------------- ##
+
+AT_SETUP([%precedence suffices])
+
+AT_DATA([input.y],
+[[%precedence "then"
+%precedence "else"
+%%
+stmt:
+ "if" cond "then" stmt
+| "if" cond "then" stmt "else" stmt
+| "stmt"
+;
+
+cond:
+ "exp"
+;
+]])
+
+AT_BISON_CHECK([-o input.c input.y])
+
+AT_CLEANUP
+
+
+## ------------------------------ ##
+## %precedence does not suffice. ##
+## ------------------------------ ##
+
+AT_SETUP([%precedence does not suffice])
+
+AT_DATA([input.y],
+[[%precedence "then"
+%precedence "else"
+%%
+stmt:
+ "if" cond "then" stmt
+| "if" cond "then" stmt "else" stmt
+| "stmt"
+;
+
+cond:
+ "exp"
+| cond "then" cond
+;
+]])
+
+AT_BISON_CHECK([-o input.c input.y], 0, [],
+[[input.y: conflicts: 1 shift/reduce
+input.y:12.3-18: warning: rule useless in parser due to conflicts: cond: cond "then" cond [-Wother]
+]])
+
+AT_CLEANUP
+
+
## -------------------------------- ##
## Defaulted Conflicted Reduction. ##
## -------------------------------- ##
AT_BISON_CHECK([-o input.c --report=all input.y], 0, [],
[[input.y: conflicts: 1 reduce/reduce
-input.y:4.6-8: warning: rule useless in parser due to conflicts: id: '0'
+input.y:4.6-8: warning: rule useless in parser due to conflicts: id: '0' [-Wother]
]])
# Check the contents of the report.
AT_BISON_CHECK([[--report=all input.y]], 0, [],
[[input.y: conflicts: 1 shift/reduce, 1 reduce/reduce
-input.y:12.5-20: warning: rule useless in parser due to conflicts: resolved_conflict: 'a' unreachable1
-input.y:20.5-20: warning: rule useless in parser due to conflicts: unreachable1: 'a' unreachable2
-input.y:21.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */
-input.y:25.13: warning: rule useless in parser due to conflicts: unreachable2: /* empty */
-input.y:25.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */
-input.y:31.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a'
-input.y:32.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */
+input.y:12.5-20: warning: rule useless in parser due to conflicts: resolved_conflict: 'a' unreachable1 [-Wother]
+input.y:20.5-20: warning: rule useless in parser due to conflicts: unreachable1: 'a' unreachable2 [-Wother]
+input.y:21.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */ [-Wother]
+input.y:25.13: warning: rule useless in parser due to conflicts: unreachable2: /* empty */ [-Wother]
+input.y:25.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */ [-Wother]
+input.y:31.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a' [-Wother]
+input.y:32.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */ [-Wother]
]])
AT_CHECK([[cat input.output]], 0,
AT_BISON_CHECK([[input-keep.y]], 0, [],
[[input-keep.y: conflicts: 2 shift/reduce, 2 reduce/reduce
-input-keep.y:22.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */
-input-keep.y:26.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */
-input-keep.y:32.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a'
-input-keep.y:33.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */
+input-keep.y:22.4: warning: rule useless in parser due to conflicts: unreachable1: /* empty */ [-Wother]
+input-keep.y:26.16: warning: rule useless in parser due to conflicts: unreachable2: /* empty */ [-Wother]
+input-keep.y:32.5-7: warning: rule useless in parser due to conflicts: reported_conflicts: 'a' [-Wother]
+input-keep.y:33.4: warning: rule useless in parser due to conflicts: reported_conflicts: /* empty */ [-Wother]
]])
AT_CLEANUP