# Exercising Bison on conflicts. -*- Autotest -*-
-# Copyright 2002 Free Software Foundation, Inc.
+# Copyright (C) 2002 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_BANNER([[Conflicts.]])
+## ---------------- ##
+## S/R in initial. ##
+## ---------------- ##
+
+# I once hacked Bison in such a way that it lost its reductions on the
+# initial state (because it was confusing it with the last state). It
+# took me a while to strip down my failures to this simple case. So
+# make sure it finds the s/r conflict below.
+
+AT_SETUP([S/R in initial])
+
+AT_DATA([[input.y]],
+[[%expect 1
+%%
+exp: e 'e';
+e: 'e' | /* Nothing. */;
+]])
+
+AT_CHECK([bison input.y -o input.c])
+
+AT_CLEANUP
+
## ------------------- ##
## %nonassoc and eof. ##
## ------------------- ##
AT_DATA([input.y],
[[
%{
+#include <config.h>
+/* We don't need a perfect malloc for these tests. */
+#undef malloc
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <error.h>
+
+#if STDC_HEADERS
+# include <stdlib.h>
+#endif
+
#define YYERROR_VERBOSE 1
-#define yyerror(Msg) \
-do { \
- fprintf (stderr, "%s\n", Msg); \
- exit (1); \
-} while (0)
+static void
+yyerror (const char *msg)
+{
+ fprintf (stderr, "%s\n", msg);
+ exit (1);
+}
/* The current argument. */
static const char *input = NULL;
AT_SETUP([Unresolved SR Conflicts])
+AT_KEYWORDS([report])
+
AT_DATA([input.y],
[[%token NUM OP
%%
exp: exp OP exp | NUM;
]])
-AT_CHECK([bison input.y -o input.c -v], 0, [],
+AT_CHECK([bison input.y -o input.c --report=all], 0, [],
[input.y contains 1 shift/reduce conflict.
])
Grammar
- Number, Line, Rule
- 0 3 $axiom -> exp $
- 1 3 exp -> exp OP exp
- 2 3 exp -> NUM
+ 0 $axiom: exp $
+
+ 1 exp: exp OP exp
+ 2 | NUM
Terminals, with rules where they appear
$ (0) 0
error (256)
-NUM (257) 2
-OP (258) 1
+NUM (258) 2
+OP (259) 1
Nonterminals, with rules where they appear
state 0
+ $axiom -> . exp $ (rule 0)
+ exp -> . exp OP exp (rule 1)
+ exp -> . NUM (rule 2)
+
NUM shift, and go to state 1
exp go to state 2
state 4
+ exp -> . exp OP exp (rule 1)
exp -> exp OP . exp (rule 1)
+ exp -> . NUM (rule 2)
NUM shift, and go to state 1
state 5
- exp -> exp . OP exp (rule 1)
- exp -> exp OP exp . (rule 1)
+ exp -> exp . OP exp [$, OP] (rule 1)
+ exp -> exp OP exp . [$, OP] (rule 1)
OP shift, and go to state 4
AT_SETUP([Solved SR Conflicts])
+AT_KEYWORDS([report])
+
AT_DATA([input.y],
[[%token NUM OP
%right OP
exp: exp OP exp | NUM;
]])
-AT_CHECK([bison input.y -o input.c -v], 0, [], [])
+AT_CHECK([bison input.y -o input.c --report=all], 0, [], [])
# Check the contents of the report.
AT_CHECK([cat input.output], [],
-[[Conflict in state 5 between rule 2 and token OP resolved as shift.
-
+[[Grammar
-Grammar
+ 0 $axiom: exp $
- Number, Line, Rule
- 0 4 $axiom -> exp $
- 1 4 exp -> exp OP exp
- 2 4 exp -> NUM
+ 1 exp: exp OP exp
+ 2 | NUM
Terminals, with rules where they appear
$ (0) 0
error (256)
-NUM (257) 2
-OP (258) 1
+NUM (258) 2
+OP (259) 1
Nonterminals, with rules where they appear
state 0
+ $axiom -> . exp $ (rule 0)
+ exp -> . exp OP exp (rule 1)
+ exp -> . NUM (rule 2)
+
NUM shift, and go to state 1
exp go to state 2
state 4
+ exp -> . exp OP exp (rule 1)
exp -> exp OP . exp (rule 1)
+ exp -> . NUM (rule 2)
NUM shift, and go to state 1
state 5
- exp -> exp . OP exp (rule 1)
- exp -> exp OP exp . (rule 1)
+ exp -> exp . OP exp [$] (rule 1)
+ exp -> exp OP exp . [$] (rule 1)
OP shift, and go to state 4
$default reduce using rule 1 (exp)
+ Conflict between rule 2 and token OP resolved as reduce (%right OP).
]])