# 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
-## -------------------------------------- ##
-## %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
%%
%%]], [AT_SKEL_CC_IF([[
void
-yy::parser::error (const yy::location &, std::string const &msg)
+yy::parser::error (std::string const &msg)
{
std::cerr << msg << std::endl;
}]], [[
;
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
+]])
+
+AT_CLEANUP
+
+
## -------------------------------- ##
## Defaulted Conflicted Reduction. ##
## -------------------------------- ##