+
+AT_DATA([input.y],
+[{}
+])
+AT_BISON_CHECK([input.y], [1], [],
+[[input.y:1.1-2: syntax error, unexpected {...}
+]])
+
+
+AT_DATA_GRAMMAR([input.y],
+[[%{
+/* This is seen in GCC: a %{ and %} in middle of a comment. */
+const char *foo = "So %{ and %} can be here too.";
+
+#if 0
+/* These examples test Bison while not stressing C compilers too much.
+ Many C compilers mishandle backslash-newlines, so this part of the
+ test is inside "#if 0". The comment and string are written so that
+ the "#endif" will be seen regardless of the C compiler bugs that we
+ know about, namely:
+
+ HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
+ comment.
+
+ The Apple Darwin compiler (as of late 2002) mishandles
+ \\[newline]' within a character constant.
+
+ */
+
+/\
+* A comment with backslash-newlines in it. %} *\
+\
+/
+/* { Close the above comment, if the C compiler mishandled it. */
+
+char str[] = "\\
+" A string with backslash-newlines in it %{ %} \\
+\
+"";
+
+char apostrophe = '\'';
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+%}
+/* %{ and %} can be here too. */
+
+%{
+/* Exercise pre-prologue dependency to %union. */
+typedef int value;
+%}
+
+/* Exercise M4 quoting: '@:>@@:>@', 0. */
+
+/* Also exercise %union. */
+%union
+{
+ value ival; /* A comment to exercise an old bug. */
+};
+
+
+/* Exercise post-prologue dependency to %union. */
+%{
+static YYSTYPE value_as_yystype (value val);
+
+/* Exercise quotes in declarations. */
+char quote[] = "@:>@@:>@,";
+%}
+
+%{
+static void yyerror (const char *s);
+static int yylex (void);
+%}
+
+%type <ival> '@<:@'
+
+/* Exercise quotes in strings. */
+%token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
+
+%%
+/* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
+exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
+ {
+ /* Exercise quotes in braces. */
+ char tmp[] = "@<:@%c@:>@,\n";
+ printf (tmp, $1);
+ }
+;
+
+two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
+oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
+output.or.oline.opt: ;|oline;;|output;;;
+output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
+%%
+/* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
+
+static YYSTYPE
+value_as_yystype (value val)
+{
+ YYSTYPE res;
+ res.ival = val;
+ return res;
+}
+
+static int
+yylex (void)
+{
+ static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\
+#output "; /* "
+ */
+ static size_t toknum;
+ if (! (toknum < sizeof input))
+ abort ();
+ yylval = value_as_yystype (input[toknum]);
+ return input[toknum++];
+}
+
+static void
+yyerror (const char *msg)
+{
+ fprintf (stderr, "%s\n", msg);
+}
+]])
+
+# Pacify Emacs'font-lock-mode: "
+
+AT_DATA([main.c],
+[[typedef int value;
+#include "input.h"
+
+int yyparse (void);
+
+int
+main (void)
+{
+ return yyparse ();
+}
+]])
+
+AT_BISON_CHECK([-d -v -o input.c input.y])
+AT_COMPILE([input.o], [-c input.c])
+AT_COMPILE([main.o], [-c main.c])
+AT_COMPILE([input], [input.o main.o])
+AT_PARSER_CHECK([./input], 0,
+[[[@<:@],
+]])
+
+AT_CLEANUP
+
+
+## ---------------------- ##
+## Typed symbol aliases. ##
+## ---------------------- ##
+
+AT_SETUP([Typed symbol aliases])
+
+# Bison 2.0 broke typed symbol aliases - ensure they work.
+
+AT_DATA_GRAMMAR([input.y],
+[[%union
+{
+ int val;
+};
+%token <val> MY_TOKEN "MY TOKEN"
+%type <val> exp
+%%
+exp: "MY TOKEN";
+%%
+]])
+
+AT_BISON_CHECK([-o input.c input.y])
+
+AT_CLEANUP
+
+
+## --------- ##
+## Require. ##
+## --------- ##
+
+m4_define([AT_CHECK_REQUIRE],
+[AT_SETUP([Require $1])
+AT_DATA_GRAMMAR([input.y],
+[[%require "$1";
+%%
+empty_file:;
+]])
+AT_BISON_CHECK([-o input.c input.y], $2, [], ignore)
+AT_CLEANUP
+])
+
+AT_CHECK_REQUIRE(1.0, 0)
+AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
+## FIXME: Some day augment this version number.
+AT_CHECK_REQUIRE(100.0, 63)
+
+
+## ------------------------------------- ##
+## String aliases for character tokens. ##
+## ------------------------------------- ##
+
+AT_SETUP([String aliases for character tokens])
+
+# Bison once thought a character token and its alias were different
+# symbols with the same user token number.
+
+AT_DATA_GRAMMAR([input.y],
+[[%token 'a' "a"
+%%
+start: 'a';
+%%
+]])
+
+AT_BISON_CHECK([-o input.c input.y])
+
+AT_CLEANUP
+
+
+## --------------------- ##
+## Unclosed constructs. ##
+## --------------------- ##
+
+AT_SETUP([Unclosed constructs])
+
+# Bison's scan-gram.l once forgot to STRING_FINISH some unclosed
+# constructs, so they were prepended to whatever it STRING_GROW'ed
+# next. It also threw them away rather than returning them to the
+# parser. The effect was confusing subsequent error messages.
+
+AT_DATA([input.y],
+[[%token A "a
+%token B "b"
+%token AB "ab" // Used to complain that "ab" was already used.
+%token C '1
+%token TWO "2"
+%token TICK_TWELVE "'12" // Used to complain that "'12" was already used.
+
+%%
+
+start: ;
+
+// Used to report a syntax error because it didn't see any kind of symbol
+// identifier.
+%type <f> 'a
+;
+%type <f> "a
+;
+// Used to report a syntax error because it didn't see braced code.
+%destructor { free ($$)
+]])
+
+AT_BISON_CHECK([-o input.c input.y], 1, [],
+[[input.y:1.10-2.0: missing `"' at end of line
+input.y:4.10-5.0: missing `'' at end of line
+input.y:14.11-15.0: missing `'' at end of line
+input.y:16.11-17.0: missing `"' at end of line
+input.y:19.13-20.0: missing `}' at end of file
+input.y:20.1: syntax error, unexpected end of file
+]])
+
+AT_CLEANUP
+
+
+## ------------------------- ##
+## %start after first rule. ##
+## ------------------------- ##
+
+AT_SETUP([%start after first rule])
+
+# Bison once complained that a %start after the first rule was a
+# redeclaration of the start symbol.
+
+AT_DATA([input.y],
+[[%%
+false_start: ;
+start: false_start ;
+%start start;
+]])
+
+AT_BISON_CHECK([-o input.c input.y])
+
+AT_CLEANUP
+
+
+## --------------------- ##
+## %prec takes a token. ##
+## --------------------- ##
+
+AT_SETUP([%prec takes a token])
+
+# Bison once allowed %prec sym where sym was a nonterminal.