+## ---------------------- ##
+## Actions after errors. ##
+## ---------------------- ##
+
+AT_SETUP([Actions after errors])
+
+
+
+AT_DATA_GRAMMAR([[input.y]],
+[[%{
+#include <stdio.h>
+#include <stdlib.h>
+
+static int yylex (void);
+static void yyerror (char const *);
+
+#define YYDEBUG 1
+%}
+%union { int ival; }
+%type <ival> 'x' ';' thing line input
+
+%%
+input:
+ /* Nothing. */
+ {
+ $$ = 0;
+ printf ("input (%d): /* Nothing */\n", $$);
+ }
+| line input /* Right recursive to load the stack so that popping at
+ EOF can be exercised. */
+ {
+ $$ = 2;
+ printf ("input (%d): line (%d) input (%d)\n", $$, $1, $2);
+ }
+;
+
+line:
+ thing thing thing ';'
+ {
+ $$ = $1;
+ printf ("line (%d): thing (%d) thing (%d) thing (%d) ';' (%d)\n",
+ $$, $1, $2, $3, $4);
+ }
+| thing thing ';'
+ {
+ $$ = $1;
+ printf ("line (%d): thing (%d) thing (%d) ';' (%d)\n", $$, $1, $2, $3);
+ }
+| thing ';'
+ {
+ $$ = $1;
+ printf ("line (%d): thing (%d) ';' (%d)\n", $$, $1, $2);
+ }
+| error ';'
+ {
+ $$ = -1;
+ printf ("line (%d): error ';' (%d)\n", $$, $2);
+ }
+;
+
+thing:
+ 'x'
+ {
+ $$ = $1;
+ printf ("thing (%d): 'x' (%d)\n", $$, $1);
+ }
+;
+%%
+static size_t counter;
+
+static int
+yylex (void)
+{
+ static char const input[] =
+ {
+ /* Exericise the discarding of stack top and input until `error'
+ can be reduced. */
+ 'x', 'x', 'x', 'x', 'x', 'x', ';',
+
+ /* Load the stack and provoke an error that cannot be caught by
+ the grammar, to check that the stack is cleared. */
+ 'x', 'x', ';',
+ 'x', ';',
+ 'y'
+ };
+
+ if (counter < sizeof input)
+ {
+ yylval.ival = counter;
+ printf ("sending: '%c' (%d)\n", input[counter], yylval.ival);
+ return input[counter++];
+ }
+ else
+ {
+ printf ("sending: EOF\n");
+ return EOF;
+ }
+}
+
+static void
+yyerror (char const *msg)
+{
+ printf ("%lu: %s\n", (unsigned long int) counter, msg);
+}
+
+int
+main (void)
+{
+ yydebug = !!getenv ("YYDEBUG");
+ return yyparse ();
+}
+]])
+
+AT_CHECK([bison -o input.c input.y])
+AT_COMPILE([input])
+AT_PARSER_CHECK([./input], 1,
+[[sending: 'x' (0)
+thing (0): 'x' (0)
+sending: 'x' (1)
+thing (1): 'x' (1)
+sending: 'x' (2)
+thing (2): 'x' (2)
+sending: 'x' (3)
+4: syntax error
+sending: 'x' (4)
+sending: 'x' (5)
+sending: ';' (6)
+line (-1): error ';' (6)
+sending: 'x' (7)
+thing (7): 'x' (7)
+sending: 'x' (8)
+thing (8): 'x' (8)
+sending: ';' (9)
+line (7): thing (7) thing (8) ';' (9)
+sending: 'x' (10)
+thing (10): 'x' (10)
+sending: ';' (11)
+line (10): thing (10) ';' (11)
+sending: 'y' (12)
+13: syntax error
+sending: EOF
+]])
+
+AT_CLEANUP
+
+
+