#! /bin/sh
## --------------------- ##
## M4sh Initialization.  ##
## --------------------- ##

# Be Bourne compatible
if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
  emulate sh
  NULLCMD=:
  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
  # is contrary to our usage.  Disable this feature.
  alias -g '${1+"$@"}'='"$@"'
elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
  set -o posix
fi

# Support unset when possible.
if (FOO=FOO; unset FOO) >/dev/null 2>&1; then
  as_unset=unset
else
  as_unset=false
fi


# Work around bugs in pre-3.0 UWIN ksh.
$as_unset ENV MAIL MAILPATH
PS1='$ '
PS2='> '
PS4='+ '

# NLS nuisances.
for as_var in \
  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
  LC_TELEPHONE LC_TIME
do
  if (set +x; test -n "`(eval $as_var=C; export $as_var) 2>&1`"); then
    eval $as_var=C; export $as_var
  else
    $as_unset $as_var
  fi
done

# Required to use basename.
if expr a : '\(a\)' >/dev/null 2>&1; then
  as_expr=expr
else
  as_expr=false
fi

if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
  as_basename=basename
else
  as_basename=false
fi


# Name of the executable.
as_me=`$as_basename "$0" ||
$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
	 X"$0" : 'X\(//\)$' \| \
	 X"$0" : 'X\(/\)$' \| \
	 .     : '\(.\)' 2>/dev/null ||
echo X/"$0" |
    sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
  	  /^X\/\(\/\/\)$/{ s//\1/; q; }
  	  /^X\/\(\/\).*/{ s//\1/; q; }
  	  s/.*/./; q'`


# PATH needs CR, and LINENO needs CR and PATH.
# Avoid depending upon Character Ranges.
as_cr_letters='abcdefghijklmnopqrstuvwxyz'
as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
as_cr_Letters=$as_cr_letters$as_cr_LETTERS
as_cr_digits='0123456789'
as_cr_alnum=$as_cr_Letters$as_cr_digits

# The user is always right.
if test "${PATH_SEPARATOR+set}" != set; then
  echo "#! /bin/sh" >conf$$.sh
  echo  "exit 0"   >>conf$$.sh
  chmod +x conf$$.sh
  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
    PATH_SEPARATOR=';'
  else
    PATH_SEPARATOR=:
  fi
  rm -f conf$$.sh
fi


  as_lineno_1=$LINENO
  as_lineno_2=$LINENO
  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
  test "x$as_lineno_1" != "x$as_lineno_2" &&
  test "x$as_lineno_3"  = "x$as_lineno_2"  || {
  # Find who we are.  Look in the path if we contain no path at all
  # relative or not.
  case $0 in
    *[\\/]* ) as_myself=$0 ;;
    *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
done

       ;;
  esac
  # We did not find ourselves, most probably we were run as `sh COMMAND'
  # in which case we are not to be found in the path.
  if test "x$as_myself" = x; then
    as_myself=$0
  fi
  if test ! -f "$as_myself"; then
    { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2
   { (exit 1); exit 1; }; }
  fi
  case $CONFIG_SHELL in
  '')
    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
  for as_base in sh bash ksh sh5; do
	 case $as_dir in
	 /*)
	   if ("$as_dir/$as_base" -c '
  as_lineno_1=$LINENO
  as_lineno_2=$LINENO
  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
  test "x$as_lineno_1" != "x$as_lineno_2" &&
  test "x$as_lineno_3"  = "x$as_lineno_2" ') 2>/dev/null; then
	     $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
	     $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
	     CONFIG_SHELL=$as_dir/$as_base
	     export CONFIG_SHELL
	     exec "$CONFIG_SHELL" "$0" ${1+"$@"}
	   fi;;
	 esac
       done
done
;;
  esac

  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
  # uniformly replaced by the line number.  The first 'sed' inserts a
  # line-number line before each line; the second 'sed' does the real
  # work.  The second script uses 'N' to pair each line-number line
  # with the numbered line, and appends trailing '-' during
  # substitution so that $LINENO is not a special case at line end.
  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
  # second 'sed' script.  Blame Lee E. McMahon for sed's syntax.  :-)
  sed '=' <$as_myself |
    sed '
      N
      s,$,-,
      : loop
      s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
      t loop
      s,-$,,
      s,^['$as_cr_digits']*\n,,
    ' >$as_me.lineno &&
  chmod +x $as_me.lineno ||
    { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
   { (exit 1); exit 1; }; }

  # Don't try to exec as it changes $[0], causing all sort of problems
  # (the dirname of $[0] is not the place where we might find the
  # original and so on.  Autoconf is especially sensible to this).
  . ./$as_me.lineno
  # Exit status is that of the last command.
  exit
}


case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
  *c*,-n*) ECHO_N= ECHO_C='
' ECHO_T='	' ;;
  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
esac

if expr a : '\(a\)' >/dev/null 2>&1; then
  as_expr=expr
else
  as_expr=false
fi

rm -f conf$$ conf$$.exe conf$$.file
echo >conf$$.file
if ln -s conf$$.file conf$$ 2>/dev/null; then
  # We could just check for DJGPP; but this test a) works b) is more generic
  # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
  if test -f conf$$.exe; then
    # Don't use ln at all; we don't have any links
    as_ln_s='cp -p'
  else
    as_ln_s='ln -s'
  fi
elif ln conf$$.file conf$$ 2>/dev/null; then
  as_ln_s=ln
else
  as_ln_s='cp -p'
fi
rm -f conf$$ conf$$.exe conf$$.file

if mkdir -p . 2>/dev/null; then
  as_mkdir_p=:
else
  as_mkdir_p=false
fi

as_executable_p="test -f"

# Sed expression to map a string onto a valid CPP name.
as_tr_cpp="sed y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g"

# Sed expression to map a string onto a valid variable name.
as_tr_sh="sed y%*+%pp%;s%[^_$as_cr_alnum]%_%g"


# IFS
# We need space, tab and new line, in precisely that order.
as_nl='
'
IFS=" 	$as_nl"

# CDPATH.
$as_unset CDPATH

# PATH needs CR, and LINENO needs CR and PATH.
# Avoid depending upon Character Ranges.
as_cr_letters='abcdefghijklmnopqrstuvwxyz'
as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
as_cr_Letters=$as_cr_letters$as_cr_LETTERS
as_cr_digits='0123456789'
as_cr_alnum=$as_cr_Letters$as_cr_digits

# The user is always right.
if test "${PATH_SEPARATOR+set}" != set; then
  echo "#! /bin/sh" >conf$$.sh
  echo  "exit 0"   >>conf$$.sh
  chmod +x conf$$.sh
  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
    PATH_SEPARATOR=';'
  else
    PATH_SEPARATOR=:
  fi
  rm -f conf$$.sh
fi


  as_lineno_1=$LINENO
  as_lineno_2=$LINENO
  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
  test "x$as_lineno_1" != "x$as_lineno_2" &&
  test "x$as_lineno_3"  = "x$as_lineno_2"  || {
  # Find who we are.  Look in the path if we contain no path at all
  # relative or not.
  case $0 in
    *[\\/]* ) as_myself=$0 ;;
    *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
done

       ;;
  esac
  # We did not find ourselves, most probably we were run as `sh COMMAND'
  # in which case we are not to be found in the path.
  if test "x$as_myself" = x; then
    as_myself=$0
  fi
  if test ! -f "$as_myself"; then
    { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2
   { (exit 1); exit 1; }; }
  fi
  case $CONFIG_SHELL in
  '')
    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
  for as_base in sh bash ksh sh5; do
	 case $as_dir in
	 /*)
	   if ("$as_dir/$as_base" -c '
  as_lineno_1=$LINENO
  as_lineno_2=$LINENO
  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
  test "x$as_lineno_1" != "x$as_lineno_2" &&
  test "x$as_lineno_3"  = "x$as_lineno_2" ') 2>/dev/null; then
	     $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
	     $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
	     CONFIG_SHELL=$as_dir/$as_base
	     export CONFIG_SHELL
	     exec "$CONFIG_SHELL" "$0" ${1+"$@"}
	   fi;;
	 esac
       done
done
;;
  esac

  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
  # uniformly replaced by the line number.  The first 'sed' inserts a
  # line-number line before each line; the second 'sed' does the real
  # work.  The second script uses 'N' to pair each line-number line
  # with the numbered line, and appends trailing '-' during
  # substitution so that $LINENO is not a special case at line end.
  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
  # second 'sed' script.  Blame Lee E. McMahon for sed's syntax.  :-)
  sed '=' <$as_myself |
    sed '
      N
      s,$,-,
      : loop
      s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
      t loop
      s,-$,,
      s,^['$as_cr_digits']*\n,,
    ' >$as_me.lineno &&
  chmod +x $as_me.lineno ||
    { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
   { (exit 1); exit 1; }; }

  # Don't try to exec as it changes $[0], causing all sort of problems
  # (the dirname of $[0] is not the place where we might find the
  # original and so on.  Autoconf is especially sensible to this).
  . ./$as_me.lineno
  # Exit status is that of the last command.
  exit
}


case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
  *c*,-n*) ECHO_N= ECHO_C='
' ECHO_T='	' ;;
  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
esac

if expr a : '\(a\)' >/dev/null 2>&1; then
  as_expr=expr
else
  as_expr=false
fi

rm -f conf$$ conf$$.exe conf$$.file
echo >conf$$.file
if ln -s conf$$.file conf$$ 2>/dev/null; then
  # We could just check for DJGPP; but this test a) works b) is more generic
  # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
  if test -f conf$$.exe; then
    # Don't use ln at all; we don't have any links
    as_ln_s='cp -p'
  else
    as_ln_s='ln -s'
  fi
elif ln conf$$.file conf$$ 2>/dev/null; then
  as_ln_s=ln
else
  as_ln_s='cp -p'
fi
rm -f conf$$ conf$$.exe conf$$.file

if mkdir -p . 2>/dev/null; then
  as_mkdir_p=:
else
  as_mkdir_p=false
fi

as_executable_p="test -f"

# Sed expression to map a string onto a valid CPP name.
as_tr_cpp="sed y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g"

# Sed expression to map a string onto a valid variable name.
as_tr_sh="sed y%*+%pp%;s%[^_$as_cr_alnum]%_%g"


# IFS
# We need space, tab and new line, in precisely that order.
as_nl='
'
IFS=" 	$as_nl"

# CDPATH.
$as_unset CDPATH



SHELL=${CONFIG_SHELL-/bin/sh}

# How were we run?
at_cli_args="$@"

# Load the config file.
for at_file in atconfig atlocal
do
  test -r $at_file || continue
  . ./$at_file || { echo "$as_me: error: invalid content: $at_file" >&2
   { (exit 1); exit 1; }; }
done

# atconfig delivers paths relative to the directory the test suite is
# in, but the groups themselves are run in testsuite-dir/group-dir.
if test -n "$at_top_srcdir"; then
  builddir=../..
  for at_dir in srcdir top_srcdir top_builddir
  do
    at_val=`eval echo '${'at_$at_dir'}'`
    eval "$at_dir=$at_val/../.."
  done
fi

# Not all shells have the 'times' builtin; the subshell is needed to make
# sure we discard the 'times: not found' message from the shell.
at_times_skip=:
(times) >/dev/null 2>&1 && at_times_skip=false

# CLI Arguments to pass to the debugging scripts.
at_debug_args=
# -e sets to true
at_errexit_p=false
# Shall we be verbose?
at_verbose=:
at_quiet=echo

# Shall we keep the debug scripts?  Must be `:' when the suite is
# run by a debug script, so that the script doesn't remove itself.
at_debug_p=false
# Display help message?
at_help_p=false
# List test groups?
at_list_p=false
# Test groups to run
at_groups=

# The directory we are in.
at_dir=`pwd`
# The directory the whole suite works in.
# Should be absolutely to let the user `cd' at will.
at_suite_dir=$at_dir/$as_me.dir
# The file containing the location of the last AT_CHECK.
at_check_line_file=$at_suite_dir/at-check-line
# The files containing the output of the tested commands.
at_stdout=$at_suite_dir/at-stdout
at_stder1=$at_suite_dir/at-stder1
at_stderr=$at_suite_dir/at-stderr
# The file containing dates.
at_times_file=$at_suite_dir/at-times

# List of the tested programs.
at_tested='bison'
# List of the all the test groups.
at_groups_all=' banner-1 1 2 3 4 banner-2 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 banner-3 21 22 23 banner-4 24 25 26 27 28 29 banner-5 30 31 32 33 34 banner-6 35 36 37 38 banner-7 39 40 41 42 banner-8 43 44 45 46 47 48 49 50 51 banner-9 52 53 54 55 56 57 58 59 60 61 62 63 64 banner-10 65 66 67 68 69 70 71 72 73 74 75 76 77 banner-11 78 79 80 81 82 banner-12 83 84 banner-13 85 86 87 88 89 90 91 92 93 94 banner-14 95 96 97 98 99 100 101 102 103 banner-15 104'
# As many dots as there are digits in the last test group number.
# Used to normalize the test group numbers so that `ls' lists them in
# numerical order.
at_format='...'
# Description of all the test groups.
at_help_all=
at_help_all=$at_help_all'1;input.at:28;Invalid $n;
'
at_help_all=$at_help_all'2;input.at:46;Invalid @n;
'
at_help_all=$at_help_all'3;input.at:64;Type Clashes;
'
at_help_all=$at_help_all'4;input.at:93;Torturing the Scanner;
'
at_help_all=$at_help_all'5;output.at:38;Output files:  & -dv.;
'
at_help_all=$at_help_all'6;output.at:40;Output files:  & -dv -o foo.c.;
'
at_help_all=$at_help_all'7;output.at:42;Output files:  & -dv -o foo.tab.c.;
'
at_help_all=$at_help_all'8;output.at:44;Output files:  & -dv -y.;
'
at_help_all=$at_help_all'9;output.at:46;Output files:  & -dv -b bar.;
'
at_help_all=$at_help_all'10;output.at:48;Output files:  & -dv -g -o foo.c.;
'
at_help_all=$at_help_all'11;output.at:52;Output files: %defines %verbose & .;
'
at_help_all=$at_help_all'12;output.at:54;Output files: %defines %verbose %yacc & .;
'
at_help_all=$at_help_all'13;output.at:57;Output files: %defines %verbose %yacc & .;
'
at_help_all=$at_help_all'14;output.at:61;Output files: %file-prefix="bar" %defines %verbose & .;
'
at_help_all=$at_help_all'15;output.at:63;Output files: %output="bar.c" %defines %verbose %yacc & .;
'
at_help_all=$at_help_all'16;output.at:67;Output files: %file-prefix="baz" %output="bar.c" %defines %verbose %yacc & .;
'
at_help_all=$at_help_all'17;output.at:72;Output files: %defines %verbose & .;
'
at_help_all=$at_help_all'18;output.at:75;Output files: %defines %verbose  & -o foo.c.;
'
at_help_all=$at_help_all'19;output.at:79;Output files:  & --defines=foo.hpp -o foo.c++.;
'
at_help_all=$at_help_all'20;output.at:83;Output files:  & -o foo.c++ --graph=foo.gph.;
'
at_help_all=$at_help_all'21;sets.at:66;Nullable;
'
at_help_all=$at_help_all'22;sets.at:151;Broken Closure;
'
at_help_all=$at_help_all'23;sets.at:193;Firsts;
'
at_help_all=$at_help_all'24;reduce.at:26;Useless Terminals;
'
at_help_all=$at_help_all'25;reduce.at:70;Useless Nonterminals;
'
at_help_all=$at_help_all'26;reduce.at:125;Useless Rules;report
'
at_help_all=$at_help_all'27;reduce.at:212;Reduced Automaton;report
'
at_help_all=$at_help_all'28;reduce.at:301;Underivable Rules;report
'
at_help_all=$at_help_all'29;reduce.at:342;Empty Language;
'
at_help_all=$at_help_all'30;synclines.at:93;Prologue synch line;
'
at_help_all=$at_help_all'31;synclines.at:112;%union synch line;
'
at_help_all=$at_help_all'32;synclines.at:135;Postprologue synch line;
'
at_help_all=$at_help_all'33;synclines.at:154;Action synch line;
'
at_help_all=$at_help_all'34;synclines.at:172;Epilogue synch line;
'
at_help_all=$at_help_all'35;headers.at:27;%union and --defines;
'
at_help_all=$at_help_all'36;headers.at:76;Invalid CPP guards: input/input;
'
at_help_all=$at_help_all'37;headers.at:77;Invalid CPP guards: 9foo;
'
at_help_all=$at_help_all'38;headers.at:86;export YYLTYPE;
'
at_help_all=$at_help_all'39;actions.at:25;Mid-rule actions;
'
at_help_all=$at_help_all'40;actions.at:89;Actions after errors;
'
at_help_all=$at_help_all'41;actions.at:236;Exotic Dollars;
'
at_help_all=$at_help_all'42;actions.at:514;Printers and Destructors: ;
'
at_help_all=$at_help_all'43;conflicts.at:31;S/R in initial;
'
at_help_all=$at_help_all'44;conflicts.at:51;%nonassoc and eof;
'
at_help_all=$at_help_all'45;conflicts.at:131;Unresolved SR Conflicts;report
'
at_help_all=$at_help_all'46;conflicts.at:238;Resolved SR Conflicts;report
'
at_help_all=$at_help_all'47;conflicts.at:360;Defaulted Conflicted Reduction;report
'
at_help_all=$at_help_all'48;conflicts.at:479;%expect not enough;
'
at_help_all=$at_help_all'49;conflicts.at:499;%expect right;
'
at_help_all=$at_help_all'50;conflicts.at:516;%expect too much;
'
at_help_all=$at_help_all'51;conflicts.at:536;%expect with reduce conflicts;
'
at_help_all=$at_help_all'52;calc.at:547;Calculator ;
'
at_help_all=$at_help_all'53;calc.at:549;Calculator %defines;
'
at_help_all=$at_help_all'54;calc.at:550;Calculator %locations;
'
at_help_all=$at_help_all'55;calc.at:551;Calculator %name-prefix="calc";
'
at_help_all=$at_help_all'56;calc.at:552;Calculator %verbose;
'
at_help_all=$at_help_all'57;calc.at:553;Calculator %yacc;
'
at_help_all=$at_help_all'58;calc.at:554;Calculator %error-verbose;
'
at_help_all=$at_help_all'59;calc.at:556;Calculator %error-verbose %locations;
'
at_help_all=$at_help_all'60;calc.at:558;Calculator %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc;
'
at_help_all=$at_help_all'61;calc.at:560;Calculator %debug;
'
at_help_all=$at_help_all'62;calc.at:561;Calculator %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc;
'
at_help_all=$at_help_all'63;calc.at:563;Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc;
'
at_help_all=$at_help_all'64;calc.at:565;Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count};
'
at_help_all=$at_help_all'65;calc.at:582;Calculator %glr-parser ;
'
at_help_all=$at_help_all'66;calc.at:584;Calculator %glr-parser %defines;
'
at_help_all=$at_help_all'67;calc.at:585;Calculator %glr-parser %locations;
'
at_help_all=$at_help_all'68;calc.at:586;Calculator %glr-parser %name-prefix="calc";
'
at_help_all=$at_help_all'69;calc.at:587;Calculator %glr-parser %verbose;
'
at_help_all=$at_help_all'70;calc.at:588;Calculator %glr-parser %yacc;
'
at_help_all=$at_help_all'71;calc.at:589;Calculator %glr-parser %error-verbose;
'
at_help_all=$at_help_all'72;calc.at:591;Calculator %glr-parser %error-verbose %locations;
'
at_help_all=$at_help_all'73;calc.at:593;Calculator %glr-parser %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc;
'
at_help_all=$at_help_all'74;calc.at:595;Calculator %glr-parser %debug;
'
at_help_all=$at_help_all'75;calc.at:596;Calculator %glr-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc;
'
at_help_all=$at_help_all'76;calc.at:598;Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc;
'
at_help_all=$at_help_all'77;calc.at:600;Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count};
'
at_help_all=$at_help_all'78;torture.at:140;Big triangle;
'
at_help_all=$at_help_all'79;torture.at:231;Big horizontal;
'
at_help_all=$at_help_all'80;torture.at:366;Many lookaheads;
'
at_help_all=$at_help_all'81;torture.at:440;Exploding the Stack Size with Alloca;
'
at_help_all=$at_help_all'82;torture.at:461;Exploding the Stack Size with Malloc;
'
at_help_all=$at_help_all'83;existing.at:24;GNU AWK Grammar;
'
at_help_all=$at_help_all'84;existing.at:364;GNU Cim Grammar;
'
at_help_all=$at_help_all'85;regression.at:27;Early token definitions;
'
at_help_all=$at_help_all'86;regression.at:65;Braces parsing;
'
at_help_all=$at_help_all'87;regression.at:87;Duplicate string;
'
at_help_all=$at_help_all'88;regression.at:113;Rule Line Numbers;report
'
at_help_all=$at_help_all'89;regression.at:257;Mixing %token styles;
'
at_help_all=$at_help_all'90;regression.at:280;Invalid inputs;
'
at_help_all=$at_help_all'91;regression.at:313;Token definitions;
'
at_help_all=$at_help_all'92;regression.at:341;Characters Escapes;
'
at_help_all=$at_help_all'93;regression.at:372;Web2c Report;report
'
at_help_all=$at_help_all'94;regression.at:549;Web2c Actions;report
'
at_help_all=$at_help_all'95;cxx-type.at:255;GLR: Resolve ambiguity, impure, no locations;
'
at_help_all=$at_help_all'96;cxx-type.at:262;GLR: Resolve ambiguity, impure, locations;
'
at_help_all=$at_help_all'97;cxx-type.at:268;GLR: Resolve ambiguity, pure, no locations;
'
at_help_all=$at_help_all'98;cxx-type.at:275;GLR: Resolve ambiguity, pure, locations;
'
at_help_all=$at_help_all'99;cxx-type.at:282;GLR: Merge conflicting parses, impure, no locations;
'
at_help_all=$at_help_all'100;cxx-type.at:289;GLR: Merge conflicting parses, impure, locations;
'
at_help_all=$at_help_all'101;cxx-type.at:296;GLR: Merge conflicting parses, pure, no locations;
'
at_help_all=$at_help_all'102;cxx-type.at:302;GLR: Merge conflicting parses, pure, locations;
'
at_help_all=$at_help_all'103;cxx-type.at:309;GLR: Verbose messages, resolve ambiguity, impure, no locations;
'
at_help_all=$at_help_all'104;glr-regr1.at:21;Badly Collapsed GLR States;
'



while test $# -gt 0; do
  case $1 in
    --help | -h )
        at_help_p=:
        ;;

    --list | -l )
        at_list_p=:
        ;;

    --version | -V )
        echo "$as_me (GNU Bison 1.875)"
        exit 0
        ;;

    --clean | -c )
        rm -rf $at_suite_dir $as_me.log
        exit 0
        ;;

    --debug | -d )
        at_debug_p=:
        ;;

    --errexit | -e )
        at_debug_p=:
        at_errexit_p=:
        ;;

    --verbose | -v )
        at_verbose=echo; at_quiet=:
        ;;

    --trace | -x )
        at_traceon='set -vx'; at_traceoff='set +vx'
        ;;

    [0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9])
        at_groups="$at_groups$1 "
        ;;

    # Ranges
    [0-9]- | [0-9][0-9]- | [0-9][0-9][0-9]- | [0-9][0-9][0-9][0-9]-)
        at_range_start=`echo $1 |tr -d '-'`
        at_range=`echo " $at_groups_all " | \
          sed -e 's,^.* '$at_range_start' ,'$at_range_start' ,'`
        at_groups="$at_groups$at_range "
        ;;

    -[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | -[0-9][0-9][0-9][0-9])
        at_range_end=`echo $1 |tr -d '-'`
        at_range=`echo " $at_groups_all " | \
          sed -e 's, '$at_range_end' .*$, '$at_range_end','`
        at_groups="$at_groups$at_range "
        ;;

    [0-9]-[0-9] | [0-9]-[0-9][0-9] | [0-9]-[0-9][0-9][0-9] | \
    [0-9]-[0-9][0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9] | \
    [0-9][0-9]-[0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9][0-9][0-9] | \
    [0-9][0-9][0-9]-[0-9][0-9][0-9] | \
    [0-9][0-9][0-9]-[0-9][0-9][0-9][0-9] | \
    [0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9] )
        at_range_start=`echo $1 |sed 's,-.*,,'`
        at_range_end=`echo $1 |sed 's,.*-,,'`
        # FIXME: Maybe test to make sure start <= end?
        at_range=`echo " $at_groups_all " | \
          sed -e 's,^.* '$at_range_start' ,'$at_range_start' ,' \
              -e 's, '$at_range_end' .*$, '$at_range_end','`
        at_groups="$at_groups$at_range "
        ;;

    # Keywords.
    --keywords | -k )
        shift
        at_groups_selected=$at_help_all
        for at_keyword in `IFS=,; set X $1; shift; echo ${1+$@}`
        do
          # It is on purpose that we match the test group titles too.
          at_groups_selected=`echo "$at_groups_selected" |
			      grep -i "^[^;]*;[^;]*;.*$at_keyword"`
        done
        at_groups_selected=`echo "$at_groups_selected" | sed 's/;.*//'`
	# Smash the end of lines.
	at_groups_selected=`echo $at_groups_selected`
        at_groups="$at_groups$at_groups_selected "
        ;;

    *=*)
  	at_envvar=`expr "x$1" : 'x\([^=]*\)='`
  	# Reject names that are not valid shell variable names.
  	expr "x$at_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
  	  { echo "$as_me: error: invalid variable name: $at_envvar" >&2
   { (exit 1); exit 1; }; }
  	at_value=`expr "x$1" : 'x[^=]*=\(.*\)'`
  	at_value=`echo "$at_value" | sed "s/'/'\\\\\\\\''/g"`
  	eval "$at_envvar='$at_value'"
  	export $at_envvar
	# Propagate to debug scripts.
  	at_debug_args="$at_debug_args $1"
  	;;

     *) echo "$as_me: invalid option: $1" >&2
        echo "Try \`$0 --help' for more information." >&2
        exit 1
        ;;
  esac
  shift
done

# Selected test groups.
test -z "$at_groups" && at_groups=$at_groups_all

# Help message.
if $at_help_p; then
  cat <<_ATEOF
Usage: $0 [OPTION]... [VARIABLE=VALUE]... [TESTS]

Run all the tests, or the selected TESTS, and save a detailed log file.
Upon failure, create debugging scripts.

You should not change environment variables unless explicitly passed
as command line arguments.  Set \`AUTOTEST_PATH' to select the executables
to exercise.  Each relative directory is expanded as build and source
directories relatively to the top level of this distribution.  E.g.,

  $ $0 AUTOTEST_PATH=bin

possibly amounts into

  PATH=/tmp/foo-1.0/bin:/src/foo-1.0/bin:\$PATH

Operation modes:
  -h, --help     print the help message, then exit
  -V, --version  print version number, then exit
  -c, --clean    remove all the files this test suite might create and exit
  -l, --list     describes all the tests, or the selected TESTS

Execution tuning:
  -k, --keywords=KEYWORDS
                 select the tests matching all the comma separated KEYWORDS
                 accumulates
  -e, --errexit  abort as soon as a test fails; implies --debug
  -v, --verbose  force more detailed output
                 default for debugging scripts
  -d, --debug    inhibit clean up and debug script creation
                 default for debugging scripts
  -x, --trace    enable tests shell tracing

Report bugs to <bug-bison@gnu.org>.
_ATEOF
  exit 0
fi

# List of tests.
if $at_list_p; then
  cat <<_ATEOF
GNU Bison 1.875 test suite test groups:

 NUM: FILENAME:LINE      TEST-GROUP-NAME
      KEYWORDS

_ATEOF
  # "  1 42  45 " => "^(1|42|45);".
  at_groups_pattern=`echo "$at_groups" | sed 's/^  *//;s/  *$//;s/  */|/g'`
  echo "$at_help_all" |
    awk 'BEGIN { FS = ";" }
         { if ($1 !~ /^('"$at_groups_pattern"')$/) next }
         { if ($1) printf " %3d: %-18s %s\n", $1, $2, $3
           if ($4) printf "      %s\n", $4 } '
  exit 0
fi

# Don't take risks: use only absolute directories in PATH.
#
# For stand-alone test suites, AUTOTEST_PATH is relative to `.'.
#
# For embedded test suites, AUTOTEST_PATH is relative to the top level
# of the package.  Then expand it into build/src parts, since users
# may create executables in both places.
#
# There might be directories that don't exist, but don't redirect
# builtins' (eg., cd) stderr directly: Ultrix's sh hates that.
AUTOTEST_PATH=`echo $AUTOTEST_PATH | tr ':' $PATH_SEPARATOR`
at_path=
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $AUTOTEST_PATH $PATH
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
  case $as_dir in
  [\\/]* | ?:[\\/]* )
    at_path=$at_path$PATH_SEPARATOR$as_dir
    ;;
  * )
    if test -z "$at_top_builddir"; then
      # Stand-alone test suite.
      at_path=$at_path$PATH_SEPARATOR$as_dir
    else
      # Embedded test suite.
      at_path=$at_path$PATH_SEPARATOR$at_top_builddir/$as_dir
      at_path=$at_path$PATH_SEPARATOR$at_top_srcdir/$as_dir
    fi
    ;;
esac
done


# Now build and simplify PATH.
PATH=
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $at_path
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
  as_dir=`(cd "$as_dir" && pwd) 2>/dev/null`
test -d "$as_dir" || continue
case $PATH in
                  $as_dir                 | \
                  $as_dir$PATH_SEPARATOR* | \
  *$PATH_SEPARATOR$as_dir                 | \
  *$PATH_SEPARATOR$as_dir$PATH_SEPARATOR* ) ;;

  '') PATH=$as_dir ;;
   *) PATH=$PATH$PATH_SEPARATOR$as_dir ;;
esac
done

export PATH

# Setting up the FDs.
# 5 is stdout conditioned by verbosity.
if test $at_verbose = echo; then
  exec 5>&1
else
  exec 5>/dev/null
fi

# 6 is the log file.  To be preserved if `-d'.

if $at_debug_p; then
  exec 6>/dev/null
else
  exec 6>$as_me.log
fi

# Banners and logs.
cat <<\_ASBOX
## --------------------------- ##
## GNU Bison 1.875 test suite. ##
## --------------------------- ##
_ASBOX
{
  cat <<\_ASBOX
## --------------------------- ##
## GNU Bison 1.875 test suite. ##
## --------------------------- ##
_ASBOX
  echo

  echo "$as_me: command line was:"
  echo "  $ $0 $at_cli_args"
  echo

  # Try to find a few ChangeLogs in case it might help determining the
  # exact version.  Use the relative dir: if the top dir is a symlink,
  # find will not follow it (and options to follow the links are not
  # portable), which would result in no output here.
  if test -n "$at_top_srcdir"; then
    cat <<\_ASBOX
## ----------- ##
## ChangeLogs. ##
## ----------- ##
_ASBOX
    echo
    for at_file in `find "$at_top_srcdir" -name ChangeLog -print`
    do
      echo "$as_me: $at_file:"
      sed 's/^/| /;10q' $at_file
      echo
    done

    {
cat <<_ASUNAME
## --------- ##
## Platform. ##
## --------- ##

hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
uname -m = `(uname -m) 2>/dev/null || echo unknown`
uname -r = `(uname -r) 2>/dev/null || echo unknown`
uname -s = `(uname -s) 2>/dev/null || echo unknown`
uname -v = `(uname -v) 2>/dev/null || echo unknown`

/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`

/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
hostinfo               = `(hostinfo) 2>/dev/null               || echo unknown`
/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`

_ASUNAME

as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
  echo "PATH: $as_dir"
done

}
    echo
  fi

  # Contents of the config files.
  for at_file in atconfig atlocal
  do
    test -r $at_file || continue
    echo "$as_me: $at_file:"
    sed 's/^/| /' $at_file
    echo
  done

  cat <<\_ASBOX
## ---------------- ##
## Tested programs. ##
## ---------------- ##
_ASBOX
  echo
} >&6

# Report what programs are being tested.
for at_program in : $at_tested
do
  test "$at_program" = : && continue
  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
  IFS=$as_save_IFS
  test -z "$as_dir" && as_dir=.
  test -f $as_dir/$at_program && break
done

  if test -f $as_dir/$at_program; then
    {
      echo "testsuite.at:67: $as_dir/$at_program --version"
      $as_dir/$at_program --version
      echo
    } >&6 2>&1
  else
    { { echo "$as_me:$LINENO: error: cannot find $at_program" >&6
echo "$as_me: error: cannot find $at_program" >&2;}
   { (exit 1); exit 1; }; }
  fi
done

{
  cat <<\_ASBOX
## --------------------------- ##
## Silently running the tests. ##
## --------------------------- ##
_ASBOX
} >&6

at_start_date=`date`
at_start_time=`(date +%s) 2>/dev/null`
echo "$as_me: starting at: $at_start_date" >&6
at_pass_list=
at_fail_list=
at_skip_list=
at_group_count=0

# Create the master directory if it doesn't already exist.
test -d $at_suite_dir ||
  mkdir $at_suite_dir ||
  { { echo "$as_me:$LINENO: error: cannot create $at_suite_dir" >&6
echo "$as_me: error: cannot create $at_suite_dir" >&2;}
   { (exit 1); exit 1; }; }

# Can we diff with `/dev/null'?  DU 5.0 refuses.
if diff /dev/null /dev/null >/dev/null 2>&1; then
  at_devnull=/dev/null
else
  at_devnull=$at_suite_dir/devnull
  cp /dev/null $at_devnull
fi

# Use `diff -u' when possible.
if diff -u $at_devnull $at_devnull >/dev/null 2>&1; then
  at_diff='diff -u'
else
  at_diff=diff
fi


for at_group in $at_groups
do
  # Be sure to come back to the top test directory.
  cd $at_suite_dir

  case $at_group in
    banner-*) ;;
    *)
     # Skip tests we already run (using --keywords makes it easy to get
     # duplication).
     case " $at_pass_test $at_skip_test $at_fail_test " in
       *" $at_group "* ) continue;;
     esac

     # Normalize the test group number.
     at_group_normalized=`expr "00000$at_group" : ".*\($at_format\)"`

     # Create a fresh directory for the next test group, and enter.
     at_group_dir=$at_suite_dir/$at_group_normalized
     rm -rf $at_group_dir
     mkdir $at_group_dir ||
       { { echo "$as_me:$LINENO: error: cannot create $at_group_dir" >&6
echo "$as_me: error: cannot create $at_group_dir" >&2;}
   { (exit 1); exit 1; }; }
     cd $at_group_dir
    ;;
  esac

  at_status=0
  # Clearly separate the test groups when verbose.
  test $at_group_count != 0 && $at_verbose
  case $at_group in

  banner-1 ) # Banner 1. input.at:19
    cat <<\_ATEOF

Input Processing.

_ATEOF
    ;;

  1 ) # 1. input.at:28: Invalid $n
    at_setup_line='input.at:28'
    $at_verbose "1. input.at:28: testing Invalid $n..."
    $at_quiet $ECHO_N "  1: input.at:28       $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%%
exp: { $$ = $1 ; };
_ATEOF


$at_traceoff
$at_verbose "input.at:37: bison input.y"
echo input.at:37 >$at_check_line_file
( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y:2.13-14: integer out of range: \`\$1'
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "input.at:37: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  2 ) # 2. input.at:46: Invalid @n
    at_setup_line='input.at:46'
    $at_verbose "2. input.at:46: testing Invalid @n..."
    $at_quiet $ECHO_N "  2: input.at:46       $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%%
exp: { @$ = @1 ; };
_ATEOF


$at_traceoff
$at_verbose "input.at:55: bison input.y"
echo input.at:55 >$at_check_line_file
( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y:2.13-14: integer out of range: \`@1'
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "input.at:55: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  3 ) # 3. input.at:64: Type Clashes
    at_setup_line='input.at:64'
    $at_verbose "3. input.at:64: testing Type Clashes..."
    $at_quiet $ECHO_N "  3: input.at:64       $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%token foo
%type <bar> exp
%%
exp: foo {} foo
   | foo
   | /* Empty. */
   ;
_ATEOF


$at_traceoff
$at_verbose "input.at:80: bison input.y"
echo input.at:80 >$at_check_line_file
( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y:4.6-15: warning: type clash on default action: <bar> != <>
input.y:5.6-8: warning: type clash on default action: <bar> != <>
input.y:6.5: warning: empty rule for typed nonterminal, and no action
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "input.at:80: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  4 ) # 4. input.at:93: Torturing the Scanner
    at_setup_line='input.at:93'
    $at_verbose "4. input.at:93: testing Torturing the Scanner..."
    $at_quiet $ECHO_N "  4: input.at:93       $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

%{
/* 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>
%}
/* %{ 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 ??!??'??(??)??-??/??<??=??> \x0\0"

%%
/* Exercise M4 quoting: ']]', [, 1.  */
exp: '[' '\1' two '$' '@' '{' oline output
  {
    /* 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: '#' '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 const char *input = "[\1\2$@{@oline@__oline__\
#output "; /* "
  */
  yylval = value_as_yystype (*input);
  return *input++;
}

static void
yyerror (const char *msg)
{
  fprintf (stderr, "%s\n", msg);
}
_ATEOF



# Pacify Emacs'font-lock-mode: "

cat >main.c <<'_ATEOF'
typedef int value;
#include "input.h"

int yyparse (void);

int
main (void)
{
  return yyparse ();
}
_ATEOF


$at_traceoff
$at_verbose "input.at:221: bison -d -v -o input.c input.y"
echo input.at:221 >$at_check_line_file
( $at_traceon; bison -d -v -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "input.at:221: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "input.at:222: \$CC \$CFLAGS \$CPPFLAGS -c input.c -o input.o"
echo input.at:222 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c -o input.o ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "input.at:222: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "input.at:223: \$CC \$CFLAGS \$CPPFLAGS -c main.c -o main.o"
echo input.at:223 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c main.c -o main.o ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "input.at:223: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "input.at:224: \$CC \$CFLAGS \$CPPFLAGS input.o main.o -o input"
echo input.at:224 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS input.o main.o -o input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "input.at:224: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "input.at:227: \$PREPARSER ./input"
echo input.at:227 >$at_check_line_file
( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "[[],
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "input.at:227: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-2 ) # Banner 2. output.at:19
    cat <<\_ATEOF

Output file names.

_ATEOF
    ;;

  5 ) # 5. output.at:38: Output files:  & -dv.
    at_setup_line='output.at:38'
    $at_verbose "5. output.at:38: testing Output files:  & -dv...."
    $at_quiet $ECHO_N "  5: output.at:38      $ECHO_C"
    (
      $at_traceon

cat >foo.y <<'_ATEOF'

%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:38: bison -dv foo.y"
echo output.at:38 >$at_check_line_file
( $at_traceon; bison -dv foo.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:38: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:38: ls foo.output foo.tab.c foo.tab.h"
echo output.at:38 >$at_check_line_file
( $at_traceon; ls foo.output foo.tab.c foo.tab.h ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:38: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  6 ) # 6. output.at:40: Output files:  & -dv -o foo.c.
    at_setup_line='output.at:40'
    $at_verbose "6. output.at:40: testing Output files:  & -dv -o foo.c...."
    $at_quiet $ECHO_N "  6: output.at:40      $ECHO_C"
    (
      $at_traceon

cat >foo.y <<'_ATEOF'

%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:40: bison -dv -o foo.c foo.y"
echo output.at:40 >$at_check_line_file
( $at_traceon; bison -dv -o foo.c foo.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:40: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:40: ls foo.c foo.h foo.output"
echo output.at:40 >$at_check_line_file
( $at_traceon; ls foo.c foo.h foo.output ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:40: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  7 ) # 7. output.at:42: Output files:  & -dv -o foo.tab.c.
    at_setup_line='output.at:42'
    $at_verbose "7. output.at:42: testing Output files:  & -dv -o foo.tab.c...."
    $at_quiet $ECHO_N "  7: output.at:42      $ECHO_C"
    (
      $at_traceon

cat >foo.y <<'_ATEOF'

%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:42: bison -dv -o foo.tab.c foo.y"
echo output.at:42 >$at_check_line_file
( $at_traceon; bison -dv -o foo.tab.c foo.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:42: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:42: ls foo.output foo.tab.c foo.tab.h"
echo output.at:42 >$at_check_line_file
( $at_traceon; ls foo.output foo.tab.c foo.tab.h ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:42: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  8 ) # 8. output.at:44: Output files:  & -dv -y.
    at_setup_line='output.at:44'
    $at_verbose "8. output.at:44: testing Output files:  & -dv -y...."
    $at_quiet $ECHO_N "  8: output.at:44      $ECHO_C"
    (
      $at_traceon

cat >foo.y <<'_ATEOF'

%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:44: bison -dv -y foo.y"
echo output.at:44 >$at_check_line_file
( $at_traceon; bison -dv -y foo.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:44: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:44: ls y.output y.tab.c y.tab.h"
echo output.at:44 >$at_check_line_file
( $at_traceon; ls y.output y.tab.c y.tab.h ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:44: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  9 ) # 9. output.at:46: Output files:  & -dv -b bar.
    at_setup_line='output.at:46'
    $at_verbose "9. output.at:46: testing Output files:  & -dv -b bar...."
    $at_quiet $ECHO_N "  9: output.at:46      $ECHO_C"
    (
      $at_traceon

cat >foo.y <<'_ATEOF'

%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:46: bison -dv -b bar foo.y"
echo output.at:46 >$at_check_line_file
( $at_traceon; bison -dv -b bar foo.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:46: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:46: ls bar.output bar.tab.c bar.tab.h"
echo output.at:46 >$at_check_line_file
( $at_traceon; ls bar.output bar.tab.c bar.tab.h ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:46: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  10 ) # 10. output.at:48: Output files:  & -dv -g -o foo.c.
    at_setup_line='output.at:48'
    $at_verbose "10. output.at:48: testing Output files:  & -dv -g -o foo.c...."
    $at_quiet $ECHO_N " 10: output.at:48      $ECHO_C"
    (
      $at_traceon

cat >foo.y <<'_ATEOF'

%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:48: bison -dv -g -o foo.c foo.y"
echo output.at:48 >$at_check_line_file
( $at_traceon; bison -dv -g -o foo.c foo.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:48: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:48: ls foo.c foo.h foo.output foo.vcg"
echo output.at:48 >$at_check_line_file
( $at_traceon; ls foo.c foo.h foo.output foo.vcg ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:48: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  11 ) # 11. output.at:52: Output files: %defines %verbose & .
    at_setup_line='output.at:52'
    $at_verbose "11. output.at:52: testing Output files: %defines %verbose & ...."
    $at_quiet $ECHO_N " 11: output.at:52      $ECHO_C"
    (
      $at_traceon

cat >foo.y <<'_ATEOF'
%defines %verbose
%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:52: bison  foo.y"
echo output.at:52 >$at_check_line_file
( $at_traceon; bison  foo.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:52: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:52: ls foo.output foo.tab.c foo.tab.h"
echo output.at:52 >$at_check_line_file
( $at_traceon; ls foo.output foo.tab.c foo.tab.h ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:52: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  12 ) # 12. output.at:54: Output files: %defines %verbose %yacc & .
    at_setup_line='output.at:54'
    $at_verbose "12. output.at:54: testing Output files: %defines %verbose %yacc & ...."
    $at_quiet $ECHO_N " 12: output.at:54      $ECHO_C"
    (
      $at_traceon

cat >foo.y <<'_ATEOF'
%defines %verbose %yacc
%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:54: bison  foo.y"
echo output.at:54 >$at_check_line_file
( $at_traceon; bison  foo.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:54: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:54: ls y.output y.tab.c y.tab.h"
echo output.at:54 >$at_check_line_file
( $at_traceon; ls y.output y.tab.c y.tab.h ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:54: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  13 ) # 13. output.at:57: Output files: %defines %verbose %yacc & .
    at_setup_line='output.at:57'
    $at_verbose "13. output.at:57: testing Output files: %defines %verbose %yacc & ...."
    $at_quiet $ECHO_N " 13: output.at:57      $ECHO_C"
    (
      $at_traceon

cat >foo.yy <<'_ATEOF'
%defines %verbose %yacc
%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:57: bison  foo.yy"
echo output.at:57 >$at_check_line_file
( $at_traceon; bison  foo.yy ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:57: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:57: ls y.output y.tab.c y.tab.h"
echo output.at:57 >$at_check_line_file
( $at_traceon; ls y.output y.tab.c y.tab.h ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:57: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  14 ) # 14. output.at:61: Output files: %file-prefix="bar" %defines %verbose & .
    at_setup_line='output.at:61'
    $at_verbose "14. output.at:61: testing Output files: %file-prefix="bar" %defines %verbose & ...."
    $at_quiet $ECHO_N " 14: output.at:61      $ECHO_C"
    (
      $at_traceon

cat >foo.y <<'_ATEOF'
%file-prefix="bar" %defines %verbose
%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:61: bison  foo.y"
echo output.at:61 >$at_check_line_file
( $at_traceon; bison  foo.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:61: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:61: ls bar.output bar.tab.c bar.tab.h"
echo output.at:61 >$at_check_line_file
( $at_traceon; ls bar.output bar.tab.c bar.tab.h ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:61: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  15 ) # 15. output.at:63: Output files: %output="bar.c" %defines %verbose %yacc & .
    at_setup_line='output.at:63'
    $at_verbose "15. output.at:63: testing Output files: %output="bar.c" %defines %verbose %yacc & ...."
    $at_quiet $ECHO_N " 15: output.at:63      $ECHO_C"
    (
      $at_traceon

cat >foo.y <<'_ATEOF'
%output="bar.c" %defines %verbose %yacc
%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:63: bison  foo.y"
echo output.at:63 >$at_check_line_file
( $at_traceon; bison  foo.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:63: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:63: ls bar.output bar.c bar.h"
echo output.at:63 >$at_check_line_file
( $at_traceon; ls bar.output bar.c bar.h ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:63: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  16 ) # 16. output.at:67: Output files: %file-prefix="baz" %output="bar.c" %defines %verbose %yacc & .
    at_setup_line='output.at:67'
    $at_verbose "16. output.at:67: testing Output files: %file-prefix="baz" %output="bar.c" %defines %verbose %yacc & ...."
    $at_quiet $ECHO_N " 16: output.at:67      $ECHO_C"
    (
      $at_traceon

cat >foo.y <<'_ATEOF'
%file-prefix="baz" %output="bar.c" %defines %verbose %yacc
%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:67: bison  foo.y"
echo output.at:67 >$at_check_line_file
( $at_traceon; bison  foo.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:67: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:67: ls bar.output bar.c bar.h"
echo output.at:67 >$at_check_line_file
( $at_traceon; ls bar.output bar.c bar.h ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:67: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  17 ) # 17. output.at:72: Output files: %defines %verbose & .
    at_setup_line='output.at:72'
    $at_verbose "17. output.at:72: testing Output files: %defines %verbose & ...."
    $at_quiet $ECHO_N " 17: output.at:72      $ECHO_C"
    (
      $at_traceon

cat >foo.yy <<'_ATEOF'
%defines %verbose
%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:72: bison  foo.yy"
echo output.at:72 >$at_check_line_file
( $at_traceon; bison  foo.yy ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:72: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:72: ls foo.output foo.tab.cc foo.tab.hh"
echo output.at:72 >$at_check_line_file
( $at_traceon; ls foo.output foo.tab.cc foo.tab.hh ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:72: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  18 ) # 18. output.at:75: Output files: %defines %verbose  & -o foo.c.
    at_setup_line='output.at:75'
    $at_verbose "18. output.at:75: testing Output files: %defines %verbose  & -o foo.c...."
    $at_quiet $ECHO_N " 18: output.at:75      $ECHO_C"
    (
      $at_traceon

cat >foo.yy <<'_ATEOF'
%defines %verbose
%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:75: bison -o foo.c foo.yy"
echo output.at:75 >$at_check_line_file
( $at_traceon; bison -o foo.c foo.yy ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:75: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:75: ls foo.c foo.h foo.output"
echo output.at:75 >$at_check_line_file
( $at_traceon; ls foo.c foo.h foo.output ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:75: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  19 ) # 19. output.at:79: Output files:  & --defines=foo.hpp -o foo.c++.
    at_setup_line='output.at:79'
    $at_verbose "19. output.at:79: testing Output files:  & --defines=foo.hpp -o foo.c++...."
    $at_quiet $ECHO_N " 19: output.at:79      $ECHO_C"
    (
      $at_traceon

cat >foo.yy <<'_ATEOF'

%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:79: bison --defines=foo.hpp -o foo.c++ foo.yy"
echo output.at:79 >$at_check_line_file
( $at_traceon; bison --defines=foo.hpp -o foo.c++ foo.yy ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:79: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:79: ls foo.c++ foo.hpp"
echo output.at:79 >$at_check_line_file
( $at_traceon; ls foo.c++ foo.hpp ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:79: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  20 ) # 20. output.at:83: Output files:  & -o foo.c++ --graph=foo.gph.
    at_setup_line='output.at:83'
    $at_verbose "20. output.at:83: testing Output files:  & -o foo.c++ --graph=foo.gph...."
    $at_quiet $ECHO_N " 20: output.at:83      $ECHO_C"
    (
      $at_traceon

cat >foo.yy <<'_ATEOF'

%%
foo: {};
_ATEOF


$at_traceoff
$at_verbose "output.at:83: bison -o foo.c++ --graph=foo.gph foo.yy"
echo output.at:83 >$at_check_line_file
( $at_traceon; bison -o foo.c++ --graph=foo.gph foo.yy ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:83: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "output.at:83: ls foo.c++ foo.gph"
echo output.at:83 >$at_check_line_file
( $at_traceon; ls foo.c++ foo.gph ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "output.at:83: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-3 ) # Banner 3. sets.at:59
    cat <<\_ATEOF

Grammar Sets (Firsts etc.).

_ATEOF
    ;;

  21 ) # 21. sets.at:66: Nullable
    at_setup_line='sets.at:66'
    $at_verbose "21. sets.at:66: testing Nullable..."
    $at_quiet $ECHO_N " 21: sets.at:66        $ECHO_C"
    (
      $at_traceon


# At some point, nullable had been smoking grass, and managed to say:
#
# Entering set_nullable
# NULLABLE
#         'e': yes
#         (null): no
# ...

cat >input.y <<'_ATEOF'
%%
e: 'e' | /* Nothing */;
_ATEOF


$at_traceoff
$at_verbose "sets.at:81: bison --trace=sets input.y"
echo sets.at:81 >$at_check_line_file
( $at_traceon; bison --trace=sets input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "sets.at:81: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

cat >extract.sed <<'_ATEOF'
#n
/^NULLABLE$/ {
   :null
   p
   n
   /^[ 	]*$/ !b null
}
/^FIRSTS$/ {
   :firsts
   p
   n
   /^[ 	]*$/ !b firsts
}
/^FDERIVES$/ {
   :fderiv
   p
   n
   /^[ 	]*$/ !b fderiv
}
/^DERIVES$/ {
   :deriv
   p
   n
   /^[ 	]*$/ !b deriv
}
_ATEOF

$at_traceoff
$at_verbose "sets.at:82: sed -f extract.sed stderr"
echo sets.at:82 >$at_check_line_file
( $at_traceon; sed -f extract.sed stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "sets.at:82: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "sets.at:82: mv stdout sets"
echo sets.at:82 >$at_check_line_file
( $at_traceon; mv stdout sets ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "sets.at:82: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "sets.at:107: cat sets"
echo sets.at:107 >$at_check_line_file
( $at_traceon; cat sets ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "DERIVES
	\$accept derives
		  0  e \$end
	e derives
		  1  'e'
		  2  /* empty */
NULLABLE
	\$accept: no
	e: yes
FIRSTS
	\$accept firsts
		\$accept
		e
	e firsts
		e
FDERIVES
	\$accept derives
		  0  e \$end
		  1  'e'
		  2  /* empty */
	e derives
		  1  'e'
		  2  /* empty */
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "sets.at:107: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  22 ) # 22. sets.at:151: Broken Closure
    at_setup_line='sets.at:151'
    $at_verbose "22. sets.at:151: testing Broken Closure..."
    $at_quiet $ECHO_N " 22: sets.at:151       $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%%
a: b;
b: c;
c: d;
d: e;
e: f;
f: g;
g: h;
h: 'h';
_ATEOF


$at_traceoff
$at_verbose "sets.at:165: bison --trace=sets input.y"
echo sets.at:165 >$at_check_line_file
( $at_traceon; bison --trace=sets input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "sets.at:165: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "sets.at:183: sed -n 's/[	 ]*\$//;/^RTC: Firsts Output BEGIN/,/^RTC: Firsts Output END/p' stderr"
echo sets.at:183 >$at_check_line_file
( $at_traceon; sed -n 's/[	 ]*$//;/^RTC: Firsts Output BEGIN/,/^RTC: Firsts Output END/p' stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "RTC: Firsts Output BEGIN

   012345678
  .---------.
 0|111111111|
 1| 11111111|
 2|  1111111|
 3|   111111|
 4|    11111|
 5|     1111|
 6|      111|
 7|       11|
 8|        1|
  \`---------'
RTC: Firsts Output END
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "sets.at:183: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  23 ) # 23. sets.at:193: Firsts
    at_setup_line='sets.at:193'
    $at_verbose "23. sets.at:193: testing Firsts..."
    $at_quiet $ECHO_N " 23: sets.at:193       $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%nonassoc '<' '>'
%left '+' '-'
%right '^' '='
%%
exp:
   exp '<' exp
 | exp '>' exp
 | exp '+' exp
 | exp '-' exp
 | exp '^' exp
 | exp '=' exp
 | "exp"
 ;
_ATEOF


$at_traceoff
$at_verbose "sets.at:211: bison --trace=sets input.y"
echo sets.at:211 >$at_check_line_file
( $at_traceon; bison --trace=sets input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "sets.at:211: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

cat >extract.sed <<'_ATEOF'
#n
/^NULLABLE$/ {
   :null
   p
   n
   /^[ 	]*$/ !b null
}
/^FIRSTS$/ {
   :firsts
   p
   n
   /^[ 	]*$/ !b firsts
}
/^FDERIVES$/ {
   :fderiv
   p
   n
   /^[ 	]*$/ !b fderiv
}
/^DERIVES$/ {
   :deriv
   p
   n
   /^[ 	]*$/ !b deriv
}
_ATEOF

$at_traceoff
$at_verbose "sets.at:212: sed -f extract.sed stderr"
echo sets.at:212 >$at_check_line_file
( $at_traceon; sed -f extract.sed stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "sets.at:212: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "sets.at:212: mv stdout sets"
echo sets.at:212 >$at_check_line_file
( $at_traceon; mv stdout sets ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "sets.at:212: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "sets.at:252: cat sets"
echo sets.at:252 >$at_check_line_file
( $at_traceon; cat sets ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "DERIVES
	\$accept derives
		  0  exp \$end
	exp derives
		  1  exp '<' exp
		  2  exp '>' exp
		  3  exp '+' exp
		  4  exp '-' exp
		  5  exp '^' exp
		  6  exp '=' exp
		  7  \"exp\"
NULLABLE
	\$accept: no
	exp: no
FIRSTS
	\$accept firsts
		\$accept
		exp
	exp firsts
		exp
FDERIVES
	\$accept derives
		  0  exp \$end
		  1  exp '<' exp
		  2  exp '>' exp
		  3  exp '+' exp
		  4  exp '-' exp
		  5  exp '^' exp
		  6  exp '=' exp
		  7  \"exp\"
	exp derives
		  1  exp '<' exp
		  2  exp '>' exp
		  3  exp '+' exp
		  4  exp '-' exp
		  5  exp '^' exp
		  6  exp '=' exp
		  7  \"exp\"
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "sets.at:252: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-4 ) # Banner 4. reduce.at:19
    cat <<\_ATEOF

Grammar Reduction.

_ATEOF
    ;;

  24 ) # 24. reduce.at:26: Useless Terminals
    at_setup_line='reduce.at:26'
    $at_verbose "24. reduce.at:26: testing Useless Terminals..."
    $at_quiet $ECHO_N " 24: reduce.at:26      $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%verbose
%output="input.c"

%token useless1
%token useless2
%token useless3
%token useless4
%token useless5
%token useless6
%token useless7
%token useless8
%token useless9

%token useful
%%
exp: useful;
_ATEOF


$at_traceoff
$at_verbose "reduce.at:47: bison input.y"
echo reduce.at:47 >$at_check_line_file
( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "reduce.at:47: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "reduce.at:60: sed -n '/^Grammar/q;/^\$/!p' input.output"
echo reduce.at:60 >$at_check_line_file
( $at_traceon; sed -n '/^Grammar/q;/^$/!p' input.output ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "Terminals which are not used
   useless1
   useless2
   useless3
   useless4
   useless5
   useless6
   useless7
   useless8
   useless9
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "reduce.at:60: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  25 ) # 25. reduce.at:70: Useless Nonterminals
    at_setup_line='reduce.at:70'
    $at_verbose "25. reduce.at:70: testing Useless Nonterminals..."
    $at_quiet $ECHO_N " 25: reduce.at:70      $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%verbose
%output="input.c"

%nterm useless1
%nterm useless2
%nterm useless3
%nterm useless4
%nterm useless5
%nterm useless6
%nterm useless7
%nterm useless8
%nterm useless9

%token useful
%%
exp: useful;
_ATEOF


$at_traceoff
$at_verbose "reduce.at:102: bison input.y"
echo reduce.at:102 >$at_check_line_file
( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y: warning: 9 useless nonterminals
input.y:4.8-15: warning: useless nonterminal: useless1
input.y:5.8-15: warning: useless nonterminal: useless2
input.y:6.8-15: warning: useless nonterminal: useless3
input.y:7.8-15: warning: useless nonterminal: useless4
input.y:8.8-15: warning: useless nonterminal: useless5
input.y:9.8-15: warning: useless nonterminal: useless6
input.y:10.8-15: warning: useless nonterminal: useless7
input.y:11.8-15: warning: useless nonterminal: useless8
input.y:12.8-15: warning: useless nonterminal: useless9
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "reduce.at:102: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "reduce.at:115: sed -n '/^Grammar/q;/^\$/!p' input.output"
echo reduce.at:115 >$at_check_line_file
( $at_traceon; sed -n '/^Grammar/q;/^$/!p' input.output ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "Useless nonterminals
   useless1
   useless2
   useless3
   useless4
   useless5
   useless6
   useless7
   useless8
   useless9
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "reduce.at:115: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  26 ) # 26. reduce.at:125: Useless Rules
    at_setup_line='reduce.at:125'
    $at_verbose "26. reduce.at:125: testing Useless Rules..."
    $at_quiet $ECHO_N " 26: reduce.at:125     $ECHO_C"
    (
      $at_traceon




cat >input.y <<'_ATEOF'
%verbose
%output="input.c"
%token useful
%%
exp: useful;
useless1: '1';
useless2: '2';
useless3: '3';
useless4: '4';
useless5: '5';
useless6: '6';
useless7: '7';
useless8: '8';
useless9: '9';
_ATEOF


$at_traceoff
$at_verbose "reduce.at:166: bison input.y"
echo reduce.at:166 >$at_check_line_file
( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y: warning: 9 useless nonterminals and 9 useless rules
input.y:6.1-8: warning: useless nonterminal: useless1
input.y:7.1-8: warning: useless nonterminal: useless2
input.y:8.1-8: warning: useless nonterminal: useless3
input.y:9.1-8: warning: useless nonterminal: useless4
input.y:10.1-8: warning: useless nonterminal: useless5
input.y:11.1-8: warning: useless nonterminal: useless6
input.y:12.1-8: warning: useless nonterminal: useless7
input.y:13.1-8: warning: useless nonterminal: useless8
input.y:14.1-8: warning: useless nonterminal: useless9
input.y:6.11-13: warning: useless rule: useless1: '1'
input.y:7.11-13: warning: useless rule: useless2: '2'
input.y:8.11-13: warning: useless rule: useless3: '3'
input.y:9.11-13: warning: useless rule: useless4: '4'
input.y:10.11-13: warning: useless rule: useless5: '5'
input.y:11.11-13: warning: useless rule: useless6: '6'
input.y:12.11-13: warning: useless rule: useless7: '7'
input.y:13.11-13: warning: useless rule: useless8: '8'
input.y:14.11-13: warning: useless rule: useless9: '9'
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "reduce.at:166: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "reduce.at:199: sed -n '/^Grammar/q;/^\$/!p' input.output"
echo reduce.at:199 >$at_check_line_file
( $at_traceon; sed -n '/^Grammar/q;/^$/!p' input.output ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "Useless nonterminals
   useless1
   useless2
   useless3
   useless4
   useless5
   useless6
   useless7
   useless8
   useless9
Terminals which are not used
   '1'
   '2'
   '3'
   '4'
   '5'
   '6'
   '7'
   '8'
   '9'
Useless rules
    2 useless1: '1'
    3 useless2: '2'
    4 useless3: '3'
    5 useless4: '4'
    6 useless5: '5'
    7 useless6: '6'
    8 useless7: '7'
    9 useless8: '8'
   10 useless9: '9'
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "reduce.at:199: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  27 ) # 27. reduce.at:212: Reduced Automaton
    at_setup_line='reduce.at:212'
    $at_verbose "27. reduce.at:212: testing Reduced Automaton..."
    $at_quiet $ECHO_N " 27: reduce.at:212     $ECHO_C"
    (
      $at_traceon




# The non reduced grammar.
# ------------------------
cat >not-reduced.y <<'_ATEOF'
/* A useless token. */
%token useless_token
/* A useful one. */
%token useful
%verbose
%output="not-reduced.c"

%%

exp: useful            { /* A useful action. */ }
   | non_productive    { /* A non productive action. */ }
   ;

not_reachable: useful  { /* A not reachable action. */ }
             ;

non_productive: non_productive useless_token
                       { /* Another non productive action. */ }
              ;
%%
_ATEOF


$at_traceoff
$at_verbose "reduce.at:248: bison not-reduced.y"
echo reduce.at:248 >$at_check_line_file
( $at_traceon; bison not-reduced.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "not-reduced.y: warning: 2 useless nonterminals and 3 useless rules
not-reduced.y:14.1-13: warning: useless nonterminal: not_reachable
not-reduced.y:11.6-19: warning: useless nonterminal: non_productive
not-reduced.y:11.6-57: warning: useless rule: exp: non_productive
not-reduced.y:14.16-56: warning: useless rule: not_reachable: useful
not-reduced.y:17.17-18.63: warning: useless rule: non_productive: non_productive useless_token
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "reduce.at:248: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "reduce.at:260: sed -n '/^Grammar/q;/^\$/!p' not-reduced.output"
echo reduce.at:260 >$at_check_line_file
( $at_traceon; sed -n '/^Grammar/q;/^$/!p' not-reduced.output ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "Useless nonterminals
   not_reachable
   non_productive
Terminals which are not used
   useless_token
Useless rules
    2 exp: non_productive
    3 not_reachable: useful
    4 non_productive: non_productive useless_token
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "reduce.at:260: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# The reduced grammar.
# --------------------
cat >reduced.y <<'_ATEOF'
/* A useless token. */
%token useless_token
/* A useful one. */
%token useful
%verbose
%output="reduced.c"

%%

exp: useful            { /* A useful action. */ }
//   | non_productive    { /* A non productive action. */ } */
   ;

//not_reachable: useful  { /* A not reachable action. */ }
//             ;

//non_productive: non_productive useless_token
//                       { /* Another non productive action. */ }
//              ;
%%
_ATEOF


$at_traceoff
$at_verbose "reduce.at:287: bison reduced.y"
echo reduce.at:287 >$at_check_line_file
( $at_traceon; bison reduced.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "reduce.at:287: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Comparing the parsers.
cp reduced.c expout
$at_traceoff
$at_verbose "reduce.at:291: sed 's/not-reduced/reduced/g' not-reduced.c"
echo reduce.at:291 >$at_check_line_file
( $at_traceon; sed 's/not-reduced/reduced/g' not-reduced.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "reduce.at:291: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  28 ) # 28. reduce.at:301: Underivable Rules
    at_setup_line='reduce.at:301'
    $at_verbose "28. reduce.at:301: testing Underivable Rules..."
    $at_quiet $ECHO_N " 28: reduce.at:301     $ECHO_C"
    (
      $at_traceon




cat >input.y <<'_ATEOF'
%verbose
%output="input.c"
%token useful
%%
exp: useful | underivable;
underivable: indirection;
indirection: underivable;
_ATEOF


$at_traceoff
$at_verbose "reduce.at:322: bison input.y"
echo reduce.at:322 >$at_check_line_file
( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y: warning: 2 useless nonterminals and 3 useless rules
input.y:5.15-25: warning: useless nonterminal: underivable
input.y:6.14-24: warning: useless nonterminal: indirection
input.y:5.15-25: warning: useless rule: exp: underivable
input.y:6.14-24: warning: useless rule: underivable: indirection
input.y:7.14-24: warning: useless rule: indirection: underivable
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "reduce.at:322: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "reduce.at:332: sed -n '/^Grammar/q;/^\$/!p' input.output"
echo reduce.at:332 >$at_check_line_file
( $at_traceon; sed -n '/^Grammar/q;/^$/!p' input.output ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "Useless nonterminals
   underivable
   indirection
Useless rules
    2 exp: underivable
    3 underivable: indirection
    4 indirection: underivable
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "reduce.at:332: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  29 ) # 29. reduce.at:342: Empty Language
    at_setup_line='reduce.at:342'
    $at_verbose "29. reduce.at:342: testing Empty Language..."
    $at_quiet $ECHO_N " 29: reduce.at:342     $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%output="input.c"
%%
exp: exp;
_ATEOF


$at_traceoff
$at_verbose "reduce.at:353: bison input.y"
echo reduce.at:353 >$at_check_line_file
( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y: warning: 2 useless nonterminals and 2 useless rules
input.y:3.1-3: fatal error: start symbol exp does not derive any sentence
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "reduce.at:353: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-5 ) # Banner 5. synclines.at:19
    cat <<\_ATEOF

User Actions.

_ATEOF
    ;;

  30 ) # 30. synclines.at:93: Prologue synch line
    at_setup_line='synclines.at:93'
    $at_verbose "30. synclines.at:93: testing Prologue synch line..."
    $at_quiet $ECHO_N " 30: synclines.at:93   $ECHO_C"
    (
      $at_traceon


# It seems impossible to find a generic scheme to check the location
# of an error.  Even requiring GCC is not sufficient, since for instance
# the version modified by Apple:
#
# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
# | 19991024 (release) configure:2124: $? = 0
#
# instead of:
#
# | input.y:2: #error "2"
#
# it reports:
#
# | input.y:2: "2"
# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode

cat >syncline.c <<'_ATEOF'
#error "1"
_ATEOF


$at_traceoff
$at_verbose "synclines.at:93: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c"
echo synclines.at:93 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   *);;
esac

$at_failed && exit 1
$at_traceon

# In case GCC displays column information, strip it down.
#
#   input.y:4:2: #error "4"    or input.y:4.2: #error "4"
# =>
#   input.y:4: #error "4"
#
$at_traceoff
$at_verbose "synclines.at:93: sed 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' stderr"
echo synclines.at:93 >$at_check_line_file
( $at_traceon; sed 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:93: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "synclines.at:93: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77"
echo synclines.at:93 >$at_check_line_file
( $at_traceon; test "`cat stdout`" = 'syncline.c:1: #error "1"' || exit 77 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:93: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input.y <<'_ATEOF'
%{
#error "2"
void yyerror (const char *s);
int yylex (void);
%}
%%
exp: '0';
_ATEOF

$at_traceoff
$at_verbose "synclines.at:93: bison -o input.c input.y"
echo synclines.at:93 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:93: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "synclines.at:93: \$CC \$CFLAGS \$CPPFLAGS -c input.c"
echo synclines.at:93 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   *);;
esac

$at_failed && exit 1
$at_traceon

# In case GCC displays column information, strip it down.
#
#   input.y:4:2: #error "4"    or input.y:4.2: #error "4"
# =>
#   input.y:4: #error "4"
#
$at_traceoff
$at_verbose "synclines.at:93: sed 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' stderr"
echo synclines.at:93 >$at_check_line_file
( $at_traceon; sed 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:93: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "synclines.at:93: cat stdout"
echo synclines.at:93 >$at_check_line_file
( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "input.y:2: #error \"2\"
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:93: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  31 ) # 31. synclines.at:112: %union synch line
    at_setup_line='synclines.at:112'
    $at_verbose "31. synclines.at:112: testing %union synch line..."
    $at_quiet $ECHO_N " 31: synclines.at:112  $ECHO_C"
    (
      $at_traceon


# It seems impossible to find a generic scheme to check the location
# of an error.  Even requiring GCC is not sufficient, since for instance
# the version modified by Apple:
#
# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
# | 19991024 (release) configure:2124: $? = 0
#
# instead of:
#
# | input.y:2: #error "2"
#
# it reports:
#
# | input.y:2: "2"
# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode

cat >syncline.c <<'_ATEOF'
#error "1"
_ATEOF


$at_traceoff
$at_verbose "synclines.at:112: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c"
echo synclines.at:112 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   *);;
esac

$at_failed && exit 1
$at_traceon

# In case GCC displays column information, strip it down.
#
#   input.y:4:2: #error "4"    or input.y:4.2: #error "4"
# =>
#   input.y:4: #error "4"
#
$at_traceoff
$at_verbose "synclines.at:112: sed 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' stderr"
echo synclines.at:112 >$at_check_line_file
( $at_traceon; sed 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:112: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "synclines.at:112: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77"
echo synclines.at:112 >$at_check_line_file
( $at_traceon; test "`cat stdout`" = 'syncline.c:1: #error "1"' || exit 77 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:112: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input.y <<'_ATEOF'
%union {
#error "2"
}
%{
void yyerror (const char *s);
int yylex (void);
%}
%%
exp: '0';
_ATEOF

$at_traceoff
$at_verbose "synclines.at:112: bison -o input.c input.y"
echo synclines.at:112 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:112: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "synclines.at:112: \$CC \$CFLAGS \$CPPFLAGS -c input.c"
echo synclines.at:112 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   *);;
esac

$at_failed && exit 1
$at_traceon

# In case GCC displays column information, strip it down.
#
#   input.y:4:2: #error "4"    or input.y:4.2: #error "4"
# =>
#   input.y:4: #error "4"
#
$at_traceoff
$at_verbose "synclines.at:112: sed 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' stderr"
echo synclines.at:112 >$at_check_line_file
( $at_traceon; sed 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:112: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "synclines.at:112: cat stdout"
echo synclines.at:112 >$at_check_line_file
( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "input.y:2: #error \"2\"
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:112: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  32 ) # 32. synclines.at:135: Postprologue synch line
    at_setup_line='synclines.at:135'
    $at_verbose "32. synclines.at:135: testing Postprologue synch line..."
    $at_quiet $ECHO_N " 32: synclines.at:135  $ECHO_C"
    (
      $at_traceon


# It seems impossible to find a generic scheme to check the location
# of an error.  Even requiring GCC is not sufficient, since for instance
# the version modified by Apple:
#
# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
# | 19991024 (release) configure:2124: $? = 0
#
# instead of:
#
# | input.y:2: #error "2"
#
# it reports:
#
# | input.y:2: "2"
# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode

cat >syncline.c <<'_ATEOF'
#error "1"
_ATEOF


$at_traceoff
$at_verbose "synclines.at:135: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c"
echo synclines.at:135 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   *);;
esac

$at_failed && exit 1
$at_traceon

# In case GCC displays column information, strip it down.
#
#   input.y:4:2: #error "4"    or input.y:4.2: #error "4"
# =>
#   input.y:4: #error "4"
#
$at_traceoff
$at_verbose "synclines.at:135: sed 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' stderr"
echo synclines.at:135 >$at_check_line_file
( $at_traceon; sed 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:135: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "synclines.at:135: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77"
echo synclines.at:135 >$at_check_line_file
( $at_traceon; test "`cat stdout`" = 'syncline.c:1: #error "1"' || exit 77 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:135: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input.y <<'_ATEOF'
%{
void yyerror (const char *s);
int yylex (void);
%}
%union
{
  int ival;
}
%{
#error "10"
%}
%%
exp: '0';
_ATEOF

$at_traceoff
$at_verbose "synclines.at:135: bison -o input.c input.y"
echo synclines.at:135 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:135: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "synclines.at:135: \$CC \$CFLAGS \$CPPFLAGS -c input.c"
echo synclines.at:135 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   *);;
esac

$at_failed && exit 1
$at_traceon

# In case GCC displays column information, strip it down.
#
#   input.y:4:2: #error "4"    or input.y:4.2: #error "4"
# =>
#   input.y:4: #error "4"
#
$at_traceoff
$at_verbose "synclines.at:135: sed 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' stderr"
echo synclines.at:135 >$at_check_line_file
( $at_traceon; sed 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:135: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "synclines.at:135: cat stdout"
echo synclines.at:135 >$at_check_line_file
( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "input.y:10: #error \"10\"
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:135: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  33 ) # 33. synclines.at:154: Action synch line
    at_setup_line='synclines.at:154'
    $at_verbose "33. synclines.at:154: testing Action synch line..."
    $at_quiet $ECHO_N " 33: synclines.at:154  $ECHO_C"
    (
      $at_traceon


# It seems impossible to find a generic scheme to check the location
# of an error.  Even requiring GCC is not sufficient, since for instance
# the version modified by Apple:
#
# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
# | 19991024 (release) configure:2124: $? = 0
#
# instead of:
#
# | input.y:2: #error "2"
#
# it reports:
#
# | input.y:2: "2"
# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode

cat >syncline.c <<'_ATEOF'
#error "1"
_ATEOF


$at_traceoff
$at_verbose "synclines.at:154: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c"
echo synclines.at:154 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   *);;
esac

$at_failed && exit 1
$at_traceon

# In case GCC displays column information, strip it down.
#
#   input.y:4:2: #error "4"    or input.y:4.2: #error "4"
# =>
#   input.y:4: #error "4"
#
$at_traceoff
$at_verbose "synclines.at:154: sed 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' stderr"
echo synclines.at:154 >$at_check_line_file
( $at_traceon; sed 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:154: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "synclines.at:154: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77"
echo synclines.at:154 >$at_check_line_file
( $at_traceon; test "`cat stdout`" = 'syncline.c:1: #error "1"' || exit 77 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:154: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input.y <<'_ATEOF'
%{
void yyerror (const char *s);
int yylex (void);
%}
%%
exp:
{
#error "8"
};
_ATEOF

$at_traceoff
$at_verbose "synclines.at:154: bison -o input.c input.y"
echo synclines.at:154 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:154: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "synclines.at:154: \$CC \$CFLAGS \$CPPFLAGS -c input.c"
echo synclines.at:154 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   *);;
esac

$at_failed && exit 1
$at_traceon

# In case GCC displays column information, strip it down.
#
#   input.y:4:2: #error "4"    or input.y:4.2: #error "4"
# =>
#   input.y:4: #error "4"
#
$at_traceoff
$at_verbose "synclines.at:154: sed 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' stderr"
echo synclines.at:154 >$at_check_line_file
( $at_traceon; sed 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:154: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "synclines.at:154: cat stdout"
echo synclines.at:154 >$at_check_line_file
( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "input.y:8: #error \"8\"
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:154: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  34 ) # 34. synclines.at:172: Epilogue synch line
    at_setup_line='synclines.at:172'
    $at_verbose "34. synclines.at:172: testing Epilogue synch line..."
    $at_quiet $ECHO_N " 34: synclines.at:172  $ECHO_C"
    (
      $at_traceon


# It seems impossible to find a generic scheme to check the location
# of an error.  Even requiring GCC is not sufficient, since for instance
# the version modified by Apple:
#
# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
# | 19991024 (release) configure:2124: $? = 0
#
# instead of:
#
# | input.y:2: #error "2"
#
# it reports:
#
# | input.y:2: "2"
# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode

cat >syncline.c <<'_ATEOF'
#error "1"
_ATEOF


$at_traceoff
$at_verbose "synclines.at:172: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c"
echo synclines.at:172 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   *);;
esac

$at_failed && exit 1
$at_traceon

# In case GCC displays column information, strip it down.
#
#   input.y:4:2: #error "4"    or input.y:4.2: #error "4"
# =>
#   input.y:4: #error "4"
#
$at_traceoff
$at_verbose "synclines.at:172: sed 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' stderr"
echo synclines.at:172 >$at_check_line_file
( $at_traceon; sed 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:172: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "synclines.at:172: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77"
echo synclines.at:172 >$at_check_line_file
( $at_traceon; test "`cat stdout`" = 'syncline.c:1: #error "1"' || exit 77 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:172: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input.y <<'_ATEOF'
%{
void yyerror (const char *s);
int yylex (void);
%}
%%
exp: '0';
%%
#error "8"
_ATEOF

$at_traceoff
$at_verbose "synclines.at:172: bison -o input.c input.y"
echo synclines.at:172 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:172: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "synclines.at:172: \$CC \$CFLAGS \$CPPFLAGS -c input.c"
echo synclines.at:172 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   *);;
esac

$at_failed && exit 1
$at_traceon

# In case GCC displays column information, strip it down.
#
#   input.y:4:2: #error "4"    or input.y:4.2: #error "4"
# =>
#   input.y:4: #error "4"
#
$at_traceoff
$at_verbose "synclines.at:172: sed 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' stderr"
echo synclines.at:172 >$at_check_line_file
( $at_traceon; sed 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:172: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "synclines.at:172: cat stdout"
echo synclines.at:172 >$at_check_line_file
( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "input.y:8: #error \"8\"
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "synclines.at:172: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-6 ) # Banner 6. headers.at:19
    cat <<\_ATEOF

Parser Headers.

_ATEOF
    ;;

  35 ) # 35. headers.at:27: %union and --defines
    at_setup_line='headers.at:27'
    $at_verbose "35. headers.at:27: testing %union and --defines..."
    $at_quiet $ECHO_N " 35: headers.at:27     $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%union
{
  int   integer;
  char *string ;
}
%%
exp: {};
_ATEOF


$at_traceoff
$at_verbose "headers.at:39: bison --defines input.y"
echo headers.at:39 >$at_check_line_file
( $at_traceon; bison --defines input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "headers.at:39: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  36 ) # 36. headers.at:76: Invalid CPP guards: input/input
    at_setup_line='headers.at:76'
    $at_verbose "36. headers.at:76: testing Invalid CPP guards: input/input..."
    $at_quiet $ECHO_N " 36: headers.at:76     $ECHO_C"
    (
      $at_traceon


# Possibly create inner directories.
dirname=`(dirname input/input) 2>/dev/null ||
$as_expr Xinput/input : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
         Xinput/input : 'X\(//\)[^/]' \| \
         Xinput/input : 'X\(//\)$' \| \
         Xinput/input : 'X\(/\)' \| \
         .     : '\(.\)' 2>/dev/null ||
echo Xinput/input |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
  	  /^X\(\/\/\)$/{ s//\1/; q; }
  	  /^X\(\/\).*/{ s//\1/; q; }
  	  s/.*/./; q'`
{ if $as_mkdir_p; then
    mkdir -p $dirname
  else
    as_dir=$dirname
    as_dirs=
    while test ! -d "$as_dir"; do
      as_dirs="$as_dir $as_dirs"
      as_dir=`(dirname "$as_dir") 2>/dev/null ||
$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
         X"$as_dir" : 'X\(//\)[^/]' \| \
         X"$as_dir" : 'X\(//\)$' \| \
         X"$as_dir" : 'X\(/\)' \| \
         .     : '\(.\)' 2>/dev/null ||
echo X"$as_dir" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
  	  /^X\(\/\/\)$/{ s//\1/; q; }
  	  /^X\(\/\).*/{ s//\1/; q; }
  	  s/.*/./; q'`
    done
    test ! -n "$as_dirs" || mkdir $as_dirs
  fi || { { echo "$as_me:$LINENO: error: cannot create directory $dirname" >&6
echo "$as_me: error: cannot create directory $dirname" >&2;}
   { (exit 1); exit 1; }; }; }


cat >input/input.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

%{
#include "input/input.h"
%}
%%
dummy:;
%%
#include "input/input.h"
_ATEOF



$at_traceoff
$at_verbose "headers.at:76: bison --defines=input/input.h --output=y.tab.c input/input.y"
echo headers.at:76 >$at_check_line_file
( $at_traceon; bison --defines=input/input.h --output=y.tab.c input/input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "headers.at:76: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# CPP should be happy with it.
$at_traceoff
$at_verbose "headers.at:76: \$CC -E -I. y.tab.c"
echo headers.at:76 >$at_check_line_file
( $at_traceon; $CC -E -I. y.tab.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "headers.at:76: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  37 ) # 37. headers.at:77: Invalid CPP guards: 9foo
    at_setup_line='headers.at:77'
    $at_verbose "37. headers.at:77: testing Invalid CPP guards: 9foo..."
    $at_quiet $ECHO_N " 37: headers.at:77     $ECHO_C"
    (
      $at_traceon


# Possibly create inner directories.
dirname=`(dirname 9foo) 2>/dev/null ||
$as_expr X9foo : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
         X9foo : 'X\(//\)[^/]' \| \
         X9foo : 'X\(//\)$' \| \
         X9foo : 'X\(/\)' \| \
         .     : '\(.\)' 2>/dev/null ||
echo X9foo |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
  	  /^X\(\/\/\)$/{ s//\1/; q; }
  	  /^X\(\/\).*/{ s//\1/; q; }
  	  s/.*/./; q'`
{ if $as_mkdir_p; then
    mkdir -p $dirname
  else
    as_dir=$dirname
    as_dirs=
    while test ! -d "$as_dir"; do
      as_dirs="$as_dir $as_dirs"
      as_dir=`(dirname "$as_dir") 2>/dev/null ||
$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
         X"$as_dir" : 'X\(//\)[^/]' \| \
         X"$as_dir" : 'X\(//\)$' \| \
         X"$as_dir" : 'X\(/\)' \| \
         .     : '\(.\)' 2>/dev/null ||
echo X"$as_dir" |
    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
  	  /^X\(\/\/\)$/{ s//\1/; q; }
  	  /^X\(\/\).*/{ s//\1/; q; }
  	  s/.*/./; q'`
    done
    test ! -n "$as_dirs" || mkdir $as_dirs
  fi || { { echo "$as_me:$LINENO: error: cannot create directory $dirname" >&6
echo "$as_me: error: cannot create directory $dirname" >&2;}
   { (exit 1); exit 1; }; }; }


cat >9foo.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

%{
#include "9foo.h"
%}
%%
dummy:;
%%
#include "9foo.h"
_ATEOF



$at_traceoff
$at_verbose "headers.at:77: bison --defines=9foo.h --output=y.tab.c 9foo.y"
echo headers.at:77 >$at_check_line_file
( $at_traceon; bison --defines=9foo.h --output=y.tab.c 9foo.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "headers.at:77: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# CPP should be happy with it.
$at_traceoff
$at_verbose "headers.at:77: \$CC -E -I. y.tab.c"
echo headers.at:77 >$at_check_line_file
( $at_traceon; $CC -E -I. y.tab.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "headers.at:77: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  38 ) # 38. headers.at:86: export YYLTYPE
    at_setup_line='headers.at:86'
    $at_verbose "38. headers.at:86: testing export YYLTYPE..."
    $at_quiet $ECHO_N " 38: headers.at:86     $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

%locations

%name-prefix="my_"
%{
#include <stdio.h>
#include <stdlib.h>

static int
my_lex (void)
{
  return EOF;
}

static void
my_error (const char *msg)
{
  fprintf (stderr, "%s\n", msg);
}

%}
%%
exp:;
_ATEOF



$at_traceoff
$at_verbose "headers.at:113: bison --defines -o input.c input.y"
echo headers.at:113 >$at_check_line_file
( $at_traceon; bison --defines -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "headers.at:113: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# YYLTYPE should be defined, and MY_LLOC declared.
cat >caller.c <<'_ATEOF'
#include "input.h"
YYLTYPE *my_llocp = &my_lloc;

int my_parse (void);

int
main (void)
{
  return my_parse ();
}
_ATEOF


# Link and execute, just to make sure everything is fine (and in
# particular, that MY_LLOC is indeed defined somewhere).
$at_traceoff
$at_verbose "headers.at:131: \$CC \$CFLAGS \$CPPFLAGS -c caller.c -o caller.o"
echo headers.at:131 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c caller.c -o caller.o ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "headers.at:131: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "headers.at:132: \$CC \$CFLAGS \$CPPFLAGS -c input.c -o input.o"
echo headers.at:132 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c -o input.o ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "headers.at:132: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "headers.at:133: \$CC \$CFLAGS \$CPPFLAGS caller.o input.o -o caller"
echo headers.at:133 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS caller.o input.o -o caller ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "headers.at:133: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "headers.at:134: \$PREPARSER ./caller"
echo headers.at:134 >$at_check_line_file
( $at_traceon; $PREPARSER ./caller ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "headers.at:134: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-7 ) # Banner 7. actions.at:19
    cat <<\_ATEOF

User Actions.

_ATEOF
    ;;

  39 ) # 39. actions.at:25: Mid-rule actions
    at_setup_line='actions.at:25'
    $at_verbose "39. actions.at:25: testing Mid-rule actions..."
    $at_quiet $ECHO_N " 39: actions.at:25     $ECHO_C"
    (
      $at_traceon


# Bison once forgot the mid-rule actions.  It was because the action
# was attached to the host rule (the one with the mid-rule action),
# instead of being attached to the empty rule dedicated to this
# action.

cat >input.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

%{
# include <stdio.h>
# include <stdlib.h>
  static void yyerror (const char *msg);
  static int yylex (void);
# define YYDEBUG         1
# define YYERROR_VERBOSE 1
%}
%%
exp:     { putchar ('0'); }
     '1' { putchar ('1'); }
     '2' { putchar ('2'); }
     '3' { putchar ('3'); }
     '4' { putchar ('4'); }
     '5' { putchar ('5'); }
     '6' { putchar ('6'); }
     '7' { putchar ('7'); }
     '8' { putchar ('8'); }
     '9' { putchar ('9'); }
         { putchar ('\n'); }
   ;
%%
static int
yylex (void)
{
  static const char *input = "123456789";
  return *input++;
}

static void
yyerror (const char *msg)
{
  fprintf (stderr, "%s\n", msg);
}

int
main (void)
{
  return yyparse ();
}
_ATEOF



$at_traceoff
$at_verbose "actions.at:75: bison -d -v -o input.c input.y"
echo actions.at:75 >$at_check_line_file
( $at_traceon; bison -d -v -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "actions.at:75: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "actions.at:76: \$CC \$CFLAGS \$CPPFLAGS input.c -o input"
echo actions.at:76 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS input.c -o input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "actions.at:76: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "actions.at:79: \$PREPARSER ./input"
echo actions.at:79 >$at_check_line_file
( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "0123456789
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "actions.at:79: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  40 ) # 40. actions.at:89: Actions after errors
    at_setup_line='actions.at:89'
    $at_verbose "40. actions.at:89: testing Actions after errors..."
    $at_quiet $ECHO_N " 40: actions.at:89     $ECHO_C"
    (
      $at_traceon




cat >input.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

%{
#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[] =
    {
      /* Exercise 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 ();
}
_ATEOF



$at_traceoff
$at_verbose "actions.at:198: bison -o input.c input.y"
echo actions.at:198 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "actions.at:198: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "actions.at:199: \$CC \$CFLAGS \$CPPFLAGS input.c -o input"
echo actions.at:199 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS input.c -o input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "actions.at:199: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "actions.at:226: \$PREPARSER ./input"
echo actions.at:226 >$at_check_line_file
( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "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_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "actions.at:226: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  41 ) # 41. actions.at:236: Exotic Dollars
    at_setup_line='actions.at:236'
    $at_verbose "41. actions.at:236: testing Exotic Dollars..."
    $at_quiet $ECHO_N " 41: actions.at:236    $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

%{
# include <stdio.h>
# include <stdlib.h>
  static void yyerror (const char *msg);
  static int yylex (void);
# define YYDEBUG         1
# define YYERROR_VERBOSE 1
%}

%union
{
  int val;
};

%type <val> a_1 a_2 a_5
            sum_of_the_five_previous_values

%%
exp: a_1 a_2 { $<val>$ = 3; } { $<val>$ = $<val>3 + 1; } a_5
     sum_of_the_five_previous_values
    {
       printf ("%d\n", $6);
    }
;
a_1: { $$ = 1; };
a_2: { $$ = 2; };
a_5: { $$ = 5; };

sum_of_the_five_previous_values:
    {
       $$ = $<val>0 + $<val>-1 + $<val>-2 + $<val>-3 + $<val>-4;
    }
;

%%
static int
yylex (void)
{
  return EOF;
}

static void
yyerror (const char *msg)
{
  fprintf (stderr, "%s\n", msg);
}

int
main (void)
{
  return yyparse ();
}
_ATEOF



$at_traceoff
$at_verbose "actions.at:293: bison -d -v -o input.c input.y"
echo actions.at:293 >$at_check_line_file
( $at_traceon; bison -d -v -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "actions.at:293: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "actions.at:294: \$CC \$CFLAGS \$CPPFLAGS input.c -o input"
echo actions.at:294 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS input.c -o input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "actions.at:294: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "actions.at:297: \$PREPARSER ./input"
echo actions.at:297 >$at_check_line_file
( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "15
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "actions.at:297: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  42 ) # 42. actions.at:514: Printers and Destructors:
    at_setup_line='actions.at:514'
    $at_verbose "42. actions.at:514: testing Printers and Destructors: ..."
    $at_quiet $ECHO_N " 42: actions.at:514    $ECHO_C"
    (
      $at_traceon


# Make sure complex $n work.

cat >input.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}


%{
#include <stdio.h>
#include <stdlib.h>
#define RANGE(Location) (Location).first_line, (Location).last_line
static int yylex (void);
static void yyerror (const char *msg);
%}
%error-verbose
%debug
%verbose
%locations
%union
{
  int ival;
}
%type <ival> 'x' ';' thing line input

%printer { fprintf (yyoutput, "%d@%d-%d", $$, RANGE (@$)); }
   input line thing 'x'

%destructor
  { printf ("Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
  input

%destructor
  { printf ("Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
  line

%destructor
  { printf ("Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
  thing

%destructor
  { printf ("Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
  'x'

%%
input:
  /* Nothing. */
    {
      $$ = 0;
      printf ("input (%d@%d-%d): /* Nothing */\n", $$, RANGE (@$));
    }
| line input /* Right recursive to load the stack so that popping at
		EOF can	be exercised.  */
    {
      $$ = 2;
      printf ("input (%d@%d-%d): line (%d@%d-%d) input (%d@%d-%d)\n",
	      $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2));
    }
;

line:
  thing thing thing ';'
    {
      $$ = $1;
      printf ("line (%d@%d-%d): thing (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ';' (%d@%d-%d)\n",
              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
              $3, RANGE (@3), $4, RANGE (@4));
    }
| thing thing ';'
    {
      $$ = $1;
      printf ("line (%d@%d-%d): thing (%d@%d-%d) thing (%d@%d-%d) ';' (%d@%d-%d)\n",
              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2), $3, RANGE (@3));
    }
| thing ';'
    {
      $$ = $1;
      printf ("line (%d@%d-%d): thing (%d@%d-%d) ';' (%d@%d-%d)\n",
              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2));
    }
| error ';'
    {
      $$ = -1;
      printf ("line (%d@%d-%d): error (@%d-%d) ';' (%d@%d-%d)\n",
              $$, RANGE (@$), RANGE (@1), $2, RANGE (@2));
    }
;

thing:
  'x'
    {
      $$ = $1;
      printf ("thing (%d@%d-%d): 'x' (%d@%d-%d)\n",
              $$, RANGE (@$), $1, RANGE (@1));
    }
;
%%
static int
yylex (void)
{
  static const unsigned int input[] =
    {
      /* Exercise 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'
    };
  static unsigned int counter = 0;

  if (counter < (sizeof(input) / sizeof (input[0])))
    {
       yylval.ival = counter;
       /* As in BASIC, line numbers go from 10 to 10.  */
       yylloc.first_line = yylloc.first_column = 10 * counter;
       yylloc.last_line = yylloc.last_column = yylloc.first_line + 9;
       printf ("sending: '%c' (%d@%d-%d)\n",
               input[counter], yylval.ival, RANGE (yylloc));
       return (int) input[counter++];
    }
  else
    {
      printf ("sending: EOF\n");
      return EOF;
    }
}

static void
yyerror (const char *msg)
{
  printf ("%d-%d: %s\n", RANGE (yylloc), msg);
}

int
main (void)
{
  yydebug = !!getenv ("YYDEBUG");
  if (yyparse ())
    {
      printf ("Parsing FAILED.\n");
      exit (1);
    }
  printf ("Successful parse.\n");
  return 0;
}
_ATEOF



$at_traceoff
$at_verbose "actions.at:514: bison -o input.c input.y"
echo actions.at:514 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "actions.at:514: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "actions.at:514: \$CC \$CFLAGS \$CPPFLAGS input.c -o input"
echo actions.at:514 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS input.c -o input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "actions.at:514: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "actions.at:514: \$PREPARSER ./input"
echo actions.at:514 >$at_check_line_file
( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "sending: 'x' (0@0-9)
thing (0@0-9): 'x' (0@0-9)
sending: 'x' (1@10-19)
thing (1@10-19): 'x' (1@10-19)
sending: 'x' (2@20-29)
thing (2@20-29): 'x' (2@20-29)
sending: 'x' (3@30-39)
30-39: syntax error, unexpected 'x', expecting ';'
Freeing nterm thing (2@20-29)
Freeing nterm thing (1@10-19)
Freeing nterm thing (0@0-9)
Freeing token 'x' (3@30-39)
sending: 'x' (4@40-49)
Freeing token 'x' (4@40-49)
sending: 'x' (5@50-59)
Freeing token 'x' (5@50-59)
sending: ';' (6@60-69)
line (-1@0-69): error (@0-59) ';' (6@60-69)
sending: 'x' (7@70-79)
thing (7@70-79): 'x' (7@70-79)
sending: 'x' (8@80-89)
thing (8@80-89): 'x' (8@80-89)
sending: ';' (9@90-99)
line (7@70-99): thing (7@70-79) thing (8@80-89) ';' (9@90-99)
sending: 'x' (10@100-109)
thing (10@100-109): 'x' (10@100-109)
sending: ';' (11@110-119)
line (10@100-119): thing (10@100-109) ';' (11@110-119)
sending: 'y' (12@120-129)
120-129: syntax error, unexpected \$undefined, expecting \$end or 'x'
sending: EOF
Freeing nterm line (10@100-119)
Freeing nterm line (7@70-99)
Freeing nterm line (-1@0-69)
Parsing FAILED.
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "actions.at:514: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-8 ) # Banner 8. conflicts.at:19
    cat <<\_ATEOF

Conflicts.

_ATEOF
    ;;

  43 ) # 43. conflicts.at:31: S/R in initial
    at_setup_line='conflicts.at:31'
    $at_verbose "43. conflicts.at:31: testing S/R in initial..."
    $at_quiet $ECHO_N " 43: conflicts.at:31   $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%expect 1
%%
exp: e 'e';
e: 'e' | /* Nothing. */;
_ATEOF


$at_traceoff
$at_verbose "conflicts.at:42: bison -o input.c input.y"
echo conflicts.at:42 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y:4.9: warning: rule never reduced because of conflicts: e: /* empty */
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "conflicts.at:42: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  44 ) # 44. conflicts.at:51: %nonassoc and eof
    at_setup_line='conflicts.at:51'
    $at_verbose "44. conflicts.at:51: testing %nonassoc and eof..."
    $at_quiet $ECHO_N " 44: conflicts.at:51   $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}


%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
#endif

#define YYERROR_VERBOSE 1
static void
yyerror (const char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

/* The current argument. */
static const char *input = NULL;

static int
yylex (void)
{
  /* No token stands for end of file. */
  if (input && *input)
    return *input++;
  else
    return 0;
}

%}

%nonassoc '<' '>'

%%
expr: expr '<' expr
    | expr '>' expr
    | '0'
    ;
%%
int
main (int argc, const char *argv[])
{
  if (argc > 1)
    input = argv[1];
  return yyparse ();
}
_ATEOF



# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "conflicts.at:103: bison -o input.c input.y"
echo conflicts.at:103 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "conflicts.at:103: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "conflicts.at:104: \$CC \$CFLAGS \$CPPFLAGS input.c -o input"
echo conflicts.at:104 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS input.c -o input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "conflicts.at:104: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "conflicts.at:106: \$PREPARSER ./input '0<0'"
echo conflicts.at:106 >$at_check_line_file
( $at_traceon; $PREPARSER ./input '0<0' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "conflicts.at:106: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

# FIXME: This is an actual bug, but a new one, in the sense that
# no one has ever spotted it!  The messages are *wrong*: there should
# be nothing there, it should be expected eof.
$at_traceoff
$at_verbose "conflicts.at:112: \$PREPARSER ./input '0<0<0'"
echo conflicts.at:112 >$at_check_line_file
( $at_traceon; $PREPARSER ./input '0<0<0' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "syntax error, unexpected '<', expecting '<' or '>'
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "conflicts.at:112: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "conflicts.at:114: \$PREPARSER ./input '0>0'"
echo conflicts.at:114 >$at_check_line_file
( $at_traceon; $PREPARSER ./input '0>0' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "conflicts.at:114: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "conflicts.at:117: \$PREPARSER ./input '0>0>0'"
echo conflicts.at:117 >$at_check_line_file
( $at_traceon; $PREPARSER ./input '0>0>0' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "syntax error, unexpected '>', expecting '<' or '>'
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "conflicts.at:117: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "conflicts.at:121: \$PREPARSER ./input '0<0>0'"
echo conflicts.at:121 >$at_check_line_file
( $at_traceon; $PREPARSER ./input '0<0>0' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "syntax error, unexpected '>', expecting '<' or '>'
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "conflicts.at:121: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  45 ) # 45. conflicts.at:131: Unresolved SR Conflicts
    at_setup_line='conflicts.at:131'
    $at_verbose "45. conflicts.at:131: testing Unresolved SR Conflicts..."
    $at_quiet $ECHO_N " 45: conflicts.at:131  $ECHO_C"
    (
      $at_traceon




cat >input.y <<'_ATEOF'
%token NUM OP
%%
exp: exp OP exp | NUM;
_ATEOF


$at_traceoff
$at_verbose "conflicts.at:143: bison -o input.c --report=all input.y"
echo conflicts.at:143 >$at_check_line_file
( $at_traceon; bison -o input.c --report=all input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y: conflicts: 1 shift/reduce
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "conflicts.at:143: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Check the contents of the report.
$at_traceoff
$at_verbose "conflicts.at:228: cat input.output"
echo conflicts.at:228 >$at_check_line_file
( $at_traceon; cat input.output ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "State 5 conflicts: 1 shift/reduce


Grammar

    0 \$accept: exp \$end

    1 exp: exp OP exp
    2    | NUM


Terminals, with rules where they appear

\$end (0) 0
error (256)
NUM (258) 2
OP (259) 1


Nonterminals, with rules where they appear

\$accept (5)
    on left: 0
exp (6)
    on left: 1 2, on right: 0 1


state 0

    0 \$accept: . exp \$end
    1 exp: . exp OP exp
    2    | . NUM

    NUM  shift, and go to state 1

    exp  go to state 2


state 1

    2 exp: NUM .

    \$default  reduce using rule 2 (exp)


state 2

    0 \$accept: exp . \$end
    1 exp: exp . OP exp

    \$end  shift, and go to state 3
    OP    shift, and go to state 4


state 3

    0 \$accept: exp \$end .

    \$default  accept


state 4

    1 exp: . exp OP exp
    1    | exp OP . exp
    2    | . NUM

    NUM  shift, and go to state 1

    exp  go to state 5


state 5

    1 exp: exp . OP exp  [\$end, OP]
    1    | exp OP exp .  [\$end, OP]

    OP  shift, and go to state 4

    OP        [reduce using rule 1 (exp)]
    \$default  reduce using rule 1 (exp)
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "conflicts.at:228: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  46 ) # 46. conflicts.at:238: Resolved SR Conflicts
    at_setup_line='conflicts.at:238'
    $at_verbose "46. conflicts.at:238: testing Resolved SR Conflicts..."
    $at_quiet $ECHO_N " 46: conflicts.at:238  $ECHO_C"
    (
      $at_traceon




cat >input.y <<'_ATEOF'
%token NUM OP
%left OP
%%
exp: exp OP exp | NUM;
_ATEOF


$at_traceoff
$at_verbose "conflicts.at:249: bison -o input.c --report=all input.y"
echo conflicts.at:249 >$at_check_line_file
( $at_traceon; bison -o input.c --report=all input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "conflicts.at:249: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Check the contents of the report.
$at_traceoff
$at_verbose "conflicts.at:330: cat input.output"
echo conflicts.at:330 >$at_check_line_file
( $at_traceon; cat input.output ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "Grammar

    0 \$accept: exp \$end

    1 exp: exp OP exp
    2    | NUM


Terminals, with rules where they appear

\$end (0) 0
error (256)
NUM (258) 2
OP (259) 1


Nonterminals, with rules where they appear

\$accept (5)
    on left: 0
exp (6)
    on left: 1 2, on right: 0 1


state 0

    0 \$accept: . exp \$end
    1 exp: . exp OP exp
    2    | . NUM

    NUM  shift, and go to state 1

    exp  go to state 2


state 1

    2 exp: NUM .

    \$default  reduce using rule 2 (exp)


state 2

    0 \$accept: exp . \$end
    1 exp: exp . OP exp

    \$end  shift, and go to state 3
    OP    shift, and go to state 4


state 3

    0 \$accept: exp \$end .

    \$default  accept


state 4

    1 exp: . exp OP exp
    1    | exp OP . exp
    2    | . NUM

    NUM  shift, and go to state 1

    exp  go to state 5


state 5

    1 exp: exp . OP exp  [\$end, OP]
    1    | exp OP exp .  [\$end, OP]

    \$default  reduce using rule 1 (exp)

    Conflict between rule 1 and token OP resolved as reduce (%left OP).
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "conflicts.at:330: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  47 ) # 47. conflicts.at:360: Defaulted Conflicted Reduction
    at_setup_line='conflicts.at:360'
    $at_verbose "47. conflicts.at:360: testing Defaulted Conflicted Reduction..."
    $at_quiet $ECHO_N " 47: conflicts.at:360  $ECHO_C"
    (
      $at_traceon



cat >input.y <<'_ATEOF'
%%
exp: num | id;
num: '0';
id : '0';
%%
_ATEOF


$at_traceoff
$at_verbose "conflicts.at:374: bison -o input.c --report=all input.y"
echo conflicts.at:374 >$at_check_line_file
( $at_traceon; bison -o input.c --report=all input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y: conflicts: 1 reduce/reduce
input.y:4.6-8: warning: rule never reduced because of conflicts: id: '0'
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "conflicts.at:374: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Check the contents of the report.
$at_traceoff
$at_verbose "conflicts.at:468: cat input.output"
echo conflicts.at:468 >$at_check_line_file
( $at_traceon; cat input.output ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "Rules never reduced

    4 id: '0'


State 1 conflicts: 1 reduce/reduce


Grammar

    0 \$accept: exp \$end

    1 exp: num
    2    | id

    3 num: '0'

    4 id: '0'


Terminals, with rules where they appear

\$end (0) 0
'0' (48) 3 4
error (256)


Nonterminals, with rules where they appear

\$accept (4)
    on left: 0
exp (5)
    on left: 1 2, on right: 0
num (6)
    on left: 3, on right: 1
id (7)
    on left: 4, on right: 2


state 0

    0 \$accept: . exp \$end
    1 exp: . num
    2    | . id
    3 num: . '0'
    4 id: . '0'

    '0'  shift, and go to state 1

    exp  go to state 2
    num  go to state 3
    id   go to state 4


state 1

    3 num: '0' .  [\$end]
    4 id: '0' .  [\$end]

    \$end      reduce using rule 3 (num)
    \$end      [reduce using rule 4 (id)]
    \$default  reduce using rule 3 (num)


state 2

    0 \$accept: exp . \$end

    \$end  shift, and go to state 5


state 3

    1 exp: num .

    \$default  reduce using rule 1 (exp)


state 4

    2 exp: id .

    \$default  reduce using rule 2 (exp)


state 5

    0 \$accept: exp \$end .

    \$default  accept
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "conflicts.at:468: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  48 ) # 48. conflicts.at:479: %expect not enough
    at_setup_line='conflicts.at:479'
    $at_verbose "48. conflicts.at:479: testing %expect not enough..."
    $at_quiet $ECHO_N " 48: conflicts.at:479  $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%token NUM OP
%expect 0
%%
exp: exp OP exp | NUM;
_ATEOF


$at_traceoff
$at_verbose "conflicts.at:491: bison -o input.c input.y"
echo conflicts.at:491 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y: conflicts: 1 shift/reduce
input.y: expected 0 shift/reduce conflicts
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "conflicts.at:491: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  49 ) # 49. conflicts.at:499: %expect right
    at_setup_line='conflicts.at:499'
    $at_verbose "49. conflicts.at:499: testing %expect right..."
    $at_quiet $ECHO_N " 49: conflicts.at:499  $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%token NUM OP
%expect 1
%%
exp: exp OP exp | NUM;
_ATEOF


$at_traceoff
$at_verbose "conflicts.at:508: bison -o input.c input.y"
echo conflicts.at:508 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "conflicts.at:508: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  50 ) # 50. conflicts.at:516: %expect too much
    at_setup_line='conflicts.at:516'
    $at_verbose "50. conflicts.at:516: testing %expect too much..."
    $at_quiet $ECHO_N " 50: conflicts.at:516  $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%token NUM OP
%expect 2
%%
exp: exp OP exp | NUM;
_ATEOF


$at_traceoff
$at_verbose "conflicts.at:528: bison -o input.c input.y"
echo conflicts.at:528 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y: conflicts: 1 shift/reduce
input.y: expected 2 shift/reduce conflicts
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "conflicts.at:528: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  51 ) # 51. conflicts.at:536: %expect with reduce conflicts
    at_setup_line='conflicts.at:536'
    $at_verbose "51. conflicts.at:536: testing %expect with reduce conflicts..."
    $at_quiet $ECHO_N " 51: conflicts.at:536  $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%expect 0
%%
program: a 'a' | a a;
a: 'a';
_ATEOF


$at_traceoff
$at_verbose "conflicts.at:548: bison -o input.c input.y"
echo conflicts.at:548 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y: conflicts: 1 reduce/reduce
input.y: expected 0 reduce/reduce conflicts
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "conflicts.at:548: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-9 ) # Banner 9. calc.at:538
    cat <<\_ATEOF

Simple LALR Calculator.

_ATEOF
    ;;

  52 ) # 52. calc.at:547: Calculator
    at_setup_line='calc.at:547'
    $at_verbose "52. calc.at:547: testing Calculator ..."
    $at_quiet $ECHO_N " 52: calc.at:547       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */

%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:547: bison -o calc.c calc.y"
echo calc.at:547 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:547: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:547 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:547: \$PREPARSER ./calc input"
echo calc.at:547 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:547: \$PREPARSER ./calc input"
echo calc.at:547 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:547: cat stderr"
echo calc.at:547 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:547: \$PREPARSER ./calc input"
echo calc.at:547 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:547: cat stderr"
echo calc.at:547 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:547: \$PREPARSER ./calc input"
echo calc.at:547 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:547: cat stderr"
echo calc.at:547 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:547: \$PREPARSER ./calc input"
echo calc.at:547 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:547: cat stderr"
echo calc.at:547 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:547: \$PREPARSER ./calc input"
echo calc.at:547 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:547: cat stderr"
echo calc.at:547 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:547: \$PREPARSER ./calc /dev/null"
echo calc.at:547 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:547: cat stderr"
echo calc.at:547 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:547: \$PREPARSER ./calc input"
echo calc.at:547 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:547: cat stderr"
echo calc.at:547 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:547: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  53 ) # 53. calc.at:549: Calculator %defines
    at_setup_line='calc.at:549'
    $at_verbose "53. calc.at:549: testing Calculator %defines..."
    $at_quiet $ECHO_N " 53: calc.at:549       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%defines
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:549: bison -o calc.c calc.y"
echo calc.at:549 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:549: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:549 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:549: \$PREPARSER ./calc input"
echo calc.at:549 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:549: \$PREPARSER ./calc input"
echo calc.at:549 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:549: cat stderr"
echo calc.at:549 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:549: \$PREPARSER ./calc input"
echo calc.at:549 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:549: cat stderr"
echo calc.at:549 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:549: \$PREPARSER ./calc input"
echo calc.at:549 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:549: cat stderr"
echo calc.at:549 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:549: \$PREPARSER ./calc input"
echo calc.at:549 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:549: cat stderr"
echo calc.at:549 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:549: \$PREPARSER ./calc input"
echo calc.at:549 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:549: cat stderr"
echo calc.at:549 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:549: \$PREPARSER ./calc /dev/null"
echo calc.at:549 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:549: cat stderr"
echo calc.at:549 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:549: \$PREPARSER ./calc input"
echo calc.at:549 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:549: cat stderr"
echo calc.at:549 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:549: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  54 ) # 54. calc.at:550: Calculator %locations
    at_setup_line='calc.at:550'
    $at_verbose "54. calc.at:550: testing Calculator %locations..."
    $at_quiet $ECHO_N " 54: calc.at:550       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%locations
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL   , YYLTYPE *yylloc
#define YYLLOC_ARG      , yylloc
#define USE_YYLLOC      (void) yylloc;

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%d.%d-%d.%d: ",
	   LOC.first_line, LOC.first_column,
	   LOC.last_line, LOC.last_column);

  fprintf (stderr, "%s\n", s);
}



static YYLTYPE last_yylloc;

static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  last_yylloc = LOC;
  if (res == '\n')
    {
      LOC.last_line++;
      LOC.last_column = 1;
    }
  else
    LOC.last_column++;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  /* Wrong when C == `\n'. */
  LOC = last_yylloc;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

      LOC.last_column = 1;
      LOC.last_line = 1;

    }


  LOC.first_column = LOC.last_column;
  LOC.first_line = LOC.last_line;


  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

      LOC.first_column = LOC.last_column;
      LOC.first_line = LOC.last_line;

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:550: bison -o calc.c calc.y"
echo calc.at:550 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:550: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:550 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:550: \$PREPARSER ./calc input"
echo calc.at:550 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:550: \$PREPARSER ./calc input"
echo calc.at:550 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:550: cat stderr"
echo calc.at:550 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:550: \$PREPARSER ./calc input"
echo calc.at:550 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:550: cat stderr"
echo calc.at:550 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:550: \$PREPARSER ./calc input"
echo calc.at:550 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:550: cat stderr"
echo calc.at:550 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:550: \$PREPARSER ./calc input"
echo calc.at:550 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:550: cat stderr"
echo calc.at:550 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:550: \$PREPARSER ./calc input"
echo calc.at:550 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:550: cat stderr"
echo calc.at:550 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:550: \$PREPARSER ./calc /dev/null"
echo calc.at:550 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:550: cat stderr"
echo calc.at:550 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:550: \$PREPARSER ./calc input"
echo calc.at:550 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:550: cat stderr"
echo calc.at:550 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:550: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  55 ) # 55. calc.at:551: Calculator %name-prefix="calc"
    at_setup_line='calc.at:551'
    $at_verbose "55. calc.at:551: testing Calculator %name-prefix="calc"..."
    $at_quiet $ECHO_N " 55: calc.at:551       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%name-prefix="calc"
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:551: bison -o calc.c calc.y"
echo calc.at:551 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:551: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:551 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:551: \$PREPARSER ./calc input"
echo calc.at:551 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:551: \$PREPARSER ./calc input"
echo calc.at:551 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:551: cat stderr"
echo calc.at:551 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:551: \$PREPARSER ./calc input"
echo calc.at:551 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:551: cat stderr"
echo calc.at:551 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:551: \$PREPARSER ./calc input"
echo calc.at:551 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:551: cat stderr"
echo calc.at:551 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:551: \$PREPARSER ./calc input"
echo calc.at:551 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:551: cat stderr"
echo calc.at:551 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:551: \$PREPARSER ./calc input"
echo calc.at:551 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:551: cat stderr"
echo calc.at:551 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:551: \$PREPARSER ./calc /dev/null"
echo calc.at:551 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:551: cat stderr"
echo calc.at:551 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:551: \$PREPARSER ./calc input"
echo calc.at:551 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:551: cat stderr"
echo calc.at:551 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:551: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  56 ) # 56. calc.at:552: Calculator %verbose
    at_setup_line='calc.at:552'
    $at_verbose "56. calc.at:552: testing Calculator %verbose..."
    $at_quiet $ECHO_N " 56: calc.at:552       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%verbose
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:552: bison -o calc.c calc.y"
echo calc.at:552 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:552: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:552 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:552: \$PREPARSER ./calc input"
echo calc.at:552 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:552: \$PREPARSER ./calc input"
echo calc.at:552 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:552: cat stderr"
echo calc.at:552 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:552: \$PREPARSER ./calc input"
echo calc.at:552 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:552: cat stderr"
echo calc.at:552 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:552: \$PREPARSER ./calc input"
echo calc.at:552 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:552: cat stderr"
echo calc.at:552 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:552: \$PREPARSER ./calc input"
echo calc.at:552 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:552: cat stderr"
echo calc.at:552 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:552: \$PREPARSER ./calc input"
echo calc.at:552 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:552: cat stderr"
echo calc.at:552 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:552: \$PREPARSER ./calc /dev/null"
echo calc.at:552 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:552: cat stderr"
echo calc.at:552 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:552: \$PREPARSER ./calc input"
echo calc.at:552 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:552: cat stderr"
echo calc.at:552 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:552: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  57 ) # 57. calc.at:553: Calculator %yacc
    at_setup_line='calc.at:553'
    $at_verbose "57. calc.at:553: testing Calculator %yacc..."
    $at_quiet $ECHO_N " 57: calc.at:553       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%yacc
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:553: bison -o calc.c calc.y"
echo calc.at:553 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:553: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:553 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:553: \$PREPARSER ./calc input"
echo calc.at:553 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:553: \$PREPARSER ./calc input"
echo calc.at:553 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:553: cat stderr"
echo calc.at:553 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:553: \$PREPARSER ./calc input"
echo calc.at:553 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:553: cat stderr"
echo calc.at:553 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:553: \$PREPARSER ./calc input"
echo calc.at:553 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:553: cat stderr"
echo calc.at:553 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:553: \$PREPARSER ./calc input"
echo calc.at:553 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:553: cat stderr"
echo calc.at:553 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:553: \$PREPARSER ./calc input"
echo calc.at:553 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:553: cat stderr"
echo calc.at:553 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:553: \$PREPARSER ./calc /dev/null"
echo calc.at:553 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:553: cat stderr"
echo calc.at:553 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:553: \$PREPARSER ./calc input"
echo calc.at:553 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:553: cat stderr"
echo calc.at:553 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:553: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  58 ) # 58. calc.at:554: Calculator %error-verbose
    at_setup_line='calc.at:554'
    $at_verbose "58. calc.at:554: testing Calculator %error-verbose..."
    $at_quiet $ECHO_N " 58: calc.at:554       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%error-verbose
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:554: bison -o calc.c calc.y"
echo calc.at:554 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:554: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:554 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:554: \$PREPARSER ./calc input"
echo calc.at:554 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:554: \$PREPARSER ./calc input"
echo calc.at:554 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:554: cat stderr"
echo calc.at:554 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:554: \$PREPARSER ./calc input"
echo calc.at:554 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:554: cat stderr"
echo calc.at:554 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:554: \$PREPARSER ./calc input"
echo calc.at:554 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:554: cat stderr"
echo calc.at:554 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:554: \$PREPARSER ./calc input"
echo calc.at:554 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:554: cat stderr"
echo calc.at:554 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:554: \$PREPARSER ./calc input"
echo calc.at:554 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:554: cat stderr"
echo calc.at:554 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:554: \$PREPARSER ./calc /dev/null"
echo calc.at:554 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:554: cat stderr"
echo calc.at:554 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:554: \$PREPARSER ./calc input"
echo calc.at:554 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:554: cat stderr"
echo calc.at:554 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:554: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  59 ) # 59. calc.at:556: Calculator %error-verbose %locations
    at_setup_line='calc.at:556'
    $at_verbose "59. calc.at:556: testing Calculator %error-verbose %locations..."
    $at_quiet $ECHO_N " 59: calc.at:556       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%error-verbose %locations
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL   , YYLTYPE *yylloc
#define YYLLOC_ARG      , yylloc
#define USE_YYLLOC      (void) yylloc;

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%d.%d-%d.%d: ",
	   LOC.first_line, LOC.first_column,
	   LOC.last_line, LOC.last_column);

  fprintf (stderr, "%s\n", s);
}



static YYLTYPE last_yylloc;

static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  last_yylloc = LOC;
  if (res == '\n')
    {
      LOC.last_line++;
      LOC.last_column = 1;
    }
  else
    LOC.last_column++;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  /* Wrong when C == `\n'. */
  LOC = last_yylloc;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

      LOC.last_column = 1;
      LOC.last_line = 1;

    }


  LOC.first_column = LOC.last_column;
  LOC.first_line = LOC.last_line;


  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

      LOC.first_column = LOC.last_column;
      LOC.first_line = LOC.last_line;

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:556: bison -o calc.c calc.y"
echo calc.at:556 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:556: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:556 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:556: \$PREPARSER ./calc input"
echo calc.at:556 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:556: \$PREPARSER ./calc input"
echo calc.at:556 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:556: cat stderr"
echo calc.at:556 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:556: \$PREPARSER ./calc input"
echo calc.at:556 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:556: cat stderr"
echo calc.at:556 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:556: \$PREPARSER ./calc input"
echo calc.at:556 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:556: cat stderr"
echo calc.at:556 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:556: \$PREPARSER ./calc input"
echo calc.at:556 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:556: cat stderr"
echo calc.at:556 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:556: \$PREPARSER ./calc input"
echo calc.at:556 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:556: cat stderr"
echo calc.at:556 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:556: \$PREPARSER ./calc /dev/null"
echo calc.at:556 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:556: cat stderr"
echo calc.at:556 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:556: \$PREPARSER ./calc input"
echo calc.at:556 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:556: cat stderr"
echo calc.at:556 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:556: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  60 ) # 60. calc.at:558: Calculator %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc
    at_setup_line='calc.at:558'
    $at_verbose "60. calc.at:558: testing Calculator %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc..."
    $at_quiet $ECHO_N " 60: calc.at:558       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL   , YYLTYPE *yylloc
#define YYLLOC_ARG      , yylloc
#define USE_YYLLOC      (void) yylloc;

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%d.%d-%d.%d: ",
	   LOC.first_line, LOC.first_column,
	   LOC.last_line, LOC.last_column);

  fprintf (stderr, "%s\n", s);
}



static YYLTYPE last_yylloc;

static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  last_yylloc = LOC;
  if (res == '\n')
    {
      LOC.last_line++;
      LOC.last_column = 1;
    }
  else
    LOC.last_column++;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  /* Wrong when C == `\n'. */
  LOC = last_yylloc;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

      LOC.last_column = 1;
      LOC.last_line = 1;

    }


  LOC.first_column = LOC.last_column;
  LOC.first_line = LOC.last_line;


  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

      LOC.first_column = LOC.last_column;
      LOC.first_line = LOC.last_line;

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:558: bison -o calc.c calc.y"
echo calc.at:558 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:558: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:558 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:558: \$PREPARSER ./calc input"
echo calc.at:558 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:558: \$PREPARSER ./calc input"
echo calc.at:558 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:558: cat stderr"
echo calc.at:558 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:558: \$PREPARSER ./calc input"
echo calc.at:558 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:558: cat stderr"
echo calc.at:558 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:558: \$PREPARSER ./calc input"
echo calc.at:558 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:558: cat stderr"
echo calc.at:558 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:558: \$PREPARSER ./calc input"
echo calc.at:558 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:558: cat stderr"
echo calc.at:558 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:558: \$PREPARSER ./calc input"
echo calc.at:558 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:558: cat stderr"
echo calc.at:558 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:558: \$PREPARSER ./calc /dev/null"
echo calc.at:558 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:558: cat stderr"
echo calc.at:558 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:558: \$PREPARSER ./calc input"
echo calc.at:558 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:558: cat stderr"
echo calc.at:558 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:558: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  61 ) # 61. calc.at:560: Calculator %debug
    at_setup_line='calc.at:560'
    $at_verbose "61. calc.at:560: testing Calculator %debug..."
    $at_quiet $ECHO_N " 61: calc.at:560       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%debug
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:560: bison -o calc.c calc.y"
echo calc.at:560 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:560: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:560 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:560: \$PREPARSER ./calc input"
echo calc.at:560 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:560: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:560 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "486
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:560: \$PREPARSER ./calc input"
echo calc.at:560 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:560: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:560 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "11
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:560: cat stderr"
echo calc.at:560 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:560: \$PREPARSER ./calc input"
echo calc.at:560 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:560: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:560 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "15
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:560: cat stderr"
echo calc.at:560 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:560: \$PREPARSER ./calc input"
echo calc.at:560 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:560: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:560 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "4
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:560: cat stderr"
echo calc.at:560 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:560: \$PREPARSER ./calc input"
echo calc.at:560 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:560: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:560 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "22
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:560: cat stderr"
echo calc.at:560 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:560: \$PREPARSER ./calc input"
echo calc.at:560 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:560: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:560 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "14
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:560: cat stderr"
echo calc.at:560 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:560: \$PREPARSER ./calc /dev/null"
echo calc.at:560 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:560: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:560 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "4
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:560: cat stderr"
echo calc.at:560 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:560: \$PREPARSER ./calc input"
echo calc.at:560 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:560: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:560 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "82
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:560: cat stderr"
echo calc.at:560 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:560: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  62 ) # 62. calc.at:561: Calculator %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
    at_setup_line='calc.at:561'
    $at_verbose "62. calc.at:561: testing Calculator %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc..."
    $at_quiet $ECHO_N " 62: calc.at:561       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL   , YYLTYPE *yylloc
#define YYLLOC_ARG      , yylloc
#define USE_YYLLOC      (void) yylloc;

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%d.%d-%d.%d: ",
	   LOC.first_line, LOC.first_column,
	   LOC.last_line, LOC.last_column);

  fprintf (stderr, "%s\n", s);
}



static YYLTYPE last_yylloc;

static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  last_yylloc = LOC;
  if (res == '\n')
    {
      LOC.last_line++;
      LOC.last_column = 1;
    }
  else
    LOC.last_column++;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  /* Wrong when C == `\n'. */
  LOC = last_yylloc;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

      LOC.last_column = 1;
      LOC.last_line = 1;

    }


  LOC.first_column = LOC.last_column;
  LOC.first_line = LOC.last_line;


  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

      LOC.first_column = LOC.last_column;
      LOC.first_line = LOC.last_line;

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:561: bison -o calc.c calc.y"
echo calc.at:561 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:561: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:561 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:561: \$PREPARSER ./calc input"
echo calc.at:561 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:561: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:561 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "486
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:561: \$PREPARSER ./calc input"
echo calc.at:561 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:561: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:561 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "11
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:561: cat stderr"
echo calc.at:561 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:561: \$PREPARSER ./calc input"
echo calc.at:561 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:561: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:561 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "15
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:561: cat stderr"
echo calc.at:561 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:561: \$PREPARSER ./calc input"
echo calc.at:561 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:561: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:561 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "4
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:561: cat stderr"
echo calc.at:561 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:561: \$PREPARSER ./calc input"
echo calc.at:561 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:561: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:561 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "22
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:561: cat stderr"
echo calc.at:561 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:561: \$PREPARSER ./calc input"
echo calc.at:561 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:561: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:561 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "14
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:561: cat stderr"
echo calc.at:561 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:561: \$PREPARSER ./calc /dev/null"
echo calc.at:561 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:561: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:561 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "4
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:561: cat stderr"
echo calc.at:561 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:561: \$PREPARSER ./calc input"
echo calc.at:561 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:561: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:561 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "82
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:561: cat stderr"
echo calc.at:561 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:561: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  63 ) # 63. calc.at:563: Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
    at_setup_line='calc.at:563'
    $at_verbose "63. calc.at:563: testing Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc..."
    $at_quiet $ECHO_N " 63: calc.at:563       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL   , YYLTYPE *yylloc
#define YYLLOC_ARG      , yylloc
#define USE_YYLLOC      (void) yylloc;

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static YYLTYPE last_yylloc;

static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  last_yylloc = LOC;
  if (res == '\n')
    {
      LOC.last_line++;
      LOC.last_column = 1;
    }
  else
    LOC.last_column++;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  /* Wrong when C == `\n'. */
  LOC = last_yylloc;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

      LOC.last_column = 1;
      LOC.last_line = 1;

    }


  LOC.first_column = LOC.last_column;
  LOC.first_line = LOC.last_line;


  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

      LOC.first_column = LOC.last_column;
      LOC.first_line = LOC.last_line;

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:563: bison -o calc.c calc.y"
echo calc.at:563 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:563: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:563 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:563: \$PREPARSER ./calc input"
echo calc.at:563 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:563: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:563 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "486
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:563: \$PREPARSER ./calc input"
echo calc.at:563 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:563: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:563 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "11
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:563: cat stderr"
echo calc.at:563 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:563: \$PREPARSER ./calc input"
echo calc.at:563 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:563: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:563 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "15
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:563: cat stderr"
echo calc.at:563 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:563: \$PREPARSER ./calc input"
echo calc.at:563 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:563: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:563 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "4
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:563: cat stderr"
echo calc.at:563 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:563: \$PREPARSER ./calc input"
echo calc.at:563 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:563: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:563 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "22
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:563: cat stderr"
echo calc.at:563 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:563: \$PREPARSER ./calc input"
echo calc.at:563 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:563: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:563 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "14
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:563: cat stderr"
echo calc.at:563 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:563: \$PREPARSER ./calc /dev/null"
echo calc.at:563 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:563: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:563 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "4
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:563: cat stderr"
echo calc.at:563 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:563: \$PREPARSER ./calc input"
echo calc.at:563 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:563: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:563 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "82
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:563: cat stderr"
echo calc.at:563 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:563: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  64 ) # 64. calc.at:565: Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count}
    at_setup_line='calc.at:565'
    $at_verbose "64. calc.at:565: testing Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count}..."
    $at_quiet $ECHO_N " 64: calc.at:565       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count}
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL   , YYLTYPE *yylloc
#define YYLLOC_ARG      , yylloc
#define USE_YYLLOC      (void) yylloc;

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (YYLTYPE *yylloc,
                     value *result, int *count,
                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         { ++*count; ++global_count; }
;

line:
  '\n'
| exp '\n'           { *result = global_result = $1; }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (YYLTYPE *yylloc,
         value *result, int *count,
         const char *s
         )
{
(void) result; (void) count;

  fprintf (stderr, "%d.%d-%d.%d: ",
	   LOC.first_line, LOC.first_column,
	   LOC.last_line, LOC.last_column);

  fprintf (stderr, "%s\n", s);
}



static YYLTYPE last_yylloc;

static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  last_yylloc = LOC;
  if (res == '\n')
    {
      LOC.last_line++;
      LOC.last_column = 1;
    }
  else
    LOC.last_column++;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  /* Wrong when C == `\n'. */
  LOC = last_yylloc;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

      LOC.last_column = 1;
      LOC.last_line = 1;

    }


  LOC.first_column = LOC.last_column;
  LOC.first_line = LOC.last_line;


  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

      LOC.first_column = LOC.last_column;
      LOC.first_line = LOC.last_line;

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse (&result, &count);
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:565: bison -o calc.c calc.y"
echo calc.at:565 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:565: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:565 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:565: \$PREPARSER ./calc input"
echo calc.at:565 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:565: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:565 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "486
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:565: \$PREPARSER ./calc input"
echo calc.at:565 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:565: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:565 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "11
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:565: cat stderr"
echo calc.at:565 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:565: \$PREPARSER ./calc input"
echo calc.at:565 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:565: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:565 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "15
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:565: cat stderr"
echo calc.at:565 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:565: \$PREPARSER ./calc input"
echo calc.at:565 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:565: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:565 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "4
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:565: cat stderr"
echo calc.at:565 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:565: \$PREPARSER ./calc input"
echo calc.at:565 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:565: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:565 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "22
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:565: cat stderr"
echo calc.at:565 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:565: \$PREPARSER ./calc input"
echo calc.at:565 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:565: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:565 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "14
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:565: cat stderr"
echo calc.at:565 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:565: \$PREPARSER ./calc /dev/null"
echo calc.at:565 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:565: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:565 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "4
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:565: cat stderr"
echo calc.at:565 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:565: \$PREPARSER ./calc input"
echo calc.at:565 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "calc.at:565: wc -l <stderr | sed 's/[^0-9]//g'"
echo calc.at:565 >$at_check_line_file
( $at_traceon; wc -l <stderr | sed 's/[^0-9]//g' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "82
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:565: cat stderr"
echo calc.at:565 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:565: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-10 ) # Banner 10. calc.at:572
    cat <<\_ATEOF

Simple GLR Calculator.

_ATEOF
    ;;

  65 ) # 65. calc.at:582: Calculator %glr-parser
    at_setup_line='calc.at:582'
    $at_verbose "65. calc.at:582: testing Calculator %glr-parser ..."
    $at_quiet $ECHO_N " 65: calc.at:582       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%glr-parser
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:582: bison -o calc.c calc.y"
echo calc.at:582 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:582: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:582 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:582: \$PREPARSER ./calc input"
echo calc.at:582 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:582: \$PREPARSER ./calc input"
echo calc.at:582 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:582: cat stderr"
echo calc.at:582 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:582: \$PREPARSER ./calc input"
echo calc.at:582 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:582: cat stderr"
echo calc.at:582 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:582: \$PREPARSER ./calc input"
echo calc.at:582 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:582: cat stderr"
echo calc.at:582 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:582: \$PREPARSER ./calc input"
echo calc.at:582 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:582: cat stderr"
echo calc.at:582 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:582: \$PREPARSER ./calc input"
echo calc.at:582 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:582: cat stderr"
echo calc.at:582 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:582: \$PREPARSER ./calc /dev/null"
echo calc.at:582 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:582: cat stderr"
echo calc.at:582 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:582: \$PREPARSER ./calc input"
echo calc.at:582 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:582: cat stderr"
echo calc.at:582 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:582: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  66 ) # 66. calc.at:584: Calculator %glr-parser %defines
    at_setup_line='calc.at:584'
    $at_verbose "66. calc.at:584: testing Calculator %glr-parser %defines..."
    $at_quiet $ECHO_N " 66: calc.at:584       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%glr-parser %defines
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:584: bison -o calc.c calc.y"
echo calc.at:584 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:584: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:584 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:584: \$PREPARSER ./calc input"
echo calc.at:584 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:584: \$PREPARSER ./calc input"
echo calc.at:584 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:584: cat stderr"
echo calc.at:584 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:584: \$PREPARSER ./calc input"
echo calc.at:584 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:584: cat stderr"
echo calc.at:584 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:584: \$PREPARSER ./calc input"
echo calc.at:584 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:584: cat stderr"
echo calc.at:584 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:584: \$PREPARSER ./calc input"
echo calc.at:584 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:584: cat stderr"
echo calc.at:584 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:584: \$PREPARSER ./calc input"
echo calc.at:584 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:584: cat stderr"
echo calc.at:584 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:584: \$PREPARSER ./calc /dev/null"
echo calc.at:584 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:584: cat stderr"
echo calc.at:584 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:584: \$PREPARSER ./calc input"
echo calc.at:584 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:584: cat stderr"
echo calc.at:584 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:584: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  67 ) # 67. calc.at:585: Calculator %glr-parser %locations
    at_setup_line='calc.at:585'
    $at_verbose "67. calc.at:585: testing Calculator %glr-parser %locations..."
    $at_quiet $ECHO_N " 67: calc.at:585       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%glr-parser %locations
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL   , YYLTYPE *yylloc
#define YYLLOC_ARG      , yylloc
#define USE_YYLLOC      (void) yylloc;

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%d.%d-%d.%d: ",
	   LOC.first_line, LOC.first_column,
	   LOC.last_line, LOC.last_column);

  fprintf (stderr, "%s\n", s);
}



static YYLTYPE last_yylloc;

static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  last_yylloc = LOC;
  if (res == '\n')
    {
      LOC.last_line++;
      LOC.last_column = 1;
    }
  else
    LOC.last_column++;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  /* Wrong when C == `\n'. */
  LOC = last_yylloc;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

      LOC.last_column = 1;
      LOC.last_line = 1;

    }


  LOC.first_column = LOC.last_column;
  LOC.first_line = LOC.last_line;


  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

      LOC.first_column = LOC.last_column;
      LOC.first_line = LOC.last_line;

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:585: bison -o calc.c calc.y"
echo calc.at:585 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:585: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:585 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:585: \$PREPARSER ./calc input"
echo calc.at:585 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:585: \$PREPARSER ./calc input"
echo calc.at:585 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:585: cat stderr"
echo calc.at:585 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:585: \$PREPARSER ./calc input"
echo calc.at:585 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:585: cat stderr"
echo calc.at:585 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:585: \$PREPARSER ./calc input"
echo calc.at:585 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:585: cat stderr"
echo calc.at:585 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:585: \$PREPARSER ./calc input"
echo calc.at:585 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:585: cat stderr"
echo calc.at:585 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:585: \$PREPARSER ./calc input"
echo calc.at:585 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:585: cat stderr"
echo calc.at:585 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:585: \$PREPARSER ./calc /dev/null"
echo calc.at:585 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:585: cat stderr"
echo calc.at:585 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:585: \$PREPARSER ./calc input"
echo calc.at:585 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:585: cat stderr"
echo calc.at:585 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:585: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  68 ) # 68. calc.at:586: Calculator %glr-parser %name-prefix="calc"
    at_setup_line='calc.at:586'
    $at_verbose "68. calc.at:586: testing Calculator %glr-parser %name-prefix="calc"..."
    $at_quiet $ECHO_N " 68: calc.at:586       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%glr-parser %name-prefix="calc"
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:586: bison -o calc.c calc.y"
echo calc.at:586 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:586: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:586 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:586: \$PREPARSER ./calc input"
echo calc.at:586 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:586: \$PREPARSER ./calc input"
echo calc.at:586 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:586: cat stderr"
echo calc.at:586 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:586: \$PREPARSER ./calc input"
echo calc.at:586 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:586: cat stderr"
echo calc.at:586 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:586: \$PREPARSER ./calc input"
echo calc.at:586 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:586: cat stderr"
echo calc.at:586 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:586: \$PREPARSER ./calc input"
echo calc.at:586 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:586: cat stderr"
echo calc.at:586 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:586: \$PREPARSER ./calc input"
echo calc.at:586 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:586: cat stderr"
echo calc.at:586 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:586: \$PREPARSER ./calc /dev/null"
echo calc.at:586 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:586: cat stderr"
echo calc.at:586 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:586: \$PREPARSER ./calc input"
echo calc.at:586 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:586: cat stderr"
echo calc.at:586 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:586: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  69 ) # 69. calc.at:587: Calculator %glr-parser %verbose
    at_setup_line='calc.at:587'
    $at_verbose "69. calc.at:587: testing Calculator %glr-parser %verbose..."
    $at_quiet $ECHO_N " 69: calc.at:587       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%glr-parser %verbose
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:587: bison -o calc.c calc.y"
echo calc.at:587 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:587: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:587 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:587: \$PREPARSER ./calc input"
echo calc.at:587 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:587: \$PREPARSER ./calc input"
echo calc.at:587 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:587: cat stderr"
echo calc.at:587 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:587: \$PREPARSER ./calc input"
echo calc.at:587 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:587: cat stderr"
echo calc.at:587 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:587: \$PREPARSER ./calc input"
echo calc.at:587 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:587: cat stderr"
echo calc.at:587 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:587: \$PREPARSER ./calc input"
echo calc.at:587 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:587: cat stderr"
echo calc.at:587 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:587: \$PREPARSER ./calc input"
echo calc.at:587 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:587: cat stderr"
echo calc.at:587 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:587: \$PREPARSER ./calc /dev/null"
echo calc.at:587 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:587: cat stderr"
echo calc.at:587 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:587: \$PREPARSER ./calc input"
echo calc.at:587 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:587: cat stderr"
echo calc.at:587 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:587: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  70 ) # 70. calc.at:588: Calculator %glr-parser %yacc
    at_setup_line='calc.at:588'
    $at_verbose "70. calc.at:588: testing Calculator %glr-parser %yacc..."
    $at_quiet $ECHO_N " 70: calc.at:588       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%glr-parser %yacc
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:588: bison -o calc.c calc.y"
echo calc.at:588 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:588: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:588 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:588: \$PREPARSER ./calc input"
echo calc.at:588 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:588: \$PREPARSER ./calc input"
echo calc.at:588 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:588: cat stderr"
echo calc.at:588 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:588: \$PREPARSER ./calc input"
echo calc.at:588 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:588: cat stderr"
echo calc.at:588 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:588: \$PREPARSER ./calc input"
echo calc.at:588 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:588: cat stderr"
echo calc.at:588 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:588: \$PREPARSER ./calc input"
echo calc.at:588 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:588: cat stderr"
echo calc.at:588 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:588: \$PREPARSER ./calc input"
echo calc.at:588 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:588: cat stderr"
echo calc.at:588 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:588: \$PREPARSER ./calc /dev/null"
echo calc.at:588 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:588: cat stderr"
echo calc.at:588 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:588: \$PREPARSER ./calc input"
echo calc.at:588 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:588: cat stderr"
echo calc.at:588 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:588: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  71 ) # 71. calc.at:589: Calculator %glr-parser %error-verbose
    at_setup_line='calc.at:589'
    $at_verbose "71. calc.at:589: testing Calculator %glr-parser %error-verbose..."
    $at_quiet $ECHO_N " 71: calc.at:589       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%glr-parser %error-verbose
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:589: bison -o calc.c calc.y"
echo calc.at:589 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:589: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:589 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:589: \$PREPARSER ./calc input"
echo calc.at:589 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:589: \$PREPARSER ./calc input"
echo calc.at:589 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:589: cat stderr"
echo calc.at:589 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:589: \$PREPARSER ./calc input"
echo calc.at:589 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:589: cat stderr"
echo calc.at:589 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:589: \$PREPARSER ./calc input"
echo calc.at:589 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:589: cat stderr"
echo calc.at:589 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:589: \$PREPARSER ./calc input"
echo calc.at:589 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:589: cat stderr"
echo calc.at:589 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:589: \$PREPARSER ./calc input"
echo calc.at:589 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:589: cat stderr"
echo calc.at:589 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:589: \$PREPARSER ./calc /dev/null"
echo calc.at:589 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:589: cat stderr"
echo calc.at:589 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:589: \$PREPARSER ./calc input"
echo calc.at:589 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:589: cat stderr"
echo calc.at:589 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:589: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  72 ) # 72. calc.at:591: Calculator %glr-parser %error-verbose %locations
    at_setup_line='calc.at:591'
    $at_verbose "72. calc.at:591: testing Calculator %glr-parser %error-verbose %locations..."
    $at_quiet $ECHO_N " 72: calc.at:591       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%glr-parser %error-verbose %locations
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL   , YYLTYPE *yylloc
#define YYLLOC_ARG      , yylloc
#define USE_YYLLOC      (void) yylloc;

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%d.%d-%d.%d: ",
	   LOC.first_line, LOC.first_column,
	   LOC.last_line, LOC.last_column);

  fprintf (stderr, "%s\n", s);
}



static YYLTYPE last_yylloc;

static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  last_yylloc = LOC;
  if (res == '\n')
    {
      LOC.last_line++;
      LOC.last_column = 1;
    }
  else
    LOC.last_column++;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  /* Wrong when C == `\n'. */
  LOC = last_yylloc;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

      LOC.last_column = 1;
      LOC.last_line = 1;

    }


  LOC.first_column = LOC.last_column;
  LOC.first_line = LOC.last_line;


  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

      LOC.first_column = LOC.last_column;
      LOC.first_line = LOC.last_line;

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:591: bison -o calc.c calc.y"
echo calc.at:591 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:591: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:591 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:591: \$PREPARSER ./calc input"
echo calc.at:591 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:591: \$PREPARSER ./calc input"
echo calc.at:591 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:591: cat stderr"
echo calc.at:591 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:591: \$PREPARSER ./calc input"
echo calc.at:591 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:591: cat stderr"
echo calc.at:591 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:591: \$PREPARSER ./calc input"
echo calc.at:591 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:591: cat stderr"
echo calc.at:591 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:591: \$PREPARSER ./calc input"
echo calc.at:591 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:591: cat stderr"
echo calc.at:591 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:591: \$PREPARSER ./calc input"
echo calc.at:591 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:591: cat stderr"
echo calc.at:591 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:591: \$PREPARSER ./calc /dev/null"
echo calc.at:591 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:591: cat stderr"
echo calc.at:591 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:591: \$PREPARSER ./calc input"
echo calc.at:591 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:591: cat stderr"
echo calc.at:591 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:591: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  73 ) # 73. calc.at:593: Calculator %glr-parser %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc
    at_setup_line='calc.at:593'
    $at_verbose "73. calc.at:593: testing Calculator %glr-parser %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc..."
    $at_quiet $ECHO_N " 73: calc.at:593       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%glr-parser %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL   , YYLTYPE *yylloc
#define YYLLOC_ARG      , yylloc
#define USE_YYLLOC      (void) yylloc;

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%d.%d-%d.%d: ",
	   LOC.first_line, LOC.first_column,
	   LOC.last_line, LOC.last_column);

  fprintf (stderr, "%s\n", s);
}



static YYLTYPE last_yylloc;

static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  last_yylloc = LOC;
  if (res == '\n')
    {
      LOC.last_line++;
      LOC.last_column = 1;
    }
  else
    LOC.last_column++;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  /* Wrong when C == `\n'. */
  LOC = last_yylloc;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

      LOC.last_column = 1;
      LOC.last_line = 1;

    }


  LOC.first_column = LOC.last_column;
  LOC.first_line = LOC.last_line;


  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

      LOC.first_column = LOC.last_column;
      LOC.first_line = LOC.last_line;

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:593: bison -o calc.c calc.y"
echo calc.at:593 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:593: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:593 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:593: \$PREPARSER ./calc input"
echo calc.at:593 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:593: \$PREPARSER ./calc input"
echo calc.at:593 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:593: cat stderr"
echo calc.at:593 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:593: \$PREPARSER ./calc input"
echo calc.at:593 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:593: cat stderr"
echo calc.at:593 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:593: \$PREPARSER ./calc input"
echo calc.at:593 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:593: cat stderr"
echo calc.at:593 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:593: \$PREPARSER ./calc input"
echo calc.at:593 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:593: cat stderr"
echo calc.at:593 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:593: \$PREPARSER ./calc input"
echo calc.at:593 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:593: cat stderr"
echo calc.at:593 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:593: \$PREPARSER ./calc /dev/null"
echo calc.at:593 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:593: cat stderr"
echo calc.at:593 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:593: \$PREPARSER ./calc input"
echo calc.at:593 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:593: cat stderr"
echo calc.at:593 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:593: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  74 ) # 74. calc.at:595: Calculator %glr-parser %debug
    at_setup_line='calc.at:595'
    $at_verbose "74. calc.at:595: testing Calculator %glr-parser %debug..."
    $at_quiet $ECHO_N " 74: calc.at:595       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%glr-parser %debug
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL
#define YYLLOC_ARG
#define USE_YYLLOC

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%s\n", s);
}



static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

    }



  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:595: bison -o calc.c calc.y"
echo calc.at:595 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:595: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:595 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:595: \$PREPARSER ./calc input"
echo calc.at:595 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:595: \$PREPARSER ./calc input"
echo calc.at:595 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:595: cat stderr"
echo calc.at:595 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:595: \$PREPARSER ./calc input"
echo calc.at:595 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:595: cat stderr"
echo calc.at:595 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:595: \$PREPARSER ./calc input"
echo calc.at:595 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:595: cat stderr"
echo calc.at:595 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:595: \$PREPARSER ./calc input"
echo calc.at:595 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:595: cat stderr"
echo calc.at:595 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:595: \$PREPARSER ./calc input"
echo calc.at:595 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:595: cat stderr"
echo calc.at:595 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:595: \$PREPARSER ./calc /dev/null"
echo calc.at:595 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:595: cat stderr"
echo calc.at:595 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:595: \$PREPARSER ./calc input"
echo calc.at:595 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.
sed 's/^[-0-9.]*: //' expout >at-expout
mv at-expout expout
# 4. If error-verbose is not used, strip the`, unexpected....' part.
sed 's/syntax error, .*$/syntax error/' expout >at-expout
mv at-expout expout
# 5. Check
$at_traceoff
$at_verbose "calc.at:595: cat stderr"
echo calc.at:595 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:595: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  75 ) # 75. calc.at:596: Calculator %glr-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
    at_setup_line='calc.at:596'
    $at_verbose "75. calc.at:596: testing Calculator %glr-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc..."
    $at_quiet $ECHO_N " 75: calc.at:596       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%glr-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL   , YYLTYPE *yylloc
#define YYLLOC_ARG      , yylloc
#define USE_YYLLOC      (void) yylloc;

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (

         const char *s
         )
{


  fprintf (stderr, "%d.%d-%d.%d: ",
	   LOC.first_line, LOC.first_column,
	   LOC.last_line, LOC.last_column);

  fprintf (stderr, "%s\n", s);
}



static YYLTYPE last_yylloc;

static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  last_yylloc = LOC;
  if (res == '\n')
    {
      LOC.last_line++;
      LOC.last_column = 1;
    }
  else
    LOC.last_column++;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  /* Wrong when C == `\n'. */
  LOC = last_yylloc;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

      LOC.last_column = 1;
      LOC.last_line = 1;

    }


  LOC.first_column = LOC.last_column;
  LOC.first_line = LOC.last_line;


  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

      LOC.first_column = LOC.last_column;
      LOC.first_line = LOC.last_line;

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:596: bison -o calc.c calc.y"
echo calc.at:596 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:596: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:596 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:596: \$PREPARSER ./calc input"
echo calc.at:596 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:596: \$PREPARSER ./calc input"
echo calc.at:596 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:596: cat stderr"
echo calc.at:596 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:596: \$PREPARSER ./calc input"
echo calc.at:596 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:596: cat stderr"
echo calc.at:596 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:596: \$PREPARSER ./calc input"
echo calc.at:596 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:596: cat stderr"
echo calc.at:596 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:596: \$PREPARSER ./calc input"
echo calc.at:596 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:596: cat stderr"
echo calc.at:596 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:596: \$PREPARSER ./calc input"
echo calc.at:596 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:596: cat stderr"
echo calc.at:596 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:596: \$PREPARSER ./calc /dev/null"
echo calc.at:596 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:596: cat stderr"
echo calc.at:596 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:596: \$PREPARSER ./calc input"
echo calc.at:596 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:596: cat stderr"
echo calc.at:596 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:596: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  76 ) # 76. calc.at:598: Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
    at_setup_line='calc.at:598'
    $at_verbose "76. calc.at:598: testing Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc..."
    $at_quiet $ECHO_N " 76: calc.at:598       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL   , YYLTYPE *yylloc
#define YYLLOC_ARG      , yylloc
#define USE_YYLLOC      (void) yylloc;

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (YYLTYPE *yylloc,

                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         {  }
;

line:
  '\n'
| exp '\n'           {  }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (YYLTYPE *yylloc,

         const char *s
         )
{


  fprintf (stderr, "%d.%d-%d.%d: ",
	   LOC.first_line, LOC.first_column,
	   LOC.last_line, LOC.last_column);

  fprintf (stderr, "%s\n", s);
}



static YYLTYPE last_yylloc;

static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  last_yylloc = LOC;
  if (res == '\n')
    {
      LOC.last_line++;
      LOC.last_column = 1;
    }
  else
    LOC.last_column++;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  /* Wrong when C == `\n'. */
  LOC = last_yylloc;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

      LOC.last_column = 1;
      LOC.last_line = 1;

    }


  LOC.first_column = LOC.last_column;
  LOC.first_line = LOC.last_line;


  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

      LOC.first_column = LOC.last_column;
      LOC.first_line = LOC.last_line;

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse ();
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:598: bison -o calc.c calc.y"
echo calc.at:598 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:598: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:598 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:598: \$PREPARSER ./calc input"
echo calc.at:598 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:598: \$PREPARSER ./calc input"
echo calc.at:598 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:598: cat stderr"
echo calc.at:598 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:598: \$PREPARSER ./calc input"
echo calc.at:598 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:598: cat stderr"
echo calc.at:598 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:598: \$PREPARSER ./calc input"
echo calc.at:598 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:598: cat stderr"
echo calc.at:598 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:598: \$PREPARSER ./calc input"
echo calc.at:598 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:598: cat stderr"
echo calc.at:598 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:598: \$PREPARSER ./calc input"
echo calc.at:598 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:598: cat stderr"
echo calc.at:598 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:598: \$PREPARSER ./calc /dev/null"
echo calc.at:598 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:598: cat stderr"
echo calc.at:598 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:598: \$PREPARSER ./calc input"
echo calc.at:598 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:598: cat stderr"
echo calc.at:598 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:598: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  77 ) # 77. calc.at:600: Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count}
    at_setup_line='calc.at:600'
    $at_verbose "77. calc.at:600: testing Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count}..."
    $at_quiet $ECHO_N " 77: calc.at:600       $ECHO_C"
    (
      $at_traceon









# yyerror receives the location if %location & %pure & (%glr or %parse-param).

# yyerror cannot see the locations if !glr & pure & !param.



cat >calc.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Infix notation calculator--calc */
%glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count}
%{
#include <stdio.h>

#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#endif
#include <ctype.h>

extern void perror (const char *s);

/* Exercise pre-prologue dependency to %union.  */
typedef int value;

static value global_result = 0;
static int global_count = 0;

%}

/* Exercise %union. */
%union
{
  value ival;
};

%{
#if YYPURE
#  define LOC     (*yylloc)
#  define VAL     (*yylval)
#else
#  define LOC     (yylloc)
#  define VAL     (yylval)
#endif

#define YYLLOC_FORMAL   , YYLTYPE *yylloc
#define YYLLOC_ARG      , yylloc
#define USE_YYLLOC      (void) yylloc;

#if YYPURE
#  define LEX_FORMALS     YYSTYPE *yylval YYLLOC_FORMAL
#  define LEX_ARGS        yylval          YYLLOC_ARG
#  define USE_LEX_ARGS    (void) yylval;  USE_YYLLOC
#  define LEX_PRE_FORMALS   LEX_FORMALS,
#  define LEX_PRE_ARGS      LEX_ARGS,
#else
#  define LEX_FORMALS       void
#  define LEX_PRE_FORMALS
#  define LEX_ARGS
#  define LEX_PRE_ARGS
#  define USE_LEX_ARGS
#endif

static int power (int base, int exponent);
/* yyerror receives the location if:
   - %location & %pure & %glr
   - %location & %pure & %yacc & %parse-param. */
static void yyerror (YYLTYPE *yylloc,
                     value *result, int *count,
                     const char *s
                     );
static int yylex (LEX_FORMALS);
static int yygetc (LEX_FORMALS);
static void yyungetc (LEX_PRE_FORMALS int c);
%}

/* Bison Declarations */
%token CALC_EOF 0 "end of input"
%token <ival> NUM "number"
%type  <ival> exp

%nonassoc '=' /* comparison	       */
%left '-' '+'
%left '*' '/'
%left NEG     /* negation--unary minus */
%right '^'    /* exponentiation        */

/* Grammar follows */
%%
input:
  line
| input line         { ++*count; ++global_count; }
;

line:
  '\n'
| exp '\n'           { *result = global_result = $1; }
;

exp:
  NUM                { $$ = $1;             }
| exp '=' exp
  {
    if ($1 != $3)
      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
    $$ = $1;
  }
| exp '+' exp        { $$ = $1 + $3;        }
| exp '-' exp        { $$ = $1 - $3;        }
| exp '*' exp        { $$ = $1 * $3;        }
| exp '/' exp        { $$ = $1 / $3;        }
| '-' exp  %prec NEG { $$ = -$2;            }
| exp '^' exp        { $$ = power ($1, $3); }
| '(' exp ')'        { $$ = $2;             }
| '(' error ')'      { $$ = 0;              }
;
%%
/* The input. */
static FILE *yyin;

static void
yyerror (YYLTYPE *yylloc,
         value *result, int *count,
         const char *s
         )
{
(void) result; (void) count;

  fprintf (stderr, "%d.%d-%d.%d: ",
	   LOC.first_line, LOC.first_column,
	   LOC.last_line, LOC.last_column);

  fprintf (stderr, "%s\n", s);
}



static YYLTYPE last_yylloc;

static int
yygetc (LEX_FORMALS)
{
  int res = getc (yyin);
  USE_LEX_ARGS;

  last_yylloc = LOC;
  if (res == '\n')
    {
      LOC.last_line++;
      LOC.last_column = 1;
    }
  else
    LOC.last_column++;

  return res;
}


static void
yyungetc (LEX_PRE_FORMALS int c)
{
  USE_LEX_ARGS;

  /* Wrong when C == `\n'. */
  LOC = last_yylloc;

  ungetc (c, yyin);
}

static int
read_signed_integer (LEX_FORMALS)
{
  int c = yygetc (LEX_ARGS);
  int sign = 1;
  int n = 0;

  USE_LEX_ARGS;
  if (c == '-')
    {
      c = yygetc (LEX_ARGS);
      sign = -1;
    }

  while (isdigit (c))
    {
      n = 10 * n + (c - '0');
      c = yygetc (LEX_ARGS);
    }

  yyungetc (LEX_PRE_ARGS c);

  return sign * n;
}



/*---------------------------------------------------------------.
| Lexical analyzer returns an integer on the stack and the token |
| NUM, or the ASCII character read if not a number.  Skips all   |
| blanks and tabs, returns 0 for EOF.                            |
`---------------------------------------------------------------*/

static int
yylex (LEX_FORMALS)
{
  static int init = 1;
  int c;

  if (init)
    {
      init = 0;

      LOC.last_column = 1;
      LOC.last_line = 1;

    }


  LOC.first_column = LOC.last_column;
  LOC.first_line = LOC.last_line;


  /* Skip white space.  */
  while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t')
    {

      LOC.first_column = LOC.last_column;
      LOC.first_line = LOC.last_line;

    }

  /* process numbers   */
  if (c == '.' || isdigit (c))
    {
      yyungetc (LEX_PRE_ARGS c);
      VAL.ival = read_signed_integer (LEX_ARGS);
      return NUM;
    }

  /* Return end-of-file.  */
  if (c == EOF)
    return CALC_EOF;

  /* Return single chars. */
  return c;
}

static int
power (int base, int exponent)
{
  int res = 1;
  if (exponent < 0)
    exit (1);
  for (/* Niente */; exponent; --exponent)
    res *= base;
  return res;
}

int
main (int argc, const char **argv)
{
  value result = 0;
  int count = 0;
  int status;

  if (argc == 2)
    yyin = fopen (argv[1], "r");
  else
    yyin = stdin;

  if (!yyin)
    {
      perror (argv[1]);
      exit (1);
    }

#if YYDEBUG
  yydebug = 1;
#endif
  status = yyparse (&result, &count);
  if (global_result != result)
    abort ();
  if (global_count != count)
    abort ();
  return status;
}
_ATEOF





# Specify the output files to avoid problems on different file systems.
$at_traceoff
$at_verbose "calc.at:600: bison -o calc.c calc.y"
echo calc.at:600 >$at_check_line_file
( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "calc.at:600: \$CC \$CFLAGS \$CPPFLAGS calc.c -o calc"
echo calc.at:600 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS calc.c -o calc ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Test the priorities.
cat >input <<'_ATEOF'
1 + 2 * 3 = 7
1 + 2 * -3 = -5

-1^2 = -1
(-1)^2 = 1

---1 = -1

1 - 2 - 3 = -4
1 - (2 - 3) = 2

2^2^3 = 256
(2^2)^3 = 64
_ATEOF

$at_traceoff
$at_verbose "calc.at:600: \$PREPARSER ./calc input"
echo calc.at:600 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon




# Some syntax errors.
cat >input <<'_ATEOF'
0 0
_ATEOF

$at_traceoff
$at_verbose "calc.at:600: \$PREPARSER ./calc input"
echo calc.at:600 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected "number"
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:600: cat stderr"
echo calc.at:600 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1//2
_ATEOF

$at_traceoff
$at_verbose "calc.at:600: \$PREPARSER ./calc input"
echo calc.at:600 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.3-1.4: syntax error, unexpected '/', expecting "number" or '-' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:600: cat stderr"
echo calc.at:600 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
error
_ATEOF

$at_traceoff
$at_verbose "calc.at:600: \$PREPARSER ./calc input"
echo calc.at:600 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected $undefined, expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:600: cat stderr"
echo calc.at:600 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'
1 = 2 = 3
_ATEOF

$at_traceoff
$at_verbose "calc.at:600: \$PREPARSER ./calc input"
echo calc.at:600 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.7-1.8: syntax error, unexpected '='
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:600: cat stderr"
echo calc.at:600 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


cat >input <<'_ATEOF'

+1
_ATEOF

$at_traceoff
$at_verbose "calc.at:600: \$PREPARSER ./calc input"
echo calc.at:600 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
2.1-2.2: syntax error, unexpected '+'
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:600: cat stderr"
echo calc.at:600 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Exercise error messages with EOF: work on an empty file.
$at_traceoff
$at_verbose "calc.at:600: \$PREPARSER ./calc /dev/null"
echo calc.at:600 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.1-1.2: syntax error, unexpected "end of input", expecting "number" or '-' or '\n' or '('
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:600: cat stderr"
echo calc.at:600 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Exercise the error token: without it, we die at the first error,
# hence be sure i. to have several errors, ii. to test the action
# associated to `error'.
cat >input <<'_ATEOF'
(1 ++ 2) + (0 0) = 1
_ATEOF

$at_traceoff
$at_verbose "calc.at:600: \$PREPARSER ./calc input"
echo calc.at:600 >$at_check_line_file
( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; tee stderr <$at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Normalize the observed and expected error messages, depending upon the
# options.
# 1. Remove the traces from observed.
sed '/^Starting/d
/^Entering/d
/^Stack/d
/^Reading/d
/^Reducing/d
/^Shifting/d
/^state/d
/^Error:/d
/^Next/d
/^Discarding/d
/^yydestructor:/d' stderr >at-stderr
mv at-stderr stderr
# 2. Create the reference error message.
cat >expout <<'_ATEOF'
1.5-1.6: syntax error, unexpected '+', expecting "number" or '-' or '('
1.15-1.16: syntax error, unexpected "number"
calc: error: 0 != 1
_ATEOF

# 3. If locations are not used, remove them.

# 4. If error-verbose is not used, strip the`, unexpected....' part.

# 5. Check
$at_traceoff
$at_verbose "calc.at:600: cat stderr"
echo calc.at:600 >$at_check_line_file
( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff expout $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "calc.at:600: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon












    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-11 ) # Banner 11. torture.at:19
    cat <<\_ATEOF

Torture Tests.

_ATEOF
    ;;

  78 ) # 78. torture.at:140: Big triangle
    at_setup_line='torture.at:140'
    $at_verbose "78. torture.at:140: testing Big triangle..."
    $at_quiet $ECHO_N " 78: torture.at:140    $ECHO_C"
    (
      $at_traceon


# I have been able to go up to 2000 on my machine.
# I tried 3000, a 29Mb grammar file, but then my system killed bison.
# With 500 and the new parser, which consume far too much memory,
# it gets killed too.  Of course the parser is to be cleaned.
cat >gengram.pl <<'_ATEOF'
#! /usr/bin/perl -w

use strict;
my $max = $ARGV[0] || 10;

print <<EOF;
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

%{
#include <stdio.h>
#include <stdlib.h>

#define YYERROR_VERBOSE 1
#define YYDEBUG 1

static int yylex (void);
static void yyerror (const char *msg);
%}
%union
{
  int val;
};

%token END "end"
%type <val> exp input
EOF

for my $size (1 .. $max)
  {
    print "%token t$size $size \"$size\"\n";
  };

print <<EOF;
%%
input:
  exp        { if (\$1 != 0) abort (); \$\$ = \$1; }
| input exp  { if (\$2 != \$1 + 1) abort (); \$\$ = \$2; }
;

exp:
  END
    { \$\$ = 0; }
EOF

for my $size (1 .. $max)
  {
    use Text::Wrap;
    print wrap ("| ", "   ",
		(map { "\"$_\"" } (1 .. $size)),
		" END \n"),
		  "    { \$\$ = $size; }\n";
  };
print ";\n";

print <<EOF;
%%
static int
yylex (void)
{
  static int inner = 1;
  static int outer = 0;
  if (outer > $max)
    return 0;
  else if (inner > outer)
    {
      inner = 1;
      ++outer;
      return END;
    }
  return inner++;
}

static void
yyerror (const char *msg)
{
  fprintf (stderr, "%s\\n", msg);
}

int
main (void)
{
  yydebug = !!getenv ("YYDEBUG");
  return yyparse ();
}
EOF
_ATEOF


$at_traceoff
$at_verbose "torture.at:146: perl -w ./gengram.pl 200 || exit 77"
echo torture.at:146 >$at_check_line_file
( $at_traceon; perl -w ./gengram.pl 200 || exit 77 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:146: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

mv stdout input.y

$at_traceoff
$at_verbose "torture.at:147: bison -v -o input.c input.y"
echo torture.at:147 >$at_check_line_file
( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:147: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "torture.at:148: \$CC \$CFLAGS \$CPPFLAGS input.c -o input"
echo torture.at:148 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS input.c -o input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:148: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "torture.at:149: \$PREPARSER ./input"
echo torture.at:149 >$at_check_line_file
( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:149: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  79 ) # 79. torture.at:231: Big horizontal
    at_setup_line='torture.at:231'
    $at_verbose "79. torture.at:231: testing Big horizontal..."
    $at_quiet $ECHO_N " 79: torture.at:231    $ECHO_C"
    (
      $at_traceon


# I have been able to go up to 10000 on my machine, but I had to
# increase the maximum stack size (* 100).  It gave:
#
# input.y      263k
# input.tab.c  1.3M
# input        453k
#
# gengram.pl 10000                 0.70s user 0.01s sys  99% cpu    0.711 total
# bison input.y                  730.56s user 0.53s sys  99% cpu 12:12.34 total
# gcc -Wall input.tab.c -o input   5.81s user 0.20s sys 100% cpu     6.01 total
# ./input                          0.00s user 0.01s sys 108% cpu     0.01 total
#
cat >gengram.pl <<'_ATEOF'
#! /usr/bin/perl -w

use strict;
my $max = $ARGV[0] || 10;

print <<EOF;
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

%{
#include <stdio.h>
#include <stdlib.h>

#define YYERROR_VERBOSE 1
#define YYDEBUG 1

static int yylex (void);
static void yyerror (const char *msg);
%}
EOF

for my $size (1 .. $max)
  {
    print "%token t$size $size \"$size\"\n";
  };

print <<EOF;
%%
EOF

use Text::Wrap;
print
  wrap ("exp: ", "  ",
	(map { "\"$_\"" } (1 .. $max)), ";"),
  "\n";

print <<EOF;
%%
static int
yylex (void)
{
  static int counter = 1;
  if (counter > $max)
    return 0;
  else
  return counter++;
}

static void
yyerror (const char *msg)
{
  fprintf (stderr, "%s\\n", msg);
}

int
main (void)
{
  yydebug = !!getenv ("YYDEBUG");
  return yyparse ();
}
EOF
_ATEOF


$at_traceoff
$at_verbose "torture.at:245: perl -w ./gengram.pl 1000 || exit 77"
echo torture.at:245 >$at_check_line_file
( $at_traceon; perl -w ./gengram.pl 1000 || exit 77 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:245: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

mv stdout input.y


# 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.
data_limit=`(ulimit -S -d) 2>/dev/null`
case $data_limit in
[0-9]*)
  if test "$data_limit" -lt 204000; then
    ulimit -S -d 204000
  fi
esac

$at_traceoff
$at_verbose "torture.at:251: bison -v -o input.c input.y"
echo torture.at:251 >$at_check_line_file
( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:251: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "torture.at:252: \$CC \$CFLAGS \$CPPFLAGS input.c -o input"
echo torture.at:252 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS input.c -o input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:252: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "torture.at:253: \$PREPARSER ./input"
echo torture.at:253 >$at_check_line_file
( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:253: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  80 ) # 80. torture.at:366: Many lookaheads
    at_setup_line='torture.at:366'
    $at_verbose "80. torture.at:366: testing Many lookaheads..."
    $at_quiet $ECHO_N " 80: torture.at:366    $ECHO_C"
    (
      $at_traceon


cat >gengram.pl <<'_ATEOF'
#! /usr/bin/perl -w

use strict;
use Text::Wrap;
my $max = $ARGV[0] || 10;

print <<EOF;
%{
#include <stdio.h>
#include <stdlib.h>

#define YYERROR_VERBOSE 1
#define YYDEBUG 1

static int yylex (void);
static void yyerror (const char *msg);
%}
%union
{
  int val;
};

%type <val> input exp
%token token
EOF

print
  wrap ("%type <val> ",
	"            ",
	map { "n$_" } (1 .. $max)),
  "\n";

for my $count (1 .. $max)
  {
    print "%token t$count $count \"$count\"\n";
  };

print <<EOF;
%%
input:
  exp        { if (\$1 != 1) abort (); \$\$ = \$1; }
| input exp  { if (\$2 != \$1 + 1) abort (); \$\$ = \$2; }
;

exp:
  n1 "1" { if (\$1 != 1) abort (); }
EOF

for my $count (2 .. $max)
  {
    print "| n$count \"$count\" { if (\$1 != $count) abort (); }\n";
  };
print ";\n";

for my $count (1 .. $max)
  {
    print "n$count: token { \$\$ = $count; };\n";
  };

print <<EOF;
%%
static int
yylex (void)
{
  static int return_token = 1;
  static int counter = 1;
  if (counter > $max)
    return 0;
  if (return_token)
    {
      return_token = 0;
      return token;
    }
  return_token = 1;
  return counter++;
}

static void
yyerror (const char *msg)
{
  fprintf (stderr, "%s\\n", msg);
}

int
main (void)
{
  yydebug = !!getenv ("YYDEBUG");
  return yyparse ();
}
EOF
_ATEOF


$at_traceoff
$at_verbose "torture.at:368: perl -w ./gengram.pl 1000 || exit 77"
echo torture.at:368 >$at_check_line_file
( $at_traceon; perl -w ./gengram.pl 1000 || exit 77 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; tee stdout <$at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:368: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

mv stdout input.y


# 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.
data_limit=`(ulimit -S -d) 2>/dev/null`
case $data_limit in
[0-9]*)
  if test "$data_limit" -lt 204000; then
    ulimit -S -d 204000
  fi
esac

$at_traceoff
$at_verbose "torture.at:374: bison -v -o input.c input.y"
echo torture.at:374 >$at_check_line_file
( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:374: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "torture.at:375: \$CC \$CFLAGS \$CPPFLAGS input.c -o input"
echo torture.at:375 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS input.c -o input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:375: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "torture.at:376: \$PREPARSER ./input"
echo torture.at:376 >$at_check_line_file
( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:376: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  81 ) # 81. torture.at:440: Exploding the Stack Size with Alloca
    at_setup_line='torture.at:440'
    $at_verbose "81. torture.at:440: testing Exploding the Stack Size with Alloca..."
    $at_quiet $ECHO_N " 81: torture.at:440    $ECHO_C"
    (
      $at_traceon


# A grammar of parens growing the stack thanks to right recursion.
# exp:
cat >input.y <<'_ATEOF'
%{
#include <stdio.h>
#include <stdlib.h>

  static int yylex (void);
  static void yyerror (const char *msg);
%}
%error-verbose
%debug
%token WAIT_FOR_EOF
%%
exp: WAIT_FOR_EOF exp | ;
%%
static void
yyerror (const char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

/* There are YYLVAL_MAX of WAIT_FOR_EOFs. */
unsigned int yylval_max;

static int
yylex (void)
{
  if (yylval--)
    return WAIT_FOR_EOF;
  else
    return EOF;
}

int
main (int argc, const char **argv)
{
  if (argc != 2)
    abort ();
  yylval = atoi (argv[1]);
  yydebug = 1;
  return yyparse ();
}
_ATEOF

$at_traceoff
$at_verbose "torture.at:442: bison -o input.c input.y"
echo torture.at:442 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:442: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "torture.at:442: \$CC \$CFLAGS \$CPPFLAGS input.c -o input"
echo torture.at:442 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS input.c -o input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:442: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Below the limit of 200.
$at_traceoff
$at_verbose "torture.at:445: \$PREPARSER ./input 20"
echo torture.at:445 >$at_check_line_file
( $at_traceon; $PREPARSER ./input 20 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:445: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

# Two enlargements: 2 * 2 * 200.
$at_traceoff
$at_verbose "torture.at:447: \$PREPARSER ./input 900"
echo torture.at:447 >$at_check_line_file
( $at_traceon; $PREPARSER ./input 900 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:447: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

# Fails: beyond the limit of 10,000 (which we don't reach anyway since we
# multiply by two starting at 200 => 5120 is the last possible).
$at_traceoff
$at_verbose "torture.at:450: \$PREPARSER ./input 10000"
echo torture.at:450 >$at_check_line_file
( $at_traceon; $PREPARSER ./input 10000 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "torture.at:450: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  82 ) # 82. torture.at:461: Exploding the Stack Size with Malloc
    at_setup_line='torture.at:461'
    $at_verbose "82. torture.at:461: testing Exploding the Stack Size with Malloc..."
    $at_quiet $ECHO_N " 82: torture.at:461    $ECHO_C"
    (
      $at_traceon


# A grammar of parens growing the stack thanks to right recursion.
# exp:
cat >input.y <<'_ATEOF'
%{
#include <stdio.h>
#include <stdlib.h>
#define YYSTACK_USE_ALLOCA 0
  static int yylex (void);
  static void yyerror (const char *msg);
%}
%error-verbose
%debug
%token WAIT_FOR_EOF
%%
exp: WAIT_FOR_EOF exp | ;
%%
static void
yyerror (const char *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (1);
}

/* There are YYLVAL_MAX of WAIT_FOR_EOFs. */
unsigned int yylval_max;

static int
yylex (void)
{
  if (yylval--)
    return WAIT_FOR_EOF;
  else
    return EOF;
}

int
main (int argc, const char **argv)
{
  if (argc != 2)
    abort ();
  yylval = atoi (argv[1]);
  yydebug = 1;
  return yyparse ();
}
_ATEOF

$at_traceoff
$at_verbose "torture.at:463: bison -o input.c input.y"
echo torture.at:463 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:463: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "torture.at:463: \$CC \$CFLAGS \$CPPFLAGS input.c -o input"
echo torture.at:463 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS input.c -o input ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:463: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon



# Below the limit of 200.
$at_traceoff
$at_verbose "torture.at:466: \$PREPARSER ./input 20"
echo torture.at:466 >$at_check_line_file
( $at_traceon; $PREPARSER ./input 20 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:466: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

# Two enlargements: 2 * 2 * 200.
$at_traceoff
$at_verbose "torture.at:468: \$PREPARSER ./input 900"
echo torture.at:468 >$at_check_line_file
( $at_traceon; $PREPARSER ./input 900 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "torture.at:468: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

# Fails: beyond the limit of 10,000 (which we don't reach anyway since we
# multiply by two starting at 200 => 5120 is the possible).
$at_traceoff
$at_verbose "torture.at:471: \$PREPARSER ./input 10000"
echo torture.at:471 >$at_check_line_file
( $at_traceon; $PREPARSER ./input 10000 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "torture.at:471: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-12 ) # Banner 12. existing.at:19
    cat <<\_ATEOF

Existing Grammars.

_ATEOF
    ;;

  83 ) # 83. existing.at:24: GNU AWK Grammar
    at_setup_line='existing.at:24'
    $at_verbose "83. existing.at:24: testing GNU AWK Grammar..."
    $at_quiet $ECHO_N " 83: existing.at:24    $ECHO_C"
    (
      $at_traceon


# We have been careful to strip all the actions excepts the
# mid-rule actions.  We rely on %expect to check that there are
# indeed 65 SR conflicts.
#
# Bison was once wrong, due to an incorrect computation of nullable.
# It reported 485 SR conflicts!

cat >input.y <<'_ATEOF'
%expect 65

%token FUNC_CALL NAME REGEXP
%token ERROR
%token YNUMBER YSTRING
%token RELOP APPEND_OP
%token ASSIGNOP MATCHOP NEWLINE CONCAT_OP
%token LEX_BEGIN LEX_END LEX_IF LEX_ELSE LEX_RETURN LEX_DELETE
%token LEX_WHILE LEX_DO LEX_FOR LEX_BREAK LEX_CONTINUE
%token LEX_PRINT LEX_PRINTF LEX_NEXT LEX_EXIT LEX_FUNCTION
%token LEX_GETLINE LEX_NEXTFILE
%token LEX_IN
%token LEX_AND LEX_OR INCREMENT DECREMENT
%token LEX_BUILTIN LEX_LENGTH

/* Lowest to highest */
%right ASSIGNOP
%right '?' ':'
%left LEX_OR
%left LEX_AND
%left LEX_GETLINE
%nonassoc LEX_IN
%left FUNC_CALL LEX_BUILTIN LEX_LENGTH
%nonassoc ','
%nonassoc MATCHOP
%nonassoc RELOP '<' '>' '|' APPEND_OP TWOWAYIO
%left CONCAT_OP
%left YSTRING YNUMBER
%left '+' '-'
%left '*' '/' '%'
%right '!' UNARY
%right '^'
%left INCREMENT DECREMENT
%left '$'
%left '(' ')'
%%

start
	: opt_nls program opt_nls
	;

program
	: rule
	| program rule
	| error
	| program error
	| /* empty */
	;

rule
	: LEX_BEGIN {} action
	| LEX_END {}   action
	| LEX_BEGIN statement_term
	| LEX_END statement_term
	| pattern action
	| action
	| pattern statement_term
	| function_prologue function_body
	;

func_name
	: NAME
	| FUNC_CALL
	| lex_builtin
	;

lex_builtin
	: LEX_BUILTIN
	| LEX_LENGTH
	;

function_prologue
	: LEX_FUNCTION {} func_name '(' opt_param_list r_paren opt_nls
	;

function_body
	: l_brace statements r_brace opt_semi opt_nls
	| l_brace r_brace opt_semi opt_nls
	;


pattern
	: exp
	| exp ',' exp
	;

regexp
	/*
	 * In this rule, want_regexp tells yylex that the next thing
	 * is a regexp so it should read up to the closing slash.
	 */
	: '/' {} REGEXP '/'
	;

action
	: l_brace statements r_brace opt_semi opt_nls
	| l_brace r_brace opt_semi opt_nls
	;

statements
	: statement
	| statements statement
	| error
	| statements error
	;

statement_term
	: nls
	| semi opt_nls
	;

statement
	: semi opt_nls
	| l_brace r_brace
	| l_brace statements r_brace
	| if_statement
	| LEX_WHILE '(' exp r_paren opt_nls statement
	| LEX_DO opt_nls statement LEX_WHILE '(' exp r_paren opt_nls
	| LEX_FOR '(' NAME LEX_IN NAME r_paren opt_nls statement
	| LEX_FOR '(' opt_exp semi opt_nls exp semi opt_nls opt_exp r_paren opt_nls statement
	| LEX_FOR '(' opt_exp semi opt_nls semi opt_nls opt_exp r_paren opt_nls statement
	| LEX_BREAK statement_term
	| LEX_CONTINUE statement_term
	| print '(' expression_list r_paren output_redir statement_term
	| print opt_rexpression_list output_redir statement_term
	| LEX_NEXT statement_term
	| LEX_NEXTFILE statement_term
	| LEX_EXIT opt_exp statement_term
	| LEX_RETURN {} opt_exp statement_term
	| LEX_DELETE NAME '[' expression_list ']' statement_term
	| LEX_DELETE NAME  statement_term
	| exp statement_term
	;

print
	: LEX_PRINT
	| LEX_PRINTF
	;

if_statement
	: LEX_IF '(' exp r_paren opt_nls statement
	| LEX_IF '(' exp r_paren opt_nls statement
	     LEX_ELSE opt_nls statement
	;

nls
	: NEWLINE
	| nls NEWLINE
	;

opt_nls
	: /* empty */
	| nls
	;

input_redir
	: /* empty */
	| '<' simp_exp
	;

output_redir
	: /* empty */
	| '>' exp
	| APPEND_OP exp
	| '|' exp
	| TWOWAYIO exp
	;

opt_param_list
	: /* empty */
	| param_list
	;

param_list
	: NAME
	| param_list comma NAME
	| error
	| param_list error
	| param_list comma error
	;

/* optional expression, as in for loop */
opt_exp
	: /* empty */
	| exp
	;

opt_rexpression_list
	: /* empty */
	| rexpression_list
	;

rexpression_list
	: rexp
	| rexpression_list comma rexp
	| error
	| rexpression_list error
	| rexpression_list error rexp
	| rexpression_list comma error
	;

opt_expression_list
	: /* empty */
	| expression_list
	;

expression_list
	: exp
	| expression_list comma exp
	| error
	| expression_list error
	| expression_list error exp
	| expression_list comma error
	;

/* Expressions, not including the comma operator.  */
exp	: variable ASSIGNOP {} exp
	| '(' expression_list r_paren LEX_IN NAME
	| exp '|' LEX_GETLINE opt_variable
	| exp TWOWAYIO LEX_GETLINE opt_variable
	| LEX_GETLINE opt_variable input_redir
	| exp LEX_AND exp
	| exp LEX_OR exp
	| exp MATCHOP exp
	| regexp
	| '!' regexp %prec UNARY
	| exp LEX_IN NAME
	| exp RELOP exp
	| exp '<' exp
	| exp '>' exp
	| exp '?' exp ':' exp
	| simp_exp
	| exp simp_exp %prec CONCAT_OP
	;

rexp
	: variable ASSIGNOP {} rexp
	| rexp LEX_AND rexp
	| rexp LEX_OR rexp
	| LEX_GETLINE opt_variable input_redir
	| regexp
	| '!' regexp %prec UNARY
	| rexp MATCHOP rexp
	| rexp LEX_IN NAME
	| rexp RELOP rexp
	| rexp '?' rexp ':' rexp
	| simp_exp
	| rexp simp_exp %prec CONCAT_OP
	;

simp_exp
	: non_post_simp_exp
	/* Binary operators in order of decreasing precedence.  */
	| simp_exp '^' simp_exp
	| simp_exp '*' simp_exp
	| simp_exp '/' simp_exp
	| simp_exp '%' simp_exp
	| simp_exp '+' simp_exp
	| simp_exp '-' simp_exp
	| variable INCREMENT
	| variable DECREMENT
	;

non_post_simp_exp
	: '!' simp_exp %prec UNARY
	| '(' exp r_paren
	| LEX_BUILTIN
	  '(' opt_expression_list r_paren
	| LEX_LENGTH '(' opt_expression_list r_paren
	| LEX_LENGTH
	| FUNC_CALL '(' opt_expression_list r_paren
	| variable
	| INCREMENT variable
	| DECREMENT variable
	| YNUMBER
	| YSTRING
	| '-' simp_exp    %prec UNARY
	| '+' simp_exp    %prec UNARY
	;

opt_variable
	: /* empty */
	| variable
	;

variable
	: NAME
	| NAME '[' expression_list ']'
	| '$' non_post_simp_exp
	;

l_brace
	: '{' opt_nls
	;

r_brace
	: '}' opt_nls
	;

r_paren
	: ')'
	;

opt_semi
	: /* empty */
	| semi
	;

semi
	: ';'
	;

comma	: ',' opt_nls
	;

%%
_ATEOF


# Pass plenty of options, to exercise plenty of code, even if we
# don't actually check the output.  But SEGV is watching us, and
# so might do dmalloc.
$at_traceoff
$at_verbose "existing.at:355: bison --verbose --defines input.y"
echo existing.at:355 >$at_check_line_file
( $at_traceon; bison --verbose --defines input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "existing.at:355: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  84 ) # 84. existing.at:364: GNU Cim Grammar
    at_setup_line='existing.at:364'
    $at_verbose "84. existing.at:364: testing GNU Cim Grammar..."
    $at_quiet $ECHO_N " 84: existing.at:364   $ECHO_C"
    (
      $at_traceon


# GNU Cim, the GNU Simula 87 Compiler.

# Bison was once wrong, due to an incorrect computation of the RR conflicts.
# It reported 80 SR && 99 RR conflicts instead of 78/10!!!

cat >input.y <<'_ATEOF'
%union {
	long token;
	long ival;
        long arrdim;
	double rval;
	char *ident;
	char *tval;
	char stat_decl;
       }

%token
        HACTIVATE HAFTER /*HAND*/ HARRAY HAT
        HBEFORE HBEGIN HBOOLEAN
        HCHARACTER HCLASS /*HCOMMENT*/ HCONC
        HDELAY HDO
        HELSE HEND HEQ /*HEQV*/ HEXTERNAL
        HFOR
        HGE HGO HGOTO HGT
        HHIDDEN
        HIF /*HIMP*/ HIN HINNER HINSPECT HINTEGER HIS
        HLABEL HLE HLONG HLT
        HNAME HNE HNEW HNONE /*HNOT*/ HNOTEXT
        /*HOR*/ HOTHERWISE
        HPRIOR HPROCEDURE HPROTECTED
        HQUA
        HREACTIVATE HREAL HREF
        HSHORT HSTEP HSWITCH
        HTEXT HTHEN HTHIS HTO
        HUNTIL
        HVALUE HVAR HVIRTUAL
        HWHEN HWHILE

        HASSIGNVALUE HASSIGNREF
        /*HDOT*/ HPAREXPSEPARATOR HLABELSEPARATOR HSTATEMENTSEPARATOR
        HBEGPAR HENDPAR
        HEQR HNER
        HADD HSUB HMUL HDIV HINTDIV HEXP
  	HDOTDOTDOT

%token <ident> HIDENTIFIER
%token <ival> HBOOLEANKONST HINTEGERKONST HCHARACTERKONST
%token <rval> HREALKONST
%token <tval> HTEXTKONST

%type <tval> EXT_IDENT
%type <stat_decl> DECLSTATEMENT MODULSTATEMENT MBEE_DECLSTMS MBEE_DECLSTMSU
%type <stat_decl> MODULS
%type <ident> EXPRESSION_SIMP MBEE_ARG_R_PT
%type <arrdim> BAUND_PAIR_LIST

%right <token> HASSIGN
%left   HORELSE
%left   HANDTHEN
%left   HEQV
%left   HIMP
%left   HOR
%left   HAND

%left   HNOT

%left <token> HVALRELOPERATOR HREFRELOPERATOR HOBJRELOPERATOR

%left	HCONC

%left <token> HTERMOPERATOR
%left <token> UNEAR
%left <token> HFACTOROPERATOR
%left         HPRIMARYOPERATOR

%left   HQUA

%left   HDOT

%start  MAIN_MODULE
%%
/* GRAMATIKK FOR PROGRAM MODULES */
MAIN_MODULE     :       {	  categ=CLOCAL; mout(MBLOCK);
                                  beginBlock(KBLOKK);separat_comp=FALSE;}
			MODULS	{ endBlock(NULL,CCNO);   mout(MENDBLOCK);}
  		|	error HSTATEMENTSEPARATOR MBEE_DECLSTMS
		;
EXT_DECLARATION	:	HEXTERNAL
			MBEE_TYPE
			HPROCEDURE
				{ MBEENEWBLOCK();
				  kind=KPROC;}
			EXT_LIST
		|
			HEXTERNAL
			HIDENTIFIER
			HPROCEDURE
				{ MBEENEWBLOCK();
				  type=TNOTY;
				  kind=KPROC;
				  if($2==Ckind)categ=CCPROC;else
				  yerror (1);
                                  ysensitive=sensitive;
                                  sensitive=ON;}
			HIDENTIFIER { $<ident>$=$5;
                                  sensitive=ysensitive;}
			EXTERNAL_KIND_ITEM
			        { categ=CLOCAL;}
		|	HEXTERNAL
			HCLASS
				{ MBEENEWBLOCK();
				  kind=KCLASS;}
			EXT_LIST

		;
EXTERNAL_KIND_ITEM:	EXT_IDENT
			HOBJRELOPERATOR
				{ if($2!=HIS)yerror (2);}
		        MBEE_TYPE HPROCEDURE
			HIDENTIFIER
				{         regDecl($6, type, KPROC, CCPROC);
                                          beginBlock(kind);}
                        HEADING EMPTY_BLOCK
				{ categ=CLOCAL;
				  endBlock($1==NULL?$<ident>0:tag($1),CCCPROC);}
/*		|
			EXT_IDENT
				{ if($1!=NULL)yerror (3);
				  regDecl($0, type, kind, categ);}
			MBEE_REST_EXT_LIST
				{ endBlock(NULL,CCNO);}
		;
MBEE_REST_EXT_LIST:	/* EMPTY
		|	HPAREXPSEPARATOR EXT_KIND_LIST
		;
EXT_KIND_LIST	:	EXT_KIND_ITEM
		|	EXT_KIND_LIST HPAREXPSEPARATOR EXT_KIND_ITEM
		;
EXT_KIND_ITEM	:	HIDENTIFIER
			EXT_IDENT
				{ if($2!=NULL)yerror (3);
				  regDecl($1, type, kind, categ);}*/
		;
EMPTY_BLOCK	:	/*EMPT*/
		|	HBEGIN HEND
		;
EXT_LIST	:	EXT_ITEM
		|	EXT_LIST HPAREXPSEPARATOR EXT_ITEM
		;
EXT_ITEM	:	HIDENTIFIER
			EXT_IDENT
				{ lesinn_external_spec($1,$2, kind);}
		;
EXT_IDENT	:	/* EMPTY */ { $$=NULL;}
		|	HVALRELOPERATOR { if($1!=HEQ)yerror (9);
                                          external=TRUE;}
			HTEXTKONST { $$=$3;external=FALSE;}
		;
/* GRAMATIKK FOR TYPER */
NO_TYPE         :       /*EMPT*/        { type=TNOTY;}
                ;
MBEE_TYPE       :       NO_TYPE
                |       TYPE
                ;
TYPE            :       HREF HBEGPAR
                        HIDENTIFIER
                                { prefquantident=$3;
                                          type=TREF;}
                        HENDPAR
                |       HTEXT           { type=TTEXT;}
                |       HBOOLEAN        { type=TBOOL;}
                |       HCHARACTER      { type=TCHAR;}
                |       HSHORT HINTEGER { type=TSHORT;}
                |       HINTEGER        { type=TINTG;}
                |       HREAL           { type=TREAL;}
                |       HLONG HREAL     { type=TLONG;}
                ;

/* GRAMATIKK FOR DEL AV SETNINGER */
MBEE_ELSE_PART  :       /*EMPT*/
/*		|	HELSE
			HIF
                        EXPRESSION
                        HTHEN   { 		  mout(MELSE);
						  mout(MIF);
                                  OBSBLOCK();}
                        BLOCK   { MBEEENDBLOCK();}
                        MBEE_ELSE_PART          { mout(MENDIF);}*/
                |       HELSE   { OBSBLOCK();     mout(MELSE);}
                        BLOCK   { MBEEENDBLOCK();}
                ;
FOR_LIST        :       FOR_LIST_ELEMENT        { mout(MENDSEP);
                                                  mout(MLISTSEP);}
                |       FOR_LIST_ELEMENT
                        HPAREXPSEPARATOR
                        FOR_LIST                { mout(MLISTSEP);}
                ;
FOR_LIST_ELEMENT:       EXPRESSION
                        MBEE_F_L_EL_R_PT
                ;
MBEE_F_L_EL_R_PT:       /*EMPT*/
                |       HWHILE
                        EXPRESSION              { mout(MFORWHILE);}
                |       HSTEP
                        EXPRESSION
                        HUNTIL
                        EXPRESSION              { mout(MUNTIL);
                                                  mout(MSTEP);}
                ;
GOTO            :       HGO
                        HTO
                |       HGOTO
                ;
CONN_STATE_R_PT :       WHEN_CLAUSE_LIST
                |       HDO   {   beginBlock(KCON);   mout(MDO);
                              OBSBLOCK(); }
                        BLOCK {   endBlock(NULL,CCNO);
                                  MBEEENDBLOCK();  mout(MENDDO);}
                ;
WHEN_CLAUSE_LIST:       HWHEN
                        HIDENTIFIER
                        HDO    {   beginBlock(KCON);  mout(MIDENTIFIER);
                                   OBSBLOCK();     moutId($2);
				   		   mout(MWHEN);}
                        BLOCK  {   endBlock(NULL,CCNO);
                              MBEEENDBLOCK(); mout(MENDWHEN);}
                |       WHEN_CLAUSE_LIST
                        HWHEN
                        HIDENTIFIER
                        HDO    { beginBlock(KCON);	   mout(MIDENTIFIER);
                                 OBSBLOCK();       moutId($3);
				 		   mout(MWHEN);}
                        BLOCK  { endBlock(NULL,CCNO);
                              MBEEENDBLOCK();    mout(MENDWHEN);}
                ;
MBEE_OTWI_CLAUS :       /*EMPT*/
                |       HOTHERWISE {OBSBLOCK();    mout(MOTHERWISE);}

                        BLOCK      {MBEEENDBLOCK();mout(MENDOTHERWISE);}
                ;
ACTIVATOR	:	HACTIVATE		{ mout(MBOOLEANKONST);
						  moutIval(FALSE);}
		|	HREACTIVATE		{ mout(MBOOLEANKONST);
						  moutIval(TRUE);}
		;
SCHEDULE	:	/*EMPT*/		{ mout(MCHARACTERKONST);
						  moutIval(DIRECT);
						  mout(MINTEGERKONST);
						  moutIval(0);
						  mout(MNONE);
						  mout(MBOOLEANKONST);
						  moutIval(FALSE);}
		|	ATDELAY EXPRESSION	{ mout(MNONE);}
			PRIOR
		|	BEFOREAFTER		{ mout(MINTEGERKONST);
						  moutIval(0);}
			EXPRESSION		{ mout(MBOOLEANKONST);
						  moutIval(FALSE);}
		;
ATDELAY		:	HAT			{ mout(MCHARACTERKONST);
						  moutIval(AT);}
		|	HDELAY			{ mout(MCHARACTERKONST);
						  moutIval(DELAYS);}
		;
BEFOREAFTER	:	HBEFORE			{ mout(MCHARACTERKONST);
						  moutIval(BEFORE);}
		|	HAFTER			{ mout(MCHARACTERKONST);
						  moutIval(AFTER);}
		;
PRIOR		:	/*EMPT*/		{ mout(MBOOLEANKONST);
						  moutIval(FALSE);}
		|	HPRIOR			{ mout(MBOOLEANKONST);
						  moutIval(TRUE);}
		;
/* GRAMATIKK FOR SETNINGER OG DEKLARASJONER */
MODULSTATEMENT  :       HWHILE
                        EXPRESSION
                        HDO     { STOPOBSBLOCK(); mout(MWHILE);
                                  OBSBLOCK();}
                        BLOCK   { MBEEENDBLOCK(); mout(MENDWHILE);
					  	          $$=STATEMENT;}
	    	|       HIF
                        EXPRESSION
                        HTHEN   { STOPOBSBLOCK(); mout(MIF);
                                  OBSBLOCK();}
                        BLOCK   { MBEEENDBLOCK();}
                        MBEE_ELSE_PART          { mout(MENDIF);
							  $$=STATEMENT;}
		|       HFOR
                        HIDENTIFIER
                        HASSIGN { STOPOBSBLOCK(); mout(MIDENTIFIER);
                                                  moutId($2);}
                        FOR_LIST
                        HDO     { beginBlock(KFOR);
                        if($3==HASSIGNVALUE)      mout(MFOR);
                                        else      mout(MFORR);
                                  OBSBLOCK();     mout(MFORDO);}
                        BLOCK   { MBEEENDBLOCK();
                                  endBlock(NULL,CCNO); mout(MENDFOR);
							  $$=STATEMENT;}
		|       GOTO
                        EXPRESSION              { mout(MGOTO);
                                  STOPOBSBLOCK();	  $$=STATEMENT;}
		|       HINSPECT
                        EXPRESSION              { mout(MINSPECT);
                                  STOPOBSBLOCK();
                                  beginBlock(KINSP);}
                        CONN_STATE_R_PT
                                { endBlock(NULL,CCNO);}
                        MBEE_OTWI_CLAUS         { mout(MENDINSPECT);
							  $$=STATEMENT;}
		|       HINNER  { STOPOBSBLOCK(); mout(MINNER);
                                  regInner();		  $$=STATEMENT;}
                |       HIDENTIFIER
                        HLABELSEPARATOR
                                { STOPOBSBLOCK();
                                  regDecl($1, TLABEL, KSIMPLE, categ);    mout(MLABEL);
                                                  moutId($1);
                                                  mout(MENDLABEL);}
                        DECLSTATEMENT   { if($4<=DECLARATION)
                                            { yerror (27);
                                              $$=DECLARATION;}
                                          else $$=$4;}
                |       EXPRESSION_SIMP
                        HBEGIN
                                { $<ident>$=$1; }
			IMPORT_SPEC_MODULE
				{ mout(MPRBLOCK);
				  prefquantident=$1;
                                  beginBlock(KPRBLK);}
                        MBEE_DECLSTMS
                        HEND    { endBlock(NULL,CCNO); mout(MENDPRBLOCK);
                                                          $$=STATEMENT;}
		|	EXPRESSION_SIMP HBEGIN error HSTATEMENTSEPARATOR
                        MBEE_DECLSTMS HEND              { $$=STATEMENT;
			         endBlock(NULL,CCNO); mout(MENDPRBLOCK);}
		|	EXPRESSION_SIMP HBEGIN error HEND
						        { $$=STATEMENT;
			         endBlock(NULL,CCNO); mout(MENDPRBLOCK);}

                |       EXPRESSION_SIMP
                                { STOPOBSBLOCK();         $$=STATEMENT;
                                                  mout(MENDASSIGN);}
		|	ACTIVATOR EXPRESSION SCHEDULE
						{      	  $$=STATEMENT;
						  mout(MENDSEP);
						  mout(MARGUMENTSEP);
						  mout(MARGUMENTSEP);
						  mout(MARGUMENTSEP);
						  mout(MARGUMENTSEP);
						  mout(MARGUMENTSEP);
						  mout(MARGUMENTSEP);
						  mout(MARGUMENT);
						  moutId(activateid);
						  mout(MENDASSIGN);}
                |       HBEGIN
                                { STOPOBSBLOCK();
                                  OBSBLOCK();}
                        MBEE_DECLSTMS
                        HEND    { MBEEENDBLOCK();         $$=STATEMENT;}
		|       MBEE_TYPE HPROCEDURE
                        HIDENTIFIER
                                { MBEENEWBLOCK(); mout(MPROCEDURE);
                                          regDecl($3, type, KPROC, categ);
                                          beginBlock(KPROC);}
                        HEADING BLOCK   { endBlock(NULL,CCNO); $$=DECLARATION;
                                                  mout(MENDPROCEDURE);}
		|       HIDENTIFIER
			HCLASS
                        NO_TYPE
				{ $<ident>$=$1; }
			IMPORT_SPEC_MODULE
                        HIDENTIFIER
				{ prefquantident=$1;
				  mout(MCLASS);
                                          regDecl($6, TNOTY, KCLASS, categ);
                                          beginBlock(KCLASS);}
                        HEADING
                        BLOCK           { endBlock(NULL,CCNO); $$=DECLARATION;
                                                  mout(MENDCLASS);}
                |       HCLASS
                        NO_TYPE
                        HIDENTIFIER
                                { prefquantident=0;
                                  MBEENEWBLOCK(); mout(MCLASS);
                                          regDecl($3, TNOTY, KCLASS, categ);
                                          beginBlock(KCLASS);}
                        HEADING
                        BLOCK           { endBlock(NULL,CCNO); $$=DECLARATION;
                                                  mout(MENDCLASS);}
                |       EXT_DECLARATION			{ $$=EXTDECLARATION;}
		|       /*EMPT*/{ STOPOBSBLOCK();	  $$=EMPTYSTATEMENT;}
                ;
IMPORT_SPEC_MODULE:		{ MBEENEWBLOCK();
                                  kind=KCLASS;
				  if($<ident>0==simsetident &&
				     findDecl(simsetident,cblock,FALSE)==NULL)
				    lesinn_external_spec(simsetident,
					SIMSETATRFILE, kind);
				  if($<ident>0==simulationident && findDecl(
				    simulationident,cblock,FALSE)==NULL)
				    lesinn_external_spec(simulationident,
					SIMULATIONATRFILE, kind);
				  if(($<ident>0==fileident && findDecl(
				      fileident,cblock,FALSE)==NULL) ||
				     ($<ident>0==outfileident && findDecl(
				      outfileident,cblock,FALSE)==NULL) ||
				     ($<ident>0==infileident && findDecl(
				      infileident,cblock,FALSE)==NULL) ||
				     ($<ident>0==directfileident && findDecl(
				      directfileident,cblock,FALSE)==NULL) ||
				     ($<ident>0==printfileident && findDecl(
				      printfileident,cblock,FALSE)==NULL) ||
				     ($<ident>0==bytefileident && findDecl(
				      bytefileident,cblock,FALSE)==NULL) ||
				     ($<ident>0==inbytefileident && findDecl(
				      inbytefileident,cblock,FALSE)==NULL) ||
				     ($<ident>0==outbytefileident && findDecl(
				      outbytefileident,cblock,FALSE)==NULL) ||
				     ($<ident>0==directbytefileident && findDecl(
				      directbytefileident,cblock,FALSE)==NULL))
				    lesinn_external_spec(fileident,
					FILEATRFILE, kind);}
		;
DECLSTATEMENT	:	MODULSTATEMENT
		|       TYPE
                        HIDENTIFIER
			MBEE_CONSTANT
                        HPAREXPSEPARATOR
                                { MBEENEWBLOCK();
                                          kind=KSIMPLE;
                                          regDecl($2, type, KSIMPLE, categ);
					  categ=CLOCAL;}
                        IDENTIFIER_LISTC                { $$=DECLARATION;}
                |       TYPE
                        HIDENTIFIER
			MBEE_CONSTANT
                                { MBEENEWBLOCK();
                                          regDecl($2, type, KSIMPLE, categ);
					  categ=CLOCAL;	  $$=DECLARATION;}
                |       MBEE_TYPE
                        HARRAY  { MBEENEWBLOCK();
                                          kind=KARRAY;}
                        ARR_SEGMENT_LIST                { $$=DECLARATION;}
                |       HSWITCH
                        HIDENTIFIER
                        HASSIGN { MBEENEWBLOCK(); mout(MIDENTIFIER);
                                                  moutId($2);
                                          regDecl($2, TLABEL, KARRAY, categ);}
                        SWITCH_LIST                     { $$=DECLARATION;
                                                   mout(MSWITCH);
                                                   mout(MENDSWITCH);}
                ;
BLOCK           :       DECLSTATEMENT   { if($1<=DECLARATION)yerror (29);}
                |       HBEGIN MBEE_DECLSTMS HEND
		|	HBEGIN error HSTATEMENTSEPARATOR MBEE_DECLSTMS HEND
		|	HBEGIN error HEND
		;
MBEE_DECLSTMS   :       MBEE_DECLSTMSU  { if($1<=DECLARATION)yerror (28);
					  $$=$1;}
                ;
MBEE_DECLSTMSU  :       DECLSTATEMENT   { $$=$1;}
                |       MBEE_DECLSTMSU
                        HSTATEMENTSEPARATOR
                        DECLSTATEMENT   { if($1>=STATEMENT && $3<=DECLARATION)
                                            yerror (26);
                                          $$=$3;}
                ;
MODULS		:	MODULSTATEMENT	{ if($1==DECLARATION)
					  {separat_comp=TRUE;gettimestamp();}
                                          $$=$1;}
  		|	MODULS HSTATEMENTSEPARATOR MODULSTATEMENT
					{ if($1>=STATEMENT && $3<=DECLARATION)
                                            yerror (26);else
       					  if($1>=STATEMENT
					     && $3!=EMPTYSTATEMENT)yerror (25);
                                          if(separat_comp && $3==STATEMENT)
                                             yerror (25);
                                          if($3==DECLARATION && !separat_comp)
					  {separat_comp=TRUE;gettimestamp();}
					  $$=$3;}
		;
/* GRAMATIKK FOR DEL AV DEKLARASJONER */
ARR_SEGMENT_LIST:       ARR_SEGMENT
                |       ARR_SEGMENT_LIST
                        HPAREXPSEPARATOR
                        ARR_SEGMENT
                ;
ARR_SEGMENT	:       ARRAY_SEGMENT
                        HBEGPAR
                        BAUND_PAIR_LIST HENDPAR { mout(MARRAY);
                                                  mout(MENDARRAY);
                                                  setArrayDim($3);}
                ;
ARRAY_SEGMENT   :       ARRAY_SEGMENT_EL        { mout(MENDSEP);
                                                  mout(MARRAYSEP);}

                |       ARRAY_SEGMENT_EL
                        HPAREXPSEPARATOR
                        ARRAY_SEGMENT           { mout(MARRAYSEP);}
                ;
ARRAY_SEGMENT_EL:       HIDENTIFIER             { mout(MIDENTIFIER);
                                                  moutId($1);
                                                  regDecl($1, type, kind, categ);
				   if(lastArray==NULL)
                                     lastArray=cblock->lastparloc;}
                ;
BAUND_PAIR_LIST :       BAUND_PAIR              { mout(MENDSEP);
                                                  mout(MBOUNDSEP);
                                                  $$=1;}
                |       BAUND_PAIR
                        HPAREXPSEPARATOR
                        BAUND_PAIR_LIST         { mout(MBOUNDSEP);
                                                  $$=$3+1;}
                ;
BAUND_PAIR      :       EXPRESSION
                        HLABELSEPARATOR
                        EXPRESSION              { mout(MBOUNDPARSEP);}
                ;
SWITCH_LIST     :       EXPRESSION              { mout(MENDSEP);
                                                  mout(MSWITCHSEP);}
                |       EXPRESSION
                        HPAREXPSEPARATOR
                        SWITCH_LIST             { mout(MSWITCHSEP);}
                ;
HEADING         :       MBEE_FMAL_PAR_P HSTATEMENTSEPARATOR { kind=KNOKD;}
                        MBEE_MODE_PART  { categ=CSPEC;}
                        MBEE_SPEC_PART  { kind=KNOKD;}
                        MBEE_PROT_PART  { categ=CVIRT;}
                        MBEE_VIRT_PART
                                        { categ=CLOCAL;}
                ;
MBEE_FMAL_PAR_P :       /*EMPT*/
                |       FMAL_PAR_PART
                ;
FMAL_PAR_PART   :       HBEGPAR NO_TYPE
                        MBEE_LISTV HENDPAR
                ;
MBEE_LISTV      :       /*EMPT*/
                |       LISTV
                ;
LISTV           :       HIDENTIFIER     { regDecl($1, type, KNOKD, CDEFLT);}
                |	FPP_CATEG HDOTDOTDOT      { regDecl(varargsid, TVARARGS, KNOKD, categ);}
                |       HIDENTIFIER     { regDecl($1, type, KNOKD, CDEFLT);}
                        HPAREXPSEPARATOR LISTV {}
                |       FPP_SPEC
                |       FPP_SPEC
                        HPAREXPSEPARATOR LISTV
                ;
FPP_HEADING     :       HBEGPAR NO_TYPE
                        FPP_MBEE_LISTV HENDPAR
                ;
FPP_MBEE_LISTV  :       /*EMPT*/
                |       FPP_LISTV
                ;
FPP_LISTV       :	FPP_CATEG HDOTDOTDOT      { regDecl(varargsid, TVARARGS, KNOKD, categ);}
                |       FPP_SPEC
                |       FPP_SPEC
                        HPAREXPSEPARATOR LISTV
                ;
FPP_SPEC        :       FPP_CATEG SPECIFIER HIDENTIFIER
                                       { regDecl($3, type, kind, categ);}
		|	FPP_CATEG FPP_PROC_DECL_IN_SPEC
		;
FPP_CATEG       :       HNAME HLABELSEPARATOR
                                       { categ=CNAME;}
                |       HVALUE HLABELSEPARATOR
                                       { categ=CVALUE;}
                |       HVAR HLABELSEPARATOR
                                       { categ=CVAR;}
                |       /*EMPT*/       { categ=CDEFLT;}
                ;
FPP_PROC_DECL_IN_SPEC:	MBEE_TYPE HPROCEDURE
                        HIDENTIFIER
                                	{ $<ival>$=categ;
                                          regDecl($3, type, KPROC, categ);
                                          beginBlock(KPROC);}
                        FPP_HEADING
					{ categ=$<ival>4; /* M} settes tilbake*/}
				{ endBlock(NULL,CCNO);}
		;
IDENTIFIER_LISTV:       HIDENTIFIER     { regDecl($1, type, kind, categ);}
                |	HDOTDOTDOT {	  regDecl(varargsid, TVARARGS, kind, categ);}
                |       HIDENTIFIER     { regDecl($1, type, kind, categ);}
                        HPAREXPSEPARATOR IDENTIFIER_LISTV {}
                ;
MBEE_MODE_PART  :       /*EMPT*/
                |       MODE_PART
                ;
MODE_PART       :       NAME_PART
                |       VALUE_PART
                |       VAR_PART
                |       NAME_PART VALUE_PART
                |       VALUE_PART NAME_PART
                |       NAME_PART VAR_PART
                |       VAR_PART NAME_PART
                |       VALUE_PART VAR_PART
                |       VAR_PART VALUE_PART
                |       VAR_PART NAME_PART VALUE_PART
                |       NAME_PART VAR_PART VALUE_PART
                |       NAME_PART VALUE_PART VAR_PART
                |       VAR_PART VALUE_PART NAME_PART
                |       VALUE_PART VAR_PART NAME_PART
                |       VALUE_PART NAME_PART VAR_PART
                ;
NAME_PART       :       HNAME           { categ=CNAME;}
                        IDENTIFIER_LISTV
                        HSTATEMENTSEPARATOR
                ;
VAR_PART        :       HVAR            { categ=CVAR;}
                        IDENTIFIER_LISTV
                        HSTATEMENTSEPARATOR
                ;
VALUE_PART      :       HVALUE          { categ=CVALUE;}
                        IDENTIFIER_LISTV HSTATEMENTSEPARATOR
                ;
MBEE_SPEC_PART  :       /*EMPT*/
                |       SPEC_PART
                ;
SPEC_PART       :       ONE_SPEC
                |       SPEC_PART ONE_SPEC
                ;
ONE_SPEC	:	SPECIFIER IDENTIFIER_LIST HSTATEMENTSEPARATOR
		|	NO_TYPE HPROCEDURE HIDENTIFIER HOBJRELOPERATOR
			  { if($4!=HIS) yerror (8);}
			PROC_DECL_IN_SPEC HSTATEMENTSEPARATOR
                |       FPP_PROC_DECL_IN_SPEC HSTATEMENTSEPARATOR
                |       MBEE_TYPE HPROCEDURE HIDENTIFIER HSTATEMENTSEPARATOR
					{ yerror (45);}
                |       MBEE_TYPE HPROCEDURE HIDENTIFIER HPAREXPSEPARATOR
                        IDENTIFIER_LIST HSTATEMENTSEPARATOR
					{ yerror (45);}
		;
SPECIFIER       :       TYPE            { kind=KSIMPLE;}
                |       MBEE_TYPE
                        HARRAY          { kind=KARRAY;}
                |       HLABEL          { type=TLABEL;
                                          kind=KSIMPLE;}
                |       HSWITCH         { type=TLABEL;
                                          kind=KARRAY;}
                ;
PROC_DECL_IN_SPEC:	MBEE_TYPE HPROCEDURE
                        HIDENTIFIER
                                	{ $<ival>$=categ;
                                          regDecl($3, type, KPROC, categ);
                                          beginBlock(KPROC);}
                        HEADING
					{ categ=$<ival>4; /* M} settes tilbake*/}
			MBEE_BEGIN_END
				{ endBlock(NULL,CCNO);}
		;
MBEE_BEGIN_END	:	/* EMPTY */
		|	HBEGIN HEND
		;
MBEE_PROT_PART  :       /*EMPT*/
                |       PROTECTION_PART
                ;
PROTECTION_PART :       PROT_SPECIFIER IDENTIFIER_LIST
                        HSTATEMENTSEPARATOR
                |       PROTECTION_PART  PROT_SPECIFIER
                        IDENTIFIER_LIST HSTATEMENTSEPARATOR
                ;
PROT_SPECIFIER  :       HHIDDEN         { categ=CHIDEN;}
                |       HPROTECTED      { categ=CPROT;}
                |       HHIDDEN
                        HPROTECTED      { categ=CHIPRO;}
                |       HPROTECTED
                        HHIDDEN         { categ=CHIPRO;}
                ;
MBEE_VIRT_PART  :       /*EMPT*/
                |       VIRTUAL_PART
                ;
VIRTUAL_PART    :       HVIRTUAL
                        HLABELSEPARATOR
                        MBEE_SPEC_PART
                ;
IDENTIFIER_LIST :       HIDENTIFIER     { regDecl($1, type, kind, categ);}
                |       IDENTIFIER_LIST HPAREXPSEPARATOR
                        HIDENTIFIER     { regDecl($3, type, kind, categ);}
                ;
IDENTIFIER_LISTC:       HIDENTIFIER
			MBEE_CONSTANT   { regDecl($1, type, kind, categ);
					  categ=CLOCAL;}
                |       IDENTIFIER_LISTC HPAREXPSEPARATOR
                        HIDENTIFIER
			MBEE_CONSTANT   { regDecl($3, type, kind, categ);
					  categ=CLOCAL;}
                ;
MBEE_CONSTANT	:	/* EMPTY */
		|	HVALRELOPERATOR
				{ MBEENEWBLOCK();
			    if($1!=HEQ) yerror (8);
					  if(type==TREF)yerror (7);
					  categ=CCONSTU;
						  mout(MIDENTIFIER);
						  moutId($<token>0);}
			EXPRESSION		{ mout(MASSIGN);
						  mout(MCONST);}
		;

/* GRAMATIKK FOR UTTRYKK */
EXPRESSION      :       EXPRESSION_SIMP {}
                |       HIF
                        EXPRESSION
                        HTHEN
                        EXPRESSION
                        HELSE
                        EXPRESSION              { mout(MELSEE);
                                                  mout(MIFE);}
                ;
EXPRESSION_SIMP :	EXPRESSION_SIMP
			HASSIGN
			EXPRESSION { if($2==HASSIGNREF)mout(MASSIGNR);
                                          else    mout(MASSIGN);$$=NULL;}
		|

			EXPRESSION_SIMP
                        HCONC
                        EXPRESSION_SIMP         { mout(MCONC);$$=NULL;}
                |       EXPRESSION_SIMP HOR
                        HELSE
                        EXPRESSION_SIMP
                        %prec HORELSE           { mout(MORELSEE);$$=NULL;}
                |       EXPRESSION_SIMP HAND
                        HTHEN
                        EXPRESSION_SIMP
                        %prec HANDTHEN          { mout(MANDTHENE);$$=NULL;}
                |       EXPRESSION_SIMP
                        HEQV EXPRESSION_SIMP    { mout(MEQV);$$=NULL;}
                |       EXPRESSION_SIMP
                        HIMP EXPRESSION_SIMP    { mout(MIMP);$$=NULL;}
                |       EXPRESSION_SIMP
                        HOR EXPRESSION_SIMP     { mout(MOR);$$=NULL;}
                |       EXPRESSION_SIMP
                        HAND EXPRESSION_SIMP    { mout(MAND);$$=NULL;}
                |       HNOT EXPRESSION_SIMP    { mout(MNOT);$$=NULL;}
                |       EXPRESSION_SIMP
                        HVALRELOPERATOR
                        EXPRESSION_SIMP
                                { switch($2)
                                    {   case HEQ: mout(MEQ);break;
                                        case HNE: mout(MNE);break;
                                        case HLT: mout(MLT);break;
                                        case HLE: mout(MLE);break;
                                        case HGT: mout(MGT);break;
                                        case HGE: mout(MGE);break;
                                    }$$=NULL;}
                |       EXPRESSION_SIMP
                        HREFRELOPERATOR
                        EXPRESSION_SIMP
                                { if($2==HNER)    mout(MNER);
                                        else      mout(MEQR);$$=NULL;}
                |       EXPRESSION_SIMP
                        HOBJRELOPERATOR
                        EXPRESSION_SIMP
                                { if($2==HIS)     mout(MIS);
                                        else      mout(MINS);$$=NULL;}
                |       HTERMOPERATOR
                        EXPRESSION_SIMP %prec UNEAR
                                { if($1==HADD)    mout(MUADD);
                                        else      mout(MUSUB);$$=NULL;}
                |       EXPRESSION_SIMP
                        HTERMOPERATOR
                        EXPRESSION_SIMP
                                { if($2==HADD)    mout(MADD);
                                        else      mout(MSUB);$$=NULL;}
                |       EXPRESSION_SIMP
                        HFACTOROPERATOR
                        EXPRESSION_SIMP
                                { if($2==HMUL)    mout(MMUL); else
                                  if($2==HDIV)    mout(MDIV);
                                        else      mout(MINTDIV);$$=NULL;}
                |       EXPRESSION_SIMP
                        HPRIMARYOPERATOR
                        EXPRESSION_SIMP         { mout(MPRIMARY);$$=NULL;}
                |       HBEGPAR
                        EXPRESSION HENDPAR      { mout(MNOOP);$$=NULL;}
                |       HTEXTKONST              { mout(MTEXTKONST);
                                                  moutTval($1);$$=NULL;}
                |       HCHARACTERKONST         { mout(MCHARACTERKONST);
                                                  moutIval($1);$$=NULL;}
                |       HREALKONST              { mout(MREALKONST);
                                                  moutRval($1);$$=NULL;}
                |       HINTEGERKONST           { mout(MINTEGERKONST);
                                                  moutIval($1);$$=NULL;}
                |       HBOOLEANKONST           { mout(MBOOLEANKONST);
                                                  moutIval($1);$$=NULL;}
                |       HNONE                   { mout(MNONE);$$=NULL;}
                |       HIDENTIFIER
                                { $<ident>$=$1;}
                        MBEE_ARG_R_PT {}
                |       HTHIS HIDENTIFIER       { mout(MTHIS);
                                                  moutId($2);$$=NULL;}
                |       HNEW
                        HIDENTIFIER
                        ARG_R_PT                { mout(MNEWARG);
                                                  moutId($2);$$=NULL;}
                |       EXPRESSION_SIMP
                        HDOT
                        EXPRESSION_SIMP         { mout(MDOT);$$=NULL;}
                |       EXPRESSION_SIMP
                        HQUA HIDENTIFIER        { mout(MQUA);
                                                  moutId($3);$$=NULL;}
                ;
ARG_R_PT        :       /*EMPTY*/               { mout(MENDSEP);}
                |       HBEGPAR
                        ARGUMENT_LIST HENDPAR
                ;
MBEE_ARG_R_PT   :       /*EMPTY*/               { mout(MIDENTIFIER);
                                                  moutId($<ident>0);
						  $$=$<ident>0;}
                |       HBEGPAR
                        ARGUMENT_LIST HENDPAR   { mout(MARGUMENT);
                                                  moutId($<ident>0);}
                ;
ARGUMENT_LIST   :       EXPRESSION              { mout(MENDSEP);
                                                  mout(MARGUMENTSEP);}
                |       EXPRESSION
                        HPAREXPSEPARATOR
                        ARGUMENT_LIST           { mout(MARGUMENTSEP);}
                ;
%%
_ATEOF


# Pass plenty of options, to exercise plenty of code, even if we
# don't actually check the output.  But SEGV is watching us, and
# so might do dmalloc.
$at_traceoff
$at_verbose "existing.at:1195: bison --verbose --defines input.y"
echo existing.at:1195 >$at_check_line_file
( $at_traceon; bison --verbose --defines input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y: conflicts: 78 shift/reduce, 10 reduce/reduce
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "existing.at:1195: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "existing.at:1207: grep '^State.*conflicts:' input.output"
echo existing.at:1207 >$at_check_line_file
( $at_traceon; grep '^State.*conflicts:' input.output ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "State 64 conflicts: 14 shift/reduce
State 164 conflicts: 1 shift/reduce
State 201 conflicts: 33 shift/reduce, 4 reduce/reduce
State 206 conflicts: 1 shift/reduce
State 240 conflicts: 1 shift/reduce
State 335 conflicts: 9 shift/reduce, 2 reduce/reduce
State 356 conflicts: 1 shift/reduce
State 360 conflicts: 9 shift/reduce, 2 reduce/reduce
State 427 conflicts: 9 shift/reduce, 2 reduce/reduce
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "existing.at:1207: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-13 ) # Banner 13. regression.at:19
    cat <<\_ATEOF

Regression tests.

_ATEOF
    ;;

  85 ) # 85. regression.at:27: Early token definitions
    at_setup_line='regression.at:27'
    $at_verbose "85. regression.at:27: testing Early token definitions..."
    $at_quiet $ECHO_N " 85: regression.at:27  $ECHO_C"
    (
      $at_traceon


# Found in GCJ: they expect the tokens to be defined before the user
# prologue, so that they can use the token definitions in it.

cat >input.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

%{
void yyerror (const char *s);
int yylex (void);
%}

%union
{
  int val;
};
%{
#ifndef MY_TOKEN
# error "MY_TOKEN not defined."
#endif
%}
%token MY_TOKEN
%%
exp: MY_TOKEN;
%%
_ATEOF



$at_traceoff
$at_verbose "regression.at:53: bison -o input.c input.y"
echo regression.at:53 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:53: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "regression.at:54: \$CC \$CFLAGS \$CPPFLAGS -c input.c -o input.o"
echo regression.at:54 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c -o input.o ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:54: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  86 ) # 86. regression.at:65: Braces parsing
    at_setup_line='regression.at:65'
    $at_verbose "86. regression.at:65: testing Braces parsing..."
    $at_quiet $ECHO_N " 86: regression.at:65  $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
/* Bison used to swallow the character after `}'. */

%%
exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
%%
_ATEOF


$at_traceoff
$at_verbose "regression.at:75: bison -v -o input.c input.y"
echo regression.at:75 >$at_check_line_file
( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:75: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "regression.at:77: grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c"
echo regression.at:77 >$at_check_line_file
( $at_traceon; grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
(echo stdout:; cat $at_stdout) >&5
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:77: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  87 ) # 87. regression.at:87: Duplicate string
    at_setup_line='regression.at:87'
    $at_verbose "87. regression.at:87: testing Duplicate string..."
    $at_quiet $ECHO_N " 87: regression.at:87  $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
/* `Bison -v' used to dump core when two tokens are defined with the same
   string, as LE and GE below. */

%token NUM
%token LE "<="
%token GE "<="

%%
exp: '(' exp ')' | NUM ;
%%
_ATEOF


$at_traceoff
$at_verbose "regression.at:104: bison -v -o input.c input.y"
echo regression.at:104 >$at_check_line_file
( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y:6.8-14: warning: symbol \`\"<=\"' used more than once as a literal string
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:104: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  88 ) # 88. regression.at:113: Rule Line Numbers
    at_setup_line='regression.at:113'
    $at_verbose "88. regression.at:113: testing Rule Line Numbers..."
    $at_quiet $ECHO_N " 88: regression.at:113 $ECHO_C"
    (
      $at_traceon




cat >input.y <<'_ATEOF'
%%
expr:
'a'

{

}

'b'

{

}

|


{


}

'c'

{

};
_ATEOF


$at_traceoff
$at_verbose "regression.at:147: bison -o input.c -v input.y"
echo regression.at:147 >$at_check_line_file
( $at_traceon; bison -o input.c -v input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:147: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Check the contents of the report.
$at_traceoff
$at_verbose "regression.at:246: cat input.output"
echo regression.at:246 >$at_check_line_file
( $at_traceon; cat input.output ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "Grammar

    0 \$accept: expr \$end

    1 @1: /* empty */

    2 expr: 'a' @1 'b'

    3 @2: /* empty */

    4 expr: @2 'c'


Terminals, with rules where they appear

\$end (0) 0
'a' (97) 2
'b' (98) 2
'c' (99) 4
error (256)


Nonterminals, with rules where they appear

\$accept (6)
    on left: 0
expr (7)
    on left: 2 4, on right: 0
@1 (8)
    on left: 1, on right: 2
@2 (9)
    on left: 3, on right: 4


state 0

    0 \$accept: . expr \$end

    'a'  shift, and go to state 1

    \$default  reduce using rule 3 (@2)

    expr  go to state 2
    @2    go to state 3


state 1

    2 expr: 'a' . @1 'b'

    \$default  reduce using rule 1 (@1)

    @1  go to state 4


state 2

    0 \$accept: expr . \$end

    \$end  shift, and go to state 5


state 3

    4 expr: @2 . 'c'

    'c'  shift, and go to state 6


state 4

    2 expr: 'a' @1 . 'b'

    'b'  shift, and go to state 7


state 5

    0 \$accept: expr \$end .

    \$default  accept


state 6

    4 expr: @2 'c' .

    \$default  reduce using rule 4 (expr)


state 7

    2 expr: 'a' @1 'b' .

    \$default  reduce using rule 2 (expr)
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:246: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  89 ) # 89. regression.at:257: Mixing %token styles
    at_setup_line='regression.at:257'
    $at_verbose "89. regression.at:257: testing Mixing %token styles..."
    $at_quiet $ECHO_N " 89: regression.at:257 $ECHO_C"
    (
      $at_traceon


# Taken from the documentation.
cat >input.y <<'_ATEOF'
%token  <operator>  OR      "||"
%token  <operator>  LE 134  "<="
%left  OR  "<="
%%
exp: ;
%%
_ATEOF


$at_traceoff
$at_verbose "regression.at:269: bison -v -o input.c input.y"
echo regression.at:269 >$at_check_line_file
( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:269: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  90 ) # 90. regression.at:280: Invalid inputs
    at_setup_line='regression.at:280'
    $at_verbose "90. regression.at:280: testing Invalid inputs..."
    $at_quiet $ECHO_N " 90: regression.at:280 $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%%
?
default: 'a' }
%&
%a-does-not-exist
%-
%{
_ATEOF


$at_traceoff
$at_verbose "regression.at:302: bison input.y"
echo regression.at:302 >$at_check_line_file
( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "input.y:2.1: invalid character: \`?'
input.y:3.14: invalid character: \`}'
input.y:4.1: invalid character: \`%'
input.y:4.2: invalid character: \`&'
input.y:5.1-17: invalid directive: \`%a-does-not-exist'
input.y:6.1: invalid character: \`%'
input.y:6.2: invalid character: \`-'
input.y:7.1-8.0: missing \`%}' at end of file
input.y:7.1-8.0: syntax error, unexpected \"%{...%}\"
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   1) ;;
   *) $at_verbose "regression.at:302: exit code was $at_status, expected 1" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  91 ) # 91. regression.at:313: Token definitions
    at_setup_line='regression.at:313'
    $at_verbose "91. regression.at:313: testing Token definitions..."
    $at_quiet $ECHO_N " 91: regression.at:313 $ECHO_C"
    (
      $at_traceon


# Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
cat >input.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

%{
void yyerror (const char *s);
int yylex (void);
%}
%token MYEOF 0 "end of file"
%token 'a' "a"
%token b "b"
%token c 'c'
%token 'd' d
%%
exp: "a";
_ATEOF



$at_traceoff
$at_verbose "regression.at:330: bison -o input.c input.y"
echo regression.at:330 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:330: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "regression.at:331: \$CC \$CFLAGS \$CPPFLAGS -c input.c -o input.o"
echo regression.at:331 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c -o input.o ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:331: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  92 ) # 92. regression.at:341: Characters Escapes
    at_setup_line='regression.at:341'
    $at_verbose "92. regression.at:341: testing Characters Escapes..."
    $at_quiet $ECHO_N " 92: regression.at:341 $ECHO_C"
    (
      $at_traceon


cat >input.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

%{
void yyerror (const char *s);
int yylex (void);
%}
%%
exp:
  '\'' "\'"
| '\"' "\""
| '"'  "'"
;
_ATEOF


# Pacify font-lock-mode: "

$at_traceoff
$at_verbose "regression.at:357: bison -o input.c input.y"
echo regression.at:357 >$at_check_line_file
( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:357: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "regression.at:358: \$CC \$CFLAGS \$CPPFLAGS -c input.c -o input.o"
echo regression.at:358 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c -o input.o ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:358: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  93 ) # 93. regression.at:372: Web2c Report
    at_setup_line='regression.at:372'
    $at_verbose "93. regression.at:372: testing Web2c Report..."
    $at_quiet $ECHO_N " 93: regression.at:372 $ECHO_C"
    (
      $at_traceon




cat >input.y <<'_ATEOF'
%token	undef_id_tok const_id_tok

%start CONST_DEC_PART

%%
CONST_DEC_PART:
         CONST_DEC_LIST
        ;

CONST_DEC_LIST:
	  CONST_DEC
        | CONST_DEC_LIST CONST_DEC
        ;

CONST_DEC:
	  { } undef_id_tok '=' const_id_tok ';'
        ;
%%
_ATEOF


$at_traceoff
$at_verbose "regression.at:397: bison -v input.y"
echo regression.at:397 >$at_check_line_file
( $at_traceon; bison -v input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:397: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "regression.at:522: cat input.output"
echo regression.at:522 >$at_check_line_file
( $at_traceon; cat input.output ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "Grammar

    0 \$accept: CONST_DEC_PART \$end

    1 CONST_DEC_PART: CONST_DEC_LIST

    2 CONST_DEC_LIST: CONST_DEC
    3               | CONST_DEC_LIST CONST_DEC

    4 @1: /* empty */

    5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';'


Terminals, with rules where they appear

\$end (0) 0
';' (59) 5
'=' (61) 5
error (256)
undef_id_tok (258) 5
const_id_tok (259) 5


Nonterminals, with rules where they appear

\$accept (7)
    on left: 0
CONST_DEC_PART (8)
    on left: 1, on right: 0
CONST_DEC_LIST (9)
    on left: 2 3, on right: 1 3
CONST_DEC (10)
    on left: 5, on right: 2 3
@1 (11)
    on left: 4, on right: 5


state 0

    0 \$accept: . CONST_DEC_PART \$end

    \$default  reduce using rule 4 (@1)

    CONST_DEC_PART  go to state 1
    CONST_DEC_LIST  go to state 2
    CONST_DEC       go to state 3
    @1              go to state 4


state 1

    0 \$accept: CONST_DEC_PART . \$end

    \$end  shift, and go to state 5


state 2

    1 CONST_DEC_PART: CONST_DEC_LIST .
    3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC

    undef_id_tok  reduce using rule 4 (@1)
    \$default      reduce using rule 1 (CONST_DEC_PART)

    CONST_DEC  go to state 6
    @1         go to state 4


state 3

    2 CONST_DEC_LIST: CONST_DEC .

    \$default  reduce using rule 2 (CONST_DEC_LIST)


state 4

    5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';'

    undef_id_tok  shift, and go to state 7


state 5

    0 \$accept: CONST_DEC_PART \$end .

    \$default  accept


state 6

    3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .

    \$default  reduce using rule 3 (CONST_DEC_LIST)


state 7

    5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';'

    '='  shift, and go to state 8


state 8

    5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';'

    const_id_tok  shift, and go to state 9


state 9

    5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';'

    ';'  shift, and go to state 10


state 10

    5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' .

    \$default  reduce using rule 5 (CONST_DEC)
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:522: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  94 ) # 94. regression.at:549: Web2c Actions
    at_setup_line='regression.at:549'
    $at_verbose "94. regression.at:549: testing Web2c Actions..."
    $at_quiet $ECHO_N " 94: regression.at:549 $ECHO_C"
    (
      $at_traceon




cat >input.y <<'_ATEOF'
%%
statement:  struct_stat;
struct_stat:  /* empty. */ | if else;
if: "if" "const" "then" statement;
else: "else" statement;
%%
_ATEOF


$at_traceoff
$at_verbose "regression.at:562: bison -v -o input.c input.y"
echo regression.at:562 >$at_check_line_file
( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:562: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


# Check only the tables.  We don't use --no-parser, because it is
# still to be implemented in the experimental branch of Bison.
sed -n 's/  *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c

$at_traceoff
$at_verbose "regression.at:660: cat tables.c"
echo regression.at:660 >$at_check_line_file
( $at_traceon; cat tables.c ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "static const unsigned char yytranslate[] =
{
       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
       5,     6
};
static const unsigned char yyprhs[] =
{
       0,     0,     3,     5,     6,     9,    14
};
static const yysigned_char yyrhs[] =
{
       8,     0,    -1,     9,    -1,    -1,    10,    11,    -1,     3,
       4,     5,     8,    -1,     6,     8,    -1
};
static const unsigned char yyrline[] =
{
       0,     2,     2,     3,     3,     4,     5
};
static const char *const yytname[] =
{
  \"\$end\", \"error\", \"\$undefined\", \"\\\"if\\\"\", \"\\\"const\\\"\", \"\\\"then\\\"\",
  \"\\\"else\\\"\", \"\$accept\", \"statement\", \"struct_stat\", \"if\", \"else\", 0
};
static const unsigned short yytoknum[] =
{
       0,   256,   257,   258,   259,   260,   261
};
static const unsigned char yyr1[] =
{
       0,     7,     8,     9,     9,    10,    11
};
static const unsigned char yyr2[] =
{
       0,     2,     1,     0,     2,     4,     2
};
static const unsigned char yydefact[] =
{
       3,     0,     0,     2,     0,     0,     1,     3,     4,     3,
       6,     5
};
static const yysigned_char yydefgoto[] =
{
      -1,     2,     3,     4,     8
};
static const yysigned_char yypact[] =
{
      -2,    -1,     4,    -8,     0,     2,    -8,    -2,    -8,    -2,
      -8,    -8
};
static const yysigned_char yypgoto[] =
{
      -8,    -7,    -8,    -8,    -8
};
static const unsigned char yytable[] =
{
      10,     1,    11,     5,     6,     0,     7,     9
};
static const yysigned_char yycheck[] =
{
       7,     3,     9,     4,     0,    -1,     6,     5
};
static const unsigned char yystos[] =
{
       0,     3,     8,     9,    10,     4,     0,     6,    11,     5,
       8,     8
};
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "regression.at:660: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-14 ) # Banner 14. cxx-type.at:19
    cat <<\_ATEOF

C++ Type Syntax (GLR).

_ATEOF
    ;;

  95 ) # 95. cxx-type.at:255: GLR: Resolve ambiguity, impure, no locations
    at_setup_line='cxx-type.at:255'
    $at_verbose "95. cxx-type.at:255: testing GLR: Resolve ambiguity, impure, no locations..."
    $at_quiet $ECHO_N " 95: cxx-type.at:255   $ECHO_C"
    (
      $at_traceon

cat >types.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Simplified C++ Type and Expression Grammar.  */



%{
  #include <stdio.h>
  #define YYSTYPE const char*
  #define YYLTYPE int

  #define YYINITDEPTH 10
  int yyerror (
#if YYPURE && YYLSP_NEEDED
               YYLTYPE *yylocation,
#endif
               const char *s
              );

  #if YYPURE
  int yylex (YYSTYPE *lvalp);
  #else
  int yylex (void);
  #endif

%}

%token TYPENAME ID

%right '='
%left '+'

%glr-parser

%%

prog :
     | prog stmt   { printf ("\n"); }
     ;

stmt : expr ';'  %dprec 1
     | decl      %dprec 2
     | error ';'
     | '@'  { YYACCEPT; }
     ;

expr : ID 		{ printf ("%s ", $$); }
     | TYPENAME '(' expr ')'
			{ printf ("%s <cast> ", $1); }
     | expr '+' expr	{ printf ("+ "); }
     | expr '=' expr	{ printf ("= "); }
     ;

decl : TYPENAME declarator ';'
			{ printf ("%s <declare> ", $1); }
     | TYPENAME declarator '=' expr ';'
			{ printf ("%s <init-declare> ", $1); }
     ;

declarator : ID		{ printf ("\"%s\" ", $1); }
     | '(' declarator ')'
     ;

%%

#include <ctype.h>
#include <stdlib.h>
#include <string.h>

int
main (int argc, char** argv)
{
  if (argc != 2)
    abort ();
  if (!freopen (argv[1], "r", stdin))
    abort ();
  exit (yyparse ());
}

#if YYPURE
int
yylex (YYSTYPE *lvalp)
#else
int
yylex ()
#endif
{
  char buffer[256];
  int c;
  unsigned int i;

#if YYPURE
# define yylval (*lvalp)

#endif

  while (1)
    {
      c = getchar ();
      switch (c)
	{
	case EOF:
	  return 0;
	case ' ': case '\t': case '\n': case '\f':
	  break;
	default:
	  if (isalpha (c))
	    {
	      i = 0;

	      do
		{
		  buffer[i++] = c;
		  if (i == sizeof buffer - 1)
		    abort ();
		  c = getchar ();
		}
	      while (isalnum (c) || c == '_');

	      ungetc (c, stdin);
	      buffer[i++] = 0;
	      yylval = strcpy (malloc (i), buffer);
	      return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
	    }
	  return c;
	}
    }
}

int
yyerror (
#if YYPURE && YYLSP_NEEDED
         YYLTYPE *yylocation,
#endif
         const char *s
        )
{
#if YYPURE && YYLSP_NEEDED
  (void) *yylocation;
#endif
  fprintf (stderr, "%s\n", s);
  return 0;
}



_ATEOF



cat >test-input <<'_ATEOF'


z + q;

T x;

T x = y;

x = y;

T (x) + y;

T (x);

T (y) = z + q;

T (y y) = z + q;

z + q;

@

This is total garbage, but it should be ignored.
_ATEOF


$at_traceoff
$at_verbose "cxx-type.at:257: bison -o types.c types.y"
echo cxx-type.at:257 >$at_check_line_file
( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:257: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "cxx-type.at:257: \$CC \$CFLAGS \$CPPFLAGS types.c -o types"
echo cxx-type.at:257 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS types.c -o types ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:257: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "cxx-type.at:259: \$PREPARSER ./types test-input | sed 's/  *\$//'"
echo cxx-type.at:259 >$at_check_line_file
( $at_traceon; $PREPARSER ./types test-input | sed 's/  *$//' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "syntax error
" | $at_diff - $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "z q +
\"x\" T <declare>
\"x\" y T <init-declare>
x y =
x T <cast> y +
\"x\" T <declare>
\"y\" z q + T <init-declare>
y
z q +
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:259: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  96 ) # 96. cxx-type.at:262: GLR: Resolve ambiguity, impure, locations
    at_setup_line='cxx-type.at:262'
    $at_verbose "96. cxx-type.at:262: testing GLR: Resolve ambiguity, impure, locations..."
    $at_quiet $ECHO_N " 96: cxx-type.at:262   $ECHO_C"
    (
      $at_traceon

cat >types.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Simplified C++ Type and Expression Grammar.  */

%locations

%{
  #include <stdio.h>
  #define YYSTYPE const char*
  #define YYLTYPE int

  #define YYINITDEPTH 10
  int yyerror (
#if YYPURE && YYLSP_NEEDED
               YYLTYPE *yylocation,
#endif
               const char *s
              );

  #if YYPURE
  int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
  #else
  int yylex (void);
  #endif

%}

%token TYPENAME ID

%right '='
%left '+'

%glr-parser

%%

prog :
     | prog stmt   { printf ("\n"); }
     ;

stmt : expr ';'  %dprec 1
     | decl      %dprec 2
     | error ';'
     | '@'  { YYACCEPT; }
     ;

expr : ID 		{ printf ("%s ", $$); }
     | TYPENAME '(' expr ')'
			{ printf ("%s <cast> ", $1); }
     | expr '+' expr	{ printf ("+ "); }
     | expr '=' expr	{ printf ("= "); }
     ;

decl : TYPENAME declarator ';'
			{ printf ("%s <declare> ", $1); }
     | TYPENAME declarator '=' expr ';'
			{ printf ("%s <init-declare> ", $1); }
     ;

declarator : ID		{ printf ("\"%s\" ", $1); }
     | '(' declarator ')'
     ;

%%

#include <ctype.h>
#include <stdlib.h>
#include <string.h>

int
main (int argc, char** argv)
{
  if (argc != 2)
    abort ();
  if (!freopen (argv[1], "r", stdin))
    abort ();
  exit (yyparse ());
}

#if YYPURE
int
yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
#else
int
yylex ()
#endif
{
  char buffer[256];
  int c;
  unsigned int i;

#if YYPURE
# define yylval (*lvalp)
  (void) llocp;
#endif

  while (1)
    {
      c = getchar ();
      switch (c)
	{
	case EOF:
	  return 0;
	case ' ': case '\t': case '\n': case '\f':
	  break;
	default:
	  if (isalpha (c))
	    {
	      i = 0;

	      do
		{
		  buffer[i++] = c;
		  if (i == sizeof buffer - 1)
		    abort ();
		  c = getchar ();
		}
	      while (isalnum (c) || c == '_');

	      ungetc (c, stdin);
	      buffer[i++] = 0;
	      yylval = strcpy (malloc (i), buffer);
	      return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
	    }
	  return c;
	}
    }
}

int
yyerror (
#if YYPURE && YYLSP_NEEDED
         YYLTYPE *yylocation,
#endif
         const char *s
        )
{
#if YYPURE && YYLSP_NEEDED
  (void) *yylocation;
#endif
  fprintf (stderr, "%s\n", s);
  return 0;
}



_ATEOF



cat >test-input <<'_ATEOF'


z + q;

T x;

T x = y;

x = y;

T (x) + y;

T (x);

T (y) = z + q;

T (y y) = z + q;

z + q;

@

This is total garbage, but it should be ignored.
_ATEOF


$at_traceoff
$at_verbose "cxx-type.at:263: bison -o types.c types.y"
echo cxx-type.at:263 >$at_check_line_file
( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:263: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "cxx-type.at:263: \$CC \$CFLAGS \$CPPFLAGS types.c -o types"
echo cxx-type.at:263 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS types.c -o types ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:263: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "cxx-type.at:265: \$PREPARSER ./types test-input | sed 's/  *\$//'"
echo cxx-type.at:265 >$at_check_line_file
( $at_traceon; $PREPARSER ./types test-input | sed 's/  *$//' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "syntax error
" | $at_diff - $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "z q +
\"x\" T <declare>
\"x\" y T <init-declare>
x y =
x T <cast> y +
\"x\" T <declare>
\"y\" z q + T <init-declare>
y
z q +
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:265: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  97 ) # 97. cxx-type.at:268: GLR: Resolve ambiguity, pure, no locations
    at_setup_line='cxx-type.at:268'
    $at_verbose "97. cxx-type.at:268: testing GLR: Resolve ambiguity, pure, no locations..."
    $at_quiet $ECHO_N " 97: cxx-type.at:268   $ECHO_C"
    (
      $at_traceon

cat >types.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Simplified C++ Type and Expression Grammar.  */

%pure-parser

%{
  #include <stdio.h>
  #define YYSTYPE const char*
  #define YYLTYPE int

  #define YYINITDEPTH 10
  int yyerror (
#if YYPURE && YYLSP_NEEDED
               YYLTYPE *yylocation,
#endif
               const char *s
              );

  #if YYPURE
  int yylex (YYSTYPE *lvalp);
  #else
  int yylex (void);
  #endif

%}

%token TYPENAME ID

%right '='
%left '+'

%glr-parser

%%

prog :
     | prog stmt   { printf ("\n"); }
     ;

stmt : expr ';'  %dprec 1
     | decl      %dprec 2
     | error ';'
     | '@'  { YYACCEPT; }
     ;

expr : ID 		{ printf ("%s ", $$); }
     | TYPENAME '(' expr ')'
			{ printf ("%s <cast> ", $1); }
     | expr '+' expr	{ printf ("+ "); }
     | expr '=' expr	{ printf ("= "); }
     ;

decl : TYPENAME declarator ';'
			{ printf ("%s <declare> ", $1); }
     | TYPENAME declarator '=' expr ';'
			{ printf ("%s <init-declare> ", $1); }
     ;

declarator : ID		{ printf ("\"%s\" ", $1); }
     | '(' declarator ')'
     ;

%%

#include <ctype.h>
#include <stdlib.h>
#include <string.h>

int
main (int argc, char** argv)
{
  if (argc != 2)
    abort ();
  if (!freopen (argv[1], "r", stdin))
    abort ();
  exit (yyparse ());
}

#if YYPURE
int
yylex (YYSTYPE *lvalp)
#else
int
yylex ()
#endif
{
  char buffer[256];
  int c;
  unsigned int i;

#if YYPURE
# define yylval (*lvalp)

#endif

  while (1)
    {
      c = getchar ();
      switch (c)
	{
	case EOF:
	  return 0;
	case ' ': case '\t': case '\n': case '\f':
	  break;
	default:
	  if (isalpha (c))
	    {
	      i = 0;

	      do
		{
		  buffer[i++] = c;
		  if (i == sizeof buffer - 1)
		    abort ();
		  c = getchar ();
		}
	      while (isalnum (c) || c == '_');

	      ungetc (c, stdin);
	      buffer[i++] = 0;
	      yylval = strcpy (malloc (i), buffer);
	      return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
	    }
	  return c;
	}
    }
}

int
yyerror (
#if YYPURE && YYLSP_NEEDED
         YYLTYPE *yylocation,
#endif
         const char *s
        )
{
#if YYPURE && YYLSP_NEEDED
  (void) *yylocation;
#endif
  fprintf (stderr, "%s\n", s);
  return 0;
}



_ATEOF



cat >test-input <<'_ATEOF'


z + q;

T x;

T x = y;

x = y;

T (x) + y;

T (x);

T (y) = z + q;

T (y y) = z + q;

z + q;

@

This is total garbage, but it should be ignored.
_ATEOF


$at_traceoff
$at_verbose "cxx-type.at:270: bison -o types.c types.y"
echo cxx-type.at:270 >$at_check_line_file
( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:270: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "cxx-type.at:270: \$CC \$CFLAGS \$CPPFLAGS types.c -o types"
echo cxx-type.at:270 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS types.c -o types ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:270: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "cxx-type.at:272: \$PREPARSER ./types test-input | sed 's/  *\$//'"
echo cxx-type.at:272 >$at_check_line_file
( $at_traceon; $PREPARSER ./types test-input | sed 's/  *$//' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "syntax error
" | $at_diff - $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "z q +
\"x\" T <declare>
\"x\" y T <init-declare>
x y =
x T <cast> y +
\"x\" T <declare>
\"y\" z q + T <init-declare>
y
z q +
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:272: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  98 ) # 98. cxx-type.at:275: GLR: Resolve ambiguity, pure, locations
    at_setup_line='cxx-type.at:275'
    $at_verbose "98. cxx-type.at:275: testing GLR: Resolve ambiguity, pure, locations..."
    $at_quiet $ECHO_N " 98: cxx-type.at:275   $ECHO_C"
    (
      $at_traceon

cat >types.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Simplified C++ Type and Expression Grammar.  */

%pure-parser %locations

%{
  #include <stdio.h>
  #define YYSTYPE const char*
  #define YYLTYPE int

  #define YYINITDEPTH 10
  int yyerror (
#if YYPURE && YYLSP_NEEDED
               YYLTYPE *yylocation,
#endif
               const char *s
              );

  #if YYPURE
  int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
  #else
  int yylex (void);
  #endif

%}

%token TYPENAME ID

%right '='
%left '+'

%glr-parser

%%

prog :
     | prog stmt   { printf ("\n"); }
     ;

stmt : expr ';'  %dprec 1
     | decl      %dprec 2
     | error ';'
     | '@'  { YYACCEPT; }
     ;

expr : ID 		{ printf ("%s ", $$); }
     | TYPENAME '(' expr ')'
			{ printf ("%s <cast> ", $1); }
     | expr '+' expr	{ printf ("+ "); }
     | expr '=' expr	{ printf ("= "); }
     ;

decl : TYPENAME declarator ';'
			{ printf ("%s <declare> ", $1); }
     | TYPENAME declarator '=' expr ';'
			{ printf ("%s <init-declare> ", $1); }
     ;

declarator : ID		{ printf ("\"%s\" ", $1); }
     | '(' declarator ')'
     ;

%%

#include <ctype.h>
#include <stdlib.h>
#include <string.h>

int
main (int argc, char** argv)
{
  if (argc != 2)
    abort ();
  if (!freopen (argv[1], "r", stdin))
    abort ();
  exit (yyparse ());
}

#if YYPURE
int
yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
#else
int
yylex ()
#endif
{
  char buffer[256];
  int c;
  unsigned int i;

#if YYPURE
# define yylval (*lvalp)
  (void) llocp;
#endif

  while (1)
    {
      c = getchar ();
      switch (c)
	{
	case EOF:
	  return 0;
	case ' ': case '\t': case '\n': case '\f':
	  break;
	default:
	  if (isalpha (c))
	    {
	      i = 0;

	      do
		{
		  buffer[i++] = c;
		  if (i == sizeof buffer - 1)
		    abort ();
		  c = getchar ();
		}
	      while (isalnum (c) || c == '_');

	      ungetc (c, stdin);
	      buffer[i++] = 0;
	      yylval = strcpy (malloc (i), buffer);
	      return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
	    }
	  return c;
	}
    }
}

int
yyerror (
#if YYPURE && YYLSP_NEEDED
         YYLTYPE *yylocation,
#endif
         const char *s
        )
{
#if YYPURE && YYLSP_NEEDED
  (void) *yylocation;
#endif
  fprintf (stderr, "%s\n", s);
  return 0;
}



_ATEOF



cat >test-input <<'_ATEOF'


z + q;

T x;

T x = y;

x = y;

T (x) + y;

T (x);

T (y) = z + q;

T (y y) = z + q;

z + q;

@

This is total garbage, but it should be ignored.
_ATEOF


$at_traceoff
$at_verbose "cxx-type.at:277: bison -o types.c types.y"
echo cxx-type.at:277 >$at_check_line_file
( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:277: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "cxx-type.at:277: \$CC \$CFLAGS \$CPPFLAGS types.c -o types"
echo cxx-type.at:277 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS types.c -o types ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:277: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "cxx-type.at:279: \$PREPARSER ./types test-input | sed 's/  *\$//'"
echo cxx-type.at:279 >$at_check_line_file
( $at_traceon; $PREPARSER ./types test-input | sed 's/  *$//' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "syntax error
" | $at_diff - $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "z q +
\"x\" T <declare>
\"x\" y T <init-declare>
x y =
x T <cast> y +
\"x\" T <declare>
\"y\" z q + T <init-declare>
y
z q +
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:279: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  99 ) # 99. cxx-type.at:282: GLR: Merge conflicting parses, impure, no locations
    at_setup_line='cxx-type.at:282'
    $at_verbose "99. cxx-type.at:282: testing GLR: Merge conflicting parses, impure, no locations..."
    $at_quiet $ECHO_N " 99: cxx-type.at:282   $ECHO_C"
    (
      $at_traceon

cat >types.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Simplified C++ Type and Expression Grammar.  */



%{
  #include <stdio.h>
  #define YYSTYPE const char*
  #define YYLTYPE int
 static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);
  #define YYINITDEPTH 10
  int yyerror (
#if YYPURE && YYLSP_NEEDED
               YYLTYPE *yylocation,
#endif
               const char *s
              );

  #if YYPURE
  int yylex (YYSTYPE *lvalp);
  #else
  int yylex (void);
  #endif

%}

%token TYPENAME ID

%right '='
%left '+'

%glr-parser

%%

prog :
     | prog stmt   { printf ("\n"); }
     ;

stmt : expr ';'  %merge <stmtMerge>
     | decl      %merge <stmtMerge>
     | error ';'
     | '@'  { YYACCEPT; }
     ;

expr : ID 		{ printf ("%s ", $$); }
     | TYPENAME '(' expr ')'
			{ printf ("%s <cast> ", $1); }
     | expr '+' expr	{ printf ("+ "); }
     | expr '=' expr	{ printf ("= "); }
     ;

decl : TYPENAME declarator ';'
			{ printf ("%s <declare> ", $1); }
     | TYPENAME declarator '=' expr ';'
			{ printf ("%s <init-declare> ", $1); }
     ;

declarator : ID		{ printf ("\"%s\" ", $1); }
     | '(' declarator ')'
     ;

%%

#include <ctype.h>
#include <stdlib.h>
#include <string.h>

int
main (int argc, char** argv)
{
  if (argc != 2)
    abort ();
  if (!freopen (argv[1], "r", stdin))
    abort ();
  exit (yyparse ());
}

#if YYPURE
int
yylex (YYSTYPE *lvalp)
#else
int
yylex ()
#endif
{
  char buffer[256];
  int c;
  unsigned int i;

#if YYPURE
# define yylval (*lvalp)

#endif

  while (1)
    {
      c = getchar ();
      switch (c)
	{
	case EOF:
	  return 0;
	case ' ': case '\t': case '\n': case '\f':
	  break;
	default:
	  if (isalpha (c))
	    {
	      i = 0;

	      do
		{
		  buffer[i++] = c;
		  if (i == sizeof buffer - 1)
		    abort ();
		  c = getchar ();
		}
	      while (isalnum (c) || c == '_');

	      ungetc (c, stdin);
	      buffer[i++] = 0;
	      yylval = strcpy (malloc (i), buffer);
	      return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
	    }
	  return c;
	}
    }
}

int
yyerror (
#if YYPURE && YYLSP_NEEDED
         YYLTYPE *yylocation,
#endif
         const char *s
        )
{
#if YYPURE && YYLSP_NEEDED
  (void) *yylocation;
#endif
  fprintf (stderr, "%s\n", s);
  return 0;
}


static YYSTYPE
stmtMerge (YYSTYPE x0, YYSTYPE x1)
{
  /* Use the arguments. */
  (void) x0;
  (void) x1;
  printf ("<OR> ");
  return "";
}

_ATEOF



cat >test-input <<'_ATEOF'


z + q;

T x;

T x = y;

x = y;

T (x) + y;

T (x);

T (y) = z + q;

T (y y) = z + q;

z + q;

@

This is total garbage, but it should be ignored.
_ATEOF


$at_traceoff
$at_verbose "cxx-type.at:284: bison -o types.c types.y"
echo cxx-type.at:284 >$at_check_line_file
( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:284: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "cxx-type.at:284: \$CC \$CFLAGS \$CPPFLAGS types.c -o types"
echo cxx-type.at:284 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS types.c -o types ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:284: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "cxx-type.at:286: \$PREPARSER ./types test-input | sed 's/  *\$//'"
echo cxx-type.at:286 >$at_check_line_file
( $at_traceon; $PREPARSER ./types test-input | sed 's/  *$//' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "syntax error
" | $at_diff - $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "z q +
\"x\" T <declare>
\"x\" y T <init-declare>
x y =
x T <cast> y +
\"x\" T <declare> x T <cast> <OR>
\"y\" z q + T <init-declare> y T <cast> z q + = <OR>
y
z q +
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:286: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  100 ) # 100. cxx-type.at:289: GLR: Merge conflicting parses, impure, locations
    at_setup_line='cxx-type.at:289'
    $at_verbose "100. cxx-type.at:289: testing GLR: Merge conflicting parses, impure, locations..."
    $at_quiet $ECHO_N "100: cxx-type.at:289   $ECHO_C"
    (
      $at_traceon

cat >types.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Simplified C++ Type and Expression Grammar.  */

%locations

%{
  #include <stdio.h>
  #define YYSTYPE const char*
  #define YYLTYPE int
 static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);
  #define YYINITDEPTH 10
  int yyerror (
#if YYPURE && YYLSP_NEEDED
               YYLTYPE *yylocation,
#endif
               const char *s
              );

  #if YYPURE
  int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
  #else
  int yylex (void);
  #endif

%}

%token TYPENAME ID

%right '='
%left '+'

%glr-parser

%%

prog :
     | prog stmt   { printf ("\n"); }
     ;

stmt : expr ';'  %merge <stmtMerge>
     | decl      %merge <stmtMerge>
     | error ';'
     | '@'  { YYACCEPT; }
     ;

expr : ID 		{ printf ("%s ", $$); }
     | TYPENAME '(' expr ')'
			{ printf ("%s <cast> ", $1); }
     | expr '+' expr	{ printf ("+ "); }
     | expr '=' expr	{ printf ("= "); }
     ;

decl : TYPENAME declarator ';'
			{ printf ("%s <declare> ", $1); }
     | TYPENAME declarator '=' expr ';'
			{ printf ("%s <init-declare> ", $1); }
     ;

declarator : ID		{ printf ("\"%s\" ", $1); }
     | '(' declarator ')'
     ;

%%

#include <ctype.h>
#include <stdlib.h>
#include <string.h>

int
main (int argc, char** argv)
{
  if (argc != 2)
    abort ();
  if (!freopen (argv[1], "r", stdin))
    abort ();
  exit (yyparse ());
}

#if YYPURE
int
yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
#else
int
yylex ()
#endif
{
  char buffer[256];
  int c;
  unsigned int i;

#if YYPURE
# define yylval (*lvalp)
  (void) llocp;
#endif

  while (1)
    {
      c = getchar ();
      switch (c)
	{
	case EOF:
	  return 0;
	case ' ': case '\t': case '\n': case '\f':
	  break;
	default:
	  if (isalpha (c))
	    {
	      i = 0;

	      do
		{
		  buffer[i++] = c;
		  if (i == sizeof buffer - 1)
		    abort ();
		  c = getchar ();
		}
	      while (isalnum (c) || c == '_');

	      ungetc (c, stdin);
	      buffer[i++] = 0;
	      yylval = strcpy (malloc (i), buffer);
	      return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
	    }
	  return c;
	}
    }
}

int
yyerror (
#if YYPURE && YYLSP_NEEDED
         YYLTYPE *yylocation,
#endif
         const char *s
        )
{
#if YYPURE && YYLSP_NEEDED
  (void) *yylocation;
#endif
  fprintf (stderr, "%s\n", s);
  return 0;
}


static YYSTYPE
stmtMerge (YYSTYPE x0, YYSTYPE x1)
{
  /* Use the arguments. */
  (void) x0;
  (void) x1;
  printf ("<OR> ");
  return "";
}

_ATEOF



cat >test-input <<'_ATEOF'


z + q;

T x;

T x = y;

x = y;

T (x) + y;

T (x);

T (y) = z + q;

T (y y) = z + q;

z + q;

@

This is total garbage, but it should be ignored.
_ATEOF


$at_traceoff
$at_verbose "cxx-type.at:291: bison -o types.c types.y"
echo cxx-type.at:291 >$at_check_line_file
( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:291: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "cxx-type.at:291: \$CC \$CFLAGS \$CPPFLAGS types.c -o types"
echo cxx-type.at:291 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS types.c -o types ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:291: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "cxx-type.at:293: \$PREPARSER ./types test-input | sed 's/  *\$//'"
echo cxx-type.at:293 >$at_check_line_file
( $at_traceon; $PREPARSER ./types test-input | sed 's/  *$//' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "syntax error
" | $at_diff - $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "z q +
\"x\" T <declare>
\"x\" y T <init-declare>
x y =
x T <cast> y +
\"x\" T <declare> x T <cast> <OR>
\"y\" z q + T <init-declare> y T <cast> z q + = <OR>
y
z q +
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:293: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  101 ) # 101. cxx-type.at:296: GLR: Merge conflicting parses, pure, no locations
    at_setup_line='cxx-type.at:296'
    $at_verbose "101. cxx-type.at:296: testing GLR: Merge conflicting parses, pure, no locations..."
    $at_quiet $ECHO_N "101: cxx-type.at:296   $ECHO_C"
    (
      $at_traceon

cat >types.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Simplified C++ Type and Expression Grammar.  */

%pure-parser

%{
  #include <stdio.h>
  #define YYSTYPE const char*
  #define YYLTYPE int
 static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);
  #define YYINITDEPTH 10
  int yyerror (
#if YYPURE && YYLSP_NEEDED
               YYLTYPE *yylocation,
#endif
               const char *s
              );

  #if YYPURE
  int yylex (YYSTYPE *lvalp);
  #else
  int yylex (void);
  #endif

%}

%token TYPENAME ID

%right '='
%left '+'

%glr-parser

%%

prog :
     | prog stmt   { printf ("\n"); }
     ;

stmt : expr ';'  %merge <stmtMerge>
     | decl      %merge <stmtMerge>
     | error ';'
     | '@'  { YYACCEPT; }
     ;

expr : ID 		{ printf ("%s ", $$); }
     | TYPENAME '(' expr ')'
			{ printf ("%s <cast> ", $1); }
     | expr '+' expr	{ printf ("+ "); }
     | expr '=' expr	{ printf ("= "); }
     ;

decl : TYPENAME declarator ';'
			{ printf ("%s <declare> ", $1); }
     | TYPENAME declarator '=' expr ';'
			{ printf ("%s <init-declare> ", $1); }
     ;

declarator : ID		{ printf ("\"%s\" ", $1); }
     | '(' declarator ')'
     ;

%%

#include <ctype.h>
#include <stdlib.h>
#include <string.h>

int
main (int argc, char** argv)
{
  if (argc != 2)
    abort ();
  if (!freopen (argv[1], "r", stdin))
    abort ();
  exit (yyparse ());
}

#if YYPURE
int
yylex (YYSTYPE *lvalp)
#else
int
yylex ()
#endif
{
  char buffer[256];
  int c;
  unsigned int i;

#if YYPURE
# define yylval (*lvalp)

#endif

  while (1)
    {
      c = getchar ();
      switch (c)
	{
	case EOF:
	  return 0;
	case ' ': case '\t': case '\n': case '\f':
	  break;
	default:
	  if (isalpha (c))
	    {
	      i = 0;

	      do
		{
		  buffer[i++] = c;
		  if (i == sizeof buffer - 1)
		    abort ();
		  c = getchar ();
		}
	      while (isalnum (c) || c == '_');

	      ungetc (c, stdin);
	      buffer[i++] = 0;
	      yylval = strcpy (malloc (i), buffer);
	      return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
	    }
	  return c;
	}
    }
}

int
yyerror (
#if YYPURE && YYLSP_NEEDED
         YYLTYPE *yylocation,
#endif
         const char *s
        )
{
#if YYPURE && YYLSP_NEEDED
  (void) *yylocation;
#endif
  fprintf (stderr, "%s\n", s);
  return 0;
}


static YYSTYPE
stmtMerge (YYSTYPE x0, YYSTYPE x1)
{
  /* Use the arguments. */
  (void) x0;
  (void) x1;
  printf ("<OR> ");
  return "";
}

_ATEOF



cat >test-input <<'_ATEOF'


z + q;

T x;

T x = y;

x = y;

T (x) + y;

T (x);

T (y) = z + q;

T (y y) = z + q;

z + q;

@

This is total garbage, but it should be ignored.
_ATEOF


$at_traceoff
$at_verbose "cxx-type.at:298: bison -o types.c types.y"
echo cxx-type.at:298 >$at_check_line_file
( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:298: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "cxx-type.at:298: \$CC \$CFLAGS \$CPPFLAGS types.c -o types"
echo cxx-type.at:298 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS types.c -o types ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:298: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "cxx-type.at:300: \$PREPARSER ./types test-input | sed 's/  *\$//'"
echo cxx-type.at:300 >$at_check_line_file
( $at_traceon; $PREPARSER ./types test-input | sed 's/  *$//' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "syntax error
" | $at_diff - $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "z q +
\"x\" T <declare>
\"x\" y T <init-declare>
x y =
x T <cast> y +
\"x\" T <declare> x T <cast> <OR>
\"y\" z q + T <init-declare> y T <cast> z q + = <OR>
y
z q +
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:300: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  102 ) # 102. cxx-type.at:302: GLR: Merge conflicting parses, pure, locations
    at_setup_line='cxx-type.at:302'
    $at_verbose "102. cxx-type.at:302: testing GLR: Merge conflicting parses, pure, locations..."
    $at_quiet $ECHO_N "102: cxx-type.at:302   $ECHO_C"
    (
      $at_traceon

cat >types.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Simplified C++ Type and Expression Grammar.  */

%pure-parser %locations

%{
  #include <stdio.h>
  #define YYSTYPE const char*
  #define YYLTYPE int
 static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);
  #define YYINITDEPTH 10
  int yyerror (
#if YYPURE && YYLSP_NEEDED
               YYLTYPE *yylocation,
#endif
               const char *s
              );

  #if YYPURE
  int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
  #else
  int yylex (void);
  #endif

%}

%token TYPENAME ID

%right '='
%left '+'

%glr-parser

%%

prog :
     | prog stmt   { printf ("\n"); }
     ;

stmt : expr ';'  %merge <stmtMerge>
     | decl      %merge <stmtMerge>
     | error ';'
     | '@'  { YYACCEPT; }
     ;

expr : ID 		{ printf ("%s ", $$); }
     | TYPENAME '(' expr ')'
			{ printf ("%s <cast> ", $1); }
     | expr '+' expr	{ printf ("+ "); }
     | expr '=' expr	{ printf ("= "); }
     ;

decl : TYPENAME declarator ';'
			{ printf ("%s <declare> ", $1); }
     | TYPENAME declarator '=' expr ';'
			{ printf ("%s <init-declare> ", $1); }
     ;

declarator : ID		{ printf ("\"%s\" ", $1); }
     | '(' declarator ')'
     ;

%%

#include <ctype.h>
#include <stdlib.h>
#include <string.h>

int
main (int argc, char** argv)
{
  if (argc != 2)
    abort ();
  if (!freopen (argv[1], "r", stdin))
    abort ();
  exit (yyparse ());
}

#if YYPURE
int
yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
#else
int
yylex ()
#endif
{
  char buffer[256];
  int c;
  unsigned int i;

#if YYPURE
# define yylval (*lvalp)
  (void) llocp;
#endif

  while (1)
    {
      c = getchar ();
      switch (c)
	{
	case EOF:
	  return 0;
	case ' ': case '\t': case '\n': case '\f':
	  break;
	default:
	  if (isalpha (c))
	    {
	      i = 0;

	      do
		{
		  buffer[i++] = c;
		  if (i == sizeof buffer - 1)
		    abort ();
		  c = getchar ();
		}
	      while (isalnum (c) || c == '_');

	      ungetc (c, stdin);
	      buffer[i++] = 0;
	      yylval = strcpy (malloc (i), buffer);
	      return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
	    }
	  return c;
	}
    }
}

int
yyerror (
#if YYPURE && YYLSP_NEEDED
         YYLTYPE *yylocation,
#endif
         const char *s
        )
{
#if YYPURE && YYLSP_NEEDED
  (void) *yylocation;
#endif
  fprintf (stderr, "%s\n", s);
  return 0;
}


static YYSTYPE
stmtMerge (YYSTYPE x0, YYSTYPE x1)
{
  /* Use the arguments. */
  (void) x0;
  (void) x1;
  printf ("<OR> ");
  return "";
}

_ATEOF



cat >test-input <<'_ATEOF'


z + q;

T x;

T x = y;

x = y;

T (x) + y;

T (x);

T (y) = z + q;

T (y y) = z + q;

z + q;

@

This is total garbage, but it should be ignored.
_ATEOF


$at_traceoff
$at_verbose "cxx-type.at:304: bison -o types.c types.y"
echo cxx-type.at:304 >$at_check_line_file
( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:304: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "cxx-type.at:304: \$CC \$CFLAGS \$CPPFLAGS types.c -o types"
echo cxx-type.at:304 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS types.c -o types ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:304: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "cxx-type.at:306: \$PREPARSER ./types test-input | sed 's/  *\$//'"
echo cxx-type.at:306 >$at_check_line_file
( $at_traceon; $PREPARSER ./types test-input | sed 's/  *$//' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "syntax error
" | $at_diff - $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "z q +
\"x\" T <declare>
\"x\" y T <init-declare>
x y =
x T <cast> y +
\"x\" T <declare> x T <cast> <OR>
\"y\" z q + T <init-declare> y T <cast> z q + = <OR>
y
z q +
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:306: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;

  103 ) # 103. cxx-type.at:309: GLR: Verbose messages, resolve ambiguity, impure, no locations
    at_setup_line='cxx-type.at:309'
    $at_verbose "103. cxx-type.at:309: testing GLR: Verbose messages, resolve ambiguity, impure, no locations..."
    $at_quiet $ECHO_N "103: cxx-type.at:309   $ECHO_C"
    (
      $at_traceon

cat >types.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Simplified C++ Type and Expression Grammar.  */

%error-verbose

%{
  #include <stdio.h>
  #define YYSTYPE const char*
  #define YYLTYPE int
 static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);
  #define YYINITDEPTH 10
  int yyerror (
#if YYPURE && YYLSP_NEEDED
               YYLTYPE *yylocation,
#endif
               const char *s
              );

  #if YYPURE
  int yylex (YYSTYPE *lvalp);
  #else
  int yylex (void);
  #endif

%}

%token TYPENAME ID

%right '='
%left '+'

%glr-parser

%%

prog :
     | prog stmt   { printf ("\n"); }
     ;

stmt : expr ';'  %merge <stmtMerge>
     | decl      %merge <stmtMerge>
     | error ';'
     | '@'  { YYACCEPT; }
     ;

expr : ID 		{ printf ("%s ", $$); }
     | TYPENAME '(' expr ')'
			{ printf ("%s <cast> ", $1); }
     | expr '+' expr	{ printf ("+ "); }
     | expr '=' expr	{ printf ("= "); }
     ;

decl : TYPENAME declarator ';'
			{ printf ("%s <declare> ", $1); }
     | TYPENAME declarator '=' expr ';'
			{ printf ("%s <init-declare> ", $1); }
     ;

declarator : ID		{ printf ("\"%s\" ", $1); }
     | '(' declarator ')'
     ;

%%

#include <ctype.h>
#include <stdlib.h>
#include <string.h>

int
main (int argc, char** argv)
{
  if (argc != 2)
    abort ();
  if (!freopen (argv[1], "r", stdin))
    abort ();
  exit (yyparse ());
}

#if YYPURE
int
yylex (YYSTYPE *lvalp)
#else
int
yylex ()
#endif
{
  char buffer[256];
  int c;
  unsigned int i;

#if YYPURE
# define yylval (*lvalp)

#endif

  while (1)
    {
      c = getchar ();
      switch (c)
	{
	case EOF:
	  return 0;
	case ' ': case '\t': case '\n': case '\f':
	  break;
	default:
	  if (isalpha (c))
	    {
	      i = 0;

	      do
		{
		  buffer[i++] = c;
		  if (i == sizeof buffer - 1)
		    abort ();
		  c = getchar ();
		}
	      while (isalnum (c) || c == '_');

	      ungetc (c, stdin);
	      buffer[i++] = 0;
	      yylval = strcpy (malloc (i), buffer);
	      return isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
	    }
	  return c;
	}
    }
}

int
yyerror (
#if YYPURE && YYLSP_NEEDED
         YYLTYPE *yylocation,
#endif
         const char *s
        )
{
#if YYPURE && YYLSP_NEEDED
  (void) *yylocation;
#endif
  fprintf (stderr, "%s\n", s);
  return 0;
}


static YYSTYPE
stmtMerge (YYSTYPE x0, YYSTYPE x1)
{
  /* Use the arguments. */
  (void) x0;
  (void) x1;
  printf ("<OR> ");
  return "";
}

_ATEOF



cat >test-input <<'_ATEOF'


z + q;

T x;

T x = y;

x = y;

T (x) + y;

T (x);

T (y) = z + q;

T (y y) = z + q;

z + q;

@

This is total garbage, but it should be ignored.
_ATEOF


$at_traceoff
$at_verbose "cxx-type.at:311: bison -o types.c types.y"
echo cxx-type.at:311 >$at_check_line_file
( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:311: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "cxx-type.at:311: \$CC \$CFLAGS \$CPPFLAGS types.c -o types"
echo cxx-type.at:311 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS types.c -o types ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:311: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


$at_traceoff
$at_verbose "cxx-type.at:313: \$PREPARSER ./types test-input | sed 's/  *\$//'"
echo cxx-type.at:313 >$at_check_line_file
( $at_traceon; $PREPARSER ./types test-input | sed 's/  *$//' ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "syntax error, unexpected ID, expecting '=' or '+' or ')'
" | $at_diff - $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "z q +
\"x\" T <declare>
\"x\" y T <init-declare>
x y =
x T <cast> y +
\"x\" T <declare> x T <cast> <OR>
\"y\" z q + T <init-declare> y T <cast> z q + = <OR>
y
z q +
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "cxx-type.at:313: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  banner-15 ) # Banner 15. glr-regr1.at:19
    cat <<\_ATEOF

GLR Regression Test #1.

_ATEOF
    ;;

  104 ) # 104. glr-regr1.at:21: Badly Collapsed GLR States
    at_setup_line='glr-regr1.at:21'
    $at_verbose "104. glr-regr1.at:21: testing Badly Collapsed GLR States..."
    $at_quiet $ECHO_N "104: glr-regr1.at:21   $ECHO_C"
    (
      $at_traceon


cat >glr-regr1.y <<'_ATEOF'
%{
#if HAVE_CONFIG_H
# include <config.h>
  /* We don't need perfect functions for these tests. */
# undef malloc
# undef memcmp
# undef realloc
#endif
%}

/* Regression Test: Improper state compression */
/* Reported by Scott McPeak */

%{
#include <stdio.h>

#define YYSTYPE int
static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1);
int yylex (void);
int yyerror (char const *msg);
%}


%glr-parser


/* -------- productions ------ */
%%

StartSymbol: E  { $$=0; }                   %merge <exprMerge>
           ;

E: E 'P' E { $$=1; printf("E -> E 'P' E\n"); }  %merge <exprMerge>
 | 'B'     { $$=2; printf("E -> 'B'\n"); }      %merge <exprMerge>
 ;



/* ---------- C code ----------- */
%%

static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1)
{
  (void) x0;
  (void) x1;
  printf ("<OR>\n");
  return 0;
}

int
main (void)
{
  return yyparse ();
}

int
yyerror (char const *msg)
{
  fprintf (stderr, "%s\n", msg);
  exit (4);
}


int
yylex (void)
{
  for (;;)
    {
      int ch = getchar ();
      if (ch == EOF)
	return 0;
      else if (ch == 'B' || ch == 'P')
	return ch;
    }
}
_ATEOF



$at_traceoff
$at_verbose "glr-regr1.at:93: bison -o glr-regr1.c glr-regr1.y"
echo glr-regr1.at:93 >$at_check_line_file
( $at_traceon; bison -o glr-regr1.c glr-regr1.y ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
echo >>$at_stderr; echo "glr-regr1.y: conflicts: 1 shift/reduce
" | $at_diff - $at_stderr >&5 || at_failed=:
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "glr-regr1.at:93: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "glr-regr1.at:94: \$CC \$CFLAGS \$CPPFLAGS glr-regr1.c -o glr-regr1"
echo glr-regr1.at:94 >$at_check_line_file
( $at_traceon; $CC $CFLAGS $CPPFLAGS glr-regr1.c -o glr-regr1 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
(echo stderr:; cat $at_stderr) >&5
$at_diff $at_devnull $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "glr-regr1.at:94: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon

$at_traceoff
$at_verbose "glr-regr1.at:105: echo BPBPB | ./glr-regr1"
echo glr-regr1.at:105 >$at_check_line_file
( $at_traceon; echo BPBPB | ./glr-regr1 ) >$at_stdout 2>$at_stder1
at_status=$?
grep '^ *+' $at_stder1 >&2
grep -v '^ *+' $at_stder1 >$at_stderr
at_failed=false
$at_diff $at_devnull $at_stderr >&5 || at_failed=:
echo >>$at_stdout; echo "E -> 'B'
E -> 'B'
E -> E 'P' E
E -> 'B'
E -> E 'P' E
E -> 'B'
E -> E 'P' E
E -> E 'P' E
<OR>
" | $at_diff - $at_stdout >&5 || at_failed=:
case $at_status in
   77) exit 77;;
   0) ;;
   *) $at_verbose "glr-regr1.at:105: exit code was $at_status, expected 0" >&2
      at_failed=:;;
esac

$at_failed && exit 1
$at_traceon


    $at_times_skip || times >$at_times_file
    )
    at_status=$?
    ;;


  * )
    echo "$as_me: no such test group: $at_group" >&2
    continue
    ;;
  esac

  # Be sure to come back to the suite directory, in particular
  # since below we might `rm' the group directory we are in currently.
  cd $at_suite_dir

  case $at_group in
    banner-*) ;;
    *)
      if test ! -f $at_check_line_file; then
        sed "s/^ */$as_me: warning: /" <<_ATEOF
        A failure happened in a test group before any test could be
        run. This means that test suite is improperly designed.  Please
        report this failure to <bug-bison@gnu.org>.
_ATEOF
    	echo "$at_setup_line" >$at_check_line_file
      fi
      at_group_count=`expr 1 + $at_group_count`
      $at_verbose $ECHO_N "$at_group. $at_setup_line: $ECHO_C"
      case $at_status in
        0)  at_msg="ok"
            at_pass_list="$at_pass_list $at_group"
            # Cleanup the group directory, unless the user wants the files.
            $at_debug_p || rm -rf $at_group_dir
            ;;
        77) at_msg="ok (skipped near \``cat $at_check_line_file`')"
            at_skip_list="$at_skip_list $at_group"
            # Cleanup the group directory, unless the user wants the files.
            $at_debug_p || rm -rf $at_group_dir
            ;;
        *)  at_msg="FAILED near \``cat $at_check_line_file`'"
            at_fail_list="$at_fail_list $at_group"
            # Up failure, keep the group directory for autopsy.
            # Create the debugging script.
            {
              echo "#! /bin/sh"
              echo 'test "${ZSH_VERSION+set}" = set && alias -g '\''${1+"$@"}'\''='\''"$@"'\'''
              echo "cd $at_dir"
              echo 'exec ${CONFIG_SHELL-'"$SHELL"'}' "$0" \
                   '-v -d' "$at_debug_args" "$at_group" '${1+"$@"}'
              echo 'exit 1'
            } >$at_group_dir/run
            chmod +x $at_group_dir/run
            ;;
      esac
      echo $at_msg
      at_log_msg="$at_group. $at_setup_line: $at_msg"
      # If the group failed, $at_times_file is not available.
      test -f $at_times_file &&
        at_log_msg="$at_log_msg	(`sed 1d $at_times_file`)"
      echo "$at_log_msg" >&6
      $at_errexit_p && test -n "$at_fail_list" && break
      ;;
  esac
done

# Back to the top directory, in particular because we might
# rerun the suite verbosely.
cd $at_dir

# Compute the duration of the suite.
at_stop_date=`date`
at_stop_time=`(date +%s) 2>/dev/null`
echo "$as_me: ending at: $at_stop_date" >&6
at_duration_s=`(expr $at_stop_time - $at_start_time) 2>/dev/null`
at_duration_m=`(expr $at_duration_s / 60) 2>/dev/null`
at_duration_h=`(expr $at_duration_m / 60) 2>/dev/null`
at_duration_s=`(expr $at_duration_s % 60) 2>/dev/null`
at_duration_m=`(expr $at_duration_m % 60) 2>/dev/null`
at_duration="${at_duration_h}h ${at_duration_m}m ${at_duration_s}s"
if test "$at_duration" != "h m s"; then
  echo "$as_me: test suite duration: $at_duration" >&6
fi

# Wrap up the test suite with summary statistics.
at_skip_count=`set dummy $at_skip_list; shift; echo $#`
at_fail_count=`set dummy $at_fail_list; shift; echo $#`
if test $at_fail_count = 0; then
  if test $at_skip_count = 0; then
    sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
## All $at_group_count tests were successful. ##
_ASBOX
  else
    sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
## All $at_group_count tests were successful ($at_skip_count skipped). ##
_ASBOX
  fi
elif test $at_debug_p = false; then
  if $at_errexit_p; then
    cat <<\_ASBOX
## ------------------------------------------------------------ ##
## ERROR: One of the tests failed, inhibiting subsequent tests. ##
## ------------------------------------------------------------ ##
_ASBOX
  else
    sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
## ERROR: Suite unsuccessful, $at_fail_count of $at_group_count tests failed. ##
_ASBOX
  fi

  # Normalize the names so that `ls' lists them in order.
  echo 'You may investigate any problem if you feel able to do so, in which'
  echo 'case the test suite provides a good starting point.'
  echo
  echo 'Now, failed tests will be executed again, verbosely, and logged'
  echo 'in the file '$as_me'.log.'

  {
    echo
    echo
    cat <<\_ASBOX
## ------------------------ ##
## Summary of the failures. ##
## ------------------------ ##
_ASBOX

    # Summary of failed and skipped tests.
    if test $at_fail_count != 0; then
      echo "Failed tests:"
      $SHELL $0 $at_fail_list --list
      echo
    fi
    if test $at_skip_count != 0; then
      echo "Skipped tests:"
      $SHELL $0 $at_skip_list --list
      echo
    fi
    echo

    cat <<\_ASBOX
## --------------------------------------- ##
## Verbosely re-running the failing tests. ##
## --------------------------------------- ##
_ASBOX
    echo
  } >&6

  exec 6>/dev/null
  $SHELL $0 -v -d $at_debug_args $at_fail_list 2>&1 | tee -a $as_me.log
  exec 6>>$as_me.log

  {
    echo
    if test -n "$at_top_srcdir"; then
      cat <<\_ASBOX
## ------------------- ##
## Configuration logs. ##
## ------------------- ##
_ASBOX
      echo
      for at_file in `find "$at_top_srcdir" -name config.log -print`
      do
  	echo "$as_me: $at_file:"
  	sed 's/^/| /' $at_file
  	echo
      done
    fi
  } >&6


  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
## $as_me.log is created. ##
_ASBOX

  echo
  echo "Please send \`$as_me.log' and all information you think might help:"
  echo
  echo "   To: <bug-bison@gnu.org>"
  echo "   Subject: [GNU Bison 1.875] $as_me:$at_fail_list failed"
  echo
  exit 1
fi

exit 0


