1#! /bin/sh
2## --------------------- ##
3## M4sh Initialization.  ##
4## --------------------- ##
5
6# Be Bourne compatible
7if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
8  emulate sh
9  NULLCMD=:
10  # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
11  # is contrary to our usage.  Disable this feature.
12  alias -g '${1+"$@"}'='"$@"'
13elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
14  set -o posix
15fi
16DUALCASE=1; export DUALCASE # for MKS sh
17
18# Support unset when possible.
19if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
20  as_unset=unset
21else
22  as_unset=false
23fi
24
25
26# Work around bugs in pre-3.0 UWIN ksh.
27$as_unset ENV MAIL MAILPATH
28PS1='$ '
29PS2='> '
30PS4='+ '
31
32# NLS nuisances.
33for as_var in \
34  LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
35  LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
36  LC_TELEPHONE LC_TIME
37do
38  if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
39    eval $as_var=C; export $as_var
40  else
41    $as_unset $as_var
42  fi
43done
44
45# Required to use basename.
46if expr a : '\(a\)' >/dev/null 2>&1; then
47  as_expr=expr
48else
49  as_expr=false
50fi
51
52if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
53  as_basename=basename
54else
55  as_basename=false
56fi
57
58
59# Name of the executable.
60as_me=`$as_basename "$0" ||
61$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
62	 X"$0" : 'X\(//\)$' \| \
63	 X"$0" : 'X\(/\)$' \| \
64	 .     : '\(.\)' 2>/dev/null ||
65echo X/"$0" |
66    sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
67  	  /^X\/\(\/\/\)$/{ s//\1/; q; }
68  	  /^X\/\(\/\).*/{ s//\1/; q; }
69  	  s/.*/./; q'`
70
71
72# PATH needs CR, and LINENO needs CR and PATH.
73# Avoid depending upon Character Ranges.
74as_cr_letters='abcdefghijklmnopqrstuvwxyz'
75as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
76as_cr_Letters=$as_cr_letters$as_cr_LETTERS
77as_cr_digits='0123456789'
78as_cr_alnum=$as_cr_Letters$as_cr_digits
79
80# The user is always right.
81if test "${PATH_SEPARATOR+set}" != set; then
82  echo "#! /bin/sh" >conf$$.sh
83  echo  "exit 0"   >>conf$$.sh
84  chmod +x conf$$.sh
85  if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
86    PATH_SEPARATOR=';'
87  else
88    PATH_SEPARATOR=:
89  fi
90  rm -f conf$$.sh
91fi
92
93
94  as_lineno_1=$LINENO
95  as_lineno_2=$LINENO
96  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
97  test "x$as_lineno_1" != "x$as_lineno_2" &&
98  test "x$as_lineno_3"  = "x$as_lineno_2"  || {
99  # Find who we are.  Look in the path if we contain no path at all
100  # relative or not.
101  case $0 in
102    *[\\/]* ) as_myself=$0 ;;
103    *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
104for as_dir in $PATH
105do
106  IFS=$as_save_IFS
107  test -z "$as_dir" && as_dir=.
108  test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
109done
110
111       ;;
112  esac
113  # We did not find ourselves, most probably we were run as `sh COMMAND'
114  # in which case we are not to be found in the path.
115  if test "x$as_myself" = x; then
116    as_myself=$0
117  fi
118  if test ! -f "$as_myself"; then
119    { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2
120   { (exit 1); exit 1; }; }
121  fi
122  case $CONFIG_SHELL in
123  '')
124    as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
125for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
126do
127  IFS=$as_save_IFS
128  test -z "$as_dir" && as_dir=.
129  for as_base in sh bash ksh sh5; do
130	 case $as_dir in
131	 /*)
132	   if ("$as_dir/$as_base" -c '
133  as_lineno_1=$LINENO
134  as_lineno_2=$LINENO
135  as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
136  test "x$as_lineno_1" != "x$as_lineno_2" &&
137  test "x$as_lineno_3"  = "x$as_lineno_2" ') 2>/dev/null; then
138	     $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
139	     $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
140	     CONFIG_SHELL=$as_dir/$as_base
141	     export CONFIG_SHELL
142	     exec "$CONFIG_SHELL" "$0" ${1+"$@"}
143	   fi;;
144	 esac
145       done
146done
147;;
148  esac
149
150  # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
151  # uniformly replaced by the line number.  The first 'sed' inserts a
152  # line-number line before each line; the second 'sed' does the real
153  # work.  The second script uses 'N' to pair each line-number line
154  # with the numbered line, and appends trailing '-' during
155  # substitution so that $LINENO is not a special case at line end.
156  # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
157  # second 'sed' script.  Blame Lee E. McMahon for sed's syntax.  :-)
158  sed '=' <$as_myself |
159    sed '
160      N
161      s,$,-,
162      : loop
163      s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
164      t loop
165      s,-$,,
166      s,^['$as_cr_digits']*\n,,
167    ' >$as_me.lineno &&
168  chmod +x $as_me.lineno ||
169    { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
170   { (exit 1); exit 1; }; }
171
172  # Don't try to exec as it changes $[0], causing all sort of problems
173  # (the dirname of $[0] is not the place where we might find the
174  # original and so on.  Autoconf is especially sensible to this).
175  . ./$as_me.lineno
176  # Exit status is that of the last command.
177  exit
178}
179
180
181case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
182  *c*,-n*) ECHO_N= ECHO_C='
183' ECHO_T='	' ;;
184  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
185  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
186esac
187
188if expr a : '\(a\)' >/dev/null 2>&1; then
189  as_expr=expr
190else
191  as_expr=false
192fi
193
194rm -f conf$$ conf$$.exe conf$$.file
195echo >conf$$.file
196if ln -s conf$$.file conf$$ 2>/dev/null; then
197  # We could just check for DJGPP; but this test a) works b) is more generic
198  # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
199  if test -f conf$$.exe; then
200    # Don't use ln at all; we don't have any links
201    as_ln_s='cp -p'
202  else
203    as_ln_s='ln -s'
204  fi
205elif ln conf$$.file conf$$ 2>/dev/null; then
206  as_ln_s=ln
207else
208  as_ln_s='cp -p'
209fi
210rm -f conf$$ conf$$.exe conf$$.file
211
212if mkdir -p . 2>/dev/null; then
213  as_mkdir_p=:
214else
215  test -d ./-p && rmdir ./-p
216  as_mkdir_p=false
217fi
218
219as_executable_p="test -f"
220
221# Sed expression to map a string onto a valid CPP name.
222as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
223
224# Sed expression to map a string onto a valid variable name.
225as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
226
227
228# IFS
229# We need space, tab and new line, in precisely that order.
230as_nl='
231'
232IFS=" 	$as_nl"
233
234# CDPATH.
235$as_unset CDPATH
236
237
238SHELL=${CONFIG_SHELL-/bin/sh}
239
240# How were we run?
241at_cli_args="$@"
242
243# Load the config file.
244for at_file in atconfig atlocal
245do
246  test -r $at_file || continue
247  . ./$at_file || { echo "$as_me: error: invalid content: $at_file" >&2
248   { (exit 1); exit 1; }; }
249done
250
251# atconfig delivers paths relative to the directory the test suite is
252# in, but the groups themselves are run in testsuite-dir/group-dir.
253if test -n "$at_top_srcdir"; then
254  builddir=../..
255  for at_dir in srcdir top_srcdir top_builddir
256  do
257    at_val=`eval echo '${'at_$at_dir'}'`
258    eval "$at_dir=\$at_val/../.."
259  done
260fi
261
262# Not all shells have the 'times' builtin; the subshell is needed to make
263# sure we discard the 'times: not found' message from the shell.
264at_times_p=false
265(times) >/dev/null 2>&1 && at_times_p=:
266
267# CLI Arguments to pass to the debugging scripts.
268at_debug_args=
269# -e sets to true
270at_errexit_p=false
271# Shall we be verbose?
272at_verbose=:
273at_quiet=echo
274
275# Shall we keep the debug scripts?  Must be `:' when the suite is
276# run by a debug script, so that the script doesn't remove itself.
277at_debug_p=false
278# Display help message?
279at_help_p=false
280# List test groups?
281at_list_p=false
282# Test groups to run
283at_groups=
284
285# The directory we are in.
286at_dir=`pwd`
287# The directory the whole suite works in.
288# Should be absolutely to let the user `cd' at will.
289at_suite_dir=$at_dir/$as_me.dir
290# The file containing the suite.
291at_suite_log=$at_dir/$as_me.log
292# The file containing the location of the last AT_CHECK.
293at_check_line_file=$at_suite_dir/at-check-line
294# The file containing the exit status of the last command.
295at_status_file=$at_suite_dir/at-status
296# The files containing the output of the tested commands.
297at_stdout=$at_suite_dir/at-stdout
298at_stder1=$at_suite_dir/at-stder1
299at_stderr=$at_suite_dir/at-stderr
300# The file containing dates.
301at_times_file=$at_suite_dir/at-times
302
303# List of the tested programs.
304at_tested='bison'
305# List of the all the test groups.
306at_groups_all=' banner-1 1 2 3 4 5 6 7 8 9 10 banner-2 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 banner-3 31 32 33 34 banner-4 35 36 37 38 39 40 banner-5 41 42 43 44 45 banner-6 46 47 48 49 banner-7 50 51 52 53 54 55 56 57 banner-8 58 59 60 61 62 63 64 65 66 67 68 69 banner-9 70 71 72 73 74 75 76 77 78 79 80 81 82 83 banner-10 84 85 86 87 88 89 90 91 92 93 94 95 96 97 banner-11 98 99 100 101 102 banner-12 103 104 banner-13 105 106 107 108 109 banner-14 110 111 112 banner-15 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 banner-16 131 132 banner-17 133 134 135 136 137 138 139 140 141 banner-18 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158'
307# As many dots as there are digits in the last test group number.
308# Used to normalize the test group numbers so that `ls' lists them in
309# numerical order.
310at_format='...'
311# Description of all the test groups.
312at_help_all='1;input.at:28;Invalid dollar-n;;
3132;input.at:46;Invalid @n;;
3143;input.at:64;Type Clashes;;
3154;input.at:89;Unused values;;
3165;input.at:157;Incompatible Aliases;;
3176;input.at:198;Torturing the Scanner;;
3187;input.at:357;Typed symbol aliases;;
3198;input.at:393;Require 1.0;;
3209;input.at:394;Require 2.3;;
32110;input.at:396;Require 100.0;;
32211;output.at:43;Output files:  -dv ;;
32312;output.at:46;Output files:  -dv >&-;;
32413;output.at:48;Output files:  -dv -o foo.c ;;
32514;output.at:50;Output files:  -dv -o foo.tab.c ;;
32615;output.at:52;Output files:  -dv -y ;;
32716;output.at:54;Output files:  -dv -b bar ;;
32817;output.at:56;Output files:  -dv -g -o foo.c ;;
32918;output.at:60;Output files: %defines %verbose  ;;
33019;output.at:62;Output files: %defines %verbose %yacc  ;;
33120;output.at:65;Output files: %defines %verbose %yacc  ;;
33221;output.at:69;Output files: %file-prefix="bar" %defines %verbose  ;;
33322;output.at:71;Output files: %output="bar.c" %defines %verbose %yacc  ;;
33423;output.at:75;Output files: %file-prefix="baz" %output="bar.c" %defines %verbose %yacc  ;;
33524;output.at:80;Output files: %defines %verbose  ;;
33625;output.at:83;Output files: %defines %verbose  -o foo.c ;;
33726;output.at:87;Output files:  --defines=foo.hpp -o foo.c++ ;;
33827;output.at:91;Output files:  -o foo.c++ --graph=foo.gph ;;
33928;output.at:105;Output files: %skeleton "lalr1.cc" %defines %verbose  ;;
34029;output.at:109;Output files: %skeleton "lalr1.cc" %defines %verbose  ;;
34130;output.at:114;Output files: %skeleton "lalr1.cc" %defines %verbose -o subdir/foo.cc ;;
34231;sets.at:66;Nullable;;
34332;sets.at:151;Broken Closure;;
34433;sets.at:193;Firsts;;
34534;sets.at:269;Accept;;
34635;reduce.at:26;Useless Terminals;;
34736;reduce.at:70;Useless Nonterminals;;
34837;reduce.at:125;Useless Rules;report;
34938;reduce.at:212;Reduced Automaton;report;
35039;reduce.at:301;Underivable Rules;report;
35140;reduce.at:342;Empty Language;;
35241;synclines.at:95;Prologue synch line;;
35342;synclines.at:115;%union synch line;;
35443;synclines.at:138;Postprologue synch line;;
35544;synclines.at:157;Action synch line;;
35645;synclines.at:175;Epilogue synch line;;
35746;headers.at:27;%union and --defines;;
35847;headers.at:77;Invalid CPP guards: input/input;;
35948;headers.at:78;Invalid CPP guards: 9foo;;
36049;headers.at:87;export YYLTYPE;;
36150;actions.at:25;Mid-rule actions;;
36251;actions.at:91;Exotic Dollars;;
36352;actions.at:527;Printers and Destructors : ;;
36453;actions.at:528;Printers and Destructors with union: ;;
36554;actions.at:533;Printers and Destructors : %defines %skeleton "lalr1.cc";c++;
36655;actions.at:534;Printers and Destructors with union: %defines %skeleton "lalr1.cc";c++;
36756;actions.at:536;Printers and Destructors : %glr-parser;;
36857;actions.at:537;Printers and Destructors with union: %glr-parser;;
36958;conflicts.at:32;S/R in initial;;
37059;conflicts.at:52;%nonassoc and eof;;
37160;conflicts.at:128;Unresolved SR Conflicts;report;
37261;conflicts.at:235;Resolved SR Conflicts;report;
37362;conflicts.at:357;Defaulted Conflicted Reduction;report;
37463;conflicts.at:476;%expect not enough;;
37564;conflicts.at:496;%expect right;;
37665;conflicts.at:513;%expect too much;;
37766;conflicts.at:533;%expect with reduce conflicts;;
37867;conflicts.at:553;%no-default-prec without %prec;;
37968;conflicts.at:579;%no-default-prec with %prec;;
38069;conflicts.at:603;%default-prec;;
38170;calc.at:550;Calculator ;;
38271;calc.at:552;Calculator %defines;;
38372;calc.at:553;Calculator %locations;;
38473;calc.at:554;Calculator %name-prefix="calc";;
38574;calc.at:555;Calculator %verbose;;
38675;calc.at:556;Calculator %yacc;;
38776;calc.at:557;Calculator %error-verbose;;
38877;calc.at:559;Calculator %pure-parser %locations;;
38978;calc.at:560;Calculator %error-verbose %locations;;
39079;calc.at:562;Calculator %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc;;
39180;calc.at:564;Calculator %debug;;
39281;calc.at:565;Calculator %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc;;
39382;calc.at:567;Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc;;
39483;calc.at:569;Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count};;
39584;calc.at:586;Calculator %glr-parser ;;
39685;calc.at:588;Calculator %glr-parser %defines;;
39786;calc.at:589;Calculator %glr-parser %locations;;
39887;calc.at:590;Calculator %glr-parser %name-prefix="calc";;
39988;calc.at:591;Calculator %glr-parser %verbose;;
40089;calc.at:592;Calculator %glr-parser %yacc;;
40190;calc.at:593;Calculator %glr-parser %error-verbose;;
40291;calc.at:595;Calculator %glr-parser %pure-parser %locations;;
40392;calc.at:596;Calculator %glr-parser %error-verbose %locations;;
40493;calc.at:598;Calculator %glr-parser %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc;;
40594;calc.at:600;Calculator %glr-parser %debug;;
40695;calc.at:601;Calculator %glr-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc;;
40796;calc.at:603;Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc;;
40897;calc.at:605;Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count};;
40998;calc.at:621;Calculator %skeleton "lalr1.cc" %defines %locations ;c++;
41099;calc.at:622;Calculator %skeleton "lalr1.cc" %defines %locations %error-verbose %name-prefix="calc" %verbose %yacc;c++;
411100;calc.at:624;Calculator %skeleton "lalr1.cc" %defines %locations %error-verbose %debug %name-prefix="calc" %verbose %yacc;c++;
412101;calc.at:626;Calculator %skeleton "lalr1.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc;c++;
413102;calc.at:628;Calculator %skeleton "lalr1.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count};c++;
414103;calc.at:651;Calculator %skeleton "glr.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc;c++;
415104;calc.at:653;Calculator %skeleton "glr.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count};c++;
416105;torture.at:140;Big triangle;;
417106;torture.at:232;Big horizontal;;
418107;torture.at:368;Many look-ahead tokens;;
419108;torture.at:445;Exploding the Stack Size with Alloca;;
420109;torture.at:471;Exploding the Stack Size with Malloc;;
421110;existing.at:26;GNU AWK Grammar;;
422111;existing.at:364;GNU Cim Grammar;;
423112;existing.at:980;GNU pic Grammar;;
424113;regression.at:28;Trivial grammars;;
425114;regression.at:57;Early token definitions;;
426115;regression.at:95;Braces parsing;;
427116;regression.at:117;Duplicate string;;
428117;regression.at:143;Rule Line Numbers;report;
429118;regression.at:287;Mixing %token styles;;
430119;regression.at:310;Invalid inputs;;
431120;regression.at:336;Invalid inputs with {};;
432121;regression.at:363;Token definitions;;
433122;regression.at:416;Characters Escapes;;
434123;regression.at:447;Web2c Report;report;
435124;regression.at:624;Web2c Actions;report;
436125;regression.at:866;Dancer ;;
437126;regression.at:867;Dancer %glr-parser;;
438127;regression.at:868;Dancer %skeleton "lalr1.cc";c++;
439128;regression.at:963;Expecting two tokens ;;
440129;regression.at:964;Expecting two tokens %glr-parser;;
441130;regression.at:965;Expecting two tokens %skeleton "lalr1.cc";c++;
442131;c++.at:102;Doxygen Public Documentation;;
443132;c++.at:103;Doxygen Private Documentation;;
444133;cxx-type.at:412;GLR: Resolve ambiguity, impure, no locations;;
445134;cxx-type.at:419;GLR: Resolve ambiguity, impure, locations;;
446135;cxx-type.at:425;GLR: Resolve ambiguity, pure, no locations;;
447136;cxx-type.at:432;GLR: Resolve ambiguity, pure, locations;;
448137;cxx-type.at:439;GLR: Merge conflicting parses, impure, no locations;;
449138;cxx-type.at:446;GLR: Merge conflicting parses, impure, locations;;
450139;cxx-type.at:453;GLR: Merge conflicting parses, pure, no locations;;
451140;cxx-type.at:459;GLR: Merge conflicting parses, pure, locations;;
452141;cxx-type.at:466;GLR: Verbose messages, resolve ambiguity, impure, no locations;;
453142;glr-regression.at:25;Badly Collapsed GLR States;;
454143;glr-regression.at:116;Improper handling of embedded actions and dollar(-N) in GLR parsers;;
455144;glr-regression.at:232;Improper merging of GLR delayed action sets;;
456145;glr-regression.at:337;Duplicate representation of merged trees;;
457146;glr-regression.at:432;User destructor for unresolved GLR semantic value;;
458147;glr-regression.at:502;User destructor after an error during a split parse;;
459148;glr-regression.at:566;Duplicated user destructor for lookahead;;
460149;glr-regression.at:644;Incorrectly initialized location for empty right-hand side in GLR;;
461150;glr-regression.at:740;No users destructors if stack 0 deleted;;
462151;glr-regression.at:820;Corrupted semantic options if user action cuts parse;;
463152;glr-regression.at:881;Undesirable destructors if user action cuts parse;;
464153;glr-regression.at:947;Leaked semantic values if user action cuts parse;;
465154;glr-regression.at:1078;Incorrect lookahead during deterministic GLR;;
466155;glr-regression.at:1212;Incorrect lookahead during nondeterministic GLR;;
467156;glr-regression.at:1429;Leaked semantic values when reporting ambiguity;;
468157;glr-regression.at:1519;Leaked lookahead after nondeterministic parse syntax error;;
469158;glr-regression.at:1585;Uninitialized location when reporting ambiguity;;
470'
471
472at_keywords=
473at_prev=
474for at_option
475do
476  # If the previous option needs an argument, assign it.
477  if test -n "$at_prev"; then
478    at_option=$at_prev=$at_option
479    at_prev=
480  fi
481
482  at_optarg=`expr "x$at_option" : 'x[^=]*=\(.*\)'`
483
484  # Accept the important Cygnus configure options, so we can diagnose typos.
485
486  case $at_option in
487    --help | -h )
488	at_help_p=:
489	;;
490
491    --list | -l )
492	at_list_p=:
493	;;
494
495    --version | -V )
496	echo "$as_me (GNU Bison 2.3)"
497	exit 0
498	;;
499
500    --clean | -c )
501	rm -rf $at_suite_dir $at_suite_log
502	exit 0
503	;;
504
505    --debug | -d )
506	at_debug_p=:
507	;;
508
509    --errexit | -e )
510	at_debug_p=:
511	at_errexit_p=:
512	;;
513
514    --verbose | -v )
515	at_verbose=echo; at_quiet=:
516	;;
517
518    --trace | -x )
519	at_traceon='set -vx'; at_traceoff='set +vx'
520	;;
521
522    [0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9])
523	at_groups="$at_groups$at_option "
524	;;
525
526    # Ranges
527    [0-9]- | [0-9][0-9]- | [0-9][0-9][0-9]- | [0-9][0-9][0-9][0-9]-)
528	at_range_start=`echo $at_option |tr -d '-'`
529	at_range=`echo " $at_groups_all " | \
530	  sed -e 's,^.* '$at_range_start' ,'$at_range_start' ,'`
531	at_groups="$at_groups$at_range "
532	;;
533
534    -[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | -[0-9][0-9][0-9][0-9])
535	at_range_end=`echo $at_option |tr -d '-'`
536	at_range=`echo " $at_groups_all " | \
537	  sed -e 's, '$at_range_end' .*$, '$at_range_end','`
538	at_groups="$at_groups$at_range "
539	;;
540
541    [0-9]-[0-9] | [0-9]-[0-9][0-9] | [0-9]-[0-9][0-9][0-9] | \
542    [0-9]-[0-9][0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9] | \
543    [0-9][0-9]-[0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9][0-9][0-9] | \
544    [0-9][0-9][0-9]-[0-9][0-9][0-9] | \
545    [0-9][0-9][0-9]-[0-9][0-9][0-9][0-9] | \
546    [0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9] )
547	at_range_start=`echo $at_option |sed 's,-.*,,'`
548	at_range_end=`echo $at_option |sed 's,.*-,,'`
549	# FIXME: Maybe test to make sure start <= end?
550	at_range=`echo " $at_groups_all " | \
551	  sed -e 's,^.* '$at_range_start' ,'$at_range_start' ,' \
552	      -e 's, '$at_range_end' .*$, '$at_range_end','`
553	at_groups="$at_groups$at_range "
554	;;
555
556    # Keywords.
557    --keywords | -k )
558	at_prev=--keywords
559	;;
560    --keywords=* )
561	at_keywords="$at_keywords,$at_optarg"
562	;;
563
564    *=*)
565  	at_envvar=`expr "x$at_option" : 'x\([^=]*\)='`
566  	# Reject names that are not valid shell variable names.
567  	expr "x$at_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
568  	  { echo "$as_me: error: invalid variable name: $at_envvar" >&2
569   { (exit 1); exit 1; }; }
570  	at_value=`echo "$at_optarg" | sed "s/'/'\\\\\\\\''/g"`
571  	eval "$at_envvar='$at_value'"
572  	export $at_envvar
573	# Propagate to debug scripts.
574  	at_debug_args="$at_debug_args $at_option"
575  	;;
576
577     *) echo "$as_me: invalid option: $at_option" >&2
578	echo "Try \`$0 --help' for more information." >&2
579	exit 1
580	;;
581  esac
582done
583
584# Process the --keywords
585if test -n "$at_keywords"; then
586  at_groups_selected=$at_help_all
587  for at_keyword in `IFS=,; set X $at_keywords; shift; echo ${1+$@}`
588  do
589    # It is on purpose that we match the test group titles too.
590    at_groups_selected=`echo "$at_groups_selected" |
591			grep -i "^[^;]*;[^;]*.*[; ]$at_keyword[ ;]"`
592  done
593  at_groups_selected=`echo "$at_groups_selected" | sed 's/;.*//'`
594  # Smash the end of lines.
595  at_groups_selected=`echo $at_groups_selected`
596  at_groups="$at_groups$at_groups_selected "
597fi
598
599# Selected test groups.
600test -z "$at_groups" && at_groups=$at_groups_all
601
602# Help message.
603if $at_help_p; then
604  cat <<_ATEOF
605Usage: $0 [OPTION]... [VARIABLE=VALUE]... [TESTS]
606
607Run all the tests, or the selected TESTS, and save a detailed log file.
608Upon failure, create debugging scripts.
609
610You should not change environment variables unless explicitly passed
611as command line arguments.  Set \`AUTOTEST_PATH' to select the executables
612to exercise.  Each relative directory is expanded as build and source
613directories relatively to the top level of this distribution.  E.g.,
614
615  $ $0 AUTOTEST_PATH=bin
616
617possibly amounts into
618
619  PATH=/tmp/foo-1.0/bin:/src/foo-1.0/bin:\$PATH
620_ATEOF
621cat <<_ATEOF
622
623Operation modes:
624  -h, --help     print the help message, then exit
625  -V, --version  print version number, then exit
626  -c, --clean    remove all the files this test suite might create and exit
627  -l, --list     describes all the tests, or the selected TESTS
628_ATEOF
629cat <<_ATEOF
630
631Execution tuning:
632  -k, --keywords=KEYWORDS
633	         select the tests matching all the comma separated KEYWORDS
634	         accumulates
635  -e, --errexit  abort as soon as a test fails; implies --debug
636  -v, --verbose  force more detailed output
637	         default for debugging scripts
638  -d, --debug    inhibit clean up and debug script creation
639	         default for debugging scripts
640  -x, --trace    enable tests shell tracing
641_ATEOF
642cat <<_ATEOF
643
644Report bugs to <bug-bison@gnu.org>.
645_ATEOF
646  exit 0
647fi
648
649# List of tests.
650if $at_list_p; then
651  cat <<_ATEOF
652GNU Bison 2.3 test suite test groups:
653
654 NUM: FILENAME:LINE      TEST-GROUP-NAME
655      KEYWORDS
656
657_ATEOF
658  # "  1 42  45 " => "^(1|42|45);".
659  at_groups_pattern=`echo "$at_groups" | sed 's/^  *//;s/  *$//;s/  */|/g'`
660  echo "$at_help_all" |
661    awk 'BEGIN { FS = ";" }
662	 { if ($1 !~ /^('"$at_groups_pattern"')$/) next }
663	 { if ($1) printf " %3d: %-18s %s\n", $1, $2, $3
664	   if ($4) printf "      %s\n", $4 } '
665  exit 0
666fi
667
668# Don't take risks: use only absolute directories in PATH.
669#
670# For stand-alone test suites, AUTOTEST_PATH is relative to `.'.
671#
672# For embedded test suites, AUTOTEST_PATH is relative to the top level
673# of the package.  Then expand it into build/src parts, since users
674# may create executables in both places.
675#
676# There might be directories that don't exist, but don't redirect
677# builtins' (eg., cd) stderr directly: Ultrix's sh hates that.
678AUTOTEST_PATH=`echo $AUTOTEST_PATH | tr ':' $PATH_SEPARATOR`
679at_path=
680as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
681for as_dir in $AUTOTEST_PATH $PATH
682do
683  IFS=$as_save_IFS
684  test -z "$as_dir" && as_dir=.
685  case $as_dir in
686  [\\/]* | ?:[\\/]* )
687    at_path=$at_path$PATH_SEPARATOR$as_dir
688    ;;
689  * )
690    if test -z "$at_top_builddir"; then
691      # Stand-alone test suite.
692      at_path=$at_path$PATH_SEPARATOR$as_dir
693    else
694      # Embedded test suite.
695      at_path=$at_path$PATH_SEPARATOR$at_top_builddir/$as_dir
696      at_path=$at_path$PATH_SEPARATOR$at_top_srcdir/$as_dir
697    fi
698    ;;
699esac
700done
701
702
703# Now build and simplify PATH.
704PATH=
705as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
706for as_dir in $at_path
707do
708  IFS=$as_save_IFS
709  test -z "$as_dir" && as_dir=.
710  as_dir=`(cd "$as_dir" && pwd) 2>/dev/null`
711test -d "$as_dir" || continue
712case $PATH in
713	          $as_dir                 | \
714	          $as_dir$PATH_SEPARATOR* | \
715  *$PATH_SEPARATOR$as_dir                 | \
716  *$PATH_SEPARATOR$as_dir$PATH_SEPARATOR* ) ;;
717
718  '') PATH=$as_dir ;;
719   *) PATH=$PATH$PATH_SEPARATOR$as_dir ;;
720esac
721done
722
723export PATH
724
725# Setting up the FDs.
726# 5 is the log file.  Not to be overwritten if `-d'.
727
728$at_debug_p && at_suite_log=/dev/null
729exec 5>$at_suite_log
730
731# Banners and logs.
732cat <<\_ASBOX
733## ------------------------- ##
734## GNU Bison 2.3 test suite. ##
735## ------------------------- ##
736_ASBOX
737{
738  cat <<\_ASBOX
739## ------------------------- ##
740## GNU Bison 2.3 test suite. ##
741## ------------------------- ##
742_ASBOX
743  echo
744
745  echo "$as_me: command line was:"
746  echo "  $ $0 $at_cli_args"
747  echo
748
749  # Try to find a few ChangeLogs in case it might help determining the
750  # exact version.  Use the relative dir: if the top dir is a symlink,
751  # find will not follow it (and options to follow the links are not
752  # portable), which would result in no output here.
753  if test -n "$at_top_srcdir"; then
754    cat <<\_ASBOX
755## ----------- ##
756## ChangeLogs. ##
757## ----------- ##
758_ASBOX
759    echo
760    for at_file in `find "$at_top_srcdir" -name ChangeLog -print`
761    do
762      echo "$as_me: $at_file:"
763      sed 's/^/| /;10q' $at_file
764      echo
765    done
766
767    {
768cat <<_ASUNAME
769## --------- ##
770## Platform. ##
771## --------- ##
772
773hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
774uname -m = `(uname -m) 2>/dev/null || echo unknown`
775uname -r = `(uname -r) 2>/dev/null || echo unknown`
776uname -s = `(uname -s) 2>/dev/null || echo unknown`
777uname -v = `(uname -v) 2>/dev/null || echo unknown`
778
779/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
780/bin/uname -X     = `(/bin/uname -X) 2>/dev/null     || echo unknown`
781
782/bin/arch              = `(/bin/arch) 2>/dev/null              || echo unknown`
783/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null       || echo unknown`
784/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
785hostinfo               = `(hostinfo) 2>/dev/null               || echo unknown`
786/bin/machine           = `(/bin/machine) 2>/dev/null           || echo unknown`
787/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null       || echo unknown`
788/bin/universe          = `(/bin/universe) 2>/dev/null          || echo unknown`
789
790_ASUNAME
791
792as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
793for as_dir in $PATH
794do
795  IFS=$as_save_IFS
796  test -z "$as_dir" && as_dir=.
797  echo "PATH: $as_dir"
798done
799
800}
801    echo
802  fi
803
804  # Contents of the config files.
805  for at_file in atconfig atlocal
806  do
807    test -r $at_file || continue
808    echo "$as_me: $at_file:"
809    sed 's/^/| /' $at_file
810    echo
811  done
812
813  cat <<\_ASBOX
814## ---------------- ##
815## Tested programs. ##
816## ---------------- ##
817_ASBOX
818  echo
819} >&5
820
821# Report what programs are being tested.
822for at_program in : $at_tested
823do
824  test "$at_program" = : && continue
825  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
826for as_dir in $PATH
827do
828  IFS=$as_save_IFS
829  test -z "$as_dir" && as_dir=.
830  test -f $as_dir/$at_program && break
831done
832
833  if test -f $as_dir/$at_program; then
834    {
835      echo "local.at:216: $as_dir/$at_program --version"
836      $as_dir/$at_program --version
837      echo
838    } >&5 2>&1
839  else
840    { { echo "$as_me:$LINENO: error: cannot find $at_program" >&5
841echo "$as_me: error: cannot find $at_program" >&2;}
842   { (exit 1); exit 1; }; }
843  fi
844done
845
846{
847  cat <<\_ASBOX
848## ------------------ ##
849## Running the tests. ##
850## ------------------ ##
851_ASBOX
852} >&5
853
854at_start_date=`date`
855at_start_time=`(date +%s) 2>/dev/null`
856echo "$as_me: starting at: $at_start_date" >&5
857at_xpass_list=
858at_xfail_list=
859at_pass_list=
860at_fail_list=
861at_skip_list=
862at_group_count=0
863
864# Create the master directory if it doesn't already exist.
865test -d $at_suite_dir ||
866  mkdir $at_suite_dir ||
867  { { echo "$as_me:$LINENO: error: cannot create $at_suite_dir" >&5
868echo "$as_me: error: cannot create $at_suite_dir" >&2;}
869   { (exit 1); exit 1; }; }
870
871# Can we diff with `/dev/null'?  DU 5.0 refuses.
872if diff /dev/null /dev/null >/dev/null 2>&1; then
873  at_devnull=/dev/null
874else
875  at_devnull=$at_suite_dir/devnull
876  cp /dev/null $at_devnull
877fi
878
879# Use `diff -u' when possible.
880if diff -u $at_devnull $at_devnull >/dev/null 2>&1; then
881  at_diff='diff -u'
882else
883  at_diff=diff
884fi
885
886
887for at_group in $at_groups
888do
889  # Be sure to come back to the top test directory.
890  cd $at_suite_dir
891
892  case $at_group in
893    banner-*)
894      at_group_log=$at_suite_log
895      ;;
896
897    *)
898      # Skip tests we already run (using --keywords makes it easy to get
899      # duplication).
900      case " $at_pass_test $at_skip_test $at_fail_test " in
901	*" $at_group "* ) continue;;
902      esac
903
904      # Normalize the test group number.
905      at_group_normalized=`expr "00000$at_group" : ".*\($at_format\)"`
906
907      # Create a fresh directory for the next test group, and enter.
908      at_group_dir=$at_suite_dir/$at_group_normalized
909      at_group_log=$at_group_dir/$as_me.log
910      rm -rf $at_group_dir
911      mkdir $at_group_dir ||
912	{ { echo "$as_me:$LINENO: error: cannot create $at_group_dir" >&5
913echo "$as_me: error: cannot create $at_group_dir" >&2;}
914   { (exit 1); exit 1; }; }
915      cd $at_group_dir
916      ;;
917  esac
918
919  echo 0 > $at_status_file
920
921  # Clearly separate the test groups when verbose.
922  test $at_group_count != 0 && $at_verbose
923
924  # In verbose mode, append to the log file *and* show on
925  # the standard output; in quiet mode only write to the log
926  if test $at_verbose = echo; then
927    at_tee_pipe="tee -a $at_group_log"
928  else
929    at_tee_pipe="cat >> $at_group_log"
930  fi
931
932  case $at_group in
933
934  banner-1 ) # Banner 1. input.at:19
935    cat <<\_ATEOF
936
937Input Processing.
938
939_ATEOF
940    ;;
941
942  1 ) # 1. input.at:28: Invalid dollar-n
943    at_setup_line='input.at:28'
944    at_desc='Invalid dollar-n'
945    $at_quiet $ECHO_N "  1: Invalid dollar-n                             $ECHO_C"
946    at_xfail=no
947    (
948      echo "1. input.at:28: testing ..."
949      $at_traceon
950
951
952cat >input.y <<'_ATEOF'
953%%
954exp: { $$ = $1 ; };
955_ATEOF
956
957
958$at_traceoff
959echo "input.at:37: bison input.y"
960echo input.at:37 >$at_check_line_file
961( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
962at_status=$?
963grep '^ *+' $at_stder1 >&2
964grep -v '^ *+' $at_stder1 >$at_stderr
965at_failed=false
966echo >>$at_stderr; echo "input.y:2.13-14: integer out of range: \`\$1'
967" | $at_diff - $at_stderr || at_failed=:
968$at_diff $at_devnull $at_stdout || at_failed=:
969case $at_status in
970   77) echo 77 > $at_status_file
971            exit 77;;
972   1) ;;
973   *) echo "input.at:37: exit code was $at_status, expected 1"
974      at_failed=:;;
975esac
976if $at_failed; then
977
978  echo 1 > $at_status_file
979  exit 1
980fi
981
982$at_traceon
983
984
985      $at_traceoff
986      $at_times_p && times >$at_times_file
987    ) 5>&1 2>&1 | eval $at_tee_pipe
988    at_status=`cat $at_status_file`
989    ;;
990
991  2 ) # 2. input.at:46: Invalid @n
992    at_setup_line='input.at:46'
993    at_desc='Invalid @n'
994    $at_quiet $ECHO_N "  2: Invalid @n                                   $ECHO_C"
995    at_xfail=no
996    (
997      echo "2. input.at:46: testing ..."
998      $at_traceon
999
1000
1001cat >input.y <<'_ATEOF'
1002%%
1003exp: { @$ = @1 ; };
1004_ATEOF
1005
1006
1007$at_traceoff
1008echo "input.at:55: bison input.y"
1009echo input.at:55 >$at_check_line_file
1010( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
1011at_status=$?
1012grep '^ *+' $at_stder1 >&2
1013grep -v '^ *+' $at_stder1 >$at_stderr
1014at_failed=false
1015echo >>$at_stderr; echo "input.y:2.13-14: integer out of range: \`@1'
1016" | $at_diff - $at_stderr || at_failed=:
1017$at_diff $at_devnull $at_stdout || at_failed=:
1018case $at_status in
1019   77) echo 77 > $at_status_file
1020            exit 77;;
1021   1) ;;
1022   *) echo "input.at:55: exit code was $at_status, expected 1"
1023      at_failed=:;;
1024esac
1025if $at_failed; then
1026
1027  echo 1 > $at_status_file
1028  exit 1
1029fi
1030
1031$at_traceon
1032
1033
1034      $at_traceoff
1035      $at_times_p && times >$at_times_file
1036    ) 5>&1 2>&1 | eval $at_tee_pipe
1037    at_status=`cat $at_status_file`
1038    ;;
1039
1040  3 ) # 3. input.at:64: Type Clashes
1041    at_setup_line='input.at:64'
1042    at_desc='Type Clashes'
1043    $at_quiet $ECHO_N "  3: Type Clashes                                 $ECHO_C"
1044    at_xfail=no
1045    (
1046      echo "3. input.at:64: testing ..."
1047      $at_traceon
1048
1049
1050cat >input.y <<'_ATEOF'
1051%token foo
1052%type <bar> exp
1053%%
1054exp: foo {} foo
1055   | foo
1056   | /* Empty. */
1057   ;
1058_ATEOF
1059
1060
1061$at_traceoff
1062echo "input.at:80: bison input.y"
1063echo input.at:80 >$at_check_line_file
1064( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
1065at_status=$?
1066grep '^ *+' $at_stder1 >&2
1067grep -v '^ *+' $at_stder1 >$at_stderr
1068at_failed=false
1069echo >>$at_stderr; echo "input.y:4.6-15: warning: type clash on default action: <bar> != <>
1070input.y:5.6-8: warning: type clash on default action: <bar> != <>
1071input.y:6.5: warning: empty rule for typed nonterminal, and no action
1072" | $at_diff - $at_stderr || at_failed=:
1073$at_diff $at_devnull $at_stdout || at_failed=:
1074case $at_status in
1075   77) echo 77 > $at_status_file
1076            exit 77;;
1077   0) ;;
1078   *) echo "input.at:80: exit code was $at_status, expected 0"
1079      at_failed=:;;
1080esac
1081if $at_failed; then
1082
1083  echo 1 > $at_status_file
1084  exit 1
1085fi
1086
1087$at_traceon
1088
1089
1090      $at_traceoff
1091      $at_times_p && times >$at_times_file
1092    ) 5>&1 2>&1 | eval $at_tee_pipe
1093    at_status=`cat $at_status_file`
1094    ;;
1095
1096  4 ) # 4. input.at:89: Unused values
1097    at_setup_line='input.at:89'
1098    at_desc='Unused values'
1099    $at_quiet $ECHO_N "  4: Unused values                                $ECHO_C"
1100    at_xfail=no
1101    (
1102      echo "4. input.at:89: testing ..."
1103      $at_traceon
1104
1105
1106cat >input.y <<'_ATEOF'
1107%token <integer> INT
1108%type <integer> a b c d e f g h i j k l
1109%destructor { destroy ($$); } INT a b c d e f g h i j k l
1110%%
1111start:
1112  'a' a { $2 } | 'b' b { $2 } | 'c' c { $2 } | 'd' d { $2 } | 'e' e { $2 }
1113| 'f' f { $2 } | 'g' g { $2 } | 'h' h { $2 } | 'i' i { $2 } | 'j' j { $2 }
1114| 'k' k { $2 } | 'l' l { $2 }
1115;
1116
1117a: INT | INT { } INT { } INT { };
1118b: INT | /* empty */;
1119c: INT | INT { $1 } INT { } INT { };
1120d: INT | INT { } INT { $1 } INT { };
1121e: INT | INT { } INT {  } INT { $1 };
1122f: INT | INT { } INT {  } INT { $$ = $1 + $3 + $5; };
1123g: INT | INT { $$ } INT { $$ } INT { };
1124h: INT | INT { $$ } INT { $$ = $2 } INT { };
1125i: INT | INT INT { } { $$ = $1 + $2; };
1126j: INT | INT INT { $<integer>$ = 1; } { $$ = $1 + $2; };
1127k: INT | INT INT { $$; } { $$ = $3; } { };
1128l: INT | INT { $$ = $1; } INT { $$ = $2 + $3; } INT { $$ = $4 + $5; };
1129
1130_ATEOF
1131
1132
1133$at_traceoff
1134echo "input.at:148: bison input.y"
1135echo input.at:148 >$at_check_line_file
1136( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
1137at_status=$?
1138grep '^ *+' $at_stder1 >&2
1139grep -v '^ *+' $at_stder1 >$at_stderr
1140at_failed=false
1141echo >>$at_stderr; echo "input.y:11.10-32: warning: unset value: \$\$
1142input.y:11.10-32: warning: unused value: \$1
1143input.y:11.10-32: warning: unused value: \$3
1144input.y:11.10-32: warning: unused value: \$5
1145input.y:12.9: warning: empty rule for typed nonterminal, and no action
1146input.y:13.10-35: warning: unset value: \$\$
1147input.y:13.10-35: warning: unused value: \$3
1148input.y:13.10-35: warning: unused value: \$5
1149input.y:14.10-35: warning: unset value: \$\$
1150input.y:14.10-35: warning: unused value: \$3
1151input.y:14.10-35: warning: unused value: \$5
1152input.y:15.10-36: warning: unset value: \$\$
1153input.y:15.10-36: warning: unused value: \$3
1154input.y:15.10-36: warning: unused value: \$5
1155input.y:17.10-38: warning: unset value: \$\$
1156input.y:17.10-38: warning: unused value: \$1
1157input.y:17.10-38: warning: unused value: \$2
1158input.y:17.10-38: warning: unused value: \$3
1159input.y:17.10-38: warning: unused value: \$4
1160input.y:17.10-38: warning: unused value: \$5
1161input.y:18.10-43: warning: unset value: \$\$
1162input.y:18.10-43: warning: unused value: \$1
1163input.y:18.10-43: warning: unused value: \$3
1164input.y:18.10-43: warning: unused value: \$4
1165input.y:18.10-43: warning: unused value: \$5
1166input.y:20.10-55: warning: unused value: \$3
1167input.y:21.10-41: warning: unset value: \$\$
1168input.y:21.10-41: warning: unused value: \$1
1169input.y:21.10-41: warning: unused value: \$2
1170input.y:21.10-41: warning: unused value: \$4
1171" | $at_diff - $at_stderr || at_failed=:
1172$at_diff $at_devnull $at_stdout || at_failed=:
1173case $at_status in
1174   77) echo 77 > $at_status_file
1175            exit 77;;
1176   0) ;;
1177   *) echo "input.at:148: exit code was $at_status, expected 0"
1178      at_failed=:;;
1179esac
1180if $at_failed; then
1181
1182  echo 1 > $at_status_file
1183  exit 1
1184fi
1185
1186$at_traceon
1187
1188
1189      $at_traceoff
1190      $at_times_p && times >$at_times_file
1191    ) 5>&1 2>&1 | eval $at_tee_pipe
1192    at_status=`cat $at_status_file`
1193    ;;
1194
1195  5 ) # 5. input.at:157: Incompatible Aliases
1196    at_setup_line='input.at:157'
1197    at_desc='Incompatible Aliases'
1198    $at_quiet $ECHO_N "  5: Incompatible Aliases                         $ECHO_C"
1199    at_xfail=no
1200    (
1201      echo "5. input.at:157: testing ..."
1202      $at_traceon
1203
1204
1205cat >input.y <<'_ATEOF'
1206%token foo "foo"
1207
1208%type <bar>       foo
1209%printer {bar}    foo
1210%destructor {bar} foo
1211%left             foo
1212
1213%type <baz>       "foo"
1214%printer {baz}    "foo"
1215%destructor {baz} "foo"
1216%left             "foo"
1217
1218%%
1219exp: foo;
1220_ATEOF
1221
1222
1223$at_traceoff
1224echo "input.at:185: bison input.y"
1225echo input.at:185 >$at_check_line_file
1226( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
1227at_status=$?
1228grep '^ *+' $at_stder1 >&2
1229grep -v '^ *+' $at_stder1 >$at_stderr
1230at_failed=false
1231echo >>$at_stderr; echo "input.y:8.7-11: %type redeclaration for foo
1232input.y:3.7-11: first declaration
1233input.y:10.13-17: %destructor redeclaration for foo
1234input.y:5.13-17: first declaration
1235input.y:9.10-14: %printer redeclaration for foo
1236input.y:10.13-17: first declaration
1237input.y:11.1-5: %left redeclaration for foo
1238input.y:6.1-5: first declaration
1239" | $at_diff - $at_stderr || at_failed=:
1240$at_diff $at_devnull $at_stdout || at_failed=:
1241case $at_status in
1242   77) echo 77 > $at_status_file
1243            exit 77;;
1244   1) ;;
1245   *) echo "input.at:185: exit code was $at_status, expected 1"
1246      at_failed=:;;
1247esac
1248if $at_failed; then
1249
1250  echo 1 > $at_status_file
1251  exit 1
1252fi
1253
1254$at_traceon
1255
1256
1257      $at_traceoff
1258      $at_times_p && times >$at_times_file
1259    ) 5>&1 2>&1 | eval $at_tee_pipe
1260    at_status=`cat $at_status_file`
1261    ;;
1262
1263  6 ) # 6. input.at:198: Torturing the Scanner
1264    at_setup_line='input.at:198'
1265    at_desc='Torturing the Scanner'
1266    $at_quiet $ECHO_N "  6: Torturing the Scanner                        $ECHO_C"
1267    at_xfail=no
1268    (
1269      echo "6. input.at:198: testing ..."
1270      $at_traceon
1271
1272
1273
1274cat >input.y <<'_ATEOF'
1275_ATEOF
1276
1277$at_traceoff
1278echo "input.at:204: bison input.y"
1279echo input.at:204 >$at_check_line_file
1280( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
1281at_status=$?
1282grep '^ *+' $at_stder1 >&2
1283grep -v '^ *+' $at_stder1 >$at_stderr
1284at_failed=false
1285echo >>$at_stderr; echo "input.y:1.1: syntax error, unexpected end of file
1286" | $at_diff - $at_stderr || at_failed=:
1287$at_diff $at_devnull $at_stdout || at_failed=:
1288case $at_status in
1289   77) echo 77 > $at_status_file
1290            exit 77;;
1291   1) ;;
1292   *) echo "input.at:204: exit code was $at_status, expected 1"
1293      at_failed=:;;
1294esac
1295if $at_failed; then
1296
1297  echo 1 > $at_status_file
1298  exit 1
1299fi
1300
1301$at_traceon
1302
1303
1304
1305cat >input.y <<'_ATEOF'
1306{}
1307_ATEOF
1308
1309$at_traceoff
1310echo "input.at:212: bison input.y"
1311echo input.at:212 >$at_check_line_file
1312( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
1313at_status=$?
1314grep '^ *+' $at_stder1 >&2
1315grep -v '^ *+' $at_stder1 >$at_stderr
1316at_failed=false
1317echo >>$at_stderr; echo "input.y:1.1-2: syntax error, unexpected {...}
1318" | $at_diff - $at_stderr || at_failed=:
1319$at_diff $at_devnull $at_stdout || at_failed=:
1320case $at_status in
1321   77) echo 77 > $at_status_file
1322            exit 77;;
1323   1) ;;
1324   *) echo "input.at:212: exit code was $at_status, expected 1"
1325      at_failed=:;;
1326esac
1327if $at_failed; then
1328
1329  echo 1 > $at_status_file
1330  exit 1
1331fi
1332
1333$at_traceon
1334
1335
1336
1337cat >input.y <<'_ATEOF'
1338%{
1339#ifdef HAVE_CONFIG_H
1340# include <config.h>
1341  /* We don't need perfect functions for these tests. */
1342# undef malloc
1343# undef memcmp
1344# undef realloc
1345#endif
1346%}
1347
1348%{
1349/* This is seen in GCC: a %{ and %} in middle of a comment. */
1350const char *foo = "So %{ and %} can be here too.";
1351
1352#if 0
1353/* These examples test Bison while not stressing C compilers too much.
1354   Many C compilers mishandle backslash-newlines, so this part of the
1355   test is inside "#if 0".  The comment and string are written so that
1356   the "#endif" will be seen regardless of the C compiler bugs that we
1357   know about, namely:
1358
1359     HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
1360     comment.
1361
1362     The Apple Darwin compiler (as of late 2002) mishandles
1363     \\[newline]' within a character constant.
1364
1365   */
1366
1367/\
1368* A comment with backslash-newlines in it. %} *\
1369\
1370/
1371/* { Close the above comment, if the C compiler mishandled it.  */
1372
1373char str[] = "\\
1374" A string with backslash-newlines in it %{ %} \\
1375\
1376"";
1377
1378char apostrophe = '\'';
1379#endif
1380
1381#include <stdio.h>
1382%}
1383/* %{ and %} can be here too. */
1384
1385%{
1386/* Exercise pre-prologue dependency to %union.  */
1387typedef int value;
1388%}
1389
1390/* Exercise M4 quoting: ']]', 0.  */
1391
1392/* Also exercise %union. */
1393%union
1394{
1395  value ival; /* A comment to exercise an old bug. */
1396};
1397
1398
1399/* Exercise post-prologue dependency to %union.  */
1400%{
1401static YYSTYPE value_as_yystype (value val);
1402
1403/* Exercise quotes in declarations.  */
1404char quote[] = "]],";
1405%}
1406
1407%{
1408static void yyerror (const char *s);
1409static int yylex (void);
1410%}
1411
1412%type <ival> '['
1413
1414/* Exercise quotes in strings.  */
1415%token FAKE "fake [] \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
1416
1417%%
1418/* Exercise M4 quoting: ']]', [, 1.  */
1419exp: '[' '\1' two '$' '@' '{' oline output.or.oline.opt
1420  {
1421    /* Exercise quotes in braces.  */
1422    char tmp[] = "[%c],\n";
1423    printf (tmp, $1);
1424  }
1425;
1426
1427two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
1428oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
1429output.or.oline.opt: ;|oline;;|output;;;
1430output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
1431%%
1432/* Exercise M4 quoting: ']]', [, 2.  */
1433
1434static YYSTYPE
1435value_as_yystype (value val)
1436{
1437  YYSTYPE res;
1438  res.ival = val;
1439  return res;
1440}
1441
1442static int
1443yylex (void)
1444{
1445  static const char *input = "[\1\2$@{@oline@__oline__\
1446#output "; /* "
1447  */
1448  yylval = value_as_yystype (*input);
1449  return *input++;
1450}
1451
1452static void
1453yyerror (const char *msg)
1454{
1455  fprintf (stderr, "%s\n", msg);
1456}
1457_ATEOF
1458
1459
1460
1461# Pacify Emacs'font-lock-mode: "
1462
1463cat >main.c <<'_ATEOF'
1464typedef int value;
1465#include "input.h"
1466
1467int yyparse (void);
1468
1469int
1470main (void)
1471{
1472  return yyparse ();
1473}
1474_ATEOF
1475
1476
1477$at_traceoff
1478echo "input.at:342: bison -d -v -o input.c input.y"
1479echo input.at:342 >$at_check_line_file
1480( $at_traceon; bison -d -v -o input.c input.y ) >$at_stdout 2>$at_stder1
1481at_status=$?
1482grep '^ *+' $at_stder1 >&2
1483grep -v '^ *+' $at_stder1 >$at_stderr
1484at_failed=false
1485$at_diff $at_devnull $at_stderr || at_failed=:
1486$at_diff $at_devnull $at_stdout || at_failed=:
1487case $at_status in
1488   77) echo 77 > $at_status_file
1489            exit 77;;
1490   0) ;;
1491   *) echo "input.at:342: exit code was $at_status, expected 0"
1492      at_failed=:;;
1493esac
1494if $at_failed; then
1495
1496  echo 1 > $at_status_file
1497  exit 1
1498fi
1499
1500$at_traceon
1501
1502$at_traceoff
1503echo "input.at:343: \$CC \$CFLAGS \$CPPFLAGS -o input.o -c input.c"
1504echo input.at:343 >$at_check_line_file
1505( $at_traceon; $CC $CFLAGS $CPPFLAGS -o input.o -c input.c ) >$at_stdout 2>$at_stder1
1506at_status=$?
1507grep '^ *+' $at_stder1 >&2
1508grep -v '^ *+' $at_stder1 >$at_stderr
1509at_failed=false
1510echo stderr:; cat $at_stderr
1511echo stdout:; cat $at_stdout
1512case $at_status in
1513   77) echo 77 > $at_status_file
1514            exit 77;;
1515   0) ;;
1516   *) echo "input.at:343: exit code was $at_status, expected 0"
1517      at_failed=:;;
1518esac
1519if $at_failed; then
1520
1521  echo 1 > $at_status_file
1522  exit 1
1523fi
1524
1525$at_traceon
1526
1527$at_traceoff
1528echo "input.at:344: \$CC \$CFLAGS \$CPPFLAGS -o main.o -c main.c"
1529echo input.at:344 >$at_check_line_file
1530( $at_traceon; $CC $CFLAGS $CPPFLAGS -o main.o -c main.c ) >$at_stdout 2>$at_stder1
1531at_status=$?
1532grep '^ *+' $at_stder1 >&2
1533grep -v '^ *+' $at_stder1 >$at_stderr
1534at_failed=false
1535echo stderr:; cat $at_stderr
1536echo stdout:; cat $at_stdout
1537case $at_status in
1538   77) echo 77 > $at_status_file
1539            exit 77;;
1540   0) ;;
1541   *) echo "input.at:344: exit code was $at_status, expected 0"
1542      at_failed=:;;
1543esac
1544if $at_failed; then
1545
1546  echo 1 > $at_status_file
1547  exit 1
1548fi
1549
1550$at_traceon
1551
1552$at_traceoff
1553echo "input.at:345: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.o main.o \$LIBS"
1554echo input.at:345 >$at_check_line_file
1555( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.o main.o $LIBS ) >$at_stdout 2>$at_stder1
1556at_status=$?
1557grep '^ *+' $at_stder1 >&2
1558grep -v '^ *+' $at_stder1 >$at_stderr
1559at_failed=false
1560echo stderr:; cat $at_stderr
1561echo stdout:; cat $at_stdout
1562case $at_status in
1563   77) echo 77 > $at_status_file
1564            exit 77;;
1565   0) ;;
1566   *) echo "input.at:345: exit code was $at_status, expected 0"
1567      at_failed=:;;
1568esac
1569if $at_failed; then
1570
1571  echo 1 > $at_status_file
1572  exit 1
1573fi
1574
1575$at_traceon
1576
1577$at_traceoff
1578echo "input.at:348: \$PREPARSER ./input"
1579echo input.at:348 >$at_check_line_file
1580( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
1581at_status=$?
1582grep '^ *+' $at_stder1 >&2
1583grep -v '^ *+' $at_stder1 >$at_stderr
1584at_failed=false
1585$at_diff $at_devnull $at_stderr || at_failed=:
1586echo >>$at_stdout; echo "[[],
1587" | $at_diff - $at_stdout || at_failed=:
1588case $at_status in
1589   77) echo 77 > $at_status_file
1590            exit 77;;
1591   0) ;;
1592   *) echo "input.at:348: exit code was $at_status, expected 0"
1593      at_failed=:;;
1594esac
1595if $at_failed; then
1596
1597  echo 1 > $at_status_file
1598  exit 1
1599fi
1600
1601$at_traceon
1602
1603
1604      $at_traceoff
1605      $at_times_p && times >$at_times_file
1606    ) 5>&1 2>&1 | eval $at_tee_pipe
1607    at_status=`cat $at_status_file`
1608    ;;
1609
1610  7 ) # 7. input.at:357: Typed symbol aliases
1611    at_setup_line='input.at:357'
1612    at_desc='Typed symbol aliases'
1613    $at_quiet $ECHO_N "  7: Typed symbol aliases                         $ECHO_C"
1614    at_xfail=no
1615    (
1616      echo "7. input.at:357: testing ..."
1617      $at_traceon
1618
1619
1620# Bison 2.0 broke typed symbol aliases - ensure they work.
1621
1622cat >input.y <<'_ATEOF'
1623%{
1624#ifdef HAVE_CONFIG_H
1625# include <config.h>
1626  /* We don't need perfect functions for these tests. */
1627# undef malloc
1628# undef memcmp
1629# undef realloc
1630#endif
1631%}
1632
1633%union
1634{
1635  int val;
1636};
1637%token <val> MY_TOKEN "MY TOKEN"
1638%type <val> exp
1639%%
1640exp: "MY TOKEN";
1641%%
1642_ATEOF
1643
1644
1645
1646$at_traceoff
1647echo "input.at:373: bison -o input.c input.y"
1648echo input.at:373 >$at_check_line_file
1649( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
1650at_status=$?
1651grep '^ *+' $at_stder1 >&2
1652grep -v '^ *+' $at_stder1 >$at_stderr
1653at_failed=false
1654$at_diff $at_devnull $at_stderr || at_failed=:
1655$at_diff $at_devnull $at_stdout || at_failed=:
1656case $at_status in
1657   77) echo 77 > $at_status_file
1658            exit 77;;
1659   0) ;;
1660   *) echo "input.at:373: exit code was $at_status, expected 0"
1661      at_failed=:;;
1662esac
1663if $at_failed; then
1664
1665  echo 1 > $at_status_file
1666  exit 1
1667fi
1668
1669$at_traceon
1670
1671
1672      $at_traceoff
1673      $at_times_p && times >$at_times_file
1674    ) 5>&1 2>&1 | eval $at_tee_pipe
1675    at_status=`cat $at_status_file`
1676    ;;
1677
1678  8 ) # 8. input.at:393: Require 1.0
1679    at_setup_line='input.at:393'
1680    at_desc='Require 1.0'
1681    $at_quiet $ECHO_N "  8: Require 1.0                                  $ECHO_C"
1682    at_xfail=no
1683    (
1684      echo "8. input.at:393: testing ..."
1685      $at_traceon
1686
1687cat >input.y <<'_ATEOF'
1688%{
1689#ifdef HAVE_CONFIG_H
1690# include <config.h>
1691  /* We don't need perfect functions for these tests. */
1692# undef malloc
1693# undef memcmp
1694# undef realloc
1695#endif
1696%}
1697
1698%require "1.0";
1699%%
1700empty_file:;
1701_ATEOF
1702
1703
1704$at_traceoff
1705echo "input.at:393: bison -o input.c input.y"
1706echo input.at:393 >$at_check_line_file
1707( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
1708at_status=$?
1709grep '^ *+' $at_stder1 >&2
1710grep -v '^ *+' $at_stder1 >$at_stderr
1711at_failed=false
1712echo stderr:; cat $at_stderr
1713$at_diff $at_devnull $at_stdout || at_failed=:
1714case $at_status in
1715   77) echo 77 > $at_status_file
1716            exit 77;;
1717   0) ;;
1718   *) echo "input.at:393: exit code was $at_status, expected 0"
1719      at_failed=:;;
1720esac
1721if $at_failed; then
1722
1723  echo 1 > $at_status_file
1724  exit 1
1725fi
1726
1727$at_traceon
1728
1729      $at_traceoff
1730      $at_times_p && times >$at_times_file
1731    ) 5>&1 2>&1 | eval $at_tee_pipe
1732    at_status=`cat $at_status_file`
1733    ;;
1734
1735  9 ) # 9. input.at:394: Require 2.3
1736    at_setup_line='input.at:394'
1737    at_desc='Require 2.3'
1738    $at_quiet $ECHO_N "  9: Require 2.3                                  $ECHO_C"
1739    at_xfail=no
1740    (
1741      echo "9. input.at:394: testing ..."
1742      $at_traceon
1743
1744cat >input.y <<'_ATEOF'
1745%{
1746#ifdef HAVE_CONFIG_H
1747# include <config.h>
1748  /* We don't need perfect functions for these tests. */
1749# undef malloc
1750# undef memcmp
1751# undef realloc
1752#endif
1753%}
1754
1755%require "2.3";
1756%%
1757empty_file:;
1758_ATEOF
1759
1760
1761$at_traceoff
1762echo "input.at:394: bison -o input.c input.y"
1763echo input.at:394 >$at_check_line_file
1764( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
1765at_status=$?
1766grep '^ *+' $at_stder1 >&2
1767grep -v '^ *+' $at_stder1 >$at_stderr
1768at_failed=false
1769echo stderr:; cat $at_stderr
1770$at_diff $at_devnull $at_stdout || at_failed=:
1771case $at_status in
1772   77) echo 77 > $at_status_file
1773            exit 77;;
1774   0) ;;
1775   *) echo "input.at:394: exit code was $at_status, expected 0"
1776      at_failed=:;;
1777esac
1778if $at_failed; then
1779
1780  echo 1 > $at_status_file
1781  exit 1
1782fi
1783
1784$at_traceon
1785
1786      $at_traceoff
1787      $at_times_p && times >$at_times_file
1788    ) 5>&1 2>&1 | eval $at_tee_pipe
1789    at_status=`cat $at_status_file`
1790    ;;
1791
1792  10 ) # 10. input.at:396: Require 100.0
1793    at_setup_line='input.at:396'
1794    at_desc='Require 100.0'
1795    $at_quiet $ECHO_N " 10: Require 100.0                                $ECHO_C"
1796    at_xfail=no
1797    (
1798      echo "10. input.at:396: testing ..."
1799      $at_traceon
1800
1801cat >input.y <<'_ATEOF'
1802%{
1803#ifdef HAVE_CONFIG_H
1804# include <config.h>
1805  /* We don't need perfect functions for these tests. */
1806# undef malloc
1807# undef memcmp
1808# undef realloc
1809#endif
1810%}
1811
1812%require "100.0";
1813%%
1814empty_file:;
1815_ATEOF
1816
1817
1818$at_traceoff
1819echo "input.at:396: bison -o input.c input.y"
1820echo input.at:396 >$at_check_line_file
1821( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
1822at_status=$?
1823grep '^ *+' $at_stder1 >&2
1824grep -v '^ *+' $at_stder1 >$at_stderr
1825at_failed=false
1826echo stderr:; cat $at_stderr
1827$at_diff $at_devnull $at_stdout || at_failed=:
1828case $at_status in
1829   77) echo 77 > $at_status_file
1830            exit 77;;
1831   63) ;;
1832   *) echo "input.at:396: exit code was $at_status, expected 63"
1833      at_failed=:;;
1834esac
1835if $at_failed; then
1836
1837  echo 1 > $at_status_file
1838  exit 1
1839fi
1840
1841$at_traceon
1842
1843      $at_traceoff
1844      $at_times_p && times >$at_times_file
1845    ) 5>&1 2>&1 | eval $at_tee_pipe
1846    at_status=`cat $at_status_file`
1847    ;;
1848
1849
1850  banner-2 ) # Banner 2. output.at:19
1851    cat <<\_ATEOF
1852
1853Output file names.
1854
1855_ATEOF
1856    ;;
1857
1858  11 ) # 11. output.at:43: Output files:  -dv
1859    at_setup_line='output.at:43'
1860    at_desc='Output files:  -dv '
1861    $at_quiet $ECHO_N " 11: Output files:  -dv                           $ECHO_C"
1862    at_xfail=no
1863    (
1864      echo "11. output.at:43: testing ..."
1865      $at_traceon
1866
1867case "foo.y" in
1868  */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;;
1869esac
1870cat >foo.y <<'_ATEOF'
1871
1872%%
1873foo: {};
1874_ATEOF
1875
1876
1877$at_traceoff
1878echo "output.at:43: bison -dv foo.y "
1879echo output.at:43 >$at_check_line_file
1880( $at_traceon; bison -dv foo.y  ) >$at_stdout 2>$at_stder1
1881at_status=$?
1882grep '^ *+' $at_stder1 >&2
1883grep -v '^ *+' $at_stder1 >$at_stderr
1884at_failed=false
1885$at_diff $at_devnull $at_stderr || at_failed=:
1886$at_diff $at_devnull $at_stdout || at_failed=:
1887case $at_status in
1888   77) echo 77 > $at_status_file
1889            exit 77;;
1890   0) ;;
1891   *) echo "output.at:43: exit code was $at_status, expected 0"
1892      at_failed=:;;
1893esac
1894if $at_failed; then
1895
1896  echo 1 > $at_status_file
1897  exit 1
1898fi
1899
1900$at_traceon
1901
1902$at_traceoff
1903echo "output.at:43: ls foo.output foo.tab.c foo.tab.h"
1904echo output.at:43 >$at_check_line_file
1905( $at_traceon; ls foo.output foo.tab.c foo.tab.h ) >$at_stdout 2>$at_stder1
1906at_status=$?
1907grep '^ *+' $at_stder1 >&2
1908grep -v '^ *+' $at_stder1 >$at_stderr
1909at_failed=false
1910$at_diff $at_devnull $at_stderr || at_failed=:
1911echo stdout:; cat $at_stdout
1912case $at_status in
1913   77) echo 77 > $at_status_file
1914            exit 77;;
1915   0) ;;
1916   *) echo "output.at:43: exit code was $at_status, expected 0"
1917      at_failed=:;;
1918esac
1919if $at_failed; then
1920
1921  echo 1 > $at_status_file
1922  exit 1
1923fi
1924
1925$at_traceon
1926
1927
1928      $at_traceoff
1929      $at_times_p && times >$at_times_file
1930    ) 5>&1 2>&1 | eval $at_tee_pipe
1931    at_status=`cat $at_status_file`
1932    ;;
1933
1934  12 ) # 12. output.at:46: Output files:  -dv >&-
1935    at_setup_line='output.at:46'
1936    at_desc='Output files:  -dv >&-'
1937    $at_quiet $ECHO_N " 12: Output files:  -dv >&-                       $ECHO_C"
1938    at_xfail=no
1939    (
1940      echo "12. output.at:46: testing ..."
1941      $at_traceon
1942
1943case "foo.y" in
1944  */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;;
1945esac
1946cat >foo.y <<'_ATEOF'
1947
1948%%
1949foo: {};
1950_ATEOF
1951
1952
1953$at_traceoff
1954echo "output.at:46: bison -dv foo.y >&-"
1955echo output.at:46 >$at_check_line_file
1956( $at_traceon; bison -dv foo.y >&- ) >$at_stdout 2>$at_stder1
1957at_status=$?
1958grep '^ *+' $at_stder1 >&2
1959grep -v '^ *+' $at_stder1 >$at_stderr
1960at_failed=false
1961$at_diff $at_devnull $at_stderr || at_failed=:
1962$at_diff $at_devnull $at_stdout || at_failed=:
1963case $at_status in
1964   77) echo 77 > $at_status_file
1965            exit 77;;
1966   0) ;;
1967   *) echo "output.at:46: exit code was $at_status, expected 0"
1968      at_failed=:;;
1969esac
1970if $at_failed; then
1971
1972  echo 1 > $at_status_file
1973  exit 1
1974fi
1975
1976$at_traceon
1977
1978$at_traceoff
1979echo "output.at:46: ls foo.output foo.tab.c foo.tab.h"
1980echo output.at:46 >$at_check_line_file
1981( $at_traceon; ls foo.output foo.tab.c foo.tab.h ) >$at_stdout 2>$at_stder1
1982at_status=$?
1983grep '^ *+' $at_stder1 >&2
1984grep -v '^ *+' $at_stder1 >$at_stderr
1985at_failed=false
1986$at_diff $at_devnull $at_stderr || at_failed=:
1987echo stdout:; cat $at_stdout
1988case $at_status in
1989   77) echo 77 > $at_status_file
1990            exit 77;;
1991   0) ;;
1992   *) echo "output.at:46: exit code was $at_status, expected 0"
1993      at_failed=:;;
1994esac
1995if $at_failed; then
1996
1997  echo 1 > $at_status_file
1998  exit 1
1999fi
2000
2001$at_traceon
2002
2003
2004      $at_traceoff
2005      $at_times_p && times >$at_times_file
2006    ) 5>&1 2>&1 | eval $at_tee_pipe
2007    at_status=`cat $at_status_file`
2008    ;;
2009
2010  13 ) # 13. output.at:48: Output files:  -dv -o foo.c
2011    at_setup_line='output.at:48'
2012    at_desc='Output files:  -dv -o foo.c '
2013    $at_quiet $ECHO_N " 13: Output files:  -dv -o foo.c                  $ECHO_C"
2014    at_xfail=no
2015    (
2016      echo "13. output.at:48: testing ..."
2017      $at_traceon
2018
2019case "foo.y" in
2020  */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;;
2021esac
2022cat >foo.y <<'_ATEOF'
2023
2024%%
2025foo: {};
2026_ATEOF
2027
2028
2029$at_traceoff
2030echo "output.at:48: bison -dv -o foo.c foo.y "
2031echo output.at:48 >$at_check_line_file
2032( $at_traceon; bison -dv -o foo.c foo.y  ) >$at_stdout 2>$at_stder1
2033at_status=$?
2034grep '^ *+' $at_stder1 >&2
2035grep -v '^ *+' $at_stder1 >$at_stderr
2036at_failed=false
2037$at_diff $at_devnull $at_stderr || at_failed=:
2038$at_diff $at_devnull $at_stdout || at_failed=:
2039case $at_status in
2040   77) echo 77 > $at_status_file
2041            exit 77;;
2042   0) ;;
2043   *) echo "output.at:48: exit code was $at_status, expected 0"
2044      at_failed=:;;
2045esac
2046if $at_failed; then
2047
2048  echo 1 > $at_status_file
2049  exit 1
2050fi
2051
2052$at_traceon
2053
2054$at_traceoff
2055echo "output.at:48: ls foo.c foo.h foo.output"
2056echo output.at:48 >$at_check_line_file
2057( $at_traceon; ls foo.c foo.h foo.output ) >$at_stdout 2>$at_stder1
2058at_status=$?
2059grep '^ *+' $at_stder1 >&2
2060grep -v '^ *+' $at_stder1 >$at_stderr
2061at_failed=false
2062$at_diff $at_devnull $at_stderr || at_failed=:
2063echo stdout:; cat $at_stdout
2064case $at_status in
2065   77) echo 77 > $at_status_file
2066            exit 77;;
2067   0) ;;
2068   *) echo "output.at:48: exit code was $at_status, expected 0"
2069      at_failed=:;;
2070esac
2071if $at_failed; then
2072
2073  echo 1 > $at_status_file
2074  exit 1
2075fi
2076
2077$at_traceon
2078
2079
2080      $at_traceoff
2081      $at_times_p && times >$at_times_file
2082    ) 5>&1 2>&1 | eval $at_tee_pipe
2083    at_status=`cat $at_status_file`
2084    ;;
2085
2086  14 ) # 14. output.at:50: Output files:  -dv -o foo.tab.c
2087    at_setup_line='output.at:50'
2088    at_desc='Output files:  -dv -o foo.tab.c '
2089    $at_quiet $ECHO_N " 14: Output files:  -dv -o foo.tab.c              $ECHO_C"
2090    at_xfail=no
2091    (
2092      echo "14. output.at:50: testing ..."
2093      $at_traceon
2094
2095case "foo.y" in
2096  */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;;
2097esac
2098cat >foo.y <<'_ATEOF'
2099
2100%%
2101foo: {};
2102_ATEOF
2103
2104
2105$at_traceoff
2106echo "output.at:50: bison -dv -o foo.tab.c foo.y "
2107echo output.at:50 >$at_check_line_file
2108( $at_traceon; bison -dv -o foo.tab.c foo.y  ) >$at_stdout 2>$at_stder1
2109at_status=$?
2110grep '^ *+' $at_stder1 >&2
2111grep -v '^ *+' $at_stder1 >$at_stderr
2112at_failed=false
2113$at_diff $at_devnull $at_stderr || at_failed=:
2114$at_diff $at_devnull $at_stdout || at_failed=:
2115case $at_status in
2116   77) echo 77 > $at_status_file
2117            exit 77;;
2118   0) ;;
2119   *) echo "output.at:50: exit code was $at_status, expected 0"
2120      at_failed=:;;
2121esac
2122if $at_failed; then
2123
2124  echo 1 > $at_status_file
2125  exit 1
2126fi
2127
2128$at_traceon
2129
2130$at_traceoff
2131echo "output.at:50: ls foo.output foo.tab.c foo.tab.h"
2132echo output.at:50 >$at_check_line_file
2133( $at_traceon; ls foo.output foo.tab.c foo.tab.h ) >$at_stdout 2>$at_stder1
2134at_status=$?
2135grep '^ *+' $at_stder1 >&2
2136grep -v '^ *+' $at_stder1 >$at_stderr
2137at_failed=false
2138$at_diff $at_devnull $at_stderr || at_failed=:
2139echo stdout:; cat $at_stdout
2140case $at_status in
2141   77) echo 77 > $at_status_file
2142            exit 77;;
2143   0) ;;
2144   *) echo "output.at:50: exit code was $at_status, expected 0"
2145      at_failed=:;;
2146esac
2147if $at_failed; then
2148
2149  echo 1 > $at_status_file
2150  exit 1
2151fi
2152
2153$at_traceon
2154
2155
2156      $at_traceoff
2157      $at_times_p && times >$at_times_file
2158    ) 5>&1 2>&1 | eval $at_tee_pipe
2159    at_status=`cat $at_status_file`
2160    ;;
2161
2162  15 ) # 15. output.at:52: Output files:  -dv -y
2163    at_setup_line='output.at:52'
2164    at_desc='Output files:  -dv -y '
2165    $at_quiet $ECHO_N " 15: Output files:  -dv -y                        $ECHO_C"
2166    at_xfail=no
2167    (
2168      echo "15. output.at:52: testing ..."
2169      $at_traceon
2170
2171case "foo.y" in
2172  */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;;
2173esac
2174cat >foo.y <<'_ATEOF'
2175
2176%%
2177foo: {};
2178_ATEOF
2179
2180
2181$at_traceoff
2182echo "output.at:52: bison -dv -y foo.y "
2183echo output.at:52 >$at_check_line_file
2184( $at_traceon; bison -dv -y foo.y  ) >$at_stdout 2>$at_stder1
2185at_status=$?
2186grep '^ *+' $at_stder1 >&2
2187grep -v '^ *+' $at_stder1 >$at_stderr
2188at_failed=false
2189$at_diff $at_devnull $at_stderr || at_failed=:
2190$at_diff $at_devnull $at_stdout || at_failed=:
2191case $at_status in
2192   77) echo 77 > $at_status_file
2193            exit 77;;
2194   0) ;;
2195   *) echo "output.at:52: exit code was $at_status, expected 0"
2196      at_failed=:;;
2197esac
2198if $at_failed; then
2199
2200  echo 1 > $at_status_file
2201  exit 1
2202fi
2203
2204$at_traceon
2205
2206$at_traceoff
2207echo "output.at:52: ls y.output y.tab.c y.tab.h"
2208echo output.at:52 >$at_check_line_file
2209( $at_traceon; ls y.output y.tab.c y.tab.h ) >$at_stdout 2>$at_stder1
2210at_status=$?
2211grep '^ *+' $at_stder1 >&2
2212grep -v '^ *+' $at_stder1 >$at_stderr
2213at_failed=false
2214$at_diff $at_devnull $at_stderr || at_failed=:
2215echo stdout:; cat $at_stdout
2216case $at_status in
2217   77) echo 77 > $at_status_file
2218            exit 77;;
2219   0) ;;
2220   *) echo "output.at:52: exit code was $at_status, expected 0"
2221      at_failed=:;;
2222esac
2223if $at_failed; then
2224
2225  echo 1 > $at_status_file
2226  exit 1
2227fi
2228
2229$at_traceon
2230
2231
2232      $at_traceoff
2233      $at_times_p && times >$at_times_file
2234    ) 5>&1 2>&1 | eval $at_tee_pipe
2235    at_status=`cat $at_status_file`
2236    ;;
2237
2238  16 ) # 16. output.at:54: Output files:  -dv -b bar
2239    at_setup_line='output.at:54'
2240    at_desc='Output files:  -dv -b bar '
2241    $at_quiet $ECHO_N " 16: Output files:  -dv -b bar                    $ECHO_C"
2242    at_xfail=no
2243    (
2244      echo "16. output.at:54: testing ..."
2245      $at_traceon
2246
2247case "foo.y" in
2248  */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;;
2249esac
2250cat >foo.y <<'_ATEOF'
2251
2252%%
2253foo: {};
2254_ATEOF
2255
2256
2257$at_traceoff
2258echo "output.at:54: bison -dv -b bar foo.y "
2259echo output.at:54 >$at_check_line_file
2260( $at_traceon; bison -dv -b bar foo.y  ) >$at_stdout 2>$at_stder1
2261at_status=$?
2262grep '^ *+' $at_stder1 >&2
2263grep -v '^ *+' $at_stder1 >$at_stderr
2264at_failed=false
2265$at_diff $at_devnull $at_stderr || at_failed=:
2266$at_diff $at_devnull $at_stdout || at_failed=:
2267case $at_status in
2268   77) echo 77 > $at_status_file
2269            exit 77;;
2270   0) ;;
2271   *) echo "output.at:54: exit code was $at_status, expected 0"
2272      at_failed=:;;
2273esac
2274if $at_failed; then
2275
2276  echo 1 > $at_status_file
2277  exit 1
2278fi
2279
2280$at_traceon
2281
2282$at_traceoff
2283echo "output.at:54: ls bar.output bar.tab.c bar.tab.h"
2284echo output.at:54 >$at_check_line_file
2285( $at_traceon; ls bar.output bar.tab.c bar.tab.h ) >$at_stdout 2>$at_stder1
2286at_status=$?
2287grep '^ *+' $at_stder1 >&2
2288grep -v '^ *+' $at_stder1 >$at_stderr
2289at_failed=false
2290$at_diff $at_devnull $at_stderr || at_failed=:
2291echo stdout:; cat $at_stdout
2292case $at_status in
2293   77) echo 77 > $at_status_file
2294            exit 77;;
2295   0) ;;
2296   *) echo "output.at:54: exit code was $at_status, expected 0"
2297      at_failed=:;;
2298esac
2299if $at_failed; then
2300
2301  echo 1 > $at_status_file
2302  exit 1
2303fi
2304
2305$at_traceon
2306
2307
2308      $at_traceoff
2309      $at_times_p && times >$at_times_file
2310    ) 5>&1 2>&1 | eval $at_tee_pipe
2311    at_status=`cat $at_status_file`
2312    ;;
2313
2314  17 ) # 17. output.at:56: Output files:  -dv -g -o foo.c
2315    at_setup_line='output.at:56'
2316    at_desc='Output files:  -dv -g -o foo.c '
2317    $at_quiet $ECHO_N " 17: Output files:  -dv -g -o foo.c               $ECHO_C"
2318    at_xfail=no
2319    (
2320      echo "17. output.at:56: testing ..."
2321      $at_traceon
2322
2323case "foo.y" in
2324  */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;;
2325esac
2326cat >foo.y <<'_ATEOF'
2327
2328%%
2329foo: {};
2330_ATEOF
2331
2332
2333$at_traceoff
2334echo "output.at:56: bison -dv -g -o foo.c foo.y "
2335echo output.at:56 >$at_check_line_file
2336( $at_traceon; bison -dv -g -o foo.c foo.y  ) >$at_stdout 2>$at_stder1
2337at_status=$?
2338grep '^ *+' $at_stder1 >&2
2339grep -v '^ *+' $at_stder1 >$at_stderr
2340at_failed=false
2341$at_diff $at_devnull $at_stderr || at_failed=:
2342$at_diff $at_devnull $at_stdout || at_failed=:
2343case $at_status in
2344   77) echo 77 > $at_status_file
2345            exit 77;;
2346   0) ;;
2347   *) echo "output.at:56: exit code was $at_status, expected 0"
2348      at_failed=:;;
2349esac
2350if $at_failed; then
2351
2352  echo 1 > $at_status_file
2353  exit 1
2354fi
2355
2356$at_traceon
2357
2358$at_traceoff
2359echo "output.at:56: ls foo.c foo.h foo.output foo.vcg"
2360echo output.at:56 >$at_check_line_file
2361( $at_traceon; ls foo.c foo.h foo.output foo.vcg ) >$at_stdout 2>$at_stder1
2362at_status=$?
2363grep '^ *+' $at_stder1 >&2
2364grep -v '^ *+' $at_stder1 >$at_stderr
2365at_failed=false
2366$at_diff $at_devnull $at_stderr || at_failed=:
2367echo stdout:; cat $at_stdout
2368case $at_status in
2369   77) echo 77 > $at_status_file
2370            exit 77;;
2371   0) ;;
2372   *) echo "output.at:56: exit code was $at_status, expected 0"
2373      at_failed=:;;
2374esac
2375if $at_failed; then
2376
2377  echo 1 > $at_status_file
2378  exit 1
2379fi
2380
2381$at_traceon
2382
2383
2384      $at_traceoff
2385      $at_times_p && times >$at_times_file
2386    ) 5>&1 2>&1 | eval $at_tee_pipe
2387    at_status=`cat $at_status_file`
2388    ;;
2389
2390  18 ) # 18. output.at:60: Output files: %defines %verbose
2391    at_setup_line='output.at:60'
2392    at_desc='Output files: %defines %verbose  '
2393    $at_quiet $ECHO_N " 18: Output files: %defines %verbose              $ECHO_C"
2394    at_xfail=no
2395    (
2396      echo "18. output.at:60: testing ..."
2397      $at_traceon
2398
2399case "foo.y" in
2400  */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;;
2401esac
2402cat >foo.y <<'_ATEOF'
2403%defines %verbose
2404%%
2405foo: {};
2406_ATEOF
2407
2408
2409$at_traceoff
2410echo "output.at:60: bison  foo.y "
2411echo output.at:60 >$at_check_line_file
2412( $at_traceon; bison  foo.y  ) >$at_stdout 2>$at_stder1
2413at_status=$?
2414grep '^ *+' $at_stder1 >&2
2415grep -v '^ *+' $at_stder1 >$at_stderr
2416at_failed=false
2417$at_diff $at_devnull $at_stderr || at_failed=:
2418$at_diff $at_devnull $at_stdout || at_failed=:
2419case $at_status in
2420   77) echo 77 > $at_status_file
2421            exit 77;;
2422   0) ;;
2423   *) echo "output.at:60: exit code was $at_status, expected 0"
2424      at_failed=:;;
2425esac
2426if $at_failed; then
2427
2428  echo 1 > $at_status_file
2429  exit 1
2430fi
2431
2432$at_traceon
2433
2434$at_traceoff
2435echo "output.at:60: ls foo.output foo.tab.c foo.tab.h"
2436echo output.at:60 >$at_check_line_file
2437( $at_traceon; ls foo.output foo.tab.c foo.tab.h ) >$at_stdout 2>$at_stder1
2438at_status=$?
2439grep '^ *+' $at_stder1 >&2
2440grep -v '^ *+' $at_stder1 >$at_stderr
2441at_failed=false
2442$at_diff $at_devnull $at_stderr || at_failed=:
2443echo stdout:; cat $at_stdout
2444case $at_status in
2445   77) echo 77 > $at_status_file
2446            exit 77;;
2447   0) ;;
2448   *) echo "output.at:60: exit code was $at_status, expected 0"
2449      at_failed=:;;
2450esac
2451if $at_failed; then
2452
2453  echo 1 > $at_status_file
2454  exit 1
2455fi
2456
2457$at_traceon
2458
2459
2460      $at_traceoff
2461      $at_times_p && times >$at_times_file
2462    ) 5>&1 2>&1 | eval $at_tee_pipe
2463    at_status=`cat $at_status_file`
2464    ;;
2465
2466  19 ) # 19. output.at:62: Output files: %defines %verbose %yacc
2467    at_setup_line='output.at:62'
2468    at_desc='Output files: %defines %verbose %yacc  '
2469    $at_quiet $ECHO_N " 19: Output files: %defines %verbose %yacc        $ECHO_C"
2470    at_xfail=no
2471    (
2472      echo "19. output.at:62: testing ..."
2473      $at_traceon
2474
2475case "foo.y" in
2476  */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;;
2477esac
2478cat >foo.y <<'_ATEOF'
2479%defines %verbose %yacc
2480%%
2481foo: {};
2482_ATEOF
2483
2484
2485$at_traceoff
2486echo "output.at:62: bison  foo.y "
2487echo output.at:62 >$at_check_line_file
2488( $at_traceon; bison  foo.y  ) >$at_stdout 2>$at_stder1
2489at_status=$?
2490grep '^ *+' $at_stder1 >&2
2491grep -v '^ *+' $at_stder1 >$at_stderr
2492at_failed=false
2493$at_diff $at_devnull $at_stderr || at_failed=:
2494$at_diff $at_devnull $at_stdout || at_failed=:
2495case $at_status in
2496   77) echo 77 > $at_status_file
2497            exit 77;;
2498   0) ;;
2499   *) echo "output.at:62: exit code was $at_status, expected 0"
2500      at_failed=:;;
2501esac
2502if $at_failed; then
2503
2504  echo 1 > $at_status_file
2505  exit 1
2506fi
2507
2508$at_traceon
2509
2510$at_traceoff
2511echo "output.at:62: ls y.output y.tab.c y.tab.h"
2512echo output.at:62 >$at_check_line_file
2513( $at_traceon; ls y.output y.tab.c y.tab.h ) >$at_stdout 2>$at_stder1
2514at_status=$?
2515grep '^ *+' $at_stder1 >&2
2516grep -v '^ *+' $at_stder1 >$at_stderr
2517at_failed=false
2518$at_diff $at_devnull $at_stderr || at_failed=:
2519echo stdout:; cat $at_stdout
2520case $at_status in
2521   77) echo 77 > $at_status_file
2522            exit 77;;
2523   0) ;;
2524   *) echo "output.at:62: exit code was $at_status, expected 0"
2525      at_failed=:;;
2526esac
2527if $at_failed; then
2528
2529  echo 1 > $at_status_file
2530  exit 1
2531fi
2532
2533$at_traceon
2534
2535
2536      $at_traceoff
2537      $at_times_p && times >$at_times_file
2538    ) 5>&1 2>&1 | eval $at_tee_pipe
2539    at_status=`cat $at_status_file`
2540    ;;
2541
2542  20 ) # 20. output.at:65: Output files: %defines %verbose %yacc
2543    at_setup_line='output.at:65'
2544    at_desc='Output files: %defines %verbose %yacc  '
2545    $at_quiet $ECHO_N " 20: Output files: %defines %verbose %yacc        $ECHO_C"
2546    at_xfail=no
2547    (
2548      echo "20. output.at:65: testing ..."
2549      $at_traceon
2550
2551case "foo.yy" in
2552  */*) mkdir `echo "foo.yy" | sed 's,/.*,,'`;;
2553esac
2554cat >foo.yy <<'_ATEOF'
2555%defines %verbose %yacc
2556%%
2557foo: {};
2558_ATEOF
2559
2560
2561$at_traceoff
2562echo "output.at:65: bison  foo.yy "
2563echo output.at:65 >$at_check_line_file
2564( $at_traceon; bison  foo.yy  ) >$at_stdout 2>$at_stder1
2565at_status=$?
2566grep '^ *+' $at_stder1 >&2
2567grep -v '^ *+' $at_stder1 >$at_stderr
2568at_failed=false
2569$at_diff $at_devnull $at_stderr || at_failed=:
2570$at_diff $at_devnull $at_stdout || at_failed=:
2571case $at_status in
2572   77) echo 77 > $at_status_file
2573            exit 77;;
2574   0) ;;
2575   *) echo "output.at:65: exit code was $at_status, expected 0"
2576      at_failed=:;;
2577esac
2578if $at_failed; then
2579
2580  echo 1 > $at_status_file
2581  exit 1
2582fi
2583
2584$at_traceon
2585
2586$at_traceoff
2587echo "output.at:65: ls y.output y.tab.c y.tab.h"
2588echo output.at:65 >$at_check_line_file
2589( $at_traceon; ls y.output y.tab.c y.tab.h ) >$at_stdout 2>$at_stder1
2590at_status=$?
2591grep '^ *+' $at_stder1 >&2
2592grep -v '^ *+' $at_stder1 >$at_stderr
2593at_failed=false
2594$at_diff $at_devnull $at_stderr || at_failed=:
2595echo stdout:; cat $at_stdout
2596case $at_status in
2597   77) echo 77 > $at_status_file
2598            exit 77;;
2599   0) ;;
2600   *) echo "output.at:65: exit code was $at_status, expected 0"
2601      at_failed=:;;
2602esac
2603if $at_failed; then
2604
2605  echo 1 > $at_status_file
2606  exit 1
2607fi
2608
2609$at_traceon
2610
2611
2612      $at_traceoff
2613      $at_times_p && times >$at_times_file
2614    ) 5>&1 2>&1 | eval $at_tee_pipe
2615    at_status=`cat $at_status_file`
2616    ;;
2617
2618  21 ) # 21. output.at:69: Output files: %file-prefix="bar" %defines %verbose
2619    at_setup_line='output.at:69'
2620    at_desc='Output files: %file-prefix="bar" %defines %verbose  '
2621    $at_quiet $ECHO_N " 21: Output files: %file-prefix="bar" %defines %verbose  $ECHO_C"
2622    at_xfail=no
2623    (
2624      echo "21. output.at:69: testing ..."
2625      $at_traceon
2626
2627case "foo.y" in
2628  */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;;
2629esac
2630cat >foo.y <<'_ATEOF'
2631%file-prefix="bar" %defines %verbose
2632%%
2633foo: {};
2634_ATEOF
2635
2636
2637$at_traceoff
2638echo "output.at:69: bison  foo.y "
2639echo output.at:69 >$at_check_line_file
2640( $at_traceon; bison  foo.y  ) >$at_stdout 2>$at_stder1
2641at_status=$?
2642grep '^ *+' $at_stder1 >&2
2643grep -v '^ *+' $at_stder1 >$at_stderr
2644at_failed=false
2645$at_diff $at_devnull $at_stderr || at_failed=:
2646$at_diff $at_devnull $at_stdout || at_failed=:
2647case $at_status in
2648   77) echo 77 > $at_status_file
2649            exit 77;;
2650   0) ;;
2651   *) echo "output.at:69: exit code was $at_status, expected 0"
2652      at_failed=:;;
2653esac
2654if $at_failed; then
2655
2656  echo 1 > $at_status_file
2657  exit 1
2658fi
2659
2660$at_traceon
2661
2662$at_traceoff
2663echo "output.at:69: ls bar.output bar.tab.c bar.tab.h"
2664echo output.at:69 >$at_check_line_file
2665( $at_traceon; ls bar.output bar.tab.c bar.tab.h ) >$at_stdout 2>$at_stder1
2666at_status=$?
2667grep '^ *+' $at_stder1 >&2
2668grep -v '^ *+' $at_stder1 >$at_stderr
2669at_failed=false
2670$at_diff $at_devnull $at_stderr || at_failed=:
2671echo stdout:; cat $at_stdout
2672case $at_status in
2673   77) echo 77 > $at_status_file
2674            exit 77;;
2675   0) ;;
2676   *) echo "output.at:69: exit code was $at_status, expected 0"
2677      at_failed=:;;
2678esac
2679if $at_failed; then
2680
2681  echo 1 > $at_status_file
2682  exit 1
2683fi
2684
2685$at_traceon
2686
2687
2688      $at_traceoff
2689      $at_times_p && times >$at_times_file
2690    ) 5>&1 2>&1 | eval $at_tee_pipe
2691    at_status=`cat $at_status_file`
2692    ;;
2693
2694  22 ) # 22. output.at:71: Output files: %output="bar.c" %defines %verbose %yacc
2695    at_setup_line='output.at:71'
2696    at_desc='Output files: %output="bar.c" %defines %verbose %yacc  '
2697    $at_quiet $ECHO_N " 22: Output files: %output="bar.c" %defines %verbose %yacc  $ECHO_C"
2698    at_xfail=no
2699    (
2700      echo "22. output.at:71: testing ..."
2701      $at_traceon
2702
2703case "foo.y" in
2704  */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;;
2705esac
2706cat >foo.y <<'_ATEOF'
2707%output="bar.c" %defines %verbose %yacc
2708%%
2709foo: {};
2710_ATEOF
2711
2712
2713$at_traceoff
2714echo "output.at:71: bison  foo.y "
2715echo output.at:71 >$at_check_line_file
2716( $at_traceon; bison  foo.y  ) >$at_stdout 2>$at_stder1
2717at_status=$?
2718grep '^ *+' $at_stder1 >&2
2719grep -v '^ *+' $at_stder1 >$at_stderr
2720at_failed=false
2721$at_diff $at_devnull $at_stderr || at_failed=:
2722$at_diff $at_devnull $at_stdout || at_failed=:
2723case $at_status in
2724   77) echo 77 > $at_status_file
2725            exit 77;;
2726   0) ;;
2727   *) echo "output.at:71: exit code was $at_status, expected 0"
2728      at_failed=:;;
2729esac
2730if $at_failed; then
2731
2732  echo 1 > $at_status_file
2733  exit 1
2734fi
2735
2736$at_traceon
2737
2738$at_traceoff
2739echo "output.at:71: ls bar.output bar.c bar.h"
2740echo output.at:71 >$at_check_line_file
2741( $at_traceon; ls bar.output bar.c bar.h ) >$at_stdout 2>$at_stder1
2742at_status=$?
2743grep '^ *+' $at_stder1 >&2
2744grep -v '^ *+' $at_stder1 >$at_stderr
2745at_failed=false
2746$at_diff $at_devnull $at_stderr || at_failed=:
2747echo stdout:; cat $at_stdout
2748case $at_status in
2749   77) echo 77 > $at_status_file
2750            exit 77;;
2751   0) ;;
2752   *) echo "output.at:71: exit code was $at_status, expected 0"
2753      at_failed=:;;
2754esac
2755if $at_failed; then
2756
2757  echo 1 > $at_status_file
2758  exit 1
2759fi
2760
2761$at_traceon
2762
2763
2764      $at_traceoff
2765      $at_times_p && times >$at_times_file
2766    ) 5>&1 2>&1 | eval $at_tee_pipe
2767    at_status=`cat $at_status_file`
2768    ;;
2769
2770  23 ) # 23. output.at:75: Output files: %file-prefix="baz" %output="bar.c" %defines %verbose %yacc
2771    at_setup_line='output.at:75'
2772    at_desc='Output files: %file-prefix="baz" %output="bar.c" %defines %verbose %yacc  '
2773    $at_quiet $ECHO_N " 23: Output files: %file-prefix="baz" %output="bar.c" %defines %verbose %yacc  $ECHO_C"
2774    at_xfail=no
2775    (
2776      echo "23. output.at:75: testing ..."
2777      $at_traceon
2778
2779case "foo.y" in
2780  */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;;
2781esac
2782cat >foo.y <<'_ATEOF'
2783%file-prefix="baz" %output="bar.c" %defines %verbose %yacc
2784%%
2785foo: {};
2786_ATEOF
2787
2788
2789$at_traceoff
2790echo "output.at:75: bison  foo.y "
2791echo output.at:75 >$at_check_line_file
2792( $at_traceon; bison  foo.y  ) >$at_stdout 2>$at_stder1
2793at_status=$?
2794grep '^ *+' $at_stder1 >&2
2795grep -v '^ *+' $at_stder1 >$at_stderr
2796at_failed=false
2797$at_diff $at_devnull $at_stderr || at_failed=:
2798$at_diff $at_devnull $at_stdout || at_failed=:
2799case $at_status in
2800   77) echo 77 > $at_status_file
2801            exit 77;;
2802   0) ;;
2803   *) echo "output.at:75: exit code was $at_status, expected 0"
2804      at_failed=:;;
2805esac
2806if $at_failed; then
2807
2808  echo 1 > $at_status_file
2809  exit 1
2810fi
2811
2812$at_traceon
2813
2814$at_traceoff
2815echo "output.at:75: ls bar.output bar.c bar.h"
2816echo output.at:75 >$at_check_line_file
2817( $at_traceon; ls bar.output bar.c bar.h ) >$at_stdout 2>$at_stder1
2818at_status=$?
2819grep '^ *+' $at_stder1 >&2
2820grep -v '^ *+' $at_stder1 >$at_stderr
2821at_failed=false
2822$at_diff $at_devnull $at_stderr || at_failed=:
2823echo stdout:; cat $at_stdout
2824case $at_status in
2825   77) echo 77 > $at_status_file
2826            exit 77;;
2827   0) ;;
2828   *) echo "output.at:75: exit code was $at_status, expected 0"
2829      at_failed=:;;
2830esac
2831if $at_failed; then
2832
2833  echo 1 > $at_status_file
2834  exit 1
2835fi
2836
2837$at_traceon
2838
2839
2840      $at_traceoff
2841      $at_times_p && times >$at_times_file
2842    ) 5>&1 2>&1 | eval $at_tee_pipe
2843    at_status=`cat $at_status_file`
2844    ;;
2845
2846  24 ) # 24. output.at:80: Output files: %defines %verbose
2847    at_setup_line='output.at:80'
2848    at_desc='Output files: %defines %verbose  '
2849    $at_quiet $ECHO_N " 24: Output files: %defines %verbose              $ECHO_C"
2850    at_xfail=no
2851    (
2852      echo "24. output.at:80: testing ..."
2853      $at_traceon
2854
2855case "foo.yy" in
2856  */*) mkdir `echo "foo.yy" | sed 's,/.*,,'`;;
2857esac
2858cat >foo.yy <<'_ATEOF'
2859%defines %verbose
2860%%
2861foo: {};
2862_ATEOF
2863
2864
2865$at_traceoff
2866echo "output.at:80: bison  foo.yy "
2867echo output.at:80 >$at_check_line_file
2868( $at_traceon; bison  foo.yy  ) >$at_stdout 2>$at_stder1
2869at_status=$?
2870grep '^ *+' $at_stder1 >&2
2871grep -v '^ *+' $at_stder1 >$at_stderr
2872at_failed=false
2873$at_diff $at_devnull $at_stderr || at_failed=:
2874$at_diff $at_devnull $at_stdout || at_failed=:
2875case $at_status in
2876   77) echo 77 > $at_status_file
2877            exit 77;;
2878   0) ;;
2879   *) echo "output.at:80: exit code was $at_status, expected 0"
2880      at_failed=:;;
2881esac
2882if $at_failed; then
2883
2884  echo 1 > $at_status_file
2885  exit 1
2886fi
2887
2888$at_traceon
2889
2890$at_traceoff
2891echo "output.at:80: ls foo.output foo.tab.cc foo.tab.hh"
2892echo output.at:80 >$at_check_line_file
2893( $at_traceon; ls foo.output foo.tab.cc foo.tab.hh ) >$at_stdout 2>$at_stder1
2894at_status=$?
2895grep '^ *+' $at_stder1 >&2
2896grep -v '^ *+' $at_stder1 >$at_stderr
2897at_failed=false
2898$at_diff $at_devnull $at_stderr || at_failed=:
2899echo stdout:; cat $at_stdout
2900case $at_status in
2901   77) echo 77 > $at_status_file
2902            exit 77;;
2903   0) ;;
2904   *) echo "output.at:80: exit code was $at_status, expected 0"
2905      at_failed=:;;
2906esac
2907if $at_failed; then
2908
2909  echo 1 > $at_status_file
2910  exit 1
2911fi
2912
2913$at_traceon
2914
2915
2916      $at_traceoff
2917      $at_times_p && times >$at_times_file
2918    ) 5>&1 2>&1 | eval $at_tee_pipe
2919    at_status=`cat $at_status_file`
2920    ;;
2921
2922  25 ) # 25. output.at:83: Output files: %defines %verbose  -o foo.c
2923    at_setup_line='output.at:83'
2924    at_desc='Output files: %defines %verbose  -o foo.c '
2925    $at_quiet $ECHO_N " 25: Output files: %defines %verbose  -o foo.c    $ECHO_C"
2926    at_xfail=no
2927    (
2928      echo "25. output.at:83: testing ..."
2929      $at_traceon
2930
2931case "foo.yy" in
2932  */*) mkdir `echo "foo.yy" | sed 's,/.*,,'`;;
2933esac
2934cat >foo.yy <<'_ATEOF'
2935%defines %verbose
2936%%
2937foo: {};
2938_ATEOF
2939
2940
2941$at_traceoff
2942echo "output.at:83: bison -o foo.c foo.yy "
2943echo output.at:83 >$at_check_line_file
2944( $at_traceon; bison -o foo.c foo.yy  ) >$at_stdout 2>$at_stder1
2945at_status=$?
2946grep '^ *+' $at_stder1 >&2
2947grep -v '^ *+' $at_stder1 >$at_stderr
2948at_failed=false
2949$at_diff $at_devnull $at_stderr || at_failed=:
2950$at_diff $at_devnull $at_stdout || at_failed=:
2951case $at_status in
2952   77) echo 77 > $at_status_file
2953            exit 77;;
2954   0) ;;
2955   *) echo "output.at:83: exit code was $at_status, expected 0"
2956      at_failed=:;;
2957esac
2958if $at_failed; then
2959
2960  echo 1 > $at_status_file
2961  exit 1
2962fi
2963
2964$at_traceon
2965
2966$at_traceoff
2967echo "output.at:83: ls foo.c foo.h foo.output"
2968echo output.at:83 >$at_check_line_file
2969( $at_traceon; ls foo.c foo.h foo.output ) >$at_stdout 2>$at_stder1
2970at_status=$?
2971grep '^ *+' $at_stder1 >&2
2972grep -v '^ *+' $at_stder1 >$at_stderr
2973at_failed=false
2974$at_diff $at_devnull $at_stderr || at_failed=:
2975echo stdout:; cat $at_stdout
2976case $at_status in
2977   77) echo 77 > $at_status_file
2978            exit 77;;
2979   0) ;;
2980   *) echo "output.at:83: exit code was $at_status, expected 0"
2981      at_failed=:;;
2982esac
2983if $at_failed; then
2984
2985  echo 1 > $at_status_file
2986  exit 1
2987fi
2988
2989$at_traceon
2990
2991
2992      $at_traceoff
2993      $at_times_p && times >$at_times_file
2994    ) 5>&1 2>&1 | eval $at_tee_pipe
2995    at_status=`cat $at_status_file`
2996    ;;
2997
2998  26 ) # 26. output.at:87: Output files:  --defines=foo.hpp -o foo.c++
2999    at_setup_line='output.at:87'
3000    at_desc='Output files:  --defines=foo.hpp -o foo.c++ '
3001    $at_quiet $ECHO_N " 26: Output files:  --defines=foo.hpp -o foo.c++  $ECHO_C"
3002    at_xfail=no
3003    (
3004      echo "26. output.at:87: testing ..."
3005      $at_traceon
3006
3007case "foo.yy" in
3008  */*) mkdir `echo "foo.yy" | sed 's,/.*,,'`;;
3009esac
3010cat >foo.yy <<'_ATEOF'
3011
3012%%
3013foo: {};
3014_ATEOF
3015
3016
3017$at_traceoff
3018echo "output.at:87: bison --defines=foo.hpp -o foo.c++ foo.yy "
3019echo output.at:87 >$at_check_line_file
3020( $at_traceon; bison --defines=foo.hpp -o foo.c++ foo.yy  ) >$at_stdout 2>$at_stder1
3021at_status=$?
3022grep '^ *+' $at_stder1 >&2
3023grep -v '^ *+' $at_stder1 >$at_stderr
3024at_failed=false
3025$at_diff $at_devnull $at_stderr || at_failed=:
3026$at_diff $at_devnull $at_stdout || at_failed=:
3027case $at_status in
3028   77) echo 77 > $at_status_file
3029            exit 77;;
3030   0) ;;
3031   *) echo "output.at:87: exit code was $at_status, expected 0"
3032      at_failed=:;;
3033esac
3034if $at_failed; then
3035
3036  echo 1 > $at_status_file
3037  exit 1
3038fi
3039
3040$at_traceon
3041
3042$at_traceoff
3043echo "output.at:87: ls foo.c++ foo.hpp"
3044echo output.at:87 >$at_check_line_file
3045( $at_traceon; ls foo.c++ foo.hpp ) >$at_stdout 2>$at_stder1
3046at_status=$?
3047grep '^ *+' $at_stder1 >&2
3048grep -v '^ *+' $at_stder1 >$at_stderr
3049at_failed=false
3050$at_diff $at_devnull $at_stderr || at_failed=:
3051echo stdout:; cat $at_stdout
3052case $at_status in
3053   77) echo 77 > $at_status_file
3054            exit 77;;
3055   0) ;;
3056   *) echo "output.at:87: exit code was $at_status, expected 0"
3057      at_failed=:;;
3058esac
3059if $at_failed; then
3060
3061  echo 1 > $at_status_file
3062  exit 1
3063fi
3064
3065$at_traceon
3066
3067
3068      $at_traceoff
3069      $at_times_p && times >$at_times_file
3070    ) 5>&1 2>&1 | eval $at_tee_pipe
3071    at_status=`cat $at_status_file`
3072    ;;
3073
3074  27 ) # 27. output.at:91: Output files:  -o foo.c++ --graph=foo.gph
3075    at_setup_line='output.at:91'
3076    at_desc='Output files:  -o foo.c++ --graph=foo.gph '
3077    $at_quiet $ECHO_N " 27: Output files:  -o foo.c++ --graph=foo.gph    $ECHO_C"
3078    at_xfail=no
3079    (
3080      echo "27. output.at:91: testing ..."
3081      $at_traceon
3082
3083case "foo.yy" in
3084  */*) mkdir `echo "foo.yy" | sed 's,/.*,,'`;;
3085esac
3086cat >foo.yy <<'_ATEOF'
3087
3088%%
3089foo: {};
3090_ATEOF
3091
3092
3093$at_traceoff
3094echo "output.at:91: bison -o foo.c++ --graph=foo.gph foo.yy "
3095echo output.at:91 >$at_check_line_file
3096( $at_traceon; bison -o foo.c++ --graph=foo.gph foo.yy  ) >$at_stdout 2>$at_stder1
3097at_status=$?
3098grep '^ *+' $at_stder1 >&2
3099grep -v '^ *+' $at_stder1 >$at_stderr
3100at_failed=false
3101$at_diff $at_devnull $at_stderr || at_failed=:
3102$at_diff $at_devnull $at_stdout || at_failed=:
3103case $at_status in
3104   77) echo 77 > $at_status_file
3105            exit 77;;
3106   0) ;;
3107   *) echo "output.at:91: exit code was $at_status, expected 0"
3108      at_failed=:;;
3109esac
3110if $at_failed; then
3111
3112  echo 1 > $at_status_file
3113  exit 1
3114fi
3115
3116$at_traceon
3117
3118$at_traceoff
3119echo "output.at:91: ls foo.c++ foo.gph"
3120echo output.at:91 >$at_check_line_file
3121( $at_traceon; ls foo.c++ foo.gph ) >$at_stdout 2>$at_stder1
3122at_status=$?
3123grep '^ *+' $at_stder1 >&2
3124grep -v '^ *+' $at_stder1 >$at_stderr
3125at_failed=false
3126$at_diff $at_devnull $at_stderr || at_failed=:
3127echo stdout:; cat $at_stdout
3128case $at_status in
3129   77) echo 77 > $at_status_file
3130            exit 77;;
3131   0) ;;
3132   *) echo "output.at:91: exit code was $at_status, expected 0"
3133      at_failed=:;;
3134esac
3135if $at_failed; then
3136
3137  echo 1 > $at_status_file
3138  exit 1
3139fi
3140
3141$at_traceon
3142
3143
3144      $at_traceoff
3145      $at_times_p && times >$at_times_file
3146    ) 5>&1 2>&1 | eval $at_tee_pipe
3147    at_status=`cat $at_status_file`
3148    ;;
3149
3150  28 ) # 28. output.at:105: Output files: %skeleton "lalr1.cc" %defines %verbose
3151    at_setup_line='output.at:105'
3152    at_desc='Output files: %skeleton "lalr1.cc" %defines %verbose  '
3153    $at_quiet $ECHO_N " 28: Output files: %skeleton "lalr1.cc" %defines %verbose  $ECHO_C"
3154    at_xfail=no
3155    (
3156      echo "28. output.at:105: testing ..."
3157      $at_traceon
3158
3159case "foo.yy" in
3160  */*) mkdir `echo "foo.yy" | sed 's,/.*,,'`;;
3161esac
3162cat >foo.yy <<'_ATEOF'
3163%skeleton "lalr1.cc" %defines %verbose
3164%%
3165foo: {};
3166_ATEOF
3167
3168
3169$at_traceoff
3170echo "output.at:105: bison  foo.yy "
3171echo output.at:105 >$at_check_line_file
3172( $at_traceon; bison  foo.yy  ) >$at_stdout 2>$at_stder1
3173at_status=$?
3174grep '^ *+' $at_stder1 >&2
3175grep -v '^ *+' $at_stder1 >$at_stderr
3176at_failed=false
3177$at_diff $at_devnull $at_stderr || at_failed=:
3178$at_diff $at_devnull $at_stdout || at_failed=:
3179case $at_status in
3180   77) echo 77 > $at_status_file
3181            exit 77;;
3182   0) ;;
3183   *) echo "output.at:105: exit code was $at_status, expected 0"
3184      at_failed=:;;
3185esac
3186if $at_failed; then
3187
3188  echo 1 > $at_status_file
3189  exit 1
3190fi
3191
3192$at_traceon
3193
3194$at_traceoff
3195echo "output.at:105: ls foo.tab.cc foo.tab.hh foo.output location.hh stack.hh position.hh"
3196echo output.at:105 >$at_check_line_file
3197( $at_traceon; ls foo.tab.cc foo.tab.hh foo.output location.hh stack.hh position.hh ) >$at_stdout 2>$at_stder1
3198at_status=$?
3199grep '^ *+' $at_stder1 >&2
3200grep -v '^ *+' $at_stder1 >$at_stderr
3201at_failed=false
3202$at_diff $at_devnull $at_stderr || at_failed=:
3203echo stdout:; cat $at_stdout
3204case $at_status in
3205   77) echo 77 > $at_status_file
3206            exit 77;;
3207   0) ;;
3208   *) echo "output.at:105: exit code was $at_status, expected 0"
3209      at_failed=:;;
3210esac
3211if $at_failed; then
3212
3213  echo 1 > $at_status_file
3214  exit 1
3215fi
3216
3217$at_traceon
3218
3219
3220      $at_traceoff
3221      $at_times_p && times >$at_times_file
3222    ) 5>&1 2>&1 | eval $at_tee_pipe
3223    at_status=`cat $at_status_file`
3224    ;;
3225
3226  29 ) # 29. output.at:109: Output files: %skeleton "lalr1.cc" %defines %verbose
3227    at_setup_line='output.at:109'
3228    at_desc='Output files: %skeleton "lalr1.cc" %defines %verbose  '
3229    $at_quiet $ECHO_N " 29: Output files: %skeleton "lalr1.cc" %defines %verbose  $ECHO_C"
3230    at_xfail=no
3231    (
3232      echo "29. output.at:109: testing ..."
3233      $at_traceon
3234
3235case "subdir/foo.yy" in
3236  */*) mkdir `echo "subdir/foo.yy" | sed 's,/.*,,'`;;
3237esac
3238cat >subdir/foo.yy <<'_ATEOF'
3239%skeleton "lalr1.cc" %defines %verbose
3240%%
3241foo: {};
3242_ATEOF
3243
3244
3245$at_traceoff
3246echo "output.at:109: bison  subdir/foo.yy "
3247echo output.at:109 >$at_check_line_file
3248( $at_traceon; bison  subdir/foo.yy  ) >$at_stdout 2>$at_stder1
3249at_status=$?
3250grep '^ *+' $at_stder1 >&2
3251grep -v '^ *+' $at_stder1 >$at_stderr
3252at_failed=false
3253$at_diff $at_devnull $at_stderr || at_failed=:
3254$at_diff $at_devnull $at_stdout || at_failed=:
3255case $at_status in
3256   77) echo 77 > $at_status_file
3257            exit 77;;
3258   0) ;;
3259   *) echo "output.at:109: exit code was $at_status, expected 0"
3260      at_failed=:;;
3261esac
3262if $at_failed; then
3263
3264  echo 1 > $at_status_file
3265  exit 1
3266fi
3267
3268$at_traceon
3269
3270$at_traceoff
3271echo "output.at:109: ls foo.tab.cc foo.tab.hh foo.output location.hh stack.hh position.hh"
3272echo output.at:109 >$at_check_line_file
3273( $at_traceon; ls foo.tab.cc foo.tab.hh foo.output location.hh stack.hh position.hh ) >$at_stdout 2>$at_stder1
3274at_status=$?
3275grep '^ *+' $at_stder1 >&2
3276grep -v '^ *+' $at_stder1 >$at_stderr
3277at_failed=false
3278$at_diff $at_devnull $at_stderr || at_failed=:
3279echo stdout:; cat $at_stdout
3280case $at_status in
3281   77) echo 77 > $at_status_file
3282            exit 77;;
3283   0) ;;
3284   *) echo "output.at:109: exit code was $at_status, expected 0"
3285      at_failed=:;;
3286esac
3287if $at_failed; then
3288
3289  echo 1 > $at_status_file
3290  exit 1
3291fi
3292
3293$at_traceon
3294
3295# Also make sure that the includes do not refer to the subdirectory.
3296$at_traceoff
3297echo "output.at:109: grep 'include .subdir/' foo.tab.cc"
3298echo output.at:109 >$at_check_line_file
3299( $at_traceon; grep 'include .subdir/' foo.tab.cc ) >$at_stdout 2>$at_stder1
3300at_status=$?
3301grep '^ *+' $at_stder1 >&2
3302grep -v '^ *+' $at_stder1 >$at_stderr
3303at_failed=false
3304$at_diff $at_devnull $at_stderr || at_failed=:
3305$at_diff $at_devnull $at_stdout || at_failed=:
3306case $at_status in
3307   77) echo 77 > $at_status_file
3308            exit 77;;
3309   1) ;;
3310   *) echo "output.at:109: exit code was $at_status, expected 1"
3311      at_failed=:;;
3312esac
3313if $at_failed; then
3314
3315  echo 1 > $at_status_file
3316  exit 1
3317fi
3318
3319$at_traceon
3320
3321$at_traceoff
3322echo "output.at:109: grep 'include .subdir/' foo.tab.hh"
3323echo output.at:109 >$at_check_line_file
3324( $at_traceon; grep 'include .subdir/' foo.tab.hh ) >$at_stdout 2>$at_stder1
3325at_status=$?
3326grep '^ *+' $at_stder1 >&2
3327grep -v '^ *+' $at_stder1 >$at_stderr
3328at_failed=false
3329$at_diff $at_devnull $at_stderr || at_failed=:
3330$at_diff $at_devnull $at_stdout || at_failed=:
3331case $at_status in
3332   77) echo 77 > $at_status_file
3333            exit 77;;
3334   1) ;;
3335   *) echo "output.at:109: exit code was $at_status, expected 1"
3336      at_failed=:;;
3337esac
3338if $at_failed; then
3339
3340  echo 1 > $at_status_file
3341  exit 1
3342fi
3343
3344$at_traceon
3345
3346
3347      $at_traceoff
3348      $at_times_p && times >$at_times_file
3349    ) 5>&1 2>&1 | eval $at_tee_pipe
3350    at_status=`cat $at_status_file`
3351    ;;
3352
3353  30 ) # 30. output.at:114: Output files: %skeleton "lalr1.cc" %defines %verbose -o subdir/foo.cc
3354    at_setup_line='output.at:114'
3355    at_desc='Output files: %skeleton "lalr1.cc" %defines %verbose -o subdir/foo.cc '
3356    $at_quiet $ECHO_N " 30: Output files: %skeleton "lalr1.cc" %defines %verbose -o subdir/foo.cc $ECHO_C"
3357    at_xfail=no
3358    (
3359      echo "30. output.at:114: testing ..."
3360      $at_traceon
3361
3362case "subdir/foo.yy" in
3363  */*) mkdir `echo "subdir/foo.yy" | sed 's,/.*,,'`;;
3364esac
3365cat >subdir/foo.yy <<'_ATEOF'
3366%skeleton "lalr1.cc" %defines %verbose
3367%%
3368foo: {};
3369_ATEOF
3370
3371
3372$at_traceoff
3373echo "output.at:114: bison -o subdir/foo.cc subdir/foo.yy "
3374echo output.at:114 >$at_check_line_file
3375( $at_traceon; bison -o subdir/foo.cc subdir/foo.yy  ) >$at_stdout 2>$at_stder1
3376at_status=$?
3377grep '^ *+' $at_stder1 >&2
3378grep -v '^ *+' $at_stder1 >$at_stderr
3379at_failed=false
3380$at_diff $at_devnull $at_stderr || at_failed=:
3381$at_diff $at_devnull $at_stdout || at_failed=:
3382case $at_status in
3383   77) echo 77 > $at_status_file
3384            exit 77;;
3385   0) ;;
3386   *) echo "output.at:114: exit code was $at_status, expected 0"
3387      at_failed=:;;
3388esac
3389if $at_failed; then
3390
3391  echo 1 > $at_status_file
3392  exit 1
3393fi
3394
3395$at_traceon
3396
3397$at_traceoff
3398echo "output.at:114: ls subdir/foo.cc subdir/foo.hh subdir/foo.output subdir/location.hh subdir/stack.hh subdir/position.hh"
3399echo output.at:114 >$at_check_line_file
3400( $at_traceon; ls subdir/foo.cc subdir/foo.hh subdir/foo.output subdir/location.hh subdir/stack.hh subdir/position.hh ) >$at_stdout 2>$at_stder1
3401at_status=$?
3402grep '^ *+' $at_stder1 >&2
3403grep -v '^ *+' $at_stder1 >$at_stderr
3404at_failed=false
3405$at_diff $at_devnull $at_stderr || at_failed=:
3406echo stdout:; cat $at_stdout
3407case $at_status in
3408   77) echo 77 > $at_status_file
3409            exit 77;;
3410   0) ;;
3411   *) echo "output.at:114: exit code was $at_status, expected 0"
3412      at_failed=:;;
3413esac
3414if $at_failed; then
3415
3416  echo 1 > $at_status_file
3417  exit 1
3418fi
3419
3420$at_traceon
3421
3422# Also make sure that the includes do not refer to the subdirectory.
3423$at_traceoff
3424echo "output.at:114: grep 'include .subdir/' subdir/foo.cc"
3425echo output.at:114 >$at_check_line_file
3426( $at_traceon; grep 'include .subdir/' subdir/foo.cc ) >$at_stdout 2>$at_stder1
3427at_status=$?
3428grep '^ *+' $at_stder1 >&2
3429grep -v '^ *+' $at_stder1 >$at_stderr
3430at_failed=false
3431$at_diff $at_devnull $at_stderr || at_failed=:
3432$at_diff $at_devnull $at_stdout || at_failed=:
3433case $at_status in
3434   77) echo 77 > $at_status_file
3435            exit 77;;
3436   1) ;;
3437   *) echo "output.at:114: exit code was $at_status, expected 1"
3438      at_failed=:;;
3439esac
3440if $at_failed; then
3441
3442  echo 1 > $at_status_file
3443  exit 1
3444fi
3445
3446$at_traceon
3447
3448$at_traceoff
3449echo "output.at:114: grep 'include .subdir/' subdir/foo.hh"
3450echo output.at:114 >$at_check_line_file
3451( $at_traceon; grep 'include .subdir/' subdir/foo.hh ) >$at_stdout 2>$at_stder1
3452at_status=$?
3453grep '^ *+' $at_stder1 >&2
3454grep -v '^ *+' $at_stder1 >$at_stderr
3455at_failed=false
3456$at_diff $at_devnull $at_stderr || at_failed=:
3457$at_diff $at_devnull $at_stdout || at_failed=:
3458case $at_status in
3459   77) echo 77 > $at_status_file
3460            exit 77;;
3461   1) ;;
3462   *) echo "output.at:114: exit code was $at_status, expected 1"
3463      at_failed=:;;
3464esac
3465if $at_failed; then
3466
3467  echo 1 > $at_status_file
3468  exit 1
3469fi
3470
3471$at_traceon
3472
3473
3474      $at_traceoff
3475      $at_times_p && times >$at_times_file
3476    ) 5>&1 2>&1 | eval $at_tee_pipe
3477    at_status=`cat $at_status_file`
3478    ;;
3479
3480
3481  banner-3 ) # Banner 3. sets.at:59
3482    cat <<\_ATEOF
3483
3484Grammar Sets (Firsts etc.).
3485
3486_ATEOF
3487    ;;
3488
3489  31 ) # 31. sets.at:66: Nullable
3490    at_setup_line='sets.at:66'
3491    at_desc='Nullable'
3492    $at_quiet $ECHO_N " 31: Nullable                                     $ECHO_C"
3493    at_xfail=no
3494    (
3495      echo "31. sets.at:66: testing ..."
3496      $at_traceon
3497
3498
3499# At some point, nullable had been smoking grass, and managed to say:
3500#
3501# Entering set_nullable
3502# NULLABLE
3503#         'e': yes
3504#         (null): no
3505# ...
3506
3507cat >input.y <<'_ATEOF'
3508%%
3509e: 'e' | /* Nothing */;
3510_ATEOF
3511
3512
3513$at_traceoff
3514echo "sets.at:81: bison --trace=sets input.y"
3515echo sets.at:81 >$at_check_line_file
3516( $at_traceon; bison --trace=sets input.y ) >$at_stdout 2>$at_stder1
3517at_status=$?
3518grep '^ *+' $at_stder1 >&2
3519grep -v '^ *+' $at_stder1 >$at_stderr
3520at_failed=false
3521echo stderr:; tee stderr <$at_stderr
3522$at_diff $at_devnull $at_stdout || at_failed=:
3523case $at_status in
3524   77) echo 77 > $at_status_file
3525            exit 77;;
3526   0) ;;
3527   *) echo "sets.at:81: exit code was $at_status, expected 0"
3528      at_failed=:;;
3529esac
3530if $at_failed; then
3531
3532  echo 1 > $at_status_file
3533  exit 1
3534fi
3535
3536$at_traceon
3537
3538cat >extract.sed <<'_ATEOF'
3539#n
3540/^NULLABLE$/ {
3541   :null
3542   p
3543   n
3544   /^[	 ]*$/ !b null
3545}
3546/^FIRSTS$/ {
3547   :firsts
3548   p
3549   n
3550   /^[	 ]*$/ !b firsts
3551}
3552/^FDERIVES$/ {
3553   :fderiv
3554   p
3555   n
3556   /^[	 ]*$/ !b fderiv
3557}
3558/^DERIVES$/ {
3559   :deriv
3560   p
3561   n
3562   /^[	 ]*$/ !b deriv
3563}
3564_ATEOF
3565
3566$at_traceoff
3567echo "sets.at:82: sed -f extract.sed stderr"
3568echo sets.at:82 >$at_check_line_file
3569( $at_traceon; sed -f extract.sed stderr ) >$at_stdout 2>$at_stder1
3570at_status=$?
3571grep '^ *+' $at_stder1 >&2
3572grep -v '^ *+' $at_stder1 >$at_stderr
3573at_failed=false
3574$at_diff $at_devnull $at_stderr || at_failed=:
3575echo stdout:; tee stdout <$at_stdout
3576case $at_status in
3577   77) echo 77 > $at_status_file
3578            exit 77;;
3579   0) ;;
3580   *) echo "sets.at:82: exit code was $at_status, expected 0"
3581      at_failed=:;;
3582esac
3583if $at_failed; then
3584
3585  echo 1 > $at_status_file
3586  exit 1
3587fi
3588
3589$at_traceon
3590
3591$at_traceoff
3592echo "sets.at:82: mv stdout sets"
3593echo sets.at:82 >$at_check_line_file
3594( $at_traceon; mv stdout sets ) >$at_stdout 2>$at_stder1
3595at_status=$?
3596grep '^ *+' $at_stder1 >&2
3597grep -v '^ *+' $at_stder1 >$at_stderr
3598at_failed=false
3599$at_diff $at_devnull $at_stderr || at_failed=:
3600$at_diff $at_devnull $at_stdout || at_failed=:
3601case $at_status in
3602   77) echo 77 > $at_status_file
3603            exit 77;;
3604   0) ;;
3605   *) echo "sets.at:82: exit code was $at_status, expected 0"
3606      at_failed=:;;
3607esac
3608if $at_failed; then
3609
3610  echo 1 > $at_status_file
3611  exit 1
3612fi
3613
3614$at_traceon
3615
3616
3617$at_traceoff
3618echo "sets.at:107: cat sets"
3619echo sets.at:107 >$at_check_line_file
3620( $at_traceon; cat sets ) >$at_stdout 2>$at_stder1
3621at_status=$?
3622grep '^ *+' $at_stder1 >&2
3623grep -v '^ *+' $at_stder1 >$at_stderr
3624at_failed=false
3625$at_diff $at_devnull $at_stderr || at_failed=:
3626echo >>$at_stdout; echo "DERIVES
3627	\$accept derives
3628		  0  e \$end
3629	e derives
3630		  1  'e'
3631		  2  /* empty */
3632NULLABLE
3633	\$accept: no
3634	e: yes
3635FIRSTS
3636	\$accept firsts
3637		\$accept
3638		e
3639	e firsts
3640		e
3641FDERIVES
3642	\$accept derives
3643		  0  e \$end
3644		  1  'e'
3645		  2  /* empty */
3646	e derives
3647		  1  'e'
3648		  2  /* empty */
3649" | $at_diff - $at_stdout || at_failed=:
3650case $at_status in
3651   77) echo 77 > $at_status_file
3652            exit 77;;
3653   0) ;;
3654   *) echo "sets.at:107: exit code was $at_status, expected 0"
3655      at_failed=:;;
3656esac
3657if $at_failed; then
3658
3659  echo 1 > $at_status_file
3660  exit 1
3661fi
3662
3663$at_traceon
3664
3665
3666      $at_traceoff
3667      $at_times_p && times >$at_times_file
3668    ) 5>&1 2>&1 | eval $at_tee_pipe
3669    at_status=`cat $at_status_file`
3670    ;;
3671
3672  32 ) # 32. sets.at:151: Broken Closure
3673    at_setup_line='sets.at:151'
3674    at_desc='Broken Closure'
3675    $at_quiet $ECHO_N " 32: Broken Closure                               $ECHO_C"
3676    at_xfail=no
3677    (
3678      echo "32. sets.at:151: testing ..."
3679      $at_traceon
3680
3681
3682cat >input.y <<'_ATEOF'
3683%%
3684a: b;
3685b: c;
3686c: d;
3687d: e;
3688e: f;
3689f: g;
3690g: h;
3691h: 'h';
3692_ATEOF
3693
3694
3695$at_traceoff
3696echo "sets.at:165: bison --trace=sets input.y"
3697echo sets.at:165 >$at_check_line_file
3698( $at_traceon; bison --trace=sets input.y ) >$at_stdout 2>$at_stder1
3699at_status=$?
3700grep '^ *+' $at_stder1 >&2
3701grep -v '^ *+' $at_stder1 >$at_stderr
3702at_failed=false
3703echo stderr:; tee stderr <$at_stderr
3704$at_diff $at_devnull $at_stdout || at_failed=:
3705case $at_status in
3706   77) echo 77 > $at_status_file
3707            exit 77;;
3708   0) ;;
3709   *) echo "sets.at:165: exit code was $at_status, expected 0"
3710      at_failed=:;;
3711esac
3712if $at_failed; then
3713
3714  echo 1 > $at_status_file
3715  exit 1
3716fi
3717
3718$at_traceon
3719
3720
3721$at_traceoff
3722echo "sets.at:183: sed -n 's/[	 ]*\$//;/^RTC: Firsts Output BEGIN/,/^RTC: Firsts Output END/p' stderr"
3723echo sets.at:183 >$at_check_line_file
3724( $at_traceon; sed -n 's/[	 ]*$//;/^RTC: Firsts Output BEGIN/,/^RTC: Firsts Output END/p' stderr ) >$at_stdout 2>$at_stder1
3725at_status=$?
3726grep '^ *+' $at_stder1 >&2
3727grep -v '^ *+' $at_stder1 >$at_stderr
3728at_failed=false
3729$at_diff $at_devnull $at_stderr || at_failed=:
3730echo >>$at_stdout; echo "RTC: Firsts Output BEGIN
3731
3732   012345678
3733  .---------.
3734 0|111111111|
3735 1| 11111111|
3736 2|  1111111|
3737 3|   111111|
3738 4|    11111|
3739 5|     1111|
3740 6|      111|
3741 7|       11|
3742 8|        1|
3743  \`---------'
3744RTC: Firsts Output END
3745" | $at_diff - $at_stdout || at_failed=:
3746case $at_status in
3747   77) echo 77 > $at_status_file
3748            exit 77;;
3749   0) ;;
3750   *) echo "sets.at:183: exit code was $at_status, expected 0"
3751      at_failed=:;;
3752esac
3753if $at_failed; then
3754
3755  echo 1 > $at_status_file
3756  exit 1
3757fi
3758
3759$at_traceon
3760
3761
3762      $at_traceoff
3763      $at_times_p && times >$at_times_file
3764    ) 5>&1 2>&1 | eval $at_tee_pipe
3765    at_status=`cat $at_status_file`
3766    ;;
3767
3768  33 ) # 33. sets.at:193: Firsts
3769    at_setup_line='sets.at:193'
3770    at_desc='Firsts'
3771    $at_quiet $ECHO_N " 33: Firsts                                       $ECHO_C"
3772    at_xfail=no
3773    (
3774      echo "33. sets.at:193: testing ..."
3775      $at_traceon
3776
3777
3778cat >input.y <<'_ATEOF'
3779%nonassoc '<' '>'
3780%left '+' '-'
3781%right '^' '='
3782%%
3783exp:
3784   exp '<' exp
3785 | exp '>' exp
3786 | exp '+' exp
3787 | exp '-' exp
3788 | exp '^' exp
3789 | exp '=' exp
3790 | "exp"
3791 ;
3792_ATEOF
3793
3794
3795$at_traceoff
3796echo "sets.at:211: bison --trace=sets input.y"
3797echo sets.at:211 >$at_check_line_file
3798( $at_traceon; bison --trace=sets input.y ) >$at_stdout 2>$at_stder1
3799at_status=$?
3800grep '^ *+' $at_stder1 >&2
3801grep -v '^ *+' $at_stder1 >$at_stderr
3802at_failed=false
3803echo stderr:; tee stderr <$at_stderr
3804$at_diff $at_devnull $at_stdout || at_failed=:
3805case $at_status in
3806   77) echo 77 > $at_status_file
3807            exit 77;;
3808   0) ;;
3809   *) echo "sets.at:211: exit code was $at_status, expected 0"
3810      at_failed=:;;
3811esac
3812if $at_failed; then
3813
3814  echo 1 > $at_status_file
3815  exit 1
3816fi
3817
3818$at_traceon
3819
3820cat >extract.sed <<'_ATEOF'
3821#n
3822/^NULLABLE$/ {
3823   :null
3824   p
3825   n
3826   /^[	 ]*$/ !b null
3827}
3828/^FIRSTS$/ {
3829   :firsts
3830   p
3831   n
3832   /^[	 ]*$/ !b firsts
3833}
3834/^FDERIVES$/ {
3835   :fderiv
3836   p
3837   n
3838   /^[	 ]*$/ !b fderiv
3839}
3840/^DERIVES$/ {
3841   :deriv
3842   p
3843   n
3844   /^[	 ]*$/ !b deriv
3845}
3846_ATEOF
3847
3848$at_traceoff
3849echo "sets.at:212: sed -f extract.sed stderr"
3850echo sets.at:212 >$at_check_line_file
3851( $at_traceon; sed -f extract.sed stderr ) >$at_stdout 2>$at_stder1
3852at_status=$?
3853grep '^ *+' $at_stder1 >&2
3854grep -v '^ *+' $at_stder1 >$at_stderr
3855at_failed=false
3856$at_diff $at_devnull $at_stderr || at_failed=:
3857echo stdout:; tee stdout <$at_stdout
3858case $at_status in
3859   77) echo 77 > $at_status_file
3860            exit 77;;
3861   0) ;;
3862   *) echo "sets.at:212: exit code was $at_status, expected 0"
3863      at_failed=:;;
3864esac
3865if $at_failed; then
3866
3867  echo 1 > $at_status_file
3868  exit 1
3869fi
3870
3871$at_traceon
3872
3873$at_traceoff
3874echo "sets.at:212: mv stdout sets"
3875echo sets.at:212 >$at_check_line_file
3876( $at_traceon; mv stdout sets ) >$at_stdout 2>$at_stder1
3877at_status=$?
3878grep '^ *+' $at_stder1 >&2
3879grep -v '^ *+' $at_stder1 >$at_stderr
3880at_failed=false
3881$at_diff $at_devnull $at_stderr || at_failed=:
3882$at_diff $at_devnull $at_stdout || at_failed=:
3883case $at_status in
3884   77) echo 77 > $at_status_file
3885            exit 77;;
3886   0) ;;
3887   *) echo "sets.at:212: exit code was $at_status, expected 0"
3888      at_failed=:;;
3889esac
3890if $at_failed; then
3891
3892  echo 1 > $at_status_file
3893  exit 1
3894fi
3895
3896$at_traceon
3897
3898
3899$at_traceoff
3900echo "sets.at:252: cat sets"
3901echo sets.at:252 >$at_check_line_file
3902( $at_traceon; cat sets ) >$at_stdout 2>$at_stder1
3903at_status=$?
3904grep '^ *+' $at_stder1 >&2
3905grep -v '^ *+' $at_stder1 >$at_stderr
3906at_failed=false
3907$at_diff $at_devnull $at_stderr || at_failed=:
3908echo >>$at_stdout; echo "DERIVES
3909	\$accept derives
3910		  0  exp \$end
3911	exp derives
3912		  1  exp '<' exp
3913		  2  exp '>' exp
3914		  3  exp '+' exp
3915		  4  exp '-' exp
3916		  5  exp '^' exp
3917		  6  exp '=' exp
3918		  7  \"exp\"
3919NULLABLE
3920	\$accept: no
3921	exp: no
3922FIRSTS
3923	\$accept firsts
3924		\$accept
3925		exp
3926	exp firsts
3927		exp
3928FDERIVES
3929	\$accept derives
3930		  0  exp \$end
3931		  1  exp '<' exp
3932		  2  exp '>' exp
3933		  3  exp '+' exp
3934		  4  exp '-' exp
3935		  5  exp '^' exp
3936		  6  exp '=' exp
3937		  7  \"exp\"
3938	exp derives
3939		  1  exp '<' exp
3940		  2  exp '>' exp
3941		  3  exp '+' exp
3942		  4  exp '-' exp
3943		  5  exp '^' exp
3944		  6  exp '=' exp
3945		  7  \"exp\"
3946" | $at_diff - $at_stdout || at_failed=:
3947case $at_status in
3948   77) echo 77 > $at_status_file
3949            exit 77;;
3950   0) ;;
3951   *) echo "sets.at:252: exit code was $at_status, expected 0"
3952      at_failed=:;;
3953esac
3954if $at_failed; then
3955
3956  echo 1 > $at_status_file
3957  exit 1
3958fi
3959
3960$at_traceon
3961
3962
3963      $at_traceoff
3964      $at_times_p && times >$at_times_file
3965    ) 5>&1 2>&1 | eval $at_tee_pipe
3966    at_status=`cat $at_status_file`
3967    ;;
3968
3969  34 ) # 34. sets.at:269: Accept
3970    at_setup_line='sets.at:269'
3971    at_desc='Accept'
3972    $at_quiet $ECHO_N " 34: Accept                                       $ECHO_C"
3973    at_xfail=no
3974    (
3975      echo "34. sets.at:269: testing ..."
3976      $at_traceon
3977
3978
3979cat >input.y <<'_ATEOF'
3980%token END 0
3981%%
3982input:
3983  'a'
3984| '(' input ')'
3985| '(' error END
3986;
3987_ATEOF
3988
3989
3990$at_traceoff
3991echo "sets.at:281: bison -v -o input.c input.y"
3992echo sets.at:281 >$at_check_line_file
3993( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
3994at_status=$?
3995grep '^ *+' $at_stder1 >&2
3996grep -v '^ *+' $at_stder1 >$at_stderr
3997at_failed=false
3998$at_diff $at_devnull $at_stderr || at_failed=:
3999$at_diff $at_devnull $at_stdout || at_failed=:
4000case $at_status in
4001   77) echo 77 > $at_status_file
4002            exit 77;;
4003   0) ;;
4004   *) echo "sets.at:281: exit code was $at_status, expected 0"
4005      at_failed=:;;
4006esac
4007if $at_failed; then
4008
4009  echo 1 > $at_status_file
4010  exit 1
4011fi
4012
4013$at_traceon
4014
4015
4016# Get the final state in the parser.
4017$at_traceoff
4018echo "sets.at:285: sed -n 's/.*define YYFINAL *\\([0-9][0-9]*\\)/final state \\1/p' input.c"
4019echo sets.at:285 >$at_check_line_file
4020( $at_traceon; sed -n 's/.*define YYFINAL *\([0-9][0-9]*\)/final state \1/p' input.c ) >$at_stdout 2>$at_stder1
4021at_status=$?
4022grep '^ *+' $at_stder1 >&2
4023grep -v '^ *+' $at_stder1 >$at_stderr
4024at_failed=false
4025$at_diff $at_devnull $at_stderr || at_failed=:
4026echo stdout:; tee stdout <$at_stdout
4027case $at_status in
4028   77) echo 77 > $at_status_file
4029            exit 77;;
4030   0) ;;
4031   *) echo "sets.at:285: exit code was $at_status, expected 0"
4032      at_failed=:;;
4033esac
4034if $at_failed; then
4035
4036  echo 1 > $at_status_file
4037  exit 1
4038fi
4039
4040$at_traceon
4041
4042mv stdout expout
4043
4044# Get the final state in the report, from the "accept" action..
4045$at_traceoff
4046echo "sets.at:300: sed -n '
4047           /^state \\(.*\\)/{
4048	     s//final state \\1/
4049	     x
4050	   }
4051	   / accept/{
4052	     x
4053	     p
4054	     q
4055	   }
4056	' input.output"
4057echo sets.at:300 >$at_check_line_file
4058( $at_traceon; sed -n '
4059           /^state \(.*\)/{
4060	     s//final state \1/
4061	     x
4062	   }
4063	   / accept/{
4064	     x
4065	     p
4066	     q
4067	   }
4068	' input.output ) >$at_stdout 2>$at_stder1
4069at_status=$?
4070grep '^ *+' $at_stder1 >&2
4071grep -v '^ *+' $at_stder1 >$at_stderr
4072at_failed=false
4073$at_diff $at_devnull $at_stderr || at_failed=:
4074$at_diff expout $at_stdout || at_failed=:
4075case $at_status in
4076   77) echo 77 > $at_status_file
4077            exit 77;;
4078   0) ;;
4079   *) echo "sets.at:300: exit code was $at_status, expected 0"
4080      at_failed=:;;
4081esac
4082if $at_failed; then
4083
4084  echo 1 > $at_status_file
4085  exit 1
4086fi
4087
4088$at_traceon
4089
4090
4091      $at_traceoff
4092      $at_times_p && times >$at_times_file
4093    ) 5>&1 2>&1 | eval $at_tee_pipe
4094    at_status=`cat $at_status_file`
4095    ;;
4096
4097
4098  banner-4 ) # Banner 4. reduce.at:19
4099    cat <<\_ATEOF
4100
4101Grammar Reduction.
4102
4103_ATEOF
4104    ;;
4105
4106  35 ) # 35. reduce.at:26: Useless Terminals
4107    at_setup_line='reduce.at:26'
4108    at_desc='Useless Terminals'
4109    $at_quiet $ECHO_N " 35: Useless Terminals                            $ECHO_C"
4110    at_xfail=no
4111    (
4112      echo "35. reduce.at:26: testing ..."
4113      $at_traceon
4114
4115
4116cat >input.y <<'_ATEOF'
4117%verbose
4118%output="input.c"
4119
4120%token useless1
4121%token useless2
4122%token useless3
4123%token useless4
4124%token useless5
4125%token useless6
4126%token useless7
4127%token useless8
4128%token useless9
4129
4130%token useful
4131%%
4132exp: useful;
4133_ATEOF
4134
4135
4136$at_traceoff
4137echo "reduce.at:47: bison input.y"
4138echo reduce.at:47 >$at_check_line_file
4139( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
4140at_status=$?
4141grep '^ *+' $at_stder1 >&2
4142grep -v '^ *+' $at_stder1 >$at_stderr
4143at_failed=false
4144$at_diff $at_devnull $at_stderr || at_failed=:
4145$at_diff $at_devnull $at_stdout || at_failed=:
4146case $at_status in
4147   77) echo 77 > $at_status_file
4148            exit 77;;
4149   0) ;;
4150   *) echo "reduce.at:47: exit code was $at_status, expected 0"
4151      at_failed=:;;
4152esac
4153if $at_failed; then
4154
4155  echo 1 > $at_status_file
4156  exit 1
4157fi
4158
4159$at_traceon
4160
4161
4162$at_traceoff
4163echo "reduce.at:60: sed -n '/^Grammar/q;/^\$/!p' input.output"
4164echo reduce.at:60 >$at_check_line_file
4165( $at_traceon; sed -n '/^Grammar/q;/^$/!p' input.output ) >$at_stdout 2>$at_stder1
4166at_status=$?
4167grep '^ *+' $at_stder1 >&2
4168grep -v '^ *+' $at_stder1 >$at_stderr
4169at_failed=false
4170$at_diff $at_devnull $at_stderr || at_failed=:
4171echo >>$at_stdout; echo "Terminals which are not used
4172   useless1
4173   useless2
4174   useless3
4175   useless4
4176   useless5
4177   useless6
4178   useless7
4179   useless8
4180   useless9
4181" | $at_diff - $at_stdout || at_failed=:
4182case $at_status in
4183   77) echo 77 > $at_status_file
4184            exit 77;;
4185   0) ;;
4186   *) echo "reduce.at:60: exit code was $at_status, expected 0"
4187      at_failed=:;;
4188esac
4189if $at_failed; then
4190
4191  echo 1 > $at_status_file
4192  exit 1
4193fi
4194
4195$at_traceon
4196
4197
4198      $at_traceoff
4199      $at_times_p && times >$at_times_file
4200    ) 5>&1 2>&1 | eval $at_tee_pipe
4201    at_status=`cat $at_status_file`
4202    ;;
4203
4204  36 ) # 36. reduce.at:70: Useless Nonterminals
4205    at_setup_line='reduce.at:70'
4206    at_desc='Useless Nonterminals'
4207    $at_quiet $ECHO_N " 36: Useless Nonterminals                         $ECHO_C"
4208    at_xfail=no
4209    (
4210      echo "36. reduce.at:70: testing ..."
4211      $at_traceon
4212
4213
4214cat >input.y <<'_ATEOF'
4215%verbose
4216%output="input.c"
4217
4218%nterm useless1
4219%nterm useless2
4220%nterm useless3
4221%nterm useless4
4222%nterm useless5
4223%nterm useless6
4224%nterm useless7
4225%nterm useless8
4226%nterm useless9
4227
4228%token useful
4229%%
4230exp: useful;
4231_ATEOF
4232
4233
4234$at_traceoff
4235echo "reduce.at:102: bison input.y"
4236echo reduce.at:102 >$at_check_line_file
4237( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
4238at_status=$?
4239grep '^ *+' $at_stder1 >&2
4240grep -v '^ *+' $at_stder1 >$at_stderr
4241at_failed=false
4242echo >>$at_stderr; echo "input.y: warning: 9 useless nonterminals
4243input.y:4.8-15: warning: useless nonterminal: useless1
4244input.y:5.8-15: warning: useless nonterminal: useless2
4245input.y:6.8-15: warning: useless nonterminal: useless3
4246input.y:7.8-15: warning: useless nonterminal: useless4
4247input.y:8.8-15: warning: useless nonterminal: useless5
4248input.y:9.8-15: warning: useless nonterminal: useless6
4249input.y:10.8-15: warning: useless nonterminal: useless7
4250input.y:11.8-15: warning: useless nonterminal: useless8
4251input.y:12.8-15: warning: useless nonterminal: useless9
4252" | $at_diff - $at_stderr || at_failed=:
4253$at_diff $at_devnull $at_stdout || at_failed=:
4254case $at_status in
4255   77) echo 77 > $at_status_file
4256            exit 77;;
4257   0) ;;
4258   *) echo "reduce.at:102: exit code was $at_status, expected 0"
4259      at_failed=:;;
4260esac
4261if $at_failed; then
4262
4263  echo 1 > $at_status_file
4264  exit 1
4265fi
4266
4267$at_traceon
4268
4269
4270$at_traceoff
4271echo "reduce.at:115: sed -n '/^Grammar/q;/^\$/!p' input.output"
4272echo reduce.at:115 >$at_check_line_file
4273( $at_traceon; sed -n '/^Grammar/q;/^$/!p' input.output ) >$at_stdout 2>$at_stder1
4274at_status=$?
4275grep '^ *+' $at_stder1 >&2
4276grep -v '^ *+' $at_stder1 >$at_stderr
4277at_failed=false
4278$at_diff $at_devnull $at_stderr || at_failed=:
4279echo >>$at_stdout; echo "Useless nonterminals
4280   useless1
4281   useless2
4282   useless3
4283   useless4
4284   useless5
4285   useless6
4286   useless7
4287   useless8
4288   useless9
4289" | $at_diff - $at_stdout || at_failed=:
4290case $at_status in
4291   77) echo 77 > $at_status_file
4292            exit 77;;
4293   0) ;;
4294   *) echo "reduce.at:115: exit code was $at_status, expected 0"
4295      at_failed=:;;
4296esac
4297if $at_failed; then
4298
4299  echo 1 > $at_status_file
4300  exit 1
4301fi
4302
4303$at_traceon
4304
4305
4306      $at_traceoff
4307      $at_times_p && times >$at_times_file
4308    ) 5>&1 2>&1 | eval $at_tee_pipe
4309    at_status=`cat $at_status_file`
4310    ;;
4311
4312  37 ) # 37. reduce.at:125: Useless Rules
4313    at_setup_line='reduce.at:125'
4314    at_desc='Useless Rules'
4315    $at_quiet $ECHO_N " 37: Useless Rules                                $ECHO_C"
4316    at_xfail=no
4317    (
4318      echo "37. reduce.at:125: testing ..."
4319      $at_traceon
4320
4321
4322
4323
4324cat >input.y <<'_ATEOF'
4325%verbose
4326%output="input.c"
4327%token useful
4328%%
4329exp: useful;
4330useless1: '1';
4331useless2: '2';
4332useless3: '3';
4333useless4: '4';
4334useless5: '5';
4335useless6: '6';
4336useless7: '7';
4337useless8: '8';
4338useless9: '9';
4339_ATEOF
4340
4341
4342$at_traceoff
4343echo "reduce.at:166: bison input.y"
4344echo reduce.at:166 >$at_check_line_file
4345( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
4346at_status=$?
4347grep '^ *+' $at_stder1 >&2
4348grep -v '^ *+' $at_stder1 >$at_stderr
4349at_failed=false
4350echo >>$at_stderr; echo "input.y: warning: 9 useless nonterminals and 9 useless rules
4351input.y:6.1-8: warning: useless nonterminal: useless1
4352input.y:7.1-8: warning: useless nonterminal: useless2
4353input.y:8.1-8: warning: useless nonterminal: useless3
4354input.y:9.1-8: warning: useless nonterminal: useless4
4355input.y:10.1-8: warning: useless nonterminal: useless5
4356input.y:11.1-8: warning: useless nonterminal: useless6
4357input.y:12.1-8: warning: useless nonterminal: useless7
4358input.y:13.1-8: warning: useless nonterminal: useless8
4359input.y:14.1-8: warning: useless nonterminal: useless9
4360input.y:6.11-13: warning: useless rule: useless1: '1'
4361input.y:7.11-13: warning: useless rule: useless2: '2'
4362input.y:8.11-13: warning: useless rule: useless3: '3'
4363input.y:9.11-13: warning: useless rule: useless4: '4'
4364input.y:10.11-13: warning: useless rule: useless5: '5'
4365input.y:11.11-13: warning: useless rule: useless6: '6'
4366input.y:12.11-13: warning: useless rule: useless7: '7'
4367input.y:13.11-13: warning: useless rule: useless8: '8'
4368input.y:14.11-13: warning: useless rule: useless9: '9'
4369" | $at_diff - $at_stderr || at_failed=:
4370$at_diff $at_devnull $at_stdout || at_failed=:
4371case $at_status in
4372   77) echo 77 > $at_status_file
4373            exit 77;;
4374   0) ;;
4375   *) echo "reduce.at:166: exit code was $at_status, expected 0"
4376      at_failed=:;;
4377esac
4378if $at_failed; then
4379
4380  echo 1 > $at_status_file
4381  exit 1
4382fi
4383
4384$at_traceon
4385
4386
4387$at_traceoff
4388echo "reduce.at:199: sed -n '/^Grammar/q;/^\$/!p' input.output"
4389echo reduce.at:199 >$at_check_line_file
4390( $at_traceon; sed -n '/^Grammar/q;/^$/!p' input.output ) >$at_stdout 2>$at_stder1
4391at_status=$?
4392grep '^ *+' $at_stder1 >&2
4393grep -v '^ *+' $at_stder1 >$at_stderr
4394at_failed=false
4395$at_diff $at_devnull $at_stderr || at_failed=:
4396echo >>$at_stdout; echo "Useless nonterminals
4397   useless1
4398   useless2
4399   useless3
4400   useless4
4401   useless5
4402   useless6
4403   useless7
4404   useless8
4405   useless9
4406Terminals which are not used
4407   '1'
4408   '2'
4409   '3'
4410   '4'
4411   '5'
4412   '6'
4413   '7'
4414   '8'
4415   '9'
4416Useless rules
4417    2 useless1: '1'
4418    3 useless2: '2'
4419    4 useless3: '3'
4420    5 useless4: '4'
4421    6 useless5: '5'
4422    7 useless6: '6'
4423    8 useless7: '7'
4424    9 useless8: '8'
4425   10 useless9: '9'
4426" | $at_diff - $at_stdout || at_failed=:
4427case $at_status in
4428   77) echo 77 > $at_status_file
4429            exit 77;;
4430   0) ;;
4431   *) echo "reduce.at:199: exit code was $at_status, expected 0"
4432      at_failed=:;;
4433esac
4434if $at_failed; then
4435
4436  echo 1 > $at_status_file
4437  exit 1
4438fi
4439
4440$at_traceon
4441
4442
4443      $at_traceoff
4444      $at_times_p && times >$at_times_file
4445    ) 5>&1 2>&1 | eval $at_tee_pipe
4446    at_status=`cat $at_status_file`
4447    ;;
4448
4449  38 ) # 38. reduce.at:212: Reduced Automaton
4450    at_setup_line='reduce.at:212'
4451    at_desc='Reduced Automaton'
4452    $at_quiet $ECHO_N " 38: Reduced Automaton                            $ECHO_C"
4453    at_xfail=no
4454    (
4455      echo "38. reduce.at:212: testing ..."
4456      $at_traceon
4457
4458
4459
4460
4461# The non reduced grammar.
4462# ------------------------
4463cat >not-reduced.y <<'_ATEOF'
4464/* A useless token. */
4465%token useless_token
4466/* A useful one. */
4467%token useful
4468%verbose
4469%output="not-reduced.c"
4470
4471%%
4472
4473exp: useful            { /* A useful action. */ }
4474   | non_productive    { /* A non productive action. */ }
4475   ;
4476
4477not_reachable: useful  { /* A not reachable action. */ }
4478             ;
4479
4480non_productive: non_productive useless_token
4481                       { /* Another non productive action. */ }
4482              ;
4483%%
4484_ATEOF
4485
4486
4487$at_traceoff
4488echo "reduce.at:248: bison not-reduced.y"
4489echo reduce.at:248 >$at_check_line_file
4490( $at_traceon; bison not-reduced.y ) >$at_stdout 2>$at_stder1
4491at_status=$?
4492grep '^ *+' $at_stder1 >&2
4493grep -v '^ *+' $at_stder1 >$at_stderr
4494at_failed=false
4495echo >>$at_stderr; echo "not-reduced.y: warning: 2 useless nonterminals and 3 useless rules
4496not-reduced.y:14.1-13: warning: useless nonterminal: not_reachable
4497not-reduced.y:11.6-19: warning: useless nonterminal: non_productive
4498not-reduced.y:11.6-57: warning: useless rule: exp: non_productive
4499not-reduced.y:14.16-56: warning: useless rule: not_reachable: useful
4500not-reduced.y:17.17-18.63: warning: useless rule: non_productive: non_productive useless_token
4501" | $at_diff - $at_stderr || at_failed=:
4502$at_diff $at_devnull $at_stdout || at_failed=:
4503case $at_status in
4504   77) echo 77 > $at_status_file
4505            exit 77;;
4506   0) ;;
4507   *) echo "reduce.at:248: exit code was $at_status, expected 0"
4508      at_failed=:;;
4509esac
4510if $at_failed; then
4511
4512  echo 1 > $at_status_file
4513  exit 1
4514fi
4515
4516$at_traceon
4517
4518
4519$at_traceoff
4520echo "reduce.at:260: sed -n '/^Grammar/q;/^\$/!p' not-reduced.output"
4521echo reduce.at:260 >$at_check_line_file
4522( $at_traceon; sed -n '/^Grammar/q;/^$/!p' not-reduced.output ) >$at_stdout 2>$at_stder1
4523at_status=$?
4524grep '^ *+' $at_stder1 >&2
4525grep -v '^ *+' $at_stder1 >$at_stderr
4526at_failed=false
4527$at_diff $at_devnull $at_stderr || at_failed=:
4528echo >>$at_stdout; echo "Useless nonterminals
4529   not_reachable
4530   non_productive
4531Terminals which are not used
4532   useless_token
4533Useless rules
4534    2 exp: non_productive
4535    3 not_reachable: useful
4536    4 non_productive: non_productive useless_token
4537" | $at_diff - $at_stdout || at_failed=:
4538case $at_status in
4539   77) echo 77 > $at_status_file
4540            exit 77;;
4541   0) ;;
4542   *) echo "reduce.at:260: exit code was $at_status, expected 0"
4543      at_failed=:;;
4544esac
4545if $at_failed; then
4546
4547  echo 1 > $at_status_file
4548  exit 1
4549fi
4550
4551$at_traceon
4552
4553
4554# The reduced grammar.
4555# --------------------
4556cat >reduced.y <<'_ATEOF'
4557/* A useless token. */
4558%token useless_token
4559/* A useful one. */
4560%token useful
4561%verbose
4562%output="reduced.c"
4563
4564%%
4565
4566exp: useful            { /* A useful action. */ }
4567//   | non_productive    { /* A non productive action. */ } */
4568   ;
4569
4570//not_reachable: useful  { /* A not reachable action. */ }
4571//             ;
4572
4573//non_productive: non_productive useless_token
4574//                       { /* Another non productive action. */ }
4575//              ;
4576%%
4577_ATEOF
4578
4579
4580$at_traceoff
4581echo "reduce.at:287: bison reduced.y"
4582echo reduce.at:287 >$at_check_line_file
4583( $at_traceon; bison reduced.y ) >$at_stdout 2>$at_stder1
4584at_status=$?
4585grep '^ *+' $at_stder1 >&2
4586grep -v '^ *+' $at_stder1 >$at_stderr
4587at_failed=false
4588$at_diff $at_devnull $at_stderr || at_failed=:
4589$at_diff $at_devnull $at_stdout || at_failed=:
4590case $at_status in
4591   77) echo 77 > $at_status_file
4592            exit 77;;
4593   0) ;;
4594   *) echo "reduce.at:287: exit code was $at_status, expected 0"
4595      at_failed=:;;
4596esac
4597if $at_failed; then
4598
4599  echo 1 > $at_status_file
4600  exit 1
4601fi
4602
4603$at_traceon
4604
4605
4606# Comparing the parsers.
4607cp reduced.c expout
4608$at_traceoff
4609echo "reduce.at:291: sed 's/not-reduced/reduced/g' not-reduced.c"
4610echo reduce.at:291 >$at_check_line_file
4611( $at_traceon; sed 's/not-reduced/reduced/g' not-reduced.c ) >$at_stdout 2>$at_stder1
4612at_status=$?
4613grep '^ *+' $at_stder1 >&2
4614grep -v '^ *+' $at_stder1 >$at_stderr
4615at_failed=false
4616$at_diff $at_devnull $at_stderr || at_failed=:
4617$at_diff expout $at_stdout || at_failed=:
4618case $at_status in
4619   77) echo 77 > $at_status_file
4620            exit 77;;
4621   0) ;;
4622   *) echo "reduce.at:291: exit code was $at_status, expected 0"
4623      at_failed=:;;
4624esac
4625if $at_failed; then
4626
4627  echo 1 > $at_status_file
4628  exit 1
4629fi
4630
4631$at_traceon
4632
4633
4634      $at_traceoff
4635      $at_times_p && times >$at_times_file
4636    ) 5>&1 2>&1 | eval $at_tee_pipe
4637    at_status=`cat $at_status_file`
4638    ;;
4639
4640  39 ) # 39. reduce.at:301: Underivable Rules
4641    at_setup_line='reduce.at:301'
4642    at_desc='Underivable Rules'
4643    $at_quiet $ECHO_N " 39: Underivable Rules                            $ECHO_C"
4644    at_xfail=no
4645    (
4646      echo "39. reduce.at:301: testing ..."
4647      $at_traceon
4648
4649
4650
4651
4652cat >input.y <<'_ATEOF'
4653%verbose
4654%output="input.c"
4655%token useful
4656%%
4657exp: useful | underivable;
4658underivable: indirection;
4659indirection: underivable;
4660_ATEOF
4661
4662
4663$at_traceoff
4664echo "reduce.at:322: bison input.y"
4665echo reduce.at:322 >$at_check_line_file
4666( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
4667at_status=$?
4668grep '^ *+' $at_stder1 >&2
4669grep -v '^ *+' $at_stder1 >$at_stderr
4670at_failed=false
4671echo >>$at_stderr; echo "input.y: warning: 2 useless nonterminals and 3 useless rules
4672input.y:5.15-25: warning: useless nonterminal: underivable
4673input.y:6.14-24: warning: useless nonterminal: indirection
4674input.y:5.15-25: warning: useless rule: exp: underivable
4675input.y:6.14-24: warning: useless rule: underivable: indirection
4676input.y:7.14-24: warning: useless rule: indirection: underivable
4677" | $at_diff - $at_stderr || at_failed=:
4678$at_diff $at_devnull $at_stdout || at_failed=:
4679case $at_status in
4680   77) echo 77 > $at_status_file
4681            exit 77;;
4682   0) ;;
4683   *) echo "reduce.at:322: exit code was $at_status, expected 0"
4684      at_failed=:;;
4685esac
4686if $at_failed; then
4687
4688  echo 1 > $at_status_file
4689  exit 1
4690fi
4691
4692$at_traceon
4693
4694
4695$at_traceoff
4696echo "reduce.at:332: sed -n '/^Grammar/q;/^\$/!p' input.output"
4697echo reduce.at:332 >$at_check_line_file
4698( $at_traceon; sed -n '/^Grammar/q;/^$/!p' input.output ) >$at_stdout 2>$at_stder1
4699at_status=$?
4700grep '^ *+' $at_stder1 >&2
4701grep -v '^ *+' $at_stder1 >$at_stderr
4702at_failed=false
4703$at_diff $at_devnull $at_stderr || at_failed=:
4704echo >>$at_stdout; echo "Useless nonterminals
4705   underivable
4706   indirection
4707Useless rules
4708    2 exp: underivable
4709    3 underivable: indirection
4710    4 indirection: underivable
4711" | $at_diff - $at_stdout || at_failed=:
4712case $at_status in
4713   77) echo 77 > $at_status_file
4714            exit 77;;
4715   0) ;;
4716   *) echo "reduce.at:332: exit code was $at_status, expected 0"
4717      at_failed=:;;
4718esac
4719if $at_failed; then
4720
4721  echo 1 > $at_status_file
4722  exit 1
4723fi
4724
4725$at_traceon
4726
4727
4728      $at_traceoff
4729      $at_times_p && times >$at_times_file
4730    ) 5>&1 2>&1 | eval $at_tee_pipe
4731    at_status=`cat $at_status_file`
4732    ;;
4733
4734  40 ) # 40. reduce.at:342: Empty Language
4735    at_setup_line='reduce.at:342'
4736    at_desc='Empty Language'
4737    $at_quiet $ECHO_N " 40: Empty Language                               $ECHO_C"
4738    at_xfail=no
4739    (
4740      echo "40. reduce.at:342: testing ..."
4741      $at_traceon
4742
4743
4744cat >input.y <<'_ATEOF'
4745%output="input.c"
4746%%
4747exp: exp;
4748_ATEOF
4749
4750
4751$at_traceoff
4752echo "reduce.at:353: bison input.y"
4753echo reduce.at:353 >$at_check_line_file
4754( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
4755at_status=$?
4756grep '^ *+' $at_stder1 >&2
4757grep -v '^ *+' $at_stder1 >$at_stderr
4758at_failed=false
4759echo >>$at_stderr; echo "input.y: warning: 2 useless nonterminals and 2 useless rules
4760input.y:3.1-3: fatal error: start symbol exp does not derive any sentence
4761" | $at_diff - $at_stderr || at_failed=:
4762$at_diff $at_devnull $at_stdout || at_failed=:
4763case $at_status in
4764   77) echo 77 > $at_status_file
4765            exit 77;;
4766   1) ;;
4767   *) echo "reduce.at:353: exit code was $at_status, expected 1"
4768      at_failed=:;;
4769esac
4770if $at_failed; then
4771
4772  echo 1 > $at_status_file
4773  exit 1
4774fi
4775
4776$at_traceon
4777
4778
4779      $at_traceoff
4780      $at_times_p && times >$at_times_file
4781    ) 5>&1 2>&1 | eval $at_tee_pipe
4782    at_status=`cat $at_status_file`
4783    ;;
4784
4785
4786  banner-5 ) # Banner 5. synclines.at:19
4787    cat <<\_ATEOF
4788
4789User Actions.
4790
4791_ATEOF
4792    ;;
4793
4794  41 ) # 41. synclines.at:95: Prologue synch line
4795    at_setup_line='synclines.at:95'
4796    at_desc='Prologue synch line'
4797    $at_quiet $ECHO_N " 41: Prologue synch line                          $ECHO_C"
4798    at_xfail=no
4799    (
4800      echo "41. synclines.at:95: testing ..."
4801      $at_traceon
4802
4803
4804# It seems impossible to find a generic scheme to check the location
4805# of an error.  Even requiring GCC is not sufficient, since for instance
4806# the version modified by Apple:
4807#
4808# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
4809# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
4810# | 19991024 (release) configure:2124: $? = 0
4811#
4812# instead of:
4813#
4814# | input.y:2: #error "2"
4815#
4816# it reports:
4817#
4818# | input.y:2: "2"
4819# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
4820
4821cat >syncline.c <<'_ATEOF'
4822#error "1"
4823_ATEOF
4824
4825
4826$at_traceoff
4827echo "synclines.at:95: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c"
4828echo synclines.at:95 >$at_check_line_file
4829( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1
4830at_status=$?
4831grep '^ *+' $at_stder1 >&2
4832grep -v '^ *+' $at_stder1 >$at_stderr
4833at_failed=false
4834echo stderr:; tee stderr <$at_stderr
4835$at_diff $at_devnull $at_stdout || at_failed=:
4836case $at_status in
4837   77) echo 77 > $at_status_file
4838            exit 77;;
4839   *);;
4840esac
4841if $at_failed; then
4842
4843  echo 1 > $at_status_file
4844  exit 1
4845fi
4846
4847$at_traceon
4848
4849# In case GCC displays column information, strip it down.
4850#
4851#   input.y:4:2: #error "4"    or
4852#   input.y:4.2: #error "4"    or
4853#   input.y:4:2: error: #error "4"
4854# =>
4855#   input.y:4: #error "4"
4856#
4857$at_traceoff
4858echo "synclines.at:95: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr"
4859echo synclines.at:95 >$at_check_line_file
4860( $at_traceon; sed -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' -e 's/^\([^:]*:[^:]*:\)[^#]*\( #error\)/\1\2/' stderr ) >$at_stdout 2>$at_stder1
4861at_status=$?
4862grep '^ *+' $at_stder1 >&2
4863grep -v '^ *+' $at_stder1 >$at_stderr
4864at_failed=false
4865$at_diff $at_devnull $at_stderr || at_failed=:
4866echo stdout:; tee stdout <$at_stdout
4867case $at_status in
4868   77) echo 77 > $at_status_file
4869            exit 77;;
4870   0) ;;
4871   *) echo "synclines.at:95: exit code was $at_status, expected 0"
4872      at_failed=:;;
4873esac
4874if $at_failed; then
4875
4876  echo 1 > $at_status_file
4877  exit 1
4878fi
4879
4880$at_traceon
4881
4882
4883$at_traceoff
4884echo "synclines.at:95: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77"
4885echo synclines.at:95 >$at_check_line_file
4886( $at_traceon; test "`cat stdout`" = 'syncline.c:1: #error "1"' || exit 77 ) >$at_stdout 2>$at_stder1
4887at_status=$?
4888grep '^ *+' $at_stder1 >&2
4889grep -v '^ *+' $at_stder1 >$at_stderr
4890at_failed=false
4891$at_diff $at_devnull $at_stderr || at_failed=:
4892$at_diff $at_devnull $at_stdout || at_failed=:
4893case $at_status in
4894   77) echo 77 > $at_status_file
4895            exit 77;;
4896   0) ;;
4897   *) echo "synclines.at:95: exit code was $at_status, expected 0"
4898      at_failed=:;;
4899esac
4900if $at_failed; then
4901
4902  echo 1 > $at_status_file
4903  exit 1
4904fi
4905
4906$at_traceon
4907
4908
4909cat >input.y <<'_ATEOF'
4910%{
4911#error "2"
4912void yyerror (const char *s);
4913int yylex (void);
4914%}
4915%%
4916exp: '0';
4917_ATEOF
4918
4919$at_traceoff
4920echo "synclines.at:95: bison -o input.c input.y"
4921echo synclines.at:95 >$at_check_line_file
4922( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
4923at_status=$?
4924grep '^ *+' $at_stder1 >&2
4925grep -v '^ *+' $at_stder1 >$at_stderr
4926at_failed=false
4927$at_diff $at_devnull $at_stderr || at_failed=:
4928$at_diff $at_devnull $at_stdout || at_failed=:
4929case $at_status in
4930   77) echo 77 > $at_status_file
4931            exit 77;;
4932   0) ;;
4933   *) echo "synclines.at:95: exit code was $at_status, expected 0"
4934      at_failed=:;;
4935esac
4936if $at_failed; then
4937
4938  echo 1 > $at_status_file
4939  exit 1
4940fi
4941
4942$at_traceon
4943
4944$at_traceoff
4945echo "synclines.at:95: \$CC \$CFLAGS \$CPPFLAGS -c input.c"
4946echo synclines.at:95 >$at_check_line_file
4947( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1
4948at_status=$?
4949grep '^ *+' $at_stder1 >&2
4950grep -v '^ *+' $at_stder1 >$at_stderr
4951at_failed=false
4952echo stderr:; tee stderr <$at_stderr
4953$at_diff $at_devnull $at_stdout || at_failed=:
4954case $at_status in
4955   77) echo 77 > $at_status_file
4956            exit 77;;
4957   *);;
4958esac
4959if $at_failed; then
4960
4961  echo 1 > $at_status_file
4962  exit 1
4963fi
4964
4965$at_traceon
4966
4967# In case GCC displays column information, strip it down.
4968#
4969#   input.y:4:2: #error "4"    or
4970#   input.y:4.2: #error "4"    or
4971#   input.y:4:2: error: #error "4"
4972# =>
4973#   input.y:4: #error "4"
4974#
4975$at_traceoff
4976echo "synclines.at:95: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr"
4977echo synclines.at:95 >$at_check_line_file
4978( $at_traceon; sed -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' -e 's/^\([^:]*:[^:]*:\)[^#]*\( #error\)/\1\2/' stderr ) >$at_stdout 2>$at_stder1
4979at_status=$?
4980grep '^ *+' $at_stder1 >&2
4981grep -v '^ *+' $at_stder1 >$at_stderr
4982at_failed=false
4983$at_diff $at_devnull $at_stderr || at_failed=:
4984echo stdout:; tee stdout <$at_stdout
4985case $at_status in
4986   77) echo 77 > $at_status_file
4987            exit 77;;
4988   0) ;;
4989   *) echo "synclines.at:95: exit code was $at_status, expected 0"
4990      at_failed=:;;
4991esac
4992if $at_failed; then
4993
4994  echo 1 > $at_status_file
4995  exit 1
4996fi
4997
4998$at_traceon
4999
5000
5001$at_traceoff
5002echo "synclines.at:95: cat stdout"
5003echo synclines.at:95 >$at_check_line_file
5004( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1
5005at_status=$?
5006grep '^ *+' $at_stder1 >&2
5007grep -v '^ *+' $at_stder1 >$at_stderr
5008at_failed=false
5009$at_diff $at_devnull $at_stderr || at_failed=:
5010echo >>$at_stdout; echo "input.y:2: #error \"2\"
5011" | $at_diff - $at_stdout || at_failed=:
5012case $at_status in
5013   77) echo 77 > $at_status_file
5014            exit 77;;
5015   0) ;;
5016   *) echo "synclines.at:95: exit code was $at_status, expected 0"
5017      at_failed=:;;
5018esac
5019if $at_failed; then
5020
5021  echo 1 > $at_status_file
5022  exit 1
5023fi
5024
5025$at_traceon
5026
5027      $at_traceoff
5028      $at_times_p && times >$at_times_file
5029    ) 5>&1 2>&1 | eval $at_tee_pipe
5030    at_status=`cat $at_status_file`
5031    ;;
5032
5033  42 ) # 42. synclines.at:115: %union synch line
5034    at_setup_line='synclines.at:115'
5035    at_desc='%union synch line'
5036    $at_quiet $ECHO_N " 42: %union synch line                            $ECHO_C"
5037    at_xfail=no
5038    (
5039      echo "42. synclines.at:115: testing ..."
5040      $at_traceon
5041
5042
5043# It seems impossible to find a generic scheme to check the location
5044# of an error.  Even requiring GCC is not sufficient, since for instance
5045# the version modified by Apple:
5046#
5047# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
5048# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
5049# | 19991024 (release) configure:2124: $? = 0
5050#
5051# instead of:
5052#
5053# | input.y:2: #error "2"
5054#
5055# it reports:
5056#
5057# | input.y:2: "2"
5058# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
5059
5060cat >syncline.c <<'_ATEOF'
5061#error "1"
5062_ATEOF
5063
5064
5065$at_traceoff
5066echo "synclines.at:115: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c"
5067echo synclines.at:115 >$at_check_line_file
5068( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1
5069at_status=$?
5070grep '^ *+' $at_stder1 >&2
5071grep -v '^ *+' $at_stder1 >$at_stderr
5072at_failed=false
5073echo stderr:; tee stderr <$at_stderr
5074$at_diff $at_devnull $at_stdout || at_failed=:
5075case $at_status in
5076   77) echo 77 > $at_status_file
5077            exit 77;;
5078   *);;
5079esac
5080if $at_failed; then
5081
5082  echo 1 > $at_status_file
5083  exit 1
5084fi
5085
5086$at_traceon
5087
5088# In case GCC displays column information, strip it down.
5089#
5090#   input.y:4:2: #error "4"    or
5091#   input.y:4.2: #error "4"    or
5092#   input.y:4:2: error: #error "4"
5093# =>
5094#   input.y:4: #error "4"
5095#
5096$at_traceoff
5097echo "synclines.at:115: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr"
5098echo synclines.at:115 >$at_check_line_file
5099( $at_traceon; sed -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' -e 's/^\([^:]*:[^:]*:\)[^#]*\( #error\)/\1\2/' stderr ) >$at_stdout 2>$at_stder1
5100at_status=$?
5101grep '^ *+' $at_stder1 >&2
5102grep -v '^ *+' $at_stder1 >$at_stderr
5103at_failed=false
5104$at_diff $at_devnull $at_stderr || at_failed=:
5105echo stdout:; tee stdout <$at_stdout
5106case $at_status in
5107   77) echo 77 > $at_status_file
5108            exit 77;;
5109   0) ;;
5110   *) echo "synclines.at:115: exit code was $at_status, expected 0"
5111      at_failed=:;;
5112esac
5113if $at_failed; then
5114
5115  echo 1 > $at_status_file
5116  exit 1
5117fi
5118
5119$at_traceon
5120
5121
5122$at_traceoff
5123echo "synclines.at:115: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77"
5124echo synclines.at:115 >$at_check_line_file
5125( $at_traceon; test "`cat stdout`" = 'syncline.c:1: #error "1"' || exit 77 ) >$at_stdout 2>$at_stder1
5126at_status=$?
5127grep '^ *+' $at_stder1 >&2
5128grep -v '^ *+' $at_stder1 >$at_stderr
5129at_failed=false
5130$at_diff $at_devnull $at_stderr || at_failed=:
5131$at_diff $at_devnull $at_stdout || at_failed=:
5132case $at_status in
5133   77) echo 77 > $at_status_file
5134            exit 77;;
5135   0) ;;
5136   *) echo "synclines.at:115: exit code was $at_status, expected 0"
5137      at_failed=:;;
5138esac
5139if $at_failed; then
5140
5141  echo 1 > $at_status_file
5142  exit 1
5143fi
5144
5145$at_traceon
5146
5147
5148cat >input.y <<'_ATEOF'
5149%union {
5150#error "2"
5151  char dummy;
5152}
5153%{
5154void yyerror (const char *s);
5155int yylex (void);
5156%}
5157%%
5158exp: '0';
5159_ATEOF
5160
5161$at_traceoff
5162echo "synclines.at:115: bison -o input.c input.y"
5163echo synclines.at:115 >$at_check_line_file
5164( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
5165at_status=$?
5166grep '^ *+' $at_stder1 >&2
5167grep -v '^ *+' $at_stder1 >$at_stderr
5168at_failed=false
5169$at_diff $at_devnull $at_stderr || at_failed=:
5170$at_diff $at_devnull $at_stdout || at_failed=:
5171case $at_status in
5172   77) echo 77 > $at_status_file
5173            exit 77;;
5174   0) ;;
5175   *) echo "synclines.at:115: exit code was $at_status, expected 0"
5176      at_failed=:;;
5177esac
5178if $at_failed; then
5179
5180  echo 1 > $at_status_file
5181  exit 1
5182fi
5183
5184$at_traceon
5185
5186$at_traceoff
5187echo "synclines.at:115: \$CC \$CFLAGS \$CPPFLAGS -c input.c"
5188echo synclines.at:115 >$at_check_line_file
5189( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1
5190at_status=$?
5191grep '^ *+' $at_stder1 >&2
5192grep -v '^ *+' $at_stder1 >$at_stderr
5193at_failed=false
5194echo stderr:; tee stderr <$at_stderr
5195$at_diff $at_devnull $at_stdout || at_failed=:
5196case $at_status in
5197   77) echo 77 > $at_status_file
5198            exit 77;;
5199   *);;
5200esac
5201if $at_failed; then
5202
5203  echo 1 > $at_status_file
5204  exit 1
5205fi
5206
5207$at_traceon
5208
5209# In case GCC displays column information, strip it down.
5210#
5211#   input.y:4:2: #error "4"    or
5212#   input.y:4.2: #error "4"    or
5213#   input.y:4:2: error: #error "4"
5214# =>
5215#   input.y:4: #error "4"
5216#
5217$at_traceoff
5218echo "synclines.at:115: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr"
5219echo synclines.at:115 >$at_check_line_file
5220( $at_traceon; sed -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' -e 's/^\([^:]*:[^:]*:\)[^#]*\( #error\)/\1\2/' stderr ) >$at_stdout 2>$at_stder1
5221at_status=$?
5222grep '^ *+' $at_stder1 >&2
5223grep -v '^ *+' $at_stder1 >$at_stderr
5224at_failed=false
5225$at_diff $at_devnull $at_stderr || at_failed=:
5226echo stdout:; tee stdout <$at_stdout
5227case $at_status in
5228   77) echo 77 > $at_status_file
5229            exit 77;;
5230   0) ;;
5231   *) echo "synclines.at:115: exit code was $at_status, expected 0"
5232      at_failed=:;;
5233esac
5234if $at_failed; then
5235
5236  echo 1 > $at_status_file
5237  exit 1
5238fi
5239
5240$at_traceon
5241
5242
5243$at_traceoff
5244echo "synclines.at:115: cat stdout"
5245echo synclines.at:115 >$at_check_line_file
5246( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1
5247at_status=$?
5248grep '^ *+' $at_stder1 >&2
5249grep -v '^ *+' $at_stder1 >$at_stderr
5250at_failed=false
5251$at_diff $at_devnull $at_stderr || at_failed=:
5252echo >>$at_stdout; echo "input.y:2: #error \"2\"
5253" | $at_diff - $at_stdout || at_failed=:
5254case $at_status in
5255   77) echo 77 > $at_status_file
5256            exit 77;;
5257   0) ;;
5258   *) echo "synclines.at:115: exit code was $at_status, expected 0"
5259      at_failed=:;;
5260esac
5261if $at_failed; then
5262
5263  echo 1 > $at_status_file
5264  exit 1
5265fi
5266
5267$at_traceon
5268
5269      $at_traceoff
5270      $at_times_p && times >$at_times_file
5271    ) 5>&1 2>&1 | eval $at_tee_pipe
5272    at_status=`cat $at_status_file`
5273    ;;
5274
5275  43 ) # 43. synclines.at:138: Postprologue synch line
5276    at_setup_line='synclines.at:138'
5277    at_desc='Postprologue synch line'
5278    $at_quiet $ECHO_N " 43: Postprologue synch line                      $ECHO_C"
5279    at_xfail=no
5280    (
5281      echo "43. synclines.at:138: testing ..."
5282      $at_traceon
5283
5284
5285# It seems impossible to find a generic scheme to check the location
5286# of an error.  Even requiring GCC is not sufficient, since for instance
5287# the version modified by Apple:
5288#
5289# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
5290# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
5291# | 19991024 (release) configure:2124: $? = 0
5292#
5293# instead of:
5294#
5295# | input.y:2: #error "2"
5296#
5297# it reports:
5298#
5299# | input.y:2: "2"
5300# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
5301
5302cat >syncline.c <<'_ATEOF'
5303#error "1"
5304_ATEOF
5305
5306
5307$at_traceoff
5308echo "synclines.at:138: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c"
5309echo synclines.at:138 >$at_check_line_file
5310( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1
5311at_status=$?
5312grep '^ *+' $at_stder1 >&2
5313grep -v '^ *+' $at_stder1 >$at_stderr
5314at_failed=false
5315echo stderr:; tee stderr <$at_stderr
5316$at_diff $at_devnull $at_stdout || at_failed=:
5317case $at_status in
5318   77) echo 77 > $at_status_file
5319            exit 77;;
5320   *);;
5321esac
5322if $at_failed; then
5323
5324  echo 1 > $at_status_file
5325  exit 1
5326fi
5327
5328$at_traceon
5329
5330# In case GCC displays column information, strip it down.
5331#
5332#   input.y:4:2: #error "4"    or
5333#   input.y:4.2: #error "4"    or
5334#   input.y:4:2: error: #error "4"
5335# =>
5336#   input.y:4: #error "4"
5337#
5338$at_traceoff
5339echo "synclines.at:138: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr"
5340echo synclines.at:138 >$at_check_line_file
5341( $at_traceon; sed -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' -e 's/^\([^:]*:[^:]*:\)[^#]*\( #error\)/\1\2/' stderr ) >$at_stdout 2>$at_stder1
5342at_status=$?
5343grep '^ *+' $at_stder1 >&2
5344grep -v '^ *+' $at_stder1 >$at_stderr
5345at_failed=false
5346$at_diff $at_devnull $at_stderr || at_failed=:
5347echo stdout:; tee stdout <$at_stdout
5348case $at_status in
5349   77) echo 77 > $at_status_file
5350            exit 77;;
5351   0) ;;
5352   *) echo "synclines.at:138: exit code was $at_status, expected 0"
5353      at_failed=:;;
5354esac
5355if $at_failed; then
5356
5357  echo 1 > $at_status_file
5358  exit 1
5359fi
5360
5361$at_traceon
5362
5363
5364$at_traceoff
5365echo "synclines.at:138: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77"
5366echo synclines.at:138 >$at_check_line_file
5367( $at_traceon; test "`cat stdout`" = 'syncline.c:1: #error "1"' || exit 77 ) >$at_stdout 2>$at_stder1
5368at_status=$?
5369grep '^ *+' $at_stder1 >&2
5370grep -v '^ *+' $at_stder1 >$at_stderr
5371at_failed=false
5372$at_diff $at_devnull $at_stderr || at_failed=:
5373$at_diff $at_devnull $at_stdout || at_failed=:
5374case $at_status in
5375   77) echo 77 > $at_status_file
5376            exit 77;;
5377   0) ;;
5378   *) echo "synclines.at:138: exit code was $at_status, expected 0"
5379      at_failed=:;;
5380esac
5381if $at_failed; then
5382
5383  echo 1 > $at_status_file
5384  exit 1
5385fi
5386
5387$at_traceon
5388
5389
5390cat >input.y <<'_ATEOF'
5391%{
5392void yyerror (const char *s);
5393int yylex (void);
5394%}
5395%union
5396{
5397  int ival;
5398}
5399%{
5400#error "10"
5401%}
5402%%
5403exp: '0';
5404_ATEOF
5405
5406$at_traceoff
5407echo "synclines.at:138: bison -o input.c input.y"
5408echo synclines.at:138 >$at_check_line_file
5409( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
5410at_status=$?
5411grep '^ *+' $at_stder1 >&2
5412grep -v '^ *+' $at_stder1 >$at_stderr
5413at_failed=false
5414$at_diff $at_devnull $at_stderr || at_failed=:
5415$at_diff $at_devnull $at_stdout || at_failed=:
5416case $at_status in
5417   77) echo 77 > $at_status_file
5418            exit 77;;
5419   0) ;;
5420   *) echo "synclines.at:138: exit code was $at_status, expected 0"
5421      at_failed=:;;
5422esac
5423if $at_failed; then
5424
5425  echo 1 > $at_status_file
5426  exit 1
5427fi
5428
5429$at_traceon
5430
5431$at_traceoff
5432echo "synclines.at:138: \$CC \$CFLAGS \$CPPFLAGS -c input.c"
5433echo synclines.at:138 >$at_check_line_file
5434( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1
5435at_status=$?
5436grep '^ *+' $at_stder1 >&2
5437grep -v '^ *+' $at_stder1 >$at_stderr
5438at_failed=false
5439echo stderr:; tee stderr <$at_stderr
5440$at_diff $at_devnull $at_stdout || at_failed=:
5441case $at_status in
5442   77) echo 77 > $at_status_file
5443            exit 77;;
5444   *);;
5445esac
5446if $at_failed; then
5447
5448  echo 1 > $at_status_file
5449  exit 1
5450fi
5451
5452$at_traceon
5453
5454# In case GCC displays column information, strip it down.
5455#
5456#   input.y:4:2: #error "4"    or
5457#   input.y:4.2: #error "4"    or
5458#   input.y:4:2: error: #error "4"
5459# =>
5460#   input.y:4: #error "4"
5461#
5462$at_traceoff
5463echo "synclines.at:138: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr"
5464echo synclines.at:138 >$at_check_line_file
5465( $at_traceon; sed -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' -e 's/^\([^:]*:[^:]*:\)[^#]*\( #error\)/\1\2/' stderr ) >$at_stdout 2>$at_stder1
5466at_status=$?
5467grep '^ *+' $at_stder1 >&2
5468grep -v '^ *+' $at_stder1 >$at_stderr
5469at_failed=false
5470$at_diff $at_devnull $at_stderr || at_failed=:
5471echo stdout:; tee stdout <$at_stdout
5472case $at_status in
5473   77) echo 77 > $at_status_file
5474            exit 77;;
5475   0) ;;
5476   *) echo "synclines.at:138: exit code was $at_status, expected 0"
5477      at_failed=:;;
5478esac
5479if $at_failed; then
5480
5481  echo 1 > $at_status_file
5482  exit 1
5483fi
5484
5485$at_traceon
5486
5487
5488$at_traceoff
5489echo "synclines.at:138: cat stdout"
5490echo synclines.at:138 >$at_check_line_file
5491( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1
5492at_status=$?
5493grep '^ *+' $at_stder1 >&2
5494grep -v '^ *+' $at_stder1 >$at_stderr
5495at_failed=false
5496$at_diff $at_devnull $at_stderr || at_failed=:
5497echo >>$at_stdout; echo "input.y:10: #error \"10\"
5498" | $at_diff - $at_stdout || at_failed=:
5499case $at_status in
5500   77) echo 77 > $at_status_file
5501            exit 77;;
5502   0) ;;
5503   *) echo "synclines.at:138: exit code was $at_status, expected 0"
5504      at_failed=:;;
5505esac
5506if $at_failed; then
5507
5508  echo 1 > $at_status_file
5509  exit 1
5510fi
5511
5512$at_traceon
5513
5514      $at_traceoff
5515      $at_times_p && times >$at_times_file
5516    ) 5>&1 2>&1 | eval $at_tee_pipe
5517    at_status=`cat $at_status_file`
5518    ;;
5519
5520  44 ) # 44. synclines.at:157: Action synch line
5521    at_setup_line='synclines.at:157'
5522    at_desc='Action synch line'
5523    $at_quiet $ECHO_N " 44: Action synch line                            $ECHO_C"
5524    at_xfail=no
5525    (
5526      echo "44. synclines.at:157: testing ..."
5527      $at_traceon
5528
5529
5530# It seems impossible to find a generic scheme to check the location
5531# of an error.  Even requiring GCC is not sufficient, since for instance
5532# the version modified by Apple:
5533#
5534# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
5535# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
5536# | 19991024 (release) configure:2124: $? = 0
5537#
5538# instead of:
5539#
5540# | input.y:2: #error "2"
5541#
5542# it reports:
5543#
5544# | input.y:2: "2"
5545# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
5546
5547cat >syncline.c <<'_ATEOF'
5548#error "1"
5549_ATEOF
5550
5551
5552$at_traceoff
5553echo "synclines.at:157: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c"
5554echo synclines.at:157 >$at_check_line_file
5555( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1
5556at_status=$?
5557grep '^ *+' $at_stder1 >&2
5558grep -v '^ *+' $at_stder1 >$at_stderr
5559at_failed=false
5560echo stderr:; tee stderr <$at_stderr
5561$at_diff $at_devnull $at_stdout || at_failed=:
5562case $at_status in
5563   77) echo 77 > $at_status_file
5564            exit 77;;
5565   *);;
5566esac
5567if $at_failed; then
5568
5569  echo 1 > $at_status_file
5570  exit 1
5571fi
5572
5573$at_traceon
5574
5575# In case GCC displays column information, strip it down.
5576#
5577#   input.y:4:2: #error "4"    or
5578#   input.y:4.2: #error "4"    or
5579#   input.y:4:2: error: #error "4"
5580# =>
5581#   input.y:4: #error "4"
5582#
5583$at_traceoff
5584echo "synclines.at:157: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr"
5585echo synclines.at:157 >$at_check_line_file
5586( $at_traceon; sed -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' -e 's/^\([^:]*:[^:]*:\)[^#]*\( #error\)/\1\2/' stderr ) >$at_stdout 2>$at_stder1
5587at_status=$?
5588grep '^ *+' $at_stder1 >&2
5589grep -v '^ *+' $at_stder1 >$at_stderr
5590at_failed=false
5591$at_diff $at_devnull $at_stderr || at_failed=:
5592echo stdout:; tee stdout <$at_stdout
5593case $at_status in
5594   77) echo 77 > $at_status_file
5595            exit 77;;
5596   0) ;;
5597   *) echo "synclines.at:157: exit code was $at_status, expected 0"
5598      at_failed=:;;
5599esac
5600if $at_failed; then
5601
5602  echo 1 > $at_status_file
5603  exit 1
5604fi
5605
5606$at_traceon
5607
5608
5609$at_traceoff
5610echo "synclines.at:157: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77"
5611echo synclines.at:157 >$at_check_line_file
5612( $at_traceon; test "`cat stdout`" = 'syncline.c:1: #error "1"' || exit 77 ) >$at_stdout 2>$at_stder1
5613at_status=$?
5614grep '^ *+' $at_stder1 >&2
5615grep -v '^ *+' $at_stder1 >$at_stderr
5616at_failed=false
5617$at_diff $at_devnull $at_stderr || at_failed=:
5618$at_diff $at_devnull $at_stdout || at_failed=:
5619case $at_status in
5620   77) echo 77 > $at_status_file
5621            exit 77;;
5622   0) ;;
5623   *) echo "synclines.at:157: exit code was $at_status, expected 0"
5624      at_failed=:;;
5625esac
5626if $at_failed; then
5627
5628  echo 1 > $at_status_file
5629  exit 1
5630fi
5631
5632$at_traceon
5633
5634
5635cat >input.y <<'_ATEOF'
5636%{
5637void yyerror (const char *s);
5638int yylex (void);
5639%}
5640%%
5641exp:
5642{
5643#error "8"
5644};
5645_ATEOF
5646
5647$at_traceoff
5648echo "synclines.at:157: bison -o input.c input.y"
5649echo synclines.at:157 >$at_check_line_file
5650( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
5651at_status=$?
5652grep '^ *+' $at_stder1 >&2
5653grep -v '^ *+' $at_stder1 >$at_stderr
5654at_failed=false
5655$at_diff $at_devnull $at_stderr || at_failed=:
5656$at_diff $at_devnull $at_stdout || at_failed=:
5657case $at_status in
5658   77) echo 77 > $at_status_file
5659            exit 77;;
5660   0) ;;
5661   *) echo "synclines.at:157: exit code was $at_status, expected 0"
5662      at_failed=:;;
5663esac
5664if $at_failed; then
5665
5666  echo 1 > $at_status_file
5667  exit 1
5668fi
5669
5670$at_traceon
5671
5672$at_traceoff
5673echo "synclines.at:157: \$CC \$CFLAGS \$CPPFLAGS -c input.c"
5674echo synclines.at:157 >$at_check_line_file
5675( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1
5676at_status=$?
5677grep '^ *+' $at_stder1 >&2
5678grep -v '^ *+' $at_stder1 >$at_stderr
5679at_failed=false
5680echo stderr:; tee stderr <$at_stderr
5681$at_diff $at_devnull $at_stdout || at_failed=:
5682case $at_status in
5683   77) echo 77 > $at_status_file
5684            exit 77;;
5685   *);;
5686esac
5687if $at_failed; then
5688
5689  echo 1 > $at_status_file
5690  exit 1
5691fi
5692
5693$at_traceon
5694
5695# In case GCC displays column information, strip it down.
5696#
5697#   input.y:4:2: #error "4"    or
5698#   input.y:4.2: #error "4"    or
5699#   input.y:4:2: error: #error "4"
5700# =>
5701#   input.y:4: #error "4"
5702#
5703$at_traceoff
5704echo "synclines.at:157: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr"
5705echo synclines.at:157 >$at_check_line_file
5706( $at_traceon; sed -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' -e 's/^\([^:]*:[^:]*:\)[^#]*\( #error\)/\1\2/' stderr ) >$at_stdout 2>$at_stder1
5707at_status=$?
5708grep '^ *+' $at_stder1 >&2
5709grep -v '^ *+' $at_stder1 >$at_stderr
5710at_failed=false
5711$at_diff $at_devnull $at_stderr || at_failed=:
5712echo stdout:; tee stdout <$at_stdout
5713case $at_status in
5714   77) echo 77 > $at_status_file
5715            exit 77;;
5716   0) ;;
5717   *) echo "synclines.at:157: exit code was $at_status, expected 0"
5718      at_failed=:;;
5719esac
5720if $at_failed; then
5721
5722  echo 1 > $at_status_file
5723  exit 1
5724fi
5725
5726$at_traceon
5727
5728
5729$at_traceoff
5730echo "synclines.at:157: cat stdout"
5731echo synclines.at:157 >$at_check_line_file
5732( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1
5733at_status=$?
5734grep '^ *+' $at_stder1 >&2
5735grep -v '^ *+' $at_stder1 >$at_stderr
5736at_failed=false
5737$at_diff $at_devnull $at_stderr || at_failed=:
5738echo >>$at_stdout; echo "input.y:8: #error \"8\"
5739" | $at_diff - $at_stdout || at_failed=:
5740case $at_status in
5741   77) echo 77 > $at_status_file
5742            exit 77;;
5743   0) ;;
5744   *) echo "synclines.at:157: exit code was $at_status, expected 0"
5745      at_failed=:;;
5746esac
5747if $at_failed; then
5748
5749  echo 1 > $at_status_file
5750  exit 1
5751fi
5752
5753$at_traceon
5754
5755      $at_traceoff
5756      $at_times_p && times >$at_times_file
5757    ) 5>&1 2>&1 | eval $at_tee_pipe
5758    at_status=`cat $at_status_file`
5759    ;;
5760
5761  45 ) # 45. synclines.at:175: Epilogue synch line
5762    at_setup_line='synclines.at:175'
5763    at_desc='Epilogue synch line'
5764    $at_quiet $ECHO_N " 45: Epilogue synch line                          $ECHO_C"
5765    at_xfail=no
5766    (
5767      echo "45. synclines.at:175: testing ..."
5768      $at_traceon
5769
5770
5771# It seems impossible to find a generic scheme to check the location
5772# of an error.  Even requiring GCC is not sufficient, since for instance
5773# the version modified by Apple:
5774#
5775# | Reading specs from /usr/libexec/gcc/darwin/ppc/2.95.2/specs
5776# | Apple Computer, Inc. version gcc-934.3, based on gcc version 2.95.2
5777# | 19991024 (release) configure:2124: $? = 0
5778#
5779# instead of:
5780#
5781# | input.y:2: #error "2"
5782#
5783# it reports:
5784#
5785# | input.y:2: "2"
5786# | cpp-precomp: warning: errors during smart preprocessing, retrying in basic mode
5787
5788cat >syncline.c <<'_ATEOF'
5789#error "1"
5790_ATEOF
5791
5792
5793$at_traceoff
5794echo "synclines.at:175: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c"
5795echo synclines.at:175 >$at_check_line_file
5796( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1
5797at_status=$?
5798grep '^ *+' $at_stder1 >&2
5799grep -v '^ *+' $at_stder1 >$at_stderr
5800at_failed=false
5801echo stderr:; tee stderr <$at_stderr
5802$at_diff $at_devnull $at_stdout || at_failed=:
5803case $at_status in
5804   77) echo 77 > $at_status_file
5805            exit 77;;
5806   *);;
5807esac
5808if $at_failed; then
5809
5810  echo 1 > $at_status_file
5811  exit 1
5812fi
5813
5814$at_traceon
5815
5816# In case GCC displays column information, strip it down.
5817#
5818#   input.y:4:2: #error "4"    or
5819#   input.y:4.2: #error "4"    or
5820#   input.y:4:2: error: #error "4"
5821# =>
5822#   input.y:4: #error "4"
5823#
5824$at_traceoff
5825echo "synclines.at:175: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr"
5826echo synclines.at:175 >$at_check_line_file
5827( $at_traceon; sed -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' -e 's/^\([^:]*:[^:]*:\)[^#]*\( #error\)/\1\2/' stderr ) >$at_stdout 2>$at_stder1
5828at_status=$?
5829grep '^ *+' $at_stder1 >&2
5830grep -v '^ *+' $at_stder1 >$at_stderr
5831at_failed=false
5832$at_diff $at_devnull $at_stderr || at_failed=:
5833echo stdout:; tee stdout <$at_stdout
5834case $at_status in
5835   77) echo 77 > $at_status_file
5836            exit 77;;
5837   0) ;;
5838   *) echo "synclines.at:175: exit code was $at_status, expected 0"
5839      at_failed=:;;
5840esac
5841if $at_failed; then
5842
5843  echo 1 > $at_status_file
5844  exit 1
5845fi
5846
5847$at_traceon
5848
5849
5850$at_traceoff
5851echo "synclines.at:175: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77"
5852echo synclines.at:175 >$at_check_line_file
5853( $at_traceon; test "`cat stdout`" = 'syncline.c:1: #error "1"' || exit 77 ) >$at_stdout 2>$at_stder1
5854at_status=$?
5855grep '^ *+' $at_stder1 >&2
5856grep -v '^ *+' $at_stder1 >$at_stderr
5857at_failed=false
5858$at_diff $at_devnull $at_stderr || at_failed=:
5859$at_diff $at_devnull $at_stdout || at_failed=:
5860case $at_status in
5861   77) echo 77 > $at_status_file
5862            exit 77;;
5863   0) ;;
5864   *) echo "synclines.at:175: exit code was $at_status, expected 0"
5865      at_failed=:;;
5866esac
5867if $at_failed; then
5868
5869  echo 1 > $at_status_file
5870  exit 1
5871fi
5872
5873$at_traceon
5874
5875
5876cat >input.y <<'_ATEOF'
5877%{
5878void yyerror (const char *s);
5879int yylex (void);
5880%}
5881%%
5882exp: '0';
5883%%
5884#error "8"
5885_ATEOF
5886
5887$at_traceoff
5888echo "synclines.at:175: bison -o input.c input.y"
5889echo synclines.at:175 >$at_check_line_file
5890( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
5891at_status=$?
5892grep '^ *+' $at_stder1 >&2
5893grep -v '^ *+' $at_stder1 >$at_stderr
5894at_failed=false
5895$at_diff $at_devnull $at_stderr || at_failed=:
5896$at_diff $at_devnull $at_stdout || at_failed=:
5897case $at_status in
5898   77) echo 77 > $at_status_file
5899            exit 77;;
5900   0) ;;
5901   *) echo "synclines.at:175: exit code was $at_status, expected 0"
5902      at_failed=:;;
5903esac
5904if $at_failed; then
5905
5906  echo 1 > $at_status_file
5907  exit 1
5908fi
5909
5910$at_traceon
5911
5912$at_traceoff
5913echo "synclines.at:175: \$CC \$CFLAGS \$CPPFLAGS -c input.c"
5914echo synclines.at:175 >$at_check_line_file
5915( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1
5916at_status=$?
5917grep '^ *+' $at_stder1 >&2
5918grep -v '^ *+' $at_stder1 >$at_stderr
5919at_failed=false
5920echo stderr:; tee stderr <$at_stderr
5921$at_diff $at_devnull $at_stdout || at_failed=:
5922case $at_status in
5923   77) echo 77 > $at_status_file
5924            exit 77;;
5925   *);;
5926esac
5927if $at_failed; then
5928
5929  echo 1 > $at_status_file
5930  exit 1
5931fi
5932
5933$at_traceon
5934
5935# In case GCC displays column information, strip it down.
5936#
5937#   input.y:4:2: #error "4"    or
5938#   input.y:4.2: #error "4"    or
5939#   input.y:4:2: error: #error "4"
5940# =>
5941#   input.y:4: #error "4"
5942#
5943$at_traceoff
5944echo "synclines.at:175: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr"
5945echo synclines.at:175 >$at_check_line_file
5946( $at_traceon; sed -e 's/^\([^:]*:[^:.]*\)[.:][^:]*:\(.*\)$/\1:\2/' -e 's/^\([^:]*:[^:]*:\)[^#]*\( #error\)/\1\2/' stderr ) >$at_stdout 2>$at_stder1
5947at_status=$?
5948grep '^ *+' $at_stder1 >&2
5949grep -v '^ *+' $at_stder1 >$at_stderr
5950at_failed=false
5951$at_diff $at_devnull $at_stderr || at_failed=:
5952echo stdout:; tee stdout <$at_stdout
5953case $at_status in
5954   77) echo 77 > $at_status_file
5955            exit 77;;
5956   0) ;;
5957   *) echo "synclines.at:175: exit code was $at_status, expected 0"
5958      at_failed=:;;
5959esac
5960if $at_failed; then
5961
5962  echo 1 > $at_status_file
5963  exit 1
5964fi
5965
5966$at_traceon
5967
5968
5969$at_traceoff
5970echo "synclines.at:175: cat stdout"
5971echo synclines.at:175 >$at_check_line_file
5972( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1
5973at_status=$?
5974grep '^ *+' $at_stder1 >&2
5975grep -v '^ *+' $at_stder1 >$at_stderr
5976at_failed=false
5977$at_diff $at_devnull $at_stderr || at_failed=:
5978echo >>$at_stdout; echo "input.y:8: #error \"8\"
5979" | $at_diff - $at_stdout || at_failed=:
5980case $at_status in
5981   77) echo 77 > $at_status_file
5982            exit 77;;
5983   0) ;;
5984   *) echo "synclines.at:175: exit code was $at_status, expected 0"
5985      at_failed=:;;
5986esac
5987if $at_failed; then
5988
5989  echo 1 > $at_status_file
5990  exit 1
5991fi
5992
5993$at_traceon
5994
5995      $at_traceoff
5996      $at_times_p && times >$at_times_file
5997    ) 5>&1 2>&1 | eval $at_tee_pipe
5998    at_status=`cat $at_status_file`
5999    ;;
6000
6001
6002  banner-6 ) # Banner 6. headers.at:19
6003    cat <<\_ATEOF
6004
6005Parser Headers.
6006
6007_ATEOF
6008    ;;
6009
6010  46 ) # 46. headers.at:27: %union and --defines
6011    at_setup_line='headers.at:27'
6012    at_desc='%union and --defines'
6013    $at_quiet $ECHO_N " 46: %union and --defines                         $ECHO_C"
6014    at_xfail=no
6015    (
6016      echo "46. headers.at:27: testing ..."
6017      $at_traceon
6018
6019
6020cat >input.y <<'_ATEOF'
6021%union
6022{
6023  int   integer;
6024  char *string ;
6025}
6026%%
6027exp: {};
6028_ATEOF
6029
6030
6031$at_traceoff
6032echo "headers.at:39: bison --defines input.y"
6033echo headers.at:39 >$at_check_line_file
6034( $at_traceon; bison --defines input.y ) >$at_stdout 2>$at_stder1
6035at_status=$?
6036grep '^ *+' $at_stder1 >&2
6037grep -v '^ *+' $at_stder1 >$at_stderr
6038at_failed=false
6039$at_diff $at_devnull $at_stderr || at_failed=:
6040$at_diff $at_devnull $at_stdout || at_failed=:
6041case $at_status in
6042   77) echo 77 > $at_status_file
6043            exit 77;;
6044   0) ;;
6045   *) echo "headers.at:39: exit code was $at_status, expected 0"
6046      at_failed=:;;
6047esac
6048if $at_failed; then
6049
6050  echo 1 > $at_status_file
6051  exit 1
6052fi
6053
6054$at_traceon
6055
6056
6057      $at_traceoff
6058      $at_times_p && times >$at_times_file
6059    ) 5>&1 2>&1 | eval $at_tee_pipe
6060    at_status=`cat $at_status_file`
6061    ;;
6062
6063  47 ) # 47. headers.at:77: Invalid CPP guards: input/input
6064    at_setup_line='headers.at:77'
6065    at_desc='Invalid CPP guards: input/input'
6066    $at_quiet $ECHO_N " 47: Invalid CPP guards: input/input              $ECHO_C"
6067    at_xfail=no
6068    (
6069      echo "47. headers.at:77: testing ..."
6070      $at_traceon
6071
6072
6073# Possibly create inner directories.
6074dirname=`(dirname input/input) 2>/dev/null ||
6075$as_expr Xinput/input : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
6076	 Xinput/input : 'X\(//\)[^/]' \| \
6077	 Xinput/input : 'X\(//\)$' \| \
6078	 Xinput/input : 'X\(/\)' \| \
6079	 .     : '\(.\)' 2>/dev/null ||
6080echo Xinput/input |
6081    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
6082  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
6083  	  /^X\(\/\/\)$/{ s//\1/; q; }
6084  	  /^X\(\/\).*/{ s//\1/; q; }
6085  	  s/.*/./; q'`
6086{ if $as_mkdir_p; then
6087    mkdir -p $dirname
6088  else
6089    as_dir=$dirname
6090    as_dirs=
6091    while test ! -d "$as_dir"; do
6092      as_dirs="$as_dir $as_dirs"
6093      as_dir=`(dirname "$as_dir") 2>/dev/null ||
6094$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
6095	 X"$as_dir" : 'X\(//\)[^/]' \| \
6096	 X"$as_dir" : 'X\(//\)$' \| \
6097	 X"$as_dir" : 'X\(/\)' \| \
6098	 .     : '\(.\)' 2>/dev/null ||
6099echo X"$as_dir" |
6100    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
6101  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
6102  	  /^X\(\/\/\)$/{ s//\1/; q; }
6103  	  /^X\(\/\).*/{ s//\1/; q; }
6104  	  s/.*/./; q'`
6105    done
6106    test ! -n "$as_dirs" || mkdir $as_dirs
6107  fi || { { echo "$as_me:$LINENO: error: cannot create directory $dirname" >&5
6108echo "$as_me: error: cannot create directory $dirname" >&2;}
6109   { (exit 1); exit 1; }; }; }
6110
6111
6112cat >input/input.y <<'_ATEOF'
6113%{
6114#ifdef HAVE_CONFIG_H
6115# include <config.h>
6116  /* We don't need perfect functions for these tests. */
6117# undef malloc
6118# undef memcmp
6119# undef realloc
6120#endif
6121%}
6122
6123%{
6124#include <input/input.h>
6125void yyerror (const char *);
6126int yylex (void);
6127%}
6128%%
6129dummy:;
6130%%
6131#include <input/input.h>
6132_ATEOF
6133
6134
6135
6136$at_traceoff
6137echo "headers.at:77: bison --defines=input/input.h --output=y.tab.c input/input.y"
6138echo headers.at:77 >$at_check_line_file
6139( $at_traceon; bison --defines=input/input.h --output=y.tab.c input/input.y ) >$at_stdout 2>$at_stder1
6140at_status=$?
6141grep '^ *+' $at_stder1 >&2
6142grep -v '^ *+' $at_stder1 >$at_stderr
6143at_failed=false
6144$at_diff $at_devnull $at_stderr || at_failed=:
6145$at_diff $at_devnull $at_stdout || at_failed=:
6146case $at_status in
6147   77) echo 77 > $at_status_file
6148            exit 77;;
6149   0) ;;
6150   *) echo "headers.at:77: exit code was $at_status, expected 0"
6151      at_failed=:;;
6152esac
6153if $at_failed; then
6154
6155  echo 1 > $at_status_file
6156  exit 1
6157fi
6158
6159$at_traceon
6160
6161
6162$at_traceoff
6163echo "headers.at:77: \$CC \$CFLAGS \$CPPFLAGS -o y.tab.o -I. -c y.tab.c"
6164echo headers.at:77 >$at_check_line_file
6165( $at_traceon; $CC $CFLAGS $CPPFLAGS -o y.tab.o -I. -c y.tab.c ) >$at_stdout 2>$at_stder1
6166at_status=$?
6167grep '^ *+' $at_stder1 >&2
6168grep -v '^ *+' $at_stder1 >$at_stderr
6169at_failed=false
6170echo stderr:; cat $at_stderr
6171echo stdout:; cat $at_stdout
6172case $at_status in
6173   77) echo 77 > $at_status_file
6174            exit 77;;
6175   0) ;;
6176   *) echo "headers.at:77: exit code was $at_status, expected 0"
6177      at_failed=:;;
6178esac
6179if $at_failed; then
6180
6181  echo 1 > $at_status_file
6182  exit 1
6183fi
6184
6185$at_traceon
6186
6187
6188      $at_traceoff
6189      $at_times_p && times >$at_times_file
6190    ) 5>&1 2>&1 | eval $at_tee_pipe
6191    at_status=`cat $at_status_file`
6192    ;;
6193
6194  48 ) # 48. headers.at:78: Invalid CPP guards: 9foo
6195    at_setup_line='headers.at:78'
6196    at_desc='Invalid CPP guards: 9foo'
6197    $at_quiet $ECHO_N " 48: Invalid CPP guards: 9foo                     $ECHO_C"
6198    at_xfail=no
6199    (
6200      echo "48. headers.at:78: testing ..."
6201      $at_traceon
6202
6203
6204# Possibly create inner directories.
6205dirname=`(dirname 9foo) 2>/dev/null ||
6206$as_expr X9foo : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
6207	 X9foo : 'X\(//\)[^/]' \| \
6208	 X9foo : 'X\(//\)$' \| \
6209	 X9foo : 'X\(/\)' \| \
6210	 .     : '\(.\)' 2>/dev/null ||
6211echo X9foo |
6212    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
6213  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
6214  	  /^X\(\/\/\)$/{ s//\1/; q; }
6215  	  /^X\(\/\).*/{ s//\1/; q; }
6216  	  s/.*/./; q'`
6217{ if $as_mkdir_p; then
6218    mkdir -p $dirname
6219  else
6220    as_dir=$dirname
6221    as_dirs=
6222    while test ! -d "$as_dir"; do
6223      as_dirs="$as_dir $as_dirs"
6224      as_dir=`(dirname "$as_dir") 2>/dev/null ||
6225$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
6226	 X"$as_dir" : 'X\(//\)[^/]' \| \
6227	 X"$as_dir" : 'X\(//\)$' \| \
6228	 X"$as_dir" : 'X\(/\)' \| \
6229	 .     : '\(.\)' 2>/dev/null ||
6230echo X"$as_dir" |
6231    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
6232  	  /^X\(\/\/\)[^/].*/{ s//\1/; q; }
6233  	  /^X\(\/\/\)$/{ s//\1/; q; }
6234  	  /^X\(\/\).*/{ s//\1/; q; }
6235  	  s/.*/./; q'`
6236    done
6237    test ! -n "$as_dirs" || mkdir $as_dirs
6238  fi || { { echo "$as_me:$LINENO: error: cannot create directory $dirname" >&5
6239echo "$as_me: error: cannot create directory $dirname" >&2;}
6240   { (exit 1); exit 1; }; }; }
6241
6242
6243cat >9foo.y <<'_ATEOF'
6244%{
6245#ifdef HAVE_CONFIG_H
6246# include <config.h>
6247  /* We don't need perfect functions for these tests. */
6248# undef malloc
6249# undef memcmp
6250# undef realloc
6251#endif
6252%}
6253
6254%{
6255#include <9foo.h>
6256void yyerror (const char *);
6257int yylex (void);
6258%}
6259%%
6260dummy:;
6261%%
6262#include <9foo.h>
6263_ATEOF
6264
6265
6266
6267$at_traceoff
6268echo "headers.at:78: bison --defines=9foo.h --output=y.tab.c 9foo.y"
6269echo headers.at:78 >$at_check_line_file
6270( $at_traceon; bison --defines=9foo.h --output=y.tab.c 9foo.y ) >$at_stdout 2>$at_stder1
6271at_status=$?
6272grep '^ *+' $at_stder1 >&2
6273grep -v '^ *+' $at_stder1 >$at_stderr
6274at_failed=false
6275$at_diff $at_devnull $at_stderr || at_failed=:
6276$at_diff $at_devnull $at_stdout || at_failed=:
6277case $at_status in
6278   77) echo 77 > $at_status_file
6279            exit 77;;
6280   0) ;;
6281   *) echo "headers.at:78: exit code was $at_status, expected 0"
6282      at_failed=:;;
6283esac
6284if $at_failed; then
6285
6286  echo 1 > $at_status_file
6287  exit 1
6288fi
6289
6290$at_traceon
6291
6292
6293$at_traceoff
6294echo "headers.at:78: \$CC \$CFLAGS \$CPPFLAGS -o y.tab.o -I. -c y.tab.c"
6295echo headers.at:78 >$at_check_line_file
6296( $at_traceon; $CC $CFLAGS $CPPFLAGS -o y.tab.o -I. -c y.tab.c ) >$at_stdout 2>$at_stder1
6297at_status=$?
6298grep '^ *+' $at_stder1 >&2
6299grep -v '^ *+' $at_stder1 >$at_stderr
6300at_failed=false
6301echo stderr:; cat $at_stderr
6302echo stdout:; cat $at_stdout
6303case $at_status in
6304   77) echo 77 > $at_status_file
6305            exit 77;;
6306   0) ;;
6307   *) echo "headers.at:78: exit code was $at_status, expected 0"
6308      at_failed=:;;
6309esac
6310if $at_failed; then
6311
6312  echo 1 > $at_status_file
6313  exit 1
6314fi
6315
6316$at_traceon
6317
6318
6319      $at_traceoff
6320      $at_times_p && times >$at_times_file
6321    ) 5>&1 2>&1 | eval $at_tee_pipe
6322    at_status=`cat $at_status_file`
6323    ;;
6324
6325  49 ) # 49. headers.at:87: export YYLTYPE
6326    at_setup_line='headers.at:87'
6327    at_desc='export YYLTYPE'
6328    $at_quiet $ECHO_N " 49: export YYLTYPE                               $ECHO_C"
6329    at_xfail=no
6330    (
6331      echo "49. headers.at:87: testing ..."
6332      $at_traceon
6333
6334
6335cat >input.y <<'_ATEOF'
6336%{
6337#ifdef HAVE_CONFIG_H
6338# include <config.h>
6339  /* We don't need perfect functions for these tests. */
6340# undef malloc
6341# undef memcmp
6342# undef realloc
6343#endif
6344%}
6345
6346%locations
6347
6348%name-prefix="my_"
6349%{
6350#include <stdio.h>
6351#include <stdlib.h>
6352
6353static int
6354my_lex (void)
6355{
6356  return EOF;
6357}
6358
6359static void
6360my_error (const char *msg)
6361{
6362  fprintf (stderr, "%s\n", msg);
6363}
6364
6365%}
6366%%
6367exp:;
6368_ATEOF
6369
6370
6371
6372$at_traceoff
6373echo "headers.at:114: bison --defines -o input.c input.y"
6374echo headers.at:114 >$at_check_line_file
6375( $at_traceon; bison --defines -o input.c input.y ) >$at_stdout 2>$at_stder1
6376at_status=$?
6377grep '^ *+' $at_stder1 >&2
6378grep -v '^ *+' $at_stder1 >$at_stderr
6379at_failed=false
6380$at_diff $at_devnull $at_stderr || at_failed=:
6381$at_diff $at_devnull $at_stdout || at_failed=:
6382case $at_status in
6383   77) echo 77 > $at_status_file
6384            exit 77;;
6385   0) ;;
6386   *) echo "headers.at:114: exit code was $at_status, expected 0"
6387      at_failed=:;;
6388esac
6389if $at_failed; then
6390
6391  echo 1 > $at_status_file
6392  exit 1
6393fi
6394
6395$at_traceon
6396
6397
6398# YYLTYPE should be defined, and MY_LLOC declared.
6399cat >caller.c <<'_ATEOF'
6400#include "input.h"
6401YYLTYPE *my_llocp = &my_lloc;
6402
6403int my_parse (void);
6404
6405int
6406main (void)
6407{
6408  return my_parse ();
6409}
6410_ATEOF
6411
6412
6413# Link and execute, just to make sure everything is fine (and in
6414# particular, that MY_LLOC is indeed defined somewhere).
6415$at_traceoff
6416echo "headers.at:132: \$CC \$CFLAGS \$CPPFLAGS -o caller.o -c caller.c"
6417echo headers.at:132 >$at_check_line_file
6418( $at_traceon; $CC $CFLAGS $CPPFLAGS -o caller.o -c caller.c ) >$at_stdout 2>$at_stder1
6419at_status=$?
6420grep '^ *+' $at_stder1 >&2
6421grep -v '^ *+' $at_stder1 >$at_stderr
6422at_failed=false
6423echo stderr:; cat $at_stderr
6424echo stdout:; cat $at_stdout
6425case $at_status in
6426   77) echo 77 > $at_status_file
6427            exit 77;;
6428   0) ;;
6429   *) echo "headers.at:132: exit code was $at_status, expected 0"
6430      at_failed=:;;
6431esac
6432if $at_failed; then
6433
6434  echo 1 > $at_status_file
6435  exit 1
6436fi
6437
6438$at_traceon
6439
6440$at_traceoff
6441echo "headers.at:133: \$CC \$CFLAGS \$CPPFLAGS -o input.o -c input.c"
6442echo headers.at:133 >$at_check_line_file
6443( $at_traceon; $CC $CFLAGS $CPPFLAGS -o input.o -c input.c ) >$at_stdout 2>$at_stder1
6444at_status=$?
6445grep '^ *+' $at_stder1 >&2
6446grep -v '^ *+' $at_stder1 >$at_stderr
6447at_failed=false
6448echo stderr:; cat $at_stderr
6449echo stdout:; cat $at_stdout
6450case $at_status in
6451   77) echo 77 > $at_status_file
6452            exit 77;;
6453   0) ;;
6454   *) echo "headers.at:133: exit code was $at_status, expected 0"
6455      at_failed=:;;
6456esac
6457if $at_failed; then
6458
6459  echo 1 > $at_status_file
6460  exit 1
6461fi
6462
6463$at_traceon
6464
6465$at_traceoff
6466echo "headers.at:134: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o caller caller.o input.o \$LIBS"
6467echo headers.at:134 >$at_check_line_file
6468( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o caller caller.o input.o $LIBS ) >$at_stdout 2>$at_stder1
6469at_status=$?
6470grep '^ *+' $at_stder1 >&2
6471grep -v '^ *+' $at_stder1 >$at_stderr
6472at_failed=false
6473echo stderr:; cat $at_stderr
6474echo stdout:; cat $at_stdout
6475case $at_status in
6476   77) echo 77 > $at_status_file
6477            exit 77;;
6478   0) ;;
6479   *) echo "headers.at:134: exit code was $at_status, expected 0"
6480      at_failed=:;;
6481esac
6482if $at_failed; then
6483
6484  echo 1 > $at_status_file
6485  exit 1
6486fi
6487
6488$at_traceon
6489
6490$at_traceoff
6491echo "headers.at:135: \$PREPARSER ./caller"
6492echo headers.at:135 >$at_check_line_file
6493( $at_traceon; $PREPARSER ./caller ) >$at_stdout 2>$at_stder1
6494at_status=$?
6495grep '^ *+' $at_stder1 >&2
6496grep -v '^ *+' $at_stder1 >$at_stderr
6497at_failed=false
6498$at_diff $at_devnull $at_stderr || at_failed=:
6499$at_diff $at_devnull $at_stdout || at_failed=:
6500case $at_status in
6501   77) echo 77 > $at_status_file
6502            exit 77;;
6503   0) ;;
6504   *) echo "headers.at:135: exit code was $at_status, expected 0"
6505      at_failed=:;;
6506esac
6507if $at_failed; then
6508
6509  echo 1 > $at_status_file
6510  exit 1
6511fi
6512
6513$at_traceon
6514
6515
6516      $at_traceoff
6517      $at_times_p && times >$at_times_file
6518    ) 5>&1 2>&1 | eval $at_tee_pipe
6519    at_status=`cat $at_status_file`
6520    ;;
6521
6522
6523  banner-7 ) # Banner 7. actions.at:19
6524    cat <<\_ATEOF
6525
6526User Actions.
6527
6528_ATEOF
6529    ;;
6530
6531  50 ) # 50. actions.at:25: Mid-rule actions
6532    at_setup_line='actions.at:25'
6533    at_desc='Mid-rule actions'
6534    $at_quiet $ECHO_N " 50: Mid-rule actions                             $ECHO_C"
6535    at_xfail=no
6536    (
6537      echo "50. actions.at:25: testing ..."
6538      $at_traceon
6539
6540
6541# Bison once forgot the mid-rule actions.  It was because the action
6542# was attached to the host rule (the one with the mid-rule action),
6543# instead of being attached to the empty rule dedicated to this
6544# action.
6545
6546cat >input.y <<'_ATEOF'
6547%{
6548#ifdef HAVE_CONFIG_H
6549# include <config.h>
6550  /* We don't need perfect functions for these tests. */
6551# undef malloc
6552# undef memcmp
6553# undef realloc
6554#endif
6555%}
6556
6557%error-verbose
6558%debug
6559%{
6560# include <stdio.h>
6561# include <stdlib.h>
6562  static void yyerror (const char *msg);
6563  static int yylex (void);
6564%}
6565%%
6566exp:     { putchar ('0'); }
6567     '1' { putchar ('1'); }
6568     '2' { putchar ('2'); }
6569     '3' { putchar ('3'); }
6570     '4' { putchar ('4'); }
6571     '5' { putchar ('5'); }
6572     '6' { putchar ('6'); }
6573     '7' { putchar ('7'); }
6574     '8' { putchar ('8'); }
6575     '9' { putchar ('9'); }
6576         { putchar ('\n'); }
6577   ;
6578%%
6579static int
6580yylex (void)
6581{
6582  static const char *input = "123456789";
6583  return *input++;
6584}
6585
6586static void
6587yyerror (const char *msg)
6588{
6589  fprintf (stderr, "%s\n", msg);
6590}
6591
6592int
6593main (void)
6594{
6595  return yyparse ();
6596}
6597_ATEOF
6598
6599
6600
6601$at_traceoff
6602echo "actions.at:75: bison -d -v -o input.c input.y"
6603echo actions.at:75 >$at_check_line_file
6604( $at_traceon; bison -d -v -o input.c input.y ) >$at_stdout 2>$at_stder1
6605at_status=$?
6606grep '^ *+' $at_stder1 >&2
6607grep -v '^ *+' $at_stder1 >$at_stderr
6608at_failed=false
6609$at_diff $at_devnull $at_stderr || at_failed=:
6610$at_diff $at_devnull $at_stdout || at_failed=:
6611case $at_status in
6612   77) echo 77 > $at_status_file
6613            exit 77;;
6614   0) ;;
6615   *) echo "actions.at:75: exit code was $at_status, expected 0"
6616      at_failed=:;;
6617esac
6618if $at_failed; then
6619
6620  echo 1 > $at_status_file
6621  exit 1
6622fi
6623
6624$at_traceon
6625
6626$at_traceoff
6627echo "actions.at:76: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS"
6628echo actions.at:76 >$at_check_line_file
6629( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1
6630at_status=$?
6631grep '^ *+' $at_stder1 >&2
6632grep -v '^ *+' $at_stder1 >$at_stderr
6633at_failed=false
6634echo stderr:; cat $at_stderr
6635echo stdout:; cat $at_stdout
6636case $at_status in
6637   77) echo 77 > $at_status_file
6638            exit 77;;
6639   0) ;;
6640   *) echo "actions.at:76: exit code was $at_status, expected 0"
6641      at_failed=:;;
6642esac
6643if $at_failed; then
6644
6645  echo 1 > $at_status_file
6646  exit 1
6647fi
6648
6649$at_traceon
6650
6651$at_traceoff
6652echo "actions.at:79: \$PREPARSER ./input"
6653echo actions.at:79 >$at_check_line_file
6654( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
6655at_status=$?
6656grep '^ *+' $at_stder1 >&2
6657grep -v '^ *+' $at_stder1 >$at_stderr
6658at_failed=false
6659$at_diff $at_devnull $at_stderr || at_failed=:
6660echo >>$at_stdout; echo "0123456789
6661" | $at_diff - $at_stdout || at_failed=:
6662case $at_status in
6663   77) echo 77 > $at_status_file
6664            exit 77;;
6665   0) ;;
6666   *) echo "actions.at:79: exit code was $at_status, expected 0"
6667      at_failed=:;;
6668esac
6669if $at_failed; then
6670
6671  echo 1 > $at_status_file
6672  exit 1
6673fi
6674
6675$at_traceon
6676
6677
6678      $at_traceoff
6679      $at_times_p && times >$at_times_file
6680    ) 5>&1 2>&1 | eval $at_tee_pipe
6681    at_status=`cat $at_status_file`
6682    ;;
6683
6684  51 ) # 51. actions.at:91: Exotic Dollars
6685    at_setup_line='actions.at:91'
6686    at_desc='Exotic Dollars'
6687    $at_quiet $ECHO_N " 51: Exotic Dollars                               $ECHO_C"
6688    at_xfail=no
6689    (
6690      echo "51. actions.at:91: testing ..."
6691      $at_traceon
6692
6693
6694cat >input.y <<'_ATEOF'
6695%{
6696#ifdef HAVE_CONFIG_H
6697# include <config.h>
6698  /* We don't need perfect functions for these tests. */
6699# undef malloc
6700# undef memcmp
6701# undef realloc
6702#endif
6703%}
6704
6705%error-verbose
6706%debug
6707%{
6708# include <stdio.h>
6709# include <stdlib.h>
6710  static void yyerror (const char *msg);
6711  static int yylex (void);
6712# define USE(Var)
6713%}
6714
6715%union
6716{
6717  int val;
6718};
6719
6720%type <val> a_1 a_2 a_5
6721            sum_of_the_five_previous_values
6722
6723%%
6724exp: a_1 a_2 { $<val>$ = 3; } { $<val>$ = $<val>3 + 1; } a_5
6725     sum_of_the_five_previous_values
6726    {
6727       USE (($1, $2, $<foo>3, $<foo>4, $5));
6728       printf ("%d\n", $6);
6729    }
6730;
6731a_1: { $$ = 1; };
6732a_2: { $$ = 2; };
6733a_5: { $$ = 5; };
6734
6735sum_of_the_five_previous_values:
6736    {
6737       $$ = $<val>0 + $<val>-1 + $<val>-2 + $<val>-3 + $<val>-4;
6738    }
6739;
6740
6741%%
6742static int
6743yylex (void)
6744{
6745  return EOF;
6746}
6747
6748static void
6749yyerror (const char *msg)
6750{
6751  fprintf (stderr, "%s\n", msg);
6752}
6753
6754int
6755main (void)
6756{
6757  return yyparse ();
6758}
6759_ATEOF
6760
6761
6762
6763$at_traceoff
6764echo "actions.at:150: bison -d -v -o input.c input.y"
6765echo actions.at:150 >$at_check_line_file
6766( $at_traceon; bison -d -v -o input.c input.y ) >$at_stdout 2>$at_stder1
6767at_status=$?
6768grep '^ *+' $at_stder1 >&2
6769grep -v '^ *+' $at_stder1 >$at_stderr
6770at_failed=false
6771$at_diff $at_devnull $at_stderr || at_failed=:
6772$at_diff $at_devnull $at_stdout || at_failed=:
6773case $at_status in
6774   77) echo 77 > $at_status_file
6775            exit 77;;
6776   0) ;;
6777   *) echo "actions.at:150: exit code was $at_status, expected 0"
6778      at_failed=:;;
6779esac
6780if $at_failed; then
6781
6782  echo 1 > $at_status_file
6783  exit 1
6784fi
6785
6786$at_traceon
6787
6788$at_traceoff
6789echo "actions.at:151: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS"
6790echo actions.at:151 >$at_check_line_file
6791( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1
6792at_status=$?
6793grep '^ *+' $at_stder1 >&2
6794grep -v '^ *+' $at_stder1 >$at_stderr
6795at_failed=false
6796echo stderr:; cat $at_stderr
6797echo stdout:; cat $at_stdout
6798case $at_status in
6799   77) echo 77 > $at_status_file
6800            exit 77;;
6801   0) ;;
6802   *) echo "actions.at:151: exit code was $at_status, expected 0"
6803      at_failed=:;;
6804esac
6805if $at_failed; then
6806
6807  echo 1 > $at_status_file
6808  exit 1
6809fi
6810
6811$at_traceon
6812
6813$at_traceoff
6814echo "actions.at:154: \$PREPARSER ./input"
6815echo actions.at:154 >$at_check_line_file
6816( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
6817at_status=$?
6818grep '^ *+' $at_stder1 >&2
6819grep -v '^ *+' $at_stder1 >$at_stderr
6820at_failed=false
6821$at_diff $at_devnull $at_stderr || at_failed=:
6822echo >>$at_stdout; echo "15
6823" | $at_diff - $at_stdout || at_failed=:
6824case $at_status in
6825   77) echo 77 > $at_status_file
6826            exit 77;;
6827   0) ;;
6828   *) echo "actions.at:154: exit code was $at_status, expected 0"
6829      at_failed=:;;
6830esac
6831if $at_failed; then
6832
6833  echo 1 > $at_status_file
6834  exit 1
6835fi
6836
6837$at_traceon
6838
6839
6840      $at_traceoff
6841      $at_times_p && times >$at_times_file
6842    ) 5>&1 2>&1 | eval $at_tee_pipe
6843    at_status=`cat $at_status_file`
6844    ;;
6845
6846  52 ) # 52. actions.at:527: Printers and Destructors :
6847    at_setup_line='actions.at:527'
6848    at_desc='Printers and Destructors : '
6849    $at_quiet $ECHO_N " 52: Printers and Destructors :                   $ECHO_C"
6850    at_xfail=no
6851    (
6852      echo "52. actions.at:527: testing ..."
6853      $at_traceon
6854
6855
6856
6857# Make sure complex $n work.
6858
6859# Be sure to pass all the %directives to this macro to have correct
6860# helping macros.  So don't put any directly in the Bison file.
6861
6862
6863
6864
6865# Using yacc.c?
6866
6867
6868
6869
6870
6871
6872
6873# yyerror receives the location if %location & %pure & (%glr or %parse-param).
6874
6875# yyerror always sees the locations (when activated), except if
6876# yacc & pure & !param.
6877
6878
6879# The interface is pure: either because %pure-parser, or because we
6880# are using the C++ parsers.
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892cat >input.y <<'_ATEOF'
6893%{
6894#ifdef HAVE_CONFIG_H
6895# include <config.h>
6896  /* We don't need perfect functions for these tests. */
6897# undef malloc
6898# undef memcmp
6899# undef realloc
6900#endif
6901%}
6902
6903%{
6904#include <stdio.h>
6905#include <stdlib.h>
6906#include <assert.h>
6907
6908#define YYINITDEPTH 10
6909#define YYMAXDEPTH 10
6910#define RANGE(Location) (Location).first_line, (Location).last_line
6911%}
6912
6913%error-verbose
6914%debug
6915%verbose
6916%locations
6917
6918
6919
6920
6921%{
6922
6923static int yylex (void);
6924static void yyerror (const char *msg);
6925%}
6926
6927
6928
6929%printer
6930  {
6931    fprintf (yyoutput, "%d", $$);
6932  }
6933  input line thing 'x' 'y'
6934
6935%destructor
6936  { printf ("Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
6937  input
6938
6939%destructor
6940  { printf ("Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
6941  line
6942
6943%destructor
6944  { printf ("Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
6945  thing
6946
6947%destructor
6948  { printf ("Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
6949  'x'
6950
6951%destructor
6952  { printf ("Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
6953  'y'
6954
6955%%
6956/*
6957   This grammar is made to exercise error recovery.
6958   "Lines" starting with `(' support error recovery, with
6959   ')' as synchronizing token.  Lines starting with 'x' can never
6960   be recovered from if in error.
6961*/
6962
6963input:
6964  /* Nothing. */
6965    {
6966      $$ = 0;
6967      printf ("input (%d@%d-%d): /* Nothing */\n", $$, RANGE (@$));
6968    }
6969| line input /* Right recursive to load the stack so that popping at
6970		EOF can	be exercised.  */
6971    {
6972      $$ = 2;
6973      printf ("input (%d@%d-%d): line (%d@%d-%d) input (%d@%d-%d)\n",
6974	      $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2));
6975    }
6976;
6977
6978line:
6979  thing thing thing ';'
6980    {
6981      $$ = $1;
6982      printf ("line (%d@%d-%d): thing (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ';' (%d@%d-%d)\n",
6983              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
6984              $3, RANGE (@3), $4, RANGE (@4));
6985    }
6986| '(' thing thing ')'
6987    {
6988      $$ = $1;
6989      printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
6990              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
6991              $3, RANGE (@3), $4, RANGE (@4));
6992    }
6993| '(' thing ')'
6994    {
6995      $$ = $1;
6996      printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
6997              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2), $3, RANGE (@3));
6998    }
6999| '(' error ')'
7000    {
7001      $$ = -1;
7002      printf ("line (%d@%d-%d): '(' (%d@%d-%d) error (@%d-%d) ')' (%d@%d-%d)\n",
7003              $$, RANGE (@$), $1, RANGE (@1), RANGE (@2), $3, RANGE (@3));
7004    }
7005;
7006
7007thing:
7008  'x'
7009    {
7010      $$ = $1;
7011      printf ("thing (%d@%d-%d): 'x' (%d@%d-%d)\n",
7012              $$, RANGE (@$), $1, RANGE (@1));
7013    }
7014;
7015%%
7016/* Alias to ARGV[1]. */
7017const char *source = 0;
7018
7019static int
7020yylex (void)
7021{
7022  static unsigned int counter = 0;
7023
7024  int c = (yylval) = counter++;
7025  /* As in BASIC, line numbers go from 10 to 10.  */
7026 (yylloc).first_line = (yylloc).first_column = 10 * c;
7027  (yylloc).last_line = (yylloc).last_column = (yylloc).first_line + 9;
7028
7029
7030  if (source[c])
7031    printf ("sending: '%c'", source[c]);
7032  else
7033    printf ("sending: EOF");
7034  printf (" (%d@%d-%d)\n", c, RANGE ((yylloc)));
7035  return source[c];
7036}
7037
7038static void
7039yyerror (const char *msg)
7040{
7041  printf ("%d-%d: %s\n", RANGE (yylloc), msg);
7042}
7043
7044int
7045main (int argc, const char *argv[])
7046{
7047  int status;
7048  yydebug = !!getenv ("YYDEBUG");
7049  assert (argc == 2);
7050  source = argv[1];
7051  status = yyparse ();
7052  switch (status)
7053    {
7054      case 0: printf ("Successful parse.\n"); break;
7055      case 1: printf ("Parsing FAILED.\n"); break;
7056      default: printf ("Parsing FAILED (status %d).\n", status); break;
7057    }
7058  return status;
7059}
7060_ATEOF
7061
7062
7063
7064$at_traceoff
7065echo "actions.at:527: bison -o input.c input.y"
7066echo actions.at:527 >$at_check_line_file
7067( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
7068at_status=$?
7069grep '^ *+' $at_stder1 >&2
7070grep -v '^ *+' $at_stder1 >$at_stderr
7071at_failed=false
7072$at_diff $at_devnull $at_stderr || at_failed=:
7073$at_diff $at_devnull $at_stdout || at_failed=:
7074case $at_status in
7075   77) echo 77 > $at_status_file
7076            exit 77;;
7077   0) ;;
7078   *) echo "actions.at:527: exit code was $at_status, expected 0"
7079      at_failed=:;;
7080esac
7081if $at_failed; then
7082
7083  echo 1 > $at_status_file
7084  exit 1
7085fi
7086
7087$at_traceon
7088
7089   $at_traceoff
7090echo "actions.at:527: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS"
7091echo actions.at:527 >$at_check_line_file
7092( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1
7093at_status=$?
7094grep '^ *+' $at_stder1 >&2
7095grep -v '^ *+' $at_stder1 >$at_stderr
7096at_failed=false
7097echo stderr:; cat $at_stderr
7098echo stdout:; cat $at_stdout
7099case $at_status in
7100   77) echo 77 > $at_status_file
7101            exit 77;;
7102   0) ;;
7103   *) echo "actions.at:527: exit code was $at_status, expected 0"
7104      at_failed=:;;
7105esac
7106if $at_failed; then
7107
7108  echo 1 > $at_status_file
7109  exit 1
7110fi
7111
7112$at_traceon
7113
7114
7115
7116# Check the location of "empty"
7117# -----------------------------
7118# I.e., epsilon-reductions, as in "(x)" which ends by reducing
7119# an empty "line" nterm.
7120# FIXME: This location is not satisfying.  Depend on the lookahead?
7121$at_traceoff
7122echo "actions.at:527: \$PREPARSER ./input '(x)'"
7123echo actions.at:527 >$at_check_line_file
7124( $at_traceon; $PREPARSER ./input '(x)' ) >$at_stdout 2>$at_stder1
7125at_status=$?
7126grep '^ *+' $at_stder1 >&2
7127grep -v '^ *+' $at_stder1 >$at_stderr
7128at_failed=false
7129$at_diff $at_devnull $at_stderr || at_failed=:
7130echo >>$at_stdout; echo "sending: '(' (0@0-9)
7131sending: 'x' (1@10-19)
7132thing (1@10-19): 'x' (1@10-19)
7133sending: ')' (2@20-29)
7134line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
7135sending: EOF (3@30-39)
7136input (0@29-29): /* Nothing */
7137input (2@0-29): line (0@0-29) input (0@29-29)
7138Freeing nterm input (2@0-29)
7139Successful parse.
7140" | $at_diff - $at_stdout || at_failed=:
7141case $at_status in
7142   77) echo 77 > $at_status_file
7143            exit 77;;
7144   0) ;;
7145   *) echo "actions.at:527: exit code was $at_status, expected 0"
7146      at_failed=:;;
7147esac
7148if $at_failed; then
7149
7150  echo 1 > $at_status_file
7151  exit 1
7152fi
7153
7154$at_traceon
7155
7156
7157
7158# Check locations in error recovery
7159# ---------------------------------
7160# '(y)' is an error, but can be recovered from.  But what's the location
7161# of the error itself ('y'), and of the resulting reduction ('(error)').
7162$at_traceoff
7163echo "actions.at:527: \$PREPARSER ./input '(y)'"
7164echo actions.at:527 >$at_check_line_file
7165( $at_traceon; $PREPARSER ./input '(y)' ) >$at_stdout 2>$at_stder1
7166at_status=$?
7167grep '^ *+' $at_stder1 >&2
7168grep -v '^ *+' $at_stder1 >$at_stderr
7169at_failed=false
7170$at_diff $at_devnull $at_stderr || at_failed=:
7171echo >>$at_stdout; echo "sending: '(' (0@0-9)
7172sending: 'y' (1@10-19)
717310-19: syntax error, unexpected 'y', expecting 'x'
7174Freeing token 'y' (1@10-19)
7175sending: ')' (2@20-29)
7176line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
7177sending: EOF (3@30-39)
7178input (0@29-29): /* Nothing */
7179input (2@0-29): line (-1@0-29) input (0@29-29)
7180Freeing nterm input (2@0-29)
7181Successful parse.
7182" | $at_diff - $at_stdout || at_failed=:
7183case $at_status in
7184   77) echo 77 > $at_status_file
7185            exit 77;;
7186   0) ;;
7187   *) echo "actions.at:527: exit code was $at_status, expected 0"
7188      at_failed=:;;
7189esac
7190if $at_failed; then
7191
7192  echo 1 > $at_status_file
7193  exit 1
7194fi
7195
7196$at_traceon
7197
7198
7199
7200# Syntax errors caught by the parser
7201# ----------------------------------
7202# Exercise the discarding of stack top and input until `error'
7203# can be reduced.
7204#
7205#     '(', 'x', 'x', 'x', 'x', 'x', ')',
7206#
7207# Load the stack and provoke an error that cannot be caught by the
7208# grammar, to check that the stack is cleared.  And make sure the
7209# lookahead is freed.
7210#
7211#     '(', 'x', ')',
7212#     '(', 'x', ')',
7213#     'y'
7214$at_traceoff
7215echo "actions.at:527: \$PREPARSER ./input '(xxxxx)(x)(x)y'"
7216echo actions.at:527 >$at_check_line_file
7217( $at_traceon; $PREPARSER ./input '(xxxxx)(x)(x)y' ) >$at_stdout 2>$at_stder1
7218at_status=$?
7219grep '^ *+' $at_stder1 >&2
7220grep -v '^ *+' $at_stder1 >$at_stderr
7221at_failed=false
7222$at_diff $at_devnull $at_stderr || at_failed=:
7223echo >>$at_stdout; echo "sending: '(' (0@0-9)
7224sending: 'x' (1@10-19)
7225thing (1@10-19): 'x' (1@10-19)
7226sending: 'x' (2@20-29)
7227thing (2@20-29): 'x' (2@20-29)
7228sending: 'x' (3@30-39)
722930-39: syntax error, unexpected 'x', expecting ')'
7230Freeing nterm thing (2@20-29)
7231Freeing nterm thing (1@10-19)
7232Freeing token 'x' (3@30-39)
7233sending: 'x' (4@40-49)
7234Freeing token 'x' (4@40-49)
7235sending: 'x' (5@50-59)
7236Freeing token 'x' (5@50-59)
7237sending: ')' (6@60-69)
7238line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69)
7239sending: '(' (7@70-79)
7240sending: 'x' (8@80-89)
7241thing (8@80-89): 'x' (8@80-89)
7242sending: ')' (9@90-99)
7243line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99)
7244sending: '(' (10@100-109)
7245sending: 'x' (11@110-119)
7246thing (11@110-119): 'x' (11@110-119)
7247sending: ')' (12@120-129)
7248line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129)
7249sending: 'y' (13@130-139)
7250input (0@129-129): /* Nothing */
7251input (2@100-129): line (10@100-129) input (0@129-129)
7252input (2@70-129): line (7@70-99) input (2@100-129)
7253input (2@0-129): line (-1@0-69) input (2@70-129)
7254130-139: syntax error, unexpected 'y', expecting \$end
7255Freeing nterm input (2@0-129)
7256Freeing token 'y' (13@130-139)
7257Parsing FAILED.
7258" | $at_diff - $at_stdout || at_failed=:
7259case $at_status in
7260   77) echo 77 > $at_status_file
7261            exit 77;;
7262   1) ;;
7263   *) echo "actions.at:527: exit code was $at_status, expected 1"
7264      at_failed=:;;
7265esac
7266if $at_failed; then
7267
7268  echo 1 > $at_status_file
7269  exit 1
7270fi
7271
7272$at_traceon
7273
7274
7275# Check destruction upon stack overflow
7276# -------------------------------------
7277# Upon stack overflow, all symbols on the stack should be destroyed.
7278# Only check for yacc.c.
7279
7280$at_traceoff
7281echo "actions.at:527: \$PREPARSER ./input '(x)(x)(x)(x)(x)(x)(x)'"
7282echo actions.at:527 >$at_check_line_file
7283( $at_traceon; $PREPARSER ./input '(x)(x)(x)(x)(x)(x)(x)' ) >$at_stdout 2>$at_stder1
7284at_status=$?
7285grep '^ *+' $at_stder1 >&2
7286grep -v '^ *+' $at_stder1 >$at_stderr
7287at_failed=false
7288$at_diff $at_devnull $at_stderr || at_failed=:
7289echo >>$at_stdout; echo "sending: '(' (0@0-9)
7290sending: 'x' (1@10-19)
7291thing (1@10-19): 'x' (1@10-19)
7292sending: ')' (2@20-29)
7293line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
7294sending: '(' (3@30-39)
7295sending: 'x' (4@40-49)
7296thing (4@40-49): 'x' (4@40-49)
7297sending: ')' (5@50-59)
7298line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
7299sending: '(' (6@60-69)
7300sending: 'x' (7@70-79)
7301thing (7@70-79): 'x' (7@70-79)
7302sending: ')' (8@80-89)
7303line (6@60-89): '(' (6@60-69) thing (7@70-79) ')' (8@80-89)
7304sending: '(' (9@90-99)
7305sending: 'x' (10@100-109)
7306thing (10@100-109): 'x' (10@100-109)
7307sending: ')' (11@110-119)
7308line (9@90-119): '(' (9@90-99) thing (10@100-109) ')' (11@110-119)
7309sending: '(' (12@120-129)
7310sending: 'x' (13@130-139)
7311thing (13@130-139): 'x' (13@130-139)
7312sending: ')' (14@140-149)
7313line (12@120-149): '(' (12@120-129) thing (13@130-139) ')' (14@140-149)
7314sending: '(' (15@150-159)
7315sending: 'x' (16@160-169)
7316thing (16@160-169): 'x' (16@160-169)
7317sending: ')' (17@170-179)
7318line (15@150-179): '(' (15@150-159) thing (16@160-169) ')' (17@170-179)
7319sending: '(' (18@180-189)
7320sending: 'x' (19@190-199)
7321thing (19@190-199): 'x' (19@190-199)
7322sending: ')' (20@200-209)
7323200-209: memory exhausted
7324Freeing nterm thing (19@190-199)
7325Freeing nterm line (15@150-179)
7326Freeing nterm line (12@120-149)
7327Freeing nterm line (9@90-119)
7328Freeing nterm line (6@60-89)
7329Freeing nterm line (3@30-59)
7330Freeing nterm line (0@0-29)
7331Parsing FAILED (status 2).
7332" | $at_diff - $at_stdout || at_failed=:
7333case $at_status in
7334   77) echo 77 > $at_status_file
7335            exit 77;;
7336   2) ;;
7337   *) echo "actions.at:527: exit code was $at_status, expected 2"
7338      at_failed=:;;
7339esac
7340if $at_failed; then
7341
7342  echo 1 > $at_status_file
7343  exit 1
7344fi
7345
7346$at_traceon
7347
7348
7349
7350
7351
7352      $at_traceoff
7353      $at_times_p && times >$at_times_file
7354    ) 5>&1 2>&1 | eval $at_tee_pipe
7355    at_status=`cat $at_status_file`
7356    ;;
7357
7358  53 ) # 53. actions.at:528: Printers and Destructors with union:
7359    at_setup_line='actions.at:528'
7360    at_desc='Printers and Destructors with union: '
7361    $at_quiet $ECHO_N " 53: Printers and Destructors with union:         $ECHO_C"
7362    at_xfail=no
7363    (
7364      echo "53. actions.at:528: testing ..."
7365      $at_traceon
7366
7367
7368
7369# Make sure complex $n work.
7370
7371# Be sure to pass all the %directives to this macro to have correct
7372# helping macros.  So don't put any directly in the Bison file.
7373
7374
7375
7376
7377# Using yacc.c?
7378
7379
7380
7381
7382
7383
7384
7385# yyerror receives the location if %location & %pure & (%glr or %parse-param).
7386
7387# yyerror always sees the locations (when activated), except if
7388# yacc & pure & !param.
7389
7390
7391# The interface is pure: either because %pure-parser, or because we
7392# are using the C++ parsers.
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404cat >input.y <<'_ATEOF'
7405%{
7406#ifdef HAVE_CONFIG_H
7407# include <config.h>
7408  /* We don't need perfect functions for these tests. */
7409# undef malloc
7410# undef memcmp
7411# undef realloc
7412#endif
7413%}
7414
7415%{
7416#include <stdio.h>
7417#include <stdlib.h>
7418#include <assert.h>
7419
7420#define YYINITDEPTH 10
7421#define YYMAXDEPTH 10
7422#define RANGE(Location) (Location).first_line, (Location).last_line
7423%}
7424
7425%error-verbose
7426%debug
7427%verbose
7428%locations
7429
7430%union
7431{
7432  int ival;
7433}
7434
7435
7436%{
7437
7438static int yylex (void);
7439static void yyerror (const char *msg);
7440%}
7441
7442%type <ival> '(' 'x' 'y' ')' ';' thing line input
7443
7444%printer
7445  {
7446    fprintf (yyoutput, "%d", $$);
7447  }
7448  input line thing 'x' 'y'
7449
7450%destructor
7451  { printf ("Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
7452  input
7453
7454%destructor
7455  { printf ("Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
7456  line
7457
7458%destructor
7459  { printf ("Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
7460  thing
7461
7462%destructor
7463  { printf ("Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
7464  'x'
7465
7466%destructor
7467  { printf ("Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
7468  'y'
7469
7470%%
7471/*
7472   This grammar is made to exercise error recovery.
7473   "Lines" starting with `(' support error recovery, with
7474   ')' as synchronizing token.  Lines starting with 'x' can never
7475   be recovered from if in error.
7476*/
7477
7478input:
7479  /* Nothing. */
7480    {
7481      $$ = 0;
7482      printf ("input (%d@%d-%d): /* Nothing */\n", $$, RANGE (@$));
7483    }
7484| line input /* Right recursive to load the stack so that popping at
7485		EOF can	be exercised.  */
7486    {
7487      $$ = 2;
7488      printf ("input (%d@%d-%d): line (%d@%d-%d) input (%d@%d-%d)\n",
7489	      $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2));
7490    }
7491;
7492
7493line:
7494  thing thing thing ';'
7495    {
7496      $$ = $1;
7497      printf ("line (%d@%d-%d): thing (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ';' (%d@%d-%d)\n",
7498              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
7499              $3, RANGE (@3), $4, RANGE (@4));
7500    }
7501| '(' thing thing ')'
7502    {
7503      $$ = $1;
7504      printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
7505              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
7506              $3, RANGE (@3), $4, RANGE (@4));
7507    }
7508| '(' thing ')'
7509    {
7510      $$ = $1;
7511      printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
7512              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2), $3, RANGE (@3));
7513    }
7514| '(' error ')'
7515    {
7516      $$ = -1;
7517      printf ("line (%d@%d-%d): '(' (%d@%d-%d) error (@%d-%d) ')' (%d@%d-%d)\n",
7518              $$, RANGE (@$), $1, RANGE (@1), RANGE (@2), $3, RANGE (@3));
7519    }
7520;
7521
7522thing:
7523  'x'
7524    {
7525      $$ = $1;
7526      printf ("thing (%d@%d-%d): 'x' (%d@%d-%d)\n",
7527              $$, RANGE (@$), $1, RANGE (@1));
7528    }
7529;
7530%%
7531/* Alias to ARGV[1]. */
7532const char *source = 0;
7533
7534static int
7535yylex (void)
7536{
7537  static unsigned int counter = 0;
7538
7539  int c = (yylval).ival = counter++;
7540  /* As in BASIC, line numbers go from 10 to 10.  */
7541 (yylloc).first_line = (yylloc).first_column = 10 * c;
7542  (yylloc).last_line = (yylloc).last_column = (yylloc).first_line + 9;
7543
7544
7545  if (source[c])
7546    printf ("sending: '%c'", source[c]);
7547  else
7548    printf ("sending: EOF");
7549  printf (" (%d@%d-%d)\n", c, RANGE ((yylloc)));
7550  return source[c];
7551}
7552
7553static void
7554yyerror (const char *msg)
7555{
7556  printf ("%d-%d: %s\n", RANGE (yylloc), msg);
7557}
7558
7559int
7560main (int argc, const char *argv[])
7561{
7562  int status;
7563  yydebug = !!getenv ("YYDEBUG");
7564  assert (argc == 2);
7565  source = argv[1];
7566  status = yyparse ();
7567  switch (status)
7568    {
7569      case 0: printf ("Successful parse.\n"); break;
7570      case 1: printf ("Parsing FAILED.\n"); break;
7571      default: printf ("Parsing FAILED (status %d).\n", status); break;
7572    }
7573  return status;
7574}
7575_ATEOF
7576
7577
7578
7579$at_traceoff
7580echo "actions.at:528: bison -o input.c input.y"
7581echo actions.at:528 >$at_check_line_file
7582( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
7583at_status=$?
7584grep '^ *+' $at_stder1 >&2
7585grep -v '^ *+' $at_stder1 >$at_stderr
7586at_failed=false
7587$at_diff $at_devnull $at_stderr || at_failed=:
7588$at_diff $at_devnull $at_stdout || at_failed=:
7589case $at_status in
7590   77) echo 77 > $at_status_file
7591            exit 77;;
7592   0) ;;
7593   *) echo "actions.at:528: exit code was $at_status, expected 0"
7594      at_failed=:;;
7595esac
7596if $at_failed; then
7597
7598  echo 1 > $at_status_file
7599  exit 1
7600fi
7601
7602$at_traceon
7603
7604   $at_traceoff
7605echo "actions.at:528: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS"
7606echo actions.at:528 >$at_check_line_file
7607( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1
7608at_status=$?
7609grep '^ *+' $at_stder1 >&2
7610grep -v '^ *+' $at_stder1 >$at_stderr
7611at_failed=false
7612echo stderr:; cat $at_stderr
7613echo stdout:; cat $at_stdout
7614case $at_status in
7615   77) echo 77 > $at_status_file
7616            exit 77;;
7617   0) ;;
7618   *) echo "actions.at:528: exit code was $at_status, expected 0"
7619      at_failed=:;;
7620esac
7621if $at_failed; then
7622
7623  echo 1 > $at_status_file
7624  exit 1
7625fi
7626
7627$at_traceon
7628
7629
7630
7631# Check the location of "empty"
7632# -----------------------------
7633# I.e., epsilon-reductions, as in "(x)" which ends by reducing
7634# an empty "line" nterm.
7635# FIXME: This location is not satisfying.  Depend on the lookahead?
7636$at_traceoff
7637echo "actions.at:528: \$PREPARSER ./input '(x)'"
7638echo actions.at:528 >$at_check_line_file
7639( $at_traceon; $PREPARSER ./input '(x)' ) >$at_stdout 2>$at_stder1
7640at_status=$?
7641grep '^ *+' $at_stder1 >&2
7642grep -v '^ *+' $at_stder1 >$at_stderr
7643at_failed=false
7644$at_diff $at_devnull $at_stderr || at_failed=:
7645echo >>$at_stdout; echo "sending: '(' (0@0-9)
7646sending: 'x' (1@10-19)
7647thing (1@10-19): 'x' (1@10-19)
7648sending: ')' (2@20-29)
7649line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
7650sending: EOF (3@30-39)
7651input (0@29-29): /* Nothing */
7652input (2@0-29): line (0@0-29) input (0@29-29)
7653Freeing nterm input (2@0-29)
7654Successful parse.
7655" | $at_diff - $at_stdout || at_failed=:
7656case $at_status in
7657   77) echo 77 > $at_status_file
7658            exit 77;;
7659   0) ;;
7660   *) echo "actions.at:528: exit code was $at_status, expected 0"
7661      at_failed=:;;
7662esac
7663if $at_failed; then
7664
7665  echo 1 > $at_status_file
7666  exit 1
7667fi
7668
7669$at_traceon
7670
7671
7672
7673# Check locations in error recovery
7674# ---------------------------------
7675# '(y)' is an error, but can be recovered from.  But what's the location
7676# of the error itself ('y'), and of the resulting reduction ('(error)').
7677$at_traceoff
7678echo "actions.at:528: \$PREPARSER ./input '(y)'"
7679echo actions.at:528 >$at_check_line_file
7680( $at_traceon; $PREPARSER ./input '(y)' ) >$at_stdout 2>$at_stder1
7681at_status=$?
7682grep '^ *+' $at_stder1 >&2
7683grep -v '^ *+' $at_stder1 >$at_stderr
7684at_failed=false
7685$at_diff $at_devnull $at_stderr || at_failed=:
7686echo >>$at_stdout; echo "sending: '(' (0@0-9)
7687sending: 'y' (1@10-19)
768810-19: syntax error, unexpected 'y', expecting 'x'
7689Freeing token 'y' (1@10-19)
7690sending: ')' (2@20-29)
7691line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
7692sending: EOF (3@30-39)
7693input (0@29-29): /* Nothing */
7694input (2@0-29): line (-1@0-29) input (0@29-29)
7695Freeing nterm input (2@0-29)
7696Successful parse.
7697" | $at_diff - $at_stdout || at_failed=:
7698case $at_status in
7699   77) echo 77 > $at_status_file
7700            exit 77;;
7701   0) ;;
7702   *) echo "actions.at:528: exit code was $at_status, expected 0"
7703      at_failed=:;;
7704esac
7705if $at_failed; then
7706
7707  echo 1 > $at_status_file
7708  exit 1
7709fi
7710
7711$at_traceon
7712
7713
7714
7715# Syntax errors caught by the parser
7716# ----------------------------------
7717# Exercise the discarding of stack top and input until `error'
7718# can be reduced.
7719#
7720#     '(', 'x', 'x', 'x', 'x', 'x', ')',
7721#
7722# Load the stack and provoke an error that cannot be caught by the
7723# grammar, to check that the stack is cleared.  And make sure the
7724# lookahead is freed.
7725#
7726#     '(', 'x', ')',
7727#     '(', 'x', ')',
7728#     'y'
7729$at_traceoff
7730echo "actions.at:528: \$PREPARSER ./input '(xxxxx)(x)(x)y'"
7731echo actions.at:528 >$at_check_line_file
7732( $at_traceon; $PREPARSER ./input '(xxxxx)(x)(x)y' ) >$at_stdout 2>$at_stder1
7733at_status=$?
7734grep '^ *+' $at_stder1 >&2
7735grep -v '^ *+' $at_stder1 >$at_stderr
7736at_failed=false
7737$at_diff $at_devnull $at_stderr || at_failed=:
7738echo >>$at_stdout; echo "sending: '(' (0@0-9)
7739sending: 'x' (1@10-19)
7740thing (1@10-19): 'x' (1@10-19)
7741sending: 'x' (2@20-29)
7742thing (2@20-29): 'x' (2@20-29)
7743sending: 'x' (3@30-39)
774430-39: syntax error, unexpected 'x', expecting ')'
7745Freeing nterm thing (2@20-29)
7746Freeing nterm thing (1@10-19)
7747Freeing token 'x' (3@30-39)
7748sending: 'x' (4@40-49)
7749Freeing token 'x' (4@40-49)
7750sending: 'x' (5@50-59)
7751Freeing token 'x' (5@50-59)
7752sending: ')' (6@60-69)
7753line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69)
7754sending: '(' (7@70-79)
7755sending: 'x' (8@80-89)
7756thing (8@80-89): 'x' (8@80-89)
7757sending: ')' (9@90-99)
7758line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99)
7759sending: '(' (10@100-109)
7760sending: 'x' (11@110-119)
7761thing (11@110-119): 'x' (11@110-119)
7762sending: ')' (12@120-129)
7763line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129)
7764sending: 'y' (13@130-139)
7765input (0@129-129): /* Nothing */
7766input (2@100-129): line (10@100-129) input (0@129-129)
7767input (2@70-129): line (7@70-99) input (2@100-129)
7768input (2@0-129): line (-1@0-69) input (2@70-129)
7769130-139: syntax error, unexpected 'y', expecting \$end
7770Freeing nterm input (2@0-129)
7771Freeing token 'y' (13@130-139)
7772Parsing FAILED.
7773" | $at_diff - $at_stdout || at_failed=:
7774case $at_status in
7775   77) echo 77 > $at_status_file
7776            exit 77;;
7777   1) ;;
7778   *) echo "actions.at:528: exit code was $at_status, expected 1"
7779      at_failed=:;;
7780esac
7781if $at_failed; then
7782
7783  echo 1 > $at_status_file
7784  exit 1
7785fi
7786
7787$at_traceon
7788
7789
7790# Check destruction upon stack overflow
7791# -------------------------------------
7792# Upon stack overflow, all symbols on the stack should be destroyed.
7793# Only check for yacc.c.
7794
7795$at_traceoff
7796echo "actions.at:528: \$PREPARSER ./input '(x)(x)(x)(x)(x)(x)(x)'"
7797echo actions.at:528 >$at_check_line_file
7798( $at_traceon; $PREPARSER ./input '(x)(x)(x)(x)(x)(x)(x)' ) >$at_stdout 2>$at_stder1
7799at_status=$?
7800grep '^ *+' $at_stder1 >&2
7801grep -v '^ *+' $at_stder1 >$at_stderr
7802at_failed=false
7803$at_diff $at_devnull $at_stderr || at_failed=:
7804echo >>$at_stdout; echo "sending: '(' (0@0-9)
7805sending: 'x' (1@10-19)
7806thing (1@10-19): 'x' (1@10-19)
7807sending: ')' (2@20-29)
7808line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
7809sending: '(' (3@30-39)
7810sending: 'x' (4@40-49)
7811thing (4@40-49): 'x' (4@40-49)
7812sending: ')' (5@50-59)
7813line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59)
7814sending: '(' (6@60-69)
7815sending: 'x' (7@70-79)
7816thing (7@70-79): 'x' (7@70-79)
7817sending: ')' (8@80-89)
7818line (6@60-89): '(' (6@60-69) thing (7@70-79) ')' (8@80-89)
7819sending: '(' (9@90-99)
7820sending: 'x' (10@100-109)
7821thing (10@100-109): 'x' (10@100-109)
7822sending: ')' (11@110-119)
7823line (9@90-119): '(' (9@90-99) thing (10@100-109) ')' (11@110-119)
7824sending: '(' (12@120-129)
7825sending: 'x' (13@130-139)
7826thing (13@130-139): 'x' (13@130-139)
7827sending: ')' (14@140-149)
7828line (12@120-149): '(' (12@120-129) thing (13@130-139) ')' (14@140-149)
7829sending: '(' (15@150-159)
7830sending: 'x' (16@160-169)
7831thing (16@160-169): 'x' (16@160-169)
7832sending: ')' (17@170-179)
7833line (15@150-179): '(' (15@150-159) thing (16@160-169) ')' (17@170-179)
7834sending: '(' (18@180-189)
7835sending: 'x' (19@190-199)
7836thing (19@190-199): 'x' (19@190-199)
7837sending: ')' (20@200-209)
7838200-209: memory exhausted
7839Freeing nterm thing (19@190-199)
7840Freeing nterm line (15@150-179)
7841Freeing nterm line (12@120-149)
7842Freeing nterm line (9@90-119)
7843Freeing nterm line (6@60-89)
7844Freeing nterm line (3@30-59)
7845Freeing nterm line (0@0-29)
7846Parsing FAILED (status 2).
7847" | $at_diff - $at_stdout || at_failed=:
7848case $at_status in
7849   77) echo 77 > $at_status_file
7850            exit 77;;
7851   2) ;;
7852   *) echo "actions.at:528: exit code was $at_status, expected 2"
7853      at_failed=:;;
7854esac
7855if $at_failed; then
7856
7857  echo 1 > $at_status_file
7858  exit 1
7859fi
7860
7861$at_traceon
7862
7863
7864
7865
7866
7867      $at_traceoff
7868      $at_times_p && times >$at_times_file
7869    ) 5>&1 2>&1 | eval $at_tee_pipe
7870    at_status=`cat $at_status_file`
7871    ;;
7872
7873  54 ) # 54. actions.at:533: Printers and Destructors : %defines %skeleton "lalr1.cc"
7874    at_setup_line='actions.at:533'
7875    at_desc='Printers and Destructors : %defines %skeleton "lalr1.cc"'
7876    $at_quiet $ECHO_N " 54: Printers and Destructors : %defines %skeleton "lalr1.cc"$ECHO_C"
7877    at_xfail=no
7878    (
7879      echo "54. actions.at:533: testing ..."
7880      $at_traceon
7881
7882
7883
7884# Make sure complex $n work.
7885
7886# Be sure to pass all the %directives to this macro to have correct
7887# helping macros.  So don't put any directly in the Bison file.
7888
7889
7890
7891
7892# Using yacc.c?
7893
7894
7895
7896
7897
7898
7899
7900# yyerror receives the location if %location & %pure & (%glr or %parse-param).
7901
7902# yyerror always sees the locations (when activated), except if
7903# yacc & pure & !param.
7904
7905
7906# The interface is pure: either because %pure-parser, or because we
7907# are using the C++ parsers.
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919cat >input.y <<'_ATEOF'
7920%{
7921#ifdef HAVE_CONFIG_H
7922# include <config.h>
7923  /* We don't need perfect functions for these tests. */
7924# undef malloc
7925# undef memcmp
7926# undef realloc
7927#endif
7928%}
7929
7930%{
7931#include <stdio.h>
7932#include <stdlib.h>
7933#include <assert.h>
7934
7935#define YYINITDEPTH 10
7936#define YYMAXDEPTH 10
7937#define RANGE(Location) (Location).begin.line, (Location).end.line
7938%}
7939
7940%error-verbose
7941%debug
7942%verbose
7943%locations
7944%defines %skeleton "lalr1.cc"
7945
7946%define "global_tokens_and_yystype"
7947
7948%{
7949typedef yy::location YYLTYPE;
7950                #define YYSTYPE int
7951static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
7952
7953%}
7954
7955
7956
7957%printer
7958  {
7959    debug_stream () << $$;;
7960  }
7961  input line thing 'x' 'y'
7962
7963%destructor
7964  { printf ("Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
7965  input
7966
7967%destructor
7968  { printf ("Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
7969  line
7970
7971%destructor
7972  { printf ("Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
7973  thing
7974
7975%destructor
7976  { printf ("Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
7977  'x'
7978
7979%destructor
7980  { printf ("Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
7981  'y'
7982
7983%%
7984/*
7985   This grammar is made to exercise error recovery.
7986   "Lines" starting with `(' support error recovery, with
7987   ')' as synchronizing token.  Lines starting with 'x' can never
7988   be recovered from if in error.
7989*/
7990
7991input:
7992  /* Nothing. */
7993    {
7994      $$ = 0;
7995      printf ("input (%d@%d-%d): /* Nothing */\n", $$, RANGE (@$));
7996    }
7997| line input /* Right recursive to load the stack so that popping at
7998		EOF can	be exercised.  */
7999    {
8000      $$ = 2;
8001      printf ("input (%d@%d-%d): line (%d@%d-%d) input (%d@%d-%d)\n",
8002	      $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2));
8003    }
8004;
8005
8006line:
8007  thing thing thing ';'
8008    {
8009      $$ = $1;
8010      printf ("line (%d@%d-%d): thing (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ';' (%d@%d-%d)\n",
8011              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
8012              $3, RANGE (@3), $4, RANGE (@4));
8013    }
8014| '(' thing thing ')'
8015    {
8016      $$ = $1;
8017      printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
8018              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
8019              $3, RANGE (@3), $4, RANGE (@4));
8020    }
8021| '(' thing ')'
8022    {
8023      $$ = $1;
8024      printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
8025              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2), $3, RANGE (@3));
8026    }
8027| '(' error ')'
8028    {
8029      $$ = -1;
8030      printf ("line (%d@%d-%d): '(' (%d@%d-%d) error (@%d-%d) ')' (%d@%d-%d)\n",
8031              $$, RANGE (@$), $1, RANGE (@1), RANGE (@2), $3, RANGE (@3));
8032    }
8033;
8034
8035thing:
8036  'x'
8037    {
8038      $$ = $1;
8039      printf ("thing (%d@%d-%d): 'x' (%d@%d-%d)\n",
8040              $$, RANGE (@$), $1, RANGE (@1));
8041    }
8042;
8043%%
8044/* Alias to ARGV[1]. */
8045const char *source = 0;
8046
8047static int
8048yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
8049{
8050  static unsigned int counter = 0;
8051
8052  int c = (*lvalp) = counter++;
8053  /* As in BASIC, line numbers go from 10 to 10.  */
8054 (*llocp).begin.line = (*llocp).begin.column = 10 * c;
8055  (*llocp).end.line = (*llocp).end.column = (*llocp).begin.line + 9;
8056
8057
8058  if (source[c])
8059    printf ("sending: '%c'", source[c]);
8060  else
8061    printf ("sending: EOF");
8062  printf (" (%d@%d-%d)\n", c, RANGE ((*llocp)));
8063  return source[c];
8064}
8065
8066/* A C++ error reporting function. */
8067void
8068yy::parser::error (const location& l, const std::string& m)
8069{
8070  printf ("%d-%d: %s\n", RANGE (l), m.c_str());
8071}
8072
8073static bool yydebug;
8074int
8075yyparse ()
8076{
8077  yy::parser parser;
8078  parser.set_debug_level (yydebug);
8079  return parser.parse ();
8080}
8081
8082
8083int
8084main (int argc, const char *argv[])
8085{
8086  int status;
8087  yydebug = !!getenv ("YYDEBUG");
8088  assert (argc == 2);
8089  source = argv[1];
8090  status = yyparse ();
8091  switch (status)
8092    {
8093      case 0: printf ("Successful parse.\n"); break;
8094      case 1: printf ("Parsing FAILED.\n"); break;
8095      default: printf ("Parsing FAILED (status %d).\n", status); break;
8096    }
8097  return status;
8098}
8099_ATEOF
8100
8101
8102
8103$at_traceoff
8104echo "actions.at:533: bison -o input.cc input.y"
8105echo actions.at:533 >$at_check_line_file
8106( $at_traceon; bison -o input.cc input.y ) >$at_stdout 2>$at_stder1
8107at_status=$?
8108grep '^ *+' $at_stder1 >&2
8109grep -v '^ *+' $at_stder1 >$at_stderr
8110at_failed=false
8111$at_diff $at_devnull $at_stderr || at_failed=:
8112$at_diff $at_devnull $at_stdout || at_failed=:
8113case $at_status in
8114   77) echo 77 > $at_status_file
8115            exit 77;;
8116   0) ;;
8117   *) echo "actions.at:533: exit code was $at_status, expected 0"
8118      at_failed=:;;
8119esac
8120if $at_failed; then
8121
8122  echo 1 > $at_status_file
8123  exit 1
8124fi
8125
8126$at_traceon
8127
8128
8129$at_traceoff
8130echo "actions.at:533: \$BISON_CXX_WORKS"
8131echo actions.at:533 >$at_check_line_file
8132( $at_traceon; $BISON_CXX_WORKS ) >$at_stdout 2>$at_stder1
8133at_status=$?
8134grep '^ *+' $at_stder1 >&2
8135grep -v '^ *+' $at_stder1 >$at_stderr
8136at_failed=false
8137echo stderr:; cat $at_stderr
8138echo stdout:; cat $at_stdout
8139case $at_status in
8140   77) echo 77 > $at_status_file
8141            exit 77;;
8142   0) ;;
8143   *) echo "actions.at:533: exit code was $at_status, expected 0"
8144      at_failed=:;;
8145esac
8146if $at_failed; then
8147
8148  echo 1 > $at_status_file
8149  exit 1
8150fi
8151
8152$at_traceon
8153
8154$at_traceoff
8155echo "actions.at:533: \$CXX \$CXXFLAGS \$CPPFLAGS \$LDFLAGS -o input input.cc \$LIBS"
8156echo actions.at:533 >$at_check_line_file
8157( $at_traceon; $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o input input.cc $LIBS ) >$at_stdout 2>$at_stder1
8158at_status=$?
8159grep '^ *+' $at_stder1 >&2
8160grep -v '^ *+' $at_stder1 >$at_stderr
8161at_failed=false
8162echo stderr:; cat $at_stderr
8163echo stdout:; cat $at_stdout
8164case $at_status in
8165   77) echo 77 > $at_status_file
8166            exit 77;;
8167   0) ;;
8168   *) echo "actions.at:533: exit code was $at_status, expected 0"
8169      at_failed=:;;
8170esac
8171if $at_failed; then
8172
8173  echo 1 > $at_status_file
8174  exit 1
8175fi
8176
8177$at_traceon
8178
8179
8180
8181# Check the location of "empty"
8182# -----------------------------
8183# I.e., epsilon-reductions, as in "(x)" which ends by reducing
8184# an empty "line" nterm.
8185# FIXME: This location is not satisfying.  Depend on the lookahead?
8186$at_traceoff
8187echo "actions.at:533: \$PREPARSER ./input '(x)'"
8188echo actions.at:533 >$at_check_line_file
8189( $at_traceon; $PREPARSER ./input '(x)' ) >$at_stdout 2>$at_stder1
8190at_status=$?
8191grep '^ *+' $at_stder1 >&2
8192grep -v '^ *+' $at_stder1 >$at_stderr
8193at_failed=false
8194$at_diff $at_devnull $at_stderr || at_failed=:
8195echo >>$at_stdout; echo "sending: '(' (0@0-9)
8196sending: 'x' (1@10-19)
8197thing (1@10-19): 'x' (1@10-19)
8198sending: ')' (2@20-29)
8199line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
8200sending: EOF (3@30-39)
8201input (0@29-29): /* Nothing */
8202input (2@0-29): line (0@0-29) input (0@29-29)
8203Freeing nterm input (2@0-29)
8204Successful parse.
8205" | $at_diff - $at_stdout || at_failed=:
8206case $at_status in
8207   77) echo 77 > $at_status_file
8208            exit 77;;
8209   0) ;;
8210   *) echo "actions.at:533: exit code was $at_status, expected 0"
8211      at_failed=:;;
8212esac
8213if $at_failed; then
8214
8215  echo 1 > $at_status_file
8216  exit 1
8217fi
8218
8219$at_traceon
8220
8221
8222
8223# Check locations in error recovery
8224# ---------------------------------
8225# '(y)' is an error, but can be recovered from.  But what's the location
8226# of the error itself ('y'), and of the resulting reduction ('(error)').
8227$at_traceoff
8228echo "actions.at:533: \$PREPARSER ./input '(y)'"
8229echo actions.at:533 >$at_check_line_file
8230( $at_traceon; $PREPARSER ./input '(y)' ) >$at_stdout 2>$at_stder1
8231at_status=$?
8232grep '^ *+' $at_stder1 >&2
8233grep -v '^ *+' $at_stder1 >$at_stderr
8234at_failed=false
8235$at_diff $at_devnull $at_stderr || at_failed=:
8236echo >>$at_stdout; echo "sending: '(' (0@0-9)
8237sending: 'y' (1@10-19)
823810-19: syntax error, unexpected 'y', expecting 'x'
8239Freeing token 'y' (1@10-19)
8240sending: ')' (2@20-29)
8241line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
8242sending: EOF (3@30-39)
8243input (0@29-29): /* Nothing */
8244input (2@0-29): line (-1@0-29) input (0@29-29)
8245Freeing nterm input (2@0-29)
8246Successful parse.
8247" | $at_diff - $at_stdout || at_failed=:
8248case $at_status in
8249   77) echo 77 > $at_status_file
8250            exit 77;;
8251   0) ;;
8252   *) echo "actions.at:533: exit code was $at_status, expected 0"
8253      at_failed=:;;
8254esac
8255if $at_failed; then
8256
8257  echo 1 > $at_status_file
8258  exit 1
8259fi
8260
8261$at_traceon
8262
8263
8264
8265# Syntax errors caught by the parser
8266# ----------------------------------
8267# Exercise the discarding of stack top and input until `error'
8268# can be reduced.
8269#
8270#     '(', 'x', 'x', 'x', 'x', 'x', ')',
8271#
8272# Load the stack and provoke an error that cannot be caught by the
8273# grammar, to check that the stack is cleared.  And make sure the
8274# lookahead is freed.
8275#
8276#     '(', 'x', ')',
8277#     '(', 'x', ')',
8278#     'y'
8279$at_traceoff
8280echo "actions.at:533: \$PREPARSER ./input '(xxxxx)(x)(x)y'"
8281echo actions.at:533 >$at_check_line_file
8282( $at_traceon; $PREPARSER ./input '(xxxxx)(x)(x)y' ) >$at_stdout 2>$at_stder1
8283at_status=$?
8284grep '^ *+' $at_stder1 >&2
8285grep -v '^ *+' $at_stder1 >$at_stderr
8286at_failed=false
8287$at_diff $at_devnull $at_stderr || at_failed=:
8288echo >>$at_stdout; echo "sending: '(' (0@0-9)
8289sending: 'x' (1@10-19)
8290thing (1@10-19): 'x' (1@10-19)
8291sending: 'x' (2@20-29)
8292thing (2@20-29): 'x' (2@20-29)
8293sending: 'x' (3@30-39)
829430-39: syntax error, unexpected 'x', expecting ')'
8295Freeing nterm thing (2@20-29)
8296Freeing nterm thing (1@10-19)
8297Freeing token 'x' (3@30-39)
8298sending: 'x' (4@40-49)
8299Freeing token 'x' (4@40-49)
8300sending: 'x' (5@50-59)
8301Freeing token 'x' (5@50-59)
8302sending: ')' (6@60-69)
8303line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69)
8304sending: '(' (7@70-79)
8305sending: 'x' (8@80-89)
8306thing (8@80-89): 'x' (8@80-89)
8307sending: ')' (9@90-99)
8308line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99)
8309sending: '(' (10@100-109)
8310sending: 'x' (11@110-119)
8311thing (11@110-119): 'x' (11@110-119)
8312sending: ')' (12@120-129)
8313line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129)
8314sending: 'y' (13@130-139)
8315input (0@129-129): /* Nothing */
8316input (2@100-129): line (10@100-129) input (0@129-129)
8317input (2@70-129): line (7@70-99) input (2@100-129)
8318input (2@0-129): line (-1@0-69) input (2@70-129)
8319130-139: syntax error, unexpected 'y', expecting \$end
8320Freeing nterm input (2@0-129)
8321Freeing token 'y' (13@130-139)
8322Parsing FAILED.
8323" | $at_diff - $at_stdout || at_failed=:
8324case $at_status in
8325   77) echo 77 > $at_status_file
8326            exit 77;;
8327   1) ;;
8328   *) echo "actions.at:533: exit code was $at_status, expected 1"
8329      at_failed=:;;
8330esac
8331if $at_failed; then
8332
8333  echo 1 > $at_status_file
8334  exit 1
8335fi
8336
8337$at_traceon
8338
8339
8340# Check destruction upon stack overflow
8341# -------------------------------------
8342# Upon stack overflow, all symbols on the stack should be destroyed.
8343# Only check for yacc.c.
8344
8345
8346
8347
8348      $at_traceoff
8349      $at_times_p && times >$at_times_file
8350    ) 5>&1 2>&1 | eval $at_tee_pipe
8351    at_status=`cat $at_status_file`
8352    ;;
8353
8354  55 ) # 55. actions.at:534: Printers and Destructors with union: %defines %skeleton "lalr1.cc"
8355    at_setup_line='actions.at:534'
8356    at_desc='Printers and Destructors with union: %defines %skeleton "lalr1.cc"'
8357    $at_quiet $ECHO_N " 55: Printers and Destructors with union: %defines %skeleton "lalr1.cc"$ECHO_C"
8358    at_xfail=no
8359    (
8360      echo "55. actions.at:534: testing ..."
8361      $at_traceon
8362
8363
8364
8365# Make sure complex $n work.
8366
8367# Be sure to pass all the %directives to this macro to have correct
8368# helping macros.  So don't put any directly in the Bison file.
8369
8370
8371
8372
8373# Using yacc.c?
8374
8375
8376
8377
8378
8379
8380
8381# yyerror receives the location if %location & %pure & (%glr or %parse-param).
8382
8383# yyerror always sees the locations (when activated), except if
8384# yacc & pure & !param.
8385
8386
8387# The interface is pure: either because %pure-parser, or because we
8388# are using the C++ parsers.
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400cat >input.y <<'_ATEOF'
8401%{
8402#ifdef HAVE_CONFIG_H
8403# include <config.h>
8404  /* We don't need perfect functions for these tests. */
8405# undef malloc
8406# undef memcmp
8407# undef realloc
8408#endif
8409%}
8410
8411%{
8412#include <stdio.h>
8413#include <stdlib.h>
8414#include <assert.h>
8415
8416#define YYINITDEPTH 10
8417#define YYMAXDEPTH 10
8418#define RANGE(Location) (Location).begin.line, (Location).end.line
8419%}
8420
8421%error-verbose
8422%debug
8423%verbose
8424%locations
8425%defines %skeleton "lalr1.cc"
8426%union
8427{
8428  int ival;
8429}
8430%define "global_tokens_and_yystype"
8431
8432%{
8433typedef yy::location YYLTYPE;
8434
8435static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
8436
8437%}
8438
8439%type <ival> '(' 'x' 'y' ')' ';' thing line input
8440
8441%printer
8442  {
8443    debug_stream () << $$;;
8444  }
8445  input line thing 'x' 'y'
8446
8447%destructor
8448  { printf ("Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
8449  input
8450
8451%destructor
8452  { printf ("Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
8453  line
8454
8455%destructor
8456  { printf ("Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
8457  thing
8458
8459%destructor
8460  { printf ("Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
8461  'x'
8462
8463%destructor
8464  { printf ("Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
8465  'y'
8466
8467%%
8468/*
8469   This grammar is made to exercise error recovery.
8470   "Lines" starting with `(' support error recovery, with
8471   ')' as synchronizing token.  Lines starting with 'x' can never
8472   be recovered from if in error.
8473*/
8474
8475input:
8476  /* Nothing. */
8477    {
8478      $$ = 0;
8479      printf ("input (%d@%d-%d): /* Nothing */\n", $$, RANGE (@$));
8480    }
8481| line input /* Right recursive to load the stack so that popping at
8482		EOF can	be exercised.  */
8483    {
8484      $$ = 2;
8485      printf ("input (%d@%d-%d): line (%d@%d-%d) input (%d@%d-%d)\n",
8486	      $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2));
8487    }
8488;
8489
8490line:
8491  thing thing thing ';'
8492    {
8493      $$ = $1;
8494      printf ("line (%d@%d-%d): thing (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ';' (%d@%d-%d)\n",
8495              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
8496              $3, RANGE (@3), $4, RANGE (@4));
8497    }
8498| '(' thing thing ')'
8499    {
8500      $$ = $1;
8501      printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
8502              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
8503              $3, RANGE (@3), $4, RANGE (@4));
8504    }
8505| '(' thing ')'
8506    {
8507      $$ = $1;
8508      printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
8509              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2), $3, RANGE (@3));
8510    }
8511| '(' error ')'
8512    {
8513      $$ = -1;
8514      printf ("line (%d@%d-%d): '(' (%d@%d-%d) error (@%d-%d) ')' (%d@%d-%d)\n",
8515              $$, RANGE (@$), $1, RANGE (@1), RANGE (@2), $3, RANGE (@3));
8516    }
8517;
8518
8519thing:
8520  'x'
8521    {
8522      $$ = $1;
8523      printf ("thing (%d@%d-%d): 'x' (%d@%d-%d)\n",
8524              $$, RANGE (@$), $1, RANGE (@1));
8525    }
8526;
8527%%
8528/* Alias to ARGV[1]. */
8529const char *source = 0;
8530
8531static int
8532yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
8533{
8534  static unsigned int counter = 0;
8535
8536  int c = (*lvalp).ival = counter++;
8537  /* As in BASIC, line numbers go from 10 to 10.  */
8538 (*llocp).begin.line = (*llocp).begin.column = 10 * c;
8539  (*llocp).end.line = (*llocp).end.column = (*llocp).begin.line + 9;
8540
8541
8542  if (source[c])
8543    printf ("sending: '%c'", source[c]);
8544  else
8545    printf ("sending: EOF");
8546  printf (" (%d@%d-%d)\n", c, RANGE ((*llocp)));
8547  return source[c];
8548}
8549
8550/* A C++ error reporting function. */
8551void
8552yy::parser::error (const location& l, const std::string& m)
8553{
8554  printf ("%d-%d: %s\n", RANGE (l), m.c_str());
8555}
8556
8557static bool yydebug;
8558int
8559yyparse ()
8560{
8561  yy::parser parser;
8562  parser.set_debug_level (yydebug);
8563  return parser.parse ();
8564}
8565
8566
8567int
8568main (int argc, const char *argv[])
8569{
8570  int status;
8571  yydebug = !!getenv ("YYDEBUG");
8572  assert (argc == 2);
8573  source = argv[1];
8574  status = yyparse ();
8575  switch (status)
8576    {
8577      case 0: printf ("Successful parse.\n"); break;
8578      case 1: printf ("Parsing FAILED.\n"); break;
8579      default: printf ("Parsing FAILED (status %d).\n", status); break;
8580    }
8581  return status;
8582}
8583_ATEOF
8584
8585
8586
8587$at_traceoff
8588echo "actions.at:534: bison -o input.cc input.y"
8589echo actions.at:534 >$at_check_line_file
8590( $at_traceon; bison -o input.cc input.y ) >$at_stdout 2>$at_stder1
8591at_status=$?
8592grep '^ *+' $at_stder1 >&2
8593grep -v '^ *+' $at_stder1 >$at_stderr
8594at_failed=false
8595$at_diff $at_devnull $at_stderr || at_failed=:
8596$at_diff $at_devnull $at_stdout || at_failed=:
8597case $at_status in
8598   77) echo 77 > $at_status_file
8599            exit 77;;
8600   0) ;;
8601   *) echo "actions.at:534: exit code was $at_status, expected 0"
8602      at_failed=:;;
8603esac
8604if $at_failed; then
8605
8606  echo 1 > $at_status_file
8607  exit 1
8608fi
8609
8610$at_traceon
8611
8612
8613$at_traceoff
8614echo "actions.at:534: \$BISON_CXX_WORKS"
8615echo actions.at:534 >$at_check_line_file
8616( $at_traceon; $BISON_CXX_WORKS ) >$at_stdout 2>$at_stder1
8617at_status=$?
8618grep '^ *+' $at_stder1 >&2
8619grep -v '^ *+' $at_stder1 >$at_stderr
8620at_failed=false
8621echo stderr:; cat $at_stderr
8622echo stdout:; cat $at_stdout
8623case $at_status in
8624   77) echo 77 > $at_status_file
8625            exit 77;;
8626   0) ;;
8627   *) echo "actions.at:534: exit code was $at_status, expected 0"
8628      at_failed=:;;
8629esac
8630if $at_failed; then
8631
8632  echo 1 > $at_status_file
8633  exit 1
8634fi
8635
8636$at_traceon
8637
8638$at_traceoff
8639echo "actions.at:534: \$CXX \$CXXFLAGS \$CPPFLAGS \$LDFLAGS -o input input.cc \$LIBS"
8640echo actions.at:534 >$at_check_line_file
8641( $at_traceon; $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o input input.cc $LIBS ) >$at_stdout 2>$at_stder1
8642at_status=$?
8643grep '^ *+' $at_stder1 >&2
8644grep -v '^ *+' $at_stder1 >$at_stderr
8645at_failed=false
8646echo stderr:; cat $at_stderr
8647echo stdout:; cat $at_stdout
8648case $at_status in
8649   77) echo 77 > $at_status_file
8650            exit 77;;
8651   0) ;;
8652   *) echo "actions.at:534: exit code was $at_status, expected 0"
8653      at_failed=:;;
8654esac
8655if $at_failed; then
8656
8657  echo 1 > $at_status_file
8658  exit 1
8659fi
8660
8661$at_traceon
8662
8663
8664
8665# Check the location of "empty"
8666# -----------------------------
8667# I.e., epsilon-reductions, as in "(x)" which ends by reducing
8668# an empty "line" nterm.
8669# FIXME: This location is not satisfying.  Depend on the lookahead?
8670$at_traceoff
8671echo "actions.at:534: \$PREPARSER ./input '(x)'"
8672echo actions.at:534 >$at_check_line_file
8673( $at_traceon; $PREPARSER ./input '(x)' ) >$at_stdout 2>$at_stder1
8674at_status=$?
8675grep '^ *+' $at_stder1 >&2
8676grep -v '^ *+' $at_stder1 >$at_stderr
8677at_failed=false
8678$at_diff $at_devnull $at_stderr || at_failed=:
8679echo >>$at_stdout; echo "sending: '(' (0@0-9)
8680sending: 'x' (1@10-19)
8681thing (1@10-19): 'x' (1@10-19)
8682sending: ')' (2@20-29)
8683line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
8684sending: EOF (3@30-39)
8685input (0@29-29): /* Nothing */
8686input (2@0-29): line (0@0-29) input (0@29-29)
8687Freeing nterm input (2@0-29)
8688Successful parse.
8689" | $at_diff - $at_stdout || at_failed=:
8690case $at_status in
8691   77) echo 77 > $at_status_file
8692            exit 77;;
8693   0) ;;
8694   *) echo "actions.at:534: exit code was $at_status, expected 0"
8695      at_failed=:;;
8696esac
8697if $at_failed; then
8698
8699  echo 1 > $at_status_file
8700  exit 1
8701fi
8702
8703$at_traceon
8704
8705
8706
8707# Check locations in error recovery
8708# ---------------------------------
8709# '(y)' is an error, but can be recovered from.  But what's the location
8710# of the error itself ('y'), and of the resulting reduction ('(error)').
8711$at_traceoff
8712echo "actions.at:534: \$PREPARSER ./input '(y)'"
8713echo actions.at:534 >$at_check_line_file
8714( $at_traceon; $PREPARSER ./input '(y)' ) >$at_stdout 2>$at_stder1
8715at_status=$?
8716grep '^ *+' $at_stder1 >&2
8717grep -v '^ *+' $at_stder1 >$at_stderr
8718at_failed=false
8719$at_diff $at_devnull $at_stderr || at_failed=:
8720echo >>$at_stdout; echo "sending: '(' (0@0-9)
8721sending: 'y' (1@10-19)
872210-19: syntax error, unexpected 'y', expecting 'x'
8723Freeing token 'y' (1@10-19)
8724sending: ')' (2@20-29)
8725line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
8726sending: EOF (3@30-39)
8727input (0@29-29): /* Nothing */
8728input (2@0-29): line (-1@0-29) input (0@29-29)
8729Freeing nterm input (2@0-29)
8730Successful parse.
8731" | $at_diff - $at_stdout || at_failed=:
8732case $at_status in
8733   77) echo 77 > $at_status_file
8734            exit 77;;
8735   0) ;;
8736   *) echo "actions.at:534: exit code was $at_status, expected 0"
8737      at_failed=:;;
8738esac
8739if $at_failed; then
8740
8741  echo 1 > $at_status_file
8742  exit 1
8743fi
8744
8745$at_traceon
8746
8747
8748
8749# Syntax errors caught by the parser
8750# ----------------------------------
8751# Exercise the discarding of stack top and input until `error'
8752# can be reduced.
8753#
8754#     '(', 'x', 'x', 'x', 'x', 'x', ')',
8755#
8756# Load the stack and provoke an error that cannot be caught by the
8757# grammar, to check that the stack is cleared.  And make sure the
8758# lookahead is freed.
8759#
8760#     '(', 'x', ')',
8761#     '(', 'x', ')',
8762#     'y'
8763$at_traceoff
8764echo "actions.at:534: \$PREPARSER ./input '(xxxxx)(x)(x)y'"
8765echo actions.at:534 >$at_check_line_file
8766( $at_traceon; $PREPARSER ./input '(xxxxx)(x)(x)y' ) >$at_stdout 2>$at_stder1
8767at_status=$?
8768grep '^ *+' $at_stder1 >&2
8769grep -v '^ *+' $at_stder1 >$at_stderr
8770at_failed=false
8771$at_diff $at_devnull $at_stderr || at_failed=:
8772echo >>$at_stdout; echo "sending: '(' (0@0-9)
8773sending: 'x' (1@10-19)
8774thing (1@10-19): 'x' (1@10-19)
8775sending: 'x' (2@20-29)
8776thing (2@20-29): 'x' (2@20-29)
8777sending: 'x' (3@30-39)
877830-39: syntax error, unexpected 'x', expecting ')'
8779Freeing nterm thing (2@20-29)
8780Freeing nterm thing (1@10-19)
8781Freeing token 'x' (3@30-39)
8782sending: 'x' (4@40-49)
8783Freeing token 'x' (4@40-49)
8784sending: 'x' (5@50-59)
8785Freeing token 'x' (5@50-59)
8786sending: ')' (6@60-69)
8787line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69)
8788sending: '(' (7@70-79)
8789sending: 'x' (8@80-89)
8790thing (8@80-89): 'x' (8@80-89)
8791sending: ')' (9@90-99)
8792line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99)
8793sending: '(' (10@100-109)
8794sending: 'x' (11@110-119)
8795thing (11@110-119): 'x' (11@110-119)
8796sending: ')' (12@120-129)
8797line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129)
8798sending: 'y' (13@130-139)
8799input (0@129-129): /* Nothing */
8800input (2@100-129): line (10@100-129) input (0@129-129)
8801input (2@70-129): line (7@70-99) input (2@100-129)
8802input (2@0-129): line (-1@0-69) input (2@70-129)
8803130-139: syntax error, unexpected 'y', expecting \$end
8804Freeing nterm input (2@0-129)
8805Freeing token 'y' (13@130-139)
8806Parsing FAILED.
8807" | $at_diff - $at_stdout || at_failed=:
8808case $at_status in
8809   77) echo 77 > $at_status_file
8810            exit 77;;
8811   1) ;;
8812   *) echo "actions.at:534: exit code was $at_status, expected 1"
8813      at_failed=:;;
8814esac
8815if $at_failed; then
8816
8817  echo 1 > $at_status_file
8818  exit 1
8819fi
8820
8821$at_traceon
8822
8823
8824# Check destruction upon stack overflow
8825# -------------------------------------
8826# Upon stack overflow, all symbols on the stack should be destroyed.
8827# Only check for yacc.c.
8828
8829
8830
8831
8832      $at_traceoff
8833      $at_times_p && times >$at_times_file
8834    ) 5>&1 2>&1 | eval $at_tee_pipe
8835    at_status=`cat $at_status_file`
8836    ;;
8837
8838  56 ) # 56. actions.at:536: Printers and Destructors : %glr-parser
8839    at_setup_line='actions.at:536'
8840    at_desc='Printers and Destructors : %glr-parser'
8841    $at_quiet $ECHO_N " 56: Printers and Destructors : %glr-parser       $ECHO_C"
8842    at_xfail=no
8843    (
8844      echo "56. actions.at:536: testing ..."
8845      $at_traceon
8846
8847
8848
8849# Make sure complex $n work.
8850
8851# Be sure to pass all the %directives to this macro to have correct
8852# helping macros.  So don't put any directly in the Bison file.
8853
8854
8855
8856
8857# Using yacc.c?
8858
8859
8860
8861
8862
8863
8864
8865# yyerror receives the location if %location & %pure & (%glr or %parse-param).
8866
8867# yyerror always sees the locations (when activated), except if
8868# yacc & pure & !param.
8869
8870
8871# The interface is pure: either because %pure-parser, or because we
8872# are using the C++ parsers.
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884cat >input.y <<'_ATEOF'
8885%{
8886#ifdef HAVE_CONFIG_H
8887# include <config.h>
8888  /* We don't need perfect functions for these tests. */
8889# undef malloc
8890# undef memcmp
8891# undef realloc
8892#endif
8893%}
8894
8895%{
8896#include <stdio.h>
8897#include <stdlib.h>
8898#include <assert.h>
8899
8900#define YYINITDEPTH 10
8901#define YYMAXDEPTH 10
8902#define RANGE(Location) (Location).first_line, (Location).last_line
8903%}
8904
8905%error-verbose
8906%debug
8907%verbose
8908%locations
8909%glr-parser
8910
8911
8912
8913%{
8914
8915static int yylex (void);
8916static void yyerror (const char *msg);
8917%}
8918
8919
8920
8921%printer
8922  {
8923    fprintf (yyoutput, "%d", $$);
8924  }
8925  input line thing 'x' 'y'
8926
8927%destructor
8928  { printf ("Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
8929  input
8930
8931%destructor
8932  { printf ("Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
8933  line
8934
8935%destructor
8936  { printf ("Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
8937  thing
8938
8939%destructor
8940  { printf ("Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
8941  'x'
8942
8943%destructor
8944  { printf ("Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
8945  'y'
8946
8947%%
8948/*
8949   This grammar is made to exercise error recovery.
8950   "Lines" starting with `(' support error recovery, with
8951   ')' as synchronizing token.  Lines starting with 'x' can never
8952   be recovered from if in error.
8953*/
8954
8955input:
8956  /* Nothing. */
8957    {
8958      $$ = 0;
8959      printf ("input (%d@%d-%d): /* Nothing */\n", $$, RANGE (@$));
8960    }
8961| line input /* Right recursive to load the stack so that popping at
8962		EOF can	be exercised.  */
8963    {
8964      $$ = 2;
8965      printf ("input (%d@%d-%d): line (%d@%d-%d) input (%d@%d-%d)\n",
8966	      $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2));
8967    }
8968;
8969
8970line:
8971  thing thing thing ';'
8972    {
8973      $$ = $1;
8974      printf ("line (%d@%d-%d): thing (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ';' (%d@%d-%d)\n",
8975              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
8976              $3, RANGE (@3), $4, RANGE (@4));
8977    }
8978| '(' thing thing ')'
8979    {
8980      $$ = $1;
8981      printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
8982              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
8983              $3, RANGE (@3), $4, RANGE (@4));
8984    }
8985| '(' thing ')'
8986    {
8987      $$ = $1;
8988      printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
8989              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2), $3, RANGE (@3));
8990    }
8991| '(' error ')'
8992    {
8993      $$ = -1;
8994      printf ("line (%d@%d-%d): '(' (%d@%d-%d) error (@%d-%d) ')' (%d@%d-%d)\n",
8995              $$, RANGE (@$), $1, RANGE (@1), RANGE (@2), $3, RANGE (@3));
8996    }
8997;
8998
8999thing:
9000  'x'
9001    {
9002      $$ = $1;
9003      printf ("thing (%d@%d-%d): 'x' (%d@%d-%d)\n",
9004              $$, RANGE (@$), $1, RANGE (@1));
9005    }
9006;
9007%%
9008/* Alias to ARGV[1]. */
9009const char *source = 0;
9010
9011static int
9012yylex (void)
9013{
9014  static unsigned int counter = 0;
9015
9016  int c = (yylval) = counter++;
9017  /* As in BASIC, line numbers go from 10 to 10.  */
9018 (yylloc).first_line = (yylloc).first_column = 10 * c;
9019  (yylloc).last_line = (yylloc).last_column = (yylloc).first_line + 9;
9020
9021
9022  if (source[c])
9023    printf ("sending: '%c'", source[c]);
9024  else
9025    printf ("sending: EOF");
9026  printf (" (%d@%d-%d)\n", c, RANGE ((yylloc)));
9027  return source[c];
9028}
9029
9030static void
9031yyerror (const char *msg)
9032{
9033  printf ("%d-%d: %s\n", RANGE (yylloc), msg);
9034}
9035
9036int
9037main (int argc, const char *argv[])
9038{
9039  int status;
9040  yydebug = !!getenv ("YYDEBUG");
9041  assert (argc == 2);
9042  source = argv[1];
9043  status = yyparse ();
9044  switch (status)
9045    {
9046      case 0: printf ("Successful parse.\n"); break;
9047      case 1: printf ("Parsing FAILED.\n"); break;
9048      default: printf ("Parsing FAILED (status %d).\n", status); break;
9049    }
9050  return status;
9051}
9052_ATEOF
9053
9054
9055
9056$at_traceoff
9057echo "actions.at:536: bison -o input.c input.y"
9058echo actions.at:536 >$at_check_line_file
9059( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
9060at_status=$?
9061grep '^ *+' $at_stder1 >&2
9062grep -v '^ *+' $at_stder1 >$at_stderr
9063at_failed=false
9064$at_diff $at_devnull $at_stderr || at_failed=:
9065$at_diff $at_devnull $at_stdout || at_failed=:
9066case $at_status in
9067   77) echo 77 > $at_status_file
9068            exit 77;;
9069   0) ;;
9070   *) echo "actions.at:536: exit code was $at_status, expected 0"
9071      at_failed=:;;
9072esac
9073if $at_failed; then
9074
9075  echo 1 > $at_status_file
9076  exit 1
9077fi
9078
9079$at_traceon
9080
9081   $at_traceoff
9082echo "actions.at:536: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS"
9083echo actions.at:536 >$at_check_line_file
9084( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1
9085at_status=$?
9086grep '^ *+' $at_stder1 >&2
9087grep -v '^ *+' $at_stder1 >$at_stderr
9088at_failed=false
9089echo stderr:; cat $at_stderr
9090echo stdout:; cat $at_stdout
9091case $at_status in
9092   77) echo 77 > $at_status_file
9093            exit 77;;
9094   0) ;;
9095   *) echo "actions.at:536: exit code was $at_status, expected 0"
9096      at_failed=:;;
9097esac
9098if $at_failed; then
9099
9100  echo 1 > $at_status_file
9101  exit 1
9102fi
9103
9104$at_traceon
9105
9106
9107
9108# Check the location of "empty"
9109# -----------------------------
9110# I.e., epsilon-reductions, as in "(x)" which ends by reducing
9111# an empty "line" nterm.
9112# FIXME: This location is not satisfying.  Depend on the lookahead?
9113$at_traceoff
9114echo "actions.at:536: \$PREPARSER ./input '(x)'"
9115echo actions.at:536 >$at_check_line_file
9116( $at_traceon; $PREPARSER ./input '(x)' ) >$at_stdout 2>$at_stder1
9117at_status=$?
9118grep '^ *+' $at_stder1 >&2
9119grep -v '^ *+' $at_stder1 >$at_stderr
9120at_failed=false
9121$at_diff $at_devnull $at_stderr || at_failed=:
9122echo >>$at_stdout; echo "sending: '(' (0@0-9)
9123sending: 'x' (1@10-19)
9124thing (1@10-19): 'x' (1@10-19)
9125sending: ')' (2@20-29)
9126line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
9127sending: EOF (3@30-39)
9128input (0@29-29): /* Nothing */
9129input (2@0-29): line (0@0-29) input (0@29-29)
9130Freeing nterm input (2@0-29)
9131Successful parse.
9132" | $at_diff - $at_stdout || at_failed=:
9133case $at_status in
9134   77) echo 77 > $at_status_file
9135            exit 77;;
9136   0) ;;
9137   *) echo "actions.at:536: exit code was $at_status, expected 0"
9138      at_failed=:;;
9139esac
9140if $at_failed; then
9141
9142  echo 1 > $at_status_file
9143  exit 1
9144fi
9145
9146$at_traceon
9147
9148
9149
9150# Check locations in error recovery
9151# ---------------------------------
9152# '(y)' is an error, but can be recovered from.  But what's the location
9153# of the error itself ('y'), and of the resulting reduction ('(error)').
9154$at_traceoff
9155echo "actions.at:536: \$PREPARSER ./input '(y)'"
9156echo actions.at:536 >$at_check_line_file
9157( $at_traceon; $PREPARSER ./input '(y)' ) >$at_stdout 2>$at_stder1
9158at_status=$?
9159grep '^ *+' $at_stder1 >&2
9160grep -v '^ *+' $at_stder1 >$at_stderr
9161at_failed=false
9162$at_diff $at_devnull $at_stderr || at_failed=:
9163echo >>$at_stdout; echo "sending: '(' (0@0-9)
9164sending: 'y' (1@10-19)
916510-19: syntax error, unexpected 'y', expecting 'x'
9166Freeing token 'y' (1@10-19)
9167sending: ')' (2@20-29)
9168line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
9169sending: EOF (3@30-39)
9170input (0@29-29): /* Nothing */
9171input (2@0-29): line (-1@0-29) input (0@29-29)
9172Freeing nterm input (2@0-29)
9173Successful parse.
9174" | $at_diff - $at_stdout || at_failed=:
9175case $at_status in
9176   77) echo 77 > $at_status_file
9177            exit 77;;
9178   0) ;;
9179   *) echo "actions.at:536: exit code was $at_status, expected 0"
9180      at_failed=:;;
9181esac
9182if $at_failed; then
9183
9184  echo 1 > $at_status_file
9185  exit 1
9186fi
9187
9188$at_traceon
9189
9190
9191
9192# Syntax errors caught by the parser
9193# ----------------------------------
9194# Exercise the discarding of stack top and input until `error'
9195# can be reduced.
9196#
9197#     '(', 'x', 'x', 'x', 'x', 'x', ')',
9198#
9199# Load the stack and provoke an error that cannot be caught by the
9200# grammar, to check that the stack is cleared.  And make sure the
9201# lookahead is freed.
9202#
9203#     '(', 'x', ')',
9204#     '(', 'x', ')',
9205#     'y'
9206$at_traceoff
9207echo "actions.at:536: \$PREPARSER ./input '(xxxxx)(x)(x)y'"
9208echo actions.at:536 >$at_check_line_file
9209( $at_traceon; $PREPARSER ./input '(xxxxx)(x)(x)y' ) >$at_stdout 2>$at_stder1
9210at_status=$?
9211grep '^ *+' $at_stder1 >&2
9212grep -v '^ *+' $at_stder1 >$at_stderr
9213at_failed=false
9214$at_diff $at_devnull $at_stderr || at_failed=:
9215echo >>$at_stdout; echo "sending: '(' (0@0-9)
9216sending: 'x' (1@10-19)
9217thing (1@10-19): 'x' (1@10-19)
9218sending: 'x' (2@20-29)
9219thing (2@20-29): 'x' (2@20-29)
9220sending: 'x' (3@30-39)
922130-39: syntax error, unexpected 'x', expecting ')'
9222Freeing nterm thing (2@20-29)
9223Freeing nterm thing (1@10-19)
9224Freeing token 'x' (3@30-39)
9225sending: 'x' (4@40-49)
9226Freeing token 'x' (4@40-49)
9227sending: 'x' (5@50-59)
9228Freeing token 'x' (5@50-59)
9229sending: ')' (6@60-69)
9230line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69)
9231sending: '(' (7@70-79)
9232sending: 'x' (8@80-89)
9233thing (8@80-89): 'x' (8@80-89)
9234sending: ')' (9@90-99)
9235line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99)
9236sending: '(' (10@100-109)
9237sending: 'x' (11@110-119)
9238thing (11@110-119): 'x' (11@110-119)
9239sending: ')' (12@120-129)
9240line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129)
9241sending: 'y' (13@130-139)
9242input (0@129-129): /* Nothing */
9243input (2@100-129): line (10@100-129) input (0@129-129)
9244input (2@70-129): line (7@70-99) input (2@100-129)
9245input (2@0-129): line (-1@0-69) input (2@70-129)
9246130-139: syntax error, unexpected 'y', expecting \$end
9247Freeing nterm input (2@0-129)
9248Freeing token 'y' (13@130-139)
9249Parsing FAILED.
9250" | $at_diff - $at_stdout || at_failed=:
9251case $at_status in
9252   77) echo 77 > $at_status_file
9253            exit 77;;
9254   1) ;;
9255   *) echo "actions.at:536: exit code was $at_status, expected 1"
9256      at_failed=:;;
9257esac
9258if $at_failed; then
9259
9260  echo 1 > $at_status_file
9261  exit 1
9262fi
9263
9264$at_traceon
9265
9266
9267# Check destruction upon stack overflow
9268# -------------------------------------
9269# Upon stack overflow, all symbols on the stack should be destroyed.
9270# Only check for yacc.c.
9271
9272
9273
9274
9275      $at_traceoff
9276      $at_times_p && times >$at_times_file
9277    ) 5>&1 2>&1 | eval $at_tee_pipe
9278    at_status=`cat $at_status_file`
9279    ;;
9280
9281  57 ) # 57. actions.at:537: Printers and Destructors with union: %glr-parser
9282    at_setup_line='actions.at:537'
9283    at_desc='Printers and Destructors with union: %glr-parser'
9284    $at_quiet $ECHO_N " 57: Printers and Destructors with union: %glr-parser$ECHO_C"
9285    at_xfail=no
9286    (
9287      echo "57. actions.at:537: testing ..."
9288      $at_traceon
9289
9290
9291
9292# Make sure complex $n work.
9293
9294# Be sure to pass all the %directives to this macro to have correct
9295# helping macros.  So don't put any directly in the Bison file.
9296
9297
9298
9299
9300# Using yacc.c?
9301
9302
9303
9304
9305
9306
9307
9308# yyerror receives the location if %location & %pure & (%glr or %parse-param).
9309
9310# yyerror always sees the locations (when activated), except if
9311# yacc & pure & !param.
9312
9313
9314# The interface is pure: either because %pure-parser, or because we
9315# are using the C++ parsers.
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327cat >input.y <<'_ATEOF'
9328%{
9329#ifdef HAVE_CONFIG_H
9330# include <config.h>
9331  /* We don't need perfect functions for these tests. */
9332# undef malloc
9333# undef memcmp
9334# undef realloc
9335#endif
9336%}
9337
9338%{
9339#include <stdio.h>
9340#include <stdlib.h>
9341#include <assert.h>
9342
9343#define YYINITDEPTH 10
9344#define YYMAXDEPTH 10
9345#define RANGE(Location) (Location).first_line, (Location).last_line
9346%}
9347
9348%error-verbose
9349%debug
9350%verbose
9351%locations
9352%glr-parser
9353%union
9354{
9355  int ival;
9356}
9357
9358
9359%{
9360
9361static int yylex (void);
9362static void yyerror (const char *msg);
9363%}
9364
9365%type <ival> '(' 'x' 'y' ')' ';' thing line input
9366
9367%printer
9368  {
9369    fprintf (yyoutput, "%d", $$);
9370  }
9371  input line thing 'x' 'y'
9372
9373%destructor
9374  { printf ("Freeing nterm input (%d@%d-%d)\n", $$, RANGE (@$)); }
9375  input
9376
9377%destructor
9378  { printf ("Freeing nterm line (%d@%d-%d)\n", $$, RANGE (@$)); }
9379  line
9380
9381%destructor
9382  { printf ("Freeing nterm thing (%d@%d-%d)\n", $$, RANGE (@$)); }
9383  thing
9384
9385%destructor
9386  { printf ("Freeing token 'x' (%d@%d-%d)\n", $$, RANGE (@$)); }
9387  'x'
9388
9389%destructor
9390  { printf ("Freeing token 'y' (%d@%d-%d)\n", $$, RANGE (@$)); }
9391  'y'
9392
9393%%
9394/*
9395   This grammar is made to exercise error recovery.
9396   "Lines" starting with `(' support error recovery, with
9397   ')' as synchronizing token.  Lines starting with 'x' can never
9398   be recovered from if in error.
9399*/
9400
9401input:
9402  /* Nothing. */
9403    {
9404      $$ = 0;
9405      printf ("input (%d@%d-%d): /* Nothing */\n", $$, RANGE (@$));
9406    }
9407| line input /* Right recursive to load the stack so that popping at
9408		EOF can	be exercised.  */
9409    {
9410      $$ = 2;
9411      printf ("input (%d@%d-%d): line (%d@%d-%d) input (%d@%d-%d)\n",
9412	      $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2));
9413    }
9414;
9415
9416line:
9417  thing thing thing ';'
9418    {
9419      $$ = $1;
9420      printf ("line (%d@%d-%d): thing (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ';' (%d@%d-%d)\n",
9421              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
9422              $3, RANGE (@3), $4, RANGE (@4));
9423    }
9424| '(' thing thing ')'
9425    {
9426      $$ = $1;
9427      printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
9428              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2),
9429              $3, RANGE (@3), $4, RANGE (@4));
9430    }
9431| '(' thing ')'
9432    {
9433      $$ = $1;
9434      printf ("line (%d@%d-%d): '(' (%d@%d-%d) thing (%d@%d-%d) ')' (%d@%d-%d)\n",
9435              $$, RANGE (@$), $1, RANGE (@1), $2, RANGE (@2), $3, RANGE (@3));
9436    }
9437| '(' error ')'
9438    {
9439      $$ = -1;
9440      printf ("line (%d@%d-%d): '(' (%d@%d-%d) error (@%d-%d) ')' (%d@%d-%d)\n",
9441              $$, RANGE (@$), $1, RANGE (@1), RANGE (@2), $3, RANGE (@3));
9442    }
9443;
9444
9445thing:
9446  'x'
9447    {
9448      $$ = $1;
9449      printf ("thing (%d@%d-%d): 'x' (%d@%d-%d)\n",
9450              $$, RANGE (@$), $1, RANGE (@1));
9451    }
9452;
9453%%
9454/* Alias to ARGV[1]. */
9455const char *source = 0;
9456
9457static int
9458yylex (void)
9459{
9460  static unsigned int counter = 0;
9461
9462  int c = (yylval).ival = counter++;
9463  /* As in BASIC, line numbers go from 10 to 10.  */
9464 (yylloc).first_line = (yylloc).first_column = 10 * c;
9465  (yylloc).last_line = (yylloc).last_column = (yylloc).first_line + 9;
9466
9467
9468  if (source[c])
9469    printf ("sending: '%c'", source[c]);
9470  else
9471    printf ("sending: EOF");
9472  printf (" (%d@%d-%d)\n", c, RANGE ((yylloc)));
9473  return source[c];
9474}
9475
9476static void
9477yyerror (const char *msg)
9478{
9479  printf ("%d-%d: %s\n", RANGE (yylloc), msg);
9480}
9481
9482int
9483main (int argc, const char *argv[])
9484{
9485  int status;
9486  yydebug = !!getenv ("YYDEBUG");
9487  assert (argc == 2);
9488  source = argv[1];
9489  status = yyparse ();
9490  switch (status)
9491    {
9492      case 0: printf ("Successful parse.\n"); break;
9493      case 1: printf ("Parsing FAILED.\n"); break;
9494      default: printf ("Parsing FAILED (status %d).\n", status); break;
9495    }
9496  return status;
9497}
9498_ATEOF
9499
9500
9501
9502$at_traceoff
9503echo "actions.at:537: bison -o input.c input.y"
9504echo actions.at:537 >$at_check_line_file
9505( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
9506at_status=$?
9507grep '^ *+' $at_stder1 >&2
9508grep -v '^ *+' $at_stder1 >$at_stderr
9509at_failed=false
9510$at_diff $at_devnull $at_stderr || at_failed=:
9511$at_diff $at_devnull $at_stdout || at_failed=:
9512case $at_status in
9513   77) echo 77 > $at_status_file
9514            exit 77;;
9515   0) ;;
9516   *) echo "actions.at:537: exit code was $at_status, expected 0"
9517      at_failed=:;;
9518esac
9519if $at_failed; then
9520
9521  echo 1 > $at_status_file
9522  exit 1
9523fi
9524
9525$at_traceon
9526
9527   $at_traceoff
9528echo "actions.at:537: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS"
9529echo actions.at:537 >$at_check_line_file
9530( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1
9531at_status=$?
9532grep '^ *+' $at_stder1 >&2
9533grep -v '^ *+' $at_stder1 >$at_stderr
9534at_failed=false
9535echo stderr:; cat $at_stderr
9536echo stdout:; cat $at_stdout
9537case $at_status in
9538   77) echo 77 > $at_status_file
9539            exit 77;;
9540   0) ;;
9541   *) echo "actions.at:537: exit code was $at_status, expected 0"
9542      at_failed=:;;
9543esac
9544if $at_failed; then
9545
9546  echo 1 > $at_status_file
9547  exit 1
9548fi
9549
9550$at_traceon
9551
9552
9553
9554# Check the location of "empty"
9555# -----------------------------
9556# I.e., epsilon-reductions, as in "(x)" which ends by reducing
9557# an empty "line" nterm.
9558# FIXME: This location is not satisfying.  Depend on the lookahead?
9559$at_traceoff
9560echo "actions.at:537: \$PREPARSER ./input '(x)'"
9561echo actions.at:537 >$at_check_line_file
9562( $at_traceon; $PREPARSER ./input '(x)' ) >$at_stdout 2>$at_stder1
9563at_status=$?
9564grep '^ *+' $at_stder1 >&2
9565grep -v '^ *+' $at_stder1 >$at_stderr
9566at_failed=false
9567$at_diff $at_devnull $at_stderr || at_failed=:
9568echo >>$at_stdout; echo "sending: '(' (0@0-9)
9569sending: 'x' (1@10-19)
9570thing (1@10-19): 'x' (1@10-19)
9571sending: ')' (2@20-29)
9572line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29)
9573sending: EOF (3@30-39)
9574input (0@29-29): /* Nothing */
9575input (2@0-29): line (0@0-29) input (0@29-29)
9576Freeing nterm input (2@0-29)
9577Successful parse.
9578" | $at_diff - $at_stdout || at_failed=:
9579case $at_status in
9580   77) echo 77 > $at_status_file
9581            exit 77;;
9582   0) ;;
9583   *) echo "actions.at:537: exit code was $at_status, expected 0"
9584      at_failed=:;;
9585esac
9586if $at_failed; then
9587
9588  echo 1 > $at_status_file
9589  exit 1
9590fi
9591
9592$at_traceon
9593
9594
9595
9596# Check locations in error recovery
9597# ---------------------------------
9598# '(y)' is an error, but can be recovered from.  But what's the location
9599# of the error itself ('y'), and of the resulting reduction ('(error)').
9600$at_traceoff
9601echo "actions.at:537: \$PREPARSER ./input '(y)'"
9602echo actions.at:537 >$at_check_line_file
9603( $at_traceon; $PREPARSER ./input '(y)' ) >$at_stdout 2>$at_stder1
9604at_status=$?
9605grep '^ *+' $at_stder1 >&2
9606grep -v '^ *+' $at_stder1 >$at_stderr
9607at_failed=false
9608$at_diff $at_devnull $at_stderr || at_failed=:
9609echo >>$at_stdout; echo "sending: '(' (0@0-9)
9610sending: 'y' (1@10-19)
961110-19: syntax error, unexpected 'y', expecting 'x'
9612Freeing token 'y' (1@10-19)
9613sending: ')' (2@20-29)
9614line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29)
9615sending: EOF (3@30-39)
9616input (0@29-29): /* Nothing */
9617input (2@0-29): line (-1@0-29) input (0@29-29)
9618Freeing nterm input (2@0-29)
9619Successful parse.
9620" | $at_diff - $at_stdout || at_failed=:
9621case $at_status in
9622   77) echo 77 > $at_status_file
9623            exit 77;;
9624   0) ;;
9625   *) echo "actions.at:537: exit code was $at_status, expected 0"
9626      at_failed=:;;
9627esac
9628if $at_failed; then
9629
9630  echo 1 > $at_status_file
9631  exit 1
9632fi
9633
9634$at_traceon
9635
9636
9637
9638# Syntax errors caught by the parser
9639# ----------------------------------
9640# Exercise the discarding of stack top and input until `error'
9641# can be reduced.
9642#
9643#     '(', 'x', 'x', 'x', 'x', 'x', ')',
9644#
9645# Load the stack and provoke an error that cannot be caught by the
9646# grammar, to check that the stack is cleared.  And make sure the
9647# lookahead is freed.
9648#
9649#     '(', 'x', ')',
9650#     '(', 'x', ')',
9651#     'y'
9652$at_traceoff
9653echo "actions.at:537: \$PREPARSER ./input '(xxxxx)(x)(x)y'"
9654echo actions.at:537 >$at_check_line_file
9655( $at_traceon; $PREPARSER ./input '(xxxxx)(x)(x)y' ) >$at_stdout 2>$at_stder1
9656at_status=$?
9657grep '^ *+' $at_stder1 >&2
9658grep -v '^ *+' $at_stder1 >$at_stderr
9659at_failed=false
9660$at_diff $at_devnull $at_stderr || at_failed=:
9661echo >>$at_stdout; echo "sending: '(' (0@0-9)
9662sending: 'x' (1@10-19)
9663thing (1@10-19): 'x' (1@10-19)
9664sending: 'x' (2@20-29)
9665thing (2@20-29): 'x' (2@20-29)
9666sending: 'x' (3@30-39)
966730-39: syntax error, unexpected 'x', expecting ')'
9668Freeing nterm thing (2@20-29)
9669Freeing nterm thing (1@10-19)
9670Freeing token 'x' (3@30-39)
9671sending: 'x' (4@40-49)
9672Freeing token 'x' (4@40-49)
9673sending: 'x' (5@50-59)
9674Freeing token 'x' (5@50-59)
9675sending: ')' (6@60-69)
9676line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69)
9677sending: '(' (7@70-79)
9678sending: 'x' (8@80-89)
9679thing (8@80-89): 'x' (8@80-89)
9680sending: ')' (9@90-99)
9681line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99)
9682sending: '(' (10@100-109)
9683sending: 'x' (11@110-119)
9684thing (11@110-119): 'x' (11@110-119)
9685sending: ')' (12@120-129)
9686line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129)
9687sending: 'y' (13@130-139)
9688input (0@129-129): /* Nothing */
9689input (2@100-129): line (10@100-129) input (0@129-129)
9690input (2@70-129): line (7@70-99) input (2@100-129)
9691input (2@0-129): line (-1@0-69) input (2@70-129)
9692130-139: syntax error, unexpected 'y', expecting \$end
9693Freeing nterm input (2@0-129)
9694Freeing token 'y' (13@130-139)
9695Parsing FAILED.
9696" | $at_diff - $at_stdout || at_failed=:
9697case $at_status in
9698   77) echo 77 > $at_status_file
9699            exit 77;;
9700   1) ;;
9701   *) echo "actions.at:537: exit code was $at_status, expected 1"
9702      at_failed=:;;
9703esac
9704if $at_failed; then
9705
9706  echo 1 > $at_status_file
9707  exit 1
9708fi
9709
9710$at_traceon
9711
9712
9713# Check destruction upon stack overflow
9714# -------------------------------------
9715# Upon stack overflow, all symbols on the stack should be destroyed.
9716# Only check for yacc.c.
9717
9718
9719
9720
9721      $at_traceoff
9722      $at_times_p && times >$at_times_file
9723    ) 5>&1 2>&1 | eval $at_tee_pipe
9724    at_status=`cat $at_status_file`
9725    ;;
9726
9727
9728  banner-8 ) # Banner 8. conflicts.at:20
9729    cat <<\_ATEOF
9730
9731Conflicts.
9732
9733_ATEOF
9734    ;;
9735
9736  58 ) # 58. conflicts.at:32: S/R in initial
9737    at_setup_line='conflicts.at:32'
9738    at_desc='S/R in initial'
9739    $at_quiet $ECHO_N " 58: S/R in initial                               $ECHO_C"
9740    at_xfail=no
9741    (
9742      echo "58. conflicts.at:32: testing ..."
9743      $at_traceon
9744
9745
9746cat >input.y <<'_ATEOF'
9747%expect 1
9748%%
9749exp: e 'e';
9750e: 'e' | /* Nothing. */;
9751_ATEOF
9752
9753
9754$at_traceoff
9755echo "conflicts.at:43: bison -o input.c input.y"
9756echo conflicts.at:43 >$at_check_line_file
9757( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
9758at_status=$?
9759grep '^ *+' $at_stder1 >&2
9760grep -v '^ *+' $at_stder1 >$at_stderr
9761at_failed=false
9762echo >>$at_stderr; echo "input.y:4.9: warning: rule never reduced because of conflicts: e: /* empty */
9763" | $at_diff - $at_stderr || at_failed=:
9764$at_diff $at_devnull $at_stdout || at_failed=:
9765case $at_status in
9766   77) echo 77 > $at_status_file
9767            exit 77;;
9768   0) ;;
9769   *) echo "conflicts.at:43: exit code was $at_status, expected 0"
9770      at_failed=:;;
9771esac
9772if $at_failed; then
9773
9774  echo 1 > $at_status_file
9775  exit 1
9776fi
9777
9778$at_traceon
9779
9780
9781      $at_traceoff
9782      $at_times_p && times >$at_times_file
9783    ) 5>&1 2>&1 | eval $at_tee_pipe
9784    at_status=`cat $at_status_file`
9785    ;;
9786
9787  59 ) # 59. conflicts.at:52: %nonassoc and eof
9788    at_setup_line='conflicts.at:52'
9789    at_desc='%nonassoc and eof'
9790    $at_quiet $ECHO_N " 59: %nonassoc and eof                            $ECHO_C"
9791    at_xfail=no
9792    (
9793      echo "59. conflicts.at:52: testing ..."
9794      $at_traceon
9795
9796
9797cat >input.y <<'_ATEOF'
9798%{
9799#ifdef HAVE_CONFIG_H
9800# include <config.h>
9801  /* We don't need perfect functions for these tests. */
9802# undef malloc
9803# undef memcmp
9804# undef realloc
9805#endif
9806%}
9807
9808
9809%{
9810#include <stdio.h>
9811#include <stdlib.h>
9812
9813#define YYERROR_VERBOSE 1
9814static void
9815yyerror (const char *msg)
9816{
9817  fprintf (stderr, "%s\n", msg);
9818}
9819
9820/* The current argument. */
9821static const char *input = NULL;
9822
9823static int
9824yylex (void)
9825{
9826  /* No token stands for end of file. */
9827  if (input && *input)
9828    return *input++;
9829  else
9830    return 0;
9831}
9832
9833%}
9834
9835%nonassoc '<' '>'
9836
9837%%
9838expr: expr '<' expr
9839    | expr '>' expr
9840    | '0'
9841    ;
9842%%
9843int
9844main (int argc, const char *argv[])
9845{
9846  if (argc > 1)
9847    input = argv[1];
9848  return yyparse ();
9849}
9850_ATEOF
9851
9852
9853
9854# Specify the output files to avoid problems on different file systems.
9855$at_traceoff
9856echo "conflicts.at:100: bison -o input.c input.y"
9857echo conflicts.at:100 >$at_check_line_file
9858( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
9859at_status=$?
9860grep '^ *+' $at_stder1 >&2
9861grep -v '^ *+' $at_stder1 >$at_stderr
9862at_failed=false
9863$at_diff $at_devnull $at_stderr || at_failed=:
9864$at_diff $at_devnull $at_stdout || at_failed=:
9865case $at_status in
9866   77) echo 77 > $at_status_file
9867            exit 77;;
9868   0) ;;
9869   *) echo "conflicts.at:100: exit code was $at_status, expected 0"
9870      at_failed=:;;
9871esac
9872if $at_failed; then
9873
9874  echo 1 > $at_status_file
9875  exit 1
9876fi
9877
9878$at_traceon
9879
9880$at_traceoff
9881echo "conflicts.at:101: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS"
9882echo conflicts.at:101 >$at_check_line_file
9883( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1
9884at_status=$?
9885grep '^ *+' $at_stder1 >&2
9886grep -v '^ *+' $at_stder1 >$at_stderr
9887at_failed=false
9888echo stderr:; cat $at_stderr
9889echo stdout:; cat $at_stdout
9890case $at_status in
9891   77) echo 77 > $at_status_file
9892            exit 77;;
9893   0) ;;
9894   *) echo "conflicts.at:101: exit code was $at_status, expected 0"
9895      at_failed=:;;
9896esac
9897if $at_failed; then
9898
9899  echo 1 > $at_status_file
9900  exit 1
9901fi
9902
9903$at_traceon
9904
9905
9906$at_traceoff
9907echo "conflicts.at:103: \$PREPARSER ./input '0<0'"
9908echo conflicts.at:103 >$at_check_line_file
9909( $at_traceon; $PREPARSER ./input '0<0' ) >$at_stdout 2>$at_stder1
9910at_status=$?
9911grep '^ *+' $at_stder1 >&2
9912grep -v '^ *+' $at_stder1 >$at_stderr
9913at_failed=false
9914$at_diff $at_devnull $at_stderr || at_failed=:
9915$at_diff $at_devnull $at_stdout || at_failed=:
9916case $at_status in
9917   77) echo 77 > $at_status_file
9918            exit 77;;
9919   0) ;;
9920   *) echo "conflicts.at:103: exit code was $at_status, expected 0"
9921      at_failed=:;;
9922esac
9923if $at_failed; then
9924
9925  echo 1 > $at_status_file
9926  exit 1
9927fi
9928
9929$at_traceon
9930
9931# FIXME: This is an actual bug, but a new one, in the sense that
9932# no one has ever spotted it!  The messages are *wrong*: there should
9933# be nothing there, it should be expected eof.
9934$at_traceoff
9935echo "conflicts.at:109: \$PREPARSER ./input '0<0<0'"
9936echo conflicts.at:109 >$at_check_line_file
9937( $at_traceon; $PREPARSER ./input '0<0<0' ) >$at_stdout 2>$at_stder1
9938at_status=$?
9939grep '^ *+' $at_stder1 >&2
9940grep -v '^ *+' $at_stder1 >$at_stderr
9941at_failed=false
9942echo >>$at_stderr; echo "syntax error, unexpected '<', expecting '<' or '>'
9943" | $at_diff - $at_stderr || at_failed=:
9944$at_diff $at_devnull $at_stdout || at_failed=:
9945case $at_status in
9946   77) echo 77 > $at_status_file
9947            exit 77;;
9948   1) ;;
9949   *) echo "conflicts.at:109: exit code was $at_status, expected 1"
9950      at_failed=:;;
9951esac
9952if $at_failed; then
9953
9954  echo 1 > $at_status_file
9955  exit 1
9956fi
9957
9958$at_traceon
9959
9960
9961$at_traceoff
9962echo "conflicts.at:111: \$PREPARSER ./input '0>0'"
9963echo conflicts.at:111 >$at_check_line_file
9964( $at_traceon; $PREPARSER ./input '0>0' ) >$at_stdout 2>$at_stder1
9965at_status=$?
9966grep '^ *+' $at_stder1 >&2
9967grep -v '^ *+' $at_stder1 >$at_stderr
9968at_failed=false
9969$at_diff $at_devnull $at_stderr || at_failed=:
9970$at_diff $at_devnull $at_stdout || at_failed=:
9971case $at_status in
9972   77) echo 77 > $at_status_file
9973            exit 77;;
9974   0) ;;
9975   *) echo "conflicts.at:111: exit code was $at_status, expected 0"
9976      at_failed=:;;
9977esac
9978if $at_failed; then
9979
9980  echo 1 > $at_status_file
9981  exit 1
9982fi
9983
9984$at_traceon
9985
9986$at_traceoff
9987echo "conflicts.at:114: \$PREPARSER ./input '0>0>0'"
9988echo conflicts.at:114 >$at_check_line_file
9989( $at_traceon; $PREPARSER ./input '0>0>0' ) >$at_stdout 2>$at_stder1
9990at_status=$?
9991grep '^ *+' $at_stder1 >&2
9992grep -v '^ *+' $at_stder1 >$at_stderr
9993at_failed=false
9994echo >>$at_stderr; echo "syntax error, unexpected '>', expecting '<' or '>'
9995" | $at_diff - $at_stderr || at_failed=:
9996$at_diff $at_devnull $at_stdout || at_failed=:
9997case $at_status in
9998   77) echo 77 > $at_status_file
9999            exit 77;;
10000   1) ;;
10001   *) echo "conflicts.at:114: exit code was $at_status, expected 1"
10002      at_failed=:;;
10003esac
10004if $at_failed; then
10005
10006  echo 1 > $at_status_file
10007  exit 1
10008fi
10009
10010$at_traceon
10011
10012
10013$at_traceoff
10014echo "conflicts.at:118: \$PREPARSER ./input '0<0>0'"
10015echo conflicts.at:118 >$at_check_line_file
10016( $at_traceon; $PREPARSER ./input '0<0>0' ) >$at_stdout 2>$at_stder1
10017at_status=$?
10018grep '^ *+' $at_stder1 >&2
10019grep -v '^ *+' $at_stder1 >$at_stderr
10020at_failed=false
10021echo >>$at_stderr; echo "syntax error, unexpected '>', expecting '<' or '>'
10022" | $at_diff - $at_stderr || at_failed=:
10023$at_diff $at_devnull $at_stdout || at_failed=:
10024case $at_status in
10025   77) echo 77 > $at_status_file
10026            exit 77;;
10027   1) ;;
10028   *) echo "conflicts.at:118: exit code was $at_status, expected 1"
10029      at_failed=:;;
10030esac
10031if $at_failed; then
10032
10033  echo 1 > $at_status_file
10034  exit 1
10035fi
10036
10037$at_traceon
10038
10039
10040      $at_traceoff
10041      $at_times_p && times >$at_times_file
10042    ) 5>&1 2>&1 | eval $at_tee_pipe
10043    at_status=`cat $at_status_file`
10044    ;;
10045
10046  60 ) # 60. conflicts.at:128: Unresolved SR Conflicts
10047    at_setup_line='conflicts.at:128'
10048    at_desc='Unresolved SR Conflicts'
10049    $at_quiet $ECHO_N " 60: Unresolved SR Conflicts                      $ECHO_C"
10050    at_xfail=no
10051    (
10052      echo "60. conflicts.at:128: testing ..."
10053      $at_traceon
10054
10055
10056
10057
10058cat >input.y <<'_ATEOF'
10059%token NUM OP
10060%%
10061exp: exp OP exp | NUM;
10062_ATEOF
10063
10064
10065$at_traceoff
10066echo "conflicts.at:140: bison -o input.c --report=all input.y"
10067echo conflicts.at:140 >$at_check_line_file
10068( $at_traceon; bison -o input.c --report=all input.y ) >$at_stdout 2>$at_stder1
10069at_status=$?
10070grep '^ *+' $at_stder1 >&2
10071grep -v '^ *+' $at_stder1 >$at_stderr
10072at_failed=false
10073echo >>$at_stderr; echo "input.y: conflicts: 1 shift/reduce
10074" | $at_diff - $at_stderr || at_failed=:
10075$at_diff $at_devnull $at_stdout || at_failed=:
10076case $at_status in
10077   77) echo 77 > $at_status_file
10078            exit 77;;
10079   0) ;;
10080   *) echo "conflicts.at:140: exit code was $at_status, expected 0"
10081      at_failed=:;;
10082esac
10083if $at_failed; then
10084
10085  echo 1 > $at_status_file
10086  exit 1
10087fi
10088
10089$at_traceon
10090
10091
10092# Check the contents of the report.
10093$at_traceoff
10094echo "conflicts.at:225: cat input.output"
10095echo conflicts.at:225 >$at_check_line_file
10096( $at_traceon; cat input.output ) >$at_stdout 2>$at_stder1
10097at_status=$?
10098grep '^ *+' $at_stder1 >&2
10099grep -v '^ *+' $at_stder1 >$at_stderr
10100at_failed=false
10101$at_diff $at_devnull $at_stderr || at_failed=:
10102echo >>$at_stdout; echo "State 5 conflicts: 1 shift/reduce
10103
10104
10105Grammar
10106
10107    0 \$accept: exp \$end
10108
10109    1 exp: exp OP exp
10110    2    | NUM
10111
10112
10113Terminals, with rules where they appear
10114
10115\$end (0) 0
10116error (256)
10117NUM (258) 2
10118OP (259) 1
10119
10120
10121Nonterminals, with rules where they appear
10122
10123\$accept (5)
10124    on left: 0
10125exp (6)
10126    on left: 1 2, on right: 0 1
10127
10128
10129state 0
10130
10131    0 \$accept: . exp \$end
10132    1 exp: . exp OP exp
10133    2    | . NUM
10134
10135    NUM  shift, and go to state 1
10136
10137    exp  go to state 2
10138
10139
10140state 1
10141
10142    2 exp: NUM .
10143
10144    \$default  reduce using rule 2 (exp)
10145
10146
10147state 2
10148
10149    0 \$accept: exp . \$end
10150    1 exp: exp . OP exp
10151
10152    \$end  shift, and go to state 3
10153    OP    shift, and go to state 4
10154
10155
10156state 3
10157
10158    0 \$accept: exp \$end .
10159
10160    \$default  accept
10161
10162
10163state 4
10164
10165    1 exp: . exp OP exp
10166    1    | exp OP . exp
10167    2    | . NUM
10168
10169    NUM  shift, and go to state 1
10170
10171    exp  go to state 5
10172
10173
10174state 5
10175
10176    1 exp: exp . OP exp  [\$end, OP]
10177    1    | exp OP exp .  [\$end, OP]
10178
10179    OP  shift, and go to state 4
10180
10181    OP        [reduce using rule 1 (exp)]
10182    \$default  reduce using rule 1 (exp)
10183" | $at_diff - $at_stdout || at_failed=:
10184case $at_status in
10185   77) echo 77 > $at_status_file
10186            exit 77;;
10187   0) ;;
10188   *) echo "conflicts.at:225: exit code was $at_status, expected 0"
10189      at_failed=:;;
10190esac
10191if $at_failed; then
10192
10193  echo 1 > $at_status_file
10194  exit 1
10195fi
10196
10197$at_traceon
10198
10199
10200      $at_traceoff
10201      $at_times_p && times >$at_times_file
10202    ) 5>&1 2>&1 | eval $at_tee_pipe
10203    at_status=`cat $at_status_file`
10204    ;;
10205
10206  61 ) # 61. conflicts.at:235: Resolved SR Conflicts
10207    at_setup_line='conflicts.at:235'
10208    at_desc='Resolved SR Conflicts'
10209    $at_quiet $ECHO_N " 61: Resolved SR Conflicts                        $ECHO_C"
10210    at_xfail=no
10211    (
10212      echo "61. conflicts.at:235: testing ..."
10213      $at_traceon
10214
10215
10216
10217
10218cat >input.y <<'_ATEOF'
10219%token NUM OP
10220%left OP
10221%%
10222exp: exp OP exp | NUM;
10223_ATEOF
10224
10225
10226$at_traceoff
10227echo "conflicts.at:246: bison -o input.c --report=all input.y"
10228echo conflicts.at:246 >$at_check_line_file
10229( $at_traceon; bison -o input.c --report=all input.y ) >$at_stdout 2>$at_stder1
10230at_status=$?
10231grep '^ *+' $at_stder1 >&2
10232grep -v '^ *+' $at_stder1 >$at_stderr
10233at_failed=false
10234$at_diff $at_devnull $at_stderr || at_failed=:
10235$at_diff $at_devnull $at_stdout || at_failed=:
10236case $at_status in
10237   77) echo 77 > $at_status_file
10238            exit 77;;
10239   0) ;;
10240   *) echo "conflicts.at:246: exit code was $at_status, expected 0"
10241      at_failed=:;;
10242esac
10243if $at_failed; then
10244
10245  echo 1 > $at_status_file
10246  exit 1
10247fi
10248
10249$at_traceon
10250
10251
10252# Check the contents of the report.
10253$at_traceoff
10254echo "conflicts.at:327: cat input.output"
10255echo conflicts.at:327 >$at_check_line_file
10256( $at_traceon; cat input.output ) >$at_stdout 2>$at_stder1
10257at_status=$?
10258grep '^ *+' $at_stder1 >&2
10259grep -v '^ *+' $at_stder1 >$at_stderr
10260at_failed=false
10261$at_diff $at_devnull $at_stderr || at_failed=:
10262echo >>$at_stdout; echo "Grammar
10263
10264    0 \$accept: exp \$end
10265
10266    1 exp: exp OP exp
10267    2    | NUM
10268
10269
10270Terminals, with rules where they appear
10271
10272\$end (0) 0
10273error (256)
10274NUM (258) 2
10275OP (259) 1
10276
10277
10278Nonterminals, with rules where they appear
10279
10280\$accept (5)
10281    on left: 0
10282exp (6)
10283    on left: 1 2, on right: 0 1
10284
10285
10286state 0
10287
10288    0 \$accept: . exp \$end
10289    1 exp: . exp OP exp
10290    2    | . NUM
10291
10292    NUM  shift, and go to state 1
10293
10294    exp  go to state 2
10295
10296
10297state 1
10298
10299    2 exp: NUM .
10300
10301    \$default  reduce using rule 2 (exp)
10302
10303
10304state 2
10305
10306    0 \$accept: exp . \$end
10307    1 exp: exp . OP exp
10308
10309    \$end  shift, and go to state 3
10310    OP    shift, and go to state 4
10311
10312
10313state 3
10314
10315    0 \$accept: exp \$end .
10316
10317    \$default  accept
10318
10319
10320state 4
10321
10322    1 exp: . exp OP exp
10323    1    | exp OP . exp
10324    2    | . NUM
10325
10326    NUM  shift, and go to state 1
10327
10328    exp  go to state 5
10329
10330
10331state 5
10332
10333    1 exp: exp . OP exp  [\$end, OP]
10334    1    | exp OP exp .  [\$end, OP]
10335
10336    \$default  reduce using rule 1 (exp)
10337
10338    Conflict between rule 1 and token OP resolved as reduce (%left OP).
10339" | $at_diff - $at_stdout || at_failed=:
10340case $at_status in
10341   77) echo 77 > $at_status_file
10342            exit 77;;
10343   0) ;;
10344   *) echo "conflicts.at:327: exit code was $at_status, expected 0"
10345      at_failed=:;;
10346esac
10347if $at_failed; then
10348
10349  echo 1 > $at_status_file
10350  exit 1
10351fi
10352
10353$at_traceon
10354
10355
10356      $at_traceoff
10357      $at_times_p && times >$at_times_file
10358    ) 5>&1 2>&1 | eval $at_tee_pipe
10359    at_status=`cat $at_status_file`
10360    ;;
10361
10362  62 ) # 62. conflicts.at:357: Defaulted Conflicted Reduction
10363    at_setup_line='conflicts.at:357'
10364    at_desc='Defaulted Conflicted Reduction'
10365    $at_quiet $ECHO_N " 62: Defaulted Conflicted Reduction               $ECHO_C"
10366    at_xfail=no
10367    (
10368      echo "62. conflicts.at:357: testing ..."
10369      $at_traceon
10370
10371
10372
10373cat >input.y <<'_ATEOF'
10374%%
10375exp: num | id;
10376num: '0';
10377id : '0';
10378%%
10379_ATEOF
10380
10381
10382$at_traceoff
10383echo "conflicts.at:371: bison -o input.c --report=all input.y"
10384echo conflicts.at:371 >$at_check_line_file
10385( $at_traceon; bison -o input.c --report=all input.y ) >$at_stdout 2>$at_stder1
10386at_status=$?
10387grep '^ *+' $at_stder1 >&2
10388grep -v '^ *+' $at_stder1 >$at_stderr
10389at_failed=false
10390echo >>$at_stderr; echo "input.y: conflicts: 1 reduce/reduce
10391input.y:4.6-8: warning: rule never reduced because of conflicts: id: '0'
10392" | $at_diff - $at_stderr || at_failed=:
10393$at_diff $at_devnull $at_stdout || at_failed=:
10394case $at_status in
10395   77) echo 77 > $at_status_file
10396            exit 77;;
10397   0) ;;
10398   *) echo "conflicts.at:371: exit code was $at_status, expected 0"
10399      at_failed=:;;
10400esac
10401if $at_failed; then
10402
10403  echo 1 > $at_status_file
10404  exit 1
10405fi
10406
10407$at_traceon
10408
10409
10410# Check the contents of the report.
10411$at_traceoff
10412echo "conflicts.at:465: cat input.output"
10413echo conflicts.at:465 >$at_check_line_file
10414( $at_traceon; cat input.output ) >$at_stdout 2>$at_stder1
10415at_status=$?
10416grep '^ *+' $at_stder1 >&2
10417grep -v '^ *+' $at_stder1 >$at_stderr
10418at_failed=false
10419$at_diff $at_devnull $at_stderr || at_failed=:
10420echo >>$at_stdout; echo "Rules never reduced
10421
10422    4 id: '0'
10423
10424
10425State 1 conflicts: 1 reduce/reduce
10426
10427
10428Grammar
10429
10430    0 \$accept: exp \$end
10431
10432    1 exp: num
10433    2    | id
10434
10435    3 num: '0'
10436
10437    4 id: '0'
10438
10439
10440Terminals, with rules where they appear
10441
10442\$end (0) 0
10443'0' (48) 3 4
10444error (256)
10445
10446
10447Nonterminals, with rules where they appear
10448
10449\$accept (4)
10450    on left: 0
10451exp (5)
10452    on left: 1 2, on right: 0
10453num (6)
10454    on left: 3, on right: 1
10455id (7)
10456    on left: 4, on right: 2
10457
10458
10459state 0
10460
10461    0 \$accept: . exp \$end
10462    1 exp: . num
10463    2    | . id
10464    3 num: . '0'
10465    4 id: . '0'
10466
10467    '0'  shift, and go to state 1
10468
10469    exp  go to state 2
10470    num  go to state 3
10471    id   go to state 4
10472
10473
10474state 1
10475
10476    3 num: '0' .  [\$end]
10477    4 id: '0' .  [\$end]
10478
10479    \$end      reduce using rule 3 (num)
10480    \$end      [reduce using rule 4 (id)]
10481    \$default  reduce using rule 3 (num)
10482
10483
10484state 2
10485
10486    0 \$accept: exp . \$end
10487
10488    \$end  shift, and go to state 5
10489
10490
10491state 3
10492
10493    1 exp: num .
10494
10495    \$default  reduce using rule 1 (exp)
10496
10497
10498state 4
10499
10500    2 exp: id .
10501
10502    \$default  reduce using rule 2 (exp)
10503
10504
10505state 5
10506
10507    0 \$accept: exp \$end .
10508
10509    \$default  accept
10510" | $at_diff - $at_stdout || at_failed=:
10511case $at_status in
10512   77) echo 77 > $at_status_file
10513            exit 77;;
10514   0) ;;
10515   *) echo "conflicts.at:465: exit code was $at_status, expected 0"
10516      at_failed=:;;
10517esac
10518if $at_failed; then
10519
10520  echo 1 > $at_status_file
10521  exit 1
10522fi
10523
10524$at_traceon
10525
10526
10527      $at_traceoff
10528      $at_times_p && times >$at_times_file
10529    ) 5>&1 2>&1 | eval $at_tee_pipe
10530    at_status=`cat $at_status_file`
10531    ;;
10532
10533  63 ) # 63. conflicts.at:476: %expect not enough
10534    at_setup_line='conflicts.at:476'
10535    at_desc='%expect not enough'
10536    $at_quiet $ECHO_N " 63: %expect not enough                           $ECHO_C"
10537    at_xfail=no
10538    (
10539      echo "63. conflicts.at:476: testing ..."
10540      $at_traceon
10541
10542
10543cat >input.y <<'_ATEOF'
10544%token NUM OP
10545%expect 0
10546%%
10547exp: exp OP exp | NUM;
10548_ATEOF
10549
10550
10551$at_traceoff
10552echo "conflicts.at:488: bison -o input.c input.y"
10553echo conflicts.at:488 >$at_check_line_file
10554( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
10555at_status=$?
10556grep '^ *+' $at_stder1 >&2
10557grep -v '^ *+' $at_stder1 >$at_stderr
10558at_failed=false
10559echo >>$at_stderr; echo "input.y: conflicts: 1 shift/reduce
10560input.y: expected 0 shift/reduce conflicts
10561" | $at_diff - $at_stderr || at_failed=:
10562$at_diff $at_devnull $at_stdout || at_failed=:
10563case $at_status in
10564   77) echo 77 > $at_status_file
10565            exit 77;;
10566   1) ;;
10567   *) echo "conflicts.at:488: exit code was $at_status, expected 1"
10568      at_failed=:;;
10569esac
10570if $at_failed; then
10571
10572  echo 1 > $at_status_file
10573  exit 1
10574fi
10575
10576$at_traceon
10577
10578      $at_traceoff
10579      $at_times_p && times >$at_times_file
10580    ) 5>&1 2>&1 | eval $at_tee_pipe
10581    at_status=`cat $at_status_file`
10582    ;;
10583
10584  64 ) # 64. conflicts.at:496: %expect right
10585    at_setup_line='conflicts.at:496'
10586    at_desc='%expect right'
10587    $at_quiet $ECHO_N " 64: %expect right                                $ECHO_C"
10588    at_xfail=no
10589    (
10590      echo "64. conflicts.at:496: testing ..."
10591      $at_traceon
10592
10593
10594cat >input.y <<'_ATEOF'
10595%token NUM OP
10596%expect 1
10597%%
10598exp: exp OP exp | NUM;
10599_ATEOF
10600
10601
10602$at_traceoff
10603echo "conflicts.at:505: bison -o input.c input.y"
10604echo conflicts.at:505 >$at_check_line_file
10605( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
10606at_status=$?
10607grep '^ *+' $at_stder1 >&2
10608grep -v '^ *+' $at_stder1 >$at_stderr
10609at_failed=false
10610$at_diff $at_devnull $at_stderr || at_failed=:
10611$at_diff $at_devnull $at_stdout || at_failed=:
10612case $at_status in
10613   77) echo 77 > $at_status_file
10614            exit 77;;
10615   0) ;;
10616   *) echo "conflicts.at:505: exit code was $at_status, expected 0"
10617      at_failed=:;;
10618esac
10619if $at_failed; then
10620
10621  echo 1 > $at_status_file
10622  exit 1
10623fi
10624
10625$at_traceon
10626
10627      $at_traceoff
10628      $at_times_p && times >$at_times_file
10629    ) 5>&1 2>&1 | eval $at_tee_pipe
10630    at_status=`cat $at_status_file`
10631    ;;
10632
10633  65 ) # 65. conflicts.at:513: %expect too much
10634    at_setup_line='conflicts.at:513'
10635    at_desc='%expect too much'
10636    $at_quiet $ECHO_N " 65: %expect too much                             $ECHO_C"
10637    at_xfail=no
10638    (
10639      echo "65. conflicts.at:513: testing ..."
10640      $at_traceon
10641
10642
10643cat >input.y <<'_ATEOF'
10644%token NUM OP
10645%expect 2
10646%%
10647exp: exp OP exp | NUM;
10648_ATEOF
10649
10650
10651$at_traceoff
10652echo "conflicts.at:525: bison -o input.c input.y"
10653echo conflicts.at:525 >$at_check_line_file
10654( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
10655at_status=$?
10656grep '^ *+' $at_stder1 >&2
10657grep -v '^ *+' $at_stder1 >$at_stderr
10658at_failed=false
10659echo >>$at_stderr; echo "input.y: conflicts: 1 shift/reduce
10660input.y: expected 2 shift/reduce conflicts
10661" | $at_diff - $at_stderr || at_failed=:
10662$at_diff $at_devnull $at_stdout || at_failed=:
10663case $at_status in
10664   77) echo 77 > $at_status_file
10665            exit 77;;
10666   1) ;;
10667   *) echo "conflicts.at:525: exit code was $at_status, expected 1"
10668      at_failed=:;;
10669esac
10670if $at_failed; then
10671
10672  echo 1 > $at_status_file
10673  exit 1
10674fi
10675
10676$at_traceon
10677
10678      $at_traceoff
10679      $at_times_p && times >$at_times_file
10680    ) 5>&1 2>&1 | eval $at_tee_pipe
10681    at_status=`cat $at_status_file`
10682    ;;
10683
10684  66 ) # 66. conflicts.at:533: %expect with reduce conflicts
10685    at_setup_line='conflicts.at:533'
10686    at_desc='%expect with reduce conflicts'
10687    $at_quiet $ECHO_N " 66: %expect with reduce conflicts                $ECHO_C"
10688    at_xfail=no
10689    (
10690      echo "66. conflicts.at:533: testing ..."
10691      $at_traceon
10692
10693
10694cat >input.y <<'_ATEOF'
10695%expect 0
10696%%
10697program: a 'a' | a a;
10698a: 'a';
10699_ATEOF
10700
10701
10702$at_traceoff
10703echo "conflicts.at:545: bison -o input.c input.y"
10704echo conflicts.at:545 >$at_check_line_file
10705( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
10706at_status=$?
10707grep '^ *+' $at_stder1 >&2
10708grep -v '^ *+' $at_stder1 >$at_stderr
10709at_failed=false
10710echo >>$at_stderr; echo "input.y: conflicts: 1 reduce/reduce
10711input.y: expected 0 reduce/reduce conflicts
10712" | $at_diff - $at_stderr || at_failed=:
10713$at_diff $at_devnull $at_stdout || at_failed=:
10714case $at_status in
10715   77) echo 77 > $at_status_file
10716            exit 77;;
10717   1) ;;
10718   *) echo "conflicts.at:545: exit code was $at_status, expected 1"
10719      at_failed=:;;
10720esac
10721if $at_failed; then
10722
10723  echo 1 > $at_status_file
10724  exit 1
10725fi
10726
10727$at_traceon
10728
10729      $at_traceoff
10730      $at_times_p && times >$at_times_file
10731    ) 5>&1 2>&1 | eval $at_tee_pipe
10732    at_status=`cat $at_status_file`
10733    ;;
10734
10735  67 ) # 67. conflicts.at:553: %no-default-prec without %prec
10736    at_setup_line='conflicts.at:553'
10737    at_desc='%no-default-prec without %prec'
10738    $at_quiet $ECHO_N " 67: %no-default-prec without %prec               $ECHO_C"
10739    at_xfail=no
10740    (
10741      echo "67. conflicts.at:553: testing ..."
10742      $at_traceon
10743
10744
10745cat >input.y <<'_ATEOF'
10746%left '+'
10747%left '*'
10748
10749%%
10750
10751%no-default-prec;
10752
10753e:   e '+' e
10754   | e '*' e
10755   | '0'
10756   ;
10757_ATEOF
10758
10759
10760$at_traceoff
10761echo "conflicts.at:571: bison -o input.c input.y"
10762echo conflicts.at:571 >$at_check_line_file
10763( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
10764at_status=$?
10765grep '^ *+' $at_stder1 >&2
10766grep -v '^ *+' $at_stder1 >$at_stderr
10767at_failed=false
10768echo >>$at_stderr; echo "input.y: conflicts: 4 shift/reduce
10769" | $at_diff - $at_stderr || at_failed=:
10770$at_diff $at_devnull $at_stdout || at_failed=:
10771case $at_status in
10772   77) echo 77 > $at_status_file
10773            exit 77;;
10774   0) ;;
10775   *) echo "conflicts.at:571: exit code was $at_status, expected 0"
10776      at_failed=:;;
10777esac
10778if $at_failed; then
10779
10780  echo 1 > $at_status_file
10781  exit 1
10782fi
10783
10784$at_traceon
10785
10786      $at_traceoff
10787      $at_times_p && times >$at_times_file
10788    ) 5>&1 2>&1 | eval $at_tee_pipe
10789    at_status=`cat $at_status_file`
10790    ;;
10791
10792  68 ) # 68. conflicts.at:579: %no-default-prec with %prec
10793    at_setup_line='conflicts.at:579'
10794    at_desc='%no-default-prec with %prec'
10795    $at_quiet $ECHO_N " 68: %no-default-prec with %prec                  $ECHO_C"
10796    at_xfail=no
10797    (
10798      echo "68. conflicts.at:579: testing ..."
10799      $at_traceon
10800
10801
10802cat >input.y <<'_ATEOF'
10803%left '+'
10804%left '*'
10805
10806%%
10807
10808%no-default-prec;
10809
10810e:   e '+' e %prec '+'
10811   | e '*' e %prec '*'
10812   | '0'
10813   ;
10814_ATEOF
10815
10816
10817$at_traceoff
10818echo "conflicts.at:595: bison -o input.c input.y"
10819echo conflicts.at:595 >$at_check_line_file
10820( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
10821at_status=$?
10822grep '^ *+' $at_stder1 >&2
10823grep -v '^ *+' $at_stder1 >$at_stderr
10824at_failed=false
10825$at_diff $at_devnull $at_stderr || at_failed=:
10826$at_diff $at_devnull $at_stdout || at_failed=:
10827case $at_status in
10828   77) echo 77 > $at_status_file
10829            exit 77;;
10830   0) ;;
10831   *) echo "conflicts.at:595: exit code was $at_status, expected 0"
10832      at_failed=:;;
10833esac
10834if $at_failed; then
10835
10836  echo 1 > $at_status_file
10837  exit 1
10838fi
10839
10840$at_traceon
10841
10842      $at_traceoff
10843      $at_times_p && times >$at_times_file
10844    ) 5>&1 2>&1 | eval $at_tee_pipe
10845    at_status=`cat $at_status_file`
10846    ;;
10847
10848  69 ) # 69. conflicts.at:603: %default-prec
10849    at_setup_line='conflicts.at:603'
10850    at_desc='%default-prec'
10851    $at_quiet $ECHO_N " 69: %default-prec                                $ECHO_C"
10852    at_xfail=no
10853    (
10854      echo "69. conflicts.at:603: testing ..."
10855      $at_traceon
10856
10857
10858cat >input.y <<'_ATEOF'
10859%left '+'
10860%left '*'
10861
10862%%
10863
10864%default-prec;
10865
10866e:   e '+' e
10867   | e '*' e
10868   | '0'
10869   ;
10870_ATEOF
10871
10872
10873$at_traceoff
10874echo "conflicts.at:619: bison -o input.c input.y"
10875echo conflicts.at:619 >$at_check_line_file
10876( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
10877at_status=$?
10878grep '^ *+' $at_stder1 >&2
10879grep -v '^ *+' $at_stder1 >$at_stderr
10880at_failed=false
10881$at_diff $at_devnull $at_stderr || at_failed=:
10882$at_diff $at_devnull $at_stdout || at_failed=:
10883case $at_status in
10884   77) echo 77 > $at_status_file
10885            exit 77;;
10886   0) ;;
10887   *) echo "conflicts.at:619: exit code was $at_status, expected 0"
10888      at_failed=:;;
10889esac
10890if $at_failed; then
10891
10892  echo 1 > $at_status_file
10893  exit 1
10894fi
10895
10896$at_traceon
10897
10898      $at_traceoff
10899      $at_times_p && times >$at_times_file
10900    ) 5>&1 2>&1 | eval $at_tee_pipe
10901    at_status=`cat $at_status_file`
10902    ;;
10903
10904
10905  banner-9 ) # Banner 9. calc.at:541
10906    cat <<\_ATEOF
10907
10908Simple LALR(1) Calculator.
10909
10910_ATEOF
10911    ;;
10912
10913  70 ) # 70. calc.at:550: Calculator
10914    at_setup_line='calc.at:550'
10915    at_desc='Calculator '
10916    $at_quiet $ECHO_N " 70: Calculator                                   $ECHO_C"
10917    at_xfail=no
10918    (
10919      echo "70. calc.at:550: testing ..."
10920      $at_traceon
10921
10922
10923
10924
10925
10926
10927
10928
10929# Using yacc.c?
10930
10931
10932
10933
10934
10935
10936
10937# yyerror receives the location if %location & %pure & (%glr or %parse-param).
10938
10939# yyerror always sees the locations (when activated), except if
10940# yacc & pure & !param.
10941
10942
10943# The interface is pure: either because %pure-parser, or because we
10944# are using the C++ parsers.
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957cat >calc.y <<'_ATEOF'
10958%{
10959#ifdef HAVE_CONFIG_H
10960# include <config.h>
10961  /* We don't need perfect functions for these tests. */
10962# undef malloc
10963# undef memcmp
10964# undef realloc
10965#endif
10966%}
10967
10968/* Infix notation calculator--calc */
10969
10970
10971%{
10972#include <stdio.h>
10973
10974#include <stdlib.h>
10975#include <string.h>
10976#if HAVE_UNISTD_H
10977# include <unistd.h>
10978#else
10979# undef alarm
10980# define alarm(seconds) /* empty */
10981#endif
10982#include <ctype.h>
10983#define USE(Var)
10984
10985/* Exercise pre-prologue dependency to %union.  */
10986typedef int semantic_value;
10987
10988static semantic_value global_result = 0;
10989static int global_count = 0;
10990%}
10991
10992/* Exercise %union. */
10993%union
10994{
10995  semantic_value ival;
10996};
10997
10998%{
10999static int power (int base, int exponent);
11000/* yyerror receives the location if:
11001   - %location & %pure & %glr
11002   - %location & %pure & %yacc & %parse-param. */
11003static void yyerror (
11004
11005                     const char *s
11006                     );
11007static int yylex (void);
11008static int get_char (void);
11009static void unget_char ( int c);
11010%}
11011
11012
11013
11014/* Bison Declarations */
11015%token CALC_EOF 0 "end of input"
11016%token <ival> NUM "number"
11017%type  <ival> exp
11018
11019%nonassoc '=' /* comparison	       */
11020%left '-' '+'
11021%left '*' '/'
11022%left NEG     /* negation--unary minus */
11023%right '^'    /* exponentiation        */
11024
11025/* Grammar follows */
11026%%
11027input:
11028  line
11029| input line         {  }
11030;
11031
11032line:
11033  '\n'
11034| exp '\n'           { USE ($1); }
11035;
11036
11037exp:
11038  NUM                { $$ = $1;             }
11039| exp '=' exp
11040  {
11041    if ($1 != $3)
11042      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
11043    $$ = $1;
11044  }
11045| exp '+' exp        { $$ = $1 + $3;        }
11046| exp '-' exp        { $$ = $1 - $3;        }
11047| exp '*' exp        { $$ = $1 * $3;        }
11048| exp '/' exp        { $$ = $1 / $3;        }
11049| '-' exp  %prec NEG { $$ = -$2;            }
11050| exp '^' exp        { $$ = power ($1, $3); }
11051| '(' exp ')'        { $$ = $2;             }
11052| '(' error ')'      { $$ = 1111;           }
11053| '!'                { $$ = 0; YYERROR;     }
11054| '-' error          { $$ = 0; YYERROR;     }
11055;
11056%%
11057/* The input.  */
11058static FILE *input;
11059
11060static void
11061yyerror (
11062
11063         const char *s)
11064{
11065
11066
11067  fprintf (stderr, "%s\n", s);
11068}
11069
11070
11071
11072static int
11073get_char (void)
11074{
11075  int res = getc (input);
11076  ;
11077
11078  return res;
11079}
11080
11081
11082static void
11083unget_char ( int c)
11084{
11085  ;
11086
11087  ungetc (c, input);
11088}
11089
11090static int
11091read_signed_integer (void)
11092{
11093  int c = get_char ();
11094  int sign = 1;
11095  int n = 0;
11096
11097  ;
11098  if (c == '-')
11099    {
11100      c = get_char ();
11101      sign = -1;
11102    }
11103
11104  while (isdigit (c))
11105    {
11106      n = 10 * n + (c - '0');
11107      c = get_char ();
11108    }
11109
11110  unget_char ( c);
11111
11112  return sign * n;
11113}
11114
11115
11116
11117/*---------------------------------------------------------------.
11118| Lexical analyzer returns an integer on the stack and the token |
11119| NUM, or the ASCII character read if not a number.  Skips all   |
11120| blanks and tabs, returns 0 for EOF.                            |
11121`---------------------------------------------------------------*/
11122
11123static int
11124yylex (void)
11125{
11126  static int init = 1;
11127  int c;
11128
11129  if (init)
11130    {
11131      init = 0;
11132
11133    }
11134
11135
11136
11137  /* Skip white space.  */
11138  while ((c = get_char ()) == ' ' || c == '\t')
11139    {
11140
11141    }
11142
11143  /* process numbers   */
11144  if (c == '.' || isdigit (c))
11145    {
11146      unget_char ( c);
11147      (yylval).ival = read_signed_integer ();
11148      return NUM;
11149    }
11150
11151  /* Return end-of-file.  */
11152  if (c == EOF)
11153    return CALC_EOF;
11154
11155  /* Return single chars. */
11156  return c;
11157}
11158
11159static int
11160power (int base, int exponent)
11161{
11162  int res = 1;
11163  if (exponent < 0)
11164    exit (3);
11165  for (/* Niente */; exponent; --exponent)
11166    res *= base;
11167  return res;
11168}
11169
11170
11171int
11172main (int argc, const char **argv)
11173{
11174  semantic_value result = 0;
11175  int count = 0;
11176  int status;
11177
11178  /* This used to be alarm (10), but that isn't enough time for
11179     a July 1995 vintage DEC Alphastation 200 4/100 system,
11180     according to Nelson H. F. Beebe.  100 seconds is enough.  */
11181  alarm (100);
11182
11183  if (argc == 2)
11184    input = fopen (argv[1], "r");
11185  else
11186    input = stdin;
11187
11188  if (!input)
11189    {
11190      perror (argv[1]);
11191      return 3;
11192    }
11193
11194
11195  status = yyparse ();
11196  if (global_result != result)
11197    abort ();
11198  if (global_count != count)
11199    abort ();
11200  return status;
11201}
11202_ATEOF
11203
11204
11205
11206
11207
11208$at_traceoff
11209echo "calc.at:550: bison -o calc.c calc.y"
11210echo calc.at:550 >$at_check_line_file
11211( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
11212at_status=$?
11213grep '^ *+' $at_stder1 >&2
11214grep -v '^ *+' $at_stder1 >$at_stderr
11215at_failed=false
11216$at_diff $at_devnull $at_stderr || at_failed=:
11217$at_diff $at_devnull $at_stdout || at_failed=:
11218case $at_status in
11219   77) echo 77 > $at_status_file
11220            exit 77;;
11221   0) ;;
11222   *) echo "calc.at:550: exit code was $at_status, expected 0"
11223      at_failed=:;;
11224esac
11225if $at_failed; then
11226
11227  echo 1 > $at_status_file
11228  exit 1
11229fi
11230
11231$at_traceon
11232
11233   $at_traceoff
11234echo "calc.at:550: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
11235echo calc.at:550 >$at_check_line_file
11236( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
11237at_status=$?
11238grep '^ *+' $at_stder1 >&2
11239grep -v '^ *+' $at_stder1 >$at_stderr
11240at_failed=false
11241echo stderr:; cat $at_stderr
11242echo stdout:; cat $at_stdout
11243case $at_status in
11244   77) echo 77 > $at_status_file
11245            exit 77;;
11246   0) ;;
11247   *) echo "calc.at:550: exit code was $at_status, expected 0"
11248      at_failed=:;;
11249esac
11250if $at_failed; then
11251
11252  echo 1 > $at_status_file
11253  exit 1
11254fi
11255
11256$at_traceon
11257
11258
11259# Test the priorities.
11260cat >input <<'_ATEOF'
112611 + 2 * 3 = 7
112621 + 2 * -3 = -5
11263
11264-1^2 = -1
11265(-1)^2 = 1
11266
11267---1 = -1
11268
112691 - 2 - 3 = -4
112701 - (2 - 3) = 2
11271
112722^2^3 = 256
11273(2^2)^3 = 64
11274_ATEOF
11275
11276$at_traceoff
11277echo "calc.at:550: \$PREPARSER ./calc input"
11278echo calc.at:550 >$at_check_line_file
11279( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
11280at_status=$?
11281grep '^ *+' $at_stder1 >&2
11282grep -v '^ *+' $at_stder1 >$at_stderr
11283at_failed=false
11284echo stderr:; tee stderr <$at_stderr
11285$at_diff $at_devnull $at_stdout || at_failed=:
11286case $at_status in
11287   77) echo 77 > $at_status_file
11288            exit 77;;
11289   0) ;;
11290   *) echo "calc.at:550: exit code was $at_status, expected 0"
11291      at_failed=:;;
11292esac
11293if $at_failed; then
11294
11295  echo 1 > $at_status_file
11296  exit 1
11297fi
11298
11299$at_traceon
11300
11301
11302
11303# Some syntax errors.
11304cat >input <<'_ATEOF'
113050 0
11306_ATEOF
11307
11308$at_traceoff
11309echo "calc.at:550: \$PREPARSER ./calc input"
11310echo calc.at:550 >$at_check_line_file
11311( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
11312at_status=$?
11313grep '^ *+' $at_stder1 >&2
11314grep -v '^ *+' $at_stder1 >$at_stderr
11315at_failed=false
11316echo stderr:; tee stderr <$at_stderr
11317$at_diff $at_devnull $at_stdout || at_failed=:
11318case $at_status in
11319   77) echo 77 > $at_status_file
11320            exit 77;;
11321   1) ;;
11322   *) echo "calc.at:550: exit code was $at_status, expected 1"
11323      at_failed=:;;
11324esac
11325if $at_failed; then
11326
11327  echo 1 > $at_status_file
11328  exit 1
11329fi
11330
11331$at_traceon
11332
11333
11334# Normalize the observed and expected error messages, depending upon the
11335# options.
11336# 1. Remove the traces from observed.
11337sed '/^Starting/d
11338/^Entering/d
11339/^Stack/d
11340/^Reading/d
11341/^Reducing/d
11342/^Shifting/d
11343/^state/d
11344/^Cleanup:/d
11345/^Error:/d
11346/^Next/d
11347/^Discarding/d
11348/ \$[0-9$]* = /d
11349/^yydestructor:/d' stderr >at-stderr
11350mv at-stderr stderr
11351# 2. Create the reference error message.
11352cat >expout <<'_ATEOF'
113531.2: syntax error, unexpected number
11354_ATEOF
11355
11356# 3. If locations are not used, remove them.
11357sed 's/^[-0-9.]*: //' expout >at-expout
11358mv at-expout expout
11359# 4. If error-verbose is not used, strip the`, unexpected....' part.
11360sed 's/syntax error, .*$/syntax error/' expout >at-expout
11361mv at-expout expout
11362# 5. Check
11363$at_traceoff
11364echo "calc.at:550: cat stderr"
11365echo calc.at:550 >$at_check_line_file
11366( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
11367at_status=$?
11368grep '^ *+' $at_stder1 >&2
11369grep -v '^ *+' $at_stder1 >$at_stderr
11370at_failed=false
11371$at_diff $at_devnull $at_stderr || at_failed=:
11372$at_diff expout $at_stdout || at_failed=:
11373case $at_status in
11374   77) echo 77 > $at_status_file
11375            exit 77;;
11376   0) ;;
11377   *) echo "calc.at:550: exit code was $at_status, expected 0"
11378      at_failed=:;;
11379esac
11380if $at_failed; then
11381
11382  echo 1 > $at_status_file
11383  exit 1
11384fi
11385
11386$at_traceon
11387
11388
11389cat >input <<'_ATEOF'
113901//2
11391_ATEOF
11392
11393$at_traceoff
11394echo "calc.at:550: \$PREPARSER ./calc input"
11395echo calc.at:550 >$at_check_line_file
11396( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
11397at_status=$?
11398grep '^ *+' $at_stder1 >&2
11399grep -v '^ *+' $at_stder1 >$at_stderr
11400at_failed=false
11401echo stderr:; tee stderr <$at_stderr
11402$at_diff $at_devnull $at_stdout || at_failed=:
11403case $at_status in
11404   77) echo 77 > $at_status_file
11405            exit 77;;
11406   1) ;;
11407   *) echo "calc.at:550: exit code was $at_status, expected 1"
11408      at_failed=:;;
11409esac
11410if $at_failed; then
11411
11412  echo 1 > $at_status_file
11413  exit 1
11414fi
11415
11416$at_traceon
11417
11418
11419# Normalize the observed and expected error messages, depending upon the
11420# options.
11421# 1. Remove the traces from observed.
11422sed '/^Starting/d
11423/^Entering/d
11424/^Stack/d
11425/^Reading/d
11426/^Reducing/d
11427/^Shifting/d
11428/^state/d
11429/^Cleanup:/d
11430/^Error:/d
11431/^Next/d
11432/^Discarding/d
11433/ \$[0-9$]* = /d
11434/^yydestructor:/d' stderr >at-stderr
11435mv at-stderr stderr
11436# 2. Create the reference error message.
11437cat >expout <<'_ATEOF'
114381.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
11439_ATEOF
11440
11441# 3. If locations are not used, remove them.
11442sed 's/^[-0-9.]*: //' expout >at-expout
11443mv at-expout expout
11444# 4. If error-verbose is not used, strip the`, unexpected....' part.
11445sed 's/syntax error, .*$/syntax error/' expout >at-expout
11446mv at-expout expout
11447# 5. Check
11448$at_traceoff
11449echo "calc.at:550: cat stderr"
11450echo calc.at:550 >$at_check_line_file
11451( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
11452at_status=$?
11453grep '^ *+' $at_stder1 >&2
11454grep -v '^ *+' $at_stder1 >$at_stderr
11455at_failed=false
11456$at_diff $at_devnull $at_stderr || at_failed=:
11457$at_diff expout $at_stdout || at_failed=:
11458case $at_status in
11459   77) echo 77 > $at_status_file
11460            exit 77;;
11461   0) ;;
11462   *) echo "calc.at:550: exit code was $at_status, expected 0"
11463      at_failed=:;;
11464esac
11465if $at_failed; then
11466
11467  echo 1 > $at_status_file
11468  exit 1
11469fi
11470
11471$at_traceon
11472
11473
11474cat >input <<'_ATEOF'
11475error
11476_ATEOF
11477
11478$at_traceoff
11479echo "calc.at:550: \$PREPARSER ./calc input"
11480echo calc.at:550 >$at_check_line_file
11481( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
11482at_status=$?
11483grep '^ *+' $at_stder1 >&2
11484grep -v '^ *+' $at_stder1 >$at_stderr
11485at_failed=false
11486echo stderr:; tee stderr <$at_stderr
11487$at_diff $at_devnull $at_stdout || at_failed=:
11488case $at_status in
11489   77) echo 77 > $at_status_file
11490            exit 77;;
11491   1) ;;
11492   *) echo "calc.at:550: exit code was $at_status, expected 1"
11493      at_failed=:;;
11494esac
11495if $at_failed; then
11496
11497  echo 1 > $at_status_file
11498  exit 1
11499fi
11500
11501$at_traceon
11502
11503
11504# Normalize the observed and expected error messages, depending upon the
11505# options.
11506# 1. Remove the traces from observed.
11507sed '/^Starting/d
11508/^Entering/d
11509/^Stack/d
11510/^Reading/d
11511/^Reducing/d
11512/^Shifting/d
11513/^state/d
11514/^Cleanup:/d
11515/^Error:/d
11516/^Next/d
11517/^Discarding/d
11518/ \$[0-9$]* = /d
11519/^yydestructor:/d' stderr >at-stderr
11520mv at-stderr stderr
11521# 2. Create the reference error message.
11522cat >expout <<'_ATEOF'
115231.0: syntax error, unexpected $undefined
11524_ATEOF
11525
11526# 3. If locations are not used, remove them.
11527sed 's/^[-0-9.]*: //' expout >at-expout
11528mv at-expout expout
11529# 4. If error-verbose is not used, strip the`, unexpected....' part.
11530sed 's/syntax error, .*$/syntax error/' expout >at-expout
11531mv at-expout expout
11532# 5. Check
11533$at_traceoff
11534echo "calc.at:550: cat stderr"
11535echo calc.at:550 >$at_check_line_file
11536( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
11537at_status=$?
11538grep '^ *+' $at_stder1 >&2
11539grep -v '^ *+' $at_stder1 >$at_stderr
11540at_failed=false
11541$at_diff $at_devnull $at_stderr || at_failed=:
11542$at_diff expout $at_stdout || at_failed=:
11543case $at_status in
11544   77) echo 77 > $at_status_file
11545            exit 77;;
11546   0) ;;
11547   *) echo "calc.at:550: exit code was $at_status, expected 0"
11548      at_failed=:;;
11549esac
11550if $at_failed; then
11551
11552  echo 1 > $at_status_file
11553  exit 1
11554fi
11555
11556$at_traceon
11557
11558
11559cat >input <<'_ATEOF'
115601 = 2 = 3
11561_ATEOF
11562
11563$at_traceoff
11564echo "calc.at:550: \$PREPARSER ./calc input"
11565echo calc.at:550 >$at_check_line_file
11566( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
11567at_status=$?
11568grep '^ *+' $at_stder1 >&2
11569grep -v '^ *+' $at_stder1 >$at_stderr
11570at_failed=false
11571echo stderr:; tee stderr <$at_stderr
11572$at_diff $at_devnull $at_stdout || at_failed=:
11573case $at_status in
11574   77) echo 77 > $at_status_file
11575            exit 77;;
11576   1) ;;
11577   *) echo "calc.at:550: exit code was $at_status, expected 1"
11578      at_failed=:;;
11579esac
11580if $at_failed; then
11581
11582  echo 1 > $at_status_file
11583  exit 1
11584fi
11585
11586$at_traceon
11587
11588
11589# Normalize the observed and expected error messages, depending upon the
11590# options.
11591# 1. Remove the traces from observed.
11592sed '/^Starting/d
11593/^Entering/d
11594/^Stack/d
11595/^Reading/d
11596/^Reducing/d
11597/^Shifting/d
11598/^state/d
11599/^Cleanup:/d
11600/^Error:/d
11601/^Next/d
11602/^Discarding/d
11603/ \$[0-9$]* = /d
11604/^yydestructor:/d' stderr >at-stderr
11605mv at-stderr stderr
11606# 2. Create the reference error message.
11607cat >expout <<'_ATEOF'
116081.6: syntax error, unexpected '='
11609_ATEOF
11610
11611# 3. If locations are not used, remove them.
11612sed 's/^[-0-9.]*: //' expout >at-expout
11613mv at-expout expout
11614# 4. If error-verbose is not used, strip the`, unexpected....' part.
11615sed 's/syntax error, .*$/syntax error/' expout >at-expout
11616mv at-expout expout
11617# 5. Check
11618$at_traceoff
11619echo "calc.at:550: cat stderr"
11620echo calc.at:550 >$at_check_line_file
11621( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
11622at_status=$?
11623grep '^ *+' $at_stder1 >&2
11624grep -v '^ *+' $at_stder1 >$at_stderr
11625at_failed=false
11626$at_diff $at_devnull $at_stderr || at_failed=:
11627$at_diff expout $at_stdout || at_failed=:
11628case $at_status in
11629   77) echo 77 > $at_status_file
11630            exit 77;;
11631   0) ;;
11632   *) echo "calc.at:550: exit code was $at_status, expected 0"
11633      at_failed=:;;
11634esac
11635if $at_failed; then
11636
11637  echo 1 > $at_status_file
11638  exit 1
11639fi
11640
11641$at_traceon
11642
11643
11644cat >input <<'_ATEOF'
11645
11646+1
11647_ATEOF
11648
11649$at_traceoff
11650echo "calc.at:550: \$PREPARSER ./calc input"
11651echo calc.at:550 >$at_check_line_file
11652( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
11653at_status=$?
11654grep '^ *+' $at_stder1 >&2
11655grep -v '^ *+' $at_stder1 >$at_stderr
11656at_failed=false
11657echo stderr:; tee stderr <$at_stderr
11658$at_diff $at_devnull $at_stdout || at_failed=:
11659case $at_status in
11660   77) echo 77 > $at_status_file
11661            exit 77;;
11662   1) ;;
11663   *) echo "calc.at:550: exit code was $at_status, expected 1"
11664      at_failed=:;;
11665esac
11666if $at_failed; then
11667
11668  echo 1 > $at_status_file
11669  exit 1
11670fi
11671
11672$at_traceon
11673
11674
11675# Normalize the observed and expected error messages, depending upon the
11676# options.
11677# 1. Remove the traces from observed.
11678sed '/^Starting/d
11679/^Entering/d
11680/^Stack/d
11681/^Reading/d
11682/^Reducing/d
11683/^Shifting/d
11684/^state/d
11685/^Cleanup:/d
11686/^Error:/d
11687/^Next/d
11688/^Discarding/d
11689/ \$[0-9$]* = /d
11690/^yydestructor:/d' stderr >at-stderr
11691mv at-stderr stderr
11692# 2. Create the reference error message.
11693cat >expout <<'_ATEOF'
116942.0: syntax error, unexpected '+'
11695_ATEOF
11696
11697# 3. If locations are not used, remove them.
11698sed 's/^[-0-9.]*: //' expout >at-expout
11699mv at-expout expout
11700# 4. If error-verbose is not used, strip the`, unexpected....' part.
11701sed 's/syntax error, .*$/syntax error/' expout >at-expout
11702mv at-expout expout
11703# 5. Check
11704$at_traceoff
11705echo "calc.at:550: cat stderr"
11706echo calc.at:550 >$at_check_line_file
11707( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
11708at_status=$?
11709grep '^ *+' $at_stder1 >&2
11710grep -v '^ *+' $at_stder1 >$at_stderr
11711at_failed=false
11712$at_diff $at_devnull $at_stderr || at_failed=:
11713$at_diff expout $at_stdout || at_failed=:
11714case $at_status in
11715   77) echo 77 > $at_status_file
11716            exit 77;;
11717   0) ;;
11718   *) echo "calc.at:550: exit code was $at_status, expected 0"
11719      at_failed=:;;
11720esac
11721if $at_failed; then
11722
11723  echo 1 > $at_status_file
11724  exit 1
11725fi
11726
11727$at_traceon
11728
11729
11730# Exercise error messages with EOF: work on an empty file.
11731$at_traceoff
11732echo "calc.at:550: \$PREPARSER ./calc /dev/null"
11733echo calc.at:550 >$at_check_line_file
11734( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
11735at_status=$?
11736grep '^ *+' $at_stder1 >&2
11737grep -v '^ *+' $at_stder1 >$at_stderr
11738at_failed=false
11739echo stderr:; tee stderr <$at_stderr
11740$at_diff $at_devnull $at_stdout || at_failed=:
11741case $at_status in
11742   77) echo 77 > $at_status_file
11743            exit 77;;
11744   1) ;;
11745   *) echo "calc.at:550: exit code was $at_status, expected 1"
11746      at_failed=:;;
11747esac
11748if $at_failed; then
11749
11750  echo 1 > $at_status_file
11751  exit 1
11752fi
11753
11754$at_traceon
11755
11756
11757# Normalize the observed and expected error messages, depending upon the
11758# options.
11759# 1. Remove the traces from observed.
11760sed '/^Starting/d
11761/^Entering/d
11762/^Stack/d
11763/^Reading/d
11764/^Reducing/d
11765/^Shifting/d
11766/^state/d
11767/^Cleanup:/d
11768/^Error:/d
11769/^Next/d
11770/^Discarding/d
11771/ \$[0-9$]* = /d
11772/^yydestructor:/d' stderr >at-stderr
11773mv at-stderr stderr
11774# 2. Create the reference error message.
11775cat >expout <<'_ATEOF'
117761.0: syntax error, unexpected end of input
11777_ATEOF
11778
11779# 3. If locations are not used, remove them.
11780sed 's/^[-0-9.]*: //' expout >at-expout
11781mv at-expout expout
11782# 4. If error-verbose is not used, strip the`, unexpected....' part.
11783sed 's/syntax error, .*$/syntax error/' expout >at-expout
11784mv at-expout expout
11785# 5. Check
11786$at_traceoff
11787echo "calc.at:550: cat stderr"
11788echo calc.at:550 >$at_check_line_file
11789( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
11790at_status=$?
11791grep '^ *+' $at_stder1 >&2
11792grep -v '^ *+' $at_stder1 >$at_stderr
11793at_failed=false
11794$at_diff $at_devnull $at_stderr || at_failed=:
11795$at_diff expout $at_stdout || at_failed=:
11796case $at_status in
11797   77) echo 77 > $at_status_file
11798            exit 77;;
11799   0) ;;
11800   *) echo "calc.at:550: exit code was $at_status, expected 0"
11801      at_failed=:;;
11802esac
11803if $at_failed; then
11804
11805  echo 1 > $at_status_file
11806  exit 1
11807fi
11808
11809$at_traceon
11810
11811
11812
11813# Exercise the error token: without it, we die at the first error,
11814# hence be sure to
11815#
11816# - have several errors which exercise different shift/discardings
11817#   - (): nothing to pop, nothing to discard
11818#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
11819#   - (* * *): nothing to pop, a lot to discard
11820#   - (1 + 2 * *): some to pop and discard
11821#
11822# - test the action associated to `error'
11823#
11824# - check the look-ahead that triggers an error is not discarded
11825#   when we enter error recovery.  Below, the look-ahead causing the
11826#   first error is ")", which is needed to recover from the error and
11827#   produce the "0" that triggers the "0 != 1" error.
11828#
11829cat >input <<'_ATEOF'
11830() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
11831_ATEOF
11832
11833$at_traceoff
11834echo "calc.at:550: \$PREPARSER ./calc input"
11835echo calc.at:550 >$at_check_line_file
11836( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
11837at_status=$?
11838grep '^ *+' $at_stder1 >&2
11839grep -v '^ *+' $at_stder1 >$at_stderr
11840at_failed=false
11841echo stderr:; tee stderr <$at_stderr
11842$at_diff $at_devnull $at_stdout || at_failed=:
11843case $at_status in
11844   77) echo 77 > $at_status_file
11845            exit 77;;
11846   0) ;;
11847   *) echo "calc.at:550: exit code was $at_status, expected 0"
11848      at_failed=:;;
11849esac
11850if $at_failed; then
11851
11852  echo 1 > $at_status_file
11853  exit 1
11854fi
11855
11856$at_traceon
11857
11858
11859# Normalize the observed and expected error messages, depending upon the
11860# options.
11861# 1. Remove the traces from observed.
11862sed '/^Starting/d
11863/^Entering/d
11864/^Stack/d
11865/^Reading/d
11866/^Reducing/d
11867/^Shifting/d
11868/^state/d
11869/^Cleanup:/d
11870/^Error:/d
11871/^Next/d
11872/^Discarding/d
11873/ \$[0-9$]* = /d
11874/^yydestructor:/d' stderr >at-stderr
11875mv at-stderr stderr
11876# 2. Create the reference error message.
11877cat >expout <<'_ATEOF'
118781.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
118791.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
118801.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
118811.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
11882calc: error: 4444 != 1
11883_ATEOF
11884
11885# 3. If locations are not used, remove them.
11886sed 's/^[-0-9.]*: //' expout >at-expout
11887mv at-expout expout
11888# 4. If error-verbose is not used, strip the`, unexpected....' part.
11889sed 's/syntax error, .*$/syntax error/' expout >at-expout
11890mv at-expout expout
11891# 5. Check
11892$at_traceoff
11893echo "calc.at:550: cat stderr"
11894echo calc.at:550 >$at_check_line_file
11895( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
11896at_status=$?
11897grep '^ *+' $at_stder1 >&2
11898grep -v '^ *+' $at_stder1 >$at_stderr
11899at_failed=false
11900$at_diff $at_devnull $at_stderr || at_failed=:
11901$at_diff expout $at_stdout || at_failed=:
11902case $at_status in
11903   77) echo 77 > $at_status_file
11904            exit 77;;
11905   0) ;;
11906   *) echo "calc.at:550: exit code was $at_status, expected 0"
11907      at_failed=:;;
11908esac
11909if $at_failed; then
11910
11911  echo 1 > $at_status_file
11912  exit 1
11913fi
11914
11915$at_traceon
11916
11917
11918
11919# The same, but this time exercising explicitly triggered syntax errors.
11920# POSIX says the look-ahead causing the error should not be discarded.
11921cat >input <<'_ATEOF'
11922(!) + (0 0) = 1
11923_ATEOF
11924
11925$at_traceoff
11926echo "calc.at:550: \$PREPARSER ./calc input"
11927echo calc.at:550 >$at_check_line_file
11928( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
11929at_status=$?
11930grep '^ *+' $at_stder1 >&2
11931grep -v '^ *+' $at_stder1 >$at_stderr
11932at_failed=false
11933echo stderr:; tee stderr <$at_stderr
11934$at_diff $at_devnull $at_stdout || at_failed=:
11935case $at_status in
11936   77) echo 77 > $at_status_file
11937            exit 77;;
11938   0) ;;
11939   *) echo "calc.at:550: exit code was $at_status, expected 0"
11940      at_failed=:;;
11941esac
11942if $at_failed; then
11943
11944  echo 1 > $at_status_file
11945  exit 1
11946fi
11947
11948$at_traceon
11949
11950
11951# Normalize the observed and expected error messages, depending upon the
11952# options.
11953# 1. Remove the traces from observed.
11954sed '/^Starting/d
11955/^Entering/d
11956/^Stack/d
11957/^Reading/d
11958/^Reducing/d
11959/^Shifting/d
11960/^state/d
11961/^Cleanup:/d
11962/^Error:/d
11963/^Next/d
11964/^Discarding/d
11965/ \$[0-9$]* = /d
11966/^yydestructor:/d' stderr >at-stderr
11967mv at-stderr stderr
11968# 2. Create the reference error message.
11969cat >expout <<'_ATEOF'
119701.9: syntax error, unexpected number
11971calc: error: 2222 != 1
11972_ATEOF
11973
11974# 3. If locations are not used, remove them.
11975sed 's/^[-0-9.]*: //' expout >at-expout
11976mv at-expout expout
11977# 4. If error-verbose is not used, strip the`, unexpected....' part.
11978sed 's/syntax error, .*$/syntax error/' expout >at-expout
11979mv at-expout expout
11980# 5. Check
11981$at_traceoff
11982echo "calc.at:550: cat stderr"
11983echo calc.at:550 >$at_check_line_file
11984( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
11985at_status=$?
11986grep '^ *+' $at_stder1 >&2
11987grep -v '^ *+' $at_stder1 >$at_stderr
11988at_failed=false
11989$at_diff $at_devnull $at_stderr || at_failed=:
11990$at_diff expout $at_stdout || at_failed=:
11991case $at_status in
11992   77) echo 77 > $at_status_file
11993            exit 77;;
11994   0) ;;
11995   *) echo "calc.at:550: exit code was $at_status, expected 0"
11996      at_failed=:;;
11997esac
11998if $at_failed; then
11999
12000  echo 1 > $at_status_file
12001  exit 1
12002fi
12003
12004$at_traceon
12005
12006
12007cat >input <<'_ATEOF'
12008(- *) + (0 0) = 1
12009_ATEOF
12010
12011$at_traceoff
12012echo "calc.at:550: \$PREPARSER ./calc input"
12013echo calc.at:550 >$at_check_line_file
12014( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
12015at_status=$?
12016grep '^ *+' $at_stder1 >&2
12017grep -v '^ *+' $at_stder1 >$at_stderr
12018at_failed=false
12019echo stderr:; tee stderr <$at_stderr
12020$at_diff $at_devnull $at_stdout || at_failed=:
12021case $at_status in
12022   77) echo 77 > $at_status_file
12023            exit 77;;
12024   0) ;;
12025   *) echo "calc.at:550: exit code was $at_status, expected 0"
12026      at_failed=:;;
12027esac
12028if $at_failed; then
12029
12030  echo 1 > $at_status_file
12031  exit 1
12032fi
12033
12034$at_traceon
12035
12036
12037# Normalize the observed and expected error messages, depending upon the
12038# options.
12039# 1. Remove the traces from observed.
12040sed '/^Starting/d
12041/^Entering/d
12042/^Stack/d
12043/^Reading/d
12044/^Reducing/d
12045/^Shifting/d
12046/^state/d
12047/^Cleanup:/d
12048/^Error:/d
12049/^Next/d
12050/^Discarding/d
12051/ \$[0-9$]* = /d
12052/^yydestructor:/d' stderr >at-stderr
12053mv at-stderr stderr
12054# 2. Create the reference error message.
12055cat >expout <<'_ATEOF'
120561.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
120571.11: syntax error, unexpected number
12058calc: error: 2222 != 1
12059_ATEOF
12060
12061# 3. If locations are not used, remove them.
12062sed 's/^[-0-9.]*: //' expout >at-expout
12063mv at-expout expout
12064# 4. If error-verbose is not used, strip the`, unexpected....' part.
12065sed 's/syntax error, .*$/syntax error/' expout >at-expout
12066mv at-expout expout
12067# 5. Check
12068$at_traceoff
12069echo "calc.at:550: cat stderr"
12070echo calc.at:550 >$at_check_line_file
12071( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
12072at_status=$?
12073grep '^ *+' $at_stder1 >&2
12074grep -v '^ *+' $at_stder1 >$at_stderr
12075at_failed=false
12076$at_diff $at_devnull $at_stderr || at_failed=:
12077$at_diff expout $at_stdout || at_failed=:
12078case $at_status in
12079   77) echo 77 > $at_status_file
12080            exit 77;;
12081   0) ;;
12082   *) echo "calc.at:550: exit code was $at_status, expected 0"
12083      at_failed=:;;
12084esac
12085if $at_failed; then
12086
12087  echo 1 > $at_status_file
12088  exit 1
12089fi
12090
12091$at_traceon
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116      $at_traceoff
12117      $at_times_p && times >$at_times_file
12118    ) 5>&1 2>&1 | eval $at_tee_pipe
12119    at_status=`cat $at_status_file`
12120    ;;
12121
12122  71 ) # 71. calc.at:552: Calculator %defines
12123    at_setup_line='calc.at:552'
12124    at_desc='Calculator %defines'
12125    $at_quiet $ECHO_N " 71: Calculator %defines                          $ECHO_C"
12126    at_xfail=no
12127    (
12128      echo "71. calc.at:552: testing ..."
12129      $at_traceon
12130
12131
12132
12133
12134
12135
12136
12137
12138# Using yacc.c?
12139
12140
12141
12142
12143
12144
12145
12146# yyerror receives the location if %location & %pure & (%glr or %parse-param).
12147
12148# yyerror always sees the locations (when activated), except if
12149# yacc & pure & !param.
12150
12151
12152# The interface is pure: either because %pure-parser, or because we
12153# are using the C++ parsers.
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166cat >calc.y <<'_ATEOF'
12167%{
12168#ifdef HAVE_CONFIG_H
12169# include <config.h>
12170  /* We don't need perfect functions for these tests. */
12171# undef malloc
12172# undef memcmp
12173# undef realloc
12174#endif
12175%}
12176
12177/* Infix notation calculator--calc */
12178%defines
12179
12180%{
12181#include <stdio.h>
12182
12183#include <stdlib.h>
12184#include <string.h>
12185#if HAVE_UNISTD_H
12186# include <unistd.h>
12187#else
12188# undef alarm
12189# define alarm(seconds) /* empty */
12190#endif
12191#include <ctype.h>
12192#define USE(Var)
12193
12194/* Exercise pre-prologue dependency to %union.  */
12195typedef int semantic_value;
12196
12197static semantic_value global_result = 0;
12198static int global_count = 0;
12199%}
12200
12201/* Exercise %union. */
12202%union
12203{
12204  semantic_value ival;
12205};
12206
12207%{
12208static int power (int base, int exponent);
12209/* yyerror receives the location if:
12210   - %location & %pure & %glr
12211   - %location & %pure & %yacc & %parse-param. */
12212static void yyerror (
12213
12214                     const char *s
12215                     );
12216static int yylex (void);
12217static int get_char (void);
12218static void unget_char ( int c);
12219%}
12220
12221
12222
12223/* Bison Declarations */
12224%token CALC_EOF 0 "end of input"
12225%token <ival> NUM "number"
12226%type  <ival> exp
12227
12228%nonassoc '=' /* comparison	       */
12229%left '-' '+'
12230%left '*' '/'
12231%left NEG     /* negation--unary minus */
12232%right '^'    /* exponentiation        */
12233
12234/* Grammar follows */
12235%%
12236input:
12237  line
12238| input line         {  }
12239;
12240
12241line:
12242  '\n'
12243| exp '\n'           { USE ($1); }
12244;
12245
12246exp:
12247  NUM                { $$ = $1;             }
12248| exp '=' exp
12249  {
12250    if ($1 != $3)
12251      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
12252    $$ = $1;
12253  }
12254| exp '+' exp        { $$ = $1 + $3;        }
12255| exp '-' exp        { $$ = $1 - $3;        }
12256| exp '*' exp        { $$ = $1 * $3;        }
12257| exp '/' exp        { $$ = $1 / $3;        }
12258| '-' exp  %prec NEG { $$ = -$2;            }
12259| exp '^' exp        { $$ = power ($1, $3); }
12260| '(' exp ')'        { $$ = $2;             }
12261| '(' error ')'      { $$ = 1111;           }
12262| '!'                { $$ = 0; YYERROR;     }
12263| '-' error          { $$ = 0; YYERROR;     }
12264;
12265%%
12266/* The input.  */
12267static FILE *input;
12268
12269static void
12270yyerror (
12271
12272         const char *s)
12273{
12274
12275
12276  fprintf (stderr, "%s\n", s);
12277}
12278
12279
12280
12281static int
12282get_char (void)
12283{
12284  int res = getc (input);
12285  ;
12286
12287  return res;
12288}
12289
12290
12291static void
12292unget_char ( int c)
12293{
12294  ;
12295
12296  ungetc (c, input);
12297}
12298
12299static int
12300read_signed_integer (void)
12301{
12302  int c = get_char ();
12303  int sign = 1;
12304  int n = 0;
12305
12306  ;
12307  if (c == '-')
12308    {
12309      c = get_char ();
12310      sign = -1;
12311    }
12312
12313  while (isdigit (c))
12314    {
12315      n = 10 * n + (c - '0');
12316      c = get_char ();
12317    }
12318
12319  unget_char ( c);
12320
12321  return sign * n;
12322}
12323
12324
12325
12326/*---------------------------------------------------------------.
12327| Lexical analyzer returns an integer on the stack and the token |
12328| NUM, or the ASCII character read if not a number.  Skips all   |
12329| blanks and tabs, returns 0 for EOF.                            |
12330`---------------------------------------------------------------*/
12331
12332static int
12333yylex (void)
12334{
12335  static int init = 1;
12336  int c;
12337
12338  if (init)
12339    {
12340      init = 0;
12341
12342    }
12343
12344
12345
12346  /* Skip white space.  */
12347  while ((c = get_char ()) == ' ' || c == '\t')
12348    {
12349
12350    }
12351
12352  /* process numbers   */
12353  if (c == '.' || isdigit (c))
12354    {
12355      unget_char ( c);
12356      (yylval).ival = read_signed_integer ();
12357      return NUM;
12358    }
12359
12360  /* Return end-of-file.  */
12361  if (c == EOF)
12362    return CALC_EOF;
12363
12364  /* Return single chars. */
12365  return c;
12366}
12367
12368static int
12369power (int base, int exponent)
12370{
12371  int res = 1;
12372  if (exponent < 0)
12373    exit (3);
12374  for (/* Niente */; exponent; --exponent)
12375    res *= base;
12376  return res;
12377}
12378
12379
12380int
12381main (int argc, const char **argv)
12382{
12383  semantic_value result = 0;
12384  int count = 0;
12385  int status;
12386
12387  /* This used to be alarm (10), but that isn't enough time for
12388     a July 1995 vintage DEC Alphastation 200 4/100 system,
12389     according to Nelson H. F. Beebe.  100 seconds is enough.  */
12390  alarm (100);
12391
12392  if (argc == 2)
12393    input = fopen (argv[1], "r");
12394  else
12395    input = stdin;
12396
12397  if (!input)
12398    {
12399      perror (argv[1]);
12400      return 3;
12401    }
12402
12403
12404  status = yyparse ();
12405  if (global_result != result)
12406    abort ();
12407  if (global_count != count)
12408    abort ();
12409  return status;
12410}
12411_ATEOF
12412
12413
12414
12415
12416
12417$at_traceoff
12418echo "calc.at:552: bison -o calc.c calc.y"
12419echo calc.at:552 >$at_check_line_file
12420( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
12421at_status=$?
12422grep '^ *+' $at_stder1 >&2
12423grep -v '^ *+' $at_stder1 >$at_stderr
12424at_failed=false
12425$at_diff $at_devnull $at_stderr || at_failed=:
12426$at_diff $at_devnull $at_stdout || at_failed=:
12427case $at_status in
12428   77) echo 77 > $at_status_file
12429            exit 77;;
12430   0) ;;
12431   *) echo "calc.at:552: exit code was $at_status, expected 0"
12432      at_failed=:;;
12433esac
12434if $at_failed; then
12435
12436  echo 1 > $at_status_file
12437  exit 1
12438fi
12439
12440$at_traceon
12441
12442   $at_traceoff
12443echo "calc.at:552: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
12444echo calc.at:552 >$at_check_line_file
12445( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
12446at_status=$?
12447grep '^ *+' $at_stder1 >&2
12448grep -v '^ *+' $at_stder1 >$at_stderr
12449at_failed=false
12450echo stderr:; cat $at_stderr
12451echo stdout:; cat $at_stdout
12452case $at_status in
12453   77) echo 77 > $at_status_file
12454            exit 77;;
12455   0) ;;
12456   *) echo "calc.at:552: exit code was $at_status, expected 0"
12457      at_failed=:;;
12458esac
12459if $at_failed; then
12460
12461  echo 1 > $at_status_file
12462  exit 1
12463fi
12464
12465$at_traceon
12466
12467
12468# Test the priorities.
12469cat >input <<'_ATEOF'
124701 + 2 * 3 = 7
124711 + 2 * -3 = -5
12472
12473-1^2 = -1
12474(-1)^2 = 1
12475
12476---1 = -1
12477
124781 - 2 - 3 = -4
124791 - (2 - 3) = 2
12480
124812^2^3 = 256
12482(2^2)^3 = 64
12483_ATEOF
12484
12485$at_traceoff
12486echo "calc.at:552: \$PREPARSER ./calc input"
12487echo calc.at:552 >$at_check_line_file
12488( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
12489at_status=$?
12490grep '^ *+' $at_stder1 >&2
12491grep -v '^ *+' $at_stder1 >$at_stderr
12492at_failed=false
12493echo stderr:; tee stderr <$at_stderr
12494$at_diff $at_devnull $at_stdout || at_failed=:
12495case $at_status in
12496   77) echo 77 > $at_status_file
12497            exit 77;;
12498   0) ;;
12499   *) echo "calc.at:552: exit code was $at_status, expected 0"
12500      at_failed=:;;
12501esac
12502if $at_failed; then
12503
12504  echo 1 > $at_status_file
12505  exit 1
12506fi
12507
12508$at_traceon
12509
12510
12511
12512# Some syntax errors.
12513cat >input <<'_ATEOF'
125140 0
12515_ATEOF
12516
12517$at_traceoff
12518echo "calc.at:552: \$PREPARSER ./calc input"
12519echo calc.at:552 >$at_check_line_file
12520( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
12521at_status=$?
12522grep '^ *+' $at_stder1 >&2
12523grep -v '^ *+' $at_stder1 >$at_stderr
12524at_failed=false
12525echo stderr:; tee stderr <$at_stderr
12526$at_diff $at_devnull $at_stdout || at_failed=:
12527case $at_status in
12528   77) echo 77 > $at_status_file
12529            exit 77;;
12530   1) ;;
12531   *) echo "calc.at:552: exit code was $at_status, expected 1"
12532      at_failed=:;;
12533esac
12534if $at_failed; then
12535
12536  echo 1 > $at_status_file
12537  exit 1
12538fi
12539
12540$at_traceon
12541
12542
12543# Normalize the observed and expected error messages, depending upon the
12544# options.
12545# 1. Remove the traces from observed.
12546sed '/^Starting/d
12547/^Entering/d
12548/^Stack/d
12549/^Reading/d
12550/^Reducing/d
12551/^Shifting/d
12552/^state/d
12553/^Cleanup:/d
12554/^Error:/d
12555/^Next/d
12556/^Discarding/d
12557/ \$[0-9$]* = /d
12558/^yydestructor:/d' stderr >at-stderr
12559mv at-stderr stderr
12560# 2. Create the reference error message.
12561cat >expout <<'_ATEOF'
125621.2: syntax error, unexpected number
12563_ATEOF
12564
12565# 3. If locations are not used, remove them.
12566sed 's/^[-0-9.]*: //' expout >at-expout
12567mv at-expout expout
12568# 4. If error-verbose is not used, strip the`, unexpected....' part.
12569sed 's/syntax error, .*$/syntax error/' expout >at-expout
12570mv at-expout expout
12571# 5. Check
12572$at_traceoff
12573echo "calc.at:552: cat stderr"
12574echo calc.at:552 >$at_check_line_file
12575( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
12576at_status=$?
12577grep '^ *+' $at_stder1 >&2
12578grep -v '^ *+' $at_stder1 >$at_stderr
12579at_failed=false
12580$at_diff $at_devnull $at_stderr || at_failed=:
12581$at_diff expout $at_stdout || at_failed=:
12582case $at_status in
12583   77) echo 77 > $at_status_file
12584            exit 77;;
12585   0) ;;
12586   *) echo "calc.at:552: exit code was $at_status, expected 0"
12587      at_failed=:;;
12588esac
12589if $at_failed; then
12590
12591  echo 1 > $at_status_file
12592  exit 1
12593fi
12594
12595$at_traceon
12596
12597
12598cat >input <<'_ATEOF'
125991//2
12600_ATEOF
12601
12602$at_traceoff
12603echo "calc.at:552: \$PREPARSER ./calc input"
12604echo calc.at:552 >$at_check_line_file
12605( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
12606at_status=$?
12607grep '^ *+' $at_stder1 >&2
12608grep -v '^ *+' $at_stder1 >$at_stderr
12609at_failed=false
12610echo stderr:; tee stderr <$at_stderr
12611$at_diff $at_devnull $at_stdout || at_failed=:
12612case $at_status in
12613   77) echo 77 > $at_status_file
12614            exit 77;;
12615   1) ;;
12616   *) echo "calc.at:552: exit code was $at_status, expected 1"
12617      at_failed=:;;
12618esac
12619if $at_failed; then
12620
12621  echo 1 > $at_status_file
12622  exit 1
12623fi
12624
12625$at_traceon
12626
12627
12628# Normalize the observed and expected error messages, depending upon the
12629# options.
12630# 1. Remove the traces from observed.
12631sed '/^Starting/d
12632/^Entering/d
12633/^Stack/d
12634/^Reading/d
12635/^Reducing/d
12636/^Shifting/d
12637/^state/d
12638/^Cleanup:/d
12639/^Error:/d
12640/^Next/d
12641/^Discarding/d
12642/ \$[0-9$]* = /d
12643/^yydestructor:/d' stderr >at-stderr
12644mv at-stderr stderr
12645# 2. Create the reference error message.
12646cat >expout <<'_ATEOF'
126471.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
12648_ATEOF
12649
12650# 3. If locations are not used, remove them.
12651sed 's/^[-0-9.]*: //' expout >at-expout
12652mv at-expout expout
12653# 4. If error-verbose is not used, strip the`, unexpected....' part.
12654sed 's/syntax error, .*$/syntax error/' expout >at-expout
12655mv at-expout expout
12656# 5. Check
12657$at_traceoff
12658echo "calc.at:552: cat stderr"
12659echo calc.at:552 >$at_check_line_file
12660( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
12661at_status=$?
12662grep '^ *+' $at_stder1 >&2
12663grep -v '^ *+' $at_stder1 >$at_stderr
12664at_failed=false
12665$at_diff $at_devnull $at_stderr || at_failed=:
12666$at_diff expout $at_stdout || at_failed=:
12667case $at_status in
12668   77) echo 77 > $at_status_file
12669            exit 77;;
12670   0) ;;
12671   *) echo "calc.at:552: exit code was $at_status, expected 0"
12672      at_failed=:;;
12673esac
12674if $at_failed; then
12675
12676  echo 1 > $at_status_file
12677  exit 1
12678fi
12679
12680$at_traceon
12681
12682
12683cat >input <<'_ATEOF'
12684error
12685_ATEOF
12686
12687$at_traceoff
12688echo "calc.at:552: \$PREPARSER ./calc input"
12689echo calc.at:552 >$at_check_line_file
12690( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
12691at_status=$?
12692grep '^ *+' $at_stder1 >&2
12693grep -v '^ *+' $at_stder1 >$at_stderr
12694at_failed=false
12695echo stderr:; tee stderr <$at_stderr
12696$at_diff $at_devnull $at_stdout || at_failed=:
12697case $at_status in
12698   77) echo 77 > $at_status_file
12699            exit 77;;
12700   1) ;;
12701   *) echo "calc.at:552: exit code was $at_status, expected 1"
12702      at_failed=:;;
12703esac
12704if $at_failed; then
12705
12706  echo 1 > $at_status_file
12707  exit 1
12708fi
12709
12710$at_traceon
12711
12712
12713# Normalize the observed and expected error messages, depending upon the
12714# options.
12715# 1. Remove the traces from observed.
12716sed '/^Starting/d
12717/^Entering/d
12718/^Stack/d
12719/^Reading/d
12720/^Reducing/d
12721/^Shifting/d
12722/^state/d
12723/^Cleanup:/d
12724/^Error:/d
12725/^Next/d
12726/^Discarding/d
12727/ \$[0-9$]* = /d
12728/^yydestructor:/d' stderr >at-stderr
12729mv at-stderr stderr
12730# 2. Create the reference error message.
12731cat >expout <<'_ATEOF'
127321.0: syntax error, unexpected $undefined
12733_ATEOF
12734
12735# 3. If locations are not used, remove them.
12736sed 's/^[-0-9.]*: //' expout >at-expout
12737mv at-expout expout
12738# 4. If error-verbose is not used, strip the`, unexpected....' part.
12739sed 's/syntax error, .*$/syntax error/' expout >at-expout
12740mv at-expout expout
12741# 5. Check
12742$at_traceoff
12743echo "calc.at:552: cat stderr"
12744echo calc.at:552 >$at_check_line_file
12745( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
12746at_status=$?
12747grep '^ *+' $at_stder1 >&2
12748grep -v '^ *+' $at_stder1 >$at_stderr
12749at_failed=false
12750$at_diff $at_devnull $at_stderr || at_failed=:
12751$at_diff expout $at_stdout || at_failed=:
12752case $at_status in
12753   77) echo 77 > $at_status_file
12754            exit 77;;
12755   0) ;;
12756   *) echo "calc.at:552: exit code was $at_status, expected 0"
12757      at_failed=:;;
12758esac
12759if $at_failed; then
12760
12761  echo 1 > $at_status_file
12762  exit 1
12763fi
12764
12765$at_traceon
12766
12767
12768cat >input <<'_ATEOF'
127691 = 2 = 3
12770_ATEOF
12771
12772$at_traceoff
12773echo "calc.at:552: \$PREPARSER ./calc input"
12774echo calc.at:552 >$at_check_line_file
12775( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
12776at_status=$?
12777grep '^ *+' $at_stder1 >&2
12778grep -v '^ *+' $at_stder1 >$at_stderr
12779at_failed=false
12780echo stderr:; tee stderr <$at_stderr
12781$at_diff $at_devnull $at_stdout || at_failed=:
12782case $at_status in
12783   77) echo 77 > $at_status_file
12784            exit 77;;
12785   1) ;;
12786   *) echo "calc.at:552: exit code was $at_status, expected 1"
12787      at_failed=:;;
12788esac
12789if $at_failed; then
12790
12791  echo 1 > $at_status_file
12792  exit 1
12793fi
12794
12795$at_traceon
12796
12797
12798# Normalize the observed and expected error messages, depending upon the
12799# options.
12800# 1. Remove the traces from observed.
12801sed '/^Starting/d
12802/^Entering/d
12803/^Stack/d
12804/^Reading/d
12805/^Reducing/d
12806/^Shifting/d
12807/^state/d
12808/^Cleanup:/d
12809/^Error:/d
12810/^Next/d
12811/^Discarding/d
12812/ \$[0-9$]* = /d
12813/^yydestructor:/d' stderr >at-stderr
12814mv at-stderr stderr
12815# 2. Create the reference error message.
12816cat >expout <<'_ATEOF'
128171.6: syntax error, unexpected '='
12818_ATEOF
12819
12820# 3. If locations are not used, remove them.
12821sed 's/^[-0-9.]*: //' expout >at-expout
12822mv at-expout expout
12823# 4. If error-verbose is not used, strip the`, unexpected....' part.
12824sed 's/syntax error, .*$/syntax error/' expout >at-expout
12825mv at-expout expout
12826# 5. Check
12827$at_traceoff
12828echo "calc.at:552: cat stderr"
12829echo calc.at:552 >$at_check_line_file
12830( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
12831at_status=$?
12832grep '^ *+' $at_stder1 >&2
12833grep -v '^ *+' $at_stder1 >$at_stderr
12834at_failed=false
12835$at_diff $at_devnull $at_stderr || at_failed=:
12836$at_diff expout $at_stdout || at_failed=:
12837case $at_status in
12838   77) echo 77 > $at_status_file
12839            exit 77;;
12840   0) ;;
12841   *) echo "calc.at:552: exit code was $at_status, expected 0"
12842      at_failed=:;;
12843esac
12844if $at_failed; then
12845
12846  echo 1 > $at_status_file
12847  exit 1
12848fi
12849
12850$at_traceon
12851
12852
12853cat >input <<'_ATEOF'
12854
12855+1
12856_ATEOF
12857
12858$at_traceoff
12859echo "calc.at:552: \$PREPARSER ./calc input"
12860echo calc.at:552 >$at_check_line_file
12861( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
12862at_status=$?
12863grep '^ *+' $at_stder1 >&2
12864grep -v '^ *+' $at_stder1 >$at_stderr
12865at_failed=false
12866echo stderr:; tee stderr <$at_stderr
12867$at_diff $at_devnull $at_stdout || at_failed=:
12868case $at_status in
12869   77) echo 77 > $at_status_file
12870            exit 77;;
12871   1) ;;
12872   *) echo "calc.at:552: exit code was $at_status, expected 1"
12873      at_failed=:;;
12874esac
12875if $at_failed; then
12876
12877  echo 1 > $at_status_file
12878  exit 1
12879fi
12880
12881$at_traceon
12882
12883
12884# Normalize the observed and expected error messages, depending upon the
12885# options.
12886# 1. Remove the traces from observed.
12887sed '/^Starting/d
12888/^Entering/d
12889/^Stack/d
12890/^Reading/d
12891/^Reducing/d
12892/^Shifting/d
12893/^state/d
12894/^Cleanup:/d
12895/^Error:/d
12896/^Next/d
12897/^Discarding/d
12898/ \$[0-9$]* = /d
12899/^yydestructor:/d' stderr >at-stderr
12900mv at-stderr stderr
12901# 2. Create the reference error message.
12902cat >expout <<'_ATEOF'
129032.0: syntax error, unexpected '+'
12904_ATEOF
12905
12906# 3. If locations are not used, remove them.
12907sed 's/^[-0-9.]*: //' expout >at-expout
12908mv at-expout expout
12909# 4. If error-verbose is not used, strip the`, unexpected....' part.
12910sed 's/syntax error, .*$/syntax error/' expout >at-expout
12911mv at-expout expout
12912# 5. Check
12913$at_traceoff
12914echo "calc.at:552: cat stderr"
12915echo calc.at:552 >$at_check_line_file
12916( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
12917at_status=$?
12918grep '^ *+' $at_stder1 >&2
12919grep -v '^ *+' $at_stder1 >$at_stderr
12920at_failed=false
12921$at_diff $at_devnull $at_stderr || at_failed=:
12922$at_diff expout $at_stdout || at_failed=:
12923case $at_status in
12924   77) echo 77 > $at_status_file
12925            exit 77;;
12926   0) ;;
12927   *) echo "calc.at:552: exit code was $at_status, expected 0"
12928      at_failed=:;;
12929esac
12930if $at_failed; then
12931
12932  echo 1 > $at_status_file
12933  exit 1
12934fi
12935
12936$at_traceon
12937
12938
12939# Exercise error messages with EOF: work on an empty file.
12940$at_traceoff
12941echo "calc.at:552: \$PREPARSER ./calc /dev/null"
12942echo calc.at:552 >$at_check_line_file
12943( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
12944at_status=$?
12945grep '^ *+' $at_stder1 >&2
12946grep -v '^ *+' $at_stder1 >$at_stderr
12947at_failed=false
12948echo stderr:; tee stderr <$at_stderr
12949$at_diff $at_devnull $at_stdout || at_failed=:
12950case $at_status in
12951   77) echo 77 > $at_status_file
12952            exit 77;;
12953   1) ;;
12954   *) echo "calc.at:552: exit code was $at_status, expected 1"
12955      at_failed=:;;
12956esac
12957if $at_failed; then
12958
12959  echo 1 > $at_status_file
12960  exit 1
12961fi
12962
12963$at_traceon
12964
12965
12966# Normalize the observed and expected error messages, depending upon the
12967# options.
12968# 1. Remove the traces from observed.
12969sed '/^Starting/d
12970/^Entering/d
12971/^Stack/d
12972/^Reading/d
12973/^Reducing/d
12974/^Shifting/d
12975/^state/d
12976/^Cleanup:/d
12977/^Error:/d
12978/^Next/d
12979/^Discarding/d
12980/ \$[0-9$]* = /d
12981/^yydestructor:/d' stderr >at-stderr
12982mv at-stderr stderr
12983# 2. Create the reference error message.
12984cat >expout <<'_ATEOF'
129851.0: syntax error, unexpected end of input
12986_ATEOF
12987
12988# 3. If locations are not used, remove them.
12989sed 's/^[-0-9.]*: //' expout >at-expout
12990mv at-expout expout
12991# 4. If error-verbose is not used, strip the`, unexpected....' part.
12992sed 's/syntax error, .*$/syntax error/' expout >at-expout
12993mv at-expout expout
12994# 5. Check
12995$at_traceoff
12996echo "calc.at:552: cat stderr"
12997echo calc.at:552 >$at_check_line_file
12998( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
12999at_status=$?
13000grep '^ *+' $at_stder1 >&2
13001grep -v '^ *+' $at_stder1 >$at_stderr
13002at_failed=false
13003$at_diff $at_devnull $at_stderr || at_failed=:
13004$at_diff expout $at_stdout || at_failed=:
13005case $at_status in
13006   77) echo 77 > $at_status_file
13007            exit 77;;
13008   0) ;;
13009   *) echo "calc.at:552: exit code was $at_status, expected 0"
13010      at_failed=:;;
13011esac
13012if $at_failed; then
13013
13014  echo 1 > $at_status_file
13015  exit 1
13016fi
13017
13018$at_traceon
13019
13020
13021
13022# Exercise the error token: without it, we die at the first error,
13023# hence be sure to
13024#
13025# - have several errors which exercise different shift/discardings
13026#   - (): nothing to pop, nothing to discard
13027#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
13028#   - (* * *): nothing to pop, a lot to discard
13029#   - (1 + 2 * *): some to pop and discard
13030#
13031# - test the action associated to `error'
13032#
13033# - check the look-ahead that triggers an error is not discarded
13034#   when we enter error recovery.  Below, the look-ahead causing the
13035#   first error is ")", which is needed to recover from the error and
13036#   produce the "0" that triggers the "0 != 1" error.
13037#
13038cat >input <<'_ATEOF'
13039() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
13040_ATEOF
13041
13042$at_traceoff
13043echo "calc.at:552: \$PREPARSER ./calc input"
13044echo calc.at:552 >$at_check_line_file
13045( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
13046at_status=$?
13047grep '^ *+' $at_stder1 >&2
13048grep -v '^ *+' $at_stder1 >$at_stderr
13049at_failed=false
13050echo stderr:; tee stderr <$at_stderr
13051$at_diff $at_devnull $at_stdout || at_failed=:
13052case $at_status in
13053   77) echo 77 > $at_status_file
13054            exit 77;;
13055   0) ;;
13056   *) echo "calc.at:552: exit code was $at_status, expected 0"
13057      at_failed=:;;
13058esac
13059if $at_failed; then
13060
13061  echo 1 > $at_status_file
13062  exit 1
13063fi
13064
13065$at_traceon
13066
13067
13068# Normalize the observed and expected error messages, depending upon the
13069# options.
13070# 1. Remove the traces from observed.
13071sed '/^Starting/d
13072/^Entering/d
13073/^Stack/d
13074/^Reading/d
13075/^Reducing/d
13076/^Shifting/d
13077/^state/d
13078/^Cleanup:/d
13079/^Error:/d
13080/^Next/d
13081/^Discarding/d
13082/ \$[0-9$]* = /d
13083/^yydestructor:/d' stderr >at-stderr
13084mv at-stderr stderr
13085# 2. Create the reference error message.
13086cat >expout <<'_ATEOF'
130871.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
130881.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
130891.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
130901.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
13091calc: error: 4444 != 1
13092_ATEOF
13093
13094# 3. If locations are not used, remove them.
13095sed 's/^[-0-9.]*: //' expout >at-expout
13096mv at-expout expout
13097# 4. If error-verbose is not used, strip the`, unexpected....' part.
13098sed 's/syntax error, .*$/syntax error/' expout >at-expout
13099mv at-expout expout
13100# 5. Check
13101$at_traceoff
13102echo "calc.at:552: cat stderr"
13103echo calc.at:552 >$at_check_line_file
13104( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
13105at_status=$?
13106grep '^ *+' $at_stder1 >&2
13107grep -v '^ *+' $at_stder1 >$at_stderr
13108at_failed=false
13109$at_diff $at_devnull $at_stderr || at_failed=:
13110$at_diff expout $at_stdout || at_failed=:
13111case $at_status in
13112   77) echo 77 > $at_status_file
13113            exit 77;;
13114   0) ;;
13115   *) echo "calc.at:552: exit code was $at_status, expected 0"
13116      at_failed=:;;
13117esac
13118if $at_failed; then
13119
13120  echo 1 > $at_status_file
13121  exit 1
13122fi
13123
13124$at_traceon
13125
13126
13127
13128# The same, but this time exercising explicitly triggered syntax errors.
13129# POSIX says the look-ahead causing the error should not be discarded.
13130cat >input <<'_ATEOF'
13131(!) + (0 0) = 1
13132_ATEOF
13133
13134$at_traceoff
13135echo "calc.at:552: \$PREPARSER ./calc input"
13136echo calc.at:552 >$at_check_line_file
13137( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
13138at_status=$?
13139grep '^ *+' $at_stder1 >&2
13140grep -v '^ *+' $at_stder1 >$at_stderr
13141at_failed=false
13142echo stderr:; tee stderr <$at_stderr
13143$at_diff $at_devnull $at_stdout || at_failed=:
13144case $at_status in
13145   77) echo 77 > $at_status_file
13146            exit 77;;
13147   0) ;;
13148   *) echo "calc.at:552: exit code was $at_status, expected 0"
13149      at_failed=:;;
13150esac
13151if $at_failed; then
13152
13153  echo 1 > $at_status_file
13154  exit 1
13155fi
13156
13157$at_traceon
13158
13159
13160# Normalize the observed and expected error messages, depending upon the
13161# options.
13162# 1. Remove the traces from observed.
13163sed '/^Starting/d
13164/^Entering/d
13165/^Stack/d
13166/^Reading/d
13167/^Reducing/d
13168/^Shifting/d
13169/^state/d
13170/^Cleanup:/d
13171/^Error:/d
13172/^Next/d
13173/^Discarding/d
13174/ \$[0-9$]* = /d
13175/^yydestructor:/d' stderr >at-stderr
13176mv at-stderr stderr
13177# 2. Create the reference error message.
13178cat >expout <<'_ATEOF'
131791.9: syntax error, unexpected number
13180calc: error: 2222 != 1
13181_ATEOF
13182
13183# 3. If locations are not used, remove them.
13184sed 's/^[-0-9.]*: //' expout >at-expout
13185mv at-expout expout
13186# 4. If error-verbose is not used, strip the`, unexpected....' part.
13187sed 's/syntax error, .*$/syntax error/' expout >at-expout
13188mv at-expout expout
13189# 5. Check
13190$at_traceoff
13191echo "calc.at:552: cat stderr"
13192echo calc.at:552 >$at_check_line_file
13193( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
13194at_status=$?
13195grep '^ *+' $at_stder1 >&2
13196grep -v '^ *+' $at_stder1 >$at_stderr
13197at_failed=false
13198$at_diff $at_devnull $at_stderr || at_failed=:
13199$at_diff expout $at_stdout || at_failed=:
13200case $at_status in
13201   77) echo 77 > $at_status_file
13202            exit 77;;
13203   0) ;;
13204   *) echo "calc.at:552: exit code was $at_status, expected 0"
13205      at_failed=:;;
13206esac
13207if $at_failed; then
13208
13209  echo 1 > $at_status_file
13210  exit 1
13211fi
13212
13213$at_traceon
13214
13215
13216cat >input <<'_ATEOF'
13217(- *) + (0 0) = 1
13218_ATEOF
13219
13220$at_traceoff
13221echo "calc.at:552: \$PREPARSER ./calc input"
13222echo calc.at:552 >$at_check_line_file
13223( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
13224at_status=$?
13225grep '^ *+' $at_stder1 >&2
13226grep -v '^ *+' $at_stder1 >$at_stderr
13227at_failed=false
13228echo stderr:; tee stderr <$at_stderr
13229$at_diff $at_devnull $at_stdout || at_failed=:
13230case $at_status in
13231   77) echo 77 > $at_status_file
13232            exit 77;;
13233   0) ;;
13234   *) echo "calc.at:552: exit code was $at_status, expected 0"
13235      at_failed=:;;
13236esac
13237if $at_failed; then
13238
13239  echo 1 > $at_status_file
13240  exit 1
13241fi
13242
13243$at_traceon
13244
13245
13246# Normalize the observed and expected error messages, depending upon the
13247# options.
13248# 1. Remove the traces from observed.
13249sed '/^Starting/d
13250/^Entering/d
13251/^Stack/d
13252/^Reading/d
13253/^Reducing/d
13254/^Shifting/d
13255/^state/d
13256/^Cleanup:/d
13257/^Error:/d
13258/^Next/d
13259/^Discarding/d
13260/ \$[0-9$]* = /d
13261/^yydestructor:/d' stderr >at-stderr
13262mv at-stderr stderr
13263# 2. Create the reference error message.
13264cat >expout <<'_ATEOF'
132651.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
132661.11: syntax error, unexpected number
13267calc: error: 2222 != 1
13268_ATEOF
13269
13270# 3. If locations are not used, remove them.
13271sed 's/^[-0-9.]*: //' expout >at-expout
13272mv at-expout expout
13273# 4. If error-verbose is not used, strip the`, unexpected....' part.
13274sed 's/syntax error, .*$/syntax error/' expout >at-expout
13275mv at-expout expout
13276# 5. Check
13277$at_traceoff
13278echo "calc.at:552: cat stderr"
13279echo calc.at:552 >$at_check_line_file
13280( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
13281at_status=$?
13282grep '^ *+' $at_stder1 >&2
13283grep -v '^ *+' $at_stder1 >$at_stderr
13284at_failed=false
13285$at_diff $at_devnull $at_stderr || at_failed=:
13286$at_diff expout $at_stdout || at_failed=:
13287case $at_status in
13288   77) echo 77 > $at_status_file
13289            exit 77;;
13290   0) ;;
13291   *) echo "calc.at:552: exit code was $at_status, expected 0"
13292      at_failed=:;;
13293esac
13294if $at_failed; then
13295
13296  echo 1 > $at_status_file
13297  exit 1
13298fi
13299
13300$at_traceon
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325      $at_traceoff
13326      $at_times_p && times >$at_times_file
13327    ) 5>&1 2>&1 | eval $at_tee_pipe
13328    at_status=`cat $at_status_file`
13329    ;;
13330
13331  72 ) # 72. calc.at:553: Calculator %locations
13332    at_setup_line='calc.at:553'
13333    at_desc='Calculator %locations'
13334    $at_quiet $ECHO_N " 72: Calculator %locations                        $ECHO_C"
13335    at_xfail=no
13336    (
13337      echo "72. calc.at:553: testing ..."
13338      $at_traceon
13339
13340
13341
13342
13343
13344
13345
13346
13347# Using yacc.c?
13348
13349
13350
13351
13352
13353
13354
13355# yyerror receives the location if %location & %pure & (%glr or %parse-param).
13356
13357# yyerror always sees the locations (when activated), except if
13358# yacc & pure & !param.
13359
13360
13361# The interface is pure: either because %pure-parser, or because we
13362# are using the C++ parsers.
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375cat >calc.y <<'_ATEOF'
13376%{
13377#ifdef HAVE_CONFIG_H
13378# include <config.h>
13379  /* We don't need perfect functions for these tests. */
13380# undef malloc
13381# undef memcmp
13382# undef realloc
13383#endif
13384%}
13385
13386/* Infix notation calculator--calc */
13387%locations
13388
13389%{
13390#include <stdio.h>
13391
13392#include <stdlib.h>
13393#include <string.h>
13394#if HAVE_UNISTD_H
13395# include <unistd.h>
13396#else
13397# undef alarm
13398# define alarm(seconds) /* empty */
13399#endif
13400#include <ctype.h>
13401#define USE(Var)
13402
13403/* Exercise pre-prologue dependency to %union.  */
13404typedef int semantic_value;
13405
13406static semantic_value global_result = 0;
13407static int global_count = 0;
13408%}
13409
13410/* Exercise %union. */
13411%union
13412{
13413  semantic_value ival;
13414};
13415
13416%{
13417static int power (int base, int exponent);
13418/* yyerror receives the location if:
13419   - %location & %pure & %glr
13420   - %location & %pure & %yacc & %parse-param. */
13421static void yyerror (
13422
13423                     const char *s
13424                     );
13425static int yylex (void);
13426static int get_char (void);
13427static void unget_char ( int c);
13428%}
13429
13430
13431
13432/* Bison Declarations */
13433%token CALC_EOF 0 "end of input"
13434%token <ival> NUM "number"
13435%type  <ival> exp
13436
13437%nonassoc '=' /* comparison	       */
13438%left '-' '+'
13439%left '*' '/'
13440%left NEG     /* negation--unary minus */
13441%right '^'    /* exponentiation        */
13442
13443/* Grammar follows */
13444%%
13445input:
13446  line
13447| input line         {  }
13448;
13449
13450line:
13451  '\n'
13452| exp '\n'           { USE ($1); }
13453;
13454
13455exp:
13456  NUM                { $$ = $1;             }
13457| exp '=' exp
13458  {
13459    if ($1 != $3)
13460      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
13461    $$ = $1;
13462  }
13463| exp '+' exp        { $$ = $1 + $3;        }
13464| exp '-' exp        { $$ = $1 - $3;        }
13465| exp '*' exp        { $$ = $1 * $3;        }
13466| exp '/' exp        { $$ = $1 / $3;        }
13467| '-' exp  %prec NEG { $$ = -$2;            }
13468| exp '^' exp        { $$ = power ($1, $3); }
13469| '(' exp ')'        { $$ = $2;             }
13470| '(' error ')'      { $$ = 1111;           }
13471| '!'                { $$ = 0; YYERROR;     }
13472| '-' error          { $$ = 0; YYERROR;     }
13473;
13474%%
13475/* The input.  */
13476static FILE *input;
13477
13478static void
13479yyerror (
13480
13481         const char *s)
13482{
13483
13484
13485  fprintf (stderr, "%d.%d",
13486           (yylloc).first_line, (yylloc).first_column);
13487  if ((yylloc).first_line != (yylloc).last_line)
13488    fprintf (stderr, "-%d.%d",
13489	     (yylloc).last_line,  (yylloc).last_column - 1);
13490  else if ((yylloc).first_column != (yylloc).last_column - 1)
13491    fprintf (stderr, "-%d",
13492	     (yylloc).last_column - 1);
13493  fprintf (stderr, ": ");
13494  fprintf (stderr, "%s\n", s);
13495}
13496
13497
13498
13499static YYLTYPE last_yylloc;
13500
13501static int
13502get_char (void)
13503{
13504  int res = getc (input);
13505  ;
13506
13507  last_yylloc = (yylloc);
13508  if (res == '\n')
13509    {
13510      (yylloc).last_line++;
13511      (yylloc).last_column = 0;
13512    }
13513  else
13514    (yylloc).last_column++;
13515
13516  return res;
13517}
13518
13519
13520static void
13521unget_char ( int c)
13522{
13523  ;
13524
13525  /* Wrong when C == `\n'. */
13526  (yylloc) = last_yylloc;
13527
13528  ungetc (c, input);
13529}
13530
13531static int
13532read_signed_integer (void)
13533{
13534  int c = get_char ();
13535  int sign = 1;
13536  int n = 0;
13537
13538  ;
13539  if (c == '-')
13540    {
13541      c = get_char ();
13542      sign = -1;
13543    }
13544
13545  while (isdigit (c))
13546    {
13547      n = 10 * n + (c - '0');
13548      c = get_char ();
13549    }
13550
13551  unget_char ( c);
13552
13553  return sign * n;
13554}
13555
13556
13557
13558/*---------------------------------------------------------------.
13559| Lexical analyzer returns an integer on the stack and the token |
13560| NUM, or the ASCII character read if not a number.  Skips all   |
13561| blanks and tabs, returns 0 for EOF.                            |
13562`---------------------------------------------------------------*/
13563
13564static int
13565yylex (void)
13566{
13567  static int init = 1;
13568  int c;
13569
13570  if (init)
13571    {
13572      init = 0;
13573
13574      (yylloc).last_column = 0;
13575      (yylloc).last_line = 1;
13576
13577    }
13578
13579
13580 (yylloc).first_column = (yylloc).last_column;
13581  (yylloc).first_line   = (yylloc).last_line;
13582
13583
13584  /* Skip white space.  */
13585  while ((c = get_char ()) == ' ' || c == '\t')
13586    {
13587     (yylloc).first_column = (yylloc).last_column;
13588      (yylloc).first_line   = (yylloc).last_line;
13589
13590    }
13591
13592  /* process numbers   */
13593  if (c == '.' || isdigit (c))
13594    {
13595      unget_char ( c);
13596      (yylval).ival = read_signed_integer ();
13597      return NUM;
13598    }
13599
13600  /* Return end-of-file.  */
13601  if (c == EOF)
13602    return CALC_EOF;
13603
13604  /* Return single chars. */
13605  return c;
13606}
13607
13608static int
13609power (int base, int exponent)
13610{
13611  int res = 1;
13612  if (exponent < 0)
13613    exit (3);
13614  for (/* Niente */; exponent; --exponent)
13615    res *= base;
13616  return res;
13617}
13618
13619
13620int
13621main (int argc, const char **argv)
13622{
13623  semantic_value result = 0;
13624  int count = 0;
13625  int status;
13626
13627  /* This used to be alarm (10), but that isn't enough time for
13628     a July 1995 vintage DEC Alphastation 200 4/100 system,
13629     according to Nelson H. F. Beebe.  100 seconds is enough.  */
13630  alarm (100);
13631
13632  if (argc == 2)
13633    input = fopen (argv[1], "r");
13634  else
13635    input = stdin;
13636
13637  if (!input)
13638    {
13639      perror (argv[1]);
13640      return 3;
13641    }
13642
13643
13644  status = yyparse ();
13645  if (global_result != result)
13646    abort ();
13647  if (global_count != count)
13648    abort ();
13649  return status;
13650}
13651_ATEOF
13652
13653
13654
13655
13656
13657$at_traceoff
13658echo "calc.at:553: bison -o calc.c calc.y"
13659echo calc.at:553 >$at_check_line_file
13660( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
13661at_status=$?
13662grep '^ *+' $at_stder1 >&2
13663grep -v '^ *+' $at_stder1 >$at_stderr
13664at_failed=false
13665$at_diff $at_devnull $at_stderr || at_failed=:
13666$at_diff $at_devnull $at_stdout || at_failed=:
13667case $at_status in
13668   77) echo 77 > $at_status_file
13669            exit 77;;
13670   0) ;;
13671   *) echo "calc.at:553: exit code was $at_status, expected 0"
13672      at_failed=:;;
13673esac
13674if $at_failed; then
13675
13676  echo 1 > $at_status_file
13677  exit 1
13678fi
13679
13680$at_traceon
13681
13682   $at_traceoff
13683echo "calc.at:553: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
13684echo calc.at:553 >$at_check_line_file
13685( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
13686at_status=$?
13687grep '^ *+' $at_stder1 >&2
13688grep -v '^ *+' $at_stder1 >$at_stderr
13689at_failed=false
13690echo stderr:; cat $at_stderr
13691echo stdout:; cat $at_stdout
13692case $at_status in
13693   77) echo 77 > $at_status_file
13694            exit 77;;
13695   0) ;;
13696   *) echo "calc.at:553: exit code was $at_status, expected 0"
13697      at_failed=:;;
13698esac
13699if $at_failed; then
13700
13701  echo 1 > $at_status_file
13702  exit 1
13703fi
13704
13705$at_traceon
13706
13707
13708# Test the priorities.
13709cat >input <<'_ATEOF'
137101 + 2 * 3 = 7
137111 + 2 * -3 = -5
13712
13713-1^2 = -1
13714(-1)^2 = 1
13715
13716---1 = -1
13717
137181 - 2 - 3 = -4
137191 - (2 - 3) = 2
13720
137212^2^3 = 256
13722(2^2)^3 = 64
13723_ATEOF
13724
13725$at_traceoff
13726echo "calc.at:553: \$PREPARSER ./calc input"
13727echo calc.at:553 >$at_check_line_file
13728( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
13729at_status=$?
13730grep '^ *+' $at_stder1 >&2
13731grep -v '^ *+' $at_stder1 >$at_stderr
13732at_failed=false
13733echo stderr:; tee stderr <$at_stderr
13734$at_diff $at_devnull $at_stdout || at_failed=:
13735case $at_status in
13736   77) echo 77 > $at_status_file
13737            exit 77;;
13738   0) ;;
13739   *) echo "calc.at:553: exit code was $at_status, expected 0"
13740      at_failed=:;;
13741esac
13742if $at_failed; then
13743
13744  echo 1 > $at_status_file
13745  exit 1
13746fi
13747
13748$at_traceon
13749
13750
13751
13752# Some syntax errors.
13753cat >input <<'_ATEOF'
137540 0
13755_ATEOF
13756
13757$at_traceoff
13758echo "calc.at:553: \$PREPARSER ./calc input"
13759echo calc.at:553 >$at_check_line_file
13760( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
13761at_status=$?
13762grep '^ *+' $at_stder1 >&2
13763grep -v '^ *+' $at_stder1 >$at_stderr
13764at_failed=false
13765echo stderr:; tee stderr <$at_stderr
13766$at_diff $at_devnull $at_stdout || at_failed=:
13767case $at_status in
13768   77) echo 77 > $at_status_file
13769            exit 77;;
13770   1) ;;
13771   *) echo "calc.at:553: exit code was $at_status, expected 1"
13772      at_failed=:;;
13773esac
13774if $at_failed; then
13775
13776  echo 1 > $at_status_file
13777  exit 1
13778fi
13779
13780$at_traceon
13781
13782
13783# Normalize the observed and expected error messages, depending upon the
13784# options.
13785# 1. Remove the traces from observed.
13786sed '/^Starting/d
13787/^Entering/d
13788/^Stack/d
13789/^Reading/d
13790/^Reducing/d
13791/^Shifting/d
13792/^state/d
13793/^Cleanup:/d
13794/^Error:/d
13795/^Next/d
13796/^Discarding/d
13797/ \$[0-9$]* = /d
13798/^yydestructor:/d' stderr >at-stderr
13799mv at-stderr stderr
13800# 2. Create the reference error message.
13801cat >expout <<'_ATEOF'
138021.2: syntax error, unexpected number
13803_ATEOF
13804
13805# 3. If locations are not used, remove them.
13806
13807# 4. If error-verbose is not used, strip the`, unexpected....' part.
13808sed 's/syntax error, .*$/syntax error/' expout >at-expout
13809mv at-expout expout
13810# 5. Check
13811$at_traceoff
13812echo "calc.at:553: cat stderr"
13813echo calc.at:553 >$at_check_line_file
13814( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
13815at_status=$?
13816grep '^ *+' $at_stder1 >&2
13817grep -v '^ *+' $at_stder1 >$at_stderr
13818at_failed=false
13819$at_diff $at_devnull $at_stderr || at_failed=:
13820$at_diff expout $at_stdout || at_failed=:
13821case $at_status in
13822   77) echo 77 > $at_status_file
13823            exit 77;;
13824   0) ;;
13825   *) echo "calc.at:553: exit code was $at_status, expected 0"
13826      at_failed=:;;
13827esac
13828if $at_failed; then
13829
13830  echo 1 > $at_status_file
13831  exit 1
13832fi
13833
13834$at_traceon
13835
13836
13837cat >input <<'_ATEOF'
138381//2
13839_ATEOF
13840
13841$at_traceoff
13842echo "calc.at:553: \$PREPARSER ./calc input"
13843echo calc.at:553 >$at_check_line_file
13844( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
13845at_status=$?
13846grep '^ *+' $at_stder1 >&2
13847grep -v '^ *+' $at_stder1 >$at_stderr
13848at_failed=false
13849echo stderr:; tee stderr <$at_stderr
13850$at_diff $at_devnull $at_stdout || at_failed=:
13851case $at_status in
13852   77) echo 77 > $at_status_file
13853            exit 77;;
13854   1) ;;
13855   *) echo "calc.at:553: exit code was $at_status, expected 1"
13856      at_failed=:;;
13857esac
13858if $at_failed; then
13859
13860  echo 1 > $at_status_file
13861  exit 1
13862fi
13863
13864$at_traceon
13865
13866
13867# Normalize the observed and expected error messages, depending upon the
13868# options.
13869# 1. Remove the traces from observed.
13870sed '/^Starting/d
13871/^Entering/d
13872/^Stack/d
13873/^Reading/d
13874/^Reducing/d
13875/^Shifting/d
13876/^state/d
13877/^Cleanup:/d
13878/^Error:/d
13879/^Next/d
13880/^Discarding/d
13881/ \$[0-9$]* = /d
13882/^yydestructor:/d' stderr >at-stderr
13883mv at-stderr stderr
13884# 2. Create the reference error message.
13885cat >expout <<'_ATEOF'
138861.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
13887_ATEOF
13888
13889# 3. If locations are not used, remove them.
13890
13891# 4. If error-verbose is not used, strip the`, unexpected....' part.
13892sed 's/syntax error, .*$/syntax error/' expout >at-expout
13893mv at-expout expout
13894# 5. Check
13895$at_traceoff
13896echo "calc.at:553: cat stderr"
13897echo calc.at:553 >$at_check_line_file
13898( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
13899at_status=$?
13900grep '^ *+' $at_stder1 >&2
13901grep -v '^ *+' $at_stder1 >$at_stderr
13902at_failed=false
13903$at_diff $at_devnull $at_stderr || at_failed=:
13904$at_diff expout $at_stdout || at_failed=:
13905case $at_status in
13906   77) echo 77 > $at_status_file
13907            exit 77;;
13908   0) ;;
13909   *) echo "calc.at:553: exit code was $at_status, expected 0"
13910      at_failed=:;;
13911esac
13912if $at_failed; then
13913
13914  echo 1 > $at_status_file
13915  exit 1
13916fi
13917
13918$at_traceon
13919
13920
13921cat >input <<'_ATEOF'
13922error
13923_ATEOF
13924
13925$at_traceoff
13926echo "calc.at:553: \$PREPARSER ./calc input"
13927echo calc.at:553 >$at_check_line_file
13928( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
13929at_status=$?
13930grep '^ *+' $at_stder1 >&2
13931grep -v '^ *+' $at_stder1 >$at_stderr
13932at_failed=false
13933echo stderr:; tee stderr <$at_stderr
13934$at_diff $at_devnull $at_stdout || at_failed=:
13935case $at_status in
13936   77) echo 77 > $at_status_file
13937            exit 77;;
13938   1) ;;
13939   *) echo "calc.at:553: exit code was $at_status, expected 1"
13940      at_failed=:;;
13941esac
13942if $at_failed; then
13943
13944  echo 1 > $at_status_file
13945  exit 1
13946fi
13947
13948$at_traceon
13949
13950
13951# Normalize the observed and expected error messages, depending upon the
13952# options.
13953# 1. Remove the traces from observed.
13954sed '/^Starting/d
13955/^Entering/d
13956/^Stack/d
13957/^Reading/d
13958/^Reducing/d
13959/^Shifting/d
13960/^state/d
13961/^Cleanup:/d
13962/^Error:/d
13963/^Next/d
13964/^Discarding/d
13965/ \$[0-9$]* = /d
13966/^yydestructor:/d' stderr >at-stderr
13967mv at-stderr stderr
13968# 2. Create the reference error message.
13969cat >expout <<'_ATEOF'
139701.0: syntax error, unexpected $undefined
13971_ATEOF
13972
13973# 3. If locations are not used, remove them.
13974
13975# 4. If error-verbose is not used, strip the`, unexpected....' part.
13976sed 's/syntax error, .*$/syntax error/' expout >at-expout
13977mv at-expout expout
13978# 5. Check
13979$at_traceoff
13980echo "calc.at:553: cat stderr"
13981echo calc.at:553 >$at_check_line_file
13982( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
13983at_status=$?
13984grep '^ *+' $at_stder1 >&2
13985grep -v '^ *+' $at_stder1 >$at_stderr
13986at_failed=false
13987$at_diff $at_devnull $at_stderr || at_failed=:
13988$at_diff expout $at_stdout || at_failed=:
13989case $at_status in
13990   77) echo 77 > $at_status_file
13991            exit 77;;
13992   0) ;;
13993   *) echo "calc.at:553: exit code was $at_status, expected 0"
13994      at_failed=:;;
13995esac
13996if $at_failed; then
13997
13998  echo 1 > $at_status_file
13999  exit 1
14000fi
14001
14002$at_traceon
14003
14004
14005cat >input <<'_ATEOF'
140061 = 2 = 3
14007_ATEOF
14008
14009$at_traceoff
14010echo "calc.at:553: \$PREPARSER ./calc input"
14011echo calc.at:553 >$at_check_line_file
14012( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
14013at_status=$?
14014grep '^ *+' $at_stder1 >&2
14015grep -v '^ *+' $at_stder1 >$at_stderr
14016at_failed=false
14017echo stderr:; tee stderr <$at_stderr
14018$at_diff $at_devnull $at_stdout || at_failed=:
14019case $at_status in
14020   77) echo 77 > $at_status_file
14021            exit 77;;
14022   1) ;;
14023   *) echo "calc.at:553: exit code was $at_status, expected 1"
14024      at_failed=:;;
14025esac
14026if $at_failed; then
14027
14028  echo 1 > $at_status_file
14029  exit 1
14030fi
14031
14032$at_traceon
14033
14034
14035# Normalize the observed and expected error messages, depending upon the
14036# options.
14037# 1. Remove the traces from observed.
14038sed '/^Starting/d
14039/^Entering/d
14040/^Stack/d
14041/^Reading/d
14042/^Reducing/d
14043/^Shifting/d
14044/^state/d
14045/^Cleanup:/d
14046/^Error:/d
14047/^Next/d
14048/^Discarding/d
14049/ \$[0-9$]* = /d
14050/^yydestructor:/d' stderr >at-stderr
14051mv at-stderr stderr
14052# 2. Create the reference error message.
14053cat >expout <<'_ATEOF'
140541.6: syntax error, unexpected '='
14055_ATEOF
14056
14057# 3. If locations are not used, remove them.
14058
14059# 4. If error-verbose is not used, strip the`, unexpected....' part.
14060sed 's/syntax error, .*$/syntax error/' expout >at-expout
14061mv at-expout expout
14062# 5. Check
14063$at_traceoff
14064echo "calc.at:553: cat stderr"
14065echo calc.at:553 >$at_check_line_file
14066( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
14067at_status=$?
14068grep '^ *+' $at_stder1 >&2
14069grep -v '^ *+' $at_stder1 >$at_stderr
14070at_failed=false
14071$at_diff $at_devnull $at_stderr || at_failed=:
14072$at_diff expout $at_stdout || at_failed=:
14073case $at_status in
14074   77) echo 77 > $at_status_file
14075            exit 77;;
14076   0) ;;
14077   *) echo "calc.at:553: exit code was $at_status, expected 0"
14078      at_failed=:;;
14079esac
14080if $at_failed; then
14081
14082  echo 1 > $at_status_file
14083  exit 1
14084fi
14085
14086$at_traceon
14087
14088
14089cat >input <<'_ATEOF'
14090
14091+1
14092_ATEOF
14093
14094$at_traceoff
14095echo "calc.at:553: \$PREPARSER ./calc input"
14096echo calc.at:553 >$at_check_line_file
14097( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
14098at_status=$?
14099grep '^ *+' $at_stder1 >&2
14100grep -v '^ *+' $at_stder1 >$at_stderr
14101at_failed=false
14102echo stderr:; tee stderr <$at_stderr
14103$at_diff $at_devnull $at_stdout || at_failed=:
14104case $at_status in
14105   77) echo 77 > $at_status_file
14106            exit 77;;
14107   1) ;;
14108   *) echo "calc.at:553: exit code was $at_status, expected 1"
14109      at_failed=:;;
14110esac
14111if $at_failed; then
14112
14113  echo 1 > $at_status_file
14114  exit 1
14115fi
14116
14117$at_traceon
14118
14119
14120# Normalize the observed and expected error messages, depending upon the
14121# options.
14122# 1. Remove the traces from observed.
14123sed '/^Starting/d
14124/^Entering/d
14125/^Stack/d
14126/^Reading/d
14127/^Reducing/d
14128/^Shifting/d
14129/^state/d
14130/^Cleanup:/d
14131/^Error:/d
14132/^Next/d
14133/^Discarding/d
14134/ \$[0-9$]* = /d
14135/^yydestructor:/d' stderr >at-stderr
14136mv at-stderr stderr
14137# 2. Create the reference error message.
14138cat >expout <<'_ATEOF'
141392.0: syntax error, unexpected '+'
14140_ATEOF
14141
14142# 3. If locations are not used, remove them.
14143
14144# 4. If error-verbose is not used, strip the`, unexpected....' part.
14145sed 's/syntax error, .*$/syntax error/' expout >at-expout
14146mv at-expout expout
14147# 5. Check
14148$at_traceoff
14149echo "calc.at:553: cat stderr"
14150echo calc.at:553 >$at_check_line_file
14151( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
14152at_status=$?
14153grep '^ *+' $at_stder1 >&2
14154grep -v '^ *+' $at_stder1 >$at_stderr
14155at_failed=false
14156$at_diff $at_devnull $at_stderr || at_failed=:
14157$at_diff expout $at_stdout || at_failed=:
14158case $at_status in
14159   77) echo 77 > $at_status_file
14160            exit 77;;
14161   0) ;;
14162   *) echo "calc.at:553: exit code was $at_status, expected 0"
14163      at_failed=:;;
14164esac
14165if $at_failed; then
14166
14167  echo 1 > $at_status_file
14168  exit 1
14169fi
14170
14171$at_traceon
14172
14173
14174# Exercise error messages with EOF: work on an empty file.
14175$at_traceoff
14176echo "calc.at:553: \$PREPARSER ./calc /dev/null"
14177echo calc.at:553 >$at_check_line_file
14178( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
14179at_status=$?
14180grep '^ *+' $at_stder1 >&2
14181grep -v '^ *+' $at_stder1 >$at_stderr
14182at_failed=false
14183echo stderr:; tee stderr <$at_stderr
14184$at_diff $at_devnull $at_stdout || at_failed=:
14185case $at_status in
14186   77) echo 77 > $at_status_file
14187            exit 77;;
14188   1) ;;
14189   *) echo "calc.at:553: exit code was $at_status, expected 1"
14190      at_failed=:;;
14191esac
14192if $at_failed; then
14193
14194  echo 1 > $at_status_file
14195  exit 1
14196fi
14197
14198$at_traceon
14199
14200
14201# Normalize the observed and expected error messages, depending upon the
14202# options.
14203# 1. Remove the traces from observed.
14204sed '/^Starting/d
14205/^Entering/d
14206/^Stack/d
14207/^Reading/d
14208/^Reducing/d
14209/^Shifting/d
14210/^state/d
14211/^Cleanup:/d
14212/^Error:/d
14213/^Next/d
14214/^Discarding/d
14215/ \$[0-9$]* = /d
14216/^yydestructor:/d' stderr >at-stderr
14217mv at-stderr stderr
14218# 2. Create the reference error message.
14219cat >expout <<'_ATEOF'
142201.0: syntax error, unexpected end of input
14221_ATEOF
14222
14223# 3. If locations are not used, remove them.
14224
14225# 4. If error-verbose is not used, strip the`, unexpected....' part.
14226sed 's/syntax error, .*$/syntax error/' expout >at-expout
14227mv at-expout expout
14228# 5. Check
14229$at_traceoff
14230echo "calc.at:553: cat stderr"
14231echo calc.at:553 >$at_check_line_file
14232( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
14233at_status=$?
14234grep '^ *+' $at_stder1 >&2
14235grep -v '^ *+' $at_stder1 >$at_stderr
14236at_failed=false
14237$at_diff $at_devnull $at_stderr || at_failed=:
14238$at_diff expout $at_stdout || at_failed=:
14239case $at_status in
14240   77) echo 77 > $at_status_file
14241            exit 77;;
14242   0) ;;
14243   *) echo "calc.at:553: exit code was $at_status, expected 0"
14244      at_failed=:;;
14245esac
14246if $at_failed; then
14247
14248  echo 1 > $at_status_file
14249  exit 1
14250fi
14251
14252$at_traceon
14253
14254
14255
14256# Exercise the error token: without it, we die at the first error,
14257# hence be sure to
14258#
14259# - have several errors which exercise different shift/discardings
14260#   - (): nothing to pop, nothing to discard
14261#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
14262#   - (* * *): nothing to pop, a lot to discard
14263#   - (1 + 2 * *): some to pop and discard
14264#
14265# - test the action associated to `error'
14266#
14267# - check the look-ahead that triggers an error is not discarded
14268#   when we enter error recovery.  Below, the look-ahead causing the
14269#   first error is ")", which is needed to recover from the error and
14270#   produce the "0" that triggers the "0 != 1" error.
14271#
14272cat >input <<'_ATEOF'
14273() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
14274_ATEOF
14275
14276$at_traceoff
14277echo "calc.at:553: \$PREPARSER ./calc input"
14278echo calc.at:553 >$at_check_line_file
14279( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
14280at_status=$?
14281grep '^ *+' $at_stder1 >&2
14282grep -v '^ *+' $at_stder1 >$at_stderr
14283at_failed=false
14284echo stderr:; tee stderr <$at_stderr
14285$at_diff $at_devnull $at_stdout || at_failed=:
14286case $at_status in
14287   77) echo 77 > $at_status_file
14288            exit 77;;
14289   0) ;;
14290   *) echo "calc.at:553: exit code was $at_status, expected 0"
14291      at_failed=:;;
14292esac
14293if $at_failed; then
14294
14295  echo 1 > $at_status_file
14296  exit 1
14297fi
14298
14299$at_traceon
14300
14301
14302# Normalize the observed and expected error messages, depending upon the
14303# options.
14304# 1. Remove the traces from observed.
14305sed '/^Starting/d
14306/^Entering/d
14307/^Stack/d
14308/^Reading/d
14309/^Reducing/d
14310/^Shifting/d
14311/^state/d
14312/^Cleanup:/d
14313/^Error:/d
14314/^Next/d
14315/^Discarding/d
14316/ \$[0-9$]* = /d
14317/^yydestructor:/d' stderr >at-stderr
14318mv at-stderr stderr
14319# 2. Create the reference error message.
14320cat >expout <<'_ATEOF'
143211.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
143221.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
143231.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
143241.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
14325calc: error: 4444 != 1
14326_ATEOF
14327
14328# 3. If locations are not used, remove them.
14329
14330# 4. If error-verbose is not used, strip the`, unexpected....' part.
14331sed 's/syntax error, .*$/syntax error/' expout >at-expout
14332mv at-expout expout
14333# 5. Check
14334$at_traceoff
14335echo "calc.at:553: cat stderr"
14336echo calc.at:553 >$at_check_line_file
14337( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
14338at_status=$?
14339grep '^ *+' $at_stder1 >&2
14340grep -v '^ *+' $at_stder1 >$at_stderr
14341at_failed=false
14342$at_diff $at_devnull $at_stderr || at_failed=:
14343$at_diff expout $at_stdout || at_failed=:
14344case $at_status in
14345   77) echo 77 > $at_status_file
14346            exit 77;;
14347   0) ;;
14348   *) echo "calc.at:553: exit code was $at_status, expected 0"
14349      at_failed=:;;
14350esac
14351if $at_failed; then
14352
14353  echo 1 > $at_status_file
14354  exit 1
14355fi
14356
14357$at_traceon
14358
14359
14360
14361# The same, but this time exercising explicitly triggered syntax errors.
14362# POSIX says the look-ahead causing the error should not be discarded.
14363cat >input <<'_ATEOF'
14364(!) + (0 0) = 1
14365_ATEOF
14366
14367$at_traceoff
14368echo "calc.at:553: \$PREPARSER ./calc input"
14369echo calc.at:553 >$at_check_line_file
14370( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
14371at_status=$?
14372grep '^ *+' $at_stder1 >&2
14373grep -v '^ *+' $at_stder1 >$at_stderr
14374at_failed=false
14375echo stderr:; tee stderr <$at_stderr
14376$at_diff $at_devnull $at_stdout || at_failed=:
14377case $at_status in
14378   77) echo 77 > $at_status_file
14379            exit 77;;
14380   0) ;;
14381   *) echo "calc.at:553: exit code was $at_status, expected 0"
14382      at_failed=:;;
14383esac
14384if $at_failed; then
14385
14386  echo 1 > $at_status_file
14387  exit 1
14388fi
14389
14390$at_traceon
14391
14392
14393# Normalize the observed and expected error messages, depending upon the
14394# options.
14395# 1. Remove the traces from observed.
14396sed '/^Starting/d
14397/^Entering/d
14398/^Stack/d
14399/^Reading/d
14400/^Reducing/d
14401/^Shifting/d
14402/^state/d
14403/^Cleanup:/d
14404/^Error:/d
14405/^Next/d
14406/^Discarding/d
14407/ \$[0-9$]* = /d
14408/^yydestructor:/d' stderr >at-stderr
14409mv at-stderr stderr
14410# 2. Create the reference error message.
14411cat >expout <<'_ATEOF'
144121.9: syntax error, unexpected number
14413calc: error: 2222 != 1
14414_ATEOF
14415
14416# 3. If locations are not used, remove them.
14417
14418# 4. If error-verbose is not used, strip the`, unexpected....' part.
14419sed 's/syntax error, .*$/syntax error/' expout >at-expout
14420mv at-expout expout
14421# 5. Check
14422$at_traceoff
14423echo "calc.at:553: cat stderr"
14424echo calc.at:553 >$at_check_line_file
14425( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
14426at_status=$?
14427grep '^ *+' $at_stder1 >&2
14428grep -v '^ *+' $at_stder1 >$at_stderr
14429at_failed=false
14430$at_diff $at_devnull $at_stderr || at_failed=:
14431$at_diff expout $at_stdout || at_failed=:
14432case $at_status in
14433   77) echo 77 > $at_status_file
14434            exit 77;;
14435   0) ;;
14436   *) echo "calc.at:553: exit code was $at_status, expected 0"
14437      at_failed=:;;
14438esac
14439if $at_failed; then
14440
14441  echo 1 > $at_status_file
14442  exit 1
14443fi
14444
14445$at_traceon
14446
14447
14448cat >input <<'_ATEOF'
14449(- *) + (0 0) = 1
14450_ATEOF
14451
14452$at_traceoff
14453echo "calc.at:553: \$PREPARSER ./calc input"
14454echo calc.at:553 >$at_check_line_file
14455( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
14456at_status=$?
14457grep '^ *+' $at_stder1 >&2
14458grep -v '^ *+' $at_stder1 >$at_stderr
14459at_failed=false
14460echo stderr:; tee stderr <$at_stderr
14461$at_diff $at_devnull $at_stdout || at_failed=:
14462case $at_status in
14463   77) echo 77 > $at_status_file
14464            exit 77;;
14465   0) ;;
14466   *) echo "calc.at:553: exit code was $at_status, expected 0"
14467      at_failed=:;;
14468esac
14469if $at_failed; then
14470
14471  echo 1 > $at_status_file
14472  exit 1
14473fi
14474
14475$at_traceon
14476
14477
14478# Normalize the observed and expected error messages, depending upon the
14479# options.
14480# 1. Remove the traces from observed.
14481sed '/^Starting/d
14482/^Entering/d
14483/^Stack/d
14484/^Reading/d
14485/^Reducing/d
14486/^Shifting/d
14487/^state/d
14488/^Cleanup:/d
14489/^Error:/d
14490/^Next/d
14491/^Discarding/d
14492/ \$[0-9$]* = /d
14493/^yydestructor:/d' stderr >at-stderr
14494mv at-stderr stderr
14495# 2. Create the reference error message.
14496cat >expout <<'_ATEOF'
144971.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
144981.11: syntax error, unexpected number
14499calc: error: 2222 != 1
14500_ATEOF
14501
14502# 3. If locations are not used, remove them.
14503
14504# 4. If error-verbose is not used, strip the`, unexpected....' part.
14505sed 's/syntax error, .*$/syntax error/' expout >at-expout
14506mv at-expout expout
14507# 5. Check
14508$at_traceoff
14509echo "calc.at:553: cat stderr"
14510echo calc.at:553 >$at_check_line_file
14511( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
14512at_status=$?
14513grep '^ *+' $at_stder1 >&2
14514grep -v '^ *+' $at_stder1 >$at_stderr
14515at_failed=false
14516$at_diff $at_devnull $at_stderr || at_failed=:
14517$at_diff expout $at_stdout || at_failed=:
14518case $at_status in
14519   77) echo 77 > $at_status_file
14520            exit 77;;
14521   0) ;;
14522   *) echo "calc.at:553: exit code was $at_status, expected 0"
14523      at_failed=:;;
14524esac
14525if $at_failed; then
14526
14527  echo 1 > $at_status_file
14528  exit 1
14529fi
14530
14531$at_traceon
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556      $at_traceoff
14557      $at_times_p && times >$at_times_file
14558    ) 5>&1 2>&1 | eval $at_tee_pipe
14559    at_status=`cat $at_status_file`
14560    ;;
14561
14562  73 ) # 73. calc.at:554: Calculator %name-prefix="calc"
14563    at_setup_line='calc.at:554'
14564    at_desc='Calculator %name-prefix="calc"'
14565    $at_quiet $ECHO_N " 73: Calculator %name-prefix="calc"               $ECHO_C"
14566    at_xfail=no
14567    (
14568      echo "73. calc.at:554: testing ..."
14569      $at_traceon
14570
14571
14572
14573
14574
14575
14576
14577
14578# Using yacc.c?
14579
14580
14581
14582
14583
14584
14585
14586# yyerror receives the location if %location & %pure & (%glr or %parse-param).
14587
14588# yyerror always sees the locations (when activated), except if
14589# yacc & pure & !param.
14590
14591
14592# The interface is pure: either because %pure-parser, or because we
14593# are using the C++ parsers.
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606cat >calc.y <<'_ATEOF'
14607%{
14608#ifdef HAVE_CONFIG_H
14609# include <config.h>
14610  /* We don't need perfect functions for these tests. */
14611# undef malloc
14612# undef memcmp
14613# undef realloc
14614#endif
14615%}
14616
14617/* Infix notation calculator--calc */
14618%name-prefix="calc"
14619
14620%{
14621#include <stdio.h>
14622
14623#include <stdlib.h>
14624#include <string.h>
14625#if HAVE_UNISTD_H
14626# include <unistd.h>
14627#else
14628# undef alarm
14629# define alarm(seconds) /* empty */
14630#endif
14631#include <ctype.h>
14632#define USE(Var)
14633
14634/* Exercise pre-prologue dependency to %union.  */
14635typedef int semantic_value;
14636
14637static semantic_value global_result = 0;
14638static int global_count = 0;
14639%}
14640
14641/* Exercise %union. */
14642%union
14643{
14644  semantic_value ival;
14645};
14646
14647%{
14648static int power (int base, int exponent);
14649/* yyerror receives the location if:
14650   - %location & %pure & %glr
14651   - %location & %pure & %yacc & %parse-param. */
14652static void yyerror (
14653
14654                     const char *s
14655                     );
14656static int yylex (void);
14657static int get_char (void);
14658static void unget_char ( int c);
14659%}
14660
14661
14662
14663/* Bison Declarations */
14664%token CALC_EOF 0 "end of input"
14665%token <ival> NUM "number"
14666%type  <ival> exp
14667
14668%nonassoc '=' /* comparison	       */
14669%left '-' '+'
14670%left '*' '/'
14671%left NEG     /* negation--unary minus */
14672%right '^'    /* exponentiation        */
14673
14674/* Grammar follows */
14675%%
14676input:
14677  line
14678| input line         {  }
14679;
14680
14681line:
14682  '\n'
14683| exp '\n'           { USE ($1); }
14684;
14685
14686exp:
14687  NUM                { $$ = $1;             }
14688| exp '=' exp
14689  {
14690    if ($1 != $3)
14691      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
14692    $$ = $1;
14693  }
14694| exp '+' exp        { $$ = $1 + $3;        }
14695| exp '-' exp        { $$ = $1 - $3;        }
14696| exp '*' exp        { $$ = $1 * $3;        }
14697| exp '/' exp        { $$ = $1 / $3;        }
14698| '-' exp  %prec NEG { $$ = -$2;            }
14699| exp '^' exp        { $$ = power ($1, $3); }
14700| '(' exp ')'        { $$ = $2;             }
14701| '(' error ')'      { $$ = 1111;           }
14702| '!'                { $$ = 0; YYERROR;     }
14703| '-' error          { $$ = 0; YYERROR;     }
14704;
14705%%
14706/* The input.  */
14707static FILE *input;
14708
14709static void
14710yyerror (
14711
14712         const char *s)
14713{
14714
14715
14716  fprintf (stderr, "%s\n", s);
14717}
14718
14719
14720
14721static int
14722get_char (void)
14723{
14724  int res = getc (input);
14725  ;
14726
14727  return res;
14728}
14729
14730
14731static void
14732unget_char ( int c)
14733{
14734  ;
14735
14736  ungetc (c, input);
14737}
14738
14739static int
14740read_signed_integer (void)
14741{
14742  int c = get_char ();
14743  int sign = 1;
14744  int n = 0;
14745
14746  ;
14747  if (c == '-')
14748    {
14749      c = get_char ();
14750      sign = -1;
14751    }
14752
14753  while (isdigit (c))
14754    {
14755      n = 10 * n + (c - '0');
14756      c = get_char ();
14757    }
14758
14759  unget_char ( c);
14760
14761  return sign * n;
14762}
14763
14764
14765
14766/*---------------------------------------------------------------.
14767| Lexical analyzer returns an integer on the stack and the token |
14768| NUM, or the ASCII character read if not a number.  Skips all   |
14769| blanks and tabs, returns 0 for EOF.                            |
14770`---------------------------------------------------------------*/
14771
14772static int
14773yylex (void)
14774{
14775  static int init = 1;
14776  int c;
14777
14778  if (init)
14779    {
14780      init = 0;
14781
14782    }
14783
14784
14785
14786  /* Skip white space.  */
14787  while ((c = get_char ()) == ' ' || c == '\t')
14788    {
14789
14790    }
14791
14792  /* process numbers   */
14793  if (c == '.' || isdigit (c))
14794    {
14795      unget_char ( c);
14796      (yylval).ival = read_signed_integer ();
14797      return NUM;
14798    }
14799
14800  /* Return end-of-file.  */
14801  if (c == EOF)
14802    return CALC_EOF;
14803
14804  /* Return single chars. */
14805  return c;
14806}
14807
14808static int
14809power (int base, int exponent)
14810{
14811  int res = 1;
14812  if (exponent < 0)
14813    exit (3);
14814  for (/* Niente */; exponent; --exponent)
14815    res *= base;
14816  return res;
14817}
14818
14819
14820int
14821main (int argc, const char **argv)
14822{
14823  semantic_value result = 0;
14824  int count = 0;
14825  int status;
14826
14827  /* This used to be alarm (10), but that isn't enough time for
14828     a July 1995 vintage DEC Alphastation 200 4/100 system,
14829     according to Nelson H. F. Beebe.  100 seconds is enough.  */
14830  alarm (100);
14831
14832  if (argc == 2)
14833    input = fopen (argv[1], "r");
14834  else
14835    input = stdin;
14836
14837  if (!input)
14838    {
14839      perror (argv[1]);
14840      return 3;
14841    }
14842
14843
14844  status = yyparse ();
14845  if (global_result != result)
14846    abort ();
14847  if (global_count != count)
14848    abort ();
14849  return status;
14850}
14851_ATEOF
14852
14853
14854
14855
14856
14857$at_traceoff
14858echo "calc.at:554: bison -o calc.c calc.y"
14859echo calc.at:554 >$at_check_line_file
14860( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
14861at_status=$?
14862grep '^ *+' $at_stder1 >&2
14863grep -v '^ *+' $at_stder1 >$at_stderr
14864at_failed=false
14865$at_diff $at_devnull $at_stderr || at_failed=:
14866$at_diff $at_devnull $at_stdout || at_failed=:
14867case $at_status in
14868   77) echo 77 > $at_status_file
14869            exit 77;;
14870   0) ;;
14871   *) echo "calc.at:554: exit code was $at_status, expected 0"
14872      at_failed=:;;
14873esac
14874if $at_failed; then
14875
14876  echo 1 > $at_status_file
14877  exit 1
14878fi
14879
14880$at_traceon
14881
14882   $at_traceoff
14883echo "calc.at:554: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
14884echo calc.at:554 >$at_check_line_file
14885( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
14886at_status=$?
14887grep '^ *+' $at_stder1 >&2
14888grep -v '^ *+' $at_stder1 >$at_stderr
14889at_failed=false
14890echo stderr:; cat $at_stderr
14891echo stdout:; cat $at_stdout
14892case $at_status in
14893   77) echo 77 > $at_status_file
14894            exit 77;;
14895   0) ;;
14896   *) echo "calc.at:554: exit code was $at_status, expected 0"
14897      at_failed=:;;
14898esac
14899if $at_failed; then
14900
14901  echo 1 > $at_status_file
14902  exit 1
14903fi
14904
14905$at_traceon
14906
14907
14908# Test the priorities.
14909cat >input <<'_ATEOF'
149101 + 2 * 3 = 7
149111 + 2 * -3 = -5
14912
14913-1^2 = -1
14914(-1)^2 = 1
14915
14916---1 = -1
14917
149181 - 2 - 3 = -4
149191 - (2 - 3) = 2
14920
149212^2^3 = 256
14922(2^2)^3 = 64
14923_ATEOF
14924
14925$at_traceoff
14926echo "calc.at:554: \$PREPARSER ./calc input"
14927echo calc.at:554 >$at_check_line_file
14928( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
14929at_status=$?
14930grep '^ *+' $at_stder1 >&2
14931grep -v '^ *+' $at_stder1 >$at_stderr
14932at_failed=false
14933echo stderr:; tee stderr <$at_stderr
14934$at_diff $at_devnull $at_stdout || at_failed=:
14935case $at_status in
14936   77) echo 77 > $at_status_file
14937            exit 77;;
14938   0) ;;
14939   *) echo "calc.at:554: exit code was $at_status, expected 0"
14940      at_failed=:;;
14941esac
14942if $at_failed; then
14943
14944  echo 1 > $at_status_file
14945  exit 1
14946fi
14947
14948$at_traceon
14949
14950
14951
14952# Some syntax errors.
14953cat >input <<'_ATEOF'
149540 0
14955_ATEOF
14956
14957$at_traceoff
14958echo "calc.at:554: \$PREPARSER ./calc input"
14959echo calc.at:554 >$at_check_line_file
14960( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
14961at_status=$?
14962grep '^ *+' $at_stder1 >&2
14963grep -v '^ *+' $at_stder1 >$at_stderr
14964at_failed=false
14965echo stderr:; tee stderr <$at_stderr
14966$at_diff $at_devnull $at_stdout || at_failed=:
14967case $at_status in
14968   77) echo 77 > $at_status_file
14969            exit 77;;
14970   1) ;;
14971   *) echo "calc.at:554: exit code was $at_status, expected 1"
14972      at_failed=:;;
14973esac
14974if $at_failed; then
14975
14976  echo 1 > $at_status_file
14977  exit 1
14978fi
14979
14980$at_traceon
14981
14982
14983# Normalize the observed and expected error messages, depending upon the
14984# options.
14985# 1. Remove the traces from observed.
14986sed '/^Starting/d
14987/^Entering/d
14988/^Stack/d
14989/^Reading/d
14990/^Reducing/d
14991/^Shifting/d
14992/^state/d
14993/^Cleanup:/d
14994/^Error:/d
14995/^Next/d
14996/^Discarding/d
14997/ \$[0-9$]* = /d
14998/^yydestructor:/d' stderr >at-stderr
14999mv at-stderr stderr
15000# 2. Create the reference error message.
15001cat >expout <<'_ATEOF'
150021.2: syntax error, unexpected number
15003_ATEOF
15004
15005# 3. If locations are not used, remove them.
15006sed 's/^[-0-9.]*: //' expout >at-expout
15007mv at-expout expout
15008# 4. If error-verbose is not used, strip the`, unexpected....' part.
15009sed 's/syntax error, .*$/syntax error/' expout >at-expout
15010mv at-expout expout
15011# 5. Check
15012$at_traceoff
15013echo "calc.at:554: cat stderr"
15014echo calc.at:554 >$at_check_line_file
15015( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
15016at_status=$?
15017grep '^ *+' $at_stder1 >&2
15018grep -v '^ *+' $at_stder1 >$at_stderr
15019at_failed=false
15020$at_diff $at_devnull $at_stderr || at_failed=:
15021$at_diff expout $at_stdout || at_failed=:
15022case $at_status in
15023   77) echo 77 > $at_status_file
15024            exit 77;;
15025   0) ;;
15026   *) echo "calc.at:554: exit code was $at_status, expected 0"
15027      at_failed=:;;
15028esac
15029if $at_failed; then
15030
15031  echo 1 > $at_status_file
15032  exit 1
15033fi
15034
15035$at_traceon
15036
15037
15038cat >input <<'_ATEOF'
150391//2
15040_ATEOF
15041
15042$at_traceoff
15043echo "calc.at:554: \$PREPARSER ./calc input"
15044echo calc.at:554 >$at_check_line_file
15045( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
15046at_status=$?
15047grep '^ *+' $at_stder1 >&2
15048grep -v '^ *+' $at_stder1 >$at_stderr
15049at_failed=false
15050echo stderr:; tee stderr <$at_stderr
15051$at_diff $at_devnull $at_stdout || at_failed=:
15052case $at_status in
15053   77) echo 77 > $at_status_file
15054            exit 77;;
15055   1) ;;
15056   *) echo "calc.at:554: exit code was $at_status, expected 1"
15057      at_failed=:;;
15058esac
15059if $at_failed; then
15060
15061  echo 1 > $at_status_file
15062  exit 1
15063fi
15064
15065$at_traceon
15066
15067
15068# Normalize the observed and expected error messages, depending upon the
15069# options.
15070# 1. Remove the traces from observed.
15071sed '/^Starting/d
15072/^Entering/d
15073/^Stack/d
15074/^Reading/d
15075/^Reducing/d
15076/^Shifting/d
15077/^state/d
15078/^Cleanup:/d
15079/^Error:/d
15080/^Next/d
15081/^Discarding/d
15082/ \$[0-9$]* = /d
15083/^yydestructor:/d' stderr >at-stderr
15084mv at-stderr stderr
15085# 2. Create the reference error message.
15086cat >expout <<'_ATEOF'
150871.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
15088_ATEOF
15089
15090# 3. If locations are not used, remove them.
15091sed 's/^[-0-9.]*: //' expout >at-expout
15092mv at-expout expout
15093# 4. If error-verbose is not used, strip the`, unexpected....' part.
15094sed 's/syntax error, .*$/syntax error/' expout >at-expout
15095mv at-expout expout
15096# 5. Check
15097$at_traceoff
15098echo "calc.at:554: cat stderr"
15099echo calc.at:554 >$at_check_line_file
15100( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
15101at_status=$?
15102grep '^ *+' $at_stder1 >&2
15103grep -v '^ *+' $at_stder1 >$at_stderr
15104at_failed=false
15105$at_diff $at_devnull $at_stderr || at_failed=:
15106$at_diff expout $at_stdout || at_failed=:
15107case $at_status in
15108   77) echo 77 > $at_status_file
15109            exit 77;;
15110   0) ;;
15111   *) echo "calc.at:554: exit code was $at_status, expected 0"
15112      at_failed=:;;
15113esac
15114if $at_failed; then
15115
15116  echo 1 > $at_status_file
15117  exit 1
15118fi
15119
15120$at_traceon
15121
15122
15123cat >input <<'_ATEOF'
15124error
15125_ATEOF
15126
15127$at_traceoff
15128echo "calc.at:554: \$PREPARSER ./calc input"
15129echo calc.at:554 >$at_check_line_file
15130( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
15131at_status=$?
15132grep '^ *+' $at_stder1 >&2
15133grep -v '^ *+' $at_stder1 >$at_stderr
15134at_failed=false
15135echo stderr:; tee stderr <$at_stderr
15136$at_diff $at_devnull $at_stdout || at_failed=:
15137case $at_status in
15138   77) echo 77 > $at_status_file
15139            exit 77;;
15140   1) ;;
15141   *) echo "calc.at:554: exit code was $at_status, expected 1"
15142      at_failed=:;;
15143esac
15144if $at_failed; then
15145
15146  echo 1 > $at_status_file
15147  exit 1
15148fi
15149
15150$at_traceon
15151
15152
15153# Normalize the observed and expected error messages, depending upon the
15154# options.
15155# 1. Remove the traces from observed.
15156sed '/^Starting/d
15157/^Entering/d
15158/^Stack/d
15159/^Reading/d
15160/^Reducing/d
15161/^Shifting/d
15162/^state/d
15163/^Cleanup:/d
15164/^Error:/d
15165/^Next/d
15166/^Discarding/d
15167/ \$[0-9$]* = /d
15168/^yydestructor:/d' stderr >at-stderr
15169mv at-stderr stderr
15170# 2. Create the reference error message.
15171cat >expout <<'_ATEOF'
151721.0: syntax error, unexpected $undefined
15173_ATEOF
15174
15175# 3. If locations are not used, remove them.
15176sed 's/^[-0-9.]*: //' expout >at-expout
15177mv at-expout expout
15178# 4. If error-verbose is not used, strip the`, unexpected....' part.
15179sed 's/syntax error, .*$/syntax error/' expout >at-expout
15180mv at-expout expout
15181# 5. Check
15182$at_traceoff
15183echo "calc.at:554: cat stderr"
15184echo calc.at:554 >$at_check_line_file
15185( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
15186at_status=$?
15187grep '^ *+' $at_stder1 >&2
15188grep -v '^ *+' $at_stder1 >$at_stderr
15189at_failed=false
15190$at_diff $at_devnull $at_stderr || at_failed=:
15191$at_diff expout $at_stdout || at_failed=:
15192case $at_status in
15193   77) echo 77 > $at_status_file
15194            exit 77;;
15195   0) ;;
15196   *) echo "calc.at:554: exit code was $at_status, expected 0"
15197      at_failed=:;;
15198esac
15199if $at_failed; then
15200
15201  echo 1 > $at_status_file
15202  exit 1
15203fi
15204
15205$at_traceon
15206
15207
15208cat >input <<'_ATEOF'
152091 = 2 = 3
15210_ATEOF
15211
15212$at_traceoff
15213echo "calc.at:554: \$PREPARSER ./calc input"
15214echo calc.at:554 >$at_check_line_file
15215( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
15216at_status=$?
15217grep '^ *+' $at_stder1 >&2
15218grep -v '^ *+' $at_stder1 >$at_stderr
15219at_failed=false
15220echo stderr:; tee stderr <$at_stderr
15221$at_diff $at_devnull $at_stdout || at_failed=:
15222case $at_status in
15223   77) echo 77 > $at_status_file
15224            exit 77;;
15225   1) ;;
15226   *) echo "calc.at:554: exit code was $at_status, expected 1"
15227      at_failed=:;;
15228esac
15229if $at_failed; then
15230
15231  echo 1 > $at_status_file
15232  exit 1
15233fi
15234
15235$at_traceon
15236
15237
15238# Normalize the observed and expected error messages, depending upon the
15239# options.
15240# 1. Remove the traces from observed.
15241sed '/^Starting/d
15242/^Entering/d
15243/^Stack/d
15244/^Reading/d
15245/^Reducing/d
15246/^Shifting/d
15247/^state/d
15248/^Cleanup:/d
15249/^Error:/d
15250/^Next/d
15251/^Discarding/d
15252/ \$[0-9$]* = /d
15253/^yydestructor:/d' stderr >at-stderr
15254mv at-stderr stderr
15255# 2. Create the reference error message.
15256cat >expout <<'_ATEOF'
152571.6: syntax error, unexpected '='
15258_ATEOF
15259
15260# 3. If locations are not used, remove them.
15261sed 's/^[-0-9.]*: //' expout >at-expout
15262mv at-expout expout
15263# 4. If error-verbose is not used, strip the`, unexpected....' part.
15264sed 's/syntax error, .*$/syntax error/' expout >at-expout
15265mv at-expout expout
15266# 5. Check
15267$at_traceoff
15268echo "calc.at:554: cat stderr"
15269echo calc.at:554 >$at_check_line_file
15270( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
15271at_status=$?
15272grep '^ *+' $at_stder1 >&2
15273grep -v '^ *+' $at_stder1 >$at_stderr
15274at_failed=false
15275$at_diff $at_devnull $at_stderr || at_failed=:
15276$at_diff expout $at_stdout || at_failed=:
15277case $at_status in
15278   77) echo 77 > $at_status_file
15279            exit 77;;
15280   0) ;;
15281   *) echo "calc.at:554: exit code was $at_status, expected 0"
15282      at_failed=:;;
15283esac
15284if $at_failed; then
15285
15286  echo 1 > $at_status_file
15287  exit 1
15288fi
15289
15290$at_traceon
15291
15292
15293cat >input <<'_ATEOF'
15294
15295+1
15296_ATEOF
15297
15298$at_traceoff
15299echo "calc.at:554: \$PREPARSER ./calc input"
15300echo calc.at:554 >$at_check_line_file
15301( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
15302at_status=$?
15303grep '^ *+' $at_stder1 >&2
15304grep -v '^ *+' $at_stder1 >$at_stderr
15305at_failed=false
15306echo stderr:; tee stderr <$at_stderr
15307$at_diff $at_devnull $at_stdout || at_failed=:
15308case $at_status in
15309   77) echo 77 > $at_status_file
15310            exit 77;;
15311   1) ;;
15312   *) echo "calc.at:554: exit code was $at_status, expected 1"
15313      at_failed=:;;
15314esac
15315if $at_failed; then
15316
15317  echo 1 > $at_status_file
15318  exit 1
15319fi
15320
15321$at_traceon
15322
15323
15324# Normalize the observed and expected error messages, depending upon the
15325# options.
15326# 1. Remove the traces from observed.
15327sed '/^Starting/d
15328/^Entering/d
15329/^Stack/d
15330/^Reading/d
15331/^Reducing/d
15332/^Shifting/d
15333/^state/d
15334/^Cleanup:/d
15335/^Error:/d
15336/^Next/d
15337/^Discarding/d
15338/ \$[0-9$]* = /d
15339/^yydestructor:/d' stderr >at-stderr
15340mv at-stderr stderr
15341# 2. Create the reference error message.
15342cat >expout <<'_ATEOF'
153432.0: syntax error, unexpected '+'
15344_ATEOF
15345
15346# 3. If locations are not used, remove them.
15347sed 's/^[-0-9.]*: //' expout >at-expout
15348mv at-expout expout
15349# 4. If error-verbose is not used, strip the`, unexpected....' part.
15350sed 's/syntax error, .*$/syntax error/' expout >at-expout
15351mv at-expout expout
15352# 5. Check
15353$at_traceoff
15354echo "calc.at:554: cat stderr"
15355echo calc.at:554 >$at_check_line_file
15356( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
15357at_status=$?
15358grep '^ *+' $at_stder1 >&2
15359grep -v '^ *+' $at_stder1 >$at_stderr
15360at_failed=false
15361$at_diff $at_devnull $at_stderr || at_failed=:
15362$at_diff expout $at_stdout || at_failed=:
15363case $at_status in
15364   77) echo 77 > $at_status_file
15365            exit 77;;
15366   0) ;;
15367   *) echo "calc.at:554: exit code was $at_status, expected 0"
15368      at_failed=:;;
15369esac
15370if $at_failed; then
15371
15372  echo 1 > $at_status_file
15373  exit 1
15374fi
15375
15376$at_traceon
15377
15378
15379# Exercise error messages with EOF: work on an empty file.
15380$at_traceoff
15381echo "calc.at:554: \$PREPARSER ./calc /dev/null"
15382echo calc.at:554 >$at_check_line_file
15383( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
15384at_status=$?
15385grep '^ *+' $at_stder1 >&2
15386grep -v '^ *+' $at_stder1 >$at_stderr
15387at_failed=false
15388echo stderr:; tee stderr <$at_stderr
15389$at_diff $at_devnull $at_stdout || at_failed=:
15390case $at_status in
15391   77) echo 77 > $at_status_file
15392            exit 77;;
15393   1) ;;
15394   *) echo "calc.at:554: exit code was $at_status, expected 1"
15395      at_failed=:;;
15396esac
15397if $at_failed; then
15398
15399  echo 1 > $at_status_file
15400  exit 1
15401fi
15402
15403$at_traceon
15404
15405
15406# Normalize the observed and expected error messages, depending upon the
15407# options.
15408# 1. Remove the traces from observed.
15409sed '/^Starting/d
15410/^Entering/d
15411/^Stack/d
15412/^Reading/d
15413/^Reducing/d
15414/^Shifting/d
15415/^state/d
15416/^Cleanup:/d
15417/^Error:/d
15418/^Next/d
15419/^Discarding/d
15420/ \$[0-9$]* = /d
15421/^yydestructor:/d' stderr >at-stderr
15422mv at-stderr stderr
15423# 2. Create the reference error message.
15424cat >expout <<'_ATEOF'
154251.0: syntax error, unexpected end of input
15426_ATEOF
15427
15428# 3. If locations are not used, remove them.
15429sed 's/^[-0-9.]*: //' expout >at-expout
15430mv at-expout expout
15431# 4. If error-verbose is not used, strip the`, unexpected....' part.
15432sed 's/syntax error, .*$/syntax error/' expout >at-expout
15433mv at-expout expout
15434# 5. Check
15435$at_traceoff
15436echo "calc.at:554: cat stderr"
15437echo calc.at:554 >$at_check_line_file
15438( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
15439at_status=$?
15440grep '^ *+' $at_stder1 >&2
15441grep -v '^ *+' $at_stder1 >$at_stderr
15442at_failed=false
15443$at_diff $at_devnull $at_stderr || at_failed=:
15444$at_diff expout $at_stdout || at_failed=:
15445case $at_status in
15446   77) echo 77 > $at_status_file
15447            exit 77;;
15448   0) ;;
15449   *) echo "calc.at:554: exit code was $at_status, expected 0"
15450      at_failed=:;;
15451esac
15452if $at_failed; then
15453
15454  echo 1 > $at_status_file
15455  exit 1
15456fi
15457
15458$at_traceon
15459
15460
15461
15462# Exercise the error token: without it, we die at the first error,
15463# hence be sure to
15464#
15465# - have several errors which exercise different shift/discardings
15466#   - (): nothing to pop, nothing to discard
15467#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
15468#   - (* * *): nothing to pop, a lot to discard
15469#   - (1 + 2 * *): some to pop and discard
15470#
15471# - test the action associated to `error'
15472#
15473# - check the look-ahead that triggers an error is not discarded
15474#   when we enter error recovery.  Below, the look-ahead causing the
15475#   first error is ")", which is needed to recover from the error and
15476#   produce the "0" that triggers the "0 != 1" error.
15477#
15478cat >input <<'_ATEOF'
15479() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
15480_ATEOF
15481
15482$at_traceoff
15483echo "calc.at:554: \$PREPARSER ./calc input"
15484echo calc.at:554 >$at_check_line_file
15485( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
15486at_status=$?
15487grep '^ *+' $at_stder1 >&2
15488grep -v '^ *+' $at_stder1 >$at_stderr
15489at_failed=false
15490echo stderr:; tee stderr <$at_stderr
15491$at_diff $at_devnull $at_stdout || at_failed=:
15492case $at_status in
15493   77) echo 77 > $at_status_file
15494            exit 77;;
15495   0) ;;
15496   *) echo "calc.at:554: exit code was $at_status, expected 0"
15497      at_failed=:;;
15498esac
15499if $at_failed; then
15500
15501  echo 1 > $at_status_file
15502  exit 1
15503fi
15504
15505$at_traceon
15506
15507
15508# Normalize the observed and expected error messages, depending upon the
15509# options.
15510# 1. Remove the traces from observed.
15511sed '/^Starting/d
15512/^Entering/d
15513/^Stack/d
15514/^Reading/d
15515/^Reducing/d
15516/^Shifting/d
15517/^state/d
15518/^Cleanup:/d
15519/^Error:/d
15520/^Next/d
15521/^Discarding/d
15522/ \$[0-9$]* = /d
15523/^yydestructor:/d' stderr >at-stderr
15524mv at-stderr stderr
15525# 2. Create the reference error message.
15526cat >expout <<'_ATEOF'
155271.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
155281.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
155291.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
155301.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
15531calc: error: 4444 != 1
15532_ATEOF
15533
15534# 3. If locations are not used, remove them.
15535sed 's/^[-0-9.]*: //' expout >at-expout
15536mv at-expout expout
15537# 4. If error-verbose is not used, strip the`, unexpected....' part.
15538sed 's/syntax error, .*$/syntax error/' expout >at-expout
15539mv at-expout expout
15540# 5. Check
15541$at_traceoff
15542echo "calc.at:554: cat stderr"
15543echo calc.at:554 >$at_check_line_file
15544( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
15545at_status=$?
15546grep '^ *+' $at_stder1 >&2
15547grep -v '^ *+' $at_stder1 >$at_stderr
15548at_failed=false
15549$at_diff $at_devnull $at_stderr || at_failed=:
15550$at_diff expout $at_stdout || at_failed=:
15551case $at_status in
15552   77) echo 77 > $at_status_file
15553            exit 77;;
15554   0) ;;
15555   *) echo "calc.at:554: exit code was $at_status, expected 0"
15556      at_failed=:;;
15557esac
15558if $at_failed; then
15559
15560  echo 1 > $at_status_file
15561  exit 1
15562fi
15563
15564$at_traceon
15565
15566
15567
15568# The same, but this time exercising explicitly triggered syntax errors.
15569# POSIX says the look-ahead causing the error should not be discarded.
15570cat >input <<'_ATEOF'
15571(!) + (0 0) = 1
15572_ATEOF
15573
15574$at_traceoff
15575echo "calc.at:554: \$PREPARSER ./calc input"
15576echo calc.at:554 >$at_check_line_file
15577( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
15578at_status=$?
15579grep '^ *+' $at_stder1 >&2
15580grep -v '^ *+' $at_stder1 >$at_stderr
15581at_failed=false
15582echo stderr:; tee stderr <$at_stderr
15583$at_diff $at_devnull $at_stdout || at_failed=:
15584case $at_status in
15585   77) echo 77 > $at_status_file
15586            exit 77;;
15587   0) ;;
15588   *) echo "calc.at:554: exit code was $at_status, expected 0"
15589      at_failed=:;;
15590esac
15591if $at_failed; then
15592
15593  echo 1 > $at_status_file
15594  exit 1
15595fi
15596
15597$at_traceon
15598
15599
15600# Normalize the observed and expected error messages, depending upon the
15601# options.
15602# 1. Remove the traces from observed.
15603sed '/^Starting/d
15604/^Entering/d
15605/^Stack/d
15606/^Reading/d
15607/^Reducing/d
15608/^Shifting/d
15609/^state/d
15610/^Cleanup:/d
15611/^Error:/d
15612/^Next/d
15613/^Discarding/d
15614/ \$[0-9$]* = /d
15615/^yydestructor:/d' stderr >at-stderr
15616mv at-stderr stderr
15617# 2. Create the reference error message.
15618cat >expout <<'_ATEOF'
156191.9: syntax error, unexpected number
15620calc: error: 2222 != 1
15621_ATEOF
15622
15623# 3. If locations are not used, remove them.
15624sed 's/^[-0-9.]*: //' expout >at-expout
15625mv at-expout expout
15626# 4. If error-verbose is not used, strip the`, unexpected....' part.
15627sed 's/syntax error, .*$/syntax error/' expout >at-expout
15628mv at-expout expout
15629# 5. Check
15630$at_traceoff
15631echo "calc.at:554: cat stderr"
15632echo calc.at:554 >$at_check_line_file
15633( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
15634at_status=$?
15635grep '^ *+' $at_stder1 >&2
15636grep -v '^ *+' $at_stder1 >$at_stderr
15637at_failed=false
15638$at_diff $at_devnull $at_stderr || at_failed=:
15639$at_diff expout $at_stdout || at_failed=:
15640case $at_status in
15641   77) echo 77 > $at_status_file
15642            exit 77;;
15643   0) ;;
15644   *) echo "calc.at:554: exit code was $at_status, expected 0"
15645      at_failed=:;;
15646esac
15647if $at_failed; then
15648
15649  echo 1 > $at_status_file
15650  exit 1
15651fi
15652
15653$at_traceon
15654
15655
15656cat >input <<'_ATEOF'
15657(- *) + (0 0) = 1
15658_ATEOF
15659
15660$at_traceoff
15661echo "calc.at:554: \$PREPARSER ./calc input"
15662echo calc.at:554 >$at_check_line_file
15663( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
15664at_status=$?
15665grep '^ *+' $at_stder1 >&2
15666grep -v '^ *+' $at_stder1 >$at_stderr
15667at_failed=false
15668echo stderr:; tee stderr <$at_stderr
15669$at_diff $at_devnull $at_stdout || at_failed=:
15670case $at_status in
15671   77) echo 77 > $at_status_file
15672            exit 77;;
15673   0) ;;
15674   *) echo "calc.at:554: exit code was $at_status, expected 0"
15675      at_failed=:;;
15676esac
15677if $at_failed; then
15678
15679  echo 1 > $at_status_file
15680  exit 1
15681fi
15682
15683$at_traceon
15684
15685
15686# Normalize the observed and expected error messages, depending upon the
15687# options.
15688# 1. Remove the traces from observed.
15689sed '/^Starting/d
15690/^Entering/d
15691/^Stack/d
15692/^Reading/d
15693/^Reducing/d
15694/^Shifting/d
15695/^state/d
15696/^Cleanup:/d
15697/^Error:/d
15698/^Next/d
15699/^Discarding/d
15700/ \$[0-9$]* = /d
15701/^yydestructor:/d' stderr >at-stderr
15702mv at-stderr stderr
15703# 2. Create the reference error message.
15704cat >expout <<'_ATEOF'
157051.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
157061.11: syntax error, unexpected number
15707calc: error: 2222 != 1
15708_ATEOF
15709
15710# 3. If locations are not used, remove them.
15711sed 's/^[-0-9.]*: //' expout >at-expout
15712mv at-expout expout
15713# 4. If error-verbose is not used, strip the`, unexpected....' part.
15714sed 's/syntax error, .*$/syntax error/' expout >at-expout
15715mv at-expout expout
15716# 5. Check
15717$at_traceoff
15718echo "calc.at:554: cat stderr"
15719echo calc.at:554 >$at_check_line_file
15720( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
15721at_status=$?
15722grep '^ *+' $at_stder1 >&2
15723grep -v '^ *+' $at_stder1 >$at_stderr
15724at_failed=false
15725$at_diff $at_devnull $at_stderr || at_failed=:
15726$at_diff expout $at_stdout || at_failed=:
15727case $at_status in
15728   77) echo 77 > $at_status_file
15729            exit 77;;
15730   0) ;;
15731   *) echo "calc.at:554: exit code was $at_status, expected 0"
15732      at_failed=:;;
15733esac
15734if $at_failed; then
15735
15736  echo 1 > $at_status_file
15737  exit 1
15738fi
15739
15740$at_traceon
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765      $at_traceoff
15766      $at_times_p && times >$at_times_file
15767    ) 5>&1 2>&1 | eval $at_tee_pipe
15768    at_status=`cat $at_status_file`
15769    ;;
15770
15771  74 ) # 74. calc.at:555: Calculator %verbose
15772    at_setup_line='calc.at:555'
15773    at_desc='Calculator %verbose'
15774    $at_quiet $ECHO_N " 74: Calculator %verbose                          $ECHO_C"
15775    at_xfail=no
15776    (
15777      echo "74. calc.at:555: testing ..."
15778      $at_traceon
15779
15780
15781
15782
15783
15784
15785
15786
15787# Using yacc.c?
15788
15789
15790
15791
15792
15793
15794
15795# yyerror receives the location if %location & %pure & (%glr or %parse-param).
15796
15797# yyerror always sees the locations (when activated), except if
15798# yacc & pure & !param.
15799
15800
15801# The interface is pure: either because %pure-parser, or because we
15802# are using the C++ parsers.
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815cat >calc.y <<'_ATEOF'
15816%{
15817#ifdef HAVE_CONFIG_H
15818# include <config.h>
15819  /* We don't need perfect functions for these tests. */
15820# undef malloc
15821# undef memcmp
15822# undef realloc
15823#endif
15824%}
15825
15826/* Infix notation calculator--calc */
15827%verbose
15828
15829%{
15830#include <stdio.h>
15831
15832#include <stdlib.h>
15833#include <string.h>
15834#if HAVE_UNISTD_H
15835# include <unistd.h>
15836#else
15837# undef alarm
15838# define alarm(seconds) /* empty */
15839#endif
15840#include <ctype.h>
15841#define USE(Var)
15842
15843/* Exercise pre-prologue dependency to %union.  */
15844typedef int semantic_value;
15845
15846static semantic_value global_result = 0;
15847static int global_count = 0;
15848%}
15849
15850/* Exercise %union. */
15851%union
15852{
15853  semantic_value ival;
15854};
15855
15856%{
15857static int power (int base, int exponent);
15858/* yyerror receives the location if:
15859   - %location & %pure & %glr
15860   - %location & %pure & %yacc & %parse-param. */
15861static void yyerror (
15862
15863                     const char *s
15864                     );
15865static int yylex (void);
15866static int get_char (void);
15867static void unget_char ( int c);
15868%}
15869
15870
15871
15872/* Bison Declarations */
15873%token CALC_EOF 0 "end of input"
15874%token <ival> NUM "number"
15875%type  <ival> exp
15876
15877%nonassoc '=' /* comparison	       */
15878%left '-' '+'
15879%left '*' '/'
15880%left NEG     /* negation--unary minus */
15881%right '^'    /* exponentiation        */
15882
15883/* Grammar follows */
15884%%
15885input:
15886  line
15887| input line         {  }
15888;
15889
15890line:
15891  '\n'
15892| exp '\n'           { USE ($1); }
15893;
15894
15895exp:
15896  NUM                { $$ = $1;             }
15897| exp '=' exp
15898  {
15899    if ($1 != $3)
15900      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
15901    $$ = $1;
15902  }
15903| exp '+' exp        { $$ = $1 + $3;        }
15904| exp '-' exp        { $$ = $1 - $3;        }
15905| exp '*' exp        { $$ = $1 * $3;        }
15906| exp '/' exp        { $$ = $1 / $3;        }
15907| '-' exp  %prec NEG { $$ = -$2;            }
15908| exp '^' exp        { $$ = power ($1, $3); }
15909| '(' exp ')'        { $$ = $2;             }
15910| '(' error ')'      { $$ = 1111;           }
15911| '!'                { $$ = 0; YYERROR;     }
15912| '-' error          { $$ = 0; YYERROR;     }
15913;
15914%%
15915/* The input.  */
15916static FILE *input;
15917
15918static void
15919yyerror (
15920
15921         const char *s)
15922{
15923
15924
15925  fprintf (stderr, "%s\n", s);
15926}
15927
15928
15929
15930static int
15931get_char (void)
15932{
15933  int res = getc (input);
15934  ;
15935
15936  return res;
15937}
15938
15939
15940static void
15941unget_char ( int c)
15942{
15943  ;
15944
15945  ungetc (c, input);
15946}
15947
15948static int
15949read_signed_integer (void)
15950{
15951  int c = get_char ();
15952  int sign = 1;
15953  int n = 0;
15954
15955  ;
15956  if (c == '-')
15957    {
15958      c = get_char ();
15959      sign = -1;
15960    }
15961
15962  while (isdigit (c))
15963    {
15964      n = 10 * n + (c - '0');
15965      c = get_char ();
15966    }
15967
15968  unget_char ( c);
15969
15970  return sign * n;
15971}
15972
15973
15974
15975/*---------------------------------------------------------------.
15976| Lexical analyzer returns an integer on the stack and the token |
15977| NUM, or the ASCII character read if not a number.  Skips all   |
15978| blanks and tabs, returns 0 for EOF.                            |
15979`---------------------------------------------------------------*/
15980
15981static int
15982yylex (void)
15983{
15984  static int init = 1;
15985  int c;
15986
15987  if (init)
15988    {
15989      init = 0;
15990
15991    }
15992
15993
15994
15995  /* Skip white space.  */
15996  while ((c = get_char ()) == ' ' || c == '\t')
15997    {
15998
15999    }
16000
16001  /* process numbers   */
16002  if (c == '.' || isdigit (c))
16003    {
16004      unget_char ( c);
16005      (yylval).ival = read_signed_integer ();
16006      return NUM;
16007    }
16008
16009  /* Return end-of-file.  */
16010  if (c == EOF)
16011    return CALC_EOF;
16012
16013  /* Return single chars. */
16014  return c;
16015}
16016
16017static int
16018power (int base, int exponent)
16019{
16020  int res = 1;
16021  if (exponent < 0)
16022    exit (3);
16023  for (/* Niente */; exponent; --exponent)
16024    res *= base;
16025  return res;
16026}
16027
16028
16029int
16030main (int argc, const char **argv)
16031{
16032  semantic_value result = 0;
16033  int count = 0;
16034  int status;
16035
16036  /* This used to be alarm (10), but that isn't enough time for
16037     a July 1995 vintage DEC Alphastation 200 4/100 system,
16038     according to Nelson H. F. Beebe.  100 seconds is enough.  */
16039  alarm (100);
16040
16041  if (argc == 2)
16042    input = fopen (argv[1], "r");
16043  else
16044    input = stdin;
16045
16046  if (!input)
16047    {
16048      perror (argv[1]);
16049      return 3;
16050    }
16051
16052
16053  status = yyparse ();
16054  if (global_result != result)
16055    abort ();
16056  if (global_count != count)
16057    abort ();
16058  return status;
16059}
16060_ATEOF
16061
16062
16063
16064
16065
16066$at_traceoff
16067echo "calc.at:555: bison -o calc.c calc.y"
16068echo calc.at:555 >$at_check_line_file
16069( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
16070at_status=$?
16071grep '^ *+' $at_stder1 >&2
16072grep -v '^ *+' $at_stder1 >$at_stderr
16073at_failed=false
16074$at_diff $at_devnull $at_stderr || at_failed=:
16075$at_diff $at_devnull $at_stdout || at_failed=:
16076case $at_status in
16077   77) echo 77 > $at_status_file
16078            exit 77;;
16079   0) ;;
16080   *) echo "calc.at:555: exit code was $at_status, expected 0"
16081      at_failed=:;;
16082esac
16083if $at_failed; then
16084
16085  echo 1 > $at_status_file
16086  exit 1
16087fi
16088
16089$at_traceon
16090
16091   $at_traceoff
16092echo "calc.at:555: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
16093echo calc.at:555 >$at_check_line_file
16094( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
16095at_status=$?
16096grep '^ *+' $at_stder1 >&2
16097grep -v '^ *+' $at_stder1 >$at_stderr
16098at_failed=false
16099echo stderr:; cat $at_stderr
16100echo stdout:; cat $at_stdout
16101case $at_status in
16102   77) echo 77 > $at_status_file
16103            exit 77;;
16104   0) ;;
16105   *) echo "calc.at:555: exit code was $at_status, expected 0"
16106      at_failed=:;;
16107esac
16108if $at_failed; then
16109
16110  echo 1 > $at_status_file
16111  exit 1
16112fi
16113
16114$at_traceon
16115
16116
16117# Test the priorities.
16118cat >input <<'_ATEOF'
161191 + 2 * 3 = 7
161201 + 2 * -3 = -5
16121
16122-1^2 = -1
16123(-1)^2 = 1
16124
16125---1 = -1
16126
161271 - 2 - 3 = -4
161281 - (2 - 3) = 2
16129
161302^2^3 = 256
16131(2^2)^3 = 64
16132_ATEOF
16133
16134$at_traceoff
16135echo "calc.at:555: \$PREPARSER ./calc input"
16136echo calc.at:555 >$at_check_line_file
16137( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
16138at_status=$?
16139grep '^ *+' $at_stder1 >&2
16140grep -v '^ *+' $at_stder1 >$at_stderr
16141at_failed=false
16142echo stderr:; tee stderr <$at_stderr
16143$at_diff $at_devnull $at_stdout || at_failed=:
16144case $at_status in
16145   77) echo 77 > $at_status_file
16146            exit 77;;
16147   0) ;;
16148   *) echo "calc.at:555: exit code was $at_status, expected 0"
16149      at_failed=:;;
16150esac
16151if $at_failed; then
16152
16153  echo 1 > $at_status_file
16154  exit 1
16155fi
16156
16157$at_traceon
16158
16159
16160
16161# Some syntax errors.
16162cat >input <<'_ATEOF'
161630 0
16164_ATEOF
16165
16166$at_traceoff
16167echo "calc.at:555: \$PREPARSER ./calc input"
16168echo calc.at:555 >$at_check_line_file
16169( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
16170at_status=$?
16171grep '^ *+' $at_stder1 >&2
16172grep -v '^ *+' $at_stder1 >$at_stderr
16173at_failed=false
16174echo stderr:; tee stderr <$at_stderr
16175$at_diff $at_devnull $at_stdout || at_failed=:
16176case $at_status in
16177   77) echo 77 > $at_status_file
16178            exit 77;;
16179   1) ;;
16180   *) echo "calc.at:555: exit code was $at_status, expected 1"
16181      at_failed=:;;
16182esac
16183if $at_failed; then
16184
16185  echo 1 > $at_status_file
16186  exit 1
16187fi
16188
16189$at_traceon
16190
16191
16192# Normalize the observed and expected error messages, depending upon the
16193# options.
16194# 1. Remove the traces from observed.
16195sed '/^Starting/d
16196/^Entering/d
16197/^Stack/d
16198/^Reading/d
16199/^Reducing/d
16200/^Shifting/d
16201/^state/d
16202/^Cleanup:/d
16203/^Error:/d
16204/^Next/d
16205/^Discarding/d
16206/ \$[0-9$]* = /d
16207/^yydestructor:/d' stderr >at-stderr
16208mv at-stderr stderr
16209# 2. Create the reference error message.
16210cat >expout <<'_ATEOF'
162111.2: syntax error, unexpected number
16212_ATEOF
16213
16214# 3. If locations are not used, remove them.
16215sed 's/^[-0-9.]*: //' expout >at-expout
16216mv at-expout expout
16217# 4. If error-verbose is not used, strip the`, unexpected....' part.
16218sed 's/syntax error, .*$/syntax error/' expout >at-expout
16219mv at-expout expout
16220# 5. Check
16221$at_traceoff
16222echo "calc.at:555: cat stderr"
16223echo calc.at:555 >$at_check_line_file
16224( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
16225at_status=$?
16226grep '^ *+' $at_stder1 >&2
16227grep -v '^ *+' $at_stder1 >$at_stderr
16228at_failed=false
16229$at_diff $at_devnull $at_stderr || at_failed=:
16230$at_diff expout $at_stdout || at_failed=:
16231case $at_status in
16232   77) echo 77 > $at_status_file
16233            exit 77;;
16234   0) ;;
16235   *) echo "calc.at:555: exit code was $at_status, expected 0"
16236      at_failed=:;;
16237esac
16238if $at_failed; then
16239
16240  echo 1 > $at_status_file
16241  exit 1
16242fi
16243
16244$at_traceon
16245
16246
16247cat >input <<'_ATEOF'
162481//2
16249_ATEOF
16250
16251$at_traceoff
16252echo "calc.at:555: \$PREPARSER ./calc input"
16253echo calc.at:555 >$at_check_line_file
16254( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
16255at_status=$?
16256grep '^ *+' $at_stder1 >&2
16257grep -v '^ *+' $at_stder1 >$at_stderr
16258at_failed=false
16259echo stderr:; tee stderr <$at_stderr
16260$at_diff $at_devnull $at_stdout || at_failed=:
16261case $at_status in
16262   77) echo 77 > $at_status_file
16263            exit 77;;
16264   1) ;;
16265   *) echo "calc.at:555: exit code was $at_status, expected 1"
16266      at_failed=:;;
16267esac
16268if $at_failed; then
16269
16270  echo 1 > $at_status_file
16271  exit 1
16272fi
16273
16274$at_traceon
16275
16276
16277# Normalize the observed and expected error messages, depending upon the
16278# options.
16279# 1. Remove the traces from observed.
16280sed '/^Starting/d
16281/^Entering/d
16282/^Stack/d
16283/^Reading/d
16284/^Reducing/d
16285/^Shifting/d
16286/^state/d
16287/^Cleanup:/d
16288/^Error:/d
16289/^Next/d
16290/^Discarding/d
16291/ \$[0-9$]* = /d
16292/^yydestructor:/d' stderr >at-stderr
16293mv at-stderr stderr
16294# 2. Create the reference error message.
16295cat >expout <<'_ATEOF'
162961.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
16297_ATEOF
16298
16299# 3. If locations are not used, remove them.
16300sed 's/^[-0-9.]*: //' expout >at-expout
16301mv at-expout expout
16302# 4. If error-verbose is not used, strip the`, unexpected....' part.
16303sed 's/syntax error, .*$/syntax error/' expout >at-expout
16304mv at-expout expout
16305# 5. Check
16306$at_traceoff
16307echo "calc.at:555: cat stderr"
16308echo calc.at:555 >$at_check_line_file
16309( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
16310at_status=$?
16311grep '^ *+' $at_stder1 >&2
16312grep -v '^ *+' $at_stder1 >$at_stderr
16313at_failed=false
16314$at_diff $at_devnull $at_stderr || at_failed=:
16315$at_diff expout $at_stdout || at_failed=:
16316case $at_status in
16317   77) echo 77 > $at_status_file
16318            exit 77;;
16319   0) ;;
16320   *) echo "calc.at:555: exit code was $at_status, expected 0"
16321      at_failed=:;;
16322esac
16323if $at_failed; then
16324
16325  echo 1 > $at_status_file
16326  exit 1
16327fi
16328
16329$at_traceon
16330
16331
16332cat >input <<'_ATEOF'
16333error
16334_ATEOF
16335
16336$at_traceoff
16337echo "calc.at:555: \$PREPARSER ./calc input"
16338echo calc.at:555 >$at_check_line_file
16339( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
16340at_status=$?
16341grep '^ *+' $at_stder1 >&2
16342grep -v '^ *+' $at_stder1 >$at_stderr
16343at_failed=false
16344echo stderr:; tee stderr <$at_stderr
16345$at_diff $at_devnull $at_stdout || at_failed=:
16346case $at_status in
16347   77) echo 77 > $at_status_file
16348            exit 77;;
16349   1) ;;
16350   *) echo "calc.at:555: exit code was $at_status, expected 1"
16351      at_failed=:;;
16352esac
16353if $at_failed; then
16354
16355  echo 1 > $at_status_file
16356  exit 1
16357fi
16358
16359$at_traceon
16360
16361
16362# Normalize the observed and expected error messages, depending upon the
16363# options.
16364# 1. Remove the traces from observed.
16365sed '/^Starting/d
16366/^Entering/d
16367/^Stack/d
16368/^Reading/d
16369/^Reducing/d
16370/^Shifting/d
16371/^state/d
16372/^Cleanup:/d
16373/^Error:/d
16374/^Next/d
16375/^Discarding/d
16376/ \$[0-9$]* = /d
16377/^yydestructor:/d' stderr >at-stderr
16378mv at-stderr stderr
16379# 2. Create the reference error message.
16380cat >expout <<'_ATEOF'
163811.0: syntax error, unexpected $undefined
16382_ATEOF
16383
16384# 3. If locations are not used, remove them.
16385sed 's/^[-0-9.]*: //' expout >at-expout
16386mv at-expout expout
16387# 4. If error-verbose is not used, strip the`, unexpected....' part.
16388sed 's/syntax error, .*$/syntax error/' expout >at-expout
16389mv at-expout expout
16390# 5. Check
16391$at_traceoff
16392echo "calc.at:555: cat stderr"
16393echo calc.at:555 >$at_check_line_file
16394( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
16395at_status=$?
16396grep '^ *+' $at_stder1 >&2
16397grep -v '^ *+' $at_stder1 >$at_stderr
16398at_failed=false
16399$at_diff $at_devnull $at_stderr || at_failed=:
16400$at_diff expout $at_stdout || at_failed=:
16401case $at_status in
16402   77) echo 77 > $at_status_file
16403            exit 77;;
16404   0) ;;
16405   *) echo "calc.at:555: exit code was $at_status, expected 0"
16406      at_failed=:;;
16407esac
16408if $at_failed; then
16409
16410  echo 1 > $at_status_file
16411  exit 1
16412fi
16413
16414$at_traceon
16415
16416
16417cat >input <<'_ATEOF'
164181 = 2 = 3
16419_ATEOF
16420
16421$at_traceoff
16422echo "calc.at:555: \$PREPARSER ./calc input"
16423echo calc.at:555 >$at_check_line_file
16424( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
16425at_status=$?
16426grep '^ *+' $at_stder1 >&2
16427grep -v '^ *+' $at_stder1 >$at_stderr
16428at_failed=false
16429echo stderr:; tee stderr <$at_stderr
16430$at_diff $at_devnull $at_stdout || at_failed=:
16431case $at_status in
16432   77) echo 77 > $at_status_file
16433            exit 77;;
16434   1) ;;
16435   *) echo "calc.at:555: exit code was $at_status, expected 1"
16436      at_failed=:;;
16437esac
16438if $at_failed; then
16439
16440  echo 1 > $at_status_file
16441  exit 1
16442fi
16443
16444$at_traceon
16445
16446
16447# Normalize the observed and expected error messages, depending upon the
16448# options.
16449# 1. Remove the traces from observed.
16450sed '/^Starting/d
16451/^Entering/d
16452/^Stack/d
16453/^Reading/d
16454/^Reducing/d
16455/^Shifting/d
16456/^state/d
16457/^Cleanup:/d
16458/^Error:/d
16459/^Next/d
16460/^Discarding/d
16461/ \$[0-9$]* = /d
16462/^yydestructor:/d' stderr >at-stderr
16463mv at-stderr stderr
16464# 2. Create the reference error message.
16465cat >expout <<'_ATEOF'
164661.6: syntax error, unexpected '='
16467_ATEOF
16468
16469# 3. If locations are not used, remove them.
16470sed 's/^[-0-9.]*: //' expout >at-expout
16471mv at-expout expout
16472# 4. If error-verbose is not used, strip the`, unexpected....' part.
16473sed 's/syntax error, .*$/syntax error/' expout >at-expout
16474mv at-expout expout
16475# 5. Check
16476$at_traceoff
16477echo "calc.at:555: cat stderr"
16478echo calc.at:555 >$at_check_line_file
16479( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
16480at_status=$?
16481grep '^ *+' $at_stder1 >&2
16482grep -v '^ *+' $at_stder1 >$at_stderr
16483at_failed=false
16484$at_diff $at_devnull $at_stderr || at_failed=:
16485$at_diff expout $at_stdout || at_failed=:
16486case $at_status in
16487   77) echo 77 > $at_status_file
16488            exit 77;;
16489   0) ;;
16490   *) echo "calc.at:555: exit code was $at_status, expected 0"
16491      at_failed=:;;
16492esac
16493if $at_failed; then
16494
16495  echo 1 > $at_status_file
16496  exit 1
16497fi
16498
16499$at_traceon
16500
16501
16502cat >input <<'_ATEOF'
16503
16504+1
16505_ATEOF
16506
16507$at_traceoff
16508echo "calc.at:555: \$PREPARSER ./calc input"
16509echo calc.at:555 >$at_check_line_file
16510( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
16511at_status=$?
16512grep '^ *+' $at_stder1 >&2
16513grep -v '^ *+' $at_stder1 >$at_stderr
16514at_failed=false
16515echo stderr:; tee stderr <$at_stderr
16516$at_diff $at_devnull $at_stdout || at_failed=:
16517case $at_status in
16518   77) echo 77 > $at_status_file
16519            exit 77;;
16520   1) ;;
16521   *) echo "calc.at:555: exit code was $at_status, expected 1"
16522      at_failed=:;;
16523esac
16524if $at_failed; then
16525
16526  echo 1 > $at_status_file
16527  exit 1
16528fi
16529
16530$at_traceon
16531
16532
16533# Normalize the observed and expected error messages, depending upon the
16534# options.
16535# 1. Remove the traces from observed.
16536sed '/^Starting/d
16537/^Entering/d
16538/^Stack/d
16539/^Reading/d
16540/^Reducing/d
16541/^Shifting/d
16542/^state/d
16543/^Cleanup:/d
16544/^Error:/d
16545/^Next/d
16546/^Discarding/d
16547/ \$[0-9$]* = /d
16548/^yydestructor:/d' stderr >at-stderr
16549mv at-stderr stderr
16550# 2. Create the reference error message.
16551cat >expout <<'_ATEOF'
165522.0: syntax error, unexpected '+'
16553_ATEOF
16554
16555# 3. If locations are not used, remove them.
16556sed 's/^[-0-9.]*: //' expout >at-expout
16557mv at-expout expout
16558# 4. If error-verbose is not used, strip the`, unexpected....' part.
16559sed 's/syntax error, .*$/syntax error/' expout >at-expout
16560mv at-expout expout
16561# 5. Check
16562$at_traceoff
16563echo "calc.at:555: cat stderr"
16564echo calc.at:555 >$at_check_line_file
16565( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
16566at_status=$?
16567grep '^ *+' $at_stder1 >&2
16568grep -v '^ *+' $at_stder1 >$at_stderr
16569at_failed=false
16570$at_diff $at_devnull $at_stderr || at_failed=:
16571$at_diff expout $at_stdout || at_failed=:
16572case $at_status in
16573   77) echo 77 > $at_status_file
16574            exit 77;;
16575   0) ;;
16576   *) echo "calc.at:555: exit code was $at_status, expected 0"
16577      at_failed=:;;
16578esac
16579if $at_failed; then
16580
16581  echo 1 > $at_status_file
16582  exit 1
16583fi
16584
16585$at_traceon
16586
16587
16588# Exercise error messages with EOF: work on an empty file.
16589$at_traceoff
16590echo "calc.at:555: \$PREPARSER ./calc /dev/null"
16591echo calc.at:555 >$at_check_line_file
16592( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
16593at_status=$?
16594grep '^ *+' $at_stder1 >&2
16595grep -v '^ *+' $at_stder1 >$at_stderr
16596at_failed=false
16597echo stderr:; tee stderr <$at_stderr
16598$at_diff $at_devnull $at_stdout || at_failed=:
16599case $at_status in
16600   77) echo 77 > $at_status_file
16601            exit 77;;
16602   1) ;;
16603   *) echo "calc.at:555: exit code was $at_status, expected 1"
16604      at_failed=:;;
16605esac
16606if $at_failed; then
16607
16608  echo 1 > $at_status_file
16609  exit 1
16610fi
16611
16612$at_traceon
16613
16614
16615# Normalize the observed and expected error messages, depending upon the
16616# options.
16617# 1. Remove the traces from observed.
16618sed '/^Starting/d
16619/^Entering/d
16620/^Stack/d
16621/^Reading/d
16622/^Reducing/d
16623/^Shifting/d
16624/^state/d
16625/^Cleanup:/d
16626/^Error:/d
16627/^Next/d
16628/^Discarding/d
16629/ \$[0-9$]* = /d
16630/^yydestructor:/d' stderr >at-stderr
16631mv at-stderr stderr
16632# 2. Create the reference error message.
16633cat >expout <<'_ATEOF'
166341.0: syntax error, unexpected end of input
16635_ATEOF
16636
16637# 3. If locations are not used, remove them.
16638sed 's/^[-0-9.]*: //' expout >at-expout
16639mv at-expout expout
16640# 4. If error-verbose is not used, strip the`, unexpected....' part.
16641sed 's/syntax error, .*$/syntax error/' expout >at-expout
16642mv at-expout expout
16643# 5. Check
16644$at_traceoff
16645echo "calc.at:555: cat stderr"
16646echo calc.at:555 >$at_check_line_file
16647( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
16648at_status=$?
16649grep '^ *+' $at_stder1 >&2
16650grep -v '^ *+' $at_stder1 >$at_stderr
16651at_failed=false
16652$at_diff $at_devnull $at_stderr || at_failed=:
16653$at_diff expout $at_stdout || at_failed=:
16654case $at_status in
16655   77) echo 77 > $at_status_file
16656            exit 77;;
16657   0) ;;
16658   *) echo "calc.at:555: exit code was $at_status, expected 0"
16659      at_failed=:;;
16660esac
16661if $at_failed; then
16662
16663  echo 1 > $at_status_file
16664  exit 1
16665fi
16666
16667$at_traceon
16668
16669
16670
16671# Exercise the error token: without it, we die at the first error,
16672# hence be sure to
16673#
16674# - have several errors which exercise different shift/discardings
16675#   - (): nothing to pop, nothing to discard
16676#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
16677#   - (* * *): nothing to pop, a lot to discard
16678#   - (1 + 2 * *): some to pop and discard
16679#
16680# - test the action associated to `error'
16681#
16682# - check the look-ahead that triggers an error is not discarded
16683#   when we enter error recovery.  Below, the look-ahead causing the
16684#   first error is ")", which is needed to recover from the error and
16685#   produce the "0" that triggers the "0 != 1" error.
16686#
16687cat >input <<'_ATEOF'
16688() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
16689_ATEOF
16690
16691$at_traceoff
16692echo "calc.at:555: \$PREPARSER ./calc input"
16693echo calc.at:555 >$at_check_line_file
16694( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
16695at_status=$?
16696grep '^ *+' $at_stder1 >&2
16697grep -v '^ *+' $at_stder1 >$at_stderr
16698at_failed=false
16699echo stderr:; tee stderr <$at_stderr
16700$at_diff $at_devnull $at_stdout || at_failed=:
16701case $at_status in
16702   77) echo 77 > $at_status_file
16703            exit 77;;
16704   0) ;;
16705   *) echo "calc.at:555: exit code was $at_status, expected 0"
16706      at_failed=:;;
16707esac
16708if $at_failed; then
16709
16710  echo 1 > $at_status_file
16711  exit 1
16712fi
16713
16714$at_traceon
16715
16716
16717# Normalize the observed and expected error messages, depending upon the
16718# options.
16719# 1. Remove the traces from observed.
16720sed '/^Starting/d
16721/^Entering/d
16722/^Stack/d
16723/^Reading/d
16724/^Reducing/d
16725/^Shifting/d
16726/^state/d
16727/^Cleanup:/d
16728/^Error:/d
16729/^Next/d
16730/^Discarding/d
16731/ \$[0-9$]* = /d
16732/^yydestructor:/d' stderr >at-stderr
16733mv at-stderr stderr
16734# 2. Create the reference error message.
16735cat >expout <<'_ATEOF'
167361.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
167371.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
167381.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
167391.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
16740calc: error: 4444 != 1
16741_ATEOF
16742
16743# 3. If locations are not used, remove them.
16744sed 's/^[-0-9.]*: //' expout >at-expout
16745mv at-expout expout
16746# 4. If error-verbose is not used, strip the`, unexpected....' part.
16747sed 's/syntax error, .*$/syntax error/' expout >at-expout
16748mv at-expout expout
16749# 5. Check
16750$at_traceoff
16751echo "calc.at:555: cat stderr"
16752echo calc.at:555 >$at_check_line_file
16753( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
16754at_status=$?
16755grep '^ *+' $at_stder1 >&2
16756grep -v '^ *+' $at_stder1 >$at_stderr
16757at_failed=false
16758$at_diff $at_devnull $at_stderr || at_failed=:
16759$at_diff expout $at_stdout || at_failed=:
16760case $at_status in
16761   77) echo 77 > $at_status_file
16762            exit 77;;
16763   0) ;;
16764   *) echo "calc.at:555: exit code was $at_status, expected 0"
16765      at_failed=:;;
16766esac
16767if $at_failed; then
16768
16769  echo 1 > $at_status_file
16770  exit 1
16771fi
16772
16773$at_traceon
16774
16775
16776
16777# The same, but this time exercising explicitly triggered syntax errors.
16778# POSIX says the look-ahead causing the error should not be discarded.
16779cat >input <<'_ATEOF'
16780(!) + (0 0) = 1
16781_ATEOF
16782
16783$at_traceoff
16784echo "calc.at:555: \$PREPARSER ./calc input"
16785echo calc.at:555 >$at_check_line_file
16786( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
16787at_status=$?
16788grep '^ *+' $at_stder1 >&2
16789grep -v '^ *+' $at_stder1 >$at_stderr
16790at_failed=false
16791echo stderr:; tee stderr <$at_stderr
16792$at_diff $at_devnull $at_stdout || at_failed=:
16793case $at_status in
16794   77) echo 77 > $at_status_file
16795            exit 77;;
16796   0) ;;
16797   *) echo "calc.at:555: exit code was $at_status, expected 0"
16798      at_failed=:;;
16799esac
16800if $at_failed; then
16801
16802  echo 1 > $at_status_file
16803  exit 1
16804fi
16805
16806$at_traceon
16807
16808
16809# Normalize the observed and expected error messages, depending upon the
16810# options.
16811# 1. Remove the traces from observed.
16812sed '/^Starting/d
16813/^Entering/d
16814/^Stack/d
16815/^Reading/d
16816/^Reducing/d
16817/^Shifting/d
16818/^state/d
16819/^Cleanup:/d
16820/^Error:/d
16821/^Next/d
16822/^Discarding/d
16823/ \$[0-9$]* = /d
16824/^yydestructor:/d' stderr >at-stderr
16825mv at-stderr stderr
16826# 2. Create the reference error message.
16827cat >expout <<'_ATEOF'
168281.9: syntax error, unexpected number
16829calc: error: 2222 != 1
16830_ATEOF
16831
16832# 3. If locations are not used, remove them.
16833sed 's/^[-0-9.]*: //' expout >at-expout
16834mv at-expout expout
16835# 4. If error-verbose is not used, strip the`, unexpected....' part.
16836sed 's/syntax error, .*$/syntax error/' expout >at-expout
16837mv at-expout expout
16838# 5. Check
16839$at_traceoff
16840echo "calc.at:555: cat stderr"
16841echo calc.at:555 >$at_check_line_file
16842( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
16843at_status=$?
16844grep '^ *+' $at_stder1 >&2
16845grep -v '^ *+' $at_stder1 >$at_stderr
16846at_failed=false
16847$at_diff $at_devnull $at_stderr || at_failed=:
16848$at_diff expout $at_stdout || at_failed=:
16849case $at_status in
16850   77) echo 77 > $at_status_file
16851            exit 77;;
16852   0) ;;
16853   *) echo "calc.at:555: exit code was $at_status, expected 0"
16854      at_failed=:;;
16855esac
16856if $at_failed; then
16857
16858  echo 1 > $at_status_file
16859  exit 1
16860fi
16861
16862$at_traceon
16863
16864
16865cat >input <<'_ATEOF'
16866(- *) + (0 0) = 1
16867_ATEOF
16868
16869$at_traceoff
16870echo "calc.at:555: \$PREPARSER ./calc input"
16871echo calc.at:555 >$at_check_line_file
16872( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
16873at_status=$?
16874grep '^ *+' $at_stder1 >&2
16875grep -v '^ *+' $at_stder1 >$at_stderr
16876at_failed=false
16877echo stderr:; tee stderr <$at_stderr
16878$at_diff $at_devnull $at_stdout || at_failed=:
16879case $at_status in
16880   77) echo 77 > $at_status_file
16881            exit 77;;
16882   0) ;;
16883   *) echo "calc.at:555: exit code was $at_status, expected 0"
16884      at_failed=:;;
16885esac
16886if $at_failed; then
16887
16888  echo 1 > $at_status_file
16889  exit 1
16890fi
16891
16892$at_traceon
16893
16894
16895# Normalize the observed and expected error messages, depending upon the
16896# options.
16897# 1. Remove the traces from observed.
16898sed '/^Starting/d
16899/^Entering/d
16900/^Stack/d
16901/^Reading/d
16902/^Reducing/d
16903/^Shifting/d
16904/^state/d
16905/^Cleanup:/d
16906/^Error:/d
16907/^Next/d
16908/^Discarding/d
16909/ \$[0-9$]* = /d
16910/^yydestructor:/d' stderr >at-stderr
16911mv at-stderr stderr
16912# 2. Create the reference error message.
16913cat >expout <<'_ATEOF'
169141.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
169151.11: syntax error, unexpected number
16916calc: error: 2222 != 1
16917_ATEOF
16918
16919# 3. If locations are not used, remove them.
16920sed 's/^[-0-9.]*: //' expout >at-expout
16921mv at-expout expout
16922# 4. If error-verbose is not used, strip the`, unexpected....' part.
16923sed 's/syntax error, .*$/syntax error/' expout >at-expout
16924mv at-expout expout
16925# 5. Check
16926$at_traceoff
16927echo "calc.at:555: cat stderr"
16928echo calc.at:555 >$at_check_line_file
16929( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
16930at_status=$?
16931grep '^ *+' $at_stder1 >&2
16932grep -v '^ *+' $at_stder1 >$at_stderr
16933at_failed=false
16934$at_diff $at_devnull $at_stderr || at_failed=:
16935$at_diff expout $at_stdout || at_failed=:
16936case $at_status in
16937   77) echo 77 > $at_status_file
16938            exit 77;;
16939   0) ;;
16940   *) echo "calc.at:555: exit code was $at_status, expected 0"
16941      at_failed=:;;
16942esac
16943if $at_failed; then
16944
16945  echo 1 > $at_status_file
16946  exit 1
16947fi
16948
16949$at_traceon
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974      $at_traceoff
16975      $at_times_p && times >$at_times_file
16976    ) 5>&1 2>&1 | eval $at_tee_pipe
16977    at_status=`cat $at_status_file`
16978    ;;
16979
16980  75 ) # 75. calc.at:556: Calculator %yacc
16981    at_setup_line='calc.at:556'
16982    at_desc='Calculator %yacc'
16983    $at_quiet $ECHO_N " 75: Calculator %yacc                             $ECHO_C"
16984    at_xfail=no
16985    (
16986      echo "75. calc.at:556: testing ..."
16987      $at_traceon
16988
16989
16990
16991
16992
16993
16994
16995
16996# Using yacc.c?
16997
16998
16999
17000
17001
17002
17003
17004# yyerror receives the location if %location & %pure & (%glr or %parse-param).
17005
17006# yyerror always sees the locations (when activated), except if
17007# yacc & pure & !param.
17008
17009
17010# The interface is pure: either because %pure-parser, or because we
17011# are using the C++ parsers.
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024cat >calc.y <<'_ATEOF'
17025%{
17026#ifdef HAVE_CONFIG_H
17027# include <config.h>
17028  /* We don't need perfect functions for these tests. */
17029# undef malloc
17030# undef memcmp
17031# undef realloc
17032#endif
17033%}
17034
17035/* Infix notation calculator--calc */
17036%yacc
17037
17038%{
17039#include <stdio.h>
17040
17041#include <stdlib.h>
17042#include <string.h>
17043#if HAVE_UNISTD_H
17044# include <unistd.h>
17045#else
17046# undef alarm
17047# define alarm(seconds) /* empty */
17048#endif
17049#include <ctype.h>
17050#define USE(Var)
17051
17052/* Exercise pre-prologue dependency to %union.  */
17053typedef int semantic_value;
17054
17055static semantic_value global_result = 0;
17056static int global_count = 0;
17057%}
17058
17059/* Exercise %union. */
17060%union
17061{
17062  semantic_value ival;
17063};
17064
17065%{
17066static int power (int base, int exponent);
17067/* yyerror receives the location if:
17068   - %location & %pure & %glr
17069   - %location & %pure & %yacc & %parse-param. */
17070static void yyerror (
17071
17072                     const char *s
17073                     );
17074static int yylex (void);
17075static int get_char (void);
17076static void unget_char ( int c);
17077%}
17078
17079
17080
17081/* Bison Declarations */
17082%token CALC_EOF 0 "end of input"
17083%token <ival> NUM "number"
17084%type  <ival> exp
17085
17086%nonassoc '=' /* comparison	       */
17087%left '-' '+'
17088%left '*' '/'
17089%left NEG     /* negation--unary minus */
17090%right '^'    /* exponentiation        */
17091
17092/* Grammar follows */
17093%%
17094input:
17095  line
17096| input line         {  }
17097;
17098
17099line:
17100  '\n'
17101| exp '\n'           { USE ($1); }
17102;
17103
17104exp:
17105  NUM                { $$ = $1;             }
17106| exp '=' exp
17107  {
17108    if ($1 != $3)
17109      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
17110    $$ = $1;
17111  }
17112| exp '+' exp        { $$ = $1 + $3;        }
17113| exp '-' exp        { $$ = $1 - $3;        }
17114| exp '*' exp        { $$ = $1 * $3;        }
17115| exp '/' exp        { $$ = $1 / $3;        }
17116| '-' exp  %prec NEG { $$ = -$2;            }
17117| exp '^' exp        { $$ = power ($1, $3); }
17118| '(' exp ')'        { $$ = $2;             }
17119| '(' error ')'      { $$ = 1111;           }
17120| '!'                { $$ = 0; YYERROR;     }
17121| '-' error          { $$ = 0; YYERROR;     }
17122;
17123%%
17124/* The input.  */
17125static FILE *input;
17126
17127static void
17128yyerror (
17129
17130         const char *s)
17131{
17132
17133
17134  fprintf (stderr, "%s\n", s);
17135}
17136
17137
17138
17139static int
17140get_char (void)
17141{
17142  int res = getc (input);
17143  ;
17144
17145  return res;
17146}
17147
17148
17149static void
17150unget_char ( int c)
17151{
17152  ;
17153
17154  ungetc (c, input);
17155}
17156
17157static int
17158read_signed_integer (void)
17159{
17160  int c = get_char ();
17161  int sign = 1;
17162  int n = 0;
17163
17164  ;
17165  if (c == '-')
17166    {
17167      c = get_char ();
17168      sign = -1;
17169    }
17170
17171  while (isdigit (c))
17172    {
17173      n = 10 * n + (c - '0');
17174      c = get_char ();
17175    }
17176
17177  unget_char ( c);
17178
17179  return sign * n;
17180}
17181
17182
17183
17184/*---------------------------------------------------------------.
17185| Lexical analyzer returns an integer on the stack and the token |
17186| NUM, or the ASCII character read if not a number.  Skips all   |
17187| blanks and tabs, returns 0 for EOF.                            |
17188`---------------------------------------------------------------*/
17189
17190static int
17191yylex (void)
17192{
17193  static int init = 1;
17194  int c;
17195
17196  if (init)
17197    {
17198      init = 0;
17199
17200    }
17201
17202
17203
17204  /* Skip white space.  */
17205  while ((c = get_char ()) == ' ' || c == '\t')
17206    {
17207
17208    }
17209
17210  /* process numbers   */
17211  if (c == '.' || isdigit (c))
17212    {
17213      unget_char ( c);
17214      (yylval).ival = read_signed_integer ();
17215      return NUM;
17216    }
17217
17218  /* Return end-of-file.  */
17219  if (c == EOF)
17220    return CALC_EOF;
17221
17222  /* Return single chars. */
17223  return c;
17224}
17225
17226static int
17227power (int base, int exponent)
17228{
17229  int res = 1;
17230  if (exponent < 0)
17231    exit (3);
17232  for (/* Niente */; exponent; --exponent)
17233    res *= base;
17234  return res;
17235}
17236
17237
17238int
17239main (int argc, const char **argv)
17240{
17241  semantic_value result = 0;
17242  int count = 0;
17243  int status;
17244
17245  /* This used to be alarm (10), but that isn't enough time for
17246     a July 1995 vintage DEC Alphastation 200 4/100 system,
17247     according to Nelson H. F. Beebe.  100 seconds is enough.  */
17248  alarm (100);
17249
17250  if (argc == 2)
17251    input = fopen (argv[1], "r");
17252  else
17253    input = stdin;
17254
17255  if (!input)
17256    {
17257      perror (argv[1]);
17258      return 3;
17259    }
17260
17261
17262  status = yyparse ();
17263  if (global_result != result)
17264    abort ();
17265  if (global_count != count)
17266    abort ();
17267  return status;
17268}
17269_ATEOF
17270
17271
17272
17273
17274
17275$at_traceoff
17276echo "calc.at:556: bison -o calc.c calc.y"
17277echo calc.at:556 >$at_check_line_file
17278( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
17279at_status=$?
17280grep '^ *+' $at_stder1 >&2
17281grep -v '^ *+' $at_stder1 >$at_stderr
17282at_failed=false
17283$at_diff $at_devnull $at_stderr || at_failed=:
17284$at_diff $at_devnull $at_stdout || at_failed=:
17285case $at_status in
17286   77) echo 77 > $at_status_file
17287            exit 77;;
17288   0) ;;
17289   *) echo "calc.at:556: exit code was $at_status, expected 0"
17290      at_failed=:;;
17291esac
17292if $at_failed; then
17293
17294  echo 1 > $at_status_file
17295  exit 1
17296fi
17297
17298$at_traceon
17299
17300   $at_traceoff
17301echo "calc.at:556: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
17302echo calc.at:556 >$at_check_line_file
17303( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
17304at_status=$?
17305grep '^ *+' $at_stder1 >&2
17306grep -v '^ *+' $at_stder1 >$at_stderr
17307at_failed=false
17308echo stderr:; cat $at_stderr
17309echo stdout:; cat $at_stdout
17310case $at_status in
17311   77) echo 77 > $at_status_file
17312            exit 77;;
17313   0) ;;
17314   *) echo "calc.at:556: exit code was $at_status, expected 0"
17315      at_failed=:;;
17316esac
17317if $at_failed; then
17318
17319  echo 1 > $at_status_file
17320  exit 1
17321fi
17322
17323$at_traceon
17324
17325
17326# Test the priorities.
17327cat >input <<'_ATEOF'
173281 + 2 * 3 = 7
173291 + 2 * -3 = -5
17330
17331-1^2 = -1
17332(-1)^2 = 1
17333
17334---1 = -1
17335
173361 - 2 - 3 = -4
173371 - (2 - 3) = 2
17338
173392^2^3 = 256
17340(2^2)^3 = 64
17341_ATEOF
17342
17343$at_traceoff
17344echo "calc.at:556: \$PREPARSER ./calc input"
17345echo calc.at:556 >$at_check_line_file
17346( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
17347at_status=$?
17348grep '^ *+' $at_stder1 >&2
17349grep -v '^ *+' $at_stder1 >$at_stderr
17350at_failed=false
17351echo stderr:; tee stderr <$at_stderr
17352$at_diff $at_devnull $at_stdout || at_failed=:
17353case $at_status in
17354   77) echo 77 > $at_status_file
17355            exit 77;;
17356   0) ;;
17357   *) echo "calc.at:556: exit code was $at_status, expected 0"
17358      at_failed=:;;
17359esac
17360if $at_failed; then
17361
17362  echo 1 > $at_status_file
17363  exit 1
17364fi
17365
17366$at_traceon
17367
17368
17369
17370# Some syntax errors.
17371cat >input <<'_ATEOF'
173720 0
17373_ATEOF
17374
17375$at_traceoff
17376echo "calc.at:556: \$PREPARSER ./calc input"
17377echo calc.at:556 >$at_check_line_file
17378( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
17379at_status=$?
17380grep '^ *+' $at_stder1 >&2
17381grep -v '^ *+' $at_stder1 >$at_stderr
17382at_failed=false
17383echo stderr:; tee stderr <$at_stderr
17384$at_diff $at_devnull $at_stdout || at_failed=:
17385case $at_status in
17386   77) echo 77 > $at_status_file
17387            exit 77;;
17388   1) ;;
17389   *) echo "calc.at:556: exit code was $at_status, expected 1"
17390      at_failed=:;;
17391esac
17392if $at_failed; then
17393
17394  echo 1 > $at_status_file
17395  exit 1
17396fi
17397
17398$at_traceon
17399
17400
17401# Normalize the observed and expected error messages, depending upon the
17402# options.
17403# 1. Remove the traces from observed.
17404sed '/^Starting/d
17405/^Entering/d
17406/^Stack/d
17407/^Reading/d
17408/^Reducing/d
17409/^Shifting/d
17410/^state/d
17411/^Cleanup:/d
17412/^Error:/d
17413/^Next/d
17414/^Discarding/d
17415/ \$[0-9$]* = /d
17416/^yydestructor:/d' stderr >at-stderr
17417mv at-stderr stderr
17418# 2. Create the reference error message.
17419cat >expout <<'_ATEOF'
174201.2: syntax error, unexpected number
17421_ATEOF
17422
17423# 3. If locations are not used, remove them.
17424sed 's/^[-0-9.]*: //' expout >at-expout
17425mv at-expout expout
17426# 4. If error-verbose is not used, strip the`, unexpected....' part.
17427sed 's/syntax error, .*$/syntax error/' expout >at-expout
17428mv at-expout expout
17429# 5. Check
17430$at_traceoff
17431echo "calc.at:556: cat stderr"
17432echo calc.at:556 >$at_check_line_file
17433( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
17434at_status=$?
17435grep '^ *+' $at_stder1 >&2
17436grep -v '^ *+' $at_stder1 >$at_stderr
17437at_failed=false
17438$at_diff $at_devnull $at_stderr || at_failed=:
17439$at_diff expout $at_stdout || at_failed=:
17440case $at_status in
17441   77) echo 77 > $at_status_file
17442            exit 77;;
17443   0) ;;
17444   *) echo "calc.at:556: exit code was $at_status, expected 0"
17445      at_failed=:;;
17446esac
17447if $at_failed; then
17448
17449  echo 1 > $at_status_file
17450  exit 1
17451fi
17452
17453$at_traceon
17454
17455
17456cat >input <<'_ATEOF'
174571//2
17458_ATEOF
17459
17460$at_traceoff
17461echo "calc.at:556: \$PREPARSER ./calc input"
17462echo calc.at:556 >$at_check_line_file
17463( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
17464at_status=$?
17465grep '^ *+' $at_stder1 >&2
17466grep -v '^ *+' $at_stder1 >$at_stderr
17467at_failed=false
17468echo stderr:; tee stderr <$at_stderr
17469$at_diff $at_devnull $at_stdout || at_failed=:
17470case $at_status in
17471   77) echo 77 > $at_status_file
17472            exit 77;;
17473   1) ;;
17474   *) echo "calc.at:556: exit code was $at_status, expected 1"
17475      at_failed=:;;
17476esac
17477if $at_failed; then
17478
17479  echo 1 > $at_status_file
17480  exit 1
17481fi
17482
17483$at_traceon
17484
17485
17486# Normalize the observed and expected error messages, depending upon the
17487# options.
17488# 1. Remove the traces from observed.
17489sed '/^Starting/d
17490/^Entering/d
17491/^Stack/d
17492/^Reading/d
17493/^Reducing/d
17494/^Shifting/d
17495/^state/d
17496/^Cleanup:/d
17497/^Error:/d
17498/^Next/d
17499/^Discarding/d
17500/ \$[0-9$]* = /d
17501/^yydestructor:/d' stderr >at-stderr
17502mv at-stderr stderr
17503# 2. Create the reference error message.
17504cat >expout <<'_ATEOF'
175051.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
17506_ATEOF
17507
17508# 3. If locations are not used, remove them.
17509sed 's/^[-0-9.]*: //' expout >at-expout
17510mv at-expout expout
17511# 4. If error-verbose is not used, strip the`, unexpected....' part.
17512sed 's/syntax error, .*$/syntax error/' expout >at-expout
17513mv at-expout expout
17514# 5. Check
17515$at_traceoff
17516echo "calc.at:556: cat stderr"
17517echo calc.at:556 >$at_check_line_file
17518( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
17519at_status=$?
17520grep '^ *+' $at_stder1 >&2
17521grep -v '^ *+' $at_stder1 >$at_stderr
17522at_failed=false
17523$at_diff $at_devnull $at_stderr || at_failed=:
17524$at_diff expout $at_stdout || at_failed=:
17525case $at_status in
17526   77) echo 77 > $at_status_file
17527            exit 77;;
17528   0) ;;
17529   *) echo "calc.at:556: exit code was $at_status, expected 0"
17530      at_failed=:;;
17531esac
17532if $at_failed; then
17533
17534  echo 1 > $at_status_file
17535  exit 1
17536fi
17537
17538$at_traceon
17539
17540
17541cat >input <<'_ATEOF'
17542error
17543_ATEOF
17544
17545$at_traceoff
17546echo "calc.at:556: \$PREPARSER ./calc input"
17547echo calc.at:556 >$at_check_line_file
17548( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
17549at_status=$?
17550grep '^ *+' $at_stder1 >&2
17551grep -v '^ *+' $at_stder1 >$at_stderr
17552at_failed=false
17553echo stderr:; tee stderr <$at_stderr
17554$at_diff $at_devnull $at_stdout || at_failed=:
17555case $at_status in
17556   77) echo 77 > $at_status_file
17557            exit 77;;
17558   1) ;;
17559   *) echo "calc.at:556: exit code was $at_status, expected 1"
17560      at_failed=:;;
17561esac
17562if $at_failed; then
17563
17564  echo 1 > $at_status_file
17565  exit 1
17566fi
17567
17568$at_traceon
17569
17570
17571# Normalize the observed and expected error messages, depending upon the
17572# options.
17573# 1. Remove the traces from observed.
17574sed '/^Starting/d
17575/^Entering/d
17576/^Stack/d
17577/^Reading/d
17578/^Reducing/d
17579/^Shifting/d
17580/^state/d
17581/^Cleanup:/d
17582/^Error:/d
17583/^Next/d
17584/^Discarding/d
17585/ \$[0-9$]* = /d
17586/^yydestructor:/d' stderr >at-stderr
17587mv at-stderr stderr
17588# 2. Create the reference error message.
17589cat >expout <<'_ATEOF'
175901.0: syntax error, unexpected $undefined
17591_ATEOF
17592
17593# 3. If locations are not used, remove them.
17594sed 's/^[-0-9.]*: //' expout >at-expout
17595mv at-expout expout
17596# 4. If error-verbose is not used, strip the`, unexpected....' part.
17597sed 's/syntax error, .*$/syntax error/' expout >at-expout
17598mv at-expout expout
17599# 5. Check
17600$at_traceoff
17601echo "calc.at:556: cat stderr"
17602echo calc.at:556 >$at_check_line_file
17603( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
17604at_status=$?
17605grep '^ *+' $at_stder1 >&2
17606grep -v '^ *+' $at_stder1 >$at_stderr
17607at_failed=false
17608$at_diff $at_devnull $at_stderr || at_failed=:
17609$at_diff expout $at_stdout || at_failed=:
17610case $at_status in
17611   77) echo 77 > $at_status_file
17612            exit 77;;
17613   0) ;;
17614   *) echo "calc.at:556: exit code was $at_status, expected 0"
17615      at_failed=:;;
17616esac
17617if $at_failed; then
17618
17619  echo 1 > $at_status_file
17620  exit 1
17621fi
17622
17623$at_traceon
17624
17625
17626cat >input <<'_ATEOF'
176271 = 2 = 3
17628_ATEOF
17629
17630$at_traceoff
17631echo "calc.at:556: \$PREPARSER ./calc input"
17632echo calc.at:556 >$at_check_line_file
17633( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
17634at_status=$?
17635grep '^ *+' $at_stder1 >&2
17636grep -v '^ *+' $at_stder1 >$at_stderr
17637at_failed=false
17638echo stderr:; tee stderr <$at_stderr
17639$at_diff $at_devnull $at_stdout || at_failed=:
17640case $at_status in
17641   77) echo 77 > $at_status_file
17642            exit 77;;
17643   1) ;;
17644   *) echo "calc.at:556: exit code was $at_status, expected 1"
17645      at_failed=:;;
17646esac
17647if $at_failed; then
17648
17649  echo 1 > $at_status_file
17650  exit 1
17651fi
17652
17653$at_traceon
17654
17655
17656# Normalize the observed and expected error messages, depending upon the
17657# options.
17658# 1. Remove the traces from observed.
17659sed '/^Starting/d
17660/^Entering/d
17661/^Stack/d
17662/^Reading/d
17663/^Reducing/d
17664/^Shifting/d
17665/^state/d
17666/^Cleanup:/d
17667/^Error:/d
17668/^Next/d
17669/^Discarding/d
17670/ \$[0-9$]* = /d
17671/^yydestructor:/d' stderr >at-stderr
17672mv at-stderr stderr
17673# 2. Create the reference error message.
17674cat >expout <<'_ATEOF'
176751.6: syntax error, unexpected '='
17676_ATEOF
17677
17678# 3. If locations are not used, remove them.
17679sed 's/^[-0-9.]*: //' expout >at-expout
17680mv at-expout expout
17681# 4. If error-verbose is not used, strip the`, unexpected....' part.
17682sed 's/syntax error, .*$/syntax error/' expout >at-expout
17683mv at-expout expout
17684# 5. Check
17685$at_traceoff
17686echo "calc.at:556: cat stderr"
17687echo calc.at:556 >$at_check_line_file
17688( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
17689at_status=$?
17690grep '^ *+' $at_stder1 >&2
17691grep -v '^ *+' $at_stder1 >$at_stderr
17692at_failed=false
17693$at_diff $at_devnull $at_stderr || at_failed=:
17694$at_diff expout $at_stdout || at_failed=:
17695case $at_status in
17696   77) echo 77 > $at_status_file
17697            exit 77;;
17698   0) ;;
17699   *) echo "calc.at:556: exit code was $at_status, expected 0"
17700      at_failed=:;;
17701esac
17702if $at_failed; then
17703
17704  echo 1 > $at_status_file
17705  exit 1
17706fi
17707
17708$at_traceon
17709
17710
17711cat >input <<'_ATEOF'
17712
17713+1
17714_ATEOF
17715
17716$at_traceoff
17717echo "calc.at:556: \$PREPARSER ./calc input"
17718echo calc.at:556 >$at_check_line_file
17719( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
17720at_status=$?
17721grep '^ *+' $at_stder1 >&2
17722grep -v '^ *+' $at_stder1 >$at_stderr
17723at_failed=false
17724echo stderr:; tee stderr <$at_stderr
17725$at_diff $at_devnull $at_stdout || at_failed=:
17726case $at_status in
17727   77) echo 77 > $at_status_file
17728            exit 77;;
17729   1) ;;
17730   *) echo "calc.at:556: exit code was $at_status, expected 1"
17731      at_failed=:;;
17732esac
17733if $at_failed; then
17734
17735  echo 1 > $at_status_file
17736  exit 1
17737fi
17738
17739$at_traceon
17740
17741
17742# Normalize the observed and expected error messages, depending upon the
17743# options.
17744# 1. Remove the traces from observed.
17745sed '/^Starting/d
17746/^Entering/d
17747/^Stack/d
17748/^Reading/d
17749/^Reducing/d
17750/^Shifting/d
17751/^state/d
17752/^Cleanup:/d
17753/^Error:/d
17754/^Next/d
17755/^Discarding/d
17756/ \$[0-9$]* = /d
17757/^yydestructor:/d' stderr >at-stderr
17758mv at-stderr stderr
17759# 2. Create the reference error message.
17760cat >expout <<'_ATEOF'
177612.0: syntax error, unexpected '+'
17762_ATEOF
17763
17764# 3. If locations are not used, remove them.
17765sed 's/^[-0-9.]*: //' expout >at-expout
17766mv at-expout expout
17767# 4. If error-verbose is not used, strip the`, unexpected....' part.
17768sed 's/syntax error, .*$/syntax error/' expout >at-expout
17769mv at-expout expout
17770# 5. Check
17771$at_traceoff
17772echo "calc.at:556: cat stderr"
17773echo calc.at:556 >$at_check_line_file
17774( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
17775at_status=$?
17776grep '^ *+' $at_stder1 >&2
17777grep -v '^ *+' $at_stder1 >$at_stderr
17778at_failed=false
17779$at_diff $at_devnull $at_stderr || at_failed=:
17780$at_diff expout $at_stdout || at_failed=:
17781case $at_status in
17782   77) echo 77 > $at_status_file
17783            exit 77;;
17784   0) ;;
17785   *) echo "calc.at:556: exit code was $at_status, expected 0"
17786      at_failed=:;;
17787esac
17788if $at_failed; then
17789
17790  echo 1 > $at_status_file
17791  exit 1
17792fi
17793
17794$at_traceon
17795
17796
17797# Exercise error messages with EOF: work on an empty file.
17798$at_traceoff
17799echo "calc.at:556: \$PREPARSER ./calc /dev/null"
17800echo calc.at:556 >$at_check_line_file
17801( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
17802at_status=$?
17803grep '^ *+' $at_stder1 >&2
17804grep -v '^ *+' $at_stder1 >$at_stderr
17805at_failed=false
17806echo stderr:; tee stderr <$at_stderr
17807$at_diff $at_devnull $at_stdout || at_failed=:
17808case $at_status in
17809   77) echo 77 > $at_status_file
17810            exit 77;;
17811   1) ;;
17812   *) echo "calc.at:556: exit code was $at_status, expected 1"
17813      at_failed=:;;
17814esac
17815if $at_failed; then
17816
17817  echo 1 > $at_status_file
17818  exit 1
17819fi
17820
17821$at_traceon
17822
17823
17824# Normalize the observed and expected error messages, depending upon the
17825# options.
17826# 1. Remove the traces from observed.
17827sed '/^Starting/d
17828/^Entering/d
17829/^Stack/d
17830/^Reading/d
17831/^Reducing/d
17832/^Shifting/d
17833/^state/d
17834/^Cleanup:/d
17835/^Error:/d
17836/^Next/d
17837/^Discarding/d
17838/ \$[0-9$]* = /d
17839/^yydestructor:/d' stderr >at-stderr
17840mv at-stderr stderr
17841# 2. Create the reference error message.
17842cat >expout <<'_ATEOF'
178431.0: syntax error, unexpected end of input
17844_ATEOF
17845
17846# 3. If locations are not used, remove them.
17847sed 's/^[-0-9.]*: //' expout >at-expout
17848mv at-expout expout
17849# 4. If error-verbose is not used, strip the`, unexpected....' part.
17850sed 's/syntax error, .*$/syntax error/' expout >at-expout
17851mv at-expout expout
17852# 5. Check
17853$at_traceoff
17854echo "calc.at:556: cat stderr"
17855echo calc.at:556 >$at_check_line_file
17856( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
17857at_status=$?
17858grep '^ *+' $at_stder1 >&2
17859grep -v '^ *+' $at_stder1 >$at_stderr
17860at_failed=false
17861$at_diff $at_devnull $at_stderr || at_failed=:
17862$at_diff expout $at_stdout || at_failed=:
17863case $at_status in
17864   77) echo 77 > $at_status_file
17865            exit 77;;
17866   0) ;;
17867   *) echo "calc.at:556: exit code was $at_status, expected 0"
17868      at_failed=:;;
17869esac
17870if $at_failed; then
17871
17872  echo 1 > $at_status_file
17873  exit 1
17874fi
17875
17876$at_traceon
17877
17878
17879
17880# Exercise the error token: without it, we die at the first error,
17881# hence be sure to
17882#
17883# - have several errors which exercise different shift/discardings
17884#   - (): nothing to pop, nothing to discard
17885#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
17886#   - (* * *): nothing to pop, a lot to discard
17887#   - (1 + 2 * *): some to pop and discard
17888#
17889# - test the action associated to `error'
17890#
17891# - check the look-ahead that triggers an error is not discarded
17892#   when we enter error recovery.  Below, the look-ahead causing the
17893#   first error is ")", which is needed to recover from the error and
17894#   produce the "0" that triggers the "0 != 1" error.
17895#
17896cat >input <<'_ATEOF'
17897() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
17898_ATEOF
17899
17900$at_traceoff
17901echo "calc.at:556: \$PREPARSER ./calc input"
17902echo calc.at:556 >$at_check_line_file
17903( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
17904at_status=$?
17905grep '^ *+' $at_stder1 >&2
17906grep -v '^ *+' $at_stder1 >$at_stderr
17907at_failed=false
17908echo stderr:; tee stderr <$at_stderr
17909$at_diff $at_devnull $at_stdout || at_failed=:
17910case $at_status in
17911   77) echo 77 > $at_status_file
17912            exit 77;;
17913   0) ;;
17914   *) echo "calc.at:556: exit code was $at_status, expected 0"
17915      at_failed=:;;
17916esac
17917if $at_failed; then
17918
17919  echo 1 > $at_status_file
17920  exit 1
17921fi
17922
17923$at_traceon
17924
17925
17926# Normalize the observed and expected error messages, depending upon the
17927# options.
17928# 1. Remove the traces from observed.
17929sed '/^Starting/d
17930/^Entering/d
17931/^Stack/d
17932/^Reading/d
17933/^Reducing/d
17934/^Shifting/d
17935/^state/d
17936/^Cleanup:/d
17937/^Error:/d
17938/^Next/d
17939/^Discarding/d
17940/ \$[0-9$]* = /d
17941/^yydestructor:/d' stderr >at-stderr
17942mv at-stderr stderr
17943# 2. Create the reference error message.
17944cat >expout <<'_ATEOF'
179451.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
179461.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
179471.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
179481.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
17949calc: error: 4444 != 1
17950_ATEOF
17951
17952# 3. If locations are not used, remove them.
17953sed 's/^[-0-9.]*: //' expout >at-expout
17954mv at-expout expout
17955# 4. If error-verbose is not used, strip the`, unexpected....' part.
17956sed 's/syntax error, .*$/syntax error/' expout >at-expout
17957mv at-expout expout
17958# 5. Check
17959$at_traceoff
17960echo "calc.at:556: cat stderr"
17961echo calc.at:556 >$at_check_line_file
17962( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
17963at_status=$?
17964grep '^ *+' $at_stder1 >&2
17965grep -v '^ *+' $at_stder1 >$at_stderr
17966at_failed=false
17967$at_diff $at_devnull $at_stderr || at_failed=:
17968$at_diff expout $at_stdout || at_failed=:
17969case $at_status in
17970   77) echo 77 > $at_status_file
17971            exit 77;;
17972   0) ;;
17973   *) echo "calc.at:556: exit code was $at_status, expected 0"
17974      at_failed=:;;
17975esac
17976if $at_failed; then
17977
17978  echo 1 > $at_status_file
17979  exit 1
17980fi
17981
17982$at_traceon
17983
17984
17985
17986# The same, but this time exercising explicitly triggered syntax errors.
17987# POSIX says the look-ahead causing the error should not be discarded.
17988cat >input <<'_ATEOF'
17989(!) + (0 0) = 1
17990_ATEOF
17991
17992$at_traceoff
17993echo "calc.at:556: \$PREPARSER ./calc input"
17994echo calc.at:556 >$at_check_line_file
17995( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
17996at_status=$?
17997grep '^ *+' $at_stder1 >&2
17998grep -v '^ *+' $at_stder1 >$at_stderr
17999at_failed=false
18000echo stderr:; tee stderr <$at_stderr
18001$at_diff $at_devnull $at_stdout || at_failed=:
18002case $at_status in
18003   77) echo 77 > $at_status_file
18004            exit 77;;
18005   0) ;;
18006   *) echo "calc.at:556: exit code was $at_status, expected 0"
18007      at_failed=:;;
18008esac
18009if $at_failed; then
18010
18011  echo 1 > $at_status_file
18012  exit 1
18013fi
18014
18015$at_traceon
18016
18017
18018# Normalize the observed and expected error messages, depending upon the
18019# options.
18020# 1. Remove the traces from observed.
18021sed '/^Starting/d
18022/^Entering/d
18023/^Stack/d
18024/^Reading/d
18025/^Reducing/d
18026/^Shifting/d
18027/^state/d
18028/^Cleanup:/d
18029/^Error:/d
18030/^Next/d
18031/^Discarding/d
18032/ \$[0-9$]* = /d
18033/^yydestructor:/d' stderr >at-stderr
18034mv at-stderr stderr
18035# 2. Create the reference error message.
18036cat >expout <<'_ATEOF'
180371.9: syntax error, unexpected number
18038calc: error: 2222 != 1
18039_ATEOF
18040
18041# 3. If locations are not used, remove them.
18042sed 's/^[-0-9.]*: //' expout >at-expout
18043mv at-expout expout
18044# 4. If error-verbose is not used, strip the`, unexpected....' part.
18045sed 's/syntax error, .*$/syntax error/' expout >at-expout
18046mv at-expout expout
18047# 5. Check
18048$at_traceoff
18049echo "calc.at:556: cat stderr"
18050echo calc.at:556 >$at_check_line_file
18051( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
18052at_status=$?
18053grep '^ *+' $at_stder1 >&2
18054grep -v '^ *+' $at_stder1 >$at_stderr
18055at_failed=false
18056$at_diff $at_devnull $at_stderr || at_failed=:
18057$at_diff expout $at_stdout || at_failed=:
18058case $at_status in
18059   77) echo 77 > $at_status_file
18060            exit 77;;
18061   0) ;;
18062   *) echo "calc.at:556: exit code was $at_status, expected 0"
18063      at_failed=:;;
18064esac
18065if $at_failed; then
18066
18067  echo 1 > $at_status_file
18068  exit 1
18069fi
18070
18071$at_traceon
18072
18073
18074cat >input <<'_ATEOF'
18075(- *) + (0 0) = 1
18076_ATEOF
18077
18078$at_traceoff
18079echo "calc.at:556: \$PREPARSER ./calc input"
18080echo calc.at:556 >$at_check_line_file
18081( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
18082at_status=$?
18083grep '^ *+' $at_stder1 >&2
18084grep -v '^ *+' $at_stder1 >$at_stderr
18085at_failed=false
18086echo stderr:; tee stderr <$at_stderr
18087$at_diff $at_devnull $at_stdout || at_failed=:
18088case $at_status in
18089   77) echo 77 > $at_status_file
18090            exit 77;;
18091   0) ;;
18092   *) echo "calc.at:556: exit code was $at_status, expected 0"
18093      at_failed=:;;
18094esac
18095if $at_failed; then
18096
18097  echo 1 > $at_status_file
18098  exit 1
18099fi
18100
18101$at_traceon
18102
18103
18104# Normalize the observed and expected error messages, depending upon the
18105# options.
18106# 1. Remove the traces from observed.
18107sed '/^Starting/d
18108/^Entering/d
18109/^Stack/d
18110/^Reading/d
18111/^Reducing/d
18112/^Shifting/d
18113/^state/d
18114/^Cleanup:/d
18115/^Error:/d
18116/^Next/d
18117/^Discarding/d
18118/ \$[0-9$]* = /d
18119/^yydestructor:/d' stderr >at-stderr
18120mv at-stderr stderr
18121# 2. Create the reference error message.
18122cat >expout <<'_ATEOF'
181231.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
181241.11: syntax error, unexpected number
18125calc: error: 2222 != 1
18126_ATEOF
18127
18128# 3. If locations are not used, remove them.
18129sed 's/^[-0-9.]*: //' expout >at-expout
18130mv at-expout expout
18131# 4. If error-verbose is not used, strip the`, unexpected....' part.
18132sed 's/syntax error, .*$/syntax error/' expout >at-expout
18133mv at-expout expout
18134# 5. Check
18135$at_traceoff
18136echo "calc.at:556: cat stderr"
18137echo calc.at:556 >$at_check_line_file
18138( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
18139at_status=$?
18140grep '^ *+' $at_stder1 >&2
18141grep -v '^ *+' $at_stder1 >$at_stderr
18142at_failed=false
18143$at_diff $at_devnull $at_stderr || at_failed=:
18144$at_diff expout $at_stdout || at_failed=:
18145case $at_status in
18146   77) echo 77 > $at_status_file
18147            exit 77;;
18148   0) ;;
18149   *) echo "calc.at:556: exit code was $at_status, expected 0"
18150      at_failed=:;;
18151esac
18152if $at_failed; then
18153
18154  echo 1 > $at_status_file
18155  exit 1
18156fi
18157
18158$at_traceon
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183      $at_traceoff
18184      $at_times_p && times >$at_times_file
18185    ) 5>&1 2>&1 | eval $at_tee_pipe
18186    at_status=`cat $at_status_file`
18187    ;;
18188
18189  76 ) # 76. calc.at:557: Calculator %error-verbose
18190    at_setup_line='calc.at:557'
18191    at_desc='Calculator %error-verbose'
18192    $at_quiet $ECHO_N " 76: Calculator %error-verbose                    $ECHO_C"
18193    at_xfail=no
18194    (
18195      echo "76. calc.at:557: testing ..."
18196      $at_traceon
18197
18198
18199
18200
18201
18202
18203
18204
18205# Using yacc.c?
18206
18207
18208
18209
18210
18211
18212
18213# yyerror receives the location if %location & %pure & (%glr or %parse-param).
18214
18215# yyerror always sees the locations (when activated), except if
18216# yacc & pure & !param.
18217
18218
18219# The interface is pure: either because %pure-parser, or because we
18220# are using the C++ parsers.
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
18231
18232
18233cat >calc.y <<'_ATEOF'
18234%{
18235#ifdef HAVE_CONFIG_H
18236# include <config.h>
18237  /* We don't need perfect functions for these tests. */
18238# undef malloc
18239# undef memcmp
18240# undef realloc
18241#endif
18242%}
18243
18244/* Infix notation calculator--calc */
18245%error-verbose
18246
18247%{
18248#include <stdio.h>
18249
18250#include <stdlib.h>
18251#include <string.h>
18252#if HAVE_UNISTD_H
18253# include <unistd.h>
18254#else
18255# undef alarm
18256# define alarm(seconds) /* empty */
18257#endif
18258#include <ctype.h>
18259#define USE(Var)
18260
18261/* Exercise pre-prologue dependency to %union.  */
18262typedef int semantic_value;
18263
18264static semantic_value global_result = 0;
18265static int global_count = 0;
18266%}
18267
18268/* Exercise %union. */
18269%union
18270{
18271  semantic_value ival;
18272};
18273
18274%{
18275static int power (int base, int exponent);
18276/* yyerror receives the location if:
18277   - %location & %pure & %glr
18278   - %location & %pure & %yacc & %parse-param. */
18279static void yyerror (
18280
18281                     const char *s
18282                     );
18283static int yylex (void);
18284static int get_char (void);
18285static void unget_char ( int c);
18286%}
18287
18288
18289
18290/* Bison Declarations */
18291%token CALC_EOF 0 "end of input"
18292%token <ival> NUM "number"
18293%type  <ival> exp
18294
18295%nonassoc '=' /* comparison	       */
18296%left '-' '+'
18297%left '*' '/'
18298%left NEG     /* negation--unary minus */
18299%right '^'    /* exponentiation        */
18300
18301/* Grammar follows */
18302%%
18303input:
18304  line
18305| input line         {  }
18306;
18307
18308line:
18309  '\n'
18310| exp '\n'           { USE ($1); }
18311;
18312
18313exp:
18314  NUM                { $$ = $1;             }
18315| exp '=' exp
18316  {
18317    if ($1 != $3)
18318      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
18319    $$ = $1;
18320  }
18321| exp '+' exp        { $$ = $1 + $3;        }
18322| exp '-' exp        { $$ = $1 - $3;        }
18323| exp '*' exp        { $$ = $1 * $3;        }
18324| exp '/' exp        { $$ = $1 / $3;        }
18325| '-' exp  %prec NEG { $$ = -$2;            }
18326| exp '^' exp        { $$ = power ($1, $3); }
18327| '(' exp ')'        { $$ = $2;             }
18328| '(' error ')'      { $$ = 1111;           }
18329| '!'                { $$ = 0; YYERROR;     }
18330| '-' error          { $$ = 0; YYERROR;     }
18331;
18332%%
18333/* The input.  */
18334static FILE *input;
18335
18336static void
18337yyerror (
18338
18339         const char *s)
18340{
18341
18342
18343  fprintf (stderr, "%s\n", s);
18344}
18345
18346
18347
18348static int
18349get_char (void)
18350{
18351  int res = getc (input);
18352  ;
18353
18354  return res;
18355}
18356
18357
18358static void
18359unget_char ( int c)
18360{
18361  ;
18362
18363  ungetc (c, input);
18364}
18365
18366static int
18367read_signed_integer (void)
18368{
18369  int c = get_char ();
18370  int sign = 1;
18371  int n = 0;
18372
18373  ;
18374  if (c == '-')
18375    {
18376      c = get_char ();
18377      sign = -1;
18378    }
18379
18380  while (isdigit (c))
18381    {
18382      n = 10 * n + (c - '0');
18383      c = get_char ();
18384    }
18385
18386  unget_char ( c);
18387
18388  return sign * n;
18389}
18390
18391
18392
18393/*---------------------------------------------------------------.
18394| Lexical analyzer returns an integer on the stack and the token |
18395| NUM, or the ASCII character read if not a number.  Skips all   |
18396| blanks and tabs, returns 0 for EOF.                            |
18397`---------------------------------------------------------------*/
18398
18399static int
18400yylex (void)
18401{
18402  static int init = 1;
18403  int c;
18404
18405  if (init)
18406    {
18407      init = 0;
18408
18409    }
18410
18411
18412
18413  /* Skip white space.  */
18414  while ((c = get_char ()) == ' ' || c == '\t')
18415    {
18416
18417    }
18418
18419  /* process numbers   */
18420  if (c == '.' || isdigit (c))
18421    {
18422      unget_char ( c);
18423      (yylval).ival = read_signed_integer ();
18424      return NUM;
18425    }
18426
18427  /* Return end-of-file.  */
18428  if (c == EOF)
18429    return CALC_EOF;
18430
18431  /* Return single chars. */
18432  return c;
18433}
18434
18435static int
18436power (int base, int exponent)
18437{
18438  int res = 1;
18439  if (exponent < 0)
18440    exit (3);
18441  for (/* Niente */; exponent; --exponent)
18442    res *= base;
18443  return res;
18444}
18445
18446
18447int
18448main (int argc, const char **argv)
18449{
18450  semantic_value result = 0;
18451  int count = 0;
18452  int status;
18453
18454  /* This used to be alarm (10), but that isn't enough time for
18455     a July 1995 vintage DEC Alphastation 200 4/100 system,
18456     according to Nelson H. F. Beebe.  100 seconds is enough.  */
18457  alarm (100);
18458
18459  if (argc == 2)
18460    input = fopen (argv[1], "r");
18461  else
18462    input = stdin;
18463
18464  if (!input)
18465    {
18466      perror (argv[1]);
18467      return 3;
18468    }
18469
18470
18471  status = yyparse ();
18472  if (global_result != result)
18473    abort ();
18474  if (global_count != count)
18475    abort ();
18476  return status;
18477}
18478_ATEOF
18479
18480
18481
18482
18483
18484$at_traceoff
18485echo "calc.at:557: bison -o calc.c calc.y"
18486echo calc.at:557 >$at_check_line_file
18487( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
18488at_status=$?
18489grep '^ *+' $at_stder1 >&2
18490grep -v '^ *+' $at_stder1 >$at_stderr
18491at_failed=false
18492$at_diff $at_devnull $at_stderr || at_failed=:
18493$at_diff $at_devnull $at_stdout || at_failed=:
18494case $at_status in
18495   77) echo 77 > $at_status_file
18496            exit 77;;
18497   0) ;;
18498   *) echo "calc.at:557: exit code was $at_status, expected 0"
18499      at_failed=:;;
18500esac
18501if $at_failed; then
18502
18503  echo 1 > $at_status_file
18504  exit 1
18505fi
18506
18507$at_traceon
18508
18509   $at_traceoff
18510echo "calc.at:557: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
18511echo calc.at:557 >$at_check_line_file
18512( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
18513at_status=$?
18514grep '^ *+' $at_stder1 >&2
18515grep -v '^ *+' $at_stder1 >$at_stderr
18516at_failed=false
18517echo stderr:; cat $at_stderr
18518echo stdout:; cat $at_stdout
18519case $at_status in
18520   77) echo 77 > $at_status_file
18521            exit 77;;
18522   0) ;;
18523   *) echo "calc.at:557: exit code was $at_status, expected 0"
18524      at_failed=:;;
18525esac
18526if $at_failed; then
18527
18528  echo 1 > $at_status_file
18529  exit 1
18530fi
18531
18532$at_traceon
18533
18534
18535# Test the priorities.
18536cat >input <<'_ATEOF'
185371 + 2 * 3 = 7
185381 + 2 * -3 = -5
18539
18540-1^2 = -1
18541(-1)^2 = 1
18542
18543---1 = -1
18544
185451 - 2 - 3 = -4
185461 - (2 - 3) = 2
18547
185482^2^3 = 256
18549(2^2)^3 = 64
18550_ATEOF
18551
18552$at_traceoff
18553echo "calc.at:557: \$PREPARSER ./calc input"
18554echo calc.at:557 >$at_check_line_file
18555( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
18556at_status=$?
18557grep '^ *+' $at_stder1 >&2
18558grep -v '^ *+' $at_stder1 >$at_stderr
18559at_failed=false
18560echo stderr:; tee stderr <$at_stderr
18561$at_diff $at_devnull $at_stdout || at_failed=:
18562case $at_status in
18563   77) echo 77 > $at_status_file
18564            exit 77;;
18565   0) ;;
18566   *) echo "calc.at:557: exit code was $at_status, expected 0"
18567      at_failed=:;;
18568esac
18569if $at_failed; then
18570
18571  echo 1 > $at_status_file
18572  exit 1
18573fi
18574
18575$at_traceon
18576
18577
18578
18579# Some syntax errors.
18580cat >input <<'_ATEOF'
185810 0
18582_ATEOF
18583
18584$at_traceoff
18585echo "calc.at:557: \$PREPARSER ./calc input"
18586echo calc.at:557 >$at_check_line_file
18587( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
18588at_status=$?
18589grep '^ *+' $at_stder1 >&2
18590grep -v '^ *+' $at_stder1 >$at_stderr
18591at_failed=false
18592echo stderr:; tee stderr <$at_stderr
18593$at_diff $at_devnull $at_stdout || at_failed=:
18594case $at_status in
18595   77) echo 77 > $at_status_file
18596            exit 77;;
18597   1) ;;
18598   *) echo "calc.at:557: exit code was $at_status, expected 1"
18599      at_failed=:;;
18600esac
18601if $at_failed; then
18602
18603  echo 1 > $at_status_file
18604  exit 1
18605fi
18606
18607$at_traceon
18608
18609
18610# Normalize the observed and expected error messages, depending upon the
18611# options.
18612# 1. Remove the traces from observed.
18613sed '/^Starting/d
18614/^Entering/d
18615/^Stack/d
18616/^Reading/d
18617/^Reducing/d
18618/^Shifting/d
18619/^state/d
18620/^Cleanup:/d
18621/^Error:/d
18622/^Next/d
18623/^Discarding/d
18624/ \$[0-9$]* = /d
18625/^yydestructor:/d' stderr >at-stderr
18626mv at-stderr stderr
18627# 2. Create the reference error message.
18628cat >expout <<'_ATEOF'
186291.2: syntax error, unexpected number
18630_ATEOF
18631
18632# 3. If locations are not used, remove them.
18633sed 's/^[-0-9.]*: //' expout >at-expout
18634mv at-expout expout
18635# 4. If error-verbose is not used, strip the`, unexpected....' part.
18636
18637# 5. Check
18638$at_traceoff
18639echo "calc.at:557: cat stderr"
18640echo calc.at:557 >$at_check_line_file
18641( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
18642at_status=$?
18643grep '^ *+' $at_stder1 >&2
18644grep -v '^ *+' $at_stder1 >$at_stderr
18645at_failed=false
18646$at_diff $at_devnull $at_stderr || at_failed=:
18647$at_diff expout $at_stdout || at_failed=:
18648case $at_status in
18649   77) echo 77 > $at_status_file
18650            exit 77;;
18651   0) ;;
18652   *) echo "calc.at:557: exit code was $at_status, expected 0"
18653      at_failed=:;;
18654esac
18655if $at_failed; then
18656
18657  echo 1 > $at_status_file
18658  exit 1
18659fi
18660
18661$at_traceon
18662
18663
18664cat >input <<'_ATEOF'
186651//2
18666_ATEOF
18667
18668$at_traceoff
18669echo "calc.at:557: \$PREPARSER ./calc input"
18670echo calc.at:557 >$at_check_line_file
18671( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
18672at_status=$?
18673grep '^ *+' $at_stder1 >&2
18674grep -v '^ *+' $at_stder1 >$at_stderr
18675at_failed=false
18676echo stderr:; tee stderr <$at_stderr
18677$at_diff $at_devnull $at_stdout || at_failed=:
18678case $at_status in
18679   77) echo 77 > $at_status_file
18680            exit 77;;
18681   1) ;;
18682   *) echo "calc.at:557: exit code was $at_status, expected 1"
18683      at_failed=:;;
18684esac
18685if $at_failed; then
18686
18687  echo 1 > $at_status_file
18688  exit 1
18689fi
18690
18691$at_traceon
18692
18693
18694# Normalize the observed and expected error messages, depending upon the
18695# options.
18696# 1. Remove the traces from observed.
18697sed '/^Starting/d
18698/^Entering/d
18699/^Stack/d
18700/^Reading/d
18701/^Reducing/d
18702/^Shifting/d
18703/^state/d
18704/^Cleanup:/d
18705/^Error:/d
18706/^Next/d
18707/^Discarding/d
18708/ \$[0-9$]* = /d
18709/^yydestructor:/d' stderr >at-stderr
18710mv at-stderr stderr
18711# 2. Create the reference error message.
18712cat >expout <<'_ATEOF'
187131.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
18714_ATEOF
18715
18716# 3. If locations are not used, remove them.
18717sed 's/^[-0-9.]*: //' expout >at-expout
18718mv at-expout expout
18719# 4. If error-verbose is not used, strip the`, unexpected....' part.
18720
18721# 5. Check
18722$at_traceoff
18723echo "calc.at:557: cat stderr"
18724echo calc.at:557 >$at_check_line_file
18725( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
18726at_status=$?
18727grep '^ *+' $at_stder1 >&2
18728grep -v '^ *+' $at_stder1 >$at_stderr
18729at_failed=false
18730$at_diff $at_devnull $at_stderr || at_failed=:
18731$at_diff expout $at_stdout || at_failed=:
18732case $at_status in
18733   77) echo 77 > $at_status_file
18734            exit 77;;
18735   0) ;;
18736   *) echo "calc.at:557: exit code was $at_status, expected 0"
18737      at_failed=:;;
18738esac
18739if $at_failed; then
18740
18741  echo 1 > $at_status_file
18742  exit 1
18743fi
18744
18745$at_traceon
18746
18747
18748cat >input <<'_ATEOF'
18749error
18750_ATEOF
18751
18752$at_traceoff
18753echo "calc.at:557: \$PREPARSER ./calc input"
18754echo calc.at:557 >$at_check_line_file
18755( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
18756at_status=$?
18757grep '^ *+' $at_stder1 >&2
18758grep -v '^ *+' $at_stder1 >$at_stderr
18759at_failed=false
18760echo stderr:; tee stderr <$at_stderr
18761$at_diff $at_devnull $at_stdout || at_failed=:
18762case $at_status in
18763   77) echo 77 > $at_status_file
18764            exit 77;;
18765   1) ;;
18766   *) echo "calc.at:557: exit code was $at_status, expected 1"
18767      at_failed=:;;
18768esac
18769if $at_failed; then
18770
18771  echo 1 > $at_status_file
18772  exit 1
18773fi
18774
18775$at_traceon
18776
18777
18778# Normalize the observed and expected error messages, depending upon the
18779# options.
18780# 1. Remove the traces from observed.
18781sed '/^Starting/d
18782/^Entering/d
18783/^Stack/d
18784/^Reading/d
18785/^Reducing/d
18786/^Shifting/d
18787/^state/d
18788/^Cleanup:/d
18789/^Error:/d
18790/^Next/d
18791/^Discarding/d
18792/ \$[0-9$]* = /d
18793/^yydestructor:/d' stderr >at-stderr
18794mv at-stderr stderr
18795# 2. Create the reference error message.
18796cat >expout <<'_ATEOF'
187971.0: syntax error, unexpected $undefined
18798_ATEOF
18799
18800# 3. If locations are not used, remove them.
18801sed 's/^[-0-9.]*: //' expout >at-expout
18802mv at-expout expout
18803# 4. If error-verbose is not used, strip the`, unexpected....' part.
18804
18805# 5. Check
18806$at_traceoff
18807echo "calc.at:557: cat stderr"
18808echo calc.at:557 >$at_check_line_file
18809( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
18810at_status=$?
18811grep '^ *+' $at_stder1 >&2
18812grep -v '^ *+' $at_stder1 >$at_stderr
18813at_failed=false
18814$at_diff $at_devnull $at_stderr || at_failed=:
18815$at_diff expout $at_stdout || at_failed=:
18816case $at_status in
18817   77) echo 77 > $at_status_file
18818            exit 77;;
18819   0) ;;
18820   *) echo "calc.at:557: exit code was $at_status, expected 0"
18821      at_failed=:;;
18822esac
18823if $at_failed; then
18824
18825  echo 1 > $at_status_file
18826  exit 1
18827fi
18828
18829$at_traceon
18830
18831
18832cat >input <<'_ATEOF'
188331 = 2 = 3
18834_ATEOF
18835
18836$at_traceoff
18837echo "calc.at:557: \$PREPARSER ./calc input"
18838echo calc.at:557 >$at_check_line_file
18839( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
18840at_status=$?
18841grep '^ *+' $at_stder1 >&2
18842grep -v '^ *+' $at_stder1 >$at_stderr
18843at_failed=false
18844echo stderr:; tee stderr <$at_stderr
18845$at_diff $at_devnull $at_stdout || at_failed=:
18846case $at_status in
18847   77) echo 77 > $at_status_file
18848            exit 77;;
18849   1) ;;
18850   *) echo "calc.at:557: exit code was $at_status, expected 1"
18851      at_failed=:;;
18852esac
18853if $at_failed; then
18854
18855  echo 1 > $at_status_file
18856  exit 1
18857fi
18858
18859$at_traceon
18860
18861
18862# Normalize the observed and expected error messages, depending upon the
18863# options.
18864# 1. Remove the traces from observed.
18865sed '/^Starting/d
18866/^Entering/d
18867/^Stack/d
18868/^Reading/d
18869/^Reducing/d
18870/^Shifting/d
18871/^state/d
18872/^Cleanup:/d
18873/^Error:/d
18874/^Next/d
18875/^Discarding/d
18876/ \$[0-9$]* = /d
18877/^yydestructor:/d' stderr >at-stderr
18878mv at-stderr stderr
18879# 2. Create the reference error message.
18880cat >expout <<'_ATEOF'
188811.6: syntax error, unexpected '='
18882_ATEOF
18883
18884# 3. If locations are not used, remove them.
18885sed 's/^[-0-9.]*: //' expout >at-expout
18886mv at-expout expout
18887# 4. If error-verbose is not used, strip the`, unexpected....' part.
18888
18889# 5. Check
18890$at_traceoff
18891echo "calc.at:557: cat stderr"
18892echo calc.at:557 >$at_check_line_file
18893( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
18894at_status=$?
18895grep '^ *+' $at_stder1 >&2
18896grep -v '^ *+' $at_stder1 >$at_stderr
18897at_failed=false
18898$at_diff $at_devnull $at_stderr || at_failed=:
18899$at_diff expout $at_stdout || at_failed=:
18900case $at_status in
18901   77) echo 77 > $at_status_file
18902            exit 77;;
18903   0) ;;
18904   *) echo "calc.at:557: exit code was $at_status, expected 0"
18905      at_failed=:;;
18906esac
18907if $at_failed; then
18908
18909  echo 1 > $at_status_file
18910  exit 1
18911fi
18912
18913$at_traceon
18914
18915
18916cat >input <<'_ATEOF'
18917
18918+1
18919_ATEOF
18920
18921$at_traceoff
18922echo "calc.at:557: \$PREPARSER ./calc input"
18923echo calc.at:557 >$at_check_line_file
18924( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
18925at_status=$?
18926grep '^ *+' $at_stder1 >&2
18927grep -v '^ *+' $at_stder1 >$at_stderr
18928at_failed=false
18929echo stderr:; tee stderr <$at_stderr
18930$at_diff $at_devnull $at_stdout || at_failed=:
18931case $at_status in
18932   77) echo 77 > $at_status_file
18933            exit 77;;
18934   1) ;;
18935   *) echo "calc.at:557: exit code was $at_status, expected 1"
18936      at_failed=:;;
18937esac
18938if $at_failed; then
18939
18940  echo 1 > $at_status_file
18941  exit 1
18942fi
18943
18944$at_traceon
18945
18946
18947# Normalize the observed and expected error messages, depending upon the
18948# options.
18949# 1. Remove the traces from observed.
18950sed '/^Starting/d
18951/^Entering/d
18952/^Stack/d
18953/^Reading/d
18954/^Reducing/d
18955/^Shifting/d
18956/^state/d
18957/^Cleanup:/d
18958/^Error:/d
18959/^Next/d
18960/^Discarding/d
18961/ \$[0-9$]* = /d
18962/^yydestructor:/d' stderr >at-stderr
18963mv at-stderr stderr
18964# 2. Create the reference error message.
18965cat >expout <<'_ATEOF'
189662.0: syntax error, unexpected '+'
18967_ATEOF
18968
18969# 3. If locations are not used, remove them.
18970sed 's/^[-0-9.]*: //' expout >at-expout
18971mv at-expout expout
18972# 4. If error-verbose is not used, strip the`, unexpected....' part.
18973
18974# 5. Check
18975$at_traceoff
18976echo "calc.at:557: cat stderr"
18977echo calc.at:557 >$at_check_line_file
18978( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
18979at_status=$?
18980grep '^ *+' $at_stder1 >&2
18981grep -v '^ *+' $at_stder1 >$at_stderr
18982at_failed=false
18983$at_diff $at_devnull $at_stderr || at_failed=:
18984$at_diff expout $at_stdout || at_failed=:
18985case $at_status in
18986   77) echo 77 > $at_status_file
18987            exit 77;;
18988   0) ;;
18989   *) echo "calc.at:557: exit code was $at_status, expected 0"
18990      at_failed=:;;
18991esac
18992if $at_failed; then
18993
18994  echo 1 > $at_status_file
18995  exit 1
18996fi
18997
18998$at_traceon
18999
19000
19001# Exercise error messages with EOF: work on an empty file.
19002$at_traceoff
19003echo "calc.at:557: \$PREPARSER ./calc /dev/null"
19004echo calc.at:557 >$at_check_line_file
19005( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
19006at_status=$?
19007grep '^ *+' $at_stder1 >&2
19008grep -v '^ *+' $at_stder1 >$at_stderr
19009at_failed=false
19010echo stderr:; tee stderr <$at_stderr
19011$at_diff $at_devnull $at_stdout || at_failed=:
19012case $at_status in
19013   77) echo 77 > $at_status_file
19014            exit 77;;
19015   1) ;;
19016   *) echo "calc.at:557: exit code was $at_status, expected 1"
19017      at_failed=:;;
19018esac
19019if $at_failed; then
19020
19021  echo 1 > $at_status_file
19022  exit 1
19023fi
19024
19025$at_traceon
19026
19027
19028# Normalize the observed and expected error messages, depending upon the
19029# options.
19030# 1. Remove the traces from observed.
19031sed '/^Starting/d
19032/^Entering/d
19033/^Stack/d
19034/^Reading/d
19035/^Reducing/d
19036/^Shifting/d
19037/^state/d
19038/^Cleanup:/d
19039/^Error:/d
19040/^Next/d
19041/^Discarding/d
19042/ \$[0-9$]* = /d
19043/^yydestructor:/d' stderr >at-stderr
19044mv at-stderr stderr
19045# 2. Create the reference error message.
19046cat >expout <<'_ATEOF'
190471.0: syntax error, unexpected end of input
19048_ATEOF
19049
19050# 3. If locations are not used, remove them.
19051sed 's/^[-0-9.]*: //' expout >at-expout
19052mv at-expout expout
19053# 4. If error-verbose is not used, strip the`, unexpected....' part.
19054
19055# 5. Check
19056$at_traceoff
19057echo "calc.at:557: cat stderr"
19058echo calc.at:557 >$at_check_line_file
19059( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
19060at_status=$?
19061grep '^ *+' $at_stder1 >&2
19062grep -v '^ *+' $at_stder1 >$at_stderr
19063at_failed=false
19064$at_diff $at_devnull $at_stderr || at_failed=:
19065$at_diff expout $at_stdout || at_failed=:
19066case $at_status in
19067   77) echo 77 > $at_status_file
19068            exit 77;;
19069   0) ;;
19070   *) echo "calc.at:557: exit code was $at_status, expected 0"
19071      at_failed=:;;
19072esac
19073if $at_failed; then
19074
19075  echo 1 > $at_status_file
19076  exit 1
19077fi
19078
19079$at_traceon
19080
19081
19082
19083# Exercise the error token: without it, we die at the first error,
19084# hence be sure to
19085#
19086# - have several errors which exercise different shift/discardings
19087#   - (): nothing to pop, nothing to discard
19088#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
19089#   - (* * *): nothing to pop, a lot to discard
19090#   - (1 + 2 * *): some to pop and discard
19091#
19092# - test the action associated to `error'
19093#
19094# - check the look-ahead that triggers an error is not discarded
19095#   when we enter error recovery.  Below, the look-ahead causing the
19096#   first error is ")", which is needed to recover from the error and
19097#   produce the "0" that triggers the "0 != 1" error.
19098#
19099cat >input <<'_ATEOF'
19100() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
19101_ATEOF
19102
19103$at_traceoff
19104echo "calc.at:557: \$PREPARSER ./calc input"
19105echo calc.at:557 >$at_check_line_file
19106( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
19107at_status=$?
19108grep '^ *+' $at_stder1 >&2
19109grep -v '^ *+' $at_stder1 >$at_stderr
19110at_failed=false
19111echo stderr:; tee stderr <$at_stderr
19112$at_diff $at_devnull $at_stdout || at_failed=:
19113case $at_status in
19114   77) echo 77 > $at_status_file
19115            exit 77;;
19116   0) ;;
19117   *) echo "calc.at:557: exit code was $at_status, expected 0"
19118      at_failed=:;;
19119esac
19120if $at_failed; then
19121
19122  echo 1 > $at_status_file
19123  exit 1
19124fi
19125
19126$at_traceon
19127
19128
19129# Normalize the observed and expected error messages, depending upon the
19130# options.
19131# 1. Remove the traces from observed.
19132sed '/^Starting/d
19133/^Entering/d
19134/^Stack/d
19135/^Reading/d
19136/^Reducing/d
19137/^Shifting/d
19138/^state/d
19139/^Cleanup:/d
19140/^Error:/d
19141/^Next/d
19142/^Discarding/d
19143/ \$[0-9$]* = /d
19144/^yydestructor:/d' stderr >at-stderr
19145mv at-stderr stderr
19146# 2. Create the reference error message.
19147cat >expout <<'_ATEOF'
191481.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
191491.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
191501.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
191511.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
19152calc: error: 4444 != 1
19153_ATEOF
19154
19155# 3. If locations are not used, remove them.
19156sed 's/^[-0-9.]*: //' expout >at-expout
19157mv at-expout expout
19158# 4. If error-verbose is not used, strip the`, unexpected....' part.
19159
19160# 5. Check
19161$at_traceoff
19162echo "calc.at:557: cat stderr"
19163echo calc.at:557 >$at_check_line_file
19164( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
19165at_status=$?
19166grep '^ *+' $at_stder1 >&2
19167grep -v '^ *+' $at_stder1 >$at_stderr
19168at_failed=false
19169$at_diff $at_devnull $at_stderr || at_failed=:
19170$at_diff expout $at_stdout || at_failed=:
19171case $at_status in
19172   77) echo 77 > $at_status_file
19173            exit 77;;
19174   0) ;;
19175   *) echo "calc.at:557: exit code was $at_status, expected 0"
19176      at_failed=:;;
19177esac
19178if $at_failed; then
19179
19180  echo 1 > $at_status_file
19181  exit 1
19182fi
19183
19184$at_traceon
19185
19186
19187
19188# The same, but this time exercising explicitly triggered syntax errors.
19189# POSIX says the look-ahead causing the error should not be discarded.
19190cat >input <<'_ATEOF'
19191(!) + (0 0) = 1
19192_ATEOF
19193
19194$at_traceoff
19195echo "calc.at:557: \$PREPARSER ./calc input"
19196echo calc.at:557 >$at_check_line_file
19197( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
19198at_status=$?
19199grep '^ *+' $at_stder1 >&2
19200grep -v '^ *+' $at_stder1 >$at_stderr
19201at_failed=false
19202echo stderr:; tee stderr <$at_stderr
19203$at_diff $at_devnull $at_stdout || at_failed=:
19204case $at_status in
19205   77) echo 77 > $at_status_file
19206            exit 77;;
19207   0) ;;
19208   *) echo "calc.at:557: exit code was $at_status, expected 0"
19209      at_failed=:;;
19210esac
19211if $at_failed; then
19212
19213  echo 1 > $at_status_file
19214  exit 1
19215fi
19216
19217$at_traceon
19218
19219
19220# Normalize the observed and expected error messages, depending upon the
19221# options.
19222# 1. Remove the traces from observed.
19223sed '/^Starting/d
19224/^Entering/d
19225/^Stack/d
19226/^Reading/d
19227/^Reducing/d
19228/^Shifting/d
19229/^state/d
19230/^Cleanup:/d
19231/^Error:/d
19232/^Next/d
19233/^Discarding/d
19234/ \$[0-9$]* = /d
19235/^yydestructor:/d' stderr >at-stderr
19236mv at-stderr stderr
19237# 2. Create the reference error message.
19238cat >expout <<'_ATEOF'
192391.9: syntax error, unexpected number
19240calc: error: 2222 != 1
19241_ATEOF
19242
19243# 3. If locations are not used, remove them.
19244sed 's/^[-0-9.]*: //' expout >at-expout
19245mv at-expout expout
19246# 4. If error-verbose is not used, strip the`, unexpected....' part.
19247
19248# 5. Check
19249$at_traceoff
19250echo "calc.at:557: cat stderr"
19251echo calc.at:557 >$at_check_line_file
19252( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
19253at_status=$?
19254grep '^ *+' $at_stder1 >&2
19255grep -v '^ *+' $at_stder1 >$at_stderr
19256at_failed=false
19257$at_diff $at_devnull $at_stderr || at_failed=:
19258$at_diff expout $at_stdout || at_failed=:
19259case $at_status in
19260   77) echo 77 > $at_status_file
19261            exit 77;;
19262   0) ;;
19263   *) echo "calc.at:557: exit code was $at_status, expected 0"
19264      at_failed=:;;
19265esac
19266if $at_failed; then
19267
19268  echo 1 > $at_status_file
19269  exit 1
19270fi
19271
19272$at_traceon
19273
19274
19275cat >input <<'_ATEOF'
19276(- *) + (0 0) = 1
19277_ATEOF
19278
19279$at_traceoff
19280echo "calc.at:557: \$PREPARSER ./calc input"
19281echo calc.at:557 >$at_check_line_file
19282( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
19283at_status=$?
19284grep '^ *+' $at_stder1 >&2
19285grep -v '^ *+' $at_stder1 >$at_stderr
19286at_failed=false
19287echo stderr:; tee stderr <$at_stderr
19288$at_diff $at_devnull $at_stdout || at_failed=:
19289case $at_status in
19290   77) echo 77 > $at_status_file
19291            exit 77;;
19292   0) ;;
19293   *) echo "calc.at:557: exit code was $at_status, expected 0"
19294      at_failed=:;;
19295esac
19296if $at_failed; then
19297
19298  echo 1 > $at_status_file
19299  exit 1
19300fi
19301
19302$at_traceon
19303
19304
19305# Normalize the observed and expected error messages, depending upon the
19306# options.
19307# 1. Remove the traces from observed.
19308sed '/^Starting/d
19309/^Entering/d
19310/^Stack/d
19311/^Reading/d
19312/^Reducing/d
19313/^Shifting/d
19314/^state/d
19315/^Cleanup:/d
19316/^Error:/d
19317/^Next/d
19318/^Discarding/d
19319/ \$[0-9$]* = /d
19320/^yydestructor:/d' stderr >at-stderr
19321mv at-stderr stderr
19322# 2. Create the reference error message.
19323cat >expout <<'_ATEOF'
193241.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
193251.11: syntax error, unexpected number
19326calc: error: 2222 != 1
19327_ATEOF
19328
19329# 3. If locations are not used, remove them.
19330sed 's/^[-0-9.]*: //' expout >at-expout
19331mv at-expout expout
19332# 4. If error-verbose is not used, strip the`, unexpected....' part.
19333
19334# 5. Check
19335$at_traceoff
19336echo "calc.at:557: cat stderr"
19337echo calc.at:557 >$at_check_line_file
19338( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
19339at_status=$?
19340grep '^ *+' $at_stder1 >&2
19341grep -v '^ *+' $at_stder1 >$at_stderr
19342at_failed=false
19343$at_diff $at_devnull $at_stderr || at_failed=:
19344$at_diff expout $at_stdout || at_failed=:
19345case $at_status in
19346   77) echo 77 > $at_status_file
19347            exit 77;;
19348   0) ;;
19349   *) echo "calc.at:557: exit code was $at_status, expected 0"
19350      at_failed=:;;
19351esac
19352if $at_failed; then
19353
19354  echo 1 > $at_status_file
19355  exit 1
19356fi
19357
19358$at_traceon
19359
19360
19361
19362
19363
19364
19365
19366
19367
19368
19369
19370
19371
19372
19373
19374
19375
19376
19377
19378
19379
19380
19381
19382
19383      $at_traceoff
19384      $at_times_p && times >$at_times_file
19385    ) 5>&1 2>&1 | eval $at_tee_pipe
19386    at_status=`cat $at_status_file`
19387    ;;
19388
19389  77 ) # 77. calc.at:559: Calculator %pure-parser %locations
19390    at_setup_line='calc.at:559'
19391    at_desc='Calculator %pure-parser %locations'
19392    $at_quiet $ECHO_N " 77: Calculator %pure-parser %locations           $ECHO_C"
19393    at_xfail=no
19394    (
19395      echo "77. calc.at:559: testing ..."
19396      $at_traceon
19397
19398
19399
19400
19401
19402
19403
19404
19405# Using yacc.c?
19406
19407
19408
19409
19410
19411
19412
19413# yyerror receives the location if %location & %pure & (%glr or %parse-param).
19414
19415# yyerror always sees the locations (when activated), except if
19416# yacc & pure & !param.
19417
19418
19419# The interface is pure: either because %pure-parser, or because we
19420# are using the C++ parsers.
19421
19422
19423
19424
19425
19426
19427
19428
19429
19430
19431
19432
19433cat >calc.y <<'_ATEOF'
19434%{
19435#ifdef HAVE_CONFIG_H
19436# include <config.h>
19437  /* We don't need perfect functions for these tests. */
19438# undef malloc
19439# undef memcmp
19440# undef realloc
19441#endif
19442%}
19443
19444/* Infix notation calculator--calc */
19445%pure-parser %locations
19446
19447%{
19448#include <stdio.h>
19449
19450#include <stdlib.h>
19451#include <string.h>
19452#if HAVE_UNISTD_H
19453# include <unistd.h>
19454#else
19455# undef alarm
19456# define alarm(seconds) /* empty */
19457#endif
19458#include <ctype.h>
19459#define USE(Var)
19460
19461/* Exercise pre-prologue dependency to %union.  */
19462typedef int semantic_value;
19463
19464static semantic_value global_result = 0;
19465static int global_count = 0;
19466%}
19467
19468/* Exercise %union. */
19469%union
19470{
19471  semantic_value ival;
19472};
19473
19474%{
19475static int power (int base, int exponent);
19476/* yyerror receives the location if:
19477   - %location & %pure & %glr
19478   - %location & %pure & %yacc & %parse-param. */
19479static void yyerror (
19480
19481                     const char *s
19482                     );
19483static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
19484static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp);
19485static void unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c);
19486%}
19487
19488
19489
19490/* Bison Declarations */
19491%token CALC_EOF 0 "end of input"
19492%token <ival> NUM "number"
19493%type  <ival> exp
19494
19495%nonassoc '=' /* comparison	       */
19496%left '-' '+'
19497%left '*' '/'
19498%left NEG     /* negation--unary minus */
19499%right '^'    /* exponentiation        */
19500
19501/* Grammar follows */
19502%%
19503input:
19504  line
19505| input line         {  }
19506;
19507
19508line:
19509  '\n'
19510| exp '\n'           { USE ($1); }
19511;
19512
19513exp:
19514  NUM                { $$ = $1;             }
19515| exp '=' exp
19516  {
19517    if ($1 != $3)
19518      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
19519    $$ = $1;
19520  }
19521| exp '+' exp        { $$ = $1 + $3;        }
19522| exp '-' exp        { $$ = $1 - $3;        }
19523| exp '*' exp        { $$ = $1 * $3;        }
19524| exp '/' exp        { $$ = $1 / $3;        }
19525| '-' exp  %prec NEG { $$ = -$2;            }
19526| exp '^' exp        { $$ = power ($1, $3); }
19527| '(' exp ')'        { $$ = $2;             }
19528| '(' error ')'      { $$ = 1111;           }
19529| '!'                { $$ = 0; YYERROR;     }
19530| '-' error          { $$ = 0; YYERROR;     }
19531;
19532%%
19533/* The input.  */
19534static FILE *input;
19535
19536static void
19537yyerror (
19538
19539         const char *s)
19540{
19541
19542
19543  fprintf (stderr, "%s\n", s);
19544}
19545
19546
19547
19548static YYLTYPE last_yylloc;
19549
19550static int
19551get_char (YYSTYPE *lvalp, YYLTYPE *llocp)
19552{
19553  int res = getc (input);
19554  (void) lvalp;(void) llocp;
19555
19556  last_yylloc = (*llocp);
19557  if (res == '\n')
19558    {
19559      (*llocp).last_line++;
19560      (*llocp).last_column = 0;
19561    }
19562  else
19563    (*llocp).last_column++;
19564
19565  return res;
19566}
19567
19568
19569static void
19570unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c)
19571{
19572  (void) lvalp;(void) llocp;
19573
19574  /* Wrong when C == `\n'. */
19575  (*llocp) = last_yylloc;
19576
19577  ungetc (c, input);
19578}
19579
19580static int
19581read_signed_integer (YYSTYPE *lvalp, YYLTYPE *llocp)
19582{
19583  int c = get_char (lvalp, llocp);
19584  int sign = 1;
19585  int n = 0;
19586
19587  (void) lvalp;(void) llocp;
19588  if (c == '-')
19589    {
19590      c = get_char (lvalp, llocp);
19591      sign = -1;
19592    }
19593
19594  while (isdigit (c))
19595    {
19596      n = 10 * n + (c - '0');
19597      c = get_char (lvalp, llocp);
19598    }
19599
19600  unget_char (lvalp, llocp,  c);
19601
19602  return sign * n;
19603}
19604
19605
19606
19607/*---------------------------------------------------------------.
19608| Lexical analyzer returns an integer on the stack and the token |
19609| NUM, or the ASCII character read if not a number.  Skips all   |
19610| blanks and tabs, returns 0 for EOF.                            |
19611`---------------------------------------------------------------*/
19612
19613static int
19614yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
19615{
19616  static int init = 1;
19617  int c;
19618
19619  if (init)
19620    {
19621      init = 0;
19622
19623      (*llocp).last_column = 0;
19624      (*llocp).last_line = 1;
19625
19626    }
19627
19628
19629 (*llocp).first_column = (*llocp).last_column;
19630  (*llocp).first_line   = (*llocp).last_line;
19631
19632
19633  /* Skip white space.  */
19634  while ((c = get_char (lvalp, llocp)) == ' ' || c == '\t')
19635    {
19636     (*llocp).first_column = (*llocp).last_column;
19637      (*llocp).first_line   = (*llocp).last_line;
19638
19639    }
19640
19641  /* process numbers   */
19642  if (c == '.' || isdigit (c))
19643    {
19644      unget_char (lvalp, llocp,  c);
19645      (*lvalp).ival = read_signed_integer (lvalp, llocp);
19646      return NUM;
19647    }
19648
19649  /* Return end-of-file.  */
19650  if (c == EOF)
19651    return CALC_EOF;
19652
19653  /* Return single chars. */
19654  return c;
19655}
19656
19657static int
19658power (int base, int exponent)
19659{
19660  int res = 1;
19661  if (exponent < 0)
19662    exit (3);
19663  for (/* Niente */; exponent; --exponent)
19664    res *= base;
19665  return res;
19666}
19667
19668
19669int
19670main (int argc, const char **argv)
19671{
19672  semantic_value result = 0;
19673  int count = 0;
19674  int status;
19675
19676  /* This used to be alarm (10), but that isn't enough time for
19677     a July 1995 vintage DEC Alphastation 200 4/100 system,
19678     according to Nelson H. F. Beebe.  100 seconds is enough.  */
19679  alarm (100);
19680
19681  if (argc == 2)
19682    input = fopen (argv[1], "r");
19683  else
19684    input = stdin;
19685
19686  if (!input)
19687    {
19688      perror (argv[1]);
19689      return 3;
19690    }
19691
19692
19693  status = yyparse ();
19694  if (global_result != result)
19695    abort ();
19696  if (global_count != count)
19697    abort ();
19698  return status;
19699}
19700_ATEOF
19701
19702
19703
19704
19705
19706$at_traceoff
19707echo "calc.at:559: bison -o calc.c calc.y"
19708echo calc.at:559 >$at_check_line_file
19709( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
19710at_status=$?
19711grep '^ *+' $at_stder1 >&2
19712grep -v '^ *+' $at_stder1 >$at_stderr
19713at_failed=false
19714$at_diff $at_devnull $at_stderr || at_failed=:
19715$at_diff $at_devnull $at_stdout || at_failed=:
19716case $at_status in
19717   77) echo 77 > $at_status_file
19718            exit 77;;
19719   0) ;;
19720   *) echo "calc.at:559: exit code was $at_status, expected 0"
19721      at_failed=:;;
19722esac
19723if $at_failed; then
19724
19725  echo 1 > $at_status_file
19726  exit 1
19727fi
19728
19729$at_traceon
19730
19731   $at_traceoff
19732echo "calc.at:559: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
19733echo calc.at:559 >$at_check_line_file
19734( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
19735at_status=$?
19736grep '^ *+' $at_stder1 >&2
19737grep -v '^ *+' $at_stder1 >$at_stderr
19738at_failed=false
19739echo stderr:; cat $at_stderr
19740echo stdout:; cat $at_stdout
19741case $at_status in
19742   77) echo 77 > $at_status_file
19743            exit 77;;
19744   0) ;;
19745   *) echo "calc.at:559: exit code was $at_status, expected 0"
19746      at_failed=:;;
19747esac
19748if $at_failed; then
19749
19750  echo 1 > $at_status_file
19751  exit 1
19752fi
19753
19754$at_traceon
19755
19756
19757# Test the priorities.
19758cat >input <<'_ATEOF'
197591 + 2 * 3 = 7
197601 + 2 * -3 = -5
19761
19762-1^2 = -1
19763(-1)^2 = 1
19764
19765---1 = -1
19766
197671 - 2 - 3 = -4
197681 - (2 - 3) = 2
19769
197702^2^3 = 256
19771(2^2)^3 = 64
19772_ATEOF
19773
19774$at_traceoff
19775echo "calc.at:559: \$PREPARSER ./calc input"
19776echo calc.at:559 >$at_check_line_file
19777( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
19778at_status=$?
19779grep '^ *+' $at_stder1 >&2
19780grep -v '^ *+' $at_stder1 >$at_stderr
19781at_failed=false
19782echo stderr:; tee stderr <$at_stderr
19783$at_diff $at_devnull $at_stdout || at_failed=:
19784case $at_status in
19785   77) echo 77 > $at_status_file
19786            exit 77;;
19787   0) ;;
19788   *) echo "calc.at:559: exit code was $at_status, expected 0"
19789      at_failed=:;;
19790esac
19791if $at_failed; then
19792
19793  echo 1 > $at_status_file
19794  exit 1
19795fi
19796
19797$at_traceon
19798
19799
19800
19801# Some syntax errors.
19802cat >input <<'_ATEOF'
198030 0
19804_ATEOF
19805
19806$at_traceoff
19807echo "calc.at:559: \$PREPARSER ./calc input"
19808echo calc.at:559 >$at_check_line_file
19809( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
19810at_status=$?
19811grep '^ *+' $at_stder1 >&2
19812grep -v '^ *+' $at_stder1 >$at_stderr
19813at_failed=false
19814echo stderr:; tee stderr <$at_stderr
19815$at_diff $at_devnull $at_stdout || at_failed=:
19816case $at_status in
19817   77) echo 77 > $at_status_file
19818            exit 77;;
19819   1) ;;
19820   *) echo "calc.at:559: exit code was $at_status, expected 1"
19821      at_failed=:;;
19822esac
19823if $at_failed; then
19824
19825  echo 1 > $at_status_file
19826  exit 1
19827fi
19828
19829$at_traceon
19830
19831
19832# Normalize the observed and expected error messages, depending upon the
19833# options.
19834# 1. Remove the traces from observed.
19835sed '/^Starting/d
19836/^Entering/d
19837/^Stack/d
19838/^Reading/d
19839/^Reducing/d
19840/^Shifting/d
19841/^state/d
19842/^Cleanup:/d
19843/^Error:/d
19844/^Next/d
19845/^Discarding/d
19846/ \$[0-9$]* = /d
19847/^yydestructor:/d' stderr >at-stderr
19848mv at-stderr stderr
19849# 2. Create the reference error message.
19850cat >expout <<'_ATEOF'
198511.2: syntax error, unexpected number
19852_ATEOF
19853
19854# 3. If locations are not used, remove them.
19855sed 's/^[-0-9.]*: //' expout >at-expout
19856mv at-expout expout
19857# 4. If error-verbose is not used, strip the`, unexpected....' part.
19858sed 's/syntax error, .*$/syntax error/' expout >at-expout
19859mv at-expout expout
19860# 5. Check
19861$at_traceoff
19862echo "calc.at:559: cat stderr"
19863echo calc.at:559 >$at_check_line_file
19864( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
19865at_status=$?
19866grep '^ *+' $at_stder1 >&2
19867grep -v '^ *+' $at_stder1 >$at_stderr
19868at_failed=false
19869$at_diff $at_devnull $at_stderr || at_failed=:
19870$at_diff expout $at_stdout || at_failed=:
19871case $at_status in
19872   77) echo 77 > $at_status_file
19873            exit 77;;
19874   0) ;;
19875   *) echo "calc.at:559: exit code was $at_status, expected 0"
19876      at_failed=:;;
19877esac
19878if $at_failed; then
19879
19880  echo 1 > $at_status_file
19881  exit 1
19882fi
19883
19884$at_traceon
19885
19886
19887cat >input <<'_ATEOF'
198881//2
19889_ATEOF
19890
19891$at_traceoff
19892echo "calc.at:559: \$PREPARSER ./calc input"
19893echo calc.at:559 >$at_check_line_file
19894( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
19895at_status=$?
19896grep '^ *+' $at_stder1 >&2
19897grep -v '^ *+' $at_stder1 >$at_stderr
19898at_failed=false
19899echo stderr:; tee stderr <$at_stderr
19900$at_diff $at_devnull $at_stdout || at_failed=:
19901case $at_status in
19902   77) echo 77 > $at_status_file
19903            exit 77;;
19904   1) ;;
19905   *) echo "calc.at:559: exit code was $at_status, expected 1"
19906      at_failed=:;;
19907esac
19908if $at_failed; then
19909
19910  echo 1 > $at_status_file
19911  exit 1
19912fi
19913
19914$at_traceon
19915
19916
19917# Normalize the observed and expected error messages, depending upon the
19918# options.
19919# 1. Remove the traces from observed.
19920sed '/^Starting/d
19921/^Entering/d
19922/^Stack/d
19923/^Reading/d
19924/^Reducing/d
19925/^Shifting/d
19926/^state/d
19927/^Cleanup:/d
19928/^Error:/d
19929/^Next/d
19930/^Discarding/d
19931/ \$[0-9$]* = /d
19932/^yydestructor:/d' stderr >at-stderr
19933mv at-stderr stderr
19934# 2. Create the reference error message.
19935cat >expout <<'_ATEOF'
199361.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
19937_ATEOF
19938
19939# 3. If locations are not used, remove them.
19940sed 's/^[-0-9.]*: //' expout >at-expout
19941mv at-expout expout
19942# 4. If error-verbose is not used, strip the`, unexpected....' part.
19943sed 's/syntax error, .*$/syntax error/' expout >at-expout
19944mv at-expout expout
19945# 5. Check
19946$at_traceoff
19947echo "calc.at:559: cat stderr"
19948echo calc.at:559 >$at_check_line_file
19949( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
19950at_status=$?
19951grep '^ *+' $at_stder1 >&2
19952grep -v '^ *+' $at_stder1 >$at_stderr
19953at_failed=false
19954$at_diff $at_devnull $at_stderr || at_failed=:
19955$at_diff expout $at_stdout || at_failed=:
19956case $at_status in
19957   77) echo 77 > $at_status_file
19958            exit 77;;
19959   0) ;;
19960   *) echo "calc.at:559: exit code was $at_status, expected 0"
19961      at_failed=:;;
19962esac
19963if $at_failed; then
19964
19965  echo 1 > $at_status_file
19966  exit 1
19967fi
19968
19969$at_traceon
19970
19971
19972cat >input <<'_ATEOF'
19973error
19974_ATEOF
19975
19976$at_traceoff
19977echo "calc.at:559: \$PREPARSER ./calc input"
19978echo calc.at:559 >$at_check_line_file
19979( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
19980at_status=$?
19981grep '^ *+' $at_stder1 >&2
19982grep -v '^ *+' $at_stder1 >$at_stderr
19983at_failed=false
19984echo stderr:; tee stderr <$at_stderr
19985$at_diff $at_devnull $at_stdout || at_failed=:
19986case $at_status in
19987   77) echo 77 > $at_status_file
19988            exit 77;;
19989   1) ;;
19990   *) echo "calc.at:559: exit code was $at_status, expected 1"
19991      at_failed=:;;
19992esac
19993if $at_failed; then
19994
19995  echo 1 > $at_status_file
19996  exit 1
19997fi
19998
19999$at_traceon
20000
20001
20002# Normalize the observed and expected error messages, depending upon the
20003# options.
20004# 1. Remove the traces from observed.
20005sed '/^Starting/d
20006/^Entering/d
20007/^Stack/d
20008/^Reading/d
20009/^Reducing/d
20010/^Shifting/d
20011/^state/d
20012/^Cleanup:/d
20013/^Error:/d
20014/^Next/d
20015/^Discarding/d
20016/ \$[0-9$]* = /d
20017/^yydestructor:/d' stderr >at-stderr
20018mv at-stderr stderr
20019# 2. Create the reference error message.
20020cat >expout <<'_ATEOF'
200211.0: syntax error, unexpected $undefined
20022_ATEOF
20023
20024# 3. If locations are not used, remove them.
20025sed 's/^[-0-9.]*: //' expout >at-expout
20026mv at-expout expout
20027# 4. If error-verbose is not used, strip the`, unexpected....' part.
20028sed 's/syntax error, .*$/syntax error/' expout >at-expout
20029mv at-expout expout
20030# 5. Check
20031$at_traceoff
20032echo "calc.at:559: cat stderr"
20033echo calc.at:559 >$at_check_line_file
20034( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
20035at_status=$?
20036grep '^ *+' $at_stder1 >&2
20037grep -v '^ *+' $at_stder1 >$at_stderr
20038at_failed=false
20039$at_diff $at_devnull $at_stderr || at_failed=:
20040$at_diff expout $at_stdout || at_failed=:
20041case $at_status in
20042   77) echo 77 > $at_status_file
20043            exit 77;;
20044   0) ;;
20045   *) echo "calc.at:559: exit code was $at_status, expected 0"
20046      at_failed=:;;
20047esac
20048if $at_failed; then
20049
20050  echo 1 > $at_status_file
20051  exit 1
20052fi
20053
20054$at_traceon
20055
20056
20057cat >input <<'_ATEOF'
200581 = 2 = 3
20059_ATEOF
20060
20061$at_traceoff
20062echo "calc.at:559: \$PREPARSER ./calc input"
20063echo calc.at:559 >$at_check_line_file
20064( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
20065at_status=$?
20066grep '^ *+' $at_stder1 >&2
20067grep -v '^ *+' $at_stder1 >$at_stderr
20068at_failed=false
20069echo stderr:; tee stderr <$at_stderr
20070$at_diff $at_devnull $at_stdout || at_failed=:
20071case $at_status in
20072   77) echo 77 > $at_status_file
20073            exit 77;;
20074   1) ;;
20075   *) echo "calc.at:559: exit code was $at_status, expected 1"
20076      at_failed=:;;
20077esac
20078if $at_failed; then
20079
20080  echo 1 > $at_status_file
20081  exit 1
20082fi
20083
20084$at_traceon
20085
20086
20087# Normalize the observed and expected error messages, depending upon the
20088# options.
20089# 1. Remove the traces from observed.
20090sed '/^Starting/d
20091/^Entering/d
20092/^Stack/d
20093/^Reading/d
20094/^Reducing/d
20095/^Shifting/d
20096/^state/d
20097/^Cleanup:/d
20098/^Error:/d
20099/^Next/d
20100/^Discarding/d
20101/ \$[0-9$]* = /d
20102/^yydestructor:/d' stderr >at-stderr
20103mv at-stderr stderr
20104# 2. Create the reference error message.
20105cat >expout <<'_ATEOF'
201061.6: syntax error, unexpected '='
20107_ATEOF
20108
20109# 3. If locations are not used, remove them.
20110sed 's/^[-0-9.]*: //' expout >at-expout
20111mv at-expout expout
20112# 4. If error-verbose is not used, strip the`, unexpected....' part.
20113sed 's/syntax error, .*$/syntax error/' expout >at-expout
20114mv at-expout expout
20115# 5. Check
20116$at_traceoff
20117echo "calc.at:559: cat stderr"
20118echo calc.at:559 >$at_check_line_file
20119( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
20120at_status=$?
20121grep '^ *+' $at_stder1 >&2
20122grep -v '^ *+' $at_stder1 >$at_stderr
20123at_failed=false
20124$at_diff $at_devnull $at_stderr || at_failed=:
20125$at_diff expout $at_stdout || at_failed=:
20126case $at_status in
20127   77) echo 77 > $at_status_file
20128            exit 77;;
20129   0) ;;
20130   *) echo "calc.at:559: exit code was $at_status, expected 0"
20131      at_failed=:;;
20132esac
20133if $at_failed; then
20134
20135  echo 1 > $at_status_file
20136  exit 1
20137fi
20138
20139$at_traceon
20140
20141
20142cat >input <<'_ATEOF'
20143
20144+1
20145_ATEOF
20146
20147$at_traceoff
20148echo "calc.at:559: \$PREPARSER ./calc input"
20149echo calc.at:559 >$at_check_line_file
20150( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
20151at_status=$?
20152grep '^ *+' $at_stder1 >&2
20153grep -v '^ *+' $at_stder1 >$at_stderr
20154at_failed=false
20155echo stderr:; tee stderr <$at_stderr
20156$at_diff $at_devnull $at_stdout || at_failed=:
20157case $at_status in
20158   77) echo 77 > $at_status_file
20159            exit 77;;
20160   1) ;;
20161   *) echo "calc.at:559: exit code was $at_status, expected 1"
20162      at_failed=:;;
20163esac
20164if $at_failed; then
20165
20166  echo 1 > $at_status_file
20167  exit 1
20168fi
20169
20170$at_traceon
20171
20172
20173# Normalize the observed and expected error messages, depending upon the
20174# options.
20175# 1. Remove the traces from observed.
20176sed '/^Starting/d
20177/^Entering/d
20178/^Stack/d
20179/^Reading/d
20180/^Reducing/d
20181/^Shifting/d
20182/^state/d
20183/^Cleanup:/d
20184/^Error:/d
20185/^Next/d
20186/^Discarding/d
20187/ \$[0-9$]* = /d
20188/^yydestructor:/d' stderr >at-stderr
20189mv at-stderr stderr
20190# 2. Create the reference error message.
20191cat >expout <<'_ATEOF'
201922.0: syntax error, unexpected '+'
20193_ATEOF
20194
20195# 3. If locations are not used, remove them.
20196sed 's/^[-0-9.]*: //' expout >at-expout
20197mv at-expout expout
20198# 4. If error-verbose is not used, strip the`, unexpected....' part.
20199sed 's/syntax error, .*$/syntax error/' expout >at-expout
20200mv at-expout expout
20201# 5. Check
20202$at_traceoff
20203echo "calc.at:559: cat stderr"
20204echo calc.at:559 >$at_check_line_file
20205( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
20206at_status=$?
20207grep '^ *+' $at_stder1 >&2
20208grep -v '^ *+' $at_stder1 >$at_stderr
20209at_failed=false
20210$at_diff $at_devnull $at_stderr || at_failed=:
20211$at_diff expout $at_stdout || at_failed=:
20212case $at_status in
20213   77) echo 77 > $at_status_file
20214            exit 77;;
20215   0) ;;
20216   *) echo "calc.at:559: exit code was $at_status, expected 0"
20217      at_failed=:;;
20218esac
20219if $at_failed; then
20220
20221  echo 1 > $at_status_file
20222  exit 1
20223fi
20224
20225$at_traceon
20226
20227
20228# Exercise error messages with EOF: work on an empty file.
20229$at_traceoff
20230echo "calc.at:559: \$PREPARSER ./calc /dev/null"
20231echo calc.at:559 >$at_check_line_file
20232( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
20233at_status=$?
20234grep '^ *+' $at_stder1 >&2
20235grep -v '^ *+' $at_stder1 >$at_stderr
20236at_failed=false
20237echo stderr:; tee stderr <$at_stderr
20238$at_diff $at_devnull $at_stdout || at_failed=:
20239case $at_status in
20240   77) echo 77 > $at_status_file
20241            exit 77;;
20242   1) ;;
20243   *) echo "calc.at:559: exit code was $at_status, expected 1"
20244      at_failed=:;;
20245esac
20246if $at_failed; then
20247
20248  echo 1 > $at_status_file
20249  exit 1
20250fi
20251
20252$at_traceon
20253
20254
20255# Normalize the observed and expected error messages, depending upon the
20256# options.
20257# 1. Remove the traces from observed.
20258sed '/^Starting/d
20259/^Entering/d
20260/^Stack/d
20261/^Reading/d
20262/^Reducing/d
20263/^Shifting/d
20264/^state/d
20265/^Cleanup:/d
20266/^Error:/d
20267/^Next/d
20268/^Discarding/d
20269/ \$[0-9$]* = /d
20270/^yydestructor:/d' stderr >at-stderr
20271mv at-stderr stderr
20272# 2. Create the reference error message.
20273cat >expout <<'_ATEOF'
202741.0: syntax error, unexpected end of input
20275_ATEOF
20276
20277# 3. If locations are not used, remove them.
20278sed 's/^[-0-9.]*: //' expout >at-expout
20279mv at-expout expout
20280# 4. If error-verbose is not used, strip the`, unexpected....' part.
20281sed 's/syntax error, .*$/syntax error/' expout >at-expout
20282mv at-expout expout
20283# 5. Check
20284$at_traceoff
20285echo "calc.at:559: cat stderr"
20286echo calc.at:559 >$at_check_line_file
20287( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
20288at_status=$?
20289grep '^ *+' $at_stder1 >&2
20290grep -v '^ *+' $at_stder1 >$at_stderr
20291at_failed=false
20292$at_diff $at_devnull $at_stderr || at_failed=:
20293$at_diff expout $at_stdout || at_failed=:
20294case $at_status in
20295   77) echo 77 > $at_status_file
20296            exit 77;;
20297   0) ;;
20298   *) echo "calc.at:559: exit code was $at_status, expected 0"
20299      at_failed=:;;
20300esac
20301if $at_failed; then
20302
20303  echo 1 > $at_status_file
20304  exit 1
20305fi
20306
20307$at_traceon
20308
20309
20310
20311# Exercise the error token: without it, we die at the first error,
20312# hence be sure to
20313#
20314# - have several errors which exercise different shift/discardings
20315#   - (): nothing to pop, nothing to discard
20316#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
20317#   - (* * *): nothing to pop, a lot to discard
20318#   - (1 + 2 * *): some to pop and discard
20319#
20320# - test the action associated to `error'
20321#
20322# - check the look-ahead that triggers an error is not discarded
20323#   when we enter error recovery.  Below, the look-ahead causing the
20324#   first error is ")", which is needed to recover from the error and
20325#   produce the "0" that triggers the "0 != 1" error.
20326#
20327cat >input <<'_ATEOF'
20328() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
20329_ATEOF
20330
20331$at_traceoff
20332echo "calc.at:559: \$PREPARSER ./calc input"
20333echo calc.at:559 >$at_check_line_file
20334( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
20335at_status=$?
20336grep '^ *+' $at_stder1 >&2
20337grep -v '^ *+' $at_stder1 >$at_stderr
20338at_failed=false
20339echo stderr:; tee stderr <$at_stderr
20340$at_diff $at_devnull $at_stdout || at_failed=:
20341case $at_status in
20342   77) echo 77 > $at_status_file
20343            exit 77;;
20344   0) ;;
20345   *) echo "calc.at:559: exit code was $at_status, expected 0"
20346      at_failed=:;;
20347esac
20348if $at_failed; then
20349
20350  echo 1 > $at_status_file
20351  exit 1
20352fi
20353
20354$at_traceon
20355
20356
20357# Normalize the observed and expected error messages, depending upon the
20358# options.
20359# 1. Remove the traces from observed.
20360sed '/^Starting/d
20361/^Entering/d
20362/^Stack/d
20363/^Reading/d
20364/^Reducing/d
20365/^Shifting/d
20366/^state/d
20367/^Cleanup:/d
20368/^Error:/d
20369/^Next/d
20370/^Discarding/d
20371/ \$[0-9$]* = /d
20372/^yydestructor:/d' stderr >at-stderr
20373mv at-stderr stderr
20374# 2. Create the reference error message.
20375cat >expout <<'_ATEOF'
203761.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
203771.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
203781.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
203791.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
20380calc: error: 4444 != 1
20381_ATEOF
20382
20383# 3. If locations are not used, remove them.
20384sed 's/^[-0-9.]*: //' expout >at-expout
20385mv at-expout expout
20386# 4. If error-verbose is not used, strip the`, unexpected....' part.
20387sed 's/syntax error, .*$/syntax error/' expout >at-expout
20388mv at-expout expout
20389# 5. Check
20390$at_traceoff
20391echo "calc.at:559: cat stderr"
20392echo calc.at:559 >$at_check_line_file
20393( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
20394at_status=$?
20395grep '^ *+' $at_stder1 >&2
20396grep -v '^ *+' $at_stder1 >$at_stderr
20397at_failed=false
20398$at_diff $at_devnull $at_stderr || at_failed=:
20399$at_diff expout $at_stdout || at_failed=:
20400case $at_status in
20401   77) echo 77 > $at_status_file
20402            exit 77;;
20403   0) ;;
20404   *) echo "calc.at:559: exit code was $at_status, expected 0"
20405      at_failed=:;;
20406esac
20407if $at_failed; then
20408
20409  echo 1 > $at_status_file
20410  exit 1
20411fi
20412
20413$at_traceon
20414
20415
20416
20417# The same, but this time exercising explicitly triggered syntax errors.
20418# POSIX says the look-ahead causing the error should not be discarded.
20419cat >input <<'_ATEOF'
20420(!) + (0 0) = 1
20421_ATEOF
20422
20423$at_traceoff
20424echo "calc.at:559: \$PREPARSER ./calc input"
20425echo calc.at:559 >$at_check_line_file
20426( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
20427at_status=$?
20428grep '^ *+' $at_stder1 >&2
20429grep -v '^ *+' $at_stder1 >$at_stderr
20430at_failed=false
20431echo stderr:; tee stderr <$at_stderr
20432$at_diff $at_devnull $at_stdout || at_failed=:
20433case $at_status in
20434   77) echo 77 > $at_status_file
20435            exit 77;;
20436   0) ;;
20437   *) echo "calc.at:559: exit code was $at_status, expected 0"
20438      at_failed=:;;
20439esac
20440if $at_failed; then
20441
20442  echo 1 > $at_status_file
20443  exit 1
20444fi
20445
20446$at_traceon
20447
20448
20449# Normalize the observed and expected error messages, depending upon the
20450# options.
20451# 1. Remove the traces from observed.
20452sed '/^Starting/d
20453/^Entering/d
20454/^Stack/d
20455/^Reading/d
20456/^Reducing/d
20457/^Shifting/d
20458/^state/d
20459/^Cleanup:/d
20460/^Error:/d
20461/^Next/d
20462/^Discarding/d
20463/ \$[0-9$]* = /d
20464/^yydestructor:/d' stderr >at-stderr
20465mv at-stderr stderr
20466# 2. Create the reference error message.
20467cat >expout <<'_ATEOF'
204681.9: syntax error, unexpected number
20469calc: error: 2222 != 1
20470_ATEOF
20471
20472# 3. If locations are not used, remove them.
20473sed 's/^[-0-9.]*: //' expout >at-expout
20474mv at-expout expout
20475# 4. If error-verbose is not used, strip the`, unexpected....' part.
20476sed 's/syntax error, .*$/syntax error/' expout >at-expout
20477mv at-expout expout
20478# 5. Check
20479$at_traceoff
20480echo "calc.at:559: cat stderr"
20481echo calc.at:559 >$at_check_line_file
20482( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
20483at_status=$?
20484grep '^ *+' $at_stder1 >&2
20485grep -v '^ *+' $at_stder1 >$at_stderr
20486at_failed=false
20487$at_diff $at_devnull $at_stderr || at_failed=:
20488$at_diff expout $at_stdout || at_failed=:
20489case $at_status in
20490   77) echo 77 > $at_status_file
20491            exit 77;;
20492   0) ;;
20493   *) echo "calc.at:559: exit code was $at_status, expected 0"
20494      at_failed=:;;
20495esac
20496if $at_failed; then
20497
20498  echo 1 > $at_status_file
20499  exit 1
20500fi
20501
20502$at_traceon
20503
20504
20505cat >input <<'_ATEOF'
20506(- *) + (0 0) = 1
20507_ATEOF
20508
20509$at_traceoff
20510echo "calc.at:559: \$PREPARSER ./calc input"
20511echo calc.at:559 >$at_check_line_file
20512( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
20513at_status=$?
20514grep '^ *+' $at_stder1 >&2
20515grep -v '^ *+' $at_stder1 >$at_stderr
20516at_failed=false
20517echo stderr:; tee stderr <$at_stderr
20518$at_diff $at_devnull $at_stdout || at_failed=:
20519case $at_status in
20520   77) echo 77 > $at_status_file
20521            exit 77;;
20522   0) ;;
20523   *) echo "calc.at:559: exit code was $at_status, expected 0"
20524      at_failed=:;;
20525esac
20526if $at_failed; then
20527
20528  echo 1 > $at_status_file
20529  exit 1
20530fi
20531
20532$at_traceon
20533
20534
20535# Normalize the observed and expected error messages, depending upon the
20536# options.
20537# 1. Remove the traces from observed.
20538sed '/^Starting/d
20539/^Entering/d
20540/^Stack/d
20541/^Reading/d
20542/^Reducing/d
20543/^Shifting/d
20544/^state/d
20545/^Cleanup:/d
20546/^Error:/d
20547/^Next/d
20548/^Discarding/d
20549/ \$[0-9$]* = /d
20550/^yydestructor:/d' stderr >at-stderr
20551mv at-stderr stderr
20552# 2. Create the reference error message.
20553cat >expout <<'_ATEOF'
205541.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
205551.11: syntax error, unexpected number
20556calc: error: 2222 != 1
20557_ATEOF
20558
20559# 3. If locations are not used, remove them.
20560sed 's/^[-0-9.]*: //' expout >at-expout
20561mv at-expout expout
20562# 4. If error-verbose is not used, strip the`, unexpected....' part.
20563sed 's/syntax error, .*$/syntax error/' expout >at-expout
20564mv at-expout expout
20565# 5. Check
20566$at_traceoff
20567echo "calc.at:559: cat stderr"
20568echo calc.at:559 >$at_check_line_file
20569( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
20570at_status=$?
20571grep '^ *+' $at_stder1 >&2
20572grep -v '^ *+' $at_stder1 >$at_stderr
20573at_failed=false
20574$at_diff $at_devnull $at_stderr || at_failed=:
20575$at_diff expout $at_stdout || at_failed=:
20576case $at_status in
20577   77) echo 77 > $at_status_file
20578            exit 77;;
20579   0) ;;
20580   *) echo "calc.at:559: exit code was $at_status, expected 0"
20581      at_failed=:;;
20582esac
20583if $at_failed; then
20584
20585  echo 1 > $at_status_file
20586  exit 1
20587fi
20588
20589$at_traceon
20590
20591
20592
20593
20594
20595
20596
20597
20598
20599
20600
20601
20602
20603
20604
20605
20606
20607
20608
20609
20610
20611
20612
20613
20614      $at_traceoff
20615      $at_times_p && times >$at_times_file
20616    ) 5>&1 2>&1 | eval $at_tee_pipe
20617    at_status=`cat $at_status_file`
20618    ;;
20619
20620  78 ) # 78. calc.at:560: Calculator %error-verbose %locations
20621    at_setup_line='calc.at:560'
20622    at_desc='Calculator %error-verbose %locations'
20623    $at_quiet $ECHO_N " 78: Calculator %error-verbose %locations         $ECHO_C"
20624    at_xfail=no
20625    (
20626      echo "78. calc.at:560: testing ..."
20627      $at_traceon
20628
20629
20630
20631
20632
20633
20634
20635
20636# Using yacc.c?
20637
20638
20639
20640
20641
20642
20643
20644# yyerror receives the location if %location & %pure & (%glr or %parse-param).
20645
20646# yyerror always sees the locations (when activated), except if
20647# yacc & pure & !param.
20648
20649
20650# The interface is pure: either because %pure-parser, or because we
20651# are using the C++ parsers.
20652
20653
20654
20655
20656
20657
20658
20659
20660
20661
20662
20663
20664cat >calc.y <<'_ATEOF'
20665%{
20666#ifdef HAVE_CONFIG_H
20667# include <config.h>
20668  /* We don't need perfect functions for these tests. */
20669# undef malloc
20670# undef memcmp
20671# undef realloc
20672#endif
20673%}
20674
20675/* Infix notation calculator--calc */
20676%error-verbose %locations
20677
20678%{
20679#include <stdio.h>
20680
20681#include <stdlib.h>
20682#include <string.h>
20683#if HAVE_UNISTD_H
20684# include <unistd.h>
20685#else
20686# undef alarm
20687# define alarm(seconds) /* empty */
20688#endif
20689#include <ctype.h>
20690#define USE(Var)
20691
20692/* Exercise pre-prologue dependency to %union.  */
20693typedef int semantic_value;
20694
20695static semantic_value global_result = 0;
20696static int global_count = 0;
20697%}
20698
20699/* Exercise %union. */
20700%union
20701{
20702  semantic_value ival;
20703};
20704
20705%{
20706static int power (int base, int exponent);
20707/* yyerror receives the location if:
20708   - %location & %pure & %glr
20709   - %location & %pure & %yacc & %parse-param. */
20710static void yyerror (
20711
20712                     const char *s
20713                     );
20714static int yylex (void);
20715static int get_char (void);
20716static void unget_char ( int c);
20717%}
20718
20719
20720
20721/* Bison Declarations */
20722%token CALC_EOF 0 "end of input"
20723%token <ival> NUM "number"
20724%type  <ival> exp
20725
20726%nonassoc '=' /* comparison	       */
20727%left '-' '+'
20728%left '*' '/'
20729%left NEG     /* negation--unary minus */
20730%right '^'    /* exponentiation        */
20731
20732/* Grammar follows */
20733%%
20734input:
20735  line
20736| input line         {  }
20737;
20738
20739line:
20740  '\n'
20741| exp '\n'           { USE ($1); }
20742;
20743
20744exp:
20745  NUM                { $$ = $1;             }
20746| exp '=' exp
20747  {
20748    if ($1 != $3)
20749      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
20750    $$ = $1;
20751  }
20752| exp '+' exp        { $$ = $1 + $3;        }
20753| exp '-' exp        { $$ = $1 - $3;        }
20754| exp '*' exp        { $$ = $1 * $3;        }
20755| exp '/' exp        { $$ = $1 / $3;        }
20756| '-' exp  %prec NEG { $$ = -$2;            }
20757| exp '^' exp        { $$ = power ($1, $3); }
20758| '(' exp ')'        { $$ = $2;             }
20759| '(' error ')'      { $$ = 1111;           }
20760| '!'                { $$ = 0; YYERROR;     }
20761| '-' error          { $$ = 0; YYERROR;     }
20762;
20763%%
20764/* The input.  */
20765static FILE *input;
20766
20767static void
20768yyerror (
20769
20770         const char *s)
20771{
20772
20773
20774  fprintf (stderr, "%d.%d",
20775           (yylloc).first_line, (yylloc).first_column);
20776  if ((yylloc).first_line != (yylloc).last_line)
20777    fprintf (stderr, "-%d.%d",
20778	     (yylloc).last_line,  (yylloc).last_column - 1);
20779  else if ((yylloc).first_column != (yylloc).last_column - 1)
20780    fprintf (stderr, "-%d",
20781	     (yylloc).last_column - 1);
20782  fprintf (stderr, ": ");
20783  fprintf (stderr, "%s\n", s);
20784}
20785
20786
20787
20788static YYLTYPE last_yylloc;
20789
20790static int
20791get_char (void)
20792{
20793  int res = getc (input);
20794  ;
20795
20796  last_yylloc = (yylloc);
20797  if (res == '\n')
20798    {
20799      (yylloc).last_line++;
20800      (yylloc).last_column = 0;
20801    }
20802  else
20803    (yylloc).last_column++;
20804
20805  return res;
20806}
20807
20808
20809static void
20810unget_char ( int c)
20811{
20812  ;
20813
20814  /* Wrong when C == `\n'. */
20815  (yylloc) = last_yylloc;
20816
20817  ungetc (c, input);
20818}
20819
20820static int
20821read_signed_integer (void)
20822{
20823  int c = get_char ();
20824  int sign = 1;
20825  int n = 0;
20826
20827  ;
20828  if (c == '-')
20829    {
20830      c = get_char ();
20831      sign = -1;
20832    }
20833
20834  while (isdigit (c))
20835    {
20836      n = 10 * n + (c - '0');
20837      c = get_char ();
20838    }
20839
20840  unget_char ( c);
20841
20842  return sign * n;
20843}
20844
20845
20846
20847/*---------------------------------------------------------------.
20848| Lexical analyzer returns an integer on the stack and the token |
20849| NUM, or the ASCII character read if not a number.  Skips all   |
20850| blanks and tabs, returns 0 for EOF.                            |
20851`---------------------------------------------------------------*/
20852
20853static int
20854yylex (void)
20855{
20856  static int init = 1;
20857  int c;
20858
20859  if (init)
20860    {
20861      init = 0;
20862
20863      (yylloc).last_column = 0;
20864      (yylloc).last_line = 1;
20865
20866    }
20867
20868
20869 (yylloc).first_column = (yylloc).last_column;
20870  (yylloc).first_line   = (yylloc).last_line;
20871
20872
20873  /* Skip white space.  */
20874  while ((c = get_char ()) == ' ' || c == '\t')
20875    {
20876     (yylloc).first_column = (yylloc).last_column;
20877      (yylloc).first_line   = (yylloc).last_line;
20878
20879    }
20880
20881  /* process numbers   */
20882  if (c == '.' || isdigit (c))
20883    {
20884      unget_char ( c);
20885      (yylval).ival = read_signed_integer ();
20886      return NUM;
20887    }
20888
20889  /* Return end-of-file.  */
20890  if (c == EOF)
20891    return CALC_EOF;
20892
20893  /* Return single chars. */
20894  return c;
20895}
20896
20897static int
20898power (int base, int exponent)
20899{
20900  int res = 1;
20901  if (exponent < 0)
20902    exit (3);
20903  for (/* Niente */; exponent; --exponent)
20904    res *= base;
20905  return res;
20906}
20907
20908
20909int
20910main (int argc, const char **argv)
20911{
20912  semantic_value result = 0;
20913  int count = 0;
20914  int status;
20915
20916  /* This used to be alarm (10), but that isn't enough time for
20917     a July 1995 vintage DEC Alphastation 200 4/100 system,
20918     according to Nelson H. F. Beebe.  100 seconds is enough.  */
20919  alarm (100);
20920
20921  if (argc == 2)
20922    input = fopen (argv[1], "r");
20923  else
20924    input = stdin;
20925
20926  if (!input)
20927    {
20928      perror (argv[1]);
20929      return 3;
20930    }
20931
20932
20933  status = yyparse ();
20934  if (global_result != result)
20935    abort ();
20936  if (global_count != count)
20937    abort ();
20938  return status;
20939}
20940_ATEOF
20941
20942
20943
20944
20945
20946$at_traceoff
20947echo "calc.at:560: bison -o calc.c calc.y"
20948echo calc.at:560 >$at_check_line_file
20949( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
20950at_status=$?
20951grep '^ *+' $at_stder1 >&2
20952grep -v '^ *+' $at_stder1 >$at_stderr
20953at_failed=false
20954$at_diff $at_devnull $at_stderr || at_failed=:
20955$at_diff $at_devnull $at_stdout || at_failed=:
20956case $at_status in
20957   77) echo 77 > $at_status_file
20958            exit 77;;
20959   0) ;;
20960   *) echo "calc.at:560: exit code was $at_status, expected 0"
20961      at_failed=:;;
20962esac
20963if $at_failed; then
20964
20965  echo 1 > $at_status_file
20966  exit 1
20967fi
20968
20969$at_traceon
20970
20971   $at_traceoff
20972echo "calc.at:560: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
20973echo calc.at:560 >$at_check_line_file
20974( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
20975at_status=$?
20976grep '^ *+' $at_stder1 >&2
20977grep -v '^ *+' $at_stder1 >$at_stderr
20978at_failed=false
20979echo stderr:; cat $at_stderr
20980echo stdout:; cat $at_stdout
20981case $at_status in
20982   77) echo 77 > $at_status_file
20983            exit 77;;
20984   0) ;;
20985   *) echo "calc.at:560: exit code was $at_status, expected 0"
20986      at_failed=:;;
20987esac
20988if $at_failed; then
20989
20990  echo 1 > $at_status_file
20991  exit 1
20992fi
20993
20994$at_traceon
20995
20996
20997# Test the priorities.
20998cat >input <<'_ATEOF'
209991 + 2 * 3 = 7
210001 + 2 * -3 = -5
21001
21002-1^2 = -1
21003(-1)^2 = 1
21004
21005---1 = -1
21006
210071 - 2 - 3 = -4
210081 - (2 - 3) = 2
21009
210102^2^3 = 256
21011(2^2)^3 = 64
21012_ATEOF
21013
21014$at_traceoff
21015echo "calc.at:560: \$PREPARSER ./calc input"
21016echo calc.at:560 >$at_check_line_file
21017( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
21018at_status=$?
21019grep '^ *+' $at_stder1 >&2
21020grep -v '^ *+' $at_stder1 >$at_stderr
21021at_failed=false
21022echo stderr:; tee stderr <$at_stderr
21023$at_diff $at_devnull $at_stdout || at_failed=:
21024case $at_status in
21025   77) echo 77 > $at_status_file
21026            exit 77;;
21027   0) ;;
21028   *) echo "calc.at:560: exit code was $at_status, expected 0"
21029      at_failed=:;;
21030esac
21031if $at_failed; then
21032
21033  echo 1 > $at_status_file
21034  exit 1
21035fi
21036
21037$at_traceon
21038
21039
21040
21041# Some syntax errors.
21042cat >input <<'_ATEOF'
210430 0
21044_ATEOF
21045
21046$at_traceoff
21047echo "calc.at:560: \$PREPARSER ./calc input"
21048echo calc.at:560 >$at_check_line_file
21049( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
21050at_status=$?
21051grep '^ *+' $at_stder1 >&2
21052grep -v '^ *+' $at_stder1 >$at_stderr
21053at_failed=false
21054echo stderr:; tee stderr <$at_stderr
21055$at_diff $at_devnull $at_stdout || at_failed=:
21056case $at_status in
21057   77) echo 77 > $at_status_file
21058            exit 77;;
21059   1) ;;
21060   *) echo "calc.at:560: exit code was $at_status, expected 1"
21061      at_failed=:;;
21062esac
21063if $at_failed; then
21064
21065  echo 1 > $at_status_file
21066  exit 1
21067fi
21068
21069$at_traceon
21070
21071
21072# Normalize the observed and expected error messages, depending upon the
21073# options.
21074# 1. Remove the traces from observed.
21075sed '/^Starting/d
21076/^Entering/d
21077/^Stack/d
21078/^Reading/d
21079/^Reducing/d
21080/^Shifting/d
21081/^state/d
21082/^Cleanup:/d
21083/^Error:/d
21084/^Next/d
21085/^Discarding/d
21086/ \$[0-9$]* = /d
21087/^yydestructor:/d' stderr >at-stderr
21088mv at-stderr stderr
21089# 2. Create the reference error message.
21090cat >expout <<'_ATEOF'
210911.2: syntax error, unexpected number
21092_ATEOF
21093
21094# 3. If locations are not used, remove them.
21095
21096# 4. If error-verbose is not used, strip the`, unexpected....' part.
21097
21098# 5. Check
21099$at_traceoff
21100echo "calc.at:560: cat stderr"
21101echo calc.at:560 >$at_check_line_file
21102( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
21103at_status=$?
21104grep '^ *+' $at_stder1 >&2
21105grep -v '^ *+' $at_stder1 >$at_stderr
21106at_failed=false
21107$at_diff $at_devnull $at_stderr || at_failed=:
21108$at_diff expout $at_stdout || at_failed=:
21109case $at_status in
21110   77) echo 77 > $at_status_file
21111            exit 77;;
21112   0) ;;
21113   *) echo "calc.at:560: exit code was $at_status, expected 0"
21114      at_failed=:;;
21115esac
21116if $at_failed; then
21117
21118  echo 1 > $at_status_file
21119  exit 1
21120fi
21121
21122$at_traceon
21123
21124
21125cat >input <<'_ATEOF'
211261//2
21127_ATEOF
21128
21129$at_traceoff
21130echo "calc.at:560: \$PREPARSER ./calc input"
21131echo calc.at:560 >$at_check_line_file
21132( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
21133at_status=$?
21134grep '^ *+' $at_stder1 >&2
21135grep -v '^ *+' $at_stder1 >$at_stderr
21136at_failed=false
21137echo stderr:; tee stderr <$at_stderr
21138$at_diff $at_devnull $at_stdout || at_failed=:
21139case $at_status in
21140   77) echo 77 > $at_status_file
21141            exit 77;;
21142   1) ;;
21143   *) echo "calc.at:560: exit code was $at_status, expected 1"
21144      at_failed=:;;
21145esac
21146if $at_failed; then
21147
21148  echo 1 > $at_status_file
21149  exit 1
21150fi
21151
21152$at_traceon
21153
21154
21155# Normalize the observed and expected error messages, depending upon the
21156# options.
21157# 1. Remove the traces from observed.
21158sed '/^Starting/d
21159/^Entering/d
21160/^Stack/d
21161/^Reading/d
21162/^Reducing/d
21163/^Shifting/d
21164/^state/d
21165/^Cleanup:/d
21166/^Error:/d
21167/^Next/d
21168/^Discarding/d
21169/ \$[0-9$]* = /d
21170/^yydestructor:/d' stderr >at-stderr
21171mv at-stderr stderr
21172# 2. Create the reference error message.
21173cat >expout <<'_ATEOF'
211741.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
21175_ATEOF
21176
21177# 3. If locations are not used, remove them.
21178
21179# 4. If error-verbose is not used, strip the`, unexpected....' part.
21180
21181# 5. Check
21182$at_traceoff
21183echo "calc.at:560: cat stderr"
21184echo calc.at:560 >$at_check_line_file
21185( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
21186at_status=$?
21187grep '^ *+' $at_stder1 >&2
21188grep -v '^ *+' $at_stder1 >$at_stderr
21189at_failed=false
21190$at_diff $at_devnull $at_stderr || at_failed=:
21191$at_diff expout $at_stdout || at_failed=:
21192case $at_status in
21193   77) echo 77 > $at_status_file
21194            exit 77;;
21195   0) ;;
21196   *) echo "calc.at:560: exit code was $at_status, expected 0"
21197      at_failed=:;;
21198esac
21199if $at_failed; then
21200
21201  echo 1 > $at_status_file
21202  exit 1
21203fi
21204
21205$at_traceon
21206
21207
21208cat >input <<'_ATEOF'
21209error
21210_ATEOF
21211
21212$at_traceoff
21213echo "calc.at:560: \$PREPARSER ./calc input"
21214echo calc.at:560 >$at_check_line_file
21215( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
21216at_status=$?
21217grep '^ *+' $at_stder1 >&2
21218grep -v '^ *+' $at_stder1 >$at_stderr
21219at_failed=false
21220echo stderr:; tee stderr <$at_stderr
21221$at_diff $at_devnull $at_stdout || at_failed=:
21222case $at_status in
21223   77) echo 77 > $at_status_file
21224            exit 77;;
21225   1) ;;
21226   *) echo "calc.at:560: exit code was $at_status, expected 1"
21227      at_failed=:;;
21228esac
21229if $at_failed; then
21230
21231  echo 1 > $at_status_file
21232  exit 1
21233fi
21234
21235$at_traceon
21236
21237
21238# Normalize the observed and expected error messages, depending upon the
21239# options.
21240# 1. Remove the traces from observed.
21241sed '/^Starting/d
21242/^Entering/d
21243/^Stack/d
21244/^Reading/d
21245/^Reducing/d
21246/^Shifting/d
21247/^state/d
21248/^Cleanup:/d
21249/^Error:/d
21250/^Next/d
21251/^Discarding/d
21252/ \$[0-9$]* = /d
21253/^yydestructor:/d' stderr >at-stderr
21254mv at-stderr stderr
21255# 2. Create the reference error message.
21256cat >expout <<'_ATEOF'
212571.0: syntax error, unexpected $undefined
21258_ATEOF
21259
21260# 3. If locations are not used, remove them.
21261
21262# 4. If error-verbose is not used, strip the`, unexpected....' part.
21263
21264# 5. Check
21265$at_traceoff
21266echo "calc.at:560: cat stderr"
21267echo calc.at:560 >$at_check_line_file
21268( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
21269at_status=$?
21270grep '^ *+' $at_stder1 >&2
21271grep -v '^ *+' $at_stder1 >$at_stderr
21272at_failed=false
21273$at_diff $at_devnull $at_stderr || at_failed=:
21274$at_diff expout $at_stdout || at_failed=:
21275case $at_status in
21276   77) echo 77 > $at_status_file
21277            exit 77;;
21278   0) ;;
21279   *) echo "calc.at:560: exit code was $at_status, expected 0"
21280      at_failed=:;;
21281esac
21282if $at_failed; then
21283
21284  echo 1 > $at_status_file
21285  exit 1
21286fi
21287
21288$at_traceon
21289
21290
21291cat >input <<'_ATEOF'
212921 = 2 = 3
21293_ATEOF
21294
21295$at_traceoff
21296echo "calc.at:560: \$PREPARSER ./calc input"
21297echo calc.at:560 >$at_check_line_file
21298( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
21299at_status=$?
21300grep '^ *+' $at_stder1 >&2
21301grep -v '^ *+' $at_stder1 >$at_stderr
21302at_failed=false
21303echo stderr:; tee stderr <$at_stderr
21304$at_diff $at_devnull $at_stdout || at_failed=:
21305case $at_status in
21306   77) echo 77 > $at_status_file
21307            exit 77;;
21308   1) ;;
21309   *) echo "calc.at:560: exit code was $at_status, expected 1"
21310      at_failed=:;;
21311esac
21312if $at_failed; then
21313
21314  echo 1 > $at_status_file
21315  exit 1
21316fi
21317
21318$at_traceon
21319
21320
21321# Normalize the observed and expected error messages, depending upon the
21322# options.
21323# 1. Remove the traces from observed.
21324sed '/^Starting/d
21325/^Entering/d
21326/^Stack/d
21327/^Reading/d
21328/^Reducing/d
21329/^Shifting/d
21330/^state/d
21331/^Cleanup:/d
21332/^Error:/d
21333/^Next/d
21334/^Discarding/d
21335/ \$[0-9$]* = /d
21336/^yydestructor:/d' stderr >at-stderr
21337mv at-stderr stderr
21338# 2. Create the reference error message.
21339cat >expout <<'_ATEOF'
213401.6: syntax error, unexpected '='
21341_ATEOF
21342
21343# 3. If locations are not used, remove them.
21344
21345# 4. If error-verbose is not used, strip the`, unexpected....' part.
21346
21347# 5. Check
21348$at_traceoff
21349echo "calc.at:560: cat stderr"
21350echo calc.at:560 >$at_check_line_file
21351( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
21352at_status=$?
21353grep '^ *+' $at_stder1 >&2
21354grep -v '^ *+' $at_stder1 >$at_stderr
21355at_failed=false
21356$at_diff $at_devnull $at_stderr || at_failed=:
21357$at_diff expout $at_stdout || at_failed=:
21358case $at_status in
21359   77) echo 77 > $at_status_file
21360            exit 77;;
21361   0) ;;
21362   *) echo "calc.at:560: exit code was $at_status, expected 0"
21363      at_failed=:;;
21364esac
21365if $at_failed; then
21366
21367  echo 1 > $at_status_file
21368  exit 1
21369fi
21370
21371$at_traceon
21372
21373
21374cat >input <<'_ATEOF'
21375
21376+1
21377_ATEOF
21378
21379$at_traceoff
21380echo "calc.at:560: \$PREPARSER ./calc input"
21381echo calc.at:560 >$at_check_line_file
21382( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
21383at_status=$?
21384grep '^ *+' $at_stder1 >&2
21385grep -v '^ *+' $at_stder1 >$at_stderr
21386at_failed=false
21387echo stderr:; tee stderr <$at_stderr
21388$at_diff $at_devnull $at_stdout || at_failed=:
21389case $at_status in
21390   77) echo 77 > $at_status_file
21391            exit 77;;
21392   1) ;;
21393   *) echo "calc.at:560: exit code was $at_status, expected 1"
21394      at_failed=:;;
21395esac
21396if $at_failed; then
21397
21398  echo 1 > $at_status_file
21399  exit 1
21400fi
21401
21402$at_traceon
21403
21404
21405# Normalize the observed and expected error messages, depending upon the
21406# options.
21407# 1. Remove the traces from observed.
21408sed '/^Starting/d
21409/^Entering/d
21410/^Stack/d
21411/^Reading/d
21412/^Reducing/d
21413/^Shifting/d
21414/^state/d
21415/^Cleanup:/d
21416/^Error:/d
21417/^Next/d
21418/^Discarding/d
21419/ \$[0-9$]* = /d
21420/^yydestructor:/d' stderr >at-stderr
21421mv at-stderr stderr
21422# 2. Create the reference error message.
21423cat >expout <<'_ATEOF'
214242.0: syntax error, unexpected '+'
21425_ATEOF
21426
21427# 3. If locations are not used, remove them.
21428
21429# 4. If error-verbose is not used, strip the`, unexpected....' part.
21430
21431# 5. Check
21432$at_traceoff
21433echo "calc.at:560: cat stderr"
21434echo calc.at:560 >$at_check_line_file
21435( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
21436at_status=$?
21437grep '^ *+' $at_stder1 >&2
21438grep -v '^ *+' $at_stder1 >$at_stderr
21439at_failed=false
21440$at_diff $at_devnull $at_stderr || at_failed=:
21441$at_diff expout $at_stdout || at_failed=:
21442case $at_status in
21443   77) echo 77 > $at_status_file
21444            exit 77;;
21445   0) ;;
21446   *) echo "calc.at:560: exit code was $at_status, expected 0"
21447      at_failed=:;;
21448esac
21449if $at_failed; then
21450
21451  echo 1 > $at_status_file
21452  exit 1
21453fi
21454
21455$at_traceon
21456
21457
21458# Exercise error messages with EOF: work on an empty file.
21459$at_traceoff
21460echo "calc.at:560: \$PREPARSER ./calc /dev/null"
21461echo calc.at:560 >$at_check_line_file
21462( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
21463at_status=$?
21464grep '^ *+' $at_stder1 >&2
21465grep -v '^ *+' $at_stder1 >$at_stderr
21466at_failed=false
21467echo stderr:; tee stderr <$at_stderr
21468$at_diff $at_devnull $at_stdout || at_failed=:
21469case $at_status in
21470   77) echo 77 > $at_status_file
21471            exit 77;;
21472   1) ;;
21473   *) echo "calc.at:560: exit code was $at_status, expected 1"
21474      at_failed=:;;
21475esac
21476if $at_failed; then
21477
21478  echo 1 > $at_status_file
21479  exit 1
21480fi
21481
21482$at_traceon
21483
21484
21485# Normalize the observed and expected error messages, depending upon the
21486# options.
21487# 1. Remove the traces from observed.
21488sed '/^Starting/d
21489/^Entering/d
21490/^Stack/d
21491/^Reading/d
21492/^Reducing/d
21493/^Shifting/d
21494/^state/d
21495/^Cleanup:/d
21496/^Error:/d
21497/^Next/d
21498/^Discarding/d
21499/ \$[0-9$]* = /d
21500/^yydestructor:/d' stderr >at-stderr
21501mv at-stderr stderr
21502# 2. Create the reference error message.
21503cat >expout <<'_ATEOF'
215041.0: syntax error, unexpected end of input
21505_ATEOF
21506
21507# 3. If locations are not used, remove them.
21508
21509# 4. If error-verbose is not used, strip the`, unexpected....' part.
21510
21511# 5. Check
21512$at_traceoff
21513echo "calc.at:560: cat stderr"
21514echo calc.at:560 >$at_check_line_file
21515( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
21516at_status=$?
21517grep '^ *+' $at_stder1 >&2
21518grep -v '^ *+' $at_stder1 >$at_stderr
21519at_failed=false
21520$at_diff $at_devnull $at_stderr || at_failed=:
21521$at_diff expout $at_stdout || at_failed=:
21522case $at_status in
21523   77) echo 77 > $at_status_file
21524            exit 77;;
21525   0) ;;
21526   *) echo "calc.at:560: exit code was $at_status, expected 0"
21527      at_failed=:;;
21528esac
21529if $at_failed; then
21530
21531  echo 1 > $at_status_file
21532  exit 1
21533fi
21534
21535$at_traceon
21536
21537
21538
21539# Exercise the error token: without it, we die at the first error,
21540# hence be sure to
21541#
21542# - have several errors which exercise different shift/discardings
21543#   - (): nothing to pop, nothing to discard
21544#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
21545#   - (* * *): nothing to pop, a lot to discard
21546#   - (1 + 2 * *): some to pop and discard
21547#
21548# - test the action associated to `error'
21549#
21550# - check the look-ahead that triggers an error is not discarded
21551#   when we enter error recovery.  Below, the look-ahead causing the
21552#   first error is ")", which is needed to recover from the error and
21553#   produce the "0" that triggers the "0 != 1" error.
21554#
21555cat >input <<'_ATEOF'
21556() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
21557_ATEOF
21558
21559$at_traceoff
21560echo "calc.at:560: \$PREPARSER ./calc input"
21561echo calc.at:560 >$at_check_line_file
21562( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
21563at_status=$?
21564grep '^ *+' $at_stder1 >&2
21565grep -v '^ *+' $at_stder1 >$at_stderr
21566at_failed=false
21567echo stderr:; tee stderr <$at_stderr
21568$at_diff $at_devnull $at_stdout || at_failed=:
21569case $at_status in
21570   77) echo 77 > $at_status_file
21571            exit 77;;
21572   0) ;;
21573   *) echo "calc.at:560: exit code was $at_status, expected 0"
21574      at_failed=:;;
21575esac
21576if $at_failed; then
21577
21578  echo 1 > $at_status_file
21579  exit 1
21580fi
21581
21582$at_traceon
21583
21584
21585# Normalize the observed and expected error messages, depending upon the
21586# options.
21587# 1. Remove the traces from observed.
21588sed '/^Starting/d
21589/^Entering/d
21590/^Stack/d
21591/^Reading/d
21592/^Reducing/d
21593/^Shifting/d
21594/^state/d
21595/^Cleanup:/d
21596/^Error:/d
21597/^Next/d
21598/^Discarding/d
21599/ \$[0-9$]* = /d
21600/^yydestructor:/d' stderr >at-stderr
21601mv at-stderr stderr
21602# 2. Create the reference error message.
21603cat >expout <<'_ATEOF'
216041.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
216051.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
216061.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
216071.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
21608calc: error: 4444 != 1
21609_ATEOF
21610
21611# 3. If locations are not used, remove them.
21612
21613# 4. If error-verbose is not used, strip the`, unexpected....' part.
21614
21615# 5. Check
21616$at_traceoff
21617echo "calc.at:560: cat stderr"
21618echo calc.at:560 >$at_check_line_file
21619( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
21620at_status=$?
21621grep '^ *+' $at_stder1 >&2
21622grep -v '^ *+' $at_stder1 >$at_stderr
21623at_failed=false
21624$at_diff $at_devnull $at_stderr || at_failed=:
21625$at_diff expout $at_stdout || at_failed=:
21626case $at_status in
21627   77) echo 77 > $at_status_file
21628            exit 77;;
21629   0) ;;
21630   *) echo "calc.at:560: exit code was $at_status, expected 0"
21631      at_failed=:;;
21632esac
21633if $at_failed; then
21634
21635  echo 1 > $at_status_file
21636  exit 1
21637fi
21638
21639$at_traceon
21640
21641
21642
21643# The same, but this time exercising explicitly triggered syntax errors.
21644# POSIX says the look-ahead causing the error should not be discarded.
21645cat >input <<'_ATEOF'
21646(!) + (0 0) = 1
21647_ATEOF
21648
21649$at_traceoff
21650echo "calc.at:560: \$PREPARSER ./calc input"
21651echo calc.at:560 >$at_check_line_file
21652( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
21653at_status=$?
21654grep '^ *+' $at_stder1 >&2
21655grep -v '^ *+' $at_stder1 >$at_stderr
21656at_failed=false
21657echo stderr:; tee stderr <$at_stderr
21658$at_diff $at_devnull $at_stdout || at_failed=:
21659case $at_status in
21660   77) echo 77 > $at_status_file
21661            exit 77;;
21662   0) ;;
21663   *) echo "calc.at:560: exit code was $at_status, expected 0"
21664      at_failed=:;;
21665esac
21666if $at_failed; then
21667
21668  echo 1 > $at_status_file
21669  exit 1
21670fi
21671
21672$at_traceon
21673
21674
21675# Normalize the observed and expected error messages, depending upon the
21676# options.
21677# 1. Remove the traces from observed.
21678sed '/^Starting/d
21679/^Entering/d
21680/^Stack/d
21681/^Reading/d
21682/^Reducing/d
21683/^Shifting/d
21684/^state/d
21685/^Cleanup:/d
21686/^Error:/d
21687/^Next/d
21688/^Discarding/d
21689/ \$[0-9$]* = /d
21690/^yydestructor:/d' stderr >at-stderr
21691mv at-stderr stderr
21692# 2. Create the reference error message.
21693cat >expout <<'_ATEOF'
216941.9: syntax error, unexpected number
21695calc: error: 2222 != 1
21696_ATEOF
21697
21698# 3. If locations are not used, remove them.
21699
21700# 4. If error-verbose is not used, strip the`, unexpected....' part.
21701
21702# 5. Check
21703$at_traceoff
21704echo "calc.at:560: cat stderr"
21705echo calc.at:560 >$at_check_line_file
21706( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
21707at_status=$?
21708grep '^ *+' $at_stder1 >&2
21709grep -v '^ *+' $at_stder1 >$at_stderr
21710at_failed=false
21711$at_diff $at_devnull $at_stderr || at_failed=:
21712$at_diff expout $at_stdout || at_failed=:
21713case $at_status in
21714   77) echo 77 > $at_status_file
21715            exit 77;;
21716   0) ;;
21717   *) echo "calc.at:560: exit code was $at_status, expected 0"
21718      at_failed=:;;
21719esac
21720if $at_failed; then
21721
21722  echo 1 > $at_status_file
21723  exit 1
21724fi
21725
21726$at_traceon
21727
21728
21729cat >input <<'_ATEOF'
21730(- *) + (0 0) = 1
21731_ATEOF
21732
21733$at_traceoff
21734echo "calc.at:560: \$PREPARSER ./calc input"
21735echo calc.at:560 >$at_check_line_file
21736( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
21737at_status=$?
21738grep '^ *+' $at_stder1 >&2
21739grep -v '^ *+' $at_stder1 >$at_stderr
21740at_failed=false
21741echo stderr:; tee stderr <$at_stderr
21742$at_diff $at_devnull $at_stdout || at_failed=:
21743case $at_status in
21744   77) echo 77 > $at_status_file
21745            exit 77;;
21746   0) ;;
21747   *) echo "calc.at:560: exit code was $at_status, expected 0"
21748      at_failed=:;;
21749esac
21750if $at_failed; then
21751
21752  echo 1 > $at_status_file
21753  exit 1
21754fi
21755
21756$at_traceon
21757
21758
21759# Normalize the observed and expected error messages, depending upon the
21760# options.
21761# 1. Remove the traces from observed.
21762sed '/^Starting/d
21763/^Entering/d
21764/^Stack/d
21765/^Reading/d
21766/^Reducing/d
21767/^Shifting/d
21768/^state/d
21769/^Cleanup:/d
21770/^Error:/d
21771/^Next/d
21772/^Discarding/d
21773/ \$[0-9$]* = /d
21774/^yydestructor:/d' stderr >at-stderr
21775mv at-stderr stderr
21776# 2. Create the reference error message.
21777cat >expout <<'_ATEOF'
217781.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
217791.11: syntax error, unexpected number
21780calc: error: 2222 != 1
21781_ATEOF
21782
21783# 3. If locations are not used, remove them.
21784
21785# 4. If error-verbose is not used, strip the`, unexpected....' part.
21786
21787# 5. Check
21788$at_traceoff
21789echo "calc.at:560: cat stderr"
21790echo calc.at:560 >$at_check_line_file
21791( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
21792at_status=$?
21793grep '^ *+' $at_stder1 >&2
21794grep -v '^ *+' $at_stder1 >$at_stderr
21795at_failed=false
21796$at_diff $at_devnull $at_stderr || at_failed=:
21797$at_diff expout $at_stdout || at_failed=:
21798case $at_status in
21799   77) echo 77 > $at_status_file
21800            exit 77;;
21801   0) ;;
21802   *) echo "calc.at:560: exit code was $at_status, expected 0"
21803      at_failed=:;;
21804esac
21805if $at_failed; then
21806
21807  echo 1 > $at_status_file
21808  exit 1
21809fi
21810
21811$at_traceon
21812
21813
21814
21815
21816
21817
21818
21819
21820
21821
21822
21823
21824
21825
21826
21827
21828
21829
21830
21831
21832
21833
21834
21835
21836      $at_traceoff
21837      $at_times_p && times >$at_times_file
21838    ) 5>&1 2>&1 | eval $at_tee_pipe
21839    at_status=`cat $at_status_file`
21840    ;;
21841
21842  79 ) # 79. calc.at:562: Calculator %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc
21843    at_setup_line='calc.at:562'
21844    at_desc='Calculator %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc'
21845    $at_quiet $ECHO_N " 79: Calculator %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc$ECHO_C"
21846    at_xfail=no
21847    (
21848      echo "79. calc.at:562: testing ..."
21849      $at_traceon
21850
21851
21852
21853
21854
21855
21856
21857
21858# Using yacc.c?
21859
21860
21861
21862
21863
21864
21865
21866# yyerror receives the location if %location & %pure & (%glr or %parse-param).
21867
21868# yyerror always sees the locations (when activated), except if
21869# yacc & pure & !param.
21870
21871
21872# The interface is pure: either because %pure-parser, or because we
21873# are using the C++ parsers.
21874
21875
21876
21877
21878
21879
21880
21881
21882
21883
21884
21885
21886cat >calc.y <<'_ATEOF'
21887%{
21888#ifdef HAVE_CONFIG_H
21889# include <config.h>
21890  /* We don't need perfect functions for these tests. */
21891# undef malloc
21892# undef memcmp
21893# undef realloc
21894#endif
21895%}
21896
21897/* Infix notation calculator--calc */
21898%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc
21899
21900%{
21901#include <stdio.h>
21902
21903#include <stdlib.h>
21904#include <string.h>
21905#if HAVE_UNISTD_H
21906# include <unistd.h>
21907#else
21908# undef alarm
21909# define alarm(seconds) /* empty */
21910#endif
21911#include <ctype.h>
21912#define USE(Var)
21913
21914/* Exercise pre-prologue dependency to %union.  */
21915typedef int semantic_value;
21916
21917static semantic_value global_result = 0;
21918static int global_count = 0;
21919%}
21920
21921/* Exercise %union. */
21922%union
21923{
21924  semantic_value ival;
21925};
21926
21927%{
21928static int power (int base, int exponent);
21929/* yyerror receives the location if:
21930   - %location & %pure & %glr
21931   - %location & %pure & %yacc & %parse-param. */
21932static void yyerror (
21933
21934                     const char *s
21935                     );
21936static int yylex (void);
21937static int get_char (void);
21938static void unget_char ( int c);
21939%}
21940
21941
21942
21943/* Bison Declarations */
21944%token CALC_EOF 0 "end of input"
21945%token <ival> NUM "number"
21946%type  <ival> exp
21947
21948%nonassoc '=' /* comparison	       */
21949%left '-' '+'
21950%left '*' '/'
21951%left NEG     /* negation--unary minus */
21952%right '^'    /* exponentiation        */
21953
21954/* Grammar follows */
21955%%
21956input:
21957  line
21958| input line         {  }
21959;
21960
21961line:
21962  '\n'
21963| exp '\n'           { USE ($1); }
21964;
21965
21966exp:
21967  NUM                { $$ = $1;             }
21968| exp '=' exp
21969  {
21970    if ($1 != $3)
21971      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
21972    $$ = $1;
21973  }
21974| exp '+' exp        { $$ = $1 + $3;        }
21975| exp '-' exp        { $$ = $1 - $3;        }
21976| exp '*' exp        { $$ = $1 * $3;        }
21977| exp '/' exp        { $$ = $1 / $3;        }
21978| '-' exp  %prec NEG { $$ = -$2;            }
21979| exp '^' exp        { $$ = power ($1, $3); }
21980| '(' exp ')'        { $$ = $2;             }
21981| '(' error ')'      { $$ = 1111;           }
21982| '!'                { $$ = 0; YYERROR;     }
21983| '-' error          { $$ = 0; YYERROR;     }
21984;
21985%%
21986/* The input.  */
21987static FILE *input;
21988
21989static void
21990yyerror (
21991
21992         const char *s)
21993{
21994
21995
21996  fprintf (stderr, "%d.%d",
21997           (yylloc).first_line, (yylloc).first_column);
21998  if ((yylloc).first_line != (yylloc).last_line)
21999    fprintf (stderr, "-%d.%d",
22000	     (yylloc).last_line,  (yylloc).last_column - 1);
22001  else if ((yylloc).first_column != (yylloc).last_column - 1)
22002    fprintf (stderr, "-%d",
22003	     (yylloc).last_column - 1);
22004  fprintf (stderr, ": ");
22005  fprintf (stderr, "%s\n", s);
22006}
22007
22008
22009
22010static YYLTYPE last_yylloc;
22011
22012static int
22013get_char (void)
22014{
22015  int res = getc (input);
22016  ;
22017
22018  last_yylloc = (yylloc);
22019  if (res == '\n')
22020    {
22021      (yylloc).last_line++;
22022      (yylloc).last_column = 0;
22023    }
22024  else
22025    (yylloc).last_column++;
22026
22027  return res;
22028}
22029
22030
22031static void
22032unget_char ( int c)
22033{
22034  ;
22035
22036  /* Wrong when C == `\n'. */
22037  (yylloc) = last_yylloc;
22038
22039  ungetc (c, input);
22040}
22041
22042static int
22043read_signed_integer (void)
22044{
22045  int c = get_char ();
22046  int sign = 1;
22047  int n = 0;
22048
22049  ;
22050  if (c == '-')
22051    {
22052      c = get_char ();
22053      sign = -1;
22054    }
22055
22056  while (isdigit (c))
22057    {
22058      n = 10 * n + (c - '0');
22059      c = get_char ();
22060    }
22061
22062  unget_char ( c);
22063
22064  return sign * n;
22065}
22066
22067
22068
22069/*---------------------------------------------------------------.
22070| Lexical analyzer returns an integer on the stack and the token |
22071| NUM, or the ASCII character read if not a number.  Skips all   |
22072| blanks and tabs, returns 0 for EOF.                            |
22073`---------------------------------------------------------------*/
22074
22075static int
22076yylex (void)
22077{
22078  static int init = 1;
22079  int c;
22080
22081  if (init)
22082    {
22083      init = 0;
22084
22085      (yylloc).last_column = 0;
22086      (yylloc).last_line = 1;
22087
22088    }
22089
22090
22091 (yylloc).first_column = (yylloc).last_column;
22092  (yylloc).first_line   = (yylloc).last_line;
22093
22094
22095  /* Skip white space.  */
22096  while ((c = get_char ()) == ' ' || c == '\t')
22097    {
22098     (yylloc).first_column = (yylloc).last_column;
22099      (yylloc).first_line   = (yylloc).last_line;
22100
22101    }
22102
22103  /* process numbers   */
22104  if (c == '.' || isdigit (c))
22105    {
22106      unget_char ( c);
22107      (yylval).ival = read_signed_integer ();
22108      return NUM;
22109    }
22110
22111  /* Return end-of-file.  */
22112  if (c == EOF)
22113    return CALC_EOF;
22114
22115  /* Return single chars. */
22116  return c;
22117}
22118
22119static int
22120power (int base, int exponent)
22121{
22122  int res = 1;
22123  if (exponent < 0)
22124    exit (3);
22125  for (/* Niente */; exponent; --exponent)
22126    res *= base;
22127  return res;
22128}
22129
22130
22131int
22132main (int argc, const char **argv)
22133{
22134  semantic_value result = 0;
22135  int count = 0;
22136  int status;
22137
22138  /* This used to be alarm (10), but that isn't enough time for
22139     a July 1995 vintage DEC Alphastation 200 4/100 system,
22140     according to Nelson H. F. Beebe.  100 seconds is enough.  */
22141  alarm (100);
22142
22143  if (argc == 2)
22144    input = fopen (argv[1], "r");
22145  else
22146    input = stdin;
22147
22148  if (!input)
22149    {
22150      perror (argv[1]);
22151      return 3;
22152    }
22153
22154
22155  status = yyparse ();
22156  if (global_result != result)
22157    abort ();
22158  if (global_count != count)
22159    abort ();
22160  return status;
22161}
22162_ATEOF
22163
22164
22165
22166
22167
22168$at_traceoff
22169echo "calc.at:562: bison -o calc.c calc.y"
22170echo calc.at:562 >$at_check_line_file
22171( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
22172at_status=$?
22173grep '^ *+' $at_stder1 >&2
22174grep -v '^ *+' $at_stder1 >$at_stderr
22175at_failed=false
22176$at_diff $at_devnull $at_stderr || at_failed=:
22177$at_diff $at_devnull $at_stdout || at_failed=:
22178case $at_status in
22179   77) echo 77 > $at_status_file
22180            exit 77;;
22181   0) ;;
22182   *) echo "calc.at:562: exit code was $at_status, expected 0"
22183      at_failed=:;;
22184esac
22185if $at_failed; then
22186
22187  echo 1 > $at_status_file
22188  exit 1
22189fi
22190
22191$at_traceon
22192
22193   $at_traceoff
22194echo "calc.at:562: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
22195echo calc.at:562 >$at_check_line_file
22196( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
22197at_status=$?
22198grep '^ *+' $at_stder1 >&2
22199grep -v '^ *+' $at_stder1 >$at_stderr
22200at_failed=false
22201echo stderr:; cat $at_stderr
22202echo stdout:; cat $at_stdout
22203case $at_status in
22204   77) echo 77 > $at_status_file
22205            exit 77;;
22206   0) ;;
22207   *) echo "calc.at:562: exit code was $at_status, expected 0"
22208      at_failed=:;;
22209esac
22210if $at_failed; then
22211
22212  echo 1 > $at_status_file
22213  exit 1
22214fi
22215
22216$at_traceon
22217
22218
22219# Test the priorities.
22220cat >input <<'_ATEOF'
222211 + 2 * 3 = 7
222221 + 2 * -3 = -5
22223
22224-1^2 = -1
22225(-1)^2 = 1
22226
22227---1 = -1
22228
222291 - 2 - 3 = -4
222301 - (2 - 3) = 2
22231
222322^2^3 = 256
22233(2^2)^3 = 64
22234_ATEOF
22235
22236$at_traceoff
22237echo "calc.at:562: \$PREPARSER ./calc input"
22238echo calc.at:562 >$at_check_line_file
22239( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
22240at_status=$?
22241grep '^ *+' $at_stder1 >&2
22242grep -v '^ *+' $at_stder1 >$at_stderr
22243at_failed=false
22244echo stderr:; tee stderr <$at_stderr
22245$at_diff $at_devnull $at_stdout || at_failed=:
22246case $at_status in
22247   77) echo 77 > $at_status_file
22248            exit 77;;
22249   0) ;;
22250   *) echo "calc.at:562: exit code was $at_status, expected 0"
22251      at_failed=:;;
22252esac
22253if $at_failed; then
22254
22255  echo 1 > $at_status_file
22256  exit 1
22257fi
22258
22259$at_traceon
22260
22261
22262
22263# Some syntax errors.
22264cat >input <<'_ATEOF'
222650 0
22266_ATEOF
22267
22268$at_traceoff
22269echo "calc.at:562: \$PREPARSER ./calc input"
22270echo calc.at:562 >$at_check_line_file
22271( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
22272at_status=$?
22273grep '^ *+' $at_stder1 >&2
22274grep -v '^ *+' $at_stder1 >$at_stderr
22275at_failed=false
22276echo stderr:; tee stderr <$at_stderr
22277$at_diff $at_devnull $at_stdout || at_failed=:
22278case $at_status in
22279   77) echo 77 > $at_status_file
22280            exit 77;;
22281   1) ;;
22282   *) echo "calc.at:562: exit code was $at_status, expected 1"
22283      at_failed=:;;
22284esac
22285if $at_failed; then
22286
22287  echo 1 > $at_status_file
22288  exit 1
22289fi
22290
22291$at_traceon
22292
22293
22294# Normalize the observed and expected error messages, depending upon the
22295# options.
22296# 1. Remove the traces from observed.
22297sed '/^Starting/d
22298/^Entering/d
22299/^Stack/d
22300/^Reading/d
22301/^Reducing/d
22302/^Shifting/d
22303/^state/d
22304/^Cleanup:/d
22305/^Error:/d
22306/^Next/d
22307/^Discarding/d
22308/ \$[0-9$]* = /d
22309/^yydestructor:/d' stderr >at-stderr
22310mv at-stderr stderr
22311# 2. Create the reference error message.
22312cat >expout <<'_ATEOF'
223131.2: syntax error, unexpected number
22314_ATEOF
22315
22316# 3. If locations are not used, remove them.
22317
22318# 4. If error-verbose is not used, strip the`, unexpected....' part.
22319
22320# 5. Check
22321$at_traceoff
22322echo "calc.at:562: cat stderr"
22323echo calc.at:562 >$at_check_line_file
22324( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
22325at_status=$?
22326grep '^ *+' $at_stder1 >&2
22327grep -v '^ *+' $at_stder1 >$at_stderr
22328at_failed=false
22329$at_diff $at_devnull $at_stderr || at_failed=:
22330$at_diff expout $at_stdout || at_failed=:
22331case $at_status in
22332   77) echo 77 > $at_status_file
22333            exit 77;;
22334   0) ;;
22335   *) echo "calc.at:562: exit code was $at_status, expected 0"
22336      at_failed=:;;
22337esac
22338if $at_failed; then
22339
22340  echo 1 > $at_status_file
22341  exit 1
22342fi
22343
22344$at_traceon
22345
22346
22347cat >input <<'_ATEOF'
223481//2
22349_ATEOF
22350
22351$at_traceoff
22352echo "calc.at:562: \$PREPARSER ./calc input"
22353echo calc.at:562 >$at_check_line_file
22354( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
22355at_status=$?
22356grep '^ *+' $at_stder1 >&2
22357grep -v '^ *+' $at_stder1 >$at_stderr
22358at_failed=false
22359echo stderr:; tee stderr <$at_stderr
22360$at_diff $at_devnull $at_stdout || at_failed=:
22361case $at_status in
22362   77) echo 77 > $at_status_file
22363            exit 77;;
22364   1) ;;
22365   *) echo "calc.at:562: exit code was $at_status, expected 1"
22366      at_failed=:;;
22367esac
22368if $at_failed; then
22369
22370  echo 1 > $at_status_file
22371  exit 1
22372fi
22373
22374$at_traceon
22375
22376
22377# Normalize the observed and expected error messages, depending upon the
22378# options.
22379# 1. Remove the traces from observed.
22380sed '/^Starting/d
22381/^Entering/d
22382/^Stack/d
22383/^Reading/d
22384/^Reducing/d
22385/^Shifting/d
22386/^state/d
22387/^Cleanup:/d
22388/^Error:/d
22389/^Next/d
22390/^Discarding/d
22391/ \$[0-9$]* = /d
22392/^yydestructor:/d' stderr >at-stderr
22393mv at-stderr stderr
22394# 2. Create the reference error message.
22395cat >expout <<'_ATEOF'
223961.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
22397_ATEOF
22398
22399# 3. If locations are not used, remove them.
22400
22401# 4. If error-verbose is not used, strip the`, unexpected....' part.
22402
22403# 5. Check
22404$at_traceoff
22405echo "calc.at:562: cat stderr"
22406echo calc.at:562 >$at_check_line_file
22407( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
22408at_status=$?
22409grep '^ *+' $at_stder1 >&2
22410grep -v '^ *+' $at_stder1 >$at_stderr
22411at_failed=false
22412$at_diff $at_devnull $at_stderr || at_failed=:
22413$at_diff expout $at_stdout || at_failed=:
22414case $at_status in
22415   77) echo 77 > $at_status_file
22416            exit 77;;
22417   0) ;;
22418   *) echo "calc.at:562: exit code was $at_status, expected 0"
22419      at_failed=:;;
22420esac
22421if $at_failed; then
22422
22423  echo 1 > $at_status_file
22424  exit 1
22425fi
22426
22427$at_traceon
22428
22429
22430cat >input <<'_ATEOF'
22431error
22432_ATEOF
22433
22434$at_traceoff
22435echo "calc.at:562: \$PREPARSER ./calc input"
22436echo calc.at:562 >$at_check_line_file
22437( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
22438at_status=$?
22439grep '^ *+' $at_stder1 >&2
22440grep -v '^ *+' $at_stder1 >$at_stderr
22441at_failed=false
22442echo stderr:; tee stderr <$at_stderr
22443$at_diff $at_devnull $at_stdout || at_failed=:
22444case $at_status in
22445   77) echo 77 > $at_status_file
22446            exit 77;;
22447   1) ;;
22448   *) echo "calc.at:562: exit code was $at_status, expected 1"
22449      at_failed=:;;
22450esac
22451if $at_failed; then
22452
22453  echo 1 > $at_status_file
22454  exit 1
22455fi
22456
22457$at_traceon
22458
22459
22460# Normalize the observed and expected error messages, depending upon the
22461# options.
22462# 1. Remove the traces from observed.
22463sed '/^Starting/d
22464/^Entering/d
22465/^Stack/d
22466/^Reading/d
22467/^Reducing/d
22468/^Shifting/d
22469/^state/d
22470/^Cleanup:/d
22471/^Error:/d
22472/^Next/d
22473/^Discarding/d
22474/ \$[0-9$]* = /d
22475/^yydestructor:/d' stderr >at-stderr
22476mv at-stderr stderr
22477# 2. Create the reference error message.
22478cat >expout <<'_ATEOF'
224791.0: syntax error, unexpected $undefined
22480_ATEOF
22481
22482# 3. If locations are not used, remove them.
22483
22484# 4. If error-verbose is not used, strip the`, unexpected....' part.
22485
22486# 5. Check
22487$at_traceoff
22488echo "calc.at:562: cat stderr"
22489echo calc.at:562 >$at_check_line_file
22490( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
22491at_status=$?
22492grep '^ *+' $at_stder1 >&2
22493grep -v '^ *+' $at_stder1 >$at_stderr
22494at_failed=false
22495$at_diff $at_devnull $at_stderr || at_failed=:
22496$at_diff expout $at_stdout || at_failed=:
22497case $at_status in
22498   77) echo 77 > $at_status_file
22499            exit 77;;
22500   0) ;;
22501   *) echo "calc.at:562: exit code was $at_status, expected 0"
22502      at_failed=:;;
22503esac
22504if $at_failed; then
22505
22506  echo 1 > $at_status_file
22507  exit 1
22508fi
22509
22510$at_traceon
22511
22512
22513cat >input <<'_ATEOF'
225141 = 2 = 3
22515_ATEOF
22516
22517$at_traceoff
22518echo "calc.at:562: \$PREPARSER ./calc input"
22519echo calc.at:562 >$at_check_line_file
22520( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
22521at_status=$?
22522grep '^ *+' $at_stder1 >&2
22523grep -v '^ *+' $at_stder1 >$at_stderr
22524at_failed=false
22525echo stderr:; tee stderr <$at_stderr
22526$at_diff $at_devnull $at_stdout || at_failed=:
22527case $at_status in
22528   77) echo 77 > $at_status_file
22529            exit 77;;
22530   1) ;;
22531   *) echo "calc.at:562: exit code was $at_status, expected 1"
22532      at_failed=:;;
22533esac
22534if $at_failed; then
22535
22536  echo 1 > $at_status_file
22537  exit 1
22538fi
22539
22540$at_traceon
22541
22542
22543# Normalize the observed and expected error messages, depending upon the
22544# options.
22545# 1. Remove the traces from observed.
22546sed '/^Starting/d
22547/^Entering/d
22548/^Stack/d
22549/^Reading/d
22550/^Reducing/d
22551/^Shifting/d
22552/^state/d
22553/^Cleanup:/d
22554/^Error:/d
22555/^Next/d
22556/^Discarding/d
22557/ \$[0-9$]* = /d
22558/^yydestructor:/d' stderr >at-stderr
22559mv at-stderr stderr
22560# 2. Create the reference error message.
22561cat >expout <<'_ATEOF'
225621.6: syntax error, unexpected '='
22563_ATEOF
22564
22565# 3. If locations are not used, remove them.
22566
22567# 4. If error-verbose is not used, strip the`, unexpected....' part.
22568
22569# 5. Check
22570$at_traceoff
22571echo "calc.at:562: cat stderr"
22572echo calc.at:562 >$at_check_line_file
22573( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
22574at_status=$?
22575grep '^ *+' $at_stder1 >&2
22576grep -v '^ *+' $at_stder1 >$at_stderr
22577at_failed=false
22578$at_diff $at_devnull $at_stderr || at_failed=:
22579$at_diff expout $at_stdout || at_failed=:
22580case $at_status in
22581   77) echo 77 > $at_status_file
22582            exit 77;;
22583   0) ;;
22584   *) echo "calc.at:562: exit code was $at_status, expected 0"
22585      at_failed=:;;
22586esac
22587if $at_failed; then
22588
22589  echo 1 > $at_status_file
22590  exit 1
22591fi
22592
22593$at_traceon
22594
22595
22596cat >input <<'_ATEOF'
22597
22598+1
22599_ATEOF
22600
22601$at_traceoff
22602echo "calc.at:562: \$PREPARSER ./calc input"
22603echo calc.at:562 >$at_check_line_file
22604( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
22605at_status=$?
22606grep '^ *+' $at_stder1 >&2
22607grep -v '^ *+' $at_stder1 >$at_stderr
22608at_failed=false
22609echo stderr:; tee stderr <$at_stderr
22610$at_diff $at_devnull $at_stdout || at_failed=:
22611case $at_status in
22612   77) echo 77 > $at_status_file
22613            exit 77;;
22614   1) ;;
22615   *) echo "calc.at:562: exit code was $at_status, expected 1"
22616      at_failed=:;;
22617esac
22618if $at_failed; then
22619
22620  echo 1 > $at_status_file
22621  exit 1
22622fi
22623
22624$at_traceon
22625
22626
22627# Normalize the observed and expected error messages, depending upon the
22628# options.
22629# 1. Remove the traces from observed.
22630sed '/^Starting/d
22631/^Entering/d
22632/^Stack/d
22633/^Reading/d
22634/^Reducing/d
22635/^Shifting/d
22636/^state/d
22637/^Cleanup:/d
22638/^Error:/d
22639/^Next/d
22640/^Discarding/d
22641/ \$[0-9$]* = /d
22642/^yydestructor:/d' stderr >at-stderr
22643mv at-stderr stderr
22644# 2. Create the reference error message.
22645cat >expout <<'_ATEOF'
226462.0: syntax error, unexpected '+'
22647_ATEOF
22648
22649# 3. If locations are not used, remove them.
22650
22651# 4. If error-verbose is not used, strip the`, unexpected....' part.
22652
22653# 5. Check
22654$at_traceoff
22655echo "calc.at:562: cat stderr"
22656echo calc.at:562 >$at_check_line_file
22657( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
22658at_status=$?
22659grep '^ *+' $at_stder1 >&2
22660grep -v '^ *+' $at_stder1 >$at_stderr
22661at_failed=false
22662$at_diff $at_devnull $at_stderr || at_failed=:
22663$at_diff expout $at_stdout || at_failed=:
22664case $at_status in
22665   77) echo 77 > $at_status_file
22666            exit 77;;
22667   0) ;;
22668   *) echo "calc.at:562: exit code was $at_status, expected 0"
22669      at_failed=:;;
22670esac
22671if $at_failed; then
22672
22673  echo 1 > $at_status_file
22674  exit 1
22675fi
22676
22677$at_traceon
22678
22679
22680# Exercise error messages with EOF: work on an empty file.
22681$at_traceoff
22682echo "calc.at:562: \$PREPARSER ./calc /dev/null"
22683echo calc.at:562 >$at_check_line_file
22684( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
22685at_status=$?
22686grep '^ *+' $at_stder1 >&2
22687grep -v '^ *+' $at_stder1 >$at_stderr
22688at_failed=false
22689echo stderr:; tee stderr <$at_stderr
22690$at_diff $at_devnull $at_stdout || at_failed=:
22691case $at_status in
22692   77) echo 77 > $at_status_file
22693            exit 77;;
22694   1) ;;
22695   *) echo "calc.at:562: exit code was $at_status, expected 1"
22696      at_failed=:;;
22697esac
22698if $at_failed; then
22699
22700  echo 1 > $at_status_file
22701  exit 1
22702fi
22703
22704$at_traceon
22705
22706
22707# Normalize the observed and expected error messages, depending upon the
22708# options.
22709# 1. Remove the traces from observed.
22710sed '/^Starting/d
22711/^Entering/d
22712/^Stack/d
22713/^Reading/d
22714/^Reducing/d
22715/^Shifting/d
22716/^state/d
22717/^Cleanup:/d
22718/^Error:/d
22719/^Next/d
22720/^Discarding/d
22721/ \$[0-9$]* = /d
22722/^yydestructor:/d' stderr >at-stderr
22723mv at-stderr stderr
22724# 2. Create the reference error message.
22725cat >expout <<'_ATEOF'
227261.0: syntax error, unexpected end of input
22727_ATEOF
22728
22729# 3. If locations are not used, remove them.
22730
22731# 4. If error-verbose is not used, strip the`, unexpected....' part.
22732
22733# 5. Check
22734$at_traceoff
22735echo "calc.at:562: cat stderr"
22736echo calc.at:562 >$at_check_line_file
22737( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
22738at_status=$?
22739grep '^ *+' $at_stder1 >&2
22740grep -v '^ *+' $at_stder1 >$at_stderr
22741at_failed=false
22742$at_diff $at_devnull $at_stderr || at_failed=:
22743$at_diff expout $at_stdout || at_failed=:
22744case $at_status in
22745   77) echo 77 > $at_status_file
22746            exit 77;;
22747   0) ;;
22748   *) echo "calc.at:562: exit code was $at_status, expected 0"
22749      at_failed=:;;
22750esac
22751if $at_failed; then
22752
22753  echo 1 > $at_status_file
22754  exit 1
22755fi
22756
22757$at_traceon
22758
22759
22760
22761# Exercise the error token: without it, we die at the first error,
22762# hence be sure to
22763#
22764# - have several errors which exercise different shift/discardings
22765#   - (): nothing to pop, nothing to discard
22766#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
22767#   - (* * *): nothing to pop, a lot to discard
22768#   - (1 + 2 * *): some to pop and discard
22769#
22770# - test the action associated to `error'
22771#
22772# - check the look-ahead that triggers an error is not discarded
22773#   when we enter error recovery.  Below, the look-ahead causing the
22774#   first error is ")", which is needed to recover from the error and
22775#   produce the "0" that triggers the "0 != 1" error.
22776#
22777cat >input <<'_ATEOF'
22778() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
22779_ATEOF
22780
22781$at_traceoff
22782echo "calc.at:562: \$PREPARSER ./calc input"
22783echo calc.at:562 >$at_check_line_file
22784( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
22785at_status=$?
22786grep '^ *+' $at_stder1 >&2
22787grep -v '^ *+' $at_stder1 >$at_stderr
22788at_failed=false
22789echo stderr:; tee stderr <$at_stderr
22790$at_diff $at_devnull $at_stdout || at_failed=:
22791case $at_status in
22792   77) echo 77 > $at_status_file
22793            exit 77;;
22794   0) ;;
22795   *) echo "calc.at:562: exit code was $at_status, expected 0"
22796      at_failed=:;;
22797esac
22798if $at_failed; then
22799
22800  echo 1 > $at_status_file
22801  exit 1
22802fi
22803
22804$at_traceon
22805
22806
22807# Normalize the observed and expected error messages, depending upon the
22808# options.
22809# 1. Remove the traces from observed.
22810sed '/^Starting/d
22811/^Entering/d
22812/^Stack/d
22813/^Reading/d
22814/^Reducing/d
22815/^Shifting/d
22816/^state/d
22817/^Cleanup:/d
22818/^Error:/d
22819/^Next/d
22820/^Discarding/d
22821/ \$[0-9$]* = /d
22822/^yydestructor:/d' stderr >at-stderr
22823mv at-stderr stderr
22824# 2. Create the reference error message.
22825cat >expout <<'_ATEOF'
228261.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
228271.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
228281.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
228291.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
22830calc: error: 4444 != 1
22831_ATEOF
22832
22833# 3. If locations are not used, remove them.
22834
22835# 4. If error-verbose is not used, strip the`, unexpected....' part.
22836
22837# 5. Check
22838$at_traceoff
22839echo "calc.at:562: cat stderr"
22840echo calc.at:562 >$at_check_line_file
22841( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
22842at_status=$?
22843grep '^ *+' $at_stder1 >&2
22844grep -v '^ *+' $at_stder1 >$at_stderr
22845at_failed=false
22846$at_diff $at_devnull $at_stderr || at_failed=:
22847$at_diff expout $at_stdout || at_failed=:
22848case $at_status in
22849   77) echo 77 > $at_status_file
22850            exit 77;;
22851   0) ;;
22852   *) echo "calc.at:562: exit code was $at_status, expected 0"
22853      at_failed=:;;
22854esac
22855if $at_failed; then
22856
22857  echo 1 > $at_status_file
22858  exit 1
22859fi
22860
22861$at_traceon
22862
22863
22864
22865# The same, but this time exercising explicitly triggered syntax errors.
22866# POSIX says the look-ahead causing the error should not be discarded.
22867cat >input <<'_ATEOF'
22868(!) + (0 0) = 1
22869_ATEOF
22870
22871$at_traceoff
22872echo "calc.at:562: \$PREPARSER ./calc input"
22873echo calc.at:562 >$at_check_line_file
22874( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
22875at_status=$?
22876grep '^ *+' $at_stder1 >&2
22877grep -v '^ *+' $at_stder1 >$at_stderr
22878at_failed=false
22879echo stderr:; tee stderr <$at_stderr
22880$at_diff $at_devnull $at_stdout || at_failed=:
22881case $at_status in
22882   77) echo 77 > $at_status_file
22883            exit 77;;
22884   0) ;;
22885   *) echo "calc.at:562: exit code was $at_status, expected 0"
22886      at_failed=:;;
22887esac
22888if $at_failed; then
22889
22890  echo 1 > $at_status_file
22891  exit 1
22892fi
22893
22894$at_traceon
22895
22896
22897# Normalize the observed and expected error messages, depending upon the
22898# options.
22899# 1. Remove the traces from observed.
22900sed '/^Starting/d
22901/^Entering/d
22902/^Stack/d
22903/^Reading/d
22904/^Reducing/d
22905/^Shifting/d
22906/^state/d
22907/^Cleanup:/d
22908/^Error:/d
22909/^Next/d
22910/^Discarding/d
22911/ \$[0-9$]* = /d
22912/^yydestructor:/d' stderr >at-stderr
22913mv at-stderr stderr
22914# 2. Create the reference error message.
22915cat >expout <<'_ATEOF'
229161.9: syntax error, unexpected number
22917calc: error: 2222 != 1
22918_ATEOF
22919
22920# 3. If locations are not used, remove them.
22921
22922# 4. If error-verbose is not used, strip the`, unexpected....' part.
22923
22924# 5. Check
22925$at_traceoff
22926echo "calc.at:562: cat stderr"
22927echo calc.at:562 >$at_check_line_file
22928( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
22929at_status=$?
22930grep '^ *+' $at_stder1 >&2
22931grep -v '^ *+' $at_stder1 >$at_stderr
22932at_failed=false
22933$at_diff $at_devnull $at_stderr || at_failed=:
22934$at_diff expout $at_stdout || at_failed=:
22935case $at_status in
22936   77) echo 77 > $at_status_file
22937            exit 77;;
22938   0) ;;
22939   *) echo "calc.at:562: exit code was $at_status, expected 0"
22940      at_failed=:;;
22941esac
22942if $at_failed; then
22943
22944  echo 1 > $at_status_file
22945  exit 1
22946fi
22947
22948$at_traceon
22949
22950
22951cat >input <<'_ATEOF'
22952(- *) + (0 0) = 1
22953_ATEOF
22954
22955$at_traceoff
22956echo "calc.at:562: \$PREPARSER ./calc input"
22957echo calc.at:562 >$at_check_line_file
22958( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
22959at_status=$?
22960grep '^ *+' $at_stder1 >&2
22961grep -v '^ *+' $at_stder1 >$at_stderr
22962at_failed=false
22963echo stderr:; tee stderr <$at_stderr
22964$at_diff $at_devnull $at_stdout || at_failed=:
22965case $at_status in
22966   77) echo 77 > $at_status_file
22967            exit 77;;
22968   0) ;;
22969   *) echo "calc.at:562: exit code was $at_status, expected 0"
22970      at_failed=:;;
22971esac
22972if $at_failed; then
22973
22974  echo 1 > $at_status_file
22975  exit 1
22976fi
22977
22978$at_traceon
22979
22980
22981# Normalize the observed and expected error messages, depending upon the
22982# options.
22983# 1. Remove the traces from observed.
22984sed '/^Starting/d
22985/^Entering/d
22986/^Stack/d
22987/^Reading/d
22988/^Reducing/d
22989/^Shifting/d
22990/^state/d
22991/^Cleanup:/d
22992/^Error:/d
22993/^Next/d
22994/^Discarding/d
22995/ \$[0-9$]* = /d
22996/^yydestructor:/d' stderr >at-stderr
22997mv at-stderr stderr
22998# 2. Create the reference error message.
22999cat >expout <<'_ATEOF'
230001.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
230011.11: syntax error, unexpected number
23002calc: error: 2222 != 1
23003_ATEOF
23004
23005# 3. If locations are not used, remove them.
23006
23007# 4. If error-verbose is not used, strip the`, unexpected....' part.
23008
23009# 5. Check
23010$at_traceoff
23011echo "calc.at:562: cat stderr"
23012echo calc.at:562 >$at_check_line_file
23013( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
23014at_status=$?
23015grep '^ *+' $at_stder1 >&2
23016grep -v '^ *+' $at_stder1 >$at_stderr
23017at_failed=false
23018$at_diff $at_devnull $at_stderr || at_failed=:
23019$at_diff expout $at_stdout || at_failed=:
23020case $at_status in
23021   77) echo 77 > $at_status_file
23022            exit 77;;
23023   0) ;;
23024   *) echo "calc.at:562: exit code was $at_status, expected 0"
23025      at_failed=:;;
23026esac
23027if $at_failed; then
23028
23029  echo 1 > $at_status_file
23030  exit 1
23031fi
23032
23033$at_traceon
23034
23035
23036
23037
23038
23039
23040
23041
23042
23043
23044
23045
23046
23047
23048
23049
23050
23051
23052
23053
23054
23055
23056
23057
23058      $at_traceoff
23059      $at_times_p && times >$at_times_file
23060    ) 5>&1 2>&1 | eval $at_tee_pipe
23061    at_status=`cat $at_status_file`
23062    ;;
23063
23064  80 ) # 80. calc.at:564: Calculator %debug
23065    at_setup_line='calc.at:564'
23066    at_desc='Calculator %debug'
23067    $at_quiet $ECHO_N " 80: Calculator %debug                            $ECHO_C"
23068    at_xfail=no
23069    (
23070      echo "80. calc.at:564: testing ..."
23071      $at_traceon
23072
23073
23074
23075
23076
23077
23078
23079
23080# Using yacc.c?
23081
23082
23083
23084
23085
23086
23087
23088# yyerror receives the location if %location & %pure & (%glr or %parse-param).
23089
23090# yyerror always sees the locations (when activated), except if
23091# yacc & pure & !param.
23092
23093
23094# The interface is pure: either because %pure-parser, or because we
23095# are using the C++ parsers.
23096
23097
23098
23099
23100
23101
23102
23103
23104
23105
23106
23107
23108cat >calc.y <<'_ATEOF'
23109%{
23110#ifdef HAVE_CONFIG_H
23111# include <config.h>
23112  /* We don't need perfect functions for these tests. */
23113# undef malloc
23114# undef memcmp
23115# undef realloc
23116#endif
23117%}
23118
23119/* Infix notation calculator--calc */
23120%debug
23121
23122%{
23123#include <stdio.h>
23124
23125#include <stdlib.h>
23126#include <string.h>
23127#if HAVE_UNISTD_H
23128# include <unistd.h>
23129#else
23130# undef alarm
23131# define alarm(seconds) /* empty */
23132#endif
23133#include <ctype.h>
23134#define USE(Var)
23135
23136/* Exercise pre-prologue dependency to %union.  */
23137typedef int semantic_value;
23138
23139static semantic_value global_result = 0;
23140static int global_count = 0;
23141%}
23142
23143/* Exercise %union. */
23144%union
23145{
23146  semantic_value ival;
23147};
23148
23149%{
23150static int power (int base, int exponent);
23151/* yyerror receives the location if:
23152   - %location & %pure & %glr
23153   - %location & %pure & %yacc & %parse-param. */
23154static void yyerror (
23155
23156                     const char *s
23157                     );
23158static int yylex (void);
23159static int get_char (void);
23160static void unget_char ( int c);
23161%}
23162
23163
23164
23165/* Bison Declarations */
23166%token CALC_EOF 0 "end of input"
23167%token <ival> NUM "number"
23168%type  <ival> exp
23169
23170%nonassoc '=' /* comparison	       */
23171%left '-' '+'
23172%left '*' '/'
23173%left NEG     /* negation--unary minus */
23174%right '^'    /* exponentiation        */
23175
23176/* Grammar follows */
23177%%
23178input:
23179  line
23180| input line         {  }
23181;
23182
23183line:
23184  '\n'
23185| exp '\n'           { USE ($1); }
23186;
23187
23188exp:
23189  NUM                { $$ = $1;             }
23190| exp '=' exp
23191  {
23192    if ($1 != $3)
23193      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
23194    $$ = $1;
23195  }
23196| exp '+' exp        { $$ = $1 + $3;        }
23197| exp '-' exp        { $$ = $1 - $3;        }
23198| exp '*' exp        { $$ = $1 * $3;        }
23199| exp '/' exp        { $$ = $1 / $3;        }
23200| '-' exp  %prec NEG { $$ = -$2;            }
23201| exp '^' exp        { $$ = power ($1, $3); }
23202| '(' exp ')'        { $$ = $2;             }
23203| '(' error ')'      { $$ = 1111;           }
23204| '!'                { $$ = 0; YYERROR;     }
23205| '-' error          { $$ = 0; YYERROR;     }
23206;
23207%%
23208/* The input.  */
23209static FILE *input;
23210
23211static void
23212yyerror (
23213
23214         const char *s)
23215{
23216
23217
23218  fprintf (stderr, "%s\n", s);
23219}
23220
23221
23222
23223static int
23224get_char (void)
23225{
23226  int res = getc (input);
23227  ;
23228
23229  return res;
23230}
23231
23232
23233static void
23234unget_char ( int c)
23235{
23236  ;
23237
23238  ungetc (c, input);
23239}
23240
23241static int
23242read_signed_integer (void)
23243{
23244  int c = get_char ();
23245  int sign = 1;
23246  int n = 0;
23247
23248  ;
23249  if (c == '-')
23250    {
23251      c = get_char ();
23252      sign = -1;
23253    }
23254
23255  while (isdigit (c))
23256    {
23257      n = 10 * n + (c - '0');
23258      c = get_char ();
23259    }
23260
23261  unget_char ( c);
23262
23263  return sign * n;
23264}
23265
23266
23267
23268/*---------------------------------------------------------------.
23269| Lexical analyzer returns an integer on the stack and the token |
23270| NUM, or the ASCII character read if not a number.  Skips all   |
23271| blanks and tabs, returns 0 for EOF.                            |
23272`---------------------------------------------------------------*/
23273
23274static int
23275yylex (void)
23276{
23277  static int init = 1;
23278  int c;
23279
23280  if (init)
23281    {
23282      init = 0;
23283
23284    }
23285
23286
23287
23288  /* Skip white space.  */
23289  while ((c = get_char ()) == ' ' || c == '\t')
23290    {
23291
23292    }
23293
23294  /* process numbers   */
23295  if (c == '.' || isdigit (c))
23296    {
23297      unget_char ( c);
23298      (yylval).ival = read_signed_integer ();
23299      return NUM;
23300    }
23301
23302  /* Return end-of-file.  */
23303  if (c == EOF)
23304    return CALC_EOF;
23305
23306  /* Return single chars. */
23307  return c;
23308}
23309
23310static int
23311power (int base, int exponent)
23312{
23313  int res = 1;
23314  if (exponent < 0)
23315    exit (3);
23316  for (/* Niente */; exponent; --exponent)
23317    res *= base;
23318  return res;
23319}
23320
23321
23322int
23323main (int argc, const char **argv)
23324{
23325  semantic_value result = 0;
23326  int count = 0;
23327  int status;
23328
23329  /* This used to be alarm (10), but that isn't enough time for
23330     a July 1995 vintage DEC Alphastation 200 4/100 system,
23331     according to Nelson H. F. Beebe.  100 seconds is enough.  */
23332  alarm (100);
23333
23334  if (argc == 2)
23335    input = fopen (argv[1], "r");
23336  else
23337    input = stdin;
23338
23339  if (!input)
23340    {
23341      perror (argv[1]);
23342      return 3;
23343    }
23344
23345  yydebug = 1;
23346  status = yyparse ();
23347  if (global_result != result)
23348    abort ();
23349  if (global_count != count)
23350    abort ();
23351  return status;
23352}
23353_ATEOF
23354
23355
23356
23357
23358
23359$at_traceoff
23360echo "calc.at:564: bison -o calc.c calc.y"
23361echo calc.at:564 >$at_check_line_file
23362( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
23363at_status=$?
23364grep '^ *+' $at_stder1 >&2
23365grep -v '^ *+' $at_stder1 >$at_stderr
23366at_failed=false
23367$at_diff $at_devnull $at_stderr || at_failed=:
23368$at_diff $at_devnull $at_stdout || at_failed=:
23369case $at_status in
23370   77) echo 77 > $at_status_file
23371            exit 77;;
23372   0) ;;
23373   *) echo "calc.at:564: exit code was $at_status, expected 0"
23374      at_failed=:;;
23375esac
23376if $at_failed; then
23377
23378  echo 1 > $at_status_file
23379  exit 1
23380fi
23381
23382$at_traceon
23383
23384   $at_traceoff
23385echo "calc.at:564: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
23386echo calc.at:564 >$at_check_line_file
23387( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
23388at_status=$?
23389grep '^ *+' $at_stder1 >&2
23390grep -v '^ *+' $at_stder1 >$at_stderr
23391at_failed=false
23392echo stderr:; cat $at_stderr
23393echo stdout:; cat $at_stdout
23394case $at_status in
23395   77) echo 77 > $at_status_file
23396            exit 77;;
23397   0) ;;
23398   *) echo "calc.at:564: exit code was $at_status, expected 0"
23399      at_failed=:;;
23400esac
23401if $at_failed; then
23402
23403  echo 1 > $at_status_file
23404  exit 1
23405fi
23406
23407$at_traceon
23408
23409
23410# Test the priorities.
23411cat >input <<'_ATEOF'
234121 + 2 * 3 = 7
234131 + 2 * -3 = -5
23414
23415-1^2 = -1
23416(-1)^2 = 1
23417
23418---1 = -1
23419
234201 - 2 - 3 = -4
234211 - (2 - 3) = 2
23422
234232^2^3 = 256
23424(2^2)^3 = 64
23425_ATEOF
23426
23427$at_traceoff
23428echo "calc.at:564: \$PREPARSER ./calc input"
23429echo calc.at:564 >$at_check_line_file
23430( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
23431at_status=$?
23432grep '^ *+' $at_stder1 >&2
23433grep -v '^ *+' $at_stder1 >$at_stderr
23434at_failed=false
23435echo stderr:; tee stderr <$at_stderr
23436$at_diff $at_devnull $at_stdout || at_failed=:
23437case $at_status in
23438   77) echo 77 > $at_status_file
23439            exit 77;;
23440   0) ;;
23441   *) echo "calc.at:564: exit code was $at_status, expected 0"
23442      at_failed=:;;
23443esac
23444if $at_failed; then
23445
23446  echo 1 > $at_status_file
23447  exit 1
23448fi
23449
23450$at_traceon
23451
23452
23453
23454# Some syntax errors.
23455cat >input <<'_ATEOF'
234560 0
23457_ATEOF
23458
23459$at_traceoff
23460echo "calc.at:564: \$PREPARSER ./calc input"
23461echo calc.at:564 >$at_check_line_file
23462( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
23463at_status=$?
23464grep '^ *+' $at_stder1 >&2
23465grep -v '^ *+' $at_stder1 >$at_stderr
23466at_failed=false
23467echo stderr:; tee stderr <$at_stderr
23468$at_diff $at_devnull $at_stdout || at_failed=:
23469case $at_status in
23470   77) echo 77 > $at_status_file
23471            exit 77;;
23472   1) ;;
23473   *) echo "calc.at:564: exit code was $at_status, expected 1"
23474      at_failed=:;;
23475esac
23476if $at_failed; then
23477
23478  echo 1 > $at_status_file
23479  exit 1
23480fi
23481
23482$at_traceon
23483
23484
23485# Normalize the observed and expected error messages, depending upon the
23486# options.
23487# 1. Remove the traces from observed.
23488sed '/^Starting/d
23489/^Entering/d
23490/^Stack/d
23491/^Reading/d
23492/^Reducing/d
23493/^Shifting/d
23494/^state/d
23495/^Cleanup:/d
23496/^Error:/d
23497/^Next/d
23498/^Discarding/d
23499/ \$[0-9$]* = /d
23500/^yydestructor:/d' stderr >at-stderr
23501mv at-stderr stderr
23502# 2. Create the reference error message.
23503cat >expout <<'_ATEOF'
235041.2: syntax error, unexpected number
23505_ATEOF
23506
23507# 3. If locations are not used, remove them.
23508sed 's/^[-0-9.]*: //' expout >at-expout
23509mv at-expout expout
23510# 4. If error-verbose is not used, strip the`, unexpected....' part.
23511sed 's/syntax error, .*$/syntax error/' expout >at-expout
23512mv at-expout expout
23513# 5. Check
23514$at_traceoff
23515echo "calc.at:564: cat stderr"
23516echo calc.at:564 >$at_check_line_file
23517( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
23518at_status=$?
23519grep '^ *+' $at_stder1 >&2
23520grep -v '^ *+' $at_stder1 >$at_stderr
23521at_failed=false
23522$at_diff $at_devnull $at_stderr || at_failed=:
23523$at_diff expout $at_stdout || at_failed=:
23524case $at_status in
23525   77) echo 77 > $at_status_file
23526            exit 77;;
23527   0) ;;
23528   *) echo "calc.at:564: exit code was $at_status, expected 0"
23529      at_failed=:;;
23530esac
23531if $at_failed; then
23532
23533  echo 1 > $at_status_file
23534  exit 1
23535fi
23536
23537$at_traceon
23538
23539
23540cat >input <<'_ATEOF'
235411//2
23542_ATEOF
23543
23544$at_traceoff
23545echo "calc.at:564: \$PREPARSER ./calc input"
23546echo calc.at:564 >$at_check_line_file
23547( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
23548at_status=$?
23549grep '^ *+' $at_stder1 >&2
23550grep -v '^ *+' $at_stder1 >$at_stderr
23551at_failed=false
23552echo stderr:; tee stderr <$at_stderr
23553$at_diff $at_devnull $at_stdout || at_failed=:
23554case $at_status in
23555   77) echo 77 > $at_status_file
23556            exit 77;;
23557   1) ;;
23558   *) echo "calc.at:564: exit code was $at_status, expected 1"
23559      at_failed=:;;
23560esac
23561if $at_failed; then
23562
23563  echo 1 > $at_status_file
23564  exit 1
23565fi
23566
23567$at_traceon
23568
23569
23570# Normalize the observed and expected error messages, depending upon the
23571# options.
23572# 1. Remove the traces from observed.
23573sed '/^Starting/d
23574/^Entering/d
23575/^Stack/d
23576/^Reading/d
23577/^Reducing/d
23578/^Shifting/d
23579/^state/d
23580/^Cleanup:/d
23581/^Error:/d
23582/^Next/d
23583/^Discarding/d
23584/ \$[0-9$]* = /d
23585/^yydestructor:/d' stderr >at-stderr
23586mv at-stderr stderr
23587# 2. Create the reference error message.
23588cat >expout <<'_ATEOF'
235891.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
23590_ATEOF
23591
23592# 3. If locations are not used, remove them.
23593sed 's/^[-0-9.]*: //' expout >at-expout
23594mv at-expout expout
23595# 4. If error-verbose is not used, strip the`, unexpected....' part.
23596sed 's/syntax error, .*$/syntax error/' expout >at-expout
23597mv at-expout expout
23598# 5. Check
23599$at_traceoff
23600echo "calc.at:564: cat stderr"
23601echo calc.at:564 >$at_check_line_file
23602( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
23603at_status=$?
23604grep '^ *+' $at_stder1 >&2
23605grep -v '^ *+' $at_stder1 >$at_stderr
23606at_failed=false
23607$at_diff $at_devnull $at_stderr || at_failed=:
23608$at_diff expout $at_stdout || at_failed=:
23609case $at_status in
23610   77) echo 77 > $at_status_file
23611            exit 77;;
23612   0) ;;
23613   *) echo "calc.at:564: exit code was $at_status, expected 0"
23614      at_failed=:;;
23615esac
23616if $at_failed; then
23617
23618  echo 1 > $at_status_file
23619  exit 1
23620fi
23621
23622$at_traceon
23623
23624
23625cat >input <<'_ATEOF'
23626error
23627_ATEOF
23628
23629$at_traceoff
23630echo "calc.at:564: \$PREPARSER ./calc input"
23631echo calc.at:564 >$at_check_line_file
23632( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
23633at_status=$?
23634grep '^ *+' $at_stder1 >&2
23635grep -v '^ *+' $at_stder1 >$at_stderr
23636at_failed=false
23637echo stderr:; tee stderr <$at_stderr
23638$at_diff $at_devnull $at_stdout || at_failed=:
23639case $at_status in
23640   77) echo 77 > $at_status_file
23641            exit 77;;
23642   1) ;;
23643   *) echo "calc.at:564: exit code was $at_status, expected 1"
23644      at_failed=:;;
23645esac
23646if $at_failed; then
23647
23648  echo 1 > $at_status_file
23649  exit 1
23650fi
23651
23652$at_traceon
23653
23654
23655# Normalize the observed and expected error messages, depending upon the
23656# options.
23657# 1. Remove the traces from observed.
23658sed '/^Starting/d
23659/^Entering/d
23660/^Stack/d
23661/^Reading/d
23662/^Reducing/d
23663/^Shifting/d
23664/^state/d
23665/^Cleanup:/d
23666/^Error:/d
23667/^Next/d
23668/^Discarding/d
23669/ \$[0-9$]* = /d
23670/^yydestructor:/d' stderr >at-stderr
23671mv at-stderr stderr
23672# 2. Create the reference error message.
23673cat >expout <<'_ATEOF'
236741.0: syntax error, unexpected $undefined
23675_ATEOF
23676
23677# 3. If locations are not used, remove them.
23678sed 's/^[-0-9.]*: //' expout >at-expout
23679mv at-expout expout
23680# 4. If error-verbose is not used, strip the`, unexpected....' part.
23681sed 's/syntax error, .*$/syntax error/' expout >at-expout
23682mv at-expout expout
23683# 5. Check
23684$at_traceoff
23685echo "calc.at:564: cat stderr"
23686echo calc.at:564 >$at_check_line_file
23687( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
23688at_status=$?
23689grep '^ *+' $at_stder1 >&2
23690grep -v '^ *+' $at_stder1 >$at_stderr
23691at_failed=false
23692$at_diff $at_devnull $at_stderr || at_failed=:
23693$at_diff expout $at_stdout || at_failed=:
23694case $at_status in
23695   77) echo 77 > $at_status_file
23696            exit 77;;
23697   0) ;;
23698   *) echo "calc.at:564: exit code was $at_status, expected 0"
23699      at_failed=:;;
23700esac
23701if $at_failed; then
23702
23703  echo 1 > $at_status_file
23704  exit 1
23705fi
23706
23707$at_traceon
23708
23709
23710cat >input <<'_ATEOF'
237111 = 2 = 3
23712_ATEOF
23713
23714$at_traceoff
23715echo "calc.at:564: \$PREPARSER ./calc input"
23716echo calc.at:564 >$at_check_line_file
23717( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
23718at_status=$?
23719grep '^ *+' $at_stder1 >&2
23720grep -v '^ *+' $at_stder1 >$at_stderr
23721at_failed=false
23722echo stderr:; tee stderr <$at_stderr
23723$at_diff $at_devnull $at_stdout || at_failed=:
23724case $at_status in
23725   77) echo 77 > $at_status_file
23726            exit 77;;
23727   1) ;;
23728   *) echo "calc.at:564: exit code was $at_status, expected 1"
23729      at_failed=:;;
23730esac
23731if $at_failed; then
23732
23733  echo 1 > $at_status_file
23734  exit 1
23735fi
23736
23737$at_traceon
23738
23739
23740# Normalize the observed and expected error messages, depending upon the
23741# options.
23742# 1. Remove the traces from observed.
23743sed '/^Starting/d
23744/^Entering/d
23745/^Stack/d
23746/^Reading/d
23747/^Reducing/d
23748/^Shifting/d
23749/^state/d
23750/^Cleanup:/d
23751/^Error:/d
23752/^Next/d
23753/^Discarding/d
23754/ \$[0-9$]* = /d
23755/^yydestructor:/d' stderr >at-stderr
23756mv at-stderr stderr
23757# 2. Create the reference error message.
23758cat >expout <<'_ATEOF'
237591.6: syntax error, unexpected '='
23760_ATEOF
23761
23762# 3. If locations are not used, remove them.
23763sed 's/^[-0-9.]*: //' expout >at-expout
23764mv at-expout expout
23765# 4. If error-verbose is not used, strip the`, unexpected....' part.
23766sed 's/syntax error, .*$/syntax error/' expout >at-expout
23767mv at-expout expout
23768# 5. Check
23769$at_traceoff
23770echo "calc.at:564: cat stderr"
23771echo calc.at:564 >$at_check_line_file
23772( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
23773at_status=$?
23774grep '^ *+' $at_stder1 >&2
23775grep -v '^ *+' $at_stder1 >$at_stderr
23776at_failed=false
23777$at_diff $at_devnull $at_stderr || at_failed=:
23778$at_diff expout $at_stdout || at_failed=:
23779case $at_status in
23780   77) echo 77 > $at_status_file
23781            exit 77;;
23782   0) ;;
23783   *) echo "calc.at:564: exit code was $at_status, expected 0"
23784      at_failed=:;;
23785esac
23786if $at_failed; then
23787
23788  echo 1 > $at_status_file
23789  exit 1
23790fi
23791
23792$at_traceon
23793
23794
23795cat >input <<'_ATEOF'
23796
23797+1
23798_ATEOF
23799
23800$at_traceoff
23801echo "calc.at:564: \$PREPARSER ./calc input"
23802echo calc.at:564 >$at_check_line_file
23803( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
23804at_status=$?
23805grep '^ *+' $at_stder1 >&2
23806grep -v '^ *+' $at_stder1 >$at_stderr
23807at_failed=false
23808echo stderr:; tee stderr <$at_stderr
23809$at_diff $at_devnull $at_stdout || at_failed=:
23810case $at_status in
23811   77) echo 77 > $at_status_file
23812            exit 77;;
23813   1) ;;
23814   *) echo "calc.at:564: exit code was $at_status, expected 1"
23815      at_failed=:;;
23816esac
23817if $at_failed; then
23818
23819  echo 1 > $at_status_file
23820  exit 1
23821fi
23822
23823$at_traceon
23824
23825
23826# Normalize the observed and expected error messages, depending upon the
23827# options.
23828# 1. Remove the traces from observed.
23829sed '/^Starting/d
23830/^Entering/d
23831/^Stack/d
23832/^Reading/d
23833/^Reducing/d
23834/^Shifting/d
23835/^state/d
23836/^Cleanup:/d
23837/^Error:/d
23838/^Next/d
23839/^Discarding/d
23840/ \$[0-9$]* = /d
23841/^yydestructor:/d' stderr >at-stderr
23842mv at-stderr stderr
23843# 2. Create the reference error message.
23844cat >expout <<'_ATEOF'
238452.0: syntax error, unexpected '+'
23846_ATEOF
23847
23848# 3. If locations are not used, remove them.
23849sed 's/^[-0-9.]*: //' expout >at-expout
23850mv at-expout expout
23851# 4. If error-verbose is not used, strip the`, unexpected....' part.
23852sed 's/syntax error, .*$/syntax error/' expout >at-expout
23853mv at-expout expout
23854# 5. Check
23855$at_traceoff
23856echo "calc.at:564: cat stderr"
23857echo calc.at:564 >$at_check_line_file
23858( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
23859at_status=$?
23860grep '^ *+' $at_stder1 >&2
23861grep -v '^ *+' $at_stder1 >$at_stderr
23862at_failed=false
23863$at_diff $at_devnull $at_stderr || at_failed=:
23864$at_diff expout $at_stdout || at_failed=:
23865case $at_status in
23866   77) echo 77 > $at_status_file
23867            exit 77;;
23868   0) ;;
23869   *) echo "calc.at:564: exit code was $at_status, expected 0"
23870      at_failed=:;;
23871esac
23872if $at_failed; then
23873
23874  echo 1 > $at_status_file
23875  exit 1
23876fi
23877
23878$at_traceon
23879
23880
23881# Exercise error messages with EOF: work on an empty file.
23882$at_traceoff
23883echo "calc.at:564: \$PREPARSER ./calc /dev/null"
23884echo calc.at:564 >$at_check_line_file
23885( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
23886at_status=$?
23887grep '^ *+' $at_stder1 >&2
23888grep -v '^ *+' $at_stder1 >$at_stderr
23889at_failed=false
23890echo stderr:; tee stderr <$at_stderr
23891$at_diff $at_devnull $at_stdout || at_failed=:
23892case $at_status in
23893   77) echo 77 > $at_status_file
23894            exit 77;;
23895   1) ;;
23896   *) echo "calc.at:564: exit code was $at_status, expected 1"
23897      at_failed=:;;
23898esac
23899if $at_failed; then
23900
23901  echo 1 > $at_status_file
23902  exit 1
23903fi
23904
23905$at_traceon
23906
23907
23908# Normalize the observed and expected error messages, depending upon the
23909# options.
23910# 1. Remove the traces from observed.
23911sed '/^Starting/d
23912/^Entering/d
23913/^Stack/d
23914/^Reading/d
23915/^Reducing/d
23916/^Shifting/d
23917/^state/d
23918/^Cleanup:/d
23919/^Error:/d
23920/^Next/d
23921/^Discarding/d
23922/ \$[0-9$]* = /d
23923/^yydestructor:/d' stderr >at-stderr
23924mv at-stderr stderr
23925# 2. Create the reference error message.
23926cat >expout <<'_ATEOF'
239271.0: syntax error, unexpected end of input
23928_ATEOF
23929
23930# 3. If locations are not used, remove them.
23931sed 's/^[-0-9.]*: //' expout >at-expout
23932mv at-expout expout
23933# 4. If error-verbose is not used, strip the`, unexpected....' part.
23934sed 's/syntax error, .*$/syntax error/' expout >at-expout
23935mv at-expout expout
23936# 5. Check
23937$at_traceoff
23938echo "calc.at:564: cat stderr"
23939echo calc.at:564 >$at_check_line_file
23940( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
23941at_status=$?
23942grep '^ *+' $at_stder1 >&2
23943grep -v '^ *+' $at_stder1 >$at_stderr
23944at_failed=false
23945$at_diff $at_devnull $at_stderr || at_failed=:
23946$at_diff expout $at_stdout || at_failed=:
23947case $at_status in
23948   77) echo 77 > $at_status_file
23949            exit 77;;
23950   0) ;;
23951   *) echo "calc.at:564: exit code was $at_status, expected 0"
23952      at_failed=:;;
23953esac
23954if $at_failed; then
23955
23956  echo 1 > $at_status_file
23957  exit 1
23958fi
23959
23960$at_traceon
23961
23962
23963
23964# Exercise the error token: without it, we die at the first error,
23965# hence be sure to
23966#
23967# - have several errors which exercise different shift/discardings
23968#   - (): nothing to pop, nothing to discard
23969#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
23970#   - (* * *): nothing to pop, a lot to discard
23971#   - (1 + 2 * *): some to pop and discard
23972#
23973# - test the action associated to `error'
23974#
23975# - check the look-ahead that triggers an error is not discarded
23976#   when we enter error recovery.  Below, the look-ahead causing the
23977#   first error is ")", which is needed to recover from the error and
23978#   produce the "0" that triggers the "0 != 1" error.
23979#
23980cat >input <<'_ATEOF'
23981() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
23982_ATEOF
23983
23984$at_traceoff
23985echo "calc.at:564: \$PREPARSER ./calc input"
23986echo calc.at:564 >$at_check_line_file
23987( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
23988at_status=$?
23989grep '^ *+' $at_stder1 >&2
23990grep -v '^ *+' $at_stder1 >$at_stderr
23991at_failed=false
23992echo stderr:; tee stderr <$at_stderr
23993$at_diff $at_devnull $at_stdout || at_failed=:
23994case $at_status in
23995   77) echo 77 > $at_status_file
23996            exit 77;;
23997   0) ;;
23998   *) echo "calc.at:564: exit code was $at_status, expected 0"
23999      at_failed=:;;
24000esac
24001if $at_failed; then
24002
24003  echo 1 > $at_status_file
24004  exit 1
24005fi
24006
24007$at_traceon
24008
24009
24010# Normalize the observed and expected error messages, depending upon the
24011# options.
24012# 1. Remove the traces from observed.
24013sed '/^Starting/d
24014/^Entering/d
24015/^Stack/d
24016/^Reading/d
24017/^Reducing/d
24018/^Shifting/d
24019/^state/d
24020/^Cleanup:/d
24021/^Error:/d
24022/^Next/d
24023/^Discarding/d
24024/ \$[0-9$]* = /d
24025/^yydestructor:/d' stderr >at-stderr
24026mv at-stderr stderr
24027# 2. Create the reference error message.
24028cat >expout <<'_ATEOF'
240291.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
240301.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
240311.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
240321.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
24033calc: error: 4444 != 1
24034_ATEOF
24035
24036# 3. If locations are not used, remove them.
24037sed 's/^[-0-9.]*: //' expout >at-expout
24038mv at-expout expout
24039# 4. If error-verbose is not used, strip the`, unexpected....' part.
24040sed 's/syntax error, .*$/syntax error/' expout >at-expout
24041mv at-expout expout
24042# 5. Check
24043$at_traceoff
24044echo "calc.at:564: cat stderr"
24045echo calc.at:564 >$at_check_line_file
24046( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
24047at_status=$?
24048grep '^ *+' $at_stder1 >&2
24049grep -v '^ *+' $at_stder1 >$at_stderr
24050at_failed=false
24051$at_diff $at_devnull $at_stderr || at_failed=:
24052$at_diff expout $at_stdout || at_failed=:
24053case $at_status in
24054   77) echo 77 > $at_status_file
24055            exit 77;;
24056   0) ;;
24057   *) echo "calc.at:564: exit code was $at_status, expected 0"
24058      at_failed=:;;
24059esac
24060if $at_failed; then
24061
24062  echo 1 > $at_status_file
24063  exit 1
24064fi
24065
24066$at_traceon
24067
24068
24069
24070# The same, but this time exercising explicitly triggered syntax errors.
24071# POSIX says the look-ahead causing the error should not be discarded.
24072cat >input <<'_ATEOF'
24073(!) + (0 0) = 1
24074_ATEOF
24075
24076$at_traceoff
24077echo "calc.at:564: \$PREPARSER ./calc input"
24078echo calc.at:564 >$at_check_line_file
24079( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
24080at_status=$?
24081grep '^ *+' $at_stder1 >&2
24082grep -v '^ *+' $at_stder1 >$at_stderr
24083at_failed=false
24084echo stderr:; tee stderr <$at_stderr
24085$at_diff $at_devnull $at_stdout || at_failed=:
24086case $at_status in
24087   77) echo 77 > $at_status_file
24088            exit 77;;
24089   0) ;;
24090   *) echo "calc.at:564: exit code was $at_status, expected 0"
24091      at_failed=:;;
24092esac
24093if $at_failed; then
24094
24095  echo 1 > $at_status_file
24096  exit 1
24097fi
24098
24099$at_traceon
24100
24101
24102# Normalize the observed and expected error messages, depending upon the
24103# options.
24104# 1. Remove the traces from observed.
24105sed '/^Starting/d
24106/^Entering/d
24107/^Stack/d
24108/^Reading/d
24109/^Reducing/d
24110/^Shifting/d
24111/^state/d
24112/^Cleanup:/d
24113/^Error:/d
24114/^Next/d
24115/^Discarding/d
24116/ \$[0-9$]* = /d
24117/^yydestructor:/d' stderr >at-stderr
24118mv at-stderr stderr
24119# 2. Create the reference error message.
24120cat >expout <<'_ATEOF'
241211.9: syntax error, unexpected number
24122calc: error: 2222 != 1
24123_ATEOF
24124
24125# 3. If locations are not used, remove them.
24126sed 's/^[-0-9.]*: //' expout >at-expout
24127mv at-expout expout
24128# 4. If error-verbose is not used, strip the`, unexpected....' part.
24129sed 's/syntax error, .*$/syntax error/' expout >at-expout
24130mv at-expout expout
24131# 5. Check
24132$at_traceoff
24133echo "calc.at:564: cat stderr"
24134echo calc.at:564 >$at_check_line_file
24135( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
24136at_status=$?
24137grep '^ *+' $at_stder1 >&2
24138grep -v '^ *+' $at_stder1 >$at_stderr
24139at_failed=false
24140$at_diff $at_devnull $at_stderr || at_failed=:
24141$at_diff expout $at_stdout || at_failed=:
24142case $at_status in
24143   77) echo 77 > $at_status_file
24144            exit 77;;
24145   0) ;;
24146   *) echo "calc.at:564: exit code was $at_status, expected 0"
24147      at_failed=:;;
24148esac
24149if $at_failed; then
24150
24151  echo 1 > $at_status_file
24152  exit 1
24153fi
24154
24155$at_traceon
24156
24157
24158cat >input <<'_ATEOF'
24159(- *) + (0 0) = 1
24160_ATEOF
24161
24162$at_traceoff
24163echo "calc.at:564: \$PREPARSER ./calc input"
24164echo calc.at:564 >$at_check_line_file
24165( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
24166at_status=$?
24167grep '^ *+' $at_stder1 >&2
24168grep -v '^ *+' $at_stder1 >$at_stderr
24169at_failed=false
24170echo stderr:; tee stderr <$at_stderr
24171$at_diff $at_devnull $at_stdout || at_failed=:
24172case $at_status in
24173   77) echo 77 > $at_status_file
24174            exit 77;;
24175   0) ;;
24176   *) echo "calc.at:564: exit code was $at_status, expected 0"
24177      at_failed=:;;
24178esac
24179if $at_failed; then
24180
24181  echo 1 > $at_status_file
24182  exit 1
24183fi
24184
24185$at_traceon
24186
24187
24188# Normalize the observed and expected error messages, depending upon the
24189# options.
24190# 1. Remove the traces from observed.
24191sed '/^Starting/d
24192/^Entering/d
24193/^Stack/d
24194/^Reading/d
24195/^Reducing/d
24196/^Shifting/d
24197/^state/d
24198/^Cleanup:/d
24199/^Error:/d
24200/^Next/d
24201/^Discarding/d
24202/ \$[0-9$]* = /d
24203/^yydestructor:/d' stderr >at-stderr
24204mv at-stderr stderr
24205# 2. Create the reference error message.
24206cat >expout <<'_ATEOF'
242071.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
242081.11: syntax error, unexpected number
24209calc: error: 2222 != 1
24210_ATEOF
24211
24212# 3. If locations are not used, remove them.
24213sed 's/^[-0-9.]*: //' expout >at-expout
24214mv at-expout expout
24215# 4. If error-verbose is not used, strip the`, unexpected....' part.
24216sed 's/syntax error, .*$/syntax error/' expout >at-expout
24217mv at-expout expout
24218# 5. Check
24219$at_traceoff
24220echo "calc.at:564: cat stderr"
24221echo calc.at:564 >$at_check_line_file
24222( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
24223at_status=$?
24224grep '^ *+' $at_stder1 >&2
24225grep -v '^ *+' $at_stder1 >$at_stderr
24226at_failed=false
24227$at_diff $at_devnull $at_stderr || at_failed=:
24228$at_diff expout $at_stdout || at_failed=:
24229case $at_status in
24230   77) echo 77 > $at_status_file
24231            exit 77;;
24232   0) ;;
24233   *) echo "calc.at:564: exit code was $at_status, expected 0"
24234      at_failed=:;;
24235esac
24236if $at_failed; then
24237
24238  echo 1 > $at_status_file
24239  exit 1
24240fi
24241
24242$at_traceon
24243
24244
24245
24246
24247
24248
24249
24250
24251
24252
24253
24254
24255
24256
24257
24258
24259
24260
24261
24262
24263
24264
24265
24266
24267      $at_traceoff
24268      $at_times_p && times >$at_times_file
24269    ) 5>&1 2>&1 | eval $at_tee_pipe
24270    at_status=`cat $at_status_file`
24271    ;;
24272
24273  81 ) # 81. calc.at:565: Calculator %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
24274    at_setup_line='calc.at:565'
24275    at_desc='Calculator %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc'
24276    $at_quiet $ECHO_N " 81: Calculator %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc$ECHO_C"
24277    at_xfail=no
24278    (
24279      echo "81. calc.at:565: testing ..."
24280      $at_traceon
24281
24282
24283
24284
24285
24286
24287
24288
24289# Using yacc.c?
24290
24291
24292
24293
24294
24295
24296
24297# yyerror receives the location if %location & %pure & (%glr or %parse-param).
24298
24299# yyerror always sees the locations (when activated), except if
24300# yacc & pure & !param.
24301
24302
24303# The interface is pure: either because %pure-parser, or because we
24304# are using the C++ parsers.
24305
24306
24307
24308
24309
24310
24311
24312
24313
24314
24315
24316
24317cat >calc.y <<'_ATEOF'
24318%{
24319#ifdef HAVE_CONFIG_H
24320# include <config.h>
24321  /* We don't need perfect functions for these tests. */
24322# undef malloc
24323# undef memcmp
24324# undef realloc
24325#endif
24326%}
24327
24328/* Infix notation calculator--calc */
24329%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
24330
24331%{
24332#include <stdio.h>
24333
24334#include <stdlib.h>
24335#include <string.h>
24336#if HAVE_UNISTD_H
24337# include <unistd.h>
24338#else
24339# undef alarm
24340# define alarm(seconds) /* empty */
24341#endif
24342#include <ctype.h>
24343#define USE(Var)
24344
24345/* Exercise pre-prologue dependency to %union.  */
24346typedef int semantic_value;
24347
24348static semantic_value global_result = 0;
24349static int global_count = 0;
24350%}
24351
24352/* Exercise %union. */
24353%union
24354{
24355  semantic_value ival;
24356};
24357
24358%{
24359static int power (int base, int exponent);
24360/* yyerror receives the location if:
24361   - %location & %pure & %glr
24362   - %location & %pure & %yacc & %parse-param. */
24363static void yyerror (
24364
24365                     const char *s
24366                     );
24367static int yylex (void);
24368static int get_char (void);
24369static void unget_char ( int c);
24370%}
24371
24372
24373
24374/* Bison Declarations */
24375%token CALC_EOF 0 "end of input"
24376%token <ival> NUM "number"
24377%type  <ival> exp
24378
24379%nonassoc '=' /* comparison	       */
24380%left '-' '+'
24381%left '*' '/'
24382%left NEG     /* negation--unary minus */
24383%right '^'    /* exponentiation        */
24384
24385/* Grammar follows */
24386%%
24387input:
24388  line
24389| input line         {  }
24390;
24391
24392line:
24393  '\n'
24394| exp '\n'           { USE ($1); }
24395;
24396
24397exp:
24398  NUM                { $$ = $1;             }
24399| exp '=' exp
24400  {
24401    if ($1 != $3)
24402      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
24403    $$ = $1;
24404  }
24405| exp '+' exp        { $$ = $1 + $3;        }
24406| exp '-' exp        { $$ = $1 - $3;        }
24407| exp '*' exp        { $$ = $1 * $3;        }
24408| exp '/' exp        { $$ = $1 / $3;        }
24409| '-' exp  %prec NEG { $$ = -$2;            }
24410| exp '^' exp        { $$ = power ($1, $3); }
24411| '(' exp ')'        { $$ = $2;             }
24412| '(' error ')'      { $$ = 1111;           }
24413| '!'                { $$ = 0; YYERROR;     }
24414| '-' error          { $$ = 0; YYERROR;     }
24415;
24416%%
24417/* The input.  */
24418static FILE *input;
24419
24420static void
24421yyerror (
24422
24423         const char *s)
24424{
24425
24426
24427  fprintf (stderr, "%d.%d",
24428           (yylloc).first_line, (yylloc).first_column);
24429  if ((yylloc).first_line != (yylloc).last_line)
24430    fprintf (stderr, "-%d.%d",
24431	     (yylloc).last_line,  (yylloc).last_column - 1);
24432  else if ((yylloc).first_column != (yylloc).last_column - 1)
24433    fprintf (stderr, "-%d",
24434	     (yylloc).last_column - 1);
24435  fprintf (stderr, ": ");
24436  fprintf (stderr, "%s\n", s);
24437}
24438
24439
24440
24441static YYLTYPE last_yylloc;
24442
24443static int
24444get_char (void)
24445{
24446  int res = getc (input);
24447  ;
24448
24449  last_yylloc = (yylloc);
24450  if (res == '\n')
24451    {
24452      (yylloc).last_line++;
24453      (yylloc).last_column = 0;
24454    }
24455  else
24456    (yylloc).last_column++;
24457
24458  return res;
24459}
24460
24461
24462static void
24463unget_char ( int c)
24464{
24465  ;
24466
24467  /* Wrong when C == `\n'. */
24468  (yylloc) = last_yylloc;
24469
24470  ungetc (c, input);
24471}
24472
24473static int
24474read_signed_integer (void)
24475{
24476  int c = get_char ();
24477  int sign = 1;
24478  int n = 0;
24479
24480  ;
24481  if (c == '-')
24482    {
24483      c = get_char ();
24484      sign = -1;
24485    }
24486
24487  while (isdigit (c))
24488    {
24489      n = 10 * n + (c - '0');
24490      c = get_char ();
24491    }
24492
24493  unget_char ( c);
24494
24495  return sign * n;
24496}
24497
24498
24499
24500/*---------------------------------------------------------------.
24501| Lexical analyzer returns an integer on the stack and the token |
24502| NUM, or the ASCII character read if not a number.  Skips all   |
24503| blanks and tabs, returns 0 for EOF.                            |
24504`---------------------------------------------------------------*/
24505
24506static int
24507yylex (void)
24508{
24509  static int init = 1;
24510  int c;
24511
24512  if (init)
24513    {
24514      init = 0;
24515
24516      (yylloc).last_column = 0;
24517      (yylloc).last_line = 1;
24518
24519    }
24520
24521
24522 (yylloc).first_column = (yylloc).last_column;
24523  (yylloc).first_line   = (yylloc).last_line;
24524
24525
24526  /* Skip white space.  */
24527  while ((c = get_char ()) == ' ' || c == '\t')
24528    {
24529     (yylloc).first_column = (yylloc).last_column;
24530      (yylloc).first_line   = (yylloc).last_line;
24531
24532    }
24533
24534  /* process numbers   */
24535  if (c == '.' || isdigit (c))
24536    {
24537      unget_char ( c);
24538      (yylval).ival = read_signed_integer ();
24539      return NUM;
24540    }
24541
24542  /* Return end-of-file.  */
24543  if (c == EOF)
24544    return CALC_EOF;
24545
24546  /* Return single chars. */
24547  return c;
24548}
24549
24550static int
24551power (int base, int exponent)
24552{
24553  int res = 1;
24554  if (exponent < 0)
24555    exit (3);
24556  for (/* Niente */; exponent; --exponent)
24557    res *= base;
24558  return res;
24559}
24560
24561
24562int
24563main (int argc, const char **argv)
24564{
24565  semantic_value result = 0;
24566  int count = 0;
24567  int status;
24568
24569  /* This used to be alarm (10), but that isn't enough time for
24570     a July 1995 vintage DEC Alphastation 200 4/100 system,
24571     according to Nelson H. F. Beebe.  100 seconds is enough.  */
24572  alarm (100);
24573
24574  if (argc == 2)
24575    input = fopen (argv[1], "r");
24576  else
24577    input = stdin;
24578
24579  if (!input)
24580    {
24581      perror (argv[1]);
24582      return 3;
24583    }
24584
24585  yydebug = 1;
24586  status = yyparse ();
24587  if (global_result != result)
24588    abort ();
24589  if (global_count != count)
24590    abort ();
24591  return status;
24592}
24593_ATEOF
24594
24595
24596
24597
24598
24599$at_traceoff
24600echo "calc.at:565: bison -o calc.c calc.y"
24601echo calc.at:565 >$at_check_line_file
24602( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
24603at_status=$?
24604grep '^ *+' $at_stder1 >&2
24605grep -v '^ *+' $at_stder1 >$at_stderr
24606at_failed=false
24607$at_diff $at_devnull $at_stderr || at_failed=:
24608$at_diff $at_devnull $at_stdout || at_failed=:
24609case $at_status in
24610   77) echo 77 > $at_status_file
24611            exit 77;;
24612   0) ;;
24613   *) echo "calc.at:565: exit code was $at_status, expected 0"
24614      at_failed=:;;
24615esac
24616if $at_failed; then
24617
24618  echo 1 > $at_status_file
24619  exit 1
24620fi
24621
24622$at_traceon
24623
24624   $at_traceoff
24625echo "calc.at:565: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
24626echo calc.at:565 >$at_check_line_file
24627( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
24628at_status=$?
24629grep '^ *+' $at_stder1 >&2
24630grep -v '^ *+' $at_stder1 >$at_stderr
24631at_failed=false
24632echo stderr:; cat $at_stderr
24633echo stdout:; cat $at_stdout
24634case $at_status in
24635   77) echo 77 > $at_status_file
24636            exit 77;;
24637   0) ;;
24638   *) echo "calc.at:565: exit code was $at_status, expected 0"
24639      at_failed=:;;
24640esac
24641if $at_failed; then
24642
24643  echo 1 > $at_status_file
24644  exit 1
24645fi
24646
24647$at_traceon
24648
24649
24650# Test the priorities.
24651cat >input <<'_ATEOF'
246521 + 2 * 3 = 7
246531 + 2 * -3 = -5
24654
24655-1^2 = -1
24656(-1)^2 = 1
24657
24658---1 = -1
24659
246601 - 2 - 3 = -4
246611 - (2 - 3) = 2
24662
246632^2^3 = 256
24664(2^2)^3 = 64
24665_ATEOF
24666
24667$at_traceoff
24668echo "calc.at:565: \$PREPARSER ./calc input"
24669echo calc.at:565 >$at_check_line_file
24670( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
24671at_status=$?
24672grep '^ *+' $at_stder1 >&2
24673grep -v '^ *+' $at_stder1 >$at_stderr
24674at_failed=false
24675echo stderr:; tee stderr <$at_stderr
24676$at_diff $at_devnull $at_stdout || at_failed=:
24677case $at_status in
24678   77) echo 77 > $at_status_file
24679            exit 77;;
24680   0) ;;
24681   *) echo "calc.at:565: exit code was $at_status, expected 0"
24682      at_failed=:;;
24683esac
24684if $at_failed; then
24685
24686  echo 1 > $at_status_file
24687  exit 1
24688fi
24689
24690$at_traceon
24691
24692
24693
24694# Some syntax errors.
24695cat >input <<'_ATEOF'
246960 0
24697_ATEOF
24698
24699$at_traceoff
24700echo "calc.at:565: \$PREPARSER ./calc input"
24701echo calc.at:565 >$at_check_line_file
24702( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
24703at_status=$?
24704grep '^ *+' $at_stder1 >&2
24705grep -v '^ *+' $at_stder1 >$at_stderr
24706at_failed=false
24707echo stderr:; tee stderr <$at_stderr
24708$at_diff $at_devnull $at_stdout || at_failed=:
24709case $at_status in
24710   77) echo 77 > $at_status_file
24711            exit 77;;
24712   1) ;;
24713   *) echo "calc.at:565: exit code was $at_status, expected 1"
24714      at_failed=:;;
24715esac
24716if $at_failed; then
24717
24718  echo 1 > $at_status_file
24719  exit 1
24720fi
24721
24722$at_traceon
24723
24724
24725# Normalize the observed and expected error messages, depending upon the
24726# options.
24727# 1. Remove the traces from observed.
24728sed '/^Starting/d
24729/^Entering/d
24730/^Stack/d
24731/^Reading/d
24732/^Reducing/d
24733/^Shifting/d
24734/^state/d
24735/^Cleanup:/d
24736/^Error:/d
24737/^Next/d
24738/^Discarding/d
24739/ \$[0-9$]* = /d
24740/^yydestructor:/d' stderr >at-stderr
24741mv at-stderr stderr
24742# 2. Create the reference error message.
24743cat >expout <<'_ATEOF'
247441.2: syntax error, unexpected number
24745_ATEOF
24746
24747# 3. If locations are not used, remove them.
24748
24749# 4. If error-verbose is not used, strip the`, unexpected....' part.
24750
24751# 5. Check
24752$at_traceoff
24753echo "calc.at:565: cat stderr"
24754echo calc.at:565 >$at_check_line_file
24755( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
24756at_status=$?
24757grep '^ *+' $at_stder1 >&2
24758grep -v '^ *+' $at_stder1 >$at_stderr
24759at_failed=false
24760$at_diff $at_devnull $at_stderr || at_failed=:
24761$at_diff expout $at_stdout || at_failed=:
24762case $at_status in
24763   77) echo 77 > $at_status_file
24764            exit 77;;
24765   0) ;;
24766   *) echo "calc.at:565: exit code was $at_status, expected 0"
24767      at_failed=:;;
24768esac
24769if $at_failed; then
24770
24771  echo 1 > $at_status_file
24772  exit 1
24773fi
24774
24775$at_traceon
24776
24777
24778cat >input <<'_ATEOF'
247791//2
24780_ATEOF
24781
24782$at_traceoff
24783echo "calc.at:565: \$PREPARSER ./calc input"
24784echo calc.at:565 >$at_check_line_file
24785( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
24786at_status=$?
24787grep '^ *+' $at_stder1 >&2
24788grep -v '^ *+' $at_stder1 >$at_stderr
24789at_failed=false
24790echo stderr:; tee stderr <$at_stderr
24791$at_diff $at_devnull $at_stdout || at_failed=:
24792case $at_status in
24793   77) echo 77 > $at_status_file
24794            exit 77;;
24795   1) ;;
24796   *) echo "calc.at:565: exit code was $at_status, expected 1"
24797      at_failed=:;;
24798esac
24799if $at_failed; then
24800
24801  echo 1 > $at_status_file
24802  exit 1
24803fi
24804
24805$at_traceon
24806
24807
24808# Normalize the observed and expected error messages, depending upon the
24809# options.
24810# 1. Remove the traces from observed.
24811sed '/^Starting/d
24812/^Entering/d
24813/^Stack/d
24814/^Reading/d
24815/^Reducing/d
24816/^Shifting/d
24817/^state/d
24818/^Cleanup:/d
24819/^Error:/d
24820/^Next/d
24821/^Discarding/d
24822/ \$[0-9$]* = /d
24823/^yydestructor:/d' stderr >at-stderr
24824mv at-stderr stderr
24825# 2. Create the reference error message.
24826cat >expout <<'_ATEOF'
248271.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
24828_ATEOF
24829
24830# 3. If locations are not used, remove them.
24831
24832# 4. If error-verbose is not used, strip the`, unexpected....' part.
24833
24834# 5. Check
24835$at_traceoff
24836echo "calc.at:565: cat stderr"
24837echo calc.at:565 >$at_check_line_file
24838( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
24839at_status=$?
24840grep '^ *+' $at_stder1 >&2
24841grep -v '^ *+' $at_stder1 >$at_stderr
24842at_failed=false
24843$at_diff $at_devnull $at_stderr || at_failed=:
24844$at_diff expout $at_stdout || at_failed=:
24845case $at_status in
24846   77) echo 77 > $at_status_file
24847            exit 77;;
24848   0) ;;
24849   *) echo "calc.at:565: exit code was $at_status, expected 0"
24850      at_failed=:;;
24851esac
24852if $at_failed; then
24853
24854  echo 1 > $at_status_file
24855  exit 1
24856fi
24857
24858$at_traceon
24859
24860
24861cat >input <<'_ATEOF'
24862error
24863_ATEOF
24864
24865$at_traceoff
24866echo "calc.at:565: \$PREPARSER ./calc input"
24867echo calc.at:565 >$at_check_line_file
24868( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
24869at_status=$?
24870grep '^ *+' $at_stder1 >&2
24871grep -v '^ *+' $at_stder1 >$at_stderr
24872at_failed=false
24873echo stderr:; tee stderr <$at_stderr
24874$at_diff $at_devnull $at_stdout || at_failed=:
24875case $at_status in
24876   77) echo 77 > $at_status_file
24877            exit 77;;
24878   1) ;;
24879   *) echo "calc.at:565: exit code was $at_status, expected 1"
24880      at_failed=:;;
24881esac
24882if $at_failed; then
24883
24884  echo 1 > $at_status_file
24885  exit 1
24886fi
24887
24888$at_traceon
24889
24890
24891# Normalize the observed and expected error messages, depending upon the
24892# options.
24893# 1. Remove the traces from observed.
24894sed '/^Starting/d
24895/^Entering/d
24896/^Stack/d
24897/^Reading/d
24898/^Reducing/d
24899/^Shifting/d
24900/^state/d
24901/^Cleanup:/d
24902/^Error:/d
24903/^Next/d
24904/^Discarding/d
24905/ \$[0-9$]* = /d
24906/^yydestructor:/d' stderr >at-stderr
24907mv at-stderr stderr
24908# 2. Create the reference error message.
24909cat >expout <<'_ATEOF'
249101.0: syntax error, unexpected $undefined
24911_ATEOF
24912
24913# 3. If locations are not used, remove them.
24914
24915# 4. If error-verbose is not used, strip the`, unexpected....' part.
24916
24917# 5. Check
24918$at_traceoff
24919echo "calc.at:565: cat stderr"
24920echo calc.at:565 >$at_check_line_file
24921( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
24922at_status=$?
24923grep '^ *+' $at_stder1 >&2
24924grep -v '^ *+' $at_stder1 >$at_stderr
24925at_failed=false
24926$at_diff $at_devnull $at_stderr || at_failed=:
24927$at_diff expout $at_stdout || at_failed=:
24928case $at_status in
24929   77) echo 77 > $at_status_file
24930            exit 77;;
24931   0) ;;
24932   *) echo "calc.at:565: exit code was $at_status, expected 0"
24933      at_failed=:;;
24934esac
24935if $at_failed; then
24936
24937  echo 1 > $at_status_file
24938  exit 1
24939fi
24940
24941$at_traceon
24942
24943
24944cat >input <<'_ATEOF'
249451 = 2 = 3
24946_ATEOF
24947
24948$at_traceoff
24949echo "calc.at:565: \$PREPARSER ./calc input"
24950echo calc.at:565 >$at_check_line_file
24951( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
24952at_status=$?
24953grep '^ *+' $at_stder1 >&2
24954grep -v '^ *+' $at_stder1 >$at_stderr
24955at_failed=false
24956echo stderr:; tee stderr <$at_stderr
24957$at_diff $at_devnull $at_stdout || at_failed=:
24958case $at_status in
24959   77) echo 77 > $at_status_file
24960            exit 77;;
24961   1) ;;
24962   *) echo "calc.at:565: exit code was $at_status, expected 1"
24963      at_failed=:;;
24964esac
24965if $at_failed; then
24966
24967  echo 1 > $at_status_file
24968  exit 1
24969fi
24970
24971$at_traceon
24972
24973
24974# Normalize the observed and expected error messages, depending upon the
24975# options.
24976# 1. Remove the traces from observed.
24977sed '/^Starting/d
24978/^Entering/d
24979/^Stack/d
24980/^Reading/d
24981/^Reducing/d
24982/^Shifting/d
24983/^state/d
24984/^Cleanup:/d
24985/^Error:/d
24986/^Next/d
24987/^Discarding/d
24988/ \$[0-9$]* = /d
24989/^yydestructor:/d' stderr >at-stderr
24990mv at-stderr stderr
24991# 2. Create the reference error message.
24992cat >expout <<'_ATEOF'
249931.6: syntax error, unexpected '='
24994_ATEOF
24995
24996# 3. If locations are not used, remove them.
24997
24998# 4. If error-verbose is not used, strip the`, unexpected....' part.
24999
25000# 5. Check
25001$at_traceoff
25002echo "calc.at:565: cat stderr"
25003echo calc.at:565 >$at_check_line_file
25004( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
25005at_status=$?
25006grep '^ *+' $at_stder1 >&2
25007grep -v '^ *+' $at_stder1 >$at_stderr
25008at_failed=false
25009$at_diff $at_devnull $at_stderr || at_failed=:
25010$at_diff expout $at_stdout || at_failed=:
25011case $at_status in
25012   77) echo 77 > $at_status_file
25013            exit 77;;
25014   0) ;;
25015   *) echo "calc.at:565: exit code was $at_status, expected 0"
25016      at_failed=:;;
25017esac
25018if $at_failed; then
25019
25020  echo 1 > $at_status_file
25021  exit 1
25022fi
25023
25024$at_traceon
25025
25026
25027cat >input <<'_ATEOF'
25028
25029+1
25030_ATEOF
25031
25032$at_traceoff
25033echo "calc.at:565: \$PREPARSER ./calc input"
25034echo calc.at:565 >$at_check_line_file
25035( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
25036at_status=$?
25037grep '^ *+' $at_stder1 >&2
25038grep -v '^ *+' $at_stder1 >$at_stderr
25039at_failed=false
25040echo stderr:; tee stderr <$at_stderr
25041$at_diff $at_devnull $at_stdout || at_failed=:
25042case $at_status in
25043   77) echo 77 > $at_status_file
25044            exit 77;;
25045   1) ;;
25046   *) echo "calc.at:565: exit code was $at_status, expected 1"
25047      at_failed=:;;
25048esac
25049if $at_failed; then
25050
25051  echo 1 > $at_status_file
25052  exit 1
25053fi
25054
25055$at_traceon
25056
25057
25058# Normalize the observed and expected error messages, depending upon the
25059# options.
25060# 1. Remove the traces from observed.
25061sed '/^Starting/d
25062/^Entering/d
25063/^Stack/d
25064/^Reading/d
25065/^Reducing/d
25066/^Shifting/d
25067/^state/d
25068/^Cleanup:/d
25069/^Error:/d
25070/^Next/d
25071/^Discarding/d
25072/ \$[0-9$]* = /d
25073/^yydestructor:/d' stderr >at-stderr
25074mv at-stderr stderr
25075# 2. Create the reference error message.
25076cat >expout <<'_ATEOF'
250772.0: syntax error, unexpected '+'
25078_ATEOF
25079
25080# 3. If locations are not used, remove them.
25081
25082# 4. If error-verbose is not used, strip the`, unexpected....' part.
25083
25084# 5. Check
25085$at_traceoff
25086echo "calc.at:565: cat stderr"
25087echo calc.at:565 >$at_check_line_file
25088( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
25089at_status=$?
25090grep '^ *+' $at_stder1 >&2
25091grep -v '^ *+' $at_stder1 >$at_stderr
25092at_failed=false
25093$at_diff $at_devnull $at_stderr || at_failed=:
25094$at_diff expout $at_stdout || at_failed=:
25095case $at_status in
25096   77) echo 77 > $at_status_file
25097            exit 77;;
25098   0) ;;
25099   *) echo "calc.at:565: exit code was $at_status, expected 0"
25100      at_failed=:;;
25101esac
25102if $at_failed; then
25103
25104  echo 1 > $at_status_file
25105  exit 1
25106fi
25107
25108$at_traceon
25109
25110
25111# Exercise error messages with EOF: work on an empty file.
25112$at_traceoff
25113echo "calc.at:565: \$PREPARSER ./calc /dev/null"
25114echo calc.at:565 >$at_check_line_file
25115( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
25116at_status=$?
25117grep '^ *+' $at_stder1 >&2
25118grep -v '^ *+' $at_stder1 >$at_stderr
25119at_failed=false
25120echo stderr:; tee stderr <$at_stderr
25121$at_diff $at_devnull $at_stdout || at_failed=:
25122case $at_status in
25123   77) echo 77 > $at_status_file
25124            exit 77;;
25125   1) ;;
25126   *) echo "calc.at:565: exit code was $at_status, expected 1"
25127      at_failed=:;;
25128esac
25129if $at_failed; then
25130
25131  echo 1 > $at_status_file
25132  exit 1
25133fi
25134
25135$at_traceon
25136
25137
25138# Normalize the observed and expected error messages, depending upon the
25139# options.
25140# 1. Remove the traces from observed.
25141sed '/^Starting/d
25142/^Entering/d
25143/^Stack/d
25144/^Reading/d
25145/^Reducing/d
25146/^Shifting/d
25147/^state/d
25148/^Cleanup:/d
25149/^Error:/d
25150/^Next/d
25151/^Discarding/d
25152/ \$[0-9$]* = /d
25153/^yydestructor:/d' stderr >at-stderr
25154mv at-stderr stderr
25155# 2. Create the reference error message.
25156cat >expout <<'_ATEOF'
251571.0: syntax error, unexpected end of input
25158_ATEOF
25159
25160# 3. If locations are not used, remove them.
25161
25162# 4. If error-verbose is not used, strip the`, unexpected....' part.
25163
25164# 5. Check
25165$at_traceoff
25166echo "calc.at:565: cat stderr"
25167echo calc.at:565 >$at_check_line_file
25168( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
25169at_status=$?
25170grep '^ *+' $at_stder1 >&2
25171grep -v '^ *+' $at_stder1 >$at_stderr
25172at_failed=false
25173$at_diff $at_devnull $at_stderr || at_failed=:
25174$at_diff expout $at_stdout || at_failed=:
25175case $at_status in
25176   77) echo 77 > $at_status_file
25177            exit 77;;
25178   0) ;;
25179   *) echo "calc.at:565: exit code was $at_status, expected 0"
25180      at_failed=:;;
25181esac
25182if $at_failed; then
25183
25184  echo 1 > $at_status_file
25185  exit 1
25186fi
25187
25188$at_traceon
25189
25190
25191
25192# Exercise the error token: without it, we die at the first error,
25193# hence be sure to
25194#
25195# - have several errors which exercise different shift/discardings
25196#   - (): nothing to pop, nothing to discard
25197#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
25198#   - (* * *): nothing to pop, a lot to discard
25199#   - (1 + 2 * *): some to pop and discard
25200#
25201# - test the action associated to `error'
25202#
25203# - check the look-ahead that triggers an error is not discarded
25204#   when we enter error recovery.  Below, the look-ahead causing the
25205#   first error is ")", which is needed to recover from the error and
25206#   produce the "0" that triggers the "0 != 1" error.
25207#
25208cat >input <<'_ATEOF'
25209() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
25210_ATEOF
25211
25212$at_traceoff
25213echo "calc.at:565: \$PREPARSER ./calc input"
25214echo calc.at:565 >$at_check_line_file
25215( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
25216at_status=$?
25217grep '^ *+' $at_stder1 >&2
25218grep -v '^ *+' $at_stder1 >$at_stderr
25219at_failed=false
25220echo stderr:; tee stderr <$at_stderr
25221$at_diff $at_devnull $at_stdout || at_failed=:
25222case $at_status in
25223   77) echo 77 > $at_status_file
25224            exit 77;;
25225   0) ;;
25226   *) echo "calc.at:565: exit code was $at_status, expected 0"
25227      at_failed=:;;
25228esac
25229if $at_failed; then
25230
25231  echo 1 > $at_status_file
25232  exit 1
25233fi
25234
25235$at_traceon
25236
25237
25238# Normalize the observed and expected error messages, depending upon the
25239# options.
25240# 1. Remove the traces from observed.
25241sed '/^Starting/d
25242/^Entering/d
25243/^Stack/d
25244/^Reading/d
25245/^Reducing/d
25246/^Shifting/d
25247/^state/d
25248/^Cleanup:/d
25249/^Error:/d
25250/^Next/d
25251/^Discarding/d
25252/ \$[0-9$]* = /d
25253/^yydestructor:/d' stderr >at-stderr
25254mv at-stderr stderr
25255# 2. Create the reference error message.
25256cat >expout <<'_ATEOF'
252571.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
252581.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
252591.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
252601.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
25261calc: error: 4444 != 1
25262_ATEOF
25263
25264# 3. If locations are not used, remove them.
25265
25266# 4. If error-verbose is not used, strip the`, unexpected....' part.
25267
25268# 5. Check
25269$at_traceoff
25270echo "calc.at:565: cat stderr"
25271echo calc.at:565 >$at_check_line_file
25272( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
25273at_status=$?
25274grep '^ *+' $at_stder1 >&2
25275grep -v '^ *+' $at_stder1 >$at_stderr
25276at_failed=false
25277$at_diff $at_devnull $at_stderr || at_failed=:
25278$at_diff expout $at_stdout || at_failed=:
25279case $at_status in
25280   77) echo 77 > $at_status_file
25281            exit 77;;
25282   0) ;;
25283   *) echo "calc.at:565: exit code was $at_status, expected 0"
25284      at_failed=:;;
25285esac
25286if $at_failed; then
25287
25288  echo 1 > $at_status_file
25289  exit 1
25290fi
25291
25292$at_traceon
25293
25294
25295
25296# The same, but this time exercising explicitly triggered syntax errors.
25297# POSIX says the look-ahead causing the error should not be discarded.
25298cat >input <<'_ATEOF'
25299(!) + (0 0) = 1
25300_ATEOF
25301
25302$at_traceoff
25303echo "calc.at:565: \$PREPARSER ./calc input"
25304echo calc.at:565 >$at_check_line_file
25305( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
25306at_status=$?
25307grep '^ *+' $at_stder1 >&2
25308grep -v '^ *+' $at_stder1 >$at_stderr
25309at_failed=false
25310echo stderr:; tee stderr <$at_stderr
25311$at_diff $at_devnull $at_stdout || at_failed=:
25312case $at_status in
25313   77) echo 77 > $at_status_file
25314            exit 77;;
25315   0) ;;
25316   *) echo "calc.at:565: exit code was $at_status, expected 0"
25317      at_failed=:;;
25318esac
25319if $at_failed; then
25320
25321  echo 1 > $at_status_file
25322  exit 1
25323fi
25324
25325$at_traceon
25326
25327
25328# Normalize the observed and expected error messages, depending upon the
25329# options.
25330# 1. Remove the traces from observed.
25331sed '/^Starting/d
25332/^Entering/d
25333/^Stack/d
25334/^Reading/d
25335/^Reducing/d
25336/^Shifting/d
25337/^state/d
25338/^Cleanup:/d
25339/^Error:/d
25340/^Next/d
25341/^Discarding/d
25342/ \$[0-9$]* = /d
25343/^yydestructor:/d' stderr >at-stderr
25344mv at-stderr stderr
25345# 2. Create the reference error message.
25346cat >expout <<'_ATEOF'
253471.9: syntax error, unexpected number
25348calc: error: 2222 != 1
25349_ATEOF
25350
25351# 3. If locations are not used, remove them.
25352
25353# 4. If error-verbose is not used, strip the`, unexpected....' part.
25354
25355# 5. Check
25356$at_traceoff
25357echo "calc.at:565: cat stderr"
25358echo calc.at:565 >$at_check_line_file
25359( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
25360at_status=$?
25361grep '^ *+' $at_stder1 >&2
25362grep -v '^ *+' $at_stder1 >$at_stderr
25363at_failed=false
25364$at_diff $at_devnull $at_stderr || at_failed=:
25365$at_diff expout $at_stdout || at_failed=:
25366case $at_status in
25367   77) echo 77 > $at_status_file
25368            exit 77;;
25369   0) ;;
25370   *) echo "calc.at:565: exit code was $at_status, expected 0"
25371      at_failed=:;;
25372esac
25373if $at_failed; then
25374
25375  echo 1 > $at_status_file
25376  exit 1
25377fi
25378
25379$at_traceon
25380
25381
25382cat >input <<'_ATEOF'
25383(- *) + (0 0) = 1
25384_ATEOF
25385
25386$at_traceoff
25387echo "calc.at:565: \$PREPARSER ./calc input"
25388echo calc.at:565 >$at_check_line_file
25389( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
25390at_status=$?
25391grep '^ *+' $at_stder1 >&2
25392grep -v '^ *+' $at_stder1 >$at_stderr
25393at_failed=false
25394echo stderr:; tee stderr <$at_stderr
25395$at_diff $at_devnull $at_stdout || at_failed=:
25396case $at_status in
25397   77) echo 77 > $at_status_file
25398            exit 77;;
25399   0) ;;
25400   *) echo "calc.at:565: exit code was $at_status, expected 0"
25401      at_failed=:;;
25402esac
25403if $at_failed; then
25404
25405  echo 1 > $at_status_file
25406  exit 1
25407fi
25408
25409$at_traceon
25410
25411
25412# Normalize the observed and expected error messages, depending upon the
25413# options.
25414# 1. Remove the traces from observed.
25415sed '/^Starting/d
25416/^Entering/d
25417/^Stack/d
25418/^Reading/d
25419/^Reducing/d
25420/^Shifting/d
25421/^state/d
25422/^Cleanup:/d
25423/^Error:/d
25424/^Next/d
25425/^Discarding/d
25426/ \$[0-9$]* = /d
25427/^yydestructor:/d' stderr >at-stderr
25428mv at-stderr stderr
25429# 2. Create the reference error message.
25430cat >expout <<'_ATEOF'
254311.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
254321.11: syntax error, unexpected number
25433calc: error: 2222 != 1
25434_ATEOF
25435
25436# 3. If locations are not used, remove them.
25437
25438# 4. If error-verbose is not used, strip the`, unexpected....' part.
25439
25440# 5. Check
25441$at_traceoff
25442echo "calc.at:565: cat stderr"
25443echo calc.at:565 >$at_check_line_file
25444( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
25445at_status=$?
25446grep '^ *+' $at_stder1 >&2
25447grep -v '^ *+' $at_stder1 >$at_stderr
25448at_failed=false
25449$at_diff $at_devnull $at_stderr || at_failed=:
25450$at_diff expout $at_stdout || at_failed=:
25451case $at_status in
25452   77) echo 77 > $at_status_file
25453            exit 77;;
25454   0) ;;
25455   *) echo "calc.at:565: exit code was $at_status, expected 0"
25456      at_failed=:;;
25457esac
25458if $at_failed; then
25459
25460  echo 1 > $at_status_file
25461  exit 1
25462fi
25463
25464$at_traceon
25465
25466
25467
25468
25469
25470
25471
25472
25473
25474
25475
25476
25477
25478
25479
25480
25481
25482
25483
25484
25485
25486
25487
25488
25489      $at_traceoff
25490      $at_times_p && times >$at_times_file
25491    ) 5>&1 2>&1 | eval $at_tee_pipe
25492    at_status=`cat $at_status_file`
25493    ;;
25494
25495  82 ) # 82. calc.at:567: Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
25496    at_setup_line='calc.at:567'
25497    at_desc='Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc'
25498    $at_quiet $ECHO_N " 82: Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc$ECHO_C"
25499    at_xfail=no
25500    (
25501      echo "82. calc.at:567: testing ..."
25502      $at_traceon
25503
25504
25505
25506
25507
25508
25509
25510
25511# Using yacc.c?
25512
25513
25514
25515
25516
25517
25518
25519# yyerror receives the location if %location & %pure & (%glr or %parse-param).
25520
25521# yyerror always sees the locations (when activated), except if
25522# yacc & pure & !param.
25523
25524
25525# The interface is pure: either because %pure-parser, or because we
25526# are using the C++ parsers.
25527
25528
25529
25530
25531
25532
25533
25534
25535
25536
25537
25538
25539cat >calc.y <<'_ATEOF'
25540%{
25541#ifdef HAVE_CONFIG_H
25542# include <config.h>
25543  /* We don't need perfect functions for these tests. */
25544# undef malloc
25545# undef memcmp
25546# undef realloc
25547#endif
25548%}
25549
25550/* Infix notation calculator--calc */
25551%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
25552
25553%{
25554#include <stdio.h>
25555
25556#include <stdlib.h>
25557#include <string.h>
25558#if HAVE_UNISTD_H
25559# include <unistd.h>
25560#else
25561# undef alarm
25562# define alarm(seconds) /* empty */
25563#endif
25564#include <ctype.h>
25565#define USE(Var)
25566
25567/* Exercise pre-prologue dependency to %union.  */
25568typedef int semantic_value;
25569
25570static semantic_value global_result = 0;
25571static int global_count = 0;
25572%}
25573
25574/* Exercise %union. */
25575%union
25576{
25577  semantic_value ival;
25578};
25579
25580%{
25581static int power (int base, int exponent);
25582/* yyerror receives the location if:
25583   - %location & %pure & %glr
25584   - %location & %pure & %yacc & %parse-param. */
25585static void yyerror (
25586
25587                     const char *s
25588                     );
25589static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
25590static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp);
25591static void unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c);
25592%}
25593
25594
25595
25596/* Bison Declarations */
25597%token CALC_EOF 0 "end of input"
25598%token <ival> NUM "number"
25599%type  <ival> exp
25600
25601%nonassoc '=' /* comparison	       */
25602%left '-' '+'
25603%left '*' '/'
25604%left NEG     /* negation--unary minus */
25605%right '^'    /* exponentiation        */
25606
25607/* Grammar follows */
25608%%
25609input:
25610  line
25611| input line         {  }
25612;
25613
25614line:
25615  '\n'
25616| exp '\n'           { USE ($1); }
25617;
25618
25619exp:
25620  NUM                { $$ = $1;             }
25621| exp '=' exp
25622  {
25623    if ($1 != $3)
25624      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
25625    $$ = $1;
25626  }
25627| exp '+' exp        { $$ = $1 + $3;        }
25628| exp '-' exp        { $$ = $1 - $3;        }
25629| exp '*' exp        { $$ = $1 * $3;        }
25630| exp '/' exp        { $$ = $1 / $3;        }
25631| '-' exp  %prec NEG { $$ = -$2;            }
25632| exp '^' exp        { $$ = power ($1, $3); }
25633| '(' exp ')'        { $$ = $2;             }
25634| '(' error ')'      { $$ = 1111;           }
25635| '!'                { $$ = 0; YYERROR;     }
25636| '-' error          { $$ = 0; YYERROR;     }
25637;
25638%%
25639/* The input.  */
25640static FILE *input;
25641
25642static void
25643yyerror (
25644
25645         const char *s)
25646{
25647
25648
25649  fprintf (stderr, "%s\n", s);
25650}
25651
25652
25653
25654static YYLTYPE last_yylloc;
25655
25656static int
25657get_char (YYSTYPE *lvalp, YYLTYPE *llocp)
25658{
25659  int res = getc (input);
25660  (void) lvalp;(void) llocp;
25661
25662  last_yylloc = (*llocp);
25663  if (res == '\n')
25664    {
25665      (*llocp).last_line++;
25666      (*llocp).last_column = 0;
25667    }
25668  else
25669    (*llocp).last_column++;
25670
25671  return res;
25672}
25673
25674
25675static void
25676unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c)
25677{
25678  (void) lvalp;(void) llocp;
25679
25680  /* Wrong when C == `\n'. */
25681  (*llocp) = last_yylloc;
25682
25683  ungetc (c, input);
25684}
25685
25686static int
25687read_signed_integer (YYSTYPE *lvalp, YYLTYPE *llocp)
25688{
25689  int c = get_char (lvalp, llocp);
25690  int sign = 1;
25691  int n = 0;
25692
25693  (void) lvalp;(void) llocp;
25694  if (c == '-')
25695    {
25696      c = get_char (lvalp, llocp);
25697      sign = -1;
25698    }
25699
25700  while (isdigit (c))
25701    {
25702      n = 10 * n + (c - '0');
25703      c = get_char (lvalp, llocp);
25704    }
25705
25706  unget_char (lvalp, llocp,  c);
25707
25708  return sign * n;
25709}
25710
25711
25712
25713/*---------------------------------------------------------------.
25714| Lexical analyzer returns an integer on the stack and the token |
25715| NUM, or the ASCII character read if not a number.  Skips all   |
25716| blanks and tabs, returns 0 for EOF.                            |
25717`---------------------------------------------------------------*/
25718
25719static int
25720yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
25721{
25722  static int init = 1;
25723  int c;
25724
25725  if (init)
25726    {
25727      init = 0;
25728
25729      (*llocp).last_column = 0;
25730      (*llocp).last_line = 1;
25731
25732    }
25733
25734
25735 (*llocp).first_column = (*llocp).last_column;
25736  (*llocp).first_line   = (*llocp).last_line;
25737
25738
25739  /* Skip white space.  */
25740  while ((c = get_char (lvalp, llocp)) == ' ' || c == '\t')
25741    {
25742     (*llocp).first_column = (*llocp).last_column;
25743      (*llocp).first_line   = (*llocp).last_line;
25744
25745    }
25746
25747  /* process numbers   */
25748  if (c == '.' || isdigit (c))
25749    {
25750      unget_char (lvalp, llocp,  c);
25751      (*lvalp).ival = read_signed_integer (lvalp, llocp);
25752      return NUM;
25753    }
25754
25755  /* Return end-of-file.  */
25756  if (c == EOF)
25757    return CALC_EOF;
25758
25759  /* Return single chars. */
25760  return c;
25761}
25762
25763static int
25764power (int base, int exponent)
25765{
25766  int res = 1;
25767  if (exponent < 0)
25768    exit (3);
25769  for (/* Niente */; exponent; --exponent)
25770    res *= base;
25771  return res;
25772}
25773
25774
25775int
25776main (int argc, const char **argv)
25777{
25778  semantic_value result = 0;
25779  int count = 0;
25780  int status;
25781
25782  /* This used to be alarm (10), but that isn't enough time for
25783     a July 1995 vintage DEC Alphastation 200 4/100 system,
25784     according to Nelson H. F. Beebe.  100 seconds is enough.  */
25785  alarm (100);
25786
25787  if (argc == 2)
25788    input = fopen (argv[1], "r");
25789  else
25790    input = stdin;
25791
25792  if (!input)
25793    {
25794      perror (argv[1]);
25795      return 3;
25796    }
25797
25798  yydebug = 1;
25799  status = yyparse ();
25800  if (global_result != result)
25801    abort ();
25802  if (global_count != count)
25803    abort ();
25804  return status;
25805}
25806_ATEOF
25807
25808
25809
25810
25811
25812$at_traceoff
25813echo "calc.at:567: bison -o calc.c calc.y"
25814echo calc.at:567 >$at_check_line_file
25815( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
25816at_status=$?
25817grep '^ *+' $at_stder1 >&2
25818grep -v '^ *+' $at_stder1 >$at_stderr
25819at_failed=false
25820$at_diff $at_devnull $at_stderr || at_failed=:
25821$at_diff $at_devnull $at_stdout || at_failed=:
25822case $at_status in
25823   77) echo 77 > $at_status_file
25824            exit 77;;
25825   0) ;;
25826   *) echo "calc.at:567: exit code was $at_status, expected 0"
25827      at_failed=:;;
25828esac
25829if $at_failed; then
25830
25831  echo 1 > $at_status_file
25832  exit 1
25833fi
25834
25835$at_traceon
25836
25837   $at_traceoff
25838echo "calc.at:567: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
25839echo calc.at:567 >$at_check_line_file
25840( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
25841at_status=$?
25842grep '^ *+' $at_stder1 >&2
25843grep -v '^ *+' $at_stder1 >$at_stderr
25844at_failed=false
25845echo stderr:; cat $at_stderr
25846echo stdout:; cat $at_stdout
25847case $at_status in
25848   77) echo 77 > $at_status_file
25849            exit 77;;
25850   0) ;;
25851   *) echo "calc.at:567: exit code was $at_status, expected 0"
25852      at_failed=:;;
25853esac
25854if $at_failed; then
25855
25856  echo 1 > $at_status_file
25857  exit 1
25858fi
25859
25860$at_traceon
25861
25862
25863# Test the priorities.
25864cat >input <<'_ATEOF'
258651 + 2 * 3 = 7
258661 + 2 * -3 = -5
25867
25868-1^2 = -1
25869(-1)^2 = 1
25870
25871---1 = -1
25872
258731 - 2 - 3 = -4
258741 - (2 - 3) = 2
25875
258762^2^3 = 256
25877(2^2)^3 = 64
25878_ATEOF
25879
25880$at_traceoff
25881echo "calc.at:567: \$PREPARSER ./calc input"
25882echo calc.at:567 >$at_check_line_file
25883( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
25884at_status=$?
25885grep '^ *+' $at_stder1 >&2
25886grep -v '^ *+' $at_stder1 >$at_stderr
25887at_failed=false
25888echo stderr:; tee stderr <$at_stderr
25889$at_diff $at_devnull $at_stdout || at_failed=:
25890case $at_status in
25891   77) echo 77 > $at_status_file
25892            exit 77;;
25893   0) ;;
25894   *) echo "calc.at:567: exit code was $at_status, expected 0"
25895      at_failed=:;;
25896esac
25897if $at_failed; then
25898
25899  echo 1 > $at_status_file
25900  exit 1
25901fi
25902
25903$at_traceon
25904
25905
25906
25907# Some syntax errors.
25908cat >input <<'_ATEOF'
259090 0
25910_ATEOF
25911
25912$at_traceoff
25913echo "calc.at:567: \$PREPARSER ./calc input"
25914echo calc.at:567 >$at_check_line_file
25915( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
25916at_status=$?
25917grep '^ *+' $at_stder1 >&2
25918grep -v '^ *+' $at_stder1 >$at_stderr
25919at_failed=false
25920echo stderr:; tee stderr <$at_stderr
25921$at_diff $at_devnull $at_stdout || at_failed=:
25922case $at_status in
25923   77) echo 77 > $at_status_file
25924            exit 77;;
25925   1) ;;
25926   *) echo "calc.at:567: exit code was $at_status, expected 1"
25927      at_failed=:;;
25928esac
25929if $at_failed; then
25930
25931  echo 1 > $at_status_file
25932  exit 1
25933fi
25934
25935$at_traceon
25936
25937
25938# Normalize the observed and expected error messages, depending upon the
25939# options.
25940# 1. Remove the traces from observed.
25941sed '/^Starting/d
25942/^Entering/d
25943/^Stack/d
25944/^Reading/d
25945/^Reducing/d
25946/^Shifting/d
25947/^state/d
25948/^Cleanup:/d
25949/^Error:/d
25950/^Next/d
25951/^Discarding/d
25952/ \$[0-9$]* = /d
25953/^yydestructor:/d' stderr >at-stderr
25954mv at-stderr stderr
25955# 2. Create the reference error message.
25956cat >expout <<'_ATEOF'
259571.2: syntax error, unexpected number
25958_ATEOF
25959
25960# 3. If locations are not used, remove them.
25961sed 's/^[-0-9.]*: //' expout >at-expout
25962mv at-expout expout
25963# 4. If error-verbose is not used, strip the`, unexpected....' part.
25964
25965# 5. Check
25966$at_traceoff
25967echo "calc.at:567: cat stderr"
25968echo calc.at:567 >$at_check_line_file
25969( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
25970at_status=$?
25971grep '^ *+' $at_stder1 >&2
25972grep -v '^ *+' $at_stder1 >$at_stderr
25973at_failed=false
25974$at_diff $at_devnull $at_stderr || at_failed=:
25975$at_diff expout $at_stdout || at_failed=:
25976case $at_status in
25977   77) echo 77 > $at_status_file
25978            exit 77;;
25979   0) ;;
25980   *) echo "calc.at:567: exit code was $at_status, expected 0"
25981      at_failed=:;;
25982esac
25983if $at_failed; then
25984
25985  echo 1 > $at_status_file
25986  exit 1
25987fi
25988
25989$at_traceon
25990
25991
25992cat >input <<'_ATEOF'
259931//2
25994_ATEOF
25995
25996$at_traceoff
25997echo "calc.at:567: \$PREPARSER ./calc input"
25998echo calc.at:567 >$at_check_line_file
25999( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
26000at_status=$?
26001grep '^ *+' $at_stder1 >&2
26002grep -v '^ *+' $at_stder1 >$at_stderr
26003at_failed=false
26004echo stderr:; tee stderr <$at_stderr
26005$at_diff $at_devnull $at_stdout || at_failed=:
26006case $at_status in
26007   77) echo 77 > $at_status_file
26008            exit 77;;
26009   1) ;;
26010   *) echo "calc.at:567: exit code was $at_status, expected 1"
26011      at_failed=:;;
26012esac
26013if $at_failed; then
26014
26015  echo 1 > $at_status_file
26016  exit 1
26017fi
26018
26019$at_traceon
26020
26021
26022# Normalize the observed and expected error messages, depending upon the
26023# options.
26024# 1. Remove the traces from observed.
26025sed '/^Starting/d
26026/^Entering/d
26027/^Stack/d
26028/^Reading/d
26029/^Reducing/d
26030/^Shifting/d
26031/^state/d
26032/^Cleanup:/d
26033/^Error:/d
26034/^Next/d
26035/^Discarding/d
26036/ \$[0-9$]* = /d
26037/^yydestructor:/d' stderr >at-stderr
26038mv at-stderr stderr
26039# 2. Create the reference error message.
26040cat >expout <<'_ATEOF'
260411.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
26042_ATEOF
26043
26044# 3. If locations are not used, remove them.
26045sed 's/^[-0-9.]*: //' expout >at-expout
26046mv at-expout expout
26047# 4. If error-verbose is not used, strip the`, unexpected....' part.
26048
26049# 5. Check
26050$at_traceoff
26051echo "calc.at:567: cat stderr"
26052echo calc.at:567 >$at_check_line_file
26053( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
26054at_status=$?
26055grep '^ *+' $at_stder1 >&2
26056grep -v '^ *+' $at_stder1 >$at_stderr
26057at_failed=false
26058$at_diff $at_devnull $at_stderr || at_failed=:
26059$at_diff expout $at_stdout || at_failed=:
26060case $at_status in
26061   77) echo 77 > $at_status_file
26062            exit 77;;
26063   0) ;;
26064   *) echo "calc.at:567: exit code was $at_status, expected 0"
26065      at_failed=:;;
26066esac
26067if $at_failed; then
26068
26069  echo 1 > $at_status_file
26070  exit 1
26071fi
26072
26073$at_traceon
26074
26075
26076cat >input <<'_ATEOF'
26077error
26078_ATEOF
26079
26080$at_traceoff
26081echo "calc.at:567: \$PREPARSER ./calc input"
26082echo calc.at:567 >$at_check_line_file
26083( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
26084at_status=$?
26085grep '^ *+' $at_stder1 >&2
26086grep -v '^ *+' $at_stder1 >$at_stderr
26087at_failed=false
26088echo stderr:; tee stderr <$at_stderr
26089$at_diff $at_devnull $at_stdout || at_failed=:
26090case $at_status in
26091   77) echo 77 > $at_status_file
26092            exit 77;;
26093   1) ;;
26094   *) echo "calc.at:567: exit code was $at_status, expected 1"
26095      at_failed=:;;
26096esac
26097if $at_failed; then
26098
26099  echo 1 > $at_status_file
26100  exit 1
26101fi
26102
26103$at_traceon
26104
26105
26106# Normalize the observed and expected error messages, depending upon the
26107# options.
26108# 1. Remove the traces from observed.
26109sed '/^Starting/d
26110/^Entering/d
26111/^Stack/d
26112/^Reading/d
26113/^Reducing/d
26114/^Shifting/d
26115/^state/d
26116/^Cleanup:/d
26117/^Error:/d
26118/^Next/d
26119/^Discarding/d
26120/ \$[0-9$]* = /d
26121/^yydestructor:/d' stderr >at-stderr
26122mv at-stderr stderr
26123# 2. Create the reference error message.
26124cat >expout <<'_ATEOF'
261251.0: syntax error, unexpected $undefined
26126_ATEOF
26127
26128# 3. If locations are not used, remove them.
26129sed 's/^[-0-9.]*: //' expout >at-expout
26130mv at-expout expout
26131# 4. If error-verbose is not used, strip the`, unexpected....' part.
26132
26133# 5. Check
26134$at_traceoff
26135echo "calc.at:567: cat stderr"
26136echo calc.at:567 >$at_check_line_file
26137( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
26138at_status=$?
26139grep '^ *+' $at_stder1 >&2
26140grep -v '^ *+' $at_stder1 >$at_stderr
26141at_failed=false
26142$at_diff $at_devnull $at_stderr || at_failed=:
26143$at_diff expout $at_stdout || at_failed=:
26144case $at_status in
26145   77) echo 77 > $at_status_file
26146            exit 77;;
26147   0) ;;
26148   *) echo "calc.at:567: exit code was $at_status, expected 0"
26149      at_failed=:;;
26150esac
26151if $at_failed; then
26152
26153  echo 1 > $at_status_file
26154  exit 1
26155fi
26156
26157$at_traceon
26158
26159
26160cat >input <<'_ATEOF'
261611 = 2 = 3
26162_ATEOF
26163
26164$at_traceoff
26165echo "calc.at:567: \$PREPARSER ./calc input"
26166echo calc.at:567 >$at_check_line_file
26167( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
26168at_status=$?
26169grep '^ *+' $at_stder1 >&2
26170grep -v '^ *+' $at_stder1 >$at_stderr
26171at_failed=false
26172echo stderr:; tee stderr <$at_stderr
26173$at_diff $at_devnull $at_stdout || at_failed=:
26174case $at_status in
26175   77) echo 77 > $at_status_file
26176            exit 77;;
26177   1) ;;
26178   *) echo "calc.at:567: exit code was $at_status, expected 1"
26179      at_failed=:;;
26180esac
26181if $at_failed; then
26182
26183  echo 1 > $at_status_file
26184  exit 1
26185fi
26186
26187$at_traceon
26188
26189
26190# Normalize the observed and expected error messages, depending upon the
26191# options.
26192# 1. Remove the traces from observed.
26193sed '/^Starting/d
26194/^Entering/d
26195/^Stack/d
26196/^Reading/d
26197/^Reducing/d
26198/^Shifting/d
26199/^state/d
26200/^Cleanup:/d
26201/^Error:/d
26202/^Next/d
26203/^Discarding/d
26204/ \$[0-9$]* = /d
26205/^yydestructor:/d' stderr >at-stderr
26206mv at-stderr stderr
26207# 2. Create the reference error message.
26208cat >expout <<'_ATEOF'
262091.6: syntax error, unexpected '='
26210_ATEOF
26211
26212# 3. If locations are not used, remove them.
26213sed 's/^[-0-9.]*: //' expout >at-expout
26214mv at-expout expout
26215# 4. If error-verbose is not used, strip the`, unexpected....' part.
26216
26217# 5. Check
26218$at_traceoff
26219echo "calc.at:567: cat stderr"
26220echo calc.at:567 >$at_check_line_file
26221( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
26222at_status=$?
26223grep '^ *+' $at_stder1 >&2
26224grep -v '^ *+' $at_stder1 >$at_stderr
26225at_failed=false
26226$at_diff $at_devnull $at_stderr || at_failed=:
26227$at_diff expout $at_stdout || at_failed=:
26228case $at_status in
26229   77) echo 77 > $at_status_file
26230            exit 77;;
26231   0) ;;
26232   *) echo "calc.at:567: exit code was $at_status, expected 0"
26233      at_failed=:;;
26234esac
26235if $at_failed; then
26236
26237  echo 1 > $at_status_file
26238  exit 1
26239fi
26240
26241$at_traceon
26242
26243
26244cat >input <<'_ATEOF'
26245
26246+1
26247_ATEOF
26248
26249$at_traceoff
26250echo "calc.at:567: \$PREPARSER ./calc input"
26251echo calc.at:567 >$at_check_line_file
26252( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
26253at_status=$?
26254grep '^ *+' $at_stder1 >&2
26255grep -v '^ *+' $at_stder1 >$at_stderr
26256at_failed=false
26257echo stderr:; tee stderr <$at_stderr
26258$at_diff $at_devnull $at_stdout || at_failed=:
26259case $at_status in
26260   77) echo 77 > $at_status_file
26261            exit 77;;
26262   1) ;;
26263   *) echo "calc.at:567: exit code was $at_status, expected 1"
26264      at_failed=:;;
26265esac
26266if $at_failed; then
26267
26268  echo 1 > $at_status_file
26269  exit 1
26270fi
26271
26272$at_traceon
26273
26274
26275# Normalize the observed and expected error messages, depending upon the
26276# options.
26277# 1. Remove the traces from observed.
26278sed '/^Starting/d
26279/^Entering/d
26280/^Stack/d
26281/^Reading/d
26282/^Reducing/d
26283/^Shifting/d
26284/^state/d
26285/^Cleanup:/d
26286/^Error:/d
26287/^Next/d
26288/^Discarding/d
26289/ \$[0-9$]* = /d
26290/^yydestructor:/d' stderr >at-stderr
26291mv at-stderr stderr
26292# 2. Create the reference error message.
26293cat >expout <<'_ATEOF'
262942.0: syntax error, unexpected '+'
26295_ATEOF
26296
26297# 3. If locations are not used, remove them.
26298sed 's/^[-0-9.]*: //' expout >at-expout
26299mv at-expout expout
26300# 4. If error-verbose is not used, strip the`, unexpected....' part.
26301
26302# 5. Check
26303$at_traceoff
26304echo "calc.at:567: cat stderr"
26305echo calc.at:567 >$at_check_line_file
26306( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
26307at_status=$?
26308grep '^ *+' $at_stder1 >&2
26309grep -v '^ *+' $at_stder1 >$at_stderr
26310at_failed=false
26311$at_diff $at_devnull $at_stderr || at_failed=:
26312$at_diff expout $at_stdout || at_failed=:
26313case $at_status in
26314   77) echo 77 > $at_status_file
26315            exit 77;;
26316   0) ;;
26317   *) echo "calc.at:567: exit code was $at_status, expected 0"
26318      at_failed=:;;
26319esac
26320if $at_failed; then
26321
26322  echo 1 > $at_status_file
26323  exit 1
26324fi
26325
26326$at_traceon
26327
26328
26329# Exercise error messages with EOF: work on an empty file.
26330$at_traceoff
26331echo "calc.at:567: \$PREPARSER ./calc /dev/null"
26332echo calc.at:567 >$at_check_line_file
26333( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
26334at_status=$?
26335grep '^ *+' $at_stder1 >&2
26336grep -v '^ *+' $at_stder1 >$at_stderr
26337at_failed=false
26338echo stderr:; tee stderr <$at_stderr
26339$at_diff $at_devnull $at_stdout || at_failed=:
26340case $at_status in
26341   77) echo 77 > $at_status_file
26342            exit 77;;
26343   1) ;;
26344   *) echo "calc.at:567: exit code was $at_status, expected 1"
26345      at_failed=:;;
26346esac
26347if $at_failed; then
26348
26349  echo 1 > $at_status_file
26350  exit 1
26351fi
26352
26353$at_traceon
26354
26355
26356# Normalize the observed and expected error messages, depending upon the
26357# options.
26358# 1. Remove the traces from observed.
26359sed '/^Starting/d
26360/^Entering/d
26361/^Stack/d
26362/^Reading/d
26363/^Reducing/d
26364/^Shifting/d
26365/^state/d
26366/^Cleanup:/d
26367/^Error:/d
26368/^Next/d
26369/^Discarding/d
26370/ \$[0-9$]* = /d
26371/^yydestructor:/d' stderr >at-stderr
26372mv at-stderr stderr
26373# 2. Create the reference error message.
26374cat >expout <<'_ATEOF'
263751.0: syntax error, unexpected end of input
26376_ATEOF
26377
26378# 3. If locations are not used, remove them.
26379sed 's/^[-0-9.]*: //' expout >at-expout
26380mv at-expout expout
26381# 4. If error-verbose is not used, strip the`, unexpected....' part.
26382
26383# 5. Check
26384$at_traceoff
26385echo "calc.at:567: cat stderr"
26386echo calc.at:567 >$at_check_line_file
26387( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
26388at_status=$?
26389grep '^ *+' $at_stder1 >&2
26390grep -v '^ *+' $at_stder1 >$at_stderr
26391at_failed=false
26392$at_diff $at_devnull $at_stderr || at_failed=:
26393$at_diff expout $at_stdout || at_failed=:
26394case $at_status in
26395   77) echo 77 > $at_status_file
26396            exit 77;;
26397   0) ;;
26398   *) echo "calc.at:567: exit code was $at_status, expected 0"
26399      at_failed=:;;
26400esac
26401if $at_failed; then
26402
26403  echo 1 > $at_status_file
26404  exit 1
26405fi
26406
26407$at_traceon
26408
26409
26410
26411# Exercise the error token: without it, we die at the first error,
26412# hence be sure to
26413#
26414# - have several errors which exercise different shift/discardings
26415#   - (): nothing to pop, nothing to discard
26416#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
26417#   - (* * *): nothing to pop, a lot to discard
26418#   - (1 + 2 * *): some to pop and discard
26419#
26420# - test the action associated to `error'
26421#
26422# - check the look-ahead that triggers an error is not discarded
26423#   when we enter error recovery.  Below, the look-ahead causing the
26424#   first error is ")", which is needed to recover from the error and
26425#   produce the "0" that triggers the "0 != 1" error.
26426#
26427cat >input <<'_ATEOF'
26428() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
26429_ATEOF
26430
26431$at_traceoff
26432echo "calc.at:567: \$PREPARSER ./calc input"
26433echo calc.at:567 >$at_check_line_file
26434( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
26435at_status=$?
26436grep '^ *+' $at_stder1 >&2
26437grep -v '^ *+' $at_stder1 >$at_stderr
26438at_failed=false
26439echo stderr:; tee stderr <$at_stderr
26440$at_diff $at_devnull $at_stdout || at_failed=:
26441case $at_status in
26442   77) echo 77 > $at_status_file
26443            exit 77;;
26444   0) ;;
26445   *) echo "calc.at:567: exit code was $at_status, expected 0"
26446      at_failed=:;;
26447esac
26448if $at_failed; then
26449
26450  echo 1 > $at_status_file
26451  exit 1
26452fi
26453
26454$at_traceon
26455
26456
26457# Normalize the observed and expected error messages, depending upon the
26458# options.
26459# 1. Remove the traces from observed.
26460sed '/^Starting/d
26461/^Entering/d
26462/^Stack/d
26463/^Reading/d
26464/^Reducing/d
26465/^Shifting/d
26466/^state/d
26467/^Cleanup:/d
26468/^Error:/d
26469/^Next/d
26470/^Discarding/d
26471/ \$[0-9$]* = /d
26472/^yydestructor:/d' stderr >at-stderr
26473mv at-stderr stderr
26474# 2. Create the reference error message.
26475cat >expout <<'_ATEOF'
264761.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
264771.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
264781.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
264791.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
26480calc: error: 4444 != 1
26481_ATEOF
26482
26483# 3. If locations are not used, remove them.
26484sed 's/^[-0-9.]*: //' expout >at-expout
26485mv at-expout expout
26486# 4. If error-verbose is not used, strip the`, unexpected....' part.
26487
26488# 5. Check
26489$at_traceoff
26490echo "calc.at:567: cat stderr"
26491echo calc.at:567 >$at_check_line_file
26492( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
26493at_status=$?
26494grep '^ *+' $at_stder1 >&2
26495grep -v '^ *+' $at_stder1 >$at_stderr
26496at_failed=false
26497$at_diff $at_devnull $at_stderr || at_failed=:
26498$at_diff expout $at_stdout || at_failed=:
26499case $at_status in
26500   77) echo 77 > $at_status_file
26501            exit 77;;
26502   0) ;;
26503   *) echo "calc.at:567: exit code was $at_status, expected 0"
26504      at_failed=:;;
26505esac
26506if $at_failed; then
26507
26508  echo 1 > $at_status_file
26509  exit 1
26510fi
26511
26512$at_traceon
26513
26514
26515
26516# The same, but this time exercising explicitly triggered syntax errors.
26517# POSIX says the look-ahead causing the error should not be discarded.
26518cat >input <<'_ATEOF'
26519(!) + (0 0) = 1
26520_ATEOF
26521
26522$at_traceoff
26523echo "calc.at:567: \$PREPARSER ./calc input"
26524echo calc.at:567 >$at_check_line_file
26525( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
26526at_status=$?
26527grep '^ *+' $at_stder1 >&2
26528grep -v '^ *+' $at_stder1 >$at_stderr
26529at_failed=false
26530echo stderr:; tee stderr <$at_stderr
26531$at_diff $at_devnull $at_stdout || at_failed=:
26532case $at_status in
26533   77) echo 77 > $at_status_file
26534            exit 77;;
26535   0) ;;
26536   *) echo "calc.at:567: exit code was $at_status, expected 0"
26537      at_failed=:;;
26538esac
26539if $at_failed; then
26540
26541  echo 1 > $at_status_file
26542  exit 1
26543fi
26544
26545$at_traceon
26546
26547
26548# Normalize the observed and expected error messages, depending upon the
26549# options.
26550# 1. Remove the traces from observed.
26551sed '/^Starting/d
26552/^Entering/d
26553/^Stack/d
26554/^Reading/d
26555/^Reducing/d
26556/^Shifting/d
26557/^state/d
26558/^Cleanup:/d
26559/^Error:/d
26560/^Next/d
26561/^Discarding/d
26562/ \$[0-9$]* = /d
26563/^yydestructor:/d' stderr >at-stderr
26564mv at-stderr stderr
26565# 2. Create the reference error message.
26566cat >expout <<'_ATEOF'
265671.9: syntax error, unexpected number
26568calc: error: 2222 != 1
26569_ATEOF
26570
26571# 3. If locations are not used, remove them.
26572sed 's/^[-0-9.]*: //' expout >at-expout
26573mv at-expout expout
26574# 4. If error-verbose is not used, strip the`, unexpected....' part.
26575
26576# 5. Check
26577$at_traceoff
26578echo "calc.at:567: cat stderr"
26579echo calc.at:567 >$at_check_line_file
26580( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
26581at_status=$?
26582grep '^ *+' $at_stder1 >&2
26583grep -v '^ *+' $at_stder1 >$at_stderr
26584at_failed=false
26585$at_diff $at_devnull $at_stderr || at_failed=:
26586$at_diff expout $at_stdout || at_failed=:
26587case $at_status in
26588   77) echo 77 > $at_status_file
26589            exit 77;;
26590   0) ;;
26591   *) echo "calc.at:567: exit code was $at_status, expected 0"
26592      at_failed=:;;
26593esac
26594if $at_failed; then
26595
26596  echo 1 > $at_status_file
26597  exit 1
26598fi
26599
26600$at_traceon
26601
26602
26603cat >input <<'_ATEOF'
26604(- *) + (0 0) = 1
26605_ATEOF
26606
26607$at_traceoff
26608echo "calc.at:567: \$PREPARSER ./calc input"
26609echo calc.at:567 >$at_check_line_file
26610( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
26611at_status=$?
26612grep '^ *+' $at_stder1 >&2
26613grep -v '^ *+' $at_stder1 >$at_stderr
26614at_failed=false
26615echo stderr:; tee stderr <$at_stderr
26616$at_diff $at_devnull $at_stdout || at_failed=:
26617case $at_status in
26618   77) echo 77 > $at_status_file
26619            exit 77;;
26620   0) ;;
26621   *) echo "calc.at:567: exit code was $at_status, expected 0"
26622      at_failed=:;;
26623esac
26624if $at_failed; then
26625
26626  echo 1 > $at_status_file
26627  exit 1
26628fi
26629
26630$at_traceon
26631
26632
26633# Normalize the observed and expected error messages, depending upon the
26634# options.
26635# 1. Remove the traces from observed.
26636sed '/^Starting/d
26637/^Entering/d
26638/^Stack/d
26639/^Reading/d
26640/^Reducing/d
26641/^Shifting/d
26642/^state/d
26643/^Cleanup:/d
26644/^Error:/d
26645/^Next/d
26646/^Discarding/d
26647/ \$[0-9$]* = /d
26648/^yydestructor:/d' stderr >at-stderr
26649mv at-stderr stderr
26650# 2. Create the reference error message.
26651cat >expout <<'_ATEOF'
266521.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
266531.11: syntax error, unexpected number
26654calc: error: 2222 != 1
26655_ATEOF
26656
26657# 3. If locations are not used, remove them.
26658sed 's/^[-0-9.]*: //' expout >at-expout
26659mv at-expout expout
26660# 4. If error-verbose is not used, strip the`, unexpected....' part.
26661
26662# 5. Check
26663$at_traceoff
26664echo "calc.at:567: cat stderr"
26665echo calc.at:567 >$at_check_line_file
26666( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
26667at_status=$?
26668grep '^ *+' $at_stder1 >&2
26669grep -v '^ *+' $at_stder1 >$at_stderr
26670at_failed=false
26671$at_diff $at_devnull $at_stderr || at_failed=:
26672$at_diff expout $at_stdout || at_failed=:
26673case $at_status in
26674   77) echo 77 > $at_status_file
26675            exit 77;;
26676   0) ;;
26677   *) echo "calc.at:567: exit code was $at_status, expected 0"
26678      at_failed=:;;
26679esac
26680if $at_failed; then
26681
26682  echo 1 > $at_status_file
26683  exit 1
26684fi
26685
26686$at_traceon
26687
26688
26689
26690
26691
26692
26693
26694
26695
26696
26697
26698
26699
26700
26701
26702
26703
26704
26705
26706
26707
26708
26709
26710
26711      $at_traceoff
26712      $at_times_p && times >$at_times_file
26713    ) 5>&1 2>&1 | eval $at_tee_pipe
26714    at_status=`cat $at_status_file`
26715    ;;
26716
26717  83 ) # 83. calc.at:569: Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}
26718    at_setup_line='calc.at:569'
26719    at_desc='Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}'
26720    $at_quiet $ECHO_N " 83: Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}$ECHO_C"
26721    at_xfail=no
26722    (
26723      echo "83. calc.at:569: testing ..."
26724      $at_traceon
26725
26726
26727
26728
26729
26730
26731
26732
26733# Using yacc.c?
26734
26735
26736
26737
26738
26739
26740
26741# yyerror receives the location if %location & %pure & (%glr or %parse-param).
26742
26743# yyerror always sees the locations (when activated), except if
26744# yacc & pure & !param.
26745
26746
26747# The interface is pure: either because %pure-parser, or because we
26748# are using the C++ parsers.
26749
26750
26751
26752
26753
26754
26755
26756
26757
26758
26759
26760
26761cat >calc.y <<'_ATEOF'
26762%{
26763#ifdef HAVE_CONFIG_H
26764# include <config.h>
26765  /* We don't need perfect functions for these tests. */
26766# undef malloc
26767# undef memcmp
26768# undef realloc
26769#endif
26770%}
26771
26772/* Infix notation calculator--calc */
26773%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}
26774
26775%{
26776#include <stdio.h>
26777
26778#include <stdlib.h>
26779#include <string.h>
26780#if HAVE_UNISTD_H
26781# include <unistd.h>
26782#else
26783# undef alarm
26784# define alarm(seconds) /* empty */
26785#endif
26786#include <ctype.h>
26787#define USE(Var)
26788
26789/* Exercise pre-prologue dependency to %union.  */
26790typedef int semantic_value;
26791
26792static semantic_value global_result = 0;
26793static int global_count = 0;
26794%}
26795
26796/* Exercise %union. */
26797%union
26798{
26799  semantic_value ival;
26800};
26801
26802%{
26803static int power (int base, int exponent);
26804/* yyerror receives the location if:
26805   - %location & %pure & %glr
26806   - %location & %pure & %yacc & %parse-param. */
26807static void yyerror (YYLTYPE *llocp,
26808                     semantic_value *result, int *count,
26809                     const char *s
26810                     );
26811static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
26812static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp);
26813static void unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c);
26814%}
26815
26816
26817
26818/* Bison Declarations */
26819%token CALC_EOF 0 "end of input"
26820%token <ival> NUM "number"
26821%type  <ival> exp
26822
26823%nonassoc '=' /* comparison	       */
26824%left '-' '+'
26825%left '*' '/'
26826%left NEG     /* negation--unary minus */
26827%right '^'    /* exponentiation        */
26828
26829/* Grammar follows */
26830%%
26831input:
26832  line
26833| input line         { ++*count; ++global_count; }
26834;
26835
26836line:
26837  '\n'
26838| exp '\n'           { *result = global_result = $1; }
26839;
26840
26841exp:
26842  NUM                { $$ = $1;             }
26843| exp '=' exp
26844  {
26845    if ($1 != $3)
26846      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
26847    $$ = $1;
26848  }
26849| exp '+' exp        { $$ = $1 + $3;        }
26850| exp '-' exp        { $$ = $1 - $3;        }
26851| exp '*' exp        { $$ = $1 * $3;        }
26852| exp '/' exp        { $$ = $1 / $3;        }
26853| '-' exp  %prec NEG { $$ = -$2;            }
26854| exp '^' exp        { $$ = power ($1, $3); }
26855| '(' exp ')'        { $$ = $2;             }
26856| '(' error ')'      { $$ = 1111;           }
26857| '!'                { $$ = 0; YYERROR;     }
26858| '-' error          { $$ = 0; YYERROR;     }
26859;
26860%%
26861/* The input.  */
26862static FILE *input;
26863
26864static void
26865yyerror (YYLTYPE *llocp,
26866         semantic_value *result, int *count,
26867         const char *s)
26868{
26869(void) result; (void) count;
26870
26871  fprintf (stderr, "%d.%d",
26872           (*llocp).first_line, (*llocp).first_column);
26873  if ((*llocp).first_line != (*llocp).last_line)
26874    fprintf (stderr, "-%d.%d",
26875	     (*llocp).last_line,  (*llocp).last_column - 1);
26876  else if ((*llocp).first_column != (*llocp).last_column - 1)
26877    fprintf (stderr, "-%d",
26878	     (*llocp).last_column - 1);
26879  fprintf (stderr, ": ");
26880  fprintf (stderr, "%s\n", s);
26881}
26882
26883
26884
26885static YYLTYPE last_yylloc;
26886
26887static int
26888get_char (YYSTYPE *lvalp, YYLTYPE *llocp)
26889{
26890  int res = getc (input);
26891  (void) lvalp;(void) llocp;
26892
26893  last_yylloc = (*llocp);
26894  if (res == '\n')
26895    {
26896      (*llocp).last_line++;
26897      (*llocp).last_column = 0;
26898    }
26899  else
26900    (*llocp).last_column++;
26901
26902  return res;
26903}
26904
26905
26906static void
26907unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c)
26908{
26909  (void) lvalp;(void) llocp;
26910
26911  /* Wrong when C == `\n'. */
26912  (*llocp) = last_yylloc;
26913
26914  ungetc (c, input);
26915}
26916
26917static int
26918read_signed_integer (YYSTYPE *lvalp, YYLTYPE *llocp)
26919{
26920  int c = get_char (lvalp, llocp);
26921  int sign = 1;
26922  int n = 0;
26923
26924  (void) lvalp;(void) llocp;
26925  if (c == '-')
26926    {
26927      c = get_char (lvalp, llocp);
26928      sign = -1;
26929    }
26930
26931  while (isdigit (c))
26932    {
26933      n = 10 * n + (c - '0');
26934      c = get_char (lvalp, llocp);
26935    }
26936
26937  unget_char (lvalp, llocp,  c);
26938
26939  return sign * n;
26940}
26941
26942
26943
26944/*---------------------------------------------------------------.
26945| Lexical analyzer returns an integer on the stack and the token |
26946| NUM, or the ASCII character read if not a number.  Skips all   |
26947| blanks and tabs, returns 0 for EOF.                            |
26948`---------------------------------------------------------------*/
26949
26950static int
26951yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
26952{
26953  static int init = 1;
26954  int c;
26955
26956  if (init)
26957    {
26958      init = 0;
26959
26960      (*llocp).last_column = 0;
26961      (*llocp).last_line = 1;
26962
26963    }
26964
26965
26966 (*llocp).first_column = (*llocp).last_column;
26967  (*llocp).first_line   = (*llocp).last_line;
26968
26969
26970  /* Skip white space.  */
26971  while ((c = get_char (lvalp, llocp)) == ' ' || c == '\t')
26972    {
26973     (*llocp).first_column = (*llocp).last_column;
26974      (*llocp).first_line   = (*llocp).last_line;
26975
26976    }
26977
26978  /* process numbers   */
26979  if (c == '.' || isdigit (c))
26980    {
26981      unget_char (lvalp, llocp,  c);
26982      (*lvalp).ival = read_signed_integer (lvalp, llocp);
26983      return NUM;
26984    }
26985
26986  /* Return end-of-file.  */
26987  if (c == EOF)
26988    return CALC_EOF;
26989
26990  /* Return single chars. */
26991  return c;
26992}
26993
26994static int
26995power (int base, int exponent)
26996{
26997  int res = 1;
26998  if (exponent < 0)
26999    exit (3);
27000  for (/* Niente */; exponent; --exponent)
27001    res *= base;
27002  return res;
27003}
27004
27005
27006int
27007main (int argc, const char **argv)
27008{
27009  semantic_value result = 0;
27010  int count = 0;
27011  int status;
27012
27013  /* This used to be alarm (10), but that isn't enough time for
27014     a July 1995 vintage DEC Alphastation 200 4/100 system,
27015     according to Nelson H. F. Beebe.  100 seconds is enough.  */
27016  alarm (100);
27017
27018  if (argc == 2)
27019    input = fopen (argv[1], "r");
27020  else
27021    input = stdin;
27022
27023  if (!input)
27024    {
27025      perror (argv[1]);
27026      return 3;
27027    }
27028
27029  yydebug = 1;
27030  status = yyparse (&result, &count);
27031  if (global_result != result)
27032    abort ();
27033  if (global_count != count)
27034    abort ();
27035  return status;
27036}
27037_ATEOF
27038
27039
27040
27041
27042
27043$at_traceoff
27044echo "calc.at:569: bison -o calc.c calc.y"
27045echo calc.at:569 >$at_check_line_file
27046( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
27047at_status=$?
27048grep '^ *+' $at_stder1 >&2
27049grep -v '^ *+' $at_stder1 >$at_stderr
27050at_failed=false
27051$at_diff $at_devnull $at_stderr || at_failed=:
27052$at_diff $at_devnull $at_stdout || at_failed=:
27053case $at_status in
27054   77) echo 77 > $at_status_file
27055            exit 77;;
27056   0) ;;
27057   *) echo "calc.at:569: exit code was $at_status, expected 0"
27058      at_failed=:;;
27059esac
27060if $at_failed; then
27061
27062  echo 1 > $at_status_file
27063  exit 1
27064fi
27065
27066$at_traceon
27067
27068   $at_traceoff
27069echo "calc.at:569: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
27070echo calc.at:569 >$at_check_line_file
27071( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
27072at_status=$?
27073grep '^ *+' $at_stder1 >&2
27074grep -v '^ *+' $at_stder1 >$at_stderr
27075at_failed=false
27076echo stderr:; cat $at_stderr
27077echo stdout:; cat $at_stdout
27078case $at_status in
27079   77) echo 77 > $at_status_file
27080            exit 77;;
27081   0) ;;
27082   *) echo "calc.at:569: exit code was $at_status, expected 0"
27083      at_failed=:;;
27084esac
27085if $at_failed; then
27086
27087  echo 1 > $at_status_file
27088  exit 1
27089fi
27090
27091$at_traceon
27092
27093
27094# Test the priorities.
27095cat >input <<'_ATEOF'
270961 + 2 * 3 = 7
270971 + 2 * -3 = -5
27098
27099-1^2 = -1
27100(-1)^2 = 1
27101
27102---1 = -1
27103
271041 - 2 - 3 = -4
271051 - (2 - 3) = 2
27106
271072^2^3 = 256
27108(2^2)^3 = 64
27109_ATEOF
27110
27111$at_traceoff
27112echo "calc.at:569: \$PREPARSER ./calc input"
27113echo calc.at:569 >$at_check_line_file
27114( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
27115at_status=$?
27116grep '^ *+' $at_stder1 >&2
27117grep -v '^ *+' $at_stder1 >$at_stderr
27118at_failed=false
27119echo stderr:; tee stderr <$at_stderr
27120$at_diff $at_devnull $at_stdout || at_failed=:
27121case $at_status in
27122   77) echo 77 > $at_status_file
27123            exit 77;;
27124   0) ;;
27125   *) echo "calc.at:569: exit code was $at_status, expected 0"
27126      at_failed=:;;
27127esac
27128if $at_failed; then
27129
27130  echo 1 > $at_status_file
27131  exit 1
27132fi
27133
27134$at_traceon
27135
27136
27137
27138# Some syntax errors.
27139cat >input <<'_ATEOF'
271400 0
27141_ATEOF
27142
27143$at_traceoff
27144echo "calc.at:569: \$PREPARSER ./calc input"
27145echo calc.at:569 >$at_check_line_file
27146( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
27147at_status=$?
27148grep '^ *+' $at_stder1 >&2
27149grep -v '^ *+' $at_stder1 >$at_stderr
27150at_failed=false
27151echo stderr:; tee stderr <$at_stderr
27152$at_diff $at_devnull $at_stdout || at_failed=:
27153case $at_status in
27154   77) echo 77 > $at_status_file
27155            exit 77;;
27156   1) ;;
27157   *) echo "calc.at:569: exit code was $at_status, expected 1"
27158      at_failed=:;;
27159esac
27160if $at_failed; then
27161
27162  echo 1 > $at_status_file
27163  exit 1
27164fi
27165
27166$at_traceon
27167
27168
27169# Normalize the observed and expected error messages, depending upon the
27170# options.
27171# 1. Remove the traces from observed.
27172sed '/^Starting/d
27173/^Entering/d
27174/^Stack/d
27175/^Reading/d
27176/^Reducing/d
27177/^Shifting/d
27178/^state/d
27179/^Cleanup:/d
27180/^Error:/d
27181/^Next/d
27182/^Discarding/d
27183/ \$[0-9$]* = /d
27184/^yydestructor:/d' stderr >at-stderr
27185mv at-stderr stderr
27186# 2. Create the reference error message.
27187cat >expout <<'_ATEOF'
271881.2: syntax error, unexpected number
27189_ATEOF
27190
27191# 3. If locations are not used, remove them.
27192
27193# 4. If error-verbose is not used, strip the`, unexpected....' part.
27194
27195# 5. Check
27196$at_traceoff
27197echo "calc.at:569: cat stderr"
27198echo calc.at:569 >$at_check_line_file
27199( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
27200at_status=$?
27201grep '^ *+' $at_stder1 >&2
27202grep -v '^ *+' $at_stder1 >$at_stderr
27203at_failed=false
27204$at_diff $at_devnull $at_stderr || at_failed=:
27205$at_diff expout $at_stdout || at_failed=:
27206case $at_status in
27207   77) echo 77 > $at_status_file
27208            exit 77;;
27209   0) ;;
27210   *) echo "calc.at:569: exit code was $at_status, expected 0"
27211      at_failed=:;;
27212esac
27213if $at_failed; then
27214
27215  echo 1 > $at_status_file
27216  exit 1
27217fi
27218
27219$at_traceon
27220
27221
27222cat >input <<'_ATEOF'
272231//2
27224_ATEOF
27225
27226$at_traceoff
27227echo "calc.at:569: \$PREPARSER ./calc input"
27228echo calc.at:569 >$at_check_line_file
27229( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
27230at_status=$?
27231grep '^ *+' $at_stder1 >&2
27232grep -v '^ *+' $at_stder1 >$at_stderr
27233at_failed=false
27234echo stderr:; tee stderr <$at_stderr
27235$at_diff $at_devnull $at_stdout || at_failed=:
27236case $at_status in
27237   77) echo 77 > $at_status_file
27238            exit 77;;
27239   1) ;;
27240   *) echo "calc.at:569: exit code was $at_status, expected 1"
27241      at_failed=:;;
27242esac
27243if $at_failed; then
27244
27245  echo 1 > $at_status_file
27246  exit 1
27247fi
27248
27249$at_traceon
27250
27251
27252# Normalize the observed and expected error messages, depending upon the
27253# options.
27254# 1. Remove the traces from observed.
27255sed '/^Starting/d
27256/^Entering/d
27257/^Stack/d
27258/^Reading/d
27259/^Reducing/d
27260/^Shifting/d
27261/^state/d
27262/^Cleanup:/d
27263/^Error:/d
27264/^Next/d
27265/^Discarding/d
27266/ \$[0-9$]* = /d
27267/^yydestructor:/d' stderr >at-stderr
27268mv at-stderr stderr
27269# 2. Create the reference error message.
27270cat >expout <<'_ATEOF'
272711.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
27272_ATEOF
27273
27274# 3. If locations are not used, remove them.
27275
27276# 4. If error-verbose is not used, strip the`, unexpected....' part.
27277
27278# 5. Check
27279$at_traceoff
27280echo "calc.at:569: cat stderr"
27281echo calc.at:569 >$at_check_line_file
27282( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
27283at_status=$?
27284grep '^ *+' $at_stder1 >&2
27285grep -v '^ *+' $at_stder1 >$at_stderr
27286at_failed=false
27287$at_diff $at_devnull $at_stderr || at_failed=:
27288$at_diff expout $at_stdout || at_failed=:
27289case $at_status in
27290   77) echo 77 > $at_status_file
27291            exit 77;;
27292   0) ;;
27293   *) echo "calc.at:569: exit code was $at_status, expected 0"
27294      at_failed=:;;
27295esac
27296if $at_failed; then
27297
27298  echo 1 > $at_status_file
27299  exit 1
27300fi
27301
27302$at_traceon
27303
27304
27305cat >input <<'_ATEOF'
27306error
27307_ATEOF
27308
27309$at_traceoff
27310echo "calc.at:569: \$PREPARSER ./calc input"
27311echo calc.at:569 >$at_check_line_file
27312( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
27313at_status=$?
27314grep '^ *+' $at_stder1 >&2
27315grep -v '^ *+' $at_stder1 >$at_stderr
27316at_failed=false
27317echo stderr:; tee stderr <$at_stderr
27318$at_diff $at_devnull $at_stdout || at_failed=:
27319case $at_status in
27320   77) echo 77 > $at_status_file
27321            exit 77;;
27322   1) ;;
27323   *) echo "calc.at:569: exit code was $at_status, expected 1"
27324      at_failed=:;;
27325esac
27326if $at_failed; then
27327
27328  echo 1 > $at_status_file
27329  exit 1
27330fi
27331
27332$at_traceon
27333
27334
27335# Normalize the observed and expected error messages, depending upon the
27336# options.
27337# 1. Remove the traces from observed.
27338sed '/^Starting/d
27339/^Entering/d
27340/^Stack/d
27341/^Reading/d
27342/^Reducing/d
27343/^Shifting/d
27344/^state/d
27345/^Cleanup:/d
27346/^Error:/d
27347/^Next/d
27348/^Discarding/d
27349/ \$[0-9$]* = /d
27350/^yydestructor:/d' stderr >at-stderr
27351mv at-stderr stderr
27352# 2. Create the reference error message.
27353cat >expout <<'_ATEOF'
273541.0: syntax error, unexpected $undefined
27355_ATEOF
27356
27357# 3. If locations are not used, remove them.
27358
27359# 4. If error-verbose is not used, strip the`, unexpected....' part.
27360
27361# 5. Check
27362$at_traceoff
27363echo "calc.at:569: cat stderr"
27364echo calc.at:569 >$at_check_line_file
27365( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
27366at_status=$?
27367grep '^ *+' $at_stder1 >&2
27368grep -v '^ *+' $at_stder1 >$at_stderr
27369at_failed=false
27370$at_diff $at_devnull $at_stderr || at_failed=:
27371$at_diff expout $at_stdout || at_failed=:
27372case $at_status in
27373   77) echo 77 > $at_status_file
27374            exit 77;;
27375   0) ;;
27376   *) echo "calc.at:569: exit code was $at_status, expected 0"
27377      at_failed=:;;
27378esac
27379if $at_failed; then
27380
27381  echo 1 > $at_status_file
27382  exit 1
27383fi
27384
27385$at_traceon
27386
27387
27388cat >input <<'_ATEOF'
273891 = 2 = 3
27390_ATEOF
27391
27392$at_traceoff
27393echo "calc.at:569: \$PREPARSER ./calc input"
27394echo calc.at:569 >$at_check_line_file
27395( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
27396at_status=$?
27397grep '^ *+' $at_stder1 >&2
27398grep -v '^ *+' $at_stder1 >$at_stderr
27399at_failed=false
27400echo stderr:; tee stderr <$at_stderr
27401$at_diff $at_devnull $at_stdout || at_failed=:
27402case $at_status in
27403   77) echo 77 > $at_status_file
27404            exit 77;;
27405   1) ;;
27406   *) echo "calc.at:569: exit code was $at_status, expected 1"
27407      at_failed=:;;
27408esac
27409if $at_failed; then
27410
27411  echo 1 > $at_status_file
27412  exit 1
27413fi
27414
27415$at_traceon
27416
27417
27418# Normalize the observed and expected error messages, depending upon the
27419# options.
27420# 1. Remove the traces from observed.
27421sed '/^Starting/d
27422/^Entering/d
27423/^Stack/d
27424/^Reading/d
27425/^Reducing/d
27426/^Shifting/d
27427/^state/d
27428/^Cleanup:/d
27429/^Error:/d
27430/^Next/d
27431/^Discarding/d
27432/ \$[0-9$]* = /d
27433/^yydestructor:/d' stderr >at-stderr
27434mv at-stderr stderr
27435# 2. Create the reference error message.
27436cat >expout <<'_ATEOF'
274371.6: syntax error, unexpected '='
27438_ATEOF
27439
27440# 3. If locations are not used, remove them.
27441
27442# 4. If error-verbose is not used, strip the`, unexpected....' part.
27443
27444# 5. Check
27445$at_traceoff
27446echo "calc.at:569: cat stderr"
27447echo calc.at:569 >$at_check_line_file
27448( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
27449at_status=$?
27450grep '^ *+' $at_stder1 >&2
27451grep -v '^ *+' $at_stder1 >$at_stderr
27452at_failed=false
27453$at_diff $at_devnull $at_stderr || at_failed=:
27454$at_diff expout $at_stdout || at_failed=:
27455case $at_status in
27456   77) echo 77 > $at_status_file
27457            exit 77;;
27458   0) ;;
27459   *) echo "calc.at:569: exit code was $at_status, expected 0"
27460      at_failed=:;;
27461esac
27462if $at_failed; then
27463
27464  echo 1 > $at_status_file
27465  exit 1
27466fi
27467
27468$at_traceon
27469
27470
27471cat >input <<'_ATEOF'
27472
27473+1
27474_ATEOF
27475
27476$at_traceoff
27477echo "calc.at:569: \$PREPARSER ./calc input"
27478echo calc.at:569 >$at_check_line_file
27479( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
27480at_status=$?
27481grep '^ *+' $at_stder1 >&2
27482grep -v '^ *+' $at_stder1 >$at_stderr
27483at_failed=false
27484echo stderr:; tee stderr <$at_stderr
27485$at_diff $at_devnull $at_stdout || at_failed=:
27486case $at_status in
27487   77) echo 77 > $at_status_file
27488            exit 77;;
27489   1) ;;
27490   *) echo "calc.at:569: exit code was $at_status, expected 1"
27491      at_failed=:;;
27492esac
27493if $at_failed; then
27494
27495  echo 1 > $at_status_file
27496  exit 1
27497fi
27498
27499$at_traceon
27500
27501
27502# Normalize the observed and expected error messages, depending upon the
27503# options.
27504# 1. Remove the traces from observed.
27505sed '/^Starting/d
27506/^Entering/d
27507/^Stack/d
27508/^Reading/d
27509/^Reducing/d
27510/^Shifting/d
27511/^state/d
27512/^Cleanup:/d
27513/^Error:/d
27514/^Next/d
27515/^Discarding/d
27516/ \$[0-9$]* = /d
27517/^yydestructor:/d' stderr >at-stderr
27518mv at-stderr stderr
27519# 2. Create the reference error message.
27520cat >expout <<'_ATEOF'
275212.0: syntax error, unexpected '+'
27522_ATEOF
27523
27524# 3. If locations are not used, remove them.
27525
27526# 4. If error-verbose is not used, strip the`, unexpected....' part.
27527
27528# 5. Check
27529$at_traceoff
27530echo "calc.at:569: cat stderr"
27531echo calc.at:569 >$at_check_line_file
27532( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
27533at_status=$?
27534grep '^ *+' $at_stder1 >&2
27535grep -v '^ *+' $at_stder1 >$at_stderr
27536at_failed=false
27537$at_diff $at_devnull $at_stderr || at_failed=:
27538$at_diff expout $at_stdout || at_failed=:
27539case $at_status in
27540   77) echo 77 > $at_status_file
27541            exit 77;;
27542   0) ;;
27543   *) echo "calc.at:569: exit code was $at_status, expected 0"
27544      at_failed=:;;
27545esac
27546if $at_failed; then
27547
27548  echo 1 > $at_status_file
27549  exit 1
27550fi
27551
27552$at_traceon
27553
27554
27555# Exercise error messages with EOF: work on an empty file.
27556$at_traceoff
27557echo "calc.at:569: \$PREPARSER ./calc /dev/null"
27558echo calc.at:569 >$at_check_line_file
27559( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
27560at_status=$?
27561grep '^ *+' $at_stder1 >&2
27562grep -v '^ *+' $at_stder1 >$at_stderr
27563at_failed=false
27564echo stderr:; tee stderr <$at_stderr
27565$at_diff $at_devnull $at_stdout || at_failed=:
27566case $at_status in
27567   77) echo 77 > $at_status_file
27568            exit 77;;
27569   1) ;;
27570   *) echo "calc.at:569: exit code was $at_status, expected 1"
27571      at_failed=:;;
27572esac
27573if $at_failed; then
27574
27575  echo 1 > $at_status_file
27576  exit 1
27577fi
27578
27579$at_traceon
27580
27581
27582# Normalize the observed and expected error messages, depending upon the
27583# options.
27584# 1. Remove the traces from observed.
27585sed '/^Starting/d
27586/^Entering/d
27587/^Stack/d
27588/^Reading/d
27589/^Reducing/d
27590/^Shifting/d
27591/^state/d
27592/^Cleanup:/d
27593/^Error:/d
27594/^Next/d
27595/^Discarding/d
27596/ \$[0-9$]* = /d
27597/^yydestructor:/d' stderr >at-stderr
27598mv at-stderr stderr
27599# 2. Create the reference error message.
27600cat >expout <<'_ATEOF'
276011.0: syntax error, unexpected end of input
27602_ATEOF
27603
27604# 3. If locations are not used, remove them.
27605
27606# 4. If error-verbose is not used, strip the`, unexpected....' part.
27607
27608# 5. Check
27609$at_traceoff
27610echo "calc.at:569: cat stderr"
27611echo calc.at:569 >$at_check_line_file
27612( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
27613at_status=$?
27614grep '^ *+' $at_stder1 >&2
27615grep -v '^ *+' $at_stder1 >$at_stderr
27616at_failed=false
27617$at_diff $at_devnull $at_stderr || at_failed=:
27618$at_diff expout $at_stdout || at_failed=:
27619case $at_status in
27620   77) echo 77 > $at_status_file
27621            exit 77;;
27622   0) ;;
27623   *) echo "calc.at:569: exit code was $at_status, expected 0"
27624      at_failed=:;;
27625esac
27626if $at_failed; then
27627
27628  echo 1 > $at_status_file
27629  exit 1
27630fi
27631
27632$at_traceon
27633
27634
27635
27636# Exercise the error token: without it, we die at the first error,
27637# hence be sure to
27638#
27639# - have several errors which exercise different shift/discardings
27640#   - (): nothing to pop, nothing to discard
27641#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
27642#   - (* * *): nothing to pop, a lot to discard
27643#   - (1 + 2 * *): some to pop and discard
27644#
27645# - test the action associated to `error'
27646#
27647# - check the look-ahead that triggers an error is not discarded
27648#   when we enter error recovery.  Below, the look-ahead causing the
27649#   first error is ")", which is needed to recover from the error and
27650#   produce the "0" that triggers the "0 != 1" error.
27651#
27652cat >input <<'_ATEOF'
27653() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
27654_ATEOF
27655
27656$at_traceoff
27657echo "calc.at:569: \$PREPARSER ./calc input"
27658echo calc.at:569 >$at_check_line_file
27659( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
27660at_status=$?
27661grep '^ *+' $at_stder1 >&2
27662grep -v '^ *+' $at_stder1 >$at_stderr
27663at_failed=false
27664echo stderr:; tee stderr <$at_stderr
27665$at_diff $at_devnull $at_stdout || at_failed=:
27666case $at_status in
27667   77) echo 77 > $at_status_file
27668            exit 77;;
27669   0) ;;
27670   *) echo "calc.at:569: exit code was $at_status, expected 0"
27671      at_failed=:;;
27672esac
27673if $at_failed; then
27674
27675  echo 1 > $at_status_file
27676  exit 1
27677fi
27678
27679$at_traceon
27680
27681
27682# Normalize the observed and expected error messages, depending upon the
27683# options.
27684# 1. Remove the traces from observed.
27685sed '/^Starting/d
27686/^Entering/d
27687/^Stack/d
27688/^Reading/d
27689/^Reducing/d
27690/^Shifting/d
27691/^state/d
27692/^Cleanup:/d
27693/^Error:/d
27694/^Next/d
27695/^Discarding/d
27696/ \$[0-9$]* = /d
27697/^yydestructor:/d' stderr >at-stderr
27698mv at-stderr stderr
27699# 2. Create the reference error message.
27700cat >expout <<'_ATEOF'
277011.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
277021.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
277031.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
277041.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
27705calc: error: 4444 != 1
27706_ATEOF
27707
27708# 3. If locations are not used, remove them.
27709
27710# 4. If error-verbose is not used, strip the`, unexpected....' part.
27711
27712# 5. Check
27713$at_traceoff
27714echo "calc.at:569: cat stderr"
27715echo calc.at:569 >$at_check_line_file
27716( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
27717at_status=$?
27718grep '^ *+' $at_stder1 >&2
27719grep -v '^ *+' $at_stder1 >$at_stderr
27720at_failed=false
27721$at_diff $at_devnull $at_stderr || at_failed=:
27722$at_diff expout $at_stdout || at_failed=:
27723case $at_status in
27724   77) echo 77 > $at_status_file
27725            exit 77;;
27726   0) ;;
27727   *) echo "calc.at:569: exit code was $at_status, expected 0"
27728      at_failed=:;;
27729esac
27730if $at_failed; then
27731
27732  echo 1 > $at_status_file
27733  exit 1
27734fi
27735
27736$at_traceon
27737
27738
27739
27740# The same, but this time exercising explicitly triggered syntax errors.
27741# POSIX says the look-ahead causing the error should not be discarded.
27742cat >input <<'_ATEOF'
27743(!) + (0 0) = 1
27744_ATEOF
27745
27746$at_traceoff
27747echo "calc.at:569: \$PREPARSER ./calc input"
27748echo calc.at:569 >$at_check_line_file
27749( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
27750at_status=$?
27751grep '^ *+' $at_stder1 >&2
27752grep -v '^ *+' $at_stder1 >$at_stderr
27753at_failed=false
27754echo stderr:; tee stderr <$at_stderr
27755$at_diff $at_devnull $at_stdout || at_failed=:
27756case $at_status in
27757   77) echo 77 > $at_status_file
27758            exit 77;;
27759   0) ;;
27760   *) echo "calc.at:569: exit code was $at_status, expected 0"
27761      at_failed=:;;
27762esac
27763if $at_failed; then
27764
27765  echo 1 > $at_status_file
27766  exit 1
27767fi
27768
27769$at_traceon
27770
27771
27772# Normalize the observed and expected error messages, depending upon the
27773# options.
27774# 1. Remove the traces from observed.
27775sed '/^Starting/d
27776/^Entering/d
27777/^Stack/d
27778/^Reading/d
27779/^Reducing/d
27780/^Shifting/d
27781/^state/d
27782/^Cleanup:/d
27783/^Error:/d
27784/^Next/d
27785/^Discarding/d
27786/ \$[0-9$]* = /d
27787/^yydestructor:/d' stderr >at-stderr
27788mv at-stderr stderr
27789# 2. Create the reference error message.
27790cat >expout <<'_ATEOF'
277911.9: syntax error, unexpected number
27792calc: error: 2222 != 1
27793_ATEOF
27794
27795# 3. If locations are not used, remove them.
27796
27797# 4. If error-verbose is not used, strip the`, unexpected....' part.
27798
27799# 5. Check
27800$at_traceoff
27801echo "calc.at:569: cat stderr"
27802echo calc.at:569 >$at_check_line_file
27803( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
27804at_status=$?
27805grep '^ *+' $at_stder1 >&2
27806grep -v '^ *+' $at_stder1 >$at_stderr
27807at_failed=false
27808$at_diff $at_devnull $at_stderr || at_failed=:
27809$at_diff expout $at_stdout || at_failed=:
27810case $at_status in
27811   77) echo 77 > $at_status_file
27812            exit 77;;
27813   0) ;;
27814   *) echo "calc.at:569: exit code was $at_status, expected 0"
27815      at_failed=:;;
27816esac
27817if $at_failed; then
27818
27819  echo 1 > $at_status_file
27820  exit 1
27821fi
27822
27823$at_traceon
27824
27825
27826cat >input <<'_ATEOF'
27827(- *) + (0 0) = 1
27828_ATEOF
27829
27830$at_traceoff
27831echo "calc.at:569: \$PREPARSER ./calc input"
27832echo calc.at:569 >$at_check_line_file
27833( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
27834at_status=$?
27835grep '^ *+' $at_stder1 >&2
27836grep -v '^ *+' $at_stder1 >$at_stderr
27837at_failed=false
27838echo stderr:; tee stderr <$at_stderr
27839$at_diff $at_devnull $at_stdout || at_failed=:
27840case $at_status in
27841   77) echo 77 > $at_status_file
27842            exit 77;;
27843   0) ;;
27844   *) echo "calc.at:569: exit code was $at_status, expected 0"
27845      at_failed=:;;
27846esac
27847if $at_failed; then
27848
27849  echo 1 > $at_status_file
27850  exit 1
27851fi
27852
27853$at_traceon
27854
27855
27856# Normalize the observed and expected error messages, depending upon the
27857# options.
27858# 1. Remove the traces from observed.
27859sed '/^Starting/d
27860/^Entering/d
27861/^Stack/d
27862/^Reading/d
27863/^Reducing/d
27864/^Shifting/d
27865/^state/d
27866/^Cleanup:/d
27867/^Error:/d
27868/^Next/d
27869/^Discarding/d
27870/ \$[0-9$]* = /d
27871/^yydestructor:/d' stderr >at-stderr
27872mv at-stderr stderr
27873# 2. Create the reference error message.
27874cat >expout <<'_ATEOF'
278751.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
278761.11: syntax error, unexpected number
27877calc: error: 2222 != 1
27878_ATEOF
27879
27880# 3. If locations are not used, remove them.
27881
27882# 4. If error-verbose is not used, strip the`, unexpected....' part.
27883
27884# 5. Check
27885$at_traceoff
27886echo "calc.at:569: cat stderr"
27887echo calc.at:569 >$at_check_line_file
27888( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
27889at_status=$?
27890grep '^ *+' $at_stder1 >&2
27891grep -v '^ *+' $at_stder1 >$at_stderr
27892at_failed=false
27893$at_diff $at_devnull $at_stderr || at_failed=:
27894$at_diff expout $at_stdout || at_failed=:
27895case $at_status in
27896   77) echo 77 > $at_status_file
27897            exit 77;;
27898   0) ;;
27899   *) echo "calc.at:569: exit code was $at_status, expected 0"
27900      at_failed=:;;
27901esac
27902if $at_failed; then
27903
27904  echo 1 > $at_status_file
27905  exit 1
27906fi
27907
27908$at_traceon
27909
27910
27911
27912
27913
27914
27915
27916
27917
27918
27919
27920
27921
27922
27923
27924
27925
27926
27927
27928
27929
27930
27931
27932
27933      $at_traceoff
27934      $at_times_p && times >$at_times_file
27935    ) 5>&1 2>&1 | eval $at_tee_pipe
27936    at_status=`cat $at_status_file`
27937    ;;
27938
27939
27940  banner-10 ) # Banner 10. calc.at:576
27941    cat <<\_ATEOF
27942
27943Simple GLR Calculator.
27944
27945_ATEOF
27946    ;;
27947
27948  84 ) # 84. calc.at:586: Calculator %glr-parser
27949    at_setup_line='calc.at:586'
27950    at_desc='Calculator %glr-parser '
27951    $at_quiet $ECHO_N " 84: Calculator %glr-parser                       $ECHO_C"
27952    at_xfail=no
27953    (
27954      echo "84. calc.at:586: testing ..."
27955      $at_traceon
27956
27957
27958
27959
27960
27961
27962
27963
27964# Using yacc.c?
27965
27966
27967
27968
27969
27970
27971
27972# yyerror receives the location if %location & %pure & (%glr or %parse-param).
27973
27974# yyerror always sees the locations (when activated), except if
27975# yacc & pure & !param.
27976
27977
27978# The interface is pure: either because %pure-parser, or because we
27979# are using the C++ parsers.
27980
27981
27982
27983
27984
27985
27986
27987
27988
27989
27990
27991
27992cat >calc.y <<'_ATEOF'
27993%{
27994#ifdef HAVE_CONFIG_H
27995# include <config.h>
27996  /* We don't need perfect functions for these tests. */
27997# undef malloc
27998# undef memcmp
27999# undef realloc
28000#endif
28001%}
28002
28003/* Infix notation calculator--calc */
28004%glr-parser
28005
28006%{
28007#include <stdio.h>
28008
28009#include <stdlib.h>
28010#include <string.h>
28011#if HAVE_UNISTD_H
28012# include <unistd.h>
28013#else
28014# undef alarm
28015# define alarm(seconds) /* empty */
28016#endif
28017#include <ctype.h>
28018#define USE(Var)
28019
28020/* Exercise pre-prologue dependency to %union.  */
28021typedef int semantic_value;
28022
28023static semantic_value global_result = 0;
28024static int global_count = 0;
28025%}
28026
28027/* Exercise %union. */
28028%union
28029{
28030  semantic_value ival;
28031};
28032
28033%{
28034static int power (int base, int exponent);
28035/* yyerror receives the location if:
28036   - %location & %pure & %glr
28037   - %location & %pure & %yacc & %parse-param. */
28038static void yyerror (
28039
28040                     const char *s
28041                     );
28042static int yylex (void);
28043static int get_char (void);
28044static void unget_char ( int c);
28045%}
28046
28047
28048
28049/* Bison Declarations */
28050%token CALC_EOF 0 "end of input"
28051%token <ival> NUM "number"
28052%type  <ival> exp
28053
28054%nonassoc '=' /* comparison	       */
28055%left '-' '+'
28056%left '*' '/'
28057%left NEG     /* negation--unary minus */
28058%right '^'    /* exponentiation        */
28059
28060/* Grammar follows */
28061%%
28062input:
28063  line
28064| input line         {  }
28065;
28066
28067line:
28068  '\n'
28069| exp '\n'           { USE ($1); }
28070;
28071
28072exp:
28073  NUM                { $$ = $1;             }
28074| exp '=' exp
28075  {
28076    if ($1 != $3)
28077      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
28078    $$ = $1;
28079  }
28080| exp '+' exp        { $$ = $1 + $3;        }
28081| exp '-' exp        { $$ = $1 - $3;        }
28082| exp '*' exp        { $$ = $1 * $3;        }
28083| exp '/' exp        { $$ = $1 / $3;        }
28084| '-' exp  %prec NEG { $$ = -$2;            }
28085| exp '^' exp        { $$ = power ($1, $3); }
28086| '(' exp ')'        { $$ = $2;             }
28087| '(' error ')'      { $$ = 1111;           }
28088| '!'                { $$ = 0; YYERROR;     }
28089| '-' error          { $$ = 0; YYERROR;     }
28090;
28091%%
28092/* The input.  */
28093static FILE *input;
28094
28095static void
28096yyerror (
28097
28098         const char *s)
28099{
28100
28101
28102  fprintf (stderr, "%s\n", s);
28103}
28104
28105
28106
28107static int
28108get_char (void)
28109{
28110  int res = getc (input);
28111  ;
28112
28113  return res;
28114}
28115
28116
28117static void
28118unget_char ( int c)
28119{
28120  ;
28121
28122  ungetc (c, input);
28123}
28124
28125static int
28126read_signed_integer (void)
28127{
28128  int c = get_char ();
28129  int sign = 1;
28130  int n = 0;
28131
28132  ;
28133  if (c == '-')
28134    {
28135      c = get_char ();
28136      sign = -1;
28137    }
28138
28139  while (isdigit (c))
28140    {
28141      n = 10 * n + (c - '0');
28142      c = get_char ();
28143    }
28144
28145  unget_char ( c);
28146
28147  return sign * n;
28148}
28149
28150
28151
28152/*---------------------------------------------------------------.
28153| Lexical analyzer returns an integer on the stack and the token |
28154| NUM, or the ASCII character read if not a number.  Skips all   |
28155| blanks and tabs, returns 0 for EOF.                            |
28156`---------------------------------------------------------------*/
28157
28158static int
28159yylex (void)
28160{
28161  static int init = 1;
28162  int c;
28163
28164  if (init)
28165    {
28166      init = 0;
28167
28168    }
28169
28170
28171
28172  /* Skip white space.  */
28173  while ((c = get_char ()) == ' ' || c == '\t')
28174    {
28175
28176    }
28177
28178  /* process numbers   */
28179  if (c == '.' || isdigit (c))
28180    {
28181      unget_char ( c);
28182      (yylval).ival = read_signed_integer ();
28183      return NUM;
28184    }
28185
28186  /* Return end-of-file.  */
28187  if (c == EOF)
28188    return CALC_EOF;
28189
28190  /* Return single chars. */
28191  return c;
28192}
28193
28194static int
28195power (int base, int exponent)
28196{
28197  int res = 1;
28198  if (exponent < 0)
28199    exit (3);
28200  for (/* Niente */; exponent; --exponent)
28201    res *= base;
28202  return res;
28203}
28204
28205
28206int
28207main (int argc, const char **argv)
28208{
28209  semantic_value result = 0;
28210  int count = 0;
28211  int status;
28212
28213  /* This used to be alarm (10), but that isn't enough time for
28214     a July 1995 vintage DEC Alphastation 200 4/100 system,
28215     according to Nelson H. F. Beebe.  100 seconds is enough.  */
28216  alarm (100);
28217
28218  if (argc == 2)
28219    input = fopen (argv[1], "r");
28220  else
28221    input = stdin;
28222
28223  if (!input)
28224    {
28225      perror (argv[1]);
28226      return 3;
28227    }
28228
28229
28230  status = yyparse ();
28231  if (global_result != result)
28232    abort ();
28233  if (global_count != count)
28234    abort ();
28235  return status;
28236}
28237_ATEOF
28238
28239
28240
28241
28242
28243$at_traceoff
28244echo "calc.at:586: bison -o calc.c calc.y"
28245echo calc.at:586 >$at_check_line_file
28246( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
28247at_status=$?
28248grep '^ *+' $at_stder1 >&2
28249grep -v '^ *+' $at_stder1 >$at_stderr
28250at_failed=false
28251$at_diff $at_devnull $at_stderr || at_failed=:
28252$at_diff $at_devnull $at_stdout || at_failed=:
28253case $at_status in
28254   77) echo 77 > $at_status_file
28255            exit 77;;
28256   0) ;;
28257   *) echo "calc.at:586: exit code was $at_status, expected 0"
28258      at_failed=:;;
28259esac
28260if $at_failed; then
28261
28262  echo 1 > $at_status_file
28263  exit 1
28264fi
28265
28266$at_traceon
28267
28268   $at_traceoff
28269echo "calc.at:586: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
28270echo calc.at:586 >$at_check_line_file
28271( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
28272at_status=$?
28273grep '^ *+' $at_stder1 >&2
28274grep -v '^ *+' $at_stder1 >$at_stderr
28275at_failed=false
28276echo stderr:; cat $at_stderr
28277echo stdout:; cat $at_stdout
28278case $at_status in
28279   77) echo 77 > $at_status_file
28280            exit 77;;
28281   0) ;;
28282   *) echo "calc.at:586: exit code was $at_status, expected 0"
28283      at_failed=:;;
28284esac
28285if $at_failed; then
28286
28287  echo 1 > $at_status_file
28288  exit 1
28289fi
28290
28291$at_traceon
28292
28293
28294# Test the priorities.
28295cat >input <<'_ATEOF'
282961 + 2 * 3 = 7
282971 + 2 * -3 = -5
28298
28299-1^2 = -1
28300(-1)^2 = 1
28301
28302---1 = -1
28303
283041 - 2 - 3 = -4
283051 - (2 - 3) = 2
28306
283072^2^3 = 256
28308(2^2)^3 = 64
28309_ATEOF
28310
28311$at_traceoff
28312echo "calc.at:586: \$PREPARSER ./calc input"
28313echo calc.at:586 >$at_check_line_file
28314( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
28315at_status=$?
28316grep '^ *+' $at_stder1 >&2
28317grep -v '^ *+' $at_stder1 >$at_stderr
28318at_failed=false
28319echo stderr:; tee stderr <$at_stderr
28320$at_diff $at_devnull $at_stdout || at_failed=:
28321case $at_status in
28322   77) echo 77 > $at_status_file
28323            exit 77;;
28324   0) ;;
28325   *) echo "calc.at:586: exit code was $at_status, expected 0"
28326      at_failed=:;;
28327esac
28328if $at_failed; then
28329
28330  echo 1 > $at_status_file
28331  exit 1
28332fi
28333
28334$at_traceon
28335
28336
28337
28338# Some syntax errors.
28339cat >input <<'_ATEOF'
283400 0
28341_ATEOF
28342
28343$at_traceoff
28344echo "calc.at:586: \$PREPARSER ./calc input"
28345echo calc.at:586 >$at_check_line_file
28346( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
28347at_status=$?
28348grep '^ *+' $at_stder1 >&2
28349grep -v '^ *+' $at_stder1 >$at_stderr
28350at_failed=false
28351echo stderr:; tee stderr <$at_stderr
28352$at_diff $at_devnull $at_stdout || at_failed=:
28353case $at_status in
28354   77) echo 77 > $at_status_file
28355            exit 77;;
28356   1) ;;
28357   *) echo "calc.at:586: exit code was $at_status, expected 1"
28358      at_failed=:;;
28359esac
28360if $at_failed; then
28361
28362  echo 1 > $at_status_file
28363  exit 1
28364fi
28365
28366$at_traceon
28367
28368
28369# Normalize the observed and expected error messages, depending upon the
28370# options.
28371# 1. Remove the traces from observed.
28372sed '/^Starting/d
28373/^Entering/d
28374/^Stack/d
28375/^Reading/d
28376/^Reducing/d
28377/^Shifting/d
28378/^state/d
28379/^Cleanup:/d
28380/^Error:/d
28381/^Next/d
28382/^Discarding/d
28383/ \$[0-9$]* = /d
28384/^yydestructor:/d' stderr >at-stderr
28385mv at-stderr stderr
28386# 2. Create the reference error message.
28387cat >expout <<'_ATEOF'
283881.2: syntax error, unexpected number
28389_ATEOF
28390
28391# 3. If locations are not used, remove them.
28392sed 's/^[-0-9.]*: //' expout >at-expout
28393mv at-expout expout
28394# 4. If error-verbose is not used, strip the`, unexpected....' part.
28395sed 's/syntax error, .*$/syntax error/' expout >at-expout
28396mv at-expout expout
28397# 5. Check
28398$at_traceoff
28399echo "calc.at:586: cat stderr"
28400echo calc.at:586 >$at_check_line_file
28401( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
28402at_status=$?
28403grep '^ *+' $at_stder1 >&2
28404grep -v '^ *+' $at_stder1 >$at_stderr
28405at_failed=false
28406$at_diff $at_devnull $at_stderr || at_failed=:
28407$at_diff expout $at_stdout || at_failed=:
28408case $at_status in
28409   77) echo 77 > $at_status_file
28410            exit 77;;
28411   0) ;;
28412   *) echo "calc.at:586: exit code was $at_status, expected 0"
28413      at_failed=:;;
28414esac
28415if $at_failed; then
28416
28417  echo 1 > $at_status_file
28418  exit 1
28419fi
28420
28421$at_traceon
28422
28423
28424cat >input <<'_ATEOF'
284251//2
28426_ATEOF
28427
28428$at_traceoff
28429echo "calc.at:586: \$PREPARSER ./calc input"
28430echo calc.at:586 >$at_check_line_file
28431( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
28432at_status=$?
28433grep '^ *+' $at_stder1 >&2
28434grep -v '^ *+' $at_stder1 >$at_stderr
28435at_failed=false
28436echo stderr:; tee stderr <$at_stderr
28437$at_diff $at_devnull $at_stdout || at_failed=:
28438case $at_status in
28439   77) echo 77 > $at_status_file
28440            exit 77;;
28441   1) ;;
28442   *) echo "calc.at:586: exit code was $at_status, expected 1"
28443      at_failed=:;;
28444esac
28445if $at_failed; then
28446
28447  echo 1 > $at_status_file
28448  exit 1
28449fi
28450
28451$at_traceon
28452
28453
28454# Normalize the observed and expected error messages, depending upon the
28455# options.
28456# 1. Remove the traces from observed.
28457sed '/^Starting/d
28458/^Entering/d
28459/^Stack/d
28460/^Reading/d
28461/^Reducing/d
28462/^Shifting/d
28463/^state/d
28464/^Cleanup:/d
28465/^Error:/d
28466/^Next/d
28467/^Discarding/d
28468/ \$[0-9$]* = /d
28469/^yydestructor:/d' stderr >at-stderr
28470mv at-stderr stderr
28471# 2. Create the reference error message.
28472cat >expout <<'_ATEOF'
284731.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
28474_ATEOF
28475
28476# 3. If locations are not used, remove them.
28477sed 's/^[-0-9.]*: //' expout >at-expout
28478mv at-expout expout
28479# 4. If error-verbose is not used, strip the`, unexpected....' part.
28480sed 's/syntax error, .*$/syntax error/' expout >at-expout
28481mv at-expout expout
28482# 5. Check
28483$at_traceoff
28484echo "calc.at:586: cat stderr"
28485echo calc.at:586 >$at_check_line_file
28486( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
28487at_status=$?
28488grep '^ *+' $at_stder1 >&2
28489grep -v '^ *+' $at_stder1 >$at_stderr
28490at_failed=false
28491$at_diff $at_devnull $at_stderr || at_failed=:
28492$at_diff expout $at_stdout || at_failed=:
28493case $at_status in
28494   77) echo 77 > $at_status_file
28495            exit 77;;
28496   0) ;;
28497   *) echo "calc.at:586: exit code was $at_status, expected 0"
28498      at_failed=:;;
28499esac
28500if $at_failed; then
28501
28502  echo 1 > $at_status_file
28503  exit 1
28504fi
28505
28506$at_traceon
28507
28508
28509cat >input <<'_ATEOF'
28510error
28511_ATEOF
28512
28513$at_traceoff
28514echo "calc.at:586: \$PREPARSER ./calc input"
28515echo calc.at:586 >$at_check_line_file
28516( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
28517at_status=$?
28518grep '^ *+' $at_stder1 >&2
28519grep -v '^ *+' $at_stder1 >$at_stderr
28520at_failed=false
28521echo stderr:; tee stderr <$at_stderr
28522$at_diff $at_devnull $at_stdout || at_failed=:
28523case $at_status in
28524   77) echo 77 > $at_status_file
28525            exit 77;;
28526   1) ;;
28527   *) echo "calc.at:586: exit code was $at_status, expected 1"
28528      at_failed=:;;
28529esac
28530if $at_failed; then
28531
28532  echo 1 > $at_status_file
28533  exit 1
28534fi
28535
28536$at_traceon
28537
28538
28539# Normalize the observed and expected error messages, depending upon the
28540# options.
28541# 1. Remove the traces from observed.
28542sed '/^Starting/d
28543/^Entering/d
28544/^Stack/d
28545/^Reading/d
28546/^Reducing/d
28547/^Shifting/d
28548/^state/d
28549/^Cleanup:/d
28550/^Error:/d
28551/^Next/d
28552/^Discarding/d
28553/ \$[0-9$]* = /d
28554/^yydestructor:/d' stderr >at-stderr
28555mv at-stderr stderr
28556# 2. Create the reference error message.
28557cat >expout <<'_ATEOF'
285581.0: syntax error, unexpected $undefined
28559_ATEOF
28560
28561# 3. If locations are not used, remove them.
28562sed 's/^[-0-9.]*: //' expout >at-expout
28563mv at-expout expout
28564# 4. If error-verbose is not used, strip the`, unexpected....' part.
28565sed 's/syntax error, .*$/syntax error/' expout >at-expout
28566mv at-expout expout
28567# 5. Check
28568$at_traceoff
28569echo "calc.at:586: cat stderr"
28570echo calc.at:586 >$at_check_line_file
28571( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
28572at_status=$?
28573grep '^ *+' $at_stder1 >&2
28574grep -v '^ *+' $at_stder1 >$at_stderr
28575at_failed=false
28576$at_diff $at_devnull $at_stderr || at_failed=:
28577$at_diff expout $at_stdout || at_failed=:
28578case $at_status in
28579   77) echo 77 > $at_status_file
28580            exit 77;;
28581   0) ;;
28582   *) echo "calc.at:586: exit code was $at_status, expected 0"
28583      at_failed=:;;
28584esac
28585if $at_failed; then
28586
28587  echo 1 > $at_status_file
28588  exit 1
28589fi
28590
28591$at_traceon
28592
28593
28594cat >input <<'_ATEOF'
285951 = 2 = 3
28596_ATEOF
28597
28598$at_traceoff
28599echo "calc.at:586: \$PREPARSER ./calc input"
28600echo calc.at:586 >$at_check_line_file
28601( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
28602at_status=$?
28603grep '^ *+' $at_stder1 >&2
28604grep -v '^ *+' $at_stder1 >$at_stderr
28605at_failed=false
28606echo stderr:; tee stderr <$at_stderr
28607$at_diff $at_devnull $at_stdout || at_failed=:
28608case $at_status in
28609   77) echo 77 > $at_status_file
28610            exit 77;;
28611   1) ;;
28612   *) echo "calc.at:586: exit code was $at_status, expected 1"
28613      at_failed=:;;
28614esac
28615if $at_failed; then
28616
28617  echo 1 > $at_status_file
28618  exit 1
28619fi
28620
28621$at_traceon
28622
28623
28624# Normalize the observed and expected error messages, depending upon the
28625# options.
28626# 1. Remove the traces from observed.
28627sed '/^Starting/d
28628/^Entering/d
28629/^Stack/d
28630/^Reading/d
28631/^Reducing/d
28632/^Shifting/d
28633/^state/d
28634/^Cleanup:/d
28635/^Error:/d
28636/^Next/d
28637/^Discarding/d
28638/ \$[0-9$]* = /d
28639/^yydestructor:/d' stderr >at-stderr
28640mv at-stderr stderr
28641# 2. Create the reference error message.
28642cat >expout <<'_ATEOF'
286431.6: syntax error, unexpected '='
28644_ATEOF
28645
28646# 3. If locations are not used, remove them.
28647sed 's/^[-0-9.]*: //' expout >at-expout
28648mv at-expout expout
28649# 4. If error-verbose is not used, strip the`, unexpected....' part.
28650sed 's/syntax error, .*$/syntax error/' expout >at-expout
28651mv at-expout expout
28652# 5. Check
28653$at_traceoff
28654echo "calc.at:586: cat stderr"
28655echo calc.at:586 >$at_check_line_file
28656( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
28657at_status=$?
28658grep '^ *+' $at_stder1 >&2
28659grep -v '^ *+' $at_stder1 >$at_stderr
28660at_failed=false
28661$at_diff $at_devnull $at_stderr || at_failed=:
28662$at_diff expout $at_stdout || at_failed=:
28663case $at_status in
28664   77) echo 77 > $at_status_file
28665            exit 77;;
28666   0) ;;
28667   *) echo "calc.at:586: exit code was $at_status, expected 0"
28668      at_failed=:;;
28669esac
28670if $at_failed; then
28671
28672  echo 1 > $at_status_file
28673  exit 1
28674fi
28675
28676$at_traceon
28677
28678
28679cat >input <<'_ATEOF'
28680
28681+1
28682_ATEOF
28683
28684$at_traceoff
28685echo "calc.at:586: \$PREPARSER ./calc input"
28686echo calc.at:586 >$at_check_line_file
28687( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
28688at_status=$?
28689grep '^ *+' $at_stder1 >&2
28690grep -v '^ *+' $at_stder1 >$at_stderr
28691at_failed=false
28692echo stderr:; tee stderr <$at_stderr
28693$at_diff $at_devnull $at_stdout || at_failed=:
28694case $at_status in
28695   77) echo 77 > $at_status_file
28696            exit 77;;
28697   1) ;;
28698   *) echo "calc.at:586: exit code was $at_status, expected 1"
28699      at_failed=:;;
28700esac
28701if $at_failed; then
28702
28703  echo 1 > $at_status_file
28704  exit 1
28705fi
28706
28707$at_traceon
28708
28709
28710# Normalize the observed and expected error messages, depending upon the
28711# options.
28712# 1. Remove the traces from observed.
28713sed '/^Starting/d
28714/^Entering/d
28715/^Stack/d
28716/^Reading/d
28717/^Reducing/d
28718/^Shifting/d
28719/^state/d
28720/^Cleanup:/d
28721/^Error:/d
28722/^Next/d
28723/^Discarding/d
28724/ \$[0-9$]* = /d
28725/^yydestructor:/d' stderr >at-stderr
28726mv at-stderr stderr
28727# 2. Create the reference error message.
28728cat >expout <<'_ATEOF'
287292.0: syntax error, unexpected '+'
28730_ATEOF
28731
28732# 3. If locations are not used, remove them.
28733sed 's/^[-0-9.]*: //' expout >at-expout
28734mv at-expout expout
28735# 4. If error-verbose is not used, strip the`, unexpected....' part.
28736sed 's/syntax error, .*$/syntax error/' expout >at-expout
28737mv at-expout expout
28738# 5. Check
28739$at_traceoff
28740echo "calc.at:586: cat stderr"
28741echo calc.at:586 >$at_check_line_file
28742( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
28743at_status=$?
28744grep '^ *+' $at_stder1 >&2
28745grep -v '^ *+' $at_stder1 >$at_stderr
28746at_failed=false
28747$at_diff $at_devnull $at_stderr || at_failed=:
28748$at_diff expout $at_stdout || at_failed=:
28749case $at_status in
28750   77) echo 77 > $at_status_file
28751            exit 77;;
28752   0) ;;
28753   *) echo "calc.at:586: exit code was $at_status, expected 0"
28754      at_failed=:;;
28755esac
28756if $at_failed; then
28757
28758  echo 1 > $at_status_file
28759  exit 1
28760fi
28761
28762$at_traceon
28763
28764
28765# Exercise error messages with EOF: work on an empty file.
28766$at_traceoff
28767echo "calc.at:586: \$PREPARSER ./calc /dev/null"
28768echo calc.at:586 >$at_check_line_file
28769( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
28770at_status=$?
28771grep '^ *+' $at_stder1 >&2
28772grep -v '^ *+' $at_stder1 >$at_stderr
28773at_failed=false
28774echo stderr:; tee stderr <$at_stderr
28775$at_diff $at_devnull $at_stdout || at_failed=:
28776case $at_status in
28777   77) echo 77 > $at_status_file
28778            exit 77;;
28779   1) ;;
28780   *) echo "calc.at:586: exit code was $at_status, expected 1"
28781      at_failed=:;;
28782esac
28783if $at_failed; then
28784
28785  echo 1 > $at_status_file
28786  exit 1
28787fi
28788
28789$at_traceon
28790
28791
28792# Normalize the observed and expected error messages, depending upon the
28793# options.
28794# 1. Remove the traces from observed.
28795sed '/^Starting/d
28796/^Entering/d
28797/^Stack/d
28798/^Reading/d
28799/^Reducing/d
28800/^Shifting/d
28801/^state/d
28802/^Cleanup:/d
28803/^Error:/d
28804/^Next/d
28805/^Discarding/d
28806/ \$[0-9$]* = /d
28807/^yydestructor:/d' stderr >at-stderr
28808mv at-stderr stderr
28809# 2. Create the reference error message.
28810cat >expout <<'_ATEOF'
288111.0: syntax error, unexpected end of input
28812_ATEOF
28813
28814# 3. If locations are not used, remove them.
28815sed 's/^[-0-9.]*: //' expout >at-expout
28816mv at-expout expout
28817# 4. If error-verbose is not used, strip the`, unexpected....' part.
28818sed 's/syntax error, .*$/syntax error/' expout >at-expout
28819mv at-expout expout
28820# 5. Check
28821$at_traceoff
28822echo "calc.at:586: cat stderr"
28823echo calc.at:586 >$at_check_line_file
28824( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
28825at_status=$?
28826grep '^ *+' $at_stder1 >&2
28827grep -v '^ *+' $at_stder1 >$at_stderr
28828at_failed=false
28829$at_diff $at_devnull $at_stderr || at_failed=:
28830$at_diff expout $at_stdout || at_failed=:
28831case $at_status in
28832   77) echo 77 > $at_status_file
28833            exit 77;;
28834   0) ;;
28835   *) echo "calc.at:586: exit code was $at_status, expected 0"
28836      at_failed=:;;
28837esac
28838if $at_failed; then
28839
28840  echo 1 > $at_status_file
28841  exit 1
28842fi
28843
28844$at_traceon
28845
28846
28847
28848# Exercise the error token: without it, we die at the first error,
28849# hence be sure to
28850#
28851# - have several errors which exercise different shift/discardings
28852#   - (): nothing to pop, nothing to discard
28853#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
28854#   - (* * *): nothing to pop, a lot to discard
28855#   - (1 + 2 * *): some to pop and discard
28856#
28857# - test the action associated to `error'
28858#
28859# - check the look-ahead that triggers an error is not discarded
28860#   when we enter error recovery.  Below, the look-ahead causing the
28861#   first error is ")", which is needed to recover from the error and
28862#   produce the "0" that triggers the "0 != 1" error.
28863#
28864cat >input <<'_ATEOF'
28865() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
28866_ATEOF
28867
28868$at_traceoff
28869echo "calc.at:586: \$PREPARSER ./calc input"
28870echo calc.at:586 >$at_check_line_file
28871( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
28872at_status=$?
28873grep '^ *+' $at_stder1 >&2
28874grep -v '^ *+' $at_stder1 >$at_stderr
28875at_failed=false
28876echo stderr:; tee stderr <$at_stderr
28877$at_diff $at_devnull $at_stdout || at_failed=:
28878case $at_status in
28879   77) echo 77 > $at_status_file
28880            exit 77;;
28881   0) ;;
28882   *) echo "calc.at:586: exit code was $at_status, expected 0"
28883      at_failed=:;;
28884esac
28885if $at_failed; then
28886
28887  echo 1 > $at_status_file
28888  exit 1
28889fi
28890
28891$at_traceon
28892
28893
28894# Normalize the observed and expected error messages, depending upon the
28895# options.
28896# 1. Remove the traces from observed.
28897sed '/^Starting/d
28898/^Entering/d
28899/^Stack/d
28900/^Reading/d
28901/^Reducing/d
28902/^Shifting/d
28903/^state/d
28904/^Cleanup:/d
28905/^Error:/d
28906/^Next/d
28907/^Discarding/d
28908/ \$[0-9$]* = /d
28909/^yydestructor:/d' stderr >at-stderr
28910mv at-stderr stderr
28911# 2. Create the reference error message.
28912cat >expout <<'_ATEOF'
289131.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
289141.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
289151.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
289161.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
28917calc: error: 4444 != 1
28918_ATEOF
28919
28920# 3. If locations are not used, remove them.
28921sed 's/^[-0-9.]*: //' expout >at-expout
28922mv at-expout expout
28923# 4. If error-verbose is not used, strip the`, unexpected....' part.
28924sed 's/syntax error, .*$/syntax error/' expout >at-expout
28925mv at-expout expout
28926# 5. Check
28927$at_traceoff
28928echo "calc.at:586: cat stderr"
28929echo calc.at:586 >$at_check_line_file
28930( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
28931at_status=$?
28932grep '^ *+' $at_stder1 >&2
28933grep -v '^ *+' $at_stder1 >$at_stderr
28934at_failed=false
28935$at_diff $at_devnull $at_stderr || at_failed=:
28936$at_diff expout $at_stdout || at_failed=:
28937case $at_status in
28938   77) echo 77 > $at_status_file
28939            exit 77;;
28940   0) ;;
28941   *) echo "calc.at:586: exit code was $at_status, expected 0"
28942      at_failed=:;;
28943esac
28944if $at_failed; then
28945
28946  echo 1 > $at_status_file
28947  exit 1
28948fi
28949
28950$at_traceon
28951
28952
28953
28954# The same, but this time exercising explicitly triggered syntax errors.
28955# POSIX says the look-ahead causing the error should not be discarded.
28956cat >input <<'_ATEOF'
28957(!) + (0 0) = 1
28958_ATEOF
28959
28960$at_traceoff
28961echo "calc.at:586: \$PREPARSER ./calc input"
28962echo calc.at:586 >$at_check_line_file
28963( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
28964at_status=$?
28965grep '^ *+' $at_stder1 >&2
28966grep -v '^ *+' $at_stder1 >$at_stderr
28967at_failed=false
28968echo stderr:; tee stderr <$at_stderr
28969$at_diff $at_devnull $at_stdout || at_failed=:
28970case $at_status in
28971   77) echo 77 > $at_status_file
28972            exit 77;;
28973   0) ;;
28974   *) echo "calc.at:586: exit code was $at_status, expected 0"
28975      at_failed=:;;
28976esac
28977if $at_failed; then
28978
28979  echo 1 > $at_status_file
28980  exit 1
28981fi
28982
28983$at_traceon
28984
28985
28986# Normalize the observed and expected error messages, depending upon the
28987# options.
28988# 1. Remove the traces from observed.
28989sed '/^Starting/d
28990/^Entering/d
28991/^Stack/d
28992/^Reading/d
28993/^Reducing/d
28994/^Shifting/d
28995/^state/d
28996/^Cleanup:/d
28997/^Error:/d
28998/^Next/d
28999/^Discarding/d
29000/ \$[0-9$]* = /d
29001/^yydestructor:/d' stderr >at-stderr
29002mv at-stderr stderr
29003# 2. Create the reference error message.
29004cat >expout <<'_ATEOF'
290051.9: syntax error, unexpected number
29006calc: error: 2222 != 1
29007_ATEOF
29008
29009# 3. If locations are not used, remove them.
29010sed 's/^[-0-9.]*: //' expout >at-expout
29011mv at-expout expout
29012# 4. If error-verbose is not used, strip the`, unexpected....' part.
29013sed 's/syntax error, .*$/syntax error/' expout >at-expout
29014mv at-expout expout
29015# 5. Check
29016$at_traceoff
29017echo "calc.at:586: cat stderr"
29018echo calc.at:586 >$at_check_line_file
29019( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
29020at_status=$?
29021grep '^ *+' $at_stder1 >&2
29022grep -v '^ *+' $at_stder1 >$at_stderr
29023at_failed=false
29024$at_diff $at_devnull $at_stderr || at_failed=:
29025$at_diff expout $at_stdout || at_failed=:
29026case $at_status in
29027   77) echo 77 > $at_status_file
29028            exit 77;;
29029   0) ;;
29030   *) echo "calc.at:586: exit code was $at_status, expected 0"
29031      at_failed=:;;
29032esac
29033if $at_failed; then
29034
29035  echo 1 > $at_status_file
29036  exit 1
29037fi
29038
29039$at_traceon
29040
29041
29042cat >input <<'_ATEOF'
29043(- *) + (0 0) = 1
29044_ATEOF
29045
29046$at_traceoff
29047echo "calc.at:586: \$PREPARSER ./calc input"
29048echo calc.at:586 >$at_check_line_file
29049( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
29050at_status=$?
29051grep '^ *+' $at_stder1 >&2
29052grep -v '^ *+' $at_stder1 >$at_stderr
29053at_failed=false
29054echo stderr:; tee stderr <$at_stderr
29055$at_diff $at_devnull $at_stdout || at_failed=:
29056case $at_status in
29057   77) echo 77 > $at_status_file
29058            exit 77;;
29059   0) ;;
29060   *) echo "calc.at:586: exit code was $at_status, expected 0"
29061      at_failed=:;;
29062esac
29063if $at_failed; then
29064
29065  echo 1 > $at_status_file
29066  exit 1
29067fi
29068
29069$at_traceon
29070
29071
29072# Normalize the observed and expected error messages, depending upon the
29073# options.
29074# 1. Remove the traces from observed.
29075sed '/^Starting/d
29076/^Entering/d
29077/^Stack/d
29078/^Reading/d
29079/^Reducing/d
29080/^Shifting/d
29081/^state/d
29082/^Cleanup:/d
29083/^Error:/d
29084/^Next/d
29085/^Discarding/d
29086/ \$[0-9$]* = /d
29087/^yydestructor:/d' stderr >at-stderr
29088mv at-stderr stderr
29089# 2. Create the reference error message.
29090cat >expout <<'_ATEOF'
290911.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
290921.11: syntax error, unexpected number
29093calc: error: 2222 != 1
29094_ATEOF
29095
29096# 3. If locations are not used, remove them.
29097sed 's/^[-0-9.]*: //' expout >at-expout
29098mv at-expout expout
29099# 4. If error-verbose is not used, strip the`, unexpected....' part.
29100sed 's/syntax error, .*$/syntax error/' expout >at-expout
29101mv at-expout expout
29102# 5. Check
29103$at_traceoff
29104echo "calc.at:586: cat stderr"
29105echo calc.at:586 >$at_check_line_file
29106( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
29107at_status=$?
29108grep '^ *+' $at_stder1 >&2
29109grep -v '^ *+' $at_stder1 >$at_stderr
29110at_failed=false
29111$at_diff $at_devnull $at_stderr || at_failed=:
29112$at_diff expout $at_stdout || at_failed=:
29113case $at_status in
29114   77) echo 77 > $at_status_file
29115            exit 77;;
29116   0) ;;
29117   *) echo "calc.at:586: exit code was $at_status, expected 0"
29118      at_failed=:;;
29119esac
29120if $at_failed; then
29121
29122  echo 1 > $at_status_file
29123  exit 1
29124fi
29125
29126$at_traceon
29127
29128
29129
29130
29131
29132
29133
29134
29135
29136
29137
29138
29139
29140
29141
29142
29143
29144
29145
29146
29147
29148
29149
29150
29151      $at_traceoff
29152      $at_times_p && times >$at_times_file
29153    ) 5>&1 2>&1 | eval $at_tee_pipe
29154    at_status=`cat $at_status_file`
29155    ;;
29156
29157  85 ) # 85. calc.at:588: Calculator %glr-parser %defines
29158    at_setup_line='calc.at:588'
29159    at_desc='Calculator %glr-parser %defines'
29160    $at_quiet $ECHO_N " 85: Calculator %glr-parser %defines              $ECHO_C"
29161    at_xfail=no
29162    (
29163      echo "85. calc.at:588: testing ..."
29164      $at_traceon
29165
29166
29167
29168
29169
29170
29171
29172
29173# Using yacc.c?
29174
29175
29176
29177
29178
29179
29180
29181# yyerror receives the location if %location & %pure & (%glr or %parse-param).
29182
29183# yyerror always sees the locations (when activated), except if
29184# yacc & pure & !param.
29185
29186
29187# The interface is pure: either because %pure-parser, or because we
29188# are using the C++ parsers.
29189
29190
29191
29192
29193
29194
29195
29196
29197
29198
29199
29200
29201cat >calc.y <<'_ATEOF'
29202%{
29203#ifdef HAVE_CONFIG_H
29204# include <config.h>
29205  /* We don't need perfect functions for these tests. */
29206# undef malloc
29207# undef memcmp
29208# undef realloc
29209#endif
29210%}
29211
29212/* Infix notation calculator--calc */
29213%glr-parser %defines
29214
29215%{
29216#include <stdio.h>
29217
29218#include <stdlib.h>
29219#include <string.h>
29220#if HAVE_UNISTD_H
29221# include <unistd.h>
29222#else
29223# undef alarm
29224# define alarm(seconds) /* empty */
29225#endif
29226#include <ctype.h>
29227#define USE(Var)
29228
29229/* Exercise pre-prologue dependency to %union.  */
29230typedef int semantic_value;
29231
29232static semantic_value global_result = 0;
29233static int global_count = 0;
29234%}
29235
29236/* Exercise %union. */
29237%union
29238{
29239  semantic_value ival;
29240};
29241
29242%{
29243static int power (int base, int exponent);
29244/* yyerror receives the location if:
29245   - %location & %pure & %glr
29246   - %location & %pure & %yacc & %parse-param. */
29247static void yyerror (
29248
29249                     const char *s
29250                     );
29251static int yylex (void);
29252static int get_char (void);
29253static void unget_char ( int c);
29254%}
29255
29256
29257
29258/* Bison Declarations */
29259%token CALC_EOF 0 "end of input"
29260%token <ival> NUM "number"
29261%type  <ival> exp
29262
29263%nonassoc '=' /* comparison	       */
29264%left '-' '+'
29265%left '*' '/'
29266%left NEG     /* negation--unary minus */
29267%right '^'    /* exponentiation        */
29268
29269/* Grammar follows */
29270%%
29271input:
29272  line
29273| input line         {  }
29274;
29275
29276line:
29277  '\n'
29278| exp '\n'           { USE ($1); }
29279;
29280
29281exp:
29282  NUM                { $$ = $1;             }
29283| exp '=' exp
29284  {
29285    if ($1 != $3)
29286      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
29287    $$ = $1;
29288  }
29289| exp '+' exp        { $$ = $1 + $3;        }
29290| exp '-' exp        { $$ = $1 - $3;        }
29291| exp '*' exp        { $$ = $1 * $3;        }
29292| exp '/' exp        { $$ = $1 / $3;        }
29293| '-' exp  %prec NEG { $$ = -$2;            }
29294| exp '^' exp        { $$ = power ($1, $3); }
29295| '(' exp ')'        { $$ = $2;             }
29296| '(' error ')'      { $$ = 1111;           }
29297| '!'                { $$ = 0; YYERROR;     }
29298| '-' error          { $$ = 0; YYERROR;     }
29299;
29300%%
29301/* The input.  */
29302static FILE *input;
29303
29304static void
29305yyerror (
29306
29307         const char *s)
29308{
29309
29310
29311  fprintf (stderr, "%s\n", s);
29312}
29313
29314
29315
29316static int
29317get_char (void)
29318{
29319  int res = getc (input);
29320  ;
29321
29322  return res;
29323}
29324
29325
29326static void
29327unget_char ( int c)
29328{
29329  ;
29330
29331  ungetc (c, input);
29332}
29333
29334static int
29335read_signed_integer (void)
29336{
29337  int c = get_char ();
29338  int sign = 1;
29339  int n = 0;
29340
29341  ;
29342  if (c == '-')
29343    {
29344      c = get_char ();
29345      sign = -1;
29346    }
29347
29348  while (isdigit (c))
29349    {
29350      n = 10 * n + (c - '0');
29351      c = get_char ();
29352    }
29353
29354  unget_char ( c);
29355
29356  return sign * n;
29357}
29358
29359
29360
29361/*---------------------------------------------------------------.
29362| Lexical analyzer returns an integer on the stack and the token |
29363| NUM, or the ASCII character read if not a number.  Skips all   |
29364| blanks and tabs, returns 0 for EOF.                            |
29365`---------------------------------------------------------------*/
29366
29367static int
29368yylex (void)
29369{
29370  static int init = 1;
29371  int c;
29372
29373  if (init)
29374    {
29375      init = 0;
29376
29377    }
29378
29379
29380
29381  /* Skip white space.  */
29382  while ((c = get_char ()) == ' ' || c == '\t')
29383    {
29384
29385    }
29386
29387  /* process numbers   */
29388  if (c == '.' || isdigit (c))
29389    {
29390      unget_char ( c);
29391      (yylval).ival = read_signed_integer ();
29392      return NUM;
29393    }
29394
29395  /* Return end-of-file.  */
29396  if (c == EOF)
29397    return CALC_EOF;
29398
29399  /* Return single chars. */
29400  return c;
29401}
29402
29403static int
29404power (int base, int exponent)
29405{
29406  int res = 1;
29407  if (exponent < 0)
29408    exit (3);
29409  for (/* Niente */; exponent; --exponent)
29410    res *= base;
29411  return res;
29412}
29413
29414
29415int
29416main (int argc, const char **argv)
29417{
29418  semantic_value result = 0;
29419  int count = 0;
29420  int status;
29421
29422  /* This used to be alarm (10), but that isn't enough time for
29423     a July 1995 vintage DEC Alphastation 200 4/100 system,
29424     according to Nelson H. F. Beebe.  100 seconds is enough.  */
29425  alarm (100);
29426
29427  if (argc == 2)
29428    input = fopen (argv[1], "r");
29429  else
29430    input = stdin;
29431
29432  if (!input)
29433    {
29434      perror (argv[1]);
29435      return 3;
29436    }
29437
29438
29439  status = yyparse ();
29440  if (global_result != result)
29441    abort ();
29442  if (global_count != count)
29443    abort ();
29444  return status;
29445}
29446_ATEOF
29447
29448
29449
29450
29451
29452$at_traceoff
29453echo "calc.at:588: bison -o calc.c calc.y"
29454echo calc.at:588 >$at_check_line_file
29455( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
29456at_status=$?
29457grep '^ *+' $at_stder1 >&2
29458grep -v '^ *+' $at_stder1 >$at_stderr
29459at_failed=false
29460$at_diff $at_devnull $at_stderr || at_failed=:
29461$at_diff $at_devnull $at_stdout || at_failed=:
29462case $at_status in
29463   77) echo 77 > $at_status_file
29464            exit 77;;
29465   0) ;;
29466   *) echo "calc.at:588: exit code was $at_status, expected 0"
29467      at_failed=:;;
29468esac
29469if $at_failed; then
29470
29471  echo 1 > $at_status_file
29472  exit 1
29473fi
29474
29475$at_traceon
29476
29477   $at_traceoff
29478echo "calc.at:588: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
29479echo calc.at:588 >$at_check_line_file
29480( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
29481at_status=$?
29482grep '^ *+' $at_stder1 >&2
29483grep -v '^ *+' $at_stder1 >$at_stderr
29484at_failed=false
29485echo stderr:; cat $at_stderr
29486echo stdout:; cat $at_stdout
29487case $at_status in
29488   77) echo 77 > $at_status_file
29489            exit 77;;
29490   0) ;;
29491   *) echo "calc.at:588: exit code was $at_status, expected 0"
29492      at_failed=:;;
29493esac
29494if $at_failed; then
29495
29496  echo 1 > $at_status_file
29497  exit 1
29498fi
29499
29500$at_traceon
29501
29502
29503# Test the priorities.
29504cat >input <<'_ATEOF'
295051 + 2 * 3 = 7
295061 + 2 * -3 = -5
29507
29508-1^2 = -1
29509(-1)^2 = 1
29510
29511---1 = -1
29512
295131 - 2 - 3 = -4
295141 - (2 - 3) = 2
29515
295162^2^3 = 256
29517(2^2)^3 = 64
29518_ATEOF
29519
29520$at_traceoff
29521echo "calc.at:588: \$PREPARSER ./calc input"
29522echo calc.at:588 >$at_check_line_file
29523( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
29524at_status=$?
29525grep '^ *+' $at_stder1 >&2
29526grep -v '^ *+' $at_stder1 >$at_stderr
29527at_failed=false
29528echo stderr:; tee stderr <$at_stderr
29529$at_diff $at_devnull $at_stdout || at_failed=:
29530case $at_status in
29531   77) echo 77 > $at_status_file
29532            exit 77;;
29533   0) ;;
29534   *) echo "calc.at:588: exit code was $at_status, expected 0"
29535      at_failed=:;;
29536esac
29537if $at_failed; then
29538
29539  echo 1 > $at_status_file
29540  exit 1
29541fi
29542
29543$at_traceon
29544
29545
29546
29547# Some syntax errors.
29548cat >input <<'_ATEOF'
295490 0
29550_ATEOF
29551
29552$at_traceoff
29553echo "calc.at:588: \$PREPARSER ./calc input"
29554echo calc.at:588 >$at_check_line_file
29555( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
29556at_status=$?
29557grep '^ *+' $at_stder1 >&2
29558grep -v '^ *+' $at_stder1 >$at_stderr
29559at_failed=false
29560echo stderr:; tee stderr <$at_stderr
29561$at_diff $at_devnull $at_stdout || at_failed=:
29562case $at_status in
29563   77) echo 77 > $at_status_file
29564            exit 77;;
29565   1) ;;
29566   *) echo "calc.at:588: exit code was $at_status, expected 1"
29567      at_failed=:;;
29568esac
29569if $at_failed; then
29570
29571  echo 1 > $at_status_file
29572  exit 1
29573fi
29574
29575$at_traceon
29576
29577
29578# Normalize the observed and expected error messages, depending upon the
29579# options.
29580# 1. Remove the traces from observed.
29581sed '/^Starting/d
29582/^Entering/d
29583/^Stack/d
29584/^Reading/d
29585/^Reducing/d
29586/^Shifting/d
29587/^state/d
29588/^Cleanup:/d
29589/^Error:/d
29590/^Next/d
29591/^Discarding/d
29592/ \$[0-9$]* = /d
29593/^yydestructor:/d' stderr >at-stderr
29594mv at-stderr stderr
29595# 2. Create the reference error message.
29596cat >expout <<'_ATEOF'
295971.2: syntax error, unexpected number
29598_ATEOF
29599
29600# 3. If locations are not used, remove them.
29601sed 's/^[-0-9.]*: //' expout >at-expout
29602mv at-expout expout
29603# 4. If error-verbose is not used, strip the`, unexpected....' part.
29604sed 's/syntax error, .*$/syntax error/' expout >at-expout
29605mv at-expout expout
29606# 5. Check
29607$at_traceoff
29608echo "calc.at:588: cat stderr"
29609echo calc.at:588 >$at_check_line_file
29610( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
29611at_status=$?
29612grep '^ *+' $at_stder1 >&2
29613grep -v '^ *+' $at_stder1 >$at_stderr
29614at_failed=false
29615$at_diff $at_devnull $at_stderr || at_failed=:
29616$at_diff expout $at_stdout || at_failed=:
29617case $at_status in
29618   77) echo 77 > $at_status_file
29619            exit 77;;
29620   0) ;;
29621   *) echo "calc.at:588: exit code was $at_status, expected 0"
29622      at_failed=:;;
29623esac
29624if $at_failed; then
29625
29626  echo 1 > $at_status_file
29627  exit 1
29628fi
29629
29630$at_traceon
29631
29632
29633cat >input <<'_ATEOF'
296341//2
29635_ATEOF
29636
29637$at_traceoff
29638echo "calc.at:588: \$PREPARSER ./calc input"
29639echo calc.at:588 >$at_check_line_file
29640( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
29641at_status=$?
29642grep '^ *+' $at_stder1 >&2
29643grep -v '^ *+' $at_stder1 >$at_stderr
29644at_failed=false
29645echo stderr:; tee stderr <$at_stderr
29646$at_diff $at_devnull $at_stdout || at_failed=:
29647case $at_status in
29648   77) echo 77 > $at_status_file
29649            exit 77;;
29650   1) ;;
29651   *) echo "calc.at:588: exit code was $at_status, expected 1"
29652      at_failed=:;;
29653esac
29654if $at_failed; then
29655
29656  echo 1 > $at_status_file
29657  exit 1
29658fi
29659
29660$at_traceon
29661
29662
29663# Normalize the observed and expected error messages, depending upon the
29664# options.
29665# 1. Remove the traces from observed.
29666sed '/^Starting/d
29667/^Entering/d
29668/^Stack/d
29669/^Reading/d
29670/^Reducing/d
29671/^Shifting/d
29672/^state/d
29673/^Cleanup:/d
29674/^Error:/d
29675/^Next/d
29676/^Discarding/d
29677/ \$[0-9$]* = /d
29678/^yydestructor:/d' stderr >at-stderr
29679mv at-stderr stderr
29680# 2. Create the reference error message.
29681cat >expout <<'_ATEOF'
296821.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
29683_ATEOF
29684
29685# 3. If locations are not used, remove them.
29686sed 's/^[-0-9.]*: //' expout >at-expout
29687mv at-expout expout
29688# 4. If error-verbose is not used, strip the`, unexpected....' part.
29689sed 's/syntax error, .*$/syntax error/' expout >at-expout
29690mv at-expout expout
29691# 5. Check
29692$at_traceoff
29693echo "calc.at:588: cat stderr"
29694echo calc.at:588 >$at_check_line_file
29695( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
29696at_status=$?
29697grep '^ *+' $at_stder1 >&2
29698grep -v '^ *+' $at_stder1 >$at_stderr
29699at_failed=false
29700$at_diff $at_devnull $at_stderr || at_failed=:
29701$at_diff expout $at_stdout || at_failed=:
29702case $at_status in
29703   77) echo 77 > $at_status_file
29704            exit 77;;
29705   0) ;;
29706   *) echo "calc.at:588: exit code was $at_status, expected 0"
29707      at_failed=:;;
29708esac
29709if $at_failed; then
29710
29711  echo 1 > $at_status_file
29712  exit 1
29713fi
29714
29715$at_traceon
29716
29717
29718cat >input <<'_ATEOF'
29719error
29720_ATEOF
29721
29722$at_traceoff
29723echo "calc.at:588: \$PREPARSER ./calc input"
29724echo calc.at:588 >$at_check_line_file
29725( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
29726at_status=$?
29727grep '^ *+' $at_stder1 >&2
29728grep -v '^ *+' $at_stder1 >$at_stderr
29729at_failed=false
29730echo stderr:; tee stderr <$at_stderr
29731$at_diff $at_devnull $at_stdout || at_failed=:
29732case $at_status in
29733   77) echo 77 > $at_status_file
29734            exit 77;;
29735   1) ;;
29736   *) echo "calc.at:588: exit code was $at_status, expected 1"
29737      at_failed=:;;
29738esac
29739if $at_failed; then
29740
29741  echo 1 > $at_status_file
29742  exit 1
29743fi
29744
29745$at_traceon
29746
29747
29748# Normalize the observed and expected error messages, depending upon the
29749# options.
29750# 1. Remove the traces from observed.
29751sed '/^Starting/d
29752/^Entering/d
29753/^Stack/d
29754/^Reading/d
29755/^Reducing/d
29756/^Shifting/d
29757/^state/d
29758/^Cleanup:/d
29759/^Error:/d
29760/^Next/d
29761/^Discarding/d
29762/ \$[0-9$]* = /d
29763/^yydestructor:/d' stderr >at-stderr
29764mv at-stderr stderr
29765# 2. Create the reference error message.
29766cat >expout <<'_ATEOF'
297671.0: syntax error, unexpected $undefined
29768_ATEOF
29769
29770# 3. If locations are not used, remove them.
29771sed 's/^[-0-9.]*: //' expout >at-expout
29772mv at-expout expout
29773# 4. If error-verbose is not used, strip the`, unexpected....' part.
29774sed 's/syntax error, .*$/syntax error/' expout >at-expout
29775mv at-expout expout
29776# 5. Check
29777$at_traceoff
29778echo "calc.at:588: cat stderr"
29779echo calc.at:588 >$at_check_line_file
29780( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
29781at_status=$?
29782grep '^ *+' $at_stder1 >&2
29783grep -v '^ *+' $at_stder1 >$at_stderr
29784at_failed=false
29785$at_diff $at_devnull $at_stderr || at_failed=:
29786$at_diff expout $at_stdout || at_failed=:
29787case $at_status in
29788   77) echo 77 > $at_status_file
29789            exit 77;;
29790   0) ;;
29791   *) echo "calc.at:588: exit code was $at_status, expected 0"
29792      at_failed=:;;
29793esac
29794if $at_failed; then
29795
29796  echo 1 > $at_status_file
29797  exit 1
29798fi
29799
29800$at_traceon
29801
29802
29803cat >input <<'_ATEOF'
298041 = 2 = 3
29805_ATEOF
29806
29807$at_traceoff
29808echo "calc.at:588: \$PREPARSER ./calc input"
29809echo calc.at:588 >$at_check_line_file
29810( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
29811at_status=$?
29812grep '^ *+' $at_stder1 >&2
29813grep -v '^ *+' $at_stder1 >$at_stderr
29814at_failed=false
29815echo stderr:; tee stderr <$at_stderr
29816$at_diff $at_devnull $at_stdout || at_failed=:
29817case $at_status in
29818   77) echo 77 > $at_status_file
29819            exit 77;;
29820   1) ;;
29821   *) echo "calc.at:588: exit code was $at_status, expected 1"
29822      at_failed=:;;
29823esac
29824if $at_failed; then
29825
29826  echo 1 > $at_status_file
29827  exit 1
29828fi
29829
29830$at_traceon
29831
29832
29833# Normalize the observed and expected error messages, depending upon the
29834# options.
29835# 1. Remove the traces from observed.
29836sed '/^Starting/d
29837/^Entering/d
29838/^Stack/d
29839/^Reading/d
29840/^Reducing/d
29841/^Shifting/d
29842/^state/d
29843/^Cleanup:/d
29844/^Error:/d
29845/^Next/d
29846/^Discarding/d
29847/ \$[0-9$]* = /d
29848/^yydestructor:/d' stderr >at-stderr
29849mv at-stderr stderr
29850# 2. Create the reference error message.
29851cat >expout <<'_ATEOF'
298521.6: syntax error, unexpected '='
29853_ATEOF
29854
29855# 3. If locations are not used, remove them.
29856sed 's/^[-0-9.]*: //' expout >at-expout
29857mv at-expout expout
29858# 4. If error-verbose is not used, strip the`, unexpected....' part.
29859sed 's/syntax error, .*$/syntax error/' expout >at-expout
29860mv at-expout expout
29861# 5. Check
29862$at_traceoff
29863echo "calc.at:588: cat stderr"
29864echo calc.at:588 >$at_check_line_file
29865( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
29866at_status=$?
29867grep '^ *+' $at_stder1 >&2
29868grep -v '^ *+' $at_stder1 >$at_stderr
29869at_failed=false
29870$at_diff $at_devnull $at_stderr || at_failed=:
29871$at_diff expout $at_stdout || at_failed=:
29872case $at_status in
29873   77) echo 77 > $at_status_file
29874            exit 77;;
29875   0) ;;
29876   *) echo "calc.at:588: exit code was $at_status, expected 0"
29877      at_failed=:;;
29878esac
29879if $at_failed; then
29880
29881  echo 1 > $at_status_file
29882  exit 1
29883fi
29884
29885$at_traceon
29886
29887
29888cat >input <<'_ATEOF'
29889
29890+1
29891_ATEOF
29892
29893$at_traceoff
29894echo "calc.at:588: \$PREPARSER ./calc input"
29895echo calc.at:588 >$at_check_line_file
29896( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
29897at_status=$?
29898grep '^ *+' $at_stder1 >&2
29899grep -v '^ *+' $at_stder1 >$at_stderr
29900at_failed=false
29901echo stderr:; tee stderr <$at_stderr
29902$at_diff $at_devnull $at_stdout || at_failed=:
29903case $at_status in
29904   77) echo 77 > $at_status_file
29905            exit 77;;
29906   1) ;;
29907   *) echo "calc.at:588: exit code was $at_status, expected 1"
29908      at_failed=:;;
29909esac
29910if $at_failed; then
29911
29912  echo 1 > $at_status_file
29913  exit 1
29914fi
29915
29916$at_traceon
29917
29918
29919# Normalize the observed and expected error messages, depending upon the
29920# options.
29921# 1. Remove the traces from observed.
29922sed '/^Starting/d
29923/^Entering/d
29924/^Stack/d
29925/^Reading/d
29926/^Reducing/d
29927/^Shifting/d
29928/^state/d
29929/^Cleanup:/d
29930/^Error:/d
29931/^Next/d
29932/^Discarding/d
29933/ \$[0-9$]* = /d
29934/^yydestructor:/d' stderr >at-stderr
29935mv at-stderr stderr
29936# 2. Create the reference error message.
29937cat >expout <<'_ATEOF'
299382.0: syntax error, unexpected '+'
29939_ATEOF
29940
29941# 3. If locations are not used, remove them.
29942sed 's/^[-0-9.]*: //' expout >at-expout
29943mv at-expout expout
29944# 4. If error-verbose is not used, strip the`, unexpected....' part.
29945sed 's/syntax error, .*$/syntax error/' expout >at-expout
29946mv at-expout expout
29947# 5. Check
29948$at_traceoff
29949echo "calc.at:588: cat stderr"
29950echo calc.at:588 >$at_check_line_file
29951( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
29952at_status=$?
29953grep '^ *+' $at_stder1 >&2
29954grep -v '^ *+' $at_stder1 >$at_stderr
29955at_failed=false
29956$at_diff $at_devnull $at_stderr || at_failed=:
29957$at_diff expout $at_stdout || at_failed=:
29958case $at_status in
29959   77) echo 77 > $at_status_file
29960            exit 77;;
29961   0) ;;
29962   *) echo "calc.at:588: exit code was $at_status, expected 0"
29963      at_failed=:;;
29964esac
29965if $at_failed; then
29966
29967  echo 1 > $at_status_file
29968  exit 1
29969fi
29970
29971$at_traceon
29972
29973
29974# Exercise error messages with EOF: work on an empty file.
29975$at_traceoff
29976echo "calc.at:588: \$PREPARSER ./calc /dev/null"
29977echo calc.at:588 >$at_check_line_file
29978( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
29979at_status=$?
29980grep '^ *+' $at_stder1 >&2
29981grep -v '^ *+' $at_stder1 >$at_stderr
29982at_failed=false
29983echo stderr:; tee stderr <$at_stderr
29984$at_diff $at_devnull $at_stdout || at_failed=:
29985case $at_status in
29986   77) echo 77 > $at_status_file
29987            exit 77;;
29988   1) ;;
29989   *) echo "calc.at:588: exit code was $at_status, expected 1"
29990      at_failed=:;;
29991esac
29992if $at_failed; then
29993
29994  echo 1 > $at_status_file
29995  exit 1
29996fi
29997
29998$at_traceon
29999
30000
30001# Normalize the observed and expected error messages, depending upon the
30002# options.
30003# 1. Remove the traces from observed.
30004sed '/^Starting/d
30005/^Entering/d
30006/^Stack/d
30007/^Reading/d
30008/^Reducing/d
30009/^Shifting/d
30010/^state/d
30011/^Cleanup:/d
30012/^Error:/d
30013/^Next/d
30014/^Discarding/d
30015/ \$[0-9$]* = /d
30016/^yydestructor:/d' stderr >at-stderr
30017mv at-stderr stderr
30018# 2. Create the reference error message.
30019cat >expout <<'_ATEOF'
300201.0: syntax error, unexpected end of input
30021_ATEOF
30022
30023# 3. If locations are not used, remove them.
30024sed 's/^[-0-9.]*: //' expout >at-expout
30025mv at-expout expout
30026# 4. If error-verbose is not used, strip the`, unexpected....' part.
30027sed 's/syntax error, .*$/syntax error/' expout >at-expout
30028mv at-expout expout
30029# 5. Check
30030$at_traceoff
30031echo "calc.at:588: cat stderr"
30032echo calc.at:588 >$at_check_line_file
30033( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
30034at_status=$?
30035grep '^ *+' $at_stder1 >&2
30036grep -v '^ *+' $at_stder1 >$at_stderr
30037at_failed=false
30038$at_diff $at_devnull $at_stderr || at_failed=:
30039$at_diff expout $at_stdout || at_failed=:
30040case $at_status in
30041   77) echo 77 > $at_status_file
30042            exit 77;;
30043   0) ;;
30044   *) echo "calc.at:588: exit code was $at_status, expected 0"
30045      at_failed=:;;
30046esac
30047if $at_failed; then
30048
30049  echo 1 > $at_status_file
30050  exit 1
30051fi
30052
30053$at_traceon
30054
30055
30056
30057# Exercise the error token: without it, we die at the first error,
30058# hence be sure to
30059#
30060# - have several errors which exercise different shift/discardings
30061#   - (): nothing to pop, nothing to discard
30062#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
30063#   - (* * *): nothing to pop, a lot to discard
30064#   - (1 + 2 * *): some to pop and discard
30065#
30066# - test the action associated to `error'
30067#
30068# - check the look-ahead that triggers an error is not discarded
30069#   when we enter error recovery.  Below, the look-ahead causing the
30070#   first error is ")", which is needed to recover from the error and
30071#   produce the "0" that triggers the "0 != 1" error.
30072#
30073cat >input <<'_ATEOF'
30074() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
30075_ATEOF
30076
30077$at_traceoff
30078echo "calc.at:588: \$PREPARSER ./calc input"
30079echo calc.at:588 >$at_check_line_file
30080( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
30081at_status=$?
30082grep '^ *+' $at_stder1 >&2
30083grep -v '^ *+' $at_stder1 >$at_stderr
30084at_failed=false
30085echo stderr:; tee stderr <$at_stderr
30086$at_diff $at_devnull $at_stdout || at_failed=:
30087case $at_status in
30088   77) echo 77 > $at_status_file
30089            exit 77;;
30090   0) ;;
30091   *) echo "calc.at:588: exit code was $at_status, expected 0"
30092      at_failed=:;;
30093esac
30094if $at_failed; then
30095
30096  echo 1 > $at_status_file
30097  exit 1
30098fi
30099
30100$at_traceon
30101
30102
30103# Normalize the observed and expected error messages, depending upon the
30104# options.
30105# 1. Remove the traces from observed.
30106sed '/^Starting/d
30107/^Entering/d
30108/^Stack/d
30109/^Reading/d
30110/^Reducing/d
30111/^Shifting/d
30112/^state/d
30113/^Cleanup:/d
30114/^Error:/d
30115/^Next/d
30116/^Discarding/d
30117/ \$[0-9$]* = /d
30118/^yydestructor:/d' stderr >at-stderr
30119mv at-stderr stderr
30120# 2. Create the reference error message.
30121cat >expout <<'_ATEOF'
301221.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
301231.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
301241.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
301251.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
30126calc: error: 4444 != 1
30127_ATEOF
30128
30129# 3. If locations are not used, remove them.
30130sed 's/^[-0-9.]*: //' expout >at-expout
30131mv at-expout expout
30132# 4. If error-verbose is not used, strip the`, unexpected....' part.
30133sed 's/syntax error, .*$/syntax error/' expout >at-expout
30134mv at-expout expout
30135# 5. Check
30136$at_traceoff
30137echo "calc.at:588: cat stderr"
30138echo calc.at:588 >$at_check_line_file
30139( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
30140at_status=$?
30141grep '^ *+' $at_stder1 >&2
30142grep -v '^ *+' $at_stder1 >$at_stderr
30143at_failed=false
30144$at_diff $at_devnull $at_stderr || at_failed=:
30145$at_diff expout $at_stdout || at_failed=:
30146case $at_status in
30147   77) echo 77 > $at_status_file
30148            exit 77;;
30149   0) ;;
30150   *) echo "calc.at:588: exit code was $at_status, expected 0"
30151      at_failed=:;;
30152esac
30153if $at_failed; then
30154
30155  echo 1 > $at_status_file
30156  exit 1
30157fi
30158
30159$at_traceon
30160
30161
30162
30163# The same, but this time exercising explicitly triggered syntax errors.
30164# POSIX says the look-ahead causing the error should not be discarded.
30165cat >input <<'_ATEOF'
30166(!) + (0 0) = 1
30167_ATEOF
30168
30169$at_traceoff
30170echo "calc.at:588: \$PREPARSER ./calc input"
30171echo calc.at:588 >$at_check_line_file
30172( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
30173at_status=$?
30174grep '^ *+' $at_stder1 >&2
30175grep -v '^ *+' $at_stder1 >$at_stderr
30176at_failed=false
30177echo stderr:; tee stderr <$at_stderr
30178$at_diff $at_devnull $at_stdout || at_failed=:
30179case $at_status in
30180   77) echo 77 > $at_status_file
30181            exit 77;;
30182   0) ;;
30183   *) echo "calc.at:588: exit code was $at_status, expected 0"
30184      at_failed=:;;
30185esac
30186if $at_failed; then
30187
30188  echo 1 > $at_status_file
30189  exit 1
30190fi
30191
30192$at_traceon
30193
30194
30195# Normalize the observed and expected error messages, depending upon the
30196# options.
30197# 1. Remove the traces from observed.
30198sed '/^Starting/d
30199/^Entering/d
30200/^Stack/d
30201/^Reading/d
30202/^Reducing/d
30203/^Shifting/d
30204/^state/d
30205/^Cleanup:/d
30206/^Error:/d
30207/^Next/d
30208/^Discarding/d
30209/ \$[0-9$]* = /d
30210/^yydestructor:/d' stderr >at-stderr
30211mv at-stderr stderr
30212# 2. Create the reference error message.
30213cat >expout <<'_ATEOF'
302141.9: syntax error, unexpected number
30215calc: error: 2222 != 1
30216_ATEOF
30217
30218# 3. If locations are not used, remove them.
30219sed 's/^[-0-9.]*: //' expout >at-expout
30220mv at-expout expout
30221# 4. If error-verbose is not used, strip the`, unexpected....' part.
30222sed 's/syntax error, .*$/syntax error/' expout >at-expout
30223mv at-expout expout
30224# 5. Check
30225$at_traceoff
30226echo "calc.at:588: cat stderr"
30227echo calc.at:588 >$at_check_line_file
30228( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
30229at_status=$?
30230grep '^ *+' $at_stder1 >&2
30231grep -v '^ *+' $at_stder1 >$at_stderr
30232at_failed=false
30233$at_diff $at_devnull $at_stderr || at_failed=:
30234$at_diff expout $at_stdout || at_failed=:
30235case $at_status in
30236   77) echo 77 > $at_status_file
30237            exit 77;;
30238   0) ;;
30239   *) echo "calc.at:588: exit code was $at_status, expected 0"
30240      at_failed=:;;
30241esac
30242if $at_failed; then
30243
30244  echo 1 > $at_status_file
30245  exit 1
30246fi
30247
30248$at_traceon
30249
30250
30251cat >input <<'_ATEOF'
30252(- *) + (0 0) = 1
30253_ATEOF
30254
30255$at_traceoff
30256echo "calc.at:588: \$PREPARSER ./calc input"
30257echo calc.at:588 >$at_check_line_file
30258( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
30259at_status=$?
30260grep '^ *+' $at_stder1 >&2
30261grep -v '^ *+' $at_stder1 >$at_stderr
30262at_failed=false
30263echo stderr:; tee stderr <$at_stderr
30264$at_diff $at_devnull $at_stdout || at_failed=:
30265case $at_status in
30266   77) echo 77 > $at_status_file
30267            exit 77;;
30268   0) ;;
30269   *) echo "calc.at:588: exit code was $at_status, expected 0"
30270      at_failed=:;;
30271esac
30272if $at_failed; then
30273
30274  echo 1 > $at_status_file
30275  exit 1
30276fi
30277
30278$at_traceon
30279
30280
30281# Normalize the observed and expected error messages, depending upon the
30282# options.
30283# 1. Remove the traces from observed.
30284sed '/^Starting/d
30285/^Entering/d
30286/^Stack/d
30287/^Reading/d
30288/^Reducing/d
30289/^Shifting/d
30290/^state/d
30291/^Cleanup:/d
30292/^Error:/d
30293/^Next/d
30294/^Discarding/d
30295/ \$[0-9$]* = /d
30296/^yydestructor:/d' stderr >at-stderr
30297mv at-stderr stderr
30298# 2. Create the reference error message.
30299cat >expout <<'_ATEOF'
303001.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
303011.11: syntax error, unexpected number
30302calc: error: 2222 != 1
30303_ATEOF
30304
30305# 3. If locations are not used, remove them.
30306sed 's/^[-0-9.]*: //' expout >at-expout
30307mv at-expout expout
30308# 4. If error-verbose is not used, strip the`, unexpected....' part.
30309sed 's/syntax error, .*$/syntax error/' expout >at-expout
30310mv at-expout expout
30311# 5. Check
30312$at_traceoff
30313echo "calc.at:588: cat stderr"
30314echo calc.at:588 >$at_check_line_file
30315( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
30316at_status=$?
30317grep '^ *+' $at_stder1 >&2
30318grep -v '^ *+' $at_stder1 >$at_stderr
30319at_failed=false
30320$at_diff $at_devnull $at_stderr || at_failed=:
30321$at_diff expout $at_stdout || at_failed=:
30322case $at_status in
30323   77) echo 77 > $at_status_file
30324            exit 77;;
30325   0) ;;
30326   *) echo "calc.at:588: exit code was $at_status, expected 0"
30327      at_failed=:;;
30328esac
30329if $at_failed; then
30330
30331  echo 1 > $at_status_file
30332  exit 1
30333fi
30334
30335$at_traceon
30336
30337
30338
30339
30340
30341
30342
30343
30344
30345
30346
30347
30348
30349
30350
30351
30352
30353
30354
30355
30356
30357
30358
30359
30360      $at_traceoff
30361      $at_times_p && times >$at_times_file
30362    ) 5>&1 2>&1 | eval $at_tee_pipe
30363    at_status=`cat $at_status_file`
30364    ;;
30365
30366  86 ) # 86. calc.at:589: Calculator %glr-parser %locations
30367    at_setup_line='calc.at:589'
30368    at_desc='Calculator %glr-parser %locations'
30369    $at_quiet $ECHO_N " 86: Calculator %glr-parser %locations            $ECHO_C"
30370    at_xfail=no
30371    (
30372      echo "86. calc.at:589: testing ..."
30373      $at_traceon
30374
30375
30376
30377
30378
30379
30380
30381
30382# Using yacc.c?
30383
30384
30385
30386
30387
30388
30389
30390# yyerror receives the location if %location & %pure & (%glr or %parse-param).
30391
30392# yyerror always sees the locations (when activated), except if
30393# yacc & pure & !param.
30394
30395
30396# The interface is pure: either because %pure-parser, or because we
30397# are using the C++ parsers.
30398
30399
30400
30401
30402
30403
30404
30405
30406
30407
30408
30409
30410cat >calc.y <<'_ATEOF'
30411%{
30412#ifdef HAVE_CONFIG_H
30413# include <config.h>
30414  /* We don't need perfect functions for these tests. */
30415# undef malloc
30416# undef memcmp
30417# undef realloc
30418#endif
30419%}
30420
30421/* Infix notation calculator--calc */
30422%glr-parser %locations
30423
30424%{
30425#include <stdio.h>
30426
30427#include <stdlib.h>
30428#include <string.h>
30429#if HAVE_UNISTD_H
30430# include <unistd.h>
30431#else
30432# undef alarm
30433# define alarm(seconds) /* empty */
30434#endif
30435#include <ctype.h>
30436#define USE(Var)
30437
30438/* Exercise pre-prologue dependency to %union.  */
30439typedef int semantic_value;
30440
30441static semantic_value global_result = 0;
30442static int global_count = 0;
30443%}
30444
30445/* Exercise %union. */
30446%union
30447{
30448  semantic_value ival;
30449};
30450
30451%{
30452static int power (int base, int exponent);
30453/* yyerror receives the location if:
30454   - %location & %pure & %glr
30455   - %location & %pure & %yacc & %parse-param. */
30456static void yyerror (
30457
30458                     const char *s
30459                     );
30460static int yylex (void);
30461static int get_char (void);
30462static void unget_char ( int c);
30463%}
30464
30465
30466
30467/* Bison Declarations */
30468%token CALC_EOF 0 "end of input"
30469%token <ival> NUM "number"
30470%type  <ival> exp
30471
30472%nonassoc '=' /* comparison	       */
30473%left '-' '+'
30474%left '*' '/'
30475%left NEG     /* negation--unary minus */
30476%right '^'    /* exponentiation        */
30477
30478/* Grammar follows */
30479%%
30480input:
30481  line
30482| input line         {  }
30483;
30484
30485line:
30486  '\n'
30487| exp '\n'           { USE ($1); }
30488;
30489
30490exp:
30491  NUM                { $$ = $1;             }
30492| exp '=' exp
30493  {
30494    if ($1 != $3)
30495      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
30496    $$ = $1;
30497  }
30498| exp '+' exp        { $$ = $1 + $3;        }
30499| exp '-' exp        { $$ = $1 - $3;        }
30500| exp '*' exp        { $$ = $1 * $3;        }
30501| exp '/' exp        { $$ = $1 / $3;        }
30502| '-' exp  %prec NEG { $$ = -$2;            }
30503| exp '^' exp        { $$ = power ($1, $3); }
30504| '(' exp ')'        { $$ = $2;             }
30505| '(' error ')'      { $$ = 1111;           }
30506| '!'                { $$ = 0; YYERROR;     }
30507| '-' error          { $$ = 0; YYERROR;     }
30508;
30509%%
30510/* The input.  */
30511static FILE *input;
30512
30513static void
30514yyerror (
30515
30516         const char *s)
30517{
30518
30519
30520  fprintf (stderr, "%d.%d",
30521           (yylloc).first_line, (yylloc).first_column);
30522  if ((yylloc).first_line != (yylloc).last_line)
30523    fprintf (stderr, "-%d.%d",
30524	     (yylloc).last_line,  (yylloc).last_column - 1);
30525  else if ((yylloc).first_column != (yylloc).last_column - 1)
30526    fprintf (stderr, "-%d",
30527	     (yylloc).last_column - 1);
30528  fprintf (stderr, ": ");
30529  fprintf (stderr, "%s\n", s);
30530}
30531
30532
30533
30534static YYLTYPE last_yylloc;
30535
30536static int
30537get_char (void)
30538{
30539  int res = getc (input);
30540  ;
30541
30542  last_yylloc = (yylloc);
30543  if (res == '\n')
30544    {
30545      (yylloc).last_line++;
30546      (yylloc).last_column = 0;
30547    }
30548  else
30549    (yylloc).last_column++;
30550
30551  return res;
30552}
30553
30554
30555static void
30556unget_char ( int c)
30557{
30558  ;
30559
30560  /* Wrong when C == `\n'. */
30561  (yylloc) = last_yylloc;
30562
30563  ungetc (c, input);
30564}
30565
30566static int
30567read_signed_integer (void)
30568{
30569  int c = get_char ();
30570  int sign = 1;
30571  int n = 0;
30572
30573  ;
30574  if (c == '-')
30575    {
30576      c = get_char ();
30577      sign = -1;
30578    }
30579
30580  while (isdigit (c))
30581    {
30582      n = 10 * n + (c - '0');
30583      c = get_char ();
30584    }
30585
30586  unget_char ( c);
30587
30588  return sign * n;
30589}
30590
30591
30592
30593/*---------------------------------------------------------------.
30594| Lexical analyzer returns an integer on the stack and the token |
30595| NUM, or the ASCII character read if not a number.  Skips all   |
30596| blanks and tabs, returns 0 for EOF.                            |
30597`---------------------------------------------------------------*/
30598
30599static int
30600yylex (void)
30601{
30602  static int init = 1;
30603  int c;
30604
30605  if (init)
30606    {
30607      init = 0;
30608
30609      (yylloc).last_column = 0;
30610      (yylloc).last_line = 1;
30611
30612    }
30613
30614
30615 (yylloc).first_column = (yylloc).last_column;
30616  (yylloc).first_line   = (yylloc).last_line;
30617
30618
30619  /* Skip white space.  */
30620  while ((c = get_char ()) == ' ' || c == '\t')
30621    {
30622     (yylloc).first_column = (yylloc).last_column;
30623      (yylloc).first_line   = (yylloc).last_line;
30624
30625    }
30626
30627  /* process numbers   */
30628  if (c == '.' || isdigit (c))
30629    {
30630      unget_char ( c);
30631      (yylval).ival = read_signed_integer ();
30632      return NUM;
30633    }
30634
30635  /* Return end-of-file.  */
30636  if (c == EOF)
30637    return CALC_EOF;
30638
30639  /* Return single chars. */
30640  return c;
30641}
30642
30643static int
30644power (int base, int exponent)
30645{
30646  int res = 1;
30647  if (exponent < 0)
30648    exit (3);
30649  for (/* Niente */; exponent; --exponent)
30650    res *= base;
30651  return res;
30652}
30653
30654
30655int
30656main (int argc, const char **argv)
30657{
30658  semantic_value result = 0;
30659  int count = 0;
30660  int status;
30661
30662  /* This used to be alarm (10), but that isn't enough time for
30663     a July 1995 vintage DEC Alphastation 200 4/100 system,
30664     according to Nelson H. F. Beebe.  100 seconds is enough.  */
30665  alarm (100);
30666
30667  if (argc == 2)
30668    input = fopen (argv[1], "r");
30669  else
30670    input = stdin;
30671
30672  if (!input)
30673    {
30674      perror (argv[1]);
30675      return 3;
30676    }
30677
30678
30679  status = yyparse ();
30680  if (global_result != result)
30681    abort ();
30682  if (global_count != count)
30683    abort ();
30684  return status;
30685}
30686_ATEOF
30687
30688
30689
30690
30691
30692$at_traceoff
30693echo "calc.at:589: bison -o calc.c calc.y"
30694echo calc.at:589 >$at_check_line_file
30695( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
30696at_status=$?
30697grep '^ *+' $at_stder1 >&2
30698grep -v '^ *+' $at_stder1 >$at_stderr
30699at_failed=false
30700$at_diff $at_devnull $at_stderr || at_failed=:
30701$at_diff $at_devnull $at_stdout || at_failed=:
30702case $at_status in
30703   77) echo 77 > $at_status_file
30704            exit 77;;
30705   0) ;;
30706   *) echo "calc.at:589: exit code was $at_status, expected 0"
30707      at_failed=:;;
30708esac
30709if $at_failed; then
30710
30711  echo 1 > $at_status_file
30712  exit 1
30713fi
30714
30715$at_traceon
30716
30717   $at_traceoff
30718echo "calc.at:589: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
30719echo calc.at:589 >$at_check_line_file
30720( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
30721at_status=$?
30722grep '^ *+' $at_stder1 >&2
30723grep -v '^ *+' $at_stder1 >$at_stderr
30724at_failed=false
30725echo stderr:; cat $at_stderr
30726echo stdout:; cat $at_stdout
30727case $at_status in
30728   77) echo 77 > $at_status_file
30729            exit 77;;
30730   0) ;;
30731   *) echo "calc.at:589: exit code was $at_status, expected 0"
30732      at_failed=:;;
30733esac
30734if $at_failed; then
30735
30736  echo 1 > $at_status_file
30737  exit 1
30738fi
30739
30740$at_traceon
30741
30742
30743# Test the priorities.
30744cat >input <<'_ATEOF'
307451 + 2 * 3 = 7
307461 + 2 * -3 = -5
30747
30748-1^2 = -1
30749(-1)^2 = 1
30750
30751---1 = -1
30752
307531 - 2 - 3 = -4
307541 - (2 - 3) = 2
30755
307562^2^3 = 256
30757(2^2)^3 = 64
30758_ATEOF
30759
30760$at_traceoff
30761echo "calc.at:589: \$PREPARSER ./calc input"
30762echo calc.at:589 >$at_check_line_file
30763( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
30764at_status=$?
30765grep '^ *+' $at_stder1 >&2
30766grep -v '^ *+' $at_stder1 >$at_stderr
30767at_failed=false
30768echo stderr:; tee stderr <$at_stderr
30769$at_diff $at_devnull $at_stdout || at_failed=:
30770case $at_status in
30771   77) echo 77 > $at_status_file
30772            exit 77;;
30773   0) ;;
30774   *) echo "calc.at:589: exit code was $at_status, expected 0"
30775      at_failed=:;;
30776esac
30777if $at_failed; then
30778
30779  echo 1 > $at_status_file
30780  exit 1
30781fi
30782
30783$at_traceon
30784
30785
30786
30787# Some syntax errors.
30788cat >input <<'_ATEOF'
307890 0
30790_ATEOF
30791
30792$at_traceoff
30793echo "calc.at:589: \$PREPARSER ./calc input"
30794echo calc.at:589 >$at_check_line_file
30795( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
30796at_status=$?
30797grep '^ *+' $at_stder1 >&2
30798grep -v '^ *+' $at_stder1 >$at_stderr
30799at_failed=false
30800echo stderr:; tee stderr <$at_stderr
30801$at_diff $at_devnull $at_stdout || at_failed=:
30802case $at_status in
30803   77) echo 77 > $at_status_file
30804            exit 77;;
30805   1) ;;
30806   *) echo "calc.at:589: exit code was $at_status, expected 1"
30807      at_failed=:;;
30808esac
30809if $at_failed; then
30810
30811  echo 1 > $at_status_file
30812  exit 1
30813fi
30814
30815$at_traceon
30816
30817
30818# Normalize the observed and expected error messages, depending upon the
30819# options.
30820# 1. Remove the traces from observed.
30821sed '/^Starting/d
30822/^Entering/d
30823/^Stack/d
30824/^Reading/d
30825/^Reducing/d
30826/^Shifting/d
30827/^state/d
30828/^Cleanup:/d
30829/^Error:/d
30830/^Next/d
30831/^Discarding/d
30832/ \$[0-9$]* = /d
30833/^yydestructor:/d' stderr >at-stderr
30834mv at-stderr stderr
30835# 2. Create the reference error message.
30836cat >expout <<'_ATEOF'
308371.2: syntax error, unexpected number
30838_ATEOF
30839
30840# 3. If locations are not used, remove them.
30841
30842# 4. If error-verbose is not used, strip the`, unexpected....' part.
30843sed 's/syntax error, .*$/syntax error/' expout >at-expout
30844mv at-expout expout
30845# 5. Check
30846$at_traceoff
30847echo "calc.at:589: cat stderr"
30848echo calc.at:589 >$at_check_line_file
30849( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
30850at_status=$?
30851grep '^ *+' $at_stder1 >&2
30852grep -v '^ *+' $at_stder1 >$at_stderr
30853at_failed=false
30854$at_diff $at_devnull $at_stderr || at_failed=:
30855$at_diff expout $at_stdout || at_failed=:
30856case $at_status in
30857   77) echo 77 > $at_status_file
30858            exit 77;;
30859   0) ;;
30860   *) echo "calc.at:589: exit code was $at_status, expected 0"
30861      at_failed=:;;
30862esac
30863if $at_failed; then
30864
30865  echo 1 > $at_status_file
30866  exit 1
30867fi
30868
30869$at_traceon
30870
30871
30872cat >input <<'_ATEOF'
308731//2
30874_ATEOF
30875
30876$at_traceoff
30877echo "calc.at:589: \$PREPARSER ./calc input"
30878echo calc.at:589 >$at_check_line_file
30879( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
30880at_status=$?
30881grep '^ *+' $at_stder1 >&2
30882grep -v '^ *+' $at_stder1 >$at_stderr
30883at_failed=false
30884echo stderr:; tee stderr <$at_stderr
30885$at_diff $at_devnull $at_stdout || at_failed=:
30886case $at_status in
30887   77) echo 77 > $at_status_file
30888            exit 77;;
30889   1) ;;
30890   *) echo "calc.at:589: exit code was $at_status, expected 1"
30891      at_failed=:;;
30892esac
30893if $at_failed; then
30894
30895  echo 1 > $at_status_file
30896  exit 1
30897fi
30898
30899$at_traceon
30900
30901
30902# Normalize the observed and expected error messages, depending upon the
30903# options.
30904# 1. Remove the traces from observed.
30905sed '/^Starting/d
30906/^Entering/d
30907/^Stack/d
30908/^Reading/d
30909/^Reducing/d
30910/^Shifting/d
30911/^state/d
30912/^Cleanup:/d
30913/^Error:/d
30914/^Next/d
30915/^Discarding/d
30916/ \$[0-9$]* = /d
30917/^yydestructor:/d' stderr >at-stderr
30918mv at-stderr stderr
30919# 2. Create the reference error message.
30920cat >expout <<'_ATEOF'
309211.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
30922_ATEOF
30923
30924# 3. If locations are not used, remove them.
30925
30926# 4. If error-verbose is not used, strip the`, unexpected....' part.
30927sed 's/syntax error, .*$/syntax error/' expout >at-expout
30928mv at-expout expout
30929# 5. Check
30930$at_traceoff
30931echo "calc.at:589: cat stderr"
30932echo calc.at:589 >$at_check_line_file
30933( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
30934at_status=$?
30935grep '^ *+' $at_stder1 >&2
30936grep -v '^ *+' $at_stder1 >$at_stderr
30937at_failed=false
30938$at_diff $at_devnull $at_stderr || at_failed=:
30939$at_diff expout $at_stdout || at_failed=:
30940case $at_status in
30941   77) echo 77 > $at_status_file
30942            exit 77;;
30943   0) ;;
30944   *) echo "calc.at:589: exit code was $at_status, expected 0"
30945      at_failed=:;;
30946esac
30947if $at_failed; then
30948
30949  echo 1 > $at_status_file
30950  exit 1
30951fi
30952
30953$at_traceon
30954
30955
30956cat >input <<'_ATEOF'
30957error
30958_ATEOF
30959
30960$at_traceoff
30961echo "calc.at:589: \$PREPARSER ./calc input"
30962echo calc.at:589 >$at_check_line_file
30963( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
30964at_status=$?
30965grep '^ *+' $at_stder1 >&2
30966grep -v '^ *+' $at_stder1 >$at_stderr
30967at_failed=false
30968echo stderr:; tee stderr <$at_stderr
30969$at_diff $at_devnull $at_stdout || at_failed=:
30970case $at_status in
30971   77) echo 77 > $at_status_file
30972            exit 77;;
30973   1) ;;
30974   *) echo "calc.at:589: exit code was $at_status, expected 1"
30975      at_failed=:;;
30976esac
30977if $at_failed; then
30978
30979  echo 1 > $at_status_file
30980  exit 1
30981fi
30982
30983$at_traceon
30984
30985
30986# Normalize the observed and expected error messages, depending upon the
30987# options.
30988# 1. Remove the traces from observed.
30989sed '/^Starting/d
30990/^Entering/d
30991/^Stack/d
30992/^Reading/d
30993/^Reducing/d
30994/^Shifting/d
30995/^state/d
30996/^Cleanup:/d
30997/^Error:/d
30998/^Next/d
30999/^Discarding/d
31000/ \$[0-9$]* = /d
31001/^yydestructor:/d' stderr >at-stderr
31002mv at-stderr stderr
31003# 2. Create the reference error message.
31004cat >expout <<'_ATEOF'
310051.0: syntax error, unexpected $undefined
31006_ATEOF
31007
31008# 3. If locations are not used, remove them.
31009
31010# 4. If error-verbose is not used, strip the`, unexpected....' part.
31011sed 's/syntax error, .*$/syntax error/' expout >at-expout
31012mv at-expout expout
31013# 5. Check
31014$at_traceoff
31015echo "calc.at:589: cat stderr"
31016echo calc.at:589 >$at_check_line_file
31017( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
31018at_status=$?
31019grep '^ *+' $at_stder1 >&2
31020grep -v '^ *+' $at_stder1 >$at_stderr
31021at_failed=false
31022$at_diff $at_devnull $at_stderr || at_failed=:
31023$at_diff expout $at_stdout || at_failed=:
31024case $at_status in
31025   77) echo 77 > $at_status_file
31026            exit 77;;
31027   0) ;;
31028   *) echo "calc.at:589: exit code was $at_status, expected 0"
31029      at_failed=:;;
31030esac
31031if $at_failed; then
31032
31033  echo 1 > $at_status_file
31034  exit 1
31035fi
31036
31037$at_traceon
31038
31039
31040cat >input <<'_ATEOF'
310411 = 2 = 3
31042_ATEOF
31043
31044$at_traceoff
31045echo "calc.at:589: \$PREPARSER ./calc input"
31046echo calc.at:589 >$at_check_line_file
31047( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
31048at_status=$?
31049grep '^ *+' $at_stder1 >&2
31050grep -v '^ *+' $at_stder1 >$at_stderr
31051at_failed=false
31052echo stderr:; tee stderr <$at_stderr
31053$at_diff $at_devnull $at_stdout || at_failed=:
31054case $at_status in
31055   77) echo 77 > $at_status_file
31056            exit 77;;
31057   1) ;;
31058   *) echo "calc.at:589: exit code was $at_status, expected 1"
31059      at_failed=:;;
31060esac
31061if $at_failed; then
31062
31063  echo 1 > $at_status_file
31064  exit 1
31065fi
31066
31067$at_traceon
31068
31069
31070# Normalize the observed and expected error messages, depending upon the
31071# options.
31072# 1. Remove the traces from observed.
31073sed '/^Starting/d
31074/^Entering/d
31075/^Stack/d
31076/^Reading/d
31077/^Reducing/d
31078/^Shifting/d
31079/^state/d
31080/^Cleanup:/d
31081/^Error:/d
31082/^Next/d
31083/^Discarding/d
31084/ \$[0-9$]* = /d
31085/^yydestructor:/d' stderr >at-stderr
31086mv at-stderr stderr
31087# 2. Create the reference error message.
31088cat >expout <<'_ATEOF'
310891.6: syntax error, unexpected '='
31090_ATEOF
31091
31092# 3. If locations are not used, remove them.
31093
31094# 4. If error-verbose is not used, strip the`, unexpected....' part.
31095sed 's/syntax error, .*$/syntax error/' expout >at-expout
31096mv at-expout expout
31097# 5. Check
31098$at_traceoff
31099echo "calc.at:589: cat stderr"
31100echo calc.at:589 >$at_check_line_file
31101( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
31102at_status=$?
31103grep '^ *+' $at_stder1 >&2
31104grep -v '^ *+' $at_stder1 >$at_stderr
31105at_failed=false
31106$at_diff $at_devnull $at_stderr || at_failed=:
31107$at_diff expout $at_stdout || at_failed=:
31108case $at_status in
31109   77) echo 77 > $at_status_file
31110            exit 77;;
31111   0) ;;
31112   *) echo "calc.at:589: exit code was $at_status, expected 0"
31113      at_failed=:;;
31114esac
31115if $at_failed; then
31116
31117  echo 1 > $at_status_file
31118  exit 1
31119fi
31120
31121$at_traceon
31122
31123
31124cat >input <<'_ATEOF'
31125
31126+1
31127_ATEOF
31128
31129$at_traceoff
31130echo "calc.at:589: \$PREPARSER ./calc input"
31131echo calc.at:589 >$at_check_line_file
31132( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
31133at_status=$?
31134grep '^ *+' $at_stder1 >&2
31135grep -v '^ *+' $at_stder1 >$at_stderr
31136at_failed=false
31137echo stderr:; tee stderr <$at_stderr
31138$at_diff $at_devnull $at_stdout || at_failed=:
31139case $at_status in
31140   77) echo 77 > $at_status_file
31141            exit 77;;
31142   1) ;;
31143   *) echo "calc.at:589: exit code was $at_status, expected 1"
31144      at_failed=:;;
31145esac
31146if $at_failed; then
31147
31148  echo 1 > $at_status_file
31149  exit 1
31150fi
31151
31152$at_traceon
31153
31154
31155# Normalize the observed and expected error messages, depending upon the
31156# options.
31157# 1. Remove the traces from observed.
31158sed '/^Starting/d
31159/^Entering/d
31160/^Stack/d
31161/^Reading/d
31162/^Reducing/d
31163/^Shifting/d
31164/^state/d
31165/^Cleanup:/d
31166/^Error:/d
31167/^Next/d
31168/^Discarding/d
31169/ \$[0-9$]* = /d
31170/^yydestructor:/d' stderr >at-stderr
31171mv at-stderr stderr
31172# 2. Create the reference error message.
31173cat >expout <<'_ATEOF'
311742.0: syntax error, unexpected '+'
31175_ATEOF
31176
31177# 3. If locations are not used, remove them.
31178
31179# 4. If error-verbose is not used, strip the`, unexpected....' part.
31180sed 's/syntax error, .*$/syntax error/' expout >at-expout
31181mv at-expout expout
31182# 5. Check
31183$at_traceoff
31184echo "calc.at:589: cat stderr"
31185echo calc.at:589 >$at_check_line_file
31186( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
31187at_status=$?
31188grep '^ *+' $at_stder1 >&2
31189grep -v '^ *+' $at_stder1 >$at_stderr
31190at_failed=false
31191$at_diff $at_devnull $at_stderr || at_failed=:
31192$at_diff expout $at_stdout || at_failed=:
31193case $at_status in
31194   77) echo 77 > $at_status_file
31195            exit 77;;
31196   0) ;;
31197   *) echo "calc.at:589: exit code was $at_status, expected 0"
31198      at_failed=:;;
31199esac
31200if $at_failed; then
31201
31202  echo 1 > $at_status_file
31203  exit 1
31204fi
31205
31206$at_traceon
31207
31208
31209# Exercise error messages with EOF: work on an empty file.
31210$at_traceoff
31211echo "calc.at:589: \$PREPARSER ./calc /dev/null"
31212echo calc.at:589 >$at_check_line_file
31213( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
31214at_status=$?
31215grep '^ *+' $at_stder1 >&2
31216grep -v '^ *+' $at_stder1 >$at_stderr
31217at_failed=false
31218echo stderr:; tee stderr <$at_stderr
31219$at_diff $at_devnull $at_stdout || at_failed=:
31220case $at_status in
31221   77) echo 77 > $at_status_file
31222            exit 77;;
31223   1) ;;
31224   *) echo "calc.at:589: exit code was $at_status, expected 1"
31225      at_failed=:;;
31226esac
31227if $at_failed; then
31228
31229  echo 1 > $at_status_file
31230  exit 1
31231fi
31232
31233$at_traceon
31234
31235
31236# Normalize the observed and expected error messages, depending upon the
31237# options.
31238# 1. Remove the traces from observed.
31239sed '/^Starting/d
31240/^Entering/d
31241/^Stack/d
31242/^Reading/d
31243/^Reducing/d
31244/^Shifting/d
31245/^state/d
31246/^Cleanup:/d
31247/^Error:/d
31248/^Next/d
31249/^Discarding/d
31250/ \$[0-9$]* = /d
31251/^yydestructor:/d' stderr >at-stderr
31252mv at-stderr stderr
31253# 2. Create the reference error message.
31254cat >expout <<'_ATEOF'
312551.0: syntax error, unexpected end of input
31256_ATEOF
31257
31258# 3. If locations are not used, remove them.
31259
31260# 4. If error-verbose is not used, strip the`, unexpected....' part.
31261sed 's/syntax error, .*$/syntax error/' expout >at-expout
31262mv at-expout expout
31263# 5. Check
31264$at_traceoff
31265echo "calc.at:589: cat stderr"
31266echo calc.at:589 >$at_check_line_file
31267( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
31268at_status=$?
31269grep '^ *+' $at_stder1 >&2
31270grep -v '^ *+' $at_stder1 >$at_stderr
31271at_failed=false
31272$at_diff $at_devnull $at_stderr || at_failed=:
31273$at_diff expout $at_stdout || at_failed=:
31274case $at_status in
31275   77) echo 77 > $at_status_file
31276            exit 77;;
31277   0) ;;
31278   *) echo "calc.at:589: exit code was $at_status, expected 0"
31279      at_failed=:;;
31280esac
31281if $at_failed; then
31282
31283  echo 1 > $at_status_file
31284  exit 1
31285fi
31286
31287$at_traceon
31288
31289
31290
31291# Exercise the error token: without it, we die at the first error,
31292# hence be sure to
31293#
31294# - have several errors which exercise different shift/discardings
31295#   - (): nothing to pop, nothing to discard
31296#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
31297#   - (* * *): nothing to pop, a lot to discard
31298#   - (1 + 2 * *): some to pop and discard
31299#
31300# - test the action associated to `error'
31301#
31302# - check the look-ahead that triggers an error is not discarded
31303#   when we enter error recovery.  Below, the look-ahead causing the
31304#   first error is ")", which is needed to recover from the error and
31305#   produce the "0" that triggers the "0 != 1" error.
31306#
31307cat >input <<'_ATEOF'
31308() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
31309_ATEOF
31310
31311$at_traceoff
31312echo "calc.at:589: \$PREPARSER ./calc input"
31313echo calc.at:589 >$at_check_line_file
31314( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
31315at_status=$?
31316grep '^ *+' $at_stder1 >&2
31317grep -v '^ *+' $at_stder1 >$at_stderr
31318at_failed=false
31319echo stderr:; tee stderr <$at_stderr
31320$at_diff $at_devnull $at_stdout || at_failed=:
31321case $at_status in
31322   77) echo 77 > $at_status_file
31323            exit 77;;
31324   0) ;;
31325   *) echo "calc.at:589: exit code was $at_status, expected 0"
31326      at_failed=:;;
31327esac
31328if $at_failed; then
31329
31330  echo 1 > $at_status_file
31331  exit 1
31332fi
31333
31334$at_traceon
31335
31336
31337# Normalize the observed and expected error messages, depending upon the
31338# options.
31339# 1. Remove the traces from observed.
31340sed '/^Starting/d
31341/^Entering/d
31342/^Stack/d
31343/^Reading/d
31344/^Reducing/d
31345/^Shifting/d
31346/^state/d
31347/^Cleanup:/d
31348/^Error:/d
31349/^Next/d
31350/^Discarding/d
31351/ \$[0-9$]* = /d
31352/^yydestructor:/d' stderr >at-stderr
31353mv at-stderr stderr
31354# 2. Create the reference error message.
31355cat >expout <<'_ATEOF'
313561.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
313571.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
313581.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
313591.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
31360calc: error: 4444 != 1
31361_ATEOF
31362
31363# 3. If locations are not used, remove them.
31364
31365# 4. If error-verbose is not used, strip the`, unexpected....' part.
31366sed 's/syntax error, .*$/syntax error/' expout >at-expout
31367mv at-expout expout
31368# 5. Check
31369$at_traceoff
31370echo "calc.at:589: cat stderr"
31371echo calc.at:589 >$at_check_line_file
31372( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
31373at_status=$?
31374grep '^ *+' $at_stder1 >&2
31375grep -v '^ *+' $at_stder1 >$at_stderr
31376at_failed=false
31377$at_diff $at_devnull $at_stderr || at_failed=:
31378$at_diff expout $at_stdout || at_failed=:
31379case $at_status in
31380   77) echo 77 > $at_status_file
31381            exit 77;;
31382   0) ;;
31383   *) echo "calc.at:589: exit code was $at_status, expected 0"
31384      at_failed=:;;
31385esac
31386if $at_failed; then
31387
31388  echo 1 > $at_status_file
31389  exit 1
31390fi
31391
31392$at_traceon
31393
31394
31395
31396# The same, but this time exercising explicitly triggered syntax errors.
31397# POSIX says the look-ahead causing the error should not be discarded.
31398cat >input <<'_ATEOF'
31399(!) + (0 0) = 1
31400_ATEOF
31401
31402$at_traceoff
31403echo "calc.at:589: \$PREPARSER ./calc input"
31404echo calc.at:589 >$at_check_line_file
31405( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
31406at_status=$?
31407grep '^ *+' $at_stder1 >&2
31408grep -v '^ *+' $at_stder1 >$at_stderr
31409at_failed=false
31410echo stderr:; tee stderr <$at_stderr
31411$at_diff $at_devnull $at_stdout || at_failed=:
31412case $at_status in
31413   77) echo 77 > $at_status_file
31414            exit 77;;
31415   0) ;;
31416   *) echo "calc.at:589: exit code was $at_status, expected 0"
31417      at_failed=:;;
31418esac
31419if $at_failed; then
31420
31421  echo 1 > $at_status_file
31422  exit 1
31423fi
31424
31425$at_traceon
31426
31427
31428# Normalize the observed and expected error messages, depending upon the
31429# options.
31430# 1. Remove the traces from observed.
31431sed '/^Starting/d
31432/^Entering/d
31433/^Stack/d
31434/^Reading/d
31435/^Reducing/d
31436/^Shifting/d
31437/^state/d
31438/^Cleanup:/d
31439/^Error:/d
31440/^Next/d
31441/^Discarding/d
31442/ \$[0-9$]* = /d
31443/^yydestructor:/d' stderr >at-stderr
31444mv at-stderr stderr
31445# 2. Create the reference error message.
31446cat >expout <<'_ATEOF'
314471.9: syntax error, unexpected number
31448calc: error: 2222 != 1
31449_ATEOF
31450
31451# 3. If locations are not used, remove them.
31452
31453# 4. If error-verbose is not used, strip the`, unexpected....' part.
31454sed 's/syntax error, .*$/syntax error/' expout >at-expout
31455mv at-expout expout
31456# 5. Check
31457$at_traceoff
31458echo "calc.at:589: cat stderr"
31459echo calc.at:589 >$at_check_line_file
31460( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
31461at_status=$?
31462grep '^ *+' $at_stder1 >&2
31463grep -v '^ *+' $at_stder1 >$at_stderr
31464at_failed=false
31465$at_diff $at_devnull $at_stderr || at_failed=:
31466$at_diff expout $at_stdout || at_failed=:
31467case $at_status in
31468   77) echo 77 > $at_status_file
31469            exit 77;;
31470   0) ;;
31471   *) echo "calc.at:589: exit code was $at_status, expected 0"
31472      at_failed=:;;
31473esac
31474if $at_failed; then
31475
31476  echo 1 > $at_status_file
31477  exit 1
31478fi
31479
31480$at_traceon
31481
31482
31483cat >input <<'_ATEOF'
31484(- *) + (0 0) = 1
31485_ATEOF
31486
31487$at_traceoff
31488echo "calc.at:589: \$PREPARSER ./calc input"
31489echo calc.at:589 >$at_check_line_file
31490( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
31491at_status=$?
31492grep '^ *+' $at_stder1 >&2
31493grep -v '^ *+' $at_stder1 >$at_stderr
31494at_failed=false
31495echo stderr:; tee stderr <$at_stderr
31496$at_diff $at_devnull $at_stdout || at_failed=:
31497case $at_status in
31498   77) echo 77 > $at_status_file
31499            exit 77;;
31500   0) ;;
31501   *) echo "calc.at:589: exit code was $at_status, expected 0"
31502      at_failed=:;;
31503esac
31504if $at_failed; then
31505
31506  echo 1 > $at_status_file
31507  exit 1
31508fi
31509
31510$at_traceon
31511
31512
31513# Normalize the observed and expected error messages, depending upon the
31514# options.
31515# 1. Remove the traces from observed.
31516sed '/^Starting/d
31517/^Entering/d
31518/^Stack/d
31519/^Reading/d
31520/^Reducing/d
31521/^Shifting/d
31522/^state/d
31523/^Cleanup:/d
31524/^Error:/d
31525/^Next/d
31526/^Discarding/d
31527/ \$[0-9$]* = /d
31528/^yydestructor:/d' stderr >at-stderr
31529mv at-stderr stderr
31530# 2. Create the reference error message.
31531cat >expout <<'_ATEOF'
315321.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
315331.11: syntax error, unexpected number
31534calc: error: 2222 != 1
31535_ATEOF
31536
31537# 3. If locations are not used, remove them.
31538
31539# 4. If error-verbose is not used, strip the`, unexpected....' part.
31540sed 's/syntax error, .*$/syntax error/' expout >at-expout
31541mv at-expout expout
31542# 5. Check
31543$at_traceoff
31544echo "calc.at:589: cat stderr"
31545echo calc.at:589 >$at_check_line_file
31546( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
31547at_status=$?
31548grep '^ *+' $at_stder1 >&2
31549grep -v '^ *+' $at_stder1 >$at_stderr
31550at_failed=false
31551$at_diff $at_devnull $at_stderr || at_failed=:
31552$at_diff expout $at_stdout || at_failed=:
31553case $at_status in
31554   77) echo 77 > $at_status_file
31555            exit 77;;
31556   0) ;;
31557   *) echo "calc.at:589: exit code was $at_status, expected 0"
31558      at_failed=:;;
31559esac
31560if $at_failed; then
31561
31562  echo 1 > $at_status_file
31563  exit 1
31564fi
31565
31566$at_traceon
31567
31568
31569
31570
31571
31572
31573
31574
31575
31576
31577
31578
31579
31580
31581
31582
31583
31584
31585
31586
31587
31588
31589
31590
31591      $at_traceoff
31592      $at_times_p && times >$at_times_file
31593    ) 5>&1 2>&1 | eval $at_tee_pipe
31594    at_status=`cat $at_status_file`
31595    ;;
31596
31597  87 ) # 87. calc.at:590: Calculator %glr-parser %name-prefix="calc"
31598    at_setup_line='calc.at:590'
31599    at_desc='Calculator %glr-parser %name-prefix="calc"'
31600    $at_quiet $ECHO_N " 87: Calculator %glr-parser %name-prefix="calc"   $ECHO_C"
31601    at_xfail=no
31602    (
31603      echo "87. calc.at:590: testing ..."
31604      $at_traceon
31605
31606
31607
31608
31609
31610
31611
31612
31613# Using yacc.c?
31614
31615
31616
31617
31618
31619
31620
31621# yyerror receives the location if %location & %pure & (%glr or %parse-param).
31622
31623# yyerror always sees the locations (when activated), except if
31624# yacc & pure & !param.
31625
31626
31627# The interface is pure: either because %pure-parser, or because we
31628# are using the C++ parsers.
31629
31630
31631
31632
31633
31634
31635
31636
31637
31638
31639
31640
31641cat >calc.y <<'_ATEOF'
31642%{
31643#ifdef HAVE_CONFIG_H
31644# include <config.h>
31645  /* We don't need perfect functions for these tests. */
31646# undef malloc
31647# undef memcmp
31648# undef realloc
31649#endif
31650%}
31651
31652/* Infix notation calculator--calc */
31653%glr-parser %name-prefix="calc"
31654
31655%{
31656#include <stdio.h>
31657
31658#include <stdlib.h>
31659#include <string.h>
31660#if HAVE_UNISTD_H
31661# include <unistd.h>
31662#else
31663# undef alarm
31664# define alarm(seconds) /* empty */
31665#endif
31666#include <ctype.h>
31667#define USE(Var)
31668
31669/* Exercise pre-prologue dependency to %union.  */
31670typedef int semantic_value;
31671
31672static semantic_value global_result = 0;
31673static int global_count = 0;
31674%}
31675
31676/* Exercise %union. */
31677%union
31678{
31679  semantic_value ival;
31680};
31681
31682%{
31683static int power (int base, int exponent);
31684/* yyerror receives the location if:
31685   - %location & %pure & %glr
31686   - %location & %pure & %yacc & %parse-param. */
31687static void yyerror (
31688
31689                     const char *s
31690                     );
31691static int yylex (void);
31692static int get_char (void);
31693static void unget_char ( int c);
31694%}
31695
31696
31697
31698/* Bison Declarations */
31699%token CALC_EOF 0 "end of input"
31700%token <ival> NUM "number"
31701%type  <ival> exp
31702
31703%nonassoc '=' /* comparison	       */
31704%left '-' '+'
31705%left '*' '/'
31706%left NEG     /* negation--unary minus */
31707%right '^'    /* exponentiation        */
31708
31709/* Grammar follows */
31710%%
31711input:
31712  line
31713| input line         {  }
31714;
31715
31716line:
31717  '\n'
31718| exp '\n'           { USE ($1); }
31719;
31720
31721exp:
31722  NUM                { $$ = $1;             }
31723| exp '=' exp
31724  {
31725    if ($1 != $3)
31726      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
31727    $$ = $1;
31728  }
31729| exp '+' exp        { $$ = $1 + $3;        }
31730| exp '-' exp        { $$ = $1 - $3;        }
31731| exp '*' exp        { $$ = $1 * $3;        }
31732| exp '/' exp        { $$ = $1 / $3;        }
31733| '-' exp  %prec NEG { $$ = -$2;            }
31734| exp '^' exp        { $$ = power ($1, $3); }
31735| '(' exp ')'        { $$ = $2;             }
31736| '(' error ')'      { $$ = 1111;           }
31737| '!'                { $$ = 0; YYERROR;     }
31738| '-' error          { $$ = 0; YYERROR;     }
31739;
31740%%
31741/* The input.  */
31742static FILE *input;
31743
31744static void
31745yyerror (
31746
31747         const char *s)
31748{
31749
31750
31751  fprintf (stderr, "%s\n", s);
31752}
31753
31754
31755
31756static int
31757get_char (void)
31758{
31759  int res = getc (input);
31760  ;
31761
31762  return res;
31763}
31764
31765
31766static void
31767unget_char ( int c)
31768{
31769  ;
31770
31771  ungetc (c, input);
31772}
31773
31774static int
31775read_signed_integer (void)
31776{
31777  int c = get_char ();
31778  int sign = 1;
31779  int n = 0;
31780
31781  ;
31782  if (c == '-')
31783    {
31784      c = get_char ();
31785      sign = -1;
31786    }
31787
31788  while (isdigit (c))
31789    {
31790      n = 10 * n + (c - '0');
31791      c = get_char ();
31792    }
31793
31794  unget_char ( c);
31795
31796  return sign * n;
31797}
31798
31799
31800
31801/*---------------------------------------------------------------.
31802| Lexical analyzer returns an integer on the stack and the token |
31803| NUM, or the ASCII character read if not a number.  Skips all   |
31804| blanks and tabs, returns 0 for EOF.                            |
31805`---------------------------------------------------------------*/
31806
31807static int
31808yylex (void)
31809{
31810  static int init = 1;
31811  int c;
31812
31813  if (init)
31814    {
31815      init = 0;
31816
31817    }
31818
31819
31820
31821  /* Skip white space.  */
31822  while ((c = get_char ()) == ' ' || c == '\t')
31823    {
31824
31825    }
31826
31827  /* process numbers   */
31828  if (c == '.' || isdigit (c))
31829    {
31830      unget_char ( c);
31831      (yylval).ival = read_signed_integer ();
31832      return NUM;
31833    }
31834
31835  /* Return end-of-file.  */
31836  if (c == EOF)
31837    return CALC_EOF;
31838
31839  /* Return single chars. */
31840  return c;
31841}
31842
31843static int
31844power (int base, int exponent)
31845{
31846  int res = 1;
31847  if (exponent < 0)
31848    exit (3);
31849  for (/* Niente */; exponent; --exponent)
31850    res *= base;
31851  return res;
31852}
31853
31854
31855int
31856main (int argc, const char **argv)
31857{
31858  semantic_value result = 0;
31859  int count = 0;
31860  int status;
31861
31862  /* This used to be alarm (10), but that isn't enough time for
31863     a July 1995 vintage DEC Alphastation 200 4/100 system,
31864     according to Nelson H. F. Beebe.  100 seconds is enough.  */
31865  alarm (100);
31866
31867  if (argc == 2)
31868    input = fopen (argv[1], "r");
31869  else
31870    input = stdin;
31871
31872  if (!input)
31873    {
31874      perror (argv[1]);
31875      return 3;
31876    }
31877
31878
31879  status = yyparse ();
31880  if (global_result != result)
31881    abort ();
31882  if (global_count != count)
31883    abort ();
31884  return status;
31885}
31886_ATEOF
31887
31888
31889
31890
31891
31892$at_traceoff
31893echo "calc.at:590: bison -o calc.c calc.y"
31894echo calc.at:590 >$at_check_line_file
31895( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
31896at_status=$?
31897grep '^ *+' $at_stder1 >&2
31898grep -v '^ *+' $at_stder1 >$at_stderr
31899at_failed=false
31900$at_diff $at_devnull $at_stderr || at_failed=:
31901$at_diff $at_devnull $at_stdout || at_failed=:
31902case $at_status in
31903   77) echo 77 > $at_status_file
31904            exit 77;;
31905   0) ;;
31906   *) echo "calc.at:590: exit code was $at_status, expected 0"
31907      at_failed=:;;
31908esac
31909if $at_failed; then
31910
31911  echo 1 > $at_status_file
31912  exit 1
31913fi
31914
31915$at_traceon
31916
31917   $at_traceoff
31918echo "calc.at:590: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
31919echo calc.at:590 >$at_check_line_file
31920( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
31921at_status=$?
31922grep '^ *+' $at_stder1 >&2
31923grep -v '^ *+' $at_stder1 >$at_stderr
31924at_failed=false
31925echo stderr:; cat $at_stderr
31926echo stdout:; cat $at_stdout
31927case $at_status in
31928   77) echo 77 > $at_status_file
31929            exit 77;;
31930   0) ;;
31931   *) echo "calc.at:590: exit code was $at_status, expected 0"
31932      at_failed=:;;
31933esac
31934if $at_failed; then
31935
31936  echo 1 > $at_status_file
31937  exit 1
31938fi
31939
31940$at_traceon
31941
31942
31943# Test the priorities.
31944cat >input <<'_ATEOF'
319451 + 2 * 3 = 7
319461 + 2 * -3 = -5
31947
31948-1^2 = -1
31949(-1)^2 = 1
31950
31951---1 = -1
31952
319531 - 2 - 3 = -4
319541 - (2 - 3) = 2
31955
319562^2^3 = 256
31957(2^2)^3 = 64
31958_ATEOF
31959
31960$at_traceoff
31961echo "calc.at:590: \$PREPARSER ./calc input"
31962echo calc.at:590 >$at_check_line_file
31963( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
31964at_status=$?
31965grep '^ *+' $at_stder1 >&2
31966grep -v '^ *+' $at_stder1 >$at_stderr
31967at_failed=false
31968echo stderr:; tee stderr <$at_stderr
31969$at_diff $at_devnull $at_stdout || at_failed=:
31970case $at_status in
31971   77) echo 77 > $at_status_file
31972            exit 77;;
31973   0) ;;
31974   *) echo "calc.at:590: exit code was $at_status, expected 0"
31975      at_failed=:;;
31976esac
31977if $at_failed; then
31978
31979  echo 1 > $at_status_file
31980  exit 1
31981fi
31982
31983$at_traceon
31984
31985
31986
31987# Some syntax errors.
31988cat >input <<'_ATEOF'
319890 0
31990_ATEOF
31991
31992$at_traceoff
31993echo "calc.at:590: \$PREPARSER ./calc input"
31994echo calc.at:590 >$at_check_line_file
31995( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
31996at_status=$?
31997grep '^ *+' $at_stder1 >&2
31998grep -v '^ *+' $at_stder1 >$at_stderr
31999at_failed=false
32000echo stderr:; tee stderr <$at_stderr
32001$at_diff $at_devnull $at_stdout || at_failed=:
32002case $at_status in
32003   77) echo 77 > $at_status_file
32004            exit 77;;
32005   1) ;;
32006   *) echo "calc.at:590: exit code was $at_status, expected 1"
32007      at_failed=:;;
32008esac
32009if $at_failed; then
32010
32011  echo 1 > $at_status_file
32012  exit 1
32013fi
32014
32015$at_traceon
32016
32017
32018# Normalize the observed and expected error messages, depending upon the
32019# options.
32020# 1. Remove the traces from observed.
32021sed '/^Starting/d
32022/^Entering/d
32023/^Stack/d
32024/^Reading/d
32025/^Reducing/d
32026/^Shifting/d
32027/^state/d
32028/^Cleanup:/d
32029/^Error:/d
32030/^Next/d
32031/^Discarding/d
32032/ \$[0-9$]* = /d
32033/^yydestructor:/d' stderr >at-stderr
32034mv at-stderr stderr
32035# 2. Create the reference error message.
32036cat >expout <<'_ATEOF'
320371.2: syntax error, unexpected number
32038_ATEOF
32039
32040# 3. If locations are not used, remove them.
32041sed 's/^[-0-9.]*: //' expout >at-expout
32042mv at-expout expout
32043# 4. If error-verbose is not used, strip the`, unexpected....' part.
32044sed 's/syntax error, .*$/syntax error/' expout >at-expout
32045mv at-expout expout
32046# 5. Check
32047$at_traceoff
32048echo "calc.at:590: cat stderr"
32049echo calc.at:590 >$at_check_line_file
32050( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
32051at_status=$?
32052grep '^ *+' $at_stder1 >&2
32053grep -v '^ *+' $at_stder1 >$at_stderr
32054at_failed=false
32055$at_diff $at_devnull $at_stderr || at_failed=:
32056$at_diff expout $at_stdout || at_failed=:
32057case $at_status in
32058   77) echo 77 > $at_status_file
32059            exit 77;;
32060   0) ;;
32061   *) echo "calc.at:590: exit code was $at_status, expected 0"
32062      at_failed=:;;
32063esac
32064if $at_failed; then
32065
32066  echo 1 > $at_status_file
32067  exit 1
32068fi
32069
32070$at_traceon
32071
32072
32073cat >input <<'_ATEOF'
320741//2
32075_ATEOF
32076
32077$at_traceoff
32078echo "calc.at:590: \$PREPARSER ./calc input"
32079echo calc.at:590 >$at_check_line_file
32080( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
32081at_status=$?
32082grep '^ *+' $at_stder1 >&2
32083grep -v '^ *+' $at_stder1 >$at_stderr
32084at_failed=false
32085echo stderr:; tee stderr <$at_stderr
32086$at_diff $at_devnull $at_stdout || at_failed=:
32087case $at_status in
32088   77) echo 77 > $at_status_file
32089            exit 77;;
32090   1) ;;
32091   *) echo "calc.at:590: exit code was $at_status, expected 1"
32092      at_failed=:;;
32093esac
32094if $at_failed; then
32095
32096  echo 1 > $at_status_file
32097  exit 1
32098fi
32099
32100$at_traceon
32101
32102
32103# Normalize the observed and expected error messages, depending upon the
32104# options.
32105# 1. Remove the traces from observed.
32106sed '/^Starting/d
32107/^Entering/d
32108/^Stack/d
32109/^Reading/d
32110/^Reducing/d
32111/^Shifting/d
32112/^state/d
32113/^Cleanup:/d
32114/^Error:/d
32115/^Next/d
32116/^Discarding/d
32117/ \$[0-9$]* = /d
32118/^yydestructor:/d' stderr >at-stderr
32119mv at-stderr stderr
32120# 2. Create the reference error message.
32121cat >expout <<'_ATEOF'
321221.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
32123_ATEOF
32124
32125# 3. If locations are not used, remove them.
32126sed 's/^[-0-9.]*: //' expout >at-expout
32127mv at-expout expout
32128# 4. If error-verbose is not used, strip the`, unexpected....' part.
32129sed 's/syntax error, .*$/syntax error/' expout >at-expout
32130mv at-expout expout
32131# 5. Check
32132$at_traceoff
32133echo "calc.at:590: cat stderr"
32134echo calc.at:590 >$at_check_line_file
32135( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
32136at_status=$?
32137grep '^ *+' $at_stder1 >&2
32138grep -v '^ *+' $at_stder1 >$at_stderr
32139at_failed=false
32140$at_diff $at_devnull $at_stderr || at_failed=:
32141$at_diff expout $at_stdout || at_failed=:
32142case $at_status in
32143   77) echo 77 > $at_status_file
32144            exit 77;;
32145   0) ;;
32146   *) echo "calc.at:590: exit code was $at_status, expected 0"
32147      at_failed=:;;
32148esac
32149if $at_failed; then
32150
32151  echo 1 > $at_status_file
32152  exit 1
32153fi
32154
32155$at_traceon
32156
32157
32158cat >input <<'_ATEOF'
32159error
32160_ATEOF
32161
32162$at_traceoff
32163echo "calc.at:590: \$PREPARSER ./calc input"
32164echo calc.at:590 >$at_check_line_file
32165( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
32166at_status=$?
32167grep '^ *+' $at_stder1 >&2
32168grep -v '^ *+' $at_stder1 >$at_stderr
32169at_failed=false
32170echo stderr:; tee stderr <$at_stderr
32171$at_diff $at_devnull $at_stdout || at_failed=:
32172case $at_status in
32173   77) echo 77 > $at_status_file
32174            exit 77;;
32175   1) ;;
32176   *) echo "calc.at:590: exit code was $at_status, expected 1"
32177      at_failed=:;;
32178esac
32179if $at_failed; then
32180
32181  echo 1 > $at_status_file
32182  exit 1
32183fi
32184
32185$at_traceon
32186
32187
32188# Normalize the observed and expected error messages, depending upon the
32189# options.
32190# 1. Remove the traces from observed.
32191sed '/^Starting/d
32192/^Entering/d
32193/^Stack/d
32194/^Reading/d
32195/^Reducing/d
32196/^Shifting/d
32197/^state/d
32198/^Cleanup:/d
32199/^Error:/d
32200/^Next/d
32201/^Discarding/d
32202/ \$[0-9$]* = /d
32203/^yydestructor:/d' stderr >at-stderr
32204mv at-stderr stderr
32205# 2. Create the reference error message.
32206cat >expout <<'_ATEOF'
322071.0: syntax error, unexpected $undefined
32208_ATEOF
32209
32210# 3. If locations are not used, remove them.
32211sed 's/^[-0-9.]*: //' expout >at-expout
32212mv at-expout expout
32213# 4. If error-verbose is not used, strip the`, unexpected....' part.
32214sed 's/syntax error, .*$/syntax error/' expout >at-expout
32215mv at-expout expout
32216# 5. Check
32217$at_traceoff
32218echo "calc.at:590: cat stderr"
32219echo calc.at:590 >$at_check_line_file
32220( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
32221at_status=$?
32222grep '^ *+' $at_stder1 >&2
32223grep -v '^ *+' $at_stder1 >$at_stderr
32224at_failed=false
32225$at_diff $at_devnull $at_stderr || at_failed=:
32226$at_diff expout $at_stdout || at_failed=:
32227case $at_status in
32228   77) echo 77 > $at_status_file
32229            exit 77;;
32230   0) ;;
32231   *) echo "calc.at:590: exit code was $at_status, expected 0"
32232      at_failed=:;;
32233esac
32234if $at_failed; then
32235
32236  echo 1 > $at_status_file
32237  exit 1
32238fi
32239
32240$at_traceon
32241
32242
32243cat >input <<'_ATEOF'
322441 = 2 = 3
32245_ATEOF
32246
32247$at_traceoff
32248echo "calc.at:590: \$PREPARSER ./calc input"
32249echo calc.at:590 >$at_check_line_file
32250( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
32251at_status=$?
32252grep '^ *+' $at_stder1 >&2
32253grep -v '^ *+' $at_stder1 >$at_stderr
32254at_failed=false
32255echo stderr:; tee stderr <$at_stderr
32256$at_diff $at_devnull $at_stdout || at_failed=:
32257case $at_status in
32258   77) echo 77 > $at_status_file
32259            exit 77;;
32260   1) ;;
32261   *) echo "calc.at:590: exit code was $at_status, expected 1"
32262      at_failed=:;;
32263esac
32264if $at_failed; then
32265
32266  echo 1 > $at_status_file
32267  exit 1
32268fi
32269
32270$at_traceon
32271
32272
32273# Normalize the observed and expected error messages, depending upon the
32274# options.
32275# 1. Remove the traces from observed.
32276sed '/^Starting/d
32277/^Entering/d
32278/^Stack/d
32279/^Reading/d
32280/^Reducing/d
32281/^Shifting/d
32282/^state/d
32283/^Cleanup:/d
32284/^Error:/d
32285/^Next/d
32286/^Discarding/d
32287/ \$[0-9$]* = /d
32288/^yydestructor:/d' stderr >at-stderr
32289mv at-stderr stderr
32290# 2. Create the reference error message.
32291cat >expout <<'_ATEOF'
322921.6: syntax error, unexpected '='
32293_ATEOF
32294
32295# 3. If locations are not used, remove them.
32296sed 's/^[-0-9.]*: //' expout >at-expout
32297mv at-expout expout
32298# 4. If error-verbose is not used, strip the`, unexpected....' part.
32299sed 's/syntax error, .*$/syntax error/' expout >at-expout
32300mv at-expout expout
32301# 5. Check
32302$at_traceoff
32303echo "calc.at:590: cat stderr"
32304echo calc.at:590 >$at_check_line_file
32305( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
32306at_status=$?
32307grep '^ *+' $at_stder1 >&2
32308grep -v '^ *+' $at_stder1 >$at_stderr
32309at_failed=false
32310$at_diff $at_devnull $at_stderr || at_failed=:
32311$at_diff expout $at_stdout || at_failed=:
32312case $at_status in
32313   77) echo 77 > $at_status_file
32314            exit 77;;
32315   0) ;;
32316   *) echo "calc.at:590: exit code was $at_status, expected 0"
32317      at_failed=:;;
32318esac
32319if $at_failed; then
32320
32321  echo 1 > $at_status_file
32322  exit 1
32323fi
32324
32325$at_traceon
32326
32327
32328cat >input <<'_ATEOF'
32329
32330+1
32331_ATEOF
32332
32333$at_traceoff
32334echo "calc.at:590: \$PREPARSER ./calc input"
32335echo calc.at:590 >$at_check_line_file
32336( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
32337at_status=$?
32338grep '^ *+' $at_stder1 >&2
32339grep -v '^ *+' $at_stder1 >$at_stderr
32340at_failed=false
32341echo stderr:; tee stderr <$at_stderr
32342$at_diff $at_devnull $at_stdout || at_failed=:
32343case $at_status in
32344   77) echo 77 > $at_status_file
32345            exit 77;;
32346   1) ;;
32347   *) echo "calc.at:590: exit code was $at_status, expected 1"
32348      at_failed=:;;
32349esac
32350if $at_failed; then
32351
32352  echo 1 > $at_status_file
32353  exit 1
32354fi
32355
32356$at_traceon
32357
32358
32359# Normalize the observed and expected error messages, depending upon the
32360# options.
32361# 1. Remove the traces from observed.
32362sed '/^Starting/d
32363/^Entering/d
32364/^Stack/d
32365/^Reading/d
32366/^Reducing/d
32367/^Shifting/d
32368/^state/d
32369/^Cleanup:/d
32370/^Error:/d
32371/^Next/d
32372/^Discarding/d
32373/ \$[0-9$]* = /d
32374/^yydestructor:/d' stderr >at-stderr
32375mv at-stderr stderr
32376# 2. Create the reference error message.
32377cat >expout <<'_ATEOF'
323782.0: syntax error, unexpected '+'
32379_ATEOF
32380
32381# 3. If locations are not used, remove them.
32382sed 's/^[-0-9.]*: //' expout >at-expout
32383mv at-expout expout
32384# 4. If error-verbose is not used, strip the`, unexpected....' part.
32385sed 's/syntax error, .*$/syntax error/' expout >at-expout
32386mv at-expout expout
32387# 5. Check
32388$at_traceoff
32389echo "calc.at:590: cat stderr"
32390echo calc.at:590 >$at_check_line_file
32391( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
32392at_status=$?
32393grep '^ *+' $at_stder1 >&2
32394grep -v '^ *+' $at_stder1 >$at_stderr
32395at_failed=false
32396$at_diff $at_devnull $at_stderr || at_failed=:
32397$at_diff expout $at_stdout || at_failed=:
32398case $at_status in
32399   77) echo 77 > $at_status_file
32400            exit 77;;
32401   0) ;;
32402   *) echo "calc.at:590: exit code was $at_status, expected 0"
32403      at_failed=:;;
32404esac
32405if $at_failed; then
32406
32407  echo 1 > $at_status_file
32408  exit 1
32409fi
32410
32411$at_traceon
32412
32413
32414# Exercise error messages with EOF: work on an empty file.
32415$at_traceoff
32416echo "calc.at:590: \$PREPARSER ./calc /dev/null"
32417echo calc.at:590 >$at_check_line_file
32418( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
32419at_status=$?
32420grep '^ *+' $at_stder1 >&2
32421grep -v '^ *+' $at_stder1 >$at_stderr
32422at_failed=false
32423echo stderr:; tee stderr <$at_stderr
32424$at_diff $at_devnull $at_stdout || at_failed=:
32425case $at_status in
32426   77) echo 77 > $at_status_file
32427            exit 77;;
32428   1) ;;
32429   *) echo "calc.at:590: exit code was $at_status, expected 1"
32430      at_failed=:;;
32431esac
32432if $at_failed; then
32433
32434  echo 1 > $at_status_file
32435  exit 1
32436fi
32437
32438$at_traceon
32439
32440
32441# Normalize the observed and expected error messages, depending upon the
32442# options.
32443# 1. Remove the traces from observed.
32444sed '/^Starting/d
32445/^Entering/d
32446/^Stack/d
32447/^Reading/d
32448/^Reducing/d
32449/^Shifting/d
32450/^state/d
32451/^Cleanup:/d
32452/^Error:/d
32453/^Next/d
32454/^Discarding/d
32455/ \$[0-9$]* = /d
32456/^yydestructor:/d' stderr >at-stderr
32457mv at-stderr stderr
32458# 2. Create the reference error message.
32459cat >expout <<'_ATEOF'
324601.0: syntax error, unexpected end of input
32461_ATEOF
32462
32463# 3. If locations are not used, remove them.
32464sed 's/^[-0-9.]*: //' expout >at-expout
32465mv at-expout expout
32466# 4. If error-verbose is not used, strip the`, unexpected....' part.
32467sed 's/syntax error, .*$/syntax error/' expout >at-expout
32468mv at-expout expout
32469# 5. Check
32470$at_traceoff
32471echo "calc.at:590: cat stderr"
32472echo calc.at:590 >$at_check_line_file
32473( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
32474at_status=$?
32475grep '^ *+' $at_stder1 >&2
32476grep -v '^ *+' $at_stder1 >$at_stderr
32477at_failed=false
32478$at_diff $at_devnull $at_stderr || at_failed=:
32479$at_diff expout $at_stdout || at_failed=:
32480case $at_status in
32481   77) echo 77 > $at_status_file
32482            exit 77;;
32483   0) ;;
32484   *) echo "calc.at:590: exit code was $at_status, expected 0"
32485      at_failed=:;;
32486esac
32487if $at_failed; then
32488
32489  echo 1 > $at_status_file
32490  exit 1
32491fi
32492
32493$at_traceon
32494
32495
32496
32497# Exercise the error token: without it, we die at the first error,
32498# hence be sure to
32499#
32500# - have several errors which exercise different shift/discardings
32501#   - (): nothing to pop, nothing to discard
32502#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
32503#   - (* * *): nothing to pop, a lot to discard
32504#   - (1 + 2 * *): some to pop and discard
32505#
32506# - test the action associated to `error'
32507#
32508# - check the look-ahead that triggers an error is not discarded
32509#   when we enter error recovery.  Below, the look-ahead causing the
32510#   first error is ")", which is needed to recover from the error and
32511#   produce the "0" that triggers the "0 != 1" error.
32512#
32513cat >input <<'_ATEOF'
32514() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
32515_ATEOF
32516
32517$at_traceoff
32518echo "calc.at:590: \$PREPARSER ./calc input"
32519echo calc.at:590 >$at_check_line_file
32520( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
32521at_status=$?
32522grep '^ *+' $at_stder1 >&2
32523grep -v '^ *+' $at_stder1 >$at_stderr
32524at_failed=false
32525echo stderr:; tee stderr <$at_stderr
32526$at_diff $at_devnull $at_stdout || at_failed=:
32527case $at_status in
32528   77) echo 77 > $at_status_file
32529            exit 77;;
32530   0) ;;
32531   *) echo "calc.at:590: exit code was $at_status, expected 0"
32532      at_failed=:;;
32533esac
32534if $at_failed; then
32535
32536  echo 1 > $at_status_file
32537  exit 1
32538fi
32539
32540$at_traceon
32541
32542
32543# Normalize the observed and expected error messages, depending upon the
32544# options.
32545# 1. Remove the traces from observed.
32546sed '/^Starting/d
32547/^Entering/d
32548/^Stack/d
32549/^Reading/d
32550/^Reducing/d
32551/^Shifting/d
32552/^state/d
32553/^Cleanup:/d
32554/^Error:/d
32555/^Next/d
32556/^Discarding/d
32557/ \$[0-9$]* = /d
32558/^yydestructor:/d' stderr >at-stderr
32559mv at-stderr stderr
32560# 2. Create the reference error message.
32561cat >expout <<'_ATEOF'
325621.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
325631.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
325641.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
325651.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
32566calc: error: 4444 != 1
32567_ATEOF
32568
32569# 3. If locations are not used, remove them.
32570sed 's/^[-0-9.]*: //' expout >at-expout
32571mv at-expout expout
32572# 4. If error-verbose is not used, strip the`, unexpected....' part.
32573sed 's/syntax error, .*$/syntax error/' expout >at-expout
32574mv at-expout expout
32575# 5. Check
32576$at_traceoff
32577echo "calc.at:590: cat stderr"
32578echo calc.at:590 >$at_check_line_file
32579( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
32580at_status=$?
32581grep '^ *+' $at_stder1 >&2
32582grep -v '^ *+' $at_stder1 >$at_stderr
32583at_failed=false
32584$at_diff $at_devnull $at_stderr || at_failed=:
32585$at_diff expout $at_stdout || at_failed=:
32586case $at_status in
32587   77) echo 77 > $at_status_file
32588            exit 77;;
32589   0) ;;
32590   *) echo "calc.at:590: exit code was $at_status, expected 0"
32591      at_failed=:;;
32592esac
32593if $at_failed; then
32594
32595  echo 1 > $at_status_file
32596  exit 1
32597fi
32598
32599$at_traceon
32600
32601
32602
32603# The same, but this time exercising explicitly triggered syntax errors.
32604# POSIX says the look-ahead causing the error should not be discarded.
32605cat >input <<'_ATEOF'
32606(!) + (0 0) = 1
32607_ATEOF
32608
32609$at_traceoff
32610echo "calc.at:590: \$PREPARSER ./calc input"
32611echo calc.at:590 >$at_check_line_file
32612( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
32613at_status=$?
32614grep '^ *+' $at_stder1 >&2
32615grep -v '^ *+' $at_stder1 >$at_stderr
32616at_failed=false
32617echo stderr:; tee stderr <$at_stderr
32618$at_diff $at_devnull $at_stdout || at_failed=:
32619case $at_status in
32620   77) echo 77 > $at_status_file
32621            exit 77;;
32622   0) ;;
32623   *) echo "calc.at:590: exit code was $at_status, expected 0"
32624      at_failed=:;;
32625esac
32626if $at_failed; then
32627
32628  echo 1 > $at_status_file
32629  exit 1
32630fi
32631
32632$at_traceon
32633
32634
32635# Normalize the observed and expected error messages, depending upon the
32636# options.
32637# 1. Remove the traces from observed.
32638sed '/^Starting/d
32639/^Entering/d
32640/^Stack/d
32641/^Reading/d
32642/^Reducing/d
32643/^Shifting/d
32644/^state/d
32645/^Cleanup:/d
32646/^Error:/d
32647/^Next/d
32648/^Discarding/d
32649/ \$[0-9$]* = /d
32650/^yydestructor:/d' stderr >at-stderr
32651mv at-stderr stderr
32652# 2. Create the reference error message.
32653cat >expout <<'_ATEOF'
326541.9: syntax error, unexpected number
32655calc: error: 2222 != 1
32656_ATEOF
32657
32658# 3. If locations are not used, remove them.
32659sed 's/^[-0-9.]*: //' expout >at-expout
32660mv at-expout expout
32661# 4. If error-verbose is not used, strip the`, unexpected....' part.
32662sed 's/syntax error, .*$/syntax error/' expout >at-expout
32663mv at-expout expout
32664# 5. Check
32665$at_traceoff
32666echo "calc.at:590: cat stderr"
32667echo calc.at:590 >$at_check_line_file
32668( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
32669at_status=$?
32670grep '^ *+' $at_stder1 >&2
32671grep -v '^ *+' $at_stder1 >$at_stderr
32672at_failed=false
32673$at_diff $at_devnull $at_stderr || at_failed=:
32674$at_diff expout $at_stdout || at_failed=:
32675case $at_status in
32676   77) echo 77 > $at_status_file
32677            exit 77;;
32678   0) ;;
32679   *) echo "calc.at:590: exit code was $at_status, expected 0"
32680      at_failed=:;;
32681esac
32682if $at_failed; then
32683
32684  echo 1 > $at_status_file
32685  exit 1
32686fi
32687
32688$at_traceon
32689
32690
32691cat >input <<'_ATEOF'
32692(- *) + (0 0) = 1
32693_ATEOF
32694
32695$at_traceoff
32696echo "calc.at:590: \$PREPARSER ./calc input"
32697echo calc.at:590 >$at_check_line_file
32698( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
32699at_status=$?
32700grep '^ *+' $at_stder1 >&2
32701grep -v '^ *+' $at_stder1 >$at_stderr
32702at_failed=false
32703echo stderr:; tee stderr <$at_stderr
32704$at_diff $at_devnull $at_stdout || at_failed=:
32705case $at_status in
32706   77) echo 77 > $at_status_file
32707            exit 77;;
32708   0) ;;
32709   *) echo "calc.at:590: exit code was $at_status, expected 0"
32710      at_failed=:;;
32711esac
32712if $at_failed; then
32713
32714  echo 1 > $at_status_file
32715  exit 1
32716fi
32717
32718$at_traceon
32719
32720
32721# Normalize the observed and expected error messages, depending upon the
32722# options.
32723# 1. Remove the traces from observed.
32724sed '/^Starting/d
32725/^Entering/d
32726/^Stack/d
32727/^Reading/d
32728/^Reducing/d
32729/^Shifting/d
32730/^state/d
32731/^Cleanup:/d
32732/^Error:/d
32733/^Next/d
32734/^Discarding/d
32735/ \$[0-9$]* = /d
32736/^yydestructor:/d' stderr >at-stderr
32737mv at-stderr stderr
32738# 2. Create the reference error message.
32739cat >expout <<'_ATEOF'
327401.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
327411.11: syntax error, unexpected number
32742calc: error: 2222 != 1
32743_ATEOF
32744
32745# 3. If locations are not used, remove them.
32746sed 's/^[-0-9.]*: //' expout >at-expout
32747mv at-expout expout
32748# 4. If error-verbose is not used, strip the`, unexpected....' part.
32749sed 's/syntax error, .*$/syntax error/' expout >at-expout
32750mv at-expout expout
32751# 5. Check
32752$at_traceoff
32753echo "calc.at:590: cat stderr"
32754echo calc.at:590 >$at_check_line_file
32755( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
32756at_status=$?
32757grep '^ *+' $at_stder1 >&2
32758grep -v '^ *+' $at_stder1 >$at_stderr
32759at_failed=false
32760$at_diff $at_devnull $at_stderr || at_failed=:
32761$at_diff expout $at_stdout || at_failed=:
32762case $at_status in
32763   77) echo 77 > $at_status_file
32764            exit 77;;
32765   0) ;;
32766   *) echo "calc.at:590: exit code was $at_status, expected 0"
32767      at_failed=:;;
32768esac
32769if $at_failed; then
32770
32771  echo 1 > $at_status_file
32772  exit 1
32773fi
32774
32775$at_traceon
32776
32777
32778
32779
32780
32781
32782
32783
32784
32785
32786
32787
32788
32789
32790
32791
32792
32793
32794
32795
32796
32797
32798
32799
32800      $at_traceoff
32801      $at_times_p && times >$at_times_file
32802    ) 5>&1 2>&1 | eval $at_tee_pipe
32803    at_status=`cat $at_status_file`
32804    ;;
32805
32806  88 ) # 88. calc.at:591: Calculator %glr-parser %verbose
32807    at_setup_line='calc.at:591'
32808    at_desc='Calculator %glr-parser %verbose'
32809    $at_quiet $ECHO_N " 88: Calculator %glr-parser %verbose              $ECHO_C"
32810    at_xfail=no
32811    (
32812      echo "88. calc.at:591: testing ..."
32813      $at_traceon
32814
32815
32816
32817
32818
32819
32820
32821
32822# Using yacc.c?
32823
32824
32825
32826
32827
32828
32829
32830# yyerror receives the location if %location & %pure & (%glr or %parse-param).
32831
32832# yyerror always sees the locations (when activated), except if
32833# yacc & pure & !param.
32834
32835
32836# The interface is pure: either because %pure-parser, or because we
32837# are using the C++ parsers.
32838
32839
32840
32841
32842
32843
32844
32845
32846
32847
32848
32849
32850cat >calc.y <<'_ATEOF'
32851%{
32852#ifdef HAVE_CONFIG_H
32853# include <config.h>
32854  /* We don't need perfect functions for these tests. */
32855# undef malloc
32856# undef memcmp
32857# undef realloc
32858#endif
32859%}
32860
32861/* Infix notation calculator--calc */
32862%glr-parser %verbose
32863
32864%{
32865#include <stdio.h>
32866
32867#include <stdlib.h>
32868#include <string.h>
32869#if HAVE_UNISTD_H
32870# include <unistd.h>
32871#else
32872# undef alarm
32873# define alarm(seconds) /* empty */
32874#endif
32875#include <ctype.h>
32876#define USE(Var)
32877
32878/* Exercise pre-prologue dependency to %union.  */
32879typedef int semantic_value;
32880
32881static semantic_value global_result = 0;
32882static int global_count = 0;
32883%}
32884
32885/* Exercise %union. */
32886%union
32887{
32888  semantic_value ival;
32889};
32890
32891%{
32892static int power (int base, int exponent);
32893/* yyerror receives the location if:
32894   - %location & %pure & %glr
32895   - %location & %pure & %yacc & %parse-param. */
32896static void yyerror (
32897
32898                     const char *s
32899                     );
32900static int yylex (void);
32901static int get_char (void);
32902static void unget_char ( int c);
32903%}
32904
32905
32906
32907/* Bison Declarations */
32908%token CALC_EOF 0 "end of input"
32909%token <ival> NUM "number"
32910%type  <ival> exp
32911
32912%nonassoc '=' /* comparison	       */
32913%left '-' '+'
32914%left '*' '/'
32915%left NEG     /* negation--unary minus */
32916%right '^'    /* exponentiation        */
32917
32918/* Grammar follows */
32919%%
32920input:
32921  line
32922| input line         {  }
32923;
32924
32925line:
32926  '\n'
32927| exp '\n'           { USE ($1); }
32928;
32929
32930exp:
32931  NUM                { $$ = $1;             }
32932| exp '=' exp
32933  {
32934    if ($1 != $3)
32935      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
32936    $$ = $1;
32937  }
32938| exp '+' exp        { $$ = $1 + $3;        }
32939| exp '-' exp        { $$ = $1 - $3;        }
32940| exp '*' exp        { $$ = $1 * $3;        }
32941| exp '/' exp        { $$ = $1 / $3;        }
32942| '-' exp  %prec NEG { $$ = -$2;            }
32943| exp '^' exp        { $$ = power ($1, $3); }
32944| '(' exp ')'        { $$ = $2;             }
32945| '(' error ')'      { $$ = 1111;           }
32946| '!'                { $$ = 0; YYERROR;     }
32947| '-' error          { $$ = 0; YYERROR;     }
32948;
32949%%
32950/* The input.  */
32951static FILE *input;
32952
32953static void
32954yyerror (
32955
32956         const char *s)
32957{
32958
32959
32960  fprintf (stderr, "%s\n", s);
32961}
32962
32963
32964
32965static int
32966get_char (void)
32967{
32968  int res = getc (input);
32969  ;
32970
32971  return res;
32972}
32973
32974
32975static void
32976unget_char ( int c)
32977{
32978  ;
32979
32980  ungetc (c, input);
32981}
32982
32983static int
32984read_signed_integer (void)
32985{
32986  int c = get_char ();
32987  int sign = 1;
32988  int n = 0;
32989
32990  ;
32991  if (c == '-')
32992    {
32993      c = get_char ();
32994      sign = -1;
32995    }
32996
32997  while (isdigit (c))
32998    {
32999      n = 10 * n + (c - '0');
33000      c = get_char ();
33001    }
33002
33003  unget_char ( c);
33004
33005  return sign * n;
33006}
33007
33008
33009
33010/*---------------------------------------------------------------.
33011| Lexical analyzer returns an integer on the stack and the token |
33012| NUM, or the ASCII character read if not a number.  Skips all   |
33013| blanks and tabs, returns 0 for EOF.                            |
33014`---------------------------------------------------------------*/
33015
33016static int
33017yylex (void)
33018{
33019  static int init = 1;
33020  int c;
33021
33022  if (init)
33023    {
33024      init = 0;
33025
33026    }
33027
33028
33029
33030  /* Skip white space.  */
33031  while ((c = get_char ()) == ' ' || c == '\t')
33032    {
33033
33034    }
33035
33036  /* process numbers   */
33037  if (c == '.' || isdigit (c))
33038    {
33039      unget_char ( c);
33040      (yylval).ival = read_signed_integer ();
33041      return NUM;
33042    }
33043
33044  /* Return end-of-file.  */
33045  if (c == EOF)
33046    return CALC_EOF;
33047
33048  /* Return single chars. */
33049  return c;
33050}
33051
33052static int
33053power (int base, int exponent)
33054{
33055  int res = 1;
33056  if (exponent < 0)
33057    exit (3);
33058  for (/* Niente */; exponent; --exponent)
33059    res *= base;
33060  return res;
33061}
33062
33063
33064int
33065main (int argc, const char **argv)
33066{
33067  semantic_value result = 0;
33068  int count = 0;
33069  int status;
33070
33071  /* This used to be alarm (10), but that isn't enough time for
33072     a July 1995 vintage DEC Alphastation 200 4/100 system,
33073     according to Nelson H. F. Beebe.  100 seconds is enough.  */
33074  alarm (100);
33075
33076  if (argc == 2)
33077    input = fopen (argv[1], "r");
33078  else
33079    input = stdin;
33080
33081  if (!input)
33082    {
33083      perror (argv[1]);
33084      return 3;
33085    }
33086
33087
33088  status = yyparse ();
33089  if (global_result != result)
33090    abort ();
33091  if (global_count != count)
33092    abort ();
33093  return status;
33094}
33095_ATEOF
33096
33097
33098
33099
33100
33101$at_traceoff
33102echo "calc.at:591: bison -o calc.c calc.y"
33103echo calc.at:591 >$at_check_line_file
33104( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
33105at_status=$?
33106grep '^ *+' $at_stder1 >&2
33107grep -v '^ *+' $at_stder1 >$at_stderr
33108at_failed=false
33109$at_diff $at_devnull $at_stderr || at_failed=:
33110$at_diff $at_devnull $at_stdout || at_failed=:
33111case $at_status in
33112   77) echo 77 > $at_status_file
33113            exit 77;;
33114   0) ;;
33115   *) echo "calc.at:591: exit code was $at_status, expected 0"
33116      at_failed=:;;
33117esac
33118if $at_failed; then
33119
33120  echo 1 > $at_status_file
33121  exit 1
33122fi
33123
33124$at_traceon
33125
33126   $at_traceoff
33127echo "calc.at:591: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
33128echo calc.at:591 >$at_check_line_file
33129( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
33130at_status=$?
33131grep '^ *+' $at_stder1 >&2
33132grep -v '^ *+' $at_stder1 >$at_stderr
33133at_failed=false
33134echo stderr:; cat $at_stderr
33135echo stdout:; cat $at_stdout
33136case $at_status in
33137   77) echo 77 > $at_status_file
33138            exit 77;;
33139   0) ;;
33140   *) echo "calc.at:591: exit code was $at_status, expected 0"
33141      at_failed=:;;
33142esac
33143if $at_failed; then
33144
33145  echo 1 > $at_status_file
33146  exit 1
33147fi
33148
33149$at_traceon
33150
33151
33152# Test the priorities.
33153cat >input <<'_ATEOF'
331541 + 2 * 3 = 7
331551 + 2 * -3 = -5
33156
33157-1^2 = -1
33158(-1)^2 = 1
33159
33160---1 = -1
33161
331621 - 2 - 3 = -4
331631 - (2 - 3) = 2
33164
331652^2^3 = 256
33166(2^2)^3 = 64
33167_ATEOF
33168
33169$at_traceoff
33170echo "calc.at:591: \$PREPARSER ./calc input"
33171echo calc.at:591 >$at_check_line_file
33172( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
33173at_status=$?
33174grep '^ *+' $at_stder1 >&2
33175grep -v '^ *+' $at_stder1 >$at_stderr
33176at_failed=false
33177echo stderr:; tee stderr <$at_stderr
33178$at_diff $at_devnull $at_stdout || at_failed=:
33179case $at_status in
33180   77) echo 77 > $at_status_file
33181            exit 77;;
33182   0) ;;
33183   *) echo "calc.at:591: exit code was $at_status, expected 0"
33184      at_failed=:;;
33185esac
33186if $at_failed; then
33187
33188  echo 1 > $at_status_file
33189  exit 1
33190fi
33191
33192$at_traceon
33193
33194
33195
33196# Some syntax errors.
33197cat >input <<'_ATEOF'
331980 0
33199_ATEOF
33200
33201$at_traceoff
33202echo "calc.at:591: \$PREPARSER ./calc input"
33203echo calc.at:591 >$at_check_line_file
33204( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
33205at_status=$?
33206grep '^ *+' $at_stder1 >&2
33207grep -v '^ *+' $at_stder1 >$at_stderr
33208at_failed=false
33209echo stderr:; tee stderr <$at_stderr
33210$at_diff $at_devnull $at_stdout || at_failed=:
33211case $at_status in
33212   77) echo 77 > $at_status_file
33213            exit 77;;
33214   1) ;;
33215   *) echo "calc.at:591: exit code was $at_status, expected 1"
33216      at_failed=:;;
33217esac
33218if $at_failed; then
33219
33220  echo 1 > $at_status_file
33221  exit 1
33222fi
33223
33224$at_traceon
33225
33226
33227# Normalize the observed and expected error messages, depending upon the
33228# options.
33229# 1. Remove the traces from observed.
33230sed '/^Starting/d
33231/^Entering/d
33232/^Stack/d
33233/^Reading/d
33234/^Reducing/d
33235/^Shifting/d
33236/^state/d
33237/^Cleanup:/d
33238/^Error:/d
33239/^Next/d
33240/^Discarding/d
33241/ \$[0-9$]* = /d
33242/^yydestructor:/d' stderr >at-stderr
33243mv at-stderr stderr
33244# 2. Create the reference error message.
33245cat >expout <<'_ATEOF'
332461.2: syntax error, unexpected number
33247_ATEOF
33248
33249# 3. If locations are not used, remove them.
33250sed 's/^[-0-9.]*: //' expout >at-expout
33251mv at-expout expout
33252# 4. If error-verbose is not used, strip the`, unexpected....' part.
33253sed 's/syntax error, .*$/syntax error/' expout >at-expout
33254mv at-expout expout
33255# 5. Check
33256$at_traceoff
33257echo "calc.at:591: cat stderr"
33258echo calc.at:591 >$at_check_line_file
33259( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
33260at_status=$?
33261grep '^ *+' $at_stder1 >&2
33262grep -v '^ *+' $at_stder1 >$at_stderr
33263at_failed=false
33264$at_diff $at_devnull $at_stderr || at_failed=:
33265$at_diff expout $at_stdout || at_failed=:
33266case $at_status in
33267   77) echo 77 > $at_status_file
33268            exit 77;;
33269   0) ;;
33270   *) echo "calc.at:591: exit code was $at_status, expected 0"
33271      at_failed=:;;
33272esac
33273if $at_failed; then
33274
33275  echo 1 > $at_status_file
33276  exit 1
33277fi
33278
33279$at_traceon
33280
33281
33282cat >input <<'_ATEOF'
332831//2
33284_ATEOF
33285
33286$at_traceoff
33287echo "calc.at:591: \$PREPARSER ./calc input"
33288echo calc.at:591 >$at_check_line_file
33289( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
33290at_status=$?
33291grep '^ *+' $at_stder1 >&2
33292grep -v '^ *+' $at_stder1 >$at_stderr
33293at_failed=false
33294echo stderr:; tee stderr <$at_stderr
33295$at_diff $at_devnull $at_stdout || at_failed=:
33296case $at_status in
33297   77) echo 77 > $at_status_file
33298            exit 77;;
33299   1) ;;
33300   *) echo "calc.at:591: exit code was $at_status, expected 1"
33301      at_failed=:;;
33302esac
33303if $at_failed; then
33304
33305  echo 1 > $at_status_file
33306  exit 1
33307fi
33308
33309$at_traceon
33310
33311
33312# Normalize the observed and expected error messages, depending upon the
33313# options.
33314# 1. Remove the traces from observed.
33315sed '/^Starting/d
33316/^Entering/d
33317/^Stack/d
33318/^Reading/d
33319/^Reducing/d
33320/^Shifting/d
33321/^state/d
33322/^Cleanup:/d
33323/^Error:/d
33324/^Next/d
33325/^Discarding/d
33326/ \$[0-9$]* = /d
33327/^yydestructor:/d' stderr >at-stderr
33328mv at-stderr stderr
33329# 2. Create the reference error message.
33330cat >expout <<'_ATEOF'
333311.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
33332_ATEOF
33333
33334# 3. If locations are not used, remove them.
33335sed 's/^[-0-9.]*: //' expout >at-expout
33336mv at-expout expout
33337# 4. If error-verbose is not used, strip the`, unexpected....' part.
33338sed 's/syntax error, .*$/syntax error/' expout >at-expout
33339mv at-expout expout
33340# 5. Check
33341$at_traceoff
33342echo "calc.at:591: cat stderr"
33343echo calc.at:591 >$at_check_line_file
33344( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
33345at_status=$?
33346grep '^ *+' $at_stder1 >&2
33347grep -v '^ *+' $at_stder1 >$at_stderr
33348at_failed=false
33349$at_diff $at_devnull $at_stderr || at_failed=:
33350$at_diff expout $at_stdout || at_failed=:
33351case $at_status in
33352   77) echo 77 > $at_status_file
33353            exit 77;;
33354   0) ;;
33355   *) echo "calc.at:591: exit code was $at_status, expected 0"
33356      at_failed=:;;
33357esac
33358if $at_failed; then
33359
33360  echo 1 > $at_status_file
33361  exit 1
33362fi
33363
33364$at_traceon
33365
33366
33367cat >input <<'_ATEOF'
33368error
33369_ATEOF
33370
33371$at_traceoff
33372echo "calc.at:591: \$PREPARSER ./calc input"
33373echo calc.at:591 >$at_check_line_file
33374( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
33375at_status=$?
33376grep '^ *+' $at_stder1 >&2
33377grep -v '^ *+' $at_stder1 >$at_stderr
33378at_failed=false
33379echo stderr:; tee stderr <$at_stderr
33380$at_diff $at_devnull $at_stdout || at_failed=:
33381case $at_status in
33382   77) echo 77 > $at_status_file
33383            exit 77;;
33384   1) ;;
33385   *) echo "calc.at:591: exit code was $at_status, expected 1"
33386      at_failed=:;;
33387esac
33388if $at_failed; then
33389
33390  echo 1 > $at_status_file
33391  exit 1
33392fi
33393
33394$at_traceon
33395
33396
33397# Normalize the observed and expected error messages, depending upon the
33398# options.
33399# 1. Remove the traces from observed.
33400sed '/^Starting/d
33401/^Entering/d
33402/^Stack/d
33403/^Reading/d
33404/^Reducing/d
33405/^Shifting/d
33406/^state/d
33407/^Cleanup:/d
33408/^Error:/d
33409/^Next/d
33410/^Discarding/d
33411/ \$[0-9$]* = /d
33412/^yydestructor:/d' stderr >at-stderr
33413mv at-stderr stderr
33414# 2. Create the reference error message.
33415cat >expout <<'_ATEOF'
334161.0: syntax error, unexpected $undefined
33417_ATEOF
33418
33419# 3. If locations are not used, remove them.
33420sed 's/^[-0-9.]*: //' expout >at-expout
33421mv at-expout expout
33422# 4. If error-verbose is not used, strip the`, unexpected....' part.
33423sed 's/syntax error, .*$/syntax error/' expout >at-expout
33424mv at-expout expout
33425# 5. Check
33426$at_traceoff
33427echo "calc.at:591: cat stderr"
33428echo calc.at:591 >$at_check_line_file
33429( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
33430at_status=$?
33431grep '^ *+' $at_stder1 >&2
33432grep -v '^ *+' $at_stder1 >$at_stderr
33433at_failed=false
33434$at_diff $at_devnull $at_stderr || at_failed=:
33435$at_diff expout $at_stdout || at_failed=:
33436case $at_status in
33437   77) echo 77 > $at_status_file
33438            exit 77;;
33439   0) ;;
33440   *) echo "calc.at:591: exit code was $at_status, expected 0"
33441      at_failed=:;;
33442esac
33443if $at_failed; then
33444
33445  echo 1 > $at_status_file
33446  exit 1
33447fi
33448
33449$at_traceon
33450
33451
33452cat >input <<'_ATEOF'
334531 = 2 = 3
33454_ATEOF
33455
33456$at_traceoff
33457echo "calc.at:591: \$PREPARSER ./calc input"
33458echo calc.at:591 >$at_check_line_file
33459( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
33460at_status=$?
33461grep '^ *+' $at_stder1 >&2
33462grep -v '^ *+' $at_stder1 >$at_stderr
33463at_failed=false
33464echo stderr:; tee stderr <$at_stderr
33465$at_diff $at_devnull $at_stdout || at_failed=:
33466case $at_status in
33467   77) echo 77 > $at_status_file
33468            exit 77;;
33469   1) ;;
33470   *) echo "calc.at:591: exit code was $at_status, expected 1"
33471      at_failed=:;;
33472esac
33473if $at_failed; then
33474
33475  echo 1 > $at_status_file
33476  exit 1
33477fi
33478
33479$at_traceon
33480
33481
33482# Normalize the observed and expected error messages, depending upon the
33483# options.
33484# 1. Remove the traces from observed.
33485sed '/^Starting/d
33486/^Entering/d
33487/^Stack/d
33488/^Reading/d
33489/^Reducing/d
33490/^Shifting/d
33491/^state/d
33492/^Cleanup:/d
33493/^Error:/d
33494/^Next/d
33495/^Discarding/d
33496/ \$[0-9$]* = /d
33497/^yydestructor:/d' stderr >at-stderr
33498mv at-stderr stderr
33499# 2. Create the reference error message.
33500cat >expout <<'_ATEOF'
335011.6: syntax error, unexpected '='
33502_ATEOF
33503
33504# 3. If locations are not used, remove them.
33505sed 's/^[-0-9.]*: //' expout >at-expout
33506mv at-expout expout
33507# 4. If error-verbose is not used, strip the`, unexpected....' part.
33508sed 's/syntax error, .*$/syntax error/' expout >at-expout
33509mv at-expout expout
33510# 5. Check
33511$at_traceoff
33512echo "calc.at:591: cat stderr"
33513echo calc.at:591 >$at_check_line_file
33514( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
33515at_status=$?
33516grep '^ *+' $at_stder1 >&2
33517grep -v '^ *+' $at_stder1 >$at_stderr
33518at_failed=false
33519$at_diff $at_devnull $at_stderr || at_failed=:
33520$at_diff expout $at_stdout || at_failed=:
33521case $at_status in
33522   77) echo 77 > $at_status_file
33523            exit 77;;
33524   0) ;;
33525   *) echo "calc.at:591: exit code was $at_status, expected 0"
33526      at_failed=:;;
33527esac
33528if $at_failed; then
33529
33530  echo 1 > $at_status_file
33531  exit 1
33532fi
33533
33534$at_traceon
33535
33536
33537cat >input <<'_ATEOF'
33538
33539+1
33540_ATEOF
33541
33542$at_traceoff
33543echo "calc.at:591: \$PREPARSER ./calc input"
33544echo calc.at:591 >$at_check_line_file
33545( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
33546at_status=$?
33547grep '^ *+' $at_stder1 >&2
33548grep -v '^ *+' $at_stder1 >$at_stderr
33549at_failed=false
33550echo stderr:; tee stderr <$at_stderr
33551$at_diff $at_devnull $at_stdout || at_failed=:
33552case $at_status in
33553   77) echo 77 > $at_status_file
33554            exit 77;;
33555   1) ;;
33556   *) echo "calc.at:591: exit code was $at_status, expected 1"
33557      at_failed=:;;
33558esac
33559if $at_failed; then
33560
33561  echo 1 > $at_status_file
33562  exit 1
33563fi
33564
33565$at_traceon
33566
33567
33568# Normalize the observed and expected error messages, depending upon the
33569# options.
33570# 1. Remove the traces from observed.
33571sed '/^Starting/d
33572/^Entering/d
33573/^Stack/d
33574/^Reading/d
33575/^Reducing/d
33576/^Shifting/d
33577/^state/d
33578/^Cleanup:/d
33579/^Error:/d
33580/^Next/d
33581/^Discarding/d
33582/ \$[0-9$]* = /d
33583/^yydestructor:/d' stderr >at-stderr
33584mv at-stderr stderr
33585# 2. Create the reference error message.
33586cat >expout <<'_ATEOF'
335872.0: syntax error, unexpected '+'
33588_ATEOF
33589
33590# 3. If locations are not used, remove them.
33591sed 's/^[-0-9.]*: //' expout >at-expout
33592mv at-expout expout
33593# 4. If error-verbose is not used, strip the`, unexpected....' part.
33594sed 's/syntax error, .*$/syntax error/' expout >at-expout
33595mv at-expout expout
33596# 5. Check
33597$at_traceoff
33598echo "calc.at:591: cat stderr"
33599echo calc.at:591 >$at_check_line_file
33600( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
33601at_status=$?
33602grep '^ *+' $at_stder1 >&2
33603grep -v '^ *+' $at_stder1 >$at_stderr
33604at_failed=false
33605$at_diff $at_devnull $at_stderr || at_failed=:
33606$at_diff expout $at_stdout || at_failed=:
33607case $at_status in
33608   77) echo 77 > $at_status_file
33609            exit 77;;
33610   0) ;;
33611   *) echo "calc.at:591: exit code was $at_status, expected 0"
33612      at_failed=:;;
33613esac
33614if $at_failed; then
33615
33616  echo 1 > $at_status_file
33617  exit 1
33618fi
33619
33620$at_traceon
33621
33622
33623# Exercise error messages with EOF: work on an empty file.
33624$at_traceoff
33625echo "calc.at:591: \$PREPARSER ./calc /dev/null"
33626echo calc.at:591 >$at_check_line_file
33627( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
33628at_status=$?
33629grep '^ *+' $at_stder1 >&2
33630grep -v '^ *+' $at_stder1 >$at_stderr
33631at_failed=false
33632echo stderr:; tee stderr <$at_stderr
33633$at_diff $at_devnull $at_stdout || at_failed=:
33634case $at_status in
33635   77) echo 77 > $at_status_file
33636            exit 77;;
33637   1) ;;
33638   *) echo "calc.at:591: exit code was $at_status, expected 1"
33639      at_failed=:;;
33640esac
33641if $at_failed; then
33642
33643  echo 1 > $at_status_file
33644  exit 1
33645fi
33646
33647$at_traceon
33648
33649
33650# Normalize the observed and expected error messages, depending upon the
33651# options.
33652# 1. Remove the traces from observed.
33653sed '/^Starting/d
33654/^Entering/d
33655/^Stack/d
33656/^Reading/d
33657/^Reducing/d
33658/^Shifting/d
33659/^state/d
33660/^Cleanup:/d
33661/^Error:/d
33662/^Next/d
33663/^Discarding/d
33664/ \$[0-9$]* = /d
33665/^yydestructor:/d' stderr >at-stderr
33666mv at-stderr stderr
33667# 2. Create the reference error message.
33668cat >expout <<'_ATEOF'
336691.0: syntax error, unexpected end of input
33670_ATEOF
33671
33672# 3. If locations are not used, remove them.
33673sed 's/^[-0-9.]*: //' expout >at-expout
33674mv at-expout expout
33675# 4. If error-verbose is not used, strip the`, unexpected....' part.
33676sed 's/syntax error, .*$/syntax error/' expout >at-expout
33677mv at-expout expout
33678# 5. Check
33679$at_traceoff
33680echo "calc.at:591: cat stderr"
33681echo calc.at:591 >$at_check_line_file
33682( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
33683at_status=$?
33684grep '^ *+' $at_stder1 >&2
33685grep -v '^ *+' $at_stder1 >$at_stderr
33686at_failed=false
33687$at_diff $at_devnull $at_stderr || at_failed=:
33688$at_diff expout $at_stdout || at_failed=:
33689case $at_status in
33690   77) echo 77 > $at_status_file
33691            exit 77;;
33692   0) ;;
33693   *) echo "calc.at:591: exit code was $at_status, expected 0"
33694      at_failed=:;;
33695esac
33696if $at_failed; then
33697
33698  echo 1 > $at_status_file
33699  exit 1
33700fi
33701
33702$at_traceon
33703
33704
33705
33706# Exercise the error token: without it, we die at the first error,
33707# hence be sure to
33708#
33709# - have several errors which exercise different shift/discardings
33710#   - (): nothing to pop, nothing to discard
33711#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
33712#   - (* * *): nothing to pop, a lot to discard
33713#   - (1 + 2 * *): some to pop and discard
33714#
33715# - test the action associated to `error'
33716#
33717# - check the look-ahead that triggers an error is not discarded
33718#   when we enter error recovery.  Below, the look-ahead causing the
33719#   first error is ")", which is needed to recover from the error and
33720#   produce the "0" that triggers the "0 != 1" error.
33721#
33722cat >input <<'_ATEOF'
33723() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
33724_ATEOF
33725
33726$at_traceoff
33727echo "calc.at:591: \$PREPARSER ./calc input"
33728echo calc.at:591 >$at_check_line_file
33729( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
33730at_status=$?
33731grep '^ *+' $at_stder1 >&2
33732grep -v '^ *+' $at_stder1 >$at_stderr
33733at_failed=false
33734echo stderr:; tee stderr <$at_stderr
33735$at_diff $at_devnull $at_stdout || at_failed=:
33736case $at_status in
33737   77) echo 77 > $at_status_file
33738            exit 77;;
33739   0) ;;
33740   *) echo "calc.at:591: exit code was $at_status, expected 0"
33741      at_failed=:;;
33742esac
33743if $at_failed; then
33744
33745  echo 1 > $at_status_file
33746  exit 1
33747fi
33748
33749$at_traceon
33750
33751
33752# Normalize the observed and expected error messages, depending upon the
33753# options.
33754# 1. Remove the traces from observed.
33755sed '/^Starting/d
33756/^Entering/d
33757/^Stack/d
33758/^Reading/d
33759/^Reducing/d
33760/^Shifting/d
33761/^state/d
33762/^Cleanup:/d
33763/^Error:/d
33764/^Next/d
33765/^Discarding/d
33766/ \$[0-9$]* = /d
33767/^yydestructor:/d' stderr >at-stderr
33768mv at-stderr stderr
33769# 2. Create the reference error message.
33770cat >expout <<'_ATEOF'
337711.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
337721.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
337731.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
337741.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
33775calc: error: 4444 != 1
33776_ATEOF
33777
33778# 3. If locations are not used, remove them.
33779sed 's/^[-0-9.]*: //' expout >at-expout
33780mv at-expout expout
33781# 4. If error-verbose is not used, strip the`, unexpected....' part.
33782sed 's/syntax error, .*$/syntax error/' expout >at-expout
33783mv at-expout expout
33784# 5. Check
33785$at_traceoff
33786echo "calc.at:591: cat stderr"
33787echo calc.at:591 >$at_check_line_file
33788( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
33789at_status=$?
33790grep '^ *+' $at_stder1 >&2
33791grep -v '^ *+' $at_stder1 >$at_stderr
33792at_failed=false
33793$at_diff $at_devnull $at_stderr || at_failed=:
33794$at_diff expout $at_stdout || at_failed=:
33795case $at_status in
33796   77) echo 77 > $at_status_file
33797            exit 77;;
33798   0) ;;
33799   *) echo "calc.at:591: exit code was $at_status, expected 0"
33800      at_failed=:;;
33801esac
33802if $at_failed; then
33803
33804  echo 1 > $at_status_file
33805  exit 1
33806fi
33807
33808$at_traceon
33809
33810
33811
33812# The same, but this time exercising explicitly triggered syntax errors.
33813# POSIX says the look-ahead causing the error should not be discarded.
33814cat >input <<'_ATEOF'
33815(!) + (0 0) = 1
33816_ATEOF
33817
33818$at_traceoff
33819echo "calc.at:591: \$PREPARSER ./calc input"
33820echo calc.at:591 >$at_check_line_file
33821( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
33822at_status=$?
33823grep '^ *+' $at_stder1 >&2
33824grep -v '^ *+' $at_stder1 >$at_stderr
33825at_failed=false
33826echo stderr:; tee stderr <$at_stderr
33827$at_diff $at_devnull $at_stdout || at_failed=:
33828case $at_status in
33829   77) echo 77 > $at_status_file
33830            exit 77;;
33831   0) ;;
33832   *) echo "calc.at:591: exit code was $at_status, expected 0"
33833      at_failed=:;;
33834esac
33835if $at_failed; then
33836
33837  echo 1 > $at_status_file
33838  exit 1
33839fi
33840
33841$at_traceon
33842
33843
33844# Normalize the observed and expected error messages, depending upon the
33845# options.
33846# 1. Remove the traces from observed.
33847sed '/^Starting/d
33848/^Entering/d
33849/^Stack/d
33850/^Reading/d
33851/^Reducing/d
33852/^Shifting/d
33853/^state/d
33854/^Cleanup:/d
33855/^Error:/d
33856/^Next/d
33857/^Discarding/d
33858/ \$[0-9$]* = /d
33859/^yydestructor:/d' stderr >at-stderr
33860mv at-stderr stderr
33861# 2. Create the reference error message.
33862cat >expout <<'_ATEOF'
338631.9: syntax error, unexpected number
33864calc: error: 2222 != 1
33865_ATEOF
33866
33867# 3. If locations are not used, remove them.
33868sed 's/^[-0-9.]*: //' expout >at-expout
33869mv at-expout expout
33870# 4. If error-verbose is not used, strip the`, unexpected....' part.
33871sed 's/syntax error, .*$/syntax error/' expout >at-expout
33872mv at-expout expout
33873# 5. Check
33874$at_traceoff
33875echo "calc.at:591: cat stderr"
33876echo calc.at:591 >$at_check_line_file
33877( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
33878at_status=$?
33879grep '^ *+' $at_stder1 >&2
33880grep -v '^ *+' $at_stder1 >$at_stderr
33881at_failed=false
33882$at_diff $at_devnull $at_stderr || at_failed=:
33883$at_diff expout $at_stdout || at_failed=:
33884case $at_status in
33885   77) echo 77 > $at_status_file
33886            exit 77;;
33887   0) ;;
33888   *) echo "calc.at:591: exit code was $at_status, expected 0"
33889      at_failed=:;;
33890esac
33891if $at_failed; then
33892
33893  echo 1 > $at_status_file
33894  exit 1
33895fi
33896
33897$at_traceon
33898
33899
33900cat >input <<'_ATEOF'
33901(- *) + (0 0) = 1
33902_ATEOF
33903
33904$at_traceoff
33905echo "calc.at:591: \$PREPARSER ./calc input"
33906echo calc.at:591 >$at_check_line_file
33907( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
33908at_status=$?
33909grep '^ *+' $at_stder1 >&2
33910grep -v '^ *+' $at_stder1 >$at_stderr
33911at_failed=false
33912echo stderr:; tee stderr <$at_stderr
33913$at_diff $at_devnull $at_stdout || at_failed=:
33914case $at_status in
33915   77) echo 77 > $at_status_file
33916            exit 77;;
33917   0) ;;
33918   *) echo "calc.at:591: exit code was $at_status, expected 0"
33919      at_failed=:;;
33920esac
33921if $at_failed; then
33922
33923  echo 1 > $at_status_file
33924  exit 1
33925fi
33926
33927$at_traceon
33928
33929
33930# Normalize the observed and expected error messages, depending upon the
33931# options.
33932# 1. Remove the traces from observed.
33933sed '/^Starting/d
33934/^Entering/d
33935/^Stack/d
33936/^Reading/d
33937/^Reducing/d
33938/^Shifting/d
33939/^state/d
33940/^Cleanup:/d
33941/^Error:/d
33942/^Next/d
33943/^Discarding/d
33944/ \$[0-9$]* = /d
33945/^yydestructor:/d' stderr >at-stderr
33946mv at-stderr stderr
33947# 2. Create the reference error message.
33948cat >expout <<'_ATEOF'
339491.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
339501.11: syntax error, unexpected number
33951calc: error: 2222 != 1
33952_ATEOF
33953
33954# 3. If locations are not used, remove them.
33955sed 's/^[-0-9.]*: //' expout >at-expout
33956mv at-expout expout
33957# 4. If error-verbose is not used, strip the`, unexpected....' part.
33958sed 's/syntax error, .*$/syntax error/' expout >at-expout
33959mv at-expout expout
33960# 5. Check
33961$at_traceoff
33962echo "calc.at:591: cat stderr"
33963echo calc.at:591 >$at_check_line_file
33964( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
33965at_status=$?
33966grep '^ *+' $at_stder1 >&2
33967grep -v '^ *+' $at_stder1 >$at_stderr
33968at_failed=false
33969$at_diff $at_devnull $at_stderr || at_failed=:
33970$at_diff expout $at_stdout || at_failed=:
33971case $at_status in
33972   77) echo 77 > $at_status_file
33973            exit 77;;
33974   0) ;;
33975   *) echo "calc.at:591: exit code was $at_status, expected 0"
33976      at_failed=:;;
33977esac
33978if $at_failed; then
33979
33980  echo 1 > $at_status_file
33981  exit 1
33982fi
33983
33984$at_traceon
33985
33986
33987
33988
33989
33990
33991
33992
33993
33994
33995
33996
33997
33998
33999
34000
34001
34002
34003
34004
34005
34006
34007
34008
34009      $at_traceoff
34010      $at_times_p && times >$at_times_file
34011    ) 5>&1 2>&1 | eval $at_tee_pipe
34012    at_status=`cat $at_status_file`
34013    ;;
34014
34015  89 ) # 89. calc.at:592: Calculator %glr-parser %yacc
34016    at_setup_line='calc.at:592'
34017    at_desc='Calculator %glr-parser %yacc'
34018    $at_quiet $ECHO_N " 89: Calculator %glr-parser %yacc                 $ECHO_C"
34019    at_xfail=no
34020    (
34021      echo "89. calc.at:592: testing ..."
34022      $at_traceon
34023
34024
34025
34026
34027
34028
34029
34030
34031# Using yacc.c?
34032
34033
34034
34035
34036
34037
34038
34039# yyerror receives the location if %location & %pure & (%glr or %parse-param).
34040
34041# yyerror always sees the locations (when activated), except if
34042# yacc & pure & !param.
34043
34044
34045# The interface is pure: either because %pure-parser, or because we
34046# are using the C++ parsers.
34047
34048
34049
34050
34051
34052
34053
34054
34055
34056
34057
34058
34059cat >calc.y <<'_ATEOF'
34060%{
34061#ifdef HAVE_CONFIG_H
34062# include <config.h>
34063  /* We don't need perfect functions for these tests. */
34064# undef malloc
34065# undef memcmp
34066# undef realloc
34067#endif
34068%}
34069
34070/* Infix notation calculator--calc */
34071%glr-parser %yacc
34072
34073%{
34074#include <stdio.h>
34075
34076#include <stdlib.h>
34077#include <string.h>
34078#if HAVE_UNISTD_H
34079# include <unistd.h>
34080#else
34081# undef alarm
34082# define alarm(seconds) /* empty */
34083#endif
34084#include <ctype.h>
34085#define USE(Var)
34086
34087/* Exercise pre-prologue dependency to %union.  */
34088typedef int semantic_value;
34089
34090static semantic_value global_result = 0;
34091static int global_count = 0;
34092%}
34093
34094/* Exercise %union. */
34095%union
34096{
34097  semantic_value ival;
34098};
34099
34100%{
34101static int power (int base, int exponent);
34102/* yyerror receives the location if:
34103   - %location & %pure & %glr
34104   - %location & %pure & %yacc & %parse-param. */
34105static void yyerror (
34106
34107                     const char *s
34108                     );
34109static int yylex (void);
34110static int get_char (void);
34111static void unget_char ( int c);
34112%}
34113
34114
34115
34116/* Bison Declarations */
34117%token CALC_EOF 0 "end of input"
34118%token <ival> NUM "number"
34119%type  <ival> exp
34120
34121%nonassoc '=' /* comparison	       */
34122%left '-' '+'
34123%left '*' '/'
34124%left NEG     /* negation--unary minus */
34125%right '^'    /* exponentiation        */
34126
34127/* Grammar follows */
34128%%
34129input:
34130  line
34131| input line         {  }
34132;
34133
34134line:
34135  '\n'
34136| exp '\n'           { USE ($1); }
34137;
34138
34139exp:
34140  NUM                { $$ = $1;             }
34141| exp '=' exp
34142  {
34143    if ($1 != $3)
34144      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
34145    $$ = $1;
34146  }
34147| exp '+' exp        { $$ = $1 + $3;        }
34148| exp '-' exp        { $$ = $1 - $3;        }
34149| exp '*' exp        { $$ = $1 * $3;        }
34150| exp '/' exp        { $$ = $1 / $3;        }
34151| '-' exp  %prec NEG { $$ = -$2;            }
34152| exp '^' exp        { $$ = power ($1, $3); }
34153| '(' exp ')'        { $$ = $2;             }
34154| '(' error ')'      { $$ = 1111;           }
34155| '!'                { $$ = 0; YYERROR;     }
34156| '-' error          { $$ = 0; YYERROR;     }
34157;
34158%%
34159/* The input.  */
34160static FILE *input;
34161
34162static void
34163yyerror (
34164
34165         const char *s)
34166{
34167
34168
34169  fprintf (stderr, "%s\n", s);
34170}
34171
34172
34173
34174static int
34175get_char (void)
34176{
34177  int res = getc (input);
34178  ;
34179
34180  return res;
34181}
34182
34183
34184static void
34185unget_char ( int c)
34186{
34187  ;
34188
34189  ungetc (c, input);
34190}
34191
34192static int
34193read_signed_integer (void)
34194{
34195  int c = get_char ();
34196  int sign = 1;
34197  int n = 0;
34198
34199  ;
34200  if (c == '-')
34201    {
34202      c = get_char ();
34203      sign = -1;
34204    }
34205
34206  while (isdigit (c))
34207    {
34208      n = 10 * n + (c - '0');
34209      c = get_char ();
34210    }
34211
34212  unget_char ( c);
34213
34214  return sign * n;
34215}
34216
34217
34218
34219/*---------------------------------------------------------------.
34220| Lexical analyzer returns an integer on the stack and the token |
34221| NUM, or the ASCII character read if not a number.  Skips all   |
34222| blanks and tabs, returns 0 for EOF.                            |
34223`---------------------------------------------------------------*/
34224
34225static int
34226yylex (void)
34227{
34228  static int init = 1;
34229  int c;
34230
34231  if (init)
34232    {
34233      init = 0;
34234
34235    }
34236
34237
34238
34239  /* Skip white space.  */
34240  while ((c = get_char ()) == ' ' || c == '\t')
34241    {
34242
34243    }
34244
34245  /* process numbers   */
34246  if (c == '.' || isdigit (c))
34247    {
34248      unget_char ( c);
34249      (yylval).ival = read_signed_integer ();
34250      return NUM;
34251    }
34252
34253  /* Return end-of-file.  */
34254  if (c == EOF)
34255    return CALC_EOF;
34256
34257  /* Return single chars. */
34258  return c;
34259}
34260
34261static int
34262power (int base, int exponent)
34263{
34264  int res = 1;
34265  if (exponent < 0)
34266    exit (3);
34267  for (/* Niente */; exponent; --exponent)
34268    res *= base;
34269  return res;
34270}
34271
34272
34273int
34274main (int argc, const char **argv)
34275{
34276  semantic_value result = 0;
34277  int count = 0;
34278  int status;
34279
34280  /* This used to be alarm (10), but that isn't enough time for
34281     a July 1995 vintage DEC Alphastation 200 4/100 system,
34282     according to Nelson H. F. Beebe.  100 seconds is enough.  */
34283  alarm (100);
34284
34285  if (argc == 2)
34286    input = fopen (argv[1], "r");
34287  else
34288    input = stdin;
34289
34290  if (!input)
34291    {
34292      perror (argv[1]);
34293      return 3;
34294    }
34295
34296
34297  status = yyparse ();
34298  if (global_result != result)
34299    abort ();
34300  if (global_count != count)
34301    abort ();
34302  return status;
34303}
34304_ATEOF
34305
34306
34307
34308
34309
34310$at_traceoff
34311echo "calc.at:592: bison -o calc.c calc.y"
34312echo calc.at:592 >$at_check_line_file
34313( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
34314at_status=$?
34315grep '^ *+' $at_stder1 >&2
34316grep -v '^ *+' $at_stder1 >$at_stderr
34317at_failed=false
34318$at_diff $at_devnull $at_stderr || at_failed=:
34319$at_diff $at_devnull $at_stdout || at_failed=:
34320case $at_status in
34321   77) echo 77 > $at_status_file
34322            exit 77;;
34323   0) ;;
34324   *) echo "calc.at:592: exit code was $at_status, expected 0"
34325      at_failed=:;;
34326esac
34327if $at_failed; then
34328
34329  echo 1 > $at_status_file
34330  exit 1
34331fi
34332
34333$at_traceon
34334
34335   $at_traceoff
34336echo "calc.at:592: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
34337echo calc.at:592 >$at_check_line_file
34338( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
34339at_status=$?
34340grep '^ *+' $at_stder1 >&2
34341grep -v '^ *+' $at_stder1 >$at_stderr
34342at_failed=false
34343echo stderr:; cat $at_stderr
34344echo stdout:; cat $at_stdout
34345case $at_status in
34346   77) echo 77 > $at_status_file
34347            exit 77;;
34348   0) ;;
34349   *) echo "calc.at:592: exit code was $at_status, expected 0"
34350      at_failed=:;;
34351esac
34352if $at_failed; then
34353
34354  echo 1 > $at_status_file
34355  exit 1
34356fi
34357
34358$at_traceon
34359
34360
34361# Test the priorities.
34362cat >input <<'_ATEOF'
343631 + 2 * 3 = 7
343641 + 2 * -3 = -5
34365
34366-1^2 = -1
34367(-1)^2 = 1
34368
34369---1 = -1
34370
343711 - 2 - 3 = -4
343721 - (2 - 3) = 2
34373
343742^2^3 = 256
34375(2^2)^3 = 64
34376_ATEOF
34377
34378$at_traceoff
34379echo "calc.at:592: \$PREPARSER ./calc input"
34380echo calc.at:592 >$at_check_line_file
34381( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
34382at_status=$?
34383grep '^ *+' $at_stder1 >&2
34384grep -v '^ *+' $at_stder1 >$at_stderr
34385at_failed=false
34386echo stderr:; tee stderr <$at_stderr
34387$at_diff $at_devnull $at_stdout || at_failed=:
34388case $at_status in
34389   77) echo 77 > $at_status_file
34390            exit 77;;
34391   0) ;;
34392   *) echo "calc.at:592: exit code was $at_status, expected 0"
34393      at_failed=:;;
34394esac
34395if $at_failed; then
34396
34397  echo 1 > $at_status_file
34398  exit 1
34399fi
34400
34401$at_traceon
34402
34403
34404
34405# Some syntax errors.
34406cat >input <<'_ATEOF'
344070 0
34408_ATEOF
34409
34410$at_traceoff
34411echo "calc.at:592: \$PREPARSER ./calc input"
34412echo calc.at:592 >$at_check_line_file
34413( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
34414at_status=$?
34415grep '^ *+' $at_stder1 >&2
34416grep -v '^ *+' $at_stder1 >$at_stderr
34417at_failed=false
34418echo stderr:; tee stderr <$at_stderr
34419$at_diff $at_devnull $at_stdout || at_failed=:
34420case $at_status in
34421   77) echo 77 > $at_status_file
34422            exit 77;;
34423   1) ;;
34424   *) echo "calc.at:592: exit code was $at_status, expected 1"
34425      at_failed=:;;
34426esac
34427if $at_failed; then
34428
34429  echo 1 > $at_status_file
34430  exit 1
34431fi
34432
34433$at_traceon
34434
34435
34436# Normalize the observed and expected error messages, depending upon the
34437# options.
34438# 1. Remove the traces from observed.
34439sed '/^Starting/d
34440/^Entering/d
34441/^Stack/d
34442/^Reading/d
34443/^Reducing/d
34444/^Shifting/d
34445/^state/d
34446/^Cleanup:/d
34447/^Error:/d
34448/^Next/d
34449/^Discarding/d
34450/ \$[0-9$]* = /d
34451/^yydestructor:/d' stderr >at-stderr
34452mv at-stderr stderr
34453# 2. Create the reference error message.
34454cat >expout <<'_ATEOF'
344551.2: syntax error, unexpected number
34456_ATEOF
34457
34458# 3. If locations are not used, remove them.
34459sed 's/^[-0-9.]*: //' expout >at-expout
34460mv at-expout expout
34461# 4. If error-verbose is not used, strip the`, unexpected....' part.
34462sed 's/syntax error, .*$/syntax error/' expout >at-expout
34463mv at-expout expout
34464# 5. Check
34465$at_traceoff
34466echo "calc.at:592: cat stderr"
34467echo calc.at:592 >$at_check_line_file
34468( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
34469at_status=$?
34470grep '^ *+' $at_stder1 >&2
34471grep -v '^ *+' $at_stder1 >$at_stderr
34472at_failed=false
34473$at_diff $at_devnull $at_stderr || at_failed=:
34474$at_diff expout $at_stdout || at_failed=:
34475case $at_status in
34476   77) echo 77 > $at_status_file
34477            exit 77;;
34478   0) ;;
34479   *) echo "calc.at:592: exit code was $at_status, expected 0"
34480      at_failed=:;;
34481esac
34482if $at_failed; then
34483
34484  echo 1 > $at_status_file
34485  exit 1
34486fi
34487
34488$at_traceon
34489
34490
34491cat >input <<'_ATEOF'
344921//2
34493_ATEOF
34494
34495$at_traceoff
34496echo "calc.at:592: \$PREPARSER ./calc input"
34497echo calc.at:592 >$at_check_line_file
34498( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
34499at_status=$?
34500grep '^ *+' $at_stder1 >&2
34501grep -v '^ *+' $at_stder1 >$at_stderr
34502at_failed=false
34503echo stderr:; tee stderr <$at_stderr
34504$at_diff $at_devnull $at_stdout || at_failed=:
34505case $at_status in
34506   77) echo 77 > $at_status_file
34507            exit 77;;
34508   1) ;;
34509   *) echo "calc.at:592: exit code was $at_status, expected 1"
34510      at_failed=:;;
34511esac
34512if $at_failed; then
34513
34514  echo 1 > $at_status_file
34515  exit 1
34516fi
34517
34518$at_traceon
34519
34520
34521# Normalize the observed and expected error messages, depending upon the
34522# options.
34523# 1. Remove the traces from observed.
34524sed '/^Starting/d
34525/^Entering/d
34526/^Stack/d
34527/^Reading/d
34528/^Reducing/d
34529/^Shifting/d
34530/^state/d
34531/^Cleanup:/d
34532/^Error:/d
34533/^Next/d
34534/^Discarding/d
34535/ \$[0-9$]* = /d
34536/^yydestructor:/d' stderr >at-stderr
34537mv at-stderr stderr
34538# 2. Create the reference error message.
34539cat >expout <<'_ATEOF'
345401.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
34541_ATEOF
34542
34543# 3. If locations are not used, remove them.
34544sed 's/^[-0-9.]*: //' expout >at-expout
34545mv at-expout expout
34546# 4. If error-verbose is not used, strip the`, unexpected....' part.
34547sed 's/syntax error, .*$/syntax error/' expout >at-expout
34548mv at-expout expout
34549# 5. Check
34550$at_traceoff
34551echo "calc.at:592: cat stderr"
34552echo calc.at:592 >$at_check_line_file
34553( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
34554at_status=$?
34555grep '^ *+' $at_stder1 >&2
34556grep -v '^ *+' $at_stder1 >$at_stderr
34557at_failed=false
34558$at_diff $at_devnull $at_stderr || at_failed=:
34559$at_diff expout $at_stdout || at_failed=:
34560case $at_status in
34561   77) echo 77 > $at_status_file
34562            exit 77;;
34563   0) ;;
34564   *) echo "calc.at:592: exit code was $at_status, expected 0"
34565      at_failed=:;;
34566esac
34567if $at_failed; then
34568
34569  echo 1 > $at_status_file
34570  exit 1
34571fi
34572
34573$at_traceon
34574
34575
34576cat >input <<'_ATEOF'
34577error
34578_ATEOF
34579
34580$at_traceoff
34581echo "calc.at:592: \$PREPARSER ./calc input"
34582echo calc.at:592 >$at_check_line_file
34583( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
34584at_status=$?
34585grep '^ *+' $at_stder1 >&2
34586grep -v '^ *+' $at_stder1 >$at_stderr
34587at_failed=false
34588echo stderr:; tee stderr <$at_stderr
34589$at_diff $at_devnull $at_stdout || at_failed=:
34590case $at_status in
34591   77) echo 77 > $at_status_file
34592            exit 77;;
34593   1) ;;
34594   *) echo "calc.at:592: exit code was $at_status, expected 1"
34595      at_failed=:;;
34596esac
34597if $at_failed; then
34598
34599  echo 1 > $at_status_file
34600  exit 1
34601fi
34602
34603$at_traceon
34604
34605
34606# Normalize the observed and expected error messages, depending upon the
34607# options.
34608# 1. Remove the traces from observed.
34609sed '/^Starting/d
34610/^Entering/d
34611/^Stack/d
34612/^Reading/d
34613/^Reducing/d
34614/^Shifting/d
34615/^state/d
34616/^Cleanup:/d
34617/^Error:/d
34618/^Next/d
34619/^Discarding/d
34620/ \$[0-9$]* = /d
34621/^yydestructor:/d' stderr >at-stderr
34622mv at-stderr stderr
34623# 2. Create the reference error message.
34624cat >expout <<'_ATEOF'
346251.0: syntax error, unexpected $undefined
34626_ATEOF
34627
34628# 3. If locations are not used, remove them.
34629sed 's/^[-0-9.]*: //' expout >at-expout
34630mv at-expout expout
34631# 4. If error-verbose is not used, strip the`, unexpected....' part.
34632sed 's/syntax error, .*$/syntax error/' expout >at-expout
34633mv at-expout expout
34634# 5. Check
34635$at_traceoff
34636echo "calc.at:592: cat stderr"
34637echo calc.at:592 >$at_check_line_file
34638( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
34639at_status=$?
34640grep '^ *+' $at_stder1 >&2
34641grep -v '^ *+' $at_stder1 >$at_stderr
34642at_failed=false
34643$at_diff $at_devnull $at_stderr || at_failed=:
34644$at_diff expout $at_stdout || at_failed=:
34645case $at_status in
34646   77) echo 77 > $at_status_file
34647            exit 77;;
34648   0) ;;
34649   *) echo "calc.at:592: exit code was $at_status, expected 0"
34650      at_failed=:;;
34651esac
34652if $at_failed; then
34653
34654  echo 1 > $at_status_file
34655  exit 1
34656fi
34657
34658$at_traceon
34659
34660
34661cat >input <<'_ATEOF'
346621 = 2 = 3
34663_ATEOF
34664
34665$at_traceoff
34666echo "calc.at:592: \$PREPARSER ./calc input"
34667echo calc.at:592 >$at_check_line_file
34668( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
34669at_status=$?
34670grep '^ *+' $at_stder1 >&2
34671grep -v '^ *+' $at_stder1 >$at_stderr
34672at_failed=false
34673echo stderr:; tee stderr <$at_stderr
34674$at_diff $at_devnull $at_stdout || at_failed=:
34675case $at_status in
34676   77) echo 77 > $at_status_file
34677            exit 77;;
34678   1) ;;
34679   *) echo "calc.at:592: exit code was $at_status, expected 1"
34680      at_failed=:;;
34681esac
34682if $at_failed; then
34683
34684  echo 1 > $at_status_file
34685  exit 1
34686fi
34687
34688$at_traceon
34689
34690
34691# Normalize the observed and expected error messages, depending upon the
34692# options.
34693# 1. Remove the traces from observed.
34694sed '/^Starting/d
34695/^Entering/d
34696/^Stack/d
34697/^Reading/d
34698/^Reducing/d
34699/^Shifting/d
34700/^state/d
34701/^Cleanup:/d
34702/^Error:/d
34703/^Next/d
34704/^Discarding/d
34705/ \$[0-9$]* = /d
34706/^yydestructor:/d' stderr >at-stderr
34707mv at-stderr stderr
34708# 2. Create the reference error message.
34709cat >expout <<'_ATEOF'
347101.6: syntax error, unexpected '='
34711_ATEOF
34712
34713# 3. If locations are not used, remove them.
34714sed 's/^[-0-9.]*: //' expout >at-expout
34715mv at-expout expout
34716# 4. If error-verbose is not used, strip the`, unexpected....' part.
34717sed 's/syntax error, .*$/syntax error/' expout >at-expout
34718mv at-expout expout
34719# 5. Check
34720$at_traceoff
34721echo "calc.at:592: cat stderr"
34722echo calc.at:592 >$at_check_line_file
34723( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
34724at_status=$?
34725grep '^ *+' $at_stder1 >&2
34726grep -v '^ *+' $at_stder1 >$at_stderr
34727at_failed=false
34728$at_diff $at_devnull $at_stderr || at_failed=:
34729$at_diff expout $at_stdout || at_failed=:
34730case $at_status in
34731   77) echo 77 > $at_status_file
34732            exit 77;;
34733   0) ;;
34734   *) echo "calc.at:592: exit code was $at_status, expected 0"
34735      at_failed=:;;
34736esac
34737if $at_failed; then
34738
34739  echo 1 > $at_status_file
34740  exit 1
34741fi
34742
34743$at_traceon
34744
34745
34746cat >input <<'_ATEOF'
34747
34748+1
34749_ATEOF
34750
34751$at_traceoff
34752echo "calc.at:592: \$PREPARSER ./calc input"
34753echo calc.at:592 >$at_check_line_file
34754( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
34755at_status=$?
34756grep '^ *+' $at_stder1 >&2
34757grep -v '^ *+' $at_stder1 >$at_stderr
34758at_failed=false
34759echo stderr:; tee stderr <$at_stderr
34760$at_diff $at_devnull $at_stdout || at_failed=:
34761case $at_status in
34762   77) echo 77 > $at_status_file
34763            exit 77;;
34764   1) ;;
34765   *) echo "calc.at:592: exit code was $at_status, expected 1"
34766      at_failed=:;;
34767esac
34768if $at_failed; then
34769
34770  echo 1 > $at_status_file
34771  exit 1
34772fi
34773
34774$at_traceon
34775
34776
34777# Normalize the observed and expected error messages, depending upon the
34778# options.
34779# 1. Remove the traces from observed.
34780sed '/^Starting/d
34781/^Entering/d
34782/^Stack/d
34783/^Reading/d
34784/^Reducing/d
34785/^Shifting/d
34786/^state/d
34787/^Cleanup:/d
34788/^Error:/d
34789/^Next/d
34790/^Discarding/d
34791/ \$[0-9$]* = /d
34792/^yydestructor:/d' stderr >at-stderr
34793mv at-stderr stderr
34794# 2. Create the reference error message.
34795cat >expout <<'_ATEOF'
347962.0: syntax error, unexpected '+'
34797_ATEOF
34798
34799# 3. If locations are not used, remove them.
34800sed 's/^[-0-9.]*: //' expout >at-expout
34801mv at-expout expout
34802# 4. If error-verbose is not used, strip the`, unexpected....' part.
34803sed 's/syntax error, .*$/syntax error/' expout >at-expout
34804mv at-expout expout
34805# 5. Check
34806$at_traceoff
34807echo "calc.at:592: cat stderr"
34808echo calc.at:592 >$at_check_line_file
34809( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
34810at_status=$?
34811grep '^ *+' $at_stder1 >&2
34812grep -v '^ *+' $at_stder1 >$at_stderr
34813at_failed=false
34814$at_diff $at_devnull $at_stderr || at_failed=:
34815$at_diff expout $at_stdout || at_failed=:
34816case $at_status in
34817   77) echo 77 > $at_status_file
34818            exit 77;;
34819   0) ;;
34820   *) echo "calc.at:592: exit code was $at_status, expected 0"
34821      at_failed=:;;
34822esac
34823if $at_failed; then
34824
34825  echo 1 > $at_status_file
34826  exit 1
34827fi
34828
34829$at_traceon
34830
34831
34832# Exercise error messages with EOF: work on an empty file.
34833$at_traceoff
34834echo "calc.at:592: \$PREPARSER ./calc /dev/null"
34835echo calc.at:592 >$at_check_line_file
34836( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
34837at_status=$?
34838grep '^ *+' $at_stder1 >&2
34839grep -v '^ *+' $at_stder1 >$at_stderr
34840at_failed=false
34841echo stderr:; tee stderr <$at_stderr
34842$at_diff $at_devnull $at_stdout || at_failed=:
34843case $at_status in
34844   77) echo 77 > $at_status_file
34845            exit 77;;
34846   1) ;;
34847   *) echo "calc.at:592: exit code was $at_status, expected 1"
34848      at_failed=:;;
34849esac
34850if $at_failed; then
34851
34852  echo 1 > $at_status_file
34853  exit 1
34854fi
34855
34856$at_traceon
34857
34858
34859# Normalize the observed and expected error messages, depending upon the
34860# options.
34861# 1. Remove the traces from observed.
34862sed '/^Starting/d
34863/^Entering/d
34864/^Stack/d
34865/^Reading/d
34866/^Reducing/d
34867/^Shifting/d
34868/^state/d
34869/^Cleanup:/d
34870/^Error:/d
34871/^Next/d
34872/^Discarding/d
34873/ \$[0-9$]* = /d
34874/^yydestructor:/d' stderr >at-stderr
34875mv at-stderr stderr
34876# 2. Create the reference error message.
34877cat >expout <<'_ATEOF'
348781.0: syntax error, unexpected end of input
34879_ATEOF
34880
34881# 3. If locations are not used, remove them.
34882sed 's/^[-0-9.]*: //' expout >at-expout
34883mv at-expout expout
34884# 4. If error-verbose is not used, strip the`, unexpected....' part.
34885sed 's/syntax error, .*$/syntax error/' expout >at-expout
34886mv at-expout expout
34887# 5. Check
34888$at_traceoff
34889echo "calc.at:592: cat stderr"
34890echo calc.at:592 >$at_check_line_file
34891( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
34892at_status=$?
34893grep '^ *+' $at_stder1 >&2
34894grep -v '^ *+' $at_stder1 >$at_stderr
34895at_failed=false
34896$at_diff $at_devnull $at_stderr || at_failed=:
34897$at_diff expout $at_stdout || at_failed=:
34898case $at_status in
34899   77) echo 77 > $at_status_file
34900            exit 77;;
34901   0) ;;
34902   *) echo "calc.at:592: exit code was $at_status, expected 0"
34903      at_failed=:;;
34904esac
34905if $at_failed; then
34906
34907  echo 1 > $at_status_file
34908  exit 1
34909fi
34910
34911$at_traceon
34912
34913
34914
34915# Exercise the error token: without it, we die at the first error,
34916# hence be sure to
34917#
34918# - have several errors which exercise different shift/discardings
34919#   - (): nothing to pop, nothing to discard
34920#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
34921#   - (* * *): nothing to pop, a lot to discard
34922#   - (1 + 2 * *): some to pop and discard
34923#
34924# - test the action associated to `error'
34925#
34926# - check the look-ahead that triggers an error is not discarded
34927#   when we enter error recovery.  Below, the look-ahead causing the
34928#   first error is ")", which is needed to recover from the error and
34929#   produce the "0" that triggers the "0 != 1" error.
34930#
34931cat >input <<'_ATEOF'
34932() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
34933_ATEOF
34934
34935$at_traceoff
34936echo "calc.at:592: \$PREPARSER ./calc input"
34937echo calc.at:592 >$at_check_line_file
34938( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
34939at_status=$?
34940grep '^ *+' $at_stder1 >&2
34941grep -v '^ *+' $at_stder1 >$at_stderr
34942at_failed=false
34943echo stderr:; tee stderr <$at_stderr
34944$at_diff $at_devnull $at_stdout || at_failed=:
34945case $at_status in
34946   77) echo 77 > $at_status_file
34947            exit 77;;
34948   0) ;;
34949   *) echo "calc.at:592: exit code was $at_status, expected 0"
34950      at_failed=:;;
34951esac
34952if $at_failed; then
34953
34954  echo 1 > $at_status_file
34955  exit 1
34956fi
34957
34958$at_traceon
34959
34960
34961# Normalize the observed and expected error messages, depending upon the
34962# options.
34963# 1. Remove the traces from observed.
34964sed '/^Starting/d
34965/^Entering/d
34966/^Stack/d
34967/^Reading/d
34968/^Reducing/d
34969/^Shifting/d
34970/^state/d
34971/^Cleanup:/d
34972/^Error:/d
34973/^Next/d
34974/^Discarding/d
34975/ \$[0-9$]* = /d
34976/^yydestructor:/d' stderr >at-stderr
34977mv at-stderr stderr
34978# 2. Create the reference error message.
34979cat >expout <<'_ATEOF'
349801.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
349811.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
349821.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
349831.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
34984calc: error: 4444 != 1
34985_ATEOF
34986
34987# 3. If locations are not used, remove them.
34988sed 's/^[-0-9.]*: //' expout >at-expout
34989mv at-expout expout
34990# 4. If error-verbose is not used, strip the`, unexpected....' part.
34991sed 's/syntax error, .*$/syntax error/' expout >at-expout
34992mv at-expout expout
34993# 5. Check
34994$at_traceoff
34995echo "calc.at:592: cat stderr"
34996echo calc.at:592 >$at_check_line_file
34997( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
34998at_status=$?
34999grep '^ *+' $at_stder1 >&2
35000grep -v '^ *+' $at_stder1 >$at_stderr
35001at_failed=false
35002$at_diff $at_devnull $at_stderr || at_failed=:
35003$at_diff expout $at_stdout || at_failed=:
35004case $at_status in
35005   77) echo 77 > $at_status_file
35006            exit 77;;
35007   0) ;;
35008   *) echo "calc.at:592: exit code was $at_status, expected 0"
35009      at_failed=:;;
35010esac
35011if $at_failed; then
35012
35013  echo 1 > $at_status_file
35014  exit 1
35015fi
35016
35017$at_traceon
35018
35019
35020
35021# The same, but this time exercising explicitly triggered syntax errors.
35022# POSIX says the look-ahead causing the error should not be discarded.
35023cat >input <<'_ATEOF'
35024(!) + (0 0) = 1
35025_ATEOF
35026
35027$at_traceoff
35028echo "calc.at:592: \$PREPARSER ./calc input"
35029echo calc.at:592 >$at_check_line_file
35030( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
35031at_status=$?
35032grep '^ *+' $at_stder1 >&2
35033grep -v '^ *+' $at_stder1 >$at_stderr
35034at_failed=false
35035echo stderr:; tee stderr <$at_stderr
35036$at_diff $at_devnull $at_stdout || at_failed=:
35037case $at_status in
35038   77) echo 77 > $at_status_file
35039            exit 77;;
35040   0) ;;
35041   *) echo "calc.at:592: exit code was $at_status, expected 0"
35042      at_failed=:;;
35043esac
35044if $at_failed; then
35045
35046  echo 1 > $at_status_file
35047  exit 1
35048fi
35049
35050$at_traceon
35051
35052
35053# Normalize the observed and expected error messages, depending upon the
35054# options.
35055# 1. Remove the traces from observed.
35056sed '/^Starting/d
35057/^Entering/d
35058/^Stack/d
35059/^Reading/d
35060/^Reducing/d
35061/^Shifting/d
35062/^state/d
35063/^Cleanup:/d
35064/^Error:/d
35065/^Next/d
35066/^Discarding/d
35067/ \$[0-9$]* = /d
35068/^yydestructor:/d' stderr >at-stderr
35069mv at-stderr stderr
35070# 2. Create the reference error message.
35071cat >expout <<'_ATEOF'
350721.9: syntax error, unexpected number
35073calc: error: 2222 != 1
35074_ATEOF
35075
35076# 3. If locations are not used, remove them.
35077sed 's/^[-0-9.]*: //' expout >at-expout
35078mv at-expout expout
35079# 4. If error-verbose is not used, strip the`, unexpected....' part.
35080sed 's/syntax error, .*$/syntax error/' expout >at-expout
35081mv at-expout expout
35082# 5. Check
35083$at_traceoff
35084echo "calc.at:592: cat stderr"
35085echo calc.at:592 >$at_check_line_file
35086( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
35087at_status=$?
35088grep '^ *+' $at_stder1 >&2
35089grep -v '^ *+' $at_stder1 >$at_stderr
35090at_failed=false
35091$at_diff $at_devnull $at_stderr || at_failed=:
35092$at_diff expout $at_stdout || at_failed=:
35093case $at_status in
35094   77) echo 77 > $at_status_file
35095            exit 77;;
35096   0) ;;
35097   *) echo "calc.at:592: exit code was $at_status, expected 0"
35098      at_failed=:;;
35099esac
35100if $at_failed; then
35101
35102  echo 1 > $at_status_file
35103  exit 1
35104fi
35105
35106$at_traceon
35107
35108
35109cat >input <<'_ATEOF'
35110(- *) + (0 0) = 1
35111_ATEOF
35112
35113$at_traceoff
35114echo "calc.at:592: \$PREPARSER ./calc input"
35115echo calc.at:592 >$at_check_line_file
35116( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
35117at_status=$?
35118grep '^ *+' $at_stder1 >&2
35119grep -v '^ *+' $at_stder1 >$at_stderr
35120at_failed=false
35121echo stderr:; tee stderr <$at_stderr
35122$at_diff $at_devnull $at_stdout || at_failed=:
35123case $at_status in
35124   77) echo 77 > $at_status_file
35125            exit 77;;
35126   0) ;;
35127   *) echo "calc.at:592: exit code was $at_status, expected 0"
35128      at_failed=:;;
35129esac
35130if $at_failed; then
35131
35132  echo 1 > $at_status_file
35133  exit 1
35134fi
35135
35136$at_traceon
35137
35138
35139# Normalize the observed and expected error messages, depending upon the
35140# options.
35141# 1. Remove the traces from observed.
35142sed '/^Starting/d
35143/^Entering/d
35144/^Stack/d
35145/^Reading/d
35146/^Reducing/d
35147/^Shifting/d
35148/^state/d
35149/^Cleanup:/d
35150/^Error:/d
35151/^Next/d
35152/^Discarding/d
35153/ \$[0-9$]* = /d
35154/^yydestructor:/d' stderr >at-stderr
35155mv at-stderr stderr
35156# 2. Create the reference error message.
35157cat >expout <<'_ATEOF'
351581.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
351591.11: syntax error, unexpected number
35160calc: error: 2222 != 1
35161_ATEOF
35162
35163# 3. If locations are not used, remove them.
35164sed 's/^[-0-9.]*: //' expout >at-expout
35165mv at-expout expout
35166# 4. If error-verbose is not used, strip the`, unexpected....' part.
35167sed 's/syntax error, .*$/syntax error/' expout >at-expout
35168mv at-expout expout
35169# 5. Check
35170$at_traceoff
35171echo "calc.at:592: cat stderr"
35172echo calc.at:592 >$at_check_line_file
35173( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
35174at_status=$?
35175grep '^ *+' $at_stder1 >&2
35176grep -v '^ *+' $at_stder1 >$at_stderr
35177at_failed=false
35178$at_diff $at_devnull $at_stderr || at_failed=:
35179$at_diff expout $at_stdout || at_failed=:
35180case $at_status in
35181   77) echo 77 > $at_status_file
35182            exit 77;;
35183   0) ;;
35184   *) echo "calc.at:592: exit code was $at_status, expected 0"
35185      at_failed=:;;
35186esac
35187if $at_failed; then
35188
35189  echo 1 > $at_status_file
35190  exit 1
35191fi
35192
35193$at_traceon
35194
35195
35196
35197
35198
35199
35200
35201
35202
35203
35204
35205
35206
35207
35208
35209
35210
35211
35212
35213
35214
35215
35216
35217
35218      $at_traceoff
35219      $at_times_p && times >$at_times_file
35220    ) 5>&1 2>&1 | eval $at_tee_pipe
35221    at_status=`cat $at_status_file`
35222    ;;
35223
35224  90 ) # 90. calc.at:593: Calculator %glr-parser %error-verbose
35225    at_setup_line='calc.at:593'
35226    at_desc='Calculator %glr-parser %error-verbose'
35227    $at_quiet $ECHO_N " 90: Calculator %glr-parser %error-verbose        $ECHO_C"
35228    at_xfail=no
35229    (
35230      echo "90. calc.at:593: testing ..."
35231      $at_traceon
35232
35233
35234
35235
35236
35237
35238
35239
35240# Using yacc.c?
35241
35242
35243
35244
35245
35246
35247
35248# yyerror receives the location if %location & %pure & (%glr or %parse-param).
35249
35250# yyerror always sees the locations (when activated), except if
35251# yacc & pure & !param.
35252
35253
35254# The interface is pure: either because %pure-parser, or because we
35255# are using the C++ parsers.
35256
35257
35258
35259
35260
35261
35262
35263
35264
35265
35266
35267
35268cat >calc.y <<'_ATEOF'
35269%{
35270#ifdef HAVE_CONFIG_H
35271# include <config.h>
35272  /* We don't need perfect functions for these tests. */
35273# undef malloc
35274# undef memcmp
35275# undef realloc
35276#endif
35277%}
35278
35279/* Infix notation calculator--calc */
35280%glr-parser %error-verbose
35281
35282%{
35283#include <stdio.h>
35284
35285#include <stdlib.h>
35286#include <string.h>
35287#if HAVE_UNISTD_H
35288# include <unistd.h>
35289#else
35290# undef alarm
35291# define alarm(seconds) /* empty */
35292#endif
35293#include <ctype.h>
35294#define USE(Var)
35295
35296/* Exercise pre-prologue dependency to %union.  */
35297typedef int semantic_value;
35298
35299static semantic_value global_result = 0;
35300static int global_count = 0;
35301%}
35302
35303/* Exercise %union. */
35304%union
35305{
35306  semantic_value ival;
35307};
35308
35309%{
35310static int power (int base, int exponent);
35311/* yyerror receives the location if:
35312   - %location & %pure & %glr
35313   - %location & %pure & %yacc & %parse-param. */
35314static void yyerror (
35315
35316                     const char *s
35317                     );
35318static int yylex (void);
35319static int get_char (void);
35320static void unget_char ( int c);
35321%}
35322
35323
35324
35325/* Bison Declarations */
35326%token CALC_EOF 0 "end of input"
35327%token <ival> NUM "number"
35328%type  <ival> exp
35329
35330%nonassoc '=' /* comparison	       */
35331%left '-' '+'
35332%left '*' '/'
35333%left NEG     /* negation--unary minus */
35334%right '^'    /* exponentiation        */
35335
35336/* Grammar follows */
35337%%
35338input:
35339  line
35340| input line         {  }
35341;
35342
35343line:
35344  '\n'
35345| exp '\n'           { USE ($1); }
35346;
35347
35348exp:
35349  NUM                { $$ = $1;             }
35350| exp '=' exp
35351  {
35352    if ($1 != $3)
35353      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
35354    $$ = $1;
35355  }
35356| exp '+' exp        { $$ = $1 + $3;        }
35357| exp '-' exp        { $$ = $1 - $3;        }
35358| exp '*' exp        { $$ = $1 * $3;        }
35359| exp '/' exp        { $$ = $1 / $3;        }
35360| '-' exp  %prec NEG { $$ = -$2;            }
35361| exp '^' exp        { $$ = power ($1, $3); }
35362| '(' exp ')'        { $$ = $2;             }
35363| '(' error ')'      { $$ = 1111;           }
35364| '!'                { $$ = 0; YYERROR;     }
35365| '-' error          { $$ = 0; YYERROR;     }
35366;
35367%%
35368/* The input.  */
35369static FILE *input;
35370
35371static void
35372yyerror (
35373
35374         const char *s)
35375{
35376
35377
35378  fprintf (stderr, "%s\n", s);
35379}
35380
35381
35382
35383static int
35384get_char (void)
35385{
35386  int res = getc (input);
35387  ;
35388
35389  return res;
35390}
35391
35392
35393static void
35394unget_char ( int c)
35395{
35396  ;
35397
35398  ungetc (c, input);
35399}
35400
35401static int
35402read_signed_integer (void)
35403{
35404  int c = get_char ();
35405  int sign = 1;
35406  int n = 0;
35407
35408  ;
35409  if (c == '-')
35410    {
35411      c = get_char ();
35412      sign = -1;
35413    }
35414
35415  while (isdigit (c))
35416    {
35417      n = 10 * n + (c - '0');
35418      c = get_char ();
35419    }
35420
35421  unget_char ( c);
35422
35423  return sign * n;
35424}
35425
35426
35427
35428/*---------------------------------------------------------------.
35429| Lexical analyzer returns an integer on the stack and the token |
35430| NUM, or the ASCII character read if not a number.  Skips all   |
35431| blanks and tabs, returns 0 for EOF.                            |
35432`---------------------------------------------------------------*/
35433
35434static int
35435yylex (void)
35436{
35437  static int init = 1;
35438  int c;
35439
35440  if (init)
35441    {
35442      init = 0;
35443
35444    }
35445
35446
35447
35448  /* Skip white space.  */
35449  while ((c = get_char ()) == ' ' || c == '\t')
35450    {
35451
35452    }
35453
35454  /* process numbers   */
35455  if (c == '.' || isdigit (c))
35456    {
35457      unget_char ( c);
35458      (yylval).ival = read_signed_integer ();
35459      return NUM;
35460    }
35461
35462  /* Return end-of-file.  */
35463  if (c == EOF)
35464    return CALC_EOF;
35465
35466  /* Return single chars. */
35467  return c;
35468}
35469
35470static int
35471power (int base, int exponent)
35472{
35473  int res = 1;
35474  if (exponent < 0)
35475    exit (3);
35476  for (/* Niente */; exponent; --exponent)
35477    res *= base;
35478  return res;
35479}
35480
35481
35482int
35483main (int argc, const char **argv)
35484{
35485  semantic_value result = 0;
35486  int count = 0;
35487  int status;
35488
35489  /* This used to be alarm (10), but that isn't enough time for
35490     a July 1995 vintage DEC Alphastation 200 4/100 system,
35491     according to Nelson H. F. Beebe.  100 seconds is enough.  */
35492  alarm (100);
35493
35494  if (argc == 2)
35495    input = fopen (argv[1], "r");
35496  else
35497    input = stdin;
35498
35499  if (!input)
35500    {
35501      perror (argv[1]);
35502      return 3;
35503    }
35504
35505
35506  status = yyparse ();
35507  if (global_result != result)
35508    abort ();
35509  if (global_count != count)
35510    abort ();
35511  return status;
35512}
35513_ATEOF
35514
35515
35516
35517
35518
35519$at_traceoff
35520echo "calc.at:593: bison -o calc.c calc.y"
35521echo calc.at:593 >$at_check_line_file
35522( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
35523at_status=$?
35524grep '^ *+' $at_stder1 >&2
35525grep -v '^ *+' $at_stder1 >$at_stderr
35526at_failed=false
35527$at_diff $at_devnull $at_stderr || at_failed=:
35528$at_diff $at_devnull $at_stdout || at_failed=:
35529case $at_status in
35530   77) echo 77 > $at_status_file
35531            exit 77;;
35532   0) ;;
35533   *) echo "calc.at:593: exit code was $at_status, expected 0"
35534      at_failed=:;;
35535esac
35536if $at_failed; then
35537
35538  echo 1 > $at_status_file
35539  exit 1
35540fi
35541
35542$at_traceon
35543
35544   $at_traceoff
35545echo "calc.at:593: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
35546echo calc.at:593 >$at_check_line_file
35547( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
35548at_status=$?
35549grep '^ *+' $at_stder1 >&2
35550grep -v '^ *+' $at_stder1 >$at_stderr
35551at_failed=false
35552echo stderr:; cat $at_stderr
35553echo stdout:; cat $at_stdout
35554case $at_status in
35555   77) echo 77 > $at_status_file
35556            exit 77;;
35557   0) ;;
35558   *) echo "calc.at:593: exit code was $at_status, expected 0"
35559      at_failed=:;;
35560esac
35561if $at_failed; then
35562
35563  echo 1 > $at_status_file
35564  exit 1
35565fi
35566
35567$at_traceon
35568
35569
35570# Test the priorities.
35571cat >input <<'_ATEOF'
355721 + 2 * 3 = 7
355731 + 2 * -3 = -5
35574
35575-1^2 = -1
35576(-1)^2 = 1
35577
35578---1 = -1
35579
355801 - 2 - 3 = -4
355811 - (2 - 3) = 2
35582
355832^2^3 = 256
35584(2^2)^3 = 64
35585_ATEOF
35586
35587$at_traceoff
35588echo "calc.at:593: \$PREPARSER ./calc input"
35589echo calc.at:593 >$at_check_line_file
35590( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
35591at_status=$?
35592grep '^ *+' $at_stder1 >&2
35593grep -v '^ *+' $at_stder1 >$at_stderr
35594at_failed=false
35595echo stderr:; tee stderr <$at_stderr
35596$at_diff $at_devnull $at_stdout || at_failed=:
35597case $at_status in
35598   77) echo 77 > $at_status_file
35599            exit 77;;
35600   0) ;;
35601   *) echo "calc.at:593: exit code was $at_status, expected 0"
35602      at_failed=:;;
35603esac
35604if $at_failed; then
35605
35606  echo 1 > $at_status_file
35607  exit 1
35608fi
35609
35610$at_traceon
35611
35612
35613
35614# Some syntax errors.
35615cat >input <<'_ATEOF'
356160 0
35617_ATEOF
35618
35619$at_traceoff
35620echo "calc.at:593: \$PREPARSER ./calc input"
35621echo calc.at:593 >$at_check_line_file
35622( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
35623at_status=$?
35624grep '^ *+' $at_stder1 >&2
35625grep -v '^ *+' $at_stder1 >$at_stderr
35626at_failed=false
35627echo stderr:; tee stderr <$at_stderr
35628$at_diff $at_devnull $at_stdout || at_failed=:
35629case $at_status in
35630   77) echo 77 > $at_status_file
35631            exit 77;;
35632   1) ;;
35633   *) echo "calc.at:593: exit code was $at_status, expected 1"
35634      at_failed=:;;
35635esac
35636if $at_failed; then
35637
35638  echo 1 > $at_status_file
35639  exit 1
35640fi
35641
35642$at_traceon
35643
35644
35645# Normalize the observed and expected error messages, depending upon the
35646# options.
35647# 1. Remove the traces from observed.
35648sed '/^Starting/d
35649/^Entering/d
35650/^Stack/d
35651/^Reading/d
35652/^Reducing/d
35653/^Shifting/d
35654/^state/d
35655/^Cleanup:/d
35656/^Error:/d
35657/^Next/d
35658/^Discarding/d
35659/ \$[0-9$]* = /d
35660/^yydestructor:/d' stderr >at-stderr
35661mv at-stderr stderr
35662# 2. Create the reference error message.
35663cat >expout <<'_ATEOF'
356641.2: syntax error, unexpected number
35665_ATEOF
35666
35667# 3. If locations are not used, remove them.
35668sed 's/^[-0-9.]*: //' expout >at-expout
35669mv at-expout expout
35670# 4. If error-verbose is not used, strip the`, unexpected....' part.
35671
35672# 5. Check
35673$at_traceoff
35674echo "calc.at:593: cat stderr"
35675echo calc.at:593 >$at_check_line_file
35676( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
35677at_status=$?
35678grep '^ *+' $at_stder1 >&2
35679grep -v '^ *+' $at_stder1 >$at_stderr
35680at_failed=false
35681$at_diff $at_devnull $at_stderr || at_failed=:
35682$at_diff expout $at_stdout || at_failed=:
35683case $at_status in
35684   77) echo 77 > $at_status_file
35685            exit 77;;
35686   0) ;;
35687   *) echo "calc.at:593: exit code was $at_status, expected 0"
35688      at_failed=:;;
35689esac
35690if $at_failed; then
35691
35692  echo 1 > $at_status_file
35693  exit 1
35694fi
35695
35696$at_traceon
35697
35698
35699cat >input <<'_ATEOF'
357001//2
35701_ATEOF
35702
35703$at_traceoff
35704echo "calc.at:593: \$PREPARSER ./calc input"
35705echo calc.at:593 >$at_check_line_file
35706( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
35707at_status=$?
35708grep '^ *+' $at_stder1 >&2
35709grep -v '^ *+' $at_stder1 >$at_stderr
35710at_failed=false
35711echo stderr:; tee stderr <$at_stderr
35712$at_diff $at_devnull $at_stdout || at_failed=:
35713case $at_status in
35714   77) echo 77 > $at_status_file
35715            exit 77;;
35716   1) ;;
35717   *) echo "calc.at:593: exit code was $at_status, expected 1"
35718      at_failed=:;;
35719esac
35720if $at_failed; then
35721
35722  echo 1 > $at_status_file
35723  exit 1
35724fi
35725
35726$at_traceon
35727
35728
35729# Normalize the observed and expected error messages, depending upon the
35730# options.
35731# 1. Remove the traces from observed.
35732sed '/^Starting/d
35733/^Entering/d
35734/^Stack/d
35735/^Reading/d
35736/^Reducing/d
35737/^Shifting/d
35738/^state/d
35739/^Cleanup:/d
35740/^Error:/d
35741/^Next/d
35742/^Discarding/d
35743/ \$[0-9$]* = /d
35744/^yydestructor:/d' stderr >at-stderr
35745mv at-stderr stderr
35746# 2. Create the reference error message.
35747cat >expout <<'_ATEOF'
357481.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
35749_ATEOF
35750
35751# 3. If locations are not used, remove them.
35752sed 's/^[-0-9.]*: //' expout >at-expout
35753mv at-expout expout
35754# 4. If error-verbose is not used, strip the`, unexpected....' part.
35755
35756# 5. Check
35757$at_traceoff
35758echo "calc.at:593: cat stderr"
35759echo calc.at:593 >$at_check_line_file
35760( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
35761at_status=$?
35762grep '^ *+' $at_stder1 >&2
35763grep -v '^ *+' $at_stder1 >$at_stderr
35764at_failed=false
35765$at_diff $at_devnull $at_stderr || at_failed=:
35766$at_diff expout $at_stdout || at_failed=:
35767case $at_status in
35768   77) echo 77 > $at_status_file
35769            exit 77;;
35770   0) ;;
35771   *) echo "calc.at:593: exit code was $at_status, expected 0"
35772      at_failed=:;;
35773esac
35774if $at_failed; then
35775
35776  echo 1 > $at_status_file
35777  exit 1
35778fi
35779
35780$at_traceon
35781
35782
35783cat >input <<'_ATEOF'
35784error
35785_ATEOF
35786
35787$at_traceoff
35788echo "calc.at:593: \$PREPARSER ./calc input"
35789echo calc.at:593 >$at_check_line_file
35790( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
35791at_status=$?
35792grep '^ *+' $at_stder1 >&2
35793grep -v '^ *+' $at_stder1 >$at_stderr
35794at_failed=false
35795echo stderr:; tee stderr <$at_stderr
35796$at_diff $at_devnull $at_stdout || at_failed=:
35797case $at_status in
35798   77) echo 77 > $at_status_file
35799            exit 77;;
35800   1) ;;
35801   *) echo "calc.at:593: exit code was $at_status, expected 1"
35802      at_failed=:;;
35803esac
35804if $at_failed; then
35805
35806  echo 1 > $at_status_file
35807  exit 1
35808fi
35809
35810$at_traceon
35811
35812
35813# Normalize the observed and expected error messages, depending upon the
35814# options.
35815# 1. Remove the traces from observed.
35816sed '/^Starting/d
35817/^Entering/d
35818/^Stack/d
35819/^Reading/d
35820/^Reducing/d
35821/^Shifting/d
35822/^state/d
35823/^Cleanup:/d
35824/^Error:/d
35825/^Next/d
35826/^Discarding/d
35827/ \$[0-9$]* = /d
35828/^yydestructor:/d' stderr >at-stderr
35829mv at-stderr stderr
35830# 2. Create the reference error message.
35831cat >expout <<'_ATEOF'
358321.0: syntax error, unexpected $undefined
35833_ATEOF
35834
35835# 3. If locations are not used, remove them.
35836sed 's/^[-0-9.]*: //' expout >at-expout
35837mv at-expout expout
35838# 4. If error-verbose is not used, strip the`, unexpected....' part.
35839
35840# 5. Check
35841$at_traceoff
35842echo "calc.at:593: cat stderr"
35843echo calc.at:593 >$at_check_line_file
35844( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
35845at_status=$?
35846grep '^ *+' $at_stder1 >&2
35847grep -v '^ *+' $at_stder1 >$at_stderr
35848at_failed=false
35849$at_diff $at_devnull $at_stderr || at_failed=:
35850$at_diff expout $at_stdout || at_failed=:
35851case $at_status in
35852   77) echo 77 > $at_status_file
35853            exit 77;;
35854   0) ;;
35855   *) echo "calc.at:593: exit code was $at_status, expected 0"
35856      at_failed=:;;
35857esac
35858if $at_failed; then
35859
35860  echo 1 > $at_status_file
35861  exit 1
35862fi
35863
35864$at_traceon
35865
35866
35867cat >input <<'_ATEOF'
358681 = 2 = 3
35869_ATEOF
35870
35871$at_traceoff
35872echo "calc.at:593: \$PREPARSER ./calc input"
35873echo calc.at:593 >$at_check_line_file
35874( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
35875at_status=$?
35876grep '^ *+' $at_stder1 >&2
35877grep -v '^ *+' $at_stder1 >$at_stderr
35878at_failed=false
35879echo stderr:; tee stderr <$at_stderr
35880$at_diff $at_devnull $at_stdout || at_failed=:
35881case $at_status in
35882   77) echo 77 > $at_status_file
35883            exit 77;;
35884   1) ;;
35885   *) echo "calc.at:593: exit code was $at_status, expected 1"
35886      at_failed=:;;
35887esac
35888if $at_failed; then
35889
35890  echo 1 > $at_status_file
35891  exit 1
35892fi
35893
35894$at_traceon
35895
35896
35897# Normalize the observed and expected error messages, depending upon the
35898# options.
35899# 1. Remove the traces from observed.
35900sed '/^Starting/d
35901/^Entering/d
35902/^Stack/d
35903/^Reading/d
35904/^Reducing/d
35905/^Shifting/d
35906/^state/d
35907/^Cleanup:/d
35908/^Error:/d
35909/^Next/d
35910/^Discarding/d
35911/ \$[0-9$]* = /d
35912/^yydestructor:/d' stderr >at-stderr
35913mv at-stderr stderr
35914# 2. Create the reference error message.
35915cat >expout <<'_ATEOF'
359161.6: syntax error, unexpected '='
35917_ATEOF
35918
35919# 3. If locations are not used, remove them.
35920sed 's/^[-0-9.]*: //' expout >at-expout
35921mv at-expout expout
35922# 4. If error-verbose is not used, strip the`, unexpected....' part.
35923
35924# 5. Check
35925$at_traceoff
35926echo "calc.at:593: cat stderr"
35927echo calc.at:593 >$at_check_line_file
35928( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
35929at_status=$?
35930grep '^ *+' $at_stder1 >&2
35931grep -v '^ *+' $at_stder1 >$at_stderr
35932at_failed=false
35933$at_diff $at_devnull $at_stderr || at_failed=:
35934$at_diff expout $at_stdout || at_failed=:
35935case $at_status in
35936   77) echo 77 > $at_status_file
35937            exit 77;;
35938   0) ;;
35939   *) echo "calc.at:593: exit code was $at_status, expected 0"
35940      at_failed=:;;
35941esac
35942if $at_failed; then
35943
35944  echo 1 > $at_status_file
35945  exit 1
35946fi
35947
35948$at_traceon
35949
35950
35951cat >input <<'_ATEOF'
35952
35953+1
35954_ATEOF
35955
35956$at_traceoff
35957echo "calc.at:593: \$PREPARSER ./calc input"
35958echo calc.at:593 >$at_check_line_file
35959( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
35960at_status=$?
35961grep '^ *+' $at_stder1 >&2
35962grep -v '^ *+' $at_stder1 >$at_stderr
35963at_failed=false
35964echo stderr:; tee stderr <$at_stderr
35965$at_diff $at_devnull $at_stdout || at_failed=:
35966case $at_status in
35967   77) echo 77 > $at_status_file
35968            exit 77;;
35969   1) ;;
35970   *) echo "calc.at:593: exit code was $at_status, expected 1"
35971      at_failed=:;;
35972esac
35973if $at_failed; then
35974
35975  echo 1 > $at_status_file
35976  exit 1
35977fi
35978
35979$at_traceon
35980
35981
35982# Normalize the observed and expected error messages, depending upon the
35983# options.
35984# 1. Remove the traces from observed.
35985sed '/^Starting/d
35986/^Entering/d
35987/^Stack/d
35988/^Reading/d
35989/^Reducing/d
35990/^Shifting/d
35991/^state/d
35992/^Cleanup:/d
35993/^Error:/d
35994/^Next/d
35995/^Discarding/d
35996/ \$[0-9$]* = /d
35997/^yydestructor:/d' stderr >at-stderr
35998mv at-stderr stderr
35999# 2. Create the reference error message.
36000cat >expout <<'_ATEOF'
360012.0: syntax error, unexpected '+'
36002_ATEOF
36003
36004# 3. If locations are not used, remove them.
36005sed 's/^[-0-9.]*: //' expout >at-expout
36006mv at-expout expout
36007# 4. If error-verbose is not used, strip the`, unexpected....' part.
36008
36009# 5. Check
36010$at_traceoff
36011echo "calc.at:593: cat stderr"
36012echo calc.at:593 >$at_check_line_file
36013( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
36014at_status=$?
36015grep '^ *+' $at_stder1 >&2
36016grep -v '^ *+' $at_stder1 >$at_stderr
36017at_failed=false
36018$at_diff $at_devnull $at_stderr || at_failed=:
36019$at_diff expout $at_stdout || at_failed=:
36020case $at_status in
36021   77) echo 77 > $at_status_file
36022            exit 77;;
36023   0) ;;
36024   *) echo "calc.at:593: exit code was $at_status, expected 0"
36025      at_failed=:;;
36026esac
36027if $at_failed; then
36028
36029  echo 1 > $at_status_file
36030  exit 1
36031fi
36032
36033$at_traceon
36034
36035
36036# Exercise error messages with EOF: work on an empty file.
36037$at_traceoff
36038echo "calc.at:593: \$PREPARSER ./calc /dev/null"
36039echo calc.at:593 >$at_check_line_file
36040( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
36041at_status=$?
36042grep '^ *+' $at_stder1 >&2
36043grep -v '^ *+' $at_stder1 >$at_stderr
36044at_failed=false
36045echo stderr:; tee stderr <$at_stderr
36046$at_diff $at_devnull $at_stdout || at_failed=:
36047case $at_status in
36048   77) echo 77 > $at_status_file
36049            exit 77;;
36050   1) ;;
36051   *) echo "calc.at:593: exit code was $at_status, expected 1"
36052      at_failed=:;;
36053esac
36054if $at_failed; then
36055
36056  echo 1 > $at_status_file
36057  exit 1
36058fi
36059
36060$at_traceon
36061
36062
36063# Normalize the observed and expected error messages, depending upon the
36064# options.
36065# 1. Remove the traces from observed.
36066sed '/^Starting/d
36067/^Entering/d
36068/^Stack/d
36069/^Reading/d
36070/^Reducing/d
36071/^Shifting/d
36072/^state/d
36073/^Cleanup:/d
36074/^Error:/d
36075/^Next/d
36076/^Discarding/d
36077/ \$[0-9$]* = /d
36078/^yydestructor:/d' stderr >at-stderr
36079mv at-stderr stderr
36080# 2. Create the reference error message.
36081cat >expout <<'_ATEOF'
360821.0: syntax error, unexpected end of input
36083_ATEOF
36084
36085# 3. If locations are not used, remove them.
36086sed 's/^[-0-9.]*: //' expout >at-expout
36087mv at-expout expout
36088# 4. If error-verbose is not used, strip the`, unexpected....' part.
36089
36090# 5. Check
36091$at_traceoff
36092echo "calc.at:593: cat stderr"
36093echo calc.at:593 >$at_check_line_file
36094( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
36095at_status=$?
36096grep '^ *+' $at_stder1 >&2
36097grep -v '^ *+' $at_stder1 >$at_stderr
36098at_failed=false
36099$at_diff $at_devnull $at_stderr || at_failed=:
36100$at_diff expout $at_stdout || at_failed=:
36101case $at_status in
36102   77) echo 77 > $at_status_file
36103            exit 77;;
36104   0) ;;
36105   *) echo "calc.at:593: exit code was $at_status, expected 0"
36106      at_failed=:;;
36107esac
36108if $at_failed; then
36109
36110  echo 1 > $at_status_file
36111  exit 1
36112fi
36113
36114$at_traceon
36115
36116
36117
36118# Exercise the error token: without it, we die at the first error,
36119# hence be sure to
36120#
36121# - have several errors which exercise different shift/discardings
36122#   - (): nothing to pop, nothing to discard
36123#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
36124#   - (* * *): nothing to pop, a lot to discard
36125#   - (1 + 2 * *): some to pop and discard
36126#
36127# - test the action associated to `error'
36128#
36129# - check the look-ahead that triggers an error is not discarded
36130#   when we enter error recovery.  Below, the look-ahead causing the
36131#   first error is ")", which is needed to recover from the error and
36132#   produce the "0" that triggers the "0 != 1" error.
36133#
36134cat >input <<'_ATEOF'
36135() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
36136_ATEOF
36137
36138$at_traceoff
36139echo "calc.at:593: \$PREPARSER ./calc input"
36140echo calc.at:593 >$at_check_line_file
36141( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
36142at_status=$?
36143grep '^ *+' $at_stder1 >&2
36144grep -v '^ *+' $at_stder1 >$at_stderr
36145at_failed=false
36146echo stderr:; tee stderr <$at_stderr
36147$at_diff $at_devnull $at_stdout || at_failed=:
36148case $at_status in
36149   77) echo 77 > $at_status_file
36150            exit 77;;
36151   0) ;;
36152   *) echo "calc.at:593: exit code was $at_status, expected 0"
36153      at_failed=:;;
36154esac
36155if $at_failed; then
36156
36157  echo 1 > $at_status_file
36158  exit 1
36159fi
36160
36161$at_traceon
36162
36163
36164# Normalize the observed and expected error messages, depending upon the
36165# options.
36166# 1. Remove the traces from observed.
36167sed '/^Starting/d
36168/^Entering/d
36169/^Stack/d
36170/^Reading/d
36171/^Reducing/d
36172/^Shifting/d
36173/^state/d
36174/^Cleanup:/d
36175/^Error:/d
36176/^Next/d
36177/^Discarding/d
36178/ \$[0-9$]* = /d
36179/^yydestructor:/d' stderr >at-stderr
36180mv at-stderr stderr
36181# 2. Create the reference error message.
36182cat >expout <<'_ATEOF'
361831.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
361841.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
361851.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
361861.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
36187calc: error: 4444 != 1
36188_ATEOF
36189
36190# 3. If locations are not used, remove them.
36191sed 's/^[-0-9.]*: //' expout >at-expout
36192mv at-expout expout
36193# 4. If error-verbose is not used, strip the`, unexpected....' part.
36194
36195# 5. Check
36196$at_traceoff
36197echo "calc.at:593: cat stderr"
36198echo calc.at:593 >$at_check_line_file
36199( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
36200at_status=$?
36201grep '^ *+' $at_stder1 >&2
36202grep -v '^ *+' $at_stder1 >$at_stderr
36203at_failed=false
36204$at_diff $at_devnull $at_stderr || at_failed=:
36205$at_diff expout $at_stdout || at_failed=:
36206case $at_status in
36207   77) echo 77 > $at_status_file
36208            exit 77;;
36209   0) ;;
36210   *) echo "calc.at:593: exit code was $at_status, expected 0"
36211      at_failed=:;;
36212esac
36213if $at_failed; then
36214
36215  echo 1 > $at_status_file
36216  exit 1
36217fi
36218
36219$at_traceon
36220
36221
36222
36223# The same, but this time exercising explicitly triggered syntax errors.
36224# POSIX says the look-ahead causing the error should not be discarded.
36225cat >input <<'_ATEOF'
36226(!) + (0 0) = 1
36227_ATEOF
36228
36229$at_traceoff
36230echo "calc.at:593: \$PREPARSER ./calc input"
36231echo calc.at:593 >$at_check_line_file
36232( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
36233at_status=$?
36234grep '^ *+' $at_stder1 >&2
36235grep -v '^ *+' $at_stder1 >$at_stderr
36236at_failed=false
36237echo stderr:; tee stderr <$at_stderr
36238$at_diff $at_devnull $at_stdout || at_failed=:
36239case $at_status in
36240   77) echo 77 > $at_status_file
36241            exit 77;;
36242   0) ;;
36243   *) echo "calc.at:593: exit code was $at_status, expected 0"
36244      at_failed=:;;
36245esac
36246if $at_failed; then
36247
36248  echo 1 > $at_status_file
36249  exit 1
36250fi
36251
36252$at_traceon
36253
36254
36255# Normalize the observed and expected error messages, depending upon the
36256# options.
36257# 1. Remove the traces from observed.
36258sed '/^Starting/d
36259/^Entering/d
36260/^Stack/d
36261/^Reading/d
36262/^Reducing/d
36263/^Shifting/d
36264/^state/d
36265/^Cleanup:/d
36266/^Error:/d
36267/^Next/d
36268/^Discarding/d
36269/ \$[0-9$]* = /d
36270/^yydestructor:/d' stderr >at-stderr
36271mv at-stderr stderr
36272# 2. Create the reference error message.
36273cat >expout <<'_ATEOF'
362741.9: syntax error, unexpected number
36275calc: error: 2222 != 1
36276_ATEOF
36277
36278# 3. If locations are not used, remove them.
36279sed 's/^[-0-9.]*: //' expout >at-expout
36280mv at-expout expout
36281# 4. If error-verbose is not used, strip the`, unexpected....' part.
36282
36283# 5. Check
36284$at_traceoff
36285echo "calc.at:593: cat stderr"
36286echo calc.at:593 >$at_check_line_file
36287( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
36288at_status=$?
36289grep '^ *+' $at_stder1 >&2
36290grep -v '^ *+' $at_stder1 >$at_stderr
36291at_failed=false
36292$at_diff $at_devnull $at_stderr || at_failed=:
36293$at_diff expout $at_stdout || at_failed=:
36294case $at_status in
36295   77) echo 77 > $at_status_file
36296            exit 77;;
36297   0) ;;
36298   *) echo "calc.at:593: exit code was $at_status, expected 0"
36299      at_failed=:;;
36300esac
36301if $at_failed; then
36302
36303  echo 1 > $at_status_file
36304  exit 1
36305fi
36306
36307$at_traceon
36308
36309
36310cat >input <<'_ATEOF'
36311(- *) + (0 0) = 1
36312_ATEOF
36313
36314$at_traceoff
36315echo "calc.at:593: \$PREPARSER ./calc input"
36316echo calc.at:593 >$at_check_line_file
36317( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
36318at_status=$?
36319grep '^ *+' $at_stder1 >&2
36320grep -v '^ *+' $at_stder1 >$at_stderr
36321at_failed=false
36322echo stderr:; tee stderr <$at_stderr
36323$at_diff $at_devnull $at_stdout || at_failed=:
36324case $at_status in
36325   77) echo 77 > $at_status_file
36326            exit 77;;
36327   0) ;;
36328   *) echo "calc.at:593: exit code was $at_status, expected 0"
36329      at_failed=:;;
36330esac
36331if $at_failed; then
36332
36333  echo 1 > $at_status_file
36334  exit 1
36335fi
36336
36337$at_traceon
36338
36339
36340# Normalize the observed and expected error messages, depending upon the
36341# options.
36342# 1. Remove the traces from observed.
36343sed '/^Starting/d
36344/^Entering/d
36345/^Stack/d
36346/^Reading/d
36347/^Reducing/d
36348/^Shifting/d
36349/^state/d
36350/^Cleanup:/d
36351/^Error:/d
36352/^Next/d
36353/^Discarding/d
36354/ \$[0-9$]* = /d
36355/^yydestructor:/d' stderr >at-stderr
36356mv at-stderr stderr
36357# 2. Create the reference error message.
36358cat >expout <<'_ATEOF'
363591.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
363601.11: syntax error, unexpected number
36361calc: error: 2222 != 1
36362_ATEOF
36363
36364# 3. If locations are not used, remove them.
36365sed 's/^[-0-9.]*: //' expout >at-expout
36366mv at-expout expout
36367# 4. If error-verbose is not used, strip the`, unexpected....' part.
36368
36369# 5. Check
36370$at_traceoff
36371echo "calc.at:593: cat stderr"
36372echo calc.at:593 >$at_check_line_file
36373( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
36374at_status=$?
36375grep '^ *+' $at_stder1 >&2
36376grep -v '^ *+' $at_stder1 >$at_stderr
36377at_failed=false
36378$at_diff $at_devnull $at_stderr || at_failed=:
36379$at_diff expout $at_stdout || at_failed=:
36380case $at_status in
36381   77) echo 77 > $at_status_file
36382            exit 77;;
36383   0) ;;
36384   *) echo "calc.at:593: exit code was $at_status, expected 0"
36385      at_failed=:;;
36386esac
36387if $at_failed; then
36388
36389  echo 1 > $at_status_file
36390  exit 1
36391fi
36392
36393$at_traceon
36394
36395
36396
36397
36398
36399
36400
36401
36402
36403
36404
36405
36406
36407
36408
36409
36410
36411
36412
36413
36414
36415
36416
36417
36418      $at_traceoff
36419      $at_times_p && times >$at_times_file
36420    ) 5>&1 2>&1 | eval $at_tee_pipe
36421    at_status=`cat $at_status_file`
36422    ;;
36423
36424  91 ) # 91. calc.at:595: Calculator %glr-parser %pure-parser %locations
36425    at_setup_line='calc.at:595'
36426    at_desc='Calculator %glr-parser %pure-parser %locations'
36427    $at_quiet $ECHO_N " 91: Calculator %glr-parser %pure-parser %locations$ECHO_C"
36428    at_xfail=no
36429    (
36430      echo "91. calc.at:595: testing ..."
36431      $at_traceon
36432
36433
36434
36435
36436
36437
36438
36439
36440# Using yacc.c?
36441
36442
36443
36444
36445
36446
36447
36448# yyerror receives the location if %location & %pure & (%glr or %parse-param).
36449
36450# yyerror always sees the locations (when activated), except if
36451# yacc & pure & !param.
36452
36453
36454# The interface is pure: either because %pure-parser, or because we
36455# are using the C++ parsers.
36456
36457
36458
36459
36460
36461
36462
36463
36464
36465
36466
36467
36468cat >calc.y <<'_ATEOF'
36469%{
36470#ifdef HAVE_CONFIG_H
36471# include <config.h>
36472  /* We don't need perfect functions for these tests. */
36473# undef malloc
36474# undef memcmp
36475# undef realloc
36476#endif
36477%}
36478
36479/* Infix notation calculator--calc */
36480%glr-parser %pure-parser %locations
36481
36482%{
36483#include <stdio.h>
36484
36485#include <stdlib.h>
36486#include <string.h>
36487#if HAVE_UNISTD_H
36488# include <unistd.h>
36489#else
36490# undef alarm
36491# define alarm(seconds) /* empty */
36492#endif
36493#include <ctype.h>
36494#define USE(Var)
36495
36496/* Exercise pre-prologue dependency to %union.  */
36497typedef int semantic_value;
36498
36499static semantic_value global_result = 0;
36500static int global_count = 0;
36501%}
36502
36503/* Exercise %union. */
36504%union
36505{
36506  semantic_value ival;
36507};
36508
36509%{
36510static int power (int base, int exponent);
36511/* yyerror receives the location if:
36512   - %location & %pure & %glr
36513   - %location & %pure & %yacc & %parse-param. */
36514static void yyerror (YYLTYPE *llocp,
36515
36516                     const char *s
36517                     );
36518static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
36519static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp);
36520static void unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c);
36521%}
36522
36523
36524
36525/* Bison Declarations */
36526%token CALC_EOF 0 "end of input"
36527%token <ival> NUM "number"
36528%type  <ival> exp
36529
36530%nonassoc '=' /* comparison	       */
36531%left '-' '+'
36532%left '*' '/'
36533%left NEG     /* negation--unary minus */
36534%right '^'    /* exponentiation        */
36535
36536/* Grammar follows */
36537%%
36538input:
36539  line
36540| input line         {  }
36541;
36542
36543line:
36544  '\n'
36545| exp '\n'           { USE ($1); }
36546;
36547
36548exp:
36549  NUM                { $$ = $1;             }
36550| exp '=' exp
36551  {
36552    if ($1 != $3)
36553      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
36554    $$ = $1;
36555  }
36556| exp '+' exp        { $$ = $1 + $3;        }
36557| exp '-' exp        { $$ = $1 - $3;        }
36558| exp '*' exp        { $$ = $1 * $3;        }
36559| exp '/' exp        { $$ = $1 / $3;        }
36560| '-' exp  %prec NEG { $$ = -$2;            }
36561| exp '^' exp        { $$ = power ($1, $3); }
36562| '(' exp ')'        { $$ = $2;             }
36563| '(' error ')'      { $$ = 1111;           }
36564| '!'                { $$ = 0; YYERROR;     }
36565| '-' error          { $$ = 0; YYERROR;     }
36566;
36567%%
36568/* The input.  */
36569static FILE *input;
36570
36571static void
36572yyerror (YYLTYPE *llocp,
36573
36574         const char *s)
36575{
36576
36577
36578  fprintf (stderr, "%d.%d",
36579           (*llocp).first_line, (*llocp).first_column);
36580  if ((*llocp).first_line != (*llocp).last_line)
36581    fprintf (stderr, "-%d.%d",
36582	     (*llocp).last_line,  (*llocp).last_column - 1);
36583  else if ((*llocp).first_column != (*llocp).last_column - 1)
36584    fprintf (stderr, "-%d",
36585	     (*llocp).last_column - 1);
36586  fprintf (stderr, ": ");
36587  fprintf (stderr, "%s\n", s);
36588}
36589
36590
36591
36592static YYLTYPE last_yylloc;
36593
36594static int
36595get_char (YYSTYPE *lvalp, YYLTYPE *llocp)
36596{
36597  int res = getc (input);
36598  (void) lvalp;(void) llocp;
36599
36600  last_yylloc = (*llocp);
36601  if (res == '\n')
36602    {
36603      (*llocp).last_line++;
36604      (*llocp).last_column = 0;
36605    }
36606  else
36607    (*llocp).last_column++;
36608
36609  return res;
36610}
36611
36612
36613static void
36614unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c)
36615{
36616  (void) lvalp;(void) llocp;
36617
36618  /* Wrong when C == `\n'. */
36619  (*llocp) = last_yylloc;
36620
36621  ungetc (c, input);
36622}
36623
36624static int
36625read_signed_integer (YYSTYPE *lvalp, YYLTYPE *llocp)
36626{
36627  int c = get_char (lvalp, llocp);
36628  int sign = 1;
36629  int n = 0;
36630
36631  (void) lvalp;(void) llocp;
36632  if (c == '-')
36633    {
36634      c = get_char (lvalp, llocp);
36635      sign = -1;
36636    }
36637
36638  while (isdigit (c))
36639    {
36640      n = 10 * n + (c - '0');
36641      c = get_char (lvalp, llocp);
36642    }
36643
36644  unget_char (lvalp, llocp,  c);
36645
36646  return sign * n;
36647}
36648
36649
36650
36651/*---------------------------------------------------------------.
36652| Lexical analyzer returns an integer on the stack and the token |
36653| NUM, or the ASCII character read if not a number.  Skips all   |
36654| blanks and tabs, returns 0 for EOF.                            |
36655`---------------------------------------------------------------*/
36656
36657static int
36658yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
36659{
36660  static int init = 1;
36661  int c;
36662
36663  if (init)
36664    {
36665      init = 0;
36666
36667      (*llocp).last_column = 0;
36668      (*llocp).last_line = 1;
36669
36670    }
36671
36672
36673 (*llocp).first_column = (*llocp).last_column;
36674  (*llocp).first_line   = (*llocp).last_line;
36675
36676
36677  /* Skip white space.  */
36678  while ((c = get_char (lvalp, llocp)) == ' ' || c == '\t')
36679    {
36680     (*llocp).first_column = (*llocp).last_column;
36681      (*llocp).first_line   = (*llocp).last_line;
36682
36683    }
36684
36685  /* process numbers   */
36686  if (c == '.' || isdigit (c))
36687    {
36688      unget_char (lvalp, llocp,  c);
36689      (*lvalp).ival = read_signed_integer (lvalp, llocp);
36690      return NUM;
36691    }
36692
36693  /* Return end-of-file.  */
36694  if (c == EOF)
36695    return CALC_EOF;
36696
36697  /* Return single chars. */
36698  return c;
36699}
36700
36701static int
36702power (int base, int exponent)
36703{
36704  int res = 1;
36705  if (exponent < 0)
36706    exit (3);
36707  for (/* Niente */; exponent; --exponent)
36708    res *= base;
36709  return res;
36710}
36711
36712
36713int
36714main (int argc, const char **argv)
36715{
36716  semantic_value result = 0;
36717  int count = 0;
36718  int status;
36719
36720  /* This used to be alarm (10), but that isn't enough time for
36721     a July 1995 vintage DEC Alphastation 200 4/100 system,
36722     according to Nelson H. F. Beebe.  100 seconds is enough.  */
36723  alarm (100);
36724
36725  if (argc == 2)
36726    input = fopen (argv[1], "r");
36727  else
36728    input = stdin;
36729
36730  if (!input)
36731    {
36732      perror (argv[1]);
36733      return 3;
36734    }
36735
36736
36737  status = yyparse ();
36738  if (global_result != result)
36739    abort ();
36740  if (global_count != count)
36741    abort ();
36742  return status;
36743}
36744_ATEOF
36745
36746
36747
36748
36749
36750$at_traceoff
36751echo "calc.at:595: bison -o calc.c calc.y"
36752echo calc.at:595 >$at_check_line_file
36753( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
36754at_status=$?
36755grep '^ *+' $at_stder1 >&2
36756grep -v '^ *+' $at_stder1 >$at_stderr
36757at_failed=false
36758$at_diff $at_devnull $at_stderr || at_failed=:
36759$at_diff $at_devnull $at_stdout || at_failed=:
36760case $at_status in
36761   77) echo 77 > $at_status_file
36762            exit 77;;
36763   0) ;;
36764   *) echo "calc.at:595: exit code was $at_status, expected 0"
36765      at_failed=:;;
36766esac
36767if $at_failed; then
36768
36769  echo 1 > $at_status_file
36770  exit 1
36771fi
36772
36773$at_traceon
36774
36775   $at_traceoff
36776echo "calc.at:595: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
36777echo calc.at:595 >$at_check_line_file
36778( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
36779at_status=$?
36780grep '^ *+' $at_stder1 >&2
36781grep -v '^ *+' $at_stder1 >$at_stderr
36782at_failed=false
36783echo stderr:; cat $at_stderr
36784echo stdout:; cat $at_stdout
36785case $at_status in
36786   77) echo 77 > $at_status_file
36787            exit 77;;
36788   0) ;;
36789   *) echo "calc.at:595: exit code was $at_status, expected 0"
36790      at_failed=:;;
36791esac
36792if $at_failed; then
36793
36794  echo 1 > $at_status_file
36795  exit 1
36796fi
36797
36798$at_traceon
36799
36800
36801# Test the priorities.
36802cat >input <<'_ATEOF'
368031 + 2 * 3 = 7
368041 + 2 * -3 = -5
36805
36806-1^2 = -1
36807(-1)^2 = 1
36808
36809---1 = -1
36810
368111 - 2 - 3 = -4
368121 - (2 - 3) = 2
36813
368142^2^3 = 256
36815(2^2)^3 = 64
36816_ATEOF
36817
36818$at_traceoff
36819echo "calc.at:595: \$PREPARSER ./calc input"
36820echo calc.at:595 >$at_check_line_file
36821( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
36822at_status=$?
36823grep '^ *+' $at_stder1 >&2
36824grep -v '^ *+' $at_stder1 >$at_stderr
36825at_failed=false
36826echo stderr:; tee stderr <$at_stderr
36827$at_diff $at_devnull $at_stdout || at_failed=:
36828case $at_status in
36829   77) echo 77 > $at_status_file
36830            exit 77;;
36831   0) ;;
36832   *) echo "calc.at:595: exit code was $at_status, expected 0"
36833      at_failed=:;;
36834esac
36835if $at_failed; then
36836
36837  echo 1 > $at_status_file
36838  exit 1
36839fi
36840
36841$at_traceon
36842
36843
36844
36845# Some syntax errors.
36846cat >input <<'_ATEOF'
368470 0
36848_ATEOF
36849
36850$at_traceoff
36851echo "calc.at:595: \$PREPARSER ./calc input"
36852echo calc.at:595 >$at_check_line_file
36853( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
36854at_status=$?
36855grep '^ *+' $at_stder1 >&2
36856grep -v '^ *+' $at_stder1 >$at_stderr
36857at_failed=false
36858echo stderr:; tee stderr <$at_stderr
36859$at_diff $at_devnull $at_stdout || at_failed=:
36860case $at_status in
36861   77) echo 77 > $at_status_file
36862            exit 77;;
36863   1) ;;
36864   *) echo "calc.at:595: exit code was $at_status, expected 1"
36865      at_failed=:;;
36866esac
36867if $at_failed; then
36868
36869  echo 1 > $at_status_file
36870  exit 1
36871fi
36872
36873$at_traceon
36874
36875
36876# Normalize the observed and expected error messages, depending upon the
36877# options.
36878# 1. Remove the traces from observed.
36879sed '/^Starting/d
36880/^Entering/d
36881/^Stack/d
36882/^Reading/d
36883/^Reducing/d
36884/^Shifting/d
36885/^state/d
36886/^Cleanup:/d
36887/^Error:/d
36888/^Next/d
36889/^Discarding/d
36890/ \$[0-9$]* = /d
36891/^yydestructor:/d' stderr >at-stderr
36892mv at-stderr stderr
36893# 2. Create the reference error message.
36894cat >expout <<'_ATEOF'
368951.2: syntax error, unexpected number
36896_ATEOF
36897
36898# 3. If locations are not used, remove them.
36899
36900# 4. If error-verbose is not used, strip the`, unexpected....' part.
36901sed 's/syntax error, .*$/syntax error/' expout >at-expout
36902mv at-expout expout
36903# 5. Check
36904$at_traceoff
36905echo "calc.at:595: cat stderr"
36906echo calc.at:595 >$at_check_line_file
36907( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
36908at_status=$?
36909grep '^ *+' $at_stder1 >&2
36910grep -v '^ *+' $at_stder1 >$at_stderr
36911at_failed=false
36912$at_diff $at_devnull $at_stderr || at_failed=:
36913$at_diff expout $at_stdout || at_failed=:
36914case $at_status in
36915   77) echo 77 > $at_status_file
36916            exit 77;;
36917   0) ;;
36918   *) echo "calc.at:595: exit code was $at_status, expected 0"
36919      at_failed=:;;
36920esac
36921if $at_failed; then
36922
36923  echo 1 > $at_status_file
36924  exit 1
36925fi
36926
36927$at_traceon
36928
36929
36930cat >input <<'_ATEOF'
369311//2
36932_ATEOF
36933
36934$at_traceoff
36935echo "calc.at:595: \$PREPARSER ./calc input"
36936echo calc.at:595 >$at_check_line_file
36937( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
36938at_status=$?
36939grep '^ *+' $at_stder1 >&2
36940grep -v '^ *+' $at_stder1 >$at_stderr
36941at_failed=false
36942echo stderr:; tee stderr <$at_stderr
36943$at_diff $at_devnull $at_stdout || at_failed=:
36944case $at_status in
36945   77) echo 77 > $at_status_file
36946            exit 77;;
36947   1) ;;
36948   *) echo "calc.at:595: exit code was $at_status, expected 1"
36949      at_failed=:;;
36950esac
36951if $at_failed; then
36952
36953  echo 1 > $at_status_file
36954  exit 1
36955fi
36956
36957$at_traceon
36958
36959
36960# Normalize the observed and expected error messages, depending upon the
36961# options.
36962# 1. Remove the traces from observed.
36963sed '/^Starting/d
36964/^Entering/d
36965/^Stack/d
36966/^Reading/d
36967/^Reducing/d
36968/^Shifting/d
36969/^state/d
36970/^Cleanup:/d
36971/^Error:/d
36972/^Next/d
36973/^Discarding/d
36974/ \$[0-9$]* = /d
36975/^yydestructor:/d' stderr >at-stderr
36976mv at-stderr stderr
36977# 2. Create the reference error message.
36978cat >expout <<'_ATEOF'
369791.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
36980_ATEOF
36981
36982# 3. If locations are not used, remove them.
36983
36984# 4. If error-verbose is not used, strip the`, unexpected....' part.
36985sed 's/syntax error, .*$/syntax error/' expout >at-expout
36986mv at-expout expout
36987# 5. Check
36988$at_traceoff
36989echo "calc.at:595: cat stderr"
36990echo calc.at:595 >$at_check_line_file
36991( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
36992at_status=$?
36993grep '^ *+' $at_stder1 >&2
36994grep -v '^ *+' $at_stder1 >$at_stderr
36995at_failed=false
36996$at_diff $at_devnull $at_stderr || at_failed=:
36997$at_diff expout $at_stdout || at_failed=:
36998case $at_status in
36999   77) echo 77 > $at_status_file
37000            exit 77;;
37001   0) ;;
37002   *) echo "calc.at:595: exit code was $at_status, expected 0"
37003      at_failed=:;;
37004esac
37005if $at_failed; then
37006
37007  echo 1 > $at_status_file
37008  exit 1
37009fi
37010
37011$at_traceon
37012
37013
37014cat >input <<'_ATEOF'
37015error
37016_ATEOF
37017
37018$at_traceoff
37019echo "calc.at:595: \$PREPARSER ./calc input"
37020echo calc.at:595 >$at_check_line_file
37021( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
37022at_status=$?
37023grep '^ *+' $at_stder1 >&2
37024grep -v '^ *+' $at_stder1 >$at_stderr
37025at_failed=false
37026echo stderr:; tee stderr <$at_stderr
37027$at_diff $at_devnull $at_stdout || at_failed=:
37028case $at_status in
37029   77) echo 77 > $at_status_file
37030            exit 77;;
37031   1) ;;
37032   *) echo "calc.at:595: exit code was $at_status, expected 1"
37033      at_failed=:;;
37034esac
37035if $at_failed; then
37036
37037  echo 1 > $at_status_file
37038  exit 1
37039fi
37040
37041$at_traceon
37042
37043
37044# Normalize the observed and expected error messages, depending upon the
37045# options.
37046# 1. Remove the traces from observed.
37047sed '/^Starting/d
37048/^Entering/d
37049/^Stack/d
37050/^Reading/d
37051/^Reducing/d
37052/^Shifting/d
37053/^state/d
37054/^Cleanup:/d
37055/^Error:/d
37056/^Next/d
37057/^Discarding/d
37058/ \$[0-9$]* = /d
37059/^yydestructor:/d' stderr >at-stderr
37060mv at-stderr stderr
37061# 2. Create the reference error message.
37062cat >expout <<'_ATEOF'
370631.0: syntax error, unexpected $undefined
37064_ATEOF
37065
37066# 3. If locations are not used, remove them.
37067
37068# 4. If error-verbose is not used, strip the`, unexpected....' part.
37069sed 's/syntax error, .*$/syntax error/' expout >at-expout
37070mv at-expout expout
37071# 5. Check
37072$at_traceoff
37073echo "calc.at:595: cat stderr"
37074echo calc.at:595 >$at_check_line_file
37075( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
37076at_status=$?
37077grep '^ *+' $at_stder1 >&2
37078grep -v '^ *+' $at_stder1 >$at_stderr
37079at_failed=false
37080$at_diff $at_devnull $at_stderr || at_failed=:
37081$at_diff expout $at_stdout || at_failed=:
37082case $at_status in
37083   77) echo 77 > $at_status_file
37084            exit 77;;
37085   0) ;;
37086   *) echo "calc.at:595: exit code was $at_status, expected 0"
37087      at_failed=:;;
37088esac
37089if $at_failed; then
37090
37091  echo 1 > $at_status_file
37092  exit 1
37093fi
37094
37095$at_traceon
37096
37097
37098cat >input <<'_ATEOF'
370991 = 2 = 3
37100_ATEOF
37101
37102$at_traceoff
37103echo "calc.at:595: \$PREPARSER ./calc input"
37104echo calc.at:595 >$at_check_line_file
37105( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
37106at_status=$?
37107grep '^ *+' $at_stder1 >&2
37108grep -v '^ *+' $at_stder1 >$at_stderr
37109at_failed=false
37110echo stderr:; tee stderr <$at_stderr
37111$at_diff $at_devnull $at_stdout || at_failed=:
37112case $at_status in
37113   77) echo 77 > $at_status_file
37114            exit 77;;
37115   1) ;;
37116   *) echo "calc.at:595: exit code was $at_status, expected 1"
37117      at_failed=:;;
37118esac
37119if $at_failed; then
37120
37121  echo 1 > $at_status_file
37122  exit 1
37123fi
37124
37125$at_traceon
37126
37127
37128# Normalize the observed and expected error messages, depending upon the
37129# options.
37130# 1. Remove the traces from observed.
37131sed '/^Starting/d
37132/^Entering/d
37133/^Stack/d
37134/^Reading/d
37135/^Reducing/d
37136/^Shifting/d
37137/^state/d
37138/^Cleanup:/d
37139/^Error:/d
37140/^Next/d
37141/^Discarding/d
37142/ \$[0-9$]* = /d
37143/^yydestructor:/d' stderr >at-stderr
37144mv at-stderr stderr
37145# 2. Create the reference error message.
37146cat >expout <<'_ATEOF'
371471.6: syntax error, unexpected '='
37148_ATEOF
37149
37150# 3. If locations are not used, remove them.
37151
37152# 4. If error-verbose is not used, strip the`, unexpected....' part.
37153sed 's/syntax error, .*$/syntax error/' expout >at-expout
37154mv at-expout expout
37155# 5. Check
37156$at_traceoff
37157echo "calc.at:595: cat stderr"
37158echo calc.at:595 >$at_check_line_file
37159( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
37160at_status=$?
37161grep '^ *+' $at_stder1 >&2
37162grep -v '^ *+' $at_stder1 >$at_stderr
37163at_failed=false
37164$at_diff $at_devnull $at_stderr || at_failed=:
37165$at_diff expout $at_stdout || at_failed=:
37166case $at_status in
37167   77) echo 77 > $at_status_file
37168            exit 77;;
37169   0) ;;
37170   *) echo "calc.at:595: exit code was $at_status, expected 0"
37171      at_failed=:;;
37172esac
37173if $at_failed; then
37174
37175  echo 1 > $at_status_file
37176  exit 1
37177fi
37178
37179$at_traceon
37180
37181
37182cat >input <<'_ATEOF'
37183
37184+1
37185_ATEOF
37186
37187$at_traceoff
37188echo "calc.at:595: \$PREPARSER ./calc input"
37189echo calc.at:595 >$at_check_line_file
37190( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
37191at_status=$?
37192grep '^ *+' $at_stder1 >&2
37193grep -v '^ *+' $at_stder1 >$at_stderr
37194at_failed=false
37195echo stderr:; tee stderr <$at_stderr
37196$at_diff $at_devnull $at_stdout || at_failed=:
37197case $at_status in
37198   77) echo 77 > $at_status_file
37199            exit 77;;
37200   1) ;;
37201   *) echo "calc.at:595: exit code was $at_status, expected 1"
37202      at_failed=:;;
37203esac
37204if $at_failed; then
37205
37206  echo 1 > $at_status_file
37207  exit 1
37208fi
37209
37210$at_traceon
37211
37212
37213# Normalize the observed and expected error messages, depending upon the
37214# options.
37215# 1. Remove the traces from observed.
37216sed '/^Starting/d
37217/^Entering/d
37218/^Stack/d
37219/^Reading/d
37220/^Reducing/d
37221/^Shifting/d
37222/^state/d
37223/^Cleanup:/d
37224/^Error:/d
37225/^Next/d
37226/^Discarding/d
37227/ \$[0-9$]* = /d
37228/^yydestructor:/d' stderr >at-stderr
37229mv at-stderr stderr
37230# 2. Create the reference error message.
37231cat >expout <<'_ATEOF'
372322.0: syntax error, unexpected '+'
37233_ATEOF
37234
37235# 3. If locations are not used, remove them.
37236
37237# 4. If error-verbose is not used, strip the`, unexpected....' part.
37238sed 's/syntax error, .*$/syntax error/' expout >at-expout
37239mv at-expout expout
37240# 5. Check
37241$at_traceoff
37242echo "calc.at:595: cat stderr"
37243echo calc.at:595 >$at_check_line_file
37244( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
37245at_status=$?
37246grep '^ *+' $at_stder1 >&2
37247grep -v '^ *+' $at_stder1 >$at_stderr
37248at_failed=false
37249$at_diff $at_devnull $at_stderr || at_failed=:
37250$at_diff expout $at_stdout || at_failed=:
37251case $at_status in
37252   77) echo 77 > $at_status_file
37253            exit 77;;
37254   0) ;;
37255   *) echo "calc.at:595: exit code was $at_status, expected 0"
37256      at_failed=:;;
37257esac
37258if $at_failed; then
37259
37260  echo 1 > $at_status_file
37261  exit 1
37262fi
37263
37264$at_traceon
37265
37266
37267# Exercise error messages with EOF: work on an empty file.
37268$at_traceoff
37269echo "calc.at:595: \$PREPARSER ./calc /dev/null"
37270echo calc.at:595 >$at_check_line_file
37271( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
37272at_status=$?
37273grep '^ *+' $at_stder1 >&2
37274grep -v '^ *+' $at_stder1 >$at_stderr
37275at_failed=false
37276echo stderr:; tee stderr <$at_stderr
37277$at_diff $at_devnull $at_stdout || at_failed=:
37278case $at_status in
37279   77) echo 77 > $at_status_file
37280            exit 77;;
37281   1) ;;
37282   *) echo "calc.at:595: exit code was $at_status, expected 1"
37283      at_failed=:;;
37284esac
37285if $at_failed; then
37286
37287  echo 1 > $at_status_file
37288  exit 1
37289fi
37290
37291$at_traceon
37292
37293
37294# Normalize the observed and expected error messages, depending upon the
37295# options.
37296# 1. Remove the traces from observed.
37297sed '/^Starting/d
37298/^Entering/d
37299/^Stack/d
37300/^Reading/d
37301/^Reducing/d
37302/^Shifting/d
37303/^state/d
37304/^Cleanup:/d
37305/^Error:/d
37306/^Next/d
37307/^Discarding/d
37308/ \$[0-9$]* = /d
37309/^yydestructor:/d' stderr >at-stderr
37310mv at-stderr stderr
37311# 2. Create the reference error message.
37312cat >expout <<'_ATEOF'
373131.0: syntax error, unexpected end of input
37314_ATEOF
37315
37316# 3. If locations are not used, remove them.
37317
37318# 4. If error-verbose is not used, strip the`, unexpected....' part.
37319sed 's/syntax error, .*$/syntax error/' expout >at-expout
37320mv at-expout expout
37321# 5. Check
37322$at_traceoff
37323echo "calc.at:595: cat stderr"
37324echo calc.at:595 >$at_check_line_file
37325( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
37326at_status=$?
37327grep '^ *+' $at_stder1 >&2
37328grep -v '^ *+' $at_stder1 >$at_stderr
37329at_failed=false
37330$at_diff $at_devnull $at_stderr || at_failed=:
37331$at_diff expout $at_stdout || at_failed=:
37332case $at_status in
37333   77) echo 77 > $at_status_file
37334            exit 77;;
37335   0) ;;
37336   *) echo "calc.at:595: exit code was $at_status, expected 0"
37337      at_failed=:;;
37338esac
37339if $at_failed; then
37340
37341  echo 1 > $at_status_file
37342  exit 1
37343fi
37344
37345$at_traceon
37346
37347
37348
37349# Exercise the error token: without it, we die at the first error,
37350# hence be sure to
37351#
37352# - have several errors which exercise different shift/discardings
37353#   - (): nothing to pop, nothing to discard
37354#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
37355#   - (* * *): nothing to pop, a lot to discard
37356#   - (1 + 2 * *): some to pop and discard
37357#
37358# - test the action associated to `error'
37359#
37360# - check the look-ahead that triggers an error is not discarded
37361#   when we enter error recovery.  Below, the look-ahead causing the
37362#   first error is ")", which is needed to recover from the error and
37363#   produce the "0" that triggers the "0 != 1" error.
37364#
37365cat >input <<'_ATEOF'
37366() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
37367_ATEOF
37368
37369$at_traceoff
37370echo "calc.at:595: \$PREPARSER ./calc input"
37371echo calc.at:595 >$at_check_line_file
37372( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
37373at_status=$?
37374grep '^ *+' $at_stder1 >&2
37375grep -v '^ *+' $at_stder1 >$at_stderr
37376at_failed=false
37377echo stderr:; tee stderr <$at_stderr
37378$at_diff $at_devnull $at_stdout || at_failed=:
37379case $at_status in
37380   77) echo 77 > $at_status_file
37381            exit 77;;
37382   0) ;;
37383   *) echo "calc.at:595: exit code was $at_status, expected 0"
37384      at_failed=:;;
37385esac
37386if $at_failed; then
37387
37388  echo 1 > $at_status_file
37389  exit 1
37390fi
37391
37392$at_traceon
37393
37394
37395# Normalize the observed and expected error messages, depending upon the
37396# options.
37397# 1. Remove the traces from observed.
37398sed '/^Starting/d
37399/^Entering/d
37400/^Stack/d
37401/^Reading/d
37402/^Reducing/d
37403/^Shifting/d
37404/^state/d
37405/^Cleanup:/d
37406/^Error:/d
37407/^Next/d
37408/^Discarding/d
37409/ \$[0-9$]* = /d
37410/^yydestructor:/d' stderr >at-stderr
37411mv at-stderr stderr
37412# 2. Create the reference error message.
37413cat >expout <<'_ATEOF'
374141.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
374151.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
374161.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
374171.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
37418calc: error: 4444 != 1
37419_ATEOF
37420
37421# 3. If locations are not used, remove them.
37422
37423# 4. If error-verbose is not used, strip the`, unexpected....' part.
37424sed 's/syntax error, .*$/syntax error/' expout >at-expout
37425mv at-expout expout
37426# 5. Check
37427$at_traceoff
37428echo "calc.at:595: cat stderr"
37429echo calc.at:595 >$at_check_line_file
37430( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
37431at_status=$?
37432grep '^ *+' $at_stder1 >&2
37433grep -v '^ *+' $at_stder1 >$at_stderr
37434at_failed=false
37435$at_diff $at_devnull $at_stderr || at_failed=:
37436$at_diff expout $at_stdout || at_failed=:
37437case $at_status in
37438   77) echo 77 > $at_status_file
37439            exit 77;;
37440   0) ;;
37441   *) echo "calc.at:595: exit code was $at_status, expected 0"
37442      at_failed=:;;
37443esac
37444if $at_failed; then
37445
37446  echo 1 > $at_status_file
37447  exit 1
37448fi
37449
37450$at_traceon
37451
37452
37453
37454# The same, but this time exercising explicitly triggered syntax errors.
37455# POSIX says the look-ahead causing the error should not be discarded.
37456cat >input <<'_ATEOF'
37457(!) + (0 0) = 1
37458_ATEOF
37459
37460$at_traceoff
37461echo "calc.at:595: \$PREPARSER ./calc input"
37462echo calc.at:595 >$at_check_line_file
37463( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
37464at_status=$?
37465grep '^ *+' $at_stder1 >&2
37466grep -v '^ *+' $at_stder1 >$at_stderr
37467at_failed=false
37468echo stderr:; tee stderr <$at_stderr
37469$at_diff $at_devnull $at_stdout || at_failed=:
37470case $at_status in
37471   77) echo 77 > $at_status_file
37472            exit 77;;
37473   0) ;;
37474   *) echo "calc.at:595: exit code was $at_status, expected 0"
37475      at_failed=:;;
37476esac
37477if $at_failed; then
37478
37479  echo 1 > $at_status_file
37480  exit 1
37481fi
37482
37483$at_traceon
37484
37485
37486# Normalize the observed and expected error messages, depending upon the
37487# options.
37488# 1. Remove the traces from observed.
37489sed '/^Starting/d
37490/^Entering/d
37491/^Stack/d
37492/^Reading/d
37493/^Reducing/d
37494/^Shifting/d
37495/^state/d
37496/^Cleanup:/d
37497/^Error:/d
37498/^Next/d
37499/^Discarding/d
37500/ \$[0-9$]* = /d
37501/^yydestructor:/d' stderr >at-stderr
37502mv at-stderr stderr
37503# 2. Create the reference error message.
37504cat >expout <<'_ATEOF'
375051.9: syntax error, unexpected number
37506calc: error: 2222 != 1
37507_ATEOF
37508
37509# 3. If locations are not used, remove them.
37510
37511# 4. If error-verbose is not used, strip the`, unexpected....' part.
37512sed 's/syntax error, .*$/syntax error/' expout >at-expout
37513mv at-expout expout
37514# 5. Check
37515$at_traceoff
37516echo "calc.at:595: cat stderr"
37517echo calc.at:595 >$at_check_line_file
37518( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
37519at_status=$?
37520grep '^ *+' $at_stder1 >&2
37521grep -v '^ *+' $at_stder1 >$at_stderr
37522at_failed=false
37523$at_diff $at_devnull $at_stderr || at_failed=:
37524$at_diff expout $at_stdout || at_failed=:
37525case $at_status in
37526   77) echo 77 > $at_status_file
37527            exit 77;;
37528   0) ;;
37529   *) echo "calc.at:595: exit code was $at_status, expected 0"
37530      at_failed=:;;
37531esac
37532if $at_failed; then
37533
37534  echo 1 > $at_status_file
37535  exit 1
37536fi
37537
37538$at_traceon
37539
37540
37541cat >input <<'_ATEOF'
37542(- *) + (0 0) = 1
37543_ATEOF
37544
37545$at_traceoff
37546echo "calc.at:595: \$PREPARSER ./calc input"
37547echo calc.at:595 >$at_check_line_file
37548( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
37549at_status=$?
37550grep '^ *+' $at_stder1 >&2
37551grep -v '^ *+' $at_stder1 >$at_stderr
37552at_failed=false
37553echo stderr:; tee stderr <$at_stderr
37554$at_diff $at_devnull $at_stdout || at_failed=:
37555case $at_status in
37556   77) echo 77 > $at_status_file
37557            exit 77;;
37558   0) ;;
37559   *) echo "calc.at:595: exit code was $at_status, expected 0"
37560      at_failed=:;;
37561esac
37562if $at_failed; then
37563
37564  echo 1 > $at_status_file
37565  exit 1
37566fi
37567
37568$at_traceon
37569
37570
37571# Normalize the observed and expected error messages, depending upon the
37572# options.
37573# 1. Remove the traces from observed.
37574sed '/^Starting/d
37575/^Entering/d
37576/^Stack/d
37577/^Reading/d
37578/^Reducing/d
37579/^Shifting/d
37580/^state/d
37581/^Cleanup:/d
37582/^Error:/d
37583/^Next/d
37584/^Discarding/d
37585/ \$[0-9$]* = /d
37586/^yydestructor:/d' stderr >at-stderr
37587mv at-stderr stderr
37588# 2. Create the reference error message.
37589cat >expout <<'_ATEOF'
375901.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
375911.11: syntax error, unexpected number
37592calc: error: 2222 != 1
37593_ATEOF
37594
37595# 3. If locations are not used, remove them.
37596
37597# 4. If error-verbose is not used, strip the`, unexpected....' part.
37598sed 's/syntax error, .*$/syntax error/' expout >at-expout
37599mv at-expout expout
37600# 5. Check
37601$at_traceoff
37602echo "calc.at:595: cat stderr"
37603echo calc.at:595 >$at_check_line_file
37604( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
37605at_status=$?
37606grep '^ *+' $at_stder1 >&2
37607grep -v '^ *+' $at_stder1 >$at_stderr
37608at_failed=false
37609$at_diff $at_devnull $at_stderr || at_failed=:
37610$at_diff expout $at_stdout || at_failed=:
37611case $at_status in
37612   77) echo 77 > $at_status_file
37613            exit 77;;
37614   0) ;;
37615   *) echo "calc.at:595: exit code was $at_status, expected 0"
37616      at_failed=:;;
37617esac
37618if $at_failed; then
37619
37620  echo 1 > $at_status_file
37621  exit 1
37622fi
37623
37624$at_traceon
37625
37626
37627
37628
37629
37630
37631
37632
37633
37634
37635
37636
37637
37638
37639
37640
37641
37642
37643
37644
37645
37646
37647
37648
37649      $at_traceoff
37650      $at_times_p && times >$at_times_file
37651    ) 5>&1 2>&1 | eval $at_tee_pipe
37652    at_status=`cat $at_status_file`
37653    ;;
37654
37655  92 ) # 92. calc.at:596: Calculator %glr-parser %error-verbose %locations
37656    at_setup_line='calc.at:596'
37657    at_desc='Calculator %glr-parser %error-verbose %locations'
37658    $at_quiet $ECHO_N " 92: Calculator %glr-parser %error-verbose %locations$ECHO_C"
37659    at_xfail=no
37660    (
37661      echo "92. calc.at:596: testing ..."
37662      $at_traceon
37663
37664
37665
37666
37667
37668
37669
37670
37671# Using yacc.c?
37672
37673
37674
37675
37676
37677
37678
37679# yyerror receives the location if %location & %pure & (%glr or %parse-param).
37680
37681# yyerror always sees the locations (when activated), except if
37682# yacc & pure & !param.
37683
37684
37685# The interface is pure: either because %pure-parser, or because we
37686# are using the C++ parsers.
37687
37688
37689
37690
37691
37692
37693
37694
37695
37696
37697
37698
37699cat >calc.y <<'_ATEOF'
37700%{
37701#ifdef HAVE_CONFIG_H
37702# include <config.h>
37703  /* We don't need perfect functions for these tests. */
37704# undef malloc
37705# undef memcmp
37706# undef realloc
37707#endif
37708%}
37709
37710/* Infix notation calculator--calc */
37711%glr-parser %error-verbose %locations
37712
37713%{
37714#include <stdio.h>
37715
37716#include <stdlib.h>
37717#include <string.h>
37718#if HAVE_UNISTD_H
37719# include <unistd.h>
37720#else
37721# undef alarm
37722# define alarm(seconds) /* empty */
37723#endif
37724#include <ctype.h>
37725#define USE(Var)
37726
37727/* Exercise pre-prologue dependency to %union.  */
37728typedef int semantic_value;
37729
37730static semantic_value global_result = 0;
37731static int global_count = 0;
37732%}
37733
37734/* Exercise %union. */
37735%union
37736{
37737  semantic_value ival;
37738};
37739
37740%{
37741static int power (int base, int exponent);
37742/* yyerror receives the location if:
37743   - %location & %pure & %glr
37744   - %location & %pure & %yacc & %parse-param. */
37745static void yyerror (
37746
37747                     const char *s
37748                     );
37749static int yylex (void);
37750static int get_char (void);
37751static void unget_char ( int c);
37752%}
37753
37754
37755
37756/* Bison Declarations */
37757%token CALC_EOF 0 "end of input"
37758%token <ival> NUM "number"
37759%type  <ival> exp
37760
37761%nonassoc '=' /* comparison	       */
37762%left '-' '+'
37763%left '*' '/'
37764%left NEG     /* negation--unary minus */
37765%right '^'    /* exponentiation        */
37766
37767/* Grammar follows */
37768%%
37769input:
37770  line
37771| input line         {  }
37772;
37773
37774line:
37775  '\n'
37776| exp '\n'           { USE ($1); }
37777;
37778
37779exp:
37780  NUM                { $$ = $1;             }
37781| exp '=' exp
37782  {
37783    if ($1 != $3)
37784      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
37785    $$ = $1;
37786  }
37787| exp '+' exp        { $$ = $1 + $3;        }
37788| exp '-' exp        { $$ = $1 - $3;        }
37789| exp '*' exp        { $$ = $1 * $3;        }
37790| exp '/' exp        { $$ = $1 / $3;        }
37791| '-' exp  %prec NEG { $$ = -$2;            }
37792| exp '^' exp        { $$ = power ($1, $3); }
37793| '(' exp ')'        { $$ = $2;             }
37794| '(' error ')'      { $$ = 1111;           }
37795| '!'                { $$ = 0; YYERROR;     }
37796| '-' error          { $$ = 0; YYERROR;     }
37797;
37798%%
37799/* The input.  */
37800static FILE *input;
37801
37802static void
37803yyerror (
37804
37805         const char *s)
37806{
37807
37808
37809  fprintf (stderr, "%d.%d",
37810           (yylloc).first_line, (yylloc).first_column);
37811  if ((yylloc).first_line != (yylloc).last_line)
37812    fprintf (stderr, "-%d.%d",
37813	     (yylloc).last_line,  (yylloc).last_column - 1);
37814  else if ((yylloc).first_column != (yylloc).last_column - 1)
37815    fprintf (stderr, "-%d",
37816	     (yylloc).last_column - 1);
37817  fprintf (stderr, ": ");
37818  fprintf (stderr, "%s\n", s);
37819}
37820
37821
37822
37823static YYLTYPE last_yylloc;
37824
37825static int
37826get_char (void)
37827{
37828  int res = getc (input);
37829  ;
37830
37831  last_yylloc = (yylloc);
37832  if (res == '\n')
37833    {
37834      (yylloc).last_line++;
37835      (yylloc).last_column = 0;
37836    }
37837  else
37838    (yylloc).last_column++;
37839
37840  return res;
37841}
37842
37843
37844static void
37845unget_char ( int c)
37846{
37847  ;
37848
37849  /* Wrong when C == `\n'. */
37850  (yylloc) = last_yylloc;
37851
37852  ungetc (c, input);
37853}
37854
37855static int
37856read_signed_integer (void)
37857{
37858  int c = get_char ();
37859  int sign = 1;
37860  int n = 0;
37861
37862  ;
37863  if (c == '-')
37864    {
37865      c = get_char ();
37866      sign = -1;
37867    }
37868
37869  while (isdigit (c))
37870    {
37871      n = 10 * n + (c - '0');
37872      c = get_char ();
37873    }
37874
37875  unget_char ( c);
37876
37877  return sign * n;
37878}
37879
37880
37881
37882/*---------------------------------------------------------------.
37883| Lexical analyzer returns an integer on the stack and the token |
37884| NUM, or the ASCII character read if not a number.  Skips all   |
37885| blanks and tabs, returns 0 for EOF.                            |
37886`---------------------------------------------------------------*/
37887
37888static int
37889yylex (void)
37890{
37891  static int init = 1;
37892  int c;
37893
37894  if (init)
37895    {
37896      init = 0;
37897
37898      (yylloc).last_column = 0;
37899      (yylloc).last_line = 1;
37900
37901    }
37902
37903
37904 (yylloc).first_column = (yylloc).last_column;
37905  (yylloc).first_line   = (yylloc).last_line;
37906
37907
37908  /* Skip white space.  */
37909  while ((c = get_char ()) == ' ' || c == '\t')
37910    {
37911     (yylloc).first_column = (yylloc).last_column;
37912      (yylloc).first_line   = (yylloc).last_line;
37913
37914    }
37915
37916  /* process numbers   */
37917  if (c == '.' || isdigit (c))
37918    {
37919      unget_char ( c);
37920      (yylval).ival = read_signed_integer ();
37921      return NUM;
37922    }
37923
37924  /* Return end-of-file.  */
37925  if (c == EOF)
37926    return CALC_EOF;
37927
37928  /* Return single chars. */
37929  return c;
37930}
37931
37932static int
37933power (int base, int exponent)
37934{
37935  int res = 1;
37936  if (exponent < 0)
37937    exit (3);
37938  for (/* Niente */; exponent; --exponent)
37939    res *= base;
37940  return res;
37941}
37942
37943
37944int
37945main (int argc, const char **argv)
37946{
37947  semantic_value result = 0;
37948  int count = 0;
37949  int status;
37950
37951  /* This used to be alarm (10), but that isn't enough time for
37952     a July 1995 vintage DEC Alphastation 200 4/100 system,
37953     according to Nelson H. F. Beebe.  100 seconds is enough.  */
37954  alarm (100);
37955
37956  if (argc == 2)
37957    input = fopen (argv[1], "r");
37958  else
37959    input = stdin;
37960
37961  if (!input)
37962    {
37963      perror (argv[1]);
37964      return 3;
37965    }
37966
37967
37968  status = yyparse ();
37969  if (global_result != result)
37970    abort ();
37971  if (global_count != count)
37972    abort ();
37973  return status;
37974}
37975_ATEOF
37976
37977
37978
37979
37980
37981$at_traceoff
37982echo "calc.at:596: bison -o calc.c calc.y"
37983echo calc.at:596 >$at_check_line_file
37984( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
37985at_status=$?
37986grep '^ *+' $at_stder1 >&2
37987grep -v '^ *+' $at_stder1 >$at_stderr
37988at_failed=false
37989$at_diff $at_devnull $at_stderr || at_failed=:
37990$at_diff $at_devnull $at_stdout || at_failed=:
37991case $at_status in
37992   77) echo 77 > $at_status_file
37993            exit 77;;
37994   0) ;;
37995   *) echo "calc.at:596: exit code was $at_status, expected 0"
37996      at_failed=:;;
37997esac
37998if $at_failed; then
37999
38000  echo 1 > $at_status_file
38001  exit 1
38002fi
38003
38004$at_traceon
38005
38006   $at_traceoff
38007echo "calc.at:596: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
38008echo calc.at:596 >$at_check_line_file
38009( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
38010at_status=$?
38011grep '^ *+' $at_stder1 >&2
38012grep -v '^ *+' $at_stder1 >$at_stderr
38013at_failed=false
38014echo stderr:; cat $at_stderr
38015echo stdout:; cat $at_stdout
38016case $at_status in
38017   77) echo 77 > $at_status_file
38018            exit 77;;
38019   0) ;;
38020   *) echo "calc.at:596: exit code was $at_status, expected 0"
38021      at_failed=:;;
38022esac
38023if $at_failed; then
38024
38025  echo 1 > $at_status_file
38026  exit 1
38027fi
38028
38029$at_traceon
38030
38031
38032# Test the priorities.
38033cat >input <<'_ATEOF'
380341 + 2 * 3 = 7
380351 + 2 * -3 = -5
38036
38037-1^2 = -1
38038(-1)^2 = 1
38039
38040---1 = -1
38041
380421 - 2 - 3 = -4
380431 - (2 - 3) = 2
38044
380452^2^3 = 256
38046(2^2)^3 = 64
38047_ATEOF
38048
38049$at_traceoff
38050echo "calc.at:596: \$PREPARSER ./calc input"
38051echo calc.at:596 >$at_check_line_file
38052( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
38053at_status=$?
38054grep '^ *+' $at_stder1 >&2
38055grep -v '^ *+' $at_stder1 >$at_stderr
38056at_failed=false
38057echo stderr:; tee stderr <$at_stderr
38058$at_diff $at_devnull $at_stdout || at_failed=:
38059case $at_status in
38060   77) echo 77 > $at_status_file
38061            exit 77;;
38062   0) ;;
38063   *) echo "calc.at:596: exit code was $at_status, expected 0"
38064      at_failed=:;;
38065esac
38066if $at_failed; then
38067
38068  echo 1 > $at_status_file
38069  exit 1
38070fi
38071
38072$at_traceon
38073
38074
38075
38076# Some syntax errors.
38077cat >input <<'_ATEOF'
380780 0
38079_ATEOF
38080
38081$at_traceoff
38082echo "calc.at:596: \$PREPARSER ./calc input"
38083echo calc.at:596 >$at_check_line_file
38084( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
38085at_status=$?
38086grep '^ *+' $at_stder1 >&2
38087grep -v '^ *+' $at_stder1 >$at_stderr
38088at_failed=false
38089echo stderr:; tee stderr <$at_stderr
38090$at_diff $at_devnull $at_stdout || at_failed=:
38091case $at_status in
38092   77) echo 77 > $at_status_file
38093            exit 77;;
38094   1) ;;
38095   *) echo "calc.at:596: exit code was $at_status, expected 1"
38096      at_failed=:;;
38097esac
38098if $at_failed; then
38099
38100  echo 1 > $at_status_file
38101  exit 1
38102fi
38103
38104$at_traceon
38105
38106
38107# Normalize the observed and expected error messages, depending upon the
38108# options.
38109# 1. Remove the traces from observed.
38110sed '/^Starting/d
38111/^Entering/d
38112/^Stack/d
38113/^Reading/d
38114/^Reducing/d
38115/^Shifting/d
38116/^state/d
38117/^Cleanup:/d
38118/^Error:/d
38119/^Next/d
38120/^Discarding/d
38121/ \$[0-9$]* = /d
38122/^yydestructor:/d' stderr >at-stderr
38123mv at-stderr stderr
38124# 2. Create the reference error message.
38125cat >expout <<'_ATEOF'
381261.2: syntax error, unexpected number
38127_ATEOF
38128
38129# 3. If locations are not used, remove them.
38130
38131# 4. If error-verbose is not used, strip the`, unexpected....' part.
38132
38133# 5. Check
38134$at_traceoff
38135echo "calc.at:596: cat stderr"
38136echo calc.at:596 >$at_check_line_file
38137( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
38138at_status=$?
38139grep '^ *+' $at_stder1 >&2
38140grep -v '^ *+' $at_stder1 >$at_stderr
38141at_failed=false
38142$at_diff $at_devnull $at_stderr || at_failed=:
38143$at_diff expout $at_stdout || at_failed=:
38144case $at_status in
38145   77) echo 77 > $at_status_file
38146            exit 77;;
38147   0) ;;
38148   *) echo "calc.at:596: exit code was $at_status, expected 0"
38149      at_failed=:;;
38150esac
38151if $at_failed; then
38152
38153  echo 1 > $at_status_file
38154  exit 1
38155fi
38156
38157$at_traceon
38158
38159
38160cat >input <<'_ATEOF'
381611//2
38162_ATEOF
38163
38164$at_traceoff
38165echo "calc.at:596: \$PREPARSER ./calc input"
38166echo calc.at:596 >$at_check_line_file
38167( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
38168at_status=$?
38169grep '^ *+' $at_stder1 >&2
38170grep -v '^ *+' $at_stder1 >$at_stderr
38171at_failed=false
38172echo stderr:; tee stderr <$at_stderr
38173$at_diff $at_devnull $at_stdout || at_failed=:
38174case $at_status in
38175   77) echo 77 > $at_status_file
38176            exit 77;;
38177   1) ;;
38178   *) echo "calc.at:596: exit code was $at_status, expected 1"
38179      at_failed=:;;
38180esac
38181if $at_failed; then
38182
38183  echo 1 > $at_status_file
38184  exit 1
38185fi
38186
38187$at_traceon
38188
38189
38190# Normalize the observed and expected error messages, depending upon the
38191# options.
38192# 1. Remove the traces from observed.
38193sed '/^Starting/d
38194/^Entering/d
38195/^Stack/d
38196/^Reading/d
38197/^Reducing/d
38198/^Shifting/d
38199/^state/d
38200/^Cleanup:/d
38201/^Error:/d
38202/^Next/d
38203/^Discarding/d
38204/ \$[0-9$]* = /d
38205/^yydestructor:/d' stderr >at-stderr
38206mv at-stderr stderr
38207# 2. Create the reference error message.
38208cat >expout <<'_ATEOF'
382091.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
38210_ATEOF
38211
38212# 3. If locations are not used, remove them.
38213
38214# 4. If error-verbose is not used, strip the`, unexpected....' part.
38215
38216# 5. Check
38217$at_traceoff
38218echo "calc.at:596: cat stderr"
38219echo calc.at:596 >$at_check_line_file
38220( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
38221at_status=$?
38222grep '^ *+' $at_stder1 >&2
38223grep -v '^ *+' $at_stder1 >$at_stderr
38224at_failed=false
38225$at_diff $at_devnull $at_stderr || at_failed=:
38226$at_diff expout $at_stdout || at_failed=:
38227case $at_status in
38228   77) echo 77 > $at_status_file
38229            exit 77;;
38230   0) ;;
38231   *) echo "calc.at:596: exit code was $at_status, expected 0"
38232      at_failed=:;;
38233esac
38234if $at_failed; then
38235
38236  echo 1 > $at_status_file
38237  exit 1
38238fi
38239
38240$at_traceon
38241
38242
38243cat >input <<'_ATEOF'
38244error
38245_ATEOF
38246
38247$at_traceoff
38248echo "calc.at:596: \$PREPARSER ./calc input"
38249echo calc.at:596 >$at_check_line_file
38250( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
38251at_status=$?
38252grep '^ *+' $at_stder1 >&2
38253grep -v '^ *+' $at_stder1 >$at_stderr
38254at_failed=false
38255echo stderr:; tee stderr <$at_stderr
38256$at_diff $at_devnull $at_stdout || at_failed=:
38257case $at_status in
38258   77) echo 77 > $at_status_file
38259            exit 77;;
38260   1) ;;
38261   *) echo "calc.at:596: exit code was $at_status, expected 1"
38262      at_failed=:;;
38263esac
38264if $at_failed; then
38265
38266  echo 1 > $at_status_file
38267  exit 1
38268fi
38269
38270$at_traceon
38271
38272
38273# Normalize the observed and expected error messages, depending upon the
38274# options.
38275# 1. Remove the traces from observed.
38276sed '/^Starting/d
38277/^Entering/d
38278/^Stack/d
38279/^Reading/d
38280/^Reducing/d
38281/^Shifting/d
38282/^state/d
38283/^Cleanup:/d
38284/^Error:/d
38285/^Next/d
38286/^Discarding/d
38287/ \$[0-9$]* = /d
38288/^yydestructor:/d' stderr >at-stderr
38289mv at-stderr stderr
38290# 2. Create the reference error message.
38291cat >expout <<'_ATEOF'
382921.0: syntax error, unexpected $undefined
38293_ATEOF
38294
38295# 3. If locations are not used, remove them.
38296
38297# 4. If error-verbose is not used, strip the`, unexpected....' part.
38298
38299# 5. Check
38300$at_traceoff
38301echo "calc.at:596: cat stderr"
38302echo calc.at:596 >$at_check_line_file
38303( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
38304at_status=$?
38305grep '^ *+' $at_stder1 >&2
38306grep -v '^ *+' $at_stder1 >$at_stderr
38307at_failed=false
38308$at_diff $at_devnull $at_stderr || at_failed=:
38309$at_diff expout $at_stdout || at_failed=:
38310case $at_status in
38311   77) echo 77 > $at_status_file
38312            exit 77;;
38313   0) ;;
38314   *) echo "calc.at:596: exit code was $at_status, expected 0"
38315      at_failed=:;;
38316esac
38317if $at_failed; then
38318
38319  echo 1 > $at_status_file
38320  exit 1
38321fi
38322
38323$at_traceon
38324
38325
38326cat >input <<'_ATEOF'
383271 = 2 = 3
38328_ATEOF
38329
38330$at_traceoff
38331echo "calc.at:596: \$PREPARSER ./calc input"
38332echo calc.at:596 >$at_check_line_file
38333( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
38334at_status=$?
38335grep '^ *+' $at_stder1 >&2
38336grep -v '^ *+' $at_stder1 >$at_stderr
38337at_failed=false
38338echo stderr:; tee stderr <$at_stderr
38339$at_diff $at_devnull $at_stdout || at_failed=:
38340case $at_status in
38341   77) echo 77 > $at_status_file
38342            exit 77;;
38343   1) ;;
38344   *) echo "calc.at:596: exit code was $at_status, expected 1"
38345      at_failed=:;;
38346esac
38347if $at_failed; then
38348
38349  echo 1 > $at_status_file
38350  exit 1
38351fi
38352
38353$at_traceon
38354
38355
38356# Normalize the observed and expected error messages, depending upon the
38357# options.
38358# 1. Remove the traces from observed.
38359sed '/^Starting/d
38360/^Entering/d
38361/^Stack/d
38362/^Reading/d
38363/^Reducing/d
38364/^Shifting/d
38365/^state/d
38366/^Cleanup:/d
38367/^Error:/d
38368/^Next/d
38369/^Discarding/d
38370/ \$[0-9$]* = /d
38371/^yydestructor:/d' stderr >at-stderr
38372mv at-stderr stderr
38373# 2. Create the reference error message.
38374cat >expout <<'_ATEOF'
383751.6: syntax error, unexpected '='
38376_ATEOF
38377
38378# 3. If locations are not used, remove them.
38379
38380# 4. If error-verbose is not used, strip the`, unexpected....' part.
38381
38382# 5. Check
38383$at_traceoff
38384echo "calc.at:596: cat stderr"
38385echo calc.at:596 >$at_check_line_file
38386( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
38387at_status=$?
38388grep '^ *+' $at_stder1 >&2
38389grep -v '^ *+' $at_stder1 >$at_stderr
38390at_failed=false
38391$at_diff $at_devnull $at_stderr || at_failed=:
38392$at_diff expout $at_stdout || at_failed=:
38393case $at_status in
38394   77) echo 77 > $at_status_file
38395            exit 77;;
38396   0) ;;
38397   *) echo "calc.at:596: exit code was $at_status, expected 0"
38398      at_failed=:;;
38399esac
38400if $at_failed; then
38401
38402  echo 1 > $at_status_file
38403  exit 1
38404fi
38405
38406$at_traceon
38407
38408
38409cat >input <<'_ATEOF'
38410
38411+1
38412_ATEOF
38413
38414$at_traceoff
38415echo "calc.at:596: \$PREPARSER ./calc input"
38416echo calc.at:596 >$at_check_line_file
38417( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
38418at_status=$?
38419grep '^ *+' $at_stder1 >&2
38420grep -v '^ *+' $at_stder1 >$at_stderr
38421at_failed=false
38422echo stderr:; tee stderr <$at_stderr
38423$at_diff $at_devnull $at_stdout || at_failed=:
38424case $at_status in
38425   77) echo 77 > $at_status_file
38426            exit 77;;
38427   1) ;;
38428   *) echo "calc.at:596: exit code was $at_status, expected 1"
38429      at_failed=:;;
38430esac
38431if $at_failed; then
38432
38433  echo 1 > $at_status_file
38434  exit 1
38435fi
38436
38437$at_traceon
38438
38439
38440# Normalize the observed and expected error messages, depending upon the
38441# options.
38442# 1. Remove the traces from observed.
38443sed '/^Starting/d
38444/^Entering/d
38445/^Stack/d
38446/^Reading/d
38447/^Reducing/d
38448/^Shifting/d
38449/^state/d
38450/^Cleanup:/d
38451/^Error:/d
38452/^Next/d
38453/^Discarding/d
38454/ \$[0-9$]* = /d
38455/^yydestructor:/d' stderr >at-stderr
38456mv at-stderr stderr
38457# 2. Create the reference error message.
38458cat >expout <<'_ATEOF'
384592.0: syntax error, unexpected '+'
38460_ATEOF
38461
38462# 3. If locations are not used, remove them.
38463
38464# 4. If error-verbose is not used, strip the`, unexpected....' part.
38465
38466# 5. Check
38467$at_traceoff
38468echo "calc.at:596: cat stderr"
38469echo calc.at:596 >$at_check_line_file
38470( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
38471at_status=$?
38472grep '^ *+' $at_stder1 >&2
38473grep -v '^ *+' $at_stder1 >$at_stderr
38474at_failed=false
38475$at_diff $at_devnull $at_stderr || at_failed=:
38476$at_diff expout $at_stdout || at_failed=:
38477case $at_status in
38478   77) echo 77 > $at_status_file
38479            exit 77;;
38480   0) ;;
38481   *) echo "calc.at:596: exit code was $at_status, expected 0"
38482      at_failed=:;;
38483esac
38484if $at_failed; then
38485
38486  echo 1 > $at_status_file
38487  exit 1
38488fi
38489
38490$at_traceon
38491
38492
38493# Exercise error messages with EOF: work on an empty file.
38494$at_traceoff
38495echo "calc.at:596: \$PREPARSER ./calc /dev/null"
38496echo calc.at:596 >$at_check_line_file
38497( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
38498at_status=$?
38499grep '^ *+' $at_stder1 >&2
38500grep -v '^ *+' $at_stder1 >$at_stderr
38501at_failed=false
38502echo stderr:; tee stderr <$at_stderr
38503$at_diff $at_devnull $at_stdout || at_failed=:
38504case $at_status in
38505   77) echo 77 > $at_status_file
38506            exit 77;;
38507   1) ;;
38508   *) echo "calc.at:596: exit code was $at_status, expected 1"
38509      at_failed=:;;
38510esac
38511if $at_failed; then
38512
38513  echo 1 > $at_status_file
38514  exit 1
38515fi
38516
38517$at_traceon
38518
38519
38520# Normalize the observed and expected error messages, depending upon the
38521# options.
38522# 1. Remove the traces from observed.
38523sed '/^Starting/d
38524/^Entering/d
38525/^Stack/d
38526/^Reading/d
38527/^Reducing/d
38528/^Shifting/d
38529/^state/d
38530/^Cleanup:/d
38531/^Error:/d
38532/^Next/d
38533/^Discarding/d
38534/ \$[0-9$]* = /d
38535/^yydestructor:/d' stderr >at-stderr
38536mv at-stderr stderr
38537# 2. Create the reference error message.
38538cat >expout <<'_ATEOF'
385391.0: syntax error, unexpected end of input
38540_ATEOF
38541
38542# 3. If locations are not used, remove them.
38543
38544# 4. If error-verbose is not used, strip the`, unexpected....' part.
38545
38546# 5. Check
38547$at_traceoff
38548echo "calc.at:596: cat stderr"
38549echo calc.at:596 >$at_check_line_file
38550( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
38551at_status=$?
38552grep '^ *+' $at_stder1 >&2
38553grep -v '^ *+' $at_stder1 >$at_stderr
38554at_failed=false
38555$at_diff $at_devnull $at_stderr || at_failed=:
38556$at_diff expout $at_stdout || at_failed=:
38557case $at_status in
38558   77) echo 77 > $at_status_file
38559            exit 77;;
38560   0) ;;
38561   *) echo "calc.at:596: exit code was $at_status, expected 0"
38562      at_failed=:;;
38563esac
38564if $at_failed; then
38565
38566  echo 1 > $at_status_file
38567  exit 1
38568fi
38569
38570$at_traceon
38571
38572
38573
38574# Exercise the error token: without it, we die at the first error,
38575# hence be sure to
38576#
38577# - have several errors which exercise different shift/discardings
38578#   - (): nothing to pop, nothing to discard
38579#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
38580#   - (* * *): nothing to pop, a lot to discard
38581#   - (1 + 2 * *): some to pop and discard
38582#
38583# - test the action associated to `error'
38584#
38585# - check the look-ahead that triggers an error is not discarded
38586#   when we enter error recovery.  Below, the look-ahead causing the
38587#   first error is ")", which is needed to recover from the error and
38588#   produce the "0" that triggers the "0 != 1" error.
38589#
38590cat >input <<'_ATEOF'
38591() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
38592_ATEOF
38593
38594$at_traceoff
38595echo "calc.at:596: \$PREPARSER ./calc input"
38596echo calc.at:596 >$at_check_line_file
38597( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
38598at_status=$?
38599grep '^ *+' $at_stder1 >&2
38600grep -v '^ *+' $at_stder1 >$at_stderr
38601at_failed=false
38602echo stderr:; tee stderr <$at_stderr
38603$at_diff $at_devnull $at_stdout || at_failed=:
38604case $at_status in
38605   77) echo 77 > $at_status_file
38606            exit 77;;
38607   0) ;;
38608   *) echo "calc.at:596: exit code was $at_status, expected 0"
38609      at_failed=:;;
38610esac
38611if $at_failed; then
38612
38613  echo 1 > $at_status_file
38614  exit 1
38615fi
38616
38617$at_traceon
38618
38619
38620# Normalize the observed and expected error messages, depending upon the
38621# options.
38622# 1. Remove the traces from observed.
38623sed '/^Starting/d
38624/^Entering/d
38625/^Stack/d
38626/^Reading/d
38627/^Reducing/d
38628/^Shifting/d
38629/^state/d
38630/^Cleanup:/d
38631/^Error:/d
38632/^Next/d
38633/^Discarding/d
38634/ \$[0-9$]* = /d
38635/^yydestructor:/d' stderr >at-stderr
38636mv at-stderr stderr
38637# 2. Create the reference error message.
38638cat >expout <<'_ATEOF'
386391.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
386401.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
386411.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
386421.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
38643calc: error: 4444 != 1
38644_ATEOF
38645
38646# 3. If locations are not used, remove them.
38647
38648# 4. If error-verbose is not used, strip the`, unexpected....' part.
38649
38650# 5. Check
38651$at_traceoff
38652echo "calc.at:596: cat stderr"
38653echo calc.at:596 >$at_check_line_file
38654( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
38655at_status=$?
38656grep '^ *+' $at_stder1 >&2
38657grep -v '^ *+' $at_stder1 >$at_stderr
38658at_failed=false
38659$at_diff $at_devnull $at_stderr || at_failed=:
38660$at_diff expout $at_stdout || at_failed=:
38661case $at_status in
38662   77) echo 77 > $at_status_file
38663            exit 77;;
38664   0) ;;
38665   *) echo "calc.at:596: exit code was $at_status, expected 0"
38666      at_failed=:;;
38667esac
38668if $at_failed; then
38669
38670  echo 1 > $at_status_file
38671  exit 1
38672fi
38673
38674$at_traceon
38675
38676
38677
38678# The same, but this time exercising explicitly triggered syntax errors.
38679# POSIX says the look-ahead causing the error should not be discarded.
38680cat >input <<'_ATEOF'
38681(!) + (0 0) = 1
38682_ATEOF
38683
38684$at_traceoff
38685echo "calc.at:596: \$PREPARSER ./calc input"
38686echo calc.at:596 >$at_check_line_file
38687( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
38688at_status=$?
38689grep '^ *+' $at_stder1 >&2
38690grep -v '^ *+' $at_stder1 >$at_stderr
38691at_failed=false
38692echo stderr:; tee stderr <$at_stderr
38693$at_diff $at_devnull $at_stdout || at_failed=:
38694case $at_status in
38695   77) echo 77 > $at_status_file
38696            exit 77;;
38697   0) ;;
38698   *) echo "calc.at:596: exit code was $at_status, expected 0"
38699      at_failed=:;;
38700esac
38701if $at_failed; then
38702
38703  echo 1 > $at_status_file
38704  exit 1
38705fi
38706
38707$at_traceon
38708
38709
38710# Normalize the observed and expected error messages, depending upon the
38711# options.
38712# 1. Remove the traces from observed.
38713sed '/^Starting/d
38714/^Entering/d
38715/^Stack/d
38716/^Reading/d
38717/^Reducing/d
38718/^Shifting/d
38719/^state/d
38720/^Cleanup:/d
38721/^Error:/d
38722/^Next/d
38723/^Discarding/d
38724/ \$[0-9$]* = /d
38725/^yydestructor:/d' stderr >at-stderr
38726mv at-stderr stderr
38727# 2. Create the reference error message.
38728cat >expout <<'_ATEOF'
387291.9: syntax error, unexpected number
38730calc: error: 2222 != 1
38731_ATEOF
38732
38733# 3. If locations are not used, remove them.
38734
38735# 4. If error-verbose is not used, strip the`, unexpected....' part.
38736
38737# 5. Check
38738$at_traceoff
38739echo "calc.at:596: cat stderr"
38740echo calc.at:596 >$at_check_line_file
38741( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
38742at_status=$?
38743grep '^ *+' $at_stder1 >&2
38744grep -v '^ *+' $at_stder1 >$at_stderr
38745at_failed=false
38746$at_diff $at_devnull $at_stderr || at_failed=:
38747$at_diff expout $at_stdout || at_failed=:
38748case $at_status in
38749   77) echo 77 > $at_status_file
38750            exit 77;;
38751   0) ;;
38752   *) echo "calc.at:596: exit code was $at_status, expected 0"
38753      at_failed=:;;
38754esac
38755if $at_failed; then
38756
38757  echo 1 > $at_status_file
38758  exit 1
38759fi
38760
38761$at_traceon
38762
38763
38764cat >input <<'_ATEOF'
38765(- *) + (0 0) = 1
38766_ATEOF
38767
38768$at_traceoff
38769echo "calc.at:596: \$PREPARSER ./calc input"
38770echo calc.at:596 >$at_check_line_file
38771( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
38772at_status=$?
38773grep '^ *+' $at_stder1 >&2
38774grep -v '^ *+' $at_stder1 >$at_stderr
38775at_failed=false
38776echo stderr:; tee stderr <$at_stderr
38777$at_diff $at_devnull $at_stdout || at_failed=:
38778case $at_status in
38779   77) echo 77 > $at_status_file
38780            exit 77;;
38781   0) ;;
38782   *) echo "calc.at:596: exit code was $at_status, expected 0"
38783      at_failed=:;;
38784esac
38785if $at_failed; then
38786
38787  echo 1 > $at_status_file
38788  exit 1
38789fi
38790
38791$at_traceon
38792
38793
38794# Normalize the observed and expected error messages, depending upon the
38795# options.
38796# 1. Remove the traces from observed.
38797sed '/^Starting/d
38798/^Entering/d
38799/^Stack/d
38800/^Reading/d
38801/^Reducing/d
38802/^Shifting/d
38803/^state/d
38804/^Cleanup:/d
38805/^Error:/d
38806/^Next/d
38807/^Discarding/d
38808/ \$[0-9$]* = /d
38809/^yydestructor:/d' stderr >at-stderr
38810mv at-stderr stderr
38811# 2. Create the reference error message.
38812cat >expout <<'_ATEOF'
388131.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
388141.11: syntax error, unexpected number
38815calc: error: 2222 != 1
38816_ATEOF
38817
38818# 3. If locations are not used, remove them.
38819
38820# 4. If error-verbose is not used, strip the`, unexpected....' part.
38821
38822# 5. Check
38823$at_traceoff
38824echo "calc.at:596: cat stderr"
38825echo calc.at:596 >$at_check_line_file
38826( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
38827at_status=$?
38828grep '^ *+' $at_stder1 >&2
38829grep -v '^ *+' $at_stder1 >$at_stderr
38830at_failed=false
38831$at_diff $at_devnull $at_stderr || at_failed=:
38832$at_diff expout $at_stdout || at_failed=:
38833case $at_status in
38834   77) echo 77 > $at_status_file
38835            exit 77;;
38836   0) ;;
38837   *) echo "calc.at:596: exit code was $at_status, expected 0"
38838      at_failed=:;;
38839esac
38840if $at_failed; then
38841
38842  echo 1 > $at_status_file
38843  exit 1
38844fi
38845
38846$at_traceon
38847
38848
38849
38850
38851
38852
38853
38854
38855
38856
38857
38858
38859
38860
38861
38862
38863
38864
38865
38866
38867
38868
38869
38870
38871      $at_traceoff
38872      $at_times_p && times >$at_times_file
38873    ) 5>&1 2>&1 | eval $at_tee_pipe
38874    at_status=`cat $at_status_file`
38875    ;;
38876
38877  93 ) # 93. calc.at:598: Calculator %glr-parser %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc
38878    at_setup_line='calc.at:598'
38879    at_desc='Calculator %glr-parser %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc'
38880    $at_quiet $ECHO_N " 93: Calculator %glr-parser %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc$ECHO_C"
38881    at_xfail=no
38882    (
38883      echo "93. calc.at:598: testing ..."
38884      $at_traceon
38885
38886
38887
38888
38889
38890
38891
38892
38893# Using yacc.c?
38894
38895
38896
38897
38898
38899
38900
38901# yyerror receives the location if %location & %pure & (%glr or %parse-param).
38902
38903# yyerror always sees the locations (when activated), except if
38904# yacc & pure & !param.
38905
38906
38907# The interface is pure: either because %pure-parser, or because we
38908# are using the C++ parsers.
38909
38910
38911
38912
38913
38914
38915
38916
38917
38918
38919
38920
38921cat >calc.y <<'_ATEOF'
38922%{
38923#ifdef HAVE_CONFIG_H
38924# include <config.h>
38925  /* We don't need perfect functions for these tests. */
38926# undef malloc
38927# undef memcmp
38928# undef realloc
38929#endif
38930%}
38931
38932/* Infix notation calculator--calc */
38933%glr-parser %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc
38934
38935%{
38936#include <stdio.h>
38937
38938#include <stdlib.h>
38939#include <string.h>
38940#if HAVE_UNISTD_H
38941# include <unistd.h>
38942#else
38943# undef alarm
38944# define alarm(seconds) /* empty */
38945#endif
38946#include <ctype.h>
38947#define USE(Var)
38948
38949/* Exercise pre-prologue dependency to %union.  */
38950typedef int semantic_value;
38951
38952static semantic_value global_result = 0;
38953static int global_count = 0;
38954%}
38955
38956/* Exercise %union. */
38957%union
38958{
38959  semantic_value ival;
38960};
38961
38962%{
38963static int power (int base, int exponent);
38964/* yyerror receives the location if:
38965   - %location & %pure & %glr
38966   - %location & %pure & %yacc & %parse-param. */
38967static void yyerror (
38968
38969                     const char *s
38970                     );
38971static int yylex (void);
38972static int get_char (void);
38973static void unget_char ( int c);
38974%}
38975
38976
38977
38978/* Bison Declarations */
38979%token CALC_EOF 0 "end of input"
38980%token <ival> NUM "number"
38981%type  <ival> exp
38982
38983%nonassoc '=' /* comparison	       */
38984%left '-' '+'
38985%left '*' '/'
38986%left NEG     /* negation--unary minus */
38987%right '^'    /* exponentiation        */
38988
38989/* Grammar follows */
38990%%
38991input:
38992  line
38993| input line         {  }
38994;
38995
38996line:
38997  '\n'
38998| exp '\n'           { USE ($1); }
38999;
39000
39001exp:
39002  NUM                { $$ = $1;             }
39003| exp '=' exp
39004  {
39005    if ($1 != $3)
39006      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
39007    $$ = $1;
39008  }
39009| exp '+' exp        { $$ = $1 + $3;        }
39010| exp '-' exp        { $$ = $1 - $3;        }
39011| exp '*' exp        { $$ = $1 * $3;        }
39012| exp '/' exp        { $$ = $1 / $3;        }
39013| '-' exp  %prec NEG { $$ = -$2;            }
39014| exp '^' exp        { $$ = power ($1, $3); }
39015| '(' exp ')'        { $$ = $2;             }
39016| '(' error ')'      { $$ = 1111;           }
39017| '!'                { $$ = 0; YYERROR;     }
39018| '-' error          { $$ = 0; YYERROR;     }
39019;
39020%%
39021/* The input.  */
39022static FILE *input;
39023
39024static void
39025yyerror (
39026
39027         const char *s)
39028{
39029
39030
39031  fprintf (stderr, "%d.%d",
39032           (yylloc).first_line, (yylloc).first_column);
39033  if ((yylloc).first_line != (yylloc).last_line)
39034    fprintf (stderr, "-%d.%d",
39035	     (yylloc).last_line,  (yylloc).last_column - 1);
39036  else if ((yylloc).first_column != (yylloc).last_column - 1)
39037    fprintf (stderr, "-%d",
39038	     (yylloc).last_column - 1);
39039  fprintf (stderr, ": ");
39040  fprintf (stderr, "%s\n", s);
39041}
39042
39043
39044
39045static YYLTYPE last_yylloc;
39046
39047static int
39048get_char (void)
39049{
39050  int res = getc (input);
39051  ;
39052
39053  last_yylloc = (yylloc);
39054  if (res == '\n')
39055    {
39056      (yylloc).last_line++;
39057      (yylloc).last_column = 0;
39058    }
39059  else
39060    (yylloc).last_column++;
39061
39062  return res;
39063}
39064
39065
39066static void
39067unget_char ( int c)
39068{
39069  ;
39070
39071  /* Wrong when C == `\n'. */
39072  (yylloc) = last_yylloc;
39073
39074  ungetc (c, input);
39075}
39076
39077static int
39078read_signed_integer (void)
39079{
39080  int c = get_char ();
39081  int sign = 1;
39082  int n = 0;
39083
39084  ;
39085  if (c == '-')
39086    {
39087      c = get_char ();
39088      sign = -1;
39089    }
39090
39091  while (isdigit (c))
39092    {
39093      n = 10 * n + (c - '0');
39094      c = get_char ();
39095    }
39096
39097  unget_char ( c);
39098
39099  return sign * n;
39100}
39101
39102
39103
39104/*---------------------------------------------------------------.
39105| Lexical analyzer returns an integer on the stack and the token |
39106| NUM, or the ASCII character read if not a number.  Skips all   |
39107| blanks and tabs, returns 0 for EOF.                            |
39108`---------------------------------------------------------------*/
39109
39110static int
39111yylex (void)
39112{
39113  static int init = 1;
39114  int c;
39115
39116  if (init)
39117    {
39118      init = 0;
39119
39120      (yylloc).last_column = 0;
39121      (yylloc).last_line = 1;
39122
39123    }
39124
39125
39126 (yylloc).first_column = (yylloc).last_column;
39127  (yylloc).first_line   = (yylloc).last_line;
39128
39129
39130  /* Skip white space.  */
39131  while ((c = get_char ()) == ' ' || c == '\t')
39132    {
39133     (yylloc).first_column = (yylloc).last_column;
39134      (yylloc).first_line   = (yylloc).last_line;
39135
39136    }
39137
39138  /* process numbers   */
39139  if (c == '.' || isdigit (c))
39140    {
39141      unget_char ( c);
39142      (yylval).ival = read_signed_integer ();
39143      return NUM;
39144    }
39145
39146  /* Return end-of-file.  */
39147  if (c == EOF)
39148    return CALC_EOF;
39149
39150  /* Return single chars. */
39151  return c;
39152}
39153
39154static int
39155power (int base, int exponent)
39156{
39157  int res = 1;
39158  if (exponent < 0)
39159    exit (3);
39160  for (/* Niente */; exponent; --exponent)
39161    res *= base;
39162  return res;
39163}
39164
39165
39166int
39167main (int argc, const char **argv)
39168{
39169  semantic_value result = 0;
39170  int count = 0;
39171  int status;
39172
39173  /* This used to be alarm (10), but that isn't enough time for
39174     a July 1995 vintage DEC Alphastation 200 4/100 system,
39175     according to Nelson H. F. Beebe.  100 seconds is enough.  */
39176  alarm (100);
39177
39178  if (argc == 2)
39179    input = fopen (argv[1], "r");
39180  else
39181    input = stdin;
39182
39183  if (!input)
39184    {
39185      perror (argv[1]);
39186      return 3;
39187    }
39188
39189
39190  status = yyparse ();
39191  if (global_result != result)
39192    abort ();
39193  if (global_count != count)
39194    abort ();
39195  return status;
39196}
39197_ATEOF
39198
39199
39200
39201
39202
39203$at_traceoff
39204echo "calc.at:598: bison -o calc.c calc.y"
39205echo calc.at:598 >$at_check_line_file
39206( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
39207at_status=$?
39208grep '^ *+' $at_stder1 >&2
39209grep -v '^ *+' $at_stder1 >$at_stderr
39210at_failed=false
39211$at_diff $at_devnull $at_stderr || at_failed=:
39212$at_diff $at_devnull $at_stdout || at_failed=:
39213case $at_status in
39214   77) echo 77 > $at_status_file
39215            exit 77;;
39216   0) ;;
39217   *) echo "calc.at:598: exit code was $at_status, expected 0"
39218      at_failed=:;;
39219esac
39220if $at_failed; then
39221
39222  echo 1 > $at_status_file
39223  exit 1
39224fi
39225
39226$at_traceon
39227
39228   $at_traceoff
39229echo "calc.at:598: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
39230echo calc.at:598 >$at_check_line_file
39231( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
39232at_status=$?
39233grep '^ *+' $at_stder1 >&2
39234grep -v '^ *+' $at_stder1 >$at_stderr
39235at_failed=false
39236echo stderr:; cat $at_stderr
39237echo stdout:; cat $at_stdout
39238case $at_status in
39239   77) echo 77 > $at_status_file
39240            exit 77;;
39241   0) ;;
39242   *) echo "calc.at:598: exit code was $at_status, expected 0"
39243      at_failed=:;;
39244esac
39245if $at_failed; then
39246
39247  echo 1 > $at_status_file
39248  exit 1
39249fi
39250
39251$at_traceon
39252
39253
39254# Test the priorities.
39255cat >input <<'_ATEOF'
392561 + 2 * 3 = 7
392571 + 2 * -3 = -5
39258
39259-1^2 = -1
39260(-1)^2 = 1
39261
39262---1 = -1
39263
392641 - 2 - 3 = -4
392651 - (2 - 3) = 2
39266
392672^2^3 = 256
39268(2^2)^3 = 64
39269_ATEOF
39270
39271$at_traceoff
39272echo "calc.at:598: \$PREPARSER ./calc input"
39273echo calc.at:598 >$at_check_line_file
39274( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
39275at_status=$?
39276grep '^ *+' $at_stder1 >&2
39277grep -v '^ *+' $at_stder1 >$at_stderr
39278at_failed=false
39279echo stderr:; tee stderr <$at_stderr
39280$at_diff $at_devnull $at_stdout || at_failed=:
39281case $at_status in
39282   77) echo 77 > $at_status_file
39283            exit 77;;
39284   0) ;;
39285   *) echo "calc.at:598: exit code was $at_status, expected 0"
39286      at_failed=:;;
39287esac
39288if $at_failed; then
39289
39290  echo 1 > $at_status_file
39291  exit 1
39292fi
39293
39294$at_traceon
39295
39296
39297
39298# Some syntax errors.
39299cat >input <<'_ATEOF'
393000 0
39301_ATEOF
39302
39303$at_traceoff
39304echo "calc.at:598: \$PREPARSER ./calc input"
39305echo calc.at:598 >$at_check_line_file
39306( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
39307at_status=$?
39308grep '^ *+' $at_stder1 >&2
39309grep -v '^ *+' $at_stder1 >$at_stderr
39310at_failed=false
39311echo stderr:; tee stderr <$at_stderr
39312$at_diff $at_devnull $at_stdout || at_failed=:
39313case $at_status in
39314   77) echo 77 > $at_status_file
39315            exit 77;;
39316   1) ;;
39317   *) echo "calc.at:598: exit code was $at_status, expected 1"
39318      at_failed=:;;
39319esac
39320if $at_failed; then
39321
39322  echo 1 > $at_status_file
39323  exit 1
39324fi
39325
39326$at_traceon
39327
39328
39329# Normalize the observed and expected error messages, depending upon the
39330# options.
39331# 1. Remove the traces from observed.
39332sed '/^Starting/d
39333/^Entering/d
39334/^Stack/d
39335/^Reading/d
39336/^Reducing/d
39337/^Shifting/d
39338/^state/d
39339/^Cleanup:/d
39340/^Error:/d
39341/^Next/d
39342/^Discarding/d
39343/ \$[0-9$]* = /d
39344/^yydestructor:/d' stderr >at-stderr
39345mv at-stderr stderr
39346# 2. Create the reference error message.
39347cat >expout <<'_ATEOF'
393481.2: syntax error, unexpected number
39349_ATEOF
39350
39351# 3. If locations are not used, remove them.
39352
39353# 4. If error-verbose is not used, strip the`, unexpected....' part.
39354
39355# 5. Check
39356$at_traceoff
39357echo "calc.at:598: cat stderr"
39358echo calc.at:598 >$at_check_line_file
39359( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
39360at_status=$?
39361grep '^ *+' $at_stder1 >&2
39362grep -v '^ *+' $at_stder1 >$at_stderr
39363at_failed=false
39364$at_diff $at_devnull $at_stderr || at_failed=:
39365$at_diff expout $at_stdout || at_failed=:
39366case $at_status in
39367   77) echo 77 > $at_status_file
39368            exit 77;;
39369   0) ;;
39370   *) echo "calc.at:598: exit code was $at_status, expected 0"
39371      at_failed=:;;
39372esac
39373if $at_failed; then
39374
39375  echo 1 > $at_status_file
39376  exit 1
39377fi
39378
39379$at_traceon
39380
39381
39382cat >input <<'_ATEOF'
393831//2
39384_ATEOF
39385
39386$at_traceoff
39387echo "calc.at:598: \$PREPARSER ./calc input"
39388echo calc.at:598 >$at_check_line_file
39389( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
39390at_status=$?
39391grep '^ *+' $at_stder1 >&2
39392grep -v '^ *+' $at_stder1 >$at_stderr
39393at_failed=false
39394echo stderr:; tee stderr <$at_stderr
39395$at_diff $at_devnull $at_stdout || at_failed=:
39396case $at_status in
39397   77) echo 77 > $at_status_file
39398            exit 77;;
39399   1) ;;
39400   *) echo "calc.at:598: exit code was $at_status, expected 1"
39401      at_failed=:;;
39402esac
39403if $at_failed; then
39404
39405  echo 1 > $at_status_file
39406  exit 1
39407fi
39408
39409$at_traceon
39410
39411
39412# Normalize the observed and expected error messages, depending upon the
39413# options.
39414# 1. Remove the traces from observed.
39415sed '/^Starting/d
39416/^Entering/d
39417/^Stack/d
39418/^Reading/d
39419/^Reducing/d
39420/^Shifting/d
39421/^state/d
39422/^Cleanup:/d
39423/^Error:/d
39424/^Next/d
39425/^Discarding/d
39426/ \$[0-9$]* = /d
39427/^yydestructor:/d' stderr >at-stderr
39428mv at-stderr stderr
39429# 2. Create the reference error message.
39430cat >expout <<'_ATEOF'
394311.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
39432_ATEOF
39433
39434# 3. If locations are not used, remove them.
39435
39436# 4. If error-verbose is not used, strip the`, unexpected....' part.
39437
39438# 5. Check
39439$at_traceoff
39440echo "calc.at:598: cat stderr"
39441echo calc.at:598 >$at_check_line_file
39442( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
39443at_status=$?
39444grep '^ *+' $at_stder1 >&2
39445grep -v '^ *+' $at_stder1 >$at_stderr
39446at_failed=false
39447$at_diff $at_devnull $at_stderr || at_failed=:
39448$at_diff expout $at_stdout || at_failed=:
39449case $at_status in
39450   77) echo 77 > $at_status_file
39451            exit 77;;
39452   0) ;;
39453   *) echo "calc.at:598: exit code was $at_status, expected 0"
39454      at_failed=:;;
39455esac
39456if $at_failed; then
39457
39458  echo 1 > $at_status_file
39459  exit 1
39460fi
39461
39462$at_traceon
39463
39464
39465cat >input <<'_ATEOF'
39466error
39467_ATEOF
39468
39469$at_traceoff
39470echo "calc.at:598: \$PREPARSER ./calc input"
39471echo calc.at:598 >$at_check_line_file
39472( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
39473at_status=$?
39474grep '^ *+' $at_stder1 >&2
39475grep -v '^ *+' $at_stder1 >$at_stderr
39476at_failed=false
39477echo stderr:; tee stderr <$at_stderr
39478$at_diff $at_devnull $at_stdout || at_failed=:
39479case $at_status in
39480   77) echo 77 > $at_status_file
39481            exit 77;;
39482   1) ;;
39483   *) echo "calc.at:598: exit code was $at_status, expected 1"
39484      at_failed=:;;
39485esac
39486if $at_failed; then
39487
39488  echo 1 > $at_status_file
39489  exit 1
39490fi
39491
39492$at_traceon
39493
39494
39495# Normalize the observed and expected error messages, depending upon the
39496# options.
39497# 1. Remove the traces from observed.
39498sed '/^Starting/d
39499/^Entering/d
39500/^Stack/d
39501/^Reading/d
39502/^Reducing/d
39503/^Shifting/d
39504/^state/d
39505/^Cleanup:/d
39506/^Error:/d
39507/^Next/d
39508/^Discarding/d
39509/ \$[0-9$]* = /d
39510/^yydestructor:/d' stderr >at-stderr
39511mv at-stderr stderr
39512# 2. Create the reference error message.
39513cat >expout <<'_ATEOF'
395141.0: syntax error, unexpected $undefined
39515_ATEOF
39516
39517# 3. If locations are not used, remove them.
39518
39519# 4. If error-verbose is not used, strip the`, unexpected....' part.
39520
39521# 5. Check
39522$at_traceoff
39523echo "calc.at:598: cat stderr"
39524echo calc.at:598 >$at_check_line_file
39525( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
39526at_status=$?
39527grep '^ *+' $at_stder1 >&2
39528grep -v '^ *+' $at_stder1 >$at_stderr
39529at_failed=false
39530$at_diff $at_devnull $at_stderr || at_failed=:
39531$at_diff expout $at_stdout || at_failed=:
39532case $at_status in
39533   77) echo 77 > $at_status_file
39534            exit 77;;
39535   0) ;;
39536   *) echo "calc.at:598: exit code was $at_status, expected 0"
39537      at_failed=:;;
39538esac
39539if $at_failed; then
39540
39541  echo 1 > $at_status_file
39542  exit 1
39543fi
39544
39545$at_traceon
39546
39547
39548cat >input <<'_ATEOF'
395491 = 2 = 3
39550_ATEOF
39551
39552$at_traceoff
39553echo "calc.at:598: \$PREPARSER ./calc input"
39554echo calc.at:598 >$at_check_line_file
39555( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
39556at_status=$?
39557grep '^ *+' $at_stder1 >&2
39558grep -v '^ *+' $at_stder1 >$at_stderr
39559at_failed=false
39560echo stderr:; tee stderr <$at_stderr
39561$at_diff $at_devnull $at_stdout || at_failed=:
39562case $at_status in
39563   77) echo 77 > $at_status_file
39564            exit 77;;
39565   1) ;;
39566   *) echo "calc.at:598: exit code was $at_status, expected 1"
39567      at_failed=:;;
39568esac
39569if $at_failed; then
39570
39571  echo 1 > $at_status_file
39572  exit 1
39573fi
39574
39575$at_traceon
39576
39577
39578# Normalize the observed and expected error messages, depending upon the
39579# options.
39580# 1. Remove the traces from observed.
39581sed '/^Starting/d
39582/^Entering/d
39583/^Stack/d
39584/^Reading/d
39585/^Reducing/d
39586/^Shifting/d
39587/^state/d
39588/^Cleanup:/d
39589/^Error:/d
39590/^Next/d
39591/^Discarding/d
39592/ \$[0-9$]* = /d
39593/^yydestructor:/d' stderr >at-stderr
39594mv at-stderr stderr
39595# 2. Create the reference error message.
39596cat >expout <<'_ATEOF'
395971.6: syntax error, unexpected '='
39598_ATEOF
39599
39600# 3. If locations are not used, remove them.
39601
39602# 4. If error-verbose is not used, strip the`, unexpected....' part.
39603
39604# 5. Check
39605$at_traceoff
39606echo "calc.at:598: cat stderr"
39607echo calc.at:598 >$at_check_line_file
39608( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
39609at_status=$?
39610grep '^ *+' $at_stder1 >&2
39611grep -v '^ *+' $at_stder1 >$at_stderr
39612at_failed=false
39613$at_diff $at_devnull $at_stderr || at_failed=:
39614$at_diff expout $at_stdout || at_failed=:
39615case $at_status in
39616   77) echo 77 > $at_status_file
39617            exit 77;;
39618   0) ;;
39619   *) echo "calc.at:598: exit code was $at_status, expected 0"
39620      at_failed=:;;
39621esac
39622if $at_failed; then
39623
39624  echo 1 > $at_status_file
39625  exit 1
39626fi
39627
39628$at_traceon
39629
39630
39631cat >input <<'_ATEOF'
39632
39633+1
39634_ATEOF
39635
39636$at_traceoff
39637echo "calc.at:598: \$PREPARSER ./calc input"
39638echo calc.at:598 >$at_check_line_file
39639( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
39640at_status=$?
39641grep '^ *+' $at_stder1 >&2
39642grep -v '^ *+' $at_stder1 >$at_stderr
39643at_failed=false
39644echo stderr:; tee stderr <$at_stderr
39645$at_diff $at_devnull $at_stdout || at_failed=:
39646case $at_status in
39647   77) echo 77 > $at_status_file
39648            exit 77;;
39649   1) ;;
39650   *) echo "calc.at:598: exit code was $at_status, expected 1"
39651      at_failed=:;;
39652esac
39653if $at_failed; then
39654
39655  echo 1 > $at_status_file
39656  exit 1
39657fi
39658
39659$at_traceon
39660
39661
39662# Normalize the observed and expected error messages, depending upon the
39663# options.
39664# 1. Remove the traces from observed.
39665sed '/^Starting/d
39666/^Entering/d
39667/^Stack/d
39668/^Reading/d
39669/^Reducing/d
39670/^Shifting/d
39671/^state/d
39672/^Cleanup:/d
39673/^Error:/d
39674/^Next/d
39675/^Discarding/d
39676/ \$[0-9$]* = /d
39677/^yydestructor:/d' stderr >at-stderr
39678mv at-stderr stderr
39679# 2. Create the reference error message.
39680cat >expout <<'_ATEOF'
396812.0: syntax error, unexpected '+'
39682_ATEOF
39683
39684# 3. If locations are not used, remove them.
39685
39686# 4. If error-verbose is not used, strip the`, unexpected....' part.
39687
39688# 5. Check
39689$at_traceoff
39690echo "calc.at:598: cat stderr"
39691echo calc.at:598 >$at_check_line_file
39692( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
39693at_status=$?
39694grep '^ *+' $at_stder1 >&2
39695grep -v '^ *+' $at_stder1 >$at_stderr
39696at_failed=false
39697$at_diff $at_devnull $at_stderr || at_failed=:
39698$at_diff expout $at_stdout || at_failed=:
39699case $at_status in
39700   77) echo 77 > $at_status_file
39701            exit 77;;
39702   0) ;;
39703   *) echo "calc.at:598: exit code was $at_status, expected 0"
39704      at_failed=:;;
39705esac
39706if $at_failed; then
39707
39708  echo 1 > $at_status_file
39709  exit 1
39710fi
39711
39712$at_traceon
39713
39714
39715# Exercise error messages with EOF: work on an empty file.
39716$at_traceoff
39717echo "calc.at:598: \$PREPARSER ./calc /dev/null"
39718echo calc.at:598 >$at_check_line_file
39719( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
39720at_status=$?
39721grep '^ *+' $at_stder1 >&2
39722grep -v '^ *+' $at_stder1 >$at_stderr
39723at_failed=false
39724echo stderr:; tee stderr <$at_stderr
39725$at_diff $at_devnull $at_stdout || at_failed=:
39726case $at_status in
39727   77) echo 77 > $at_status_file
39728            exit 77;;
39729   1) ;;
39730   *) echo "calc.at:598: exit code was $at_status, expected 1"
39731      at_failed=:;;
39732esac
39733if $at_failed; then
39734
39735  echo 1 > $at_status_file
39736  exit 1
39737fi
39738
39739$at_traceon
39740
39741
39742# Normalize the observed and expected error messages, depending upon the
39743# options.
39744# 1. Remove the traces from observed.
39745sed '/^Starting/d
39746/^Entering/d
39747/^Stack/d
39748/^Reading/d
39749/^Reducing/d
39750/^Shifting/d
39751/^state/d
39752/^Cleanup:/d
39753/^Error:/d
39754/^Next/d
39755/^Discarding/d
39756/ \$[0-9$]* = /d
39757/^yydestructor:/d' stderr >at-stderr
39758mv at-stderr stderr
39759# 2. Create the reference error message.
39760cat >expout <<'_ATEOF'
397611.0: syntax error, unexpected end of input
39762_ATEOF
39763
39764# 3. If locations are not used, remove them.
39765
39766# 4. If error-verbose is not used, strip the`, unexpected....' part.
39767
39768# 5. Check
39769$at_traceoff
39770echo "calc.at:598: cat stderr"
39771echo calc.at:598 >$at_check_line_file
39772( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
39773at_status=$?
39774grep '^ *+' $at_stder1 >&2
39775grep -v '^ *+' $at_stder1 >$at_stderr
39776at_failed=false
39777$at_diff $at_devnull $at_stderr || at_failed=:
39778$at_diff expout $at_stdout || at_failed=:
39779case $at_status in
39780   77) echo 77 > $at_status_file
39781            exit 77;;
39782   0) ;;
39783   *) echo "calc.at:598: exit code was $at_status, expected 0"
39784      at_failed=:;;
39785esac
39786if $at_failed; then
39787
39788  echo 1 > $at_status_file
39789  exit 1
39790fi
39791
39792$at_traceon
39793
39794
39795
39796# Exercise the error token: without it, we die at the first error,
39797# hence be sure to
39798#
39799# - have several errors which exercise different shift/discardings
39800#   - (): nothing to pop, nothing to discard
39801#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
39802#   - (* * *): nothing to pop, a lot to discard
39803#   - (1 + 2 * *): some to pop and discard
39804#
39805# - test the action associated to `error'
39806#
39807# - check the look-ahead that triggers an error is not discarded
39808#   when we enter error recovery.  Below, the look-ahead causing the
39809#   first error is ")", which is needed to recover from the error and
39810#   produce the "0" that triggers the "0 != 1" error.
39811#
39812cat >input <<'_ATEOF'
39813() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
39814_ATEOF
39815
39816$at_traceoff
39817echo "calc.at:598: \$PREPARSER ./calc input"
39818echo calc.at:598 >$at_check_line_file
39819( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
39820at_status=$?
39821grep '^ *+' $at_stder1 >&2
39822grep -v '^ *+' $at_stder1 >$at_stderr
39823at_failed=false
39824echo stderr:; tee stderr <$at_stderr
39825$at_diff $at_devnull $at_stdout || at_failed=:
39826case $at_status in
39827   77) echo 77 > $at_status_file
39828            exit 77;;
39829   0) ;;
39830   *) echo "calc.at:598: exit code was $at_status, expected 0"
39831      at_failed=:;;
39832esac
39833if $at_failed; then
39834
39835  echo 1 > $at_status_file
39836  exit 1
39837fi
39838
39839$at_traceon
39840
39841
39842# Normalize the observed and expected error messages, depending upon the
39843# options.
39844# 1. Remove the traces from observed.
39845sed '/^Starting/d
39846/^Entering/d
39847/^Stack/d
39848/^Reading/d
39849/^Reducing/d
39850/^Shifting/d
39851/^state/d
39852/^Cleanup:/d
39853/^Error:/d
39854/^Next/d
39855/^Discarding/d
39856/ \$[0-9$]* = /d
39857/^yydestructor:/d' stderr >at-stderr
39858mv at-stderr stderr
39859# 2. Create the reference error message.
39860cat >expout <<'_ATEOF'
398611.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
398621.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
398631.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
398641.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
39865calc: error: 4444 != 1
39866_ATEOF
39867
39868# 3. If locations are not used, remove them.
39869
39870# 4. If error-verbose is not used, strip the`, unexpected....' part.
39871
39872# 5. Check
39873$at_traceoff
39874echo "calc.at:598: cat stderr"
39875echo calc.at:598 >$at_check_line_file
39876( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
39877at_status=$?
39878grep '^ *+' $at_stder1 >&2
39879grep -v '^ *+' $at_stder1 >$at_stderr
39880at_failed=false
39881$at_diff $at_devnull $at_stderr || at_failed=:
39882$at_diff expout $at_stdout || at_failed=:
39883case $at_status in
39884   77) echo 77 > $at_status_file
39885            exit 77;;
39886   0) ;;
39887   *) echo "calc.at:598: exit code was $at_status, expected 0"
39888      at_failed=:;;
39889esac
39890if $at_failed; then
39891
39892  echo 1 > $at_status_file
39893  exit 1
39894fi
39895
39896$at_traceon
39897
39898
39899
39900# The same, but this time exercising explicitly triggered syntax errors.
39901# POSIX says the look-ahead causing the error should not be discarded.
39902cat >input <<'_ATEOF'
39903(!) + (0 0) = 1
39904_ATEOF
39905
39906$at_traceoff
39907echo "calc.at:598: \$PREPARSER ./calc input"
39908echo calc.at:598 >$at_check_line_file
39909( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
39910at_status=$?
39911grep '^ *+' $at_stder1 >&2
39912grep -v '^ *+' $at_stder1 >$at_stderr
39913at_failed=false
39914echo stderr:; tee stderr <$at_stderr
39915$at_diff $at_devnull $at_stdout || at_failed=:
39916case $at_status in
39917   77) echo 77 > $at_status_file
39918            exit 77;;
39919   0) ;;
39920   *) echo "calc.at:598: exit code was $at_status, expected 0"
39921      at_failed=:;;
39922esac
39923if $at_failed; then
39924
39925  echo 1 > $at_status_file
39926  exit 1
39927fi
39928
39929$at_traceon
39930
39931
39932# Normalize the observed and expected error messages, depending upon the
39933# options.
39934# 1. Remove the traces from observed.
39935sed '/^Starting/d
39936/^Entering/d
39937/^Stack/d
39938/^Reading/d
39939/^Reducing/d
39940/^Shifting/d
39941/^state/d
39942/^Cleanup:/d
39943/^Error:/d
39944/^Next/d
39945/^Discarding/d
39946/ \$[0-9$]* = /d
39947/^yydestructor:/d' stderr >at-stderr
39948mv at-stderr stderr
39949# 2. Create the reference error message.
39950cat >expout <<'_ATEOF'
399511.9: syntax error, unexpected number
39952calc: error: 2222 != 1
39953_ATEOF
39954
39955# 3. If locations are not used, remove them.
39956
39957# 4. If error-verbose is not used, strip the`, unexpected....' part.
39958
39959# 5. Check
39960$at_traceoff
39961echo "calc.at:598: cat stderr"
39962echo calc.at:598 >$at_check_line_file
39963( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
39964at_status=$?
39965grep '^ *+' $at_stder1 >&2
39966grep -v '^ *+' $at_stder1 >$at_stderr
39967at_failed=false
39968$at_diff $at_devnull $at_stderr || at_failed=:
39969$at_diff expout $at_stdout || at_failed=:
39970case $at_status in
39971   77) echo 77 > $at_status_file
39972            exit 77;;
39973   0) ;;
39974   *) echo "calc.at:598: exit code was $at_status, expected 0"
39975      at_failed=:;;
39976esac
39977if $at_failed; then
39978
39979  echo 1 > $at_status_file
39980  exit 1
39981fi
39982
39983$at_traceon
39984
39985
39986cat >input <<'_ATEOF'
39987(- *) + (0 0) = 1
39988_ATEOF
39989
39990$at_traceoff
39991echo "calc.at:598: \$PREPARSER ./calc input"
39992echo calc.at:598 >$at_check_line_file
39993( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
39994at_status=$?
39995grep '^ *+' $at_stder1 >&2
39996grep -v '^ *+' $at_stder1 >$at_stderr
39997at_failed=false
39998echo stderr:; tee stderr <$at_stderr
39999$at_diff $at_devnull $at_stdout || at_failed=:
40000case $at_status in
40001   77) echo 77 > $at_status_file
40002            exit 77;;
40003   0) ;;
40004   *) echo "calc.at:598: exit code was $at_status, expected 0"
40005      at_failed=:;;
40006esac
40007if $at_failed; then
40008
40009  echo 1 > $at_status_file
40010  exit 1
40011fi
40012
40013$at_traceon
40014
40015
40016# Normalize the observed and expected error messages, depending upon the
40017# options.
40018# 1. Remove the traces from observed.
40019sed '/^Starting/d
40020/^Entering/d
40021/^Stack/d
40022/^Reading/d
40023/^Reducing/d
40024/^Shifting/d
40025/^state/d
40026/^Cleanup:/d
40027/^Error:/d
40028/^Next/d
40029/^Discarding/d
40030/ \$[0-9$]* = /d
40031/^yydestructor:/d' stderr >at-stderr
40032mv at-stderr stderr
40033# 2. Create the reference error message.
40034cat >expout <<'_ATEOF'
400351.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
400361.11: syntax error, unexpected number
40037calc: error: 2222 != 1
40038_ATEOF
40039
40040# 3. If locations are not used, remove them.
40041
40042# 4. If error-verbose is not used, strip the`, unexpected....' part.
40043
40044# 5. Check
40045$at_traceoff
40046echo "calc.at:598: cat stderr"
40047echo calc.at:598 >$at_check_line_file
40048( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
40049at_status=$?
40050grep '^ *+' $at_stder1 >&2
40051grep -v '^ *+' $at_stder1 >$at_stderr
40052at_failed=false
40053$at_diff $at_devnull $at_stderr || at_failed=:
40054$at_diff expout $at_stdout || at_failed=:
40055case $at_status in
40056   77) echo 77 > $at_status_file
40057            exit 77;;
40058   0) ;;
40059   *) echo "calc.at:598: exit code was $at_status, expected 0"
40060      at_failed=:;;
40061esac
40062if $at_failed; then
40063
40064  echo 1 > $at_status_file
40065  exit 1
40066fi
40067
40068$at_traceon
40069
40070
40071
40072
40073
40074
40075
40076
40077
40078
40079
40080
40081
40082
40083
40084
40085
40086
40087
40088
40089
40090
40091
40092
40093      $at_traceoff
40094      $at_times_p && times >$at_times_file
40095    ) 5>&1 2>&1 | eval $at_tee_pipe
40096    at_status=`cat $at_status_file`
40097    ;;
40098
40099  94 ) # 94. calc.at:600: Calculator %glr-parser %debug
40100    at_setup_line='calc.at:600'
40101    at_desc='Calculator %glr-parser %debug'
40102    $at_quiet $ECHO_N " 94: Calculator %glr-parser %debug                $ECHO_C"
40103    at_xfail=no
40104    (
40105      echo "94. calc.at:600: testing ..."
40106      $at_traceon
40107
40108
40109
40110
40111
40112
40113
40114
40115# Using yacc.c?
40116
40117
40118
40119
40120
40121
40122
40123# yyerror receives the location if %location & %pure & (%glr or %parse-param).
40124
40125# yyerror always sees the locations (when activated), except if
40126# yacc & pure & !param.
40127
40128
40129# The interface is pure: either because %pure-parser, or because we
40130# are using the C++ parsers.
40131
40132
40133
40134
40135
40136
40137
40138
40139
40140
40141
40142
40143cat >calc.y <<'_ATEOF'
40144%{
40145#ifdef HAVE_CONFIG_H
40146# include <config.h>
40147  /* We don't need perfect functions for these tests. */
40148# undef malloc
40149# undef memcmp
40150# undef realloc
40151#endif
40152%}
40153
40154/* Infix notation calculator--calc */
40155%glr-parser %debug
40156
40157%{
40158#include <stdio.h>
40159
40160#include <stdlib.h>
40161#include <string.h>
40162#if HAVE_UNISTD_H
40163# include <unistd.h>
40164#else
40165# undef alarm
40166# define alarm(seconds) /* empty */
40167#endif
40168#include <ctype.h>
40169#define USE(Var)
40170
40171/* Exercise pre-prologue dependency to %union.  */
40172typedef int semantic_value;
40173
40174static semantic_value global_result = 0;
40175static int global_count = 0;
40176%}
40177
40178/* Exercise %union. */
40179%union
40180{
40181  semantic_value ival;
40182};
40183
40184%{
40185static int power (int base, int exponent);
40186/* yyerror receives the location if:
40187   - %location & %pure & %glr
40188   - %location & %pure & %yacc & %parse-param. */
40189static void yyerror (
40190
40191                     const char *s
40192                     );
40193static int yylex (void);
40194static int get_char (void);
40195static void unget_char ( int c);
40196%}
40197
40198
40199
40200/* Bison Declarations */
40201%token CALC_EOF 0 "end of input"
40202%token <ival> NUM "number"
40203%type  <ival> exp
40204
40205%nonassoc '=' /* comparison	       */
40206%left '-' '+'
40207%left '*' '/'
40208%left NEG     /* negation--unary minus */
40209%right '^'    /* exponentiation        */
40210
40211/* Grammar follows */
40212%%
40213input:
40214  line
40215| input line         {  }
40216;
40217
40218line:
40219  '\n'
40220| exp '\n'           { USE ($1); }
40221;
40222
40223exp:
40224  NUM                { $$ = $1;             }
40225| exp '=' exp
40226  {
40227    if ($1 != $3)
40228      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
40229    $$ = $1;
40230  }
40231| exp '+' exp        { $$ = $1 + $3;        }
40232| exp '-' exp        { $$ = $1 - $3;        }
40233| exp '*' exp        { $$ = $1 * $3;        }
40234| exp '/' exp        { $$ = $1 / $3;        }
40235| '-' exp  %prec NEG { $$ = -$2;            }
40236| exp '^' exp        { $$ = power ($1, $3); }
40237| '(' exp ')'        { $$ = $2;             }
40238| '(' error ')'      { $$ = 1111;           }
40239| '!'                { $$ = 0; YYERROR;     }
40240| '-' error          { $$ = 0; YYERROR;     }
40241;
40242%%
40243/* The input.  */
40244static FILE *input;
40245
40246static void
40247yyerror (
40248
40249         const char *s)
40250{
40251
40252
40253  fprintf (stderr, "%s\n", s);
40254}
40255
40256
40257
40258static int
40259get_char (void)
40260{
40261  int res = getc (input);
40262  ;
40263
40264  return res;
40265}
40266
40267
40268static void
40269unget_char ( int c)
40270{
40271  ;
40272
40273  ungetc (c, input);
40274}
40275
40276static int
40277read_signed_integer (void)
40278{
40279  int c = get_char ();
40280  int sign = 1;
40281  int n = 0;
40282
40283  ;
40284  if (c == '-')
40285    {
40286      c = get_char ();
40287      sign = -1;
40288    }
40289
40290  while (isdigit (c))
40291    {
40292      n = 10 * n + (c - '0');
40293      c = get_char ();
40294    }
40295
40296  unget_char ( c);
40297
40298  return sign * n;
40299}
40300
40301
40302
40303/*---------------------------------------------------------------.
40304| Lexical analyzer returns an integer on the stack and the token |
40305| NUM, or the ASCII character read if not a number.  Skips all   |
40306| blanks and tabs, returns 0 for EOF.                            |
40307`---------------------------------------------------------------*/
40308
40309static int
40310yylex (void)
40311{
40312  static int init = 1;
40313  int c;
40314
40315  if (init)
40316    {
40317      init = 0;
40318
40319    }
40320
40321
40322
40323  /* Skip white space.  */
40324  while ((c = get_char ()) == ' ' || c == '\t')
40325    {
40326
40327    }
40328
40329  /* process numbers   */
40330  if (c == '.' || isdigit (c))
40331    {
40332      unget_char ( c);
40333      (yylval).ival = read_signed_integer ();
40334      return NUM;
40335    }
40336
40337  /* Return end-of-file.  */
40338  if (c == EOF)
40339    return CALC_EOF;
40340
40341  /* Return single chars. */
40342  return c;
40343}
40344
40345static int
40346power (int base, int exponent)
40347{
40348  int res = 1;
40349  if (exponent < 0)
40350    exit (3);
40351  for (/* Niente */; exponent; --exponent)
40352    res *= base;
40353  return res;
40354}
40355
40356
40357int
40358main (int argc, const char **argv)
40359{
40360  semantic_value result = 0;
40361  int count = 0;
40362  int status;
40363
40364  /* This used to be alarm (10), but that isn't enough time for
40365     a July 1995 vintage DEC Alphastation 200 4/100 system,
40366     according to Nelson H. F. Beebe.  100 seconds is enough.  */
40367  alarm (100);
40368
40369  if (argc == 2)
40370    input = fopen (argv[1], "r");
40371  else
40372    input = stdin;
40373
40374  if (!input)
40375    {
40376      perror (argv[1]);
40377      return 3;
40378    }
40379
40380  yydebug = 1;
40381  status = yyparse ();
40382  if (global_result != result)
40383    abort ();
40384  if (global_count != count)
40385    abort ();
40386  return status;
40387}
40388_ATEOF
40389
40390
40391
40392
40393
40394$at_traceoff
40395echo "calc.at:600: bison -o calc.c calc.y"
40396echo calc.at:600 >$at_check_line_file
40397( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
40398at_status=$?
40399grep '^ *+' $at_stder1 >&2
40400grep -v '^ *+' $at_stder1 >$at_stderr
40401at_failed=false
40402$at_diff $at_devnull $at_stderr || at_failed=:
40403$at_diff $at_devnull $at_stdout || at_failed=:
40404case $at_status in
40405   77) echo 77 > $at_status_file
40406            exit 77;;
40407   0) ;;
40408   *) echo "calc.at:600: exit code was $at_status, expected 0"
40409      at_failed=:;;
40410esac
40411if $at_failed; then
40412
40413  echo 1 > $at_status_file
40414  exit 1
40415fi
40416
40417$at_traceon
40418
40419   $at_traceoff
40420echo "calc.at:600: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
40421echo calc.at:600 >$at_check_line_file
40422( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
40423at_status=$?
40424grep '^ *+' $at_stder1 >&2
40425grep -v '^ *+' $at_stder1 >$at_stderr
40426at_failed=false
40427echo stderr:; cat $at_stderr
40428echo stdout:; cat $at_stdout
40429case $at_status in
40430   77) echo 77 > $at_status_file
40431            exit 77;;
40432   0) ;;
40433   *) echo "calc.at:600: exit code was $at_status, expected 0"
40434      at_failed=:;;
40435esac
40436if $at_failed; then
40437
40438  echo 1 > $at_status_file
40439  exit 1
40440fi
40441
40442$at_traceon
40443
40444
40445# Test the priorities.
40446cat >input <<'_ATEOF'
404471 + 2 * 3 = 7
404481 + 2 * -3 = -5
40449
40450-1^2 = -1
40451(-1)^2 = 1
40452
40453---1 = -1
40454
404551 - 2 - 3 = -4
404561 - (2 - 3) = 2
40457
404582^2^3 = 256
40459(2^2)^3 = 64
40460_ATEOF
40461
40462$at_traceoff
40463echo "calc.at:600: \$PREPARSER ./calc input"
40464echo calc.at:600 >$at_check_line_file
40465( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
40466at_status=$?
40467grep '^ *+' $at_stder1 >&2
40468grep -v '^ *+' $at_stder1 >$at_stderr
40469at_failed=false
40470echo stderr:; tee stderr <$at_stderr
40471$at_diff $at_devnull $at_stdout || at_failed=:
40472case $at_status in
40473   77) echo 77 > $at_status_file
40474            exit 77;;
40475   0) ;;
40476   *) echo "calc.at:600: exit code was $at_status, expected 0"
40477      at_failed=:;;
40478esac
40479if $at_failed; then
40480
40481  echo 1 > $at_status_file
40482  exit 1
40483fi
40484
40485$at_traceon
40486
40487
40488
40489# Some syntax errors.
40490cat >input <<'_ATEOF'
404910 0
40492_ATEOF
40493
40494$at_traceoff
40495echo "calc.at:600: \$PREPARSER ./calc input"
40496echo calc.at:600 >$at_check_line_file
40497( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
40498at_status=$?
40499grep '^ *+' $at_stder1 >&2
40500grep -v '^ *+' $at_stder1 >$at_stderr
40501at_failed=false
40502echo stderr:; tee stderr <$at_stderr
40503$at_diff $at_devnull $at_stdout || at_failed=:
40504case $at_status in
40505   77) echo 77 > $at_status_file
40506            exit 77;;
40507   1) ;;
40508   *) echo "calc.at:600: exit code was $at_status, expected 1"
40509      at_failed=:;;
40510esac
40511if $at_failed; then
40512
40513  echo 1 > $at_status_file
40514  exit 1
40515fi
40516
40517$at_traceon
40518
40519
40520# Normalize the observed and expected error messages, depending upon the
40521# options.
40522# 1. Remove the traces from observed.
40523sed '/^Starting/d
40524/^Entering/d
40525/^Stack/d
40526/^Reading/d
40527/^Reducing/d
40528/^Shifting/d
40529/^state/d
40530/^Cleanup:/d
40531/^Error:/d
40532/^Next/d
40533/^Discarding/d
40534/ \$[0-9$]* = /d
40535/^yydestructor:/d' stderr >at-stderr
40536mv at-stderr stderr
40537# 2. Create the reference error message.
40538cat >expout <<'_ATEOF'
405391.2: syntax error, unexpected number
40540_ATEOF
40541
40542# 3. If locations are not used, remove them.
40543sed 's/^[-0-9.]*: //' expout >at-expout
40544mv at-expout expout
40545# 4. If error-verbose is not used, strip the`, unexpected....' part.
40546sed 's/syntax error, .*$/syntax error/' expout >at-expout
40547mv at-expout expout
40548# 5. Check
40549$at_traceoff
40550echo "calc.at:600: cat stderr"
40551echo calc.at:600 >$at_check_line_file
40552( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
40553at_status=$?
40554grep '^ *+' $at_stder1 >&2
40555grep -v '^ *+' $at_stder1 >$at_stderr
40556at_failed=false
40557$at_diff $at_devnull $at_stderr || at_failed=:
40558$at_diff expout $at_stdout || at_failed=:
40559case $at_status in
40560   77) echo 77 > $at_status_file
40561            exit 77;;
40562   0) ;;
40563   *) echo "calc.at:600: exit code was $at_status, expected 0"
40564      at_failed=:;;
40565esac
40566if $at_failed; then
40567
40568  echo 1 > $at_status_file
40569  exit 1
40570fi
40571
40572$at_traceon
40573
40574
40575cat >input <<'_ATEOF'
405761//2
40577_ATEOF
40578
40579$at_traceoff
40580echo "calc.at:600: \$PREPARSER ./calc input"
40581echo calc.at:600 >$at_check_line_file
40582( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
40583at_status=$?
40584grep '^ *+' $at_stder1 >&2
40585grep -v '^ *+' $at_stder1 >$at_stderr
40586at_failed=false
40587echo stderr:; tee stderr <$at_stderr
40588$at_diff $at_devnull $at_stdout || at_failed=:
40589case $at_status in
40590   77) echo 77 > $at_status_file
40591            exit 77;;
40592   1) ;;
40593   *) echo "calc.at:600: exit code was $at_status, expected 1"
40594      at_failed=:;;
40595esac
40596if $at_failed; then
40597
40598  echo 1 > $at_status_file
40599  exit 1
40600fi
40601
40602$at_traceon
40603
40604
40605# Normalize the observed and expected error messages, depending upon the
40606# options.
40607# 1. Remove the traces from observed.
40608sed '/^Starting/d
40609/^Entering/d
40610/^Stack/d
40611/^Reading/d
40612/^Reducing/d
40613/^Shifting/d
40614/^state/d
40615/^Cleanup:/d
40616/^Error:/d
40617/^Next/d
40618/^Discarding/d
40619/ \$[0-9$]* = /d
40620/^yydestructor:/d' stderr >at-stderr
40621mv at-stderr stderr
40622# 2. Create the reference error message.
40623cat >expout <<'_ATEOF'
406241.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
40625_ATEOF
40626
40627# 3. If locations are not used, remove them.
40628sed 's/^[-0-9.]*: //' expout >at-expout
40629mv at-expout expout
40630# 4. If error-verbose is not used, strip the`, unexpected....' part.
40631sed 's/syntax error, .*$/syntax error/' expout >at-expout
40632mv at-expout expout
40633# 5. Check
40634$at_traceoff
40635echo "calc.at:600: cat stderr"
40636echo calc.at:600 >$at_check_line_file
40637( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
40638at_status=$?
40639grep '^ *+' $at_stder1 >&2
40640grep -v '^ *+' $at_stder1 >$at_stderr
40641at_failed=false
40642$at_diff $at_devnull $at_stderr || at_failed=:
40643$at_diff expout $at_stdout || at_failed=:
40644case $at_status in
40645   77) echo 77 > $at_status_file
40646            exit 77;;
40647   0) ;;
40648   *) echo "calc.at:600: exit code was $at_status, expected 0"
40649      at_failed=:;;
40650esac
40651if $at_failed; then
40652
40653  echo 1 > $at_status_file
40654  exit 1
40655fi
40656
40657$at_traceon
40658
40659
40660cat >input <<'_ATEOF'
40661error
40662_ATEOF
40663
40664$at_traceoff
40665echo "calc.at:600: \$PREPARSER ./calc input"
40666echo calc.at:600 >$at_check_line_file
40667( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
40668at_status=$?
40669grep '^ *+' $at_stder1 >&2
40670grep -v '^ *+' $at_stder1 >$at_stderr
40671at_failed=false
40672echo stderr:; tee stderr <$at_stderr
40673$at_diff $at_devnull $at_stdout || at_failed=:
40674case $at_status in
40675   77) echo 77 > $at_status_file
40676            exit 77;;
40677   1) ;;
40678   *) echo "calc.at:600: exit code was $at_status, expected 1"
40679      at_failed=:;;
40680esac
40681if $at_failed; then
40682
40683  echo 1 > $at_status_file
40684  exit 1
40685fi
40686
40687$at_traceon
40688
40689
40690# Normalize the observed and expected error messages, depending upon the
40691# options.
40692# 1. Remove the traces from observed.
40693sed '/^Starting/d
40694/^Entering/d
40695/^Stack/d
40696/^Reading/d
40697/^Reducing/d
40698/^Shifting/d
40699/^state/d
40700/^Cleanup:/d
40701/^Error:/d
40702/^Next/d
40703/^Discarding/d
40704/ \$[0-9$]* = /d
40705/^yydestructor:/d' stderr >at-stderr
40706mv at-stderr stderr
40707# 2. Create the reference error message.
40708cat >expout <<'_ATEOF'
407091.0: syntax error, unexpected $undefined
40710_ATEOF
40711
40712# 3. If locations are not used, remove them.
40713sed 's/^[-0-9.]*: //' expout >at-expout
40714mv at-expout expout
40715# 4. If error-verbose is not used, strip the`, unexpected....' part.
40716sed 's/syntax error, .*$/syntax error/' expout >at-expout
40717mv at-expout expout
40718# 5. Check
40719$at_traceoff
40720echo "calc.at:600: cat stderr"
40721echo calc.at:600 >$at_check_line_file
40722( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
40723at_status=$?
40724grep '^ *+' $at_stder1 >&2
40725grep -v '^ *+' $at_stder1 >$at_stderr
40726at_failed=false
40727$at_diff $at_devnull $at_stderr || at_failed=:
40728$at_diff expout $at_stdout || at_failed=:
40729case $at_status in
40730   77) echo 77 > $at_status_file
40731            exit 77;;
40732   0) ;;
40733   *) echo "calc.at:600: exit code was $at_status, expected 0"
40734      at_failed=:;;
40735esac
40736if $at_failed; then
40737
40738  echo 1 > $at_status_file
40739  exit 1
40740fi
40741
40742$at_traceon
40743
40744
40745cat >input <<'_ATEOF'
407461 = 2 = 3
40747_ATEOF
40748
40749$at_traceoff
40750echo "calc.at:600: \$PREPARSER ./calc input"
40751echo calc.at:600 >$at_check_line_file
40752( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
40753at_status=$?
40754grep '^ *+' $at_stder1 >&2
40755grep -v '^ *+' $at_stder1 >$at_stderr
40756at_failed=false
40757echo stderr:; tee stderr <$at_stderr
40758$at_diff $at_devnull $at_stdout || at_failed=:
40759case $at_status in
40760   77) echo 77 > $at_status_file
40761            exit 77;;
40762   1) ;;
40763   *) echo "calc.at:600: exit code was $at_status, expected 1"
40764      at_failed=:;;
40765esac
40766if $at_failed; then
40767
40768  echo 1 > $at_status_file
40769  exit 1
40770fi
40771
40772$at_traceon
40773
40774
40775# Normalize the observed and expected error messages, depending upon the
40776# options.
40777# 1. Remove the traces from observed.
40778sed '/^Starting/d
40779/^Entering/d
40780/^Stack/d
40781/^Reading/d
40782/^Reducing/d
40783/^Shifting/d
40784/^state/d
40785/^Cleanup:/d
40786/^Error:/d
40787/^Next/d
40788/^Discarding/d
40789/ \$[0-9$]* = /d
40790/^yydestructor:/d' stderr >at-stderr
40791mv at-stderr stderr
40792# 2. Create the reference error message.
40793cat >expout <<'_ATEOF'
407941.6: syntax error, unexpected '='
40795_ATEOF
40796
40797# 3. If locations are not used, remove them.
40798sed 's/^[-0-9.]*: //' expout >at-expout
40799mv at-expout expout
40800# 4. If error-verbose is not used, strip the`, unexpected....' part.
40801sed 's/syntax error, .*$/syntax error/' expout >at-expout
40802mv at-expout expout
40803# 5. Check
40804$at_traceoff
40805echo "calc.at:600: cat stderr"
40806echo calc.at:600 >$at_check_line_file
40807( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
40808at_status=$?
40809grep '^ *+' $at_stder1 >&2
40810grep -v '^ *+' $at_stder1 >$at_stderr
40811at_failed=false
40812$at_diff $at_devnull $at_stderr || at_failed=:
40813$at_diff expout $at_stdout || at_failed=:
40814case $at_status in
40815   77) echo 77 > $at_status_file
40816            exit 77;;
40817   0) ;;
40818   *) echo "calc.at:600: exit code was $at_status, expected 0"
40819      at_failed=:;;
40820esac
40821if $at_failed; then
40822
40823  echo 1 > $at_status_file
40824  exit 1
40825fi
40826
40827$at_traceon
40828
40829
40830cat >input <<'_ATEOF'
40831
40832+1
40833_ATEOF
40834
40835$at_traceoff
40836echo "calc.at:600: \$PREPARSER ./calc input"
40837echo calc.at:600 >$at_check_line_file
40838( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
40839at_status=$?
40840grep '^ *+' $at_stder1 >&2
40841grep -v '^ *+' $at_stder1 >$at_stderr
40842at_failed=false
40843echo stderr:; tee stderr <$at_stderr
40844$at_diff $at_devnull $at_stdout || at_failed=:
40845case $at_status in
40846   77) echo 77 > $at_status_file
40847            exit 77;;
40848   1) ;;
40849   *) echo "calc.at:600: exit code was $at_status, expected 1"
40850      at_failed=:;;
40851esac
40852if $at_failed; then
40853
40854  echo 1 > $at_status_file
40855  exit 1
40856fi
40857
40858$at_traceon
40859
40860
40861# Normalize the observed and expected error messages, depending upon the
40862# options.
40863# 1. Remove the traces from observed.
40864sed '/^Starting/d
40865/^Entering/d
40866/^Stack/d
40867/^Reading/d
40868/^Reducing/d
40869/^Shifting/d
40870/^state/d
40871/^Cleanup:/d
40872/^Error:/d
40873/^Next/d
40874/^Discarding/d
40875/ \$[0-9$]* = /d
40876/^yydestructor:/d' stderr >at-stderr
40877mv at-stderr stderr
40878# 2. Create the reference error message.
40879cat >expout <<'_ATEOF'
408802.0: syntax error, unexpected '+'
40881_ATEOF
40882
40883# 3. If locations are not used, remove them.
40884sed 's/^[-0-9.]*: //' expout >at-expout
40885mv at-expout expout
40886# 4. If error-verbose is not used, strip the`, unexpected....' part.
40887sed 's/syntax error, .*$/syntax error/' expout >at-expout
40888mv at-expout expout
40889# 5. Check
40890$at_traceoff
40891echo "calc.at:600: cat stderr"
40892echo calc.at:600 >$at_check_line_file
40893( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
40894at_status=$?
40895grep '^ *+' $at_stder1 >&2
40896grep -v '^ *+' $at_stder1 >$at_stderr
40897at_failed=false
40898$at_diff $at_devnull $at_stderr || at_failed=:
40899$at_diff expout $at_stdout || at_failed=:
40900case $at_status in
40901   77) echo 77 > $at_status_file
40902            exit 77;;
40903   0) ;;
40904   *) echo "calc.at:600: exit code was $at_status, expected 0"
40905      at_failed=:;;
40906esac
40907if $at_failed; then
40908
40909  echo 1 > $at_status_file
40910  exit 1
40911fi
40912
40913$at_traceon
40914
40915
40916# Exercise error messages with EOF: work on an empty file.
40917$at_traceoff
40918echo "calc.at:600: \$PREPARSER ./calc /dev/null"
40919echo calc.at:600 >$at_check_line_file
40920( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
40921at_status=$?
40922grep '^ *+' $at_stder1 >&2
40923grep -v '^ *+' $at_stder1 >$at_stderr
40924at_failed=false
40925echo stderr:; tee stderr <$at_stderr
40926$at_diff $at_devnull $at_stdout || at_failed=:
40927case $at_status in
40928   77) echo 77 > $at_status_file
40929            exit 77;;
40930   1) ;;
40931   *) echo "calc.at:600: exit code was $at_status, expected 1"
40932      at_failed=:;;
40933esac
40934if $at_failed; then
40935
40936  echo 1 > $at_status_file
40937  exit 1
40938fi
40939
40940$at_traceon
40941
40942
40943# Normalize the observed and expected error messages, depending upon the
40944# options.
40945# 1. Remove the traces from observed.
40946sed '/^Starting/d
40947/^Entering/d
40948/^Stack/d
40949/^Reading/d
40950/^Reducing/d
40951/^Shifting/d
40952/^state/d
40953/^Cleanup:/d
40954/^Error:/d
40955/^Next/d
40956/^Discarding/d
40957/ \$[0-9$]* = /d
40958/^yydestructor:/d' stderr >at-stderr
40959mv at-stderr stderr
40960# 2. Create the reference error message.
40961cat >expout <<'_ATEOF'
409621.0: syntax error, unexpected end of input
40963_ATEOF
40964
40965# 3. If locations are not used, remove them.
40966sed 's/^[-0-9.]*: //' expout >at-expout
40967mv at-expout expout
40968# 4. If error-verbose is not used, strip the`, unexpected....' part.
40969sed 's/syntax error, .*$/syntax error/' expout >at-expout
40970mv at-expout expout
40971# 5. Check
40972$at_traceoff
40973echo "calc.at:600: cat stderr"
40974echo calc.at:600 >$at_check_line_file
40975( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
40976at_status=$?
40977grep '^ *+' $at_stder1 >&2
40978grep -v '^ *+' $at_stder1 >$at_stderr
40979at_failed=false
40980$at_diff $at_devnull $at_stderr || at_failed=:
40981$at_diff expout $at_stdout || at_failed=:
40982case $at_status in
40983   77) echo 77 > $at_status_file
40984            exit 77;;
40985   0) ;;
40986   *) echo "calc.at:600: exit code was $at_status, expected 0"
40987      at_failed=:;;
40988esac
40989if $at_failed; then
40990
40991  echo 1 > $at_status_file
40992  exit 1
40993fi
40994
40995$at_traceon
40996
40997
40998
40999# Exercise the error token: without it, we die at the first error,
41000# hence be sure to
41001#
41002# - have several errors which exercise different shift/discardings
41003#   - (): nothing to pop, nothing to discard
41004#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
41005#   - (* * *): nothing to pop, a lot to discard
41006#   - (1 + 2 * *): some to pop and discard
41007#
41008# - test the action associated to `error'
41009#
41010# - check the look-ahead that triggers an error is not discarded
41011#   when we enter error recovery.  Below, the look-ahead causing the
41012#   first error is ")", which is needed to recover from the error and
41013#   produce the "0" that triggers the "0 != 1" error.
41014#
41015cat >input <<'_ATEOF'
41016() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
41017_ATEOF
41018
41019$at_traceoff
41020echo "calc.at:600: \$PREPARSER ./calc input"
41021echo calc.at:600 >$at_check_line_file
41022( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
41023at_status=$?
41024grep '^ *+' $at_stder1 >&2
41025grep -v '^ *+' $at_stder1 >$at_stderr
41026at_failed=false
41027echo stderr:; tee stderr <$at_stderr
41028$at_diff $at_devnull $at_stdout || at_failed=:
41029case $at_status in
41030   77) echo 77 > $at_status_file
41031            exit 77;;
41032   0) ;;
41033   *) echo "calc.at:600: exit code was $at_status, expected 0"
41034      at_failed=:;;
41035esac
41036if $at_failed; then
41037
41038  echo 1 > $at_status_file
41039  exit 1
41040fi
41041
41042$at_traceon
41043
41044
41045# Normalize the observed and expected error messages, depending upon the
41046# options.
41047# 1. Remove the traces from observed.
41048sed '/^Starting/d
41049/^Entering/d
41050/^Stack/d
41051/^Reading/d
41052/^Reducing/d
41053/^Shifting/d
41054/^state/d
41055/^Cleanup:/d
41056/^Error:/d
41057/^Next/d
41058/^Discarding/d
41059/ \$[0-9$]* = /d
41060/^yydestructor:/d' stderr >at-stderr
41061mv at-stderr stderr
41062# 2. Create the reference error message.
41063cat >expout <<'_ATEOF'
410641.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
410651.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
410661.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
410671.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
41068calc: error: 4444 != 1
41069_ATEOF
41070
41071# 3. If locations are not used, remove them.
41072sed 's/^[-0-9.]*: //' expout >at-expout
41073mv at-expout expout
41074# 4. If error-verbose is not used, strip the`, unexpected....' part.
41075sed 's/syntax error, .*$/syntax error/' expout >at-expout
41076mv at-expout expout
41077# 5. Check
41078$at_traceoff
41079echo "calc.at:600: cat stderr"
41080echo calc.at:600 >$at_check_line_file
41081( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
41082at_status=$?
41083grep '^ *+' $at_stder1 >&2
41084grep -v '^ *+' $at_stder1 >$at_stderr
41085at_failed=false
41086$at_diff $at_devnull $at_stderr || at_failed=:
41087$at_diff expout $at_stdout || at_failed=:
41088case $at_status in
41089   77) echo 77 > $at_status_file
41090            exit 77;;
41091   0) ;;
41092   *) echo "calc.at:600: exit code was $at_status, expected 0"
41093      at_failed=:;;
41094esac
41095if $at_failed; then
41096
41097  echo 1 > $at_status_file
41098  exit 1
41099fi
41100
41101$at_traceon
41102
41103
41104
41105# The same, but this time exercising explicitly triggered syntax errors.
41106# POSIX says the look-ahead causing the error should not be discarded.
41107cat >input <<'_ATEOF'
41108(!) + (0 0) = 1
41109_ATEOF
41110
41111$at_traceoff
41112echo "calc.at:600: \$PREPARSER ./calc input"
41113echo calc.at:600 >$at_check_line_file
41114( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
41115at_status=$?
41116grep '^ *+' $at_stder1 >&2
41117grep -v '^ *+' $at_stder1 >$at_stderr
41118at_failed=false
41119echo stderr:; tee stderr <$at_stderr
41120$at_diff $at_devnull $at_stdout || at_failed=:
41121case $at_status in
41122   77) echo 77 > $at_status_file
41123            exit 77;;
41124   0) ;;
41125   *) echo "calc.at:600: exit code was $at_status, expected 0"
41126      at_failed=:;;
41127esac
41128if $at_failed; then
41129
41130  echo 1 > $at_status_file
41131  exit 1
41132fi
41133
41134$at_traceon
41135
41136
41137# Normalize the observed and expected error messages, depending upon the
41138# options.
41139# 1. Remove the traces from observed.
41140sed '/^Starting/d
41141/^Entering/d
41142/^Stack/d
41143/^Reading/d
41144/^Reducing/d
41145/^Shifting/d
41146/^state/d
41147/^Cleanup:/d
41148/^Error:/d
41149/^Next/d
41150/^Discarding/d
41151/ \$[0-9$]* = /d
41152/^yydestructor:/d' stderr >at-stderr
41153mv at-stderr stderr
41154# 2. Create the reference error message.
41155cat >expout <<'_ATEOF'
411561.9: syntax error, unexpected number
41157calc: error: 2222 != 1
41158_ATEOF
41159
41160# 3. If locations are not used, remove them.
41161sed 's/^[-0-9.]*: //' expout >at-expout
41162mv at-expout expout
41163# 4. If error-verbose is not used, strip the`, unexpected....' part.
41164sed 's/syntax error, .*$/syntax error/' expout >at-expout
41165mv at-expout expout
41166# 5. Check
41167$at_traceoff
41168echo "calc.at:600: cat stderr"
41169echo calc.at:600 >$at_check_line_file
41170( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
41171at_status=$?
41172grep '^ *+' $at_stder1 >&2
41173grep -v '^ *+' $at_stder1 >$at_stderr
41174at_failed=false
41175$at_diff $at_devnull $at_stderr || at_failed=:
41176$at_diff expout $at_stdout || at_failed=:
41177case $at_status in
41178   77) echo 77 > $at_status_file
41179            exit 77;;
41180   0) ;;
41181   *) echo "calc.at:600: exit code was $at_status, expected 0"
41182      at_failed=:;;
41183esac
41184if $at_failed; then
41185
41186  echo 1 > $at_status_file
41187  exit 1
41188fi
41189
41190$at_traceon
41191
41192
41193cat >input <<'_ATEOF'
41194(- *) + (0 0) = 1
41195_ATEOF
41196
41197$at_traceoff
41198echo "calc.at:600: \$PREPARSER ./calc input"
41199echo calc.at:600 >$at_check_line_file
41200( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
41201at_status=$?
41202grep '^ *+' $at_stder1 >&2
41203grep -v '^ *+' $at_stder1 >$at_stderr
41204at_failed=false
41205echo stderr:; tee stderr <$at_stderr
41206$at_diff $at_devnull $at_stdout || at_failed=:
41207case $at_status in
41208   77) echo 77 > $at_status_file
41209            exit 77;;
41210   0) ;;
41211   *) echo "calc.at:600: exit code was $at_status, expected 0"
41212      at_failed=:;;
41213esac
41214if $at_failed; then
41215
41216  echo 1 > $at_status_file
41217  exit 1
41218fi
41219
41220$at_traceon
41221
41222
41223# Normalize the observed and expected error messages, depending upon the
41224# options.
41225# 1. Remove the traces from observed.
41226sed '/^Starting/d
41227/^Entering/d
41228/^Stack/d
41229/^Reading/d
41230/^Reducing/d
41231/^Shifting/d
41232/^state/d
41233/^Cleanup:/d
41234/^Error:/d
41235/^Next/d
41236/^Discarding/d
41237/ \$[0-9$]* = /d
41238/^yydestructor:/d' stderr >at-stderr
41239mv at-stderr stderr
41240# 2. Create the reference error message.
41241cat >expout <<'_ATEOF'
412421.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
412431.11: syntax error, unexpected number
41244calc: error: 2222 != 1
41245_ATEOF
41246
41247# 3. If locations are not used, remove them.
41248sed 's/^[-0-9.]*: //' expout >at-expout
41249mv at-expout expout
41250# 4. If error-verbose is not used, strip the`, unexpected....' part.
41251sed 's/syntax error, .*$/syntax error/' expout >at-expout
41252mv at-expout expout
41253# 5. Check
41254$at_traceoff
41255echo "calc.at:600: cat stderr"
41256echo calc.at:600 >$at_check_line_file
41257( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
41258at_status=$?
41259grep '^ *+' $at_stder1 >&2
41260grep -v '^ *+' $at_stder1 >$at_stderr
41261at_failed=false
41262$at_diff $at_devnull $at_stderr || at_failed=:
41263$at_diff expout $at_stdout || at_failed=:
41264case $at_status in
41265   77) echo 77 > $at_status_file
41266            exit 77;;
41267   0) ;;
41268   *) echo "calc.at:600: exit code was $at_status, expected 0"
41269      at_failed=:;;
41270esac
41271if $at_failed; then
41272
41273  echo 1 > $at_status_file
41274  exit 1
41275fi
41276
41277$at_traceon
41278
41279
41280
41281
41282
41283
41284
41285
41286
41287
41288
41289
41290
41291
41292
41293
41294
41295
41296
41297
41298
41299
41300
41301
41302      $at_traceoff
41303      $at_times_p && times >$at_times_file
41304    ) 5>&1 2>&1 | eval $at_tee_pipe
41305    at_status=`cat $at_status_file`
41306    ;;
41307
41308  95 ) # 95. calc.at:601: Calculator %glr-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
41309    at_setup_line='calc.at:601'
41310    at_desc='Calculator %glr-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc'
41311    $at_quiet $ECHO_N " 95: Calculator %glr-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc$ECHO_C"
41312    at_xfail=no
41313    (
41314      echo "95. calc.at:601: testing ..."
41315      $at_traceon
41316
41317
41318
41319
41320
41321
41322
41323
41324# Using yacc.c?
41325
41326
41327
41328
41329
41330
41331
41332# yyerror receives the location if %location & %pure & (%glr or %parse-param).
41333
41334# yyerror always sees the locations (when activated), except if
41335# yacc & pure & !param.
41336
41337
41338# The interface is pure: either because %pure-parser, or because we
41339# are using the C++ parsers.
41340
41341
41342
41343
41344
41345
41346
41347
41348
41349
41350
41351
41352cat >calc.y <<'_ATEOF'
41353%{
41354#ifdef HAVE_CONFIG_H
41355# include <config.h>
41356  /* We don't need perfect functions for these tests. */
41357# undef malloc
41358# undef memcmp
41359# undef realloc
41360#endif
41361%}
41362
41363/* Infix notation calculator--calc */
41364%glr-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
41365
41366%{
41367#include <stdio.h>
41368
41369#include <stdlib.h>
41370#include <string.h>
41371#if HAVE_UNISTD_H
41372# include <unistd.h>
41373#else
41374# undef alarm
41375# define alarm(seconds) /* empty */
41376#endif
41377#include <ctype.h>
41378#define USE(Var)
41379
41380/* Exercise pre-prologue dependency to %union.  */
41381typedef int semantic_value;
41382
41383static semantic_value global_result = 0;
41384static int global_count = 0;
41385%}
41386
41387/* Exercise %union. */
41388%union
41389{
41390  semantic_value ival;
41391};
41392
41393%{
41394static int power (int base, int exponent);
41395/* yyerror receives the location if:
41396   - %location & %pure & %glr
41397   - %location & %pure & %yacc & %parse-param. */
41398static void yyerror (
41399
41400                     const char *s
41401                     );
41402static int yylex (void);
41403static int get_char (void);
41404static void unget_char ( int c);
41405%}
41406
41407
41408
41409/* Bison Declarations */
41410%token CALC_EOF 0 "end of input"
41411%token <ival> NUM "number"
41412%type  <ival> exp
41413
41414%nonassoc '=' /* comparison	       */
41415%left '-' '+'
41416%left '*' '/'
41417%left NEG     /* negation--unary minus */
41418%right '^'    /* exponentiation        */
41419
41420/* Grammar follows */
41421%%
41422input:
41423  line
41424| input line         {  }
41425;
41426
41427line:
41428  '\n'
41429| exp '\n'           { USE ($1); }
41430;
41431
41432exp:
41433  NUM                { $$ = $1;             }
41434| exp '=' exp
41435  {
41436    if ($1 != $3)
41437      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
41438    $$ = $1;
41439  }
41440| exp '+' exp        { $$ = $1 + $3;        }
41441| exp '-' exp        { $$ = $1 - $3;        }
41442| exp '*' exp        { $$ = $1 * $3;        }
41443| exp '/' exp        { $$ = $1 / $3;        }
41444| '-' exp  %prec NEG { $$ = -$2;            }
41445| exp '^' exp        { $$ = power ($1, $3); }
41446| '(' exp ')'        { $$ = $2;             }
41447| '(' error ')'      { $$ = 1111;           }
41448| '!'                { $$ = 0; YYERROR;     }
41449| '-' error          { $$ = 0; YYERROR;     }
41450;
41451%%
41452/* The input.  */
41453static FILE *input;
41454
41455static void
41456yyerror (
41457
41458         const char *s)
41459{
41460
41461
41462  fprintf (stderr, "%d.%d",
41463           (yylloc).first_line, (yylloc).first_column);
41464  if ((yylloc).first_line != (yylloc).last_line)
41465    fprintf (stderr, "-%d.%d",
41466	     (yylloc).last_line,  (yylloc).last_column - 1);
41467  else if ((yylloc).first_column != (yylloc).last_column - 1)
41468    fprintf (stderr, "-%d",
41469	     (yylloc).last_column - 1);
41470  fprintf (stderr, ": ");
41471  fprintf (stderr, "%s\n", s);
41472}
41473
41474
41475
41476static YYLTYPE last_yylloc;
41477
41478static int
41479get_char (void)
41480{
41481  int res = getc (input);
41482  ;
41483
41484  last_yylloc = (yylloc);
41485  if (res == '\n')
41486    {
41487      (yylloc).last_line++;
41488      (yylloc).last_column = 0;
41489    }
41490  else
41491    (yylloc).last_column++;
41492
41493  return res;
41494}
41495
41496
41497static void
41498unget_char ( int c)
41499{
41500  ;
41501
41502  /* Wrong when C == `\n'. */
41503  (yylloc) = last_yylloc;
41504
41505  ungetc (c, input);
41506}
41507
41508static int
41509read_signed_integer (void)
41510{
41511  int c = get_char ();
41512  int sign = 1;
41513  int n = 0;
41514
41515  ;
41516  if (c == '-')
41517    {
41518      c = get_char ();
41519      sign = -1;
41520    }
41521
41522  while (isdigit (c))
41523    {
41524      n = 10 * n + (c - '0');
41525      c = get_char ();
41526    }
41527
41528  unget_char ( c);
41529
41530  return sign * n;
41531}
41532
41533
41534
41535/*---------------------------------------------------------------.
41536| Lexical analyzer returns an integer on the stack and the token |
41537| NUM, or the ASCII character read if not a number.  Skips all   |
41538| blanks and tabs, returns 0 for EOF.                            |
41539`---------------------------------------------------------------*/
41540
41541static int
41542yylex (void)
41543{
41544  static int init = 1;
41545  int c;
41546
41547  if (init)
41548    {
41549      init = 0;
41550
41551      (yylloc).last_column = 0;
41552      (yylloc).last_line = 1;
41553
41554    }
41555
41556
41557 (yylloc).first_column = (yylloc).last_column;
41558  (yylloc).first_line   = (yylloc).last_line;
41559
41560
41561  /* Skip white space.  */
41562  while ((c = get_char ()) == ' ' || c == '\t')
41563    {
41564     (yylloc).first_column = (yylloc).last_column;
41565      (yylloc).first_line   = (yylloc).last_line;
41566
41567    }
41568
41569  /* process numbers   */
41570  if (c == '.' || isdigit (c))
41571    {
41572      unget_char ( c);
41573      (yylval).ival = read_signed_integer ();
41574      return NUM;
41575    }
41576
41577  /* Return end-of-file.  */
41578  if (c == EOF)
41579    return CALC_EOF;
41580
41581  /* Return single chars. */
41582  return c;
41583}
41584
41585static int
41586power (int base, int exponent)
41587{
41588  int res = 1;
41589  if (exponent < 0)
41590    exit (3);
41591  for (/* Niente */; exponent; --exponent)
41592    res *= base;
41593  return res;
41594}
41595
41596
41597int
41598main (int argc, const char **argv)
41599{
41600  semantic_value result = 0;
41601  int count = 0;
41602  int status;
41603
41604  /* This used to be alarm (10), but that isn't enough time for
41605     a July 1995 vintage DEC Alphastation 200 4/100 system,
41606     according to Nelson H. F. Beebe.  100 seconds is enough.  */
41607  alarm (100);
41608
41609  if (argc == 2)
41610    input = fopen (argv[1], "r");
41611  else
41612    input = stdin;
41613
41614  if (!input)
41615    {
41616      perror (argv[1]);
41617      return 3;
41618    }
41619
41620  yydebug = 1;
41621  status = yyparse ();
41622  if (global_result != result)
41623    abort ();
41624  if (global_count != count)
41625    abort ();
41626  return status;
41627}
41628_ATEOF
41629
41630
41631
41632
41633
41634$at_traceoff
41635echo "calc.at:601: bison -o calc.c calc.y"
41636echo calc.at:601 >$at_check_line_file
41637( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
41638at_status=$?
41639grep '^ *+' $at_stder1 >&2
41640grep -v '^ *+' $at_stder1 >$at_stderr
41641at_failed=false
41642$at_diff $at_devnull $at_stderr || at_failed=:
41643$at_diff $at_devnull $at_stdout || at_failed=:
41644case $at_status in
41645   77) echo 77 > $at_status_file
41646            exit 77;;
41647   0) ;;
41648   *) echo "calc.at:601: exit code was $at_status, expected 0"
41649      at_failed=:;;
41650esac
41651if $at_failed; then
41652
41653  echo 1 > $at_status_file
41654  exit 1
41655fi
41656
41657$at_traceon
41658
41659   $at_traceoff
41660echo "calc.at:601: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
41661echo calc.at:601 >$at_check_line_file
41662( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
41663at_status=$?
41664grep '^ *+' $at_stder1 >&2
41665grep -v '^ *+' $at_stder1 >$at_stderr
41666at_failed=false
41667echo stderr:; cat $at_stderr
41668echo stdout:; cat $at_stdout
41669case $at_status in
41670   77) echo 77 > $at_status_file
41671            exit 77;;
41672   0) ;;
41673   *) echo "calc.at:601: exit code was $at_status, expected 0"
41674      at_failed=:;;
41675esac
41676if $at_failed; then
41677
41678  echo 1 > $at_status_file
41679  exit 1
41680fi
41681
41682$at_traceon
41683
41684
41685# Test the priorities.
41686cat >input <<'_ATEOF'
416871 + 2 * 3 = 7
416881 + 2 * -3 = -5
41689
41690-1^2 = -1
41691(-1)^2 = 1
41692
41693---1 = -1
41694
416951 - 2 - 3 = -4
416961 - (2 - 3) = 2
41697
416982^2^3 = 256
41699(2^2)^3 = 64
41700_ATEOF
41701
41702$at_traceoff
41703echo "calc.at:601: \$PREPARSER ./calc input"
41704echo calc.at:601 >$at_check_line_file
41705( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
41706at_status=$?
41707grep '^ *+' $at_stder1 >&2
41708grep -v '^ *+' $at_stder1 >$at_stderr
41709at_failed=false
41710echo stderr:; tee stderr <$at_stderr
41711$at_diff $at_devnull $at_stdout || at_failed=:
41712case $at_status in
41713   77) echo 77 > $at_status_file
41714            exit 77;;
41715   0) ;;
41716   *) echo "calc.at:601: exit code was $at_status, expected 0"
41717      at_failed=:;;
41718esac
41719if $at_failed; then
41720
41721  echo 1 > $at_status_file
41722  exit 1
41723fi
41724
41725$at_traceon
41726
41727
41728
41729# Some syntax errors.
41730cat >input <<'_ATEOF'
417310 0
41732_ATEOF
41733
41734$at_traceoff
41735echo "calc.at:601: \$PREPARSER ./calc input"
41736echo calc.at:601 >$at_check_line_file
41737( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
41738at_status=$?
41739grep '^ *+' $at_stder1 >&2
41740grep -v '^ *+' $at_stder1 >$at_stderr
41741at_failed=false
41742echo stderr:; tee stderr <$at_stderr
41743$at_diff $at_devnull $at_stdout || at_failed=:
41744case $at_status in
41745   77) echo 77 > $at_status_file
41746            exit 77;;
41747   1) ;;
41748   *) echo "calc.at:601: exit code was $at_status, expected 1"
41749      at_failed=:;;
41750esac
41751if $at_failed; then
41752
41753  echo 1 > $at_status_file
41754  exit 1
41755fi
41756
41757$at_traceon
41758
41759
41760# Normalize the observed and expected error messages, depending upon the
41761# options.
41762# 1. Remove the traces from observed.
41763sed '/^Starting/d
41764/^Entering/d
41765/^Stack/d
41766/^Reading/d
41767/^Reducing/d
41768/^Shifting/d
41769/^state/d
41770/^Cleanup:/d
41771/^Error:/d
41772/^Next/d
41773/^Discarding/d
41774/ \$[0-9$]* = /d
41775/^yydestructor:/d' stderr >at-stderr
41776mv at-stderr stderr
41777# 2. Create the reference error message.
41778cat >expout <<'_ATEOF'
417791.2: syntax error, unexpected number
41780_ATEOF
41781
41782# 3. If locations are not used, remove them.
41783
41784# 4. If error-verbose is not used, strip the`, unexpected....' part.
41785
41786# 5. Check
41787$at_traceoff
41788echo "calc.at:601: cat stderr"
41789echo calc.at:601 >$at_check_line_file
41790( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
41791at_status=$?
41792grep '^ *+' $at_stder1 >&2
41793grep -v '^ *+' $at_stder1 >$at_stderr
41794at_failed=false
41795$at_diff $at_devnull $at_stderr || at_failed=:
41796$at_diff expout $at_stdout || at_failed=:
41797case $at_status in
41798   77) echo 77 > $at_status_file
41799            exit 77;;
41800   0) ;;
41801   *) echo "calc.at:601: exit code was $at_status, expected 0"
41802      at_failed=:;;
41803esac
41804if $at_failed; then
41805
41806  echo 1 > $at_status_file
41807  exit 1
41808fi
41809
41810$at_traceon
41811
41812
41813cat >input <<'_ATEOF'
418141//2
41815_ATEOF
41816
41817$at_traceoff
41818echo "calc.at:601: \$PREPARSER ./calc input"
41819echo calc.at:601 >$at_check_line_file
41820( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
41821at_status=$?
41822grep '^ *+' $at_stder1 >&2
41823grep -v '^ *+' $at_stder1 >$at_stderr
41824at_failed=false
41825echo stderr:; tee stderr <$at_stderr
41826$at_diff $at_devnull $at_stdout || at_failed=:
41827case $at_status in
41828   77) echo 77 > $at_status_file
41829            exit 77;;
41830   1) ;;
41831   *) echo "calc.at:601: exit code was $at_status, expected 1"
41832      at_failed=:;;
41833esac
41834if $at_failed; then
41835
41836  echo 1 > $at_status_file
41837  exit 1
41838fi
41839
41840$at_traceon
41841
41842
41843# Normalize the observed and expected error messages, depending upon the
41844# options.
41845# 1. Remove the traces from observed.
41846sed '/^Starting/d
41847/^Entering/d
41848/^Stack/d
41849/^Reading/d
41850/^Reducing/d
41851/^Shifting/d
41852/^state/d
41853/^Cleanup:/d
41854/^Error:/d
41855/^Next/d
41856/^Discarding/d
41857/ \$[0-9$]* = /d
41858/^yydestructor:/d' stderr >at-stderr
41859mv at-stderr stderr
41860# 2. Create the reference error message.
41861cat >expout <<'_ATEOF'
418621.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
41863_ATEOF
41864
41865# 3. If locations are not used, remove them.
41866
41867# 4. If error-verbose is not used, strip the`, unexpected....' part.
41868
41869# 5. Check
41870$at_traceoff
41871echo "calc.at:601: cat stderr"
41872echo calc.at:601 >$at_check_line_file
41873( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
41874at_status=$?
41875grep '^ *+' $at_stder1 >&2
41876grep -v '^ *+' $at_stder1 >$at_stderr
41877at_failed=false
41878$at_diff $at_devnull $at_stderr || at_failed=:
41879$at_diff expout $at_stdout || at_failed=:
41880case $at_status in
41881   77) echo 77 > $at_status_file
41882            exit 77;;
41883   0) ;;
41884   *) echo "calc.at:601: exit code was $at_status, expected 0"
41885      at_failed=:;;
41886esac
41887if $at_failed; then
41888
41889  echo 1 > $at_status_file
41890  exit 1
41891fi
41892
41893$at_traceon
41894
41895
41896cat >input <<'_ATEOF'
41897error
41898_ATEOF
41899
41900$at_traceoff
41901echo "calc.at:601: \$PREPARSER ./calc input"
41902echo calc.at:601 >$at_check_line_file
41903( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
41904at_status=$?
41905grep '^ *+' $at_stder1 >&2
41906grep -v '^ *+' $at_stder1 >$at_stderr
41907at_failed=false
41908echo stderr:; tee stderr <$at_stderr
41909$at_diff $at_devnull $at_stdout || at_failed=:
41910case $at_status in
41911   77) echo 77 > $at_status_file
41912            exit 77;;
41913   1) ;;
41914   *) echo "calc.at:601: exit code was $at_status, expected 1"
41915      at_failed=:;;
41916esac
41917if $at_failed; then
41918
41919  echo 1 > $at_status_file
41920  exit 1
41921fi
41922
41923$at_traceon
41924
41925
41926# Normalize the observed and expected error messages, depending upon the
41927# options.
41928# 1. Remove the traces from observed.
41929sed '/^Starting/d
41930/^Entering/d
41931/^Stack/d
41932/^Reading/d
41933/^Reducing/d
41934/^Shifting/d
41935/^state/d
41936/^Cleanup:/d
41937/^Error:/d
41938/^Next/d
41939/^Discarding/d
41940/ \$[0-9$]* = /d
41941/^yydestructor:/d' stderr >at-stderr
41942mv at-stderr stderr
41943# 2. Create the reference error message.
41944cat >expout <<'_ATEOF'
419451.0: syntax error, unexpected $undefined
41946_ATEOF
41947
41948# 3. If locations are not used, remove them.
41949
41950# 4. If error-verbose is not used, strip the`, unexpected....' part.
41951
41952# 5. Check
41953$at_traceoff
41954echo "calc.at:601: cat stderr"
41955echo calc.at:601 >$at_check_line_file
41956( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
41957at_status=$?
41958grep '^ *+' $at_stder1 >&2
41959grep -v '^ *+' $at_stder1 >$at_stderr
41960at_failed=false
41961$at_diff $at_devnull $at_stderr || at_failed=:
41962$at_diff expout $at_stdout || at_failed=:
41963case $at_status in
41964   77) echo 77 > $at_status_file
41965            exit 77;;
41966   0) ;;
41967   *) echo "calc.at:601: exit code was $at_status, expected 0"
41968      at_failed=:;;
41969esac
41970if $at_failed; then
41971
41972  echo 1 > $at_status_file
41973  exit 1
41974fi
41975
41976$at_traceon
41977
41978
41979cat >input <<'_ATEOF'
419801 = 2 = 3
41981_ATEOF
41982
41983$at_traceoff
41984echo "calc.at:601: \$PREPARSER ./calc input"
41985echo calc.at:601 >$at_check_line_file
41986( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
41987at_status=$?
41988grep '^ *+' $at_stder1 >&2
41989grep -v '^ *+' $at_stder1 >$at_stderr
41990at_failed=false
41991echo stderr:; tee stderr <$at_stderr
41992$at_diff $at_devnull $at_stdout || at_failed=:
41993case $at_status in
41994   77) echo 77 > $at_status_file
41995            exit 77;;
41996   1) ;;
41997   *) echo "calc.at:601: exit code was $at_status, expected 1"
41998      at_failed=:;;
41999esac
42000if $at_failed; then
42001
42002  echo 1 > $at_status_file
42003  exit 1
42004fi
42005
42006$at_traceon
42007
42008
42009# Normalize the observed and expected error messages, depending upon the
42010# options.
42011# 1. Remove the traces from observed.
42012sed '/^Starting/d
42013/^Entering/d
42014/^Stack/d
42015/^Reading/d
42016/^Reducing/d
42017/^Shifting/d
42018/^state/d
42019/^Cleanup:/d
42020/^Error:/d
42021/^Next/d
42022/^Discarding/d
42023/ \$[0-9$]* = /d
42024/^yydestructor:/d' stderr >at-stderr
42025mv at-stderr stderr
42026# 2. Create the reference error message.
42027cat >expout <<'_ATEOF'
420281.6: syntax error, unexpected '='
42029_ATEOF
42030
42031# 3. If locations are not used, remove them.
42032
42033# 4. If error-verbose is not used, strip the`, unexpected....' part.
42034
42035# 5. Check
42036$at_traceoff
42037echo "calc.at:601: cat stderr"
42038echo calc.at:601 >$at_check_line_file
42039( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
42040at_status=$?
42041grep '^ *+' $at_stder1 >&2
42042grep -v '^ *+' $at_stder1 >$at_stderr
42043at_failed=false
42044$at_diff $at_devnull $at_stderr || at_failed=:
42045$at_diff expout $at_stdout || at_failed=:
42046case $at_status in
42047   77) echo 77 > $at_status_file
42048            exit 77;;
42049   0) ;;
42050   *) echo "calc.at:601: exit code was $at_status, expected 0"
42051      at_failed=:;;
42052esac
42053if $at_failed; then
42054
42055  echo 1 > $at_status_file
42056  exit 1
42057fi
42058
42059$at_traceon
42060
42061
42062cat >input <<'_ATEOF'
42063
42064+1
42065_ATEOF
42066
42067$at_traceoff
42068echo "calc.at:601: \$PREPARSER ./calc input"
42069echo calc.at:601 >$at_check_line_file
42070( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
42071at_status=$?
42072grep '^ *+' $at_stder1 >&2
42073grep -v '^ *+' $at_stder1 >$at_stderr
42074at_failed=false
42075echo stderr:; tee stderr <$at_stderr
42076$at_diff $at_devnull $at_stdout || at_failed=:
42077case $at_status in
42078   77) echo 77 > $at_status_file
42079            exit 77;;
42080   1) ;;
42081   *) echo "calc.at:601: exit code was $at_status, expected 1"
42082      at_failed=:;;
42083esac
42084if $at_failed; then
42085
42086  echo 1 > $at_status_file
42087  exit 1
42088fi
42089
42090$at_traceon
42091
42092
42093# Normalize the observed and expected error messages, depending upon the
42094# options.
42095# 1. Remove the traces from observed.
42096sed '/^Starting/d
42097/^Entering/d
42098/^Stack/d
42099/^Reading/d
42100/^Reducing/d
42101/^Shifting/d
42102/^state/d
42103/^Cleanup:/d
42104/^Error:/d
42105/^Next/d
42106/^Discarding/d
42107/ \$[0-9$]* = /d
42108/^yydestructor:/d' stderr >at-stderr
42109mv at-stderr stderr
42110# 2. Create the reference error message.
42111cat >expout <<'_ATEOF'
421122.0: syntax error, unexpected '+'
42113_ATEOF
42114
42115# 3. If locations are not used, remove them.
42116
42117# 4. If error-verbose is not used, strip the`, unexpected....' part.
42118
42119# 5. Check
42120$at_traceoff
42121echo "calc.at:601: cat stderr"
42122echo calc.at:601 >$at_check_line_file
42123( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
42124at_status=$?
42125grep '^ *+' $at_stder1 >&2
42126grep -v '^ *+' $at_stder1 >$at_stderr
42127at_failed=false
42128$at_diff $at_devnull $at_stderr || at_failed=:
42129$at_diff expout $at_stdout || at_failed=:
42130case $at_status in
42131   77) echo 77 > $at_status_file
42132            exit 77;;
42133   0) ;;
42134   *) echo "calc.at:601: exit code was $at_status, expected 0"
42135      at_failed=:;;
42136esac
42137if $at_failed; then
42138
42139  echo 1 > $at_status_file
42140  exit 1
42141fi
42142
42143$at_traceon
42144
42145
42146# Exercise error messages with EOF: work on an empty file.
42147$at_traceoff
42148echo "calc.at:601: \$PREPARSER ./calc /dev/null"
42149echo calc.at:601 >$at_check_line_file
42150( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
42151at_status=$?
42152grep '^ *+' $at_stder1 >&2
42153grep -v '^ *+' $at_stder1 >$at_stderr
42154at_failed=false
42155echo stderr:; tee stderr <$at_stderr
42156$at_diff $at_devnull $at_stdout || at_failed=:
42157case $at_status in
42158   77) echo 77 > $at_status_file
42159            exit 77;;
42160   1) ;;
42161   *) echo "calc.at:601: exit code was $at_status, expected 1"
42162      at_failed=:;;
42163esac
42164if $at_failed; then
42165
42166  echo 1 > $at_status_file
42167  exit 1
42168fi
42169
42170$at_traceon
42171
42172
42173# Normalize the observed and expected error messages, depending upon the
42174# options.
42175# 1. Remove the traces from observed.
42176sed '/^Starting/d
42177/^Entering/d
42178/^Stack/d
42179/^Reading/d
42180/^Reducing/d
42181/^Shifting/d
42182/^state/d
42183/^Cleanup:/d
42184/^Error:/d
42185/^Next/d
42186/^Discarding/d
42187/ \$[0-9$]* = /d
42188/^yydestructor:/d' stderr >at-stderr
42189mv at-stderr stderr
42190# 2. Create the reference error message.
42191cat >expout <<'_ATEOF'
421921.0: syntax error, unexpected end of input
42193_ATEOF
42194
42195# 3. If locations are not used, remove them.
42196
42197# 4. If error-verbose is not used, strip the`, unexpected....' part.
42198
42199# 5. Check
42200$at_traceoff
42201echo "calc.at:601: cat stderr"
42202echo calc.at:601 >$at_check_line_file
42203( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
42204at_status=$?
42205grep '^ *+' $at_stder1 >&2
42206grep -v '^ *+' $at_stder1 >$at_stderr
42207at_failed=false
42208$at_diff $at_devnull $at_stderr || at_failed=:
42209$at_diff expout $at_stdout || at_failed=:
42210case $at_status in
42211   77) echo 77 > $at_status_file
42212            exit 77;;
42213   0) ;;
42214   *) echo "calc.at:601: exit code was $at_status, expected 0"
42215      at_failed=:;;
42216esac
42217if $at_failed; then
42218
42219  echo 1 > $at_status_file
42220  exit 1
42221fi
42222
42223$at_traceon
42224
42225
42226
42227# Exercise the error token: without it, we die at the first error,
42228# hence be sure to
42229#
42230# - have several errors which exercise different shift/discardings
42231#   - (): nothing to pop, nothing to discard
42232#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
42233#   - (* * *): nothing to pop, a lot to discard
42234#   - (1 + 2 * *): some to pop and discard
42235#
42236# - test the action associated to `error'
42237#
42238# - check the look-ahead that triggers an error is not discarded
42239#   when we enter error recovery.  Below, the look-ahead causing the
42240#   first error is ")", which is needed to recover from the error and
42241#   produce the "0" that triggers the "0 != 1" error.
42242#
42243cat >input <<'_ATEOF'
42244() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
42245_ATEOF
42246
42247$at_traceoff
42248echo "calc.at:601: \$PREPARSER ./calc input"
42249echo calc.at:601 >$at_check_line_file
42250( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
42251at_status=$?
42252grep '^ *+' $at_stder1 >&2
42253grep -v '^ *+' $at_stder1 >$at_stderr
42254at_failed=false
42255echo stderr:; tee stderr <$at_stderr
42256$at_diff $at_devnull $at_stdout || at_failed=:
42257case $at_status in
42258   77) echo 77 > $at_status_file
42259            exit 77;;
42260   0) ;;
42261   *) echo "calc.at:601: exit code was $at_status, expected 0"
42262      at_failed=:;;
42263esac
42264if $at_failed; then
42265
42266  echo 1 > $at_status_file
42267  exit 1
42268fi
42269
42270$at_traceon
42271
42272
42273# Normalize the observed and expected error messages, depending upon the
42274# options.
42275# 1. Remove the traces from observed.
42276sed '/^Starting/d
42277/^Entering/d
42278/^Stack/d
42279/^Reading/d
42280/^Reducing/d
42281/^Shifting/d
42282/^state/d
42283/^Cleanup:/d
42284/^Error:/d
42285/^Next/d
42286/^Discarding/d
42287/ \$[0-9$]* = /d
42288/^yydestructor:/d' stderr >at-stderr
42289mv at-stderr stderr
42290# 2. Create the reference error message.
42291cat >expout <<'_ATEOF'
422921.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
422931.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
422941.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
422951.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
42296calc: error: 4444 != 1
42297_ATEOF
42298
42299# 3. If locations are not used, remove them.
42300
42301# 4. If error-verbose is not used, strip the`, unexpected....' part.
42302
42303# 5. Check
42304$at_traceoff
42305echo "calc.at:601: cat stderr"
42306echo calc.at:601 >$at_check_line_file
42307( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
42308at_status=$?
42309grep '^ *+' $at_stder1 >&2
42310grep -v '^ *+' $at_stder1 >$at_stderr
42311at_failed=false
42312$at_diff $at_devnull $at_stderr || at_failed=:
42313$at_diff expout $at_stdout || at_failed=:
42314case $at_status in
42315   77) echo 77 > $at_status_file
42316            exit 77;;
42317   0) ;;
42318   *) echo "calc.at:601: exit code was $at_status, expected 0"
42319      at_failed=:;;
42320esac
42321if $at_failed; then
42322
42323  echo 1 > $at_status_file
42324  exit 1
42325fi
42326
42327$at_traceon
42328
42329
42330
42331# The same, but this time exercising explicitly triggered syntax errors.
42332# POSIX says the look-ahead causing the error should not be discarded.
42333cat >input <<'_ATEOF'
42334(!) + (0 0) = 1
42335_ATEOF
42336
42337$at_traceoff
42338echo "calc.at:601: \$PREPARSER ./calc input"
42339echo calc.at:601 >$at_check_line_file
42340( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
42341at_status=$?
42342grep '^ *+' $at_stder1 >&2
42343grep -v '^ *+' $at_stder1 >$at_stderr
42344at_failed=false
42345echo stderr:; tee stderr <$at_stderr
42346$at_diff $at_devnull $at_stdout || at_failed=:
42347case $at_status in
42348   77) echo 77 > $at_status_file
42349            exit 77;;
42350   0) ;;
42351   *) echo "calc.at:601: exit code was $at_status, expected 0"
42352      at_failed=:;;
42353esac
42354if $at_failed; then
42355
42356  echo 1 > $at_status_file
42357  exit 1
42358fi
42359
42360$at_traceon
42361
42362
42363# Normalize the observed and expected error messages, depending upon the
42364# options.
42365# 1. Remove the traces from observed.
42366sed '/^Starting/d
42367/^Entering/d
42368/^Stack/d
42369/^Reading/d
42370/^Reducing/d
42371/^Shifting/d
42372/^state/d
42373/^Cleanup:/d
42374/^Error:/d
42375/^Next/d
42376/^Discarding/d
42377/ \$[0-9$]* = /d
42378/^yydestructor:/d' stderr >at-stderr
42379mv at-stderr stderr
42380# 2. Create the reference error message.
42381cat >expout <<'_ATEOF'
423821.9: syntax error, unexpected number
42383calc: error: 2222 != 1
42384_ATEOF
42385
42386# 3. If locations are not used, remove them.
42387
42388# 4. If error-verbose is not used, strip the`, unexpected....' part.
42389
42390# 5. Check
42391$at_traceoff
42392echo "calc.at:601: cat stderr"
42393echo calc.at:601 >$at_check_line_file
42394( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
42395at_status=$?
42396grep '^ *+' $at_stder1 >&2
42397grep -v '^ *+' $at_stder1 >$at_stderr
42398at_failed=false
42399$at_diff $at_devnull $at_stderr || at_failed=:
42400$at_diff expout $at_stdout || at_failed=:
42401case $at_status in
42402   77) echo 77 > $at_status_file
42403            exit 77;;
42404   0) ;;
42405   *) echo "calc.at:601: exit code was $at_status, expected 0"
42406      at_failed=:;;
42407esac
42408if $at_failed; then
42409
42410  echo 1 > $at_status_file
42411  exit 1
42412fi
42413
42414$at_traceon
42415
42416
42417cat >input <<'_ATEOF'
42418(- *) + (0 0) = 1
42419_ATEOF
42420
42421$at_traceoff
42422echo "calc.at:601: \$PREPARSER ./calc input"
42423echo calc.at:601 >$at_check_line_file
42424( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
42425at_status=$?
42426grep '^ *+' $at_stder1 >&2
42427grep -v '^ *+' $at_stder1 >$at_stderr
42428at_failed=false
42429echo stderr:; tee stderr <$at_stderr
42430$at_diff $at_devnull $at_stdout || at_failed=:
42431case $at_status in
42432   77) echo 77 > $at_status_file
42433            exit 77;;
42434   0) ;;
42435   *) echo "calc.at:601: exit code was $at_status, expected 0"
42436      at_failed=:;;
42437esac
42438if $at_failed; then
42439
42440  echo 1 > $at_status_file
42441  exit 1
42442fi
42443
42444$at_traceon
42445
42446
42447# Normalize the observed and expected error messages, depending upon the
42448# options.
42449# 1. Remove the traces from observed.
42450sed '/^Starting/d
42451/^Entering/d
42452/^Stack/d
42453/^Reading/d
42454/^Reducing/d
42455/^Shifting/d
42456/^state/d
42457/^Cleanup:/d
42458/^Error:/d
42459/^Next/d
42460/^Discarding/d
42461/ \$[0-9$]* = /d
42462/^yydestructor:/d' stderr >at-stderr
42463mv at-stderr stderr
42464# 2. Create the reference error message.
42465cat >expout <<'_ATEOF'
424661.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
424671.11: syntax error, unexpected number
42468calc: error: 2222 != 1
42469_ATEOF
42470
42471# 3. If locations are not used, remove them.
42472
42473# 4. If error-verbose is not used, strip the`, unexpected....' part.
42474
42475# 5. Check
42476$at_traceoff
42477echo "calc.at:601: cat stderr"
42478echo calc.at:601 >$at_check_line_file
42479( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
42480at_status=$?
42481grep '^ *+' $at_stder1 >&2
42482grep -v '^ *+' $at_stder1 >$at_stderr
42483at_failed=false
42484$at_diff $at_devnull $at_stderr || at_failed=:
42485$at_diff expout $at_stdout || at_failed=:
42486case $at_status in
42487   77) echo 77 > $at_status_file
42488            exit 77;;
42489   0) ;;
42490   *) echo "calc.at:601: exit code was $at_status, expected 0"
42491      at_failed=:;;
42492esac
42493if $at_failed; then
42494
42495  echo 1 > $at_status_file
42496  exit 1
42497fi
42498
42499$at_traceon
42500
42501
42502
42503
42504
42505
42506
42507
42508
42509
42510
42511
42512
42513
42514
42515
42516
42517
42518
42519
42520
42521
42522
42523
42524      $at_traceoff
42525      $at_times_p && times >$at_times_file
42526    ) 5>&1 2>&1 | eval $at_tee_pipe
42527    at_status=`cat $at_status_file`
42528    ;;
42529
42530  96 ) # 96. calc.at:603: Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
42531    at_setup_line='calc.at:603'
42532    at_desc='Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc'
42533    $at_quiet $ECHO_N " 96: Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc$ECHO_C"
42534    at_xfail=no
42535    (
42536      echo "96. calc.at:603: testing ..."
42537      $at_traceon
42538
42539
42540
42541
42542
42543
42544
42545
42546# Using yacc.c?
42547
42548
42549
42550
42551
42552
42553
42554# yyerror receives the location if %location & %pure & (%glr or %parse-param).
42555
42556# yyerror always sees the locations (when activated), except if
42557# yacc & pure & !param.
42558
42559
42560# The interface is pure: either because %pure-parser, or because we
42561# are using the C++ parsers.
42562
42563
42564
42565
42566
42567
42568
42569
42570
42571
42572
42573
42574cat >calc.y <<'_ATEOF'
42575%{
42576#ifdef HAVE_CONFIG_H
42577# include <config.h>
42578  /* We don't need perfect functions for these tests. */
42579# undef malloc
42580# undef memcmp
42581# undef realloc
42582#endif
42583%}
42584
42585/* Infix notation calculator--calc */
42586%glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc
42587
42588%{
42589#include <stdio.h>
42590
42591#include <stdlib.h>
42592#include <string.h>
42593#if HAVE_UNISTD_H
42594# include <unistd.h>
42595#else
42596# undef alarm
42597# define alarm(seconds) /* empty */
42598#endif
42599#include <ctype.h>
42600#define USE(Var)
42601
42602/* Exercise pre-prologue dependency to %union.  */
42603typedef int semantic_value;
42604
42605static semantic_value global_result = 0;
42606static int global_count = 0;
42607%}
42608
42609/* Exercise %union. */
42610%union
42611{
42612  semantic_value ival;
42613};
42614
42615%{
42616static int power (int base, int exponent);
42617/* yyerror receives the location if:
42618   - %location & %pure & %glr
42619   - %location & %pure & %yacc & %parse-param. */
42620static void yyerror (YYLTYPE *llocp,
42621
42622                     const char *s
42623                     );
42624static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
42625static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp);
42626static void unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c);
42627%}
42628
42629
42630
42631/* Bison Declarations */
42632%token CALC_EOF 0 "end of input"
42633%token <ival> NUM "number"
42634%type  <ival> exp
42635
42636%nonassoc '=' /* comparison	       */
42637%left '-' '+'
42638%left '*' '/'
42639%left NEG     /* negation--unary minus */
42640%right '^'    /* exponentiation        */
42641
42642/* Grammar follows */
42643%%
42644input:
42645  line
42646| input line         {  }
42647;
42648
42649line:
42650  '\n'
42651| exp '\n'           { USE ($1); }
42652;
42653
42654exp:
42655  NUM                { $$ = $1;             }
42656| exp '=' exp
42657  {
42658    if ($1 != $3)
42659      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
42660    $$ = $1;
42661  }
42662| exp '+' exp        { $$ = $1 + $3;        }
42663| exp '-' exp        { $$ = $1 - $3;        }
42664| exp '*' exp        { $$ = $1 * $3;        }
42665| exp '/' exp        { $$ = $1 / $3;        }
42666| '-' exp  %prec NEG { $$ = -$2;            }
42667| exp '^' exp        { $$ = power ($1, $3); }
42668| '(' exp ')'        { $$ = $2;             }
42669| '(' error ')'      { $$ = 1111;           }
42670| '!'                { $$ = 0; YYERROR;     }
42671| '-' error          { $$ = 0; YYERROR;     }
42672;
42673%%
42674/* The input.  */
42675static FILE *input;
42676
42677static void
42678yyerror (YYLTYPE *llocp,
42679
42680         const char *s)
42681{
42682
42683
42684  fprintf (stderr, "%d.%d",
42685           (*llocp).first_line, (*llocp).first_column);
42686  if ((*llocp).first_line != (*llocp).last_line)
42687    fprintf (stderr, "-%d.%d",
42688	     (*llocp).last_line,  (*llocp).last_column - 1);
42689  else if ((*llocp).first_column != (*llocp).last_column - 1)
42690    fprintf (stderr, "-%d",
42691	     (*llocp).last_column - 1);
42692  fprintf (stderr, ": ");
42693  fprintf (stderr, "%s\n", s);
42694}
42695
42696
42697
42698static YYLTYPE last_yylloc;
42699
42700static int
42701get_char (YYSTYPE *lvalp, YYLTYPE *llocp)
42702{
42703  int res = getc (input);
42704  (void) lvalp;(void) llocp;
42705
42706  last_yylloc = (*llocp);
42707  if (res == '\n')
42708    {
42709      (*llocp).last_line++;
42710      (*llocp).last_column = 0;
42711    }
42712  else
42713    (*llocp).last_column++;
42714
42715  return res;
42716}
42717
42718
42719static void
42720unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c)
42721{
42722  (void) lvalp;(void) llocp;
42723
42724  /* Wrong when C == `\n'. */
42725  (*llocp) = last_yylloc;
42726
42727  ungetc (c, input);
42728}
42729
42730static int
42731read_signed_integer (YYSTYPE *lvalp, YYLTYPE *llocp)
42732{
42733  int c = get_char (lvalp, llocp);
42734  int sign = 1;
42735  int n = 0;
42736
42737  (void) lvalp;(void) llocp;
42738  if (c == '-')
42739    {
42740      c = get_char (lvalp, llocp);
42741      sign = -1;
42742    }
42743
42744  while (isdigit (c))
42745    {
42746      n = 10 * n + (c - '0');
42747      c = get_char (lvalp, llocp);
42748    }
42749
42750  unget_char (lvalp, llocp,  c);
42751
42752  return sign * n;
42753}
42754
42755
42756
42757/*---------------------------------------------------------------.
42758| Lexical analyzer returns an integer on the stack and the token |
42759| NUM, or the ASCII character read if not a number.  Skips all   |
42760| blanks and tabs, returns 0 for EOF.                            |
42761`---------------------------------------------------------------*/
42762
42763static int
42764yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
42765{
42766  static int init = 1;
42767  int c;
42768
42769  if (init)
42770    {
42771      init = 0;
42772
42773      (*llocp).last_column = 0;
42774      (*llocp).last_line = 1;
42775
42776    }
42777
42778
42779 (*llocp).first_column = (*llocp).last_column;
42780  (*llocp).first_line   = (*llocp).last_line;
42781
42782
42783  /* Skip white space.  */
42784  while ((c = get_char (lvalp, llocp)) == ' ' || c == '\t')
42785    {
42786     (*llocp).first_column = (*llocp).last_column;
42787      (*llocp).first_line   = (*llocp).last_line;
42788
42789    }
42790
42791  /* process numbers   */
42792  if (c == '.' || isdigit (c))
42793    {
42794      unget_char (lvalp, llocp,  c);
42795      (*lvalp).ival = read_signed_integer (lvalp, llocp);
42796      return NUM;
42797    }
42798
42799  /* Return end-of-file.  */
42800  if (c == EOF)
42801    return CALC_EOF;
42802
42803  /* Return single chars. */
42804  return c;
42805}
42806
42807static int
42808power (int base, int exponent)
42809{
42810  int res = 1;
42811  if (exponent < 0)
42812    exit (3);
42813  for (/* Niente */; exponent; --exponent)
42814    res *= base;
42815  return res;
42816}
42817
42818
42819int
42820main (int argc, const char **argv)
42821{
42822  semantic_value result = 0;
42823  int count = 0;
42824  int status;
42825
42826  /* This used to be alarm (10), but that isn't enough time for
42827     a July 1995 vintage DEC Alphastation 200 4/100 system,
42828     according to Nelson H. F. Beebe.  100 seconds is enough.  */
42829  alarm (100);
42830
42831  if (argc == 2)
42832    input = fopen (argv[1], "r");
42833  else
42834    input = stdin;
42835
42836  if (!input)
42837    {
42838      perror (argv[1]);
42839      return 3;
42840    }
42841
42842  yydebug = 1;
42843  status = yyparse ();
42844  if (global_result != result)
42845    abort ();
42846  if (global_count != count)
42847    abort ();
42848  return status;
42849}
42850_ATEOF
42851
42852
42853
42854
42855
42856$at_traceoff
42857echo "calc.at:603: bison -o calc.c calc.y"
42858echo calc.at:603 >$at_check_line_file
42859( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
42860at_status=$?
42861grep '^ *+' $at_stder1 >&2
42862grep -v '^ *+' $at_stder1 >$at_stderr
42863at_failed=false
42864$at_diff $at_devnull $at_stderr || at_failed=:
42865$at_diff $at_devnull $at_stdout || at_failed=:
42866case $at_status in
42867   77) echo 77 > $at_status_file
42868            exit 77;;
42869   0) ;;
42870   *) echo "calc.at:603: exit code was $at_status, expected 0"
42871      at_failed=:;;
42872esac
42873if $at_failed; then
42874
42875  echo 1 > $at_status_file
42876  exit 1
42877fi
42878
42879$at_traceon
42880
42881   $at_traceoff
42882echo "calc.at:603: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
42883echo calc.at:603 >$at_check_line_file
42884( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
42885at_status=$?
42886grep '^ *+' $at_stder1 >&2
42887grep -v '^ *+' $at_stder1 >$at_stderr
42888at_failed=false
42889echo stderr:; cat $at_stderr
42890echo stdout:; cat $at_stdout
42891case $at_status in
42892   77) echo 77 > $at_status_file
42893            exit 77;;
42894   0) ;;
42895   *) echo "calc.at:603: exit code was $at_status, expected 0"
42896      at_failed=:;;
42897esac
42898if $at_failed; then
42899
42900  echo 1 > $at_status_file
42901  exit 1
42902fi
42903
42904$at_traceon
42905
42906
42907# Test the priorities.
42908cat >input <<'_ATEOF'
429091 + 2 * 3 = 7
429101 + 2 * -3 = -5
42911
42912-1^2 = -1
42913(-1)^2 = 1
42914
42915---1 = -1
42916
429171 - 2 - 3 = -4
429181 - (2 - 3) = 2
42919
429202^2^3 = 256
42921(2^2)^3 = 64
42922_ATEOF
42923
42924$at_traceoff
42925echo "calc.at:603: \$PREPARSER ./calc input"
42926echo calc.at:603 >$at_check_line_file
42927( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
42928at_status=$?
42929grep '^ *+' $at_stder1 >&2
42930grep -v '^ *+' $at_stder1 >$at_stderr
42931at_failed=false
42932echo stderr:; tee stderr <$at_stderr
42933$at_diff $at_devnull $at_stdout || at_failed=:
42934case $at_status in
42935   77) echo 77 > $at_status_file
42936            exit 77;;
42937   0) ;;
42938   *) echo "calc.at:603: exit code was $at_status, expected 0"
42939      at_failed=:;;
42940esac
42941if $at_failed; then
42942
42943  echo 1 > $at_status_file
42944  exit 1
42945fi
42946
42947$at_traceon
42948
42949
42950
42951# Some syntax errors.
42952cat >input <<'_ATEOF'
429530 0
42954_ATEOF
42955
42956$at_traceoff
42957echo "calc.at:603: \$PREPARSER ./calc input"
42958echo calc.at:603 >$at_check_line_file
42959( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
42960at_status=$?
42961grep '^ *+' $at_stder1 >&2
42962grep -v '^ *+' $at_stder1 >$at_stderr
42963at_failed=false
42964echo stderr:; tee stderr <$at_stderr
42965$at_diff $at_devnull $at_stdout || at_failed=:
42966case $at_status in
42967   77) echo 77 > $at_status_file
42968            exit 77;;
42969   1) ;;
42970   *) echo "calc.at:603: exit code was $at_status, expected 1"
42971      at_failed=:;;
42972esac
42973if $at_failed; then
42974
42975  echo 1 > $at_status_file
42976  exit 1
42977fi
42978
42979$at_traceon
42980
42981
42982# Normalize the observed and expected error messages, depending upon the
42983# options.
42984# 1. Remove the traces from observed.
42985sed '/^Starting/d
42986/^Entering/d
42987/^Stack/d
42988/^Reading/d
42989/^Reducing/d
42990/^Shifting/d
42991/^state/d
42992/^Cleanup:/d
42993/^Error:/d
42994/^Next/d
42995/^Discarding/d
42996/ \$[0-9$]* = /d
42997/^yydestructor:/d' stderr >at-stderr
42998mv at-stderr stderr
42999# 2. Create the reference error message.
43000cat >expout <<'_ATEOF'
430011.2: syntax error, unexpected number
43002_ATEOF
43003
43004# 3. If locations are not used, remove them.
43005
43006# 4. If error-verbose is not used, strip the`, unexpected....' part.
43007
43008# 5. Check
43009$at_traceoff
43010echo "calc.at:603: cat stderr"
43011echo calc.at:603 >$at_check_line_file
43012( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
43013at_status=$?
43014grep '^ *+' $at_stder1 >&2
43015grep -v '^ *+' $at_stder1 >$at_stderr
43016at_failed=false
43017$at_diff $at_devnull $at_stderr || at_failed=:
43018$at_diff expout $at_stdout || at_failed=:
43019case $at_status in
43020   77) echo 77 > $at_status_file
43021            exit 77;;
43022   0) ;;
43023   *) echo "calc.at:603: exit code was $at_status, expected 0"
43024      at_failed=:;;
43025esac
43026if $at_failed; then
43027
43028  echo 1 > $at_status_file
43029  exit 1
43030fi
43031
43032$at_traceon
43033
43034
43035cat >input <<'_ATEOF'
430361//2
43037_ATEOF
43038
43039$at_traceoff
43040echo "calc.at:603: \$PREPARSER ./calc input"
43041echo calc.at:603 >$at_check_line_file
43042( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
43043at_status=$?
43044grep '^ *+' $at_stder1 >&2
43045grep -v '^ *+' $at_stder1 >$at_stderr
43046at_failed=false
43047echo stderr:; tee stderr <$at_stderr
43048$at_diff $at_devnull $at_stdout || at_failed=:
43049case $at_status in
43050   77) echo 77 > $at_status_file
43051            exit 77;;
43052   1) ;;
43053   *) echo "calc.at:603: exit code was $at_status, expected 1"
43054      at_failed=:;;
43055esac
43056if $at_failed; then
43057
43058  echo 1 > $at_status_file
43059  exit 1
43060fi
43061
43062$at_traceon
43063
43064
43065# Normalize the observed and expected error messages, depending upon the
43066# options.
43067# 1. Remove the traces from observed.
43068sed '/^Starting/d
43069/^Entering/d
43070/^Stack/d
43071/^Reading/d
43072/^Reducing/d
43073/^Shifting/d
43074/^state/d
43075/^Cleanup:/d
43076/^Error:/d
43077/^Next/d
43078/^Discarding/d
43079/ \$[0-9$]* = /d
43080/^yydestructor:/d' stderr >at-stderr
43081mv at-stderr stderr
43082# 2. Create the reference error message.
43083cat >expout <<'_ATEOF'
430841.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
43085_ATEOF
43086
43087# 3. If locations are not used, remove them.
43088
43089# 4. If error-verbose is not used, strip the`, unexpected....' part.
43090
43091# 5. Check
43092$at_traceoff
43093echo "calc.at:603: cat stderr"
43094echo calc.at:603 >$at_check_line_file
43095( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
43096at_status=$?
43097grep '^ *+' $at_stder1 >&2
43098grep -v '^ *+' $at_stder1 >$at_stderr
43099at_failed=false
43100$at_diff $at_devnull $at_stderr || at_failed=:
43101$at_diff expout $at_stdout || at_failed=:
43102case $at_status in
43103   77) echo 77 > $at_status_file
43104            exit 77;;
43105   0) ;;
43106   *) echo "calc.at:603: exit code was $at_status, expected 0"
43107      at_failed=:;;
43108esac
43109if $at_failed; then
43110
43111  echo 1 > $at_status_file
43112  exit 1
43113fi
43114
43115$at_traceon
43116
43117
43118cat >input <<'_ATEOF'
43119error
43120_ATEOF
43121
43122$at_traceoff
43123echo "calc.at:603: \$PREPARSER ./calc input"
43124echo calc.at:603 >$at_check_line_file
43125( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
43126at_status=$?
43127grep '^ *+' $at_stder1 >&2
43128grep -v '^ *+' $at_stder1 >$at_stderr
43129at_failed=false
43130echo stderr:; tee stderr <$at_stderr
43131$at_diff $at_devnull $at_stdout || at_failed=:
43132case $at_status in
43133   77) echo 77 > $at_status_file
43134            exit 77;;
43135   1) ;;
43136   *) echo "calc.at:603: exit code was $at_status, expected 1"
43137      at_failed=:;;
43138esac
43139if $at_failed; then
43140
43141  echo 1 > $at_status_file
43142  exit 1
43143fi
43144
43145$at_traceon
43146
43147
43148# Normalize the observed and expected error messages, depending upon the
43149# options.
43150# 1. Remove the traces from observed.
43151sed '/^Starting/d
43152/^Entering/d
43153/^Stack/d
43154/^Reading/d
43155/^Reducing/d
43156/^Shifting/d
43157/^state/d
43158/^Cleanup:/d
43159/^Error:/d
43160/^Next/d
43161/^Discarding/d
43162/ \$[0-9$]* = /d
43163/^yydestructor:/d' stderr >at-stderr
43164mv at-stderr stderr
43165# 2. Create the reference error message.
43166cat >expout <<'_ATEOF'
431671.0: syntax error, unexpected $undefined
43168_ATEOF
43169
43170# 3. If locations are not used, remove them.
43171
43172# 4. If error-verbose is not used, strip the`, unexpected....' part.
43173
43174# 5. Check
43175$at_traceoff
43176echo "calc.at:603: cat stderr"
43177echo calc.at:603 >$at_check_line_file
43178( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
43179at_status=$?
43180grep '^ *+' $at_stder1 >&2
43181grep -v '^ *+' $at_stder1 >$at_stderr
43182at_failed=false
43183$at_diff $at_devnull $at_stderr || at_failed=:
43184$at_diff expout $at_stdout || at_failed=:
43185case $at_status in
43186   77) echo 77 > $at_status_file
43187            exit 77;;
43188   0) ;;
43189   *) echo "calc.at:603: exit code was $at_status, expected 0"
43190      at_failed=:;;
43191esac
43192if $at_failed; then
43193
43194  echo 1 > $at_status_file
43195  exit 1
43196fi
43197
43198$at_traceon
43199
43200
43201cat >input <<'_ATEOF'
432021 = 2 = 3
43203_ATEOF
43204
43205$at_traceoff
43206echo "calc.at:603: \$PREPARSER ./calc input"
43207echo calc.at:603 >$at_check_line_file
43208( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
43209at_status=$?
43210grep '^ *+' $at_stder1 >&2
43211grep -v '^ *+' $at_stder1 >$at_stderr
43212at_failed=false
43213echo stderr:; tee stderr <$at_stderr
43214$at_diff $at_devnull $at_stdout || at_failed=:
43215case $at_status in
43216   77) echo 77 > $at_status_file
43217            exit 77;;
43218   1) ;;
43219   *) echo "calc.at:603: exit code was $at_status, expected 1"
43220      at_failed=:;;
43221esac
43222if $at_failed; then
43223
43224  echo 1 > $at_status_file
43225  exit 1
43226fi
43227
43228$at_traceon
43229
43230
43231# Normalize the observed and expected error messages, depending upon the
43232# options.
43233# 1. Remove the traces from observed.
43234sed '/^Starting/d
43235/^Entering/d
43236/^Stack/d
43237/^Reading/d
43238/^Reducing/d
43239/^Shifting/d
43240/^state/d
43241/^Cleanup:/d
43242/^Error:/d
43243/^Next/d
43244/^Discarding/d
43245/ \$[0-9$]* = /d
43246/^yydestructor:/d' stderr >at-stderr
43247mv at-stderr stderr
43248# 2. Create the reference error message.
43249cat >expout <<'_ATEOF'
432501.6: syntax error, unexpected '='
43251_ATEOF
43252
43253# 3. If locations are not used, remove them.
43254
43255# 4. If error-verbose is not used, strip the`, unexpected....' part.
43256
43257# 5. Check
43258$at_traceoff
43259echo "calc.at:603: cat stderr"
43260echo calc.at:603 >$at_check_line_file
43261( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
43262at_status=$?
43263grep '^ *+' $at_stder1 >&2
43264grep -v '^ *+' $at_stder1 >$at_stderr
43265at_failed=false
43266$at_diff $at_devnull $at_stderr || at_failed=:
43267$at_diff expout $at_stdout || at_failed=:
43268case $at_status in
43269   77) echo 77 > $at_status_file
43270            exit 77;;
43271   0) ;;
43272   *) echo "calc.at:603: exit code was $at_status, expected 0"
43273      at_failed=:;;
43274esac
43275if $at_failed; then
43276
43277  echo 1 > $at_status_file
43278  exit 1
43279fi
43280
43281$at_traceon
43282
43283
43284cat >input <<'_ATEOF'
43285
43286+1
43287_ATEOF
43288
43289$at_traceoff
43290echo "calc.at:603: \$PREPARSER ./calc input"
43291echo calc.at:603 >$at_check_line_file
43292( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
43293at_status=$?
43294grep '^ *+' $at_stder1 >&2
43295grep -v '^ *+' $at_stder1 >$at_stderr
43296at_failed=false
43297echo stderr:; tee stderr <$at_stderr
43298$at_diff $at_devnull $at_stdout || at_failed=:
43299case $at_status in
43300   77) echo 77 > $at_status_file
43301            exit 77;;
43302   1) ;;
43303   *) echo "calc.at:603: exit code was $at_status, expected 1"
43304      at_failed=:;;
43305esac
43306if $at_failed; then
43307
43308  echo 1 > $at_status_file
43309  exit 1
43310fi
43311
43312$at_traceon
43313
43314
43315# Normalize the observed and expected error messages, depending upon the
43316# options.
43317# 1. Remove the traces from observed.
43318sed '/^Starting/d
43319/^Entering/d
43320/^Stack/d
43321/^Reading/d
43322/^Reducing/d
43323/^Shifting/d
43324/^state/d
43325/^Cleanup:/d
43326/^Error:/d
43327/^Next/d
43328/^Discarding/d
43329/ \$[0-9$]* = /d
43330/^yydestructor:/d' stderr >at-stderr
43331mv at-stderr stderr
43332# 2. Create the reference error message.
43333cat >expout <<'_ATEOF'
433342.0: syntax error, unexpected '+'
43335_ATEOF
43336
43337# 3. If locations are not used, remove them.
43338
43339# 4. If error-verbose is not used, strip the`, unexpected....' part.
43340
43341# 5. Check
43342$at_traceoff
43343echo "calc.at:603: cat stderr"
43344echo calc.at:603 >$at_check_line_file
43345( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
43346at_status=$?
43347grep '^ *+' $at_stder1 >&2
43348grep -v '^ *+' $at_stder1 >$at_stderr
43349at_failed=false
43350$at_diff $at_devnull $at_stderr || at_failed=:
43351$at_diff expout $at_stdout || at_failed=:
43352case $at_status in
43353   77) echo 77 > $at_status_file
43354            exit 77;;
43355   0) ;;
43356   *) echo "calc.at:603: exit code was $at_status, expected 0"
43357      at_failed=:;;
43358esac
43359if $at_failed; then
43360
43361  echo 1 > $at_status_file
43362  exit 1
43363fi
43364
43365$at_traceon
43366
43367
43368# Exercise error messages with EOF: work on an empty file.
43369$at_traceoff
43370echo "calc.at:603: \$PREPARSER ./calc /dev/null"
43371echo calc.at:603 >$at_check_line_file
43372( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
43373at_status=$?
43374grep '^ *+' $at_stder1 >&2
43375grep -v '^ *+' $at_stder1 >$at_stderr
43376at_failed=false
43377echo stderr:; tee stderr <$at_stderr
43378$at_diff $at_devnull $at_stdout || at_failed=:
43379case $at_status in
43380   77) echo 77 > $at_status_file
43381            exit 77;;
43382   1) ;;
43383   *) echo "calc.at:603: exit code was $at_status, expected 1"
43384      at_failed=:;;
43385esac
43386if $at_failed; then
43387
43388  echo 1 > $at_status_file
43389  exit 1
43390fi
43391
43392$at_traceon
43393
43394
43395# Normalize the observed and expected error messages, depending upon the
43396# options.
43397# 1. Remove the traces from observed.
43398sed '/^Starting/d
43399/^Entering/d
43400/^Stack/d
43401/^Reading/d
43402/^Reducing/d
43403/^Shifting/d
43404/^state/d
43405/^Cleanup:/d
43406/^Error:/d
43407/^Next/d
43408/^Discarding/d
43409/ \$[0-9$]* = /d
43410/^yydestructor:/d' stderr >at-stderr
43411mv at-stderr stderr
43412# 2. Create the reference error message.
43413cat >expout <<'_ATEOF'
434141.0: syntax error, unexpected end of input
43415_ATEOF
43416
43417# 3. If locations are not used, remove them.
43418
43419# 4. If error-verbose is not used, strip the`, unexpected....' part.
43420
43421# 5. Check
43422$at_traceoff
43423echo "calc.at:603: cat stderr"
43424echo calc.at:603 >$at_check_line_file
43425( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
43426at_status=$?
43427grep '^ *+' $at_stder1 >&2
43428grep -v '^ *+' $at_stder1 >$at_stderr
43429at_failed=false
43430$at_diff $at_devnull $at_stderr || at_failed=:
43431$at_diff expout $at_stdout || at_failed=:
43432case $at_status in
43433   77) echo 77 > $at_status_file
43434            exit 77;;
43435   0) ;;
43436   *) echo "calc.at:603: exit code was $at_status, expected 0"
43437      at_failed=:;;
43438esac
43439if $at_failed; then
43440
43441  echo 1 > $at_status_file
43442  exit 1
43443fi
43444
43445$at_traceon
43446
43447
43448
43449# Exercise the error token: without it, we die at the first error,
43450# hence be sure to
43451#
43452# - have several errors which exercise different shift/discardings
43453#   - (): nothing to pop, nothing to discard
43454#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
43455#   - (* * *): nothing to pop, a lot to discard
43456#   - (1 + 2 * *): some to pop and discard
43457#
43458# - test the action associated to `error'
43459#
43460# - check the look-ahead that triggers an error is not discarded
43461#   when we enter error recovery.  Below, the look-ahead causing the
43462#   first error is ")", which is needed to recover from the error and
43463#   produce the "0" that triggers the "0 != 1" error.
43464#
43465cat >input <<'_ATEOF'
43466() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
43467_ATEOF
43468
43469$at_traceoff
43470echo "calc.at:603: \$PREPARSER ./calc input"
43471echo calc.at:603 >$at_check_line_file
43472( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
43473at_status=$?
43474grep '^ *+' $at_stder1 >&2
43475grep -v '^ *+' $at_stder1 >$at_stderr
43476at_failed=false
43477echo stderr:; tee stderr <$at_stderr
43478$at_diff $at_devnull $at_stdout || at_failed=:
43479case $at_status in
43480   77) echo 77 > $at_status_file
43481            exit 77;;
43482   0) ;;
43483   *) echo "calc.at:603: exit code was $at_status, expected 0"
43484      at_failed=:;;
43485esac
43486if $at_failed; then
43487
43488  echo 1 > $at_status_file
43489  exit 1
43490fi
43491
43492$at_traceon
43493
43494
43495# Normalize the observed and expected error messages, depending upon the
43496# options.
43497# 1. Remove the traces from observed.
43498sed '/^Starting/d
43499/^Entering/d
43500/^Stack/d
43501/^Reading/d
43502/^Reducing/d
43503/^Shifting/d
43504/^state/d
43505/^Cleanup:/d
43506/^Error:/d
43507/^Next/d
43508/^Discarding/d
43509/ \$[0-9$]* = /d
43510/^yydestructor:/d' stderr >at-stderr
43511mv at-stderr stderr
43512# 2. Create the reference error message.
43513cat >expout <<'_ATEOF'
435141.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
435151.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
435161.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
435171.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
43518calc: error: 4444 != 1
43519_ATEOF
43520
43521# 3. If locations are not used, remove them.
43522
43523# 4. If error-verbose is not used, strip the`, unexpected....' part.
43524
43525# 5. Check
43526$at_traceoff
43527echo "calc.at:603: cat stderr"
43528echo calc.at:603 >$at_check_line_file
43529( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
43530at_status=$?
43531grep '^ *+' $at_stder1 >&2
43532grep -v '^ *+' $at_stder1 >$at_stderr
43533at_failed=false
43534$at_diff $at_devnull $at_stderr || at_failed=:
43535$at_diff expout $at_stdout || at_failed=:
43536case $at_status in
43537   77) echo 77 > $at_status_file
43538            exit 77;;
43539   0) ;;
43540   *) echo "calc.at:603: exit code was $at_status, expected 0"
43541      at_failed=:;;
43542esac
43543if $at_failed; then
43544
43545  echo 1 > $at_status_file
43546  exit 1
43547fi
43548
43549$at_traceon
43550
43551
43552
43553# The same, but this time exercising explicitly triggered syntax errors.
43554# POSIX says the look-ahead causing the error should not be discarded.
43555cat >input <<'_ATEOF'
43556(!) + (0 0) = 1
43557_ATEOF
43558
43559$at_traceoff
43560echo "calc.at:603: \$PREPARSER ./calc input"
43561echo calc.at:603 >$at_check_line_file
43562( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
43563at_status=$?
43564grep '^ *+' $at_stder1 >&2
43565grep -v '^ *+' $at_stder1 >$at_stderr
43566at_failed=false
43567echo stderr:; tee stderr <$at_stderr
43568$at_diff $at_devnull $at_stdout || at_failed=:
43569case $at_status in
43570   77) echo 77 > $at_status_file
43571            exit 77;;
43572   0) ;;
43573   *) echo "calc.at:603: exit code was $at_status, expected 0"
43574      at_failed=:;;
43575esac
43576if $at_failed; then
43577
43578  echo 1 > $at_status_file
43579  exit 1
43580fi
43581
43582$at_traceon
43583
43584
43585# Normalize the observed and expected error messages, depending upon the
43586# options.
43587# 1. Remove the traces from observed.
43588sed '/^Starting/d
43589/^Entering/d
43590/^Stack/d
43591/^Reading/d
43592/^Reducing/d
43593/^Shifting/d
43594/^state/d
43595/^Cleanup:/d
43596/^Error:/d
43597/^Next/d
43598/^Discarding/d
43599/ \$[0-9$]* = /d
43600/^yydestructor:/d' stderr >at-stderr
43601mv at-stderr stderr
43602# 2. Create the reference error message.
43603cat >expout <<'_ATEOF'
436041.9: syntax error, unexpected number
43605calc: error: 2222 != 1
43606_ATEOF
43607
43608# 3. If locations are not used, remove them.
43609
43610# 4. If error-verbose is not used, strip the`, unexpected....' part.
43611
43612# 5. Check
43613$at_traceoff
43614echo "calc.at:603: cat stderr"
43615echo calc.at:603 >$at_check_line_file
43616( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
43617at_status=$?
43618grep '^ *+' $at_stder1 >&2
43619grep -v '^ *+' $at_stder1 >$at_stderr
43620at_failed=false
43621$at_diff $at_devnull $at_stderr || at_failed=:
43622$at_diff expout $at_stdout || at_failed=:
43623case $at_status in
43624   77) echo 77 > $at_status_file
43625            exit 77;;
43626   0) ;;
43627   *) echo "calc.at:603: exit code was $at_status, expected 0"
43628      at_failed=:;;
43629esac
43630if $at_failed; then
43631
43632  echo 1 > $at_status_file
43633  exit 1
43634fi
43635
43636$at_traceon
43637
43638
43639cat >input <<'_ATEOF'
43640(- *) + (0 0) = 1
43641_ATEOF
43642
43643$at_traceoff
43644echo "calc.at:603: \$PREPARSER ./calc input"
43645echo calc.at:603 >$at_check_line_file
43646( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
43647at_status=$?
43648grep '^ *+' $at_stder1 >&2
43649grep -v '^ *+' $at_stder1 >$at_stderr
43650at_failed=false
43651echo stderr:; tee stderr <$at_stderr
43652$at_diff $at_devnull $at_stdout || at_failed=:
43653case $at_status in
43654   77) echo 77 > $at_status_file
43655            exit 77;;
43656   0) ;;
43657   *) echo "calc.at:603: exit code was $at_status, expected 0"
43658      at_failed=:;;
43659esac
43660if $at_failed; then
43661
43662  echo 1 > $at_status_file
43663  exit 1
43664fi
43665
43666$at_traceon
43667
43668
43669# Normalize the observed and expected error messages, depending upon the
43670# options.
43671# 1. Remove the traces from observed.
43672sed '/^Starting/d
43673/^Entering/d
43674/^Stack/d
43675/^Reading/d
43676/^Reducing/d
43677/^Shifting/d
43678/^state/d
43679/^Cleanup:/d
43680/^Error:/d
43681/^Next/d
43682/^Discarding/d
43683/ \$[0-9$]* = /d
43684/^yydestructor:/d' stderr >at-stderr
43685mv at-stderr stderr
43686# 2. Create the reference error message.
43687cat >expout <<'_ATEOF'
436881.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
436891.11: syntax error, unexpected number
43690calc: error: 2222 != 1
43691_ATEOF
43692
43693# 3. If locations are not used, remove them.
43694
43695# 4. If error-verbose is not used, strip the`, unexpected....' part.
43696
43697# 5. Check
43698$at_traceoff
43699echo "calc.at:603: cat stderr"
43700echo calc.at:603 >$at_check_line_file
43701( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
43702at_status=$?
43703grep '^ *+' $at_stder1 >&2
43704grep -v '^ *+' $at_stder1 >$at_stderr
43705at_failed=false
43706$at_diff $at_devnull $at_stderr || at_failed=:
43707$at_diff expout $at_stdout || at_failed=:
43708case $at_status in
43709   77) echo 77 > $at_status_file
43710            exit 77;;
43711   0) ;;
43712   *) echo "calc.at:603: exit code was $at_status, expected 0"
43713      at_failed=:;;
43714esac
43715if $at_failed; then
43716
43717  echo 1 > $at_status_file
43718  exit 1
43719fi
43720
43721$at_traceon
43722
43723
43724
43725
43726
43727
43728
43729
43730
43731
43732
43733
43734
43735
43736
43737
43738
43739
43740
43741
43742
43743
43744
43745
43746      $at_traceoff
43747      $at_times_p && times >$at_times_file
43748    ) 5>&1 2>&1 | eval $at_tee_pipe
43749    at_status=`cat $at_status_file`
43750    ;;
43751
43752  97 ) # 97. calc.at:605: Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}
43753    at_setup_line='calc.at:605'
43754    at_desc='Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}'
43755    $at_quiet $ECHO_N " 97: Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}$ECHO_C"
43756    at_xfail=no
43757    (
43758      echo "97. calc.at:605: testing ..."
43759      $at_traceon
43760
43761
43762
43763
43764
43765
43766
43767
43768# Using yacc.c?
43769
43770
43771
43772
43773
43774
43775
43776# yyerror receives the location if %location & %pure & (%glr or %parse-param).
43777
43778# yyerror always sees the locations (when activated), except if
43779# yacc & pure & !param.
43780
43781
43782# The interface is pure: either because %pure-parser, or because we
43783# are using the C++ parsers.
43784
43785
43786
43787
43788
43789
43790
43791
43792
43793
43794
43795
43796cat >calc.y <<'_ATEOF'
43797%{
43798#ifdef HAVE_CONFIG_H
43799# include <config.h>
43800  /* We don't need perfect functions for these tests. */
43801# undef malloc
43802# undef memcmp
43803# undef realloc
43804#endif
43805%}
43806
43807/* Infix notation calculator--calc */
43808%glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}
43809
43810%{
43811#include <stdio.h>
43812
43813#include <stdlib.h>
43814#include <string.h>
43815#if HAVE_UNISTD_H
43816# include <unistd.h>
43817#else
43818# undef alarm
43819# define alarm(seconds) /* empty */
43820#endif
43821#include <ctype.h>
43822#define USE(Var)
43823
43824/* Exercise pre-prologue dependency to %union.  */
43825typedef int semantic_value;
43826
43827static semantic_value global_result = 0;
43828static int global_count = 0;
43829%}
43830
43831/* Exercise %union. */
43832%union
43833{
43834  semantic_value ival;
43835};
43836
43837%{
43838static int power (int base, int exponent);
43839/* yyerror receives the location if:
43840   - %location & %pure & %glr
43841   - %location & %pure & %yacc & %parse-param. */
43842static void yyerror (YYLTYPE *llocp,
43843                     semantic_value *result, int *count,
43844                     const char *s
43845                     );
43846static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
43847static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp);
43848static void unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c);
43849%}
43850
43851
43852
43853/* Bison Declarations */
43854%token CALC_EOF 0 "end of input"
43855%token <ival> NUM "number"
43856%type  <ival> exp
43857
43858%nonassoc '=' /* comparison	       */
43859%left '-' '+'
43860%left '*' '/'
43861%left NEG     /* negation--unary minus */
43862%right '^'    /* exponentiation        */
43863
43864/* Grammar follows */
43865%%
43866input:
43867  line
43868| input line         { ++*count; ++global_count; }
43869;
43870
43871line:
43872  '\n'
43873| exp '\n'           { *result = global_result = $1; }
43874;
43875
43876exp:
43877  NUM                { $$ = $1;             }
43878| exp '=' exp
43879  {
43880    if ($1 != $3)
43881      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
43882    $$ = $1;
43883  }
43884| exp '+' exp        { $$ = $1 + $3;        }
43885| exp '-' exp        { $$ = $1 - $3;        }
43886| exp '*' exp        { $$ = $1 * $3;        }
43887| exp '/' exp        { $$ = $1 / $3;        }
43888| '-' exp  %prec NEG { $$ = -$2;            }
43889| exp '^' exp        { $$ = power ($1, $3); }
43890| '(' exp ')'        { $$ = $2;             }
43891| '(' error ')'      { $$ = 1111;           }
43892| '!'                { $$ = 0; YYERROR;     }
43893| '-' error          { $$ = 0; YYERROR;     }
43894;
43895%%
43896/* The input.  */
43897static FILE *input;
43898
43899static void
43900yyerror (YYLTYPE *llocp,
43901         semantic_value *result, int *count,
43902         const char *s)
43903{
43904(void) result; (void) count;
43905
43906  fprintf (stderr, "%d.%d",
43907           (*llocp).first_line, (*llocp).first_column);
43908  if ((*llocp).first_line != (*llocp).last_line)
43909    fprintf (stderr, "-%d.%d",
43910	     (*llocp).last_line,  (*llocp).last_column - 1);
43911  else if ((*llocp).first_column != (*llocp).last_column - 1)
43912    fprintf (stderr, "-%d",
43913	     (*llocp).last_column - 1);
43914  fprintf (stderr, ": ");
43915  fprintf (stderr, "%s\n", s);
43916}
43917
43918
43919
43920static YYLTYPE last_yylloc;
43921
43922static int
43923get_char (YYSTYPE *lvalp, YYLTYPE *llocp)
43924{
43925  int res = getc (input);
43926  (void) lvalp;(void) llocp;
43927
43928  last_yylloc = (*llocp);
43929  if (res == '\n')
43930    {
43931      (*llocp).last_line++;
43932      (*llocp).last_column = 0;
43933    }
43934  else
43935    (*llocp).last_column++;
43936
43937  return res;
43938}
43939
43940
43941static void
43942unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c)
43943{
43944  (void) lvalp;(void) llocp;
43945
43946  /* Wrong when C == `\n'. */
43947  (*llocp) = last_yylloc;
43948
43949  ungetc (c, input);
43950}
43951
43952static int
43953read_signed_integer (YYSTYPE *lvalp, YYLTYPE *llocp)
43954{
43955  int c = get_char (lvalp, llocp);
43956  int sign = 1;
43957  int n = 0;
43958
43959  (void) lvalp;(void) llocp;
43960  if (c == '-')
43961    {
43962      c = get_char (lvalp, llocp);
43963      sign = -1;
43964    }
43965
43966  while (isdigit (c))
43967    {
43968      n = 10 * n + (c - '0');
43969      c = get_char (lvalp, llocp);
43970    }
43971
43972  unget_char (lvalp, llocp,  c);
43973
43974  return sign * n;
43975}
43976
43977
43978
43979/*---------------------------------------------------------------.
43980| Lexical analyzer returns an integer on the stack and the token |
43981| NUM, or the ASCII character read if not a number.  Skips all   |
43982| blanks and tabs, returns 0 for EOF.                            |
43983`---------------------------------------------------------------*/
43984
43985static int
43986yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
43987{
43988  static int init = 1;
43989  int c;
43990
43991  if (init)
43992    {
43993      init = 0;
43994
43995      (*llocp).last_column = 0;
43996      (*llocp).last_line = 1;
43997
43998    }
43999
44000
44001 (*llocp).first_column = (*llocp).last_column;
44002  (*llocp).first_line   = (*llocp).last_line;
44003
44004
44005  /* Skip white space.  */
44006  while ((c = get_char (lvalp, llocp)) == ' ' || c == '\t')
44007    {
44008     (*llocp).first_column = (*llocp).last_column;
44009      (*llocp).first_line   = (*llocp).last_line;
44010
44011    }
44012
44013  /* process numbers   */
44014  if (c == '.' || isdigit (c))
44015    {
44016      unget_char (lvalp, llocp,  c);
44017      (*lvalp).ival = read_signed_integer (lvalp, llocp);
44018      return NUM;
44019    }
44020
44021  /* Return end-of-file.  */
44022  if (c == EOF)
44023    return CALC_EOF;
44024
44025  /* Return single chars. */
44026  return c;
44027}
44028
44029static int
44030power (int base, int exponent)
44031{
44032  int res = 1;
44033  if (exponent < 0)
44034    exit (3);
44035  for (/* Niente */; exponent; --exponent)
44036    res *= base;
44037  return res;
44038}
44039
44040
44041int
44042main (int argc, const char **argv)
44043{
44044  semantic_value result = 0;
44045  int count = 0;
44046  int status;
44047
44048  /* This used to be alarm (10), but that isn't enough time for
44049     a July 1995 vintage DEC Alphastation 200 4/100 system,
44050     according to Nelson H. F. Beebe.  100 seconds is enough.  */
44051  alarm (100);
44052
44053  if (argc == 2)
44054    input = fopen (argv[1], "r");
44055  else
44056    input = stdin;
44057
44058  if (!input)
44059    {
44060      perror (argv[1]);
44061      return 3;
44062    }
44063
44064  yydebug = 1;
44065  status = yyparse (&result, &count);
44066  if (global_result != result)
44067    abort ();
44068  if (global_count != count)
44069    abort ();
44070  return status;
44071}
44072_ATEOF
44073
44074
44075
44076
44077
44078$at_traceoff
44079echo "calc.at:605: bison -o calc.c calc.y"
44080echo calc.at:605 >$at_check_line_file
44081( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1
44082at_status=$?
44083grep '^ *+' $at_stder1 >&2
44084grep -v '^ *+' $at_stder1 >$at_stderr
44085at_failed=false
44086$at_diff $at_devnull $at_stderr || at_failed=:
44087$at_diff $at_devnull $at_stdout || at_failed=:
44088case $at_status in
44089   77) echo 77 > $at_status_file
44090            exit 77;;
44091   0) ;;
44092   *) echo "calc.at:605: exit code was $at_status, expected 0"
44093      at_failed=:;;
44094esac
44095if $at_failed; then
44096
44097  echo 1 > $at_status_file
44098  exit 1
44099fi
44100
44101$at_traceon
44102
44103   $at_traceoff
44104echo "calc.at:605: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS"
44105echo calc.at:605 >$at_check_line_file
44106( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1
44107at_status=$?
44108grep '^ *+' $at_stder1 >&2
44109grep -v '^ *+' $at_stder1 >$at_stderr
44110at_failed=false
44111echo stderr:; cat $at_stderr
44112echo stdout:; cat $at_stdout
44113case $at_status in
44114   77) echo 77 > $at_status_file
44115            exit 77;;
44116   0) ;;
44117   *) echo "calc.at:605: exit code was $at_status, expected 0"
44118      at_failed=:;;
44119esac
44120if $at_failed; then
44121
44122  echo 1 > $at_status_file
44123  exit 1
44124fi
44125
44126$at_traceon
44127
44128
44129# Test the priorities.
44130cat >input <<'_ATEOF'
441311 + 2 * 3 = 7
441321 + 2 * -3 = -5
44133
44134-1^2 = -1
44135(-1)^2 = 1
44136
44137---1 = -1
44138
441391 - 2 - 3 = -4
441401 - (2 - 3) = 2
44141
441422^2^3 = 256
44143(2^2)^3 = 64
44144_ATEOF
44145
44146$at_traceoff
44147echo "calc.at:605: \$PREPARSER ./calc input"
44148echo calc.at:605 >$at_check_line_file
44149( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
44150at_status=$?
44151grep '^ *+' $at_stder1 >&2
44152grep -v '^ *+' $at_stder1 >$at_stderr
44153at_failed=false
44154echo stderr:; tee stderr <$at_stderr
44155$at_diff $at_devnull $at_stdout || at_failed=:
44156case $at_status in
44157   77) echo 77 > $at_status_file
44158            exit 77;;
44159   0) ;;
44160   *) echo "calc.at:605: exit code was $at_status, expected 0"
44161      at_failed=:;;
44162esac
44163if $at_failed; then
44164
44165  echo 1 > $at_status_file
44166  exit 1
44167fi
44168
44169$at_traceon
44170
44171
44172
44173# Some syntax errors.
44174cat >input <<'_ATEOF'
441750 0
44176_ATEOF
44177
44178$at_traceoff
44179echo "calc.at:605: \$PREPARSER ./calc input"
44180echo calc.at:605 >$at_check_line_file
44181( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
44182at_status=$?
44183grep '^ *+' $at_stder1 >&2
44184grep -v '^ *+' $at_stder1 >$at_stderr
44185at_failed=false
44186echo stderr:; tee stderr <$at_stderr
44187$at_diff $at_devnull $at_stdout || at_failed=:
44188case $at_status in
44189   77) echo 77 > $at_status_file
44190            exit 77;;
44191   1) ;;
44192   *) echo "calc.at:605: exit code was $at_status, expected 1"
44193      at_failed=:;;
44194esac
44195if $at_failed; then
44196
44197  echo 1 > $at_status_file
44198  exit 1
44199fi
44200
44201$at_traceon
44202
44203
44204# Normalize the observed and expected error messages, depending upon the
44205# options.
44206# 1. Remove the traces from observed.
44207sed '/^Starting/d
44208/^Entering/d
44209/^Stack/d
44210/^Reading/d
44211/^Reducing/d
44212/^Shifting/d
44213/^state/d
44214/^Cleanup:/d
44215/^Error:/d
44216/^Next/d
44217/^Discarding/d
44218/ \$[0-9$]* = /d
44219/^yydestructor:/d' stderr >at-stderr
44220mv at-stderr stderr
44221# 2. Create the reference error message.
44222cat >expout <<'_ATEOF'
442231.2: syntax error, unexpected number
44224_ATEOF
44225
44226# 3. If locations are not used, remove them.
44227
44228# 4. If error-verbose is not used, strip the`, unexpected....' part.
44229
44230# 5. Check
44231$at_traceoff
44232echo "calc.at:605: cat stderr"
44233echo calc.at:605 >$at_check_line_file
44234( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
44235at_status=$?
44236grep '^ *+' $at_stder1 >&2
44237grep -v '^ *+' $at_stder1 >$at_stderr
44238at_failed=false
44239$at_diff $at_devnull $at_stderr || at_failed=:
44240$at_diff expout $at_stdout || at_failed=:
44241case $at_status in
44242   77) echo 77 > $at_status_file
44243            exit 77;;
44244   0) ;;
44245   *) echo "calc.at:605: exit code was $at_status, expected 0"
44246      at_failed=:;;
44247esac
44248if $at_failed; then
44249
44250  echo 1 > $at_status_file
44251  exit 1
44252fi
44253
44254$at_traceon
44255
44256
44257cat >input <<'_ATEOF'
442581//2
44259_ATEOF
44260
44261$at_traceoff
44262echo "calc.at:605: \$PREPARSER ./calc input"
44263echo calc.at:605 >$at_check_line_file
44264( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
44265at_status=$?
44266grep '^ *+' $at_stder1 >&2
44267grep -v '^ *+' $at_stder1 >$at_stderr
44268at_failed=false
44269echo stderr:; tee stderr <$at_stderr
44270$at_diff $at_devnull $at_stdout || at_failed=:
44271case $at_status in
44272   77) echo 77 > $at_status_file
44273            exit 77;;
44274   1) ;;
44275   *) echo "calc.at:605: exit code was $at_status, expected 1"
44276      at_failed=:;;
44277esac
44278if $at_failed; then
44279
44280  echo 1 > $at_status_file
44281  exit 1
44282fi
44283
44284$at_traceon
44285
44286
44287# Normalize the observed and expected error messages, depending upon the
44288# options.
44289# 1. Remove the traces from observed.
44290sed '/^Starting/d
44291/^Entering/d
44292/^Stack/d
44293/^Reading/d
44294/^Reducing/d
44295/^Shifting/d
44296/^state/d
44297/^Cleanup:/d
44298/^Error:/d
44299/^Next/d
44300/^Discarding/d
44301/ \$[0-9$]* = /d
44302/^yydestructor:/d' stderr >at-stderr
44303mv at-stderr stderr
44304# 2. Create the reference error message.
44305cat >expout <<'_ATEOF'
443061.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
44307_ATEOF
44308
44309# 3. If locations are not used, remove them.
44310
44311# 4. If error-verbose is not used, strip the`, unexpected....' part.
44312
44313# 5. Check
44314$at_traceoff
44315echo "calc.at:605: cat stderr"
44316echo calc.at:605 >$at_check_line_file
44317( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
44318at_status=$?
44319grep '^ *+' $at_stder1 >&2
44320grep -v '^ *+' $at_stder1 >$at_stderr
44321at_failed=false
44322$at_diff $at_devnull $at_stderr || at_failed=:
44323$at_diff expout $at_stdout || at_failed=:
44324case $at_status in
44325   77) echo 77 > $at_status_file
44326            exit 77;;
44327   0) ;;
44328   *) echo "calc.at:605: exit code was $at_status, expected 0"
44329      at_failed=:;;
44330esac
44331if $at_failed; then
44332
44333  echo 1 > $at_status_file
44334  exit 1
44335fi
44336
44337$at_traceon
44338
44339
44340cat >input <<'_ATEOF'
44341error
44342_ATEOF
44343
44344$at_traceoff
44345echo "calc.at:605: \$PREPARSER ./calc input"
44346echo calc.at:605 >$at_check_line_file
44347( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
44348at_status=$?
44349grep '^ *+' $at_stder1 >&2
44350grep -v '^ *+' $at_stder1 >$at_stderr
44351at_failed=false
44352echo stderr:; tee stderr <$at_stderr
44353$at_diff $at_devnull $at_stdout || at_failed=:
44354case $at_status in
44355   77) echo 77 > $at_status_file
44356            exit 77;;
44357   1) ;;
44358   *) echo "calc.at:605: exit code was $at_status, expected 1"
44359      at_failed=:;;
44360esac
44361if $at_failed; then
44362
44363  echo 1 > $at_status_file
44364  exit 1
44365fi
44366
44367$at_traceon
44368
44369
44370# Normalize the observed and expected error messages, depending upon the
44371# options.
44372# 1. Remove the traces from observed.
44373sed '/^Starting/d
44374/^Entering/d
44375/^Stack/d
44376/^Reading/d
44377/^Reducing/d
44378/^Shifting/d
44379/^state/d
44380/^Cleanup:/d
44381/^Error:/d
44382/^Next/d
44383/^Discarding/d
44384/ \$[0-9$]* = /d
44385/^yydestructor:/d' stderr >at-stderr
44386mv at-stderr stderr
44387# 2. Create the reference error message.
44388cat >expout <<'_ATEOF'
443891.0: syntax error, unexpected $undefined
44390_ATEOF
44391
44392# 3. If locations are not used, remove them.
44393
44394# 4. If error-verbose is not used, strip the`, unexpected....' part.
44395
44396# 5. Check
44397$at_traceoff
44398echo "calc.at:605: cat stderr"
44399echo calc.at:605 >$at_check_line_file
44400( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
44401at_status=$?
44402grep '^ *+' $at_stder1 >&2
44403grep -v '^ *+' $at_stder1 >$at_stderr
44404at_failed=false
44405$at_diff $at_devnull $at_stderr || at_failed=:
44406$at_diff expout $at_stdout || at_failed=:
44407case $at_status in
44408   77) echo 77 > $at_status_file
44409            exit 77;;
44410   0) ;;
44411   *) echo "calc.at:605: exit code was $at_status, expected 0"
44412      at_failed=:;;
44413esac
44414if $at_failed; then
44415
44416  echo 1 > $at_status_file
44417  exit 1
44418fi
44419
44420$at_traceon
44421
44422
44423cat >input <<'_ATEOF'
444241 = 2 = 3
44425_ATEOF
44426
44427$at_traceoff
44428echo "calc.at:605: \$PREPARSER ./calc input"
44429echo calc.at:605 >$at_check_line_file
44430( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
44431at_status=$?
44432grep '^ *+' $at_stder1 >&2
44433grep -v '^ *+' $at_stder1 >$at_stderr
44434at_failed=false
44435echo stderr:; tee stderr <$at_stderr
44436$at_diff $at_devnull $at_stdout || at_failed=:
44437case $at_status in
44438   77) echo 77 > $at_status_file
44439            exit 77;;
44440   1) ;;
44441   *) echo "calc.at:605: exit code was $at_status, expected 1"
44442      at_failed=:;;
44443esac
44444if $at_failed; then
44445
44446  echo 1 > $at_status_file
44447  exit 1
44448fi
44449
44450$at_traceon
44451
44452
44453# Normalize the observed and expected error messages, depending upon the
44454# options.
44455# 1. Remove the traces from observed.
44456sed '/^Starting/d
44457/^Entering/d
44458/^Stack/d
44459/^Reading/d
44460/^Reducing/d
44461/^Shifting/d
44462/^state/d
44463/^Cleanup:/d
44464/^Error:/d
44465/^Next/d
44466/^Discarding/d
44467/ \$[0-9$]* = /d
44468/^yydestructor:/d' stderr >at-stderr
44469mv at-stderr stderr
44470# 2. Create the reference error message.
44471cat >expout <<'_ATEOF'
444721.6: syntax error, unexpected '='
44473_ATEOF
44474
44475# 3. If locations are not used, remove them.
44476
44477# 4. If error-verbose is not used, strip the`, unexpected....' part.
44478
44479# 5. Check
44480$at_traceoff
44481echo "calc.at:605: cat stderr"
44482echo calc.at:605 >$at_check_line_file
44483( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
44484at_status=$?
44485grep '^ *+' $at_stder1 >&2
44486grep -v '^ *+' $at_stder1 >$at_stderr
44487at_failed=false
44488$at_diff $at_devnull $at_stderr || at_failed=:
44489$at_diff expout $at_stdout || at_failed=:
44490case $at_status in
44491   77) echo 77 > $at_status_file
44492            exit 77;;
44493   0) ;;
44494   *) echo "calc.at:605: exit code was $at_status, expected 0"
44495      at_failed=:;;
44496esac
44497if $at_failed; then
44498
44499  echo 1 > $at_status_file
44500  exit 1
44501fi
44502
44503$at_traceon
44504
44505
44506cat >input <<'_ATEOF'
44507
44508+1
44509_ATEOF
44510
44511$at_traceoff
44512echo "calc.at:605: \$PREPARSER ./calc input"
44513echo calc.at:605 >$at_check_line_file
44514( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
44515at_status=$?
44516grep '^ *+' $at_stder1 >&2
44517grep -v '^ *+' $at_stder1 >$at_stderr
44518at_failed=false
44519echo stderr:; tee stderr <$at_stderr
44520$at_diff $at_devnull $at_stdout || at_failed=:
44521case $at_status in
44522   77) echo 77 > $at_status_file
44523            exit 77;;
44524   1) ;;
44525   *) echo "calc.at:605: exit code was $at_status, expected 1"
44526      at_failed=:;;
44527esac
44528if $at_failed; then
44529
44530  echo 1 > $at_status_file
44531  exit 1
44532fi
44533
44534$at_traceon
44535
44536
44537# Normalize the observed and expected error messages, depending upon the
44538# options.
44539# 1. Remove the traces from observed.
44540sed '/^Starting/d
44541/^Entering/d
44542/^Stack/d
44543/^Reading/d
44544/^Reducing/d
44545/^Shifting/d
44546/^state/d
44547/^Cleanup:/d
44548/^Error:/d
44549/^Next/d
44550/^Discarding/d
44551/ \$[0-9$]* = /d
44552/^yydestructor:/d' stderr >at-stderr
44553mv at-stderr stderr
44554# 2. Create the reference error message.
44555cat >expout <<'_ATEOF'
445562.0: syntax error, unexpected '+'
44557_ATEOF
44558
44559# 3. If locations are not used, remove them.
44560
44561# 4. If error-verbose is not used, strip the`, unexpected....' part.
44562
44563# 5. Check
44564$at_traceoff
44565echo "calc.at:605: cat stderr"
44566echo calc.at:605 >$at_check_line_file
44567( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
44568at_status=$?
44569grep '^ *+' $at_stder1 >&2
44570grep -v '^ *+' $at_stder1 >$at_stderr
44571at_failed=false
44572$at_diff $at_devnull $at_stderr || at_failed=:
44573$at_diff expout $at_stdout || at_failed=:
44574case $at_status in
44575   77) echo 77 > $at_status_file
44576            exit 77;;
44577   0) ;;
44578   *) echo "calc.at:605: exit code was $at_status, expected 0"
44579      at_failed=:;;
44580esac
44581if $at_failed; then
44582
44583  echo 1 > $at_status_file
44584  exit 1
44585fi
44586
44587$at_traceon
44588
44589
44590# Exercise error messages with EOF: work on an empty file.
44591$at_traceoff
44592echo "calc.at:605: \$PREPARSER ./calc /dev/null"
44593echo calc.at:605 >$at_check_line_file
44594( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
44595at_status=$?
44596grep '^ *+' $at_stder1 >&2
44597grep -v '^ *+' $at_stder1 >$at_stderr
44598at_failed=false
44599echo stderr:; tee stderr <$at_stderr
44600$at_diff $at_devnull $at_stdout || at_failed=:
44601case $at_status in
44602   77) echo 77 > $at_status_file
44603            exit 77;;
44604   1) ;;
44605   *) echo "calc.at:605: exit code was $at_status, expected 1"
44606      at_failed=:;;
44607esac
44608if $at_failed; then
44609
44610  echo 1 > $at_status_file
44611  exit 1
44612fi
44613
44614$at_traceon
44615
44616
44617# Normalize the observed and expected error messages, depending upon the
44618# options.
44619# 1. Remove the traces from observed.
44620sed '/^Starting/d
44621/^Entering/d
44622/^Stack/d
44623/^Reading/d
44624/^Reducing/d
44625/^Shifting/d
44626/^state/d
44627/^Cleanup:/d
44628/^Error:/d
44629/^Next/d
44630/^Discarding/d
44631/ \$[0-9$]* = /d
44632/^yydestructor:/d' stderr >at-stderr
44633mv at-stderr stderr
44634# 2. Create the reference error message.
44635cat >expout <<'_ATEOF'
446361.0: syntax error, unexpected end of input
44637_ATEOF
44638
44639# 3. If locations are not used, remove them.
44640
44641# 4. If error-verbose is not used, strip the`, unexpected....' part.
44642
44643# 5. Check
44644$at_traceoff
44645echo "calc.at:605: cat stderr"
44646echo calc.at:605 >$at_check_line_file
44647( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
44648at_status=$?
44649grep '^ *+' $at_stder1 >&2
44650grep -v '^ *+' $at_stder1 >$at_stderr
44651at_failed=false
44652$at_diff $at_devnull $at_stderr || at_failed=:
44653$at_diff expout $at_stdout || at_failed=:
44654case $at_status in
44655   77) echo 77 > $at_status_file
44656            exit 77;;
44657   0) ;;
44658   *) echo "calc.at:605: exit code was $at_status, expected 0"
44659      at_failed=:;;
44660esac
44661if $at_failed; then
44662
44663  echo 1 > $at_status_file
44664  exit 1
44665fi
44666
44667$at_traceon
44668
44669
44670
44671# Exercise the error token: without it, we die at the first error,
44672# hence be sure to
44673#
44674# - have several errors which exercise different shift/discardings
44675#   - (): nothing to pop, nothing to discard
44676#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
44677#   - (* * *): nothing to pop, a lot to discard
44678#   - (1 + 2 * *): some to pop and discard
44679#
44680# - test the action associated to `error'
44681#
44682# - check the look-ahead that triggers an error is not discarded
44683#   when we enter error recovery.  Below, the look-ahead causing the
44684#   first error is ")", which is needed to recover from the error and
44685#   produce the "0" that triggers the "0 != 1" error.
44686#
44687cat >input <<'_ATEOF'
44688() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
44689_ATEOF
44690
44691$at_traceoff
44692echo "calc.at:605: \$PREPARSER ./calc input"
44693echo calc.at:605 >$at_check_line_file
44694( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
44695at_status=$?
44696grep '^ *+' $at_stder1 >&2
44697grep -v '^ *+' $at_stder1 >$at_stderr
44698at_failed=false
44699echo stderr:; tee stderr <$at_stderr
44700$at_diff $at_devnull $at_stdout || at_failed=:
44701case $at_status in
44702   77) echo 77 > $at_status_file
44703            exit 77;;
44704   0) ;;
44705   *) echo "calc.at:605: exit code was $at_status, expected 0"
44706      at_failed=:;;
44707esac
44708if $at_failed; then
44709
44710  echo 1 > $at_status_file
44711  exit 1
44712fi
44713
44714$at_traceon
44715
44716
44717# Normalize the observed and expected error messages, depending upon the
44718# options.
44719# 1. Remove the traces from observed.
44720sed '/^Starting/d
44721/^Entering/d
44722/^Stack/d
44723/^Reading/d
44724/^Reducing/d
44725/^Shifting/d
44726/^state/d
44727/^Cleanup:/d
44728/^Error:/d
44729/^Next/d
44730/^Discarding/d
44731/ \$[0-9$]* = /d
44732/^yydestructor:/d' stderr >at-stderr
44733mv at-stderr stderr
44734# 2. Create the reference error message.
44735cat >expout <<'_ATEOF'
447361.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
447371.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
447381.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
447391.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
44740calc: error: 4444 != 1
44741_ATEOF
44742
44743# 3. If locations are not used, remove them.
44744
44745# 4. If error-verbose is not used, strip the`, unexpected....' part.
44746
44747# 5. Check
44748$at_traceoff
44749echo "calc.at:605: cat stderr"
44750echo calc.at:605 >$at_check_line_file
44751( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
44752at_status=$?
44753grep '^ *+' $at_stder1 >&2
44754grep -v '^ *+' $at_stder1 >$at_stderr
44755at_failed=false
44756$at_diff $at_devnull $at_stderr || at_failed=:
44757$at_diff expout $at_stdout || at_failed=:
44758case $at_status in
44759   77) echo 77 > $at_status_file
44760            exit 77;;
44761   0) ;;
44762   *) echo "calc.at:605: exit code was $at_status, expected 0"
44763      at_failed=:;;
44764esac
44765if $at_failed; then
44766
44767  echo 1 > $at_status_file
44768  exit 1
44769fi
44770
44771$at_traceon
44772
44773
44774
44775# The same, but this time exercising explicitly triggered syntax errors.
44776# POSIX says the look-ahead causing the error should not be discarded.
44777cat >input <<'_ATEOF'
44778(!) + (0 0) = 1
44779_ATEOF
44780
44781$at_traceoff
44782echo "calc.at:605: \$PREPARSER ./calc input"
44783echo calc.at:605 >$at_check_line_file
44784( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
44785at_status=$?
44786grep '^ *+' $at_stder1 >&2
44787grep -v '^ *+' $at_stder1 >$at_stderr
44788at_failed=false
44789echo stderr:; tee stderr <$at_stderr
44790$at_diff $at_devnull $at_stdout || at_failed=:
44791case $at_status in
44792   77) echo 77 > $at_status_file
44793            exit 77;;
44794   0) ;;
44795   *) echo "calc.at:605: exit code was $at_status, expected 0"
44796      at_failed=:;;
44797esac
44798if $at_failed; then
44799
44800  echo 1 > $at_status_file
44801  exit 1
44802fi
44803
44804$at_traceon
44805
44806
44807# Normalize the observed and expected error messages, depending upon the
44808# options.
44809# 1. Remove the traces from observed.
44810sed '/^Starting/d
44811/^Entering/d
44812/^Stack/d
44813/^Reading/d
44814/^Reducing/d
44815/^Shifting/d
44816/^state/d
44817/^Cleanup:/d
44818/^Error:/d
44819/^Next/d
44820/^Discarding/d
44821/ \$[0-9$]* = /d
44822/^yydestructor:/d' stderr >at-stderr
44823mv at-stderr stderr
44824# 2. Create the reference error message.
44825cat >expout <<'_ATEOF'
448261.9: syntax error, unexpected number
44827calc: error: 2222 != 1
44828_ATEOF
44829
44830# 3. If locations are not used, remove them.
44831
44832# 4. If error-verbose is not used, strip the`, unexpected....' part.
44833
44834# 5. Check
44835$at_traceoff
44836echo "calc.at:605: cat stderr"
44837echo calc.at:605 >$at_check_line_file
44838( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
44839at_status=$?
44840grep '^ *+' $at_stder1 >&2
44841grep -v '^ *+' $at_stder1 >$at_stderr
44842at_failed=false
44843$at_diff $at_devnull $at_stderr || at_failed=:
44844$at_diff expout $at_stdout || at_failed=:
44845case $at_status in
44846   77) echo 77 > $at_status_file
44847            exit 77;;
44848   0) ;;
44849   *) echo "calc.at:605: exit code was $at_status, expected 0"
44850      at_failed=:;;
44851esac
44852if $at_failed; then
44853
44854  echo 1 > $at_status_file
44855  exit 1
44856fi
44857
44858$at_traceon
44859
44860
44861cat >input <<'_ATEOF'
44862(- *) + (0 0) = 1
44863_ATEOF
44864
44865$at_traceoff
44866echo "calc.at:605: \$PREPARSER ./calc input"
44867echo calc.at:605 >$at_check_line_file
44868( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
44869at_status=$?
44870grep '^ *+' $at_stder1 >&2
44871grep -v '^ *+' $at_stder1 >$at_stderr
44872at_failed=false
44873echo stderr:; tee stderr <$at_stderr
44874$at_diff $at_devnull $at_stdout || at_failed=:
44875case $at_status in
44876   77) echo 77 > $at_status_file
44877            exit 77;;
44878   0) ;;
44879   *) echo "calc.at:605: exit code was $at_status, expected 0"
44880      at_failed=:;;
44881esac
44882if $at_failed; then
44883
44884  echo 1 > $at_status_file
44885  exit 1
44886fi
44887
44888$at_traceon
44889
44890
44891# Normalize the observed and expected error messages, depending upon the
44892# options.
44893# 1. Remove the traces from observed.
44894sed '/^Starting/d
44895/^Entering/d
44896/^Stack/d
44897/^Reading/d
44898/^Reducing/d
44899/^Shifting/d
44900/^state/d
44901/^Cleanup:/d
44902/^Error:/d
44903/^Next/d
44904/^Discarding/d
44905/ \$[0-9$]* = /d
44906/^yydestructor:/d' stderr >at-stderr
44907mv at-stderr stderr
44908# 2. Create the reference error message.
44909cat >expout <<'_ATEOF'
449101.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
449111.11: syntax error, unexpected number
44912calc: error: 2222 != 1
44913_ATEOF
44914
44915# 3. If locations are not used, remove them.
44916
44917# 4. If error-verbose is not used, strip the`, unexpected....' part.
44918
44919# 5. Check
44920$at_traceoff
44921echo "calc.at:605: cat stderr"
44922echo calc.at:605 >$at_check_line_file
44923( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
44924at_status=$?
44925grep '^ *+' $at_stder1 >&2
44926grep -v '^ *+' $at_stder1 >$at_stderr
44927at_failed=false
44928$at_diff $at_devnull $at_stderr || at_failed=:
44929$at_diff expout $at_stdout || at_failed=:
44930case $at_status in
44931   77) echo 77 > $at_status_file
44932            exit 77;;
44933   0) ;;
44934   *) echo "calc.at:605: exit code was $at_status, expected 0"
44935      at_failed=:;;
44936esac
44937if $at_failed; then
44938
44939  echo 1 > $at_status_file
44940  exit 1
44941fi
44942
44943$at_traceon
44944
44945
44946
44947
44948
44949
44950
44951
44952
44953
44954
44955
44956
44957
44958
44959
44960
44961
44962
44963
44964
44965
44966
44967
44968      $at_traceoff
44969      $at_times_p && times >$at_times_file
44970    ) 5>&1 2>&1 | eval $at_tee_pipe
44971    at_status=`cat $at_status_file`
44972    ;;
44973
44974
44975  banner-11 ) # Banner 11. calc.at:612
44976    cat <<\_ATEOF
44977
44978Simple LALR(1) C++ Calculator.
44979
44980_ATEOF
44981    ;;
44982
44983  98 ) # 98. calc.at:621: Calculator %skeleton "lalr1.cc" %defines %locations
44984    at_setup_line='calc.at:621'
44985    at_desc='Calculator %skeleton "lalr1.cc" %defines %locations '
44986    $at_quiet $ECHO_N " 98: Calculator %skeleton "lalr1.cc" %defines %locations $ECHO_C"
44987    at_xfail=no
44988    (
44989      echo "98. calc.at:621: testing ..."
44990      $at_traceon
44991
44992
44993
44994
44995
44996
44997
44998
44999# Using yacc.c?
45000
45001
45002
45003
45004
45005
45006
45007# yyerror receives the location if %location & %pure & (%glr or %parse-param).
45008
45009# yyerror always sees the locations (when activated), except if
45010# yacc & pure & !param.
45011
45012
45013# The interface is pure: either because %pure-parser, or because we
45014# are using the C++ parsers.
45015
45016
45017
45018
45019
45020
45021
45022
45023
45024
45025
45026
45027cat >calc.y <<'_ATEOF'
45028%{
45029#ifdef HAVE_CONFIG_H
45030# include <config.h>
45031  /* We don't need perfect functions for these tests. */
45032# undef malloc
45033# undef memcmp
45034# undef realloc
45035#endif
45036%}
45037
45038/* Infix notation calculator--calc */
45039%skeleton "lalr1.cc" %defines %locations
45040%define "global_tokens_and_yystype"
45041%{
45042#include <stdio.h>
45043
45044#include <stdlib.h>
45045#include <string.h>
45046#if HAVE_UNISTD_H
45047# include <unistd.h>
45048#else
45049# undef alarm
45050# define alarm(seconds) /* empty */
45051#endif
45052#include <ctype.h>
45053#define USE(Var)
45054
45055/* Exercise pre-prologue dependency to %union.  */
45056typedef int semantic_value;
45057
45058static semantic_value global_result = 0;
45059static int global_count = 0;
45060%}
45061
45062/* Exercise %union. */
45063%union
45064{
45065  semantic_value ival;
45066};
45067
45068%{
45069static int power (int base, int exponent);
45070#ifndef YYLTYPE
45071# define YYLTYPE yy::location
45072#endif
45073#define first_line   begin.line
45074#define first_column begin.column
45075#define last_line    end.line
45076#define last_column  end.column
45077
45078static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
45079static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp);
45080static void unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c);
45081%}
45082
45083/* The lalr1.cc skeleton, for backward compatibility, defines
45084   a constructor for position that initializes the filename.  The
45085   glr.cc skeleton does not (and in fact cannot: location/position
45086   are stored in a union, from which objects with constructors are
45087   excluded in C++. */
45088%initial-action {
45089  @$.initialize (0);
45090}
45091
45092
45093/* Bison Declarations */
45094%token CALC_EOF 0 "end of input"
45095%token <ival> NUM "number"
45096%type  <ival> exp
45097
45098%nonassoc '=' /* comparison	       */
45099%left '-' '+'
45100%left '*' '/'
45101%left NEG     /* negation--unary minus */
45102%right '^'    /* exponentiation        */
45103
45104/* Grammar follows */
45105%%
45106input:
45107  line
45108| input line         {  }
45109;
45110
45111line:
45112  '\n'
45113| exp '\n'           { USE ($1); }
45114;
45115
45116exp:
45117  NUM                { $$ = $1;             }
45118| exp '=' exp
45119  {
45120    if ($1 != $3)
45121      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
45122    $$ = $1;
45123  }
45124| exp '+' exp        { $$ = $1 + $3;        }
45125| exp '-' exp        { $$ = $1 - $3;        }
45126| exp '*' exp        { $$ = $1 * $3;        }
45127| exp '/' exp        { $$ = $1 / $3;        }
45128| '-' exp  %prec NEG { $$ = -$2;            }
45129| exp '^' exp        { $$ = power ($1, $3); }
45130| '(' exp ')'        { $$ = $2;             }
45131| '(' error ')'      { $$ = 1111;           }
45132| '!'                { $$ = 0; YYERROR;     }
45133| '-' error          { $$ = 0; YYERROR;     }
45134;
45135%%
45136/* The input.  */
45137static FILE *input;
45138
45139/* A C++ error reporting function.  */
45140void
45141yy::parser::error (const location& l, const std::string& m)
45142{
45143  (void) l;
45144  std::cerr << l << ": " << m << std::endl;
45145}
45146
45147int
45148yyparse ()
45149{
45150  yy::parser parser;
45151  parser.set_debug_level (!!YYDEBUG);
45152  return parser.parse ();
45153}
45154
45155
45156
45157
45158static YYLTYPE last_yylloc;
45159
45160static int
45161get_char (YYSTYPE *lvalp, YYLTYPE *llocp)
45162{
45163  int res = getc (input);
45164  (void) lvalp;(void) llocp;
45165
45166  last_yylloc = (*llocp);
45167  if (res == '\n')
45168    {
45169      (*llocp).last_line++;
45170      (*llocp).last_column = 0;
45171    }
45172  else
45173    (*llocp).last_column++;
45174
45175  return res;
45176}
45177
45178
45179static void
45180unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c)
45181{
45182  (void) lvalp;(void) llocp;
45183
45184  /* Wrong when C == `\n'. */
45185  (*llocp) = last_yylloc;
45186
45187  ungetc (c, input);
45188}
45189
45190static int
45191read_signed_integer (YYSTYPE *lvalp, YYLTYPE *llocp)
45192{
45193  int c = get_char (lvalp, llocp);
45194  int sign = 1;
45195  int n = 0;
45196
45197  (void) lvalp;(void) llocp;
45198  if (c == '-')
45199    {
45200      c = get_char (lvalp, llocp);
45201      sign = -1;
45202    }
45203
45204  while (isdigit (c))
45205    {
45206      n = 10 * n + (c - '0');
45207      c = get_char (lvalp, llocp);
45208    }
45209
45210  unget_char (lvalp, llocp,  c);
45211
45212  return sign * n;
45213}
45214
45215
45216
45217/*---------------------------------------------------------------.
45218| Lexical analyzer returns an integer on the stack and the token |
45219| NUM, or the ASCII character read if not a number.  Skips all   |
45220| blanks and tabs, returns 0 for EOF.                            |
45221`---------------------------------------------------------------*/
45222
45223static int
45224yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
45225{
45226  static int init = 1;
45227  int c;
45228
45229  if (init)
45230    {
45231      init = 0;
45232
45233      (*llocp).last_column = 0;
45234      (*llocp).last_line = 1;
45235
45236    }
45237
45238
45239 (*llocp).first_column = (*llocp).last_column;
45240  (*llocp).first_line   = (*llocp).last_line;
45241
45242
45243  /* Skip white space.  */
45244  while ((c = get_char (lvalp, llocp)) == ' ' || c == '\t')
45245    {
45246     (*llocp).first_column = (*llocp).last_column;
45247      (*llocp).first_line   = (*llocp).last_line;
45248
45249    }
45250
45251  /* process numbers   */
45252  if (c == '.' || isdigit (c))
45253    {
45254      unget_char (lvalp, llocp,  c);
45255      (*lvalp).ival = read_signed_integer (lvalp, llocp);
45256      return NUM;
45257    }
45258
45259  /* Return end-of-file.  */
45260  if (c == EOF)
45261    return CALC_EOF;
45262
45263  /* Return single chars. */
45264  return c;
45265}
45266
45267static int
45268power (int base, int exponent)
45269{
45270  int res = 1;
45271  if (exponent < 0)
45272    exit (3);
45273  for (/* Niente */; exponent; --exponent)
45274    res *= base;
45275  return res;
45276}
45277
45278
45279int
45280main (int argc, const char **argv)
45281{
45282  semantic_value result = 0;
45283  int count = 0;
45284  int status;
45285
45286  /* This used to be alarm (10), but that isn't enough time for
45287     a July 1995 vintage DEC Alphastation 200 4/100 system,
45288     according to Nelson H. F. Beebe.  100 seconds is enough.  */
45289  alarm (100);
45290
45291  if (argc == 2)
45292    input = fopen (argv[1], "r");
45293  else
45294    input = stdin;
45295
45296  if (!input)
45297    {
45298      perror (argv[1]);
45299      return 3;
45300    }
45301
45302
45303  status = yyparse ();
45304  if (global_result != result)
45305    abort ();
45306  if (global_count != count)
45307    abort ();
45308  return status;
45309}
45310_ATEOF
45311
45312
45313
45314
45315
45316$at_traceoff
45317echo "calc.at:621: bison -o calc.cc calc.y"
45318echo calc.at:621 >$at_check_line_file
45319( $at_traceon; bison -o calc.cc calc.y ) >$at_stdout 2>$at_stder1
45320at_status=$?
45321grep '^ *+' $at_stder1 >&2
45322grep -v '^ *+' $at_stder1 >$at_stderr
45323at_failed=false
45324$at_diff $at_devnull $at_stderr || at_failed=:
45325$at_diff $at_devnull $at_stdout || at_failed=:
45326case $at_status in
45327   77) echo 77 > $at_status_file
45328            exit 77;;
45329   0) ;;
45330   *) echo "calc.at:621: exit code was $at_status, expected 0"
45331      at_failed=:;;
45332esac
45333if $at_failed; then
45334
45335  echo 1 > $at_status_file
45336  exit 1
45337fi
45338
45339$at_traceon
45340
45341
45342$at_traceoff
45343echo "calc.at:621: \$BISON_CXX_WORKS"
45344echo calc.at:621 >$at_check_line_file
45345( $at_traceon; $BISON_CXX_WORKS ) >$at_stdout 2>$at_stder1
45346at_status=$?
45347grep '^ *+' $at_stder1 >&2
45348grep -v '^ *+' $at_stder1 >$at_stderr
45349at_failed=false
45350echo stderr:; cat $at_stderr
45351echo stdout:; cat $at_stdout
45352case $at_status in
45353   77) echo 77 > $at_status_file
45354            exit 77;;
45355   0) ;;
45356   *) echo "calc.at:621: exit code was $at_status, expected 0"
45357      at_failed=:;;
45358esac
45359if $at_failed; then
45360
45361  echo 1 > $at_status_file
45362  exit 1
45363fi
45364
45365$at_traceon
45366
45367$at_traceoff
45368echo "calc.at:621: \$CXX \$CXXFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.cc \$LIBS"
45369echo calc.at:621 >$at_check_line_file
45370( $at_traceon; $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o calc calc.cc $LIBS ) >$at_stdout 2>$at_stder1
45371at_status=$?
45372grep '^ *+' $at_stder1 >&2
45373grep -v '^ *+' $at_stder1 >$at_stderr
45374at_failed=false
45375echo stderr:; cat $at_stderr
45376echo stdout:; cat $at_stdout
45377case $at_status in
45378   77) echo 77 > $at_status_file
45379            exit 77;;
45380   0) ;;
45381   *) echo "calc.at:621: exit code was $at_status, expected 0"
45382      at_failed=:;;
45383esac
45384if $at_failed; then
45385
45386  echo 1 > $at_status_file
45387  exit 1
45388fi
45389
45390$at_traceon
45391
45392
45393# Test the priorities.
45394cat >input <<'_ATEOF'
453951 + 2 * 3 = 7
453961 + 2 * -3 = -5
45397
45398-1^2 = -1
45399(-1)^2 = 1
45400
45401---1 = -1
45402
454031 - 2 - 3 = -4
454041 - (2 - 3) = 2
45405
454062^2^3 = 256
45407(2^2)^3 = 64
45408_ATEOF
45409
45410$at_traceoff
45411echo "calc.at:621: \$PREPARSER ./calc input"
45412echo calc.at:621 >$at_check_line_file
45413( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
45414at_status=$?
45415grep '^ *+' $at_stder1 >&2
45416grep -v '^ *+' $at_stder1 >$at_stderr
45417at_failed=false
45418echo stderr:; tee stderr <$at_stderr
45419$at_diff $at_devnull $at_stdout || at_failed=:
45420case $at_status in
45421   77) echo 77 > $at_status_file
45422            exit 77;;
45423   0) ;;
45424   *) echo "calc.at:621: exit code was $at_status, expected 0"
45425      at_failed=:;;
45426esac
45427if $at_failed; then
45428
45429  echo 1 > $at_status_file
45430  exit 1
45431fi
45432
45433$at_traceon
45434
45435
45436
45437# Some syntax errors.
45438cat >input <<'_ATEOF'
454390 0
45440_ATEOF
45441
45442$at_traceoff
45443echo "calc.at:621: \$PREPARSER ./calc input"
45444echo calc.at:621 >$at_check_line_file
45445( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
45446at_status=$?
45447grep '^ *+' $at_stder1 >&2
45448grep -v '^ *+' $at_stder1 >$at_stderr
45449at_failed=false
45450echo stderr:; tee stderr <$at_stderr
45451$at_diff $at_devnull $at_stdout || at_failed=:
45452case $at_status in
45453   77) echo 77 > $at_status_file
45454            exit 77;;
45455   1) ;;
45456   *) echo "calc.at:621: exit code was $at_status, expected 1"
45457      at_failed=:;;
45458esac
45459if $at_failed; then
45460
45461  echo 1 > $at_status_file
45462  exit 1
45463fi
45464
45465$at_traceon
45466
45467
45468# Normalize the observed and expected error messages, depending upon the
45469# options.
45470# 1. Remove the traces from observed.
45471sed '/^Starting/d
45472/^Entering/d
45473/^Stack/d
45474/^Reading/d
45475/^Reducing/d
45476/^Shifting/d
45477/^state/d
45478/^Cleanup:/d
45479/^Error:/d
45480/^Next/d
45481/^Discarding/d
45482/ \$[0-9$]* = /d
45483/^yydestructor:/d' stderr >at-stderr
45484mv at-stderr stderr
45485# 2. Create the reference error message.
45486cat >expout <<'_ATEOF'
454871.2: syntax error, unexpected number
45488_ATEOF
45489
45490# 3. If locations are not used, remove them.
45491
45492# 4. If error-verbose is not used, strip the`, unexpected....' part.
45493sed 's/syntax error, .*$/syntax error/' expout >at-expout
45494mv at-expout expout
45495# 5. Check
45496$at_traceoff
45497echo "calc.at:621: cat stderr"
45498echo calc.at:621 >$at_check_line_file
45499( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
45500at_status=$?
45501grep '^ *+' $at_stder1 >&2
45502grep -v '^ *+' $at_stder1 >$at_stderr
45503at_failed=false
45504$at_diff $at_devnull $at_stderr || at_failed=:
45505$at_diff expout $at_stdout || at_failed=:
45506case $at_status in
45507   77) echo 77 > $at_status_file
45508            exit 77;;
45509   0) ;;
45510   *) echo "calc.at:621: exit code was $at_status, expected 0"
45511      at_failed=:;;
45512esac
45513if $at_failed; then
45514
45515  echo 1 > $at_status_file
45516  exit 1
45517fi
45518
45519$at_traceon
45520
45521
45522cat >input <<'_ATEOF'
455231//2
45524_ATEOF
45525
45526$at_traceoff
45527echo "calc.at:621: \$PREPARSER ./calc input"
45528echo calc.at:621 >$at_check_line_file
45529( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
45530at_status=$?
45531grep '^ *+' $at_stder1 >&2
45532grep -v '^ *+' $at_stder1 >$at_stderr
45533at_failed=false
45534echo stderr:; tee stderr <$at_stderr
45535$at_diff $at_devnull $at_stdout || at_failed=:
45536case $at_status in
45537   77) echo 77 > $at_status_file
45538            exit 77;;
45539   1) ;;
45540   *) echo "calc.at:621: exit code was $at_status, expected 1"
45541      at_failed=:;;
45542esac
45543if $at_failed; then
45544
45545  echo 1 > $at_status_file
45546  exit 1
45547fi
45548
45549$at_traceon
45550
45551
45552# Normalize the observed and expected error messages, depending upon the
45553# options.
45554# 1. Remove the traces from observed.
45555sed '/^Starting/d
45556/^Entering/d
45557/^Stack/d
45558/^Reading/d
45559/^Reducing/d
45560/^Shifting/d
45561/^state/d
45562/^Cleanup:/d
45563/^Error:/d
45564/^Next/d
45565/^Discarding/d
45566/ \$[0-9$]* = /d
45567/^yydestructor:/d' stderr >at-stderr
45568mv at-stderr stderr
45569# 2. Create the reference error message.
45570cat >expout <<'_ATEOF'
455711.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
45572_ATEOF
45573
45574# 3. If locations are not used, remove them.
45575
45576# 4. If error-verbose is not used, strip the`, unexpected....' part.
45577sed 's/syntax error, .*$/syntax error/' expout >at-expout
45578mv at-expout expout
45579# 5. Check
45580$at_traceoff
45581echo "calc.at:621: cat stderr"
45582echo calc.at:621 >$at_check_line_file
45583( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
45584at_status=$?
45585grep '^ *+' $at_stder1 >&2
45586grep -v '^ *+' $at_stder1 >$at_stderr
45587at_failed=false
45588$at_diff $at_devnull $at_stderr || at_failed=:
45589$at_diff expout $at_stdout || at_failed=:
45590case $at_status in
45591   77) echo 77 > $at_status_file
45592            exit 77;;
45593   0) ;;
45594   *) echo "calc.at:621: exit code was $at_status, expected 0"
45595      at_failed=:;;
45596esac
45597if $at_failed; then
45598
45599  echo 1 > $at_status_file
45600  exit 1
45601fi
45602
45603$at_traceon
45604
45605
45606cat >input <<'_ATEOF'
45607error
45608_ATEOF
45609
45610$at_traceoff
45611echo "calc.at:621: \$PREPARSER ./calc input"
45612echo calc.at:621 >$at_check_line_file
45613( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
45614at_status=$?
45615grep '^ *+' $at_stder1 >&2
45616grep -v '^ *+' $at_stder1 >$at_stderr
45617at_failed=false
45618echo stderr:; tee stderr <$at_stderr
45619$at_diff $at_devnull $at_stdout || at_failed=:
45620case $at_status in
45621   77) echo 77 > $at_status_file
45622            exit 77;;
45623   1) ;;
45624   *) echo "calc.at:621: exit code was $at_status, expected 1"
45625      at_failed=:;;
45626esac
45627if $at_failed; then
45628
45629  echo 1 > $at_status_file
45630  exit 1
45631fi
45632
45633$at_traceon
45634
45635
45636# Normalize the observed and expected error messages, depending upon the
45637# options.
45638# 1. Remove the traces from observed.
45639sed '/^Starting/d
45640/^Entering/d
45641/^Stack/d
45642/^Reading/d
45643/^Reducing/d
45644/^Shifting/d
45645/^state/d
45646/^Cleanup:/d
45647/^Error:/d
45648/^Next/d
45649/^Discarding/d
45650/ \$[0-9$]* = /d
45651/^yydestructor:/d' stderr >at-stderr
45652mv at-stderr stderr
45653# 2. Create the reference error message.
45654cat >expout <<'_ATEOF'
456551.0: syntax error, unexpected $undefined
45656_ATEOF
45657
45658# 3. If locations are not used, remove them.
45659
45660# 4. If error-verbose is not used, strip the`, unexpected....' part.
45661sed 's/syntax error, .*$/syntax error/' expout >at-expout
45662mv at-expout expout
45663# 5. Check
45664$at_traceoff
45665echo "calc.at:621: cat stderr"
45666echo calc.at:621 >$at_check_line_file
45667( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
45668at_status=$?
45669grep '^ *+' $at_stder1 >&2
45670grep -v '^ *+' $at_stder1 >$at_stderr
45671at_failed=false
45672$at_diff $at_devnull $at_stderr || at_failed=:
45673$at_diff expout $at_stdout || at_failed=:
45674case $at_status in
45675   77) echo 77 > $at_status_file
45676            exit 77;;
45677   0) ;;
45678   *) echo "calc.at:621: exit code was $at_status, expected 0"
45679      at_failed=:;;
45680esac
45681if $at_failed; then
45682
45683  echo 1 > $at_status_file
45684  exit 1
45685fi
45686
45687$at_traceon
45688
45689
45690cat >input <<'_ATEOF'
456911 = 2 = 3
45692_ATEOF
45693
45694$at_traceoff
45695echo "calc.at:621: \$PREPARSER ./calc input"
45696echo calc.at:621 >$at_check_line_file
45697( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
45698at_status=$?
45699grep '^ *+' $at_stder1 >&2
45700grep -v '^ *+' $at_stder1 >$at_stderr
45701at_failed=false
45702echo stderr:; tee stderr <$at_stderr
45703$at_diff $at_devnull $at_stdout || at_failed=:
45704case $at_status in
45705   77) echo 77 > $at_status_file
45706            exit 77;;
45707   1) ;;
45708   *) echo "calc.at:621: exit code was $at_status, expected 1"
45709      at_failed=:;;
45710esac
45711if $at_failed; then
45712
45713  echo 1 > $at_status_file
45714  exit 1
45715fi
45716
45717$at_traceon
45718
45719
45720# Normalize the observed and expected error messages, depending upon the
45721# options.
45722# 1. Remove the traces from observed.
45723sed '/^Starting/d
45724/^Entering/d
45725/^Stack/d
45726/^Reading/d
45727/^Reducing/d
45728/^Shifting/d
45729/^state/d
45730/^Cleanup:/d
45731/^Error:/d
45732/^Next/d
45733/^Discarding/d
45734/ \$[0-9$]* = /d
45735/^yydestructor:/d' stderr >at-stderr
45736mv at-stderr stderr
45737# 2. Create the reference error message.
45738cat >expout <<'_ATEOF'
457391.6: syntax error, unexpected '='
45740_ATEOF
45741
45742# 3. If locations are not used, remove them.
45743
45744# 4. If error-verbose is not used, strip the`, unexpected....' part.
45745sed 's/syntax error, .*$/syntax error/' expout >at-expout
45746mv at-expout expout
45747# 5. Check
45748$at_traceoff
45749echo "calc.at:621: cat stderr"
45750echo calc.at:621 >$at_check_line_file
45751( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
45752at_status=$?
45753grep '^ *+' $at_stder1 >&2
45754grep -v '^ *+' $at_stder1 >$at_stderr
45755at_failed=false
45756$at_diff $at_devnull $at_stderr || at_failed=:
45757$at_diff expout $at_stdout || at_failed=:
45758case $at_status in
45759   77) echo 77 > $at_status_file
45760            exit 77;;
45761   0) ;;
45762   *) echo "calc.at:621: exit code was $at_status, expected 0"
45763      at_failed=:;;
45764esac
45765if $at_failed; then
45766
45767  echo 1 > $at_status_file
45768  exit 1
45769fi
45770
45771$at_traceon
45772
45773
45774cat >input <<'_ATEOF'
45775
45776+1
45777_ATEOF
45778
45779$at_traceoff
45780echo "calc.at:621: \$PREPARSER ./calc input"
45781echo calc.at:621 >$at_check_line_file
45782( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
45783at_status=$?
45784grep '^ *+' $at_stder1 >&2
45785grep -v '^ *+' $at_stder1 >$at_stderr
45786at_failed=false
45787echo stderr:; tee stderr <$at_stderr
45788$at_diff $at_devnull $at_stdout || at_failed=:
45789case $at_status in
45790   77) echo 77 > $at_status_file
45791            exit 77;;
45792   1) ;;
45793   *) echo "calc.at:621: exit code was $at_status, expected 1"
45794      at_failed=:;;
45795esac
45796if $at_failed; then
45797
45798  echo 1 > $at_status_file
45799  exit 1
45800fi
45801
45802$at_traceon
45803
45804
45805# Normalize the observed and expected error messages, depending upon the
45806# options.
45807# 1. Remove the traces from observed.
45808sed '/^Starting/d
45809/^Entering/d
45810/^Stack/d
45811/^Reading/d
45812/^Reducing/d
45813/^Shifting/d
45814/^state/d
45815/^Cleanup:/d
45816/^Error:/d
45817/^Next/d
45818/^Discarding/d
45819/ \$[0-9$]* = /d
45820/^yydestructor:/d' stderr >at-stderr
45821mv at-stderr stderr
45822# 2. Create the reference error message.
45823cat >expout <<'_ATEOF'
458242.0: syntax error, unexpected '+'
45825_ATEOF
45826
45827# 3. If locations are not used, remove them.
45828
45829# 4. If error-verbose is not used, strip the`, unexpected....' part.
45830sed 's/syntax error, .*$/syntax error/' expout >at-expout
45831mv at-expout expout
45832# 5. Check
45833$at_traceoff
45834echo "calc.at:621: cat stderr"
45835echo calc.at:621 >$at_check_line_file
45836( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
45837at_status=$?
45838grep '^ *+' $at_stder1 >&2
45839grep -v '^ *+' $at_stder1 >$at_stderr
45840at_failed=false
45841$at_diff $at_devnull $at_stderr || at_failed=:
45842$at_diff expout $at_stdout || at_failed=:
45843case $at_status in
45844   77) echo 77 > $at_status_file
45845            exit 77;;
45846   0) ;;
45847   *) echo "calc.at:621: exit code was $at_status, expected 0"
45848      at_failed=:;;
45849esac
45850if $at_failed; then
45851
45852  echo 1 > $at_status_file
45853  exit 1
45854fi
45855
45856$at_traceon
45857
45858
45859# Exercise error messages with EOF: work on an empty file.
45860$at_traceoff
45861echo "calc.at:621: \$PREPARSER ./calc /dev/null"
45862echo calc.at:621 >$at_check_line_file
45863( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
45864at_status=$?
45865grep '^ *+' $at_stder1 >&2
45866grep -v '^ *+' $at_stder1 >$at_stderr
45867at_failed=false
45868echo stderr:; tee stderr <$at_stderr
45869$at_diff $at_devnull $at_stdout || at_failed=:
45870case $at_status in
45871   77) echo 77 > $at_status_file
45872            exit 77;;
45873   1) ;;
45874   *) echo "calc.at:621: exit code was $at_status, expected 1"
45875      at_failed=:;;
45876esac
45877if $at_failed; then
45878
45879  echo 1 > $at_status_file
45880  exit 1
45881fi
45882
45883$at_traceon
45884
45885
45886# Normalize the observed and expected error messages, depending upon the
45887# options.
45888# 1. Remove the traces from observed.
45889sed '/^Starting/d
45890/^Entering/d
45891/^Stack/d
45892/^Reading/d
45893/^Reducing/d
45894/^Shifting/d
45895/^state/d
45896/^Cleanup:/d
45897/^Error:/d
45898/^Next/d
45899/^Discarding/d
45900/ \$[0-9$]* = /d
45901/^yydestructor:/d' stderr >at-stderr
45902mv at-stderr stderr
45903# 2. Create the reference error message.
45904cat >expout <<'_ATEOF'
459051.0: syntax error, unexpected end of input
45906_ATEOF
45907
45908# 3. If locations are not used, remove them.
45909
45910# 4. If error-verbose is not used, strip the`, unexpected....' part.
45911sed 's/syntax error, .*$/syntax error/' expout >at-expout
45912mv at-expout expout
45913# 5. Check
45914$at_traceoff
45915echo "calc.at:621: cat stderr"
45916echo calc.at:621 >$at_check_line_file
45917( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
45918at_status=$?
45919grep '^ *+' $at_stder1 >&2
45920grep -v '^ *+' $at_stder1 >$at_stderr
45921at_failed=false
45922$at_diff $at_devnull $at_stderr || at_failed=:
45923$at_diff expout $at_stdout || at_failed=:
45924case $at_status in
45925   77) echo 77 > $at_status_file
45926            exit 77;;
45927   0) ;;
45928   *) echo "calc.at:621: exit code was $at_status, expected 0"
45929      at_failed=:;;
45930esac
45931if $at_failed; then
45932
45933  echo 1 > $at_status_file
45934  exit 1
45935fi
45936
45937$at_traceon
45938
45939
45940
45941# Exercise the error token: without it, we die at the first error,
45942# hence be sure to
45943#
45944# - have several errors which exercise different shift/discardings
45945#   - (): nothing to pop, nothing to discard
45946#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
45947#   - (* * *): nothing to pop, a lot to discard
45948#   - (1 + 2 * *): some to pop and discard
45949#
45950# - test the action associated to `error'
45951#
45952# - check the look-ahead that triggers an error is not discarded
45953#   when we enter error recovery.  Below, the look-ahead causing the
45954#   first error is ")", which is needed to recover from the error and
45955#   produce the "0" that triggers the "0 != 1" error.
45956#
45957cat >input <<'_ATEOF'
45958() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
45959_ATEOF
45960
45961$at_traceoff
45962echo "calc.at:621: \$PREPARSER ./calc input"
45963echo calc.at:621 >$at_check_line_file
45964( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
45965at_status=$?
45966grep '^ *+' $at_stder1 >&2
45967grep -v '^ *+' $at_stder1 >$at_stderr
45968at_failed=false
45969echo stderr:; tee stderr <$at_stderr
45970$at_diff $at_devnull $at_stdout || at_failed=:
45971case $at_status in
45972   77) echo 77 > $at_status_file
45973            exit 77;;
45974   0) ;;
45975   *) echo "calc.at:621: exit code was $at_status, expected 0"
45976      at_failed=:;;
45977esac
45978if $at_failed; then
45979
45980  echo 1 > $at_status_file
45981  exit 1
45982fi
45983
45984$at_traceon
45985
45986
45987# Normalize the observed and expected error messages, depending upon the
45988# options.
45989# 1. Remove the traces from observed.
45990sed '/^Starting/d
45991/^Entering/d
45992/^Stack/d
45993/^Reading/d
45994/^Reducing/d
45995/^Shifting/d
45996/^state/d
45997/^Cleanup:/d
45998/^Error:/d
45999/^Next/d
46000/^Discarding/d
46001/ \$[0-9$]* = /d
46002/^yydestructor:/d' stderr >at-stderr
46003mv at-stderr stderr
46004# 2. Create the reference error message.
46005cat >expout <<'_ATEOF'
460061.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
460071.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
460081.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
460091.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
46010calc: error: 4444 != 1
46011_ATEOF
46012
46013# 3. If locations are not used, remove them.
46014
46015# 4. If error-verbose is not used, strip the`, unexpected....' part.
46016sed 's/syntax error, .*$/syntax error/' expout >at-expout
46017mv at-expout expout
46018# 5. Check
46019$at_traceoff
46020echo "calc.at:621: cat stderr"
46021echo calc.at:621 >$at_check_line_file
46022( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
46023at_status=$?
46024grep '^ *+' $at_stder1 >&2
46025grep -v '^ *+' $at_stder1 >$at_stderr
46026at_failed=false
46027$at_diff $at_devnull $at_stderr || at_failed=:
46028$at_diff expout $at_stdout || at_failed=:
46029case $at_status in
46030   77) echo 77 > $at_status_file
46031            exit 77;;
46032   0) ;;
46033   *) echo "calc.at:621: exit code was $at_status, expected 0"
46034      at_failed=:;;
46035esac
46036if $at_failed; then
46037
46038  echo 1 > $at_status_file
46039  exit 1
46040fi
46041
46042$at_traceon
46043
46044
46045
46046# The same, but this time exercising explicitly triggered syntax errors.
46047# POSIX says the look-ahead causing the error should not be discarded.
46048cat >input <<'_ATEOF'
46049(!) + (0 0) = 1
46050_ATEOF
46051
46052$at_traceoff
46053echo "calc.at:621: \$PREPARSER ./calc input"
46054echo calc.at:621 >$at_check_line_file
46055( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
46056at_status=$?
46057grep '^ *+' $at_stder1 >&2
46058grep -v '^ *+' $at_stder1 >$at_stderr
46059at_failed=false
46060echo stderr:; tee stderr <$at_stderr
46061$at_diff $at_devnull $at_stdout || at_failed=:
46062case $at_status in
46063   77) echo 77 > $at_status_file
46064            exit 77;;
46065   0) ;;
46066   *) echo "calc.at:621: exit code was $at_status, expected 0"
46067      at_failed=:;;
46068esac
46069if $at_failed; then
46070
46071  echo 1 > $at_status_file
46072  exit 1
46073fi
46074
46075$at_traceon
46076
46077
46078# Normalize the observed and expected error messages, depending upon the
46079# options.
46080# 1. Remove the traces from observed.
46081sed '/^Starting/d
46082/^Entering/d
46083/^Stack/d
46084/^Reading/d
46085/^Reducing/d
46086/^Shifting/d
46087/^state/d
46088/^Cleanup:/d
46089/^Error:/d
46090/^Next/d
46091/^Discarding/d
46092/ \$[0-9$]* = /d
46093/^yydestructor:/d' stderr >at-stderr
46094mv at-stderr stderr
46095# 2. Create the reference error message.
46096cat >expout <<'_ATEOF'
460971.9: syntax error, unexpected number
46098calc: error: 2222 != 1
46099_ATEOF
46100
46101# 3. If locations are not used, remove them.
46102
46103# 4. If error-verbose is not used, strip the`, unexpected....' part.
46104sed 's/syntax error, .*$/syntax error/' expout >at-expout
46105mv at-expout expout
46106# 5. Check
46107$at_traceoff
46108echo "calc.at:621: cat stderr"
46109echo calc.at:621 >$at_check_line_file
46110( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
46111at_status=$?
46112grep '^ *+' $at_stder1 >&2
46113grep -v '^ *+' $at_stder1 >$at_stderr
46114at_failed=false
46115$at_diff $at_devnull $at_stderr || at_failed=:
46116$at_diff expout $at_stdout || at_failed=:
46117case $at_status in
46118   77) echo 77 > $at_status_file
46119            exit 77;;
46120   0) ;;
46121   *) echo "calc.at:621: exit code was $at_status, expected 0"
46122      at_failed=:;;
46123esac
46124if $at_failed; then
46125
46126  echo 1 > $at_status_file
46127  exit 1
46128fi
46129
46130$at_traceon
46131
46132
46133cat >input <<'_ATEOF'
46134(- *) + (0 0) = 1
46135_ATEOF
46136
46137$at_traceoff
46138echo "calc.at:621: \$PREPARSER ./calc input"
46139echo calc.at:621 >$at_check_line_file
46140( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
46141at_status=$?
46142grep '^ *+' $at_stder1 >&2
46143grep -v '^ *+' $at_stder1 >$at_stderr
46144at_failed=false
46145echo stderr:; tee stderr <$at_stderr
46146$at_diff $at_devnull $at_stdout || at_failed=:
46147case $at_status in
46148   77) echo 77 > $at_status_file
46149            exit 77;;
46150   0) ;;
46151   *) echo "calc.at:621: exit code was $at_status, expected 0"
46152      at_failed=:;;
46153esac
46154if $at_failed; then
46155
46156  echo 1 > $at_status_file
46157  exit 1
46158fi
46159
46160$at_traceon
46161
46162
46163# Normalize the observed and expected error messages, depending upon the
46164# options.
46165# 1. Remove the traces from observed.
46166sed '/^Starting/d
46167/^Entering/d
46168/^Stack/d
46169/^Reading/d
46170/^Reducing/d
46171/^Shifting/d
46172/^state/d
46173/^Cleanup:/d
46174/^Error:/d
46175/^Next/d
46176/^Discarding/d
46177/ \$[0-9$]* = /d
46178/^yydestructor:/d' stderr >at-stderr
46179mv at-stderr stderr
46180# 2. Create the reference error message.
46181cat >expout <<'_ATEOF'
461821.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
461831.11: syntax error, unexpected number
46184calc: error: 2222 != 1
46185_ATEOF
46186
46187# 3. If locations are not used, remove them.
46188
46189# 4. If error-verbose is not used, strip the`, unexpected....' part.
46190sed 's/syntax error, .*$/syntax error/' expout >at-expout
46191mv at-expout expout
46192# 5. Check
46193$at_traceoff
46194echo "calc.at:621: cat stderr"
46195echo calc.at:621 >$at_check_line_file
46196( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
46197at_status=$?
46198grep '^ *+' $at_stder1 >&2
46199grep -v '^ *+' $at_stder1 >$at_stderr
46200at_failed=false
46201$at_diff $at_devnull $at_stderr || at_failed=:
46202$at_diff expout $at_stdout || at_failed=:
46203case $at_status in
46204   77) echo 77 > $at_status_file
46205            exit 77;;
46206   0) ;;
46207   *) echo "calc.at:621: exit code was $at_status, expected 0"
46208      at_failed=:;;
46209esac
46210if $at_failed; then
46211
46212  echo 1 > $at_status_file
46213  exit 1
46214fi
46215
46216$at_traceon
46217
46218
46219
46220
46221
46222
46223
46224
46225
46226
46227
46228
46229
46230
46231
46232
46233
46234
46235
46236
46237
46238
46239
46240
46241      $at_traceoff
46242      $at_times_p && times >$at_times_file
46243    ) 5>&1 2>&1 | eval $at_tee_pipe
46244    at_status=`cat $at_status_file`
46245    ;;
46246
46247  99 ) # 99. calc.at:622: Calculator %skeleton "lalr1.cc" %defines %locations %error-verbose %name-prefix="calc" %verbose %yacc
46248    at_setup_line='calc.at:622'
46249    at_desc='Calculator %skeleton "lalr1.cc" %defines %locations %error-verbose %name-prefix="calc" %verbose %yacc'
46250    $at_quiet $ECHO_N " 99: Calculator %skeleton "lalr1.cc" %defines %locations %error-verbose %name-prefix="calc" %verbose %yacc$ECHO_C"
46251    at_xfail=no
46252    (
46253      echo "99. calc.at:622: testing ..."
46254      $at_traceon
46255
46256
46257
46258
46259
46260
46261
46262
46263# Using yacc.c?
46264
46265
46266
46267
46268
46269
46270
46271# yyerror receives the location if %location & %pure & (%glr or %parse-param).
46272
46273# yyerror always sees the locations (when activated), except if
46274# yacc & pure & !param.
46275
46276
46277# The interface is pure: either because %pure-parser, or because we
46278# are using the C++ parsers.
46279
46280
46281
46282
46283
46284
46285
46286
46287
46288
46289
46290
46291cat >calc.y <<'_ATEOF'
46292%{
46293#ifdef HAVE_CONFIG_H
46294# include <config.h>
46295  /* We don't need perfect functions for these tests. */
46296# undef malloc
46297# undef memcmp
46298# undef realloc
46299#endif
46300%}
46301
46302/* Infix notation calculator--calc */
46303%skeleton "lalr1.cc" %defines %locations %error-verbose %name-prefix="calc" %verbose %yacc
46304%define "global_tokens_and_yystype"
46305%{
46306#include <stdio.h>
46307
46308#include <stdlib.h>
46309#include <string.h>
46310#if HAVE_UNISTD_H
46311# include <unistd.h>
46312#else
46313# undef alarm
46314# define alarm(seconds) /* empty */
46315#endif
46316#include <ctype.h>
46317#define USE(Var)
46318
46319/* Exercise pre-prologue dependency to %union.  */
46320typedef int semantic_value;
46321
46322static semantic_value global_result = 0;
46323static int global_count = 0;
46324%}
46325
46326/* Exercise %union. */
46327%union
46328{
46329  semantic_value ival;
46330};
46331
46332%{
46333static int power (int base, int exponent);
46334#ifndef YYLTYPE
46335# define YYLTYPE calc::location
46336#endif
46337#define first_line   begin.line
46338#define first_column begin.column
46339#define last_line    end.line
46340#define last_column  end.column
46341
46342static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
46343static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp);
46344static void unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c);
46345%}
46346
46347/* The lalr1.cc skeleton, for backward compatibility, defines
46348   a constructor for position that initializes the filename.  The
46349   glr.cc skeleton does not (and in fact cannot: location/position
46350   are stored in a union, from which objects with constructors are
46351   excluded in C++. */
46352%initial-action {
46353  @$.initialize (0);
46354}
46355
46356
46357/* Bison Declarations */
46358%token CALC_EOF 0 "end of input"
46359%token <ival> NUM "number"
46360%type  <ival> exp
46361
46362%nonassoc '=' /* comparison	       */
46363%left '-' '+'
46364%left '*' '/'
46365%left NEG     /* negation--unary minus */
46366%right '^'    /* exponentiation        */
46367
46368/* Grammar follows */
46369%%
46370input:
46371  line
46372| input line         {  }
46373;
46374
46375line:
46376  '\n'
46377| exp '\n'           { USE ($1); }
46378;
46379
46380exp:
46381  NUM                { $$ = $1;             }
46382| exp '=' exp
46383  {
46384    if ($1 != $3)
46385      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
46386    $$ = $1;
46387  }
46388| exp '+' exp        { $$ = $1 + $3;        }
46389| exp '-' exp        { $$ = $1 - $3;        }
46390| exp '*' exp        { $$ = $1 * $3;        }
46391| exp '/' exp        { $$ = $1 / $3;        }
46392| '-' exp  %prec NEG { $$ = -$2;            }
46393| exp '^' exp        { $$ = power ($1, $3); }
46394| '(' exp ')'        { $$ = $2;             }
46395| '(' error ')'      { $$ = 1111;           }
46396| '!'                { $$ = 0; YYERROR;     }
46397| '-' error          { $$ = 0; YYERROR;     }
46398;
46399%%
46400/* The input.  */
46401static FILE *input;
46402
46403/* A C++ error reporting function.  */
46404void
46405calc::parser::error (const location& l, const std::string& m)
46406{
46407  (void) l;
46408  std::cerr << l << ": " << m << std::endl;
46409}
46410
46411int
46412yyparse ()
46413{
46414  calc::parser parser;
46415  parser.set_debug_level (!!YYDEBUG);
46416  return parser.parse ();
46417}
46418
46419
46420
46421
46422static YYLTYPE last_yylloc;
46423
46424static int
46425get_char (YYSTYPE *lvalp, YYLTYPE *llocp)
46426{
46427  int res = getc (input);
46428  (void) lvalp;(void) llocp;
46429
46430  last_yylloc = (*llocp);
46431  if (res == '\n')
46432    {
46433      (*llocp).last_line++;
46434      (*llocp).last_column = 0;
46435    }
46436  else
46437    (*llocp).last_column++;
46438
46439  return res;
46440}
46441
46442
46443static void
46444unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c)
46445{
46446  (void) lvalp;(void) llocp;
46447
46448  /* Wrong when C == `\n'. */
46449  (*llocp) = last_yylloc;
46450
46451  ungetc (c, input);
46452}
46453
46454static int
46455read_signed_integer (YYSTYPE *lvalp, YYLTYPE *llocp)
46456{
46457  int c = get_char (lvalp, llocp);
46458  int sign = 1;
46459  int n = 0;
46460
46461  (void) lvalp;(void) llocp;
46462  if (c == '-')
46463    {
46464      c = get_char (lvalp, llocp);
46465      sign = -1;
46466    }
46467
46468  while (isdigit (c))
46469    {
46470      n = 10 * n + (c - '0');
46471      c = get_char (lvalp, llocp);
46472    }
46473
46474  unget_char (lvalp, llocp,  c);
46475
46476  return sign * n;
46477}
46478
46479
46480
46481/*---------------------------------------------------------------.
46482| Lexical analyzer returns an integer on the stack and the token |
46483| NUM, or the ASCII character read if not a number.  Skips all   |
46484| blanks and tabs, returns 0 for EOF.                            |
46485`---------------------------------------------------------------*/
46486
46487static int
46488yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
46489{
46490  static int init = 1;
46491  int c;
46492
46493  if (init)
46494    {
46495      init = 0;
46496
46497      (*llocp).last_column = 0;
46498      (*llocp).last_line = 1;
46499
46500    }
46501
46502
46503 (*llocp).first_column = (*llocp).last_column;
46504  (*llocp).first_line   = (*llocp).last_line;
46505
46506
46507  /* Skip white space.  */
46508  while ((c = get_char (lvalp, llocp)) == ' ' || c == '\t')
46509    {
46510     (*llocp).first_column = (*llocp).last_column;
46511      (*llocp).first_line   = (*llocp).last_line;
46512
46513    }
46514
46515  /* process numbers   */
46516  if (c == '.' || isdigit (c))
46517    {
46518      unget_char (lvalp, llocp,  c);
46519      (*lvalp).ival = read_signed_integer (lvalp, llocp);
46520      return NUM;
46521    }
46522
46523  /* Return end-of-file.  */
46524  if (c == EOF)
46525    return CALC_EOF;
46526
46527  /* Return single chars. */
46528  return c;
46529}
46530
46531static int
46532power (int base, int exponent)
46533{
46534  int res = 1;
46535  if (exponent < 0)
46536    exit (3);
46537  for (/* Niente */; exponent; --exponent)
46538    res *= base;
46539  return res;
46540}
46541
46542
46543int
46544main (int argc, const char **argv)
46545{
46546  semantic_value result = 0;
46547  int count = 0;
46548  int status;
46549
46550  /* This used to be alarm (10), but that isn't enough time for
46551     a July 1995 vintage DEC Alphastation 200 4/100 system,
46552     according to Nelson H. F. Beebe.  100 seconds is enough.  */
46553  alarm (100);
46554
46555  if (argc == 2)
46556    input = fopen (argv[1], "r");
46557  else
46558    input = stdin;
46559
46560  if (!input)
46561    {
46562      perror (argv[1]);
46563      return 3;
46564    }
46565
46566
46567  status = yyparse ();
46568  if (global_result != result)
46569    abort ();
46570  if (global_count != count)
46571    abort ();
46572  return status;
46573}
46574_ATEOF
46575
46576
46577
46578
46579
46580$at_traceoff
46581echo "calc.at:622: bison -o calc.cc calc.y"
46582echo calc.at:622 >$at_check_line_file
46583( $at_traceon; bison -o calc.cc calc.y ) >$at_stdout 2>$at_stder1
46584at_status=$?
46585grep '^ *+' $at_stder1 >&2
46586grep -v '^ *+' $at_stder1 >$at_stderr
46587at_failed=false
46588$at_diff $at_devnull $at_stderr || at_failed=:
46589$at_diff $at_devnull $at_stdout || at_failed=:
46590case $at_status in
46591   77) echo 77 > $at_status_file
46592            exit 77;;
46593   0) ;;
46594   *) echo "calc.at:622: exit code was $at_status, expected 0"
46595      at_failed=:;;
46596esac
46597if $at_failed; then
46598
46599  echo 1 > $at_status_file
46600  exit 1
46601fi
46602
46603$at_traceon
46604
46605
46606$at_traceoff
46607echo "calc.at:622: \$BISON_CXX_WORKS"
46608echo calc.at:622 >$at_check_line_file
46609( $at_traceon; $BISON_CXX_WORKS ) >$at_stdout 2>$at_stder1
46610at_status=$?
46611grep '^ *+' $at_stder1 >&2
46612grep -v '^ *+' $at_stder1 >$at_stderr
46613at_failed=false
46614echo stderr:; cat $at_stderr
46615echo stdout:; cat $at_stdout
46616case $at_status in
46617   77) echo 77 > $at_status_file
46618            exit 77;;
46619   0) ;;
46620   *) echo "calc.at:622: exit code was $at_status, expected 0"
46621      at_failed=:;;
46622esac
46623if $at_failed; then
46624
46625  echo 1 > $at_status_file
46626  exit 1
46627fi
46628
46629$at_traceon
46630
46631$at_traceoff
46632echo "calc.at:622: \$CXX \$CXXFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.cc \$LIBS"
46633echo calc.at:622 >$at_check_line_file
46634( $at_traceon; $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o calc calc.cc $LIBS ) >$at_stdout 2>$at_stder1
46635at_status=$?
46636grep '^ *+' $at_stder1 >&2
46637grep -v '^ *+' $at_stder1 >$at_stderr
46638at_failed=false
46639echo stderr:; cat $at_stderr
46640echo stdout:; cat $at_stdout
46641case $at_status in
46642   77) echo 77 > $at_status_file
46643            exit 77;;
46644   0) ;;
46645   *) echo "calc.at:622: exit code was $at_status, expected 0"
46646      at_failed=:;;
46647esac
46648if $at_failed; then
46649
46650  echo 1 > $at_status_file
46651  exit 1
46652fi
46653
46654$at_traceon
46655
46656
46657# Test the priorities.
46658cat >input <<'_ATEOF'
466591 + 2 * 3 = 7
466601 + 2 * -3 = -5
46661
46662-1^2 = -1
46663(-1)^2 = 1
46664
46665---1 = -1
46666
466671 - 2 - 3 = -4
466681 - (2 - 3) = 2
46669
466702^2^3 = 256
46671(2^2)^3 = 64
46672_ATEOF
46673
46674$at_traceoff
46675echo "calc.at:622: \$PREPARSER ./calc input"
46676echo calc.at:622 >$at_check_line_file
46677( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
46678at_status=$?
46679grep '^ *+' $at_stder1 >&2
46680grep -v '^ *+' $at_stder1 >$at_stderr
46681at_failed=false
46682echo stderr:; tee stderr <$at_stderr
46683$at_diff $at_devnull $at_stdout || at_failed=:
46684case $at_status in
46685   77) echo 77 > $at_status_file
46686            exit 77;;
46687   0) ;;
46688   *) echo "calc.at:622: exit code was $at_status, expected 0"
46689      at_failed=:;;
46690esac
46691if $at_failed; then
46692
46693  echo 1 > $at_status_file
46694  exit 1
46695fi
46696
46697$at_traceon
46698
46699
46700
46701# Some syntax errors.
46702cat >input <<'_ATEOF'
467030 0
46704_ATEOF
46705
46706$at_traceoff
46707echo "calc.at:622: \$PREPARSER ./calc input"
46708echo calc.at:622 >$at_check_line_file
46709( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
46710at_status=$?
46711grep '^ *+' $at_stder1 >&2
46712grep -v '^ *+' $at_stder1 >$at_stderr
46713at_failed=false
46714echo stderr:; tee stderr <$at_stderr
46715$at_diff $at_devnull $at_stdout || at_failed=:
46716case $at_status in
46717   77) echo 77 > $at_status_file
46718            exit 77;;
46719   1) ;;
46720   *) echo "calc.at:622: exit code was $at_status, expected 1"
46721      at_failed=:;;
46722esac
46723if $at_failed; then
46724
46725  echo 1 > $at_status_file
46726  exit 1
46727fi
46728
46729$at_traceon
46730
46731
46732# Normalize the observed and expected error messages, depending upon the
46733# options.
46734# 1. Remove the traces from observed.
46735sed '/^Starting/d
46736/^Entering/d
46737/^Stack/d
46738/^Reading/d
46739/^Reducing/d
46740/^Shifting/d
46741/^state/d
46742/^Cleanup:/d
46743/^Error:/d
46744/^Next/d
46745/^Discarding/d
46746/ \$[0-9$]* = /d
46747/^yydestructor:/d' stderr >at-stderr
46748mv at-stderr stderr
46749# 2. Create the reference error message.
46750cat >expout <<'_ATEOF'
467511.2: syntax error, unexpected number
46752_ATEOF
46753
46754# 3. If locations are not used, remove them.
46755
46756# 4. If error-verbose is not used, strip the`, unexpected....' part.
46757
46758# 5. Check
46759$at_traceoff
46760echo "calc.at:622: cat stderr"
46761echo calc.at:622 >$at_check_line_file
46762( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
46763at_status=$?
46764grep '^ *+' $at_stder1 >&2
46765grep -v '^ *+' $at_stder1 >$at_stderr
46766at_failed=false
46767$at_diff $at_devnull $at_stderr || at_failed=:
46768$at_diff expout $at_stdout || at_failed=:
46769case $at_status in
46770   77) echo 77 > $at_status_file
46771            exit 77;;
46772   0) ;;
46773   *) echo "calc.at:622: exit code was $at_status, expected 0"
46774      at_failed=:;;
46775esac
46776if $at_failed; then
46777
46778  echo 1 > $at_status_file
46779  exit 1
46780fi
46781
46782$at_traceon
46783
46784
46785cat >input <<'_ATEOF'
467861//2
46787_ATEOF
46788
46789$at_traceoff
46790echo "calc.at:622: \$PREPARSER ./calc input"
46791echo calc.at:622 >$at_check_line_file
46792( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
46793at_status=$?
46794grep '^ *+' $at_stder1 >&2
46795grep -v '^ *+' $at_stder1 >$at_stderr
46796at_failed=false
46797echo stderr:; tee stderr <$at_stderr
46798$at_diff $at_devnull $at_stdout || at_failed=:
46799case $at_status in
46800   77) echo 77 > $at_status_file
46801            exit 77;;
46802   1) ;;
46803   *) echo "calc.at:622: exit code was $at_status, expected 1"
46804      at_failed=:;;
46805esac
46806if $at_failed; then
46807
46808  echo 1 > $at_status_file
46809  exit 1
46810fi
46811
46812$at_traceon
46813
46814
46815# Normalize the observed and expected error messages, depending upon the
46816# options.
46817# 1. Remove the traces from observed.
46818sed '/^Starting/d
46819/^Entering/d
46820/^Stack/d
46821/^Reading/d
46822/^Reducing/d
46823/^Shifting/d
46824/^state/d
46825/^Cleanup:/d
46826/^Error:/d
46827/^Next/d
46828/^Discarding/d
46829/ \$[0-9$]* = /d
46830/^yydestructor:/d' stderr >at-stderr
46831mv at-stderr stderr
46832# 2. Create the reference error message.
46833cat >expout <<'_ATEOF'
468341.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
46835_ATEOF
46836
46837# 3. If locations are not used, remove them.
46838
46839# 4. If error-verbose is not used, strip the`, unexpected....' part.
46840
46841# 5. Check
46842$at_traceoff
46843echo "calc.at:622: cat stderr"
46844echo calc.at:622 >$at_check_line_file
46845( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
46846at_status=$?
46847grep '^ *+' $at_stder1 >&2
46848grep -v '^ *+' $at_stder1 >$at_stderr
46849at_failed=false
46850$at_diff $at_devnull $at_stderr || at_failed=:
46851$at_diff expout $at_stdout || at_failed=:
46852case $at_status in
46853   77) echo 77 > $at_status_file
46854            exit 77;;
46855   0) ;;
46856   *) echo "calc.at:622: exit code was $at_status, expected 0"
46857      at_failed=:;;
46858esac
46859if $at_failed; then
46860
46861  echo 1 > $at_status_file
46862  exit 1
46863fi
46864
46865$at_traceon
46866
46867
46868cat >input <<'_ATEOF'
46869error
46870_ATEOF
46871
46872$at_traceoff
46873echo "calc.at:622: \$PREPARSER ./calc input"
46874echo calc.at:622 >$at_check_line_file
46875( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
46876at_status=$?
46877grep '^ *+' $at_stder1 >&2
46878grep -v '^ *+' $at_stder1 >$at_stderr
46879at_failed=false
46880echo stderr:; tee stderr <$at_stderr
46881$at_diff $at_devnull $at_stdout || at_failed=:
46882case $at_status in
46883   77) echo 77 > $at_status_file
46884            exit 77;;
46885   1) ;;
46886   *) echo "calc.at:622: exit code was $at_status, expected 1"
46887      at_failed=:;;
46888esac
46889if $at_failed; then
46890
46891  echo 1 > $at_status_file
46892  exit 1
46893fi
46894
46895$at_traceon
46896
46897
46898# Normalize the observed and expected error messages, depending upon the
46899# options.
46900# 1. Remove the traces from observed.
46901sed '/^Starting/d
46902/^Entering/d
46903/^Stack/d
46904/^Reading/d
46905/^Reducing/d
46906/^Shifting/d
46907/^state/d
46908/^Cleanup:/d
46909/^Error:/d
46910/^Next/d
46911/^Discarding/d
46912/ \$[0-9$]* = /d
46913/^yydestructor:/d' stderr >at-stderr
46914mv at-stderr stderr
46915# 2. Create the reference error message.
46916cat >expout <<'_ATEOF'
469171.0: syntax error, unexpected $undefined
46918_ATEOF
46919
46920# 3. If locations are not used, remove them.
46921
46922# 4. If error-verbose is not used, strip the`, unexpected....' part.
46923
46924# 5. Check
46925$at_traceoff
46926echo "calc.at:622: cat stderr"
46927echo calc.at:622 >$at_check_line_file
46928( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
46929at_status=$?
46930grep '^ *+' $at_stder1 >&2
46931grep -v '^ *+' $at_stder1 >$at_stderr
46932at_failed=false
46933$at_diff $at_devnull $at_stderr || at_failed=:
46934$at_diff expout $at_stdout || at_failed=:
46935case $at_status in
46936   77) echo 77 > $at_status_file
46937            exit 77;;
46938   0) ;;
46939   *) echo "calc.at:622: exit code was $at_status, expected 0"
46940      at_failed=:;;
46941esac
46942if $at_failed; then
46943
46944  echo 1 > $at_status_file
46945  exit 1
46946fi
46947
46948$at_traceon
46949
46950
46951cat >input <<'_ATEOF'
469521 = 2 = 3
46953_ATEOF
46954
46955$at_traceoff
46956echo "calc.at:622: \$PREPARSER ./calc input"
46957echo calc.at:622 >$at_check_line_file
46958( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
46959at_status=$?
46960grep '^ *+' $at_stder1 >&2
46961grep -v '^ *+' $at_stder1 >$at_stderr
46962at_failed=false
46963echo stderr:; tee stderr <$at_stderr
46964$at_diff $at_devnull $at_stdout || at_failed=:
46965case $at_status in
46966   77) echo 77 > $at_status_file
46967            exit 77;;
46968   1) ;;
46969   *) echo "calc.at:622: exit code was $at_status, expected 1"
46970      at_failed=:;;
46971esac
46972if $at_failed; then
46973
46974  echo 1 > $at_status_file
46975  exit 1
46976fi
46977
46978$at_traceon
46979
46980
46981# Normalize the observed and expected error messages, depending upon the
46982# options.
46983# 1. Remove the traces from observed.
46984sed '/^Starting/d
46985/^Entering/d
46986/^Stack/d
46987/^Reading/d
46988/^Reducing/d
46989/^Shifting/d
46990/^state/d
46991/^Cleanup:/d
46992/^Error:/d
46993/^Next/d
46994/^Discarding/d
46995/ \$[0-9$]* = /d
46996/^yydestructor:/d' stderr >at-stderr
46997mv at-stderr stderr
46998# 2. Create the reference error message.
46999cat >expout <<'_ATEOF'
470001.6: syntax error, unexpected '='
47001_ATEOF
47002
47003# 3. If locations are not used, remove them.
47004
47005# 4. If error-verbose is not used, strip the`, unexpected....' part.
47006
47007# 5. Check
47008$at_traceoff
47009echo "calc.at:622: cat stderr"
47010echo calc.at:622 >$at_check_line_file
47011( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
47012at_status=$?
47013grep '^ *+' $at_stder1 >&2
47014grep -v '^ *+' $at_stder1 >$at_stderr
47015at_failed=false
47016$at_diff $at_devnull $at_stderr || at_failed=:
47017$at_diff expout $at_stdout || at_failed=:
47018case $at_status in
47019   77) echo 77 > $at_status_file
47020            exit 77;;
47021   0) ;;
47022   *) echo "calc.at:622: exit code was $at_status, expected 0"
47023      at_failed=:;;
47024esac
47025if $at_failed; then
47026
47027  echo 1 > $at_status_file
47028  exit 1
47029fi
47030
47031$at_traceon
47032
47033
47034cat >input <<'_ATEOF'
47035
47036+1
47037_ATEOF
47038
47039$at_traceoff
47040echo "calc.at:622: \$PREPARSER ./calc input"
47041echo calc.at:622 >$at_check_line_file
47042( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
47043at_status=$?
47044grep '^ *+' $at_stder1 >&2
47045grep -v '^ *+' $at_stder1 >$at_stderr
47046at_failed=false
47047echo stderr:; tee stderr <$at_stderr
47048$at_diff $at_devnull $at_stdout || at_failed=:
47049case $at_status in
47050   77) echo 77 > $at_status_file
47051            exit 77;;
47052   1) ;;
47053   *) echo "calc.at:622: exit code was $at_status, expected 1"
47054      at_failed=:;;
47055esac
47056if $at_failed; then
47057
47058  echo 1 > $at_status_file
47059  exit 1
47060fi
47061
47062$at_traceon
47063
47064
47065# Normalize the observed and expected error messages, depending upon the
47066# options.
47067# 1. Remove the traces from observed.
47068sed '/^Starting/d
47069/^Entering/d
47070/^Stack/d
47071/^Reading/d
47072/^Reducing/d
47073/^Shifting/d
47074/^state/d
47075/^Cleanup:/d
47076/^Error:/d
47077/^Next/d
47078/^Discarding/d
47079/ \$[0-9$]* = /d
47080/^yydestructor:/d' stderr >at-stderr
47081mv at-stderr stderr
47082# 2. Create the reference error message.
47083cat >expout <<'_ATEOF'
470842.0: syntax error, unexpected '+'
47085_ATEOF
47086
47087# 3. If locations are not used, remove them.
47088
47089# 4. If error-verbose is not used, strip the`, unexpected....' part.
47090
47091# 5. Check
47092$at_traceoff
47093echo "calc.at:622: cat stderr"
47094echo calc.at:622 >$at_check_line_file
47095( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
47096at_status=$?
47097grep '^ *+' $at_stder1 >&2
47098grep -v '^ *+' $at_stder1 >$at_stderr
47099at_failed=false
47100$at_diff $at_devnull $at_stderr || at_failed=:
47101$at_diff expout $at_stdout || at_failed=:
47102case $at_status in
47103   77) echo 77 > $at_status_file
47104            exit 77;;
47105   0) ;;
47106   *) echo "calc.at:622: exit code was $at_status, expected 0"
47107      at_failed=:;;
47108esac
47109if $at_failed; then
47110
47111  echo 1 > $at_status_file
47112  exit 1
47113fi
47114
47115$at_traceon
47116
47117
47118# Exercise error messages with EOF: work on an empty file.
47119$at_traceoff
47120echo "calc.at:622: \$PREPARSER ./calc /dev/null"
47121echo calc.at:622 >$at_check_line_file
47122( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
47123at_status=$?
47124grep '^ *+' $at_stder1 >&2
47125grep -v '^ *+' $at_stder1 >$at_stderr
47126at_failed=false
47127echo stderr:; tee stderr <$at_stderr
47128$at_diff $at_devnull $at_stdout || at_failed=:
47129case $at_status in
47130   77) echo 77 > $at_status_file
47131            exit 77;;
47132   1) ;;
47133   *) echo "calc.at:622: exit code was $at_status, expected 1"
47134      at_failed=:;;
47135esac
47136if $at_failed; then
47137
47138  echo 1 > $at_status_file
47139  exit 1
47140fi
47141
47142$at_traceon
47143
47144
47145# Normalize the observed and expected error messages, depending upon the
47146# options.
47147# 1. Remove the traces from observed.
47148sed '/^Starting/d
47149/^Entering/d
47150/^Stack/d
47151/^Reading/d
47152/^Reducing/d
47153/^Shifting/d
47154/^state/d
47155/^Cleanup:/d
47156/^Error:/d
47157/^Next/d
47158/^Discarding/d
47159/ \$[0-9$]* = /d
47160/^yydestructor:/d' stderr >at-stderr
47161mv at-stderr stderr
47162# 2. Create the reference error message.
47163cat >expout <<'_ATEOF'
471641.0: syntax error, unexpected end of input
47165_ATEOF
47166
47167# 3. If locations are not used, remove them.
47168
47169# 4. If error-verbose is not used, strip the`, unexpected....' part.
47170
47171# 5. Check
47172$at_traceoff
47173echo "calc.at:622: cat stderr"
47174echo calc.at:622 >$at_check_line_file
47175( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
47176at_status=$?
47177grep '^ *+' $at_stder1 >&2
47178grep -v '^ *+' $at_stder1 >$at_stderr
47179at_failed=false
47180$at_diff $at_devnull $at_stderr || at_failed=:
47181$at_diff expout $at_stdout || at_failed=:
47182case $at_status in
47183   77) echo 77 > $at_status_file
47184            exit 77;;
47185   0) ;;
47186   *) echo "calc.at:622: exit code was $at_status, expected 0"
47187      at_failed=:;;
47188esac
47189if $at_failed; then
47190
47191  echo 1 > $at_status_file
47192  exit 1
47193fi
47194
47195$at_traceon
47196
47197
47198
47199# Exercise the error token: without it, we die at the first error,
47200# hence be sure to
47201#
47202# - have several errors which exercise different shift/discardings
47203#   - (): nothing to pop, nothing to discard
47204#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
47205#   - (* * *): nothing to pop, a lot to discard
47206#   - (1 + 2 * *): some to pop and discard
47207#
47208# - test the action associated to `error'
47209#
47210# - check the look-ahead that triggers an error is not discarded
47211#   when we enter error recovery.  Below, the look-ahead causing the
47212#   first error is ")", which is needed to recover from the error and
47213#   produce the "0" that triggers the "0 != 1" error.
47214#
47215cat >input <<'_ATEOF'
47216() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
47217_ATEOF
47218
47219$at_traceoff
47220echo "calc.at:622: \$PREPARSER ./calc input"
47221echo calc.at:622 >$at_check_line_file
47222( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
47223at_status=$?
47224grep '^ *+' $at_stder1 >&2
47225grep -v '^ *+' $at_stder1 >$at_stderr
47226at_failed=false
47227echo stderr:; tee stderr <$at_stderr
47228$at_diff $at_devnull $at_stdout || at_failed=:
47229case $at_status in
47230   77) echo 77 > $at_status_file
47231            exit 77;;
47232   0) ;;
47233   *) echo "calc.at:622: exit code was $at_status, expected 0"
47234      at_failed=:;;
47235esac
47236if $at_failed; then
47237
47238  echo 1 > $at_status_file
47239  exit 1
47240fi
47241
47242$at_traceon
47243
47244
47245# Normalize the observed and expected error messages, depending upon the
47246# options.
47247# 1. Remove the traces from observed.
47248sed '/^Starting/d
47249/^Entering/d
47250/^Stack/d
47251/^Reading/d
47252/^Reducing/d
47253/^Shifting/d
47254/^state/d
47255/^Cleanup:/d
47256/^Error:/d
47257/^Next/d
47258/^Discarding/d
47259/ \$[0-9$]* = /d
47260/^yydestructor:/d' stderr >at-stderr
47261mv at-stderr stderr
47262# 2. Create the reference error message.
47263cat >expout <<'_ATEOF'
472641.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
472651.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
472661.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
472671.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
47268calc: error: 4444 != 1
47269_ATEOF
47270
47271# 3. If locations are not used, remove them.
47272
47273# 4. If error-verbose is not used, strip the`, unexpected....' part.
47274
47275# 5. Check
47276$at_traceoff
47277echo "calc.at:622: cat stderr"
47278echo calc.at:622 >$at_check_line_file
47279( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
47280at_status=$?
47281grep '^ *+' $at_stder1 >&2
47282grep -v '^ *+' $at_stder1 >$at_stderr
47283at_failed=false
47284$at_diff $at_devnull $at_stderr || at_failed=:
47285$at_diff expout $at_stdout || at_failed=:
47286case $at_status in
47287   77) echo 77 > $at_status_file
47288            exit 77;;
47289   0) ;;
47290   *) echo "calc.at:622: exit code was $at_status, expected 0"
47291      at_failed=:;;
47292esac
47293if $at_failed; then
47294
47295  echo 1 > $at_status_file
47296  exit 1
47297fi
47298
47299$at_traceon
47300
47301
47302
47303# The same, but this time exercising explicitly triggered syntax errors.
47304# POSIX says the look-ahead causing the error should not be discarded.
47305cat >input <<'_ATEOF'
47306(!) + (0 0) = 1
47307_ATEOF
47308
47309$at_traceoff
47310echo "calc.at:622: \$PREPARSER ./calc input"
47311echo calc.at:622 >$at_check_line_file
47312( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
47313at_status=$?
47314grep '^ *+' $at_stder1 >&2
47315grep -v '^ *+' $at_stder1 >$at_stderr
47316at_failed=false
47317echo stderr:; tee stderr <$at_stderr
47318$at_diff $at_devnull $at_stdout || at_failed=:
47319case $at_status in
47320   77) echo 77 > $at_status_file
47321            exit 77;;
47322   0) ;;
47323   *) echo "calc.at:622: exit code was $at_status, expected 0"
47324      at_failed=:;;
47325esac
47326if $at_failed; then
47327
47328  echo 1 > $at_status_file
47329  exit 1
47330fi
47331
47332$at_traceon
47333
47334
47335# Normalize the observed and expected error messages, depending upon the
47336# options.
47337# 1. Remove the traces from observed.
47338sed '/^Starting/d
47339/^Entering/d
47340/^Stack/d
47341/^Reading/d
47342/^Reducing/d
47343/^Shifting/d
47344/^state/d
47345/^Cleanup:/d
47346/^Error:/d
47347/^Next/d
47348/^Discarding/d
47349/ \$[0-9$]* = /d
47350/^yydestructor:/d' stderr >at-stderr
47351mv at-stderr stderr
47352# 2. Create the reference error message.
47353cat >expout <<'_ATEOF'
473541.9: syntax error, unexpected number
47355calc: error: 2222 != 1
47356_ATEOF
47357
47358# 3. If locations are not used, remove them.
47359
47360# 4. If error-verbose is not used, strip the`, unexpected....' part.
47361
47362# 5. Check
47363$at_traceoff
47364echo "calc.at:622: cat stderr"
47365echo calc.at:622 >$at_check_line_file
47366( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
47367at_status=$?
47368grep '^ *+' $at_stder1 >&2
47369grep -v '^ *+' $at_stder1 >$at_stderr
47370at_failed=false
47371$at_diff $at_devnull $at_stderr || at_failed=:
47372$at_diff expout $at_stdout || at_failed=:
47373case $at_status in
47374   77) echo 77 > $at_status_file
47375            exit 77;;
47376   0) ;;
47377   *) echo "calc.at:622: exit code was $at_status, expected 0"
47378      at_failed=:;;
47379esac
47380if $at_failed; then
47381
47382  echo 1 > $at_status_file
47383  exit 1
47384fi
47385
47386$at_traceon
47387
47388
47389cat >input <<'_ATEOF'
47390(- *) + (0 0) = 1
47391_ATEOF
47392
47393$at_traceoff
47394echo "calc.at:622: \$PREPARSER ./calc input"
47395echo calc.at:622 >$at_check_line_file
47396( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
47397at_status=$?
47398grep '^ *+' $at_stder1 >&2
47399grep -v '^ *+' $at_stder1 >$at_stderr
47400at_failed=false
47401echo stderr:; tee stderr <$at_stderr
47402$at_diff $at_devnull $at_stdout || at_failed=:
47403case $at_status in
47404   77) echo 77 > $at_status_file
47405            exit 77;;
47406   0) ;;
47407   *) echo "calc.at:622: exit code was $at_status, expected 0"
47408      at_failed=:;;
47409esac
47410if $at_failed; then
47411
47412  echo 1 > $at_status_file
47413  exit 1
47414fi
47415
47416$at_traceon
47417
47418
47419# Normalize the observed and expected error messages, depending upon the
47420# options.
47421# 1. Remove the traces from observed.
47422sed '/^Starting/d
47423/^Entering/d
47424/^Stack/d
47425/^Reading/d
47426/^Reducing/d
47427/^Shifting/d
47428/^state/d
47429/^Cleanup:/d
47430/^Error:/d
47431/^Next/d
47432/^Discarding/d
47433/ \$[0-9$]* = /d
47434/^yydestructor:/d' stderr >at-stderr
47435mv at-stderr stderr
47436# 2. Create the reference error message.
47437cat >expout <<'_ATEOF'
474381.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
474391.11: syntax error, unexpected number
47440calc: error: 2222 != 1
47441_ATEOF
47442
47443# 3. If locations are not used, remove them.
47444
47445# 4. If error-verbose is not used, strip the`, unexpected....' part.
47446
47447# 5. Check
47448$at_traceoff
47449echo "calc.at:622: cat stderr"
47450echo calc.at:622 >$at_check_line_file
47451( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
47452at_status=$?
47453grep '^ *+' $at_stder1 >&2
47454grep -v '^ *+' $at_stder1 >$at_stderr
47455at_failed=false
47456$at_diff $at_devnull $at_stderr || at_failed=:
47457$at_diff expout $at_stdout || at_failed=:
47458case $at_status in
47459   77) echo 77 > $at_status_file
47460            exit 77;;
47461   0) ;;
47462   *) echo "calc.at:622: exit code was $at_status, expected 0"
47463      at_failed=:;;
47464esac
47465if $at_failed; then
47466
47467  echo 1 > $at_status_file
47468  exit 1
47469fi
47470
47471$at_traceon
47472
47473
47474
47475
47476
47477
47478
47479
47480
47481
47482
47483
47484
47485
47486
47487
47488
47489
47490
47491
47492
47493
47494
47495
47496      $at_traceoff
47497      $at_times_p && times >$at_times_file
47498    ) 5>&1 2>&1 | eval $at_tee_pipe
47499    at_status=`cat $at_status_file`
47500    ;;
47501
47502  100 ) # 100. calc.at:624: Calculator %skeleton "lalr1.cc" %defines %locations %error-verbose %debug %name-prefix="calc" %verbose %yacc
47503    at_setup_line='calc.at:624'
47504    at_desc='Calculator %skeleton "lalr1.cc" %defines %locations %error-verbose %debug %name-prefix="calc" %verbose %yacc'
47505    $at_quiet $ECHO_N "100: Calculator %skeleton "lalr1.cc" %defines %locations %error-verbose %debug %name-prefix="calc" %verbose %yacc$ECHO_C"
47506    at_xfail=no
47507    (
47508      echo "100. calc.at:624: testing ..."
47509      $at_traceon
47510
47511
47512
47513
47514
47515
47516
47517
47518# Using yacc.c?
47519
47520
47521
47522
47523
47524
47525
47526# yyerror receives the location if %location & %pure & (%glr or %parse-param).
47527
47528# yyerror always sees the locations (when activated), except if
47529# yacc & pure & !param.
47530
47531
47532# The interface is pure: either because %pure-parser, or because we
47533# are using the C++ parsers.
47534
47535
47536
47537
47538
47539
47540
47541
47542
47543
47544
47545
47546cat >calc.y <<'_ATEOF'
47547%{
47548#ifdef HAVE_CONFIG_H
47549# include <config.h>
47550  /* We don't need perfect functions for these tests. */
47551# undef malloc
47552# undef memcmp
47553# undef realloc
47554#endif
47555%}
47556
47557/* Infix notation calculator--calc */
47558%skeleton "lalr1.cc" %defines %locations %error-verbose %debug %name-prefix="calc" %verbose %yacc
47559%define "global_tokens_and_yystype"
47560%{
47561#include <stdio.h>
47562
47563#include <stdlib.h>
47564#include <string.h>
47565#if HAVE_UNISTD_H
47566# include <unistd.h>
47567#else
47568# undef alarm
47569# define alarm(seconds) /* empty */
47570#endif
47571#include <ctype.h>
47572#define USE(Var)
47573
47574/* Exercise pre-prologue dependency to %union.  */
47575typedef int semantic_value;
47576
47577static semantic_value global_result = 0;
47578static int global_count = 0;
47579%}
47580
47581/* Exercise %union. */
47582%union
47583{
47584  semantic_value ival;
47585};
47586
47587%{
47588static int power (int base, int exponent);
47589#ifndef YYLTYPE
47590# define YYLTYPE calc::location
47591#endif
47592#define first_line   begin.line
47593#define first_column begin.column
47594#define last_line    end.line
47595#define last_column  end.column
47596
47597static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
47598static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp);
47599static void unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c);
47600%}
47601
47602/* The lalr1.cc skeleton, for backward compatibility, defines
47603   a constructor for position that initializes the filename.  The
47604   glr.cc skeleton does not (and in fact cannot: location/position
47605   are stored in a union, from which objects with constructors are
47606   excluded in C++. */
47607%initial-action {
47608  @$.initialize (0);
47609}
47610
47611
47612/* Bison Declarations */
47613%token CALC_EOF 0 "end of input"
47614%token <ival> NUM "number"
47615%type  <ival> exp
47616
47617%nonassoc '=' /* comparison	       */
47618%left '-' '+'
47619%left '*' '/'
47620%left NEG     /* negation--unary minus */
47621%right '^'    /* exponentiation        */
47622
47623/* Grammar follows */
47624%%
47625input:
47626  line
47627| input line         {  }
47628;
47629
47630line:
47631  '\n'
47632| exp '\n'           { USE ($1); }
47633;
47634
47635exp:
47636  NUM                { $$ = $1;             }
47637| exp '=' exp
47638  {
47639    if ($1 != $3)
47640      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
47641    $$ = $1;
47642  }
47643| exp '+' exp        { $$ = $1 + $3;        }
47644| exp '-' exp        { $$ = $1 - $3;        }
47645| exp '*' exp        { $$ = $1 * $3;        }
47646| exp '/' exp        { $$ = $1 / $3;        }
47647| '-' exp  %prec NEG { $$ = -$2;            }
47648| exp '^' exp        { $$ = power ($1, $3); }
47649| '(' exp ')'        { $$ = $2;             }
47650| '(' error ')'      { $$ = 1111;           }
47651| '!'                { $$ = 0; YYERROR;     }
47652| '-' error          { $$ = 0; YYERROR;     }
47653;
47654%%
47655/* The input.  */
47656static FILE *input;
47657
47658/* A C++ error reporting function.  */
47659void
47660calc::parser::error (const location& l, const std::string& m)
47661{
47662  (void) l;
47663  std::cerr << l << ": " << m << std::endl;
47664}
47665
47666int
47667yyparse ()
47668{
47669  calc::parser parser;
47670  parser.set_debug_level (!!YYDEBUG);
47671  return parser.parse ();
47672}
47673
47674
47675
47676
47677static YYLTYPE last_yylloc;
47678
47679static int
47680get_char (YYSTYPE *lvalp, YYLTYPE *llocp)
47681{
47682  int res = getc (input);
47683  (void) lvalp;(void) llocp;
47684
47685  last_yylloc = (*llocp);
47686  if (res == '\n')
47687    {
47688      (*llocp).last_line++;
47689      (*llocp).last_column = 0;
47690    }
47691  else
47692    (*llocp).last_column++;
47693
47694  return res;
47695}
47696
47697
47698static void
47699unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c)
47700{
47701  (void) lvalp;(void) llocp;
47702
47703  /* Wrong when C == `\n'. */
47704  (*llocp) = last_yylloc;
47705
47706  ungetc (c, input);
47707}
47708
47709static int
47710read_signed_integer (YYSTYPE *lvalp, YYLTYPE *llocp)
47711{
47712  int c = get_char (lvalp, llocp);
47713  int sign = 1;
47714  int n = 0;
47715
47716  (void) lvalp;(void) llocp;
47717  if (c == '-')
47718    {
47719      c = get_char (lvalp, llocp);
47720      sign = -1;
47721    }
47722
47723  while (isdigit (c))
47724    {
47725      n = 10 * n + (c - '0');
47726      c = get_char (lvalp, llocp);
47727    }
47728
47729  unget_char (lvalp, llocp,  c);
47730
47731  return sign * n;
47732}
47733
47734
47735
47736/*---------------------------------------------------------------.
47737| Lexical analyzer returns an integer on the stack and the token |
47738| NUM, or the ASCII character read if not a number.  Skips all   |
47739| blanks and tabs, returns 0 for EOF.                            |
47740`---------------------------------------------------------------*/
47741
47742static int
47743yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
47744{
47745  static int init = 1;
47746  int c;
47747
47748  if (init)
47749    {
47750      init = 0;
47751
47752      (*llocp).last_column = 0;
47753      (*llocp).last_line = 1;
47754
47755    }
47756
47757
47758 (*llocp).first_column = (*llocp).last_column;
47759  (*llocp).first_line   = (*llocp).last_line;
47760
47761
47762  /* Skip white space.  */
47763  while ((c = get_char (lvalp, llocp)) == ' ' || c == '\t')
47764    {
47765     (*llocp).first_column = (*llocp).last_column;
47766      (*llocp).first_line   = (*llocp).last_line;
47767
47768    }
47769
47770  /* process numbers   */
47771  if (c == '.' || isdigit (c))
47772    {
47773      unget_char (lvalp, llocp,  c);
47774      (*lvalp).ival = read_signed_integer (lvalp, llocp);
47775      return NUM;
47776    }
47777
47778  /* Return end-of-file.  */
47779  if (c == EOF)
47780    return CALC_EOF;
47781
47782  /* Return single chars. */
47783  return c;
47784}
47785
47786static int
47787power (int base, int exponent)
47788{
47789  int res = 1;
47790  if (exponent < 0)
47791    exit (3);
47792  for (/* Niente */; exponent; --exponent)
47793    res *= base;
47794  return res;
47795}
47796
47797
47798int
47799main (int argc, const char **argv)
47800{
47801  semantic_value result = 0;
47802  int count = 0;
47803  int status;
47804
47805  /* This used to be alarm (10), but that isn't enough time for
47806     a July 1995 vintage DEC Alphastation 200 4/100 system,
47807     according to Nelson H. F. Beebe.  100 seconds is enough.  */
47808  alarm (100);
47809
47810  if (argc == 2)
47811    input = fopen (argv[1], "r");
47812  else
47813    input = stdin;
47814
47815  if (!input)
47816    {
47817      perror (argv[1]);
47818      return 3;
47819    }
47820
47821
47822  status = yyparse ();
47823  if (global_result != result)
47824    abort ();
47825  if (global_count != count)
47826    abort ();
47827  return status;
47828}
47829_ATEOF
47830
47831
47832
47833
47834
47835$at_traceoff
47836echo "calc.at:624: bison -o calc.cc calc.y"
47837echo calc.at:624 >$at_check_line_file
47838( $at_traceon; bison -o calc.cc calc.y ) >$at_stdout 2>$at_stder1
47839at_status=$?
47840grep '^ *+' $at_stder1 >&2
47841grep -v '^ *+' $at_stder1 >$at_stderr
47842at_failed=false
47843$at_diff $at_devnull $at_stderr || at_failed=:
47844$at_diff $at_devnull $at_stdout || at_failed=:
47845case $at_status in
47846   77) echo 77 > $at_status_file
47847            exit 77;;
47848   0) ;;
47849   *) echo "calc.at:624: exit code was $at_status, expected 0"
47850      at_failed=:;;
47851esac
47852if $at_failed; then
47853
47854  echo 1 > $at_status_file
47855  exit 1
47856fi
47857
47858$at_traceon
47859
47860
47861$at_traceoff
47862echo "calc.at:624: \$BISON_CXX_WORKS"
47863echo calc.at:624 >$at_check_line_file
47864( $at_traceon; $BISON_CXX_WORKS ) >$at_stdout 2>$at_stder1
47865at_status=$?
47866grep '^ *+' $at_stder1 >&2
47867grep -v '^ *+' $at_stder1 >$at_stderr
47868at_failed=false
47869echo stderr:; cat $at_stderr
47870echo stdout:; cat $at_stdout
47871case $at_status in
47872   77) echo 77 > $at_status_file
47873            exit 77;;
47874   0) ;;
47875   *) echo "calc.at:624: exit code was $at_status, expected 0"
47876      at_failed=:;;
47877esac
47878if $at_failed; then
47879
47880  echo 1 > $at_status_file
47881  exit 1
47882fi
47883
47884$at_traceon
47885
47886$at_traceoff
47887echo "calc.at:624: \$CXX \$CXXFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.cc \$LIBS"
47888echo calc.at:624 >$at_check_line_file
47889( $at_traceon; $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o calc calc.cc $LIBS ) >$at_stdout 2>$at_stder1
47890at_status=$?
47891grep '^ *+' $at_stder1 >&2
47892grep -v '^ *+' $at_stder1 >$at_stderr
47893at_failed=false
47894echo stderr:; cat $at_stderr
47895echo stdout:; cat $at_stdout
47896case $at_status in
47897   77) echo 77 > $at_status_file
47898            exit 77;;
47899   0) ;;
47900   *) echo "calc.at:624: exit code was $at_status, expected 0"
47901      at_failed=:;;
47902esac
47903if $at_failed; then
47904
47905  echo 1 > $at_status_file
47906  exit 1
47907fi
47908
47909$at_traceon
47910
47911
47912# Test the priorities.
47913cat >input <<'_ATEOF'
479141 + 2 * 3 = 7
479151 + 2 * -3 = -5
47916
47917-1^2 = -1
47918(-1)^2 = 1
47919
47920---1 = -1
47921
479221 - 2 - 3 = -4
479231 - (2 - 3) = 2
47924
479252^2^3 = 256
47926(2^2)^3 = 64
47927_ATEOF
47928
47929$at_traceoff
47930echo "calc.at:624: \$PREPARSER ./calc input"
47931echo calc.at:624 >$at_check_line_file
47932( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
47933at_status=$?
47934grep '^ *+' $at_stder1 >&2
47935grep -v '^ *+' $at_stder1 >$at_stderr
47936at_failed=false
47937echo stderr:; tee stderr <$at_stderr
47938$at_diff $at_devnull $at_stdout || at_failed=:
47939case $at_status in
47940   77) echo 77 > $at_status_file
47941            exit 77;;
47942   0) ;;
47943   *) echo "calc.at:624: exit code was $at_status, expected 0"
47944      at_failed=:;;
47945esac
47946if $at_failed; then
47947
47948  echo 1 > $at_status_file
47949  exit 1
47950fi
47951
47952$at_traceon
47953
47954
47955
47956# Some syntax errors.
47957cat >input <<'_ATEOF'
479580 0
47959_ATEOF
47960
47961$at_traceoff
47962echo "calc.at:624: \$PREPARSER ./calc input"
47963echo calc.at:624 >$at_check_line_file
47964( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
47965at_status=$?
47966grep '^ *+' $at_stder1 >&2
47967grep -v '^ *+' $at_stder1 >$at_stderr
47968at_failed=false
47969echo stderr:; tee stderr <$at_stderr
47970$at_diff $at_devnull $at_stdout || at_failed=:
47971case $at_status in
47972   77) echo 77 > $at_status_file
47973            exit 77;;
47974   1) ;;
47975   *) echo "calc.at:624: exit code was $at_status, expected 1"
47976      at_failed=:;;
47977esac
47978if $at_failed; then
47979
47980  echo 1 > $at_status_file
47981  exit 1
47982fi
47983
47984$at_traceon
47985
47986
47987# Normalize the observed and expected error messages, depending upon the
47988# options.
47989# 1. Remove the traces from observed.
47990sed '/^Starting/d
47991/^Entering/d
47992/^Stack/d
47993/^Reading/d
47994/^Reducing/d
47995/^Shifting/d
47996/^state/d
47997/^Cleanup:/d
47998/^Error:/d
47999/^Next/d
48000/^Discarding/d
48001/ \$[0-9$]* = /d
48002/^yydestructor:/d' stderr >at-stderr
48003mv at-stderr stderr
48004# 2. Create the reference error message.
48005cat >expout <<'_ATEOF'
480061.2: syntax error, unexpected number
48007_ATEOF
48008
48009# 3. If locations are not used, remove them.
48010
48011# 4. If error-verbose is not used, strip the`, unexpected....' part.
48012
48013# 5. Check
48014$at_traceoff
48015echo "calc.at:624: cat stderr"
48016echo calc.at:624 >$at_check_line_file
48017( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
48018at_status=$?
48019grep '^ *+' $at_stder1 >&2
48020grep -v '^ *+' $at_stder1 >$at_stderr
48021at_failed=false
48022$at_diff $at_devnull $at_stderr || at_failed=:
48023$at_diff expout $at_stdout || at_failed=:
48024case $at_status in
48025   77) echo 77 > $at_status_file
48026            exit 77;;
48027   0) ;;
48028   *) echo "calc.at:624: exit code was $at_status, expected 0"
48029      at_failed=:;;
48030esac
48031if $at_failed; then
48032
48033  echo 1 > $at_status_file
48034  exit 1
48035fi
48036
48037$at_traceon
48038
48039
48040cat >input <<'_ATEOF'
480411//2
48042_ATEOF
48043
48044$at_traceoff
48045echo "calc.at:624: \$PREPARSER ./calc input"
48046echo calc.at:624 >$at_check_line_file
48047( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
48048at_status=$?
48049grep '^ *+' $at_stder1 >&2
48050grep -v '^ *+' $at_stder1 >$at_stderr
48051at_failed=false
48052echo stderr:; tee stderr <$at_stderr
48053$at_diff $at_devnull $at_stdout || at_failed=:
48054case $at_status in
48055   77) echo 77 > $at_status_file
48056            exit 77;;
48057   1) ;;
48058   *) echo "calc.at:624: exit code was $at_status, expected 1"
48059      at_failed=:;;
48060esac
48061if $at_failed; then
48062
48063  echo 1 > $at_status_file
48064  exit 1
48065fi
48066
48067$at_traceon
48068
48069
48070# Normalize the observed and expected error messages, depending upon the
48071# options.
48072# 1. Remove the traces from observed.
48073sed '/^Starting/d
48074/^Entering/d
48075/^Stack/d
48076/^Reading/d
48077/^Reducing/d
48078/^Shifting/d
48079/^state/d
48080/^Cleanup:/d
48081/^Error:/d
48082/^Next/d
48083/^Discarding/d
48084/ \$[0-9$]* = /d
48085/^yydestructor:/d' stderr >at-stderr
48086mv at-stderr stderr
48087# 2. Create the reference error message.
48088cat >expout <<'_ATEOF'
480891.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
48090_ATEOF
48091
48092# 3. If locations are not used, remove them.
48093
48094# 4. If error-verbose is not used, strip the`, unexpected....' part.
48095
48096# 5. Check
48097$at_traceoff
48098echo "calc.at:624: cat stderr"
48099echo calc.at:624 >$at_check_line_file
48100( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
48101at_status=$?
48102grep '^ *+' $at_stder1 >&2
48103grep -v '^ *+' $at_stder1 >$at_stderr
48104at_failed=false
48105$at_diff $at_devnull $at_stderr || at_failed=:
48106$at_diff expout $at_stdout || at_failed=:
48107case $at_status in
48108   77) echo 77 > $at_status_file
48109            exit 77;;
48110   0) ;;
48111   *) echo "calc.at:624: exit code was $at_status, expected 0"
48112      at_failed=:;;
48113esac
48114if $at_failed; then
48115
48116  echo 1 > $at_status_file
48117  exit 1
48118fi
48119
48120$at_traceon
48121
48122
48123cat >input <<'_ATEOF'
48124error
48125_ATEOF
48126
48127$at_traceoff
48128echo "calc.at:624: \$PREPARSER ./calc input"
48129echo calc.at:624 >$at_check_line_file
48130( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
48131at_status=$?
48132grep '^ *+' $at_stder1 >&2
48133grep -v '^ *+' $at_stder1 >$at_stderr
48134at_failed=false
48135echo stderr:; tee stderr <$at_stderr
48136$at_diff $at_devnull $at_stdout || at_failed=:
48137case $at_status in
48138   77) echo 77 > $at_status_file
48139            exit 77;;
48140   1) ;;
48141   *) echo "calc.at:624: exit code was $at_status, expected 1"
48142      at_failed=:;;
48143esac
48144if $at_failed; then
48145
48146  echo 1 > $at_status_file
48147  exit 1
48148fi
48149
48150$at_traceon
48151
48152
48153# Normalize the observed and expected error messages, depending upon the
48154# options.
48155# 1. Remove the traces from observed.
48156sed '/^Starting/d
48157/^Entering/d
48158/^Stack/d
48159/^Reading/d
48160/^Reducing/d
48161/^Shifting/d
48162/^state/d
48163/^Cleanup:/d
48164/^Error:/d
48165/^Next/d
48166/^Discarding/d
48167/ \$[0-9$]* = /d
48168/^yydestructor:/d' stderr >at-stderr
48169mv at-stderr stderr
48170# 2. Create the reference error message.
48171cat >expout <<'_ATEOF'
481721.0: syntax error, unexpected $undefined
48173_ATEOF
48174
48175# 3. If locations are not used, remove them.
48176
48177# 4. If error-verbose is not used, strip the`, unexpected....' part.
48178
48179# 5. Check
48180$at_traceoff
48181echo "calc.at:624: cat stderr"
48182echo calc.at:624 >$at_check_line_file
48183( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
48184at_status=$?
48185grep '^ *+' $at_stder1 >&2
48186grep -v '^ *+' $at_stder1 >$at_stderr
48187at_failed=false
48188$at_diff $at_devnull $at_stderr || at_failed=:
48189$at_diff expout $at_stdout || at_failed=:
48190case $at_status in
48191   77) echo 77 > $at_status_file
48192            exit 77;;
48193   0) ;;
48194   *) echo "calc.at:624: exit code was $at_status, expected 0"
48195      at_failed=:;;
48196esac
48197if $at_failed; then
48198
48199  echo 1 > $at_status_file
48200  exit 1
48201fi
48202
48203$at_traceon
48204
48205
48206cat >input <<'_ATEOF'
482071 = 2 = 3
48208_ATEOF
48209
48210$at_traceoff
48211echo "calc.at:624: \$PREPARSER ./calc input"
48212echo calc.at:624 >$at_check_line_file
48213( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
48214at_status=$?
48215grep '^ *+' $at_stder1 >&2
48216grep -v '^ *+' $at_stder1 >$at_stderr
48217at_failed=false
48218echo stderr:; tee stderr <$at_stderr
48219$at_diff $at_devnull $at_stdout || at_failed=:
48220case $at_status in
48221   77) echo 77 > $at_status_file
48222            exit 77;;
48223   1) ;;
48224   *) echo "calc.at:624: exit code was $at_status, expected 1"
48225      at_failed=:;;
48226esac
48227if $at_failed; then
48228
48229  echo 1 > $at_status_file
48230  exit 1
48231fi
48232
48233$at_traceon
48234
48235
48236# Normalize the observed and expected error messages, depending upon the
48237# options.
48238# 1. Remove the traces from observed.
48239sed '/^Starting/d
48240/^Entering/d
48241/^Stack/d
48242/^Reading/d
48243/^Reducing/d
48244/^Shifting/d
48245/^state/d
48246/^Cleanup:/d
48247/^Error:/d
48248/^Next/d
48249/^Discarding/d
48250/ \$[0-9$]* = /d
48251/^yydestructor:/d' stderr >at-stderr
48252mv at-stderr stderr
48253# 2. Create the reference error message.
48254cat >expout <<'_ATEOF'
482551.6: syntax error, unexpected '='
48256_ATEOF
48257
48258# 3. If locations are not used, remove them.
48259
48260# 4. If error-verbose is not used, strip the`, unexpected....' part.
48261
48262# 5. Check
48263$at_traceoff
48264echo "calc.at:624: cat stderr"
48265echo calc.at:624 >$at_check_line_file
48266( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
48267at_status=$?
48268grep '^ *+' $at_stder1 >&2
48269grep -v '^ *+' $at_stder1 >$at_stderr
48270at_failed=false
48271$at_diff $at_devnull $at_stderr || at_failed=:
48272$at_diff expout $at_stdout || at_failed=:
48273case $at_status in
48274   77) echo 77 > $at_status_file
48275            exit 77;;
48276   0) ;;
48277   *) echo "calc.at:624: exit code was $at_status, expected 0"
48278      at_failed=:;;
48279esac
48280if $at_failed; then
48281
48282  echo 1 > $at_status_file
48283  exit 1
48284fi
48285
48286$at_traceon
48287
48288
48289cat >input <<'_ATEOF'
48290
48291+1
48292_ATEOF
48293
48294$at_traceoff
48295echo "calc.at:624: \$PREPARSER ./calc input"
48296echo calc.at:624 >$at_check_line_file
48297( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
48298at_status=$?
48299grep '^ *+' $at_stder1 >&2
48300grep -v '^ *+' $at_stder1 >$at_stderr
48301at_failed=false
48302echo stderr:; tee stderr <$at_stderr
48303$at_diff $at_devnull $at_stdout || at_failed=:
48304case $at_status in
48305   77) echo 77 > $at_status_file
48306            exit 77;;
48307   1) ;;
48308   *) echo "calc.at:624: exit code was $at_status, expected 1"
48309      at_failed=:;;
48310esac
48311if $at_failed; then
48312
48313  echo 1 > $at_status_file
48314  exit 1
48315fi
48316
48317$at_traceon
48318
48319
48320# Normalize the observed and expected error messages, depending upon the
48321# options.
48322# 1. Remove the traces from observed.
48323sed '/^Starting/d
48324/^Entering/d
48325/^Stack/d
48326/^Reading/d
48327/^Reducing/d
48328/^Shifting/d
48329/^state/d
48330/^Cleanup:/d
48331/^Error:/d
48332/^Next/d
48333/^Discarding/d
48334/ \$[0-9$]* = /d
48335/^yydestructor:/d' stderr >at-stderr
48336mv at-stderr stderr
48337# 2. Create the reference error message.
48338cat >expout <<'_ATEOF'
483392.0: syntax error, unexpected '+'
48340_ATEOF
48341
48342# 3. If locations are not used, remove them.
48343
48344# 4. If error-verbose is not used, strip the`, unexpected....' part.
48345
48346# 5. Check
48347$at_traceoff
48348echo "calc.at:624: cat stderr"
48349echo calc.at:624 >$at_check_line_file
48350( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
48351at_status=$?
48352grep '^ *+' $at_stder1 >&2
48353grep -v '^ *+' $at_stder1 >$at_stderr
48354at_failed=false
48355$at_diff $at_devnull $at_stderr || at_failed=:
48356$at_diff expout $at_stdout || at_failed=:
48357case $at_status in
48358   77) echo 77 > $at_status_file
48359            exit 77;;
48360   0) ;;
48361   *) echo "calc.at:624: exit code was $at_status, expected 0"
48362      at_failed=:;;
48363esac
48364if $at_failed; then
48365
48366  echo 1 > $at_status_file
48367  exit 1
48368fi
48369
48370$at_traceon
48371
48372
48373# Exercise error messages with EOF: work on an empty file.
48374$at_traceoff
48375echo "calc.at:624: \$PREPARSER ./calc /dev/null"
48376echo calc.at:624 >$at_check_line_file
48377( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
48378at_status=$?
48379grep '^ *+' $at_stder1 >&2
48380grep -v '^ *+' $at_stder1 >$at_stderr
48381at_failed=false
48382echo stderr:; tee stderr <$at_stderr
48383$at_diff $at_devnull $at_stdout || at_failed=:
48384case $at_status in
48385   77) echo 77 > $at_status_file
48386            exit 77;;
48387   1) ;;
48388   *) echo "calc.at:624: exit code was $at_status, expected 1"
48389      at_failed=:;;
48390esac
48391if $at_failed; then
48392
48393  echo 1 > $at_status_file
48394  exit 1
48395fi
48396
48397$at_traceon
48398
48399
48400# Normalize the observed and expected error messages, depending upon the
48401# options.
48402# 1. Remove the traces from observed.
48403sed '/^Starting/d
48404/^Entering/d
48405/^Stack/d
48406/^Reading/d
48407/^Reducing/d
48408/^Shifting/d
48409/^state/d
48410/^Cleanup:/d
48411/^Error:/d
48412/^Next/d
48413/^Discarding/d
48414/ \$[0-9$]* = /d
48415/^yydestructor:/d' stderr >at-stderr
48416mv at-stderr stderr
48417# 2. Create the reference error message.
48418cat >expout <<'_ATEOF'
484191.0: syntax error, unexpected end of input
48420_ATEOF
48421
48422# 3. If locations are not used, remove them.
48423
48424# 4. If error-verbose is not used, strip the`, unexpected....' part.
48425
48426# 5. Check
48427$at_traceoff
48428echo "calc.at:624: cat stderr"
48429echo calc.at:624 >$at_check_line_file
48430( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
48431at_status=$?
48432grep '^ *+' $at_stder1 >&2
48433grep -v '^ *+' $at_stder1 >$at_stderr
48434at_failed=false
48435$at_diff $at_devnull $at_stderr || at_failed=:
48436$at_diff expout $at_stdout || at_failed=:
48437case $at_status in
48438   77) echo 77 > $at_status_file
48439            exit 77;;
48440   0) ;;
48441   *) echo "calc.at:624: exit code was $at_status, expected 0"
48442      at_failed=:;;
48443esac
48444if $at_failed; then
48445
48446  echo 1 > $at_status_file
48447  exit 1
48448fi
48449
48450$at_traceon
48451
48452
48453
48454# Exercise the error token: without it, we die at the first error,
48455# hence be sure to
48456#
48457# - have several errors which exercise different shift/discardings
48458#   - (): nothing to pop, nothing to discard
48459#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
48460#   - (* * *): nothing to pop, a lot to discard
48461#   - (1 + 2 * *): some to pop and discard
48462#
48463# - test the action associated to `error'
48464#
48465# - check the look-ahead that triggers an error is not discarded
48466#   when we enter error recovery.  Below, the look-ahead causing the
48467#   first error is ")", which is needed to recover from the error and
48468#   produce the "0" that triggers the "0 != 1" error.
48469#
48470cat >input <<'_ATEOF'
48471() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
48472_ATEOF
48473
48474$at_traceoff
48475echo "calc.at:624: \$PREPARSER ./calc input"
48476echo calc.at:624 >$at_check_line_file
48477( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
48478at_status=$?
48479grep '^ *+' $at_stder1 >&2
48480grep -v '^ *+' $at_stder1 >$at_stderr
48481at_failed=false
48482echo stderr:; tee stderr <$at_stderr
48483$at_diff $at_devnull $at_stdout || at_failed=:
48484case $at_status in
48485   77) echo 77 > $at_status_file
48486            exit 77;;
48487   0) ;;
48488   *) echo "calc.at:624: exit code was $at_status, expected 0"
48489      at_failed=:;;
48490esac
48491if $at_failed; then
48492
48493  echo 1 > $at_status_file
48494  exit 1
48495fi
48496
48497$at_traceon
48498
48499
48500# Normalize the observed and expected error messages, depending upon the
48501# options.
48502# 1. Remove the traces from observed.
48503sed '/^Starting/d
48504/^Entering/d
48505/^Stack/d
48506/^Reading/d
48507/^Reducing/d
48508/^Shifting/d
48509/^state/d
48510/^Cleanup:/d
48511/^Error:/d
48512/^Next/d
48513/^Discarding/d
48514/ \$[0-9$]* = /d
48515/^yydestructor:/d' stderr >at-stderr
48516mv at-stderr stderr
48517# 2. Create the reference error message.
48518cat >expout <<'_ATEOF'
485191.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
485201.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
485211.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
485221.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
48523calc: error: 4444 != 1
48524_ATEOF
48525
48526# 3. If locations are not used, remove them.
48527
48528# 4. If error-verbose is not used, strip the`, unexpected....' part.
48529
48530# 5. Check
48531$at_traceoff
48532echo "calc.at:624: cat stderr"
48533echo calc.at:624 >$at_check_line_file
48534( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
48535at_status=$?
48536grep '^ *+' $at_stder1 >&2
48537grep -v '^ *+' $at_stder1 >$at_stderr
48538at_failed=false
48539$at_diff $at_devnull $at_stderr || at_failed=:
48540$at_diff expout $at_stdout || at_failed=:
48541case $at_status in
48542   77) echo 77 > $at_status_file
48543            exit 77;;
48544   0) ;;
48545   *) echo "calc.at:624: exit code was $at_status, expected 0"
48546      at_failed=:;;
48547esac
48548if $at_failed; then
48549
48550  echo 1 > $at_status_file
48551  exit 1
48552fi
48553
48554$at_traceon
48555
48556
48557
48558# The same, but this time exercising explicitly triggered syntax errors.
48559# POSIX says the look-ahead causing the error should not be discarded.
48560cat >input <<'_ATEOF'
48561(!) + (0 0) = 1
48562_ATEOF
48563
48564$at_traceoff
48565echo "calc.at:624: \$PREPARSER ./calc input"
48566echo calc.at:624 >$at_check_line_file
48567( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
48568at_status=$?
48569grep '^ *+' $at_stder1 >&2
48570grep -v '^ *+' $at_stder1 >$at_stderr
48571at_failed=false
48572echo stderr:; tee stderr <$at_stderr
48573$at_diff $at_devnull $at_stdout || at_failed=:
48574case $at_status in
48575   77) echo 77 > $at_status_file
48576            exit 77;;
48577   0) ;;
48578   *) echo "calc.at:624: exit code was $at_status, expected 0"
48579      at_failed=:;;
48580esac
48581if $at_failed; then
48582
48583  echo 1 > $at_status_file
48584  exit 1
48585fi
48586
48587$at_traceon
48588
48589
48590# Normalize the observed and expected error messages, depending upon the
48591# options.
48592# 1. Remove the traces from observed.
48593sed '/^Starting/d
48594/^Entering/d
48595/^Stack/d
48596/^Reading/d
48597/^Reducing/d
48598/^Shifting/d
48599/^state/d
48600/^Cleanup:/d
48601/^Error:/d
48602/^Next/d
48603/^Discarding/d
48604/ \$[0-9$]* = /d
48605/^yydestructor:/d' stderr >at-stderr
48606mv at-stderr stderr
48607# 2. Create the reference error message.
48608cat >expout <<'_ATEOF'
486091.9: syntax error, unexpected number
48610calc: error: 2222 != 1
48611_ATEOF
48612
48613# 3. If locations are not used, remove them.
48614
48615# 4. If error-verbose is not used, strip the`, unexpected....' part.
48616
48617# 5. Check
48618$at_traceoff
48619echo "calc.at:624: cat stderr"
48620echo calc.at:624 >$at_check_line_file
48621( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
48622at_status=$?
48623grep '^ *+' $at_stder1 >&2
48624grep -v '^ *+' $at_stder1 >$at_stderr
48625at_failed=false
48626$at_diff $at_devnull $at_stderr || at_failed=:
48627$at_diff expout $at_stdout || at_failed=:
48628case $at_status in
48629   77) echo 77 > $at_status_file
48630            exit 77;;
48631   0) ;;
48632   *) echo "calc.at:624: exit code was $at_status, expected 0"
48633      at_failed=:;;
48634esac
48635if $at_failed; then
48636
48637  echo 1 > $at_status_file
48638  exit 1
48639fi
48640
48641$at_traceon
48642
48643
48644cat >input <<'_ATEOF'
48645(- *) + (0 0) = 1
48646_ATEOF
48647
48648$at_traceoff
48649echo "calc.at:624: \$PREPARSER ./calc input"
48650echo calc.at:624 >$at_check_line_file
48651( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
48652at_status=$?
48653grep '^ *+' $at_stder1 >&2
48654grep -v '^ *+' $at_stder1 >$at_stderr
48655at_failed=false
48656echo stderr:; tee stderr <$at_stderr
48657$at_diff $at_devnull $at_stdout || at_failed=:
48658case $at_status in
48659   77) echo 77 > $at_status_file
48660            exit 77;;
48661   0) ;;
48662   *) echo "calc.at:624: exit code was $at_status, expected 0"
48663      at_failed=:;;
48664esac
48665if $at_failed; then
48666
48667  echo 1 > $at_status_file
48668  exit 1
48669fi
48670
48671$at_traceon
48672
48673
48674# Normalize the observed and expected error messages, depending upon the
48675# options.
48676# 1. Remove the traces from observed.
48677sed '/^Starting/d
48678/^Entering/d
48679/^Stack/d
48680/^Reading/d
48681/^Reducing/d
48682/^Shifting/d
48683/^state/d
48684/^Cleanup:/d
48685/^Error:/d
48686/^Next/d
48687/^Discarding/d
48688/ \$[0-9$]* = /d
48689/^yydestructor:/d' stderr >at-stderr
48690mv at-stderr stderr
48691# 2. Create the reference error message.
48692cat >expout <<'_ATEOF'
486931.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
486941.11: syntax error, unexpected number
48695calc: error: 2222 != 1
48696_ATEOF
48697
48698# 3. If locations are not used, remove them.
48699
48700# 4. If error-verbose is not used, strip the`, unexpected....' part.
48701
48702# 5. Check
48703$at_traceoff
48704echo "calc.at:624: cat stderr"
48705echo calc.at:624 >$at_check_line_file
48706( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
48707at_status=$?
48708grep '^ *+' $at_stder1 >&2
48709grep -v '^ *+' $at_stder1 >$at_stderr
48710at_failed=false
48711$at_diff $at_devnull $at_stderr || at_failed=:
48712$at_diff expout $at_stdout || at_failed=:
48713case $at_status in
48714   77) echo 77 > $at_status_file
48715            exit 77;;
48716   0) ;;
48717   *) echo "calc.at:624: exit code was $at_status, expected 0"
48718      at_failed=:;;
48719esac
48720if $at_failed; then
48721
48722  echo 1 > $at_status_file
48723  exit 1
48724fi
48725
48726$at_traceon
48727
48728
48729
48730
48731
48732
48733
48734
48735
48736
48737
48738
48739
48740
48741
48742
48743
48744
48745
48746
48747
48748
48749
48750
48751      $at_traceoff
48752      $at_times_p && times >$at_times_file
48753    ) 5>&1 2>&1 | eval $at_tee_pipe
48754    at_status=`cat $at_status_file`
48755    ;;
48756
48757  101 ) # 101. calc.at:626: Calculator %skeleton "lalr1.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc
48758    at_setup_line='calc.at:626'
48759    at_desc='Calculator %skeleton "lalr1.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc'
48760    $at_quiet $ECHO_N "101: Calculator %skeleton "lalr1.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc$ECHO_C"
48761    at_xfail=no
48762    (
48763      echo "101. calc.at:626: testing ..."
48764      $at_traceon
48765
48766
48767
48768
48769
48770
48771
48772
48773# Using yacc.c?
48774
48775
48776
48777
48778
48779
48780
48781# yyerror receives the location if %location & %pure & (%glr or %parse-param).
48782
48783# yyerror always sees the locations (when activated), except if
48784# yacc & pure & !param.
48785
48786
48787# The interface is pure: either because %pure-parser, or because we
48788# are using the C++ parsers.
48789
48790
48791
48792
48793
48794
48795
48796
48797
48798
48799
48800
48801cat >calc.y <<'_ATEOF'
48802%{
48803#ifdef HAVE_CONFIG_H
48804# include <config.h>
48805  /* We don't need perfect functions for these tests. */
48806# undef malloc
48807# undef memcmp
48808# undef realloc
48809#endif
48810%}
48811
48812/* Infix notation calculator--calc */
48813%skeleton "lalr1.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc
48814%define "global_tokens_and_yystype"
48815%{
48816#include <stdio.h>
48817
48818#include <stdlib.h>
48819#include <string.h>
48820#if HAVE_UNISTD_H
48821# include <unistd.h>
48822#else
48823# undef alarm
48824# define alarm(seconds) /* empty */
48825#endif
48826#include <ctype.h>
48827#define USE(Var)
48828
48829/* Exercise pre-prologue dependency to %union.  */
48830typedef int semantic_value;
48831
48832static semantic_value global_result = 0;
48833static int global_count = 0;
48834%}
48835
48836/* Exercise %union. */
48837%union
48838{
48839  semantic_value ival;
48840};
48841
48842%{
48843static int power (int base, int exponent);
48844#ifndef YYLTYPE
48845# define YYLTYPE calc::location
48846#endif
48847#define first_line   begin.line
48848#define first_column begin.column
48849#define last_line    end.line
48850#define last_column  end.column
48851
48852static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
48853static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp);
48854static void unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c);
48855%}
48856
48857/* The lalr1.cc skeleton, for backward compatibility, defines
48858   a constructor for position that initializes the filename.  The
48859   glr.cc skeleton does not (and in fact cannot: location/position
48860   are stored in a union, from which objects with constructors are
48861   excluded in C++. */
48862%initial-action {
48863  @$.initialize (0);
48864}
48865
48866
48867/* Bison Declarations */
48868%token CALC_EOF 0 "end of input"
48869%token <ival> NUM "number"
48870%type  <ival> exp
48871
48872%nonassoc '=' /* comparison	       */
48873%left '-' '+'
48874%left '*' '/'
48875%left NEG     /* negation--unary minus */
48876%right '^'    /* exponentiation        */
48877
48878/* Grammar follows */
48879%%
48880input:
48881  line
48882| input line         {  }
48883;
48884
48885line:
48886  '\n'
48887| exp '\n'           { USE ($1); }
48888;
48889
48890exp:
48891  NUM                { $$ = $1;             }
48892| exp '=' exp
48893  {
48894    if ($1 != $3)
48895      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
48896    $$ = $1;
48897  }
48898| exp '+' exp        { $$ = $1 + $3;        }
48899| exp '-' exp        { $$ = $1 - $3;        }
48900| exp '*' exp        { $$ = $1 * $3;        }
48901| exp '/' exp        { $$ = $1 / $3;        }
48902| '-' exp  %prec NEG { $$ = -$2;            }
48903| exp '^' exp        { $$ = power ($1, $3); }
48904| '(' exp ')'        { $$ = $2;             }
48905| '(' error ')'      { $$ = 1111;           }
48906| '!'                { $$ = 0; YYERROR;     }
48907| '-' error          { $$ = 0; YYERROR;     }
48908;
48909%%
48910/* The input.  */
48911static FILE *input;
48912
48913/* A C++ error reporting function.  */
48914void
48915calc::parser::error (const location& l, const std::string& m)
48916{
48917  (void) l;
48918  std::cerr << l << ": " << m << std::endl;
48919}
48920
48921int
48922yyparse ()
48923{
48924  calc::parser parser;
48925  parser.set_debug_level (!!YYDEBUG);
48926  return parser.parse ();
48927}
48928
48929
48930
48931
48932static YYLTYPE last_yylloc;
48933
48934static int
48935get_char (YYSTYPE *lvalp, YYLTYPE *llocp)
48936{
48937  int res = getc (input);
48938  (void) lvalp;(void) llocp;
48939
48940  last_yylloc = (*llocp);
48941  if (res == '\n')
48942    {
48943      (*llocp).last_line++;
48944      (*llocp).last_column = 0;
48945    }
48946  else
48947    (*llocp).last_column++;
48948
48949  return res;
48950}
48951
48952
48953static void
48954unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c)
48955{
48956  (void) lvalp;(void) llocp;
48957
48958  /* Wrong when C == `\n'. */
48959  (*llocp) = last_yylloc;
48960
48961  ungetc (c, input);
48962}
48963
48964static int
48965read_signed_integer (YYSTYPE *lvalp, YYLTYPE *llocp)
48966{
48967  int c = get_char (lvalp, llocp);
48968  int sign = 1;
48969  int n = 0;
48970
48971  (void) lvalp;(void) llocp;
48972  if (c == '-')
48973    {
48974      c = get_char (lvalp, llocp);
48975      sign = -1;
48976    }
48977
48978  while (isdigit (c))
48979    {
48980      n = 10 * n + (c - '0');
48981      c = get_char (lvalp, llocp);
48982    }
48983
48984  unget_char (lvalp, llocp,  c);
48985
48986  return sign * n;
48987}
48988
48989
48990
48991/*---------------------------------------------------------------.
48992| Lexical analyzer returns an integer on the stack and the token |
48993| NUM, or the ASCII character read if not a number.  Skips all   |
48994| blanks and tabs, returns 0 for EOF.                            |
48995`---------------------------------------------------------------*/
48996
48997static int
48998yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
48999{
49000  static int init = 1;
49001  int c;
49002
49003  if (init)
49004    {
49005      init = 0;
49006
49007      (*llocp).last_column = 0;
49008      (*llocp).last_line = 1;
49009
49010    }
49011
49012
49013 (*llocp).first_column = (*llocp).last_column;
49014  (*llocp).first_line   = (*llocp).last_line;
49015
49016
49017  /* Skip white space.  */
49018  while ((c = get_char (lvalp, llocp)) == ' ' || c == '\t')
49019    {
49020     (*llocp).first_column = (*llocp).last_column;
49021      (*llocp).first_line   = (*llocp).last_line;
49022
49023    }
49024
49025  /* process numbers   */
49026  if (c == '.' || isdigit (c))
49027    {
49028      unget_char (lvalp, llocp,  c);
49029      (*lvalp).ival = read_signed_integer (lvalp, llocp);
49030      return NUM;
49031    }
49032
49033  /* Return end-of-file.  */
49034  if (c == EOF)
49035    return CALC_EOF;
49036
49037  /* Return single chars. */
49038  return c;
49039}
49040
49041static int
49042power (int base, int exponent)
49043{
49044  int res = 1;
49045  if (exponent < 0)
49046    exit (3);
49047  for (/* Niente */; exponent; --exponent)
49048    res *= base;
49049  return res;
49050}
49051
49052
49053int
49054main (int argc, const char **argv)
49055{
49056  semantic_value result = 0;
49057  int count = 0;
49058  int status;
49059
49060  /* This used to be alarm (10), but that isn't enough time for
49061     a July 1995 vintage DEC Alphastation 200 4/100 system,
49062     according to Nelson H. F. Beebe.  100 seconds is enough.  */
49063  alarm (100);
49064
49065  if (argc == 2)
49066    input = fopen (argv[1], "r");
49067  else
49068    input = stdin;
49069
49070  if (!input)
49071    {
49072      perror (argv[1]);
49073      return 3;
49074    }
49075
49076
49077  status = yyparse ();
49078  if (global_result != result)
49079    abort ();
49080  if (global_count != count)
49081    abort ();
49082  return status;
49083}
49084_ATEOF
49085
49086
49087
49088
49089
49090$at_traceoff
49091echo "calc.at:626: bison -o calc.cc calc.y"
49092echo calc.at:626 >$at_check_line_file
49093( $at_traceon; bison -o calc.cc calc.y ) >$at_stdout 2>$at_stder1
49094at_status=$?
49095grep '^ *+' $at_stder1 >&2
49096grep -v '^ *+' $at_stder1 >$at_stderr
49097at_failed=false
49098$at_diff $at_devnull $at_stderr || at_failed=:
49099$at_diff $at_devnull $at_stdout || at_failed=:
49100case $at_status in
49101   77) echo 77 > $at_status_file
49102            exit 77;;
49103   0) ;;
49104   *) echo "calc.at:626: exit code was $at_status, expected 0"
49105      at_failed=:;;
49106esac
49107if $at_failed; then
49108
49109  echo 1 > $at_status_file
49110  exit 1
49111fi
49112
49113$at_traceon
49114
49115
49116$at_traceoff
49117echo "calc.at:626: \$BISON_CXX_WORKS"
49118echo calc.at:626 >$at_check_line_file
49119( $at_traceon; $BISON_CXX_WORKS ) >$at_stdout 2>$at_stder1
49120at_status=$?
49121grep '^ *+' $at_stder1 >&2
49122grep -v '^ *+' $at_stder1 >$at_stderr
49123at_failed=false
49124echo stderr:; cat $at_stderr
49125echo stdout:; cat $at_stdout
49126case $at_status in
49127   77) echo 77 > $at_status_file
49128            exit 77;;
49129   0) ;;
49130   *) echo "calc.at:626: exit code was $at_status, expected 0"
49131      at_failed=:;;
49132esac
49133if $at_failed; then
49134
49135  echo 1 > $at_status_file
49136  exit 1
49137fi
49138
49139$at_traceon
49140
49141$at_traceoff
49142echo "calc.at:626: \$CXX \$CXXFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.cc \$LIBS"
49143echo calc.at:626 >$at_check_line_file
49144( $at_traceon; $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o calc calc.cc $LIBS ) >$at_stdout 2>$at_stder1
49145at_status=$?
49146grep '^ *+' $at_stder1 >&2
49147grep -v '^ *+' $at_stder1 >$at_stderr
49148at_failed=false
49149echo stderr:; cat $at_stderr
49150echo stdout:; cat $at_stdout
49151case $at_status in
49152   77) echo 77 > $at_status_file
49153            exit 77;;
49154   0) ;;
49155   *) echo "calc.at:626: exit code was $at_status, expected 0"
49156      at_failed=:;;
49157esac
49158if $at_failed; then
49159
49160  echo 1 > $at_status_file
49161  exit 1
49162fi
49163
49164$at_traceon
49165
49166
49167# Test the priorities.
49168cat >input <<'_ATEOF'
491691 + 2 * 3 = 7
491701 + 2 * -3 = -5
49171
49172-1^2 = -1
49173(-1)^2 = 1
49174
49175---1 = -1
49176
491771 - 2 - 3 = -4
491781 - (2 - 3) = 2
49179
491802^2^3 = 256
49181(2^2)^3 = 64
49182_ATEOF
49183
49184$at_traceoff
49185echo "calc.at:626: \$PREPARSER ./calc input"
49186echo calc.at:626 >$at_check_line_file
49187( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
49188at_status=$?
49189grep '^ *+' $at_stder1 >&2
49190grep -v '^ *+' $at_stder1 >$at_stderr
49191at_failed=false
49192echo stderr:; tee stderr <$at_stderr
49193$at_diff $at_devnull $at_stdout || at_failed=:
49194case $at_status in
49195   77) echo 77 > $at_status_file
49196            exit 77;;
49197   0) ;;
49198   *) echo "calc.at:626: exit code was $at_status, expected 0"
49199      at_failed=:;;
49200esac
49201if $at_failed; then
49202
49203  echo 1 > $at_status_file
49204  exit 1
49205fi
49206
49207$at_traceon
49208
49209
49210
49211# Some syntax errors.
49212cat >input <<'_ATEOF'
492130 0
49214_ATEOF
49215
49216$at_traceoff
49217echo "calc.at:626: \$PREPARSER ./calc input"
49218echo calc.at:626 >$at_check_line_file
49219( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
49220at_status=$?
49221grep '^ *+' $at_stder1 >&2
49222grep -v '^ *+' $at_stder1 >$at_stderr
49223at_failed=false
49224echo stderr:; tee stderr <$at_stderr
49225$at_diff $at_devnull $at_stdout || at_failed=:
49226case $at_status in
49227   77) echo 77 > $at_status_file
49228            exit 77;;
49229   1) ;;
49230   *) echo "calc.at:626: exit code was $at_status, expected 1"
49231      at_failed=:;;
49232esac
49233if $at_failed; then
49234
49235  echo 1 > $at_status_file
49236  exit 1
49237fi
49238
49239$at_traceon
49240
49241
49242# Normalize the observed and expected error messages, depending upon the
49243# options.
49244# 1. Remove the traces from observed.
49245sed '/^Starting/d
49246/^Entering/d
49247/^Stack/d
49248/^Reading/d
49249/^Reducing/d
49250/^Shifting/d
49251/^state/d
49252/^Cleanup:/d
49253/^Error:/d
49254/^Next/d
49255/^Discarding/d
49256/ \$[0-9$]* = /d
49257/^yydestructor:/d' stderr >at-stderr
49258mv at-stderr stderr
49259# 2. Create the reference error message.
49260cat >expout <<'_ATEOF'
492611.2: syntax error, unexpected number
49262_ATEOF
49263
49264# 3. If locations are not used, remove them.
49265
49266# 4. If error-verbose is not used, strip the`, unexpected....' part.
49267
49268# 5. Check
49269$at_traceoff
49270echo "calc.at:626: cat stderr"
49271echo calc.at:626 >$at_check_line_file
49272( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
49273at_status=$?
49274grep '^ *+' $at_stder1 >&2
49275grep -v '^ *+' $at_stder1 >$at_stderr
49276at_failed=false
49277$at_diff $at_devnull $at_stderr || at_failed=:
49278$at_diff expout $at_stdout || at_failed=:
49279case $at_status in
49280   77) echo 77 > $at_status_file
49281            exit 77;;
49282   0) ;;
49283   *) echo "calc.at:626: exit code was $at_status, expected 0"
49284      at_failed=:;;
49285esac
49286if $at_failed; then
49287
49288  echo 1 > $at_status_file
49289  exit 1
49290fi
49291
49292$at_traceon
49293
49294
49295cat >input <<'_ATEOF'
492961//2
49297_ATEOF
49298
49299$at_traceoff
49300echo "calc.at:626: \$PREPARSER ./calc input"
49301echo calc.at:626 >$at_check_line_file
49302( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
49303at_status=$?
49304grep '^ *+' $at_stder1 >&2
49305grep -v '^ *+' $at_stder1 >$at_stderr
49306at_failed=false
49307echo stderr:; tee stderr <$at_stderr
49308$at_diff $at_devnull $at_stdout || at_failed=:
49309case $at_status in
49310   77) echo 77 > $at_status_file
49311            exit 77;;
49312   1) ;;
49313   *) echo "calc.at:626: exit code was $at_status, expected 1"
49314      at_failed=:;;
49315esac
49316if $at_failed; then
49317
49318  echo 1 > $at_status_file
49319  exit 1
49320fi
49321
49322$at_traceon
49323
49324
49325# Normalize the observed and expected error messages, depending upon the
49326# options.
49327# 1. Remove the traces from observed.
49328sed '/^Starting/d
49329/^Entering/d
49330/^Stack/d
49331/^Reading/d
49332/^Reducing/d
49333/^Shifting/d
49334/^state/d
49335/^Cleanup:/d
49336/^Error:/d
49337/^Next/d
49338/^Discarding/d
49339/ \$[0-9$]* = /d
49340/^yydestructor:/d' stderr >at-stderr
49341mv at-stderr stderr
49342# 2. Create the reference error message.
49343cat >expout <<'_ATEOF'
493441.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
49345_ATEOF
49346
49347# 3. If locations are not used, remove them.
49348
49349# 4. If error-verbose is not used, strip the`, unexpected....' part.
49350
49351# 5. Check
49352$at_traceoff
49353echo "calc.at:626: cat stderr"
49354echo calc.at:626 >$at_check_line_file
49355( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
49356at_status=$?
49357grep '^ *+' $at_stder1 >&2
49358grep -v '^ *+' $at_stder1 >$at_stderr
49359at_failed=false
49360$at_diff $at_devnull $at_stderr || at_failed=:
49361$at_diff expout $at_stdout || at_failed=:
49362case $at_status in
49363   77) echo 77 > $at_status_file
49364            exit 77;;
49365   0) ;;
49366   *) echo "calc.at:626: exit code was $at_status, expected 0"
49367      at_failed=:;;
49368esac
49369if $at_failed; then
49370
49371  echo 1 > $at_status_file
49372  exit 1
49373fi
49374
49375$at_traceon
49376
49377
49378cat >input <<'_ATEOF'
49379error
49380_ATEOF
49381
49382$at_traceoff
49383echo "calc.at:626: \$PREPARSER ./calc input"
49384echo calc.at:626 >$at_check_line_file
49385( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
49386at_status=$?
49387grep '^ *+' $at_stder1 >&2
49388grep -v '^ *+' $at_stder1 >$at_stderr
49389at_failed=false
49390echo stderr:; tee stderr <$at_stderr
49391$at_diff $at_devnull $at_stdout || at_failed=:
49392case $at_status in
49393   77) echo 77 > $at_status_file
49394            exit 77;;
49395   1) ;;
49396   *) echo "calc.at:626: exit code was $at_status, expected 1"
49397      at_failed=:;;
49398esac
49399if $at_failed; then
49400
49401  echo 1 > $at_status_file
49402  exit 1
49403fi
49404
49405$at_traceon
49406
49407
49408# Normalize the observed and expected error messages, depending upon the
49409# options.
49410# 1. Remove the traces from observed.
49411sed '/^Starting/d
49412/^Entering/d
49413/^Stack/d
49414/^Reading/d
49415/^Reducing/d
49416/^Shifting/d
49417/^state/d
49418/^Cleanup:/d
49419/^Error:/d
49420/^Next/d
49421/^Discarding/d
49422/ \$[0-9$]* = /d
49423/^yydestructor:/d' stderr >at-stderr
49424mv at-stderr stderr
49425# 2. Create the reference error message.
49426cat >expout <<'_ATEOF'
494271.0: syntax error, unexpected $undefined
49428_ATEOF
49429
49430# 3. If locations are not used, remove them.
49431
49432# 4. If error-verbose is not used, strip the`, unexpected....' part.
49433
49434# 5. Check
49435$at_traceoff
49436echo "calc.at:626: cat stderr"
49437echo calc.at:626 >$at_check_line_file
49438( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
49439at_status=$?
49440grep '^ *+' $at_stder1 >&2
49441grep -v '^ *+' $at_stder1 >$at_stderr
49442at_failed=false
49443$at_diff $at_devnull $at_stderr || at_failed=:
49444$at_diff expout $at_stdout || at_failed=:
49445case $at_status in
49446   77) echo 77 > $at_status_file
49447            exit 77;;
49448   0) ;;
49449   *) echo "calc.at:626: exit code was $at_status, expected 0"
49450      at_failed=:;;
49451esac
49452if $at_failed; then
49453
49454  echo 1 > $at_status_file
49455  exit 1
49456fi
49457
49458$at_traceon
49459
49460
49461cat >input <<'_ATEOF'
494621 = 2 = 3
49463_ATEOF
49464
49465$at_traceoff
49466echo "calc.at:626: \$PREPARSER ./calc input"
49467echo calc.at:626 >$at_check_line_file
49468( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
49469at_status=$?
49470grep '^ *+' $at_stder1 >&2
49471grep -v '^ *+' $at_stder1 >$at_stderr
49472at_failed=false
49473echo stderr:; tee stderr <$at_stderr
49474$at_diff $at_devnull $at_stdout || at_failed=:
49475case $at_status in
49476   77) echo 77 > $at_status_file
49477            exit 77;;
49478   1) ;;
49479   *) echo "calc.at:626: exit code was $at_status, expected 1"
49480      at_failed=:;;
49481esac
49482if $at_failed; then
49483
49484  echo 1 > $at_status_file
49485  exit 1
49486fi
49487
49488$at_traceon
49489
49490
49491# Normalize the observed and expected error messages, depending upon the
49492# options.
49493# 1. Remove the traces from observed.
49494sed '/^Starting/d
49495/^Entering/d
49496/^Stack/d
49497/^Reading/d
49498/^Reducing/d
49499/^Shifting/d
49500/^state/d
49501/^Cleanup:/d
49502/^Error:/d
49503/^Next/d
49504/^Discarding/d
49505/ \$[0-9$]* = /d
49506/^yydestructor:/d' stderr >at-stderr
49507mv at-stderr stderr
49508# 2. Create the reference error message.
49509cat >expout <<'_ATEOF'
495101.6: syntax error, unexpected '='
49511_ATEOF
49512
49513# 3. If locations are not used, remove them.
49514
49515# 4. If error-verbose is not used, strip the`, unexpected....' part.
49516
49517# 5. Check
49518$at_traceoff
49519echo "calc.at:626: cat stderr"
49520echo calc.at:626 >$at_check_line_file
49521( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
49522at_status=$?
49523grep '^ *+' $at_stder1 >&2
49524grep -v '^ *+' $at_stder1 >$at_stderr
49525at_failed=false
49526$at_diff $at_devnull $at_stderr || at_failed=:
49527$at_diff expout $at_stdout || at_failed=:
49528case $at_status in
49529   77) echo 77 > $at_status_file
49530            exit 77;;
49531   0) ;;
49532   *) echo "calc.at:626: exit code was $at_status, expected 0"
49533      at_failed=:;;
49534esac
49535if $at_failed; then
49536
49537  echo 1 > $at_status_file
49538  exit 1
49539fi
49540
49541$at_traceon
49542
49543
49544cat >input <<'_ATEOF'
49545
49546+1
49547_ATEOF
49548
49549$at_traceoff
49550echo "calc.at:626: \$PREPARSER ./calc input"
49551echo calc.at:626 >$at_check_line_file
49552( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
49553at_status=$?
49554grep '^ *+' $at_stder1 >&2
49555grep -v '^ *+' $at_stder1 >$at_stderr
49556at_failed=false
49557echo stderr:; tee stderr <$at_stderr
49558$at_diff $at_devnull $at_stdout || at_failed=:
49559case $at_status in
49560   77) echo 77 > $at_status_file
49561            exit 77;;
49562   1) ;;
49563   *) echo "calc.at:626: exit code was $at_status, expected 1"
49564      at_failed=:;;
49565esac
49566if $at_failed; then
49567
49568  echo 1 > $at_status_file
49569  exit 1
49570fi
49571
49572$at_traceon
49573
49574
49575# Normalize the observed and expected error messages, depending upon the
49576# options.
49577# 1. Remove the traces from observed.
49578sed '/^Starting/d
49579/^Entering/d
49580/^Stack/d
49581/^Reading/d
49582/^Reducing/d
49583/^Shifting/d
49584/^state/d
49585/^Cleanup:/d
49586/^Error:/d
49587/^Next/d
49588/^Discarding/d
49589/ \$[0-9$]* = /d
49590/^yydestructor:/d' stderr >at-stderr
49591mv at-stderr stderr
49592# 2. Create the reference error message.
49593cat >expout <<'_ATEOF'
495942.0: syntax error, unexpected '+'
49595_ATEOF
49596
49597# 3. If locations are not used, remove them.
49598
49599# 4. If error-verbose is not used, strip the`, unexpected....' part.
49600
49601# 5. Check
49602$at_traceoff
49603echo "calc.at:626: cat stderr"
49604echo calc.at:626 >$at_check_line_file
49605( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
49606at_status=$?
49607grep '^ *+' $at_stder1 >&2
49608grep -v '^ *+' $at_stder1 >$at_stderr
49609at_failed=false
49610$at_diff $at_devnull $at_stderr || at_failed=:
49611$at_diff expout $at_stdout || at_failed=:
49612case $at_status in
49613   77) echo 77 > $at_status_file
49614            exit 77;;
49615   0) ;;
49616   *) echo "calc.at:626: exit code was $at_status, expected 0"
49617      at_failed=:;;
49618esac
49619if $at_failed; then
49620
49621  echo 1 > $at_status_file
49622  exit 1
49623fi
49624
49625$at_traceon
49626
49627
49628# Exercise error messages with EOF: work on an empty file.
49629$at_traceoff
49630echo "calc.at:626: \$PREPARSER ./calc /dev/null"
49631echo calc.at:626 >$at_check_line_file
49632( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
49633at_status=$?
49634grep '^ *+' $at_stder1 >&2
49635grep -v '^ *+' $at_stder1 >$at_stderr
49636at_failed=false
49637echo stderr:; tee stderr <$at_stderr
49638$at_diff $at_devnull $at_stdout || at_failed=:
49639case $at_status in
49640   77) echo 77 > $at_status_file
49641            exit 77;;
49642   1) ;;
49643   *) echo "calc.at:626: exit code was $at_status, expected 1"
49644      at_failed=:;;
49645esac
49646if $at_failed; then
49647
49648  echo 1 > $at_status_file
49649  exit 1
49650fi
49651
49652$at_traceon
49653
49654
49655# Normalize the observed and expected error messages, depending upon the
49656# options.
49657# 1. Remove the traces from observed.
49658sed '/^Starting/d
49659/^Entering/d
49660/^Stack/d
49661/^Reading/d
49662/^Reducing/d
49663/^Shifting/d
49664/^state/d
49665/^Cleanup:/d
49666/^Error:/d
49667/^Next/d
49668/^Discarding/d
49669/ \$[0-9$]* = /d
49670/^yydestructor:/d' stderr >at-stderr
49671mv at-stderr stderr
49672# 2. Create the reference error message.
49673cat >expout <<'_ATEOF'
496741.0: syntax error, unexpected end of input
49675_ATEOF
49676
49677# 3. If locations are not used, remove them.
49678
49679# 4. If error-verbose is not used, strip the`, unexpected....' part.
49680
49681# 5. Check
49682$at_traceoff
49683echo "calc.at:626: cat stderr"
49684echo calc.at:626 >$at_check_line_file
49685( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
49686at_status=$?
49687grep '^ *+' $at_stder1 >&2
49688grep -v '^ *+' $at_stder1 >$at_stderr
49689at_failed=false
49690$at_diff $at_devnull $at_stderr || at_failed=:
49691$at_diff expout $at_stdout || at_failed=:
49692case $at_status in
49693   77) echo 77 > $at_status_file
49694            exit 77;;
49695   0) ;;
49696   *) echo "calc.at:626: exit code was $at_status, expected 0"
49697      at_failed=:;;
49698esac
49699if $at_failed; then
49700
49701  echo 1 > $at_status_file
49702  exit 1
49703fi
49704
49705$at_traceon
49706
49707
49708
49709# Exercise the error token: without it, we die at the first error,
49710# hence be sure to
49711#
49712# - have several errors which exercise different shift/discardings
49713#   - (): nothing to pop, nothing to discard
49714#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
49715#   - (* * *): nothing to pop, a lot to discard
49716#   - (1 + 2 * *): some to pop and discard
49717#
49718# - test the action associated to `error'
49719#
49720# - check the look-ahead that triggers an error is not discarded
49721#   when we enter error recovery.  Below, the look-ahead causing the
49722#   first error is ")", which is needed to recover from the error and
49723#   produce the "0" that triggers the "0 != 1" error.
49724#
49725cat >input <<'_ATEOF'
49726() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
49727_ATEOF
49728
49729$at_traceoff
49730echo "calc.at:626: \$PREPARSER ./calc input"
49731echo calc.at:626 >$at_check_line_file
49732( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
49733at_status=$?
49734grep '^ *+' $at_stder1 >&2
49735grep -v '^ *+' $at_stder1 >$at_stderr
49736at_failed=false
49737echo stderr:; tee stderr <$at_stderr
49738$at_diff $at_devnull $at_stdout || at_failed=:
49739case $at_status in
49740   77) echo 77 > $at_status_file
49741            exit 77;;
49742   0) ;;
49743   *) echo "calc.at:626: exit code was $at_status, expected 0"
49744      at_failed=:;;
49745esac
49746if $at_failed; then
49747
49748  echo 1 > $at_status_file
49749  exit 1
49750fi
49751
49752$at_traceon
49753
49754
49755# Normalize the observed and expected error messages, depending upon the
49756# options.
49757# 1. Remove the traces from observed.
49758sed '/^Starting/d
49759/^Entering/d
49760/^Stack/d
49761/^Reading/d
49762/^Reducing/d
49763/^Shifting/d
49764/^state/d
49765/^Cleanup:/d
49766/^Error:/d
49767/^Next/d
49768/^Discarding/d
49769/ \$[0-9$]* = /d
49770/^yydestructor:/d' stderr >at-stderr
49771mv at-stderr stderr
49772# 2. Create the reference error message.
49773cat >expout <<'_ATEOF'
497741.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
497751.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
497761.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
497771.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
49778calc: error: 4444 != 1
49779_ATEOF
49780
49781# 3. If locations are not used, remove them.
49782
49783# 4. If error-verbose is not used, strip the`, unexpected....' part.
49784
49785# 5. Check
49786$at_traceoff
49787echo "calc.at:626: cat stderr"
49788echo calc.at:626 >$at_check_line_file
49789( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
49790at_status=$?
49791grep '^ *+' $at_stder1 >&2
49792grep -v '^ *+' $at_stder1 >$at_stderr
49793at_failed=false
49794$at_diff $at_devnull $at_stderr || at_failed=:
49795$at_diff expout $at_stdout || at_failed=:
49796case $at_status in
49797   77) echo 77 > $at_status_file
49798            exit 77;;
49799   0) ;;
49800   *) echo "calc.at:626: exit code was $at_status, expected 0"
49801      at_failed=:;;
49802esac
49803if $at_failed; then
49804
49805  echo 1 > $at_status_file
49806  exit 1
49807fi
49808
49809$at_traceon
49810
49811
49812
49813# The same, but this time exercising explicitly triggered syntax errors.
49814# POSIX says the look-ahead causing the error should not be discarded.
49815cat >input <<'_ATEOF'
49816(!) + (0 0) = 1
49817_ATEOF
49818
49819$at_traceoff
49820echo "calc.at:626: \$PREPARSER ./calc input"
49821echo calc.at:626 >$at_check_line_file
49822( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
49823at_status=$?
49824grep '^ *+' $at_stder1 >&2
49825grep -v '^ *+' $at_stder1 >$at_stderr
49826at_failed=false
49827echo stderr:; tee stderr <$at_stderr
49828$at_diff $at_devnull $at_stdout || at_failed=:
49829case $at_status in
49830   77) echo 77 > $at_status_file
49831            exit 77;;
49832   0) ;;
49833   *) echo "calc.at:626: exit code was $at_status, expected 0"
49834      at_failed=:;;
49835esac
49836if $at_failed; then
49837
49838  echo 1 > $at_status_file
49839  exit 1
49840fi
49841
49842$at_traceon
49843
49844
49845# Normalize the observed and expected error messages, depending upon the
49846# options.
49847# 1. Remove the traces from observed.
49848sed '/^Starting/d
49849/^Entering/d
49850/^Stack/d
49851/^Reading/d
49852/^Reducing/d
49853/^Shifting/d
49854/^state/d
49855/^Cleanup:/d
49856/^Error:/d
49857/^Next/d
49858/^Discarding/d
49859/ \$[0-9$]* = /d
49860/^yydestructor:/d' stderr >at-stderr
49861mv at-stderr stderr
49862# 2. Create the reference error message.
49863cat >expout <<'_ATEOF'
498641.9: syntax error, unexpected number
49865calc: error: 2222 != 1
49866_ATEOF
49867
49868# 3. If locations are not used, remove them.
49869
49870# 4. If error-verbose is not used, strip the`, unexpected....' part.
49871
49872# 5. Check
49873$at_traceoff
49874echo "calc.at:626: cat stderr"
49875echo calc.at:626 >$at_check_line_file
49876( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
49877at_status=$?
49878grep '^ *+' $at_stder1 >&2
49879grep -v '^ *+' $at_stder1 >$at_stderr
49880at_failed=false
49881$at_diff $at_devnull $at_stderr || at_failed=:
49882$at_diff expout $at_stdout || at_failed=:
49883case $at_status in
49884   77) echo 77 > $at_status_file
49885            exit 77;;
49886   0) ;;
49887   *) echo "calc.at:626: exit code was $at_status, expected 0"
49888      at_failed=:;;
49889esac
49890if $at_failed; then
49891
49892  echo 1 > $at_status_file
49893  exit 1
49894fi
49895
49896$at_traceon
49897
49898
49899cat >input <<'_ATEOF'
49900(- *) + (0 0) = 1
49901_ATEOF
49902
49903$at_traceoff
49904echo "calc.at:626: \$PREPARSER ./calc input"
49905echo calc.at:626 >$at_check_line_file
49906( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
49907at_status=$?
49908grep '^ *+' $at_stder1 >&2
49909grep -v '^ *+' $at_stder1 >$at_stderr
49910at_failed=false
49911echo stderr:; tee stderr <$at_stderr
49912$at_diff $at_devnull $at_stdout || at_failed=:
49913case $at_status in
49914   77) echo 77 > $at_status_file
49915            exit 77;;
49916   0) ;;
49917   *) echo "calc.at:626: exit code was $at_status, expected 0"
49918      at_failed=:;;
49919esac
49920if $at_failed; then
49921
49922  echo 1 > $at_status_file
49923  exit 1
49924fi
49925
49926$at_traceon
49927
49928
49929# Normalize the observed and expected error messages, depending upon the
49930# options.
49931# 1. Remove the traces from observed.
49932sed '/^Starting/d
49933/^Entering/d
49934/^Stack/d
49935/^Reading/d
49936/^Reducing/d
49937/^Shifting/d
49938/^state/d
49939/^Cleanup:/d
49940/^Error:/d
49941/^Next/d
49942/^Discarding/d
49943/ \$[0-9$]* = /d
49944/^yydestructor:/d' stderr >at-stderr
49945mv at-stderr stderr
49946# 2. Create the reference error message.
49947cat >expout <<'_ATEOF'
499481.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
499491.11: syntax error, unexpected number
49950calc: error: 2222 != 1
49951_ATEOF
49952
49953# 3. If locations are not used, remove them.
49954
49955# 4. If error-verbose is not used, strip the`, unexpected....' part.
49956
49957# 5. Check
49958$at_traceoff
49959echo "calc.at:626: cat stderr"
49960echo calc.at:626 >$at_check_line_file
49961( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
49962at_status=$?
49963grep '^ *+' $at_stder1 >&2
49964grep -v '^ *+' $at_stder1 >$at_stderr
49965at_failed=false
49966$at_diff $at_devnull $at_stderr || at_failed=:
49967$at_diff expout $at_stdout || at_failed=:
49968case $at_status in
49969   77) echo 77 > $at_status_file
49970            exit 77;;
49971   0) ;;
49972   *) echo "calc.at:626: exit code was $at_status, expected 0"
49973      at_failed=:;;
49974esac
49975if $at_failed; then
49976
49977  echo 1 > $at_status_file
49978  exit 1
49979fi
49980
49981$at_traceon
49982
49983
49984
49985
49986
49987
49988
49989
49990
49991
49992
49993
49994
49995
49996
49997
49998
49999
50000
50001
50002
50003
50004
50005
50006      $at_traceoff
50007      $at_times_p && times >$at_times_file
50008    ) 5>&1 2>&1 | eval $at_tee_pipe
50009    at_status=`cat $at_status_file`
50010    ;;
50011
50012  102 ) # 102. calc.at:628: Calculator %skeleton "lalr1.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}
50013    at_setup_line='calc.at:628'
50014    at_desc='Calculator %skeleton "lalr1.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}'
50015    $at_quiet $ECHO_N "102: Calculator %skeleton "lalr1.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}$ECHO_C"
50016    at_xfail=no
50017    (
50018      echo "102. calc.at:628: testing ..."
50019      $at_traceon
50020
50021
50022
50023
50024
50025
50026
50027
50028# Using yacc.c?
50029
50030
50031
50032
50033
50034
50035
50036# yyerror receives the location if %location & %pure & (%glr or %parse-param).
50037
50038# yyerror always sees the locations (when activated), except if
50039# yacc & pure & !param.
50040
50041
50042# The interface is pure: either because %pure-parser, or because we
50043# are using the C++ parsers.
50044
50045
50046
50047
50048
50049
50050
50051
50052
50053
50054
50055
50056cat >calc.y <<'_ATEOF'
50057%{
50058#ifdef HAVE_CONFIG_H
50059# include <config.h>
50060  /* We don't need perfect functions for these tests. */
50061# undef malloc
50062# undef memcmp
50063# undef realloc
50064#endif
50065%}
50066
50067/* Infix notation calculator--calc */
50068%skeleton "lalr1.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}
50069%define "global_tokens_and_yystype"
50070%{
50071#include <stdio.h>
50072
50073#include <stdlib.h>
50074#include <string.h>
50075#if HAVE_UNISTD_H
50076# include <unistd.h>
50077#else
50078# undef alarm
50079# define alarm(seconds) /* empty */
50080#endif
50081#include <ctype.h>
50082#define USE(Var)
50083
50084/* Exercise pre-prologue dependency to %union.  */
50085typedef int semantic_value;
50086
50087static semantic_value global_result = 0;
50088static int global_count = 0;
50089%}
50090
50091/* Exercise %union. */
50092%union
50093{
50094  semantic_value ival;
50095};
50096
50097%{
50098static int power (int base, int exponent);
50099#ifndef YYLTYPE
50100# define YYLTYPE calc::location
50101#endif
50102#define first_line   begin.line
50103#define first_column begin.column
50104#define last_line    end.line
50105#define last_column  end.column
50106
50107static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
50108static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp);
50109static void unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c);
50110%}
50111
50112/* The lalr1.cc skeleton, for backward compatibility, defines
50113   a constructor for position that initializes the filename.  The
50114   glr.cc skeleton does not (and in fact cannot: location/position
50115   are stored in a union, from which objects with constructors are
50116   excluded in C++. */
50117%initial-action {
50118  @$.initialize (0);
50119}
50120
50121
50122/* Bison Declarations */
50123%token CALC_EOF 0 "end of input"
50124%token <ival> NUM "number"
50125%type  <ival> exp
50126
50127%nonassoc '=' /* comparison	       */
50128%left '-' '+'
50129%left '*' '/'
50130%left NEG     /* negation--unary minus */
50131%right '^'    /* exponentiation        */
50132
50133/* Grammar follows */
50134%%
50135input:
50136  line
50137| input line         { ++*count; ++global_count; }
50138;
50139
50140line:
50141  '\n'
50142| exp '\n'           { *result = global_result = $1; }
50143;
50144
50145exp:
50146  NUM                { $$ = $1;             }
50147| exp '=' exp
50148  {
50149    if ($1 != $3)
50150      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
50151    $$ = $1;
50152  }
50153| exp '+' exp        { $$ = $1 + $3;        }
50154| exp '-' exp        { $$ = $1 - $3;        }
50155| exp '*' exp        { $$ = $1 * $3;        }
50156| exp '/' exp        { $$ = $1 / $3;        }
50157| '-' exp  %prec NEG { $$ = -$2;            }
50158| exp '^' exp        { $$ = power ($1, $3); }
50159| '(' exp ')'        { $$ = $2;             }
50160| '(' error ')'      { $$ = 1111;           }
50161| '!'                { $$ = 0; YYERROR;     }
50162| '-' error          { $$ = 0; YYERROR;     }
50163;
50164%%
50165/* The input.  */
50166static FILE *input;
50167
50168/* A C++ error reporting function.  */
50169void
50170calc::parser::error (const location& l, const std::string& m)
50171{
50172  (void) l;
50173  std::cerr << l << ": " << m << std::endl;
50174}
50175
50176int
50177yyparse (semantic_value *result, int *count)
50178{
50179  calc::parser parser (result, count);
50180  parser.set_debug_level (!!YYDEBUG);
50181  return parser.parse ();
50182}
50183
50184
50185
50186
50187static YYLTYPE last_yylloc;
50188
50189static int
50190get_char (YYSTYPE *lvalp, YYLTYPE *llocp)
50191{
50192  int res = getc (input);
50193  (void) lvalp;(void) llocp;
50194
50195  last_yylloc = (*llocp);
50196  if (res == '\n')
50197    {
50198      (*llocp).last_line++;
50199      (*llocp).last_column = 0;
50200    }
50201  else
50202    (*llocp).last_column++;
50203
50204  return res;
50205}
50206
50207
50208static void
50209unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c)
50210{
50211  (void) lvalp;(void) llocp;
50212
50213  /* Wrong when C == `\n'. */
50214  (*llocp) = last_yylloc;
50215
50216  ungetc (c, input);
50217}
50218
50219static int
50220read_signed_integer (YYSTYPE *lvalp, YYLTYPE *llocp)
50221{
50222  int c = get_char (lvalp, llocp);
50223  int sign = 1;
50224  int n = 0;
50225
50226  (void) lvalp;(void) llocp;
50227  if (c == '-')
50228    {
50229      c = get_char (lvalp, llocp);
50230      sign = -1;
50231    }
50232
50233  while (isdigit (c))
50234    {
50235      n = 10 * n + (c - '0');
50236      c = get_char (lvalp, llocp);
50237    }
50238
50239  unget_char (lvalp, llocp,  c);
50240
50241  return sign * n;
50242}
50243
50244
50245
50246/*---------------------------------------------------------------.
50247| Lexical analyzer returns an integer on the stack and the token |
50248| NUM, or the ASCII character read if not a number.  Skips all   |
50249| blanks and tabs, returns 0 for EOF.                            |
50250`---------------------------------------------------------------*/
50251
50252static int
50253yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
50254{
50255  static int init = 1;
50256  int c;
50257
50258  if (init)
50259    {
50260      init = 0;
50261
50262      (*llocp).last_column = 0;
50263      (*llocp).last_line = 1;
50264
50265    }
50266
50267
50268 (*llocp).first_column = (*llocp).last_column;
50269  (*llocp).first_line   = (*llocp).last_line;
50270
50271
50272  /* Skip white space.  */
50273  while ((c = get_char (lvalp, llocp)) == ' ' || c == '\t')
50274    {
50275     (*llocp).first_column = (*llocp).last_column;
50276      (*llocp).first_line   = (*llocp).last_line;
50277
50278    }
50279
50280  /* process numbers   */
50281  if (c == '.' || isdigit (c))
50282    {
50283      unget_char (lvalp, llocp,  c);
50284      (*lvalp).ival = read_signed_integer (lvalp, llocp);
50285      return NUM;
50286    }
50287
50288  /* Return end-of-file.  */
50289  if (c == EOF)
50290    return CALC_EOF;
50291
50292  /* Return single chars. */
50293  return c;
50294}
50295
50296static int
50297power (int base, int exponent)
50298{
50299  int res = 1;
50300  if (exponent < 0)
50301    exit (3);
50302  for (/* Niente */; exponent; --exponent)
50303    res *= base;
50304  return res;
50305}
50306
50307
50308int
50309main (int argc, const char **argv)
50310{
50311  semantic_value result = 0;
50312  int count = 0;
50313  int status;
50314
50315  /* This used to be alarm (10), but that isn't enough time for
50316     a July 1995 vintage DEC Alphastation 200 4/100 system,
50317     according to Nelson H. F. Beebe.  100 seconds is enough.  */
50318  alarm (100);
50319
50320  if (argc == 2)
50321    input = fopen (argv[1], "r");
50322  else
50323    input = stdin;
50324
50325  if (!input)
50326    {
50327      perror (argv[1]);
50328      return 3;
50329    }
50330
50331
50332  status = yyparse (&result, &count);
50333  if (global_result != result)
50334    abort ();
50335  if (global_count != count)
50336    abort ();
50337  return status;
50338}
50339_ATEOF
50340
50341
50342
50343
50344
50345$at_traceoff
50346echo "calc.at:628: bison -o calc.cc calc.y"
50347echo calc.at:628 >$at_check_line_file
50348( $at_traceon; bison -o calc.cc calc.y ) >$at_stdout 2>$at_stder1
50349at_status=$?
50350grep '^ *+' $at_stder1 >&2
50351grep -v '^ *+' $at_stder1 >$at_stderr
50352at_failed=false
50353$at_diff $at_devnull $at_stderr || at_failed=:
50354$at_diff $at_devnull $at_stdout || at_failed=:
50355case $at_status in
50356   77) echo 77 > $at_status_file
50357            exit 77;;
50358   0) ;;
50359   *) echo "calc.at:628: exit code was $at_status, expected 0"
50360      at_failed=:;;
50361esac
50362if $at_failed; then
50363
50364  echo 1 > $at_status_file
50365  exit 1
50366fi
50367
50368$at_traceon
50369
50370
50371$at_traceoff
50372echo "calc.at:628: \$BISON_CXX_WORKS"
50373echo calc.at:628 >$at_check_line_file
50374( $at_traceon; $BISON_CXX_WORKS ) >$at_stdout 2>$at_stder1
50375at_status=$?
50376grep '^ *+' $at_stder1 >&2
50377grep -v '^ *+' $at_stder1 >$at_stderr
50378at_failed=false
50379echo stderr:; cat $at_stderr
50380echo stdout:; cat $at_stdout
50381case $at_status in
50382   77) echo 77 > $at_status_file
50383            exit 77;;
50384   0) ;;
50385   *) echo "calc.at:628: exit code was $at_status, expected 0"
50386      at_failed=:;;
50387esac
50388if $at_failed; then
50389
50390  echo 1 > $at_status_file
50391  exit 1
50392fi
50393
50394$at_traceon
50395
50396$at_traceoff
50397echo "calc.at:628: \$CXX \$CXXFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.cc \$LIBS"
50398echo calc.at:628 >$at_check_line_file
50399( $at_traceon; $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o calc calc.cc $LIBS ) >$at_stdout 2>$at_stder1
50400at_status=$?
50401grep '^ *+' $at_stder1 >&2
50402grep -v '^ *+' $at_stder1 >$at_stderr
50403at_failed=false
50404echo stderr:; cat $at_stderr
50405echo stdout:; cat $at_stdout
50406case $at_status in
50407   77) echo 77 > $at_status_file
50408            exit 77;;
50409   0) ;;
50410   *) echo "calc.at:628: exit code was $at_status, expected 0"
50411      at_failed=:;;
50412esac
50413if $at_failed; then
50414
50415  echo 1 > $at_status_file
50416  exit 1
50417fi
50418
50419$at_traceon
50420
50421
50422# Test the priorities.
50423cat >input <<'_ATEOF'
504241 + 2 * 3 = 7
504251 + 2 * -3 = -5
50426
50427-1^2 = -1
50428(-1)^2 = 1
50429
50430---1 = -1
50431
504321 - 2 - 3 = -4
504331 - (2 - 3) = 2
50434
504352^2^3 = 256
50436(2^2)^3 = 64
50437_ATEOF
50438
50439$at_traceoff
50440echo "calc.at:628: \$PREPARSER ./calc input"
50441echo calc.at:628 >$at_check_line_file
50442( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
50443at_status=$?
50444grep '^ *+' $at_stder1 >&2
50445grep -v '^ *+' $at_stder1 >$at_stderr
50446at_failed=false
50447echo stderr:; tee stderr <$at_stderr
50448$at_diff $at_devnull $at_stdout || at_failed=:
50449case $at_status in
50450   77) echo 77 > $at_status_file
50451            exit 77;;
50452   0) ;;
50453   *) echo "calc.at:628: exit code was $at_status, expected 0"
50454      at_failed=:;;
50455esac
50456if $at_failed; then
50457
50458  echo 1 > $at_status_file
50459  exit 1
50460fi
50461
50462$at_traceon
50463
50464
50465
50466# Some syntax errors.
50467cat >input <<'_ATEOF'
504680 0
50469_ATEOF
50470
50471$at_traceoff
50472echo "calc.at:628: \$PREPARSER ./calc input"
50473echo calc.at:628 >$at_check_line_file
50474( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
50475at_status=$?
50476grep '^ *+' $at_stder1 >&2
50477grep -v '^ *+' $at_stder1 >$at_stderr
50478at_failed=false
50479echo stderr:; tee stderr <$at_stderr
50480$at_diff $at_devnull $at_stdout || at_failed=:
50481case $at_status in
50482   77) echo 77 > $at_status_file
50483            exit 77;;
50484   1) ;;
50485   *) echo "calc.at:628: exit code was $at_status, expected 1"
50486      at_failed=:;;
50487esac
50488if $at_failed; then
50489
50490  echo 1 > $at_status_file
50491  exit 1
50492fi
50493
50494$at_traceon
50495
50496
50497# Normalize the observed and expected error messages, depending upon the
50498# options.
50499# 1. Remove the traces from observed.
50500sed '/^Starting/d
50501/^Entering/d
50502/^Stack/d
50503/^Reading/d
50504/^Reducing/d
50505/^Shifting/d
50506/^state/d
50507/^Cleanup:/d
50508/^Error:/d
50509/^Next/d
50510/^Discarding/d
50511/ \$[0-9$]* = /d
50512/^yydestructor:/d' stderr >at-stderr
50513mv at-stderr stderr
50514# 2. Create the reference error message.
50515cat >expout <<'_ATEOF'
505161.2: syntax error, unexpected number
50517_ATEOF
50518
50519# 3. If locations are not used, remove them.
50520
50521# 4. If error-verbose is not used, strip the`, unexpected....' part.
50522
50523# 5. Check
50524$at_traceoff
50525echo "calc.at:628: cat stderr"
50526echo calc.at:628 >$at_check_line_file
50527( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
50528at_status=$?
50529grep '^ *+' $at_stder1 >&2
50530grep -v '^ *+' $at_stder1 >$at_stderr
50531at_failed=false
50532$at_diff $at_devnull $at_stderr || at_failed=:
50533$at_diff expout $at_stdout || at_failed=:
50534case $at_status in
50535   77) echo 77 > $at_status_file
50536            exit 77;;
50537   0) ;;
50538   *) echo "calc.at:628: exit code was $at_status, expected 0"
50539      at_failed=:;;
50540esac
50541if $at_failed; then
50542
50543  echo 1 > $at_status_file
50544  exit 1
50545fi
50546
50547$at_traceon
50548
50549
50550cat >input <<'_ATEOF'
505511//2
50552_ATEOF
50553
50554$at_traceoff
50555echo "calc.at:628: \$PREPARSER ./calc input"
50556echo calc.at:628 >$at_check_line_file
50557( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
50558at_status=$?
50559grep '^ *+' $at_stder1 >&2
50560grep -v '^ *+' $at_stder1 >$at_stderr
50561at_failed=false
50562echo stderr:; tee stderr <$at_stderr
50563$at_diff $at_devnull $at_stdout || at_failed=:
50564case $at_status in
50565   77) echo 77 > $at_status_file
50566            exit 77;;
50567   1) ;;
50568   *) echo "calc.at:628: exit code was $at_status, expected 1"
50569      at_failed=:;;
50570esac
50571if $at_failed; then
50572
50573  echo 1 > $at_status_file
50574  exit 1
50575fi
50576
50577$at_traceon
50578
50579
50580# Normalize the observed and expected error messages, depending upon the
50581# options.
50582# 1. Remove the traces from observed.
50583sed '/^Starting/d
50584/^Entering/d
50585/^Stack/d
50586/^Reading/d
50587/^Reducing/d
50588/^Shifting/d
50589/^state/d
50590/^Cleanup:/d
50591/^Error:/d
50592/^Next/d
50593/^Discarding/d
50594/ \$[0-9$]* = /d
50595/^yydestructor:/d' stderr >at-stderr
50596mv at-stderr stderr
50597# 2. Create the reference error message.
50598cat >expout <<'_ATEOF'
505991.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
50600_ATEOF
50601
50602# 3. If locations are not used, remove them.
50603
50604# 4. If error-verbose is not used, strip the`, unexpected....' part.
50605
50606# 5. Check
50607$at_traceoff
50608echo "calc.at:628: cat stderr"
50609echo calc.at:628 >$at_check_line_file
50610( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
50611at_status=$?
50612grep '^ *+' $at_stder1 >&2
50613grep -v '^ *+' $at_stder1 >$at_stderr
50614at_failed=false
50615$at_diff $at_devnull $at_stderr || at_failed=:
50616$at_diff expout $at_stdout || at_failed=:
50617case $at_status in
50618   77) echo 77 > $at_status_file
50619            exit 77;;
50620   0) ;;
50621   *) echo "calc.at:628: exit code was $at_status, expected 0"
50622      at_failed=:;;
50623esac
50624if $at_failed; then
50625
50626  echo 1 > $at_status_file
50627  exit 1
50628fi
50629
50630$at_traceon
50631
50632
50633cat >input <<'_ATEOF'
50634error
50635_ATEOF
50636
50637$at_traceoff
50638echo "calc.at:628: \$PREPARSER ./calc input"
50639echo calc.at:628 >$at_check_line_file
50640( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
50641at_status=$?
50642grep '^ *+' $at_stder1 >&2
50643grep -v '^ *+' $at_stder1 >$at_stderr
50644at_failed=false
50645echo stderr:; tee stderr <$at_stderr
50646$at_diff $at_devnull $at_stdout || at_failed=:
50647case $at_status in
50648   77) echo 77 > $at_status_file
50649            exit 77;;
50650   1) ;;
50651   *) echo "calc.at:628: exit code was $at_status, expected 1"
50652      at_failed=:;;
50653esac
50654if $at_failed; then
50655
50656  echo 1 > $at_status_file
50657  exit 1
50658fi
50659
50660$at_traceon
50661
50662
50663# Normalize the observed and expected error messages, depending upon the
50664# options.
50665# 1. Remove the traces from observed.
50666sed '/^Starting/d
50667/^Entering/d
50668/^Stack/d
50669/^Reading/d
50670/^Reducing/d
50671/^Shifting/d
50672/^state/d
50673/^Cleanup:/d
50674/^Error:/d
50675/^Next/d
50676/^Discarding/d
50677/ \$[0-9$]* = /d
50678/^yydestructor:/d' stderr >at-stderr
50679mv at-stderr stderr
50680# 2. Create the reference error message.
50681cat >expout <<'_ATEOF'
506821.0: syntax error, unexpected $undefined
50683_ATEOF
50684
50685# 3. If locations are not used, remove them.
50686
50687# 4. If error-verbose is not used, strip the`, unexpected....' part.
50688
50689# 5. Check
50690$at_traceoff
50691echo "calc.at:628: cat stderr"
50692echo calc.at:628 >$at_check_line_file
50693( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
50694at_status=$?
50695grep '^ *+' $at_stder1 >&2
50696grep -v '^ *+' $at_stder1 >$at_stderr
50697at_failed=false
50698$at_diff $at_devnull $at_stderr || at_failed=:
50699$at_diff expout $at_stdout || at_failed=:
50700case $at_status in
50701   77) echo 77 > $at_status_file
50702            exit 77;;
50703   0) ;;
50704   *) echo "calc.at:628: exit code was $at_status, expected 0"
50705      at_failed=:;;
50706esac
50707if $at_failed; then
50708
50709  echo 1 > $at_status_file
50710  exit 1
50711fi
50712
50713$at_traceon
50714
50715
50716cat >input <<'_ATEOF'
507171 = 2 = 3
50718_ATEOF
50719
50720$at_traceoff
50721echo "calc.at:628: \$PREPARSER ./calc input"
50722echo calc.at:628 >$at_check_line_file
50723( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
50724at_status=$?
50725grep '^ *+' $at_stder1 >&2
50726grep -v '^ *+' $at_stder1 >$at_stderr
50727at_failed=false
50728echo stderr:; tee stderr <$at_stderr
50729$at_diff $at_devnull $at_stdout || at_failed=:
50730case $at_status in
50731   77) echo 77 > $at_status_file
50732            exit 77;;
50733   1) ;;
50734   *) echo "calc.at:628: exit code was $at_status, expected 1"
50735      at_failed=:;;
50736esac
50737if $at_failed; then
50738
50739  echo 1 > $at_status_file
50740  exit 1
50741fi
50742
50743$at_traceon
50744
50745
50746# Normalize the observed and expected error messages, depending upon the
50747# options.
50748# 1. Remove the traces from observed.
50749sed '/^Starting/d
50750/^Entering/d
50751/^Stack/d
50752/^Reading/d
50753/^Reducing/d
50754/^Shifting/d
50755/^state/d
50756/^Cleanup:/d
50757/^Error:/d
50758/^Next/d
50759/^Discarding/d
50760/ \$[0-9$]* = /d
50761/^yydestructor:/d' stderr >at-stderr
50762mv at-stderr stderr
50763# 2. Create the reference error message.
50764cat >expout <<'_ATEOF'
507651.6: syntax error, unexpected '='
50766_ATEOF
50767
50768# 3. If locations are not used, remove them.
50769
50770# 4. If error-verbose is not used, strip the`, unexpected....' part.
50771
50772# 5. Check
50773$at_traceoff
50774echo "calc.at:628: cat stderr"
50775echo calc.at:628 >$at_check_line_file
50776( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
50777at_status=$?
50778grep '^ *+' $at_stder1 >&2
50779grep -v '^ *+' $at_stder1 >$at_stderr
50780at_failed=false
50781$at_diff $at_devnull $at_stderr || at_failed=:
50782$at_diff expout $at_stdout || at_failed=:
50783case $at_status in
50784   77) echo 77 > $at_status_file
50785            exit 77;;
50786   0) ;;
50787   *) echo "calc.at:628: exit code was $at_status, expected 0"
50788      at_failed=:;;
50789esac
50790if $at_failed; then
50791
50792  echo 1 > $at_status_file
50793  exit 1
50794fi
50795
50796$at_traceon
50797
50798
50799cat >input <<'_ATEOF'
50800
50801+1
50802_ATEOF
50803
50804$at_traceoff
50805echo "calc.at:628: \$PREPARSER ./calc input"
50806echo calc.at:628 >$at_check_line_file
50807( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
50808at_status=$?
50809grep '^ *+' $at_stder1 >&2
50810grep -v '^ *+' $at_stder1 >$at_stderr
50811at_failed=false
50812echo stderr:; tee stderr <$at_stderr
50813$at_diff $at_devnull $at_stdout || at_failed=:
50814case $at_status in
50815   77) echo 77 > $at_status_file
50816            exit 77;;
50817   1) ;;
50818   *) echo "calc.at:628: exit code was $at_status, expected 1"
50819      at_failed=:;;
50820esac
50821if $at_failed; then
50822
50823  echo 1 > $at_status_file
50824  exit 1
50825fi
50826
50827$at_traceon
50828
50829
50830# Normalize the observed and expected error messages, depending upon the
50831# options.
50832# 1. Remove the traces from observed.
50833sed '/^Starting/d
50834/^Entering/d
50835/^Stack/d
50836/^Reading/d
50837/^Reducing/d
50838/^Shifting/d
50839/^state/d
50840/^Cleanup:/d
50841/^Error:/d
50842/^Next/d
50843/^Discarding/d
50844/ \$[0-9$]* = /d
50845/^yydestructor:/d' stderr >at-stderr
50846mv at-stderr stderr
50847# 2. Create the reference error message.
50848cat >expout <<'_ATEOF'
508492.0: syntax error, unexpected '+'
50850_ATEOF
50851
50852# 3. If locations are not used, remove them.
50853
50854# 4. If error-verbose is not used, strip the`, unexpected....' part.
50855
50856# 5. Check
50857$at_traceoff
50858echo "calc.at:628: cat stderr"
50859echo calc.at:628 >$at_check_line_file
50860( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
50861at_status=$?
50862grep '^ *+' $at_stder1 >&2
50863grep -v '^ *+' $at_stder1 >$at_stderr
50864at_failed=false
50865$at_diff $at_devnull $at_stderr || at_failed=:
50866$at_diff expout $at_stdout || at_failed=:
50867case $at_status in
50868   77) echo 77 > $at_status_file
50869            exit 77;;
50870   0) ;;
50871   *) echo "calc.at:628: exit code was $at_status, expected 0"
50872      at_failed=:;;
50873esac
50874if $at_failed; then
50875
50876  echo 1 > $at_status_file
50877  exit 1
50878fi
50879
50880$at_traceon
50881
50882
50883# Exercise error messages with EOF: work on an empty file.
50884$at_traceoff
50885echo "calc.at:628: \$PREPARSER ./calc /dev/null"
50886echo calc.at:628 >$at_check_line_file
50887( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
50888at_status=$?
50889grep '^ *+' $at_stder1 >&2
50890grep -v '^ *+' $at_stder1 >$at_stderr
50891at_failed=false
50892echo stderr:; tee stderr <$at_stderr
50893$at_diff $at_devnull $at_stdout || at_failed=:
50894case $at_status in
50895   77) echo 77 > $at_status_file
50896            exit 77;;
50897   1) ;;
50898   *) echo "calc.at:628: exit code was $at_status, expected 1"
50899      at_failed=:;;
50900esac
50901if $at_failed; then
50902
50903  echo 1 > $at_status_file
50904  exit 1
50905fi
50906
50907$at_traceon
50908
50909
50910# Normalize the observed and expected error messages, depending upon the
50911# options.
50912# 1. Remove the traces from observed.
50913sed '/^Starting/d
50914/^Entering/d
50915/^Stack/d
50916/^Reading/d
50917/^Reducing/d
50918/^Shifting/d
50919/^state/d
50920/^Cleanup:/d
50921/^Error:/d
50922/^Next/d
50923/^Discarding/d
50924/ \$[0-9$]* = /d
50925/^yydestructor:/d' stderr >at-stderr
50926mv at-stderr stderr
50927# 2. Create the reference error message.
50928cat >expout <<'_ATEOF'
509291.0: syntax error, unexpected end of input
50930_ATEOF
50931
50932# 3. If locations are not used, remove them.
50933
50934# 4. If error-verbose is not used, strip the`, unexpected....' part.
50935
50936# 5. Check
50937$at_traceoff
50938echo "calc.at:628: cat stderr"
50939echo calc.at:628 >$at_check_line_file
50940( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
50941at_status=$?
50942grep '^ *+' $at_stder1 >&2
50943grep -v '^ *+' $at_stder1 >$at_stderr
50944at_failed=false
50945$at_diff $at_devnull $at_stderr || at_failed=:
50946$at_diff expout $at_stdout || at_failed=:
50947case $at_status in
50948   77) echo 77 > $at_status_file
50949            exit 77;;
50950   0) ;;
50951   *) echo "calc.at:628: exit code was $at_status, expected 0"
50952      at_failed=:;;
50953esac
50954if $at_failed; then
50955
50956  echo 1 > $at_status_file
50957  exit 1
50958fi
50959
50960$at_traceon
50961
50962
50963
50964# Exercise the error token: without it, we die at the first error,
50965# hence be sure to
50966#
50967# - have several errors which exercise different shift/discardings
50968#   - (): nothing to pop, nothing to discard
50969#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
50970#   - (* * *): nothing to pop, a lot to discard
50971#   - (1 + 2 * *): some to pop and discard
50972#
50973# - test the action associated to `error'
50974#
50975# - check the look-ahead that triggers an error is not discarded
50976#   when we enter error recovery.  Below, the look-ahead causing the
50977#   first error is ")", which is needed to recover from the error and
50978#   produce the "0" that triggers the "0 != 1" error.
50979#
50980cat >input <<'_ATEOF'
50981() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
50982_ATEOF
50983
50984$at_traceoff
50985echo "calc.at:628: \$PREPARSER ./calc input"
50986echo calc.at:628 >$at_check_line_file
50987( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
50988at_status=$?
50989grep '^ *+' $at_stder1 >&2
50990grep -v '^ *+' $at_stder1 >$at_stderr
50991at_failed=false
50992echo stderr:; tee stderr <$at_stderr
50993$at_diff $at_devnull $at_stdout || at_failed=:
50994case $at_status in
50995   77) echo 77 > $at_status_file
50996            exit 77;;
50997   0) ;;
50998   *) echo "calc.at:628: exit code was $at_status, expected 0"
50999      at_failed=:;;
51000esac
51001if $at_failed; then
51002
51003  echo 1 > $at_status_file
51004  exit 1
51005fi
51006
51007$at_traceon
51008
51009
51010# Normalize the observed and expected error messages, depending upon the
51011# options.
51012# 1. Remove the traces from observed.
51013sed '/^Starting/d
51014/^Entering/d
51015/^Stack/d
51016/^Reading/d
51017/^Reducing/d
51018/^Shifting/d
51019/^state/d
51020/^Cleanup:/d
51021/^Error:/d
51022/^Next/d
51023/^Discarding/d
51024/ \$[0-9$]* = /d
51025/^yydestructor:/d' stderr >at-stderr
51026mv at-stderr stderr
51027# 2. Create the reference error message.
51028cat >expout <<'_ATEOF'
510291.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
510301.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
510311.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
510321.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
51033calc: error: 4444 != 1
51034_ATEOF
51035
51036# 3. If locations are not used, remove them.
51037
51038# 4. If error-verbose is not used, strip the`, unexpected....' part.
51039
51040# 5. Check
51041$at_traceoff
51042echo "calc.at:628: cat stderr"
51043echo calc.at:628 >$at_check_line_file
51044( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
51045at_status=$?
51046grep '^ *+' $at_stder1 >&2
51047grep -v '^ *+' $at_stder1 >$at_stderr
51048at_failed=false
51049$at_diff $at_devnull $at_stderr || at_failed=:
51050$at_diff expout $at_stdout || at_failed=:
51051case $at_status in
51052   77) echo 77 > $at_status_file
51053            exit 77;;
51054   0) ;;
51055   *) echo "calc.at:628: exit code was $at_status, expected 0"
51056      at_failed=:;;
51057esac
51058if $at_failed; then
51059
51060  echo 1 > $at_status_file
51061  exit 1
51062fi
51063
51064$at_traceon
51065
51066
51067
51068# The same, but this time exercising explicitly triggered syntax errors.
51069# POSIX says the look-ahead causing the error should not be discarded.
51070cat >input <<'_ATEOF'
51071(!) + (0 0) = 1
51072_ATEOF
51073
51074$at_traceoff
51075echo "calc.at:628: \$PREPARSER ./calc input"
51076echo calc.at:628 >$at_check_line_file
51077( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
51078at_status=$?
51079grep '^ *+' $at_stder1 >&2
51080grep -v '^ *+' $at_stder1 >$at_stderr
51081at_failed=false
51082echo stderr:; tee stderr <$at_stderr
51083$at_diff $at_devnull $at_stdout || at_failed=:
51084case $at_status in
51085   77) echo 77 > $at_status_file
51086            exit 77;;
51087   0) ;;
51088   *) echo "calc.at:628: exit code was $at_status, expected 0"
51089      at_failed=:;;
51090esac
51091if $at_failed; then
51092
51093  echo 1 > $at_status_file
51094  exit 1
51095fi
51096
51097$at_traceon
51098
51099
51100# Normalize the observed and expected error messages, depending upon the
51101# options.
51102# 1. Remove the traces from observed.
51103sed '/^Starting/d
51104/^Entering/d
51105/^Stack/d
51106/^Reading/d
51107/^Reducing/d
51108/^Shifting/d
51109/^state/d
51110/^Cleanup:/d
51111/^Error:/d
51112/^Next/d
51113/^Discarding/d
51114/ \$[0-9$]* = /d
51115/^yydestructor:/d' stderr >at-stderr
51116mv at-stderr stderr
51117# 2. Create the reference error message.
51118cat >expout <<'_ATEOF'
511191.9: syntax error, unexpected number
51120calc: error: 2222 != 1
51121_ATEOF
51122
51123# 3. If locations are not used, remove them.
51124
51125# 4. If error-verbose is not used, strip the`, unexpected....' part.
51126
51127# 5. Check
51128$at_traceoff
51129echo "calc.at:628: cat stderr"
51130echo calc.at:628 >$at_check_line_file
51131( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
51132at_status=$?
51133grep '^ *+' $at_stder1 >&2
51134grep -v '^ *+' $at_stder1 >$at_stderr
51135at_failed=false
51136$at_diff $at_devnull $at_stderr || at_failed=:
51137$at_diff expout $at_stdout || at_failed=:
51138case $at_status in
51139   77) echo 77 > $at_status_file
51140            exit 77;;
51141   0) ;;
51142   *) echo "calc.at:628: exit code was $at_status, expected 0"
51143      at_failed=:;;
51144esac
51145if $at_failed; then
51146
51147  echo 1 > $at_status_file
51148  exit 1
51149fi
51150
51151$at_traceon
51152
51153
51154cat >input <<'_ATEOF'
51155(- *) + (0 0) = 1
51156_ATEOF
51157
51158$at_traceoff
51159echo "calc.at:628: \$PREPARSER ./calc input"
51160echo calc.at:628 >$at_check_line_file
51161( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
51162at_status=$?
51163grep '^ *+' $at_stder1 >&2
51164grep -v '^ *+' $at_stder1 >$at_stderr
51165at_failed=false
51166echo stderr:; tee stderr <$at_stderr
51167$at_diff $at_devnull $at_stdout || at_failed=:
51168case $at_status in
51169   77) echo 77 > $at_status_file
51170            exit 77;;
51171   0) ;;
51172   *) echo "calc.at:628: exit code was $at_status, expected 0"
51173      at_failed=:;;
51174esac
51175if $at_failed; then
51176
51177  echo 1 > $at_status_file
51178  exit 1
51179fi
51180
51181$at_traceon
51182
51183
51184# Normalize the observed and expected error messages, depending upon the
51185# options.
51186# 1. Remove the traces from observed.
51187sed '/^Starting/d
51188/^Entering/d
51189/^Stack/d
51190/^Reading/d
51191/^Reducing/d
51192/^Shifting/d
51193/^state/d
51194/^Cleanup:/d
51195/^Error:/d
51196/^Next/d
51197/^Discarding/d
51198/ \$[0-9$]* = /d
51199/^yydestructor:/d' stderr >at-stderr
51200mv at-stderr stderr
51201# 2. Create the reference error message.
51202cat >expout <<'_ATEOF'
512031.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
512041.11: syntax error, unexpected number
51205calc: error: 2222 != 1
51206_ATEOF
51207
51208# 3. If locations are not used, remove them.
51209
51210# 4. If error-verbose is not used, strip the`, unexpected....' part.
51211
51212# 5. Check
51213$at_traceoff
51214echo "calc.at:628: cat stderr"
51215echo calc.at:628 >$at_check_line_file
51216( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
51217at_status=$?
51218grep '^ *+' $at_stder1 >&2
51219grep -v '^ *+' $at_stder1 >$at_stderr
51220at_failed=false
51221$at_diff $at_devnull $at_stderr || at_failed=:
51222$at_diff expout $at_stdout || at_failed=:
51223case $at_status in
51224   77) echo 77 > $at_status_file
51225            exit 77;;
51226   0) ;;
51227   *) echo "calc.at:628: exit code was $at_status, expected 0"
51228      at_failed=:;;
51229esac
51230if $at_failed; then
51231
51232  echo 1 > $at_status_file
51233  exit 1
51234fi
51235
51236$at_traceon
51237
51238
51239
51240
51241
51242
51243
51244
51245
51246
51247
51248
51249
51250
51251
51252
51253
51254
51255
51256
51257
51258
51259
51260
51261      $at_traceoff
51262      $at_times_p && times >$at_times_file
51263    ) 5>&1 2>&1 | eval $at_tee_pipe
51264    at_status=`cat $at_status_file`
51265    ;;
51266
51267
51268  banner-12 ) # Banner 12. calc.at:636
51269    cat <<\_ATEOF
51270
51271Simple GLR C++ Calculator.
51272
51273_ATEOF
51274    ;;
51275
51276  103 ) # 103. calc.at:651: Calculator %skeleton "glr.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc
51277    at_setup_line='calc.at:651'
51278    at_desc='Calculator %skeleton "glr.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc'
51279    $at_quiet $ECHO_N "103: Calculator %skeleton "glr.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc$ECHO_C"
51280    at_xfail=no
51281    (
51282      echo "103. calc.at:651: testing ..."
51283      $at_traceon
51284
51285
51286
51287
51288
51289
51290
51291
51292# Using yacc.c?
51293
51294
51295
51296
51297
51298
51299
51300# yyerror receives the location if %location & %pure & (%glr or %parse-param).
51301
51302# yyerror always sees the locations (when activated), except if
51303# yacc & pure & !param.
51304
51305
51306# The interface is pure: either because %pure-parser, or because we
51307# are using the C++ parsers.
51308
51309
51310
51311
51312
51313
51314
51315
51316
51317
51318
51319
51320cat >calc.y <<'_ATEOF'
51321%{
51322#ifdef HAVE_CONFIG_H
51323# include <config.h>
51324  /* We don't need perfect functions for these tests. */
51325# undef malloc
51326# undef memcmp
51327# undef realloc
51328#endif
51329%}
51330
51331/* Infix notation calculator--calc */
51332%skeleton "glr.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc
51333%define "global_tokens_and_yystype"
51334%{
51335#include <stdio.h>
51336
51337#include <stdlib.h>
51338#include <string.h>
51339#if HAVE_UNISTD_H
51340# include <unistd.h>
51341#else
51342# undef alarm
51343# define alarm(seconds) /* empty */
51344#endif
51345#include <ctype.h>
51346#define USE(Var)
51347
51348/* Exercise pre-prologue dependency to %union.  */
51349typedef int semantic_value;
51350
51351static semantic_value global_result = 0;
51352static int global_count = 0;
51353%}
51354
51355/* Exercise %union. */
51356%union
51357{
51358  semantic_value ival;
51359};
51360
51361%{
51362static int power (int base, int exponent);
51363#ifndef YYLTYPE
51364# define YYLTYPE calc::location
51365#endif
51366#define first_line   begin.line
51367#define first_column begin.column
51368#define last_line    end.line
51369#define last_column  end.column
51370
51371static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
51372static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp);
51373static void unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c);
51374%}
51375
51376/* The lalr1.cc skeleton, for backward compatibility, defines
51377   a constructor for position that initializes the filename.  The
51378   glr.cc skeleton does not (and in fact cannot: location/position
51379   are stored in a union, from which objects with constructors are
51380   excluded in C++. */
51381%initial-action {
51382  @$.initialize (0);
51383}
51384
51385
51386/* Bison Declarations */
51387%token CALC_EOF 0 "end of input"
51388%token <ival> NUM "number"
51389%type  <ival> exp
51390
51391%nonassoc '=' /* comparison	       */
51392%left '-' '+'
51393%left '*' '/'
51394%left NEG     /* negation--unary minus */
51395%right '^'    /* exponentiation        */
51396
51397/* Grammar follows */
51398%%
51399input:
51400  line
51401| input line         {  }
51402;
51403
51404line:
51405  '\n'
51406| exp '\n'           { USE ($1); }
51407;
51408
51409exp:
51410  NUM                { $$ = $1;             }
51411| exp '=' exp
51412  {
51413    if ($1 != $3)
51414      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
51415    $$ = $1;
51416  }
51417| exp '+' exp        { $$ = $1 + $3;        }
51418| exp '-' exp        { $$ = $1 - $3;        }
51419| exp '*' exp        { $$ = $1 * $3;        }
51420| exp '/' exp        { $$ = $1 / $3;        }
51421| '-' exp  %prec NEG { $$ = -$2;            }
51422| exp '^' exp        { $$ = power ($1, $3); }
51423| '(' exp ')'        { $$ = $2;             }
51424| '(' error ')'      { $$ = 1111;           }
51425| '!'                { $$ = 0; YYERROR;     }
51426| '-' error          { $$ = 0; YYERROR;     }
51427;
51428%%
51429/* The input.  */
51430static FILE *input;
51431
51432/* A C++ error reporting function.  */
51433void
51434calc::parser::error (const location& l, const std::string& m)
51435{
51436  (void) l;
51437  std::cerr << l << ": " << m << std::endl;
51438}
51439
51440int
51441yyparse ()
51442{
51443  calc::parser parser;
51444  parser.set_debug_level (!!YYDEBUG);
51445  return parser.parse ();
51446}
51447
51448
51449
51450
51451static YYLTYPE last_yylloc;
51452
51453static int
51454get_char (YYSTYPE *lvalp, YYLTYPE *llocp)
51455{
51456  int res = getc (input);
51457  (void) lvalp;(void) llocp;
51458
51459  last_yylloc = (*llocp);
51460  if (res == '\n')
51461    {
51462      (*llocp).last_line++;
51463      (*llocp).last_column = 0;
51464    }
51465  else
51466    (*llocp).last_column++;
51467
51468  return res;
51469}
51470
51471
51472static void
51473unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c)
51474{
51475  (void) lvalp;(void) llocp;
51476
51477  /* Wrong when C == `\n'. */
51478  (*llocp) = last_yylloc;
51479
51480  ungetc (c, input);
51481}
51482
51483static int
51484read_signed_integer (YYSTYPE *lvalp, YYLTYPE *llocp)
51485{
51486  int c = get_char (lvalp, llocp);
51487  int sign = 1;
51488  int n = 0;
51489
51490  (void) lvalp;(void) llocp;
51491  if (c == '-')
51492    {
51493      c = get_char (lvalp, llocp);
51494      sign = -1;
51495    }
51496
51497  while (isdigit (c))
51498    {
51499      n = 10 * n + (c - '0');
51500      c = get_char (lvalp, llocp);
51501    }
51502
51503  unget_char (lvalp, llocp,  c);
51504
51505  return sign * n;
51506}
51507
51508
51509
51510/*---------------------------------------------------------------.
51511| Lexical analyzer returns an integer on the stack and the token |
51512| NUM, or the ASCII character read if not a number.  Skips all   |
51513| blanks and tabs, returns 0 for EOF.                            |
51514`---------------------------------------------------------------*/
51515
51516static int
51517yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
51518{
51519  static int init = 1;
51520  int c;
51521
51522  if (init)
51523    {
51524      init = 0;
51525
51526      (*llocp).last_column = 0;
51527      (*llocp).last_line = 1;
51528
51529    }
51530
51531
51532 (*llocp).first_column = (*llocp).last_column;
51533  (*llocp).first_line   = (*llocp).last_line;
51534
51535
51536  /* Skip white space.  */
51537  while ((c = get_char (lvalp, llocp)) == ' ' || c == '\t')
51538    {
51539     (*llocp).first_column = (*llocp).last_column;
51540      (*llocp).first_line   = (*llocp).last_line;
51541
51542    }
51543
51544  /* process numbers   */
51545  if (c == '.' || isdigit (c))
51546    {
51547      unget_char (lvalp, llocp,  c);
51548      (*lvalp).ival = read_signed_integer (lvalp, llocp);
51549      return NUM;
51550    }
51551
51552  /* Return end-of-file.  */
51553  if (c == EOF)
51554    return CALC_EOF;
51555
51556  /* Return single chars. */
51557  return c;
51558}
51559
51560static int
51561power (int base, int exponent)
51562{
51563  int res = 1;
51564  if (exponent < 0)
51565    exit (3);
51566  for (/* Niente */; exponent; --exponent)
51567    res *= base;
51568  return res;
51569}
51570
51571
51572int
51573main (int argc, const char **argv)
51574{
51575  semantic_value result = 0;
51576  int count = 0;
51577  int status;
51578
51579  /* This used to be alarm (10), but that isn't enough time for
51580     a July 1995 vintage DEC Alphastation 200 4/100 system,
51581     according to Nelson H. F. Beebe.  100 seconds is enough.  */
51582  alarm (100);
51583
51584  if (argc == 2)
51585    input = fopen (argv[1], "r");
51586  else
51587    input = stdin;
51588
51589  if (!input)
51590    {
51591      perror (argv[1]);
51592      return 3;
51593    }
51594
51595
51596  status = yyparse ();
51597  if (global_result != result)
51598    abort ();
51599  if (global_count != count)
51600    abort ();
51601  return status;
51602}
51603_ATEOF
51604
51605
51606
51607
51608
51609$at_traceoff
51610echo "calc.at:651: bison -o calc.cc calc.y"
51611echo calc.at:651 >$at_check_line_file
51612( $at_traceon; bison -o calc.cc calc.y ) >$at_stdout 2>$at_stder1
51613at_status=$?
51614grep '^ *+' $at_stder1 >&2
51615grep -v '^ *+' $at_stder1 >$at_stderr
51616at_failed=false
51617$at_diff $at_devnull $at_stderr || at_failed=:
51618$at_diff $at_devnull $at_stdout || at_failed=:
51619case $at_status in
51620   77) echo 77 > $at_status_file
51621            exit 77;;
51622   0) ;;
51623   *) echo "calc.at:651: exit code was $at_status, expected 0"
51624      at_failed=:;;
51625esac
51626if $at_failed; then
51627
51628  echo 1 > $at_status_file
51629  exit 1
51630fi
51631
51632$at_traceon
51633
51634
51635$at_traceoff
51636echo "calc.at:651: \$BISON_CXX_WORKS"
51637echo calc.at:651 >$at_check_line_file
51638( $at_traceon; $BISON_CXX_WORKS ) >$at_stdout 2>$at_stder1
51639at_status=$?
51640grep '^ *+' $at_stder1 >&2
51641grep -v '^ *+' $at_stder1 >$at_stderr
51642at_failed=false
51643echo stderr:; cat $at_stderr
51644echo stdout:; cat $at_stdout
51645case $at_status in
51646   77) echo 77 > $at_status_file
51647            exit 77;;
51648   0) ;;
51649   *) echo "calc.at:651: exit code was $at_status, expected 0"
51650      at_failed=:;;
51651esac
51652if $at_failed; then
51653
51654  echo 1 > $at_status_file
51655  exit 1
51656fi
51657
51658$at_traceon
51659
51660$at_traceoff
51661echo "calc.at:651: \$CXX \$CXXFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.cc \$LIBS"
51662echo calc.at:651 >$at_check_line_file
51663( $at_traceon; $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o calc calc.cc $LIBS ) >$at_stdout 2>$at_stder1
51664at_status=$?
51665grep '^ *+' $at_stder1 >&2
51666grep -v '^ *+' $at_stder1 >$at_stderr
51667at_failed=false
51668echo stderr:; cat $at_stderr
51669echo stdout:; cat $at_stdout
51670case $at_status in
51671   77) echo 77 > $at_status_file
51672            exit 77;;
51673   0) ;;
51674   *) echo "calc.at:651: exit code was $at_status, expected 0"
51675      at_failed=:;;
51676esac
51677if $at_failed; then
51678
51679  echo 1 > $at_status_file
51680  exit 1
51681fi
51682
51683$at_traceon
51684
51685
51686# Test the priorities.
51687cat >input <<'_ATEOF'
516881 + 2 * 3 = 7
516891 + 2 * -3 = -5
51690
51691-1^2 = -1
51692(-1)^2 = 1
51693
51694---1 = -1
51695
516961 - 2 - 3 = -4
516971 - (2 - 3) = 2
51698
516992^2^3 = 256
51700(2^2)^3 = 64
51701_ATEOF
51702
51703$at_traceoff
51704echo "calc.at:651: \$PREPARSER ./calc input"
51705echo calc.at:651 >$at_check_line_file
51706( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
51707at_status=$?
51708grep '^ *+' $at_stder1 >&2
51709grep -v '^ *+' $at_stder1 >$at_stderr
51710at_failed=false
51711echo stderr:; tee stderr <$at_stderr
51712$at_diff $at_devnull $at_stdout || at_failed=:
51713case $at_status in
51714   77) echo 77 > $at_status_file
51715            exit 77;;
51716   0) ;;
51717   *) echo "calc.at:651: exit code was $at_status, expected 0"
51718      at_failed=:;;
51719esac
51720if $at_failed; then
51721
51722  echo 1 > $at_status_file
51723  exit 1
51724fi
51725
51726$at_traceon
51727
51728
51729
51730# Some syntax errors.
51731cat >input <<'_ATEOF'
517320 0
51733_ATEOF
51734
51735$at_traceoff
51736echo "calc.at:651: \$PREPARSER ./calc input"
51737echo calc.at:651 >$at_check_line_file
51738( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
51739at_status=$?
51740grep '^ *+' $at_stder1 >&2
51741grep -v '^ *+' $at_stder1 >$at_stderr
51742at_failed=false
51743echo stderr:; tee stderr <$at_stderr
51744$at_diff $at_devnull $at_stdout || at_failed=:
51745case $at_status in
51746   77) echo 77 > $at_status_file
51747            exit 77;;
51748   1) ;;
51749   *) echo "calc.at:651: exit code was $at_status, expected 1"
51750      at_failed=:;;
51751esac
51752if $at_failed; then
51753
51754  echo 1 > $at_status_file
51755  exit 1
51756fi
51757
51758$at_traceon
51759
51760
51761# Normalize the observed and expected error messages, depending upon the
51762# options.
51763# 1. Remove the traces from observed.
51764sed '/^Starting/d
51765/^Entering/d
51766/^Stack/d
51767/^Reading/d
51768/^Reducing/d
51769/^Shifting/d
51770/^state/d
51771/^Cleanup:/d
51772/^Error:/d
51773/^Next/d
51774/^Discarding/d
51775/ \$[0-9$]* = /d
51776/^yydestructor:/d' stderr >at-stderr
51777mv at-stderr stderr
51778# 2. Create the reference error message.
51779cat >expout <<'_ATEOF'
517801.2: syntax error, unexpected number
51781_ATEOF
51782
51783# 3. If locations are not used, remove them.
51784
51785# 4. If error-verbose is not used, strip the`, unexpected....' part.
51786
51787# 5. Check
51788$at_traceoff
51789echo "calc.at:651: cat stderr"
51790echo calc.at:651 >$at_check_line_file
51791( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
51792at_status=$?
51793grep '^ *+' $at_stder1 >&2
51794grep -v '^ *+' $at_stder1 >$at_stderr
51795at_failed=false
51796$at_diff $at_devnull $at_stderr || at_failed=:
51797$at_diff expout $at_stdout || at_failed=:
51798case $at_status in
51799   77) echo 77 > $at_status_file
51800            exit 77;;
51801   0) ;;
51802   *) echo "calc.at:651: exit code was $at_status, expected 0"
51803      at_failed=:;;
51804esac
51805if $at_failed; then
51806
51807  echo 1 > $at_status_file
51808  exit 1
51809fi
51810
51811$at_traceon
51812
51813
51814cat >input <<'_ATEOF'
518151//2
51816_ATEOF
51817
51818$at_traceoff
51819echo "calc.at:651: \$PREPARSER ./calc input"
51820echo calc.at:651 >$at_check_line_file
51821( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
51822at_status=$?
51823grep '^ *+' $at_stder1 >&2
51824grep -v '^ *+' $at_stder1 >$at_stderr
51825at_failed=false
51826echo stderr:; tee stderr <$at_stderr
51827$at_diff $at_devnull $at_stdout || at_failed=:
51828case $at_status in
51829   77) echo 77 > $at_status_file
51830            exit 77;;
51831   1) ;;
51832   *) echo "calc.at:651: exit code was $at_status, expected 1"
51833      at_failed=:;;
51834esac
51835if $at_failed; then
51836
51837  echo 1 > $at_status_file
51838  exit 1
51839fi
51840
51841$at_traceon
51842
51843
51844# Normalize the observed and expected error messages, depending upon the
51845# options.
51846# 1. Remove the traces from observed.
51847sed '/^Starting/d
51848/^Entering/d
51849/^Stack/d
51850/^Reading/d
51851/^Reducing/d
51852/^Shifting/d
51853/^state/d
51854/^Cleanup:/d
51855/^Error:/d
51856/^Next/d
51857/^Discarding/d
51858/ \$[0-9$]* = /d
51859/^yydestructor:/d' stderr >at-stderr
51860mv at-stderr stderr
51861# 2. Create the reference error message.
51862cat >expout <<'_ATEOF'
518631.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
51864_ATEOF
51865
51866# 3. If locations are not used, remove them.
51867
51868# 4. If error-verbose is not used, strip the`, unexpected....' part.
51869
51870# 5. Check
51871$at_traceoff
51872echo "calc.at:651: cat stderr"
51873echo calc.at:651 >$at_check_line_file
51874( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
51875at_status=$?
51876grep '^ *+' $at_stder1 >&2
51877grep -v '^ *+' $at_stder1 >$at_stderr
51878at_failed=false
51879$at_diff $at_devnull $at_stderr || at_failed=:
51880$at_diff expout $at_stdout || at_failed=:
51881case $at_status in
51882   77) echo 77 > $at_status_file
51883            exit 77;;
51884   0) ;;
51885   *) echo "calc.at:651: exit code was $at_status, expected 0"
51886      at_failed=:;;
51887esac
51888if $at_failed; then
51889
51890  echo 1 > $at_status_file
51891  exit 1
51892fi
51893
51894$at_traceon
51895
51896
51897cat >input <<'_ATEOF'
51898error
51899_ATEOF
51900
51901$at_traceoff
51902echo "calc.at:651: \$PREPARSER ./calc input"
51903echo calc.at:651 >$at_check_line_file
51904( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
51905at_status=$?
51906grep '^ *+' $at_stder1 >&2
51907grep -v '^ *+' $at_stder1 >$at_stderr
51908at_failed=false
51909echo stderr:; tee stderr <$at_stderr
51910$at_diff $at_devnull $at_stdout || at_failed=:
51911case $at_status in
51912   77) echo 77 > $at_status_file
51913            exit 77;;
51914   1) ;;
51915   *) echo "calc.at:651: exit code was $at_status, expected 1"
51916      at_failed=:;;
51917esac
51918if $at_failed; then
51919
51920  echo 1 > $at_status_file
51921  exit 1
51922fi
51923
51924$at_traceon
51925
51926
51927# Normalize the observed and expected error messages, depending upon the
51928# options.
51929# 1. Remove the traces from observed.
51930sed '/^Starting/d
51931/^Entering/d
51932/^Stack/d
51933/^Reading/d
51934/^Reducing/d
51935/^Shifting/d
51936/^state/d
51937/^Cleanup:/d
51938/^Error:/d
51939/^Next/d
51940/^Discarding/d
51941/ \$[0-9$]* = /d
51942/^yydestructor:/d' stderr >at-stderr
51943mv at-stderr stderr
51944# 2. Create the reference error message.
51945cat >expout <<'_ATEOF'
519461.0: syntax error, unexpected $undefined
51947_ATEOF
51948
51949# 3. If locations are not used, remove them.
51950
51951# 4. If error-verbose is not used, strip the`, unexpected....' part.
51952
51953# 5. Check
51954$at_traceoff
51955echo "calc.at:651: cat stderr"
51956echo calc.at:651 >$at_check_line_file
51957( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
51958at_status=$?
51959grep '^ *+' $at_stder1 >&2
51960grep -v '^ *+' $at_stder1 >$at_stderr
51961at_failed=false
51962$at_diff $at_devnull $at_stderr || at_failed=:
51963$at_diff expout $at_stdout || at_failed=:
51964case $at_status in
51965   77) echo 77 > $at_status_file
51966            exit 77;;
51967   0) ;;
51968   *) echo "calc.at:651: exit code was $at_status, expected 0"
51969      at_failed=:;;
51970esac
51971if $at_failed; then
51972
51973  echo 1 > $at_status_file
51974  exit 1
51975fi
51976
51977$at_traceon
51978
51979
51980cat >input <<'_ATEOF'
519811 = 2 = 3
51982_ATEOF
51983
51984$at_traceoff
51985echo "calc.at:651: \$PREPARSER ./calc input"
51986echo calc.at:651 >$at_check_line_file
51987( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
51988at_status=$?
51989grep '^ *+' $at_stder1 >&2
51990grep -v '^ *+' $at_stder1 >$at_stderr
51991at_failed=false
51992echo stderr:; tee stderr <$at_stderr
51993$at_diff $at_devnull $at_stdout || at_failed=:
51994case $at_status in
51995   77) echo 77 > $at_status_file
51996            exit 77;;
51997   1) ;;
51998   *) echo "calc.at:651: exit code was $at_status, expected 1"
51999      at_failed=:;;
52000esac
52001if $at_failed; then
52002
52003  echo 1 > $at_status_file
52004  exit 1
52005fi
52006
52007$at_traceon
52008
52009
52010# Normalize the observed and expected error messages, depending upon the
52011# options.
52012# 1. Remove the traces from observed.
52013sed '/^Starting/d
52014/^Entering/d
52015/^Stack/d
52016/^Reading/d
52017/^Reducing/d
52018/^Shifting/d
52019/^state/d
52020/^Cleanup:/d
52021/^Error:/d
52022/^Next/d
52023/^Discarding/d
52024/ \$[0-9$]* = /d
52025/^yydestructor:/d' stderr >at-stderr
52026mv at-stderr stderr
52027# 2. Create the reference error message.
52028cat >expout <<'_ATEOF'
520291.6: syntax error, unexpected '='
52030_ATEOF
52031
52032# 3. If locations are not used, remove them.
52033
52034# 4. If error-verbose is not used, strip the`, unexpected....' part.
52035
52036# 5. Check
52037$at_traceoff
52038echo "calc.at:651: cat stderr"
52039echo calc.at:651 >$at_check_line_file
52040( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
52041at_status=$?
52042grep '^ *+' $at_stder1 >&2
52043grep -v '^ *+' $at_stder1 >$at_stderr
52044at_failed=false
52045$at_diff $at_devnull $at_stderr || at_failed=:
52046$at_diff expout $at_stdout || at_failed=:
52047case $at_status in
52048   77) echo 77 > $at_status_file
52049            exit 77;;
52050   0) ;;
52051   *) echo "calc.at:651: exit code was $at_status, expected 0"
52052      at_failed=:;;
52053esac
52054if $at_failed; then
52055
52056  echo 1 > $at_status_file
52057  exit 1
52058fi
52059
52060$at_traceon
52061
52062
52063cat >input <<'_ATEOF'
52064
52065+1
52066_ATEOF
52067
52068$at_traceoff
52069echo "calc.at:651: \$PREPARSER ./calc input"
52070echo calc.at:651 >$at_check_line_file
52071( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
52072at_status=$?
52073grep '^ *+' $at_stder1 >&2
52074grep -v '^ *+' $at_stder1 >$at_stderr
52075at_failed=false
52076echo stderr:; tee stderr <$at_stderr
52077$at_diff $at_devnull $at_stdout || at_failed=:
52078case $at_status in
52079   77) echo 77 > $at_status_file
52080            exit 77;;
52081   1) ;;
52082   *) echo "calc.at:651: exit code was $at_status, expected 1"
52083      at_failed=:;;
52084esac
52085if $at_failed; then
52086
52087  echo 1 > $at_status_file
52088  exit 1
52089fi
52090
52091$at_traceon
52092
52093
52094# Normalize the observed and expected error messages, depending upon the
52095# options.
52096# 1. Remove the traces from observed.
52097sed '/^Starting/d
52098/^Entering/d
52099/^Stack/d
52100/^Reading/d
52101/^Reducing/d
52102/^Shifting/d
52103/^state/d
52104/^Cleanup:/d
52105/^Error:/d
52106/^Next/d
52107/^Discarding/d
52108/ \$[0-9$]* = /d
52109/^yydestructor:/d' stderr >at-stderr
52110mv at-stderr stderr
52111# 2. Create the reference error message.
52112cat >expout <<'_ATEOF'
521132.0: syntax error, unexpected '+'
52114_ATEOF
52115
52116# 3. If locations are not used, remove them.
52117
52118# 4. If error-verbose is not used, strip the`, unexpected....' part.
52119
52120# 5. Check
52121$at_traceoff
52122echo "calc.at:651: cat stderr"
52123echo calc.at:651 >$at_check_line_file
52124( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
52125at_status=$?
52126grep '^ *+' $at_stder1 >&2
52127grep -v '^ *+' $at_stder1 >$at_stderr
52128at_failed=false
52129$at_diff $at_devnull $at_stderr || at_failed=:
52130$at_diff expout $at_stdout || at_failed=:
52131case $at_status in
52132   77) echo 77 > $at_status_file
52133            exit 77;;
52134   0) ;;
52135   *) echo "calc.at:651: exit code was $at_status, expected 0"
52136      at_failed=:;;
52137esac
52138if $at_failed; then
52139
52140  echo 1 > $at_status_file
52141  exit 1
52142fi
52143
52144$at_traceon
52145
52146
52147# Exercise error messages with EOF: work on an empty file.
52148$at_traceoff
52149echo "calc.at:651: \$PREPARSER ./calc /dev/null"
52150echo calc.at:651 >$at_check_line_file
52151( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
52152at_status=$?
52153grep '^ *+' $at_stder1 >&2
52154grep -v '^ *+' $at_stder1 >$at_stderr
52155at_failed=false
52156echo stderr:; tee stderr <$at_stderr
52157$at_diff $at_devnull $at_stdout || at_failed=:
52158case $at_status in
52159   77) echo 77 > $at_status_file
52160            exit 77;;
52161   1) ;;
52162   *) echo "calc.at:651: exit code was $at_status, expected 1"
52163      at_failed=:;;
52164esac
52165if $at_failed; then
52166
52167  echo 1 > $at_status_file
52168  exit 1
52169fi
52170
52171$at_traceon
52172
52173
52174# Normalize the observed and expected error messages, depending upon the
52175# options.
52176# 1. Remove the traces from observed.
52177sed '/^Starting/d
52178/^Entering/d
52179/^Stack/d
52180/^Reading/d
52181/^Reducing/d
52182/^Shifting/d
52183/^state/d
52184/^Cleanup:/d
52185/^Error:/d
52186/^Next/d
52187/^Discarding/d
52188/ \$[0-9$]* = /d
52189/^yydestructor:/d' stderr >at-stderr
52190mv at-stderr stderr
52191# 2. Create the reference error message.
52192cat >expout <<'_ATEOF'
521931.0: syntax error, unexpected end of input
52194_ATEOF
52195
52196# 3. If locations are not used, remove them.
52197
52198# 4. If error-verbose is not used, strip the`, unexpected....' part.
52199
52200# 5. Check
52201$at_traceoff
52202echo "calc.at:651: cat stderr"
52203echo calc.at:651 >$at_check_line_file
52204( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
52205at_status=$?
52206grep '^ *+' $at_stder1 >&2
52207grep -v '^ *+' $at_stder1 >$at_stderr
52208at_failed=false
52209$at_diff $at_devnull $at_stderr || at_failed=:
52210$at_diff expout $at_stdout || at_failed=:
52211case $at_status in
52212   77) echo 77 > $at_status_file
52213            exit 77;;
52214   0) ;;
52215   *) echo "calc.at:651: exit code was $at_status, expected 0"
52216      at_failed=:;;
52217esac
52218if $at_failed; then
52219
52220  echo 1 > $at_status_file
52221  exit 1
52222fi
52223
52224$at_traceon
52225
52226
52227
52228# Exercise the error token: without it, we die at the first error,
52229# hence be sure to
52230#
52231# - have several errors which exercise different shift/discardings
52232#   - (): nothing to pop, nothing to discard
52233#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
52234#   - (* * *): nothing to pop, a lot to discard
52235#   - (1 + 2 * *): some to pop and discard
52236#
52237# - test the action associated to `error'
52238#
52239# - check the look-ahead that triggers an error is not discarded
52240#   when we enter error recovery.  Below, the look-ahead causing the
52241#   first error is ")", which is needed to recover from the error and
52242#   produce the "0" that triggers the "0 != 1" error.
52243#
52244cat >input <<'_ATEOF'
52245() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
52246_ATEOF
52247
52248$at_traceoff
52249echo "calc.at:651: \$PREPARSER ./calc input"
52250echo calc.at:651 >$at_check_line_file
52251( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
52252at_status=$?
52253grep '^ *+' $at_stder1 >&2
52254grep -v '^ *+' $at_stder1 >$at_stderr
52255at_failed=false
52256echo stderr:; tee stderr <$at_stderr
52257$at_diff $at_devnull $at_stdout || at_failed=:
52258case $at_status in
52259   77) echo 77 > $at_status_file
52260            exit 77;;
52261   0) ;;
52262   *) echo "calc.at:651: exit code was $at_status, expected 0"
52263      at_failed=:;;
52264esac
52265if $at_failed; then
52266
52267  echo 1 > $at_status_file
52268  exit 1
52269fi
52270
52271$at_traceon
52272
52273
52274# Normalize the observed and expected error messages, depending upon the
52275# options.
52276# 1. Remove the traces from observed.
52277sed '/^Starting/d
52278/^Entering/d
52279/^Stack/d
52280/^Reading/d
52281/^Reducing/d
52282/^Shifting/d
52283/^state/d
52284/^Cleanup:/d
52285/^Error:/d
52286/^Next/d
52287/^Discarding/d
52288/ \$[0-9$]* = /d
52289/^yydestructor:/d' stderr >at-stderr
52290mv at-stderr stderr
52291# 2. Create the reference error message.
52292cat >expout <<'_ATEOF'
522931.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
522941.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
522951.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
522961.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
52297calc: error: 4444 != 1
52298_ATEOF
52299
52300# 3. If locations are not used, remove them.
52301
52302# 4. If error-verbose is not used, strip the`, unexpected....' part.
52303
52304# 5. Check
52305$at_traceoff
52306echo "calc.at:651: cat stderr"
52307echo calc.at:651 >$at_check_line_file
52308( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
52309at_status=$?
52310grep '^ *+' $at_stder1 >&2
52311grep -v '^ *+' $at_stder1 >$at_stderr
52312at_failed=false
52313$at_diff $at_devnull $at_stderr || at_failed=:
52314$at_diff expout $at_stdout || at_failed=:
52315case $at_status in
52316   77) echo 77 > $at_status_file
52317            exit 77;;
52318   0) ;;
52319   *) echo "calc.at:651: exit code was $at_status, expected 0"
52320      at_failed=:;;
52321esac
52322if $at_failed; then
52323
52324  echo 1 > $at_status_file
52325  exit 1
52326fi
52327
52328$at_traceon
52329
52330
52331
52332# The same, but this time exercising explicitly triggered syntax errors.
52333# POSIX says the look-ahead causing the error should not be discarded.
52334cat >input <<'_ATEOF'
52335(!) + (0 0) = 1
52336_ATEOF
52337
52338$at_traceoff
52339echo "calc.at:651: \$PREPARSER ./calc input"
52340echo calc.at:651 >$at_check_line_file
52341( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
52342at_status=$?
52343grep '^ *+' $at_stder1 >&2
52344grep -v '^ *+' $at_stder1 >$at_stderr
52345at_failed=false
52346echo stderr:; tee stderr <$at_stderr
52347$at_diff $at_devnull $at_stdout || at_failed=:
52348case $at_status in
52349   77) echo 77 > $at_status_file
52350            exit 77;;
52351   0) ;;
52352   *) echo "calc.at:651: exit code was $at_status, expected 0"
52353      at_failed=:;;
52354esac
52355if $at_failed; then
52356
52357  echo 1 > $at_status_file
52358  exit 1
52359fi
52360
52361$at_traceon
52362
52363
52364# Normalize the observed and expected error messages, depending upon the
52365# options.
52366# 1. Remove the traces from observed.
52367sed '/^Starting/d
52368/^Entering/d
52369/^Stack/d
52370/^Reading/d
52371/^Reducing/d
52372/^Shifting/d
52373/^state/d
52374/^Cleanup:/d
52375/^Error:/d
52376/^Next/d
52377/^Discarding/d
52378/ \$[0-9$]* = /d
52379/^yydestructor:/d' stderr >at-stderr
52380mv at-stderr stderr
52381# 2. Create the reference error message.
52382cat >expout <<'_ATEOF'
523831.9: syntax error, unexpected number
52384calc: error: 2222 != 1
52385_ATEOF
52386
52387# 3. If locations are not used, remove them.
52388
52389# 4. If error-verbose is not used, strip the`, unexpected....' part.
52390
52391# 5. Check
52392$at_traceoff
52393echo "calc.at:651: cat stderr"
52394echo calc.at:651 >$at_check_line_file
52395( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
52396at_status=$?
52397grep '^ *+' $at_stder1 >&2
52398grep -v '^ *+' $at_stder1 >$at_stderr
52399at_failed=false
52400$at_diff $at_devnull $at_stderr || at_failed=:
52401$at_diff expout $at_stdout || at_failed=:
52402case $at_status in
52403   77) echo 77 > $at_status_file
52404            exit 77;;
52405   0) ;;
52406   *) echo "calc.at:651: exit code was $at_status, expected 0"
52407      at_failed=:;;
52408esac
52409if $at_failed; then
52410
52411  echo 1 > $at_status_file
52412  exit 1
52413fi
52414
52415$at_traceon
52416
52417
52418cat >input <<'_ATEOF'
52419(- *) + (0 0) = 1
52420_ATEOF
52421
52422$at_traceoff
52423echo "calc.at:651: \$PREPARSER ./calc input"
52424echo calc.at:651 >$at_check_line_file
52425( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
52426at_status=$?
52427grep '^ *+' $at_stder1 >&2
52428grep -v '^ *+' $at_stder1 >$at_stderr
52429at_failed=false
52430echo stderr:; tee stderr <$at_stderr
52431$at_diff $at_devnull $at_stdout || at_failed=:
52432case $at_status in
52433   77) echo 77 > $at_status_file
52434            exit 77;;
52435   0) ;;
52436   *) echo "calc.at:651: exit code was $at_status, expected 0"
52437      at_failed=:;;
52438esac
52439if $at_failed; then
52440
52441  echo 1 > $at_status_file
52442  exit 1
52443fi
52444
52445$at_traceon
52446
52447
52448# Normalize the observed and expected error messages, depending upon the
52449# options.
52450# 1. Remove the traces from observed.
52451sed '/^Starting/d
52452/^Entering/d
52453/^Stack/d
52454/^Reading/d
52455/^Reducing/d
52456/^Shifting/d
52457/^state/d
52458/^Cleanup:/d
52459/^Error:/d
52460/^Next/d
52461/^Discarding/d
52462/ \$[0-9$]* = /d
52463/^yydestructor:/d' stderr >at-stderr
52464mv at-stderr stderr
52465# 2. Create the reference error message.
52466cat >expout <<'_ATEOF'
524671.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
524681.11: syntax error, unexpected number
52469calc: error: 2222 != 1
52470_ATEOF
52471
52472# 3. If locations are not used, remove them.
52473
52474# 4. If error-verbose is not used, strip the`, unexpected....' part.
52475
52476# 5. Check
52477$at_traceoff
52478echo "calc.at:651: cat stderr"
52479echo calc.at:651 >$at_check_line_file
52480( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
52481at_status=$?
52482grep '^ *+' $at_stder1 >&2
52483grep -v '^ *+' $at_stder1 >$at_stderr
52484at_failed=false
52485$at_diff $at_devnull $at_stderr || at_failed=:
52486$at_diff expout $at_stdout || at_failed=:
52487case $at_status in
52488   77) echo 77 > $at_status_file
52489            exit 77;;
52490   0) ;;
52491   *) echo "calc.at:651: exit code was $at_status, expected 0"
52492      at_failed=:;;
52493esac
52494if $at_failed; then
52495
52496  echo 1 > $at_status_file
52497  exit 1
52498fi
52499
52500$at_traceon
52501
52502
52503
52504
52505
52506
52507
52508
52509
52510
52511
52512
52513
52514
52515
52516
52517
52518
52519
52520
52521
52522
52523
52524
52525      $at_traceoff
52526      $at_times_p && times >$at_times_file
52527    ) 5>&1 2>&1 | eval $at_tee_pipe
52528    at_status=`cat $at_status_file`
52529    ;;
52530
52531  104 ) # 104. calc.at:653: Calculator %skeleton "glr.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}
52532    at_setup_line='calc.at:653'
52533    at_desc='Calculator %skeleton "glr.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}'
52534    $at_quiet $ECHO_N "104: Calculator %skeleton "glr.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}$ECHO_C"
52535    at_xfail=no
52536    (
52537      echo "104. calc.at:653: testing ..."
52538      $at_traceon
52539
52540
52541
52542
52543
52544
52545
52546
52547# Using yacc.c?
52548
52549
52550
52551
52552
52553
52554
52555# yyerror receives the location if %location & %pure & (%glr or %parse-param).
52556
52557# yyerror always sees the locations (when activated), except if
52558# yacc & pure & !param.
52559
52560
52561# The interface is pure: either because %pure-parser, or because we
52562# are using the C++ parsers.
52563
52564
52565
52566
52567
52568
52569
52570
52571
52572
52573
52574
52575cat >calc.y <<'_ATEOF'
52576%{
52577#ifdef HAVE_CONFIG_H
52578# include <config.h>
52579  /* We don't need perfect functions for these tests. */
52580# undef malloc
52581# undef memcmp
52582# undef realloc
52583#endif
52584%}
52585
52586/* Infix notation calculator--calc */
52587%skeleton "glr.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}
52588%define "global_tokens_and_yystype"
52589%{
52590#include <stdio.h>
52591
52592#include <stdlib.h>
52593#include <string.h>
52594#if HAVE_UNISTD_H
52595# include <unistd.h>
52596#else
52597# undef alarm
52598# define alarm(seconds) /* empty */
52599#endif
52600#include <ctype.h>
52601#define USE(Var)
52602
52603/* Exercise pre-prologue dependency to %union.  */
52604typedef int semantic_value;
52605
52606static semantic_value global_result = 0;
52607static int global_count = 0;
52608%}
52609
52610/* Exercise %union. */
52611%union
52612{
52613  semantic_value ival;
52614};
52615
52616%{
52617static int power (int base, int exponent);
52618#ifndef YYLTYPE
52619# define YYLTYPE calc::location
52620#endif
52621#define first_line   begin.line
52622#define first_column begin.column
52623#define last_line    end.line
52624#define last_column  end.column
52625
52626static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp);
52627static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp);
52628static void unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c);
52629%}
52630
52631/* The lalr1.cc skeleton, for backward compatibility, defines
52632   a constructor for position that initializes the filename.  The
52633   glr.cc skeleton does not (and in fact cannot: location/position
52634   are stored in a union, from which objects with constructors are
52635   excluded in C++. */
52636%initial-action {
52637  @$.initialize (0);
52638}
52639
52640
52641/* Bison Declarations */
52642%token CALC_EOF 0 "end of input"
52643%token <ival> NUM "number"
52644%type  <ival> exp
52645
52646%nonassoc '=' /* comparison	       */
52647%left '-' '+'
52648%left '*' '/'
52649%left NEG     /* negation--unary minus */
52650%right '^'    /* exponentiation        */
52651
52652/* Grammar follows */
52653%%
52654input:
52655  line
52656| input line         { ++*count; ++global_count; }
52657;
52658
52659line:
52660  '\n'
52661| exp '\n'           { *result = global_result = $1; }
52662;
52663
52664exp:
52665  NUM                { $$ = $1;             }
52666| exp '=' exp
52667  {
52668    if ($1 != $3)
52669      fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
52670    $$ = $1;
52671  }
52672| exp '+' exp        { $$ = $1 + $3;        }
52673| exp '-' exp        { $$ = $1 - $3;        }
52674| exp '*' exp        { $$ = $1 * $3;        }
52675| exp '/' exp        { $$ = $1 / $3;        }
52676| '-' exp  %prec NEG { $$ = -$2;            }
52677| exp '^' exp        { $$ = power ($1, $3); }
52678| '(' exp ')'        { $$ = $2;             }
52679| '(' error ')'      { $$ = 1111;           }
52680| '!'                { $$ = 0; YYERROR;     }
52681| '-' error          { $$ = 0; YYERROR;     }
52682;
52683%%
52684/* The input.  */
52685static FILE *input;
52686
52687/* A C++ error reporting function.  */
52688void
52689calc::parser::error (const location& l, const std::string& m)
52690{
52691  (void) l;
52692  std::cerr << l << ": " << m << std::endl;
52693}
52694
52695int
52696yyparse (semantic_value *result, int *count)
52697{
52698  calc::parser parser (result, count);
52699  parser.set_debug_level (!!YYDEBUG);
52700  return parser.parse ();
52701}
52702
52703
52704
52705
52706static YYLTYPE last_yylloc;
52707
52708static int
52709get_char (YYSTYPE *lvalp, YYLTYPE *llocp)
52710{
52711  int res = getc (input);
52712  (void) lvalp;(void) llocp;
52713
52714  last_yylloc = (*llocp);
52715  if (res == '\n')
52716    {
52717      (*llocp).last_line++;
52718      (*llocp).last_column = 0;
52719    }
52720  else
52721    (*llocp).last_column++;
52722
52723  return res;
52724}
52725
52726
52727static void
52728unget_char (YYSTYPE *lvalp, YYLTYPE *llocp,  int c)
52729{
52730  (void) lvalp;(void) llocp;
52731
52732  /* Wrong when C == `\n'. */
52733  (*llocp) = last_yylloc;
52734
52735  ungetc (c, input);
52736}
52737
52738static int
52739read_signed_integer (YYSTYPE *lvalp, YYLTYPE *llocp)
52740{
52741  int c = get_char (lvalp, llocp);
52742  int sign = 1;
52743  int n = 0;
52744
52745  (void) lvalp;(void) llocp;
52746  if (c == '-')
52747    {
52748      c = get_char (lvalp, llocp);
52749      sign = -1;
52750    }
52751
52752  while (isdigit (c))
52753    {
52754      n = 10 * n + (c - '0');
52755      c = get_char (lvalp, llocp);
52756    }
52757
52758  unget_char (lvalp, llocp,  c);
52759
52760  return sign * n;
52761}
52762
52763
52764
52765/*---------------------------------------------------------------.
52766| Lexical analyzer returns an integer on the stack and the token |
52767| NUM, or the ASCII character read if not a number.  Skips all   |
52768| blanks and tabs, returns 0 for EOF.                            |
52769`---------------------------------------------------------------*/
52770
52771static int
52772yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
52773{
52774  static int init = 1;
52775  int c;
52776
52777  if (init)
52778    {
52779      init = 0;
52780
52781      (*llocp).last_column = 0;
52782      (*llocp).last_line = 1;
52783
52784    }
52785
52786
52787 (*llocp).first_column = (*llocp).last_column;
52788  (*llocp).first_line   = (*llocp).last_line;
52789
52790
52791  /* Skip white space.  */
52792  while ((c = get_char (lvalp, llocp)) == ' ' || c == '\t')
52793    {
52794     (*llocp).first_column = (*llocp).last_column;
52795      (*llocp).first_line   = (*llocp).last_line;
52796
52797    }
52798
52799  /* process numbers   */
52800  if (c == '.' || isdigit (c))
52801    {
52802      unget_char (lvalp, llocp,  c);
52803      (*lvalp).ival = read_signed_integer (lvalp, llocp);
52804      return NUM;
52805    }
52806
52807  /* Return end-of-file.  */
52808  if (c == EOF)
52809    return CALC_EOF;
52810
52811  /* Return single chars. */
52812  return c;
52813}
52814
52815static int
52816power (int base, int exponent)
52817{
52818  int res = 1;
52819  if (exponent < 0)
52820    exit (3);
52821  for (/* Niente */; exponent; --exponent)
52822    res *= base;
52823  return res;
52824}
52825
52826
52827int
52828main (int argc, const char **argv)
52829{
52830  semantic_value result = 0;
52831  int count = 0;
52832  int status;
52833
52834  /* This used to be alarm (10), but that isn't enough time for
52835     a July 1995 vintage DEC Alphastation 200 4/100 system,
52836     according to Nelson H. F. Beebe.  100 seconds is enough.  */
52837  alarm (100);
52838
52839  if (argc == 2)
52840    input = fopen (argv[1], "r");
52841  else
52842    input = stdin;
52843
52844  if (!input)
52845    {
52846      perror (argv[1]);
52847      return 3;
52848    }
52849
52850
52851  status = yyparse (&result, &count);
52852  if (global_result != result)
52853    abort ();
52854  if (global_count != count)
52855    abort ();
52856  return status;
52857}
52858_ATEOF
52859
52860
52861
52862
52863
52864$at_traceoff
52865echo "calc.at:653: bison -o calc.cc calc.y"
52866echo calc.at:653 >$at_check_line_file
52867( $at_traceon; bison -o calc.cc calc.y ) >$at_stdout 2>$at_stder1
52868at_status=$?
52869grep '^ *+' $at_stder1 >&2
52870grep -v '^ *+' $at_stder1 >$at_stderr
52871at_failed=false
52872$at_diff $at_devnull $at_stderr || at_failed=:
52873$at_diff $at_devnull $at_stdout || at_failed=:
52874case $at_status in
52875   77) echo 77 > $at_status_file
52876            exit 77;;
52877   0) ;;
52878   *) echo "calc.at:653: exit code was $at_status, expected 0"
52879      at_failed=:;;
52880esac
52881if $at_failed; then
52882
52883  echo 1 > $at_status_file
52884  exit 1
52885fi
52886
52887$at_traceon
52888
52889
52890$at_traceoff
52891echo "calc.at:653: \$BISON_CXX_WORKS"
52892echo calc.at:653 >$at_check_line_file
52893( $at_traceon; $BISON_CXX_WORKS ) >$at_stdout 2>$at_stder1
52894at_status=$?
52895grep '^ *+' $at_stder1 >&2
52896grep -v '^ *+' $at_stder1 >$at_stderr
52897at_failed=false
52898echo stderr:; cat $at_stderr
52899echo stdout:; cat $at_stdout
52900case $at_status in
52901   77) echo 77 > $at_status_file
52902            exit 77;;
52903   0) ;;
52904   *) echo "calc.at:653: exit code was $at_status, expected 0"
52905      at_failed=:;;
52906esac
52907if $at_failed; then
52908
52909  echo 1 > $at_status_file
52910  exit 1
52911fi
52912
52913$at_traceon
52914
52915$at_traceoff
52916echo "calc.at:653: \$CXX \$CXXFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.cc \$LIBS"
52917echo calc.at:653 >$at_check_line_file
52918( $at_traceon; $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o calc calc.cc $LIBS ) >$at_stdout 2>$at_stder1
52919at_status=$?
52920grep '^ *+' $at_stder1 >&2
52921grep -v '^ *+' $at_stder1 >$at_stderr
52922at_failed=false
52923echo stderr:; cat $at_stderr
52924echo stdout:; cat $at_stdout
52925case $at_status in
52926   77) echo 77 > $at_status_file
52927            exit 77;;
52928   0) ;;
52929   *) echo "calc.at:653: exit code was $at_status, expected 0"
52930      at_failed=:;;
52931esac
52932if $at_failed; then
52933
52934  echo 1 > $at_status_file
52935  exit 1
52936fi
52937
52938$at_traceon
52939
52940
52941# Test the priorities.
52942cat >input <<'_ATEOF'
529431 + 2 * 3 = 7
529441 + 2 * -3 = -5
52945
52946-1^2 = -1
52947(-1)^2 = 1
52948
52949---1 = -1
52950
529511 - 2 - 3 = -4
529521 - (2 - 3) = 2
52953
529542^2^3 = 256
52955(2^2)^3 = 64
52956_ATEOF
52957
52958$at_traceoff
52959echo "calc.at:653: \$PREPARSER ./calc input"
52960echo calc.at:653 >$at_check_line_file
52961( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
52962at_status=$?
52963grep '^ *+' $at_stder1 >&2
52964grep -v '^ *+' $at_stder1 >$at_stderr
52965at_failed=false
52966echo stderr:; tee stderr <$at_stderr
52967$at_diff $at_devnull $at_stdout || at_failed=:
52968case $at_status in
52969   77) echo 77 > $at_status_file
52970            exit 77;;
52971   0) ;;
52972   *) echo "calc.at:653: exit code was $at_status, expected 0"
52973      at_failed=:;;
52974esac
52975if $at_failed; then
52976
52977  echo 1 > $at_status_file
52978  exit 1
52979fi
52980
52981$at_traceon
52982
52983
52984
52985# Some syntax errors.
52986cat >input <<'_ATEOF'
529870 0
52988_ATEOF
52989
52990$at_traceoff
52991echo "calc.at:653: \$PREPARSER ./calc input"
52992echo calc.at:653 >$at_check_line_file
52993( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
52994at_status=$?
52995grep '^ *+' $at_stder1 >&2
52996grep -v '^ *+' $at_stder1 >$at_stderr
52997at_failed=false
52998echo stderr:; tee stderr <$at_stderr
52999$at_diff $at_devnull $at_stdout || at_failed=:
53000case $at_status in
53001   77) echo 77 > $at_status_file
53002            exit 77;;
53003   1) ;;
53004   *) echo "calc.at:653: exit code was $at_status, expected 1"
53005      at_failed=:;;
53006esac
53007if $at_failed; then
53008
53009  echo 1 > $at_status_file
53010  exit 1
53011fi
53012
53013$at_traceon
53014
53015
53016# Normalize the observed and expected error messages, depending upon the
53017# options.
53018# 1. Remove the traces from observed.
53019sed '/^Starting/d
53020/^Entering/d
53021/^Stack/d
53022/^Reading/d
53023/^Reducing/d
53024/^Shifting/d
53025/^state/d
53026/^Cleanup:/d
53027/^Error:/d
53028/^Next/d
53029/^Discarding/d
53030/ \$[0-9$]* = /d
53031/^yydestructor:/d' stderr >at-stderr
53032mv at-stderr stderr
53033# 2. Create the reference error message.
53034cat >expout <<'_ATEOF'
530351.2: syntax error, unexpected number
53036_ATEOF
53037
53038# 3. If locations are not used, remove them.
53039
53040# 4. If error-verbose is not used, strip the`, unexpected....' part.
53041
53042# 5. Check
53043$at_traceoff
53044echo "calc.at:653: cat stderr"
53045echo calc.at:653 >$at_check_line_file
53046( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
53047at_status=$?
53048grep '^ *+' $at_stder1 >&2
53049grep -v '^ *+' $at_stder1 >$at_stderr
53050at_failed=false
53051$at_diff $at_devnull $at_stderr || at_failed=:
53052$at_diff expout $at_stdout || at_failed=:
53053case $at_status in
53054   77) echo 77 > $at_status_file
53055            exit 77;;
53056   0) ;;
53057   *) echo "calc.at:653: exit code was $at_status, expected 0"
53058      at_failed=:;;
53059esac
53060if $at_failed; then
53061
53062  echo 1 > $at_status_file
53063  exit 1
53064fi
53065
53066$at_traceon
53067
53068
53069cat >input <<'_ATEOF'
530701//2
53071_ATEOF
53072
53073$at_traceoff
53074echo "calc.at:653: \$PREPARSER ./calc input"
53075echo calc.at:653 >$at_check_line_file
53076( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
53077at_status=$?
53078grep '^ *+' $at_stder1 >&2
53079grep -v '^ *+' $at_stder1 >$at_stderr
53080at_failed=false
53081echo stderr:; tee stderr <$at_stderr
53082$at_diff $at_devnull $at_stdout || at_failed=:
53083case $at_status in
53084   77) echo 77 > $at_status_file
53085            exit 77;;
53086   1) ;;
53087   *) echo "calc.at:653: exit code was $at_status, expected 1"
53088      at_failed=:;;
53089esac
53090if $at_failed; then
53091
53092  echo 1 > $at_status_file
53093  exit 1
53094fi
53095
53096$at_traceon
53097
53098
53099# Normalize the observed and expected error messages, depending upon the
53100# options.
53101# 1. Remove the traces from observed.
53102sed '/^Starting/d
53103/^Entering/d
53104/^Stack/d
53105/^Reading/d
53106/^Reducing/d
53107/^Shifting/d
53108/^state/d
53109/^Cleanup:/d
53110/^Error:/d
53111/^Next/d
53112/^Discarding/d
53113/ \$[0-9$]* = /d
53114/^yydestructor:/d' stderr >at-stderr
53115mv at-stderr stderr
53116# 2. Create the reference error message.
53117cat >expout <<'_ATEOF'
531181.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!'
53119_ATEOF
53120
53121# 3. If locations are not used, remove them.
53122
53123# 4. If error-verbose is not used, strip the`, unexpected....' part.
53124
53125# 5. Check
53126$at_traceoff
53127echo "calc.at:653: cat stderr"
53128echo calc.at:653 >$at_check_line_file
53129( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
53130at_status=$?
53131grep '^ *+' $at_stder1 >&2
53132grep -v '^ *+' $at_stder1 >$at_stderr
53133at_failed=false
53134$at_diff $at_devnull $at_stderr || at_failed=:
53135$at_diff expout $at_stdout || at_failed=:
53136case $at_status in
53137   77) echo 77 > $at_status_file
53138            exit 77;;
53139   0) ;;
53140   *) echo "calc.at:653: exit code was $at_status, expected 0"
53141      at_failed=:;;
53142esac
53143if $at_failed; then
53144
53145  echo 1 > $at_status_file
53146  exit 1
53147fi
53148
53149$at_traceon
53150
53151
53152cat >input <<'_ATEOF'
53153error
53154_ATEOF
53155
53156$at_traceoff
53157echo "calc.at:653: \$PREPARSER ./calc input"
53158echo calc.at:653 >$at_check_line_file
53159( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
53160at_status=$?
53161grep '^ *+' $at_stder1 >&2
53162grep -v '^ *+' $at_stder1 >$at_stderr
53163at_failed=false
53164echo stderr:; tee stderr <$at_stderr
53165$at_diff $at_devnull $at_stdout || at_failed=:
53166case $at_status in
53167   77) echo 77 > $at_status_file
53168            exit 77;;
53169   1) ;;
53170   *) echo "calc.at:653: exit code was $at_status, expected 1"
53171      at_failed=:;;
53172esac
53173if $at_failed; then
53174
53175  echo 1 > $at_status_file
53176  exit 1
53177fi
53178
53179$at_traceon
53180
53181
53182# Normalize the observed and expected error messages, depending upon the
53183# options.
53184# 1. Remove the traces from observed.
53185sed '/^Starting/d
53186/^Entering/d
53187/^Stack/d
53188/^Reading/d
53189/^Reducing/d
53190/^Shifting/d
53191/^state/d
53192/^Cleanup:/d
53193/^Error:/d
53194/^Next/d
53195/^Discarding/d
53196/ \$[0-9$]* = /d
53197/^yydestructor:/d' stderr >at-stderr
53198mv at-stderr stderr
53199# 2. Create the reference error message.
53200cat >expout <<'_ATEOF'
532011.0: syntax error, unexpected $undefined
53202_ATEOF
53203
53204# 3. If locations are not used, remove them.
53205
53206# 4. If error-verbose is not used, strip the`, unexpected....' part.
53207
53208# 5. Check
53209$at_traceoff
53210echo "calc.at:653: cat stderr"
53211echo calc.at:653 >$at_check_line_file
53212( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
53213at_status=$?
53214grep '^ *+' $at_stder1 >&2
53215grep -v '^ *+' $at_stder1 >$at_stderr
53216at_failed=false
53217$at_diff $at_devnull $at_stderr || at_failed=:
53218$at_diff expout $at_stdout || at_failed=:
53219case $at_status in
53220   77) echo 77 > $at_status_file
53221            exit 77;;
53222   0) ;;
53223   *) echo "calc.at:653: exit code was $at_status, expected 0"
53224      at_failed=:;;
53225esac
53226if $at_failed; then
53227
53228  echo 1 > $at_status_file
53229  exit 1
53230fi
53231
53232$at_traceon
53233
53234
53235cat >input <<'_ATEOF'
532361 = 2 = 3
53237_ATEOF
53238
53239$at_traceoff
53240echo "calc.at:653: \$PREPARSER ./calc input"
53241echo calc.at:653 >$at_check_line_file
53242( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
53243at_status=$?
53244grep '^ *+' $at_stder1 >&2
53245grep -v '^ *+' $at_stder1 >$at_stderr
53246at_failed=false
53247echo stderr:; tee stderr <$at_stderr
53248$at_diff $at_devnull $at_stdout || at_failed=:
53249case $at_status in
53250   77) echo 77 > $at_status_file
53251            exit 77;;
53252   1) ;;
53253   *) echo "calc.at:653: exit code was $at_status, expected 1"
53254      at_failed=:;;
53255esac
53256if $at_failed; then
53257
53258  echo 1 > $at_status_file
53259  exit 1
53260fi
53261
53262$at_traceon
53263
53264
53265# Normalize the observed and expected error messages, depending upon the
53266# options.
53267# 1. Remove the traces from observed.
53268sed '/^Starting/d
53269/^Entering/d
53270/^Stack/d
53271/^Reading/d
53272/^Reducing/d
53273/^Shifting/d
53274/^state/d
53275/^Cleanup:/d
53276/^Error:/d
53277/^Next/d
53278/^Discarding/d
53279/ \$[0-9$]* = /d
53280/^yydestructor:/d' stderr >at-stderr
53281mv at-stderr stderr
53282# 2. Create the reference error message.
53283cat >expout <<'_ATEOF'
532841.6: syntax error, unexpected '='
53285_ATEOF
53286
53287# 3. If locations are not used, remove them.
53288
53289# 4. If error-verbose is not used, strip the`, unexpected....' part.
53290
53291# 5. Check
53292$at_traceoff
53293echo "calc.at:653: cat stderr"
53294echo calc.at:653 >$at_check_line_file
53295( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
53296at_status=$?
53297grep '^ *+' $at_stder1 >&2
53298grep -v '^ *+' $at_stder1 >$at_stderr
53299at_failed=false
53300$at_diff $at_devnull $at_stderr || at_failed=:
53301$at_diff expout $at_stdout || at_failed=:
53302case $at_status in
53303   77) echo 77 > $at_status_file
53304            exit 77;;
53305   0) ;;
53306   *) echo "calc.at:653: exit code was $at_status, expected 0"
53307      at_failed=:;;
53308esac
53309if $at_failed; then
53310
53311  echo 1 > $at_status_file
53312  exit 1
53313fi
53314
53315$at_traceon
53316
53317
53318cat >input <<'_ATEOF'
53319
53320+1
53321_ATEOF
53322
53323$at_traceoff
53324echo "calc.at:653: \$PREPARSER ./calc input"
53325echo calc.at:653 >$at_check_line_file
53326( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
53327at_status=$?
53328grep '^ *+' $at_stder1 >&2
53329grep -v '^ *+' $at_stder1 >$at_stderr
53330at_failed=false
53331echo stderr:; tee stderr <$at_stderr
53332$at_diff $at_devnull $at_stdout || at_failed=:
53333case $at_status in
53334   77) echo 77 > $at_status_file
53335            exit 77;;
53336   1) ;;
53337   *) echo "calc.at:653: exit code was $at_status, expected 1"
53338      at_failed=:;;
53339esac
53340if $at_failed; then
53341
53342  echo 1 > $at_status_file
53343  exit 1
53344fi
53345
53346$at_traceon
53347
53348
53349# Normalize the observed and expected error messages, depending upon the
53350# options.
53351# 1. Remove the traces from observed.
53352sed '/^Starting/d
53353/^Entering/d
53354/^Stack/d
53355/^Reading/d
53356/^Reducing/d
53357/^Shifting/d
53358/^state/d
53359/^Cleanup:/d
53360/^Error:/d
53361/^Next/d
53362/^Discarding/d
53363/ \$[0-9$]* = /d
53364/^yydestructor:/d' stderr >at-stderr
53365mv at-stderr stderr
53366# 2. Create the reference error message.
53367cat >expout <<'_ATEOF'
533682.0: syntax error, unexpected '+'
53369_ATEOF
53370
53371# 3. If locations are not used, remove them.
53372
53373# 4. If error-verbose is not used, strip the`, unexpected....' part.
53374
53375# 5. Check
53376$at_traceoff
53377echo "calc.at:653: cat stderr"
53378echo calc.at:653 >$at_check_line_file
53379( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
53380at_status=$?
53381grep '^ *+' $at_stder1 >&2
53382grep -v '^ *+' $at_stder1 >$at_stderr
53383at_failed=false
53384$at_diff $at_devnull $at_stderr || at_failed=:
53385$at_diff expout $at_stdout || at_failed=:
53386case $at_status in
53387   77) echo 77 > $at_status_file
53388            exit 77;;
53389   0) ;;
53390   *) echo "calc.at:653: exit code was $at_status, expected 0"
53391      at_failed=:;;
53392esac
53393if $at_failed; then
53394
53395  echo 1 > $at_status_file
53396  exit 1
53397fi
53398
53399$at_traceon
53400
53401
53402# Exercise error messages with EOF: work on an empty file.
53403$at_traceoff
53404echo "calc.at:653: \$PREPARSER ./calc /dev/null"
53405echo calc.at:653 >$at_check_line_file
53406( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1
53407at_status=$?
53408grep '^ *+' $at_stder1 >&2
53409grep -v '^ *+' $at_stder1 >$at_stderr
53410at_failed=false
53411echo stderr:; tee stderr <$at_stderr
53412$at_diff $at_devnull $at_stdout || at_failed=:
53413case $at_status in
53414   77) echo 77 > $at_status_file
53415            exit 77;;
53416   1) ;;
53417   *) echo "calc.at:653: exit code was $at_status, expected 1"
53418      at_failed=:;;
53419esac
53420if $at_failed; then
53421
53422  echo 1 > $at_status_file
53423  exit 1
53424fi
53425
53426$at_traceon
53427
53428
53429# Normalize the observed and expected error messages, depending upon the
53430# options.
53431# 1. Remove the traces from observed.
53432sed '/^Starting/d
53433/^Entering/d
53434/^Stack/d
53435/^Reading/d
53436/^Reducing/d
53437/^Shifting/d
53438/^state/d
53439/^Cleanup:/d
53440/^Error:/d
53441/^Next/d
53442/^Discarding/d
53443/ \$[0-9$]* = /d
53444/^yydestructor:/d' stderr >at-stderr
53445mv at-stderr stderr
53446# 2. Create the reference error message.
53447cat >expout <<'_ATEOF'
534481.0: syntax error, unexpected end of input
53449_ATEOF
53450
53451# 3. If locations are not used, remove them.
53452
53453# 4. If error-verbose is not used, strip the`, unexpected....' part.
53454
53455# 5. Check
53456$at_traceoff
53457echo "calc.at:653: cat stderr"
53458echo calc.at:653 >$at_check_line_file
53459( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
53460at_status=$?
53461grep '^ *+' $at_stder1 >&2
53462grep -v '^ *+' $at_stder1 >$at_stderr
53463at_failed=false
53464$at_diff $at_devnull $at_stderr || at_failed=:
53465$at_diff expout $at_stdout || at_failed=:
53466case $at_status in
53467   77) echo 77 > $at_status_file
53468            exit 77;;
53469   0) ;;
53470   *) echo "calc.at:653: exit code was $at_status, expected 0"
53471      at_failed=:;;
53472esac
53473if $at_failed; then
53474
53475  echo 1 > $at_status_file
53476  exit 1
53477fi
53478
53479$at_traceon
53480
53481
53482
53483# Exercise the error token: without it, we die at the first error,
53484# hence be sure to
53485#
53486# - have several errors which exercise different shift/discardings
53487#   - (): nothing to pop, nothing to discard
53488#   - (1 + 1 + 1 +): a lot to pop, nothing to discard
53489#   - (* * *): nothing to pop, a lot to discard
53490#   - (1 + 2 * *): some to pop and discard
53491#
53492# - test the action associated to `error'
53493#
53494# - check the look-ahead that triggers an error is not discarded
53495#   when we enter error recovery.  Below, the look-ahead causing the
53496#   first error is ")", which is needed to recover from the error and
53497#   produce the "0" that triggers the "0 != 1" error.
53498#
53499cat >input <<'_ATEOF'
53500() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1
53501_ATEOF
53502
53503$at_traceoff
53504echo "calc.at:653: \$PREPARSER ./calc input"
53505echo calc.at:653 >$at_check_line_file
53506( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
53507at_status=$?
53508grep '^ *+' $at_stder1 >&2
53509grep -v '^ *+' $at_stder1 >$at_stderr
53510at_failed=false
53511echo stderr:; tee stderr <$at_stderr
53512$at_diff $at_devnull $at_stdout || at_failed=:
53513case $at_status in
53514   77) echo 77 > $at_status_file
53515            exit 77;;
53516   0) ;;
53517   *) echo "calc.at:653: exit code was $at_status, expected 0"
53518      at_failed=:;;
53519esac
53520if $at_failed; then
53521
53522  echo 1 > $at_status_file
53523  exit 1
53524fi
53525
53526$at_traceon
53527
53528
53529# Normalize the observed and expected error messages, depending upon the
53530# options.
53531# 1. Remove the traces from observed.
53532sed '/^Starting/d
53533/^Entering/d
53534/^Stack/d
53535/^Reading/d
53536/^Reducing/d
53537/^Shifting/d
53538/^state/d
53539/^Cleanup:/d
53540/^Error:/d
53541/^Next/d
53542/^Discarding/d
53543/ \$[0-9$]* = /d
53544/^yydestructor:/d' stderr >at-stderr
53545mv at-stderr stderr
53546# 2. Create the reference error message.
53547cat >expout <<'_ATEOF'
535481.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
535491.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
535501.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
535511.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
53552calc: error: 4444 != 1
53553_ATEOF
53554
53555# 3. If locations are not used, remove them.
53556
53557# 4. If error-verbose is not used, strip the`, unexpected....' part.
53558
53559# 5. Check
53560$at_traceoff
53561echo "calc.at:653: cat stderr"
53562echo calc.at:653 >$at_check_line_file
53563( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
53564at_status=$?
53565grep '^ *+' $at_stder1 >&2
53566grep -v '^ *+' $at_stder1 >$at_stderr
53567at_failed=false
53568$at_diff $at_devnull $at_stderr || at_failed=:
53569$at_diff expout $at_stdout || at_failed=:
53570case $at_status in
53571   77) echo 77 > $at_status_file
53572            exit 77;;
53573   0) ;;
53574   *) echo "calc.at:653: exit code was $at_status, expected 0"
53575      at_failed=:;;
53576esac
53577if $at_failed; then
53578
53579  echo 1 > $at_status_file
53580  exit 1
53581fi
53582
53583$at_traceon
53584
53585
53586
53587# The same, but this time exercising explicitly triggered syntax errors.
53588# POSIX says the look-ahead causing the error should not be discarded.
53589cat >input <<'_ATEOF'
53590(!) + (0 0) = 1
53591_ATEOF
53592
53593$at_traceoff
53594echo "calc.at:653: \$PREPARSER ./calc input"
53595echo calc.at:653 >$at_check_line_file
53596( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
53597at_status=$?
53598grep '^ *+' $at_stder1 >&2
53599grep -v '^ *+' $at_stder1 >$at_stderr
53600at_failed=false
53601echo stderr:; tee stderr <$at_stderr
53602$at_diff $at_devnull $at_stdout || at_failed=:
53603case $at_status in
53604   77) echo 77 > $at_status_file
53605            exit 77;;
53606   0) ;;
53607   *) echo "calc.at:653: exit code was $at_status, expected 0"
53608      at_failed=:;;
53609esac
53610if $at_failed; then
53611
53612  echo 1 > $at_status_file
53613  exit 1
53614fi
53615
53616$at_traceon
53617
53618
53619# Normalize the observed and expected error messages, depending upon the
53620# options.
53621# 1. Remove the traces from observed.
53622sed '/^Starting/d
53623/^Entering/d
53624/^Stack/d
53625/^Reading/d
53626/^Reducing/d
53627/^Shifting/d
53628/^state/d
53629/^Cleanup:/d
53630/^Error:/d
53631/^Next/d
53632/^Discarding/d
53633/ \$[0-9$]* = /d
53634/^yydestructor:/d' stderr >at-stderr
53635mv at-stderr stderr
53636# 2. Create the reference error message.
53637cat >expout <<'_ATEOF'
536381.9: syntax error, unexpected number
53639calc: error: 2222 != 1
53640_ATEOF
53641
53642# 3. If locations are not used, remove them.
53643
53644# 4. If error-verbose is not used, strip the`, unexpected....' part.
53645
53646# 5. Check
53647$at_traceoff
53648echo "calc.at:653: cat stderr"
53649echo calc.at:653 >$at_check_line_file
53650( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
53651at_status=$?
53652grep '^ *+' $at_stder1 >&2
53653grep -v '^ *+' $at_stder1 >$at_stderr
53654at_failed=false
53655$at_diff $at_devnull $at_stderr || at_failed=:
53656$at_diff expout $at_stdout || at_failed=:
53657case $at_status in
53658   77) echo 77 > $at_status_file
53659            exit 77;;
53660   0) ;;
53661   *) echo "calc.at:653: exit code was $at_status, expected 0"
53662      at_failed=:;;
53663esac
53664if $at_failed; then
53665
53666  echo 1 > $at_status_file
53667  exit 1
53668fi
53669
53670$at_traceon
53671
53672
53673cat >input <<'_ATEOF'
53674(- *) + (0 0) = 1
53675_ATEOF
53676
53677$at_traceoff
53678echo "calc.at:653: \$PREPARSER ./calc input"
53679echo calc.at:653 >$at_check_line_file
53680( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1
53681at_status=$?
53682grep '^ *+' $at_stder1 >&2
53683grep -v '^ *+' $at_stder1 >$at_stderr
53684at_failed=false
53685echo stderr:; tee stderr <$at_stderr
53686$at_diff $at_devnull $at_stdout || at_failed=:
53687case $at_status in
53688   77) echo 77 > $at_status_file
53689            exit 77;;
53690   0) ;;
53691   *) echo "calc.at:653: exit code was $at_status, expected 0"
53692      at_failed=:;;
53693esac
53694if $at_failed; then
53695
53696  echo 1 > $at_status_file
53697  exit 1
53698fi
53699
53700$at_traceon
53701
53702
53703# Normalize the observed and expected error messages, depending upon the
53704# options.
53705# 1. Remove the traces from observed.
53706sed '/^Starting/d
53707/^Entering/d
53708/^Stack/d
53709/^Reading/d
53710/^Reducing/d
53711/^Shifting/d
53712/^state/d
53713/^Cleanup:/d
53714/^Error:/d
53715/^Next/d
53716/^Discarding/d
53717/ \$[0-9$]* = /d
53718/^yydestructor:/d' stderr >at-stderr
53719mv at-stderr stderr
53720# 2. Create the reference error message.
53721cat >expout <<'_ATEOF'
537221.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
537231.11: syntax error, unexpected number
53724calc: error: 2222 != 1
53725_ATEOF
53726
53727# 3. If locations are not used, remove them.
53728
53729# 4. If error-verbose is not used, strip the`, unexpected....' part.
53730
53731# 5. Check
53732$at_traceoff
53733echo "calc.at:653: cat stderr"
53734echo calc.at:653 >$at_check_line_file
53735( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1
53736at_status=$?
53737grep '^ *+' $at_stder1 >&2
53738grep -v '^ *+' $at_stder1 >$at_stderr
53739at_failed=false
53740$at_diff $at_devnull $at_stderr || at_failed=:
53741$at_diff expout $at_stdout || at_failed=:
53742case $at_status in
53743   77) echo 77 > $at_status_file
53744            exit 77;;
53745   0) ;;
53746   *) echo "calc.at:653: exit code was $at_status, expected 0"
53747      at_failed=:;;
53748esac
53749if $at_failed; then
53750
53751  echo 1 > $at_status_file
53752  exit 1
53753fi
53754
53755$at_traceon
53756
53757
53758
53759
53760
53761
53762
53763
53764
53765
53766
53767
53768
53769
53770
53771
53772
53773
53774
53775
53776
53777
53778
53779
53780      $at_traceoff
53781      $at_times_p && times >$at_times_file
53782    ) 5>&1 2>&1 | eval $at_tee_pipe
53783    at_status=`cat $at_status_file`
53784    ;;
53785
53786
53787  banner-13 ) # Banner 13. torture.at:19
53788    cat <<\_ATEOF
53789
53790Torture Tests.
53791
53792_ATEOF
53793    ;;
53794
53795  105 ) # 105. torture.at:140: Big triangle
53796    at_setup_line='torture.at:140'
53797    at_desc='Big triangle'
53798    $at_quiet $ECHO_N "105: Big triangle                                 $ECHO_C"
53799    at_xfail=no
53800    (
53801      echo "105. torture.at:140: testing ..."
53802      $at_traceon
53803
53804
53805# I have been able to go up to 2000 on my machine.
53806# I tried 3000, a 29Mb grammar file, but then my system killed bison.
53807# With 500 and the new parser, which consume far too much memory,
53808# it gets killed too.  Of course the parser is to be cleaned.
53809cat >gengram.pl <<'_ATEOF'
53810#! /usr/bin/perl -w
53811
53812use strict;
53813my $max = $ARGV[0] || 10;
53814
53815print <<EOF;
53816%{
53817#ifdef HAVE_CONFIG_H
53818# include <config.h>
53819  /* We don't need perfect functions for these tests. */
53820# undef malloc
53821# undef memcmp
53822# undef realloc
53823#endif
53824%}
53825
53826%error-verbose
53827%debug
53828%{
53829#include <stdio.h>
53830#include <stdlib.h>
53831
53832static int yylex (void);
53833static void yyerror (const char *msg);
53834%}
53835%union
53836{
53837  int val;
53838};
53839
53840%token END "end"
53841%type <val> exp input
53842EOF
53843
53844for my $size (1 .. $max)
53845  {
53846    print "%token t$size $size \"$size\"\n";
53847  };
53848
53849print <<EOF;
53850%%
53851input:
53852  exp        { if (\$1 != 0) abort (); \$\$ = \$1; }
53853| input exp  { if (\$2 != \$1 + 1) abort (); \$\$ = \$2; }
53854;
53855
53856exp:
53857  END
53858    { \$\$ = 0; }
53859EOF
53860
53861for my $size (1 .. $max)
53862  {
53863    use Text::Wrap;
53864    print wrap ("| ", "   ",
53865		(map { "\"$_\"" } (1 .. $size)),
53866		" END \n"),
53867		  "    { \$\$ = $size; }\n";
53868  };
53869print ";\n";
53870
53871print <<EOF;
53872%%
53873static int
53874yylex (void)
53875{
53876  static int inner = 1;
53877  static int outer = 0;
53878  if (outer > $max)
53879    return 0;
53880  else if (inner > outer)
53881    {
53882      inner = 1;
53883      ++outer;
53884      return END;
53885    }
53886  return inner++;
53887}
53888
53889static void
53890yyerror (const char *msg)
53891{
53892  fprintf (stderr, "%s\\n", msg);
53893}
53894
53895int
53896main (void)
53897{
53898  yydebug = !!getenv ("YYDEBUG");
53899  return yyparse ();
53900}
53901EOF
53902_ATEOF
53903
53904
53905$at_traceoff
53906echo "torture.at:146: perl -w ./gengram.pl 200 || exit 77"
53907echo torture.at:146 >$at_check_line_file
53908( $at_traceon; perl -w ./gengram.pl 200 || exit 77 ) >$at_stdout 2>$at_stder1
53909at_status=$?
53910grep '^ *+' $at_stder1 >&2
53911grep -v '^ *+' $at_stder1 >$at_stderr
53912at_failed=false
53913$at_diff $at_devnull $at_stderr || at_failed=:
53914echo stdout:; tee stdout <$at_stdout
53915case $at_status in
53916   77) echo 77 > $at_status_file
53917            exit 77;;
53918   0) ;;
53919   *) echo "torture.at:146: exit code was $at_status, expected 0"
53920      at_failed=:;;
53921esac
53922if $at_failed; then
53923
53924  echo 1 > $at_status_file
53925  exit 1
53926fi
53927
53928$at_traceon
53929
53930mv stdout input.y
53931
53932$at_traceoff
53933echo "torture.at:147: bison -v -o input.c input.y"
53934echo torture.at:147 >$at_check_line_file
53935( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
53936at_status=$?
53937grep '^ *+' $at_stder1 >&2
53938grep -v '^ *+' $at_stder1 >$at_stderr
53939at_failed=false
53940$at_diff $at_devnull $at_stderr || at_failed=:
53941$at_diff $at_devnull $at_stdout || at_failed=:
53942case $at_status in
53943   77) echo 77 > $at_status_file
53944            exit 77;;
53945   0) ;;
53946   *) echo "torture.at:147: exit code was $at_status, expected 0"
53947      at_failed=:;;
53948esac
53949if $at_failed; then
53950
53951  echo 1 > $at_status_file
53952  exit 1
53953fi
53954
53955$at_traceon
53956
53957$at_traceoff
53958echo "torture.at:148: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS"
53959echo torture.at:148 >$at_check_line_file
53960( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1
53961at_status=$?
53962grep '^ *+' $at_stder1 >&2
53963grep -v '^ *+' $at_stder1 >$at_stderr
53964at_failed=false
53965echo stderr:; cat $at_stderr
53966echo stdout:; cat $at_stdout
53967case $at_status in
53968   77) echo 77 > $at_status_file
53969            exit 77;;
53970   0) ;;
53971   *) echo "torture.at:148: exit code was $at_status, expected 0"
53972      at_failed=:;;
53973esac
53974if $at_failed; then
53975
53976  echo 1 > $at_status_file
53977  exit 1
53978fi
53979
53980$at_traceon
53981
53982$at_traceoff
53983echo "torture.at:149: \$PREPARSER ./input"
53984echo torture.at:149 >$at_check_line_file
53985( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
53986at_status=$?
53987grep '^ *+' $at_stder1 >&2
53988grep -v '^ *+' $at_stder1 >$at_stderr
53989at_failed=false
53990$at_diff $at_devnull $at_stderr || at_failed=:
53991$at_diff $at_devnull $at_stdout || at_failed=:
53992case $at_status in
53993   77) echo 77 > $at_status_file
53994            exit 77;;
53995   0) ;;
53996   *) echo "torture.at:149: exit code was $at_status, expected 0"
53997      at_failed=:;;
53998esac
53999if $at_failed; then
54000
54001  echo 1 > $at_status_file
54002  exit 1
54003fi
54004
54005$at_traceon
54006
54007
54008      $at_traceoff
54009      $at_times_p && times >$at_times_file
54010    ) 5>&1 2>&1 | eval $at_tee_pipe
54011    at_status=`cat $at_status_file`
54012    ;;
54013
54014  106 ) # 106. torture.at:232: Big horizontal
54015    at_setup_line='torture.at:232'
54016    at_desc='Big horizontal'
54017    $at_quiet $ECHO_N "106: Big horizontal                               $ECHO_C"
54018    at_xfail=no
54019    (
54020      echo "106. torture.at:232: testing ..."
54021      $at_traceon
54022
54023
54024# I have been able to go up to 10000 on my machine, but I had to
54025# increase the maximum stack size (* 100).  It gave:
54026#
54027# input.y      263k
54028# input.tab.c  1.3M
54029# input        453k
54030#
54031# gengram.pl 10000                 0.70s user 0.01s sys  99% cpu    0.711 total
54032# bison input.y                  730.56s user 0.53s sys  99% cpu 12:12.34 total
54033# gcc -Wall input.tab.c -o input   5.81s user 0.20s sys 100% cpu     6.01 total
54034# ./input                          0.00s user 0.01s sys 108% cpu     0.01 total
54035#
54036cat >gengram.pl <<'_ATEOF'
54037#! /usr/bin/perl -w
54038
54039use strict;
54040my $max = $ARGV[0] || 10;
54041
54042print <<EOF;
54043%{
54044#ifdef HAVE_CONFIG_H
54045# include <config.h>
54046  /* We don't need perfect functions for these tests. */
54047# undef malloc
54048# undef memcmp
54049# undef realloc
54050#endif
54051%}
54052
54053%error-verbose
54054%debug
54055%{
54056#include <stdio.h>
54057#include <stdlib.h>
54058
54059static int yylex (void);
54060static void yyerror (const char *msg);
54061%}
54062
54063%token
54064EOF
54065for my $size (1 .. $max)
54066  {
54067    print "    t$size $size \"$size\"\n";
54068  };
54069
54070print <<EOF;
54071
54072%%
54073EOF
54074
54075use Text::Wrap;
54076print
54077  wrap ("exp: ", "  ",
54078	(map { "\"$_\"" } (1 .. $max)), ";"),
54079  "\n";
54080
54081print <<EOF;
54082%%
54083static int
54084yylex (void)
54085{
54086  static int counter = 1;
54087  if (counter > $max)
54088    return 0;
54089  else
54090  return counter++;
54091}
54092
54093static void
54094yyerror (const char *msg)
54095{
54096  fprintf (stderr, "%s\\n", msg);
54097}
54098
54099int
54100main (void)
54101{
54102  yydebug = !!getenv ("YYDEBUG");
54103  return yyparse ();
54104}
54105EOF
54106_ATEOF
54107
54108
54109$at_traceoff
54110echo "torture.at:246: perl -w ./gengram.pl 1000 || exit 77"
54111echo torture.at:246 >$at_check_line_file
54112( $at_traceon; perl -w ./gengram.pl 1000 || exit 77 ) >$at_stdout 2>$at_stder1
54113at_status=$?
54114grep '^ *+' $at_stder1 >&2
54115grep -v '^ *+' $at_stder1 >$at_stderr
54116at_failed=false
54117$at_diff $at_devnull $at_stderr || at_failed=:
54118echo stdout:; tee stdout <$at_stdout
54119case $at_status in
54120   77) echo 77 > $at_status_file
54121            exit 77;;
54122   0) ;;
54123   *) echo "torture.at:246: exit code was $at_status, expected 0"
54124      at_failed=:;;
54125esac
54126if $at_failed; then
54127
54128  echo 1 > $at_status_file
54129  exit 1
54130fi
54131
54132$at_traceon
54133
54134mv stdout input.y
54135
54136
54137# GNU m4 requires about 70 MiB for this test on a 32-bit host.
54138# Ask for 200 MiB, which should be plenty even on a 64-bit host.
54139data_limit=`(ulimit -S -d) 2>/dev/null`
54140case $data_limit in
54141[0-9]*)
54142  if test "$data_limit" -lt 204000; then
54143    $at_traceoff
54144echo "torture.at:250: ulimit -S -d 204000 || exit 77"
54145echo torture.at:250 >$at_check_line_file
54146( $at_traceon; ulimit -S -d 204000 || exit 77 ) >$at_stdout 2>$at_stder1
54147at_status=$?
54148grep '^ *+' $at_stder1 >&2
54149grep -v '^ *+' $at_stder1 >$at_stderr
54150at_failed=false
54151$at_diff $at_devnull $at_stderr || at_failed=:
54152$at_diff $at_devnull $at_stdout || at_failed=:
54153case $at_status in
54154   77) echo 77 > $at_status_file
54155            exit 77;;
54156   0) ;;
54157   *) echo "torture.at:250: exit code was $at_status, expected 0"
54158      at_failed=:;;
54159esac
54160if $at_failed; then
54161
54162  echo 1 > $at_status_file
54163  exit 1
54164fi
54165
54166$at_traceon
54167
54168    ulimit -S -d 204000
54169  fi
54170esac
54171
54172$at_traceoff
54173echo "torture.at:252: bison -v -o input.c input.y"
54174echo torture.at:252 >$at_check_line_file
54175( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
54176at_status=$?
54177grep '^ *+' $at_stder1 >&2
54178grep -v '^ *+' $at_stder1 >$at_stderr
54179at_failed=false
54180$at_diff $at_devnull $at_stderr || at_failed=:
54181$at_diff $at_devnull $at_stdout || at_failed=:
54182case $at_status in
54183   77) echo 77 > $at_status_file
54184            exit 77;;
54185   0) ;;
54186   *) echo "torture.at:252: exit code was $at_status, expected 0"
54187      at_failed=:;;
54188esac
54189if $at_failed; then
54190
54191  echo 1 > $at_status_file
54192  exit 1
54193fi
54194
54195$at_traceon
54196
54197$at_traceoff
54198echo "torture.at:253: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS"
54199echo torture.at:253 >$at_check_line_file
54200( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1
54201at_status=$?
54202grep '^ *+' $at_stder1 >&2
54203grep -v '^ *+' $at_stder1 >$at_stderr
54204at_failed=false
54205echo stderr:; cat $at_stderr
54206echo stdout:; cat $at_stdout
54207case $at_status in
54208   77) echo 77 > $at_status_file
54209            exit 77;;
54210   0) ;;
54211   *) echo "torture.at:253: exit code was $at_status, expected 0"
54212      at_failed=:;;
54213esac
54214if $at_failed; then
54215
54216  echo 1 > $at_status_file
54217  exit 1
54218fi
54219
54220$at_traceon
54221
54222$at_traceoff
54223echo "torture.at:254: \$PREPARSER ./input"
54224echo torture.at:254 >$at_check_line_file
54225( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
54226at_status=$?
54227grep '^ *+' $at_stder1 >&2
54228grep -v '^ *+' $at_stder1 >$at_stderr
54229at_failed=false
54230$at_diff $at_devnull $at_stderr || at_failed=:
54231$at_diff $at_devnull $at_stdout || at_failed=:
54232case $at_status in
54233   77) echo 77 > $at_status_file
54234            exit 77;;
54235   0) ;;
54236   *) echo "torture.at:254: exit code was $at_status, expected 0"
54237      at_failed=:;;
54238esac
54239if $at_failed; then
54240
54241  echo 1 > $at_status_file
54242  exit 1
54243fi
54244
54245$at_traceon
54246
54247
54248      $at_traceoff
54249      $at_times_p && times >$at_times_file
54250    ) 5>&1 2>&1 | eval $at_tee_pipe
54251    at_status=`cat $at_status_file`
54252    ;;
54253
54254  107 ) # 107. torture.at:368: Many look-ahead tokens
54255    at_setup_line='torture.at:368'
54256    at_desc='Many look-ahead tokens'
54257    $at_quiet $ECHO_N "107: Many look-ahead tokens                       $ECHO_C"
54258    at_xfail=no
54259    (
54260      echo "107. torture.at:368: testing ..."
54261      $at_traceon
54262
54263
54264cat >gengram.pl <<'_ATEOF'
54265#! /usr/bin/perl -w
54266
54267use strict;
54268use Text::Wrap;
54269my $max = $ARGV[0] || 10;
54270
54271print <<EOF;
54272%error-verbose
54273%debug
54274%{
54275# include <stdio.h>
54276# include <stdlib.h>
54277# include <assert.h>
54278
54279static int yylex (void);
54280static void yyerror (const char *msg);
54281%}
54282%union
54283{
54284  int val;
54285};
54286
54287%type <val> input exp
54288%token token
54289EOF
54290
54291print
54292  wrap ("%type <val> ",
54293	"            ",
54294	map { "n$_" } (1 .. $max)),
54295  "\n";
54296
54297print "%token\n";
54298for my $count (1 .. $max)
54299  {
54300    print "    t$count $count \"$count\"\n";
54301  };
54302
54303print <<EOF;
54304%%
54305input:
54306  exp        { assert (\$1 == 1); \$\$ = \$1; }
54307| input exp  { assert (\$2 == \$1 + 1); \$\$ = \$2; }
54308;
54309
54310exp:
54311  n1 "1" { assert (\$1 == 1); \$\$ = \$1; }
54312EOF
54313
54314for my $count (2 .. $max)
54315  {
54316    print "| n$count \"$count\" { assert (\$1 == $count); \$\$ = \$1; }\n";
54317  };
54318print ";\n";
54319
54320for my $count (1 .. $max)
54321  {
54322    print "n$count: token { \$\$ = $count; };\n";
54323  };
54324
54325print <<EOF;
54326%%
54327static int
54328yylex (void)
54329{
54330  static int return_token = 1;
54331  static int counter = 1;
54332  if (counter > $max)
54333    return 0;
54334  if (return_token)
54335    {
54336      return_token = 0;
54337      return token;
54338    }
54339  return_token = 1;
54340  return counter++;
54341}
54342
54343static void
54344yyerror (const char *msg)
54345{
54346  fprintf (stderr, "%s\\n", msg);
54347}
54348
54349int
54350main (void)
54351{
54352  yydebug = !!getenv ("YYDEBUG");
54353  return yyparse ();
54354}
54355EOF
54356_ATEOF
54357
54358
54359$at_traceoff
54360echo "torture.at:370: perl -w ./gengram.pl 1000 || exit 77"
54361echo torture.at:370 >$at_check_line_file
54362( $at_traceon; perl -w ./gengram.pl 1000 || exit 77 ) >$at_stdout 2>$at_stder1
54363at_status=$?
54364grep '^ *+' $at_stder1 >&2
54365grep -v '^ *+' $at_stder1 >$at_stderr
54366at_failed=false
54367$at_diff $at_devnull $at_stderr || at_failed=:
54368echo stdout:; tee stdout <$at_stdout
54369case $at_status in
54370   77) echo 77 > $at_status_file
54371            exit 77;;
54372   0) ;;
54373   *) echo "torture.at:370: exit code was $at_status, expected 0"
54374      at_failed=:;;
54375esac
54376if $at_failed; then
54377
54378  echo 1 > $at_status_file
54379  exit 1
54380fi
54381
54382$at_traceon
54383
54384mv stdout input.y
54385
54386
54387# GNU m4 requires about 70 MiB for this test on a 32-bit host.
54388# Ask for 200 MiB, which should be plenty even on a 64-bit host.
54389data_limit=`(ulimit -S -d) 2>/dev/null`
54390case $data_limit in
54391[0-9]*)
54392  if test "$data_limit" -lt 204000; then
54393    $at_traceoff
54394echo "torture.at:374: ulimit -S -d 204000 || exit 77"
54395echo torture.at:374 >$at_check_line_file
54396( $at_traceon; ulimit -S -d 204000 || exit 77 ) >$at_stdout 2>$at_stder1
54397at_status=$?
54398grep '^ *+' $at_stder1 >&2
54399grep -v '^ *+' $at_stder1 >$at_stderr
54400at_failed=false
54401$at_diff $at_devnull $at_stderr || at_failed=:
54402$at_diff $at_devnull $at_stdout || at_failed=:
54403case $at_status in
54404   77) echo 77 > $at_status_file
54405            exit 77;;
54406   0) ;;
54407   *) echo "torture.at:374: exit code was $at_status, expected 0"
54408      at_failed=:;;
54409esac
54410if $at_failed; then
54411
54412  echo 1 > $at_status_file
54413  exit 1
54414fi
54415
54416$at_traceon
54417
54418    ulimit -S -d 204000
54419  fi
54420esac
54421
54422$at_traceoff
54423echo "torture.at:376: bison -v -o input.c input.y"
54424echo torture.at:376 >$at_check_line_file
54425( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
54426at_status=$?
54427grep '^ *+' $at_stder1 >&2
54428grep -v '^ *+' $at_stder1 >$at_stderr
54429at_failed=false
54430$at_diff $at_devnull $at_stderr || at_failed=:
54431$at_diff $at_devnull $at_stdout || at_failed=:
54432case $at_status in
54433   77) echo 77 > $at_status_file
54434            exit 77;;
54435   0) ;;
54436   *) echo "torture.at:376: exit code was $at_status, expected 0"
54437      at_failed=:;;
54438esac
54439if $at_failed; then
54440
54441  echo 1 > $at_status_file
54442  exit 1
54443fi
54444
54445$at_traceon
54446
54447$at_traceoff
54448echo "torture.at:377: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS"
54449echo torture.at:377 >$at_check_line_file
54450( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1
54451at_status=$?
54452grep '^ *+' $at_stder1 >&2
54453grep -v '^ *+' $at_stder1 >$at_stderr
54454at_failed=false
54455echo stderr:; cat $at_stderr
54456echo stdout:; cat $at_stdout
54457case $at_status in
54458   77) echo 77 > $at_status_file
54459            exit 77;;
54460   0) ;;
54461   *) echo "torture.at:377: exit code was $at_status, expected 0"
54462      at_failed=:;;
54463esac
54464if $at_failed; then
54465
54466  echo 1 > $at_status_file
54467  exit 1
54468fi
54469
54470$at_traceon
54471
54472$at_traceoff
54473echo "torture.at:378: \$PREPARSER ./input"
54474echo torture.at:378 >$at_check_line_file
54475( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
54476at_status=$?
54477grep '^ *+' $at_stder1 >&2
54478grep -v '^ *+' $at_stder1 >$at_stderr
54479at_failed=false
54480$at_diff $at_devnull $at_stderr || at_failed=:
54481$at_diff $at_devnull $at_stdout || at_failed=:
54482case $at_status in
54483   77) echo 77 > $at_status_file
54484            exit 77;;
54485   0) ;;
54486   *) echo "torture.at:378: exit code was $at_status, expected 0"
54487      at_failed=:;;
54488esac
54489if $at_failed; then
54490
54491  echo 1 > $at_status_file
54492  exit 1
54493fi
54494
54495$at_traceon
54496
54497
54498      $at_traceoff
54499      $at_times_p && times >$at_times_file
54500    ) 5>&1 2>&1 | eval $at_tee_pipe
54501    at_status=`cat $at_status_file`
54502    ;;
54503
54504  108 ) # 108. torture.at:445: Exploding the Stack Size with Alloca
54505    at_setup_line='torture.at:445'
54506    at_desc='Exploding the Stack Size with Alloca'
54507    $at_quiet $ECHO_N "108: Exploding the Stack Size with Alloca         $ECHO_C"
54508    at_xfail=no
54509    (
54510      echo "108. torture.at:445: testing ..."
54511      $at_traceon
54512
54513
54514# A grammar of parens growing the stack thanks to right recursion.
54515# exp:
54516cat >input.y <<'_ATEOF'
54517%{
54518#include <errno.h>
54519#include <limits.h>
54520#include <stdio.h>
54521#include <stdlib.h>
54522
54523#if (defined __GNUC__ || defined __BUILTIN_VA_ARG_INCR \
54524     || defined _AIX || defined _MSC_VER || defined _ALLOCA_H)
54525# define YYSTACK_USE_ALLOCA 1
54526#endif
54527
54528  static int yylex (void);
54529  static void yyerror (const char *msg);
54530%}
54531%error-verbose
54532%debug
54533%token WAIT_FOR_EOF
54534%%
54535exp: WAIT_FOR_EOF exp | ;
54536%%
54537static void
54538yyerror (const char *msg)
54539{
54540  fprintf (stderr, "%s\n", msg);
54541}
54542
54543static int
54544yylex (void)
54545{
54546  if (yylval--)
54547    return WAIT_FOR_EOF;
54548  else
54549    return EOF;
54550}
54551
54552int
54553main (int argc, const char **argv)
54554{
54555  char *endp;
54556  if (argc != 2)
54557    abort ();
54558  yylval = strtol (argv[1], &endp, 10);
54559  if (! (argv[1] != endp
54560	 && 0 <= yylval && yylval <= INT_MAX
54561	 && errno != ERANGE))
54562    abort ();
54563  yydebug = 1;
54564  return yyparse ();
54565}
54566_ATEOF
54567
54568$at_traceoff
54569echo "torture.at:452: bison -o input.c input.y"
54570echo torture.at:452 >$at_check_line_file
54571( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
54572at_status=$?
54573grep '^ *+' $at_stder1 >&2
54574grep -v '^ *+' $at_stder1 >$at_stderr
54575at_failed=false
54576$at_diff $at_devnull $at_stderr || at_failed=:
54577$at_diff $at_devnull $at_stdout || at_failed=:
54578case $at_status in
54579   77) echo 77 > $at_status_file
54580            exit 77;;
54581   0) ;;
54582   *) echo "torture.at:452: exit code was $at_status, expected 0"
54583      at_failed=:;;
54584esac
54585if $at_failed; then
54586
54587  echo 1 > $at_status_file
54588  exit 1
54589fi
54590
54591$at_traceon
54592
54593$at_traceoff
54594echo "torture.at:452: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS"
54595echo torture.at:452 >$at_check_line_file
54596( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1
54597at_status=$?
54598grep '^ *+' $at_stder1 >&2
54599grep -v '^ *+' $at_stder1 >$at_stderr
54600at_failed=false
54601echo stderr:; cat $at_stderr
54602echo stdout:; cat $at_stdout
54603case $at_status in
54604   77) echo 77 > $at_status_file
54605            exit 77;;
54606   0) ;;
54607   *) echo "torture.at:452: exit code was $at_status, expected 0"
54608      at_failed=:;;
54609esac
54610if $at_failed; then
54611
54612  echo 1 > $at_status_file
54613  exit 1
54614fi
54615
54616$at_traceon
54617
54618
54619
54620# Below the limit of 200.
54621$at_traceoff
54622echo "torture.at:455: \$PREPARSER ./input 20"
54623echo torture.at:455 >$at_check_line_file
54624( $at_traceon; $PREPARSER ./input 20 ) >$at_stdout 2>$at_stder1
54625at_status=$?
54626grep '^ *+' $at_stder1 >&2
54627grep -v '^ *+' $at_stder1 >$at_stderr
54628at_failed=false
54629echo stderr:; cat $at_stderr
54630$at_diff $at_devnull $at_stdout || at_failed=:
54631case $at_status in
54632   77) echo 77 > $at_status_file
54633            exit 77;;
54634   0) ;;
54635   *) echo "torture.at:455: exit code was $at_status, expected 0"
54636      at_failed=:;;
54637esac
54638if $at_failed; then
54639
54640  echo 1 > $at_status_file
54641  exit 1
54642fi
54643
54644$at_traceon
54645
54646# Two enlargements: 2 * 2 * 200.
54647$at_traceoff
54648echo "torture.at:457: \$PREPARSER ./input 900"
54649echo torture.at:457 >$at_check_line_file
54650( $at_traceon; $PREPARSER ./input 900 ) >$at_stdout 2>$at_stder1
54651at_status=$?
54652grep '^ *+' $at_stder1 >&2
54653grep -v '^ *+' $at_stder1 >$at_stderr
54654at_failed=false
54655echo stderr:; cat $at_stderr
54656$at_diff $at_devnull $at_stdout || at_failed=:
54657case $at_status in
54658   77) echo 77 > $at_status_file
54659            exit 77;;
54660   0) ;;
54661   *) echo "torture.at:457: exit code was $at_status, expected 0"
54662      at_failed=:;;
54663esac
54664if $at_failed; then
54665
54666  echo 1 > $at_status_file
54667  exit 1
54668fi
54669
54670$at_traceon
54671
54672# Fails: beyond the limit of 10,000 (which we don't reach anyway since we
54673# multiply by two starting at 200 => 5120 is the last possible).
54674$at_traceoff
54675echo "torture.at:460: \$PREPARSER ./input 10000"
54676echo torture.at:460 >$at_check_line_file
54677( $at_traceon; $PREPARSER ./input 10000 ) >$at_stdout 2>$at_stder1
54678at_status=$?
54679grep '^ *+' $at_stder1 >&2
54680grep -v '^ *+' $at_stder1 >$at_stderr
54681at_failed=false
54682echo stderr:; cat $at_stderr
54683$at_diff $at_devnull $at_stdout || at_failed=:
54684case $at_status in
54685   77) echo 77 > $at_status_file
54686            exit 77;;
54687   2) ;;
54688   *) echo "torture.at:460: exit code was $at_status, expected 2"
54689      at_failed=:;;
54690esac
54691if $at_failed; then
54692
54693  echo 1 > $at_status_file
54694  exit 1
54695fi
54696
54697$at_traceon
54698
54699
54700      $at_traceoff
54701      $at_times_p && times >$at_times_file
54702    ) 5>&1 2>&1 | eval $at_tee_pipe
54703    at_status=`cat $at_status_file`
54704    ;;
54705
54706  109 ) # 109. torture.at:471: Exploding the Stack Size with Malloc
54707    at_setup_line='torture.at:471'
54708    at_desc='Exploding the Stack Size with Malloc'
54709    $at_quiet $ECHO_N "109: Exploding the Stack Size with Malloc         $ECHO_C"
54710    at_xfail=no
54711    (
54712      echo "109. torture.at:471: testing ..."
54713      $at_traceon
54714
54715
54716# A grammar of parens growing the stack thanks to right recursion.
54717# exp:
54718cat >input.y <<'_ATEOF'
54719%{
54720#include <errno.h>
54721#include <limits.h>
54722#include <stdio.h>
54723#include <stdlib.h>
54724#define YYSTACK_USE_ALLOCA 0
54725  static int yylex (void);
54726  static void yyerror (const char *msg);
54727%}
54728%error-verbose
54729%debug
54730%token WAIT_FOR_EOF
54731%%
54732exp: WAIT_FOR_EOF exp | ;
54733%%
54734static void
54735yyerror (const char *msg)
54736{
54737  fprintf (stderr, "%s\n", msg);
54738}
54739
54740static int
54741yylex (void)
54742{
54743  if (yylval--)
54744    return WAIT_FOR_EOF;
54745  else
54746    return EOF;
54747}
54748
54749int
54750main (int argc, const char **argv)
54751{
54752  char *endp;
54753  if (argc != 2)
54754    abort ();
54755  yylval = strtol (argv[1], &endp, 10);
54756  if (! (argv[1] != endp
54757	 && 0 <= yylval && yylval <= INT_MAX
54758	 && errno != ERANGE))
54759    abort ();
54760  yydebug = 1;
54761  return yyparse ();
54762}
54763_ATEOF
54764
54765$at_traceoff
54766echo "torture.at:473: bison -o input.c input.y"
54767echo torture.at:473 >$at_check_line_file
54768( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
54769at_status=$?
54770grep '^ *+' $at_stder1 >&2
54771grep -v '^ *+' $at_stder1 >$at_stderr
54772at_failed=false
54773$at_diff $at_devnull $at_stderr || at_failed=:
54774$at_diff $at_devnull $at_stdout || at_failed=:
54775case $at_status in
54776   77) echo 77 > $at_status_file
54777            exit 77;;
54778   0) ;;
54779   *) echo "torture.at:473: exit code was $at_status, expected 0"
54780      at_failed=:;;
54781esac
54782if $at_failed; then
54783
54784  echo 1 > $at_status_file
54785  exit 1
54786fi
54787
54788$at_traceon
54789
54790$at_traceoff
54791echo "torture.at:473: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS"
54792echo torture.at:473 >$at_check_line_file
54793( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1
54794at_status=$?
54795grep '^ *+' $at_stder1 >&2
54796grep -v '^ *+' $at_stder1 >$at_stderr
54797at_failed=false
54798echo stderr:; cat $at_stderr
54799echo stdout:; cat $at_stdout
54800case $at_status in
54801   77) echo 77 > $at_status_file
54802            exit 77;;
54803   0) ;;
54804   *) echo "torture.at:473: exit code was $at_status, expected 0"
54805      at_failed=:;;
54806esac
54807if $at_failed; then
54808
54809  echo 1 > $at_status_file
54810  exit 1
54811fi
54812
54813$at_traceon
54814
54815
54816
54817# Below the limit of 200.
54818$at_traceoff
54819echo "torture.at:476: \$PREPARSER ./input 20"
54820echo torture.at:476 >$at_check_line_file
54821( $at_traceon; $PREPARSER ./input 20 ) >$at_stdout 2>$at_stder1
54822at_status=$?
54823grep '^ *+' $at_stder1 >&2
54824grep -v '^ *+' $at_stder1 >$at_stderr
54825at_failed=false
54826echo stderr:; cat $at_stderr
54827$at_diff $at_devnull $at_stdout || at_failed=:
54828case $at_status in
54829   77) echo 77 > $at_status_file
54830            exit 77;;
54831   0) ;;
54832   *) echo "torture.at:476: exit code was $at_status, expected 0"
54833      at_failed=:;;
54834esac
54835if $at_failed; then
54836
54837  echo 1 > $at_status_file
54838  exit 1
54839fi
54840
54841$at_traceon
54842
54843# Two enlargements: 2 * 2 * 200.
54844$at_traceoff
54845echo "torture.at:478: \$PREPARSER ./input 900"
54846echo torture.at:478 >$at_check_line_file
54847( $at_traceon; $PREPARSER ./input 900 ) >$at_stdout 2>$at_stder1
54848at_status=$?
54849grep '^ *+' $at_stder1 >&2
54850grep -v '^ *+' $at_stder1 >$at_stderr
54851at_failed=false
54852echo stderr:; cat $at_stderr
54853$at_diff $at_devnull $at_stdout || at_failed=:
54854case $at_status in
54855   77) echo 77 > $at_status_file
54856            exit 77;;
54857   0) ;;
54858   *) echo "torture.at:478: exit code was $at_status, expected 0"
54859      at_failed=:;;
54860esac
54861if $at_failed; then
54862
54863  echo 1 > $at_status_file
54864  exit 1
54865fi
54866
54867$at_traceon
54868
54869# Fails: beyond the limit of 10,000 (which we don't reach anyway since we
54870# multiply by two starting at 200 => 5120 is the possible).
54871$at_traceoff
54872echo "torture.at:481: \$PREPARSER ./input 10000"
54873echo torture.at:481 >$at_check_line_file
54874( $at_traceon; $PREPARSER ./input 10000 ) >$at_stdout 2>$at_stder1
54875at_status=$?
54876grep '^ *+' $at_stder1 >&2
54877grep -v '^ *+' $at_stder1 >$at_stderr
54878at_failed=false
54879echo stderr:; cat $at_stderr
54880$at_diff $at_devnull $at_stdout || at_failed=:
54881case $at_status in
54882   77) echo 77 > $at_status_file
54883            exit 77;;
54884   2) ;;
54885   *) echo "torture.at:481: exit code was $at_status, expected 2"
54886      at_failed=:;;
54887esac
54888if $at_failed; then
54889
54890  echo 1 > $at_status_file
54891  exit 1
54892fi
54893
54894$at_traceon
54895
54896
54897      $at_traceoff
54898      $at_times_p && times >$at_times_file
54899    ) 5>&1 2>&1 | eval $at_tee_pipe
54900    at_status=`cat $at_status_file`
54901    ;;
54902
54903
54904  banner-14 ) # Banner 14. existing.at:21
54905    cat <<\_ATEOF
54906
54907Existing Grammars.
54908
54909_ATEOF
54910    ;;
54911
54912  110 ) # 110. existing.at:26: GNU AWK Grammar
54913    at_setup_line='existing.at:26'
54914    at_desc='GNU AWK Grammar'
54915    $at_quiet $ECHO_N "110: GNU AWK Grammar                              $ECHO_C"
54916    at_xfail=no
54917    (
54918      echo "110. existing.at:26: testing ..."
54919      $at_traceon
54920
54921
54922# We have been careful to strip all the actions excepts the
54923# mid-rule actions.  We rely on %expect to check that there are
54924# indeed 65 SR conflicts.
54925#
54926# Bison was once wrong, due to an incorrect computation of nullable.
54927# It reported 485 SR conflicts!
54928
54929cat >input.y <<'_ATEOF'
54930%expect 65
54931
54932%token FUNC_CALL NAME REGEXP
54933%token ERROR
54934%token YNUMBER YSTRING
54935%token RELOP APPEND_OP
54936%token ASSIGNOP MATCHOP NEWLINE CONCAT_OP
54937%token LEX_BEGIN LEX_END LEX_IF LEX_ELSE LEX_RETURN LEX_DELETE
54938%token LEX_WHILE LEX_DO LEX_FOR LEX_BREAK LEX_CONTINUE
54939%token LEX_PRINT LEX_PRINTF LEX_NEXT LEX_EXIT LEX_FUNCTION
54940%token LEX_GETLINE LEX_NEXTFILE
54941%token LEX_IN
54942%token LEX_AND LEX_OR INCREMENT DECREMENT
54943%token LEX_BUILTIN LEX_LENGTH
54944
54945/* Lowest to highest */
54946%right ASSIGNOP
54947%right '?' ':'
54948%left LEX_OR
54949%left LEX_AND
54950%left LEX_GETLINE
54951%nonassoc LEX_IN
54952%left FUNC_CALL LEX_BUILTIN LEX_LENGTH
54953%nonassoc ','
54954%nonassoc MATCHOP
54955%nonassoc RELOP '<' '>' '|' APPEND_OP TWOWAYIO
54956%left CONCAT_OP
54957%left YSTRING YNUMBER
54958%left '+' '-'
54959%left '*' '/' '%'
54960%right '!' UNARY
54961%right '^'
54962%left INCREMENT DECREMENT
54963%left '$'
54964%left '(' ')'
54965%%
54966
54967start
54968	: opt_nls program opt_nls
54969	;
54970
54971program
54972	: rule
54973	| program rule
54974	| error
54975	| program error
54976	| /* empty */
54977	;
54978
54979rule
54980	: LEX_BEGIN {} action
54981	| LEX_END {}   action
54982	| LEX_BEGIN statement_term
54983	| LEX_END statement_term
54984	| pattern action
54985	| action
54986	| pattern statement_term
54987	| function_prologue function_body
54988	;
54989
54990func_name
54991	: NAME
54992	| FUNC_CALL
54993	| lex_builtin
54994	;
54995
54996lex_builtin
54997	: LEX_BUILTIN
54998	| LEX_LENGTH
54999	;
55000
55001function_prologue
55002	: LEX_FUNCTION {} func_name '(' opt_param_list r_paren opt_nls
55003	;
55004
55005function_body
55006	: l_brace statements r_brace opt_semi opt_nls
55007	| l_brace r_brace opt_semi opt_nls
55008	;
55009
55010pattern
55011	: exp
55012	| exp ',' exp
55013	;
55014
55015regexp
55016	/*
55017	 * In this rule, want_regexp tells yylex that the next thing
55018	 * is a regexp so it should read up to the closing slash.
55019	 */
55020	: '/' {} REGEXP '/'
55021	;
55022
55023action
55024	: l_brace statements r_brace opt_semi opt_nls
55025	| l_brace r_brace opt_semi opt_nls
55026	;
55027
55028statements
55029	: statement
55030	| statements statement
55031	| error
55032	| statements error
55033	;
55034
55035statement_term
55036	: nls
55037	| semi opt_nls
55038	;
55039
55040statement
55041	: semi opt_nls
55042	| l_brace r_brace
55043	| l_brace statements r_brace
55044	| if_statement
55045	| LEX_WHILE '(' exp r_paren opt_nls statement
55046	| LEX_DO opt_nls statement LEX_WHILE '(' exp r_paren opt_nls
55047	| LEX_FOR '(' NAME LEX_IN NAME r_paren opt_nls statement
55048	| LEX_FOR '(' opt_exp semi opt_nls exp semi opt_nls opt_exp r_paren opt_nls statement
55049	| LEX_FOR '(' opt_exp semi opt_nls semi opt_nls opt_exp r_paren opt_nls statement
55050	| LEX_BREAK statement_term
55051	| LEX_CONTINUE statement_term
55052	| print '(' expression_list r_paren output_redir statement_term
55053	| print opt_rexpression_list output_redir statement_term
55054	| LEX_NEXT statement_term
55055	| LEX_NEXTFILE statement_term
55056	| LEX_EXIT opt_exp statement_term
55057	| LEX_RETURN {} opt_exp statement_term
55058	| LEX_DELETE NAME '[' expression_list ']' statement_term
55059	| LEX_DELETE NAME  statement_term
55060	| exp statement_term
55061	;
55062
55063print
55064	: LEX_PRINT
55065	| LEX_PRINTF
55066	;
55067
55068if_statement
55069	: LEX_IF '(' exp r_paren opt_nls statement
55070	| LEX_IF '(' exp r_paren opt_nls statement
55071	     LEX_ELSE opt_nls statement
55072	;
55073
55074nls
55075	: NEWLINE
55076	| nls NEWLINE
55077	;
55078
55079opt_nls
55080	: /* empty */
55081	| nls
55082	;
55083
55084input_redir
55085	: /* empty */
55086	| '<' simp_exp
55087	;
55088
55089output_redir
55090	: /* empty */
55091	| '>' exp
55092	| APPEND_OP exp
55093	| '|' exp
55094	| TWOWAYIO exp
55095	;
55096
55097opt_param_list
55098	: /* empty */
55099	| param_list
55100	;
55101
55102param_list
55103	: NAME
55104	| param_list comma NAME
55105	| error
55106	| param_list error
55107	| param_list comma error
55108	;
55109
55110/* optional expression, as in for loop */
55111opt_exp
55112	: /* empty */
55113	| exp
55114	;
55115
55116opt_rexpression_list
55117	: /* empty */
55118	| rexpression_list
55119	;
55120
55121rexpression_list
55122	: rexp
55123	| rexpression_list comma rexp
55124	| error
55125	| rexpression_list error
55126	| rexpression_list error rexp
55127	| rexpression_list comma error
55128	;
55129
55130opt_expression_list
55131	: /* empty */
55132	| expression_list
55133	;
55134
55135expression_list
55136	: exp
55137	| expression_list comma exp
55138	| error
55139	| expression_list error
55140	| expression_list error exp
55141	| expression_list comma error
55142	;
55143
55144/* Expressions, not including the comma operator.  */
55145exp	: variable ASSIGNOP {} exp
55146	| '(' expression_list r_paren LEX_IN NAME
55147	| exp '|' LEX_GETLINE opt_variable
55148	| exp TWOWAYIO LEX_GETLINE opt_variable
55149	| LEX_GETLINE opt_variable input_redir
55150	| exp LEX_AND exp
55151	| exp LEX_OR exp
55152	| exp MATCHOP exp
55153	| regexp
55154	| '!' regexp %prec UNARY
55155	| exp LEX_IN NAME
55156	| exp RELOP exp
55157	| exp '<' exp
55158	| exp '>' exp
55159	| exp '?' exp ':' exp
55160	| simp_exp
55161	| exp simp_exp %prec CONCAT_OP
55162	;
55163
55164rexp
55165	: variable ASSIGNOP {} rexp
55166	| rexp LEX_AND rexp
55167	| rexp LEX_OR rexp
55168	| LEX_GETLINE opt_variable input_redir
55169	| regexp
55170	| '!' regexp %prec UNARY
55171	| rexp MATCHOP rexp
55172	| rexp LEX_IN NAME
55173	| rexp RELOP rexp
55174	| rexp '?' rexp ':' rexp
55175	| simp_exp
55176	| rexp simp_exp %prec CONCAT_OP
55177	;
55178
55179simp_exp
55180	: non_post_simp_exp
55181	/* Binary operators in order of decreasing precedence.  */
55182	| simp_exp '^' simp_exp
55183	| simp_exp '*' simp_exp
55184	| simp_exp '/' simp_exp
55185	| simp_exp '%' simp_exp
55186	| simp_exp '+' simp_exp
55187	| simp_exp '-' simp_exp
55188	| variable INCREMENT
55189	| variable DECREMENT
55190	;
55191
55192non_post_simp_exp
55193	: '!' simp_exp %prec UNARY
55194	| '(' exp r_paren
55195	| LEX_BUILTIN
55196	  '(' opt_expression_list r_paren
55197	| LEX_LENGTH '(' opt_expression_list r_paren
55198	| LEX_LENGTH
55199	| FUNC_CALL '(' opt_expression_list r_paren
55200	| variable
55201	| INCREMENT variable
55202	| DECREMENT variable
55203	| YNUMBER
55204	| YSTRING
55205	| '-' simp_exp    %prec UNARY
55206	| '+' simp_exp    %prec UNARY
55207	;
55208
55209opt_variable
55210	: /* empty */
55211	| variable
55212	;
55213
55214variable
55215	: NAME
55216	| NAME '[' expression_list ']'
55217	| '$' non_post_simp_exp
55218	;
55219
55220l_brace
55221	: '{' opt_nls
55222	;
55223
55224r_brace
55225	: '}' opt_nls
55226	;
55227
55228r_paren
55229	: ')'
55230	;
55231
55232opt_semi
55233	: /* empty */
55234	| semi
55235	;
55236
55237semi
55238	: ';'
55239	;
55240
55241comma	: ',' opt_nls
55242	;
55243
55244%%
55245_ATEOF
55246
55247
55248# Pass plenty of options, to exercise plenty of code, even if we
55249# don't actually check the output.  But SEGV is watching us, and
55250# so might do dmalloc.
55251$at_traceoff
55252echo "existing.at:356: bison --verbose --defines input.y"
55253echo existing.at:356 >$at_check_line_file
55254( $at_traceon; bison --verbose --defines input.y ) >$at_stdout 2>$at_stder1
55255at_status=$?
55256grep '^ *+' $at_stder1 >&2
55257grep -v '^ *+' $at_stder1 >$at_stderr
55258at_failed=false
55259$at_diff $at_devnull $at_stderr || at_failed=:
55260$at_diff $at_devnull $at_stdout || at_failed=:
55261case $at_status in
55262   77) echo 77 > $at_status_file
55263            exit 77;;
55264   0) ;;
55265   *) echo "existing.at:356: exit code was $at_status, expected 0"
55266      at_failed=:;;
55267esac
55268if $at_failed; then
55269
55270  echo 1 > $at_status_file
55271  exit 1
55272fi
55273
55274$at_traceon
55275
55276
55277      $at_traceoff
55278      $at_times_p && times >$at_times_file
55279    ) 5>&1 2>&1 | eval $at_tee_pipe
55280    at_status=`cat $at_status_file`
55281    ;;
55282
55283  111 ) # 111. existing.at:364: GNU Cim Grammar
55284    at_setup_line='existing.at:364'
55285    at_desc='GNU Cim Grammar'
55286    $at_quiet $ECHO_N "111: GNU Cim Grammar                              $ECHO_C"
55287    at_xfail=no
55288    (
55289      echo "111. existing.at:364: testing ..."
55290      $at_traceon
55291
55292
55293# GNU Cim, the GNU Simula 87 Compiler.
55294
55295# Bison was once wrong, due to an incorrect computation of the RR conflicts.
55296# It reported 80 SR && 99 RR conflicts instead of 78/10!!!
55297
55298cat >input.y <<'_ATEOF'
55299%union {}
55300
55301%token
55302	HACTIVATE HAFTER /*HAND*/ HARRAY HAT
55303	HBEFORE HBEGIN HBOOLEAN
55304	HCHARACTER HCLASS /*HCOMMENT*/ HCONC
55305	HDELAY HDO
55306	HELSE HEND HEQ /*HEQV*/ HEXTERNAL
55307	HFOR
55308	HGE HGO HGOTO HGT
55309	HHIDDEN
55310	HIF /*HIMP*/ HIN HINNER HINSPECT HINTEGER HIS
55311	HLABEL HLE HLONG HLT
55312	HNAME HNE HNEW HNONE /*HNOT*/ HNOTEXT
55313	/*HOR*/ HOTHERWISE
55314	HPRIOR HPROCEDURE HPROTECTED
55315	HQUA
55316	HREACTIVATE HREAL HREF
55317	HSHORT HSTEP HSWITCH
55318	HTEXT HTHEN HTHIS HTO
55319	HUNTIL
55320	HVALUE HVAR HVIRTUAL
55321	HWHEN HWHILE
55322
55323	HASSIGNVALUE HASSIGNREF
55324	/*HDOT*/ HPAREXPSEPARATOR HLABELSEPARATOR HSTATEMENTSEPARATOR
55325	HBEGPAR HENDPAR
55326	HEQR HNER
55327	HADD HSUB HMUL HDIV HINTDIV HEXP
55328	HDOTDOTDOT
55329
55330%token HIDENTIFIER
55331%token HBOOLEANKONST HINTEGERKONST HCHARACTERKONST
55332%token HREALKONST
55333%token HTEXTKONST
55334
55335
55336%right HASSIGN
55337%left   HORELSE
55338%left   HANDTHEN
55339%left   HEQV
55340%left   HIMP
55341%left   HOR
55342%left   HAND
55343
55344%left   HNOT
55345
55346%left HVALRELOPERATOR HREFRELOPERATOR HOBJRELOPERATOR
55347
55348%left	HCONC
55349
55350%left HTERMOPERATOR
55351%left UNEAR
55352%left HFACTOROPERATOR
55353%left         HPRIMARYOPERATOR
55354
55355%left   HQUA
55356
55357%left   HDOT
55358
55359%start  MAIN_MODULE
55360%%
55361/* GRAMATIKK FOR PROGRAM MODULES */
55362MAIN_MODULE     :       {}
55363			MODULS
55364		|	error HSTATEMENTSEPARATOR MBEE_DECLSTMS
55365		;
55366EXT_DECLARATION	:	HEXTERNAL
55367			MBEE_TYPE
55368			HPROCEDURE
55369				{}
55370			EXT_LIST
55371		|
55372			HEXTERNAL
55373			HIDENTIFIER
55374			HPROCEDURE
55375				{}
55376			HIDENTIFIER {}
55377			EXTERNAL_KIND_ITEM
55378		|	HEXTERNAL
55379			HCLASS
55380				{}
55381			EXT_LIST
55382
55383		;
55384EXTERNAL_KIND_ITEM:	EXT_IDENT
55385			HOBJRELOPERATOR
55386				{}
55387			MBEE_TYPE HPROCEDURE
55388			HIDENTIFIER
55389				{}
55390			HEADING EMPTY_BLOCK
55391				{}
55392/*		|
55393			EXT_IDENT
55394				{}
55395			MBEE_REST_EXT_LIST
55396		;
55397MBEE_REST_EXT_LIST:	/* EMPTY
55398		|	HPAREXPSEPARATOR EXT_KIND_LIST
55399		;
55400EXT_KIND_LIST	:	EXT_KIND_ITEM
55401		|	EXT_KIND_LIST HPAREXPSEPARATOR EXT_KIND_ITEM
55402		;
55403EXT_KIND_ITEM	:	HIDENTIFIER
55404			EXT_IDENT
55405				{}*/
55406		;
55407EMPTY_BLOCK	:	/*EMPT*/
55408		|	HBEGIN HEND
55409		;
55410EXT_LIST	:	EXT_ITEM
55411		|	EXT_LIST HPAREXPSEPARATOR EXT_ITEM
55412		;
55413EXT_ITEM	:	HIDENTIFIER
55414			EXT_IDENT
55415		;
55416EXT_IDENT	:	/* EMPTY */
55417		|	HVALRELOPERATOR {}
55418			HTEXTKONST
55419		;
55420/* GRAMATIKK FOR TYPER */
55421NO_TYPE         :       /*EMPT*/
55422		;
55423MBEE_TYPE       :       NO_TYPE
55424		|       TYPE
55425		;
55426TYPE            :       HREF HBEGPAR
55427			HIDENTIFIER
55428				{}
55429			HENDPAR
55430		|       HTEXT
55431		|       HBOOLEAN
55432		|       HCHARACTER
55433		|       HSHORT HINTEGER
55434		|       HINTEGER
55435		|       HREAL
55436		|       HLONG HREAL
55437		;
55438
55439/* GRAMATIKK FOR DEL AV SETNINGER */
55440MBEE_ELSE_PART  :       /*EMPT*/
55441/*		|	HELSE
55442			HIF
55443			EXPRESSION
55444			HTHEN   {}
55445			BLOCK   {}
55446			MBEE_ELSE_PART          {}*/
55447		|       HELSE   {}
55448			BLOCK
55449		;
55450FOR_LIST        :       FOR_LIST_ELEMENT
55451		|       FOR_LIST_ELEMENT
55452			HPAREXPSEPARATOR
55453			FOR_LIST
55454		;
55455FOR_LIST_ELEMENT:       EXPRESSION
55456			MBEE_F_L_EL_R_PT
55457		;
55458MBEE_F_L_EL_R_PT:       /*EMPT*/
55459		|       HWHILE
55460			EXPRESSION
55461		|       HSTEP
55462			EXPRESSION
55463			HUNTIL
55464			EXPRESSION
55465		;
55466GOTO            :       HGO
55467			HTO
55468		|       HGOTO
55469		;
55470CONN_STATE_R_PT :       WHEN_CLAUSE_LIST
55471		|       HDO   {}
55472			BLOCK
55473		;
55474WHEN_CLAUSE_LIST:       HWHEN
55475			HIDENTIFIER
55476			HDO    {}
55477			BLOCK
55478		|       WHEN_CLAUSE_LIST
55479			HWHEN
55480			HIDENTIFIER
55481			HDO    {}
55482			BLOCK
55483		;
55484MBEE_OTWI_CLAUS :       /*EMPT*/
55485		|       HOTHERWISE {}
55486
55487			BLOCK
55488		;
55489ACTIVATOR	:	HACTIVATE
55490		|	HREACTIVATE
55491		;
55492SCHEDULE	:	/*EMPT*/
55493		|	ATDELAY EXPRESSION	{}
55494			PRIOR
55495		|	BEFOREAFTER		{}
55496			EXPRESSION
55497		;
55498ATDELAY		:	HAT
55499		|	HDELAY
55500		;
55501BEFOREAFTER	:	HBEFORE
55502		|	HAFTER
55503		;
55504PRIOR		:	/*EMPT*/
55505		|	HPRIOR
55506		;
55507/* GRAMATIKK FOR SETNINGER OG DEKLARASJONER */
55508MODULSTATEMENT  :       HWHILE
55509			EXPRESSION
55510			HDO     {}
55511			BLOCK
55512		|       HIF
55513			EXPRESSION
55514			HTHEN   {}
55515			BLOCK   {}
55516			MBEE_ELSE_PART
55517		|       HFOR
55518			HIDENTIFIER
55519			HASSIGN {}
55520			FOR_LIST
55521			HDO     {}
55522			BLOCK
55523		|       GOTO
55524			EXPRESSION
55525		|       HINSPECT
55526			EXPRESSION              {}
55527			CONN_STATE_R_PT
55528				{}
55529			MBEE_OTWI_CLAUS
55530		|       HINNER
55531		|       HIDENTIFIER
55532			HLABELSEPARATOR
55533				{}
55534			DECLSTATEMENT
55535		|       EXPRESSION_SIMP
55536			HBEGIN
55537				{}
55538			IMPORT_SPEC_MODULE
55539				{}
55540			MBEE_DECLSTMS
55541			HEND
55542		|	EXPRESSION_SIMP HBEGIN error HSTATEMENTSEPARATOR
55543			MBEE_DECLSTMS HEND
55544		|	EXPRESSION_SIMP HBEGIN error HEND
55545		|       EXPRESSION_SIMP
55546		|	ACTIVATOR EXPRESSION SCHEDULE
55547		|       HBEGIN
55548				{}
55549			MBEE_DECLSTMS
55550			HEND
55551		|       MBEE_TYPE HPROCEDURE
55552			HIDENTIFIER
55553				{}
55554			HEADING BLOCK
55555		|       HIDENTIFIER
55556			HCLASS
55557			NO_TYPE
55558				{}
55559			IMPORT_SPEC_MODULE
55560			HIDENTIFIER
55561				{}
55562			HEADING
55563			BLOCK
55564		|       HCLASS
55565			NO_TYPE
55566			HIDENTIFIER
55567				{}
55568			HEADING
55569			BLOCK
55570		|       EXT_DECLARATION
55571		|       /*EMPT*/
55572		;
55573IMPORT_SPEC_MODULE:
55574		;
55575DECLSTATEMENT	:	MODULSTATEMENT
55576		|       TYPE
55577			HIDENTIFIER
55578			MBEE_CONSTANT
55579			HPAREXPSEPARATOR
55580				{}
55581			IDENTIFIER_LISTC
55582		|       TYPE
55583			HIDENTIFIER
55584			MBEE_CONSTANT
55585		|       MBEE_TYPE
55586			HARRAY  {}
55587			ARR_SEGMENT_LIST
55588		|       HSWITCH
55589			HIDENTIFIER
55590			HASSIGN {}
55591			SWITCH_LIST
55592		;
55593BLOCK           :       DECLSTATEMENT
55594		|       HBEGIN MBEE_DECLSTMS HEND
55595		|	HBEGIN error HSTATEMENTSEPARATOR MBEE_DECLSTMS HEND
55596		|	HBEGIN error HEND
55597		;
55598MBEE_DECLSTMS   :       MBEE_DECLSTMSU
55599		;
55600MBEE_DECLSTMSU  :       DECLSTATEMENT
55601		|       MBEE_DECLSTMSU
55602			HSTATEMENTSEPARATOR
55603			DECLSTATEMENT
55604		;
55605MODULS		:	MODULSTATEMENT
55606		|	MODULS HSTATEMENTSEPARATOR MODULSTATEMENT
55607		;
55608/* GRAMATIKK FOR DEL AV DEKLARASJONER */
55609ARR_SEGMENT_LIST:       ARR_SEGMENT
55610		|       ARR_SEGMENT_LIST
55611			HPAREXPSEPARATOR
55612			ARR_SEGMENT
55613		;
55614ARR_SEGMENT	:       ARRAY_SEGMENT
55615			HBEGPAR
55616			BAUND_PAIR_LIST HENDPAR
55617		;
55618ARRAY_SEGMENT   :       ARRAY_SEGMENT_EL        {}
55619
55620		|       ARRAY_SEGMENT_EL
55621			HPAREXPSEPARATOR
55622			ARRAY_SEGMENT
55623		;
55624ARRAY_SEGMENT_EL:       HIDENTIFIER
55625		;
55626BAUND_PAIR_LIST :       BAUND_PAIR
55627		|       BAUND_PAIR
55628			HPAREXPSEPARATOR
55629			BAUND_PAIR_LIST
55630		;
55631BAUND_PAIR      :       EXPRESSION
55632			HLABELSEPARATOR
55633			EXPRESSION
55634		;
55635SWITCH_LIST     :       EXPRESSION
55636		|       EXPRESSION
55637			HPAREXPSEPARATOR
55638			SWITCH_LIST
55639		;
55640HEADING         :       MBEE_FMAL_PAR_P HSTATEMENTSEPARATOR {}
55641			MBEE_MODE_PART  {}
55642			MBEE_SPEC_PART  {}
55643			MBEE_PROT_PART  {}
55644			MBEE_VIRT_PART
55645		;
55646MBEE_FMAL_PAR_P :       /*EMPT*/
55647		|       FMAL_PAR_PART
55648		;
55649FMAL_PAR_PART   :       HBEGPAR NO_TYPE
55650			MBEE_LISTV HENDPAR
55651		;
55652MBEE_LISTV      :       /*EMPT*/
55653		|       LISTV
55654		;
55655LISTV           :       HIDENTIFIER
55656		|	FPP_CATEG HDOTDOTDOT
55657		|       HIDENTIFIER     {}
55658			HPAREXPSEPARATOR LISTV
55659		|       FPP_SPEC
55660		|       FPP_SPEC
55661			HPAREXPSEPARATOR LISTV
55662		;
55663FPP_HEADING     :       HBEGPAR NO_TYPE
55664			FPP_MBEE_LISTV HENDPAR
55665		;
55666FPP_MBEE_LISTV  :       /*EMPT*/
55667		|       FPP_LISTV
55668		;
55669FPP_LISTV       :	FPP_CATEG HDOTDOTDOT
55670		|       FPP_SPEC
55671		|       FPP_SPEC
55672			HPAREXPSEPARATOR LISTV
55673		;
55674FPP_SPEC        :       FPP_CATEG SPECIFIER HIDENTIFIER
55675		|	FPP_CATEG FPP_PROC_DECL_IN_SPEC
55676		;
55677FPP_CATEG       :       HNAME HLABELSEPARATOR
55678		|       HVALUE HLABELSEPARATOR
55679		|       HVAR HLABELSEPARATOR
55680		|       /*EMPT*/
55681		;
55682FPP_PROC_DECL_IN_SPEC:	MBEE_TYPE HPROCEDURE
55683			HIDENTIFIER
55684					{}
55685			FPP_HEADING {} { /* Yes, two "final" actions. */ }
55686		;
55687IDENTIFIER_LISTV:       HIDENTIFIER
55688		|	HDOTDOTDOT
55689		|       HIDENTIFIER     {}
55690			HPAREXPSEPARATOR IDENTIFIER_LISTV
55691		;
55692MBEE_MODE_PART  :       /*EMPT*/
55693		|       MODE_PART
55694		;
55695MODE_PART       :       NAME_PART
55696		|       VALUE_PART
55697		|       VAR_PART
55698		|       NAME_PART VALUE_PART
55699		|       VALUE_PART NAME_PART
55700		|       NAME_PART VAR_PART
55701		|       VAR_PART NAME_PART
55702		|       VALUE_PART VAR_PART
55703		|       VAR_PART VALUE_PART
55704		|       VAR_PART NAME_PART VALUE_PART
55705		|       NAME_PART VAR_PART VALUE_PART
55706		|       NAME_PART VALUE_PART VAR_PART
55707		|       VAR_PART VALUE_PART NAME_PART
55708		|       VALUE_PART VAR_PART NAME_PART
55709		|       VALUE_PART NAME_PART VAR_PART
55710		;
55711NAME_PART       :       HNAME           {}
55712			IDENTIFIER_LISTV
55713			HSTATEMENTSEPARATOR
55714		;
55715VAR_PART        :       HVAR            {}
55716			IDENTIFIER_LISTV
55717			HSTATEMENTSEPARATOR
55718		;
55719VALUE_PART      :       HVALUE          {}
55720			IDENTIFIER_LISTV HSTATEMENTSEPARATOR
55721		;
55722MBEE_SPEC_PART  :       /*EMPT*/
55723		|       SPEC_PART
55724		;
55725SPEC_PART       :       ONE_SPEC
55726		|       SPEC_PART ONE_SPEC
55727		;
55728ONE_SPEC	:	SPECIFIER IDENTIFIER_LIST HSTATEMENTSEPARATOR
55729		|	NO_TYPE HPROCEDURE HIDENTIFIER HOBJRELOPERATOR
55730			  {}
55731			PROC_DECL_IN_SPEC HSTATEMENTSEPARATOR
55732		|       FPP_PROC_DECL_IN_SPEC HSTATEMENTSEPARATOR
55733		|       MBEE_TYPE HPROCEDURE HIDENTIFIER HSTATEMENTSEPARATOR
55734		|       MBEE_TYPE HPROCEDURE HIDENTIFIER HPAREXPSEPARATOR
55735			IDENTIFIER_LIST HSTATEMENTSEPARATOR
55736		;
55737SPECIFIER       :       TYPE
55738		|       MBEE_TYPE
55739			HARRAY
55740		|       HLABEL
55741		|       HSWITCH
55742		;
55743PROC_DECL_IN_SPEC:	MBEE_TYPE HPROCEDURE
55744			HIDENTIFIER
55745					{}
55746			HEADING
55747					{}
55748			MBEE_BEGIN_END
55749		;
55750MBEE_BEGIN_END	:	/* EMPTY */
55751		|	HBEGIN HEND
55752		;
55753MBEE_PROT_PART  :       /*EMPT*/
55754		|       PROTECTION_PART
55755		;
55756PROTECTION_PART :       PROT_SPECIFIER IDENTIFIER_LIST
55757			HSTATEMENTSEPARATOR
55758		|       PROTECTION_PART  PROT_SPECIFIER
55759			IDENTIFIER_LIST HSTATEMENTSEPARATOR
55760		;
55761PROT_SPECIFIER  :       HHIDDEN
55762		|       HPROTECTED
55763		|       HHIDDEN
55764			HPROTECTED
55765		|       HPROTECTED
55766			HHIDDEN
55767		;
55768MBEE_VIRT_PART  :       /*EMPT*/
55769		|       VIRTUAL_PART
55770		;
55771VIRTUAL_PART    :       HVIRTUAL
55772			HLABELSEPARATOR
55773			MBEE_SPEC_PART
55774		;
55775IDENTIFIER_LIST :       HIDENTIFIER
55776		|       IDENTIFIER_LIST HPAREXPSEPARATOR
55777			HIDENTIFIER
55778		;
55779IDENTIFIER_LISTC:       HIDENTIFIER
55780			MBEE_CONSTANT
55781		|       IDENTIFIER_LISTC HPAREXPSEPARATOR
55782			HIDENTIFIER
55783			MBEE_CONSTANT
55784		;
55785MBEE_CONSTANT	:	/* EMPTY */
55786		|	HVALRELOPERATOR
55787				{}
55788			EXPRESSION
55789		;
55790
55791/* GRAMATIKK FOR UTTRYKK */
55792EXPRESSION      :       EXPRESSION_SIMP
55793		|       HIF
55794			EXPRESSION
55795			HTHEN
55796			EXPRESSION
55797			HELSE
55798			EXPRESSION
55799		;
55800EXPRESSION_SIMP :	EXPRESSION_SIMP
55801			HASSIGN
55802			EXPRESSION
55803		|
55804
55805			EXPRESSION_SIMP
55806			HCONC
55807			EXPRESSION_SIMP
55808		|       EXPRESSION_SIMP HOR
55809			HELSE
55810			EXPRESSION_SIMP
55811			%prec HORELSE
55812		|       EXPRESSION_SIMP HAND
55813			HTHEN
55814			EXPRESSION_SIMP
55815			%prec HANDTHEN
55816		|       EXPRESSION_SIMP
55817			HEQV EXPRESSION_SIMP
55818		|       EXPRESSION_SIMP
55819			HIMP EXPRESSION_SIMP
55820		|       EXPRESSION_SIMP
55821			HOR EXPRESSION_SIMP
55822		|       EXPRESSION_SIMP
55823			HAND EXPRESSION_SIMP
55824		|       HNOT EXPRESSION_SIMP
55825		|       EXPRESSION_SIMP
55826			HVALRELOPERATOR
55827			EXPRESSION_SIMP
55828		|       EXPRESSION_SIMP
55829			HREFRELOPERATOR
55830			EXPRESSION_SIMP
55831		|       EXPRESSION_SIMP
55832			HOBJRELOPERATOR
55833			EXPRESSION_SIMP
55834		|       HTERMOPERATOR
55835			EXPRESSION_SIMP %prec UNEAR
55836		|       EXPRESSION_SIMP
55837			HTERMOPERATOR
55838			EXPRESSION_SIMP
55839		|       EXPRESSION_SIMP
55840			HFACTOROPERATOR
55841			EXPRESSION_SIMP
55842		|       EXPRESSION_SIMP
55843			HPRIMARYOPERATOR
55844			EXPRESSION_SIMP
55845		|       HBEGPAR
55846			EXPRESSION HENDPAR
55847		|       HTEXTKONST
55848		|       HCHARACTERKONST
55849		|       HREALKONST
55850		|       HINTEGERKONST
55851		|       HBOOLEANKONST
55852		|       HNONE
55853		|       HIDENTIFIER
55854				{}
55855			MBEE_ARG_R_PT
55856		|       HTHIS HIDENTIFIER
55857		|       HNEW
55858			HIDENTIFIER
55859			ARG_R_PT
55860		|       EXPRESSION_SIMP
55861			HDOT
55862			EXPRESSION_SIMP
55863		|       EXPRESSION_SIMP
55864			HQUA HIDENTIFIER
55865		;
55866ARG_R_PT        :       /*EMPTY*/
55867		|       HBEGPAR
55868			ARGUMENT_LIST HENDPAR
55869		;
55870MBEE_ARG_R_PT   :       /*EMPTY*/
55871		|       HBEGPAR
55872			ARGUMENT_LIST HENDPAR
55873		;
55874ARGUMENT_LIST   :       EXPRESSION
55875		|       EXPRESSION
55876			HPAREXPSEPARATOR
55877			ARGUMENT_LIST
55878		;
55879%%
55880_ATEOF
55881
55882
55883# Pass plenty of options, to exercise plenty of code, even if we
55884# don't actually check the output.  But SEGV is watching us, and
55885# so might do dmalloc.
55886$at_traceoff
55887echo "existing.at:960: bison --verbose --defines input.y"
55888echo existing.at:960 >$at_check_line_file
55889( $at_traceon; bison --verbose --defines input.y ) >$at_stdout 2>$at_stder1
55890at_status=$?
55891grep '^ *+' $at_stder1 >&2
55892grep -v '^ *+' $at_stder1 >$at_stderr
55893at_failed=false
55894echo >>$at_stderr; echo "input.y: conflicts: 78 shift/reduce, 10 reduce/reduce
55895" | $at_diff - $at_stderr || at_failed=:
55896$at_diff $at_devnull $at_stdout || at_failed=:
55897case $at_status in
55898   77) echo 77 > $at_status_file
55899            exit 77;;
55900   0) ;;
55901   *) echo "existing.at:960: exit code was $at_status, expected 0"
55902      at_failed=:;;
55903esac
55904if $at_failed; then
55905
55906  echo 1 > $at_status_file
55907  exit 1
55908fi
55909
55910$at_traceon
55911
55912
55913$at_traceoff
55914echo "existing.at:972: grep '^State.*conflicts:' input.output"
55915echo existing.at:972 >$at_check_line_file
55916( $at_traceon; grep '^State.*conflicts:' input.output ) >$at_stdout 2>$at_stder1
55917at_status=$?
55918grep '^ *+' $at_stder1 >&2
55919grep -v '^ *+' $at_stder1 >$at_stderr
55920at_failed=false
55921$at_diff $at_devnull $at_stderr || at_failed=:
55922echo >>$at_stdout; echo "State 64 conflicts: 14 shift/reduce
55923State 164 conflicts: 1 shift/reduce
55924State 201 conflicts: 33 shift/reduce, 4 reduce/reduce
55925State 206 conflicts: 1 shift/reduce
55926State 240 conflicts: 1 shift/reduce
55927State 335 conflicts: 9 shift/reduce, 2 reduce/reduce
55928State 356 conflicts: 1 shift/reduce
55929State 360 conflicts: 9 shift/reduce, 2 reduce/reduce
55930State 427 conflicts: 9 shift/reduce, 2 reduce/reduce
55931" | $at_diff - $at_stdout || at_failed=:
55932case $at_status in
55933   77) echo 77 > $at_status_file
55934            exit 77;;
55935   0) ;;
55936   *) echo "existing.at:972: exit code was $at_status, expected 0"
55937      at_failed=:;;
55938esac
55939if $at_failed; then
55940
55941  echo 1 > $at_status_file
55942  exit 1
55943fi
55944
55945$at_traceon
55946
55947
55948      $at_traceoff
55949      $at_times_p && times >$at_times_file
55950    ) 5>&1 2>&1 | eval $at_tee_pipe
55951    at_status=`cat $at_status_file`
55952    ;;
55953
55954  112 ) # 112. existing.at:980: GNU pic Grammar
55955    at_setup_line='existing.at:980'
55956    at_desc='GNU pic Grammar'
55957    $at_quiet $ECHO_N "112: GNU pic Grammar                              $ECHO_C"
55958    at_xfail=no
55959    (
55960      echo "112. existing.at:980: testing ..."
55961      $at_traceon
55962
55963
55964# GNU pic, part of groff.
55965
55966# Bison once reported shift/reduce conflicts that it shouldn't have.
55967
55968cat >input.y <<'_ATEOF'
55969%union {}
55970
55971%token LABEL
55972%token VARIABLE
55973%token NUMBER
55974%token TEXT
55975%token COMMAND_LINE
55976%token DELIMITED
55977%token ORDINAL
55978%token TH
55979%token LEFT_ARROW_HEAD
55980%token RIGHT_ARROW_HEAD
55981%token DOUBLE_ARROW_HEAD
55982%token LAST
55983%token UP
55984%token DOWN
55985%token LEFT
55986%token RIGHT
55987%token BOX
55988%token CIRCLE
55989%token ELLIPSE
55990%token ARC
55991%token LINE
55992%token ARROW
55993%token MOVE
55994%token SPLINE
55995%token HEIGHT
55996%token RADIUS
55997%token WIDTH
55998%token DIAMETER
55999%token FROM
56000%token TO
56001%token AT
56002%token WITH
56003%token BY
56004%token THEN
56005%token SOLID
56006%token DOTTED
56007%token DASHED
56008%token CHOP
56009%token SAME
56010%token INVISIBLE
56011%token LJUST
56012%token RJUST
56013%token ABOVE
56014%token BELOW
56015%token OF
56016%token THE
56017%token WAY
56018%token BETWEEN
56019%token AND
56020%token HERE
56021%token DOT_N
56022%token DOT_E
56023%token DOT_W
56024%token DOT_S
56025%token DOT_NE
56026%token DOT_SE
56027%token DOT_NW
56028%token DOT_SW
56029%token DOT_C
56030%token DOT_START
56031%token DOT_END
56032%token DOT_X
56033%token DOT_Y
56034%token DOT_HT
56035%token DOT_WID
56036%token DOT_RAD
56037%token SIN
56038%token COS
56039%token ATAN2
56040%token LOG
56041%token EXP
56042%token SQRT
56043%token K_MAX
56044%token K_MIN
56045%token INT
56046%token RAND
56047%token SRAND
56048%token COPY
56049%token THRU
56050%token TOP
56051%token BOTTOM
56052%token UPPER
56053%token LOWER
56054%token SH
56055%token PRINT
56056%token CW
56057%token CCW
56058%token FOR
56059%token DO
56060%token IF
56061%token ELSE
56062%token ANDAND
56063%token OROR
56064%token NOTEQUAL
56065%token EQUALEQUAL
56066%token LESSEQUAL
56067%token GREATEREQUAL
56068%token LEFT_CORNER
56069%token RIGHT_CORNER
56070%token NORTH
56071%token SOUTH
56072%token EAST
56073%token WEST
56074%token CENTER
56075%token END
56076%token START
56077%token RESET
56078%token UNTIL
56079%token PLOT
56080%token THICKNESS
56081%token FILL
56082%token COLORED
56083%token OUTLINED
56084%token SHADED
56085%token ALIGNED
56086%token SPRINTF
56087%token COMMAND
56088
56089%left '.'
56090
56091/* this ensures that plot 17 "%g" parses as (plot 17 "%g") */
56092%left PLOT
56093%left TEXT SPRINTF
56094
56095/* give text adjustments higher precedence than TEXT, so that
56096box "foo" above ljust == box ("foo" above ljust)
56097*/
56098
56099%left LJUST RJUST ABOVE BELOW
56100
56101%left LEFT RIGHT
56102/* Give attributes that take an optional expression a higher
56103precedence than left and right, so that eg `line chop left'
56104parses properly. */
56105%left CHOP SOLID DASHED DOTTED UP DOWN FILL COLORED OUTLINED
56106%left LABEL
56107
56108%left VARIABLE NUMBER '(' SIN COS ATAN2 LOG EXP SQRT K_MAX K_MIN INT RAND SRAND LAST
56109%left ORDINAL HERE '`'
56110
56111%left BOX CIRCLE ELLIPSE ARC LINE ARROW SPLINE '[' /* ] */
56112
56113/* these need to be lower than '-' */
56114%left HEIGHT RADIUS WIDTH DIAMETER FROM TO AT THICKNESS
56115
56116/* these must have higher precedence than CHOP so that `label %prec CHOP'
56117works */
56118%left DOT_N DOT_E DOT_W DOT_S DOT_NE DOT_SE DOT_NW DOT_SW DOT_C
56119%left DOT_START DOT_END TOP BOTTOM LEFT_CORNER RIGHT_CORNER
56120%left UPPER LOWER NORTH SOUTH EAST WEST CENTER START END
56121
56122%left ','
56123%left OROR
56124%left ANDAND
56125%left EQUALEQUAL NOTEQUAL
56126%left '<' '>' LESSEQUAL GREATEREQUAL
56127
56128%left BETWEEN OF
56129%left AND
56130
56131%left '+' '-'
56132%left '*' '/' '%'
56133%right '!'
56134%right '^'
56135
56136%%
56137
56138top:
56139	optional_separator
56140	| element_list
56141	;
56142
56143element_list:
56144	optional_separator middle_element_list optional_separator
56145	;
56146
56147middle_element_list:
56148	element
56149	| middle_element_list separator element
56150	;
56151
56152optional_separator:
56153	/* empty */
56154	| separator
56155	;
56156
56157separator:
56158	';'
56159	| separator ';'
56160	;
56161
56162placeless_element:
56163	VARIABLE '=' any_expr
56164	| VARIABLE ':' '=' any_expr
56165	| UP
56166	| DOWN
56167	| LEFT
56168	| RIGHT
56169	| COMMAND_LINE
56170	| COMMAND print_args
56171	| PRINT print_args
56172	| SH
56173		{}
56174	  DELIMITED
56175	| COPY TEXT
56176	| COPY TEXT THRU
56177		{}
56178	  DELIMITED
56179		{}
56180	  until
56181	| COPY THRU
56182		{}
56183	  DELIMITED
56184		{}
56185	  until
56186	| FOR VARIABLE '=' expr TO expr optional_by DO
56187		{}
56188	  DELIMITED
56189	| simple_if
56190	| simple_if ELSE
56191		{}
56192	  DELIMITED
56193	| reset_variables
56194	| RESET
56195	;
56196
56197reset_variables:
56198	RESET VARIABLE
56199	| reset_variables VARIABLE
56200	| reset_variables ',' VARIABLE
56201	;
56202
56203print_args:
56204	print_arg
56205	| print_args print_arg
56206	;
56207
56208print_arg:
56209	expr							%prec ','
56210	| text
56211	| position						%prec ','
56212	;
56213
56214simple_if:
56215	IF any_expr THEN
56216		{}
56217	DELIMITED
56218	;
56219
56220until:
56221	/* empty */
56222	| UNTIL TEXT
56223	;
56224
56225any_expr:
56226	expr
56227	| text_expr
56228	;
56229
56230text_expr:
56231	text EQUALEQUAL text
56232	| text NOTEQUAL text
56233	| text_expr ANDAND text_expr
56234	| text_expr ANDAND expr
56235	| expr ANDAND text_expr
56236	| text_expr OROR text_expr
56237	| text_expr OROR expr
56238	| expr OROR text_expr
56239	| '!' text_expr
56240	;
56241
56242optional_by:
56243	/* empty */
56244	| BY expr
56245	| BY '*' expr
56246	;
56247
56248element:
56249	object_spec
56250	| LABEL ':' optional_separator element
56251	| LABEL ':' optional_separator position_not_place
56252	| LABEL ':' optional_separator place
56253	| '{}'
56254		{}
56255	  optional_element
56256	| placeless_element
56257	;
56258
56259optional_element:
56260	/* empty */
56261	| element
56262	;
56263
56264object_spec:
56265	BOX
56266	| CIRCLE
56267	| ELLIPSE
56268	| ARC
56269	| LINE
56270	| ARROW
56271	| MOVE
56272	| SPLINE
56273	| text							%prec TEXT
56274	| PLOT expr
56275	| PLOT expr text
56276	| '['
56277		{}
56278	  element_list ']'
56279	| object_spec HEIGHT expr
56280	| object_spec RADIUS expr
56281	| object_spec WIDTH expr
56282	| object_spec DIAMETER expr
56283	| object_spec expr					%prec HEIGHT
56284	| object_spec UP
56285	| object_spec UP expr
56286	| object_spec DOWN
56287	| object_spec DOWN expr
56288	| object_spec RIGHT
56289	| object_spec RIGHT expr
56290	| object_spec LEFT
56291	| object_spec LEFT expr
56292	| object_spec FROM position
56293	| object_spec TO position
56294	| object_spec AT position
56295	| object_spec WITH path
56296	| object_spec WITH position				%prec ','
56297	| object_spec BY expr_pair
56298	| object_spec THEN
56299	| object_spec SOLID
56300	| object_spec DOTTED
56301	| object_spec DOTTED expr
56302	| object_spec DASHED
56303	| object_spec DASHED expr
56304	| object_spec FILL
56305	| object_spec FILL expr
56306	| object_spec SHADED text
56307	| object_spec COLORED text
56308	| object_spec OUTLINED text
56309	| object_spec CHOP
56310	| object_spec CHOP expr
56311	| object_spec SAME
56312	| object_spec INVISIBLE
56313	| object_spec LEFT_ARROW_HEAD
56314	| object_spec RIGHT_ARROW_HEAD
56315	| object_spec DOUBLE_ARROW_HEAD
56316	| object_spec CW
56317	| object_spec CCW
56318	| object_spec text					%prec TEXT
56319	| object_spec LJUST
56320	| object_spec RJUST
56321	| object_spec ABOVE
56322	| object_spec BELOW
56323	| object_spec THICKNESS expr
56324	| object_spec ALIGNED
56325	;
56326
56327text:
56328	TEXT
56329	| SPRINTF '(' TEXT sprintf_args ')'
56330	;
56331
56332sprintf_args:
56333	/* empty */
56334	| sprintf_args ',' expr
56335	;
56336
56337position:
56338	position_not_place
56339	| place
56340	;
56341
56342position_not_place:
56343	expr_pair
56344	| position '+' expr_pair
56345	| position '-' expr_pair
56346	| '(' position ',' position ')'
56347	| expr between position AND position
56348	| expr '<' position ',' position '>'
56349	;
56350
56351between:
56352	BETWEEN
56353	| OF THE WAY BETWEEN
56354	;
56355
56356expr_pair:
56357	expr ',' expr
56358	| '(' expr_pair ')'
56359	;
56360
56361place:
56362	/* line at A left == line (at A) left */
56363	label							%prec CHOP
56364	| label corner
56365	| corner label
56366	| corner OF label
56367	| HERE
56368	;
56369
56370label:
56371	LABEL
56372	| nth_primitive
56373	| label '.' LABEL
56374	;
56375
56376ordinal:
56377	ORDINAL
56378	| '`' any_expr TH
56379	;
56380
56381optional_ordinal_last:
56382	LAST
56383	| ordinal LAST
56384	;
56385
56386nth_primitive:
56387	ordinal object_type
56388	| optional_ordinal_last object_type
56389	;
56390
56391object_type:
56392	BOX
56393	| CIRCLE
56394	| ELLIPSE
56395	| ARC
56396	| LINE
56397	| ARROW
56398	| SPLINE
56399	| '[' ']'
56400	| TEXT
56401	;
56402
56403label_path:
56404	'.' LABEL
56405	| label_path '.' LABEL
56406	;
56407
56408relative_path:
56409	corner							%prec CHOP
56410	/* give this a lower precedence than LEFT and RIGHT so that
56411	   [A: box] with .A left == [A: box] with (.A left) */
56412	| label_path						%prec TEXT
56413	| label_path corner
56414	;
56415
56416path:
56417	relative_path
56418	| '(' relative_path ',' relative_path ')'
56419		{}
56420	/* The rest of these rules are a compatibility sop. */
56421	| ORDINAL LAST object_type relative_path
56422	| LAST object_type relative_path
56423	| ORDINAL object_type relative_path
56424	| LABEL relative_path
56425	;
56426
56427corner:
56428	DOT_N
56429	| DOT_E
56430	| DOT_W
56431	| DOT_S
56432	| DOT_NE
56433	| DOT_SE
56434	| DOT_NW
56435	| DOT_SW
56436	| DOT_C
56437	| DOT_START
56438	| DOT_END
56439	| TOP
56440	| BOTTOM
56441	| LEFT
56442	| RIGHT
56443	| UPPER LEFT
56444	| LOWER LEFT
56445	| UPPER RIGHT
56446	| LOWER RIGHT
56447	| LEFT_CORNER
56448	| RIGHT_CORNER
56449	| UPPER LEFT_CORNER
56450	| LOWER LEFT_CORNER
56451	| UPPER RIGHT_CORNER
56452	| LOWER RIGHT_CORNER
56453	| NORTH
56454	| SOUTH
56455	| EAST
56456	| WEST
56457	| CENTER
56458	| START
56459	| END
56460	;
56461
56462expr:
56463	VARIABLE
56464	| NUMBER
56465	| place DOT_X
56466	| place DOT_Y
56467	| place DOT_HT
56468	| place DOT_WID
56469	| place DOT_RAD
56470	| expr '+' expr
56471	| expr '-' expr
56472	| expr '*' expr
56473	| expr '/' expr
56474	| expr '%' expr
56475	| expr '^' expr
56476	| '-' expr						%prec '!'
56477	| '(' any_expr ')'
56478	| SIN '(' any_expr ')'
56479	| COS '(' any_expr ')'
56480	| ATAN2 '(' any_expr ',' any_expr ')'
56481	| LOG '(' any_expr ')'
56482	| EXP '(' any_expr ')'
56483	| SQRT '(' any_expr ')'
56484	| K_MAX '(' any_expr ',' any_expr ')'
56485	| K_MIN '(' any_expr ',' any_expr ')'
56486	| INT '(' any_expr ')'
56487	| RAND '(' any_expr ')'
56488	| RAND '(' ')'
56489	| SRAND '(' any_expr ')'
56490	| expr '<' expr
56491	| expr LESSEQUAL expr
56492	| expr '>' expr
56493	| expr GREATEREQUAL expr
56494	| expr EQUALEQUAL expr
56495	| expr NOTEQUAL expr
56496	| expr ANDAND expr
56497	| expr OROR expr
56498	| '!' expr
56499	;
56500_ATEOF
56501
56502
56503# Pass plenty of options, to exercise plenty of code, even if we
56504# don't actually check the output.  But SEGV is watching us, and
56505# so might do dmalloc.
56506$at_traceoff
56507echo "existing.at:1523: bison --verbose --defines input.y"
56508echo existing.at:1523 >$at_check_line_file
56509( $at_traceon; bison --verbose --defines input.y ) >$at_stdout 2>$at_stder1
56510at_status=$?
56511grep '^ *+' $at_stder1 >&2
56512grep -v '^ *+' $at_stder1 >$at_stderr
56513at_failed=false
56514$at_diff $at_devnull $at_stderr || at_failed=:
56515$at_diff $at_devnull $at_stdout || at_failed=:
56516case $at_status in
56517   77) echo 77 > $at_status_file
56518            exit 77;;
56519   0) ;;
56520   *) echo "existing.at:1523: exit code was $at_status, expected 0"
56521      at_failed=:;;
56522esac
56523if $at_failed; then
56524
56525  echo 1 > $at_status_file
56526  exit 1
56527fi
56528
56529$at_traceon
56530
56531
56532      $at_traceoff
56533      $at_times_p && times >$at_times_file
56534    ) 5>&1 2>&1 | eval $at_tee_pipe
56535    at_status=`cat $at_status_file`
56536    ;;
56537
56538
56539  banner-15 ) # Banner 15. regression.at:21
56540    cat <<\_ATEOF
56541
56542Regression tests.
56543
56544_ATEOF
56545    ;;
56546
56547  113 ) # 113. regression.at:28: Trivial grammars
56548    at_setup_line='regression.at:28'
56549    at_desc='Trivial grammars'
56550    $at_quiet $ECHO_N "113: Trivial grammars                             $ECHO_C"
56551    at_xfail=no
56552    (
56553      echo "113. regression.at:28: testing ..."
56554      $at_traceon
56555
56556
56557cat >input.y <<'_ATEOF'
56558%{
56559#ifdef HAVE_CONFIG_H
56560# include <config.h>
56561  /* We don't need perfect functions for these tests. */
56562# undef malloc
56563# undef memcmp
56564# undef realloc
56565#endif
56566%}
56567
56568%{
56569void yyerror (char const *);
56570int yylex (void);
56571#define YYSTYPE int *
56572%}
56573
56574%error-verbose
56575
56576%%
56577
56578program: 'x';
56579_ATEOF
56580
56581
56582
56583$at_traceoff
56584echo "regression.at:44: bison -o input.c input.y"
56585echo regression.at:44 >$at_check_line_file
56586( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
56587at_status=$?
56588grep '^ *+' $at_stder1 >&2
56589grep -v '^ *+' $at_stder1 >$at_stderr
56590at_failed=false
56591$at_diff $at_devnull $at_stderr || at_failed=:
56592$at_diff $at_devnull $at_stdout || at_failed=:
56593case $at_status in
56594   77) echo 77 > $at_status_file
56595            exit 77;;
56596   0) ;;
56597   *) echo "regression.at:44: exit code was $at_status, expected 0"
56598      at_failed=:;;
56599esac
56600if $at_failed; then
56601
56602  echo 1 > $at_status_file
56603  exit 1
56604fi
56605
56606$at_traceon
56607
56608$at_traceoff
56609echo "regression.at:45: \$CC \$CFLAGS \$CPPFLAGS -o input.o -c input.c"
56610echo regression.at:45 >$at_check_line_file
56611( $at_traceon; $CC $CFLAGS $CPPFLAGS -o input.o -c input.c ) >$at_stdout 2>$at_stder1
56612at_status=$?
56613grep '^ *+' $at_stder1 >&2
56614grep -v '^ *+' $at_stder1 >$at_stderr
56615at_failed=false
56616echo stderr:; cat $at_stderr
56617echo stdout:; cat $at_stdout
56618case $at_status in
56619   77) echo 77 > $at_status_file
56620            exit 77;;
56621   0) ;;
56622   *) echo "regression.at:45: exit code was $at_status, expected 0"
56623      at_failed=:;;
56624esac
56625if $at_failed; then
56626
56627  echo 1 > $at_status_file
56628  exit 1
56629fi
56630
56631$at_traceon
56632
56633$at_traceoff
56634echo "regression.at:46: \$CC \$CFLAGS \$CPPFLAGS -o input.o -DYYDEBUG -c input.c"
56635echo regression.at:46 >$at_check_line_file
56636( $at_traceon; $CC $CFLAGS $CPPFLAGS -o input.o -DYYDEBUG -c input.c ) >$at_stdout 2>$at_stder1
56637at_status=$?
56638grep '^ *+' $at_stder1 >&2
56639grep -v '^ *+' $at_stder1 >$at_stderr
56640at_failed=false
56641echo stderr:; cat $at_stderr
56642echo stdout:; cat $at_stdout
56643case $at_status in
56644   77) echo 77 > $at_status_file
56645            exit 77;;
56646   0) ;;
56647   *) echo "regression.at:46: exit code was $at_status, expected 0"
56648      at_failed=:;;
56649esac
56650if $at_failed; then
56651
56652  echo 1 > $at_status_file
56653  exit 1
56654fi
56655
56656$at_traceon
56657
56658
56659      $at_traceoff
56660      $at_times_p && times >$at_times_file
56661    ) 5>&1 2>&1 | eval $at_tee_pipe
56662    at_status=`cat $at_status_file`
56663    ;;
56664
56665  114 ) # 114. regression.at:57: Early token definitions
56666    at_setup_line='regression.at:57'
56667    at_desc='Early token definitions'
56668    $at_quiet $ECHO_N "114: Early token definitions                      $ECHO_C"
56669    at_xfail=no
56670    (
56671      echo "114. regression.at:57: testing ..."
56672      $at_traceon
56673
56674
56675# Found in GCJ: they expect the tokens to be defined before the user
56676# prologue, so that they can use the token definitions in it.
56677
56678cat >input.y <<'_ATEOF'
56679%{
56680#ifdef HAVE_CONFIG_H
56681# include <config.h>
56682  /* We don't need perfect functions for these tests. */
56683# undef malloc
56684# undef memcmp
56685# undef realloc
56686#endif
56687%}
56688
56689%{
56690void yyerror (const char *s);
56691int yylex (void);
56692%}
56693
56694%union
56695{
56696  int val;
56697};
56698%{
56699#ifndef MY_TOKEN
56700# error "MY_TOKEN not defined."
56701#endif
56702%}
56703%token MY_TOKEN
56704%%
56705exp: MY_TOKEN;
56706%%
56707_ATEOF
56708
56709
56710
56711$at_traceoff
56712echo "regression.at:83: bison -o input.c input.y"
56713echo regression.at:83 >$at_check_line_file
56714( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
56715at_status=$?
56716grep '^ *+' $at_stder1 >&2
56717grep -v '^ *+' $at_stder1 >$at_stderr
56718at_failed=false
56719$at_diff $at_devnull $at_stderr || at_failed=:
56720$at_diff $at_devnull $at_stdout || at_failed=:
56721case $at_status in
56722   77) echo 77 > $at_status_file
56723            exit 77;;
56724   0) ;;
56725   *) echo "regression.at:83: exit code was $at_status, expected 0"
56726      at_failed=:;;
56727esac
56728if $at_failed; then
56729
56730  echo 1 > $at_status_file
56731  exit 1
56732fi
56733
56734$at_traceon
56735
56736$at_traceoff
56737echo "regression.at:84: \$CC \$CFLAGS \$CPPFLAGS -o input.o -c input.c"
56738echo regression.at:84 >$at_check_line_file
56739( $at_traceon; $CC $CFLAGS $CPPFLAGS -o input.o -c input.c ) >$at_stdout 2>$at_stder1
56740at_status=$?
56741grep '^ *+' $at_stder1 >&2
56742grep -v '^ *+' $at_stder1 >$at_stderr
56743at_failed=false
56744echo stderr:; cat $at_stderr
56745echo stdout:; cat $at_stdout
56746case $at_status in
56747   77) echo 77 > $at_status_file
56748            exit 77;;
56749   0) ;;
56750   *) echo "regression.at:84: exit code was $at_status, expected 0"
56751      at_failed=:;;
56752esac
56753if $at_failed; then
56754
56755  echo 1 > $at_status_file
56756  exit 1
56757fi
56758
56759$at_traceon
56760
56761
56762      $at_traceoff
56763      $at_times_p && times >$at_times_file
56764    ) 5>&1 2>&1 | eval $at_tee_pipe
56765    at_status=`cat $at_status_file`
56766    ;;
56767
56768  115 ) # 115. regression.at:95: Braces parsing
56769    at_setup_line='regression.at:95'
56770    at_desc='Braces parsing'
56771    $at_quiet $ECHO_N "115: Braces parsing                               $ECHO_C"
56772    at_xfail=no
56773    (
56774      echo "115. regression.at:95: testing ..."
56775      $at_traceon
56776
56777
56778cat >input.y <<'_ATEOF'
56779/* Bison used to swallow the character after `}'. */
56780
56781%%
56782exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
56783%%
56784_ATEOF
56785
56786
56787$at_traceoff
56788echo "regression.at:105: bison -v -o input.c input.y"
56789echo regression.at:105 >$at_check_line_file
56790( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
56791at_status=$?
56792grep '^ *+' $at_stder1 >&2
56793grep -v '^ *+' $at_stder1 >$at_stderr
56794at_failed=false
56795$at_diff $at_devnull $at_stderr || at_failed=:
56796$at_diff $at_devnull $at_stdout || at_failed=:
56797case $at_status in
56798   77) echo 77 > $at_status_file
56799            exit 77;;
56800   0) ;;
56801   *) echo "regression.at:105: exit code was $at_status, expected 0"
56802      at_failed=:;;
56803esac
56804if $at_failed; then
56805
56806  echo 1 > $at_status_file
56807  exit 1
56808fi
56809
56810$at_traceon
56811
56812
56813$at_traceoff
56814echo "regression.at:107: grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c"
56815echo regression.at:107 >$at_check_line_file
56816( $at_traceon; grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c ) >$at_stdout 2>$at_stder1
56817at_status=$?
56818grep '^ *+' $at_stder1 >&2
56819grep -v '^ *+' $at_stder1 >$at_stderr
56820at_failed=false
56821$at_diff $at_devnull $at_stderr || at_failed=:
56822echo stdout:; cat $at_stdout
56823case $at_status in
56824   77) echo 77 > $at_status_file
56825            exit 77;;
56826   0) ;;
56827   *) echo "regression.at:107: exit code was $at_status, expected 0"
56828      at_failed=:;;
56829esac
56830if $at_failed; then
56831
56832  echo 1 > $at_status_file
56833  exit 1
56834fi
56835
56836$at_traceon
56837
56838
56839      $at_traceoff
56840      $at_times_p && times >$at_times_file
56841    ) 5>&1 2>&1 | eval $at_tee_pipe
56842    at_status=`cat $at_status_file`
56843    ;;
56844
56845  116 ) # 116. regression.at:117: Duplicate string
56846    at_setup_line='regression.at:117'
56847    at_desc='Duplicate string'
56848    $at_quiet $ECHO_N "116: Duplicate string                             $ECHO_C"
56849    at_xfail=no
56850    (
56851      echo "116. regression.at:117: testing ..."
56852      $at_traceon
56853
56854
56855cat >input.y <<'_ATEOF'
56856/* `Bison -v' used to dump core when two tokens are defined with the same
56857   string, as LE and GE below. */
56858
56859%token NUM
56860%token LE "<="
56861%token GE "<="
56862
56863%%
56864exp: '(' exp ')' | NUM ;
56865%%
56866_ATEOF
56867
56868
56869$at_traceoff
56870echo "regression.at:134: bison -v -o input.c input.y"
56871echo regression.at:134 >$at_check_line_file
56872( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
56873at_status=$?
56874grep '^ *+' $at_stder1 >&2
56875grep -v '^ *+' $at_stder1 >$at_stderr
56876at_failed=false
56877echo >>$at_stderr; echo "input.y:6.8-14: warning: symbol \`\"<=\"' used more than once as a literal string
56878" | $at_diff - $at_stderr || at_failed=:
56879$at_diff $at_devnull $at_stdout || at_failed=:
56880case $at_status in
56881   77) echo 77 > $at_status_file
56882            exit 77;;
56883   0) ;;
56884   *) echo "regression.at:134: exit code was $at_status, expected 0"
56885      at_failed=:;;
56886esac
56887if $at_failed; then
56888
56889  echo 1 > $at_status_file
56890  exit 1
56891fi
56892
56893$at_traceon
56894
56895
56896      $at_traceoff
56897      $at_times_p && times >$at_times_file
56898    ) 5>&1 2>&1 | eval $at_tee_pipe
56899    at_status=`cat $at_status_file`
56900    ;;
56901
56902  117 ) # 117. regression.at:143: Rule Line Numbers
56903    at_setup_line='regression.at:143'
56904    at_desc='Rule Line Numbers'
56905    $at_quiet $ECHO_N "117: Rule Line Numbers                            $ECHO_C"
56906    at_xfail=no
56907    (
56908      echo "117. regression.at:143: testing ..."
56909      $at_traceon
56910
56911
56912
56913
56914cat >input.y <<'_ATEOF'
56915%%
56916expr:
56917'a'
56918
56919{
56920
56921}
56922
56923'b'
56924
56925{
56926
56927}
56928
56929|
56930
56931
56932{
56933
56934
56935}
56936
56937'c'
56938
56939{
56940
56941};
56942_ATEOF
56943
56944
56945$at_traceoff
56946echo "regression.at:177: bison -o input.c -v input.y"
56947echo regression.at:177 >$at_check_line_file
56948( $at_traceon; bison -o input.c -v input.y ) >$at_stdout 2>$at_stder1
56949at_status=$?
56950grep '^ *+' $at_stder1 >&2
56951grep -v '^ *+' $at_stder1 >$at_stderr
56952at_failed=false
56953$at_diff $at_devnull $at_stderr || at_failed=:
56954$at_diff $at_devnull $at_stdout || at_failed=:
56955case $at_status in
56956   77) echo 77 > $at_status_file
56957            exit 77;;
56958   0) ;;
56959   *) echo "regression.at:177: exit code was $at_status, expected 0"
56960      at_failed=:;;
56961esac
56962if $at_failed; then
56963
56964  echo 1 > $at_status_file
56965  exit 1
56966fi
56967
56968$at_traceon
56969
56970
56971# Check the contents of the report.
56972$at_traceoff
56973echo "regression.at:276: cat input.output"
56974echo regression.at:276 >$at_check_line_file
56975( $at_traceon; cat input.output ) >$at_stdout 2>$at_stder1
56976at_status=$?
56977grep '^ *+' $at_stder1 >&2
56978grep -v '^ *+' $at_stder1 >$at_stderr
56979at_failed=false
56980$at_diff $at_devnull $at_stderr || at_failed=:
56981echo >>$at_stdout; echo "Grammar
56982
56983    0 \$accept: expr \$end
56984
56985    1 @1: /* empty */
56986
56987    2 expr: 'a' @1 'b'
56988
56989    3 @2: /* empty */
56990
56991    4 expr: @2 'c'
56992
56993
56994Terminals, with rules where they appear
56995
56996\$end (0) 0
56997'a' (97) 2
56998'b' (98) 2
56999'c' (99) 4
57000error (256)
57001
57002
57003Nonterminals, with rules where they appear
57004
57005\$accept (6)
57006    on left: 0
57007expr (7)
57008    on left: 2 4, on right: 0
57009@1 (8)
57010    on left: 1, on right: 2
57011@2 (9)
57012    on left: 3, on right: 4
57013
57014
57015state 0
57016
57017    0 \$accept: . expr \$end
57018
57019    'a'  shift, and go to state 1
57020
57021    \$default  reduce using rule 3 (@2)
57022
57023    expr  go to state 2
57024    @2    go to state 3
57025
57026
57027state 1
57028
57029    2 expr: 'a' . @1 'b'
57030
57031    \$default  reduce using rule 1 (@1)
57032
57033    @1  go to state 4
57034
57035
57036state 2
57037
57038    0 \$accept: expr . \$end
57039
57040    \$end  shift, and go to state 5
57041
57042
57043state 3
57044
57045    4 expr: @2 . 'c'
57046
57047    'c'  shift, and go to state 6
57048
57049
57050state 4
57051
57052    2 expr: 'a' @1 . 'b'
57053
57054    'b'  shift, and go to state 7
57055
57056
57057state 5
57058
57059    0 \$accept: expr \$end .
57060
57061    \$default  accept
57062
57063
57064state 6
57065
57066    4 expr: @2 'c' .
57067
57068    \$default  reduce using rule 4 (expr)
57069
57070
57071state 7
57072
57073    2 expr: 'a' @1 'b' .
57074
57075    \$default  reduce using rule 2 (expr)
57076" | $at_diff - $at_stdout || at_failed=:
57077case $at_status in
57078   77) echo 77 > $at_status_file
57079            exit 77;;
57080   0) ;;
57081   *) echo "regression.at:276: exit code was $at_status, expected 0"
57082      at_failed=:;;
57083esac
57084if $at_failed; then
57085
57086  echo 1 > $at_status_file
57087  exit 1
57088fi
57089
57090$at_traceon
57091
57092
57093      $at_traceoff
57094      $at_times_p && times >$at_times_file
57095    ) 5>&1 2>&1 | eval $at_tee_pipe
57096    at_status=`cat $at_status_file`
57097    ;;
57098
57099  118 ) # 118. regression.at:287: Mixing %token styles
57100    at_setup_line='regression.at:287'
57101    at_desc='Mixing %token styles'
57102    $at_quiet $ECHO_N "118: Mixing %token styles                         $ECHO_C"
57103    at_xfail=no
57104    (
57105      echo "118. regression.at:287: testing ..."
57106      $at_traceon
57107
57108
57109# Taken from the documentation.
57110cat >input.y <<'_ATEOF'
57111%token  <operator>  OR      "||"
57112%token  <operator>  LE 134  "<="
57113%left  OR  "<="
57114%%
57115exp: ;
57116%%
57117_ATEOF
57118
57119
57120$at_traceoff
57121echo "regression.at:299: bison -v -o input.c input.y"
57122echo regression.at:299 >$at_check_line_file
57123( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
57124at_status=$?
57125grep '^ *+' $at_stder1 >&2
57126grep -v '^ *+' $at_stder1 >$at_stderr
57127at_failed=false
57128$at_diff $at_devnull $at_stderr || at_failed=:
57129$at_diff $at_devnull $at_stdout || at_failed=:
57130case $at_status in
57131   77) echo 77 > $at_status_file
57132            exit 77;;
57133   0) ;;
57134   *) echo "regression.at:299: exit code was $at_status, expected 0"
57135      at_failed=:;;
57136esac
57137if $at_failed; then
57138
57139  echo 1 > $at_status_file
57140  exit 1
57141fi
57142
57143$at_traceon
57144
57145
57146      $at_traceoff
57147      $at_times_p && times >$at_times_file
57148    ) 5>&1 2>&1 | eval $at_tee_pipe
57149    at_status=`cat $at_status_file`
57150    ;;
57151
57152  119 ) # 119. regression.at:310: Invalid inputs
57153    at_setup_line='regression.at:310'
57154    at_desc='Invalid inputs'
57155    $at_quiet $ECHO_N "119: Invalid inputs                               $ECHO_C"
57156    at_xfail=no
57157    (
57158      echo "119. regression.at:310: testing ..."
57159      $at_traceon
57160
57161
57162cat >input.y <<'_ATEOF'
57163%%
57164?
57165default: 'a' }
57166%&
57167%a-does-not-exist
57168%-
57169%{
57170_ATEOF
57171
57172
57173$at_traceoff
57174echo "regression.at:331: bison input.y"
57175echo regression.at:331 >$at_check_line_file
57176( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
57177at_status=$?
57178grep '^ *+' $at_stder1 >&2
57179grep -v '^ *+' $at_stder1 >$at_stderr
57180at_failed=false
57181echo >>$at_stderr; echo "input.y:2.1: invalid character: \`?'
57182input.y:3.14: invalid character: \`}'
57183input.y:4.1: invalid character: \`%'
57184input.y:4.2: invalid character: \`&'
57185input.y:5.1-17: invalid directive: \`%a-does-not-exist'
57186input.y:6.1: invalid character: \`%'
57187input.y:6.2: invalid character: \`-'
57188input.y:7.1-8.0: missing \`%}' at end of file
57189" | $at_diff - $at_stderr || at_failed=:
57190$at_diff $at_devnull $at_stdout || at_failed=:
57191case $at_status in
57192   77) echo 77 > $at_status_file
57193            exit 77;;
57194   1) ;;
57195   *) echo "regression.at:331: exit code was $at_status, expected 1"
57196      at_failed=:;;
57197esac
57198if $at_failed; then
57199
57200  echo 1 > $at_status_file
57201  exit 1
57202fi
57203
57204$at_traceon
57205
57206
57207      $at_traceoff
57208      $at_times_p && times >$at_times_file
57209    ) 5>&1 2>&1 | eval $at_tee_pipe
57210    at_status=`cat $at_status_file`
57211    ;;
57212
57213  120 ) # 120. regression.at:336: Invalid inputs with {}
57214    at_setup_line='regression.at:336'
57215    at_desc='Invalid inputs with {}'
57216    $at_quiet $ECHO_N "120: Invalid inputs with {}                       $ECHO_C"
57217    at_xfail=no
57218    (
57219      echo "120. regression.at:336: testing ..."
57220      $at_traceon
57221
57222
57223cat >input.y <<'_ATEOF'
57224
57225%destructor
57226%initial-action
57227%lex-param
57228%parse-param
57229%printer
57230%union
57231_ATEOF
57232
57233
57234$at_traceoff
57235echo "regression.at:352: bison input.y"
57236echo regression.at:352 >$at_check_line_file
57237( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1
57238at_status=$?
57239grep '^ *+' $at_stder1 >&2
57240grep -v '^ *+' $at_stder1 >$at_stderr
57241at_failed=false
57242echo >>$at_stderr; echo "input.y:3.1: missing \`{' in \"%destructor {...}\"
57243input.y:4.1: missing \`{' in \"%initial-action {...}\"
57244input.y:4.1: syntax error, unexpected %initial-action {...}, expecting string or identifier
57245" | $at_diff - $at_stderr || at_failed=:
57246$at_diff $at_devnull $at_stdout || at_failed=:
57247case $at_status in
57248   77) echo 77 > $at_status_file
57249            exit 77;;
57250   1) ;;
57251   *) echo "regression.at:352: exit code was $at_status, expected 1"
57252      at_failed=:;;
57253esac
57254if $at_failed; then
57255
57256  echo 1 > $at_status_file
57257  exit 1
57258fi
57259
57260$at_traceon
57261
57262
57263      $at_traceoff
57264      $at_times_p && times >$at_times_file
57265    ) 5>&1 2>&1 | eval $at_tee_pipe
57266    at_status=`cat $at_status_file`
57267    ;;
57268
57269  121 ) # 121. regression.at:363: Token definitions
57270    at_setup_line='regression.at:363'
57271    at_desc='Token definitions'
57272    $at_quiet $ECHO_N "121: Token definitions                            $ECHO_C"
57273    at_xfail=no
57274    (
57275      echo "121. regression.at:363: testing ..."
57276      $at_traceon
57277
57278
57279# Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
57280cat >input.y <<'_ATEOF'
57281%{
57282#ifdef HAVE_CONFIG_H
57283# include <config.h>
57284  /* We don't need perfect functions for these tests. */
57285# undef malloc
57286# undef memcmp
57287# undef realloc
57288#endif
57289%}
57290
57291%{
57292#include <stdio.h>
57293void yyerror (const char *s);
57294int yylex (void);
57295%}
57296%error-verbose
57297%token MYEOF 0 "end of file"
57298%token 'a' "a"
57299%token B_TOKEN "b"
57300%token C_TOKEN 'c'
57301%token 'd' D_TOKEN
57302%token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
57303%%
57304exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!";
57305%%
57306void
57307yyerror (char const *s)
57308{
57309  fprintf (stderr, "%s\n", s);
57310}
57311
57312int
57313yylex (void)
57314{
57315  return SPECIAL;
57316}
57317
57318int
57319main (void)
57320{
57321  return yyparse ();
57322}
57323_ATEOF
57324
57325
57326
57327$at_traceoff
57328echo "regression.at:401: bison -o input.c input.y"
57329echo regression.at:401 >$at_check_line_file
57330( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
57331at_status=$?
57332grep '^ *+' $at_stder1 >&2
57333grep -v '^ *+' $at_stder1 >$at_stderr
57334at_failed=false
57335$at_diff $at_devnull $at_stderr || at_failed=:
57336$at_diff $at_devnull $at_stdout || at_failed=:
57337case $at_status in
57338   77) echo 77 > $at_status_file
57339            exit 77;;
57340   0) ;;
57341   *) echo "regression.at:401: exit code was $at_status, expected 0"
57342      at_failed=:;;
57343esac
57344if $at_failed; then
57345
57346  echo 1 > $at_status_file
57347  exit 1
57348fi
57349
57350$at_traceon
57351
57352$at_traceoff
57353echo "regression.at:402: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS"
57354echo regression.at:402 >$at_check_line_file
57355( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1
57356at_status=$?
57357grep '^ *+' $at_stder1 >&2
57358grep -v '^ *+' $at_stder1 >$at_stderr
57359at_failed=false
57360echo stderr:; cat $at_stderr
57361echo stdout:; cat $at_stdout
57362case $at_status in
57363   77) echo 77 > $at_status_file
57364            exit 77;;
57365   0) ;;
57366   *) echo "regression.at:402: exit code was $at_status, expected 0"
57367      at_failed=:;;
57368esac
57369if $at_failed; then
57370
57371  echo 1 > $at_status_file
57372  exit 1
57373fi
57374
57375$at_traceon
57376
57377cat >experr <<'_ATEOF'
57378syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201?\?!", expecting a
57379_ATEOF
57380
57381$at_traceoff
57382echo "regression.at:406: \$PREPARSER ./input"
57383echo regression.at:406 >$at_check_line_file
57384( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1
57385at_status=$?
57386grep '^ *+' $at_stder1 >&2
57387grep -v '^ *+' $at_stder1 >$at_stderr
57388at_failed=false
57389$at_diff experr $at_stderr || at_failed=:
57390$at_diff $at_devnull $at_stdout || at_failed=:
57391case $at_status in
57392   77) echo 77 > $at_status_file
57393            exit 77;;
57394   1) ;;
57395   *) echo "regression.at:406: exit code was $at_status, expected 1"
57396      at_failed=:;;
57397esac
57398if $at_failed; then
57399
57400  echo 1 > $at_status_file
57401  exit 1
57402fi
57403
57404$at_traceon
57405
57406      $at_traceoff
57407      $at_times_p && times >$at_times_file
57408    ) 5>&1 2>&1 | eval $at_tee_pipe
57409    at_status=`cat $at_status_file`
57410    ;;
57411
57412  122 ) # 122. regression.at:416: Characters Escapes
57413    at_setup_line='regression.at:416'
57414    at_desc='Characters Escapes'
57415    $at_quiet $ECHO_N "122: Characters Escapes                           $ECHO_C"
57416    at_xfail=no
57417    (
57418      echo "122. regression.at:416: testing ..."
57419      $at_traceon
57420
57421
57422cat >input.y <<'_ATEOF'
57423%{
57424#ifdef HAVE_CONFIG_H
57425# include <config.h>
57426  /* We don't need perfect functions for these tests. */
57427# undef malloc
57428# undef memcmp
57429# undef realloc
57430#endif
57431%}
57432
57433%{
57434void yyerror (const char *s);
57435int yylex (void);
57436%}
57437%%
57438exp:
57439  '\'' "\'"
57440| '\"' "\""
57441| '"'  "'"
57442;
57443_ATEOF
57444
57445
57446# Pacify font-lock-mode: "
57447
57448$at_traceoff
57449echo "regression.at:432: bison -o input.c input.y"
57450echo regression.at:432 >$at_check_line_file
57451( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1
57452at_status=$?
57453grep '^ *+' $at_stder1 >&2
57454grep -v '^ *+' $at_stder1 >$at_stderr
57455at_failed=false
57456$at_diff $at_devnull $at_stderr || at_failed=:
57457$at_diff $at_devnull $at_stdout || at_failed=:
57458case $at_status in
57459   77) echo 77 > $at_status_file
57460            exit 77;;
57461   0) ;;
57462   *) echo "regression.at:432: exit code was $at_status, expected 0"
57463      at_failed=:;;
57464esac
57465if $at_failed; then
57466
57467  echo 1 > $at_status_file
57468  exit 1
57469fi
57470
57471$at_traceon
57472
57473$at_traceoff
57474echo "regression.at:433: \$CC \$CFLAGS \$CPPFLAGS -o input.o -c input.c"
57475echo regression.at:433 >$at_check_line_file
57476( $at_traceon; $CC $CFLAGS $CPPFLAGS -o input.o -c input.c ) >$at_stdout 2>$at_stder1
57477at_status=$?
57478grep '^ *+' $at_stder1 >&2
57479grep -v '^ *+' $at_stder1 >$at_stderr
57480at_failed=false
57481echo stderr:; cat $at_stderr
57482echo stdout:; cat $at_stdout
57483case $at_status in
57484   77) echo 77 > $at_status_file
57485            exit 77;;
57486   0) ;;
57487   *) echo "regression.at:433: exit code was $at_status, expected 0"
57488      at_failed=:;;
57489esac
57490if $at_failed; then
57491
57492  echo 1 > $at_status_file
57493  exit 1
57494fi
57495
57496$at_traceon
57497
57498      $at_traceoff
57499      $at_times_p && times >$at_times_file
57500    ) 5>&1 2>&1 | eval $at_tee_pipe
57501    at_status=`cat $at_status_file`
57502    ;;
57503
57504  123 ) # 123. regression.at:447: Web2c Report
57505    at_setup_line='regression.at:447'
57506    at_desc='Web2c Report'
57507    $at_quiet $ECHO_N "123: Web2c Report                                 $ECHO_C"
57508    at_xfail=no
57509    (
57510      echo "123. regression.at:447: testing ..."
57511      $at_traceon
57512
57513
57514
57515
57516cat >input.y <<'_ATEOF'
57517%token	undef_id_tok const_id_tok
57518
57519%start CONST_DEC_PART
57520
57521%%
57522CONST_DEC_PART:
57523         CONST_DEC_LIST
57524        ;
57525
57526CONST_DEC_LIST:
57527	  CONST_DEC
57528        | CONST_DEC_LIST CONST_DEC
57529        ;
57530
57531CONST_DEC:
57532	  { } undef_id_tok '=' const_id_tok ';'
57533        ;
57534%%
57535_ATEOF
57536
57537
57538$at_traceoff
57539echo "regression.at:472: bison -v input.y"
57540echo regression.at:472 >$at_check_line_file
57541( $at_traceon; bison -v input.y ) >$at_stdout 2>$at_stder1
57542at_status=$?
57543grep '^ *+' $at_stder1 >&2
57544grep -v '^ *+' $at_stder1 >$at_stderr
57545at_failed=false
57546$at_diff $at_devnull $at_stderr || at_failed=:
57547$at_diff $at_devnull $at_stdout || at_failed=:
57548case $at_status in
57549   77) echo 77 > $at_status_file
57550            exit 77;;
57551   0) ;;
57552   *) echo "regression.at:472: exit code was $at_status, expected 0"
57553      at_failed=:;;
57554esac
57555if $at_failed; then
57556
57557  echo 1 > $at_status_file
57558  exit 1
57559fi
57560
57561$at_traceon
57562
57563$at_traceoff
57564echo "regression.at:597: cat input.output"
57565echo regression.at:597 >$at_check_line_file
57566( $at_traceon; cat input.output ) >$at_stdout 2>$at_stder1
57567at_status=$?
57568grep '^ *+' $at_stder1 >&2
57569grep -v '^ *+' $at_stder1 >$at_stderr
57570at_failed=false
57571$at_diff $at_devnull $at_stderr || at_failed=:
57572echo >>$at_stdout; echo "Grammar
57573
57574    0 \$accept: CONST_DEC_PART \$end
57575
57576    1 CONST_DEC_PART: CONST_DEC_LIST
57577
57578    2 CONST_DEC_LIST: CONST_DEC
57579    3               | CONST_DEC_LIST CONST_DEC
57580
57581    4 @1: /* empty */
57582
57583    5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';'
57584
57585
57586Terminals, with rules where they appear
57587
57588\$end (0) 0
57589';' (59) 5
57590'=' (61) 5
57591error (256)
57592undef_id_tok (258) 5
57593const_id_tok (259) 5
57594
57595
57596Nonterminals, with rules where they appear
57597
57598\$accept (7)
57599    on left: 0
57600CONST_DEC_PART (8)
57601    on left: 1, on right: 0
57602CONST_DEC_LIST (9)
57603    on left: 2 3, on right: 1 3
57604CONST_DEC (10)
57605    on left: 5, on right: 2 3
57606@1 (11)
57607    on left: 4, on right: 5
57608
57609
57610state 0
57611
57612    0 \$accept: . CONST_DEC_PART \$end
57613
57614    \$default  reduce using rule 4 (@1)
57615
57616    CONST_DEC_PART  go to state 1
57617    CONST_DEC_LIST  go to state 2
57618    CONST_DEC       go to state 3
57619    @1              go to state 4
57620
57621
57622state 1
57623
57624    0 \$accept: CONST_DEC_PART . \$end
57625
57626    \$end  shift, and go to state 5
57627
57628
57629state 2
57630
57631    1 CONST_DEC_PART: CONST_DEC_LIST .
57632    3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
57633
57634    undef_id_tok  reduce using rule 4 (@1)
57635    \$default      reduce using rule 1 (CONST_DEC_PART)
57636
57637    CONST_DEC  go to state 6
57638    @1         go to state 4
57639
57640
57641state 3
57642
57643    2 CONST_DEC_LIST: CONST_DEC .
57644
57645    \$default  reduce using rule 2 (CONST_DEC_LIST)
57646
57647
57648state 4
57649
57650    5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';'
57651
57652    undef_id_tok  shift, and go to state 7
57653
57654
57655state 5
57656
57657    0 \$accept: CONST_DEC_PART \$end .
57658
57659    \$default  accept
57660
57661
57662state 6
57663
57664    3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
57665
57666    \$default  reduce using rule 3 (CONST_DEC_LIST)
57667
57668
57669state 7
57670
57671    5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';'
57672
57673    '='  shift, and go to state 8
57674
57675
57676state 8
57677
57678    5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';'
57679
57680    const_id_tok  shift, and go to state 9
57681
57682
57683state 9
57684
57685    5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';'
57686
57687    ';'  shift, and go to state 10
57688
57689
57690state 10
57691
57692    5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' .
57693
57694    \$default  reduce using rule 5 (CONST_DEC)
57695" | $at_diff - $at_stdout || at_failed=:
57696case $at_status in
57697   77) echo 77 > $at_status_file
57698            exit 77;;
57699   0) ;;
57700   *) echo "regression.at:597: exit code was $at_status, expected 0"
57701      at_failed=:;;
57702esac
57703if $at_failed; then
57704
57705  echo 1 > $at_status_file
57706  exit 1
57707fi
57708
57709$at_traceon
57710
57711
57712      $at_traceoff
57713      $at_times_p && times >$at_times_file
57714    ) 5>&1 2>&1 | eval $at_tee_pipe
57715    at_status=`cat $at_status_file`
57716    ;;
57717
57718  124 ) # 124. regression.at:624: Web2c Actions
57719    at_setup_line='regression.at:624'
57720    at_desc='Web2c Actions'
57721    $at_quiet $ECHO_N "124: Web2c Actions                                $ECHO_C"
57722    at_xfail=no
57723    (
57724      echo "124. regression.at:624: testing ..."
57725      $at_traceon
57726
57727
57728
57729
57730cat >input.y <<'_ATEOF'
57731%%
57732statement:  struct_stat;
57733struct_stat:  /* empty. */ | if else;
57734if: "if" "const" "then" statement;
57735else: "else" statement;
57736%%
57737_ATEOF
57738
57739
57740$at_traceoff
57741echo "regression.at:637: bison -v -o input.c input.y"
57742echo regression.at:637 >$at_check_line_file
57743( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1
57744at_status=$?
57745grep '^ *+' $at_stder1 >&2
57746grep -v '^ *+' $at_stder1 >$at_stderr
57747at_failed=false
57748$at_diff $at_devnull $at_stderr || at_failed=:
57749$at_diff $at_devnull $at_stdout || at_failed=:
57750case $at_status in
57751   77) echo 77 > $at_status_file
57752            exit 77;;
57753   0) ;;
57754   *) echo "regression.at:637: exit code was $at_status, expected 0"
57755      at_failed=:;;
57756esac
57757if $at_failed; then
57758
57759  echo 1 > $at_status_file
57760  exit 1
57761fi
57762
57763$at_traceon
57764
57765
57766# Check only the tables.  We don't use --no-parser, because it is
57767# still to be implemented in the experimental branch of Bison.
57768sed -n 's/  *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c
57769
57770$at_traceoff
57771echo "regression.at:735: cat tables.c"
57772echo regression.at:735 >$at_check_line_file
57773( $at_traceon; cat tables.c ) >$at_stdout 2>$at_stder1
57774at_status=$?
57775grep '^ *+' $at_stder1 >&2
57776grep -v '^ *+' $at_stder1 >$at_stderr
57777at_failed=false
57778$at_diff $at_devnull $at_stderr || at_failed=:
57779echo >>$at_stdout; echo "static const yytype_uint8 yytranslate[] =
57780{
57781       0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57782       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57783       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57784       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57785       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57786       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57787       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57788       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57789       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57790       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57791       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57792       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57793       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57794       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57795       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57796       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57797       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57798       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57799       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57800       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57801       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57802       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57803       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57804       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57805       2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
57806       2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
57807       5,     6
57808};
57809static const yytype_uint8 yyprhs[] =
57810{
57811       0,     0,     3,     5,     6,     9,    14
57812};
57813static const yytype_int8 yyrhs[] =
57814{
57815       8,     0,    -1,     9,    -1,    -1,    10,    11,    -1,     3,
57816       4,     5,     8,    -1,     6,     8,    -1
57817};
57818static const yytype_uint8 yyrline[] =
57819{
57820       0,     2,     2,     3,     3,     4,     5
57821};
57822static const char *const yytname[] =
57823{
57824  \"\$end\", \"error\", \"\$undefined\", \"\\\"if\\\"\", \"\\\"const\\\"\", \"\\\"then\\\"\",
57825  \"\\\"else\\\"\", \"\$accept\", \"statement\", \"struct_stat\", \"if\", \"else\", 0
57826};
57827static const yytype_uint16 yytoknum[] =
57828{
57829       0,   256,   257,   258,   259,   260,   261
57830};
57831static const yytype_uint8 yyr1[] =
57832{
57833       0,     7,     8,     9,     9,    10,    11
57834};
57835static const yytype_uint8 yyr2[] =
57836{
57837       0,     2,     1,     0,     2,     4,     2
57838};
57839static const yytype_uint8 yydefact[] =
57840{
57841       3,     0,     0,     2,     0,     0,     1,     3,     4,     3,
57842       6,     5
57843};
57844static const yytype_int8 yydefgoto[] =
57845{
57846      -1,     2,     3,     4,     8
57847};
57848static const yytype_int8 yypact[] =
57849{
57850      -2,    -1,     4,    -8,     0,     2,    -8,    -2,    -8,    -2,
57851      -8,    -8
57852};
57853static const yytype_int8 yypgoto[] =
57854{
57855      -8,    -7,    -8,    -8,    -8
57856};
57857static const yytype_uint8 yytable[] =
57858{
57859      10,     1,    11,     5,     6,     0,     7,     9
57860};
57861static const yytype_int8 yycheck[] =
57862{
57863       7,     3,     9,     4,     0,    -1,     6,     5
57864};
57865static const yytype_uint8 yystos[] =
57866{
57867       0,     3,     8,     9,    10,     4,     0,     6,    11,     5,
57868       8,     8
57869};
57870" | $at_diff - $at_stdout || at_failed=:
57871case $at_status in
57872   77) echo 77 > $at_status_file
57873            exit 77;;
57874   0) ;;
57875   *) echo "regression.at:735: exit code was $at_status, expected 0"
57876      at_failed=:;;
57877esac
57878if $at_failed; then
57879
57880  echo 1 > $at_status_file
57881  exit 1
57882fi
57883
57884$at_traceon
57885
57886
57887      $at_traceoff
57888      $at_times_p && times >$at_times_file
57889    ) 5>&1 2>&1 | eval $at_tee_pipe
57890    at_status=`cat $at_status_file`
57891    ;;
57892
57893  125 ) # 125. regression.at:866: Dancer
57894    at_setup_line='regression.at:866'
57895    at_desc='Dancer '
57896    $at_quiet $ECHO_N "125: Dancer                                       $ECHO_C"
57897    at_xfail=no
57898    (
57899      echo "125. regression.at:866: testing ..."
57900      $at_traceon
57901
57902
57903
57904
57905
57906# Using yacc.c?
57907
57908
57909
57910
57911
57912
57913
57914# yyerror receives the location if %location & %pure & (%glr or %parse-param).
57915
57916# yyerror always sees the locations (when activated), except if
57917# yacc & pure & !param.
57918
57919
57920# The interface is pure: either because %pure-parser, or because we
57921# are using the C++ parsers.
57922
57923
57924
57925
57926
57927
57928
57929
57930
57931
57932
57933cat >dancer.y <<'_ATEOF'
57934%{
57935#ifdef HAVE_CONFIG_H
57936# include <config.h>
57937  /* We don't need perfect functions for these tests. */
57938# undef malloc
57939# undef memcmp
57940# undef realloc
57941#endif
57942%}
57943
57944%{
57945static int yylex (void);
57946#include <stdio.h>
57947static void yyerror (const char *);
57948%}
57949
57950%token ARROW INVALID NUMBER STRING DATA
57951%defines
57952%verbose
57953%error-verbose
57954/* Grammar follows */
57955%%
57956line: header body
57957   ;
57958
57959header: '<' from ARROW to '>' type ':'
57960   | '<' ARROW to '>' type ':'
57961   | ARROW to type ':'
57962   | type ':'
57963   | '<' '>'
57964   ;
57965
57966from: DATA
57967   | STRING
57968   | INVALID
57969   ;
57970
57971to: DATA
57972   | STRING
57973   | INVALID
57974   ;
57975
57976type: DATA
57977   | STRING
57978   | INVALID
57979   ;
57980
57981body: /* empty */
57982   | body member
57983   ;
57984
57985member: STRING
57986   | DATA
57987   | '+' NUMBER
57988   | '-' NUMBER
57989   | NUMBER
57990   | INVALID
57991   ;
57992%%
57993static void
57994yyerror (const char *s)
57995{
57996  fprintf (stderr, "%s\n", s);
57997}
57998
57999static int
58000yylex (void)
58001{
58002  static int toknum = 0;
58003  static int tokens[] =
58004    {
58005      ':', -1
58006    };
58007
58008  return tokens[toknum++];
58009}
58010
58011int
58012main (void)
58013{
58014  return yyparse ();
58015}
58016_ATEOF
58017
58018
58019
58020$at_traceoff
58021echo "regression.at:866: bison -o dancer.c dancer.y"
58022echo regression.at:866 >$at_check_line_file
58023( $at_traceon; bison -o dancer.c dancer.y ) >$at_stdout 2>$at_stder1
58024at_status=$?
58025grep '^ *+' $at_stder1 >&2
58026grep -v '^ *+' $at_stder1 >$at_stderr
58027at_failed=false
58028$at_diff $at_devnull $at_stderr || at_failed=:
58029$at_diff $at_devnull $at_stdout || at_failed=:
58030case $at_status in
58031   77) echo 77 > $at_status_file
58032            exit 77;;
58033   0) ;;
58034   *) echo "regression.at:866: exit code was $at_status, expected 0"
58035      at_failed=:;;
58036esac
58037if $at_failed; then
58038
58039  echo 1 > $at_status_file
58040  exit 1
58041fi
58042
58043$at_traceon
58044
58045$at_traceoff
58046echo "regression.at:866: bison -o dancer.c dancer.y"
58047echo regression.at:866 >$at_check_line_file
58048( $at_traceon; bison -o dancer.c dancer.y ) >$at_stdout 2>$at_stder1
58049at_status=$?
58050grep '^ *+' $at_stder1 >&2
58051grep -v '^ *+' $at_stder1 >$at_stderr
58052at_failed=false
58053$at_diff $at_devnull $at_stderr || at_failed=:
58054$at_diff $at_devnull $at_stdout || at_failed=:
58055case $at_status in
58056   77) echo 77 > $at_status_file
58057            exit 77;;
58058   0) ;;
58059   *) echo "regression.at:866: exit code was $at_status, expected 0"
58060      at_failed=:;;
58061esac
58062if $at_failed; then
58063
58064  echo 1 > $at_status_file
58065  exit 1
58066fi
58067
58068$at_traceon
58069
58070   $at_traceoff
58071echo "regression.at:866: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o dancer dancer.c \$LIBS"
58072echo regression.at:866 >$at_check_line_file
58073( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o dancer dancer.c $LIBS ) >$at_stdout 2>$at_stder1
58074at_status=$?
58075grep '^ *+' $at_stder1 >&2
58076grep -v '^ *+' $at_stder1 >$at_stderr
58077at_failed=false
58078echo stderr:; cat $at_stderr
58079echo stdout:; cat $at_stdout
58080case $at_status in
58081   77) echo 77 > $at_status_file
58082            exit 77;;
58083   0) ;;
58084   *) echo "regression.at:866: exit code was $at_status, expected 0"
58085      at_failed=:;;
58086esac
58087if $at_failed; then
58088
58089  echo 1 > $at_status_file
58090  exit 1
58091fi
58092
58093$at_traceon
58094
58095$at_traceoff
58096echo "regression.at:866: \$PREPARSER ./dancer"
58097echo regression.at:866 >$at_check_line_file
58098( $at_traceon; $PREPARSER ./dancer ) >$at_stdout 2>$at_stder1
58099at_status=$?
58100grep '^ *+' $at_stder1 >&2
58101grep -v '^ *+' $at_stder1 >$at_stderr
58102at_failed=false
58103echo >>$at_stderr; echo "syntax error, unexpected ':'
58104" | $at_diff - $at_stderr || at_failed=:
58105$at_diff $at_devnull $at_stdout || at_failed=:
58106case $at_status in
58107   77) echo 77 > $at_status_file
58108            exit 77;;
58109   1) ;;
58110   *) echo "regression.at:866: exit code was $at_status, expected 1"
58111      at_failed=:;;
58112esac
58113if $at_failed; then
58114
58115  echo 1 > $at_status_file
58116  exit 1
58117fi
58118
58119$at_traceon
58120
58121
58122
58123
58124
58125
58126
58127
58128
58129
58130
58131
58132
58133
58134
58135
58136
58137
58138
58139
58140
58141
58142      $at_traceoff
58143      $at_times_p && times >$at_times_file
58144    ) 5>&1 2>&1 | eval $at_tee_pipe
58145    at_status=`cat $at_status_file`
58146    ;;
58147
58148  126 ) # 126. regression.at:867: Dancer %glr-parser
58149    at_setup_line='regression.at:867'
58150    at_desc='Dancer %glr-parser'
58151    $at_quiet $ECHO_N "126: Dancer %glr-parser                           $ECHO_C"
58152    at_xfail=no
58153    (
58154      echo "126. regression.at:867: testing ..."
58155      $at_traceon
58156
58157
58158
58159
58160
58161# Using yacc.c?
58162
58163
58164
58165
58166
58167
58168
58169# yyerror receives the location if %location & %pure & (%glr or %parse-param).
58170
58171# yyerror always sees the locations (when activated), except if
58172# yacc & pure & !param.
58173
58174
58175# The interface is pure: either because %pure-parser, or because we
58176# are using the C++ parsers.
58177
58178
58179
58180
58181
58182
58183
58184
58185
58186
58187
58188cat >dancer.y <<'_ATEOF'
58189%{
58190#ifdef HAVE_CONFIG_H
58191# include <config.h>
58192  /* We don't need perfect functions for these tests. */
58193# undef malloc
58194# undef memcmp
58195# undef realloc
58196#endif
58197%}
58198
58199%{
58200static int yylex (void);
58201#include <stdio.h>
58202static void yyerror (const char *);
58203%}
58204%glr-parser
58205%token ARROW INVALID NUMBER STRING DATA
58206%defines
58207%verbose
58208%error-verbose
58209/* Grammar follows */
58210%%
58211line: header body
58212   ;
58213
58214header: '<' from ARROW to '>' type ':'
58215   | '<' ARROW to '>' type ':'
58216   | ARROW to type ':'
58217   | type ':'
58218   | '<' '>'
58219   ;
58220
58221from: DATA
58222   | STRING
58223   | INVALID
58224   ;
58225
58226to: DATA
58227   | STRING
58228   | INVALID
58229   ;
58230
58231type: DATA
58232   | STRING
58233   | INVALID
58234   ;
58235
58236body: /* empty */
58237   | body member
58238   ;
58239
58240member: STRING
58241   | DATA
58242   | '+' NUMBER
58243   | '-' NUMBER
58244   | NUMBER
58245   | INVALID
58246   ;
58247%%
58248static void
58249yyerror (const char *s)
58250{
58251  fprintf (stderr, "%s\n", s);
58252}
58253
58254static int
58255yylex (void)
58256{
58257  static int toknum = 0;
58258  static int tokens[] =
58259    {
58260      ':', -1
58261    };
58262
58263  return tokens[toknum++];
58264}
58265
58266int
58267main (void)
58268{
58269  return yyparse ();
58270}
58271_ATEOF
58272
58273
58274
58275$at_traceoff
58276echo "regression.at:867: bison -o dancer.c dancer.y"
58277echo regression.at:867 >$at_check_line_file
58278( $at_traceon; bison -o dancer.c dancer.y ) >$at_stdout 2>$at_stder1
58279at_status=$?
58280grep '^ *+' $at_stder1 >&2
58281grep -v '^ *+' $at_stder1 >$at_stderr
58282at_failed=false
58283$at_diff $at_devnull $at_stderr || at_failed=:
58284$at_diff $at_devnull $at_stdout || at_failed=:
58285case $at_status in
58286   77) echo 77 > $at_status_file
58287            exit 77;;
58288   0) ;;
58289   *) echo "regression.at:867: exit code was $at_status, expected 0"
58290      at_failed=:;;
58291esac
58292if $at_failed; then
58293
58294  echo 1 > $at_status_file
58295  exit 1
58296fi
58297
58298$at_traceon
58299
58300$at_traceoff
58301echo "regression.at:867: bison -o dancer.c dancer.y"
58302echo regression.at:867 >$at_check_line_file
58303( $at_traceon; bison -o dancer.c dancer.y ) >$at_stdout 2>$at_stder1
58304at_status=$?
58305grep '^ *+' $at_stder1 >&2
58306grep -v '^ *+' $at_stder1 >$at_stderr
58307at_failed=false
58308$at_diff $at_devnull $at_stderr || at_failed=:
58309$at_diff $at_devnull $at_stdout || at_failed=:
58310case $at_status in
58311   77) echo 77 > $at_status_file
58312            exit 77;;
58313   0) ;;
58314   *) echo "regression.at:867: exit code was $at_status, expected 0"
58315      at_failed=:;;
58316esac
58317if $at_failed; then
58318
58319  echo 1 > $at_status_file
58320  exit 1
58321fi
58322
58323$at_traceon
58324
58325   $at_traceoff
58326echo "regression.at:867: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o dancer dancer.c \$LIBS"
58327echo regression.at:867 >$at_check_line_file
58328( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o dancer dancer.c $LIBS ) >$at_stdout 2>$at_stder1
58329at_status=$?
58330grep '^ *+' $at_stder1 >&2
58331grep -v '^ *+' $at_stder1 >$at_stderr
58332at_failed=false
58333echo stderr:; cat $at_stderr
58334echo stdout:; cat $at_stdout
58335case $at_status in
58336   77) echo 77 > $at_status_file
58337            exit 77;;
58338   0) ;;
58339   *) echo "regression.at:867: exit code was $at_status, expected 0"
58340      at_failed=:;;
58341esac
58342if $at_failed; then
58343
58344  echo 1 > $at_status_file
58345  exit 1
58346fi
58347
58348$at_traceon
58349
58350$at_traceoff
58351echo "regression.at:867: \$PREPARSER ./dancer"
58352echo regression.at:867 >$at_check_line_file
58353( $at_traceon; $PREPARSER ./dancer ) >$at_stdout 2>$at_stder1
58354at_status=$?
58355grep '^ *+' $at_stder1 >&2
58356grep -v '^ *+' $at_stder1 >$at_stderr
58357at_failed=false
58358echo >>$at_stderr; echo "syntax error, unexpected ':'
58359" | $at_diff - $at_stderr || at_failed=:
58360$at_diff $at_devnull $at_stdout || at_failed=:
58361case $at_status in
58362   77) echo 77 > $at_status_file
58363            exit 77;;
58364   1) ;;
58365   *) echo "regression.at:867: exit code was $at_status, expected 1"
58366      at_failed=:;;
58367esac
58368if $at_failed; then
58369
58370  echo 1 > $at_status_file
58371  exit 1
58372fi
58373
58374$at_traceon
58375
58376
58377
58378
58379
58380
58381
58382
58383
58384
58385
58386
58387
58388
58389
58390
58391
58392
58393
58394
58395
58396
58397      $at_traceoff
58398      $at_times_p && times >$at_times_file
58399    ) 5>&1 2>&1 | eval $at_tee_pipe
58400    at_status=`cat $at_status_file`
58401    ;;
58402
58403  127 ) # 127. regression.at:868: Dancer %skeleton "lalr1.cc"
58404    at_setup_line='regression.at:868'
58405    at_desc='Dancer %skeleton "lalr1.cc"'
58406    $at_quiet $ECHO_N "127: Dancer %skeleton "lalr1.cc"                  $ECHO_C"
58407    at_xfail=no
58408    (
58409      echo "127. regression.at:868: testing ..."
58410      $at_traceon
58411
58412
58413
58414
58415
58416# Using yacc.c?
58417
58418
58419
58420
58421
58422
58423
58424# yyerror receives the location if %location & %pure & (%glr or %parse-param).
58425
58426# yyerror always sees the locations (when activated), except if
58427# yacc & pure & !param.
58428
58429
58430# The interface is pure: either because %pure-parser, or because we
58431# are using the C++ parsers.
58432
58433
58434
58435
58436
58437
58438
58439
58440
58441
58442
58443cat >dancer.y <<'_ATEOF'
58444%{
58445#ifdef HAVE_CONFIG_H
58446# include <config.h>
58447  /* We don't need perfect functions for these tests. */
58448# undef malloc
58449# undef memcmp
58450# undef realloc
58451#endif
58452%}
58453
58454%{
58455static int yylex (int *);
58456
58457%}
58458%skeleton "lalr1.cc"
58459%token ARROW INVALID NUMBER STRING DATA
58460%defines
58461%verbose
58462%error-verbose
58463/* Grammar follows */
58464%%
58465line: header body
58466   ;
58467
58468header: '<' from ARROW to '>' type ':'
58469   | '<' ARROW to '>' type ':'
58470   | ARROW to type ':'
58471   | type ':'
58472   | '<' '>'
58473   ;
58474
58475from: DATA
58476   | STRING
58477   | INVALID
58478   ;
58479
58480to: DATA
58481   | STRING
58482   | INVALID
58483   ;
58484
58485type: DATA
58486   | STRING
58487   | INVALID
58488   ;
58489
58490body: /* empty */
58491   | body member
58492   ;
58493
58494member: STRING
58495   | DATA
58496   | '+' NUMBER
58497   | '-' NUMBER
58498   | NUMBER
58499   | INVALID
58500   ;
58501%%
58502/* A C++ error reporting function. */
58503void
58504yy::parser::error (const location&, const std::string& m)
58505{
58506  std::cerr << m << std::endl;
58507}
58508
58509int
58510yyparse ()
58511{
58512  yy::parser parser;
58513  parser.set_debug_level (!!YYDEBUG);
58514  return parser.parse ();
58515}
58516
58517
58518static int
58519yylex (int *lval)
58520{
58521  static int toknum = 0;
58522  static int tokens[] =
58523    {
58524      ':', -1
58525    };
58526  *lval = 0; /* Pacify GCC.  */
58527  return tokens[toknum++];
58528}
58529
58530int
58531main (void)
58532{
58533  return yyparse ();
58534}
58535_ATEOF
58536
58537
58538
58539$at_traceoff
58540echo "regression.at:868: bison -o dancer.c dancer.y"
58541echo regression.at:868 >$at_check_line_file
58542( $at_traceon; bison -o dancer.c dancer.y ) >$at_stdout 2>$at_stder1
58543at_status=$?
58544grep '^ *+' $at_stder1 >&2
58545grep -v '^ *+' $at_stder1 >$at_stderr
58546at_failed=false
58547$at_diff $at_devnull $at_stderr || at_failed=:
58548$at_diff $at_devnull $at_stdout || at_failed=:
58549case $at_status in
58550   77) echo 77 > $at_status_file
58551            exit 77;;
58552   0) ;;
58553   *) echo "regression.at:868: exit code was $at_status, expected 0"
58554      at_failed=:;;
58555esac
58556if $at_failed; then
58557
58558  echo 1 > $at_status_file
58559  exit 1
58560fi
58561
58562$at_traceon
58563
58564$at_traceoff
58565echo "regression.at:868: bison -o dancer.cc dancer.y"
58566echo regression.at:868 >$at_check_line_file
58567( $at_traceon; bison -o dancer.cc dancer.y ) >$at_stdout 2>$at_stder1
58568at_status=$?
58569grep '^ *+' $at_stder1 >&2
58570grep -v '^ *+' $at_stder1 >$at_stderr
58571at_failed=false
58572$at_diff $at_devnull $at_stderr || at_failed=:
58573$at_diff $at_devnull $at_stdout || at_failed=:
58574case $at_status in
58575   77) echo 77 > $at_status_file
58576            exit 77;;
58577   0) ;;
58578   *) echo "regression.at:868: exit code was $at_status, expected 0"
58579      at_failed=:;;
58580esac
58581if $at_failed; then
58582
58583  echo 1 > $at_status_file
58584  exit 1
58585fi
58586
58587$at_traceon
58588
58589
58590$at_traceoff
58591echo "regression.at:868: \$BISON_CXX_WORKS"
58592echo regression.at:868 >$at_check_line_file
58593( $at_traceon; $BISON_CXX_WORKS ) >$at_stdout 2>$at_stder1
58594at_status=$?
58595grep '^ *+' $at_stder1 >&2
58596grep -v '^ *+' $at_stder1 >$at_stderr
58597at_failed=false
58598echo stderr:; cat $at_stderr
58599echo stdout:; cat $at_stdout
58600case $at_status in
58601   77) echo 77 > $at_status_file
58602            exit 77;;
58603   0) ;;
58604   *) echo "regression.at:868: exit code was $at_status, expected 0"
58605      at_failed=:;;
58606esac
58607if $at_failed; then
58608
58609  echo 1 > $at_status_file
58610  exit 1
58611fi
58612
58613$at_traceon
58614
58615$at_traceoff
58616echo "regression.at:868: \$CXX \$CXXFLAGS \$CPPFLAGS \$LDFLAGS -o dancer dancer.cc \$LIBS"
58617echo regression.at:868 >$at_check_line_file
58618( $at_traceon; $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o dancer dancer.cc $LIBS ) >$at_stdout 2>$at_stder1
58619at_status=$?
58620grep '^ *+' $at_stder1 >&2
58621grep -v '^ *+' $at_stder1 >$at_stderr
58622at_failed=false
58623echo stderr:; cat $at_stderr
58624echo stdout:; cat $at_stdout
58625case $at_status in
58626   77) echo 77 > $at_status_file
58627            exit 77;;
58628   0) ;;
58629   *) echo "regression.at:868: exit code was $at_status, expected 0"
58630      at_failed=:;;
58631esac
58632if $at_failed; then
58633
58634  echo 1 > $at_status_file
58635  exit 1
58636fi
58637
58638$at_traceon
58639
58640$at_traceoff
58641echo "regression.at:868: \$PREPARSER ./dancer"
58642echo regression.at:868 >$at_check_line_file
58643( $at_traceon; $PREPARSER ./dancer ) >$at_stdout 2>$at_stder1
58644at_status=$?
58645grep '^ *+' $at_stder1 >&2
58646grep -v '^ *+' $at_stder1 >$at_stderr
58647at_failed=false
58648echo >>$at_stderr; echo "syntax error, unexpected ':'
58649" | $at_diff - $at_stderr || at_failed=:
58650$at_diff $at_devnull $at_stdout || at_failed=:
58651case $at_status in
58652   77) echo 77 > $at_status_file
58653            exit 77;;
58654   1) ;;
58655   *) echo "regression.at:868: exit code was $at_status, expected 1"
58656      at_failed=:;;
58657esac
58658if $at_failed; then
58659
58660  echo 1 > $at_status_file
58661  exit 1
58662fi
58663
58664$at_traceon
58665
58666
58667
58668
58669
58670
58671
58672
58673
58674
58675
58676
58677
58678
58679
58680
58681
58682
58683
58684
58685
58686
58687      $at_traceoff
58688      $at_times_p && times >$at_times_file
58689    ) 5>&1 2>&1 | eval $at_tee_pipe
58690    at_status=`cat $at_status_file`
58691    ;;
58692
58693  128 ) # 128. regression.at:963: Expecting two tokens
58694    at_setup_line='regression.at:963'
58695    at_desc='Expecting two tokens '
58696    $at_quiet $ECHO_N "128: Expecting two tokens                         $ECHO_C"
58697    at_xfail=no
58698    (
58699      echo "128. regression.at:963: testing ..."
58700      $at_traceon
58701
58702
58703
58704
58705
58706# Using yacc.c?
58707
58708
58709
58710
58711
58712
58713
58714# yyerror receives the location if %location & %pure & (%glr or %parse-param).
58715
58716# yyerror always sees the locations (when activated), except if
58717# yacc & pure & !param.
58718
58719
58720# The interface is pure: either because %pure-parser, or because we
58721# are using the C++ parsers.
58722
58723
58724
58725
58726
58727
58728
58729
58730
58731
58732
58733cat >expect2.y <<'_ATEOF'
58734%{
58735#ifdef HAVE_CONFIG_H
58736# include <config.h>
58737  /* We don't need perfect functions for these tests. */
58738# undef malloc
58739# undef memcmp
58740# undef realloc
58741#endif
58742%}
58743
58744%{
58745static int yylex (void);
58746#include <stdio.h>
58747static void yyerror (const char *);
58748%}
58749
58750%defines
58751%error-verbose
58752%token A 1000
58753%token B
58754
58755%%
58756program: /* empty */
58757 | program e ';'
58758 | program error ';';
58759
58760e: e '+' t | t;
58761t: A | B;
58762
58763%%
58764static void
58765yyerror (const char *s)
58766{
58767  fprintf (stderr, "%s\n", s);
58768}
58769
58770static int
58771yylex (void)
58772{
58773  static int toknum = 0;
58774  static int tokens[] =
58775    {
58776      1000, '+', '+', -1
58777    };
58778
58779  return tokens[toknum++];
58780}
58781
58782int
58783main (void)
58784{
58785  return yyparse ();
58786}
58787_ATEOF
58788
58789
58790
58791$at_traceoff
58792echo "regression.at:963: bison -o expect2.c expect2.y"
58793echo regression.at:963 >$at_check_line_file
58794( $at_traceon; bison -o expect2.c expect2.y ) >$at_stdout 2>$at_stder1
58795at_status=$?
58796grep '^ *+' $at_stder1 >&2
58797grep -v '^ *+' $at_stder1 >$at_stderr
58798at_failed=false
58799$at_diff $at_devnull $at_stderr || at_failed=:
58800$at_diff $at_devnull $at_stdout || at_failed=:
58801case $at_status in
58802   77) echo 77 > $at_status_file
58803            exit 77;;
58804   0) ;;
58805   *) echo "regression.at:963: exit code was $at_status, expected 0"
58806      at_failed=:;;
58807esac
58808if $at_failed; then
58809
58810  echo 1 > $at_status_file
58811  exit 1
58812fi
58813
58814$at_traceon
58815
58816$at_traceoff
58817echo "regression.at:963: bison -o expect2.c expect2.y"
58818echo regression.at:963 >$at_check_line_file
58819( $at_traceon; bison -o expect2.c expect2.y ) >$at_stdout 2>$at_stder1
58820at_status=$?
58821grep '^ *+' $at_stder1 >&2
58822grep -v '^ *+' $at_stder1 >$at_stderr
58823at_failed=false
58824$at_diff $at_devnull $at_stderr || at_failed=:
58825$at_diff $at_devnull $at_stdout || at_failed=:
58826case $at_status in
58827   77) echo 77 > $at_status_file
58828            exit 77;;
58829   0) ;;
58830   *) echo "regression.at:963: exit code was $at_status, expected 0"
58831      at_failed=:;;
58832esac
58833if $at_failed; then
58834
58835  echo 1 > $at_status_file
58836  exit 1
58837fi
58838
58839$at_traceon
58840
58841   $at_traceoff
58842echo "regression.at:963: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o expect2 expect2.c \$LIBS"
58843echo regression.at:963 >$at_check_line_file
58844( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o expect2 expect2.c $LIBS ) >$at_stdout 2>$at_stder1
58845at_status=$?
58846grep '^ *+' $at_stder1 >&2
58847grep -v '^ *+' $at_stder1 >$at_stderr
58848at_failed=false
58849echo stderr:; cat $at_stderr
58850echo stdout:; cat $at_stdout
58851case $at_status in
58852   77) echo 77 > $at_status_file
58853            exit 77;;
58854   0) ;;
58855   *) echo "regression.at:963: exit code was $at_status, expected 0"
58856      at_failed=:;;
58857esac
58858if $at_failed; then
58859
58860  echo 1 > $at_status_file
58861  exit 1
58862fi
58863
58864$at_traceon
58865
58866$at_traceoff
58867echo "regression.at:963: \$PREPARSER ./expect2"
58868echo regression.at:963 >$at_check_line_file
58869( $at_traceon; $PREPARSER ./expect2 ) >$at_stdout 2>$at_stder1
58870at_status=$?
58871grep '^ *+' $at_stder1 >&2
58872grep -v '^ *+' $at_stder1 >$at_stderr
58873at_failed=false
58874echo >>$at_stderr; echo "syntax error, unexpected '+', expecting A or B
58875" | $at_diff - $at_stderr || at_failed=:
58876$at_diff $at_devnull $at_stdout || at_failed=:
58877case $at_status in
58878   77) echo 77 > $at_status_file
58879            exit 77;;
58880   1) ;;
58881   *) echo "regression.at:963: exit code was $at_status, expected 1"
58882      at_failed=:;;
58883esac
58884if $at_failed; then
58885
58886  echo 1 > $at_status_file
58887  exit 1
58888fi
58889
58890$at_traceon
58891
58892
58893
58894
58895
58896
58897
58898
58899
58900
58901
58902
58903
58904
58905
58906
58907
58908
58909
58910
58911
58912
58913      $at_traceoff
58914      $at_times_p && times >$at_times_file
58915    ) 5>&1 2>&1 | eval $at_tee_pipe
58916    at_status=`cat $at_status_file`
58917    ;;
58918
58919  129 ) # 129. regression.at:964: Expecting two tokens %glr-parser
58920    at_setup_line='regression.at:964'
58921    at_desc='Expecting two tokens %glr-parser'
58922    $at_quiet $ECHO_N "129: Expecting two tokens %glr-parser             $ECHO_C"
58923    at_xfail=no
58924    (
58925      echo "129. regression.at:964: testing ..."
58926      $at_traceon
58927
58928
58929
58930
58931
58932# Using yacc.c?
58933
58934
58935
58936
58937
58938
58939
58940# yyerror receives the location if %location & %pure & (%glr or %parse-param).
58941
58942# yyerror always sees the locations (when activated), except if
58943# yacc & pure & !param.
58944
58945
58946# The interface is pure: either because %pure-parser, or because we
58947# are using the C++ parsers.
58948
58949
58950
58951
58952
58953
58954
58955
58956
58957
58958
58959cat >expect2.y <<'_ATEOF'
58960%{
58961#ifdef HAVE_CONFIG_H
58962# include <config.h>
58963  /* We don't need perfect functions for these tests. */
58964# undef malloc
58965# undef memcmp
58966# undef realloc
58967#endif
58968%}
58969
58970%{
58971static int yylex (void);
58972#include <stdio.h>
58973static void yyerror (const char *);
58974%}
58975%glr-parser
58976%defines
58977%error-verbose
58978%token A 1000
58979%token B
58980
58981%%
58982program: /* empty */
58983 | program e ';'
58984 | program error ';';
58985
58986e: e '+' t | t;
58987t: A | B;
58988
58989%%
58990static void
58991yyerror (const char *s)
58992{
58993  fprintf (stderr, "%s\n", s);
58994}
58995
58996static int
58997yylex (void)
58998{
58999  static int toknum = 0;
59000  static int tokens[] =
59001    {
59002      1000, '+', '+', -1
59003    };
59004
59005  return tokens[toknum++];
59006}
59007
59008int
59009main (void)
59010{
59011  return yyparse ();
59012}
59013_ATEOF
59014
59015
59016
59017$at_traceoff
59018echo "regression.at:964: bison -o expect2.c expect2.y"
59019echo regression.at:964 >$at_check_line_file
59020( $at_traceon; bison -o expect2.c expect2.y ) >$at_stdout 2>$at_stder1
59021at_status=$?
59022grep '^ *+' $at_stder1 >&2
59023grep -v '^ *+' $at_stder1 >$at_stderr
59024at_failed=false
59025$at_diff $at_devnull $at_stderr || at_failed=:
59026$at_diff $at_devnull $at_stdout || at_failed=:
59027case $at_status in
59028   77) echo 77 > $at_status_file
59029            exit 77;;
59030   0) ;;
59031   *) echo "regression.at:964: exit code was $at_status, expected 0"
59032      at_failed=:;;
59033esac
59034if $at_failed; then
59035
59036  echo 1 > $at_status_file
59037  exit 1
59038fi
59039
59040$at_traceon
59041
59042$at_traceoff
59043echo "regression.at:964: bison -o expect2.c expect2.y"
59044echo regression.at:964 >$at_check_line_file
59045( $at_traceon; bison -o expect2.c expect2.y ) >$at_stdout 2>$at_stder1
59046at_status=$?
59047grep '^ *+' $at_stder1 >&2
59048grep -v '^ *+' $at_stder1 >$at_stderr
59049at_failed=false
59050$at_diff $at_devnull $at_stderr || at_failed=:
59051$at_diff $at_devnull $at_stdout || at_failed=:
59052case $at_status in
59053   77) echo 77 > $at_status_file
59054            exit 77;;
59055   0) ;;
59056   *) echo "regression.at:964: exit code was $at_status, expected 0"
59057      at_failed=:;;
59058esac
59059if $at_failed; then
59060
59061  echo 1 > $at_status_file
59062  exit 1
59063fi
59064
59065$at_traceon
59066
59067   $at_traceoff
59068echo "regression.at:964: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o expect2 expect2.c \$LIBS"
59069echo regression.at:964 >$at_check_line_file
59070( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o expect2 expect2.c $LIBS ) >$at_stdout 2>$at_stder1
59071at_status=$?
59072grep '^ *+' $at_stder1 >&2
59073grep -v '^ *+' $at_stder1 >$at_stderr
59074at_failed=false
59075echo stderr:; cat $at_stderr
59076echo stdout:; cat $at_stdout
59077case $at_status in
59078   77) echo 77 > $at_status_file
59079            exit 77;;
59080   0) ;;
59081   *) echo "regression.at:964: exit code was $at_status, expected 0"
59082      at_failed=:;;
59083esac
59084if $at_failed; then
59085
59086  echo 1 > $at_status_file
59087  exit 1
59088fi
59089
59090$at_traceon
59091
59092$at_traceoff
59093echo "regression.at:964: \$PREPARSER ./expect2"
59094echo regression.at:964 >$at_check_line_file
59095( $at_traceon; $PREPARSER ./expect2 ) >$at_stdout 2>$at_stder1
59096at_status=$?
59097grep '^ *+' $at_stder1 >&2
59098grep -v '^ *+' $at_stder1 >$at_stderr
59099at_failed=false
59100echo >>$at_stderr; echo "syntax error, unexpected '+', expecting A or B
59101" | $at_diff - $at_stderr || at_failed=:
59102$at_diff $at_devnull $at_stdout || at_failed=:
59103case $at_status in
59104   77) echo 77 > $at_status_file
59105            exit 77;;
59106   1) ;;
59107   *) echo "regression.at:964: exit code was $at_status, expected 1"
59108      at_failed=:;;
59109esac
59110if $at_failed; then
59111
59112  echo 1 > $at_status_file
59113  exit 1
59114fi
59115
59116$at_traceon
59117
59118
59119
59120
59121
59122
59123
59124
59125
59126
59127
59128
59129
59130
59131
59132
59133
59134
59135
59136
59137
59138
59139      $at_traceoff
59140      $at_times_p && times >$at_times_file
59141    ) 5>&1 2>&1 | eval $at_tee_pipe
59142    at_status=`cat $at_status_file`
59143    ;;
59144
59145  130 ) # 130. regression.at:965: Expecting two tokens %skeleton "lalr1.cc"
59146    at_setup_line='regression.at:965'
59147    at_desc='Expecting two tokens %skeleton "lalr1.cc"'
59148    $at_quiet $ECHO_N "130: Expecting two tokens %skeleton "lalr1.cc"    $ECHO_C"
59149    at_xfail=no
59150    (
59151      echo "130. regression.at:965: testing ..."
59152      $at_traceon
59153
59154
59155
59156
59157
59158# Using yacc.c?
59159
59160
59161
59162
59163
59164
59165
59166# yyerror receives the location if %location & %pure & (%glr or %parse-param).
59167
59168# yyerror always sees the locations (when activated), except if
59169# yacc & pure & !param.
59170
59171
59172# The interface is pure: either because %pure-parser, or because we
59173# are using the C++ parsers.
59174
59175
59176
59177
59178
59179
59180
59181
59182
59183
59184
59185cat >expect2.y <<'_ATEOF'
59186%{
59187#ifdef HAVE_CONFIG_H
59188# include <config.h>
59189  /* We don't need perfect functions for these tests. */
59190# undef malloc
59191# undef memcmp
59192# undef realloc
59193#endif
59194%}
59195
59196%{
59197static int yylex (int *);
59198
59199%}
59200%skeleton "lalr1.cc"
59201%defines
59202%error-verbose
59203%token A 1000
59204%token B
59205
59206%%
59207program: /* empty */
59208 | program e ';'
59209 | program error ';';
59210
59211e: e '+' t | t;
59212t: A | B;
59213
59214%%
59215/* A C++ error reporting function. */
59216void
59217yy::parser::error (const location&, const std::string& m)
59218{
59219  std::cerr << m << std::endl;
59220}
59221
59222int
59223yyparse ()
59224{
59225  yy::parser parser;
59226  return parser.parse ();
59227}
59228
59229
59230static int
59231yylex (int *lval)
59232{
59233  static int toknum = 0;
59234  static int tokens[] =
59235    {
59236      1000, '+', '+', -1
59237    };
59238  *lval = 0; /* Pacify GCC.  */
59239  return tokens[toknum++];
59240}
59241
59242int
59243main (void)
59244{
59245  return yyparse ();
59246}
59247_ATEOF
59248
59249
59250
59251$at_traceoff
59252echo "regression.at:965: bison -o expect2.c expect2.y"
59253echo regression.at:965 >$at_check_line_file
59254( $at_traceon; bison -o expect2.c expect2.y ) >$at_stdout 2>$at_stder1
59255at_status=$?
59256grep '^ *+' $at_stder1 >&2
59257grep -v '^ *+' $at_stder1 >$at_stderr
59258at_failed=false
59259$at_diff $at_devnull $at_stderr || at_failed=:
59260$at_diff $at_devnull $at_stdout || at_failed=:
59261case $at_status in
59262   77) echo 77 > $at_status_file
59263            exit 77;;
59264   0) ;;
59265   *) echo "regression.at:965: exit code was $at_status, expected 0"
59266      at_failed=:;;
59267esac
59268if $at_failed; then
59269
59270  echo 1 > $at_status_file
59271  exit 1
59272fi
59273
59274$at_traceon
59275
59276$at_traceoff
59277echo "regression.at:965: bison -o expect2.cc expect2.y"
59278echo regression.at:965 >$at_check_line_file
59279( $at_traceon; bison -o expect2.cc expect2.y ) >$at_stdout 2>$at_stder1
59280at_status=$?
59281grep '^ *+' $at_stder1 >&2
59282grep -v '^ *+' $at_stder1 >$at_stderr
59283at_failed=false
59284$at_diff $at_devnull $at_stderr || at_failed=:
59285$at_diff $at_devnull $at_stdout || at_failed=:
59286case $at_status in
59287   77) echo 77 > $at_status_file
59288            exit 77;;
59289   0) ;;
59290   *) echo "regression.at:965: exit code was $at_status, expected 0"
59291      at_failed=:;;
59292esac
59293if $at_failed; then
59294
59295  echo 1 > $at_status_file
59296  exit 1
59297fi
59298
59299$at_traceon
59300
59301
59302$at_traceoff
59303echo "regression.at:965: \$BISON_CXX_WORKS"
59304echo regression.at:965 >$at_check_line_file
59305( $at_traceon; $BISON_CXX_WORKS ) >$at_stdout 2>$at_stder1
59306at_status=$?
59307grep '^ *+' $at_stder1 >&2
59308grep -v '^ *+' $at_stder1 >$at_stderr
59309at_failed=false
59310echo stderr:; cat $at_stderr
59311echo stdout:; cat $at_stdout
59312case $at_status in
59313   77) echo 77 > $at_status_file
59314            exit 77;;
59315   0) ;;
59316   *) echo "regression.at:965: exit code was $at_status, expected 0"
59317      at_failed=:;;
59318esac
59319if $at_failed; then
59320
59321  echo 1 > $at_status_file
59322  exit 1
59323fi
59324
59325$at_traceon
59326
59327$at_traceoff
59328echo "regression.at:965: \$CXX \$CXXFLAGS \$CPPFLAGS \$LDFLAGS -o expect2 expect2.cc \$LIBS"
59329echo regression.at:965 >$at_check_line_file
59330( $at_traceon; $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o expect2 expect2.cc $LIBS ) >$at_stdout 2>$at_stder1
59331at_status=$?
59332grep '^ *+' $at_stder1 >&2
59333grep -v '^ *+' $at_stder1 >$at_stderr
59334at_failed=false
59335echo stderr:; cat $at_stderr
59336echo stdout:; cat $at_stdout
59337case $at_status in
59338   77) echo 77 > $at_status_file
59339            exit 77;;
59340   0) ;;
59341   *) echo "regression.at:965: exit code was $at_status, expected 0"
59342      at_failed=:;;
59343esac
59344if $at_failed; then
59345
59346  echo 1 > $at_status_file
59347  exit 1
59348fi
59349
59350$at_traceon
59351
59352$at_traceoff
59353echo "regression.at:965: \$PREPARSER ./expect2"
59354echo regression.at:965 >$at_check_line_file
59355( $at_traceon; $PREPARSER ./expect2 ) >$at_stdout 2>$at_stder1
59356at_status=$?
59357grep '^ *+' $at_stder1 >&2
59358grep -v '^ *+' $at_stder1 >$at_stderr
59359at_failed=false
59360echo >>$at_stderr; echo "syntax error, unexpected '+', expecting A or B
59361" | $at_diff - $at_stderr || at_failed=:
59362$at_diff $at_devnull $at_stdout || at_failed=:
59363case $at_status in
59364   77) echo 77 > $at_status_file
59365            exit 77;;
59366   1) ;;
59367   *) echo "regression.at:965: exit code was $at_status, expected 1"
59368      at_failed=:;;
59369esac
59370if $at_failed; then
59371
59372  echo 1 > $at_status_file
59373  exit 1
59374fi
59375
59376$at_traceon
59377
59378
59379
59380
59381
59382
59383
59384
59385
59386
59387
59388
59389
59390
59391
59392
59393
59394
59395
59396
59397
59398
59399      $at_traceoff
59400      $at_times_p && times >$at_times_file
59401    ) 5>&1 2>&1 | eval $at_tee_pipe
59402    at_status=`cat $at_status_file`
59403    ;;
59404
59405
59406  banner-16 ) # Banner 16. c++.at:19
59407    cat <<\_ATEOF
59408
59409C++ Features.
59410
59411_ATEOF
59412    ;;
59413
59414  131 ) # 131. c++.at:102: Doxygen Public Documentation
59415    at_setup_line='c++.at:102'
59416    at_desc='Doxygen Public Documentation'
59417    $at_quiet $ECHO_N "131: Doxygen Public Documentation                 $ECHO_C"
59418    at_xfail=no
59419    (
59420      echo "131. c++.at:102: testing ..."
59421      $at_traceon
59422
59423
59424cat >input.yy <<'_ATEOF'
59425%skeleton "lalr1.cc"
59426%locations
59427%debug
59428%defines
59429%%
59430exp:;
59431%%
59432yy::parser::error (const location& l, const std::string& m)
59433{
59434  std::cerr << l << s << std::endl;
59435}
59436_ATEOF
59437
59438
59439$at_traceoff
59440echo "c++.at:102: bison -o input.cc input.yy"
59441echo c++.at:102 >$at_check_line_file
59442( $at_traceon; bison -o input.cc input.yy ) >$at_stdout 2>$at_stder1
59443at_status=$?
59444grep '^ *+' $at_stder1 >&2
59445grep -v '^ *+' $at_stder1 >$at_stderr
59446at_failed=false
59447$at_diff $at_devnull $at_stderr || at_failed=:
59448$at_diff $at_devnull $at_stdout || at_failed=:
59449case $at_status in
59450   77) echo 77 > $at_status_file
59451            exit 77;;
59452   0) ;;
59453   *) echo "c++.at:102: exit code was $at_status, expected 0"
59454      at_failed=:;;
59455esac
59456if $at_failed; then
59457
59458  echo 1 > $at_status_file
59459  exit 1
59460fi
59461
59462$at_traceon
59463
59464
59465cat >Doxyfile <<'_ATEOF'
59466# The PROJECT_NAME tag is a single word (or a sequence of words
59467# surrounded by quotes) that should identify the project.
59468PROJECT_NAME = "Bison C++ Parser"
59469
59470# The QUIET tag can be used to turn on/off the messages that are
59471# generated by doxygen. Possible values are YES and NO. If left blank
59472# NO is used.
59473QUIET = YES
59474
59475# The WARNINGS tag can be used to turn on/off the warning messages
59476# that are generated by doxygen. Possible values are YES and NO. If
59477# left blank NO is used.
59478WARNINGS     = YES
59479# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate
59480# warnings for undocumented members. If EXTRACT_ALL is set to YES then
59481# this flag will automatically be disabled.
59482WARN_IF_UNDOCUMENTED   = YES
59483# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings
59484# for potential errors in the documentation, such as not documenting
59485# some parameters in a documented function, or documenting parameters
59486# that don't exist or using markup commands wrongly.
59487WARN_IF_DOC_ERROR      = YES
59488# The WARN_FORMAT tag determines the format of the warning messages
59489# that doxygen can produce. The string should contain the $file,
59490# $line, and $text tags, which will be replaced by the file and line
59491# number from which the warning originated and the warning text.
59492WARN_FORMAT            = "$file:$line: $text"
59493
59494# If the EXTRACT_ALL tag is set to YES doxygen will assume all
59495# entities in documentation are documented, even if no documentation
59496# was available.  Private class members and static file members will
59497# be hidden unless the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set
59498# to YES
59499EXTRACT_ALL            = YES
59500
59501# If the EXTRACT_PRIVATE tag is set to YES all private members of a
59502# class will be included in the documentation.
59503EXTRACT_PRIVATE        = NO
59504
59505# If the EXTRACT_STATIC tag is set to YES all static members of a file
59506# will be included in the documentation.
59507EXTRACT_STATIC         = NO
59508_ATEOF
59509
59510
59511$at_traceoff
59512echo "c++.at:102: doxygen --version || exit 77"
59513echo c++.at:102 >$at_check_line_file
59514( $at_traceon; doxygen --version || exit 77 ) >$at_stdout 2>$at_stder1
59515at_status=$?
59516grep '^ *+' $at_stder1 >&2
59517grep -v '^ *+' $at_stder1 >$at_stderr
59518at_failed=false
59519$at_diff $at_devnull $at_stderr || at_failed=:
59520echo stdout:; cat $at_stdout
59521case $at_status in
59522   77) echo 77 > $at_status_file
59523            exit 77;;
59524   0) ;;
59525   *) echo "c++.at:102: exit code was $at_status, expected 0"
59526      at_failed=:;;
59527esac
59528if $at_failed; then
59529
59530  echo 1 > $at_status_file
59531  exit 1
59532fi
59533
59534$at_traceon
59535
59536$at_traceoff
59537echo "c++.at:102: doxygen"
59538echo c++.at:102 >$at_check_line_file
59539( $at_traceon; doxygen ) >$at_stdout 2>$at_stder1
59540at_status=$?
59541grep '^ *+' $at_stder1 >&2
59542grep -v '^ *+' $at_stder1 >$at_stderr
59543at_failed=false
59544echo stderr:; cat $at_stderr
59545$at_diff $at_devnull $at_stdout || at_failed=:
59546case $at_status in
59547   77) echo 77 > $at_status_file
59548            exit 77;;
59549   0) ;;
59550   *) echo "c++.at:102: exit code was $at_status, expected 0"
59551      at_failed=:;;
59552esac
59553if $at_failed; then
59554
59555  echo 1 > $at_status_file
59556  exit 1
59557fi
59558
59559$at_traceon
59560
59561
59562      $at_traceoff
59563      $at_times_p && times >$at_times_file
59564    ) 5>&1 2>&1 | eval $at_tee_pipe
59565    at_status=`cat $at_status_file`
59566    ;;
59567
59568  132 ) # 132. c++.at:103: Doxygen Private Documentation
59569    at_setup_line='c++.at:103'
59570    at_desc='Doxygen Private Documentation'
59571    $at_quiet $ECHO_N "132: Doxygen Private Documentation                $ECHO_C"
59572    at_xfail=no
59573    (
59574      echo "132. c++.at:103: testing ..."
59575      $at_traceon
59576
59577
59578cat >input.yy <<'_ATEOF'
59579%skeleton "lalr1.cc"
59580%locations
59581%debug
59582%defines
59583%%
59584exp:;
59585%%
59586yy::parser::error (const location& l, const std::string& m)
59587{
59588  std::cerr << l << s << std::endl;
59589}
59590_ATEOF
59591
59592
59593$at_traceoff
59594echo "c++.at:103: bison -o input.cc input.yy"
59595echo c++.at:103 >$at_check_line_file
59596( $at_traceon; bison -o input.cc input.yy ) >$at_stdout 2>$at_stder1
59597at_status=$?
59598grep '^ *+' $at_stder1 >&2
59599grep -v '^ *+' $at_stder1 >$at_stderr
59600at_failed=false
59601$at_diff $at_devnull $at_stderr || at_failed=:
59602$at_diff $at_devnull $at_stdout || at_failed=:
59603case $at_status in
59604   77) echo 77 > $at_status_file
59605            exit 77;;
59606   0) ;;
59607   *) echo "c++.at:103: exit code was $at_status, expected 0"
59608      at_failed=:;;
59609esac
59610if $at_failed; then
59611
59612  echo 1 > $at_status_file
59613  exit 1
59614fi
59615
59616$at_traceon
59617
59618
59619cat >Doxyfile <<'_ATEOF'
59620# The PROJECT_NAME tag is a single word (or a sequence of words
59621# surrounded by quotes) that should identify the project.
59622PROJECT_NAME = "Bison C++ Parser"
59623
59624# The QUIET tag can be used to turn on/off the messages that are
59625# generated by doxygen. Possible values are YES and NO. If left blank
59626# NO is used.
59627QUIET = YES
59628
59629# The WARNINGS tag can be used to turn on/off the warning messages
59630# that are generated by doxygen. Possible values are YES and NO. If
59631# left blank NO is used.
59632WARNINGS     = YES
59633# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate
59634# warnings for undocumented members. If EXTRACT_ALL is set to YES then
59635# this flag will automatically be disabled.
59636WARN_IF_UNDOCUMENTED   = YES
59637# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings
59638# for potential errors in the documentation, such as not documenting
59639# some parameters in a documented function, or documenting parameters
59640# that don't exist or using markup commands wrongly.
59641WARN_IF_DOC_ERROR      = YES
59642# The WARN_FORMAT tag determines the format of the warning messages
59643# that doxygen can produce. The string should contain the $file,
59644# $line, and $text tags, which will be replaced by the file and line
59645# number from which the warning originated and the warning text.
59646WARN_FORMAT            = "$file:$line: $text"
59647
59648# If the EXTRACT_ALL tag is set to YES doxygen will assume all
59649# entities in documentation are documented, even if no documentation
59650# was available.  Private class members and static file members will
59651# be hidden unless the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set
59652# to YES
59653EXTRACT_ALL            = YES
59654
59655# If the EXTRACT_PRIVATE tag is set to YES all private members of a
59656# class will be included in the documentation.
59657EXTRACT_PRIVATE        = YES
59658
59659# If the EXTRACT_STATIC tag is set to YES all static members of a file
59660# will be included in the documentation.
59661EXTRACT_STATIC         = YES
59662_ATEOF
59663
59664
59665$at_traceoff
59666echo "c++.at:103: doxygen --version || exit 77"
59667echo c++.at:103 >$at_check_line_file
59668( $at_traceon; doxygen --version || exit 77 ) >$at_stdout 2>$at_stder1
59669at_status=$?
59670grep '^ *+' $at_stder1 >&2
59671grep -v '^ *+' $at_stder1 >$at_stderr
59672at_failed=false
59673$at_diff $at_devnull $at_stderr || at_failed=:
59674echo stdout:; cat $at_stdout
59675case $at_status in
59676   77) echo 77 > $at_status_file
59677            exit 77;;
59678   0) ;;
59679   *) echo "c++.at:103: exit code was $at_status, expected 0"
59680      at_failed=:;;
59681esac
59682if $at_failed; then
59683
59684  echo 1 > $at_status_file
59685  exit 1
59686fi
59687
59688$at_traceon
59689
59690$at_traceoff
59691echo "c++.at:103: doxygen"
59692echo c++.at:103 >$at_check_line_file
59693( $at_traceon; doxygen ) >$at_stdout 2>$at_stder1
59694at_status=$?
59695grep '^ *+' $at_stder1 >&2
59696grep -v '^ *+' $at_stder1 >$at_stderr
59697at_failed=false
59698echo stderr:; cat $at_stderr
59699$at_diff $at_devnull $at_stdout || at_failed=:
59700case $at_status in
59701   77) echo 77 > $at_status_file
59702            exit 77;;
59703   0) ;;
59704   *) echo "c++.at:103: exit code was $at_status, expected 0"
59705      at_failed=:;;
59706esac
59707if $at_failed; then
59708
59709  echo 1 > $at_status_file
59710  exit 1
59711fi
59712
59713$at_traceon
59714
59715
59716      $at_traceoff
59717      $at_times_p && times >$at_times_file
59718    ) 5>&1 2>&1 | eval $at_tee_pipe
59719    at_status=`cat $at_status_file`
59720    ;;
59721
59722
59723  banner-17 ) # Banner 17. cxx-type.at:19
59724    cat <<\_ATEOF
59725
59726C++ Type Syntax (GLR).
59727
59728_ATEOF
59729    ;;
59730
59731  133 ) # 133. cxx-type.at:412: GLR: Resolve ambiguity, impure, no locations
59732    at_setup_line='cxx-type.at:412'
59733    at_desc='GLR: Resolve ambiguity, impure, no locations'
59734    $at_quiet $ECHO_N "133: GLR: Resolve ambiguity, impure, no locations $ECHO_C"
59735    at_xfail=no
59736    (
59737      echo "133. cxx-type.at:412: testing ..."
59738      $at_traceon
59739
59740
59741
59742
59743
59744
59745# Using yacc.c?
59746
59747
59748
59749
59750
59751
59752
59753# yyerror receives the location if %location & %pure & (%glr or %parse-param).
59754
59755# yyerror always sees the locations (when activated), except if
59756# yacc & pure & !param.
59757
59758
59759# The interface is pure: either because %pure-parser, or because we
59760# are using the C++ parsers.
59761
59762
59763
59764
59765
59766
59767
59768
59769
59770
59771
59772
59773cat >types.y <<'_ATEOF'
59774%{
59775#ifdef HAVE_CONFIG_H
59776# include <config.h>
59777  /* We don't need perfect functions for these tests. */
59778# undef malloc
59779# undef memcmp
59780# undef realloc
59781#endif
59782%}
59783
59784/* Simplified C++ Type and Expression Grammar.  */
59785
59786
59787
59788%{
59789  #include <stdio.h>
59790  union Node {
59791    struct {
59792      int isNterm;
59793      int parents;
59794    } nodeInfo;
59795    struct {
59796      int isNterm; /* 1 */
59797      int parents;
59798      char const *form;
59799      union Node *children[3];
59800    } nterm;
59801    struct {
59802      int isNterm; /* 0 */
59803      int parents;
59804      char *text;
59805    } term;
59806  };
59807  typedef union Node Node;
59808  static Node *new_nterm (char const *, Node *, Node *, Node *);
59809  static Node *new_term (char *);
59810  static void free_node (Node *);
59811  static char *node_to_string (Node *);
59812  #define YYSTYPE Node *
59813
59814  #define YYINITDEPTH 10
59815  #define YYSTACKEXPANDABLE 1
59816  struct YYLTYPE;
59817#if YYPURE
59818# if YYLSP_NEEDED
59819#  define LEX_PARAMETERS YYSTYPE *lvalp, struct YYLTYPE *llocp
59820#  define ERROR_PARAMETERS struct YYLTYPE *llocp, char const *s
59821# else
59822#  define LEX_PARAMETERS YYSTYPE *lvalp
59823# endif
59824#endif
59825#ifndef LEX_PARAMETERS
59826# define LEX_PARAMETERS void
59827#endif
59828#ifndef ERROR_PARAMETERS
59829# define ERROR_PARAMETERS char const *s
59830#endif
59831  int yylex (LEX_PARAMETERS);
59832  void yyerror (ERROR_PARAMETERS);
59833%}
59834
59835%token TYPENAME ID
59836
59837%right '='
59838%left '+'
59839
59840%glr-parser
59841
59842%destructor { free_node ($$); } stmt expr decl declarator TYPENAME ID
59843
59844%%
59845
59846prog :
59847     | prog stmt   {
59848			char *output;
59849			output = node_to_string ($2);
59850			printf ("%s\n", output);
59851			free (output);
59852			free_node ($2);
59853		   }
59854     ;
59855
59856stmt : expr ';'  %dprec 1	{ $$ = $1; }
59857     | decl      %dprec 2
59858     | error ';'	{ $$ = new_nterm ("<error>", 0, 0, 0); }
59859     | '@'		{ YYACCEPT; }
59860     ;
59861
59862expr : ID
59863     | TYPENAME '(' expr ')'
59864			{ $$ = new_nterm ("<cast>(%s,%s)", $3, $1, 0); }
59865     | expr '+' expr	{ $$ = new_nterm ("+(%s,%s)", $1, $3, 0); }
59866     | expr '=' expr    { $$ = new_nterm ("=(%s,%s)", $1, $3, 0); }
59867     ;
59868
59869decl : TYPENAME declarator ';'
59870			{ $$ = new_nterm ("<declare>(%s,%s)", $1, $2, 0); }
59871     | TYPENAME declarator '=' expr ';'
59872			{ $$ = new_nterm ("<init-declare>(%s,%s,%s)", $1,
59873					  $2, $4); }
59874     ;
59875
59876declarator : ID
59877     | '(' declarator ')' { $$ = $2; }
59878     ;
59879
59880%%
59881
59882#include <ctype.h>
59883#include <stdlib.h>
59884#include <string.h>
59885#include <stdarg.h>
59886
59887int
59888main (int argc, char **argv)
59889{
59890  if (argc != 2)
59891    abort ();
59892  if (!freopen (argv[1], "r", stdin))
59893    return 3;
59894  return yyparse ();
59895}
59896
59897int
59898yylex (LEX_PARAMETERS)
59899{
59900  char buffer[256];
59901  int c;
59902  unsigned int i;
59903  static int lineNum = 1;
59904  static int colNum = 0;
59905
59906#if YYPURE
59907# undef yylloc
59908# define yylloc (*llocp)
59909# undef yylval
59910# define yylval (*lvalp)
59911#endif
59912
59913  while (1)
59914    {
59915      c = getchar ();
59916      switch (c)
59917	{
59918	case EOF:
59919	  return 0;
59920	case '\t':
59921	  colNum = (colNum + 7) & ~7;
59922	  break;
59923	case ' ': case '\f':
59924	  colNum += 1;
59925	  break;
59926	case '\n':
59927	  lineNum += 1;
59928	  colNum = 0;
59929	  break;
59930	default:
59931	  {
59932	    int tok;
59933#if YYLSP_NEEDED
59934	    yylloc.first_line = yylloc.last_line = lineNum;
59935	    yylloc.first_column = colNum;
59936#endif
59937	    if (isalpha (c))
59938	      {
59939		i = 0;
59940
59941		do
59942		  {
59943		    buffer[i++] = c;
59944		    colNum += 1;
59945		    if (i == sizeof buffer - 1)
59946		      abort ();
59947		    c = getchar ();
59948		  }
59949		while (isalnum (c) || c == '_');
59950
59951		ungetc (c, stdin);
59952		buffer[i++] = 0;
59953		tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
59954		yylval = new_term (strcpy ((char *) malloc (i), buffer));
59955	      }
59956	    else
59957	      {
59958		colNum += 1;
59959		tok = c;
59960		yylval = 0;
59961	      }
59962#if YYLSP_NEEDED
59963	    yylloc.last_column = colNum-1;
59964#endif
59965	    return tok;
59966	  }
59967	}
59968    }
59969}
59970
59971void
59972yyerror (ERROR_PARAMETERS)
59973{
59974#if YYPURE && YYLSP_NEEDED
59975  /* Pacify GCC by using llocp.  */
59976  if (! llocp)
59977    abort ();
59978#endif
59979  fprintf (stderr, "%s\n", s);
59980}
59981
59982static Node *
59983new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
59984{
59985  Node *node = (Node *) malloc (sizeof (Node));
59986  node->nterm.isNterm = 1;
59987  node->nterm.parents = 0;
59988  node->nterm.form = form;
59989  node->nterm.children[0] = child0;
59990  if (child0)
59991    child0->nodeInfo.parents += 1;
59992  node->nterm.children[1] = child1;
59993  if (child1)
59994    child1->nodeInfo.parents += 1;
59995  node->nterm.children[2] = child2;
59996  if (child2)
59997    child2->nodeInfo.parents += 1;
59998  return node;
59999}
60000
60001static Node *
60002new_term (char *text)
60003{
60004  Node *node = (Node *) malloc (sizeof (Node));
60005  node->term.isNterm = 0;
60006  node->term.parents = 0;
60007  node->term.text = text;
60008  return node;
60009}
60010
60011static void
60012free_node (Node *node)
60013{
60014  if (!node)
60015    return;
60016  node->nodeInfo.parents -= 1;
60017  /* Free only if 0 (last parent) or -1 (no parents).  */
60018  if (node->nodeInfo.parents > 0)
60019    return;
60020  if (node->nodeInfo.isNterm == 1)
60021    {
60022      free_node (node->nterm.children[0]);
60023      free_node (node->nterm.children[1]);
60024      free_node (node->nterm.children[2]);
60025    }
60026  else
60027    free (node->term.text);
60028  free (node);
60029}
60030
60031static char *
60032node_to_string (Node *node)
60033{
60034  char *child0;
60035  char *child1;
60036  char *child2;
60037  char *buffer;
60038  if (!node)
60039    {
60040      buffer = (char *) malloc (1);
60041      buffer[0] = 0;
60042    }
60043  else if (node->nodeInfo.isNterm == 1)
60044    {
60045      child0 = node_to_string (node->nterm.children[0]);
60046      child1 = node_to_string (node->nterm.children[1]);
60047      child2 = node_to_string (node->nterm.children[2]);
60048      buffer = (char *) malloc (strlen (node->nterm.form) + strlen (child0)
60049				+ strlen (child1) + strlen (child2) + 1);
60050      sprintf (buffer, node->nterm.form, child0, child1, child2);
60051      free (child0);
60052      free (child1);
60053      free (child2);
60054    }
60055  else
60056    buffer = strdup (node->term.text);
60057  return buffer;
60058}
60059
60060
60061
60062_ATEOF
60063
60064
60065
60066cat >test-input <<'_ATEOF'
60067
60068
60069z + q;
60070
60071T x;
60072
60073T x = y;
60074
60075x = y;
60076
60077T (x) + y;
60078
60079T (x);
60080
60081T (y) = z + q;
60082
60083T (y y) = z + q;
60084
60085z + q;
60086
60087@
60088
60089This is total garbage, but it should be ignored.
60090_ATEOF
60091
60092
60093$at_traceoff
60094echo "cxx-type.at:414: bison -o types.c types.y"
60095echo cxx-type.at:414 >$at_check_line_file
60096( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
60097at_status=$?
60098grep '^ *+' $at_stder1 >&2
60099grep -v '^ *+' $at_stder1 >$at_stderr
60100at_failed=false
60101echo stderr:; cat $at_stderr
60102$at_diff $at_devnull $at_stdout || at_failed=:
60103case $at_status in
60104   77) echo 77 > $at_status_file
60105            exit 77;;
60106   0) ;;
60107   *) echo "cxx-type.at:414: exit code was $at_status, expected 0"
60108      at_failed=:;;
60109esac
60110if $at_failed; then
60111
60112  echo 1 > $at_status_file
60113  exit 1
60114fi
60115
60116$at_traceon
60117
60118$at_traceoff
60119echo "cxx-type.at:414: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o types types.c \$LIBS"
60120echo cxx-type.at:414 >$at_check_line_file
60121( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o types types.c $LIBS ) >$at_stdout 2>$at_stder1
60122at_status=$?
60123grep '^ *+' $at_stder1 >&2
60124grep -v '^ *+' $at_stder1 >$at_stderr
60125at_failed=false
60126echo stderr:; cat $at_stderr
60127echo stdout:; cat $at_stdout
60128case $at_status in
60129   77) echo 77 > $at_status_file
60130            exit 77;;
60131   0) ;;
60132   *) echo "cxx-type.at:414: exit code was $at_status, expected 0"
60133      at_failed=:;;
60134esac
60135if $at_failed; then
60136
60137  echo 1 > $at_status_file
60138  exit 1
60139fi
60140
60141$at_traceon
60142
60143
60144
60145
60146
60147
60148
60149
60150
60151
60152
60153
60154
60155
60156
60157
60158
60159
60160
60161
60162
60163
60164
60165$at_traceoff
60166echo "cxx-type.at:416: \$PREPARSER ./types test-input"
60167echo cxx-type.at:416 >$at_check_line_file
60168( $at_traceon; $PREPARSER ./types test-input ) >$at_stdout 2>$at_stder1
60169at_status=$?
60170grep '^ *+' $at_stder1 >&2
60171grep -v '^ *+' $at_stder1 >$at_stderr
60172at_failed=false
60173echo >>$at_stderr; echo "syntax error
60174" | $at_diff - $at_stderr || at_failed=:
60175echo >>$at_stdout; echo "+(z,q)
60176<declare>(T,x)
60177<init-declare>(T,x,y)
60178=(x,y)
60179+(<cast>(x,T),y)
60180<declare>(T,x)
60181<init-declare>(T,y,+(z,q))
60182<error>
60183+(z,q)
60184" | $at_diff - $at_stdout || at_failed=:
60185case $at_status in
60186   77) echo 77 > $at_status_file
60187            exit 77;;
60188   0) ;;
60189   *) echo "cxx-type.at:416: exit code was $at_status, expected 0"
60190      at_failed=:;;
60191esac
60192if $at_failed; then
60193
60194  echo 1 > $at_status_file
60195  exit 1
60196fi
60197
60198$at_traceon
60199
60200      $at_traceoff
60201      $at_times_p && times >$at_times_file
60202    ) 5>&1 2>&1 | eval $at_tee_pipe
60203    at_status=`cat $at_status_file`
60204    ;;
60205
60206  134 ) # 134. cxx-type.at:419: GLR: Resolve ambiguity, impure, locations
60207    at_setup_line='cxx-type.at:419'
60208    at_desc='GLR: Resolve ambiguity, impure, locations'
60209    $at_quiet $ECHO_N "134: GLR: Resolve ambiguity, impure, locations    $ECHO_C"
60210    at_xfail=no
60211    (
60212      echo "134. cxx-type.at:419: testing ..."
60213      $at_traceon
60214
60215
60216
60217
60218
60219
60220# Using yacc.c?
60221
60222
60223
60224
60225
60226
60227
60228# yyerror receives the location if %location & %pure & (%glr or %parse-param).
60229
60230# yyerror always sees the locations (when activated), except if
60231# yacc & pure & !param.
60232
60233
60234# The interface is pure: either because %pure-parser, or because we
60235# are using the C++ parsers.
60236
60237
60238
60239
60240
60241
60242
60243
60244
60245
60246
60247
60248cat >types.y <<'_ATEOF'
60249%{
60250#ifdef HAVE_CONFIG_H
60251# include <config.h>
60252  /* We don't need perfect functions for these tests. */
60253# undef malloc
60254# undef memcmp
60255# undef realloc
60256#endif
60257%}
60258
60259/* Simplified C++ Type and Expression Grammar.  */
60260
60261%locations
60262
60263%{
60264  #include <stdio.h>
60265  union Node {
60266    struct {
60267      int isNterm;
60268      int parents;
60269    } nodeInfo;
60270    struct {
60271      int isNterm; /* 1 */
60272      int parents;
60273      char const *form;
60274      union Node *children[3];
60275    } nterm;
60276    struct {
60277      int isNterm; /* 0 */
60278      int parents;
60279      char *text;
60280    } term;
60281  };
60282  typedef union Node Node;
60283  static Node *new_nterm (char const *, Node *, Node *, Node *);
60284  static Node *new_term (char *);
60285  static void free_node (Node *);
60286  static char *node_to_string (Node *);
60287  #define YYSTYPE Node *
60288
60289  #define YYINITDEPTH 10
60290  #define YYSTACKEXPANDABLE 1
60291  struct YYLTYPE;
60292#if YYPURE
60293# if YYLSP_NEEDED
60294#  define LEX_PARAMETERS YYSTYPE *lvalp, struct YYLTYPE *llocp
60295#  define ERROR_PARAMETERS struct YYLTYPE *llocp, char const *s
60296# else
60297#  define LEX_PARAMETERS YYSTYPE *lvalp
60298# endif
60299#endif
60300#ifndef LEX_PARAMETERS
60301# define LEX_PARAMETERS void
60302#endif
60303#ifndef ERROR_PARAMETERS
60304# define ERROR_PARAMETERS char const *s
60305#endif
60306  int yylex (LEX_PARAMETERS);
60307  void yyerror (ERROR_PARAMETERS);
60308%}
60309
60310%token TYPENAME ID
60311
60312%right '='
60313%left '+'
60314
60315%glr-parser
60316
60317%destructor { free_node ($$); } stmt expr decl declarator TYPENAME ID
60318
60319%%
60320
60321prog :
60322     | prog stmt   {
60323			char *output;
60324			printf ("%d.%d-%d.%d: ",
60325			     @2.first_line, @2.first_column,
60326			     @2.last_line, @2.last_column);
60327			output = node_to_string ($2);
60328			printf ("%s\n", output);
60329			free (output);
60330			free_node ($2);
60331		   }
60332     ;
60333
60334stmt : expr ';'  %dprec 1	{ $$ = $1; }
60335     | decl      %dprec 2
60336     | error ';'	{ $$ = new_nterm ("<error>", 0, 0, 0); }
60337     | '@'		{ YYACCEPT; }
60338     ;
60339
60340expr : ID
60341     | TYPENAME '(' expr ')'
60342			{ $$ = new_nterm ("<cast>(%s,%s)", $3, $1, 0); }
60343     | expr '+' expr	{ $$ = new_nterm ("+(%s,%s)", $1, $3, 0); }
60344     | expr '=' expr    { $$ = new_nterm ("=(%s,%s)", $1, $3, 0); }
60345     ;
60346
60347decl : TYPENAME declarator ';'
60348			{ $$ = new_nterm ("<declare>(%s,%s)", $1, $2, 0); }
60349     | TYPENAME declarator '=' expr ';'
60350			{ $$ = new_nterm ("<init-declare>(%s,%s,%s)", $1,
60351					  $2, $4); }
60352     ;
60353
60354declarator : ID
60355     | '(' declarator ')' { $$ = $2; }
60356     ;
60357
60358%%
60359
60360#include <ctype.h>
60361#include <stdlib.h>
60362#include <string.h>
60363#include <stdarg.h>
60364
60365int
60366main (int argc, char **argv)
60367{
60368  if (argc != 2)
60369    abort ();
60370  if (!freopen (argv[1], "r", stdin))
60371    return 3;
60372  return yyparse ();
60373}
60374
60375int
60376yylex (LEX_PARAMETERS)
60377{
60378  char buffer[256];
60379  int c;
60380  unsigned int i;
60381  static int lineNum = 1;
60382  static int colNum = 0;
60383
60384#if YYPURE
60385# undef yylloc
60386# define yylloc (*llocp)
60387# undef yylval
60388# define yylval (*lvalp)
60389#endif
60390
60391  while (1)
60392    {
60393      c = getchar ();
60394      switch (c)
60395	{
60396	case EOF:
60397	  return 0;
60398	case '\t':
60399	  colNum = (colNum + 7) & ~7;
60400	  break;
60401	case ' ': case '\f':
60402	  colNum += 1;
60403	  break;
60404	case '\n':
60405	  lineNum += 1;
60406	  colNum = 0;
60407	  break;
60408	default:
60409	  {
60410	    int tok;
60411#if YYLSP_NEEDED
60412	    yylloc.first_line = yylloc.last_line = lineNum;
60413	    yylloc.first_column = colNum;
60414#endif
60415	    if (isalpha (c))
60416	      {
60417		i = 0;
60418
60419		do
60420		  {
60421		    buffer[i++] = c;
60422		    colNum += 1;
60423		    if (i == sizeof buffer - 1)
60424		      abort ();
60425		    c = getchar ();
60426		  }
60427		while (isalnum (c) || c == '_');
60428
60429		ungetc (c, stdin);
60430		buffer[i++] = 0;
60431		tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
60432		yylval = new_term (strcpy ((char *) malloc (i), buffer));
60433	      }
60434	    else
60435	      {
60436		colNum += 1;
60437		tok = c;
60438		yylval = 0;
60439	      }
60440#if YYLSP_NEEDED
60441	    yylloc.last_column = colNum-1;
60442#endif
60443	    return tok;
60444	  }
60445	}
60446    }
60447}
60448
60449void
60450yyerror (ERROR_PARAMETERS)
60451{
60452#if YYPURE && YYLSP_NEEDED
60453  /* Pacify GCC by using llocp.  */
60454  if (! llocp)
60455    abort ();
60456#endif
60457  fprintf (stderr, "%s\n", s);
60458}
60459
60460static Node *
60461new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
60462{
60463  Node *node = (Node *) malloc (sizeof (Node));
60464  node->nterm.isNterm = 1;
60465  node->nterm.parents = 0;
60466  node->nterm.form = form;
60467  node->nterm.children[0] = child0;
60468  if (child0)
60469    child0->nodeInfo.parents += 1;
60470  node->nterm.children[1] = child1;
60471  if (child1)
60472    child1->nodeInfo.parents += 1;
60473  node->nterm.children[2] = child2;
60474  if (child2)
60475    child2->nodeInfo.parents += 1;
60476  return node;
60477}
60478
60479static Node *
60480new_term (char *text)
60481{
60482  Node *node = (Node *) malloc (sizeof (Node));
60483  node->term.isNterm = 0;
60484  node->term.parents = 0;
60485  node->term.text = text;
60486  return node;
60487}
60488
60489static void
60490free_node (Node *node)
60491{
60492  if (!node)
60493    return;
60494  node->nodeInfo.parents -= 1;
60495  /* Free only if 0 (last parent) or -1 (no parents).  */
60496  if (node->nodeInfo.parents > 0)
60497    return;
60498  if (node->nodeInfo.isNterm == 1)
60499    {
60500      free_node (node->nterm.children[0]);
60501      free_node (node->nterm.children[1]);
60502      free_node (node->nterm.children[2]);
60503    }
60504  else
60505    free (node->term.text);
60506  free (node);
60507}
60508
60509static char *
60510node_to_string (Node *node)
60511{
60512  char *child0;
60513  char *child1;
60514  char *child2;
60515  char *buffer;
60516  if (!node)
60517    {
60518      buffer = (char *) malloc (1);
60519      buffer[0] = 0;
60520    }
60521  else if (node->nodeInfo.isNterm == 1)
60522    {
60523      child0 = node_to_string (node->nterm.children[0]);
60524      child1 = node_to_string (node->nterm.children[1]);
60525      child2 = node_to_string (node->nterm.children[2]);
60526      buffer = (char *) malloc (strlen (node->nterm.form) + strlen (child0)
60527				+ strlen (child1) + strlen (child2) + 1);
60528      sprintf (buffer, node->nterm.form, child0, child1, child2);
60529      free (child0);
60530      free (child1);
60531      free (child2);
60532    }
60533  else
60534    buffer = strdup (node->term.text);
60535  return buffer;
60536}
60537
60538
60539
60540_ATEOF
60541
60542
60543
60544cat >test-input <<'_ATEOF'
60545
60546
60547z + q;
60548
60549T x;
60550
60551T x = y;
60552
60553x = y;
60554
60555T (x) + y;
60556
60557T (x);
60558
60559T (y) = z + q;
60560
60561T (y y) = z + q;
60562
60563z + q;
60564
60565@
60566
60567This is total garbage, but it should be ignored.
60568_ATEOF
60569
60570
60571$at_traceoff
60572echo "cxx-type.at:420: bison -o types.c types.y"
60573echo cxx-type.at:420 >$at_check_line_file
60574( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
60575at_status=$?
60576grep '^ *+' $at_stder1 >&2
60577grep -v '^ *+' $at_stder1 >$at_stderr
60578at_failed=false
60579echo stderr:; cat $at_stderr
60580$at_diff $at_devnull $at_stdout || at_failed=:
60581case $at_status in
60582   77) echo 77 > $at_status_file
60583            exit 77;;
60584   0) ;;
60585   *) echo "cxx-type.at:420: exit code was $at_status, expected 0"
60586      at_failed=:;;
60587esac
60588if $at_failed; then
60589
60590  echo 1 > $at_status_file
60591  exit 1
60592fi
60593
60594$at_traceon
60595
60596$at_traceoff
60597echo "cxx-type.at:420: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o types types.c \$LIBS"
60598echo cxx-type.at:420 >$at_check_line_file
60599( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o types types.c $LIBS ) >$at_stdout 2>$at_stder1
60600at_status=$?
60601grep '^ *+' $at_stder1 >&2
60602grep -v '^ *+' $at_stder1 >$at_stderr
60603at_failed=false
60604echo stderr:; cat $at_stderr
60605echo stdout:; cat $at_stdout
60606case $at_status in
60607   77) echo 77 > $at_status_file
60608            exit 77;;
60609   0) ;;
60610   *) echo "cxx-type.at:420: exit code was $at_status, expected 0"
60611      at_failed=:;;
60612esac
60613if $at_failed; then
60614
60615  echo 1 > $at_status_file
60616  exit 1
60617fi
60618
60619$at_traceon
60620
60621
60622
60623
60624
60625
60626
60627
60628
60629
60630
60631
60632
60633
60634
60635
60636
60637
60638
60639
60640
60641
60642
60643$at_traceoff
60644echo "cxx-type.at:422: \$PREPARSER ./types test-input"
60645echo cxx-type.at:422 >$at_check_line_file
60646( $at_traceon; $PREPARSER ./types test-input ) >$at_stdout 2>$at_stder1
60647at_status=$?
60648grep '^ *+' $at_stder1 >&2
60649grep -v '^ *+' $at_stder1 >$at_stderr
60650at_failed=false
60651echo >>$at_stderr; echo "syntax error
60652" | $at_diff - $at_stderr || at_failed=:
60653echo >>$at_stdout; echo "3.0-3.5: +(z,q)
606545.0-5.3: <declare>(T,x)
606557.0-7.7: <init-declare>(T,x,y)
606569.0-9.5: =(x,y)
6065711.0-11.9: +(<cast>(x,T),y)
6065813.0-13.5: <declare>(T,x)
6065915.0-15.13: <init-declare>(T,y,+(z,q))
6066017.0-17.15: <error>
6066119.0-19.5: +(z,q)
60662" | $at_diff - $at_stdout || at_failed=:
60663case $at_status in
60664   77) echo 77 > $at_status_file
60665            exit 77;;
60666   0) ;;
60667   *) echo "cxx-type.at:422: exit code was $at_status, expected 0"
60668      at_failed=:;;
60669esac
60670if $at_failed; then
60671
60672  echo 1 > $at_status_file
60673  exit 1
60674fi
60675
60676$at_traceon
60677
60678      $at_traceoff
60679      $at_times_p && times >$at_times_file
60680    ) 5>&1 2>&1 | eval $at_tee_pipe
60681    at_status=`cat $at_status_file`
60682    ;;
60683
60684  135 ) # 135. cxx-type.at:425: GLR: Resolve ambiguity, pure, no locations
60685    at_setup_line='cxx-type.at:425'
60686    at_desc='GLR: Resolve ambiguity, pure, no locations'
60687    $at_quiet $ECHO_N "135: GLR: Resolve ambiguity, pure, no locations   $ECHO_C"
60688    at_xfail=no
60689    (
60690      echo "135. cxx-type.at:425: testing ..."
60691      $at_traceon
60692
60693
60694
60695
60696
60697
60698# Using yacc.c?
60699
60700
60701
60702
60703
60704
60705
60706# yyerror receives the location if %location & %pure & (%glr or %parse-param).
60707
60708# yyerror always sees the locations (when activated), except if
60709# yacc & pure & !param.
60710
60711
60712# The interface is pure: either because %pure-parser, or because we
60713# are using the C++ parsers.
60714
60715
60716
60717
60718
60719
60720
60721
60722
60723
60724
60725
60726cat >types.y <<'_ATEOF'
60727%{
60728#ifdef HAVE_CONFIG_H
60729# include <config.h>
60730  /* We don't need perfect functions for these tests. */
60731# undef malloc
60732# undef memcmp
60733# undef realloc
60734#endif
60735%}
60736
60737/* Simplified C++ Type and Expression Grammar.  */
60738
60739%pure-parser
60740
60741%{
60742  #include <stdio.h>
60743  union Node {
60744    struct {
60745      int isNterm;
60746      int parents;
60747    } nodeInfo;
60748    struct {
60749      int isNterm; /* 1 */
60750      int parents;
60751      char const *form;
60752      union Node *children[3];
60753    } nterm;
60754    struct {
60755      int isNterm; /* 0 */
60756      int parents;
60757      char *text;
60758    } term;
60759  };
60760  typedef union Node Node;
60761  static Node *new_nterm (char const *, Node *, Node *, Node *);
60762  static Node *new_term (char *);
60763  static void free_node (Node *);
60764  static char *node_to_string (Node *);
60765  #define YYSTYPE Node *
60766
60767  #define YYINITDEPTH 10
60768  #define YYSTACKEXPANDABLE 1
60769  struct YYLTYPE;
60770#if YYPURE
60771# if YYLSP_NEEDED
60772#  define LEX_PARAMETERS YYSTYPE *lvalp, struct YYLTYPE *llocp
60773#  define ERROR_PARAMETERS struct YYLTYPE *llocp, char const *s
60774# else
60775#  define LEX_PARAMETERS YYSTYPE *lvalp
60776# endif
60777#endif
60778#ifndef LEX_PARAMETERS
60779# define LEX_PARAMETERS void
60780#endif
60781#ifndef ERROR_PARAMETERS
60782# define ERROR_PARAMETERS char const *s
60783#endif
60784  int yylex (LEX_PARAMETERS);
60785  void yyerror (ERROR_PARAMETERS);
60786%}
60787
60788%token TYPENAME ID
60789
60790%right '='
60791%left '+'
60792
60793%glr-parser
60794
60795%destructor { free_node ($$); } stmt expr decl declarator TYPENAME ID
60796
60797%%
60798
60799prog :
60800     | prog stmt   {
60801			char *output;
60802			output = node_to_string ($2);
60803			printf ("%s\n", output);
60804			free (output);
60805			free_node ($2);
60806		   }
60807     ;
60808
60809stmt : expr ';'  %dprec 1	{ $$ = $1; }
60810     | decl      %dprec 2
60811     | error ';'	{ $$ = new_nterm ("<error>", 0, 0, 0); }
60812     | '@'		{ YYACCEPT; }
60813     ;
60814
60815expr : ID
60816     | TYPENAME '(' expr ')'
60817			{ $$ = new_nterm ("<cast>(%s,%s)", $3, $1, 0); }
60818     | expr '+' expr	{ $$ = new_nterm ("+(%s,%s)", $1, $3, 0); }
60819     | expr '=' expr    { $$ = new_nterm ("=(%s,%s)", $1, $3, 0); }
60820     ;
60821
60822decl : TYPENAME declarator ';'
60823			{ $$ = new_nterm ("<declare>(%s,%s)", $1, $2, 0); }
60824     | TYPENAME declarator '=' expr ';'
60825			{ $$ = new_nterm ("<init-declare>(%s,%s,%s)", $1,
60826					  $2, $4); }
60827     ;
60828
60829declarator : ID
60830     | '(' declarator ')' { $$ = $2; }
60831     ;
60832
60833%%
60834
60835#include <ctype.h>
60836#include <stdlib.h>
60837#include <string.h>
60838#include <stdarg.h>
60839
60840int
60841main (int argc, char **argv)
60842{
60843  if (argc != 2)
60844    abort ();
60845  if (!freopen (argv[1], "r", stdin))
60846    return 3;
60847  return yyparse ();
60848}
60849
60850int
60851yylex (LEX_PARAMETERS)
60852{
60853  char buffer[256];
60854  int c;
60855  unsigned int i;
60856  static int lineNum = 1;
60857  static int colNum = 0;
60858
60859#if YYPURE
60860# undef yylloc
60861# define yylloc (*llocp)
60862# undef yylval
60863# define yylval (*lvalp)
60864#endif
60865
60866  while (1)
60867    {
60868      c = getchar ();
60869      switch (c)
60870	{
60871	case EOF:
60872	  return 0;
60873	case '\t':
60874	  colNum = (colNum + 7) & ~7;
60875	  break;
60876	case ' ': case '\f':
60877	  colNum += 1;
60878	  break;
60879	case '\n':
60880	  lineNum += 1;
60881	  colNum = 0;
60882	  break;
60883	default:
60884	  {
60885	    int tok;
60886#if YYLSP_NEEDED
60887	    yylloc.first_line = yylloc.last_line = lineNum;
60888	    yylloc.first_column = colNum;
60889#endif
60890	    if (isalpha (c))
60891	      {
60892		i = 0;
60893
60894		do
60895		  {
60896		    buffer[i++] = c;
60897		    colNum += 1;
60898		    if (i == sizeof buffer - 1)
60899		      abort ();
60900		    c = getchar ();
60901		  }
60902		while (isalnum (c) || c == '_');
60903
60904		ungetc (c, stdin);
60905		buffer[i++] = 0;
60906		tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
60907		yylval = new_term (strcpy ((char *) malloc (i), buffer));
60908	      }
60909	    else
60910	      {
60911		colNum += 1;
60912		tok = c;
60913		yylval = 0;
60914	      }
60915#if YYLSP_NEEDED
60916	    yylloc.last_column = colNum-1;
60917#endif
60918	    return tok;
60919	  }
60920	}
60921    }
60922}
60923
60924void
60925yyerror (ERROR_PARAMETERS)
60926{
60927#if YYPURE && YYLSP_NEEDED
60928  /* Pacify GCC by using llocp.  */
60929  if (! llocp)
60930    abort ();
60931#endif
60932  fprintf (stderr, "%s\n", s);
60933}
60934
60935static Node *
60936new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
60937{
60938  Node *node = (Node *) malloc (sizeof (Node));
60939  node->nterm.isNterm = 1;
60940  node->nterm.parents = 0;
60941  node->nterm.form = form;
60942  node->nterm.children[0] = child0;
60943  if (child0)
60944    child0->nodeInfo.parents += 1;
60945  node->nterm.children[1] = child1;
60946  if (child1)
60947    child1->nodeInfo.parents += 1;
60948  node->nterm.children[2] = child2;
60949  if (child2)
60950    child2->nodeInfo.parents += 1;
60951  return node;
60952}
60953
60954static Node *
60955new_term (char *text)
60956{
60957  Node *node = (Node *) malloc (sizeof (Node));
60958  node->term.isNterm = 0;
60959  node->term.parents = 0;
60960  node->term.text = text;
60961  return node;
60962}
60963
60964static void
60965free_node (Node *node)
60966{
60967  if (!node)
60968    return;
60969  node->nodeInfo.parents -= 1;
60970  /* Free only if 0 (last parent) or -1 (no parents).  */
60971  if (node->nodeInfo.parents > 0)
60972    return;
60973  if (node->nodeInfo.isNterm == 1)
60974    {
60975      free_node (node->nterm.children[0]);
60976      free_node (node->nterm.children[1]);
60977      free_node (node->nterm.children[2]);
60978    }
60979  else
60980    free (node->term.text);
60981  free (node);
60982}
60983
60984static char *
60985node_to_string (Node *node)
60986{
60987  char *child0;
60988  char *child1;
60989  char *child2;
60990  char *buffer;
60991  if (!node)
60992    {
60993      buffer = (char *) malloc (1);
60994      buffer[0] = 0;
60995    }
60996  else if (node->nodeInfo.isNterm == 1)
60997    {
60998      child0 = node_to_string (node->nterm.children[0]);
60999      child1 = node_to_string (node->nterm.children[1]);
61000      child2 = node_to_string (node->nterm.children[2]);
61001      buffer = (char *) malloc (strlen (node->nterm.form) + strlen (child0)
61002				+ strlen (child1) + strlen (child2) + 1);
61003      sprintf (buffer, node->nterm.form, child0, child1, child2);
61004      free (child0);
61005      free (child1);
61006      free (child2);
61007    }
61008  else
61009    buffer = strdup (node->term.text);
61010  return buffer;
61011}
61012
61013
61014
61015_ATEOF
61016
61017
61018
61019cat >test-input <<'_ATEOF'
61020
61021
61022z + q;
61023
61024T x;
61025
61026T x = y;
61027
61028x = y;
61029
61030T (x) + y;
61031
61032T (x);
61033
61034T (y) = z + q;
61035
61036T (y y) = z + q;
61037
61038z + q;
61039
61040@
61041
61042This is total garbage, but it should be ignored.
61043_ATEOF
61044
61045
61046$at_traceoff
61047echo "cxx-type.at:427: bison -o types.c types.y"
61048echo cxx-type.at:427 >$at_check_line_file
61049( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
61050at_status=$?
61051grep '^ *+' $at_stder1 >&2
61052grep -v '^ *+' $at_stder1 >$at_stderr
61053at_failed=false
61054echo stderr:; cat $at_stderr
61055$at_diff $at_devnull $at_stdout || at_failed=:
61056case $at_status in
61057   77) echo 77 > $at_status_file
61058            exit 77;;
61059   0) ;;
61060   *) echo "cxx-type.at:427: exit code was $at_status, expected 0"
61061      at_failed=:;;
61062esac
61063if $at_failed; then
61064
61065  echo 1 > $at_status_file
61066  exit 1
61067fi
61068
61069$at_traceon
61070
61071$at_traceoff
61072echo "cxx-type.at:427: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o types types.c \$LIBS"
61073echo cxx-type.at:427 >$at_check_line_file
61074( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o types types.c $LIBS ) >$at_stdout 2>$at_stder1
61075at_status=$?
61076grep '^ *+' $at_stder1 >&2
61077grep -v '^ *+' $at_stder1 >$at_stderr
61078at_failed=false
61079echo stderr:; cat $at_stderr
61080echo stdout:; cat $at_stdout
61081case $at_status in
61082   77) echo 77 > $at_status_file
61083            exit 77;;
61084   0) ;;
61085   *) echo "cxx-type.at:427: exit code was $at_status, expected 0"
61086      at_failed=:;;
61087esac
61088if $at_failed; then
61089
61090  echo 1 > $at_status_file
61091  exit 1
61092fi
61093
61094$at_traceon
61095
61096
61097
61098
61099
61100
61101
61102
61103
61104
61105
61106
61107
61108
61109
61110
61111
61112
61113
61114
61115
61116
61117
61118$at_traceoff
61119echo "cxx-type.at:429: \$PREPARSER ./types test-input"
61120echo cxx-type.at:429 >$at_check_line_file
61121( $at_traceon; $PREPARSER ./types test-input ) >$at_stdout 2>$at_stder1
61122at_status=$?
61123grep '^ *+' $at_stder1 >&2
61124grep -v '^ *+' $at_stder1 >$at_stderr
61125at_failed=false
61126echo >>$at_stderr; echo "syntax error
61127" | $at_diff - $at_stderr || at_failed=:
61128echo >>$at_stdout; echo "+(z,q)
61129<declare>(T,x)
61130<init-declare>(T,x,y)
61131=(x,y)
61132+(<cast>(x,T),y)
61133<declare>(T,x)
61134<init-declare>(T,y,+(z,q))
61135<error>
61136+(z,q)
61137" | $at_diff - $at_stdout || at_failed=:
61138case $at_status in
61139   77) echo 77 > $at_status_file
61140            exit 77;;
61141   0) ;;
61142   *) echo "cxx-type.at:429: exit code was $at_status, expected 0"
61143      at_failed=:;;
61144esac
61145if $at_failed; then
61146
61147  echo 1 > $at_status_file
61148  exit 1
61149fi
61150
61151$at_traceon
61152
61153      $at_traceoff
61154      $at_times_p && times >$at_times_file
61155    ) 5>&1 2>&1 | eval $at_tee_pipe
61156    at_status=`cat $at_status_file`
61157    ;;
61158
61159  136 ) # 136. cxx-type.at:432: GLR: Resolve ambiguity, pure, locations
61160    at_setup_line='cxx-type.at:432'
61161    at_desc='GLR: Resolve ambiguity, pure, locations'
61162    $at_quiet $ECHO_N "136: GLR: Resolve ambiguity, pure, locations      $ECHO_C"
61163    at_xfail=no
61164    (
61165      echo "136. cxx-type.at:432: testing ..."
61166      $at_traceon
61167
61168
61169
61170
61171
61172
61173# Using yacc.c?
61174
61175
61176
61177
61178
61179
61180
61181# yyerror receives the location if %location & %pure & (%glr or %parse-param).
61182
61183# yyerror always sees the locations (when activated), except if
61184# yacc & pure & !param.
61185
61186
61187# The interface is pure: either because %pure-parser, or because we
61188# are using the C++ parsers.
61189
61190
61191
61192
61193
61194
61195
61196
61197
61198
61199
61200
61201cat >types.y <<'_ATEOF'
61202%{
61203#ifdef HAVE_CONFIG_H
61204# include <config.h>
61205  /* We don't need perfect functions for these tests. */
61206# undef malloc
61207# undef memcmp
61208# undef realloc
61209#endif
61210%}
61211
61212/* Simplified C++ Type and Expression Grammar.  */
61213
61214%pure-parser %locations
61215
61216%{
61217  #include <stdio.h>
61218  union Node {
61219    struct {
61220      int isNterm;
61221      int parents;
61222    } nodeInfo;
61223    struct {
61224      int isNterm; /* 1 */
61225      int parents;
61226      char const *form;
61227      union Node *children[3];
61228    } nterm;
61229    struct {
61230      int isNterm; /* 0 */
61231      int parents;
61232      char *text;
61233    } term;
61234  };
61235  typedef union Node Node;
61236  static Node *new_nterm (char const *, Node *, Node *, Node *);
61237  static Node *new_term (char *);
61238  static void free_node (Node *);
61239  static char *node_to_string (Node *);
61240  #define YYSTYPE Node *
61241
61242  #define YYINITDEPTH 10
61243  #define YYSTACKEXPANDABLE 1
61244  struct YYLTYPE;
61245#if YYPURE
61246# if YYLSP_NEEDED
61247#  define LEX_PARAMETERS YYSTYPE *lvalp, struct YYLTYPE *llocp
61248#  define ERROR_PARAMETERS struct YYLTYPE *llocp, char const *s
61249# else
61250#  define LEX_PARAMETERS YYSTYPE *lvalp
61251# endif
61252#endif
61253#ifndef LEX_PARAMETERS
61254# define LEX_PARAMETERS void
61255#endif
61256#ifndef ERROR_PARAMETERS
61257# define ERROR_PARAMETERS char const *s
61258#endif
61259  int yylex (LEX_PARAMETERS);
61260  void yyerror (ERROR_PARAMETERS);
61261%}
61262
61263%token TYPENAME ID
61264
61265%right '='
61266%left '+'
61267
61268%glr-parser
61269
61270%destructor { free_node ($$); } stmt expr decl declarator TYPENAME ID
61271
61272%%
61273
61274prog :
61275     | prog stmt   {
61276			char *output;
61277			printf ("%d.%d-%d.%d: ",
61278			     @2.first_line, @2.first_column,
61279			     @2.last_line, @2.last_column);
61280			output = node_to_string ($2);
61281			printf ("%s\n", output);
61282			free (output);
61283			free_node ($2);
61284		   }
61285     ;
61286
61287stmt : expr ';'  %dprec 1	{ $$ = $1; }
61288     | decl      %dprec 2
61289     | error ';'	{ $$ = new_nterm ("<error>", 0, 0, 0); }
61290     | '@'		{ YYACCEPT; }
61291     ;
61292
61293expr : ID
61294     | TYPENAME '(' expr ')'
61295			{ $$ = new_nterm ("<cast>(%s,%s)", $3, $1, 0); }
61296     | expr '+' expr	{ $$ = new_nterm ("+(%s,%s)", $1, $3, 0); }
61297     | expr '=' expr    { $$ = new_nterm ("=(%s,%s)", $1, $3, 0); }
61298     ;
61299
61300decl : TYPENAME declarator ';'
61301			{ $$ = new_nterm ("<declare>(%s,%s)", $1, $2, 0); }
61302     | TYPENAME declarator '=' expr ';'
61303			{ $$ = new_nterm ("<init-declare>(%s,%s,%s)", $1,
61304					  $2, $4); }
61305     ;
61306
61307declarator : ID
61308     | '(' declarator ')' { $$ = $2; }
61309     ;
61310
61311%%
61312
61313#include <ctype.h>
61314#include <stdlib.h>
61315#include <string.h>
61316#include <stdarg.h>
61317
61318int
61319main (int argc, char **argv)
61320{
61321  if (argc != 2)
61322    abort ();
61323  if (!freopen (argv[1], "r", stdin))
61324    return 3;
61325  return yyparse ();
61326}
61327
61328int
61329yylex (LEX_PARAMETERS)
61330{
61331  char buffer[256];
61332  int c;
61333  unsigned int i;
61334  static int lineNum = 1;
61335  static int colNum = 0;
61336
61337#if YYPURE
61338# undef yylloc
61339# define yylloc (*llocp)
61340# undef yylval
61341# define yylval (*lvalp)
61342#endif
61343
61344  while (1)
61345    {
61346      c = getchar ();
61347      switch (c)
61348	{
61349	case EOF:
61350	  return 0;
61351	case '\t':
61352	  colNum = (colNum + 7) & ~7;
61353	  break;
61354	case ' ': case '\f':
61355	  colNum += 1;
61356	  break;
61357	case '\n':
61358	  lineNum += 1;
61359	  colNum = 0;
61360	  break;
61361	default:
61362	  {
61363	    int tok;
61364#if YYLSP_NEEDED
61365	    yylloc.first_line = yylloc.last_line = lineNum;
61366	    yylloc.first_column = colNum;
61367#endif
61368	    if (isalpha (c))
61369	      {
61370		i = 0;
61371
61372		do
61373		  {
61374		    buffer[i++] = c;
61375		    colNum += 1;
61376		    if (i == sizeof buffer - 1)
61377		      abort ();
61378		    c = getchar ();
61379		  }
61380		while (isalnum (c) || c == '_');
61381
61382		ungetc (c, stdin);
61383		buffer[i++] = 0;
61384		tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
61385		yylval = new_term (strcpy ((char *) malloc (i), buffer));
61386	      }
61387	    else
61388	      {
61389		colNum += 1;
61390		tok = c;
61391		yylval = 0;
61392	      }
61393#if YYLSP_NEEDED
61394	    yylloc.last_column = colNum-1;
61395#endif
61396	    return tok;
61397	  }
61398	}
61399    }
61400}
61401
61402void
61403yyerror (ERROR_PARAMETERS)
61404{
61405#if YYPURE && YYLSP_NEEDED
61406  /* Pacify GCC by using llocp.  */
61407  if (! llocp)
61408    abort ();
61409#endif
61410  fprintf (stderr, "%s\n", s);
61411}
61412
61413static Node *
61414new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
61415{
61416  Node *node = (Node *) malloc (sizeof (Node));
61417  node->nterm.isNterm = 1;
61418  node->nterm.parents = 0;
61419  node->nterm.form = form;
61420  node->nterm.children[0] = child0;
61421  if (child0)
61422    child0->nodeInfo.parents += 1;
61423  node->nterm.children[1] = child1;
61424  if (child1)
61425    child1->nodeInfo.parents += 1;
61426  node->nterm.children[2] = child2;
61427  if (child2)
61428    child2->nodeInfo.parents += 1;
61429  return node;
61430}
61431
61432static Node *
61433new_term (char *text)
61434{
61435  Node *node = (Node *) malloc (sizeof (Node));
61436  node->term.isNterm = 0;
61437  node->term.parents = 0;
61438  node->term.text = text;
61439  return node;
61440}
61441
61442static void
61443free_node (Node *node)
61444{
61445  if (!node)
61446    return;
61447  node->nodeInfo.parents -= 1;
61448  /* Free only if 0 (last parent) or -1 (no parents).  */
61449  if (node->nodeInfo.parents > 0)
61450    return;
61451  if (node->nodeInfo.isNterm == 1)
61452    {
61453      free_node (node->nterm.children[0]);
61454      free_node (node->nterm.children[1]);
61455      free_node (node->nterm.children[2]);
61456    }
61457  else
61458    free (node->term.text);
61459  free (node);
61460}
61461
61462static char *
61463node_to_string (Node *node)
61464{
61465  char *child0;
61466  char *child1;
61467  char *child2;
61468  char *buffer;
61469  if (!node)
61470    {
61471      buffer = (char *) malloc (1);
61472      buffer[0] = 0;
61473    }
61474  else if (node->nodeInfo.isNterm == 1)
61475    {
61476      child0 = node_to_string (node->nterm.children[0]);
61477      child1 = node_to_string (node->nterm.children[1]);
61478      child2 = node_to_string (node->nterm.children[2]);
61479      buffer = (char *) malloc (strlen (node->nterm.form) + strlen (child0)
61480				+ strlen (child1) + strlen (child2) + 1);
61481      sprintf (buffer, node->nterm.form, child0, child1, child2);
61482      free (child0);
61483      free (child1);
61484      free (child2);
61485    }
61486  else
61487    buffer = strdup (node->term.text);
61488  return buffer;
61489}
61490
61491
61492
61493_ATEOF
61494
61495
61496
61497cat >test-input <<'_ATEOF'
61498
61499
61500z + q;
61501
61502T x;
61503
61504T x = y;
61505
61506x = y;
61507
61508T (x) + y;
61509
61510T (x);
61511
61512T (y) = z + q;
61513
61514T (y y) = z + q;
61515
61516z + q;
61517
61518@
61519
61520This is total garbage, but it should be ignored.
61521_ATEOF
61522
61523
61524$at_traceoff
61525echo "cxx-type.at:434: bison -o types.c types.y"
61526echo cxx-type.at:434 >$at_check_line_file
61527( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
61528at_status=$?
61529grep '^ *+' $at_stder1 >&2
61530grep -v '^ *+' $at_stder1 >$at_stderr
61531at_failed=false
61532echo stderr:; cat $at_stderr
61533$at_diff $at_devnull $at_stdout || at_failed=:
61534case $at_status in
61535   77) echo 77 > $at_status_file
61536            exit 77;;
61537   0) ;;
61538   *) echo "cxx-type.at:434: exit code was $at_status, expected 0"
61539      at_failed=:;;
61540esac
61541if $at_failed; then
61542
61543  echo 1 > $at_status_file
61544  exit 1
61545fi
61546
61547$at_traceon
61548
61549$at_traceoff
61550echo "cxx-type.at:434: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o types types.c \$LIBS"
61551echo cxx-type.at:434 >$at_check_line_file
61552( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o types types.c $LIBS ) >$at_stdout 2>$at_stder1
61553at_status=$?
61554grep '^ *+' $at_stder1 >&2
61555grep -v '^ *+' $at_stder1 >$at_stderr
61556at_failed=false
61557echo stderr:; cat $at_stderr
61558echo stdout:; cat $at_stdout
61559case $at_status in
61560   77) echo 77 > $at_status_file
61561            exit 77;;
61562   0) ;;
61563   *) echo "cxx-type.at:434: exit code was $at_status, expected 0"
61564      at_failed=:;;
61565esac
61566if $at_failed; then
61567
61568  echo 1 > $at_status_file
61569  exit 1
61570fi
61571
61572$at_traceon
61573
61574
61575
61576
61577
61578
61579
61580
61581
61582
61583
61584
61585
61586
61587
61588
61589
61590
61591
61592
61593
61594
61595
61596$at_traceoff
61597echo "cxx-type.at:436: \$PREPARSER ./types test-input"
61598echo cxx-type.at:436 >$at_check_line_file
61599( $at_traceon; $PREPARSER ./types test-input ) >$at_stdout 2>$at_stder1
61600at_status=$?
61601grep '^ *+' $at_stder1 >&2
61602grep -v '^ *+' $at_stder1 >$at_stderr
61603at_failed=false
61604echo >>$at_stderr; echo "syntax error
61605" | $at_diff - $at_stderr || at_failed=:
61606echo >>$at_stdout; echo "3.0-3.5: +(z,q)
616075.0-5.3: <declare>(T,x)
616087.0-7.7: <init-declare>(T,x,y)
616099.0-9.5: =(x,y)
6161011.0-11.9: +(<cast>(x,T),y)
6161113.0-13.5: <declare>(T,x)
6161215.0-15.13: <init-declare>(T,y,+(z,q))
6161317.0-17.15: <error>
6161419.0-19.5: +(z,q)
61615" | $at_diff - $at_stdout || at_failed=:
61616case $at_status in
61617   77) echo 77 > $at_status_file
61618            exit 77;;
61619   0) ;;
61620   *) echo "cxx-type.at:436: exit code was $at_status, expected 0"
61621      at_failed=:;;
61622esac
61623if $at_failed; then
61624
61625  echo 1 > $at_status_file
61626  exit 1
61627fi
61628
61629$at_traceon
61630
61631      $at_traceoff
61632      $at_times_p && times >$at_times_file
61633    ) 5>&1 2>&1 | eval $at_tee_pipe
61634    at_status=`cat $at_status_file`
61635    ;;
61636
61637  137 ) # 137. cxx-type.at:439: GLR: Merge conflicting parses, impure, no locations
61638    at_setup_line='cxx-type.at:439'
61639    at_desc='GLR: Merge conflicting parses, impure, no locations'
61640    $at_quiet $ECHO_N "137: GLR: Merge conflicting parses, impure, no locations$ECHO_C"
61641    at_xfail=no
61642    (
61643      echo "137. cxx-type.at:439: testing ..."
61644      $at_traceon
61645
61646
61647
61648
61649
61650
61651# Using yacc.c?
61652
61653
61654
61655
61656
61657
61658
61659# yyerror receives the location if %location & %pure & (%glr or %parse-param).
61660
61661# yyerror always sees the locations (when activated), except if
61662# yacc & pure & !param.
61663
61664
61665# The interface is pure: either because %pure-parser, or because we
61666# are using the C++ parsers.
61667
61668
61669
61670
61671
61672
61673
61674
61675
61676
61677
61678
61679cat >types.y <<'_ATEOF'
61680%{
61681#ifdef HAVE_CONFIG_H
61682# include <config.h>
61683  /* We don't need perfect functions for these tests. */
61684# undef malloc
61685# undef memcmp
61686# undef realloc
61687#endif
61688%}
61689
61690/* Simplified C++ Type and Expression Grammar.  */
61691
61692
61693
61694%{
61695  #include <stdio.h>
61696  union Node {
61697    struct {
61698      int isNterm;
61699      int parents;
61700    } nodeInfo;
61701    struct {
61702      int isNterm; /* 1 */
61703      int parents;
61704      char const *form;
61705      union Node *children[3];
61706    } nterm;
61707    struct {
61708      int isNterm; /* 0 */
61709      int parents;
61710      char *text;
61711    } term;
61712  };
61713  typedef union Node Node;
61714  static Node *new_nterm (char const *, Node *, Node *, Node *);
61715  static Node *new_term (char *);
61716  static void free_node (Node *);
61717  static char *node_to_string (Node *);
61718  #define YYSTYPE Node *
61719 static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);
61720  #define YYINITDEPTH 10
61721  #define YYSTACKEXPANDABLE 1
61722  struct YYLTYPE;
61723#if YYPURE
61724# if YYLSP_NEEDED
61725#  define LEX_PARAMETERS YYSTYPE *lvalp, struct YYLTYPE *llocp
61726#  define ERROR_PARAMETERS struct YYLTYPE *llocp, char const *s
61727# else
61728#  define LEX_PARAMETERS YYSTYPE *lvalp
61729# endif
61730#endif
61731#ifndef LEX_PARAMETERS
61732# define LEX_PARAMETERS void
61733#endif
61734#ifndef ERROR_PARAMETERS
61735# define ERROR_PARAMETERS char const *s
61736#endif
61737  int yylex (LEX_PARAMETERS);
61738  void yyerror (ERROR_PARAMETERS);
61739%}
61740
61741%token TYPENAME ID
61742
61743%right '='
61744%left '+'
61745
61746%glr-parser
61747
61748%destructor { free_node ($$); } stmt expr decl declarator TYPENAME ID
61749
61750%%
61751
61752prog :
61753     | prog stmt   {
61754			char *output;
61755			output = node_to_string ($2);
61756			printf ("%s\n", output);
61757			free (output);
61758			free_node ($2);
61759		   }
61760     ;
61761
61762stmt : expr ';'  %merge <stmtMerge>	{ $$ = $1; }
61763     | decl      %merge <stmtMerge>
61764     | error ';'	{ $$ = new_nterm ("<error>", 0, 0, 0); }
61765     | '@'		{ YYACCEPT; }
61766     ;
61767
61768expr : ID
61769     | TYPENAME '(' expr ')'
61770			{ $$ = new_nterm ("<cast>(%s,%s)", $3, $1, 0); }
61771     | expr '+' expr	{ $$ = new_nterm ("+(%s,%s)", $1, $3, 0); }
61772     | expr '=' expr    { $$ = new_nterm ("=(%s,%s)", $1, $3, 0); }
61773     ;
61774
61775decl : TYPENAME declarator ';'
61776			{ $$ = new_nterm ("<declare>(%s,%s)", $1, $2, 0); }
61777     | TYPENAME declarator '=' expr ';'
61778			{ $$ = new_nterm ("<init-declare>(%s,%s,%s)", $1,
61779					  $2, $4); }
61780     ;
61781
61782declarator : ID
61783     | '(' declarator ')' { $$ = $2; }
61784     ;
61785
61786%%
61787
61788#include <ctype.h>
61789#include <stdlib.h>
61790#include <string.h>
61791#include <stdarg.h>
61792
61793int
61794main (int argc, char **argv)
61795{
61796  if (argc != 2)
61797    abort ();
61798  if (!freopen (argv[1], "r", stdin))
61799    return 3;
61800  return yyparse ();
61801}
61802
61803int
61804yylex (LEX_PARAMETERS)
61805{
61806  char buffer[256];
61807  int c;
61808  unsigned int i;
61809  static int lineNum = 1;
61810  static int colNum = 0;
61811
61812#if YYPURE
61813# undef yylloc
61814# define yylloc (*llocp)
61815# undef yylval
61816# define yylval (*lvalp)
61817#endif
61818
61819  while (1)
61820    {
61821      c = getchar ();
61822      switch (c)
61823	{
61824	case EOF:
61825	  return 0;
61826	case '\t':
61827	  colNum = (colNum + 7) & ~7;
61828	  break;
61829	case ' ': case '\f':
61830	  colNum += 1;
61831	  break;
61832	case '\n':
61833	  lineNum += 1;
61834	  colNum = 0;
61835	  break;
61836	default:
61837	  {
61838	    int tok;
61839#if YYLSP_NEEDED
61840	    yylloc.first_line = yylloc.last_line = lineNum;
61841	    yylloc.first_column = colNum;
61842#endif
61843	    if (isalpha (c))
61844	      {
61845		i = 0;
61846
61847		do
61848		  {
61849		    buffer[i++] = c;
61850		    colNum += 1;
61851		    if (i == sizeof buffer - 1)
61852		      abort ();
61853		    c = getchar ();
61854		  }
61855		while (isalnum (c) || c == '_');
61856
61857		ungetc (c, stdin);
61858		buffer[i++] = 0;
61859		tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
61860		yylval = new_term (strcpy ((char *) malloc (i), buffer));
61861	      }
61862	    else
61863	      {
61864		colNum += 1;
61865		tok = c;
61866		yylval = 0;
61867	      }
61868#if YYLSP_NEEDED
61869	    yylloc.last_column = colNum-1;
61870#endif
61871	    return tok;
61872	  }
61873	}
61874    }
61875}
61876
61877void
61878yyerror (ERROR_PARAMETERS)
61879{
61880#if YYPURE && YYLSP_NEEDED
61881  /* Pacify GCC by using llocp.  */
61882  if (! llocp)
61883    abort ();
61884#endif
61885  fprintf (stderr, "%s\n", s);
61886}
61887
61888static Node *
61889new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
61890{
61891  Node *node = (Node *) malloc (sizeof (Node));
61892  node->nterm.isNterm = 1;
61893  node->nterm.parents = 0;
61894  node->nterm.form = form;
61895  node->nterm.children[0] = child0;
61896  if (child0)
61897    child0->nodeInfo.parents += 1;
61898  node->nterm.children[1] = child1;
61899  if (child1)
61900    child1->nodeInfo.parents += 1;
61901  node->nterm.children[2] = child2;
61902  if (child2)
61903    child2->nodeInfo.parents += 1;
61904  return node;
61905}
61906
61907static Node *
61908new_term (char *text)
61909{
61910  Node *node = (Node *) malloc (sizeof (Node));
61911  node->term.isNterm = 0;
61912  node->term.parents = 0;
61913  node->term.text = text;
61914  return node;
61915}
61916
61917static void
61918free_node (Node *node)
61919{
61920  if (!node)
61921    return;
61922  node->nodeInfo.parents -= 1;
61923  /* Free only if 0 (last parent) or -1 (no parents).  */
61924  if (node->nodeInfo.parents > 0)
61925    return;
61926  if (node->nodeInfo.isNterm == 1)
61927    {
61928      free_node (node->nterm.children[0]);
61929      free_node (node->nterm.children[1]);
61930      free_node (node->nterm.children[2]);
61931    }
61932  else
61933    free (node->term.text);
61934  free (node);
61935}
61936
61937static char *
61938node_to_string (Node *node)
61939{
61940  char *child0;
61941  char *child1;
61942  char *child2;
61943  char *buffer;
61944  if (!node)
61945    {
61946      buffer = (char *) malloc (1);
61947      buffer[0] = 0;
61948    }
61949  else if (node->nodeInfo.isNterm == 1)
61950    {
61951      child0 = node_to_string (node->nterm.children[0]);
61952      child1 = node_to_string (node->nterm.children[1]);
61953      child2 = node_to_string (node->nterm.children[2]);
61954      buffer = (char *) malloc (strlen (node->nterm.form) + strlen (child0)
61955				+ strlen (child1) + strlen (child2) + 1);
61956      sprintf (buffer, node->nterm.form, child0, child1, child2);
61957      free (child0);
61958      free (child1);
61959      free (child2);
61960    }
61961  else
61962    buffer = strdup (node->term.text);
61963  return buffer;
61964}
61965
61966
61967static YYSTYPE
61968stmtMerge (YYSTYPE x0, YYSTYPE x1)
61969{
61970  return new_nterm ("<OR>(%s,%s)", x0, x1, 0);
61971}
61972
61973_ATEOF
61974
61975
61976
61977cat >test-input <<'_ATEOF'
61978
61979
61980z + q;
61981
61982T x;
61983
61984T x = y;
61985
61986x = y;
61987
61988T (x) + y;
61989
61990T (x);
61991
61992T (y) = z + q;
61993
61994T (y y) = z + q;
61995
61996z + q;
61997
61998@
61999
62000This is total garbage, but it should be ignored.
62001_ATEOF
62002
62003
62004$at_traceoff
62005echo "cxx-type.at:441: bison -o types.c types.y"
62006echo cxx-type.at:441 >$at_check_line_file
62007( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
62008at_status=$?
62009grep '^ *+' $at_stder1 >&2
62010grep -v '^ *+' $at_stder1 >$at_stderr
62011at_failed=false
62012echo stderr:; cat $at_stderr
62013$at_diff $at_devnull $at_stdout || at_failed=:
62014case $at_status in
62015   77) echo 77 > $at_status_file
62016            exit 77;;
62017   0) ;;
62018   *) echo "cxx-type.at:441: exit code was $at_status, expected 0"
62019      at_failed=:;;
62020esac
62021if $at_failed; then
62022
62023  echo 1 > $at_status_file
62024  exit 1
62025fi
62026
62027$at_traceon
62028
62029$at_traceoff
62030echo "cxx-type.at:441: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o types types.c \$LIBS"
62031echo cxx-type.at:441 >$at_check_line_file
62032( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o types types.c $LIBS ) >$at_stdout 2>$at_stder1
62033at_status=$?
62034grep '^ *+' $at_stder1 >&2
62035grep -v '^ *+' $at_stder1 >$at_stderr
62036at_failed=false
62037echo stderr:; cat $at_stderr
62038echo stdout:; cat $at_stdout
62039case $at_status in
62040   77) echo 77 > $at_status_file
62041            exit 77;;
62042   0) ;;
62043   *) echo "cxx-type.at:441: exit code was $at_status, expected 0"
62044      at_failed=:;;
62045esac
62046if $at_failed; then
62047
62048  echo 1 > $at_status_file
62049  exit 1
62050fi
62051
62052$at_traceon
62053
62054
62055
62056
62057
62058
62059
62060
62061
62062
62063
62064
62065
62066
62067
62068
62069
62070
62071
62072
62073
62074
62075
62076$at_traceoff
62077echo "cxx-type.at:443: \$PREPARSER ./types test-input"
62078echo cxx-type.at:443 >$at_check_line_file
62079( $at_traceon; $PREPARSER ./types test-input ) >$at_stdout 2>$at_stder1
62080at_status=$?
62081grep '^ *+' $at_stder1 >&2
62082grep -v '^ *+' $at_stder1 >$at_stderr
62083at_failed=false
62084echo >>$at_stderr; echo "syntax error
62085" | $at_diff - $at_stderr || at_failed=:
62086echo >>$at_stdout; echo "+(z,q)
62087<declare>(T,x)
62088<init-declare>(T,x,y)
62089=(x,y)
62090+(<cast>(x,T),y)
62091<OR>(<declare>(T,x),<cast>(x,T))
62092<OR>(<init-declare>(T,y,+(z,q)),=(<cast>(y,T),+(z,q)))
62093<error>
62094+(z,q)
62095" | $at_diff - $at_stdout || at_failed=:
62096case $at_status in
62097   77) echo 77 > $at_status_file
62098            exit 77;;
62099   0) ;;
62100   *) echo "cxx-type.at:443: exit code was $at_status, expected 0"
62101      at_failed=:;;
62102esac
62103if $at_failed; then
62104
62105  echo 1 > $at_status_file
62106  exit 1
62107fi
62108
62109$at_traceon
62110
62111      $at_traceoff
62112      $at_times_p && times >$at_times_file
62113    ) 5>&1 2>&1 | eval $at_tee_pipe
62114    at_status=`cat $at_status_file`
62115    ;;
62116
62117  138 ) # 138. cxx-type.at:446: GLR: Merge conflicting parses, impure, locations
62118    at_setup_line='cxx-type.at:446'
62119    at_desc='GLR: Merge conflicting parses, impure, locations'
62120    $at_quiet $ECHO_N "138: GLR: Merge conflicting parses, impure, locations$ECHO_C"
62121    at_xfail=no
62122    (
62123      echo "138. cxx-type.at:446: testing ..."
62124      $at_traceon
62125
62126
62127
62128
62129
62130
62131# Using yacc.c?
62132
62133
62134
62135
62136
62137
62138
62139# yyerror receives the location if %location & %pure & (%glr or %parse-param).
62140
62141# yyerror always sees the locations (when activated), except if
62142# yacc & pure & !param.
62143
62144
62145# The interface is pure: either because %pure-parser, or because we
62146# are using the C++ parsers.
62147
62148
62149
62150
62151
62152
62153
62154
62155
62156
62157
62158
62159cat >types.y <<'_ATEOF'
62160%{
62161#ifdef HAVE_CONFIG_H
62162# include <config.h>
62163  /* We don't need perfect functions for these tests. */
62164# undef malloc
62165# undef memcmp
62166# undef realloc
62167#endif
62168%}
62169
62170/* Simplified C++ Type and Expression Grammar.  */
62171
62172%locations
62173
62174%{
62175  #include <stdio.h>
62176  union Node {
62177    struct {
62178      int isNterm;
62179      int parents;
62180    } nodeInfo;
62181    struct {
62182      int isNterm; /* 1 */
62183      int parents;
62184      char const *form;
62185      union Node *children[3];
62186    } nterm;
62187    struct {
62188      int isNterm; /* 0 */
62189      int parents;
62190      char *text;
62191    } term;
62192  };
62193  typedef union Node Node;
62194  static Node *new_nterm (char const *, Node *, Node *, Node *);
62195  static Node *new_term (char *);
62196  static void free_node (Node *);
62197  static char *node_to_string (Node *);
62198  #define YYSTYPE Node *
62199 static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);
62200  #define YYINITDEPTH 10
62201  #define YYSTACKEXPANDABLE 1
62202  struct YYLTYPE;
62203#if YYPURE
62204# if YYLSP_NEEDED
62205#  define LEX_PARAMETERS YYSTYPE *lvalp, struct YYLTYPE *llocp
62206#  define ERROR_PARAMETERS struct YYLTYPE *llocp, char const *s
62207# else
62208#  define LEX_PARAMETERS YYSTYPE *lvalp
62209# endif
62210#endif
62211#ifndef LEX_PARAMETERS
62212# define LEX_PARAMETERS void
62213#endif
62214#ifndef ERROR_PARAMETERS
62215# define ERROR_PARAMETERS char const *s
62216#endif
62217  int yylex (LEX_PARAMETERS);
62218  void yyerror (ERROR_PARAMETERS);
62219%}
62220
62221%token TYPENAME ID
62222
62223%right '='
62224%left '+'
62225
62226%glr-parser
62227
62228%destructor { free_node ($$); } stmt expr decl declarator TYPENAME ID
62229
62230%%
62231
62232prog :
62233     | prog stmt   {
62234			char *output;
62235			printf ("%d.%d-%d.%d: ",
62236			     @2.first_line, @2.first_column,
62237			     @2.last_line, @2.last_column);
62238			output = node_to_string ($2);
62239			printf ("%s\n", output);
62240			free (output);
62241			free_node ($2);
62242		   }
62243     ;
62244
62245stmt : expr ';'  %merge <stmtMerge>	{ $$ = $1; }
62246     | decl      %merge <stmtMerge>
62247     | error ';'	{ $$ = new_nterm ("<error>", 0, 0, 0); }
62248     | '@'		{ YYACCEPT; }
62249     ;
62250
62251expr : ID
62252     | TYPENAME '(' expr ')'
62253			{ $$ = new_nterm ("<cast>(%s,%s)", $3, $1, 0); }
62254     | expr '+' expr	{ $$ = new_nterm ("+(%s,%s)", $1, $3, 0); }
62255     | expr '=' expr    { $$ = new_nterm ("=(%s,%s)", $1, $3, 0); }
62256     ;
62257
62258decl : TYPENAME declarator ';'
62259			{ $$ = new_nterm ("<declare>(%s,%s)", $1, $2, 0); }
62260     | TYPENAME declarator '=' expr ';'
62261			{ $$ = new_nterm ("<init-declare>(%s,%s,%s)", $1,
62262					  $2, $4); }
62263     ;
62264
62265declarator : ID
62266     | '(' declarator ')' { $$ = $2; }
62267     ;
62268
62269%%
62270
62271#include <ctype.h>
62272#include <stdlib.h>
62273#include <string.h>
62274#include <stdarg.h>
62275
62276int
62277main (int argc, char **argv)
62278{
62279  if (argc != 2)
62280    abort ();
62281  if (!freopen (argv[1], "r", stdin))
62282    return 3;
62283  return yyparse ();
62284}
62285
62286int
62287yylex (LEX_PARAMETERS)
62288{
62289  char buffer[256];
62290  int c;
62291  unsigned int i;
62292  static int lineNum = 1;
62293  static int colNum = 0;
62294
62295#if YYPURE
62296# undef yylloc
62297# define yylloc (*llocp)
62298# undef yylval
62299# define yylval (*lvalp)
62300#endif
62301
62302  while (1)
62303    {
62304      c = getchar ();
62305      switch (c)
62306	{
62307	case EOF:
62308	  return 0;
62309	case '\t':
62310	  colNum = (colNum + 7) & ~7;
62311	  break;
62312	case ' ': case '\f':
62313	  colNum += 1;
62314	  break;
62315	case '\n':
62316	  lineNum += 1;
62317	  colNum = 0;
62318	  break;
62319	default:
62320	  {
62321	    int tok;
62322#if YYLSP_NEEDED
62323	    yylloc.first_line = yylloc.last_line = lineNum;
62324	    yylloc.first_column = colNum;
62325#endif
62326	    if (isalpha (c))
62327	      {
62328		i = 0;
62329
62330		do
62331		  {
62332		    buffer[i++] = c;
62333		    colNum += 1;
62334		    if (i == sizeof buffer - 1)
62335		      abort ();
62336		    c = getchar ();
62337		  }
62338		while (isalnum (c) || c == '_');
62339
62340		ungetc (c, stdin);
62341		buffer[i++] = 0;
62342		tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
62343		yylval = new_term (strcpy ((char *) malloc (i), buffer));
62344	      }
62345	    else
62346	      {
62347		colNum += 1;
62348		tok = c;
62349		yylval = 0;
62350	      }
62351#if YYLSP_NEEDED
62352	    yylloc.last_column = colNum-1;
62353#endif
62354	    return tok;
62355	  }
62356	}
62357    }
62358}
62359
62360void
62361yyerror (ERROR_PARAMETERS)
62362{
62363#if YYPURE && YYLSP_NEEDED
62364  /* Pacify GCC by using llocp.  */
62365  if (! llocp)
62366    abort ();
62367#endif
62368  fprintf (stderr, "%s\n", s);
62369}
62370
62371static Node *
62372new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
62373{
62374  Node *node = (Node *) malloc (sizeof (Node));
62375  node->nterm.isNterm = 1;
62376  node->nterm.parents = 0;
62377  node->nterm.form = form;
62378  node->nterm.children[0] = child0;
62379  if (child0)
62380    child0->nodeInfo.parents += 1;
62381  node->nterm.children[1] = child1;
62382  if (child1)
62383    child1->nodeInfo.parents += 1;
62384  node->nterm.children[2] = child2;
62385  if (child2)
62386    child2->nodeInfo.parents += 1;
62387  return node;
62388}
62389
62390static Node *
62391new_term (char *text)
62392{
62393  Node *node = (Node *) malloc (sizeof (Node));
62394  node->term.isNterm = 0;
62395  node->term.parents = 0;
62396  node->term.text = text;
62397  return node;
62398}
62399
62400static void
62401free_node (Node *node)
62402{
62403  if (!node)
62404    return;
62405  node->nodeInfo.parents -= 1;
62406  /* Free only if 0 (last parent) or -1 (no parents).  */
62407  if (node->nodeInfo.parents > 0)
62408    return;
62409  if (node->nodeInfo.isNterm == 1)
62410    {
62411      free_node (node->nterm.children[0]);
62412      free_node (node->nterm.children[1]);
62413      free_node (node->nterm.children[2]);
62414    }
62415  else
62416    free (node->term.text);
62417  free (node);
62418}
62419
62420static char *
62421node_to_string (Node *node)
62422{
62423  char *child0;
62424  char *child1;
62425  char *child2;
62426  char *buffer;
62427  if (!node)
62428    {
62429      buffer = (char *) malloc (1);
62430      buffer[0] = 0;
62431    }
62432  else if (node->nodeInfo.isNterm == 1)
62433    {
62434      child0 = node_to_string (node->nterm.children[0]);
62435      child1 = node_to_string (node->nterm.children[1]);
62436      child2 = node_to_string (node->nterm.children[2]);
62437      buffer = (char *) malloc (strlen (node->nterm.form) + strlen (child0)
62438				+ strlen (child1) + strlen (child2) + 1);
62439      sprintf (buffer, node->nterm.form, child0, child1, child2);
62440      free (child0);
62441      free (child1);
62442      free (child2);
62443    }
62444  else
62445    buffer = strdup (node->term.text);
62446  return buffer;
62447}
62448
62449
62450static YYSTYPE
62451stmtMerge (YYSTYPE x0, YYSTYPE x1)
62452{
62453  return new_nterm ("<OR>(%s,%s)", x0, x1, 0);
62454}
62455
62456_ATEOF
62457
62458
62459
62460cat >test-input <<'_ATEOF'
62461
62462
62463z + q;
62464
62465T x;
62466
62467T x = y;
62468
62469x = y;
62470
62471T (x) + y;
62472
62473T (x);
62474
62475T (y) = z + q;
62476
62477T (y y) = z + q;
62478
62479z + q;
62480
62481@
62482
62483This is total garbage, but it should be ignored.
62484_ATEOF
62485
62486
62487$at_traceoff
62488echo "cxx-type.at:448: bison -o types.c types.y"
62489echo cxx-type.at:448 >$at_check_line_file
62490( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
62491at_status=$?
62492grep '^ *+' $at_stder1 >&2
62493grep -v '^ *+' $at_stder1 >$at_stderr
62494at_failed=false
62495echo stderr:; cat $at_stderr
62496$at_diff $at_devnull $at_stdout || at_failed=:
62497case $at_status in
62498   77) echo 77 > $at_status_file
62499            exit 77;;
62500   0) ;;
62501   *) echo "cxx-type.at:448: exit code was $at_status, expected 0"
62502      at_failed=:;;
62503esac
62504if $at_failed; then
62505
62506  echo 1 > $at_status_file
62507  exit 1
62508fi
62509
62510$at_traceon
62511
62512$at_traceoff
62513echo "cxx-type.at:448: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o types types.c \$LIBS"
62514echo cxx-type.at:448 >$at_check_line_file
62515( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o types types.c $LIBS ) >$at_stdout 2>$at_stder1
62516at_status=$?
62517grep '^ *+' $at_stder1 >&2
62518grep -v '^ *+' $at_stder1 >$at_stderr
62519at_failed=false
62520echo stderr:; cat $at_stderr
62521echo stdout:; cat $at_stdout
62522case $at_status in
62523   77) echo 77 > $at_status_file
62524            exit 77;;
62525   0) ;;
62526   *) echo "cxx-type.at:448: exit code was $at_status, expected 0"
62527      at_failed=:;;
62528esac
62529if $at_failed; then
62530
62531  echo 1 > $at_status_file
62532  exit 1
62533fi
62534
62535$at_traceon
62536
62537
62538
62539
62540
62541
62542
62543
62544
62545
62546
62547
62548
62549
62550
62551
62552
62553
62554
62555
62556
62557
62558
62559$at_traceoff
62560echo "cxx-type.at:450: \$PREPARSER ./types test-input"
62561echo cxx-type.at:450 >$at_check_line_file
62562( $at_traceon; $PREPARSER ./types test-input ) >$at_stdout 2>$at_stder1
62563at_status=$?
62564grep '^ *+' $at_stder1 >&2
62565grep -v '^ *+' $at_stder1 >$at_stderr
62566at_failed=false
62567echo >>$at_stderr; echo "syntax error
62568" | $at_diff - $at_stderr || at_failed=:
62569echo >>$at_stdout; echo "3.0-3.5: +(z,q)
625705.0-5.3: <declare>(T,x)
625717.0-7.7: <init-declare>(T,x,y)
625729.0-9.5: =(x,y)
6257311.0-11.9: +(<cast>(x,T),y)
6257413.0-13.5: <OR>(<declare>(T,x),<cast>(x,T))
6257515.0-15.13: <OR>(<init-declare>(T,y,+(z,q)),=(<cast>(y,T),+(z,q)))
6257617.0-17.15: <error>
6257719.0-19.5: +(z,q)
62578" | $at_diff - $at_stdout || at_failed=:
62579case $at_status in
62580   77) echo 77 > $at_status_file
62581            exit 77;;
62582   0) ;;
62583   *) echo "cxx-type.at:450: exit code was $at_status, expected 0"
62584      at_failed=:;;
62585esac
62586if $at_failed; then
62587
62588  echo 1 > $at_status_file
62589  exit 1
62590fi
62591
62592$at_traceon
62593
62594      $at_traceoff
62595      $at_times_p && times >$at_times_file
62596    ) 5>&1 2>&1 | eval $at_tee_pipe
62597    at_status=`cat $at_status_file`
62598    ;;
62599
62600  139 ) # 139. cxx-type.at:453: GLR: Merge conflicting parses, pure, no locations
62601    at_setup_line='cxx-type.at:453'
62602    at_desc='GLR: Merge conflicting parses, pure, no locations'
62603    $at_quiet $ECHO_N "139: GLR: Merge conflicting parses, pure, no locations$ECHO_C"
62604    at_xfail=no
62605    (
62606      echo "139. cxx-type.at:453: testing ..."
62607      $at_traceon
62608
62609
62610
62611
62612
62613
62614# Using yacc.c?
62615
62616
62617
62618
62619
62620
62621
62622# yyerror receives the location if %location & %pure & (%glr or %parse-param).
62623
62624# yyerror always sees the locations (when activated), except if
62625# yacc & pure & !param.
62626
62627
62628# The interface is pure: either because %pure-parser, or because we
62629# are using the C++ parsers.
62630
62631
62632
62633
62634
62635
62636
62637
62638
62639
62640
62641
62642cat >types.y <<'_ATEOF'
62643%{
62644#ifdef HAVE_CONFIG_H
62645# include <config.h>
62646  /* We don't need perfect functions for these tests. */
62647# undef malloc
62648# undef memcmp
62649# undef realloc
62650#endif
62651%}
62652
62653/* Simplified C++ Type and Expression Grammar.  */
62654
62655%pure-parser
62656
62657%{
62658  #include <stdio.h>
62659  union Node {
62660    struct {
62661      int isNterm;
62662      int parents;
62663    } nodeInfo;
62664    struct {
62665      int isNterm; /* 1 */
62666      int parents;
62667      char const *form;
62668      union Node *children[3];
62669    } nterm;
62670    struct {
62671      int isNterm; /* 0 */
62672      int parents;
62673      char *text;
62674    } term;
62675  };
62676  typedef union Node Node;
62677  static Node *new_nterm (char const *, Node *, Node *, Node *);
62678  static Node *new_term (char *);
62679  static void free_node (Node *);
62680  static char *node_to_string (Node *);
62681  #define YYSTYPE Node *
62682 static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);
62683  #define YYINITDEPTH 10
62684  #define YYSTACKEXPANDABLE 1
62685  struct YYLTYPE;
62686#if YYPURE
62687# if YYLSP_NEEDED
62688#  define LEX_PARAMETERS YYSTYPE *lvalp, struct YYLTYPE *llocp
62689#  define ERROR_PARAMETERS struct YYLTYPE *llocp, char const *s
62690# else
62691#  define LEX_PARAMETERS YYSTYPE *lvalp
62692# endif
62693#endif
62694#ifndef LEX_PARAMETERS
62695# define LEX_PARAMETERS void
62696#endif
62697#ifndef ERROR_PARAMETERS
62698# define ERROR_PARAMETERS char const *s
62699#endif
62700  int yylex (LEX_PARAMETERS);
62701  void yyerror (ERROR_PARAMETERS);
62702%}
62703
62704%token TYPENAME ID
62705
62706%right '='
62707%left '+'
62708
62709%glr-parser
62710
62711%destructor { free_node ($$); } stmt expr decl declarator TYPENAME ID
62712
62713%%
62714
62715prog :
62716     | prog stmt   {
62717			char *output;
62718			output = node_to_string ($2);
62719			printf ("%s\n", output);
62720			free (output);
62721			free_node ($2);
62722		   }
62723     ;
62724
62725stmt : expr ';'  %merge <stmtMerge>	{ $$ = $1; }
62726     | decl      %merge <stmtMerge>
62727     | error ';'	{ $$ = new_nterm ("<error>", 0, 0, 0); }
62728     | '@'		{ YYACCEPT; }
62729     ;
62730
62731expr : ID
62732     | TYPENAME '(' expr ')'
62733			{ $$ = new_nterm ("<cast>(%s,%s)", $3, $1, 0); }
62734     | expr '+' expr	{ $$ = new_nterm ("+(%s,%s)", $1, $3, 0); }
62735     | expr '=' expr    { $$ = new_nterm ("=(%s,%s)", $1, $3, 0); }
62736     ;
62737
62738decl : TYPENAME declarator ';'
62739			{ $$ = new_nterm ("<declare>(%s,%s)", $1, $2, 0); }
62740     | TYPENAME declarator '=' expr ';'
62741			{ $$ = new_nterm ("<init-declare>(%s,%s,%s)", $1,
62742					  $2, $4); }
62743     ;
62744
62745declarator : ID
62746     | '(' declarator ')' { $$ = $2; }
62747     ;
62748
62749%%
62750
62751#include <ctype.h>
62752#include <stdlib.h>
62753#include <string.h>
62754#include <stdarg.h>
62755
62756int
62757main (int argc, char **argv)
62758{
62759  if (argc != 2)
62760    abort ();
62761  if (!freopen (argv[1], "r", stdin))
62762    return 3;
62763  return yyparse ();
62764}
62765
62766int
62767yylex (LEX_PARAMETERS)
62768{
62769  char buffer[256];
62770  int c;
62771  unsigned int i;
62772  static int lineNum = 1;
62773  static int colNum = 0;
62774
62775#if YYPURE
62776# undef yylloc
62777# define yylloc (*llocp)
62778# undef yylval
62779# define yylval (*lvalp)
62780#endif
62781
62782  while (1)
62783    {
62784      c = getchar ();
62785      switch (c)
62786	{
62787	case EOF:
62788	  return 0;
62789	case '\t':
62790	  colNum = (colNum + 7) & ~7;
62791	  break;
62792	case ' ': case '\f':
62793	  colNum += 1;
62794	  break;
62795	case '\n':
62796	  lineNum += 1;
62797	  colNum = 0;
62798	  break;
62799	default:
62800	  {
62801	    int tok;
62802#if YYLSP_NEEDED
62803	    yylloc.first_line = yylloc.last_line = lineNum;
62804	    yylloc.first_column = colNum;
62805#endif
62806	    if (isalpha (c))
62807	      {
62808		i = 0;
62809
62810		do
62811		  {
62812		    buffer[i++] = c;
62813		    colNum += 1;
62814		    if (i == sizeof buffer - 1)
62815		      abort ();
62816		    c = getchar ();
62817		  }
62818		while (isalnum (c) || c == '_');
62819
62820		ungetc (c, stdin);
62821		buffer[i++] = 0;
62822		tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
62823		yylval = new_term (strcpy ((char *) malloc (i), buffer));
62824	      }
62825	    else
62826	      {
62827		colNum += 1;
62828		tok = c;
62829		yylval = 0;
62830	      }
62831#if YYLSP_NEEDED
62832	    yylloc.last_column = colNum-1;
62833#endif
62834	    return tok;
62835	  }
62836	}
62837    }
62838}
62839
62840void
62841yyerror (ERROR_PARAMETERS)
62842{
62843#if YYPURE && YYLSP_NEEDED
62844  /* Pacify GCC by using llocp.  */
62845  if (! llocp)
62846    abort ();
62847#endif
62848  fprintf (stderr, "%s\n", s);
62849}
62850
62851static Node *
62852new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
62853{
62854  Node *node = (Node *) malloc (sizeof (Node));
62855  node->nterm.isNterm = 1;
62856  node->nterm.parents = 0;
62857  node->nterm.form = form;
62858  node->nterm.children[0] = child0;
62859  if (child0)
62860    child0->nodeInfo.parents += 1;
62861  node->nterm.children[1] = child1;
62862  if (child1)
62863    child1->nodeInfo.parents += 1;
62864  node->nterm.children[2] = child2;
62865  if (child2)
62866    child2->nodeInfo.parents += 1;
62867  return node;
62868}
62869
62870static Node *
62871new_term (char *text)
62872{
62873  Node *node = (Node *) malloc (sizeof (Node));
62874  node->term.isNterm = 0;
62875  node->term.parents = 0;
62876  node->term.text = text;
62877  return node;
62878}
62879
62880static void
62881free_node (Node *node)
62882{
62883  if (!node)
62884    return;
62885  node->nodeInfo.parents -= 1;
62886  /* Free only if 0 (last parent) or -1 (no parents).  */
62887  if (node->nodeInfo.parents > 0)
62888    return;
62889  if (node->nodeInfo.isNterm == 1)
62890    {
62891      free_node (node->nterm.children[0]);
62892      free_node (node->nterm.children[1]);
62893      free_node (node->nterm.children[2]);
62894    }
62895  else
62896    free (node->term.text);
62897  free (node);
62898}
62899
62900static char *
62901node_to_string (Node *node)
62902{
62903  char *child0;
62904  char *child1;
62905  char *child2;
62906  char *buffer;
62907  if (!node)
62908    {
62909      buffer = (char *) malloc (1);
62910      buffer[0] = 0;
62911    }
62912  else if (node->nodeInfo.isNterm == 1)
62913    {
62914      child0 = node_to_string (node->nterm.children[0]);
62915      child1 = node_to_string (node->nterm.children[1]);
62916      child2 = node_to_string (node->nterm.children[2]);
62917      buffer = (char *) malloc (strlen (node->nterm.form) + strlen (child0)
62918				+ strlen (child1) + strlen (child2) + 1);
62919      sprintf (buffer, node->nterm.form, child0, child1, child2);
62920      free (child0);
62921      free (child1);
62922      free (child2);
62923    }
62924  else
62925    buffer = strdup (node->term.text);
62926  return buffer;
62927}
62928
62929
62930static YYSTYPE
62931stmtMerge (YYSTYPE x0, YYSTYPE x1)
62932{
62933  return new_nterm ("<OR>(%s,%s)", x0, x1, 0);
62934}
62935
62936_ATEOF
62937
62938
62939
62940cat >test-input <<'_ATEOF'
62941
62942
62943z + q;
62944
62945T x;
62946
62947T x = y;
62948
62949x = y;
62950
62951T (x) + y;
62952
62953T (x);
62954
62955T (y) = z + q;
62956
62957T (y y) = z + q;
62958
62959z + q;
62960
62961@
62962
62963This is total garbage, but it should be ignored.
62964_ATEOF
62965
62966
62967$at_traceoff
62968echo "cxx-type.at:455: bison -o types.c types.y"
62969echo cxx-type.at:455 >$at_check_line_file
62970( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
62971at_status=$?
62972grep '^ *+' $at_stder1 >&2
62973grep -v '^ *+' $at_stder1 >$at_stderr
62974at_failed=false
62975echo stderr:; cat $at_stderr
62976$at_diff $at_devnull $at_stdout || at_failed=:
62977case $at_status in
62978   77) echo 77 > $at_status_file
62979            exit 77;;
62980   0) ;;
62981   *) echo "cxx-type.at:455: exit code was $at_status, expected 0"
62982      at_failed=:;;
62983esac
62984if $at_failed; then
62985
62986  echo 1 > $at_status_file
62987  exit 1
62988fi
62989
62990$at_traceon
62991
62992$at_traceoff
62993echo "cxx-type.at:455: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o types types.c \$LIBS"
62994echo cxx-type.at:455 >$at_check_line_file
62995( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o types types.c $LIBS ) >$at_stdout 2>$at_stder1
62996at_status=$?
62997grep '^ *+' $at_stder1 >&2
62998grep -v '^ *+' $at_stder1 >$at_stderr
62999at_failed=false
63000echo stderr:; cat $at_stderr
63001echo stdout:; cat $at_stdout
63002case $at_status in
63003   77) echo 77 > $at_status_file
63004            exit 77;;
63005   0) ;;
63006   *) echo "cxx-type.at:455: exit code was $at_status, expected 0"
63007      at_failed=:;;
63008esac
63009if $at_failed; then
63010
63011  echo 1 > $at_status_file
63012  exit 1
63013fi
63014
63015$at_traceon
63016
63017
63018
63019
63020
63021
63022
63023
63024
63025
63026
63027
63028
63029
63030
63031
63032
63033
63034
63035
63036
63037
63038
63039$at_traceoff
63040echo "cxx-type.at:457: \$PREPARSER ./types test-input"
63041echo cxx-type.at:457 >$at_check_line_file
63042( $at_traceon; $PREPARSER ./types test-input ) >$at_stdout 2>$at_stder1
63043at_status=$?
63044grep '^ *+' $at_stder1 >&2
63045grep -v '^ *+' $at_stder1 >$at_stderr
63046at_failed=false
63047echo >>$at_stderr; echo "syntax error
63048" | $at_diff - $at_stderr || at_failed=:
63049echo >>$at_stdout; echo "+(z,q)
63050<declare>(T,x)
63051<init-declare>(T,x,y)
63052=(x,y)
63053+(<cast>(x,T),y)
63054<OR>(<declare>(T,x),<cast>(x,T))
63055<OR>(<init-declare>(T,y,+(z,q)),=(<cast>(y,T),+(z,q)))
63056<error>
63057+(z,q)
63058" | $at_diff - $at_stdout || at_failed=:
63059case $at_status in
63060   77) echo 77 > $at_status_file
63061            exit 77;;
63062   0) ;;
63063   *) echo "cxx-type.at:457: exit code was $at_status, expected 0"
63064      at_failed=:;;
63065esac
63066if $at_failed; then
63067
63068  echo 1 > $at_status_file
63069  exit 1
63070fi
63071
63072$at_traceon
63073
63074      $at_traceoff
63075      $at_times_p && times >$at_times_file
63076    ) 5>&1 2>&1 | eval $at_tee_pipe
63077    at_status=`cat $at_status_file`
63078    ;;
63079
63080  140 ) # 140. cxx-type.at:459: GLR: Merge conflicting parses, pure, locations
63081    at_setup_line='cxx-type.at:459'
63082    at_desc='GLR: Merge conflicting parses, pure, locations'
63083    $at_quiet $ECHO_N "140: GLR: Merge conflicting parses, pure, locations$ECHO_C"
63084    at_xfail=no
63085    (
63086      echo "140. cxx-type.at:459: testing ..."
63087      $at_traceon
63088
63089
63090
63091
63092
63093
63094# Using yacc.c?
63095
63096
63097
63098
63099
63100
63101
63102# yyerror receives the location if %location & %pure & (%glr or %parse-param).
63103
63104# yyerror always sees the locations (when activated), except if
63105# yacc & pure & !param.
63106
63107
63108# The interface is pure: either because %pure-parser, or because we
63109# are using the C++ parsers.
63110
63111
63112
63113
63114
63115
63116
63117
63118
63119
63120
63121
63122cat >types.y <<'_ATEOF'
63123%{
63124#ifdef HAVE_CONFIG_H
63125# include <config.h>
63126  /* We don't need perfect functions for these tests. */
63127# undef malloc
63128# undef memcmp
63129# undef realloc
63130#endif
63131%}
63132
63133/* Simplified C++ Type and Expression Grammar.  */
63134
63135%pure-parser %locations
63136
63137%{
63138  #include <stdio.h>
63139  union Node {
63140    struct {
63141      int isNterm;
63142      int parents;
63143    } nodeInfo;
63144    struct {
63145      int isNterm; /* 1 */
63146      int parents;
63147      char const *form;
63148      union Node *children[3];
63149    } nterm;
63150    struct {
63151      int isNterm; /* 0 */
63152      int parents;
63153      char *text;
63154    } term;
63155  };
63156  typedef union Node Node;
63157  static Node *new_nterm (char const *, Node *, Node *, Node *);
63158  static Node *new_term (char *);
63159  static void free_node (Node *);
63160  static char *node_to_string (Node *);
63161  #define YYSTYPE Node *
63162 static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);
63163  #define YYINITDEPTH 10
63164  #define YYSTACKEXPANDABLE 1
63165  struct YYLTYPE;
63166#if YYPURE
63167# if YYLSP_NEEDED
63168#  define LEX_PARAMETERS YYSTYPE *lvalp, struct YYLTYPE *llocp
63169#  define ERROR_PARAMETERS struct YYLTYPE *llocp, char const *s
63170# else
63171#  define LEX_PARAMETERS YYSTYPE *lvalp
63172# endif
63173#endif
63174#ifndef LEX_PARAMETERS
63175# define LEX_PARAMETERS void
63176#endif
63177#ifndef ERROR_PARAMETERS
63178# define ERROR_PARAMETERS char const *s
63179#endif
63180  int yylex (LEX_PARAMETERS);
63181  void yyerror (ERROR_PARAMETERS);
63182%}
63183
63184%token TYPENAME ID
63185
63186%right '='
63187%left '+'
63188
63189%glr-parser
63190
63191%destructor { free_node ($$); } stmt expr decl declarator TYPENAME ID
63192
63193%%
63194
63195prog :
63196     | prog stmt   {
63197			char *output;
63198			printf ("%d.%d-%d.%d: ",
63199			     @2.first_line, @2.first_column,
63200			     @2.last_line, @2.last_column);
63201			output = node_to_string ($2);
63202			printf ("%s\n", output);
63203			free (output);
63204			free_node ($2);
63205		   }
63206     ;
63207
63208stmt : expr ';'  %merge <stmtMerge>	{ $$ = $1; }
63209     | decl      %merge <stmtMerge>
63210     | error ';'	{ $$ = new_nterm ("<error>", 0, 0, 0); }
63211     | '@'		{ YYACCEPT; }
63212     ;
63213
63214expr : ID
63215     | TYPENAME '(' expr ')'
63216			{ $$ = new_nterm ("<cast>(%s,%s)", $3, $1, 0); }
63217     | expr '+' expr	{ $$ = new_nterm ("+(%s,%s)", $1, $3, 0); }
63218     | expr '=' expr    { $$ = new_nterm ("=(%s,%s)", $1, $3, 0); }
63219     ;
63220
63221decl : TYPENAME declarator ';'
63222			{ $$ = new_nterm ("<declare>(%s,%s)", $1, $2, 0); }
63223     | TYPENAME declarator '=' expr ';'
63224			{ $$ = new_nterm ("<init-declare>(%s,%s,%s)", $1,
63225					  $2, $4); }
63226     ;
63227
63228declarator : ID
63229     | '(' declarator ')' { $$ = $2; }
63230     ;
63231
63232%%
63233
63234#include <ctype.h>
63235#include <stdlib.h>
63236#include <string.h>
63237#include <stdarg.h>
63238
63239int
63240main (int argc, char **argv)
63241{
63242  if (argc != 2)
63243    abort ();
63244  if (!freopen (argv[1], "r", stdin))
63245    return 3;
63246  return yyparse ();
63247}
63248
63249int
63250yylex (LEX_PARAMETERS)
63251{
63252  char buffer[256];
63253  int c;
63254  unsigned int i;
63255  static int lineNum = 1;
63256  static int colNum = 0;
63257
63258#if YYPURE
63259# undef yylloc
63260# define yylloc (*llocp)
63261# undef yylval
63262# define yylval (*lvalp)
63263#endif
63264
63265  while (1)
63266    {
63267      c = getchar ();
63268      switch (c)
63269	{
63270	case EOF:
63271	  return 0;
63272	case '\t':
63273	  colNum = (colNum + 7) & ~7;
63274	  break;
63275	case ' ': case '\f':
63276	  colNum += 1;
63277	  break;
63278	case '\n':
63279	  lineNum += 1;
63280	  colNum = 0;
63281	  break;
63282	default:
63283	  {
63284	    int tok;
63285#if YYLSP_NEEDED
63286	    yylloc.first_line = yylloc.last_line = lineNum;
63287	    yylloc.first_column = colNum;
63288#endif
63289	    if (isalpha (c))
63290	      {
63291		i = 0;
63292
63293		do
63294		  {
63295		    buffer[i++] = c;
63296		    colNum += 1;
63297		    if (i == sizeof buffer - 1)
63298		      abort ();
63299		    c = getchar ();
63300		  }
63301		while (isalnum (c) || c == '_');
63302
63303		ungetc (c, stdin);
63304		buffer[i++] = 0;
63305		tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
63306		yylval = new_term (strcpy ((char *) malloc (i), buffer));
63307	      }
63308	    else
63309	      {
63310		colNum += 1;
63311		tok = c;
63312		yylval = 0;
63313	      }
63314#if YYLSP_NEEDED
63315	    yylloc.last_column = colNum-1;
63316#endif
63317	    return tok;
63318	  }
63319	}
63320    }
63321}
63322
63323void
63324yyerror (ERROR_PARAMETERS)
63325{
63326#if YYPURE && YYLSP_NEEDED
63327  /* Pacify GCC by using llocp.  */
63328  if (! llocp)
63329    abort ();
63330#endif
63331  fprintf (stderr, "%s\n", s);
63332}
63333
63334static Node *
63335new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
63336{
63337  Node *node = (Node *) malloc (sizeof (Node));
63338  node->nterm.isNterm = 1;
63339  node->nterm.parents = 0;
63340  node->nterm.form = form;
63341  node->nterm.children[0] = child0;
63342  if (child0)
63343    child0->nodeInfo.parents += 1;
63344  node->nterm.children[1] = child1;
63345  if (child1)
63346    child1->nodeInfo.parents += 1;
63347  node->nterm.children[2] = child2;
63348  if (child2)
63349    child2->nodeInfo.parents += 1;
63350  return node;
63351}
63352
63353static Node *
63354new_term (char *text)
63355{
63356  Node *node = (Node *) malloc (sizeof (Node));
63357  node->term.isNterm = 0;
63358  node->term.parents = 0;
63359  node->term.text = text;
63360  return node;
63361}
63362
63363static void
63364free_node (Node *node)
63365{
63366  if (!node)
63367    return;
63368  node->nodeInfo.parents -= 1;
63369  /* Free only if 0 (last parent) or -1 (no parents).  */
63370  if (node->nodeInfo.parents > 0)
63371    return;
63372  if (node->nodeInfo.isNterm == 1)
63373    {
63374      free_node (node->nterm.children[0]);
63375      free_node (node->nterm.children[1]);
63376      free_node (node->nterm.children[2]);
63377    }
63378  else
63379    free (node->term.text);
63380  free (node);
63381}
63382
63383static char *
63384node_to_string (Node *node)
63385{
63386  char *child0;
63387  char *child1;
63388  char *child2;
63389  char *buffer;
63390  if (!node)
63391    {
63392      buffer = (char *) malloc (1);
63393      buffer[0] = 0;
63394    }
63395  else if (node->nodeInfo.isNterm == 1)
63396    {
63397      child0 = node_to_string (node->nterm.children[0]);
63398      child1 = node_to_string (node->nterm.children[1]);
63399      child2 = node_to_string (node->nterm.children[2]);
63400      buffer = (char *) malloc (strlen (node->nterm.form) + strlen (child0)
63401				+ strlen (child1) + strlen (child2) + 1);
63402      sprintf (buffer, node->nterm.form, child0, child1, child2);
63403      free (child0);
63404      free (child1);
63405      free (child2);
63406    }
63407  else
63408    buffer = strdup (node->term.text);
63409  return buffer;
63410}
63411
63412
63413static YYSTYPE
63414stmtMerge (YYSTYPE x0, YYSTYPE x1)
63415{
63416  return new_nterm ("<OR>(%s,%s)", x0, x1, 0);
63417}
63418
63419_ATEOF
63420
63421
63422
63423cat >test-input <<'_ATEOF'
63424
63425
63426z + q;
63427
63428T x;
63429
63430T x = y;
63431
63432x = y;
63433
63434T (x) + y;
63435
63436T (x);
63437
63438T (y) = z + q;
63439
63440T (y y) = z + q;
63441
63442z + q;
63443
63444@
63445
63446This is total garbage, but it should be ignored.
63447_ATEOF
63448
63449
63450$at_traceoff
63451echo "cxx-type.at:461: bison -o types.c types.y"
63452echo cxx-type.at:461 >$at_check_line_file
63453( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
63454at_status=$?
63455grep '^ *+' $at_stder1 >&2
63456grep -v '^ *+' $at_stder1 >$at_stderr
63457at_failed=false
63458echo stderr:; cat $at_stderr
63459$at_diff $at_devnull $at_stdout || at_failed=:
63460case $at_status in
63461   77) echo 77 > $at_status_file
63462            exit 77;;
63463   0) ;;
63464   *) echo "cxx-type.at:461: exit code was $at_status, expected 0"
63465      at_failed=:;;
63466esac
63467if $at_failed; then
63468
63469  echo 1 > $at_status_file
63470  exit 1
63471fi
63472
63473$at_traceon
63474
63475$at_traceoff
63476echo "cxx-type.at:461: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o types types.c \$LIBS"
63477echo cxx-type.at:461 >$at_check_line_file
63478( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o types types.c $LIBS ) >$at_stdout 2>$at_stder1
63479at_status=$?
63480grep '^ *+' $at_stder1 >&2
63481grep -v '^ *+' $at_stder1 >$at_stderr
63482at_failed=false
63483echo stderr:; cat $at_stderr
63484echo stdout:; cat $at_stdout
63485case $at_status in
63486   77) echo 77 > $at_status_file
63487            exit 77;;
63488   0) ;;
63489   *) echo "cxx-type.at:461: exit code was $at_status, expected 0"
63490      at_failed=:;;
63491esac
63492if $at_failed; then
63493
63494  echo 1 > $at_status_file
63495  exit 1
63496fi
63497
63498$at_traceon
63499
63500
63501
63502
63503
63504
63505
63506
63507
63508
63509
63510
63511
63512
63513
63514
63515
63516
63517
63518
63519
63520
63521
63522$at_traceoff
63523echo "cxx-type.at:463: \$PREPARSER ./types test-input"
63524echo cxx-type.at:463 >$at_check_line_file
63525( $at_traceon; $PREPARSER ./types test-input ) >$at_stdout 2>$at_stder1
63526at_status=$?
63527grep '^ *+' $at_stder1 >&2
63528grep -v '^ *+' $at_stder1 >$at_stderr
63529at_failed=false
63530echo >>$at_stderr; echo "syntax error
63531" | $at_diff - $at_stderr || at_failed=:
63532echo >>$at_stdout; echo "3.0-3.5: +(z,q)
635335.0-5.3: <declare>(T,x)
635347.0-7.7: <init-declare>(T,x,y)
635359.0-9.5: =(x,y)
6353611.0-11.9: +(<cast>(x,T),y)
6353713.0-13.5: <OR>(<declare>(T,x),<cast>(x,T))
6353815.0-15.13: <OR>(<init-declare>(T,y,+(z,q)),=(<cast>(y,T),+(z,q)))
6353917.0-17.15: <error>
6354019.0-19.5: +(z,q)
63541" | $at_diff - $at_stdout || at_failed=:
63542case $at_status in
63543   77) echo 77 > $at_status_file
63544            exit 77;;
63545   0) ;;
63546   *) echo "cxx-type.at:463: exit code was $at_status, expected 0"
63547      at_failed=:;;
63548esac
63549if $at_failed; then
63550
63551  echo 1 > $at_status_file
63552  exit 1
63553fi
63554
63555$at_traceon
63556
63557      $at_traceoff
63558      $at_times_p && times >$at_times_file
63559    ) 5>&1 2>&1 | eval $at_tee_pipe
63560    at_status=`cat $at_status_file`
63561    ;;
63562
63563  141 ) # 141. cxx-type.at:466: GLR: Verbose messages, resolve ambiguity, impure, no locations
63564    at_setup_line='cxx-type.at:466'
63565    at_desc='GLR: Verbose messages, resolve ambiguity, impure, no locations'
63566    $at_quiet $ECHO_N "141: GLR: Verbose messages, resolve ambiguity, impure, no locations$ECHO_C"
63567    at_xfail=no
63568    (
63569      echo "141. cxx-type.at:466: testing ..."
63570      $at_traceon
63571
63572
63573
63574
63575
63576
63577# Using yacc.c?
63578
63579
63580
63581
63582
63583
63584
63585# yyerror receives the location if %location & %pure & (%glr or %parse-param).
63586
63587# yyerror always sees the locations (when activated), except if
63588# yacc & pure & !param.
63589
63590
63591# The interface is pure: either because %pure-parser, or because we
63592# are using the C++ parsers.
63593
63594
63595
63596
63597
63598
63599
63600
63601
63602
63603
63604
63605cat >types.y <<'_ATEOF'
63606%{
63607#ifdef HAVE_CONFIG_H
63608# include <config.h>
63609  /* We don't need perfect functions for these tests. */
63610# undef malloc
63611# undef memcmp
63612# undef realloc
63613#endif
63614%}
63615
63616/* Simplified C++ Type and Expression Grammar.  */
63617
63618%error-verbose
63619
63620%{
63621  #include <stdio.h>
63622  union Node {
63623    struct {
63624      int isNterm;
63625      int parents;
63626    } nodeInfo;
63627    struct {
63628      int isNterm; /* 1 */
63629      int parents;
63630      char const *form;
63631      union Node *children[3];
63632    } nterm;
63633    struct {
63634      int isNterm; /* 0 */
63635      int parents;
63636      char *text;
63637    } term;
63638  };
63639  typedef union Node Node;
63640  static Node *new_nterm (char const *, Node *, Node *, Node *);
63641  static Node *new_term (char *);
63642  static void free_node (Node *);
63643  static char *node_to_string (Node *);
63644  #define YYSTYPE Node *
63645 static YYSTYPE stmtMerge (YYSTYPE x0, YYSTYPE x1);
63646  #define YYINITDEPTH 10
63647  #define YYSTACKEXPANDABLE 1
63648  struct YYLTYPE;
63649#if YYPURE
63650# if YYLSP_NEEDED
63651#  define LEX_PARAMETERS YYSTYPE *lvalp, struct YYLTYPE *llocp
63652#  define ERROR_PARAMETERS struct YYLTYPE *llocp, char const *s
63653# else
63654#  define LEX_PARAMETERS YYSTYPE *lvalp
63655# endif
63656#endif
63657#ifndef LEX_PARAMETERS
63658# define LEX_PARAMETERS void
63659#endif
63660#ifndef ERROR_PARAMETERS
63661# define ERROR_PARAMETERS char const *s
63662#endif
63663  int yylex (LEX_PARAMETERS);
63664  void yyerror (ERROR_PARAMETERS);
63665%}
63666
63667%token TYPENAME ID
63668
63669%right '='
63670%left '+'
63671
63672%glr-parser
63673
63674%destructor { free_node ($$); } stmt expr decl declarator TYPENAME ID
63675
63676%%
63677
63678prog :
63679     | prog stmt   {
63680			char *output;
63681			output = node_to_string ($2);
63682			printf ("%s\n", output);
63683			free (output);
63684			free_node ($2);
63685		   }
63686     ;
63687
63688stmt : expr ';'  %merge <stmtMerge>	{ $$ = $1; }
63689     | decl      %merge <stmtMerge>
63690     | error ';'	{ $$ = new_nterm ("<error>", 0, 0, 0); }
63691     | '@'		{ YYACCEPT; }
63692     ;
63693
63694expr : ID
63695     | TYPENAME '(' expr ')'
63696			{ $$ = new_nterm ("<cast>(%s,%s)", $3, $1, 0); }
63697     | expr '+' expr	{ $$ = new_nterm ("+(%s,%s)", $1, $3, 0); }
63698     | expr '=' expr    { $$ = new_nterm ("=(%s,%s)", $1, $3, 0); }
63699     ;
63700
63701decl : TYPENAME declarator ';'
63702			{ $$ = new_nterm ("<declare>(%s,%s)", $1, $2, 0); }
63703     | TYPENAME declarator '=' expr ';'
63704			{ $$ = new_nterm ("<init-declare>(%s,%s,%s)", $1,
63705					  $2, $4); }
63706     ;
63707
63708declarator : ID
63709     | '(' declarator ')' { $$ = $2; }
63710     ;
63711
63712%%
63713
63714#include <ctype.h>
63715#include <stdlib.h>
63716#include <string.h>
63717#include <stdarg.h>
63718
63719int
63720main (int argc, char **argv)
63721{
63722  if (argc != 2)
63723    abort ();
63724  if (!freopen (argv[1], "r", stdin))
63725    return 3;
63726  return yyparse ();
63727}
63728
63729int
63730yylex (LEX_PARAMETERS)
63731{
63732  char buffer[256];
63733  int c;
63734  unsigned int i;
63735  static int lineNum = 1;
63736  static int colNum = 0;
63737
63738#if YYPURE
63739# undef yylloc
63740# define yylloc (*llocp)
63741# undef yylval
63742# define yylval (*lvalp)
63743#endif
63744
63745  while (1)
63746    {
63747      c = getchar ();
63748      switch (c)
63749	{
63750	case EOF:
63751	  return 0;
63752	case '\t':
63753	  colNum = (colNum + 7) & ~7;
63754	  break;
63755	case ' ': case '\f':
63756	  colNum += 1;
63757	  break;
63758	case '\n':
63759	  lineNum += 1;
63760	  colNum = 0;
63761	  break;
63762	default:
63763	  {
63764	    int tok;
63765#if YYLSP_NEEDED
63766	    yylloc.first_line = yylloc.last_line = lineNum;
63767	    yylloc.first_column = colNum;
63768#endif
63769	    if (isalpha (c))
63770	      {
63771		i = 0;
63772
63773		do
63774		  {
63775		    buffer[i++] = c;
63776		    colNum += 1;
63777		    if (i == sizeof buffer - 1)
63778		      abort ();
63779		    c = getchar ();
63780		  }
63781		while (isalnum (c) || c == '_');
63782
63783		ungetc (c, stdin);
63784		buffer[i++] = 0;
63785		tok = isupper ((unsigned char) buffer[0]) ? TYPENAME : ID;
63786		yylval = new_term (strcpy ((char *) malloc (i), buffer));
63787	      }
63788	    else
63789	      {
63790		colNum += 1;
63791		tok = c;
63792		yylval = 0;
63793	      }
63794#if YYLSP_NEEDED
63795	    yylloc.last_column = colNum-1;
63796#endif
63797	    return tok;
63798	  }
63799	}
63800    }
63801}
63802
63803void
63804yyerror (ERROR_PARAMETERS)
63805{
63806#if YYPURE && YYLSP_NEEDED
63807  /* Pacify GCC by using llocp.  */
63808  if (! llocp)
63809    abort ();
63810#endif
63811  fprintf (stderr, "%s\n", s);
63812}
63813
63814static Node *
63815new_nterm (char const *form, Node *child0, Node *child1, Node *child2)
63816{
63817  Node *node = (Node *) malloc (sizeof (Node));
63818  node->nterm.isNterm = 1;
63819  node->nterm.parents = 0;
63820  node->nterm.form = form;
63821  node->nterm.children[0] = child0;
63822  if (child0)
63823    child0->nodeInfo.parents += 1;
63824  node->nterm.children[1] = child1;
63825  if (child1)
63826    child1->nodeInfo.parents += 1;
63827  node->nterm.children[2] = child2;
63828  if (child2)
63829    child2->nodeInfo.parents += 1;
63830  return node;
63831}
63832
63833static Node *
63834new_term (char *text)
63835{
63836  Node *node = (Node *) malloc (sizeof (Node));
63837  node->term.isNterm = 0;
63838  node->term.parents = 0;
63839  node->term.text = text;
63840  return node;
63841}
63842
63843static void
63844free_node (Node *node)
63845{
63846  if (!node)
63847    return;
63848  node->nodeInfo.parents -= 1;
63849  /* Free only if 0 (last parent) or -1 (no parents).  */
63850  if (node->nodeInfo.parents > 0)
63851    return;
63852  if (node->nodeInfo.isNterm == 1)
63853    {
63854      free_node (node->nterm.children[0]);
63855      free_node (node->nterm.children[1]);
63856      free_node (node->nterm.children[2]);
63857    }
63858  else
63859    free (node->term.text);
63860  free (node);
63861}
63862
63863static char *
63864node_to_string (Node *node)
63865{
63866  char *child0;
63867  char *child1;
63868  char *child2;
63869  char *buffer;
63870  if (!node)
63871    {
63872      buffer = (char *) malloc (1);
63873      buffer[0] = 0;
63874    }
63875  else if (node->nodeInfo.isNterm == 1)
63876    {
63877      child0 = node_to_string (node->nterm.children[0]);
63878      child1 = node_to_string (node->nterm.children[1]);
63879      child2 = node_to_string (node->nterm.children[2]);
63880      buffer = (char *) malloc (strlen (node->nterm.form) + strlen (child0)
63881				+ strlen (child1) + strlen (child2) + 1);
63882      sprintf (buffer, node->nterm.form, child0, child1, child2);
63883      free (child0);
63884      free (child1);
63885      free (child2);
63886    }
63887  else
63888    buffer = strdup (node->term.text);
63889  return buffer;
63890}
63891
63892
63893static YYSTYPE
63894stmtMerge (YYSTYPE x0, YYSTYPE x1)
63895{
63896  return new_nterm ("<OR>(%s,%s)", x0, x1, 0);
63897}
63898
63899_ATEOF
63900
63901
63902
63903cat >test-input <<'_ATEOF'
63904
63905
63906z + q;
63907
63908T x;
63909
63910T x = y;
63911
63912x = y;
63913
63914T (x) + y;
63915
63916T (x);
63917
63918T (y) = z + q;
63919
63920T (y y) = z + q;
63921
63922z + q;
63923
63924@
63925
63926This is total garbage, but it should be ignored.
63927_ATEOF
63928
63929
63930$at_traceoff
63931echo "cxx-type.at:468: bison -o types.c types.y"
63932echo cxx-type.at:468 >$at_check_line_file
63933( $at_traceon; bison -o types.c types.y ) >$at_stdout 2>$at_stder1
63934at_status=$?
63935grep '^ *+' $at_stder1 >&2
63936grep -v '^ *+' $at_stder1 >$at_stderr
63937at_failed=false
63938echo stderr:; cat $at_stderr
63939$at_diff $at_devnull $at_stdout || at_failed=:
63940case $at_status in
63941   77) echo 77 > $at_status_file
63942            exit 77;;
63943   0) ;;
63944   *) echo "cxx-type.at:468: exit code was $at_status, expected 0"
63945      at_failed=:;;
63946esac
63947if $at_failed; then
63948
63949  echo 1 > $at_status_file
63950  exit 1
63951fi
63952
63953$at_traceon
63954
63955$at_traceoff
63956echo "cxx-type.at:468: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o types types.c \$LIBS"
63957echo cxx-type.at:468 >$at_check_line_file
63958( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o types types.c $LIBS ) >$at_stdout 2>$at_stder1
63959at_status=$?
63960grep '^ *+' $at_stder1 >&2
63961grep -v '^ *+' $at_stder1 >$at_stderr
63962at_failed=false
63963echo stderr:; cat $at_stderr
63964echo stdout:; cat $at_stdout
63965case $at_status in
63966   77) echo 77 > $at_status_file
63967            exit 77;;
63968   0) ;;
63969   *) echo "cxx-type.at:468: exit code was $at_status, expected 0"
63970      at_failed=:;;
63971esac
63972if $at_failed; then
63973
63974  echo 1 > $at_status_file
63975  exit 1
63976fi
63977
63978$at_traceon
63979
63980
63981
63982
63983
63984
63985
63986
63987
63988
63989
63990
63991
63992
63993
63994
63995
63996
63997
63998
63999
64000
64001
64002$at_traceoff
64003echo "cxx-type.at:470: \$PREPARSER ./types test-input"
64004echo cxx-type.at:470 >$at_check_line_file
64005( $at_traceon; $PREPARSER ./types test-input ) >$at_stdout 2>$at_stder1
64006at_status=$?
64007grep '^ *+' $at_stder1 >&2
64008grep -v '^ *+' $at_stder1 >$at_stderr
64009at_failed=false
64010echo >>$at_stderr; echo "syntax error, unexpected ID, expecting '=' or '+' or ')'
64011" | $at_diff - $at_stderr || at_failed=:
64012echo >>$at_stdout; echo "+(z,q)
64013<declare>(T,x)
64014<init-declare>(T,x,y)
64015=(x,y)
64016+(<cast>(x,T),y)
64017<OR>(<declare>(T,x),<cast>(x,T))
64018<OR>(<init-declare>(T,y,+(z,q)),=(<cast>(y,T),+(z,q)))
64019<error>
64020+(z,q)
64021" | $at_diff - $at_stdout || at_failed=:
64022case $at_status in
64023   77) echo 77 > $at_status_file
64024            exit 77;;
64025   0) ;;
64026   *) echo "cxx-type.at:470: exit code was $at_status, expected 0"
64027      at_failed=:;;
64028esac
64029if $at_failed; then
64030
64031  echo 1 > $at_status_file
64032  exit 1
64033fi
64034
64035$at_traceon
64036
64037      $at_traceoff
64038      $at_times_p && times >$at_times_file
64039    ) 5>&1 2>&1 | eval $at_tee_pipe
64040    at_status=`cat $at_status_file`
64041    ;;
64042
64043
64044  banner-18 ) # Banner 18. glr-regression.at:19
64045    cat <<\_ATEOF
64046
64047GLR Regression Tests
64048
64049_ATEOF
64050    ;;
64051
64052  142 ) # 142. glr-regression.at:25: Badly Collapsed GLR States
64053    at_setup_line='glr-regression.at:25'
64054    at_desc='Badly Collapsed GLR States'
64055    $at_quiet $ECHO_N "142: Badly Collapsed GLR States                   $ECHO_C"
64056    at_xfail=no
64057    (
64058      echo "142. glr-regression.at:25: testing ..."
64059      $at_traceon
64060
64061
64062cat >glr-regr1.y <<'_ATEOF'
64063%{
64064#ifdef HAVE_CONFIG_H
64065# include <config.h>
64066  /* We don't need perfect functions for these tests. */
64067# undef malloc
64068# undef memcmp
64069# undef realloc
64070#endif
64071%}
64072
64073/* Regression Test: Improper state compression */
64074/* Reported by Scott McPeak */
64075
64076%{
64077#include <stdio.h>
64078
64079#define YYSTYPE int
64080static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1);
64081int yylex (void);
64082void yyerror (char const *msg);
64083%}
64084
64085
64086%glr-parser
64087
64088
64089/* -------- productions ------ */
64090%%
64091
64092StartSymbol: E  { $$=0; }                   %merge <exprMerge>
64093           ;
64094
64095E: E 'P' E { $$=1; printf("E -> E 'P' E\n"); }  %merge <exprMerge>
64096 | 'B'     { $$=2; printf("E -> 'B'\n"); }      %merge <exprMerge>
64097 ;
64098
64099
64100
64101/* ---------- C code ----------- */
64102%%
64103
64104static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1)
64105{
64106  (void) x0;
64107  (void) x1;
64108  printf ("<OR>\n");
64109  return 0;
64110}
64111
64112int
64113main (void)
64114{
64115  return yyparse ();
64116}
64117
64118void
64119yyerror (char const *msg)
64120{
64121  fprintf (stderr, "%s\n", msg);
64122}
64123
64124
64125int
64126yylex (void)
64127{
64128  for (;;)
64129    {
64130      int ch = getchar ();
64131      if (ch == EOF)
64132	return 0;
64133      else if (ch == 'B' || ch == 'P')
64134	return ch;
64135    }
64136}
64137_ATEOF
64138
64139
64140
64141$at_traceoff
64142echo "glr-regression.at:96: bison -o glr-regr1.c glr-regr1.y"
64143echo glr-regression.at:96 >$at_check_line_file
64144( $at_traceon; bison -o glr-regr1.c glr-regr1.y ) >$at_stdout 2>$at_stder1
64145at_status=$?
64146grep '^ *+' $at_stder1 >&2
64147grep -v '^ *+' $at_stder1 >$at_stderr
64148at_failed=false
64149echo >>$at_stderr; echo "glr-regr1.y: conflicts: 1 shift/reduce
64150" | $at_diff - $at_stderr || at_failed=:
64151$at_diff $at_devnull $at_stdout || at_failed=:
64152case $at_status in
64153   77) echo 77 > $at_status_file
64154            exit 77;;
64155   0) ;;
64156   *) echo "glr-regression.at:96: exit code was $at_status, expected 0"
64157      at_failed=:;;
64158esac
64159if $at_failed; then
64160
64161  echo 1 > $at_status_file
64162  exit 1
64163fi
64164
64165$at_traceon
64166
64167$at_traceoff
64168echo "glr-regression.at:97: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr1 glr-regr1.c \$LIBS"
64169echo glr-regression.at:97 >$at_check_line_file
64170( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr1 glr-regr1.c $LIBS ) >$at_stdout 2>$at_stder1
64171at_status=$?
64172grep '^ *+' $at_stder1 >&2
64173grep -v '^ *+' $at_stder1 >$at_stderr
64174at_failed=false
64175echo stderr:; cat $at_stderr
64176echo stdout:; cat $at_stdout
64177case $at_status in
64178   77) echo 77 > $at_status_file
64179            exit 77;;
64180   0) ;;
64181   *) echo "glr-regression.at:97: exit code was $at_status, expected 0"
64182      at_failed=:;;
64183esac
64184if $at_failed; then
64185
64186  echo 1 > $at_status_file
64187  exit 1
64188fi
64189
64190$at_traceon
64191
64192$at_traceoff
64193echo "glr-regression.at:108: echo BPBPB | ./glr-regr1"
64194echo glr-regression.at:108 >$at_check_line_file
64195( $at_traceon; echo BPBPB | ./glr-regr1 ) >$at_stdout 2>$at_stder1
64196at_status=$?
64197grep '^ *+' $at_stder1 >&2
64198grep -v '^ *+' $at_stder1 >$at_stderr
64199at_failed=false
64200$at_diff $at_devnull $at_stderr || at_failed=:
64201echo >>$at_stdout; echo "E -> 'B'
64202E -> 'B'
64203E -> E 'P' E
64204E -> 'B'
64205E -> E 'P' E
64206E -> 'B'
64207E -> E 'P' E
64208E -> E 'P' E
64209<OR>
64210" | $at_diff - $at_stdout || at_failed=:
64211case $at_status in
64212   77) echo 77 > $at_status_file
64213            exit 77;;
64214   0) ;;
64215   *) echo "glr-regression.at:108: exit code was $at_status, expected 0"
64216      at_failed=:;;
64217esac
64218if $at_failed; then
64219
64220  echo 1 > $at_status_file
64221  exit 1
64222fi
64223
64224$at_traceon
64225
64226
64227      $at_traceoff
64228      $at_times_p && times >$at_times_file
64229    ) 5>&1 2>&1 | eval $at_tee_pipe
64230    at_status=`cat $at_status_file`
64231    ;;
64232
64233  143 ) # 143. glr-regression.at:116: Improper handling of embedded actions and dollar(-N) in GLR parsers
64234    at_setup_line='glr-regression.at:116'
64235    at_desc='Improper handling of embedded actions and dollar(-N) in GLR parsers'
64236    $at_quiet $ECHO_N "143: Improper handling of embedded actions and dollar(-N) in GLR parsers$ECHO_C"
64237    at_xfail=no
64238    (
64239      echo "143. glr-regression.at:116: testing ..."
64240      $at_traceon
64241
64242
64243cat >glr-regr2a.y <<'_ATEOF'
64244%{
64245#ifdef HAVE_CONFIG_H
64246# include <config.h>
64247  /* We don't need perfect functions for these tests. */
64248# undef malloc
64249# undef memcmp
64250# undef realloc
64251#endif
64252%}
64253
64254/* Regression Test: Improper handling of embedded actions and $-N  */
64255/* Reported by S. Eken */
64256
64257%{
64258  #define YYSTYPE char *
64259
64260  #include <ctype.h>
64261  #include <stdio.h>
64262  #include <stdlib.h>
64263  #include <string.h>
64264  int yylex (void);
64265  void yyerror (char const *);
64266%}
64267
64268%glr-parser
64269
64270%%
64271
64272command:
64273    's' var 't'
64274       { printf ("Variable: '%s'\n", $2); }
64275    'v' 'x' 'q'
64276       { free ($2); }
64277  | 's' var_list 't' 'e'
64278       { printf ("Varlist: '%s'\n", $2); free ($2); }
64279  | 's' var 't' var_printer 'x'
64280       { free ($2); }
64281  ;
64282
64283var:
64284  'V'
64285     { $$ = $1; }
64286  ;
64287
64288var_list:
64289  var
64290    { $$ = $1; }
64291  | var ',' var_list
64292    {
64293      char *s = (char *) realloc ($1, strlen ($1) + 1 + strlen ($3) + 1);
64294      strcat (s, ",");
64295      strcat (s, $3);
64296      free ($3);
64297      $$ = s;
64298    }
64299  ;
64300
64301var_printer: 'v'
64302   { printf ("Variable: '%s'\n", $-1); }
64303
64304%%
64305
64306FILE *input = NULL;
64307
64308int
64309yylex (void)
64310{
64311  char buf[50];
64312  char *s;
64313  switch (fscanf (input, " %1[a-z,]", buf)) {
64314  case 1:
64315    return buf[0];
64316  case EOF:
64317    return 0;
64318  default:
64319    break;
64320  }
64321  if (fscanf (input, "%49s", buf) != 1)
64322    return 0;
64323  if (sizeof buf - 1 <= strlen (buf))
64324    abort ();
64325  s = (char *) malloc (strlen (buf) + 1);
64326  strcpy (s, buf);
64327  yylval = s;
64328  return 'V';
64329}
64330
64331void
64332yyerror (char const *s)
64333{ printf ("%s\n", s);
64334}
64335
64336int
64337main (int argc, char **argv)
64338{
64339  input = stdin;
64340  if (argc == 2 && !(input = fopen (argv[1], "r"))) return 3;
64341  return yyparse ();
64342}
64343_ATEOF
64344
64345
64346
64347$at_traceoff
64348echo "glr-regression.at:212: bison -o glr-regr2a.c glr-regr2a.y"
64349echo glr-regression.at:212 >$at_check_line_file
64350( $at_traceon; bison -o glr-regr2a.c glr-regr2a.y ) >$at_stdout 2>$at_stder1
64351at_status=$?
64352grep '^ *+' $at_stder1 >&2
64353grep -v '^ *+' $at_stder1 >$at_stderr
64354at_failed=false
64355echo >>$at_stderr; echo "glr-regr2a.y: conflicts: 2 shift/reduce
64356" | $at_diff - $at_stderr || at_failed=:
64357$at_diff $at_devnull $at_stdout || at_failed=:
64358case $at_status in
64359   77) echo 77 > $at_status_file
64360            exit 77;;
64361   0) ;;
64362   *) echo "glr-regression.at:212: exit code was $at_status, expected 0"
64363      at_failed=:;;
64364esac
64365if $at_failed; then
64366
64367  echo 1 > $at_status_file
64368  exit 1
64369fi
64370
64371$at_traceon
64372
64373$at_traceoff
64374echo "glr-regression.at:213: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr2a glr-regr2a.c \$LIBS"
64375echo glr-regression.at:213 >$at_check_line_file
64376( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr2a glr-regr2a.c $LIBS ) >$at_stdout 2>$at_stder1
64377at_status=$?
64378grep '^ *+' $at_stder1 >&2
64379grep -v '^ *+' $at_stder1 >$at_stderr
64380at_failed=false
64381echo stderr:; cat $at_stderr
64382echo stdout:; cat $at_stdout
64383case $at_status in
64384   77) echo 77 > $at_status_file
64385            exit 77;;
64386   0) ;;
64387   *) echo "glr-regression.at:213: exit code was $at_status, expected 0"
64388      at_failed=:;;
64389esac
64390if $at_failed; then
64391
64392  echo 1 > $at_status_file
64393  exit 1
64394fi
64395
64396$at_traceon
64397
64398
64399$at_traceoff
64400echo "glr-regression.at:217: echo s VARIABLE_1 t v x q | ./glr-regr2a"
64401echo glr-regression.at:217 >$at_check_line_file
64402( $at_traceon; echo s VARIABLE_1 t v x q | ./glr-regr2a ) >$at_stdout 2>$at_stder1
64403at_status=$?
64404grep '^ *+' $at_stder1 >&2
64405grep -v '^ *+' $at_stder1 >$at_stderr
64406at_failed=false
64407$at_diff $at_devnull $at_stderr || at_failed=:
64408echo >>$at_stdout; echo "Variable: 'VARIABLE_1'
64409" | $at_diff - $at_stdout || at_failed=:
64410case $at_status in
64411   77) echo 77 > $at_status_file
64412            exit 77;;
64413   0) ;;
64414   *) echo "glr-regression.at:217: exit code was $at_status, expected 0"
64415      at_failed=:;;
64416esac
64417if $at_failed; then
64418
64419  echo 1 > $at_status_file
64420  exit 1
64421fi
64422
64423$at_traceon
64424
64425$at_traceoff
64426echo "glr-regression.at:220: echo s VARIABLE_1 , ANOTHER_VARIABLE_2 t e | ./glr-regr2a"
64427echo glr-regression.at:220 >$at_check_line_file
64428( $at_traceon; echo s VARIABLE_1 , ANOTHER_VARIABLE_2 t e | ./glr-regr2a ) >$at_stdout 2>$at_stder1
64429at_status=$?
64430grep '^ *+' $at_stder1 >&2
64431grep -v '^ *+' $at_stder1 >$at_stderr
64432at_failed=false
64433$at_diff $at_devnull $at_stderr || at_failed=:
64434echo >>$at_stdout; echo "Varlist: 'VARIABLE_1,ANOTHER_VARIABLE_2'
64435" | $at_diff - $at_stdout || at_failed=:
64436case $at_status in
64437   77) echo 77 > $at_status_file
64438            exit 77;;
64439   0) ;;
64440   *) echo "glr-regression.at:220: exit code was $at_status, expected 0"
64441      at_failed=:;;
64442esac
64443if $at_failed; then
64444
64445  echo 1 > $at_status_file
64446  exit 1
64447fi
64448
64449$at_traceon
64450
64451$at_traceoff
64452echo "glr-regression.at:223: echo s VARIABLE_3 t v x | ./glr-regr2a"
64453echo glr-regression.at:223 >$at_check_line_file
64454( $at_traceon; echo s VARIABLE_3 t v x | ./glr-regr2a ) >$at_stdout 2>$at_stder1
64455at_status=$?
64456grep '^ *+' $at_stder1 >&2
64457grep -v '^ *+' $at_stder1 >$at_stderr
64458at_failed=false
64459$at_diff $at_devnull $at_stderr || at_failed=:
64460echo >>$at_stdout; echo "Variable: 'VARIABLE_3'
64461" | $at_diff - $at_stdout || at_failed=:
64462case $at_status in
64463   77) echo 77 > $at_status_file
64464            exit 77;;
64465   0) ;;
64466   *) echo "glr-regression.at:223: exit code was $at_status, expected 0"
64467      at_failed=:;;
64468esac
64469if $at_failed; then
64470
64471  echo 1 > $at_status_file
64472  exit 1
64473fi
64474
64475$at_traceon
64476
64477
64478
64479      $at_traceoff
64480      $at_times_p && times >$at_times_file
64481    ) 5>&1 2>&1 | eval $at_tee_pipe
64482    at_status=`cat $at_status_file`
64483    ;;
64484
64485  144 ) # 144. glr-regression.at:232: Improper merging of GLR delayed action sets
64486    at_setup_line='glr-regression.at:232'
64487    at_desc='Improper merging of GLR delayed action sets'
64488    $at_quiet $ECHO_N "144: Improper merging of GLR delayed action sets  $ECHO_C"
64489    at_xfail=no
64490    (
64491      echo "144. glr-regression.at:232: testing ..."
64492      $at_traceon
64493
64494
64495cat >glr-regr3.y <<'_ATEOF'
64496%{
64497#ifdef HAVE_CONFIG_H
64498# include <config.h>
64499  /* We don't need perfect functions for these tests. */
64500# undef malloc
64501# undef memcmp
64502# undef realloc
64503#endif
64504%}
64505
64506/* Regression Test: Improper merging of GLR delayed action sets.  */
64507/* Reported by M. Rosien */
64508
64509%{
64510#include <stdio.h>
64511#include <stdarg.h>
64512
64513static int MergeRule (int x0, int x1);
64514static void yyerror (char const * s);
64515int yylex (void);
64516
64517#define RULE(x) (1 << (x))
64518
64519%}
64520
64521%glr-parser
64522
64523%token BAD_CHAR
64524%token P1 P2 T1 T2 T3 T4 O1 O2
64525
64526%%
64527
64528S : P1 T4 O2 NT6 P2  { printf ("Result: %x\n", $4); }
64529;
64530
64531NT1 : P1 T1 O1 T2 P2 { $$ = RULE(2); }  %merge<MergeRule>
64532;
64533
64534NT2 : NT1             { $$ = RULE(3); } %merge<MergeRule>
64535    | P1 NT1 O1 T3 P2 { $$ = RULE(4); } %merge<MergeRule>
64536;
64537
64538NT3 : T3              { $$ = RULE(5); } %merge<MergeRule>
64539    | P1 NT1 O1 T3 P2 { $$ = RULE(6); } %merge<MergeRule>
64540;
64541
64542NT4 : NT3              { $$ = RULE(7); } %merge<MergeRule>
64543    | NT2              { $$ = RULE(8); } %merge<MergeRule>
64544    | P1 NT2 O1 NT3 P2 { $$ = RULE(9); } %merge<MergeRule>
64545;
64546
64547NT5 : NT4              { $$ = RULE(10); } %merge<MergeRule>
64548;
64549
64550NT6 : P1 NT1 O1 T3 P2  { $$ = RULE(11) | $2; } %merge<MergeRule>
64551    | NT5              { $$ = RULE(12) | $1; } %merge<MergeRule>
64552;
64553
64554%%
64555
64556static int MergeRule (int x0, int x1) {
64557  return x0 | x1;
64558}
64559
64560static void yyerror(char const * s) {
64561  fprintf(stderr,"error: %s\n",s);
64562}
64563
64564FILE *input = NULL;
64565
64566int P[] = { P1, P2 };
64567int O[] = { O1, O2 };
64568int T[] = { T1, T2, T3, T4 };
64569
64570int yylex (void)
64571{
64572  char inp[3];
64573  if (fscanf (input, "%2s", inp) == EOF)
64574    return 0;
64575  switch (inp[0])
64576    {
64577    case 'p': return P[inp[1] - '1'];
64578    case 't': return T[inp[1] - '1'];
64579    case 'o': return O[inp[1] - '1'];
64580    }
64581  return BAD_CHAR;
64582}
64583
64584int main(int argc, char* argv[]) {
64585  input = stdin;
64586  if (argc == 2 && !(input = fopen (argv[1], "r"))) return 3;
64587  return yyparse ();
64588}
64589_ATEOF
64590
64591
64592
64593$at_traceoff
64594echo "glr-regression.at:322: bison -o glr-regr3.c glr-regr3.y"
64595echo glr-regression.at:322 >$at_check_line_file
64596( $at_traceon; bison -o glr-regr3.c glr-regr3.y ) >$at_stdout 2>$at_stder1
64597at_status=$?
64598grep '^ *+' $at_stder1 >&2
64599grep -v '^ *+' $at_stder1 >$at_stderr
64600at_failed=false
64601echo >>$at_stderr; echo "glr-regr3.y: conflicts: 1 shift/reduce, 1 reduce/reduce
64602" | $at_diff - $at_stderr || at_failed=:
64603$at_diff $at_devnull $at_stdout || at_failed=:
64604case $at_status in
64605   77) echo 77 > $at_status_file
64606            exit 77;;
64607   0) ;;
64608   *) echo "glr-regression.at:322: exit code was $at_status, expected 0"
64609      at_failed=:;;
64610esac
64611if $at_failed; then
64612
64613  echo 1 > $at_status_file
64614  exit 1
64615fi
64616
64617$at_traceon
64618
64619$at_traceoff
64620echo "glr-regression.at:323: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr3 glr-regr3.c \$LIBS"
64621echo glr-regression.at:323 >$at_check_line_file
64622( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr3 glr-regr3.c $LIBS ) >$at_stdout 2>$at_stder1
64623at_status=$?
64624grep '^ *+' $at_stder1 >&2
64625grep -v '^ *+' $at_stder1 >$at_stderr
64626at_failed=false
64627echo stderr:; cat $at_stderr
64628echo stdout:; cat $at_stdout
64629case $at_status in
64630   77) echo 77 > $at_status_file
64631            exit 77;;
64632   0) ;;
64633   *) echo "glr-regression.at:323: exit code was $at_status, expected 0"
64634      at_failed=:;;
64635esac
64636if $at_failed; then
64637
64638  echo 1 > $at_status_file
64639  exit 1
64640fi
64641
64642$at_traceon
64643
64644
64645$at_traceoff
64646echo "glr-regression.at:327: echo p1 t4 o2 p1 p1 t1 o1 t2 p2 o1 t3 p2 p2 | ./glr-regr3"
64647echo glr-regression.at:327 >$at_check_line_file
64648( $at_traceon; echo p1 t4 o2 p1 p1 t1 o1 t2 p2 o1 t3 p2 p2 | ./glr-regr3 ) >$at_stdout 2>$at_stder1
64649at_status=$?
64650grep '^ *+' $at_stder1 >&2
64651grep -v '^ *+' $at_stder1 >$at_stderr
64652at_failed=false
64653$at_diff $at_devnull $at_stderr || at_failed=:
64654echo >>$at_stdout; echo "Result: 1c04
64655" | $at_diff - $at_stdout || at_failed=:
64656case $at_status in
64657   77) echo 77 > $at_status_file
64658            exit 77;;
64659   0) ;;
64660   *) echo "glr-regression.at:327: exit code was $at_status, expected 0"
64661      at_failed=:;;
64662esac
64663if $at_failed; then
64664
64665  echo 1 > $at_status_file
64666  exit 1
64667fi
64668
64669$at_traceon
64670
64671
64672      $at_traceoff
64673      $at_times_p && times >$at_times_file
64674    ) 5>&1 2>&1 | eval $at_tee_pipe
64675    at_status=`cat $at_status_file`
64676    ;;
64677
64678  145 ) # 145. glr-regression.at:337: Duplicate representation of merged trees
64679    at_setup_line='glr-regression.at:337'
64680    at_desc='Duplicate representation of merged trees'
64681    $at_quiet $ECHO_N "145: Duplicate representation of merged trees     $ECHO_C"
64682    at_xfail=no
64683    (
64684      echo "145. glr-regression.at:337: testing ..."
64685      $at_traceon
64686
64687
64688cat >glr-regr4.y <<'_ATEOF'
64689%{
64690#ifdef HAVE_CONFIG_H
64691# include <config.h>
64692  /* We don't need perfect functions for these tests. */
64693# undef malloc
64694# undef memcmp
64695# undef realloc
64696#endif
64697%}
64698
64699
64700%union { char *ptr; }
64701%type <ptr> S A A1 A2 B
64702%glr-parser
64703
64704%{
64705  #include <stdio.h>
64706  #include <stdlib.h>
64707  #include <string.h>
64708  static char *merge (YYSTYPE, YYSTYPE);
64709  static char *make_value (char const *, char const *);
64710  static void yyerror (char const *);
64711  static int yylex (void);
64712%}
64713
64714%%
64715
64716tree: S { printf ("%s\n", $1); } ;
64717
64718S:
64719  A   %merge<merge> { $$ = make_value ("S", $1); }
64720  | B %merge<merge> { $$ = make_value ("S", $1); }
64721  ;
64722
64723A:
64724  A1   %merge<merge> { $$ = make_value ("A", $1); }
64725  | A2 %merge<merge> { $$ = make_value ("A", $1); }
64726  ;
64727
64728A1: 'a' { $$ = make_value ("A1", "'a'"); } ;
64729A2: 'a' { $$ = make_value ("A2", "'a'"); } ;
64730B:  'a' { $$ = make_value ("B", "'a'");  } ;
64731
64732%%
64733
64734static int
64735yylex (void)
64736{
64737  static char const *input = "a";
64738  return *input++;
64739}
64740
64741int
64742main (void)
64743{
64744  return yyparse ();
64745}
64746
64747static char *
64748make_value (char const *parent, char const *child)
64749{
64750  char const format[] = "%s <- %s";
64751  char *value =
64752    (char *) malloc (strlen (parent) + strlen (child) + sizeof format);
64753  sprintf (value, format, parent, child);
64754  return value;
64755}
64756
64757static char *
64758merge (YYSTYPE s1, YYSTYPE s2)
64759{
64760  char const format[] = "merge{ %s and %s }";
64761  char *value =
64762    (char *) malloc (strlen (s1.ptr) + strlen (s2.ptr) + sizeof format);
64763  sprintf (value, format, s1.ptr, s2.ptr);
64764  return value;
64765}
64766
64767static void
64768yyerror (char const *msg)
64769{
64770  fprintf (stderr, "%s\n", msg);
64771}
64772_ATEOF
64773
64774
64775
64776$at_traceoff
64777echo "glr-regression.at:417: bison -o glr-regr4.c glr-regr4.y"
64778echo glr-regression.at:417 >$at_check_line_file
64779( $at_traceon; bison -o glr-regr4.c glr-regr4.y ) >$at_stdout 2>$at_stder1
64780at_status=$?
64781grep '^ *+' $at_stder1 >&2
64782grep -v '^ *+' $at_stder1 >$at_stderr
64783at_failed=false
64784echo >>$at_stderr; echo "glr-regr4.y: conflicts: 1 reduce/reduce
64785" | $at_diff - $at_stderr || at_failed=:
64786$at_diff $at_devnull $at_stdout || at_failed=:
64787case $at_status in
64788   77) echo 77 > $at_status_file
64789            exit 77;;
64790   0) ;;
64791   *) echo "glr-regression.at:417: exit code was $at_status, expected 0"
64792      at_failed=:;;
64793esac
64794if $at_failed; then
64795
64796  echo 1 > $at_status_file
64797  exit 1
64798fi
64799
64800$at_traceon
64801
64802$at_traceoff
64803echo "glr-regression.at:418: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr4 glr-regr4.c \$LIBS"
64804echo glr-regression.at:418 >$at_check_line_file
64805( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr4 glr-regr4.c $LIBS ) >$at_stdout 2>$at_stder1
64806at_status=$?
64807grep '^ *+' $at_stder1 >&2
64808grep -v '^ *+' $at_stder1 >$at_stderr
64809at_failed=false
64810echo stderr:; cat $at_stderr
64811echo stdout:; cat $at_stdout
64812case $at_status in
64813   77) echo 77 > $at_status_file
64814            exit 77;;
64815   0) ;;
64816   *) echo "glr-regression.at:418: exit code was $at_status, expected 0"
64817      at_failed=:;;
64818esac
64819if $at_failed; then
64820
64821  echo 1 > $at_status_file
64822  exit 1
64823fi
64824
64825$at_traceon
64826
64827
64828$at_traceoff
64829echo "glr-regression.at:422: ./glr-regr4"
64830echo glr-regression.at:422 >$at_check_line_file
64831( $at_traceon; ./glr-regr4 ) >$at_stdout 2>$at_stder1
64832at_status=$?
64833grep '^ *+' $at_stder1 >&2
64834grep -v '^ *+' $at_stder1 >$at_stderr
64835at_failed=false
64836$at_diff $at_devnull $at_stderr || at_failed=:
64837echo >>$at_stdout; echo "merge{ S <- merge{ A <- A1 <- 'a' and A <- A2 <- 'a' } and S <- B <- 'a' }
64838" | $at_diff - $at_stdout || at_failed=:
64839case $at_status in
64840   77) echo 77 > $at_status_file
64841            exit 77;;
64842   0) ;;
64843   *) echo "glr-regression.at:422: exit code was $at_status, expected 0"
64844      at_failed=:;;
64845esac
64846if $at_failed; then
64847
64848  echo 1 > $at_status_file
64849  exit 1
64850fi
64851
64852$at_traceon
64853
64854
64855      $at_traceoff
64856      $at_times_p && times >$at_times_file
64857    ) 5>&1 2>&1 | eval $at_tee_pipe
64858    at_status=`cat $at_status_file`
64859    ;;
64860
64861  146 ) # 146. glr-regression.at:432: User destructor for unresolved GLR semantic value
64862    at_setup_line='glr-regression.at:432'
64863    at_desc='User destructor for unresolved GLR semantic value'
64864    $at_quiet $ECHO_N "146: User destructor for unresolved GLR semantic value$ECHO_C"
64865    at_xfail=no
64866    (
64867      echo "146. glr-regression.at:432: testing ..."
64868      $at_traceon
64869
64870
64871cat >glr-regr5.y <<'_ATEOF'
64872%{
64873#ifdef HAVE_CONFIG_H
64874# include <config.h>
64875  /* We don't need perfect functions for these tests. */
64876# undef malloc
64877# undef memcmp
64878# undef realloc
64879#endif
64880%}
64881
64882
64883%{
64884  #include <stdio.h>
64885  #include <stdlib.h>
64886  static void yyerror (char const *);
64887  static int yylex (void);
64888  enum { MAGIC_VALUE = -1057808125 }; /* originally chosen at random */
64889%}
64890
64891%glr-parser
64892%union { int value; }
64893%type <value> start
64894
64895%destructor {
64896  if ($$ != MAGIC_VALUE)
64897    {
64898      fprintf (stderr, "Bad destructor call.\n");
64899      exit (EXIT_FAILURE);
64900    }
64901} start
64902
64903%%
64904
64905start:
64906   'a' { $$ = MAGIC_VALUE; }
64907   | 'a' { $$ = MAGIC_VALUE; }
64908   ;
64909
64910%%
64911
64912static int
64913yylex (void)
64914{
64915  static char const *input = "a";
64916  return *input++;
64917}
64918
64919static void
64920yyerror (char const *msg)
64921{
64922  fprintf (stderr, "%s\n", msg);
64923}
64924
64925int
64926main (void)
64927{
64928  return yyparse () != 1;
64929}
64930_ATEOF
64931
64932
64933
64934$at_traceoff
64935echo "glr-regression.at:487: bison -o glr-regr5.c glr-regr5.y"
64936echo glr-regression.at:487 >$at_check_line_file
64937( $at_traceon; bison -o glr-regr5.c glr-regr5.y ) >$at_stdout 2>$at_stder1
64938at_status=$?
64939grep '^ *+' $at_stder1 >&2
64940grep -v '^ *+' $at_stder1 >$at_stderr
64941at_failed=false
64942echo >>$at_stderr; echo "glr-regr5.y: conflicts: 1 reduce/reduce
64943" | $at_diff - $at_stderr || at_failed=:
64944$at_diff $at_devnull $at_stdout || at_failed=:
64945case $at_status in
64946   77) echo 77 > $at_status_file
64947            exit 77;;
64948   0) ;;
64949   *) echo "glr-regression.at:487: exit code was $at_status, expected 0"
64950      at_failed=:;;
64951esac
64952if $at_failed; then
64953
64954  echo 1 > $at_status_file
64955  exit 1
64956fi
64957
64958$at_traceon
64959
64960$at_traceoff
64961echo "glr-regression.at:488: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr5 glr-regr5.c \$LIBS"
64962echo glr-regression.at:488 >$at_check_line_file
64963( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr5 glr-regr5.c $LIBS ) >$at_stdout 2>$at_stder1
64964at_status=$?
64965grep '^ *+' $at_stder1 >&2
64966grep -v '^ *+' $at_stder1 >$at_stderr
64967at_failed=false
64968echo stderr:; cat $at_stderr
64969echo stdout:; cat $at_stdout
64970case $at_status in
64971   77) echo 77 > $at_status_file
64972            exit 77;;
64973   0) ;;
64974   *) echo "glr-regression.at:488: exit code was $at_status, expected 0"
64975      at_failed=:;;
64976esac
64977if $at_failed; then
64978
64979  echo 1 > $at_status_file
64980  exit 1
64981fi
64982
64983$at_traceon
64984
64985
64986$at_traceoff
64987echo "glr-regression.at:492: ./glr-regr5"
64988echo glr-regression.at:492 >$at_check_line_file
64989( $at_traceon; ./glr-regr5 ) >$at_stdout 2>$at_stder1
64990at_status=$?
64991grep '^ *+' $at_stder1 >&2
64992grep -v '^ *+' $at_stder1 >$at_stderr
64993at_failed=false
64994echo >>$at_stderr; echo "syntax is ambiguous
64995" | $at_diff - $at_stderr || at_failed=:
64996$at_diff $at_devnull $at_stdout || at_failed=:
64997case $at_status in
64998   77) echo 77 > $at_status_file
64999            exit 77;;
65000   0) ;;
65001   *) echo "glr-regression.at:492: exit code was $at_status, expected 0"
65002      at_failed=:;;
65003esac
65004if $at_failed; then
65005
65006  echo 1 > $at_status_file
65007  exit 1
65008fi
65009
65010$at_traceon
65011
65012
65013      $at_traceoff
65014      $at_times_p && times >$at_times_file
65015    ) 5>&1 2>&1 | eval $at_tee_pipe
65016    at_status=`cat $at_status_file`
65017    ;;
65018
65019  147 ) # 147. glr-regression.at:502: User destructor after an error during a split parse
65020    at_setup_line='glr-regression.at:502'
65021    at_desc='User destructor after an error during a split parse'
65022    $at_quiet $ECHO_N "147: User destructor after an error during a split parse$ECHO_C"
65023    at_xfail=no
65024    (
65025      echo "147. glr-regression.at:502: testing ..."
65026      $at_traceon
65027
65028
65029cat >glr-regr6.y <<'_ATEOF'
65030%{
65031#ifdef HAVE_CONFIG_H
65032# include <config.h>
65033  /* We don't need perfect functions for these tests. */
65034# undef malloc
65035# undef memcmp
65036# undef realloc
65037#endif
65038%}
65039
65040
65041%{
65042  #include <stdio.h>
65043  #include <stdlib.h>
65044  static void yyerror (char const *);
65045  static int yylex (void);
65046%}
65047
65048%glr-parser
65049%union { int value; }
65050%type <value> 'a'
65051
65052%destructor {
65053  printf ("Destructor called.\n");
65054} 'a'
65055
65056%%
65057
65058start: 'a' | 'a' ;
65059
65060%%
65061
65062static int
65063yylex (void)
65064{
65065  static char const *input = "a";
65066  return *input++;
65067}
65068
65069static void
65070yyerror (char const *msg)
65071{
65072  fprintf (stderr, "%s\n", msg);
65073}
65074
65075int
65076main (void)
65077{
65078  return yyparse () != 1;
65079}
65080_ATEOF
65081
65082
65083
65084$at_traceoff
65085echo "glr-regression.at:549: bison -o glr-regr6.c glr-regr6.y"
65086echo glr-regression.at:549 >$at_check_line_file
65087( $at_traceon; bison -o glr-regr6.c glr-regr6.y ) >$at_stdout 2>$at_stder1
65088at_status=$?
65089grep '^ *+' $at_stder1 >&2
65090grep -v '^ *+' $at_stder1 >$at_stderr
65091at_failed=false
65092echo >>$at_stderr; echo "glr-regr6.y: conflicts: 1 reduce/reduce
65093" | $at_diff - $at_stderr || at_failed=:
65094$at_diff $at_devnull $at_stdout || at_failed=:
65095case $at_status in
65096   77) echo 77 > $at_status_file
65097            exit 77;;
65098   0) ;;
65099   *) echo "glr-regression.at:549: exit code was $at_status, expected 0"
65100      at_failed=:;;
65101esac
65102if $at_failed; then
65103
65104  echo 1 > $at_status_file
65105  exit 1
65106fi
65107
65108$at_traceon
65109
65110$at_traceoff
65111echo "glr-regression.at:550: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr6 glr-regr6.c \$LIBS"
65112echo glr-regression.at:550 >$at_check_line_file
65113( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr6 glr-regr6.c $LIBS ) >$at_stdout 2>$at_stder1
65114at_status=$?
65115grep '^ *+' $at_stder1 >&2
65116grep -v '^ *+' $at_stder1 >$at_stderr
65117at_failed=false
65118echo stderr:; cat $at_stderr
65119echo stdout:; cat $at_stdout
65120case $at_status in
65121   77) echo 77 > $at_status_file
65122            exit 77;;
65123   0) ;;
65124   *) echo "glr-regression.at:550: exit code was $at_status, expected 0"
65125      at_failed=:;;
65126esac
65127if $at_failed; then
65128
65129  echo 1 > $at_status_file
65130  exit 1
65131fi
65132
65133$at_traceon
65134
65135
65136$at_traceoff
65137echo "glr-regression.at:556: ./glr-regr6"
65138echo glr-regression.at:556 >$at_check_line_file
65139( $at_traceon; ./glr-regr6 ) >$at_stdout 2>$at_stder1
65140at_status=$?
65141grep '^ *+' $at_stder1 >&2
65142grep -v '^ *+' $at_stder1 >$at_stderr
65143at_failed=false
65144echo >>$at_stderr; echo "syntax is ambiguous
65145" | $at_diff - $at_stderr || at_failed=:
65146echo >>$at_stdout; echo "Destructor called.
65147" | $at_diff - $at_stdout || at_failed=:
65148case $at_status in
65149   77) echo 77 > $at_status_file
65150            exit 77;;
65151   0) ;;
65152   *) echo "glr-regression.at:556: exit code was $at_status, expected 0"
65153      at_failed=:;;
65154esac
65155if $at_failed; then
65156
65157  echo 1 > $at_status_file
65158  exit 1
65159fi
65160
65161$at_traceon
65162
65163
65164      $at_traceoff
65165      $at_times_p && times >$at_times_file
65166    ) 5>&1 2>&1 | eval $at_tee_pipe
65167    at_status=`cat $at_status_file`
65168    ;;
65169
65170  148 ) # 148. glr-regression.at:566: Duplicated user destructor for lookahead
65171    at_setup_line='glr-regression.at:566'
65172    at_desc='Duplicated user destructor for lookahead'
65173    $at_quiet $ECHO_N "148: Duplicated user destructor for lookahead     $ECHO_C"
65174    at_xfail=no
65175    (
65176      echo "148. glr-regression.at:566: testing ..."
65177      $at_traceon
65178
65179
65180cat >glr-regr7.y <<'_ATEOF'
65181%{
65182#ifdef HAVE_CONFIG_H
65183# include <config.h>
65184  /* We don't need perfect functions for these tests. */
65185# undef malloc
65186# undef memcmp
65187# undef realloc
65188#endif
65189%}
65190
65191
65192%{
65193  #include <stdio.h>
65194  #include <stdlib.h>
65195  static void yyerror (char const *);
65196  static int yylex (void);
65197  #define YYSTACKEXPANDABLE 0
65198%}
65199
65200%glr-parser
65201%union { int *count; }
65202%type <count> 'a'
65203
65204%destructor {
65205  if ((*$$)++)
65206    fprintf (stderr, "Destructor called on same value twice.\n");
65207} 'a'
65208
65209%%
65210
65211start:
65212    stack1 start
65213  | stack2 start
65214  | /* empty */
65215  ;
65216stack1: 'a' ;
65217stack2: 'a' ;
65218
65219%%
65220
65221static int
65222yylex (void)
65223{
65224  yylval.count = (int *) malloc (sizeof (int));
65225  if (!yylval.count)
65226    {
65227      fprintf (stderr, "Test inconclusive.\n");
65228      exit (EXIT_FAILURE);
65229    }
65230  *yylval.count = 0;
65231  return 'a';
65232}
65233
65234static void
65235yyerror (char const *msg)
65236{
65237  fprintf (stderr, "%s\n", msg);
65238}
65239
65240int
65241main (void)
65242{
65243  return yyparse ();
65244}
65245_ATEOF
65246
65247
65248
65249$at_traceoff
65250echo "glr-regression.at:627: bison -o glr-regr7.c glr-regr7.y"
65251echo glr-regression.at:627 >$at_check_line_file
65252( $at_traceon; bison -o glr-regr7.c glr-regr7.y ) >$at_stdout 2>$at_stder1
65253at_status=$?
65254grep '^ *+' $at_stder1 >&2
65255grep -v '^ *+' $at_stder1 >$at_stderr
65256at_failed=false
65257echo >>$at_stderr; echo "glr-regr7.y: conflicts: 2 reduce/reduce
65258" | $at_diff - $at_stderr || at_failed=:
65259$at_diff $at_devnull $at_stdout || at_failed=:
65260case $at_status in
65261   77) echo 77 > $at_status_file
65262            exit 77;;
65263   0) ;;
65264   *) echo "glr-regression.at:627: exit code was $at_status, expected 0"
65265      at_failed=:;;
65266esac
65267if $at_failed; then
65268
65269  echo 1 > $at_status_file
65270  exit 1
65271fi
65272
65273$at_traceon
65274
65275$at_traceoff
65276echo "glr-regression.at:628: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr7 glr-regr7.c \$LIBS"
65277echo glr-regression.at:628 >$at_check_line_file
65278( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr7 glr-regr7.c $LIBS ) >$at_stdout 2>$at_stder1
65279at_status=$?
65280grep '^ *+' $at_stder1 >&2
65281grep -v '^ *+' $at_stder1 >$at_stderr
65282at_failed=false
65283echo stderr:; cat $at_stderr
65284echo stdout:; cat $at_stdout
65285case $at_status in
65286   77) echo 77 > $at_status_file
65287            exit 77;;
65288   0) ;;
65289   *) echo "glr-regression.at:628: exit code was $at_status, expected 0"
65290      at_failed=:;;
65291esac
65292if $at_failed; then
65293
65294  echo 1 > $at_status_file
65295  exit 1
65296fi
65297
65298$at_traceon
65299
65300
65301$at_traceoff
65302echo "glr-regression.at:632: ./glr-regr7"
65303echo glr-regression.at:632 >$at_check_line_file
65304( $at_traceon; ./glr-regr7 ) >$at_stdout 2>$at_stder1
65305at_status=$?
65306grep '^ *+' $at_stder1 >&2
65307grep -v '^ *+' $at_stder1 >$at_stderr
65308at_failed=false
65309echo >>$at_stderr; echo "memory exhausted
65310" | $at_diff - $at_stderr || at_failed=:
65311$at_diff $at_devnull $at_stdout || at_failed=:
65312case $at_status in
65313   77) echo 77 > $at_status_file
65314            exit 77;;
65315   2) ;;
65316   *) echo "glr-regression.at:632: exit code was $at_status, expected 2"
65317      at_failed=:;;
65318esac
65319if $at_failed; then
65320
65321  echo 1 > $at_status_file
65322  exit 1
65323fi
65324
65325$at_traceon
65326
65327
65328      $at_traceoff
65329      $at_times_p && times >$at_times_file
65330    ) 5>&1 2>&1 | eval $at_tee_pipe
65331    at_status=`cat $at_status_file`
65332    ;;
65333
65334  149 ) # 149. glr-regression.at:644: Incorrectly initialized location for empty right-hand side in GLR
65335    at_setup_line='glr-regression.at:644'
65336    at_desc='Incorrectly initialized location for empty right-hand side in GLR'
65337    $at_quiet $ECHO_N "149: Incorrectly initialized location for empty right-hand side in GLR$ECHO_C"
65338    at_xfail=no
65339    (
65340      echo "149. glr-regression.at:644: testing ..."
65341      $at_traceon
65342
65343
65344cat >glr-regr8.y <<'_ATEOF'
65345%{
65346#ifdef HAVE_CONFIG_H
65347# include <config.h>
65348  /* We don't need perfect functions for these tests. */
65349# undef malloc
65350# undef memcmp
65351# undef realloc
65352#endif
65353%}
65354
65355
65356%{
65357  #include <stdio.h>
65358  #include <stdlib.h>
65359  static void yyerror (char const *);
65360  static int yylex (void);
65361  static void yyerror (char const *msg);
65362%}
65363
65364%token T_CONSTANT
65365%token T_PORT
65366%token T_SIGNAL
65367
65368%glr-parser
65369
65370%%
65371
65372
65373PortClause	: T_PORT InterfaceDeclaration T_PORT
65374		{ printf("%d/%d - %d/%d - %d/%d\n",
65375			 @1.first_column, @1.last_column,
65376			 @2.first_column, @2.last_column,
65377			 @3.first_column, @3.last_column); }
65378	;
65379
65380InterfaceDeclaration	: OptConstantWord	%dprec 1
65381	| OptSignalWord	%dprec 2
65382	;
65383
65384OptConstantWord	: /* empty */
65385	| T_CONSTANT
65386	;
65387
65388OptSignalWord	: /* empty */
65389		{ printf("empty: %d/%d\n", @$.first_column, @$.last_column); }
65390	| T_SIGNAL
65391	;
65392
65393%%
65394
65395void
65396yyerror (char const *msg)
65397{
65398  fprintf (stderr, "%s\n", msg);
65399}
65400
65401static int lexIndex;
65402
65403int yylex (void)
65404{
65405  lexIndex += 1;
65406  switch (lexIndex)
65407    {
65408    case 1:
65409      yylloc.first_column = 1;
65410      yylloc.last_column = 9;
65411      return T_PORT;
65412    case 2:
65413      yylloc.first_column = 13;
65414      yylloc.last_column = 17;
65415      return T_PORT;
65416    default:
65417      return 0;
65418    }
65419}
65420
65421int
65422main (void)
65423{
65424  yyparse();
65425  return 0;
65426}
65427_ATEOF
65428
65429
65430
65431$at_traceoff
65432echo "glr-regression.at:723: bison -o glr-regr8.c glr-regr8.y"
65433echo glr-regression.at:723 >$at_check_line_file
65434( $at_traceon; bison -o glr-regr8.c glr-regr8.y ) >$at_stdout 2>$at_stder1
65435at_status=$?
65436grep '^ *+' $at_stder1 >&2
65437grep -v '^ *+' $at_stder1 >$at_stderr
65438at_failed=false
65439echo >>$at_stderr; echo "glr-regr8.y: conflicts: 1 reduce/reduce
65440" | $at_diff - $at_stderr || at_failed=:
65441$at_diff $at_devnull $at_stdout || at_failed=:
65442case $at_status in
65443   77) echo 77 > $at_status_file
65444            exit 77;;
65445   0) ;;
65446   *) echo "glr-regression.at:723: exit code was $at_status, expected 0"
65447      at_failed=:;;
65448esac
65449if $at_failed; then
65450
65451  echo 1 > $at_status_file
65452  exit 1
65453fi
65454
65455$at_traceon
65456
65457$at_traceoff
65458echo "glr-regression.at:724: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr8 glr-regr8.c \$LIBS"
65459echo glr-regression.at:724 >$at_check_line_file
65460( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr8 glr-regr8.c $LIBS ) >$at_stdout 2>$at_stder1
65461at_status=$?
65462grep '^ *+' $at_stder1 >&2
65463grep -v '^ *+' $at_stder1 >$at_stderr
65464at_failed=false
65465echo stderr:; cat $at_stderr
65466echo stdout:; cat $at_stdout
65467case $at_status in
65468   77) echo 77 > $at_status_file
65469            exit 77;;
65470   0) ;;
65471   *) echo "glr-regression.at:724: exit code was $at_status, expected 0"
65472      at_failed=:;;
65473esac
65474if $at_failed; then
65475
65476  echo 1 > $at_status_file
65477  exit 1
65478fi
65479
65480$at_traceon
65481
65482
65483$at_traceoff
65484echo "glr-regression.at:730: ./glr-regr8"
65485echo glr-regression.at:730 >$at_check_line_file
65486( $at_traceon; ./glr-regr8 ) >$at_stdout 2>$at_stder1
65487at_status=$?
65488grep '^ *+' $at_stder1 >&2
65489grep -v '^ *+' $at_stder1 >$at_stderr
65490at_failed=false
65491$at_diff $at_devnull $at_stderr || at_failed=:
65492echo >>$at_stdout; echo "empty: 9/9
654931/9 - 9/9 - 13/17
65494" | $at_diff - $at_stdout || at_failed=:
65495case $at_status in
65496   77) echo 77 > $at_status_file
65497            exit 77;;
65498   0) ;;
65499   *) echo "glr-regression.at:730: exit code was $at_status, expected 0"
65500      at_failed=:;;
65501esac
65502if $at_failed; then
65503
65504  echo 1 > $at_status_file
65505  exit 1
65506fi
65507
65508$at_traceon
65509
65510
65511      $at_traceoff
65512      $at_times_p && times >$at_times_file
65513    ) 5>&1 2>&1 | eval $at_tee_pipe
65514    at_status=`cat $at_status_file`
65515    ;;
65516
65517  150 ) # 150. glr-regression.at:740: No users destructors if stack 0 deleted
65518    at_setup_line='glr-regression.at:740'
65519    at_desc='No users destructors if stack 0 deleted'
65520    $at_quiet $ECHO_N "150: No users destructors if stack 0 deleted      $ECHO_C"
65521    at_xfail=no
65522    (
65523      echo "150. glr-regression.at:740: testing ..."
65524      $at_traceon
65525
65526
65527cat >glr-regr9.y <<'_ATEOF'
65528%{
65529#ifdef HAVE_CONFIG_H
65530# include <config.h>
65531  /* We don't need perfect functions for these tests. */
65532# undef malloc
65533# undef memcmp
65534# undef realloc
65535#endif
65536%}
65537
65538
65539%{
65540# include <stdio.h>
65541# include <stdlib.h>
65542  static void yyerror (char const *);
65543  static int yylex (void);
65544# define YYSTACKEXPANDABLE 0
65545  static int tokens = 0;
65546  static int destructors = 0;
65547# define USE(Var)
65548%}
65549
65550%glr-parser
65551%union { int dummy; }
65552%type <dummy> 'a'
65553
65554%destructor {
65555  destructors += 1;
65556} 'a'
65557
65558%%
65559
65560start:
65561    ambig0 'a'   { destructors += 2; USE ($2); }
65562  | ambig1 start { destructors += 1; }
65563  | ambig2 start { destructors += 1; }
65564  ;
65565
65566ambig0: 'a' ;
65567ambig1: 'a' ;
65568ambig2: 'a' ;
65569
65570%%
65571
65572static int
65573yylex (void)
65574{
65575  tokens += 1;
65576  return 'a';
65577}
65578
65579static void
65580yyerror (char const *msg)
65581{
65582  fprintf (stderr, "%s\n", msg);
65583}
65584
65585int
65586main (void)
65587{
65588  int exit_status;
65589  exit_status = yyparse ();
65590  if (tokens != destructors)
65591    {
65592      fprintf (stderr, "Tokens = %d, Destructors = %d\n", tokens, destructors);
65593      return 1;
65594    }
65595  return !exit_status;
65596}
65597_ATEOF
65598
65599
65600
65601$at_traceoff
65602echo "glr-regression.at:806: bison -o glr-regr9.c glr-regr9.y"
65603echo glr-regression.at:806 >$at_check_line_file
65604( $at_traceon; bison -o glr-regr9.c glr-regr9.y ) >$at_stdout 2>$at_stder1
65605at_status=$?
65606grep '^ *+' $at_stder1 >&2
65607grep -v '^ *+' $at_stder1 >$at_stderr
65608at_failed=false
65609echo >>$at_stderr; echo "glr-regr9.y: conflicts: 1 reduce/reduce
65610" | $at_diff - $at_stderr || at_failed=:
65611$at_diff $at_devnull $at_stdout || at_failed=:
65612case $at_status in
65613   77) echo 77 > $at_status_file
65614            exit 77;;
65615   0) ;;
65616   *) echo "glr-regression.at:806: exit code was $at_status, expected 0"
65617      at_failed=:;;
65618esac
65619if $at_failed; then
65620
65621  echo 1 > $at_status_file
65622  exit 1
65623fi
65624
65625$at_traceon
65626
65627$at_traceoff
65628echo "glr-regression.at:807: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr9 glr-regr9.c \$LIBS"
65629echo glr-regression.at:807 >$at_check_line_file
65630( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr9 glr-regr9.c $LIBS ) >$at_stdout 2>$at_stder1
65631at_status=$?
65632grep '^ *+' $at_stder1 >&2
65633grep -v '^ *+' $at_stder1 >$at_stderr
65634at_failed=false
65635echo stderr:; cat $at_stderr
65636echo stdout:; cat $at_stdout
65637case $at_status in
65638   77) echo 77 > $at_status_file
65639            exit 77;;
65640   0) ;;
65641   *) echo "glr-regression.at:807: exit code was $at_status, expected 0"
65642      at_failed=:;;
65643esac
65644if $at_failed; then
65645
65646  echo 1 > $at_status_file
65647  exit 1
65648fi
65649
65650$at_traceon
65651
65652
65653$at_traceoff
65654echo "glr-regression.at:811: ./glr-regr9"
65655echo glr-regression.at:811 >$at_check_line_file
65656( $at_traceon; ./glr-regr9 ) >$at_stdout 2>$at_stder1
65657at_status=$?
65658grep '^ *+' $at_stder1 >&2
65659grep -v '^ *+' $at_stder1 >$at_stderr
65660at_failed=false
65661echo >>$at_stderr; echo "memory exhausted
65662" | $at_diff - $at_stderr || at_failed=:
65663$at_diff $at_devnull $at_stdout || at_failed=:
65664case $at_status in
65665   77) echo 77 > $at_status_file
65666            exit 77;;
65667   0) ;;
65668   *) echo "glr-regression.at:811: exit code was $at_status, expected 0"
65669      at_failed=:;;
65670esac
65671if $at_failed; then
65672
65673  echo 1 > $at_status_file
65674  exit 1
65675fi
65676
65677$at_traceon
65678
65679
65680      $at_traceoff
65681      $at_times_p && times >$at_times_file
65682    ) 5>&1 2>&1 | eval $at_tee_pipe
65683    at_status=`cat $at_status_file`
65684    ;;
65685
65686  151 ) # 151. glr-regression.at:820: Corrupted semantic options if user action cuts parse
65687    at_setup_line='glr-regression.at:820'
65688    at_desc='Corrupted semantic options if user action cuts parse'
65689    $at_quiet $ECHO_N "151: Corrupted semantic options if user action cuts parse$ECHO_C"
65690    at_xfail=no
65691    (
65692      echo "151. glr-regression.at:820: testing ..."
65693      $at_traceon
65694
65695
65696cat >glr-regr10.y <<'_ATEOF'
65697%{
65698#ifdef HAVE_CONFIG_H
65699# include <config.h>
65700  /* We don't need perfect functions for these tests. */
65701# undef malloc
65702# undef memcmp
65703# undef realloc
65704#endif
65705%}
65706
65707
65708%{
65709# include <stdio.h>
65710  static void yyerror (char const *);
65711  static int yylex (void);
65712  #define GARBAGE_SIZE 50
65713  static char garbage[GARBAGE_SIZE];
65714%}
65715
65716%glr-parser
65717%union { char *ptr; }
65718%type <ptr> start
65719
65720%%
65721
65722start:
65723    %dprec 2 { $$ = garbage; YYACCEPT; }
65724  | %dprec 1 { $$ = garbage; YYACCEPT; }
65725  ;
65726
65727%%
65728
65729static void
65730yyerror (char const *msg)
65731{
65732  fprintf (stderr, "%s\n", msg);
65733}
65734
65735static int
65736yylex (void)
65737{
65738  return 0;
65739}
65740
65741int
65742main (void)
65743{
65744  int i;
65745  for (i = 0; i < GARBAGE_SIZE; i+=1)
65746    garbage[i] = 108;
65747  return yyparse ();
65748}
65749_ATEOF
65750
65751
65752
65753$at_traceoff
65754echo "glr-regression.at:869: bison -o glr-regr10.c glr-regr10.y"
65755echo glr-regression.at:869 >$at_check_line_file
65756( $at_traceon; bison -o glr-regr10.c glr-regr10.y ) >$at_stdout 2>$at_stder1
65757at_status=$?
65758grep '^ *+' $at_stder1 >&2
65759grep -v '^ *+' $at_stder1 >$at_stderr
65760at_failed=false
65761echo >>$at_stderr; echo "glr-regr10.y: conflicts: 1 reduce/reduce
65762" | $at_diff - $at_stderr || at_failed=:
65763$at_diff $at_devnull $at_stdout || at_failed=:
65764case $at_status in
65765   77) echo 77 > $at_status_file
65766            exit 77;;
65767   0) ;;
65768   *) echo "glr-regression.at:869: exit code was $at_status, expected 0"
65769      at_failed=:;;
65770esac
65771if $at_failed; then
65772
65773  echo 1 > $at_status_file
65774  exit 1
65775fi
65776
65777$at_traceon
65778
65779$at_traceoff
65780echo "glr-regression.at:870: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr10 glr-regr10.c \$LIBS"
65781echo glr-regression.at:870 >$at_check_line_file
65782( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr10 glr-regr10.c $LIBS ) >$at_stdout 2>$at_stder1
65783at_status=$?
65784grep '^ *+' $at_stder1 >&2
65785grep -v '^ *+' $at_stder1 >$at_stderr
65786at_failed=false
65787echo stderr:; cat $at_stderr
65788echo stdout:; cat $at_stdout
65789case $at_status in
65790   77) echo 77 > $at_status_file
65791            exit 77;;
65792   0) ;;
65793   *) echo "glr-regression.at:870: exit code was $at_status, expected 0"
65794      at_failed=:;;
65795esac
65796if $at_failed; then
65797
65798  echo 1 > $at_status_file
65799  exit 1
65800fi
65801
65802$at_traceon
65803
65804
65805$at_traceoff
65806echo "glr-regression.at:872: ./glr-regr10"
65807echo glr-regression.at:872 >$at_check_line_file
65808( $at_traceon; ./glr-regr10 ) >$at_stdout 2>$at_stder1
65809at_status=$?
65810grep '^ *+' $at_stder1 >&2
65811grep -v '^ *+' $at_stder1 >$at_stderr
65812at_failed=false
65813$at_diff $at_devnull $at_stderr || at_failed=:
65814$at_diff $at_devnull $at_stdout || at_failed=:
65815case $at_status in
65816   77) echo 77 > $at_status_file
65817            exit 77;;
65818   0) ;;
65819   *) echo "glr-regression.at:872: exit code was $at_status, expected 0"
65820      at_failed=:;;
65821esac
65822if $at_failed; then
65823
65824  echo 1 > $at_status_file
65825  exit 1
65826fi
65827
65828$at_traceon
65829
65830
65831      $at_traceoff
65832      $at_times_p && times >$at_times_file
65833    ) 5>&1 2>&1 | eval $at_tee_pipe
65834    at_status=`cat $at_status_file`
65835    ;;
65836
65837  152 ) # 152. glr-regression.at:881: Undesirable destructors if user action cuts parse
65838    at_setup_line='glr-regression.at:881'
65839    at_desc='Undesirable destructors if user action cuts parse'
65840    $at_quiet $ECHO_N "152: Undesirable destructors if user action cuts parse$ECHO_C"
65841    at_xfail=no
65842    (
65843      echo "152. glr-regression.at:881: testing ..."
65844      $at_traceon
65845
65846
65847cat >glr-regr11.y <<'_ATEOF'
65848%{
65849#ifdef HAVE_CONFIG_H
65850# include <config.h>
65851  /* We don't need perfect functions for these tests. */
65852# undef malloc
65853# undef memcmp
65854# undef realloc
65855#endif
65856%}
65857
65858
65859%{
65860# include <stdlib.h>
65861  static void yyerror (char const *);
65862  static int yylex (void);
65863  static int destructors = 0;
65864# define USE(val)
65865%}
65866
65867%glr-parser
65868%union { int dummy; }
65869%type <int> 'a'
65870%destructor { destructors += 1; } 'a'
65871
65872%%
65873
65874start:
65875    'a' %dprec 2 { USE ($1); destructors += 1; YYACCEPT; }
65876  | 'a' %dprec 1 { USE ($1); destructors += 1; YYACCEPT; }
65877  ;
65878
65879%%
65880
65881static void
65882yyerror (char const *msg)
65883{
65884  fprintf (stderr, "%s\n", msg);
65885}
65886
65887static int
65888yylex (void)
65889{
65890  static char const *input = "a";
65891  return *input++;
65892}
65893
65894int
65895main (void)
65896{
65897  int exit_status = yyparse ();
65898  if (destructors != 1)
65899    {
65900      fprintf (stderr, "Destructor calls: %d\n", destructors);
65901      return 1;
65902    }
65903  return exit_status;
65904}
65905_ATEOF
65906
65907
65908
65909$at_traceoff
65910echo "glr-regression.at:935: bison -o glr-regr11.c glr-regr11.y"
65911echo glr-regression.at:935 >$at_check_line_file
65912( $at_traceon; bison -o glr-regr11.c glr-regr11.y ) >$at_stdout 2>$at_stder1
65913at_status=$?
65914grep '^ *+' $at_stder1 >&2
65915grep -v '^ *+' $at_stder1 >$at_stderr
65916at_failed=false
65917echo >>$at_stderr; echo "glr-regr11.y: conflicts: 1 reduce/reduce
65918" | $at_diff - $at_stderr || at_failed=:
65919$at_diff $at_devnull $at_stdout || at_failed=:
65920case $at_status in
65921   77) echo 77 > $at_status_file
65922            exit 77;;
65923   0) ;;
65924   *) echo "glr-regression.at:935: exit code was $at_status, expected 0"
65925      at_failed=:;;
65926esac
65927if $at_failed; then
65928
65929  echo 1 > $at_status_file
65930  exit 1
65931fi
65932
65933$at_traceon
65934
65935$at_traceoff
65936echo "glr-regression.at:936: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr11 glr-regr11.c \$LIBS"
65937echo glr-regression.at:936 >$at_check_line_file
65938( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr11 glr-regr11.c $LIBS ) >$at_stdout 2>$at_stder1
65939at_status=$?
65940grep '^ *+' $at_stder1 >&2
65941grep -v '^ *+' $at_stder1 >$at_stderr
65942at_failed=false
65943echo stderr:; cat $at_stderr
65944echo stdout:; cat $at_stdout
65945case $at_status in
65946   77) echo 77 > $at_status_file
65947            exit 77;;
65948   0) ;;
65949   *) echo "glr-regression.at:936: exit code was $at_status, expected 0"
65950      at_failed=:;;
65951esac
65952if $at_failed; then
65953
65954  echo 1 > $at_status_file
65955  exit 1
65956fi
65957
65958$at_traceon
65959
65960
65961$at_traceoff
65962echo "glr-regression.at:938: ./glr-regr11"
65963echo glr-regression.at:938 >$at_check_line_file
65964( $at_traceon; ./glr-regr11 ) >$at_stdout 2>$at_stder1
65965at_status=$?
65966grep '^ *+' $at_stder1 >&2
65967grep -v '^ *+' $at_stder1 >$at_stderr
65968at_failed=false
65969$at_diff $at_devnull $at_stderr || at_failed=:
65970$at_diff $at_devnull $at_stdout || at_failed=:
65971case $at_status in
65972   77) echo 77 > $at_status_file
65973            exit 77;;
65974   0) ;;
65975   *) echo "glr-regression.at:938: exit code was $at_status, expected 0"
65976      at_failed=:;;
65977esac
65978if $at_failed; then
65979
65980  echo 1 > $at_status_file
65981  exit 1
65982fi
65983
65984$at_traceon
65985
65986
65987      $at_traceoff
65988      $at_times_p && times >$at_times_file
65989    ) 5>&1 2>&1 | eval $at_tee_pipe
65990    at_status=`cat $at_status_file`
65991    ;;
65992
65993  153 ) # 153. glr-regression.at:947: Leaked semantic values if user action cuts parse
65994    at_setup_line='glr-regression.at:947'
65995    at_desc='Leaked semantic values if user action cuts parse'
65996    $at_quiet $ECHO_N "153: Leaked semantic values if user action cuts parse$ECHO_C"
65997    at_xfail=no
65998    (
65999      echo "153. glr-regression.at:947: testing ..."
66000      $at_traceon
66001
66002
66003cat >glr-regr12.y <<'_ATEOF'
66004%{
66005#ifdef HAVE_CONFIG_H
66006# include <config.h>
66007  /* We don't need perfect functions for these tests. */
66008# undef malloc
66009# undef memcmp
66010# undef realloc
66011#endif
66012%}
66013
66014
66015%glr-parser
66016%union { int dummy; }
66017%token PARENT_RHS_AFTER
66018%type <dummy> parent_rhs_before merged PARENT_RHS_AFTER
66019%destructor { parent_rhs_before_value = 0; } parent_rhs_before
66020%destructor { merged_value = 0; } merged
66021%destructor { parent_rhs_after_value = 0; } PARENT_RHS_AFTER
66022
66023%{
66024# include <stdlib.h>
66025  static int merge (YYSTYPE, YYSTYPE);
66026  static void yyerror (char const *);
66027  static int yylex (void);
66028  static int parent_rhs_before_value = 0;
66029  static int merged_value = 0;
66030  static int parent_rhs_after_value = 0;
66031# define USE(val)
66032%}
66033
66034%%
66035
66036start:
66037  alt1 %dprec 1
66038  | alt2 %dprec 2
66039  ;
66040
66041alt1:
66042  PARENT_RHS_AFTER {
66043    USE ($1);
66044    parent_rhs_after_value = 0;
66045  }
66046  ;
66047
66048alt2:
66049  parent_rhs_before merged PARENT_RHS_AFTER {
66050    USE (($1, $2, $3));
66051    parent_rhs_before_value = 0;
66052    merged_value = 0;
66053    parent_rhs_after_value = 0;
66054  }
66055  ;
66056
66057parent_rhs_before:
66058  {
66059    USE ($$);
66060    parent_rhs_before_value = 1;
66061  }
66062  ;
66063
66064merged:
66065  %merge<merge> {
66066    USE ($$);
66067    merged_value = 1;
66068  }
66069  | cut %merge<merge> {
66070    USE ($$);
66071    merged_value = 1;
66072  }
66073  ;
66074
66075cut: { YYACCEPT; } ;
66076
66077%%
66078
66079static int
66080merge (YYSTYPE s1, YYSTYPE s2)
66081{
66082  /* Not invoked. */
66083  char dummy = s1.dummy + s2.dummy;
66084  return dummy;
66085}
66086
66087static void
66088yyerror (char const *msg)
66089{
66090  fprintf (stderr, "%s\n", msg);
66091}
66092
66093static int
66094yylex (void)
66095{
66096  static int const input[] = { PARENT_RHS_AFTER, 0 };
66097  static const int *inputp = input;
66098  if (*inputp == PARENT_RHS_AFTER)
66099    parent_rhs_after_value = 1;
66100  return *inputp++;
66101}
66102
66103int
66104main (void)
66105{
66106  int exit_status = yyparse ();
66107  if (parent_rhs_before_value)
66108    {
66109      fprintf (stderr, "`parent_rhs_before' destructor not called.\n");
66110      exit_status = 1;
66111    }
66112  if (merged_value)
66113    {
66114      fprintf (stderr, "`merged' destructor not called.\n");
66115      exit_status = 1;
66116    }
66117  if (parent_rhs_after_value)
66118    {
66119      fprintf (stderr, "`PARENT_RHS_AFTER' destructor not called.\n");
66120      exit_status = 1;
66121    }
66122  return exit_status;
66123}
66124_ATEOF
66125
66126
66127
66128$at_traceoff
66129echo "glr-regression.at:1064: bison -o glr-regr12.c glr-regr12.y"
66130echo glr-regression.at:1064 >$at_check_line_file
66131( $at_traceon; bison -o glr-regr12.c glr-regr12.y ) >$at_stdout 2>$at_stder1
66132at_status=$?
66133grep '^ *+' $at_stder1 >&2
66134grep -v '^ *+' $at_stder1 >$at_stderr
66135at_failed=false
66136echo >>$at_stderr; echo "glr-regr12.y: conflicts: 1 shift/reduce, 1 reduce/reduce
66137" | $at_diff - $at_stderr || at_failed=:
66138$at_diff $at_devnull $at_stdout || at_failed=:
66139case $at_status in
66140   77) echo 77 > $at_status_file
66141            exit 77;;
66142   0) ;;
66143   *) echo "glr-regression.at:1064: exit code was $at_status, expected 0"
66144      at_failed=:;;
66145esac
66146if $at_failed; then
66147
66148  echo 1 > $at_status_file
66149  exit 1
66150fi
66151
66152$at_traceon
66153
66154$at_traceoff
66155echo "glr-regression.at:1065: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr12 glr-regr12.c \$LIBS"
66156echo glr-regression.at:1065 >$at_check_line_file
66157( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr12 glr-regr12.c $LIBS ) >$at_stdout 2>$at_stder1
66158at_status=$?
66159grep '^ *+' $at_stder1 >&2
66160grep -v '^ *+' $at_stder1 >$at_stderr
66161at_failed=false
66162echo stderr:; cat $at_stderr
66163echo stdout:; cat $at_stdout
66164case $at_status in
66165   77) echo 77 > $at_status_file
66166            exit 77;;
66167   0) ;;
66168   *) echo "glr-regression.at:1065: exit code was $at_status, expected 0"
66169      at_failed=:;;
66170esac
66171if $at_failed; then
66172
66173  echo 1 > $at_status_file
66174  exit 1
66175fi
66176
66177$at_traceon
66178
66179
66180$at_traceoff
66181echo "glr-regression.at:1067: ./glr-regr12"
66182echo glr-regression.at:1067 >$at_check_line_file
66183( $at_traceon; ./glr-regr12 ) >$at_stdout 2>$at_stder1
66184at_status=$?
66185grep '^ *+' $at_stder1 >&2
66186grep -v '^ *+' $at_stder1 >$at_stderr
66187at_failed=false
66188$at_diff $at_devnull $at_stderr || at_failed=:
66189$at_diff $at_devnull $at_stdout || at_failed=:
66190case $at_status in
66191   77) echo 77 > $at_status_file
66192            exit 77;;
66193   0) ;;
66194   *) echo "glr-regression.at:1067: exit code was $at_status, expected 0"
66195      at_failed=:;;
66196esac
66197if $at_failed; then
66198
66199  echo 1 > $at_status_file
66200  exit 1
66201fi
66202
66203$at_traceon
66204
66205
66206      $at_traceoff
66207      $at_times_p && times >$at_times_file
66208    ) 5>&1 2>&1 | eval $at_tee_pipe
66209    at_status=`cat $at_status_file`
66210    ;;
66211
66212  154 ) # 154. glr-regression.at:1078: Incorrect lookahead during deterministic GLR
66213    at_setup_line='glr-regression.at:1078'
66214    at_desc='Incorrect lookahead during deterministic GLR'
66215    $at_quiet $ECHO_N "154: Incorrect lookahead during deterministic GLR $ECHO_C"
66216    at_xfail=no
66217    (
66218      echo "154. glr-regression.at:1078: testing ..."
66219      $at_traceon
66220
66221
66222cat >glr-regr13.y <<'_ATEOF'
66223%{
66224#ifdef HAVE_CONFIG_H
66225# include <config.h>
66226  /* We don't need perfect functions for these tests. */
66227# undef malloc
66228# undef memcmp
66229# undef realloc
66230#endif
66231%}
66232
66233
66234/* Tests:
66235     - Defaulted state with initial yychar: yychar == YYEMPTY.
66236     - Nondefaulted state: yychar != YYEMPTY.
66237     - Defaulted state after lookahead: yychar != YYEMPTY.
66238     - Defaulted state after shift: yychar == YYEMPTY.
66239     - User action changing the lookahead.  */
66240
66241%{
66242  #include <stdio.h>
66243  static void yyerror (char const *);
66244  static int yylex (void);
66245  static void print_look_ahead (char const *);
66246  #define USE(value)
66247%}
66248
66249%union { char value; }
66250%type <value> 'a' 'b'
66251%glr-parser
66252%locations
66253
66254%%
66255
66256start:
66257  defstate_init defstate_shift 'b' change_lookahead 'a' {
66258    USE ($3);
66259    print_look_ahead ("start <- defstate_init defstate_shift 'b'");
66260  }
66261  ;
66262defstate_init:
66263  {
66264    print_look_ahead ("defstate_init <- empty string");
66265  }
66266  ;
66267defstate_shift:
66268  nondefstate defstate_look 'a' {
66269    USE ($3);
66270    print_look_ahead ("defstate_shift <- nondefstate defstate_look 'a'");
66271  }
66272  ;
66273defstate_look:
66274  {
66275    print_look_ahead ("defstate_look <- empty string");
66276  }
66277  ;
66278nondefstate:
66279  {
66280    print_look_ahead ("nondefstate <- empty string");
66281  }
66282  | 'b' {
66283    USE ($1);
66284    print_look_ahead ("nondefstate <- 'b'");
66285  }
66286  ;
66287change_lookahead:
66288  {
66289    yychar = 'a';
66290  }
66291  ;
66292
66293%%
66294
66295static void
66296yyerror (char const *msg)
66297{
66298  fprintf (stderr, "%s\n", msg);
66299}
66300
66301static int
66302yylex (void)
66303{
66304  static char const *input = "ab";
66305  static int i = 0;
66306  yylloc.first_line = yylloc.last_line = 1;
66307  yylloc.first_column = yylloc.last_column = i + 1;
66308  yylval.value = input[i] + 'A' - 'a';
66309  return input[i++];
66310}
66311
66312static void
66313print_look_ahead (char const *reduction)
66314{
66315  printf ("%s:\n  yychar=", reduction);
66316  if (yychar == YYEMPTY)
66317    printf ("YYEMPTY");
66318  else if (yychar == YYEOF)
66319    printf ("YYEOF");
66320  else
66321    {
66322      printf ("'%c', yylval='", yychar);
66323      if (yylval.value > ' ')
66324	printf ("%c", yylval.value);
66325      printf ("', yylloc=(%d,%d),(%d,%d)",
66326	      yylloc.first_line, yylloc.first_column,
66327	      yylloc.last_line, yylloc.last_column);
66328    }
66329  printf ("\n");
66330}
66331
66332int
66333main (void)
66334{
66335  yychar = '#'; /* Not a token in the grammar.  */
66336  yylval.value = '!';
66337  return yyparse ();
66338}
66339_ATEOF
66340
66341
66342
66343$at_traceoff
66344echo "glr-regression.at:1189: bison -o glr-regr13.c glr-regr13.y"
66345echo glr-regression.at:1189 >$at_check_line_file
66346( $at_traceon; bison -o glr-regr13.c glr-regr13.y ) >$at_stdout 2>$at_stder1
66347at_status=$?
66348grep '^ *+' $at_stder1 >&2
66349grep -v '^ *+' $at_stder1 >$at_stderr
66350at_failed=false
66351$at_diff $at_devnull $at_stderr || at_failed=:
66352$at_diff $at_devnull $at_stdout || at_failed=:
66353case $at_status in
66354   77) echo 77 > $at_status_file
66355            exit 77;;
66356   0) ;;
66357   *) echo "glr-regression.at:1189: exit code was $at_status, expected 0"
66358      at_failed=:;;
66359esac
66360if $at_failed; then
66361
66362  echo 1 > $at_status_file
66363  exit 1
66364fi
66365
66366$at_traceon
66367
66368$at_traceoff
66369echo "glr-regression.at:1190: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr13 glr-regr13.c \$LIBS"
66370echo glr-regression.at:1190 >$at_check_line_file
66371( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr13 glr-regr13.c $LIBS ) >$at_stdout 2>$at_stder1
66372at_status=$?
66373grep '^ *+' $at_stder1 >&2
66374grep -v '^ *+' $at_stder1 >$at_stderr
66375at_failed=false
66376echo stderr:; cat $at_stderr
66377echo stdout:; cat $at_stdout
66378case $at_status in
66379   77) echo 77 > $at_status_file
66380            exit 77;;
66381   0) ;;
66382   *) echo "glr-regression.at:1190: exit code was $at_status, expected 0"
66383      at_failed=:;;
66384esac
66385if $at_failed; then
66386
66387  echo 1 > $at_status_file
66388  exit 1
66389fi
66390
66391$at_traceon
66392
66393
66394$at_traceoff
66395echo "glr-regression.at:1203: ./glr-regr13"
66396echo glr-regression.at:1203 >$at_check_line_file
66397( $at_traceon; ./glr-regr13 ) >$at_stdout 2>$at_stder1
66398at_status=$?
66399grep '^ *+' $at_stder1 >&2
66400grep -v '^ *+' $at_stder1 >$at_stderr
66401at_failed=false
66402$at_diff $at_devnull $at_stderr || at_failed=:
66403echo >>$at_stdout; echo "defstate_init <- empty string:
66404  yychar=YYEMPTY
66405nondefstate <- empty string:
66406  yychar='a', yylval='A', yylloc=(1,1),(1,1)
66407defstate_look <- empty string:
66408  yychar='a', yylval='A', yylloc=(1,1),(1,1)
66409defstate_shift <- nondefstate defstate_look 'a':
66410  yychar=YYEMPTY
66411start <- defstate_init defstate_shift 'b':
66412  yychar=YYEMPTY
66413" | $at_diff - $at_stdout || at_failed=:
66414case $at_status in
66415   77) echo 77 > $at_status_file
66416            exit 77;;
66417   0) ;;
66418   *) echo "glr-regression.at:1203: exit code was $at_status, expected 0"
66419      at_failed=:;;
66420esac
66421if $at_failed; then
66422
66423  echo 1 > $at_status_file
66424  exit 1
66425fi
66426
66427$at_traceon
66428
66429
66430      $at_traceoff
66431      $at_times_p && times >$at_times_file
66432    ) 5>&1 2>&1 | eval $at_tee_pipe
66433    at_status=`cat $at_status_file`
66434    ;;
66435
66436  155 ) # 155. glr-regression.at:1212: Incorrect lookahead during nondeterministic GLR
66437    at_setup_line='glr-regression.at:1212'
66438    at_desc='Incorrect lookahead during nondeterministic GLR'
66439    $at_quiet $ECHO_N "155: Incorrect lookahead during nondeterministic GLR$ECHO_C"
66440    at_xfail=no
66441    (
66442      echo "155. glr-regression.at:1212: testing ..."
66443      $at_traceon
66444
66445
66446cat >glr-regr14.y <<'_ATEOF'
66447%{
66448#ifdef HAVE_CONFIG_H
66449# include <config.h>
66450  /* We don't need perfect functions for these tests. */
66451# undef malloc
66452# undef memcmp
66453# undef realloc
66454#endif
66455%}
66456
66457
66458/* Tests:
66459     - Conflicting actions (split-off parse, which copies lookahead need,
66460       which is necessarily yytrue) and nonconflicting actions (non-split-off
66461       parse) for nondefaulted state: yychar != YYEMPTY.
66462     - Merged deferred actions (lookahead need and RHS from different stack
66463       than the target state) and nonmerged deferred actions (same stack).
66464     - Defaulted state after lookahead: yychar != YYEMPTY.
66465     - Defaulted state after shift: yychar == YYEMPTY.
66466     - yychar != YYEMPTY but lookahead need is yyfalse (a previous stack has
66467       seen the lookahead but current stack has not).
66468     - Exceeding stack capacity (stack explosion), and thus reallocating
66469       lookahead need array.
66470   Note that it does not seem possible to see the initial yychar value during
66471   nondeterministic operation since:
66472     - In order to preserve the initial yychar, only defaulted states may be
66473       entered.
66474     - If only defaulted states are entered, there are no conflicts, so
66475       nondeterministic operation does not start.  */
66476
66477%union { char value; }
66478
66479%{
66480  #include <stdio.h>
66481  static void yyerror (char const *);
66482  static int yylex (void);
66483  static void print_look_ahead (char const *);
66484  static char merge (union YYSTYPE, union YYSTYPE);
66485  #define USE(value)
66486%}
66487
66488%type <value> 'a' 'b' 'c' 'd' stack_explosion
66489%glr-parser
66490%locations
66491
66492%%
66493
66494start:
66495  merge 'c' stack_explosion {
66496    USE ($2); USE ($3);
66497    print_look_ahead ("start <- merge 'c' stack_explosion");
66498  }
66499  ;
66500
66501/* When merging the 2 deferred actions, the lookahead needs are different.  */
66502merge:
66503  nonconflict1 'a' 'b' nonconflict2 %dprec 1 {
66504    USE ($2); USE ($3);
66505    print_look_ahead ("merge <- nonconflict1 'a' 'b' nonconflict2");
66506  }
66507  | conflict defstate_look 'a' nonconflict2 'b' defstate_shift %dprec 2 {
66508    USE ($3); USE ($5);
66509    print_look_ahead ("merge <- conflict defstate_look 'a' nonconflict2 'b'"
66510		      " defstate_shift");
66511  }
66512  ;
66513
66514nonconflict1:
66515  {
66516    print_look_ahead ("nonconflict1 <- empty string");
66517  }
66518  ;
66519nonconflict2:
66520  {
66521    print_look_ahead ("nonconflict2 <- empty string");
66522  }
66523  | 'a' {
66524    USE ($1);
66525    print_look_ahead ("nonconflict2 <- 'a'");
66526  }
66527  ;
66528conflict:
66529  {
66530    print_look_ahead ("conflict <- empty string");
66531  }
66532  ;
66533defstate_look:
66534  {
66535    print_look_ahead ("defstate_look <- empty string");
66536  }
66537  ;
66538
66539/* yychar != YYEMPTY but lookahead need is yyfalse.  */
66540defstate_shift:
66541  {
66542    print_look_ahead ("defstate_shift <- empty string");
66543  }
66544  ;
66545
66546stack_explosion:
66547  { $$ = '\0'; }
66548  | alt1 stack_explosion %merge<merge> { $$ = $2; }
66549  | alt2 stack_explosion %merge<merge> { $$ = $2; }
66550  | alt3 stack_explosion %merge<merge> { $$ = $2; }
66551  ;
66552alt1:
66553  'd' no_look {
66554    USE ($1);
66555    if (yychar != 'd' && yychar != YYEOF)
66556      {
66557	fprintf (stderr, "Incorrect lookahead during stack explosion.\n");
66558      }
66559  }
66560  ;
66561alt2:
66562  'd' no_look {
66563    USE ($1);
66564    if (yychar != 'd' && yychar != YYEOF)
66565      {
66566	fprintf (stderr, "Incorrect lookahead during stack explosion.\n");
66567      }
66568  }
66569  ;
66570alt3:
66571  'd' no_look {
66572    USE ($1);
66573    if (yychar != 'd' && yychar != YYEOF)
66574      {
66575	fprintf (stderr, "Incorrect lookahead during stack explosion.\n");
66576      }
66577  }
66578  ;
66579no_look:
66580  {
66581    if (yychar != YYEMPTY)
66582      {
66583	fprintf (stderr,
66584		 "Found lookahead where shouldn't during stack explosion.\n");
66585      }
66586  }
66587  ;
66588
66589%%
66590
66591static void
66592yyerror (char const *msg)
66593{
66594  fprintf (stderr, "%s\n", msg);
66595}
66596
66597static int
66598yylex (void)
66599{
66600  static char const *input = "abcdddd";
66601  static int i = 0;
66602  yylloc.first_line = yylloc.last_line = 1;
66603  yylloc.first_column = yylloc.last_column = i + 1;
66604  yylval.value = input[i] + 'A' - 'a';
66605  return input[i++];
66606}
66607
66608static void
66609print_look_ahead (char const *reduction)
66610{
66611  printf ("%s:\n  yychar=", reduction);
66612  if (yychar == YYEMPTY)
66613    printf ("YYEMPTY");
66614  else if (yychar == YYEOF)
66615    printf ("YYEOF");
66616  else
66617    {
66618      printf ("'%c', yylval='", yychar);
66619      if (yylval.value > ' ')
66620	printf ("%c", yylval.value);
66621      printf ("', yylloc=(%d,%d),(%d,%d)",
66622	      yylloc.first_line, yylloc.first_column,
66623	      yylloc.last_line, yylloc.last_column);
66624    }
66625  printf ("\n");
66626}
66627
66628static char
66629merge (union YYSTYPE s1, union YYSTYPE s2)
66630{
66631  char dummy = s1.value + s2.value;
66632  return dummy;
66633}
66634
66635int
66636main (void)
66637{
66638  yychar = '#'; /* Not a token in the grammar.  */
66639  yylval.value = '!';
66640  return yyparse ();
66641}
66642_ATEOF
66643
66644
66645
66646$at_traceoff
66647echo "glr-regression.at:1404: bison -o glr-regr14.c glr-regr14.y"
66648echo glr-regression.at:1404 >$at_check_line_file
66649( $at_traceon; bison -o glr-regr14.c glr-regr14.y ) >$at_stdout 2>$at_stder1
66650at_status=$?
66651grep '^ *+' $at_stder1 >&2
66652grep -v '^ *+' $at_stder1 >$at_stderr
66653at_failed=false
66654echo >>$at_stderr; echo "glr-regr14.y: conflicts: 3 reduce/reduce
66655" | $at_diff - $at_stderr || at_failed=:
66656$at_diff $at_devnull $at_stdout || at_failed=:
66657case $at_status in
66658   77) echo 77 > $at_status_file
66659            exit 77;;
66660   0) ;;
66661   *) echo "glr-regression.at:1404: exit code was $at_status, expected 0"
66662      at_failed=:;;
66663esac
66664if $at_failed; then
66665
66666  echo 1 > $at_status_file
66667  exit 1
66668fi
66669
66670$at_traceon
66671
66672$at_traceoff
66673echo "glr-regression.at:1405: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr14 glr-regr14.c \$LIBS"
66674echo glr-regression.at:1405 >$at_check_line_file
66675( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr14 glr-regr14.c $LIBS ) >$at_stdout 2>$at_stder1
66676at_status=$?
66677grep '^ *+' $at_stder1 >&2
66678grep -v '^ *+' $at_stder1 >$at_stderr
66679at_failed=false
66680echo stderr:; cat $at_stderr
66681echo stdout:; cat $at_stdout
66682case $at_status in
66683   77) echo 77 > $at_status_file
66684            exit 77;;
66685   0) ;;
66686   *) echo "glr-regression.at:1405: exit code was $at_status, expected 0"
66687      at_failed=:;;
66688esac
66689if $at_failed; then
66690
66691  echo 1 > $at_status_file
66692  exit 1
66693fi
66694
66695$at_traceon
66696
66697
66698$at_traceoff
66699echo "glr-regression.at:1420: ./glr-regr14"
66700echo glr-regression.at:1420 >$at_check_line_file
66701( $at_traceon; ./glr-regr14 ) >$at_stdout 2>$at_stder1
66702at_status=$?
66703grep '^ *+' $at_stder1 >&2
66704grep -v '^ *+' $at_stder1 >$at_stderr
66705at_failed=false
66706$at_diff $at_devnull $at_stderr || at_failed=:
66707echo >>$at_stdout; echo "conflict <- empty string:
66708  yychar='a', yylval='A', yylloc=(1,1),(1,1)
66709defstate_look <- empty string:
66710  yychar='a', yylval='A', yylloc=(1,1),(1,1)
66711nonconflict2 <- empty string:
66712  yychar='b', yylval='B', yylloc=(1,2),(1,2)
66713defstate_shift <- empty string:
66714  yychar=YYEMPTY
66715merge <- conflict defstate_look 'a' nonconflict2 'b' defstate_shift:
66716  yychar=YYEMPTY
66717start <- merge 'c' stack_explosion:
66718  yychar=YYEOF
66719" | $at_diff - $at_stdout || at_failed=:
66720case $at_status in
66721   77) echo 77 > $at_status_file
66722            exit 77;;
66723   0) ;;
66724   *) echo "glr-regression.at:1420: exit code was $at_status, expected 0"
66725      at_failed=:;;
66726esac
66727if $at_failed; then
66728
66729  echo 1 > $at_status_file
66730  exit 1
66731fi
66732
66733$at_traceon
66734
66735
66736      $at_traceoff
66737      $at_times_p && times >$at_times_file
66738    ) 5>&1 2>&1 | eval $at_tee_pipe
66739    at_status=`cat $at_status_file`
66740    ;;
66741
66742  156 ) # 156. glr-regression.at:1429: Leaked semantic values when reporting ambiguity
66743    at_setup_line='glr-regression.at:1429'
66744    at_desc='Leaked semantic values when reporting ambiguity'
66745    $at_quiet $ECHO_N "156: Leaked semantic values when reporting ambiguity$ECHO_C"
66746    at_xfail=no
66747    (
66748      echo "156. glr-regression.at:1429: testing ..."
66749      $at_traceon
66750
66751
66752cat >glr-regr15.y <<'_ATEOF'
66753%{
66754#ifdef HAVE_CONFIG_H
66755# include <config.h>
66756  /* We don't need perfect functions for these tests. */
66757# undef malloc
66758# undef memcmp
66759# undef realloc
66760#endif
66761%}
66762
66763
66764%glr-parser
66765%destructor { parent_rhs_before_value = 0; } parent_rhs_before
66766
66767%{
66768# include <stdlib.h>
66769  static void yyerror (char const *);
66770  static int yylex (void);
66771  static int parent_rhs_before_value = 0;
66772# define USE(val)
66773%}
66774
66775%%
66776
66777start:
66778  alt1 %dprec 1
66779  | alt2 %dprec 2
66780  ;
66781
66782/* This stack must be merged into the other stacks *last* (added at the
66783   beginning of the semantic options list) so that yyparse will choose to clean
66784   it up rather than the tree for which some semantic actions have been
66785   performed.  Thus, if yyreportAmbiguity longjmp's to yyparse, the values from
66786   those other trees are not cleaned up.  */
66787alt1: ;
66788
66789alt2:
66790  parent_rhs_before ambiguity {
66791    USE ($1);
66792    parent_rhs_before_value = 0;
66793  }
66794  ;
66795
66796parent_rhs_before:
66797  {
66798    USE ($$);
66799    parent_rhs_before_value = 1;
66800  }
66801  ;
66802
66803ambiguity: ambiguity1 | ambiguity2 ;
66804ambiguity1: ;
66805ambiguity2: ;
66806
66807%%
66808
66809static void
66810yyerror (char const *msg)
66811{
66812  fprintf (stderr, "%s\n", msg);
66813}
66814
66815static int
66816yylex (void)
66817{
66818  return 0;
66819}
66820
66821int
66822main (void)
66823{
66824  int exit_status = yyparse () != 1;
66825  if (parent_rhs_before_value)
66826    {
66827      fprintf (stderr, "`parent_rhs_before' destructor not called.\n");
66828      exit_status = 1;
66829    }
66830  return exit_status;
66831}
66832_ATEOF
66833
66834
66835
66836$at_traceoff
66837echo "glr-regression.at:1505: bison -o glr-regr15.c glr-regr15.y"
66838echo glr-regression.at:1505 >$at_check_line_file
66839( $at_traceon; bison -o glr-regr15.c glr-regr15.y ) >$at_stdout 2>$at_stder1
66840at_status=$?
66841grep '^ *+' $at_stder1 >&2
66842grep -v '^ *+' $at_stder1 >$at_stderr
66843at_failed=false
66844echo >>$at_stderr; echo "glr-regr15.y: conflicts: 2 reduce/reduce
66845" | $at_diff - $at_stderr || at_failed=:
66846$at_diff $at_devnull $at_stdout || at_failed=:
66847case $at_status in
66848   77) echo 77 > $at_status_file
66849            exit 77;;
66850   0) ;;
66851   *) echo "glr-regression.at:1505: exit code was $at_status, expected 0"
66852      at_failed=:;;
66853esac
66854if $at_failed; then
66855
66856  echo 1 > $at_status_file
66857  exit 1
66858fi
66859
66860$at_traceon
66861
66862$at_traceoff
66863echo "glr-regression.at:1506: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr15 glr-regr15.c \$LIBS"
66864echo glr-regression.at:1506 >$at_check_line_file
66865( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr15 glr-regr15.c $LIBS ) >$at_stdout 2>$at_stder1
66866at_status=$?
66867grep '^ *+' $at_stder1 >&2
66868grep -v '^ *+' $at_stder1 >$at_stderr
66869at_failed=false
66870echo stderr:; cat $at_stderr
66871echo stdout:; cat $at_stdout
66872case $at_status in
66873   77) echo 77 > $at_status_file
66874            exit 77;;
66875   0) ;;
66876   *) echo "glr-regression.at:1506: exit code was $at_status, expected 0"
66877      at_failed=:;;
66878esac
66879if $at_failed; then
66880
66881  echo 1 > $at_status_file
66882  exit 1
66883fi
66884
66885$at_traceon
66886
66887
66888$at_traceoff
66889echo "glr-regression.at:1510: ./glr-regr15"
66890echo glr-regression.at:1510 >$at_check_line_file
66891( $at_traceon; ./glr-regr15 ) >$at_stdout 2>$at_stder1
66892at_status=$?
66893grep '^ *+' $at_stder1 >&2
66894grep -v '^ *+' $at_stder1 >$at_stderr
66895at_failed=false
66896echo >>$at_stderr; echo "syntax is ambiguous
66897" | $at_diff - $at_stderr || at_failed=:
66898$at_diff $at_devnull $at_stdout || at_failed=:
66899case $at_status in
66900   77) echo 77 > $at_status_file
66901            exit 77;;
66902   0) ;;
66903   *) echo "glr-regression.at:1510: exit code was $at_status, expected 0"
66904      at_failed=:;;
66905esac
66906if $at_failed; then
66907
66908  echo 1 > $at_status_file
66909  exit 1
66910fi
66911
66912$at_traceon
66913
66914
66915      $at_traceoff
66916      $at_times_p && times >$at_times_file
66917    ) 5>&1 2>&1 | eval $at_tee_pipe
66918    at_status=`cat $at_status_file`
66919    ;;
66920
66921  157 ) # 157. glr-regression.at:1519: Leaked lookahead after nondeterministic parse syntax error
66922    at_setup_line='glr-regression.at:1519'
66923    at_desc='Leaked lookahead after nondeterministic parse syntax error'
66924    $at_quiet $ECHO_N "157: Leaked lookahead after nondeterministic parse syntax error$ECHO_C"
66925    at_xfail=no
66926    (
66927      echo "157. glr-regression.at:1519: testing ..."
66928      $at_traceon
66929
66930cat >glr-regr16.y <<'_ATEOF'
66931%{
66932#ifdef HAVE_CONFIG_H
66933# include <config.h>
66934  /* We don't need perfect functions for these tests. */
66935# undef malloc
66936# undef memcmp
66937# undef realloc
66938#endif
66939%}
66940
66941
66942%glr-parser
66943%destructor { lookahead_value = 0; } 'b'
66944
66945%{
66946# include <stdlib.h>
66947  static void yyerror (char const *);
66948  static int yylex (void);
66949  static int lookahead_value = 0;
66950# define USE(val)
66951%}
66952
66953%%
66954
66955start: alt1 'a' | alt2 'a' ;
66956alt1: ;
66957alt2: ;
66958
66959%%
66960
66961static void
66962yyerror (char const *msg)
66963{
66964  fprintf (stderr, "%s\n", msg);
66965}
66966
66967static int
66968yylex (void)
66969{
66970  static char const *input = "ab";
66971  if (*input == 'b')
66972    lookahead_value = 1;
66973  return *input++;
66974}
66975
66976int
66977main (void)
66978{
66979  int exit_status = yyparse () != 1;
66980  if (lookahead_value)
66981    {
66982      fprintf (stderr, "Lookahead destructor not called.\n");
66983      exit_status = 1;
66984    }
66985  return exit_status;
66986}
66987_ATEOF
66988
66989
66990
66991$at_traceoff
66992echo "glr-regression.at:1571: bison -o glr-regr16.c glr-regr16.y"
66993echo glr-regression.at:1571 >$at_check_line_file
66994( $at_traceon; bison -o glr-regr16.c glr-regr16.y ) >$at_stdout 2>$at_stder1
66995at_status=$?
66996grep '^ *+' $at_stder1 >&2
66997grep -v '^ *+' $at_stder1 >$at_stderr
66998at_failed=false
66999echo >>$at_stderr; echo "glr-regr16.y: conflicts: 1 reduce/reduce
67000" | $at_diff - $at_stderr || at_failed=:
67001$at_diff $at_devnull $at_stdout || at_failed=:
67002case $at_status in
67003   77) echo 77 > $at_status_file
67004            exit 77;;
67005   0) ;;
67006   *) echo "glr-regression.at:1571: exit code was $at_status, expected 0"
67007      at_failed=:;;
67008esac
67009if $at_failed; then
67010
67011  echo 1 > $at_status_file
67012  exit 1
67013fi
67014
67015$at_traceon
67016
67017$at_traceoff
67018echo "glr-regression.at:1572: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr16 glr-regr16.c \$LIBS"
67019echo glr-regression.at:1572 >$at_check_line_file
67020( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr16 glr-regr16.c $LIBS ) >$at_stdout 2>$at_stder1
67021at_status=$?
67022grep '^ *+' $at_stder1 >&2
67023grep -v '^ *+' $at_stder1 >$at_stderr
67024at_failed=false
67025echo stderr:; cat $at_stderr
67026echo stdout:; cat $at_stdout
67027case $at_status in
67028   77) echo 77 > $at_status_file
67029            exit 77;;
67030   0) ;;
67031   *) echo "glr-regression.at:1572: exit code was $at_status, expected 0"
67032      at_failed=:;;
67033esac
67034if $at_failed; then
67035
67036  echo 1 > $at_status_file
67037  exit 1
67038fi
67039
67040$at_traceon
67041
67042
67043$at_traceoff
67044echo "glr-regression.at:1576: ./glr-regr16"
67045echo glr-regression.at:1576 >$at_check_line_file
67046( $at_traceon; ./glr-regr16 ) >$at_stdout 2>$at_stder1
67047at_status=$?
67048grep '^ *+' $at_stder1 >&2
67049grep -v '^ *+' $at_stder1 >$at_stderr
67050at_failed=false
67051echo >>$at_stderr; echo "syntax error
67052" | $at_diff - $at_stderr || at_failed=:
67053$at_diff $at_devnull $at_stdout || at_failed=:
67054case $at_status in
67055   77) echo 77 > $at_status_file
67056            exit 77;;
67057   0) ;;
67058   *) echo "glr-regression.at:1576: exit code was $at_status, expected 0"
67059      at_failed=:;;
67060esac
67061if $at_failed; then
67062
67063  echo 1 > $at_status_file
67064  exit 1
67065fi
67066
67067$at_traceon
67068
67069
67070      $at_traceoff
67071      $at_times_p && times >$at_times_file
67072    ) 5>&1 2>&1 | eval $at_tee_pipe
67073    at_status=`cat $at_status_file`
67074    ;;
67075
67076  158 ) # 158. glr-regression.at:1585: Uninitialized location when reporting ambiguity
67077    at_setup_line='glr-regression.at:1585'
67078    at_desc='Uninitialized location when reporting ambiguity'
67079    $at_quiet $ECHO_N "158: Uninitialized location when reporting ambiguity$ECHO_C"
67080    at_xfail=no
67081    (
67082      echo "158. glr-regression.at:1585: testing ..."
67083      $at_traceon
67084
67085cat >glr-regr17.y <<'_ATEOF'
67086%{
67087#ifdef HAVE_CONFIG_H
67088# include <config.h>
67089  /* We don't need perfect functions for these tests. */
67090# undef malloc
67091# undef memcmp
67092# undef realloc
67093#endif
67094%}
67095
67096
67097%glr-parser
67098%locations
67099%pure-parser
67100%error-verbose
67101
67102%union { int dummy; }
67103
67104%{
67105  static void yyerror (YYLTYPE *, char const *);
67106  static int yylex (YYSTYPE *, YYLTYPE *);
67107%}
67108
67109%initial-action {
67110  @$.first_line = 1;
67111  @$.first_column = 1;
67112  @$.last_line = 1;
67113  @$.last_column = 1;
67114}
67115
67116%%
67117
67118/* Tests the case of an empty RHS that has inherited the location of the
67119   previous nonterminal, which is unresolved.  That location is reported as the
67120   last position of the ambiguity.  */
67121start: ambig1 empty1 | ambig2 empty2 ;
67122
67123/* Tests multiple levels of yyresolveLocations recursion.  */
67124ambig1: sub_ambig1 | sub_ambig2 ;
67125ambig2: sub_ambig1 | sub_ambig2 ;
67126
67127/* Tests the case of a non-empty RHS as well as the case of an empty RHS that
67128   has inherited the initial location.  The empty RHS's location is reported as
67129   the first position in the ambiguity.  */
67130sub_ambig1: empty1 'a' 'b' ;
67131sub_ambig2: empty2 'a' 'b' ;
67132empty1: ;
67133empty2: ;
67134
67135%%
67136
67137static void
67138yyerror (YYLTYPE *locp, char const *msg)
67139{
67140  fprintf (stderr, "Error at %d.%d-%d.%d: %s.\n", locp->first_line,
67141	   locp->first_column, locp->last_line, locp->last_column, msg);
67142}
67143
67144static int
67145yylex (YYSTYPE *lvalp, YYLTYPE *llocp)
67146{
67147  static char const input[] = "ab";
67148  static char const *inputp = input;
67149  lvalp->dummy = 0;
67150  llocp->first_line = llocp->last_line = 2;
67151  llocp->first_column = inputp - input + 1;
67152  llocp->last_column = llocp->first_column + 1;
67153  return *inputp++;
67154}
67155
67156int
67157main (void)
67158{
67159  return yyparse () != 1;
67160}
67161_ATEOF
67162
67163
67164
67165$at_traceoff
67166echo "glr-regression.at:1656: bison -o glr-regr17.c glr-regr17.y"
67167echo glr-regression.at:1656 >$at_check_line_file
67168( $at_traceon; bison -o glr-regr17.c glr-regr17.y ) >$at_stdout 2>$at_stder1
67169at_status=$?
67170grep '^ *+' $at_stder1 >&2
67171grep -v '^ *+' $at_stder1 >$at_stderr
67172at_failed=false
67173echo >>$at_stderr; echo "glr-regr17.y: conflicts: 3 reduce/reduce
67174" | $at_diff - $at_stderr || at_failed=:
67175$at_diff $at_devnull $at_stdout || at_failed=:
67176case $at_status in
67177   77) echo 77 > $at_status_file
67178            exit 77;;
67179   0) ;;
67180   *) echo "glr-regression.at:1656: exit code was $at_status, expected 0"
67181      at_failed=:;;
67182esac
67183if $at_failed; then
67184
67185  echo 1 > $at_status_file
67186  exit 1
67187fi
67188
67189$at_traceon
67190
67191$at_traceoff
67192echo "glr-regression.at:1657: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o glr-regr17 glr-regr17.c \$LIBS"
67193echo glr-regression.at:1657 >$at_check_line_file
67194( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o glr-regr17 glr-regr17.c $LIBS ) >$at_stdout 2>$at_stder1
67195at_status=$?
67196grep '^ *+' $at_stder1 >&2
67197grep -v '^ *+' $at_stder1 >$at_stderr
67198at_failed=false
67199echo stderr:; cat $at_stderr
67200echo stdout:; cat $at_stdout
67201case $at_status in
67202   77) echo 77 > $at_status_file
67203            exit 77;;
67204   0) ;;
67205   *) echo "glr-regression.at:1657: exit code was $at_status, expected 0"
67206      at_failed=:;;
67207esac
67208if $at_failed; then
67209
67210  echo 1 > $at_status_file
67211  exit 1
67212fi
67213
67214$at_traceon
67215
67216
67217$at_traceoff
67218echo "glr-regression.at:1661: ./glr-regr17"
67219echo glr-regression.at:1661 >$at_check_line_file
67220( $at_traceon; ./glr-regr17 ) >$at_stdout 2>$at_stder1
67221at_status=$?
67222grep '^ *+' $at_stder1 >&2
67223grep -v '^ *+' $at_stder1 >$at_stderr
67224at_failed=false
67225echo >>$at_stderr; echo "Error at 1.1-2.3: syntax is ambiguous.
67226" | $at_diff - $at_stderr || at_failed=:
67227$at_diff $at_devnull $at_stdout || at_failed=:
67228case $at_status in
67229   77) echo 77 > $at_status_file
67230            exit 77;;
67231   0) ;;
67232   *) echo "glr-regression.at:1661: exit code was $at_status, expected 0"
67233      at_failed=:;;
67234esac
67235if $at_failed; then
67236
67237  echo 1 > $at_status_file
67238  exit 1
67239fi
67240
67241$at_traceon
67242
67243
67244      $at_traceoff
67245      $at_times_p && times >$at_times_file
67246    ) 5>&1 2>&1 | eval $at_tee_pipe
67247    at_status=`cat $at_status_file`
67248    ;;
67249
67250
67251  * )
67252    echo "$as_me: no such test group: $at_group" >&2
67253    continue
67254    ;;
67255  esac
67256
67257  # Be sure to come back to the suite directory, in particular
67258  # since below we might `rm' the group directory we are in currently.
67259  cd $at_suite_dir
67260
67261  case $at_group in
67262    banner-*) ;;
67263    *)
67264      if test ! -f $at_check_line_file; then
67265	sed "s/^ */$as_me: warning: /" <<_ATEOF
67266	A failure happened in a test group before any test could be
67267	run. This means that test suite is improperly designed.  Please
67268	report this failure to <bug-bison@gnu.org>.
67269_ATEOF
67270    	echo "$at_setup_line" >$at_check_line_file
67271      fi
67272      at_group_count=`expr 1 + $at_group_count`
67273      $at_verbose $ECHO_N "$at_group. $at_setup_line: $ECHO_C"
67274      echo $ECHO_N "$at_group. $at_setup_line: $ECHO_C" >> $at_group_log
67275      case $at_xfail:$at_status in
67276	yes:0)
67277	    at_msg="UNEXPECTED PASS"
67278	    at_xpass_list="$at_xpass_list $at_group"
67279	    at_errexit=$at_errexit_p
67280	    ;;
67281	no:0)
67282	    at_msg="ok"
67283	    at_pass_list="$at_pass_list $at_group"
67284	    at_errexit=false
67285	    ;;
67286	*:77)
67287	    at_msg="skipped (`cat $at_check_line_file`)"
67288	    at_skip_list="$at_skip_list $at_group"
67289	    at_errexit=false
67290	    ;;
67291	yes:*)
67292	    at_msg="expected failure (`cat $at_check_line_file`)"
67293	    at_xfail_list="$at_xfail_list $at_group"
67294	    at_errexit=false
67295	    ;;
67296	no:*)
67297	    at_msg="FAILED (`cat $at_check_line_file`)"
67298	    at_fail_list="$at_fail_list $at_group"
67299	    at_errexit=$at_errexit_p
67300	    ;;
67301      esac
67302      echo $at_msg
67303      at_log_msg="$at_group. $at_desc ($at_setup_line): $at_msg"
67304      case $at_status in
67305	0|77)
67306	  # $at_times_file is only available if the group succeeded.
67307	  # We're not including the group log, so the success message
67308	  # is written in the global log separately.  But we also
67309	  # write to the group log in case they're using -d.
67310	  if test -f $at_times_file; then
67311	    at_log_msg="$at_log_msg	(`sed 1d $at_times_file`)"
67312	    rm -f $at_times_file
67313          fi
67314	  echo "$at_log_msg" >> $at_group_log
67315	  echo "$at_log_msg" >&5
67316
67317	  # Cleanup the group directory, unless the user wants the files.
67318	  $at_debug_p || rm -rf $at_group_dir
67319	  ;;
67320	*)
67321	  # Upon failure, include the log into the testsuite's global
67322	  # log.  The failure message is written in the group log.  It
67323	  # is later included in the global log.
67324	  echo "$at_log_msg" >> $at_group_log
67325
67326	  # Upon failure, keep the group directory for autopsy, and
67327	  # create the debugging script.
67328	  {
67329	    echo "#! /bin/sh"
67330	    echo 'test "${ZSH_VERSION+set}" = set && alias -g '\''${1+"$@"}'\''='\''"$@"'\'''
67331	    echo "cd $at_dir"
67332	    echo 'exec ${CONFIG_SHELL-'"$SHELL"'}' "$0" \
67333	         '-v -d' "$at_debug_args" "$at_group" '${1+"$@"}'
67334	    echo 'exit 1'
67335	  } >$at_group_dir/run
67336	  chmod +x $at_group_dir/run
67337	  $at_errexit && break
67338	  ;;
67339      esac
67340      ;;
67341  esac
67342done
67343
67344# Back to the top directory.
67345cd $at_dir
67346
67347# Compute the duration of the suite.
67348at_stop_date=`date`
67349at_stop_time=`(date +%s) 2>/dev/null`
67350echo "$as_me: ending at: $at_stop_date" >&5
67351at_duration_s=`(expr $at_stop_time - $at_start_time) 2>/dev/null`
67352at_duration_m=`(expr $at_duration_s / 60) 2>/dev/null`
67353at_duration_h=`(expr $at_duration_m / 60) 2>/dev/null`
67354at_duration_s=`(expr $at_duration_s % 60) 2>/dev/null`
67355at_duration_m=`(expr $at_duration_m % 60) 2>/dev/null`
67356at_duration="${at_duration_h}h ${at_duration_m}m ${at_duration_s}s"
67357if test "$at_duration" != "h m s"; then
67358  echo "$as_me: test suite duration: $at_duration" >&5
67359fi
67360
67361# Wrap up the test suite with summary statistics.
67362at_skip_count=`set dummy $at_skip_list; shift; echo $#`
67363at_fail_count=`set dummy $at_fail_list; shift; echo $#`
67364at_xpass_count=`set dummy $at_xpass_list; shift; echo $#`
67365at_xfail_count=`set dummy $at_xfail_list; shift; echo $#`
67366
67367at_run_count=`expr $at_group_count - $at_skip_count`
67368at_unexpected_count=`expr $at_xpass_count + $at_fail_count`
67369at_total_fail_count=`expr $at_xfail_count + $at_fail_count`
67370
67371echo
67372cat <<\_ASBOX
67373## ------------- ##
67374## Test results. ##
67375## ------------- ##
67376_ASBOX
67377echo
67378{
67379  echo
67380  cat <<\_ASBOX
67381## ------------- ##
67382## Test results. ##
67383## ------------- ##
67384_ASBOX
67385  echo
67386} >&5
67387
67388if test $at_run_count = 1; then
67389  at_result="1 test"
67390  at_were=was
67391else
67392  at_result="$at_run_count tests"
67393  at_were=were
67394fi
67395if $at_errexit_p && test $at_unexpected_count != 0; then
67396  if test $at_xpass_count = 1; then
67397    at_result="$at_result $at_were run, one passed"
67398  else
67399    at_result="$at_result $at_were run, one failed"
67400  fi
67401  at_result="$at_result unexpectedly and inhibited subsequent tests."
67402else
67403  # Don't you just love exponential explosion of the number of cases?
67404  case $at_xpass_count:$at_fail_count:$at_xfail_count in
67405    # So far, so good.
67406    0:0:0) at_result="$at_result $at_were successful." ;;
67407    0:0:*) at_result="$at_result behaved as expected." ;;
67408
67409    # Some unexpected failures
67410    0:*:0) at_result="$at_result $at_were run,
67411$at_fail_count failed unexpectedly." ;;
67412
67413    # Some failures, both expected and unexpected
67414    0:*:1) at_result="$at_result $at_were run,
67415$at_total_fail_count failed ($at_xfail_count expected failure)." ;;
67416    0:*:*) at_result="$at_result $at_were run,
67417$at_total_fail_count failed ($at_xfail_count expected failures)." ;;
67418
67419    # No unexpected failures, but some xpasses
67420    *:0:*) at_result="$at_result $at_were run,
67421$at_xpass_count passed unexpectedly." ;;
67422
67423    # No expected failures, but failures and xpasses
67424    *:1:0) at_result="$at_result $at_were run,
67425$at_unexpected_count did not behave as expected ($at_fail_count unexpected failure)." ;;
67426    *:*:0) at_result="$at_result $at_were run,
67427$at_unexpected_count did not behave as expected ($at_fail_count unexpected failures)." ;;
67428
67429    # All of them.
67430    *:*:1) at_result="$at_result $at_were run,
67431$at_xpass_count passed unexpectedly,
67432$at_total_fail_count failed ($at_xfail_count expected failure)." ;;
67433    *:*:*) at_result="$at_result $at_were run,
67434$at_xpass_count passed unexpectedly,
67435$at_total_fail_count failed ($at_xfail_count expected failures)." ;;
67436  esac
67437
67438  if test $at_skip_count = 0 && test $at_run_count -gt 1; then
67439    at_result="All $at_result"
67440  fi
67441fi
67442
67443# Now put skips in the mix.
67444case $at_skip_count in
67445  0) ;;
67446  1) at_result="$at_result
674471 test was skipped." ;;
67448  *) at_result="$at_result
67449$at_skip_count tests were skipped." ;;
67450esac
67451
67452if test $at_unexpected_count = 0; then
67453  echo "$at_result"
67454  echo "$at_result" >&5
67455else
67456  echo "ERROR: $at_result" >&2
67457  echo "ERROR: $at_result" >&5
67458  {
67459    echo
67460    cat <<\_ASBOX
67461## ------------------------ ##
67462## Summary of the failures. ##
67463## ------------------------ ##
67464_ASBOX
67465
67466    # Summary of failed and skipped tests.
67467    if test $at_fail_count != 0; then
67468      echo "Failed tests:"
67469      $SHELL $0 $at_fail_list --list
67470      echo
67471    fi
67472    if test $at_skip_count != 0; then
67473      echo "Skipped tests:"
67474      $SHELL $0 $at_skip_list --list
67475      echo
67476    fi
67477    if test $at_xpass_count != 0; then
67478      echo "Unexpected passes:"
67479      $SHELL $0 $at_xpass_list --list
67480      echo
67481    fi
67482    if test $at_fail_count != 0; then
67483      cat <<\_ASBOX
67484## ---------------------- ##
67485## Detailed failed tests. ##
67486## ---------------------- ##
67487_ASBOX
67488      echo
67489      for at_group in $at_fail_list
67490      do
67491        # Normalize the test group number.
67492        at_group_normalized=`expr "00000$at_group" : ".*\($at_format\)"`
67493        # Create a fresh directory for the next test group, and enter.
67494        at_group_dir=$at_suite_dir/$at_group_normalized
67495        at_group_log=$at_group_dir/$as_me.log
67496        cat $at_group_log
67497        echo
67498      done
67499      echo
67500    fi
67501    if test -n "$at_top_srcdir"; then
67502      sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
67503## $at_top_builddir/config.log ##
67504_ASBOX
67505      sed 's/^/| /' $at_top_builddir/config.log
67506      echo
67507    fi
67508  } >&5
67509
67510  sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
67511## $as_me.log was created. ##
67512_ASBOX
67513
67514  echo
67515  echo "Please send \`$as_me.log' and all information you think might help:"
67516  echo
67517  echo "   To: <bug-bison@gnu.org>"
67518  echo "   Subject: [GNU Bison 2.3] $as_me:$at_fail_list${at_fail_list:+ failed${at_xpass_list:+,}}$at_xpass_list${at_xpass_list:+ passed unexpectedly}"
67519  echo
67520  if test $at_debug_p = false; then
67521    echo
67522    echo 'You may investigate any problem if you feel able to do so, in which'
67523    echo 'case the test suite provides a good starting point.'
67524    echo
67525  fi
67526    exit 1
67527fi
67528
67529exit 0
67530
67531
67532