+# AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR(FILE-NAME, SIZE)
+# --------------------------------------------------
+# Create FILE-NAME, containing a self checking parser for a grammar
+# requiring SIZE lookahead tokens.
+m4_define([AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR],
+[AT_BISON_OPTION_PUSHDEFS
+AT_DATA([[gengram.pl]],
+[[#! /usr/bin/perl -w
+
+use strict;
+use Text::Wrap;
+my $max = $ARGV[0] || 10;
+
+print <<EOF;
+%error-verbose
+%debug
+%{
+]AT_DATA_SOURCE_PROLOGUE[
+# include <stdio.h>
+# include <stdlib.h>
+# include <assert.h>
+# define MAX $max
+]AT_YYLEX_DECLARE[
+]AT_YYERROR_DECLARE[
+%}
+%union
+{
+ int val;
+};
+
+%type <val> input exp
+%token token
+EOF
+
+print
+ wrap ("%type <val> ",
+ " ",
+ map { "n$_" } (1 .. $max)),
+ "\n";
+
+print "%token\n";
+for my $count (1 .. $max)
+ {
+ print " t$count $count \"$count\"\n";
+ };
+
+print <<EOF;
+%%
+input:
+ exp { assert (\@S|@1 == 1); \$\$ = \@S|@1; }
+| input exp { assert (\@S|@2 == \@S|@1 + 1); \$\$ = \@S|@2; }
+;
+
+exp:
+ n1 "1" { assert (\@S|@1 == 1); \@S|@\@S|@ = \@S|@1; }
+EOF
+
+for my $count (2 .. $max)
+ {
+ print "| n$count \"$count\" { assert (\@S|@1 == $count); \@S|@\@S|@ = \@S|@1; }\n";
+ };
+print ";\n";
+
+for my $count (1 .. $max)
+ {
+ print "n$count: token { \$\$ = $count; };\n";
+ };
+
+print <<\EOF;
+%%
+]AT_YYERROR_DEFINE[
+static int
+yylex (void)
+{
+ static int return_token = 1;
+ static int counter = 1;
+ if (counter > MAX)
+ {
+ assert (counter++ == MAX + 1);
+ return 0;
+ }
+ if (return_token)
+ {
+ return_token = 0;
+ return token;
+ }
+ return_token = 1;
+ return counter++;
+}
+
+int
+main (void)
+{
+ yydebug = !!getenv ("YYDEBUG");
+ return yyparse ();
+}
+EOF
+]])
+
+AT_CHECK([$PERL -w ./gengram.pl $2 || exit 77], 0, [stdout])
+mv stdout $1
+AT_BISON_OPTION_POPDEFS
+])
+
+
+## ------------------------ ##
+## Many lookahead tokens. ##
+## ------------------------ ##
+
+AT_SETUP([Many lookahead tokens])
+
+AT_DATA_LOOKAHEAD_TOKENS_GRAMMAR([input.y], [1000])
+
+# GNU m4 requires about 70 MiB for this test on a 32-bit host.
+# Ask for 200 MiB, which should be plenty even on a 64-bit host.
+AT_INCREASE_DATA_SIZE(204000)
+
+AT_BISON_CHECK([-v -o input.c input.y])
+AT_COMPILE([input])
+AT_PARSER_CHECK([./input])
+
+AT_CLEANUP
+
+
+
+# AT_DATA_STACK_TORTURE(C-PROLOGUE, [BISON-DECLS])
+# ------------------------------------------------