1 #! /bin/sh 2 ## --------------------- ## 3 ## M4sh Initialization. ## 4 ## --------------------- ## 5 6 # Be Bourne compatible 7 if 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+"$@"}'='"$@"' 13 elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then 14 set -o posix 15 fi 16 DUALCASE=1; export DUALCASE # for MKS sh 17 18 # Support unset when possible. 19 if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then 20 as_unset=unset 21 else 22 as_unset=false 23 fi 24 25 26 # Work around bugs in pre-3.0 UWIN ksh. 27 $as_unset ENV MAIL MAILPATH 28 PS1='$ ' 29 PS2='> ' 30 PS4='+ ' 31 32 # NLS nuisances. 33 for 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 37 do 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 43 done 44 45 # Required to use basename. 46 if expr a : '\(a\)' >/dev/null 2>&1; then 47 as_expr=expr 48 else 49 as_expr=false 50 fi 51 52 if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then 53 as_basename=basename 54 else 55 as_basename=false 56 fi 57 58 59 # Name of the executable. 60 as_me=`$as_basename "$0" || 61 $as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \ 62 X"$0" : 'X\(//\)$' \| \ 63 X"$0" : 'X\(/\)$' \| \ 64 . : '\(.\)' 2>/dev/null || 65 echo 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. 74 as_cr_letters='abcdefghijklmnopqrstuvwxyz' 75 as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ' 76 as_cr_Letters=$as_cr_letters$as_cr_LETTERS 77 as_cr_digits='0123456789' 78 as_cr_alnum=$as_cr_Letters$as_cr_digits 79 80 # The user is always right. 81 if 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 91 fi 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 104 for as_dir in $PATH 105 do 106 IFS=$as_save_IFS 107 test -z "$as_dir" && as_dir=. 108 test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break 109 done 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 125 for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH 126 do 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 146 done 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 181 case `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= ;; 186 esac 187 188 if expr a : '\(a\)' >/dev/null 2>&1; then 189 as_expr=expr 190 else 191 as_expr=false 192 fi 193 194 rm -f conf$$ conf$$.exe conf$$.file 195 echo >conf$$.file 196 if 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 205 elif ln conf$$.file conf$$ 2>/dev/null; then 206 as_ln_s=ln 207 else 208 as_ln_s='cp -p' 209 fi 210 rm -f conf$$ conf$$.exe conf$$.file 211 212 if mkdir -p . 2>/dev/null; then 213 as_mkdir_p=: 214 else 215 test -d ./-p && rmdir ./-p 216 as_mkdir_p=false 217 fi 218 219 as_executable_p="test -f" 220 221 # Sed expression to map a string onto a valid CPP name. 222 as_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. 225 as_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. 230 as_nl=' 231 ' 232 IFS=" $as_nl" 233 234 # CDPATH. 235 $as_unset CDPATH 236 237 238 SHELL=${CONFIG_SHELL-/bin/sh} 239 240 # How were we run? 241 at_cli_args="$@" 242 243 # Load the config file. 244 for at_file in atconfig atlocal 245 do 246 test -r $at_file || continue 247 . ./$at_file || { echo "$as_me: error: invalid content: $at_file" >&2 248 { (exit 1); exit 1; }; } 249 done 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. 253 if 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 260 fi 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. 264 at_times_p=false 265 (times) >/dev/null 2>&1 && at_times_p=: 266 267 # CLI Arguments to pass to the debugging scripts. 268 at_debug_args= 269 # -e sets to true 270 at_errexit_p=false 271 # Shall we be verbose? 272 at_verbose=: 273 at_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. 277 at_debug_p=false 278 # Display help message? 279 at_help_p=false 280 # List test groups? 281 at_list_p=false 282 # Test groups to run 283 at_groups= 284 285 # The directory we are in. 286 at_dir=`pwd` 287 # The directory the whole suite works in. 288 # Should be absolutely to let the user `cd' at will. 289 at_suite_dir=$at_dir/$as_me.dir 290 # The file containing the suite. 291 at_suite_log=$at_dir/$as_me.log 292 # The file containing the location of the last AT_CHECK. 293 at_check_line_file=$at_suite_dir/at-check-line 294 # The file containing the exit status of the last command. 295 at_status_file=$at_suite_dir/at-status 296 # The files containing the output of the tested commands. 297 at_stdout=$at_suite_dir/at-stdout 298 at_stder1=$at_suite_dir/at-stder1 299 at_stderr=$at_suite_dir/at-stderr 300 # The file containing dates. 301 at_times_file=$at_suite_dir/at-times 302 303 # List of the tested programs. 304 at_tested='bison' 305 # List of the all the test groups. 306 at_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. 310 at_format='...' 311 # Description of all the test groups. 312 at_help_all='1;input.at:28;Invalid dollar-n;; 313 2;input.at:46;Invalid @n;; 314 3;input.at:64;Type Clashes;; 315 4;input.at:89;Unused values;; 316 5;input.at:157;Incompatible Aliases;; 317 6;input.at:198;Torturing the Scanner;; 318 7;input.at:357;Typed symbol aliases;; 319 8;input.at:393;Require 1.0;; 320 9;input.at:394;Require 2.3;; 321 10;input.at:396;Require 100.0;; 322 11;output.at:43;Output files: -dv ;; 323 12;output.at:46;Output files: -dv >&-;; 324 13;output.at:48;Output files: -dv -o foo.c ;; 325 14;output.at:50;Output files: -dv -o foo.tab.c ;; 326 15;output.at:52;Output files: -dv -y ;; 327 16;output.at:54;Output files: -dv -b bar ;; 328 17;output.at:56;Output files: -dv -g -o foo.c ;; 329 18;output.at:60;Output files: %defines %verbose ;; 330 19;output.at:62;Output files: %defines %verbose %yacc ;; 331 20;output.at:65;Output files: %defines %verbose %yacc ;; 332 21;output.at:69;Output files: %file-prefix="bar" %defines %verbose ;; 333 22;output.at:71;Output files: %output="bar.c" %defines %verbose %yacc ;; 334 23;output.at:75;Output files: %file-prefix="baz" %output="bar.c" %defines %verbose %yacc ;; 335 24;output.at:80;Output files: %defines %verbose ;; 336 25;output.at:83;Output files: %defines %verbose -o foo.c ;; 337 26;output.at:87;Output files: --defines=foo.hpp -o foo.c++ ;; 338 27;output.at:91;Output files: -o foo.c++ --graph=foo.gph ;; 339 28;output.at:105;Output files: %skeleton "lalr1.cc" %defines %verbose ;; 340 29;output.at:109;Output files: %skeleton "lalr1.cc" %defines %verbose ;; 341 30;output.at:114;Output files: %skeleton "lalr1.cc" %defines %verbose -o subdir/foo.cc ;; 342 31;sets.at:66;Nullable;; 343 32;sets.at:151;Broken Closure;; 344 33;sets.at:193;Firsts;; 345 34;sets.at:269;Accept;; 346 35;reduce.at:26;Useless Terminals;; 347 36;reduce.at:70;Useless Nonterminals;; 348 37;reduce.at:125;Useless Rules;report; 349 38;reduce.at:212;Reduced Automaton;report; 350 39;reduce.at:301;Underivable Rules;report; 351 40;reduce.at:342;Empty Language;; 352 41;synclines.at:95;Prologue synch line;; 353 42;synclines.at:115;%union synch line;; 354 43;synclines.at:138;Postprologue synch line;; 355 44;synclines.at:157;Action synch line;; 356 45;synclines.at:175;Epilogue synch line;; 357 46;headers.at:27;%union and --defines;; 358 47;headers.at:77;Invalid CPP guards: input/input;; 359 48;headers.at:78;Invalid CPP guards: 9foo;; 360 49;headers.at:87;export YYLTYPE;; 361 50;actions.at:25;Mid-rule actions;; 362 51;actions.at:91;Exotic Dollars;; 363 52;actions.at:527;Printers and Destructors : ;; 364 53;actions.at:528;Printers and Destructors with union: ;; 365 54;actions.at:533;Printers and Destructors : %defines %skeleton "lalr1.cc";c++; 366 55;actions.at:534;Printers and Destructors with union: %defines %skeleton "lalr1.cc";c++; 367 56;actions.at:536;Printers and Destructors : %glr-parser;; 368 57;actions.at:537;Printers and Destructors with union: %glr-parser;; 369 58;conflicts.at:32;S/R in initial;; 370 59;conflicts.at:52;%nonassoc and eof;; 371 60;conflicts.at:128;Unresolved SR Conflicts;report; 372 61;conflicts.at:235;Resolved SR Conflicts;report; 373 62;conflicts.at:357;Defaulted Conflicted Reduction;report; 374 63;conflicts.at:476;%expect not enough;; 375 64;conflicts.at:496;%expect right;; 376 65;conflicts.at:513;%expect too much;; 377 66;conflicts.at:533;%expect with reduce conflicts;; 378 67;conflicts.at:553;%no-default-prec without %prec;; 379 68;conflicts.at:579;%no-default-prec with %prec;; 380 69;conflicts.at:603;%default-prec;; 381 70;calc.at:550;Calculator ;; 382 71;calc.at:552;Calculator %defines;; 383 72;calc.at:553;Calculator %locations;; 384 73;calc.at:554;Calculator %name-prefix="calc";; 385 74;calc.at:555;Calculator %verbose;; 386 75;calc.at:556;Calculator %yacc;; 387 76;calc.at:557;Calculator %error-verbose;; 388 77;calc.at:559;Calculator %pure-parser %locations;; 389 78;calc.at:560;Calculator %error-verbose %locations;; 390 79;calc.at:562;Calculator %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc;; 391 80;calc.at:564;Calculator %debug;; 392 81;calc.at:565;Calculator %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc;; 393 82;calc.at:567;Calculator %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc;; 394 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};; 395 84;calc.at:586;Calculator %glr-parser ;; 396 85;calc.at:588;Calculator %glr-parser %defines;; 397 86;calc.at:589;Calculator %glr-parser %locations;; 398 87;calc.at:590;Calculator %glr-parser %name-prefix="calc";; 399 88;calc.at:591;Calculator %glr-parser %verbose;; 400 89;calc.at:592;Calculator %glr-parser %yacc;; 401 90;calc.at:593;Calculator %glr-parser %error-verbose;; 402 91;calc.at:595;Calculator %glr-parser %pure-parser %locations;; 403 92;calc.at:596;Calculator %glr-parser %error-verbose %locations;; 404 93;calc.at:598;Calculator %glr-parser %error-verbose %locations %defines %name-prefix="calc" %verbose %yacc;; 405 94;calc.at:600;Calculator %glr-parser %debug;; 406 95;calc.at:601;Calculator %glr-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc;; 407 96;calc.at:603;Calculator %glr-parser %pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc;; 408 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};; 409 98;calc.at:621;Calculator %skeleton "lalr1.cc" %defines %locations ;c++; 410 99;calc.at:622;Calculator %skeleton "lalr1.cc" %defines %locations %error-verbose %name-prefix="calc" %verbose %yacc;c++; 411 100;calc.at:624;Calculator %skeleton "lalr1.cc" %defines %locations %error-verbose %debug %name-prefix="calc" %verbose %yacc;c++; 412 101;calc.at:626;Calculator %skeleton "lalr1.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc;c++; 413 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};c++; 414 103;calc.at:651;Calculator %skeleton "glr.cc" %defines %locations %pure-parser %error-verbose %debug %name-prefix="calc" %verbose %yacc;c++; 415 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};c++; 416 105;torture.at:140;Big triangle;; 417 106;torture.at:232;Big horizontal;; 418 107;torture.at:368;Many look-ahead tokens;; 419 108;torture.at:445;Exploding the Stack Size with Alloca;; 420 109;torture.at:471;Exploding the Stack Size with Malloc;; 421 110;existing.at:26;GNU AWK Grammar;; 422 111;existing.at:364;GNU Cim Grammar;; 423 112;existing.at:980;GNU pic Grammar;; 424 113;regression.at:28;Trivial grammars;; 425 114;regression.at:57;Early token definitions;; 426 115;regression.at:95;Braces parsing;; 427 116;regression.at:117;Duplicate string;; 428 117;regression.at:143;Rule Line Numbers;report; 429 118;regression.at:287;Mixing %token styles;; 430 119;regression.at:310;Invalid inputs;; 431 120;regression.at:336;Invalid inputs with {};; 432 121;regression.at:363;Token definitions;; 433 122;regression.at:416;Characters Escapes;; 434 123;regression.at:447;Web2c Report;report; 435 124;regression.at:624;Web2c Actions;report; 436 125;regression.at:866;Dancer ;; 437 126;regression.at:867;Dancer %glr-parser;; 438 127;regression.at:868;Dancer %skeleton "lalr1.cc";c++; 439 128;regression.at:963;Expecting two tokens ;; 440 129;regression.at:964;Expecting two tokens %glr-parser;; 441 130;regression.at:965;Expecting two tokens %skeleton "lalr1.cc";c++; 442 131;c++.at:102;Doxygen Public Documentation;; 443 132;c++.at:103;Doxygen Private Documentation;; 444 133;cxx-type.at:412;GLR: Resolve ambiguity, impure, no locations;; 445 134;cxx-type.at:419;GLR: Resolve ambiguity, impure, locations;; 446 135;cxx-type.at:425;GLR: Resolve ambiguity, pure, no locations;; 447 136;cxx-type.at:432;GLR: Resolve ambiguity, pure, locations;; 448 137;cxx-type.at:439;GLR: Merge conflicting parses, impure, no locations;; 449 138;cxx-type.at:446;GLR: Merge conflicting parses, impure, locations;; 450 139;cxx-type.at:453;GLR: Merge conflicting parses, pure, no locations;; 451 140;cxx-type.at:459;GLR: Merge conflicting parses, pure, locations;; 452 141;cxx-type.at:466;GLR: Verbose messages, resolve ambiguity, impure, no locations;; 453 142;glr-regression.at:25;Badly Collapsed GLR States;; 454 143;glr-regression.at:116;Improper handling of embedded actions and dollar(-N) in GLR parsers;; 455 144;glr-regression.at:232;Improper merging of GLR delayed action sets;; 456 145;glr-regression.at:337;Duplicate representation of merged trees;; 457 146;glr-regression.at:432;User destructor for unresolved GLR semantic value;; 458 147;glr-regression.at:502;User destructor after an error during a split parse;; 459 148;glr-regression.at:566;Duplicated user destructor for lookahead;; 460 149;glr-regression.at:644;Incorrectly initialized location for empty right-hand side in GLR;; 461 150;glr-regression.at:740;No users destructors if stack 0 deleted;; 462 151;glr-regression.at:820;Corrupted semantic options if user action cuts parse;; 463 152;glr-regression.at:881;Undesirable destructors if user action cuts parse;; 464 153;glr-regression.at:947;Leaked semantic values if user action cuts parse;; 465 154;glr-regression.at:1078;Incorrect lookahead during deterministic GLR;; 466 155;glr-regression.at:1212;Incorrect lookahead during nondeterministic GLR;; 467 156;glr-regression.at:1429;Leaked semantic values when reporting ambiguity;; 468 157;glr-regression.at:1519;Leaked lookahead after nondeterministic parse syntax error;; 469 158;glr-regression.at:1585;Uninitialized location when reporting ambiguity;; 470 ' 471 472 at_keywords= 473 at_prev= 474 for at_option 475 do 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 582 done 583 584 # Process the --keywords 585 if 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 " 597 fi 598 599 # Selected test groups. 600 test -z "$at_groups" && at_groups=$at_groups_all 601 602 # Help message. 603 if $at_help_p; then 604 cat <<_ATEOF 605 Usage: $0 [OPTION]... [VARIABLE=VALUE]... [TESTS] 606 607 Run all the tests, or the selected TESTS, and save a detailed log file. 608 Upon failure, create debugging scripts. 609 610 You should not change environment variables unless explicitly passed 611 as command line arguments. Set \`AUTOTEST_PATH' to select the executables 612 to exercise. Each relative directory is expanded as build and source 613 directories relatively to the top level of this distribution. E.g., 614 615 $ $0 AUTOTEST_PATH=bin 616 617 possibly amounts into 618 619 PATH=/tmp/foo-1.0/bin:/src/foo-1.0/bin:\$PATH 620 _ATEOF 621 cat <<_ATEOF 622 623 Operation 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 629 cat <<_ATEOF 630 631 Execution 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 642 cat <<_ATEOF 643 644 Report bugs to <bug-bison@gnu.org>. 645 _ATEOF 646 exit 0 647 fi 648 649 # List of tests. 650 if $at_list_p; then 651 cat <<_ATEOF 652 GNU 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 666 fi 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. 678 AUTOTEST_PATH=`echo $AUTOTEST_PATH | tr ':' $PATH_SEPARATOR` 679 at_path= 680 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR 681 for as_dir in $AUTOTEST_PATH $PATH 682 do 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 ;; 699 esac 700 done 701 702 703 # Now build and simplify PATH. 704 PATH= 705 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR 706 for as_dir in $at_path 707 do 708 IFS=$as_save_IFS 709 test -z "$as_dir" && as_dir=. 710 as_dir=`(cd "$as_dir" && pwd) 2>/dev/null` 711 test -d "$as_dir" || continue 712 case $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 ;; 720 esac 721 done 722 723 export 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 729 exec 5>$at_suite_log 730 731 # Banners and logs. 732 cat <<\_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 { 768 cat <<_ASUNAME 769 ## --------- ## 770 ## Platform. ## 771 ## --------- ## 772 773 hostname = `(hostname || uname -n) 2>/dev/null | sed 1q` 774 uname -m = `(uname -m) 2>/dev/null || echo unknown` 775 uname -r = `(uname -r) 2>/dev/null || echo unknown` 776 uname -s = `(uname -s) 2>/dev/null || echo unknown` 777 uname -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` 785 hostinfo = `(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 792 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR 793 for as_dir in $PATH 794 do 795 IFS=$as_save_IFS 796 test -z "$as_dir" && as_dir=. 797 echo "PATH: $as_dir" 798 done 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. 822 for at_program in : $at_tested 823 do 824 test "$at_program" = : && continue 825 as_save_IFS=$IFS; IFS=$PATH_SEPARATOR 826 for as_dir in $PATH 827 do 828 IFS=$as_save_IFS 829 test -z "$as_dir" && as_dir=. 830 test -f $as_dir/$at_program && break 831 done 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 841 echo "$as_me: error: cannot find $at_program" >&2;} 842 { (exit 1); exit 1; }; } 843 fi 844 done 845 846 { 847 cat <<\_ASBOX 848 ## ------------------ ## 849 ## Running the tests. ## 850 ## ------------------ ## 851 _ASBOX 852 } >&5 853 854 at_start_date=`date` 855 at_start_time=`(date +%s) 2>/dev/null` 856 echo "$as_me: starting at: $at_start_date" >&5 857 at_xpass_list= 858 at_xfail_list= 859 at_pass_list= 860 at_fail_list= 861 at_skip_list= 862 at_group_count=0 863 864 # Create the master directory if it doesn't already exist. 865 test -d $at_suite_dir || 866 mkdir $at_suite_dir || 867 { { echo "$as_me:$LINENO: error: cannot create $at_suite_dir" >&5 868 echo "$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. 872 if diff /dev/null /dev/null >/dev/null 2>&1; then 873 at_devnull=/dev/null 874 else 875 at_devnull=$at_suite_dir/devnull 876 cp /dev/null $at_devnull 877 fi 878 879 # Use `diff -u' when possible. 880 if diff -u $at_devnull $at_devnull >/dev/null 2>&1; then 881 at_diff='diff -u' 882 else 883 at_diff=diff 884 fi 885 886 887 for at_group in $at_groups 888 do 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 913 echo "$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 937 Input 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 952 cat >input.y <<'_ATEOF' 953 %% 954 exp: { $$ = $1 ; }; 955 _ATEOF 956 957 958 $at_traceoff 959 echo "input.at:37: bison input.y" 960 echo input.at:37 >$at_check_line_file 961 ( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1 962 at_status=$? 963 grep '^ *+' $at_stder1 >&2 964 grep -v '^ *+' $at_stder1 >$at_stderr 965 at_failed=false 966 echo >>$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=: 969 case $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=:;; 975 esac 976 if $at_failed; then 977 978 echo 1 > $at_status_file 979 exit 1 980 fi 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 1001 cat >input.y <<'_ATEOF' 1002 %% 1003 exp: { @$ = @1 ; }; 1004 _ATEOF 1005 1006 1007 $at_traceoff 1008 echo "input.at:55: bison input.y" 1009 echo input.at:55 >$at_check_line_file 1010 ( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1 1011 at_status=$? 1012 grep '^ *+' $at_stder1 >&2 1013 grep -v '^ *+' $at_stder1 >$at_stderr 1014 at_failed=false 1015 echo >>$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=: 1018 case $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=:;; 1024 esac 1025 if $at_failed; then 1026 1027 echo 1 > $at_status_file 1028 exit 1 1029 fi 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 1050 cat >input.y <<'_ATEOF' 1051 %token foo 1052 %type <bar> exp 1053 %% 1054 exp: foo {} foo 1055 | foo 1056 | /* Empty. */ 1057 ; 1058 _ATEOF 1059 1060 1061 $at_traceoff 1062 echo "input.at:80: bison input.y" 1063 echo input.at:80 >$at_check_line_file 1064 ( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1 1065 at_status=$? 1066 grep '^ *+' $at_stder1 >&2 1067 grep -v '^ *+' $at_stder1 >$at_stderr 1068 at_failed=false 1069 echo >>$at_stderr; echo "input.y:4.6-15: warning: type clash on default action: <bar> != <> 1070 input.y:5.6-8: warning: type clash on default action: <bar> != <> 1071 input.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=: 1074 case $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=:;; 1080 esac 1081 if $at_failed; then 1082 1083 echo 1 > $at_status_file 1084 exit 1 1085 fi 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 1106 cat >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 %% 1111 start: 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 1117 a: INT | INT { } INT { } INT { }; 1118 b: INT | /* empty */; 1119 c: INT | INT { $1 } INT { } INT { }; 1120 d: INT | INT { } INT { $1 } INT { }; 1121 e: INT | INT { } INT { } INT { $1 }; 1122 f: INT | INT { } INT { } INT { $$ = $1 + $3 + $5; }; 1123 g: INT | INT { $$ } INT { $$ } INT { }; 1124 h: INT | INT { $$ } INT { $$ = $2 } INT { }; 1125 i: INT | INT INT { } { $$ = $1 + $2; }; 1126 j: INT | INT INT { $<integer>$ = 1; } { $$ = $1 + $2; }; 1127 k: INT | INT INT { $$; } { $$ = $3; } { }; 1128 l: INT | INT { $$ = $1; } INT { $$ = $2 + $3; } INT { $$ = $4 + $5; }; 1129 1130 _ATEOF 1131 1132 1133 $at_traceoff 1134 echo "input.at:148: bison input.y" 1135 echo input.at:148 >$at_check_line_file 1136 ( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1 1137 at_status=$? 1138 grep '^ *+' $at_stder1 >&2 1139 grep -v '^ *+' $at_stder1 >$at_stderr 1140 at_failed=false 1141 echo >>$at_stderr; echo "input.y:11.10-32: warning: unset value: \$\$ 1142 input.y:11.10-32: warning: unused value: \$1 1143 input.y:11.10-32: warning: unused value: \$3 1144 input.y:11.10-32: warning: unused value: \$5 1145 input.y:12.9: warning: empty rule for typed nonterminal, and no action 1146 input.y:13.10-35: warning: unset value: \$\$ 1147 input.y:13.10-35: warning: unused value: \$3 1148 input.y:13.10-35: warning: unused value: \$5 1149 input.y:14.10-35: warning: unset value: \$\$ 1150 input.y:14.10-35: warning: unused value: \$3 1151 input.y:14.10-35: warning: unused value: \$5 1152 input.y:15.10-36: warning: unset value: \$\$ 1153 input.y:15.10-36: warning: unused value: \$3 1154 input.y:15.10-36: warning: unused value: \$5 1155 input.y:17.10-38: warning: unset value: \$\$ 1156 input.y:17.10-38: warning: unused value: \$1 1157 input.y:17.10-38: warning: unused value: \$2 1158 input.y:17.10-38: warning: unused value: \$3 1159 input.y:17.10-38: warning: unused value: \$4 1160 input.y:17.10-38: warning: unused value: \$5 1161 input.y:18.10-43: warning: unset value: \$\$ 1162 input.y:18.10-43: warning: unused value: \$1 1163 input.y:18.10-43: warning: unused value: \$3 1164 input.y:18.10-43: warning: unused value: \$4 1165 input.y:18.10-43: warning: unused value: \$5 1166 input.y:20.10-55: warning: unused value: \$3 1167 input.y:21.10-41: warning: unset value: \$\$ 1168 input.y:21.10-41: warning: unused value: \$1 1169 input.y:21.10-41: warning: unused value: \$2 1170 input.y:21.10-41: warning: unused value: \$4 1171 " | $at_diff - $at_stderr || at_failed=: 1172 $at_diff $at_devnull $at_stdout || at_failed=: 1173 case $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=:;; 1179 esac 1180 if $at_failed; then 1181 1182 echo 1 > $at_status_file 1183 exit 1 1184 fi 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 1205 cat >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 %% 1219 exp: foo; 1220 _ATEOF 1221 1222 1223 $at_traceoff 1224 echo "input.at:185: bison input.y" 1225 echo input.at:185 >$at_check_line_file 1226 ( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1 1227 at_status=$? 1228 grep '^ *+' $at_stder1 >&2 1229 grep -v '^ *+' $at_stder1 >$at_stderr 1230 at_failed=false 1231 echo >>$at_stderr; echo "input.y:8.7-11: %type redeclaration for foo 1232 input.y:3.7-11: first declaration 1233 input.y:10.13-17: %destructor redeclaration for foo 1234 input.y:5.13-17: first declaration 1235 input.y:9.10-14: %printer redeclaration for foo 1236 input.y:10.13-17: first declaration 1237 input.y:11.1-5: %left redeclaration for foo 1238 input.y:6.1-5: first declaration 1239 " | $at_diff - $at_stderr || at_failed=: 1240 $at_diff $at_devnull $at_stdout || at_failed=: 1241 case $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=:;; 1247 esac 1248 if $at_failed; then 1249 1250 echo 1 > $at_status_file 1251 exit 1 1252 fi 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 1274 cat >input.y <<'_ATEOF' 1275 _ATEOF 1276 1277 $at_traceoff 1278 echo "input.at:204: bison input.y" 1279 echo input.at:204 >$at_check_line_file 1280 ( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1 1281 at_status=$? 1282 grep '^ *+' $at_stder1 >&2 1283 grep -v '^ *+' $at_stder1 >$at_stderr 1284 at_failed=false 1285 echo >>$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=: 1288 case $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=:;; 1294 esac 1295 if $at_failed; then 1296 1297 echo 1 > $at_status_file 1298 exit 1 1299 fi 1300 1301 $at_traceon 1302 1303 1304 1305 cat >input.y <<'_ATEOF' 1306 {} 1307 _ATEOF 1308 1309 $at_traceoff 1310 echo "input.at:212: bison input.y" 1311 echo input.at:212 >$at_check_line_file 1312 ( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1 1313 at_status=$? 1314 grep '^ *+' $at_stder1 >&2 1315 grep -v '^ *+' $at_stder1 >$at_stderr 1316 at_failed=false 1317 echo >>$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=: 1320 case $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=:;; 1326 esac 1327 if $at_failed; then 1328 1329 echo 1 > $at_status_file 1330 exit 1 1331 fi 1332 1333 $at_traceon 1334 1335 1336 1337 cat >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. */ 1350 const 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 1373 char str[] = "\\ 1374 " A string with backslash-newlines in it %{ %} \\ 1375 \ 1376 ""; 1377 1378 char apostrophe = '\''; 1379 #endif 1380 1381 #include <stdio.h> 1382 %} 1383 /* %{ and %} can be here too. */ 1384 1385 %{ 1386 /* Exercise pre-prologue dependency to %union. */ 1387 typedef 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 %{ 1401 static YYSTYPE value_as_yystype (value val); 1402 1403 /* Exercise quotes in declarations. */ 1404 char quote[] = "]],"; 1405 %} 1406 1407 %{ 1408 static void yyerror (const char *s); 1409 static 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. */ 1419 exp: '[' '\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 1427 two: '\x000000000000000000000000000000000000000000000000000000000000000000002'; 1428 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_'; 1429 output.or.oline.opt: ;|oline;;|output;;; 1430 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' '; 1431 %% 1432 /* Exercise M4 quoting: ']]', [, 2. */ 1433 1434 static YYSTYPE 1435 value_as_yystype (value val) 1436 { 1437 YYSTYPE res; 1438 res.ival = val; 1439 return res; 1440 } 1441 1442 static int 1443 yylex (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 1452 static void 1453 yyerror (const char *msg) 1454 { 1455 fprintf (stderr, "%s\n", msg); 1456 } 1457 _ATEOF 1458 1459 1460 1461 # Pacify Emacs'font-lock-mode: " 1462 1463 cat >main.c <<'_ATEOF' 1464 typedef int value; 1465 #include "input.h" 1466 1467 int yyparse (void); 1468 1469 int 1470 main (void) 1471 { 1472 return yyparse (); 1473 } 1474 _ATEOF 1475 1476 1477 $at_traceoff 1478 echo "input.at:342: bison -d -v -o input.c input.y" 1479 echo input.at:342 >$at_check_line_file 1480 ( $at_traceon; bison -d -v -o input.c input.y ) >$at_stdout 2>$at_stder1 1481 at_status=$? 1482 grep '^ *+' $at_stder1 >&2 1483 grep -v '^ *+' $at_stder1 >$at_stderr 1484 at_failed=false 1485 $at_diff $at_devnull $at_stderr || at_failed=: 1486 $at_diff $at_devnull $at_stdout || at_failed=: 1487 case $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=:;; 1493 esac 1494 if $at_failed; then 1495 1496 echo 1 > $at_status_file 1497 exit 1 1498 fi 1499 1500 $at_traceon 1501 1502 $at_traceoff 1503 echo "input.at:343: \$CC \$CFLAGS \$CPPFLAGS -o input.o -c input.c" 1504 echo input.at:343 >$at_check_line_file 1505 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -o input.o -c input.c ) >$at_stdout 2>$at_stder1 1506 at_status=$? 1507 grep '^ *+' $at_stder1 >&2 1508 grep -v '^ *+' $at_stder1 >$at_stderr 1509 at_failed=false 1510 echo stderr:; cat $at_stderr 1511 echo stdout:; cat $at_stdout 1512 case $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=:;; 1518 esac 1519 if $at_failed; then 1520 1521 echo 1 > $at_status_file 1522 exit 1 1523 fi 1524 1525 $at_traceon 1526 1527 $at_traceoff 1528 echo "input.at:344: \$CC \$CFLAGS \$CPPFLAGS -o main.o -c main.c" 1529 echo input.at:344 >$at_check_line_file 1530 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -o main.o -c main.c ) >$at_stdout 2>$at_stder1 1531 at_status=$? 1532 grep '^ *+' $at_stder1 >&2 1533 grep -v '^ *+' $at_stder1 >$at_stderr 1534 at_failed=false 1535 echo stderr:; cat $at_stderr 1536 echo stdout:; cat $at_stdout 1537 case $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=:;; 1543 esac 1544 if $at_failed; then 1545 1546 echo 1 > $at_status_file 1547 exit 1 1548 fi 1549 1550 $at_traceon 1551 1552 $at_traceoff 1553 echo "input.at:345: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.o main.o \$LIBS" 1554 echo 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 1556 at_status=$? 1557 grep '^ *+' $at_stder1 >&2 1558 grep -v '^ *+' $at_stder1 >$at_stderr 1559 at_failed=false 1560 echo stderr:; cat $at_stderr 1561 echo stdout:; cat $at_stdout 1562 case $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=:;; 1568 esac 1569 if $at_failed; then 1570 1571 echo 1 > $at_status_file 1572 exit 1 1573 fi 1574 1575 $at_traceon 1576 1577 $at_traceoff 1578 echo "input.at:348: \$PREPARSER ./input" 1579 echo input.at:348 >$at_check_line_file 1580 ( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1 1581 at_status=$? 1582 grep '^ *+' $at_stder1 >&2 1583 grep -v '^ *+' $at_stder1 >$at_stderr 1584 at_failed=false 1585 $at_diff $at_devnull $at_stderr || at_failed=: 1586 echo >>$at_stdout; echo "[[], 1587 " | $at_diff - $at_stdout || at_failed=: 1588 case $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=:;; 1594 esac 1595 if $at_failed; then 1596 1597 echo 1 > $at_status_file 1598 exit 1 1599 fi 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 1622 cat >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 %% 1640 exp: "MY TOKEN"; 1641 %% 1642 _ATEOF 1643 1644 1645 1646 $at_traceoff 1647 echo "input.at:373: bison -o input.c input.y" 1648 echo input.at:373 >$at_check_line_file 1649 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 1650 at_status=$? 1651 grep '^ *+' $at_stder1 >&2 1652 grep -v '^ *+' $at_stder1 >$at_stderr 1653 at_failed=false 1654 $at_diff $at_devnull $at_stderr || at_failed=: 1655 $at_diff $at_devnull $at_stdout || at_failed=: 1656 case $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=:;; 1662 esac 1663 if $at_failed; then 1664 1665 echo 1 > $at_status_file 1666 exit 1 1667 fi 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 1687 cat >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 %% 1700 empty_file:; 1701 _ATEOF 1702 1703 1704 $at_traceoff 1705 echo "input.at:393: bison -o input.c input.y" 1706 echo input.at:393 >$at_check_line_file 1707 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 1708 at_status=$? 1709 grep '^ *+' $at_stder1 >&2 1710 grep -v '^ *+' $at_stder1 >$at_stderr 1711 at_failed=false 1712 echo stderr:; cat $at_stderr 1713 $at_diff $at_devnull $at_stdout || at_failed=: 1714 case $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=:;; 1720 esac 1721 if $at_failed; then 1722 1723 echo 1 > $at_status_file 1724 exit 1 1725 fi 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 1744 cat >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 %% 1757 empty_file:; 1758 _ATEOF 1759 1760 1761 $at_traceoff 1762 echo "input.at:394: bison -o input.c input.y" 1763 echo input.at:394 >$at_check_line_file 1764 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 1765 at_status=$? 1766 grep '^ *+' $at_stder1 >&2 1767 grep -v '^ *+' $at_stder1 >$at_stderr 1768 at_failed=false 1769 echo stderr:; cat $at_stderr 1770 $at_diff $at_devnull $at_stdout || at_failed=: 1771 case $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=:;; 1777 esac 1778 if $at_failed; then 1779 1780 echo 1 > $at_status_file 1781 exit 1 1782 fi 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 1801 cat >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 %% 1814 empty_file:; 1815 _ATEOF 1816 1817 1818 $at_traceoff 1819 echo "input.at:396: bison -o input.c input.y" 1820 echo input.at:396 >$at_check_line_file 1821 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 1822 at_status=$? 1823 grep '^ *+' $at_stder1 >&2 1824 grep -v '^ *+' $at_stder1 >$at_stderr 1825 at_failed=false 1826 echo stderr:; cat $at_stderr 1827 $at_diff $at_devnull $at_stdout || at_failed=: 1828 case $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=:;; 1834 esac 1835 if $at_failed; then 1836 1837 echo 1 > $at_status_file 1838 exit 1 1839 fi 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 1853 Output 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 1867 case "foo.y" in 1868 */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;; 1869 esac 1870 cat >foo.y <<'_ATEOF' 1871 1872 %% 1873 foo: {}; 1874 _ATEOF 1875 1876 1877 $at_traceoff 1878 echo "output.at:43: bison -dv foo.y " 1879 echo output.at:43 >$at_check_line_file 1880 ( $at_traceon; bison -dv foo.y ) >$at_stdout 2>$at_stder1 1881 at_status=$? 1882 grep '^ *+' $at_stder1 >&2 1883 grep -v '^ *+' $at_stder1 >$at_stderr 1884 at_failed=false 1885 $at_diff $at_devnull $at_stderr || at_failed=: 1886 $at_diff $at_devnull $at_stdout || at_failed=: 1887 case $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=:;; 1893 esac 1894 if $at_failed; then 1895 1896 echo 1 > $at_status_file 1897 exit 1 1898 fi 1899 1900 $at_traceon 1901 1902 $at_traceoff 1903 echo "output.at:43: ls foo.output foo.tab.c foo.tab.h" 1904 echo output.at:43 >$at_check_line_file 1905 ( $at_traceon; ls foo.output foo.tab.c foo.tab.h ) >$at_stdout 2>$at_stder1 1906 at_status=$? 1907 grep '^ *+' $at_stder1 >&2 1908 grep -v '^ *+' $at_stder1 >$at_stderr 1909 at_failed=false 1910 $at_diff $at_devnull $at_stderr || at_failed=: 1911 echo stdout:; cat $at_stdout 1912 case $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=:;; 1918 esac 1919 if $at_failed; then 1920 1921 echo 1 > $at_status_file 1922 exit 1 1923 fi 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 1943 case "foo.y" in 1944 */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;; 1945 esac 1946 cat >foo.y <<'_ATEOF' 1947 1948 %% 1949 foo: {}; 1950 _ATEOF 1951 1952 1953 $at_traceoff 1954 echo "output.at:46: bison -dv foo.y >&-" 1955 echo output.at:46 >$at_check_line_file 1956 ( $at_traceon; bison -dv foo.y >&- ) >$at_stdout 2>$at_stder1 1957 at_status=$? 1958 grep '^ *+' $at_stder1 >&2 1959 grep -v '^ *+' $at_stder1 >$at_stderr 1960 at_failed=false 1961 $at_diff $at_devnull $at_stderr || at_failed=: 1962 $at_diff $at_devnull $at_stdout || at_failed=: 1963 case $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=:;; 1969 esac 1970 if $at_failed; then 1971 1972 echo 1 > $at_status_file 1973 exit 1 1974 fi 1975 1976 $at_traceon 1977 1978 $at_traceoff 1979 echo "output.at:46: ls foo.output foo.tab.c foo.tab.h" 1980 echo output.at:46 >$at_check_line_file 1981 ( $at_traceon; ls foo.output foo.tab.c foo.tab.h ) >$at_stdout 2>$at_stder1 1982 at_status=$? 1983 grep '^ *+' $at_stder1 >&2 1984 grep -v '^ *+' $at_stder1 >$at_stderr 1985 at_failed=false 1986 $at_diff $at_devnull $at_stderr || at_failed=: 1987 echo stdout:; cat $at_stdout 1988 case $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=:;; 1994 esac 1995 if $at_failed; then 1996 1997 echo 1 > $at_status_file 1998 exit 1 1999 fi 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 2019 case "foo.y" in 2020 */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;; 2021 esac 2022 cat >foo.y <<'_ATEOF' 2023 2024 %% 2025 foo: {}; 2026 _ATEOF 2027 2028 2029 $at_traceoff 2030 echo "output.at:48: bison -dv -o foo.c foo.y " 2031 echo output.at:48 >$at_check_line_file 2032 ( $at_traceon; bison -dv -o foo.c foo.y ) >$at_stdout 2>$at_stder1 2033 at_status=$? 2034 grep '^ *+' $at_stder1 >&2 2035 grep -v '^ *+' $at_stder1 >$at_stderr 2036 at_failed=false 2037 $at_diff $at_devnull $at_stderr || at_failed=: 2038 $at_diff $at_devnull $at_stdout || at_failed=: 2039 case $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=:;; 2045 esac 2046 if $at_failed; then 2047 2048 echo 1 > $at_status_file 2049 exit 1 2050 fi 2051 2052 $at_traceon 2053 2054 $at_traceoff 2055 echo "output.at:48: ls foo.c foo.h foo.output" 2056 echo output.at:48 >$at_check_line_file 2057 ( $at_traceon; ls foo.c foo.h foo.output ) >$at_stdout 2>$at_stder1 2058 at_status=$? 2059 grep '^ *+' $at_stder1 >&2 2060 grep -v '^ *+' $at_stder1 >$at_stderr 2061 at_failed=false 2062 $at_diff $at_devnull $at_stderr || at_failed=: 2063 echo stdout:; cat $at_stdout 2064 case $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=:;; 2070 esac 2071 if $at_failed; then 2072 2073 echo 1 > $at_status_file 2074 exit 1 2075 fi 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 2095 case "foo.y" in 2096 */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;; 2097 esac 2098 cat >foo.y <<'_ATEOF' 2099 2100 %% 2101 foo: {}; 2102 _ATEOF 2103 2104 2105 $at_traceoff 2106 echo "output.at:50: bison -dv -o foo.tab.c foo.y " 2107 echo output.at:50 >$at_check_line_file 2108 ( $at_traceon; bison -dv -o foo.tab.c foo.y ) >$at_stdout 2>$at_stder1 2109 at_status=$? 2110 grep '^ *+' $at_stder1 >&2 2111 grep -v '^ *+' $at_stder1 >$at_stderr 2112 at_failed=false 2113 $at_diff $at_devnull $at_stderr || at_failed=: 2114 $at_diff $at_devnull $at_stdout || at_failed=: 2115 case $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=:;; 2121 esac 2122 if $at_failed; then 2123 2124 echo 1 > $at_status_file 2125 exit 1 2126 fi 2127 2128 $at_traceon 2129 2130 $at_traceoff 2131 echo "output.at:50: ls foo.output foo.tab.c foo.tab.h" 2132 echo output.at:50 >$at_check_line_file 2133 ( $at_traceon; ls foo.output foo.tab.c foo.tab.h ) >$at_stdout 2>$at_stder1 2134 at_status=$? 2135 grep '^ *+' $at_stder1 >&2 2136 grep -v '^ *+' $at_stder1 >$at_stderr 2137 at_failed=false 2138 $at_diff $at_devnull $at_stderr || at_failed=: 2139 echo stdout:; cat $at_stdout 2140 case $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=:;; 2146 esac 2147 if $at_failed; then 2148 2149 echo 1 > $at_status_file 2150 exit 1 2151 fi 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 2171 case "foo.y" in 2172 */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;; 2173 esac 2174 cat >foo.y <<'_ATEOF' 2175 2176 %% 2177 foo: {}; 2178 _ATEOF 2179 2180 2181 $at_traceoff 2182 echo "output.at:52: bison -dv -y foo.y " 2183 echo output.at:52 >$at_check_line_file 2184 ( $at_traceon; bison -dv -y foo.y ) >$at_stdout 2>$at_stder1 2185 at_status=$? 2186 grep '^ *+' $at_stder1 >&2 2187 grep -v '^ *+' $at_stder1 >$at_stderr 2188 at_failed=false 2189 $at_diff $at_devnull $at_stderr || at_failed=: 2190 $at_diff $at_devnull $at_stdout || at_failed=: 2191 case $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=:;; 2197 esac 2198 if $at_failed; then 2199 2200 echo 1 > $at_status_file 2201 exit 1 2202 fi 2203 2204 $at_traceon 2205 2206 $at_traceoff 2207 echo "output.at:52: ls y.output y.tab.c y.tab.h" 2208 echo output.at:52 >$at_check_line_file 2209 ( $at_traceon; ls y.output y.tab.c y.tab.h ) >$at_stdout 2>$at_stder1 2210 at_status=$? 2211 grep '^ *+' $at_stder1 >&2 2212 grep -v '^ *+' $at_stder1 >$at_stderr 2213 at_failed=false 2214 $at_diff $at_devnull $at_stderr || at_failed=: 2215 echo stdout:; cat $at_stdout 2216 case $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=:;; 2222 esac 2223 if $at_failed; then 2224 2225 echo 1 > $at_status_file 2226 exit 1 2227 fi 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 2247 case "foo.y" in 2248 */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;; 2249 esac 2250 cat >foo.y <<'_ATEOF' 2251 2252 %% 2253 foo: {}; 2254 _ATEOF 2255 2256 2257 $at_traceoff 2258 echo "output.at:54: bison -dv -b bar foo.y " 2259 echo output.at:54 >$at_check_line_file 2260 ( $at_traceon; bison -dv -b bar foo.y ) >$at_stdout 2>$at_stder1 2261 at_status=$? 2262 grep '^ *+' $at_stder1 >&2 2263 grep -v '^ *+' $at_stder1 >$at_stderr 2264 at_failed=false 2265 $at_diff $at_devnull $at_stderr || at_failed=: 2266 $at_diff $at_devnull $at_stdout || at_failed=: 2267 case $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=:;; 2273 esac 2274 if $at_failed; then 2275 2276 echo 1 > $at_status_file 2277 exit 1 2278 fi 2279 2280 $at_traceon 2281 2282 $at_traceoff 2283 echo "output.at:54: ls bar.output bar.tab.c bar.tab.h" 2284 echo output.at:54 >$at_check_line_file 2285 ( $at_traceon; ls bar.output bar.tab.c bar.tab.h ) >$at_stdout 2>$at_stder1 2286 at_status=$? 2287 grep '^ *+' $at_stder1 >&2 2288 grep -v '^ *+' $at_stder1 >$at_stderr 2289 at_failed=false 2290 $at_diff $at_devnull $at_stderr || at_failed=: 2291 echo stdout:; cat $at_stdout 2292 case $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=:;; 2298 esac 2299 if $at_failed; then 2300 2301 echo 1 > $at_status_file 2302 exit 1 2303 fi 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 2323 case "foo.y" in 2324 */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;; 2325 esac 2326 cat >foo.y <<'_ATEOF' 2327 2328 %% 2329 foo: {}; 2330 _ATEOF 2331 2332 2333 $at_traceoff 2334 echo "output.at:56: bison -dv -g -o foo.c foo.y " 2335 echo output.at:56 >$at_check_line_file 2336 ( $at_traceon; bison -dv -g -o foo.c foo.y ) >$at_stdout 2>$at_stder1 2337 at_status=$? 2338 grep '^ *+' $at_stder1 >&2 2339 grep -v '^ *+' $at_stder1 >$at_stderr 2340 at_failed=false 2341 $at_diff $at_devnull $at_stderr || at_failed=: 2342 $at_diff $at_devnull $at_stdout || at_failed=: 2343 case $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=:;; 2349 esac 2350 if $at_failed; then 2351 2352 echo 1 > $at_status_file 2353 exit 1 2354 fi 2355 2356 $at_traceon 2357 2358 $at_traceoff 2359 echo "output.at:56: ls foo.c foo.h foo.output foo.vcg" 2360 echo output.at:56 >$at_check_line_file 2361 ( $at_traceon; ls foo.c foo.h foo.output foo.vcg ) >$at_stdout 2>$at_stder1 2362 at_status=$? 2363 grep '^ *+' $at_stder1 >&2 2364 grep -v '^ *+' $at_stder1 >$at_stderr 2365 at_failed=false 2366 $at_diff $at_devnull $at_stderr || at_failed=: 2367 echo stdout:; cat $at_stdout 2368 case $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=:;; 2374 esac 2375 if $at_failed; then 2376 2377 echo 1 > $at_status_file 2378 exit 1 2379 fi 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 2399 case "foo.y" in 2400 */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;; 2401 esac 2402 cat >foo.y <<'_ATEOF' 2403 %defines %verbose 2404 %% 2405 foo: {}; 2406 _ATEOF 2407 2408 2409 $at_traceoff 2410 echo "output.at:60: bison foo.y " 2411 echo output.at:60 >$at_check_line_file 2412 ( $at_traceon; bison foo.y ) >$at_stdout 2>$at_stder1 2413 at_status=$? 2414 grep '^ *+' $at_stder1 >&2 2415 grep -v '^ *+' $at_stder1 >$at_stderr 2416 at_failed=false 2417 $at_diff $at_devnull $at_stderr || at_failed=: 2418 $at_diff $at_devnull $at_stdout || at_failed=: 2419 case $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=:;; 2425 esac 2426 if $at_failed; then 2427 2428 echo 1 > $at_status_file 2429 exit 1 2430 fi 2431 2432 $at_traceon 2433 2434 $at_traceoff 2435 echo "output.at:60: ls foo.output foo.tab.c foo.tab.h" 2436 echo output.at:60 >$at_check_line_file 2437 ( $at_traceon; ls foo.output foo.tab.c foo.tab.h ) >$at_stdout 2>$at_stder1 2438 at_status=$? 2439 grep '^ *+' $at_stder1 >&2 2440 grep -v '^ *+' $at_stder1 >$at_stderr 2441 at_failed=false 2442 $at_diff $at_devnull $at_stderr || at_failed=: 2443 echo stdout:; cat $at_stdout 2444 case $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=:;; 2450 esac 2451 if $at_failed; then 2452 2453 echo 1 > $at_status_file 2454 exit 1 2455 fi 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 2475 case "foo.y" in 2476 */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;; 2477 esac 2478 cat >foo.y <<'_ATEOF' 2479 %defines %verbose %yacc 2480 %% 2481 foo: {}; 2482 _ATEOF 2483 2484 2485 $at_traceoff 2486 echo "output.at:62: bison foo.y " 2487 echo output.at:62 >$at_check_line_file 2488 ( $at_traceon; bison foo.y ) >$at_stdout 2>$at_stder1 2489 at_status=$? 2490 grep '^ *+' $at_stder1 >&2 2491 grep -v '^ *+' $at_stder1 >$at_stderr 2492 at_failed=false 2493 $at_diff $at_devnull $at_stderr || at_failed=: 2494 $at_diff $at_devnull $at_stdout || at_failed=: 2495 case $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=:;; 2501 esac 2502 if $at_failed; then 2503 2504 echo 1 > $at_status_file 2505 exit 1 2506 fi 2507 2508 $at_traceon 2509 2510 $at_traceoff 2511 echo "output.at:62: ls y.output y.tab.c y.tab.h" 2512 echo output.at:62 >$at_check_line_file 2513 ( $at_traceon; ls y.output y.tab.c y.tab.h ) >$at_stdout 2>$at_stder1 2514 at_status=$? 2515 grep '^ *+' $at_stder1 >&2 2516 grep -v '^ *+' $at_stder1 >$at_stderr 2517 at_failed=false 2518 $at_diff $at_devnull $at_stderr || at_failed=: 2519 echo stdout:; cat $at_stdout 2520 case $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=:;; 2526 esac 2527 if $at_failed; then 2528 2529 echo 1 > $at_status_file 2530 exit 1 2531 fi 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 2551 case "foo.yy" in 2552 */*) mkdir `echo "foo.yy" | sed 's,/.*,,'`;; 2553 esac 2554 cat >foo.yy <<'_ATEOF' 2555 %defines %verbose %yacc 2556 %% 2557 foo: {}; 2558 _ATEOF 2559 2560 2561 $at_traceoff 2562 echo "output.at:65: bison foo.yy " 2563 echo output.at:65 >$at_check_line_file 2564 ( $at_traceon; bison foo.yy ) >$at_stdout 2>$at_stder1 2565 at_status=$? 2566 grep '^ *+' $at_stder1 >&2 2567 grep -v '^ *+' $at_stder1 >$at_stderr 2568 at_failed=false 2569 $at_diff $at_devnull $at_stderr || at_failed=: 2570 $at_diff $at_devnull $at_stdout || at_failed=: 2571 case $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=:;; 2577 esac 2578 if $at_failed; then 2579 2580 echo 1 > $at_status_file 2581 exit 1 2582 fi 2583 2584 $at_traceon 2585 2586 $at_traceoff 2587 echo "output.at:65: ls y.output y.tab.c y.tab.h" 2588 echo output.at:65 >$at_check_line_file 2589 ( $at_traceon; ls y.output y.tab.c y.tab.h ) >$at_stdout 2>$at_stder1 2590 at_status=$? 2591 grep '^ *+' $at_stder1 >&2 2592 grep -v '^ *+' $at_stder1 >$at_stderr 2593 at_failed=false 2594 $at_diff $at_devnull $at_stderr || at_failed=: 2595 echo stdout:; cat $at_stdout 2596 case $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=:;; 2602 esac 2603 if $at_failed; then 2604 2605 echo 1 > $at_status_file 2606 exit 1 2607 fi 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 2627 case "foo.y" in 2628 */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;; 2629 esac 2630 cat >foo.y <<'_ATEOF' 2631 %file-prefix="bar" %defines %verbose 2632 %% 2633 foo: {}; 2634 _ATEOF 2635 2636 2637 $at_traceoff 2638 echo "output.at:69: bison foo.y " 2639 echo output.at:69 >$at_check_line_file 2640 ( $at_traceon; bison foo.y ) >$at_stdout 2>$at_stder1 2641 at_status=$? 2642 grep '^ *+' $at_stder1 >&2 2643 grep -v '^ *+' $at_stder1 >$at_stderr 2644 at_failed=false 2645 $at_diff $at_devnull $at_stderr || at_failed=: 2646 $at_diff $at_devnull $at_stdout || at_failed=: 2647 case $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=:;; 2653 esac 2654 if $at_failed; then 2655 2656 echo 1 > $at_status_file 2657 exit 1 2658 fi 2659 2660 $at_traceon 2661 2662 $at_traceoff 2663 echo "output.at:69: ls bar.output bar.tab.c bar.tab.h" 2664 echo output.at:69 >$at_check_line_file 2665 ( $at_traceon; ls bar.output bar.tab.c bar.tab.h ) >$at_stdout 2>$at_stder1 2666 at_status=$? 2667 grep '^ *+' $at_stder1 >&2 2668 grep -v '^ *+' $at_stder1 >$at_stderr 2669 at_failed=false 2670 $at_diff $at_devnull $at_stderr || at_failed=: 2671 echo stdout:; cat $at_stdout 2672 case $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=:;; 2678 esac 2679 if $at_failed; then 2680 2681 echo 1 > $at_status_file 2682 exit 1 2683 fi 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 2703 case "foo.y" in 2704 */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;; 2705 esac 2706 cat >foo.y <<'_ATEOF' 2707 %output="bar.c" %defines %verbose %yacc 2708 %% 2709 foo: {}; 2710 _ATEOF 2711 2712 2713 $at_traceoff 2714 echo "output.at:71: bison foo.y " 2715 echo output.at:71 >$at_check_line_file 2716 ( $at_traceon; bison foo.y ) >$at_stdout 2>$at_stder1 2717 at_status=$? 2718 grep '^ *+' $at_stder1 >&2 2719 grep -v '^ *+' $at_stder1 >$at_stderr 2720 at_failed=false 2721 $at_diff $at_devnull $at_stderr || at_failed=: 2722 $at_diff $at_devnull $at_stdout || at_failed=: 2723 case $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=:;; 2729 esac 2730 if $at_failed; then 2731 2732 echo 1 > $at_status_file 2733 exit 1 2734 fi 2735 2736 $at_traceon 2737 2738 $at_traceoff 2739 echo "output.at:71: ls bar.output bar.c bar.h" 2740 echo output.at:71 >$at_check_line_file 2741 ( $at_traceon; ls bar.output bar.c bar.h ) >$at_stdout 2>$at_stder1 2742 at_status=$? 2743 grep '^ *+' $at_stder1 >&2 2744 grep -v '^ *+' $at_stder1 >$at_stderr 2745 at_failed=false 2746 $at_diff $at_devnull $at_stderr || at_failed=: 2747 echo stdout:; cat $at_stdout 2748 case $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=:;; 2754 esac 2755 if $at_failed; then 2756 2757 echo 1 > $at_status_file 2758 exit 1 2759 fi 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 2779 case "foo.y" in 2780 */*) mkdir `echo "foo.y" | sed 's,/.*,,'`;; 2781 esac 2782 cat >foo.y <<'_ATEOF' 2783 %file-prefix="baz" %output="bar.c" %defines %verbose %yacc 2784 %% 2785 foo: {}; 2786 _ATEOF 2787 2788 2789 $at_traceoff 2790 echo "output.at:75: bison foo.y " 2791 echo output.at:75 >$at_check_line_file 2792 ( $at_traceon; bison foo.y ) >$at_stdout 2>$at_stder1 2793 at_status=$? 2794 grep '^ *+' $at_stder1 >&2 2795 grep -v '^ *+' $at_stder1 >$at_stderr 2796 at_failed=false 2797 $at_diff $at_devnull $at_stderr || at_failed=: 2798 $at_diff $at_devnull $at_stdout || at_failed=: 2799 case $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=:;; 2805 esac 2806 if $at_failed; then 2807 2808 echo 1 > $at_status_file 2809 exit 1 2810 fi 2811 2812 $at_traceon 2813 2814 $at_traceoff 2815 echo "output.at:75: ls bar.output bar.c bar.h" 2816 echo output.at:75 >$at_check_line_file 2817 ( $at_traceon; ls bar.output bar.c bar.h ) >$at_stdout 2>$at_stder1 2818 at_status=$? 2819 grep '^ *+' $at_stder1 >&2 2820 grep -v '^ *+' $at_stder1 >$at_stderr 2821 at_failed=false 2822 $at_diff $at_devnull $at_stderr || at_failed=: 2823 echo stdout:; cat $at_stdout 2824 case $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=:;; 2830 esac 2831 if $at_failed; then 2832 2833 echo 1 > $at_status_file 2834 exit 1 2835 fi 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 2855 case "foo.yy" in 2856 */*) mkdir `echo "foo.yy" | sed 's,/.*,,'`;; 2857 esac 2858 cat >foo.yy <<'_ATEOF' 2859 %defines %verbose 2860 %% 2861 foo: {}; 2862 _ATEOF 2863 2864 2865 $at_traceoff 2866 echo "output.at:80: bison foo.yy " 2867 echo output.at:80 >$at_check_line_file 2868 ( $at_traceon; bison foo.yy ) >$at_stdout 2>$at_stder1 2869 at_status=$? 2870 grep '^ *+' $at_stder1 >&2 2871 grep -v '^ *+' $at_stder1 >$at_stderr 2872 at_failed=false 2873 $at_diff $at_devnull $at_stderr || at_failed=: 2874 $at_diff $at_devnull $at_stdout || at_failed=: 2875 case $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=:;; 2881 esac 2882 if $at_failed; then 2883 2884 echo 1 > $at_status_file 2885 exit 1 2886 fi 2887 2888 $at_traceon 2889 2890 $at_traceoff 2891 echo "output.at:80: ls foo.output foo.tab.cc foo.tab.hh" 2892 echo output.at:80 >$at_check_line_file 2893 ( $at_traceon; ls foo.output foo.tab.cc foo.tab.hh ) >$at_stdout 2>$at_stder1 2894 at_status=$? 2895 grep '^ *+' $at_stder1 >&2 2896 grep -v '^ *+' $at_stder1 >$at_stderr 2897 at_failed=false 2898 $at_diff $at_devnull $at_stderr || at_failed=: 2899 echo stdout:; cat $at_stdout 2900 case $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=:;; 2906 esac 2907 if $at_failed; then 2908 2909 echo 1 > $at_status_file 2910 exit 1 2911 fi 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 2931 case "foo.yy" in 2932 */*) mkdir `echo "foo.yy" | sed 's,/.*,,'`;; 2933 esac 2934 cat >foo.yy <<'_ATEOF' 2935 %defines %verbose 2936 %% 2937 foo: {}; 2938 _ATEOF 2939 2940 2941 $at_traceoff 2942 echo "output.at:83: bison -o foo.c foo.yy " 2943 echo output.at:83 >$at_check_line_file 2944 ( $at_traceon; bison -o foo.c foo.yy ) >$at_stdout 2>$at_stder1 2945 at_status=$? 2946 grep '^ *+' $at_stder1 >&2 2947 grep -v '^ *+' $at_stder1 >$at_stderr 2948 at_failed=false 2949 $at_diff $at_devnull $at_stderr || at_failed=: 2950 $at_diff $at_devnull $at_stdout || at_failed=: 2951 case $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=:;; 2957 esac 2958 if $at_failed; then 2959 2960 echo 1 > $at_status_file 2961 exit 1 2962 fi 2963 2964 $at_traceon 2965 2966 $at_traceoff 2967 echo "output.at:83: ls foo.c foo.h foo.output" 2968 echo output.at:83 >$at_check_line_file 2969 ( $at_traceon; ls foo.c foo.h foo.output ) >$at_stdout 2>$at_stder1 2970 at_status=$? 2971 grep '^ *+' $at_stder1 >&2 2972 grep -v '^ *+' $at_stder1 >$at_stderr 2973 at_failed=false 2974 $at_diff $at_devnull $at_stderr || at_failed=: 2975 echo stdout:; cat $at_stdout 2976 case $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=:;; 2982 esac 2983 if $at_failed; then 2984 2985 echo 1 > $at_status_file 2986 exit 1 2987 fi 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 3007 case "foo.yy" in 3008 */*) mkdir `echo "foo.yy" | sed 's,/.*,,'`;; 3009 esac 3010 cat >foo.yy <<'_ATEOF' 3011 3012 %% 3013 foo: {}; 3014 _ATEOF 3015 3016 3017 $at_traceoff 3018 echo "output.at:87: bison --defines=foo.hpp -o foo.c++ foo.yy " 3019 echo output.at:87 >$at_check_line_file 3020 ( $at_traceon; bison --defines=foo.hpp -o foo.c++ foo.yy ) >$at_stdout 2>$at_stder1 3021 at_status=$? 3022 grep '^ *+' $at_stder1 >&2 3023 grep -v '^ *+' $at_stder1 >$at_stderr 3024 at_failed=false 3025 $at_diff $at_devnull $at_stderr || at_failed=: 3026 $at_diff $at_devnull $at_stdout || at_failed=: 3027 case $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=:;; 3033 esac 3034 if $at_failed; then 3035 3036 echo 1 > $at_status_file 3037 exit 1 3038 fi 3039 3040 $at_traceon 3041 3042 $at_traceoff 3043 echo "output.at:87: ls foo.c++ foo.hpp" 3044 echo output.at:87 >$at_check_line_file 3045 ( $at_traceon; ls foo.c++ foo.hpp ) >$at_stdout 2>$at_stder1 3046 at_status=$? 3047 grep '^ *+' $at_stder1 >&2 3048 grep -v '^ *+' $at_stder1 >$at_stderr 3049 at_failed=false 3050 $at_diff $at_devnull $at_stderr || at_failed=: 3051 echo stdout:; cat $at_stdout 3052 case $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=:;; 3058 esac 3059 if $at_failed; then 3060 3061 echo 1 > $at_status_file 3062 exit 1 3063 fi 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 3083 case "foo.yy" in 3084 */*) mkdir `echo "foo.yy" | sed 's,/.*,,'`;; 3085 esac 3086 cat >foo.yy <<'_ATEOF' 3087 3088 %% 3089 foo: {}; 3090 _ATEOF 3091 3092 3093 $at_traceoff 3094 echo "output.at:91: bison -o foo.c++ --graph=foo.gph foo.yy " 3095 echo output.at:91 >$at_check_line_file 3096 ( $at_traceon; bison -o foo.c++ --graph=foo.gph foo.yy ) >$at_stdout 2>$at_stder1 3097 at_status=$? 3098 grep '^ *+' $at_stder1 >&2 3099 grep -v '^ *+' $at_stder1 >$at_stderr 3100 at_failed=false 3101 $at_diff $at_devnull $at_stderr || at_failed=: 3102 $at_diff $at_devnull $at_stdout || at_failed=: 3103 case $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=:;; 3109 esac 3110 if $at_failed; then 3111 3112 echo 1 > $at_status_file 3113 exit 1 3114 fi 3115 3116 $at_traceon 3117 3118 $at_traceoff 3119 echo "output.at:91: ls foo.c++ foo.gph" 3120 echo output.at:91 >$at_check_line_file 3121 ( $at_traceon; ls foo.c++ foo.gph ) >$at_stdout 2>$at_stder1 3122 at_status=$? 3123 grep '^ *+' $at_stder1 >&2 3124 grep -v '^ *+' $at_stder1 >$at_stderr 3125 at_failed=false 3126 $at_diff $at_devnull $at_stderr || at_failed=: 3127 echo stdout:; cat $at_stdout 3128 case $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=:;; 3134 esac 3135 if $at_failed; then 3136 3137 echo 1 > $at_status_file 3138 exit 1 3139 fi 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 3159 case "foo.yy" in 3160 */*) mkdir `echo "foo.yy" | sed 's,/.*,,'`;; 3161 esac 3162 cat >foo.yy <<'_ATEOF' 3163 %skeleton "lalr1.cc" %defines %verbose 3164 %% 3165 foo: {}; 3166 _ATEOF 3167 3168 3169 $at_traceoff 3170 echo "output.at:105: bison foo.yy " 3171 echo output.at:105 >$at_check_line_file 3172 ( $at_traceon; bison foo.yy ) >$at_stdout 2>$at_stder1 3173 at_status=$? 3174 grep '^ *+' $at_stder1 >&2 3175 grep -v '^ *+' $at_stder1 >$at_stderr 3176 at_failed=false 3177 $at_diff $at_devnull $at_stderr || at_failed=: 3178 $at_diff $at_devnull $at_stdout || at_failed=: 3179 case $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=:;; 3185 esac 3186 if $at_failed; then 3187 3188 echo 1 > $at_status_file 3189 exit 1 3190 fi 3191 3192 $at_traceon 3193 3194 $at_traceoff 3195 echo "output.at:105: ls foo.tab.cc foo.tab.hh foo.output location.hh stack.hh position.hh" 3196 echo 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 3198 at_status=$? 3199 grep '^ *+' $at_stder1 >&2 3200 grep -v '^ *+' $at_stder1 >$at_stderr 3201 at_failed=false 3202 $at_diff $at_devnull $at_stderr || at_failed=: 3203 echo stdout:; cat $at_stdout 3204 case $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=:;; 3210 esac 3211 if $at_failed; then 3212 3213 echo 1 > $at_status_file 3214 exit 1 3215 fi 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 3235 case "subdir/foo.yy" in 3236 */*) mkdir `echo "subdir/foo.yy" | sed 's,/.*,,'`;; 3237 esac 3238 cat >subdir/foo.yy <<'_ATEOF' 3239 %skeleton "lalr1.cc" %defines %verbose 3240 %% 3241 foo: {}; 3242 _ATEOF 3243 3244 3245 $at_traceoff 3246 echo "output.at:109: bison subdir/foo.yy " 3247 echo output.at:109 >$at_check_line_file 3248 ( $at_traceon; bison subdir/foo.yy ) >$at_stdout 2>$at_stder1 3249 at_status=$? 3250 grep '^ *+' $at_stder1 >&2 3251 grep -v '^ *+' $at_stder1 >$at_stderr 3252 at_failed=false 3253 $at_diff $at_devnull $at_stderr || at_failed=: 3254 $at_diff $at_devnull $at_stdout || at_failed=: 3255 case $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=:;; 3261 esac 3262 if $at_failed; then 3263 3264 echo 1 > $at_status_file 3265 exit 1 3266 fi 3267 3268 $at_traceon 3269 3270 $at_traceoff 3271 echo "output.at:109: ls foo.tab.cc foo.tab.hh foo.output location.hh stack.hh position.hh" 3272 echo 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 3274 at_status=$? 3275 grep '^ *+' $at_stder1 >&2 3276 grep -v '^ *+' $at_stder1 >$at_stderr 3277 at_failed=false 3278 $at_diff $at_devnull $at_stderr || at_failed=: 3279 echo stdout:; cat $at_stdout 3280 case $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=:;; 3286 esac 3287 if $at_failed; then 3288 3289 echo 1 > $at_status_file 3290 exit 1 3291 fi 3292 3293 $at_traceon 3294 3295 # Also make sure that the includes do not refer to the subdirectory. 3296 $at_traceoff 3297 echo "output.at:109: grep 'include .subdir/' foo.tab.cc" 3298 echo output.at:109 >$at_check_line_file 3299 ( $at_traceon; grep 'include .subdir/' foo.tab.cc ) >$at_stdout 2>$at_stder1 3300 at_status=$? 3301 grep '^ *+' $at_stder1 >&2 3302 grep -v '^ *+' $at_stder1 >$at_stderr 3303 at_failed=false 3304 $at_diff $at_devnull $at_stderr || at_failed=: 3305 $at_diff $at_devnull $at_stdout || at_failed=: 3306 case $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=:;; 3312 esac 3313 if $at_failed; then 3314 3315 echo 1 > $at_status_file 3316 exit 1 3317 fi 3318 3319 $at_traceon 3320 3321 $at_traceoff 3322 echo "output.at:109: grep 'include .subdir/' foo.tab.hh" 3323 echo output.at:109 >$at_check_line_file 3324 ( $at_traceon; grep 'include .subdir/' foo.tab.hh ) >$at_stdout 2>$at_stder1 3325 at_status=$? 3326 grep '^ *+' $at_stder1 >&2 3327 grep -v '^ *+' $at_stder1 >$at_stderr 3328 at_failed=false 3329 $at_diff $at_devnull $at_stderr || at_failed=: 3330 $at_diff $at_devnull $at_stdout || at_failed=: 3331 case $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=:;; 3337 esac 3338 if $at_failed; then 3339 3340 echo 1 > $at_status_file 3341 exit 1 3342 fi 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 3362 case "subdir/foo.yy" in 3363 */*) mkdir `echo "subdir/foo.yy" | sed 's,/.*,,'`;; 3364 esac 3365 cat >subdir/foo.yy <<'_ATEOF' 3366 %skeleton "lalr1.cc" %defines %verbose 3367 %% 3368 foo: {}; 3369 _ATEOF 3370 3371 3372 $at_traceoff 3373 echo "output.at:114: bison -o subdir/foo.cc subdir/foo.yy " 3374 echo output.at:114 >$at_check_line_file 3375 ( $at_traceon; bison -o subdir/foo.cc subdir/foo.yy ) >$at_stdout 2>$at_stder1 3376 at_status=$? 3377 grep '^ *+' $at_stder1 >&2 3378 grep -v '^ *+' $at_stder1 >$at_stderr 3379 at_failed=false 3380 $at_diff $at_devnull $at_stderr || at_failed=: 3381 $at_diff $at_devnull $at_stdout || at_failed=: 3382 case $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=:;; 3388 esac 3389 if $at_failed; then 3390 3391 echo 1 > $at_status_file 3392 exit 1 3393 fi 3394 3395 $at_traceon 3396 3397 $at_traceoff 3398 echo "output.at:114: ls subdir/foo.cc subdir/foo.hh subdir/foo.output subdir/location.hh subdir/stack.hh subdir/position.hh" 3399 echo 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 3401 at_status=$? 3402 grep '^ *+' $at_stder1 >&2 3403 grep -v '^ *+' $at_stder1 >$at_stderr 3404 at_failed=false 3405 $at_diff $at_devnull $at_stderr || at_failed=: 3406 echo stdout:; cat $at_stdout 3407 case $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=:;; 3413 esac 3414 if $at_failed; then 3415 3416 echo 1 > $at_status_file 3417 exit 1 3418 fi 3419 3420 $at_traceon 3421 3422 # Also make sure that the includes do not refer to the subdirectory. 3423 $at_traceoff 3424 echo "output.at:114: grep 'include .subdir/' subdir/foo.cc" 3425 echo output.at:114 >$at_check_line_file 3426 ( $at_traceon; grep 'include .subdir/' subdir/foo.cc ) >$at_stdout 2>$at_stder1 3427 at_status=$? 3428 grep '^ *+' $at_stder1 >&2 3429 grep -v '^ *+' $at_stder1 >$at_stderr 3430 at_failed=false 3431 $at_diff $at_devnull $at_stderr || at_failed=: 3432 $at_diff $at_devnull $at_stdout || at_failed=: 3433 case $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=:;; 3439 esac 3440 if $at_failed; then 3441 3442 echo 1 > $at_status_file 3443 exit 1 3444 fi 3445 3446 $at_traceon 3447 3448 $at_traceoff 3449 echo "output.at:114: grep 'include .subdir/' subdir/foo.hh" 3450 echo output.at:114 >$at_check_line_file 3451 ( $at_traceon; grep 'include .subdir/' subdir/foo.hh ) >$at_stdout 2>$at_stder1 3452 at_status=$? 3453 grep '^ *+' $at_stder1 >&2 3454 grep -v '^ *+' $at_stder1 >$at_stderr 3455 at_failed=false 3456 $at_diff $at_devnull $at_stderr || at_failed=: 3457 $at_diff $at_devnull $at_stdout || at_failed=: 3458 case $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=:;; 3464 esac 3465 if $at_failed; then 3466 3467 echo 1 > $at_status_file 3468 exit 1 3469 fi 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 3484 Grammar 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 3507 cat >input.y <<'_ATEOF' 3508 %% 3509 e: 'e' | /* Nothing */; 3510 _ATEOF 3511 3512 3513 $at_traceoff 3514 echo "sets.at:81: bison --trace=sets input.y" 3515 echo sets.at:81 >$at_check_line_file 3516 ( $at_traceon; bison --trace=sets input.y ) >$at_stdout 2>$at_stder1 3517 at_status=$? 3518 grep '^ *+' $at_stder1 >&2 3519 grep -v '^ *+' $at_stder1 >$at_stderr 3520 at_failed=false 3521 echo stderr:; tee stderr <$at_stderr 3522 $at_diff $at_devnull $at_stdout || at_failed=: 3523 case $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=:;; 3529 esac 3530 if $at_failed; then 3531 3532 echo 1 > $at_status_file 3533 exit 1 3534 fi 3535 3536 $at_traceon 3537 3538 cat >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 3567 echo "sets.at:82: sed -f extract.sed stderr" 3568 echo sets.at:82 >$at_check_line_file 3569 ( $at_traceon; sed -f extract.sed stderr ) >$at_stdout 2>$at_stder1 3570 at_status=$? 3571 grep '^ *+' $at_stder1 >&2 3572 grep -v '^ *+' $at_stder1 >$at_stderr 3573 at_failed=false 3574 $at_diff $at_devnull $at_stderr || at_failed=: 3575 echo stdout:; tee stdout <$at_stdout 3576 case $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=:;; 3582 esac 3583 if $at_failed; then 3584 3585 echo 1 > $at_status_file 3586 exit 1 3587 fi 3588 3589 $at_traceon 3590 3591 $at_traceoff 3592 echo "sets.at:82: mv stdout sets" 3593 echo sets.at:82 >$at_check_line_file 3594 ( $at_traceon; mv stdout sets ) >$at_stdout 2>$at_stder1 3595 at_status=$? 3596 grep '^ *+' $at_stder1 >&2 3597 grep -v '^ *+' $at_stder1 >$at_stderr 3598 at_failed=false 3599 $at_diff $at_devnull $at_stderr || at_failed=: 3600 $at_diff $at_devnull $at_stdout || at_failed=: 3601 case $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=:;; 3607 esac 3608 if $at_failed; then 3609 3610 echo 1 > $at_status_file 3611 exit 1 3612 fi 3613 3614 $at_traceon 3615 3616 3617 $at_traceoff 3618 echo "sets.at:107: cat sets" 3619 echo sets.at:107 >$at_check_line_file 3620 ( $at_traceon; cat sets ) >$at_stdout 2>$at_stder1 3621 at_status=$? 3622 grep '^ *+' $at_stder1 >&2 3623 grep -v '^ *+' $at_stder1 >$at_stderr 3624 at_failed=false 3625 $at_diff $at_devnull $at_stderr || at_failed=: 3626 echo >>$at_stdout; echo "DERIVES 3627 \$accept derives 3628 0 e \$end 3629 e derives 3630 1 'e' 3631 2 /* empty */ 3632 NULLABLE 3633 \$accept: no 3634 e: yes 3635 FIRSTS 3636 \$accept firsts 3637 \$accept 3638 e 3639 e firsts 3640 e 3641 FDERIVES 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=: 3650 case $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=:;; 3656 esac 3657 if $at_failed; then 3658 3659 echo 1 > $at_status_file 3660 exit 1 3661 fi 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 3682 cat >input.y <<'_ATEOF' 3683 %% 3684 a: b; 3685 b: c; 3686 c: d; 3687 d: e; 3688 e: f; 3689 f: g; 3690 g: h; 3691 h: 'h'; 3692 _ATEOF 3693 3694 3695 $at_traceoff 3696 echo "sets.at:165: bison --trace=sets input.y" 3697 echo sets.at:165 >$at_check_line_file 3698 ( $at_traceon; bison --trace=sets input.y ) >$at_stdout 2>$at_stder1 3699 at_status=$? 3700 grep '^ *+' $at_stder1 >&2 3701 grep -v '^ *+' $at_stder1 >$at_stderr 3702 at_failed=false 3703 echo stderr:; tee stderr <$at_stderr 3704 $at_diff $at_devnull $at_stdout || at_failed=: 3705 case $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=:;; 3711 esac 3712 if $at_failed; then 3713 3714 echo 1 > $at_status_file 3715 exit 1 3716 fi 3717 3718 $at_traceon 3719 3720 3721 $at_traceoff 3722 echo "sets.at:183: sed -n 's/[ ]*\$//;/^RTC: Firsts Output BEGIN/,/^RTC: Firsts Output END/p' stderr" 3723 echo 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 3725 at_status=$? 3726 grep '^ *+' $at_stder1 >&2 3727 grep -v '^ *+' $at_stder1 >$at_stderr 3728 at_failed=false 3729 $at_diff $at_devnull $at_stderr || at_failed=: 3730 echo >>$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 \`---------' 3744 RTC: Firsts Output END 3745 " | $at_diff - $at_stdout || at_failed=: 3746 case $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=:;; 3752 esac 3753 if $at_failed; then 3754 3755 echo 1 > $at_status_file 3756 exit 1 3757 fi 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 3778 cat >input.y <<'_ATEOF' 3779 %nonassoc '<' '>' 3780 %left '+' '-' 3781 %right '^' '=' 3782 %% 3783 exp: 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 3796 echo "sets.at:211: bison --trace=sets input.y" 3797 echo sets.at:211 >$at_check_line_file 3798 ( $at_traceon; bison --trace=sets input.y ) >$at_stdout 2>$at_stder1 3799 at_status=$? 3800 grep '^ *+' $at_stder1 >&2 3801 grep -v '^ *+' $at_stder1 >$at_stderr 3802 at_failed=false 3803 echo stderr:; tee stderr <$at_stderr 3804 $at_diff $at_devnull $at_stdout || at_failed=: 3805 case $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=:;; 3811 esac 3812 if $at_failed; then 3813 3814 echo 1 > $at_status_file 3815 exit 1 3816 fi 3817 3818 $at_traceon 3819 3820 cat >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 3849 echo "sets.at:212: sed -f extract.sed stderr" 3850 echo sets.at:212 >$at_check_line_file 3851 ( $at_traceon; sed -f extract.sed stderr ) >$at_stdout 2>$at_stder1 3852 at_status=$? 3853 grep '^ *+' $at_stder1 >&2 3854 grep -v '^ *+' $at_stder1 >$at_stderr 3855 at_failed=false 3856 $at_diff $at_devnull $at_stderr || at_failed=: 3857 echo stdout:; tee stdout <$at_stdout 3858 case $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=:;; 3864 esac 3865 if $at_failed; then 3866 3867 echo 1 > $at_status_file 3868 exit 1 3869 fi 3870 3871 $at_traceon 3872 3873 $at_traceoff 3874 echo "sets.at:212: mv stdout sets" 3875 echo sets.at:212 >$at_check_line_file 3876 ( $at_traceon; mv stdout sets ) >$at_stdout 2>$at_stder1 3877 at_status=$? 3878 grep '^ *+' $at_stder1 >&2 3879 grep -v '^ *+' $at_stder1 >$at_stderr 3880 at_failed=false 3881 $at_diff $at_devnull $at_stderr || at_failed=: 3882 $at_diff $at_devnull $at_stdout || at_failed=: 3883 case $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=:;; 3889 esac 3890 if $at_failed; then 3891 3892 echo 1 > $at_status_file 3893 exit 1 3894 fi 3895 3896 $at_traceon 3897 3898 3899 $at_traceoff 3900 echo "sets.at:252: cat sets" 3901 echo sets.at:252 >$at_check_line_file 3902 ( $at_traceon; cat sets ) >$at_stdout 2>$at_stder1 3903 at_status=$? 3904 grep '^ *+' $at_stder1 >&2 3905 grep -v '^ *+' $at_stder1 >$at_stderr 3906 at_failed=false 3907 $at_diff $at_devnull $at_stderr || at_failed=: 3908 echo >>$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\" 3919 NULLABLE 3920 \$accept: no 3921 exp: no 3922 FIRSTS 3923 \$accept firsts 3924 \$accept 3925 exp 3926 exp firsts 3927 exp 3928 FDERIVES 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=: 3947 case $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=:;; 3953 esac 3954 if $at_failed; then 3955 3956 echo 1 > $at_status_file 3957 exit 1 3958 fi 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 3979 cat >input.y <<'_ATEOF' 3980 %token END 0 3981 %% 3982 input: 3983 'a' 3984 | '(' input ')' 3985 | '(' error END 3986 ; 3987 _ATEOF 3988 3989 3990 $at_traceoff 3991 echo "sets.at:281: bison -v -o input.c input.y" 3992 echo sets.at:281 >$at_check_line_file 3993 ( $at_traceon; bison -v -o input.c input.y ) >$at_stdout 2>$at_stder1 3994 at_status=$? 3995 grep '^ *+' $at_stder1 >&2 3996 grep -v '^ *+' $at_stder1 >$at_stderr 3997 at_failed=false 3998 $at_diff $at_devnull $at_stderr || at_failed=: 3999 $at_diff $at_devnull $at_stdout || at_failed=: 4000 case $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=:;; 4006 esac 4007 if $at_failed; then 4008 4009 echo 1 > $at_status_file 4010 exit 1 4011 fi 4012 4013 $at_traceon 4014 4015 4016 # Get the final state in the parser. 4017 $at_traceoff 4018 echo "sets.at:285: sed -n 's/.*define YYFINAL *\\([0-9][0-9]*\\)/final state \\1/p' input.c" 4019 echo 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 4021 at_status=$? 4022 grep '^ *+' $at_stder1 >&2 4023 grep -v '^ *+' $at_stder1 >$at_stderr 4024 at_failed=false 4025 $at_diff $at_devnull $at_stderr || at_failed=: 4026 echo stdout:; tee stdout <$at_stdout 4027 case $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=:;; 4033 esac 4034 if $at_failed; then 4035 4036 echo 1 > $at_status_file 4037 exit 1 4038 fi 4039 4040 $at_traceon 4041 4042 mv stdout expout 4043 4044 # Get the final state in the report, from the "accept" action.. 4045 $at_traceoff 4046 echo "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" 4057 echo 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 4069 at_status=$? 4070 grep '^ *+' $at_stder1 >&2 4071 grep -v '^ *+' $at_stder1 >$at_stderr 4072 at_failed=false 4073 $at_diff $at_devnull $at_stderr || at_failed=: 4074 $at_diff expout $at_stdout || at_failed=: 4075 case $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=:;; 4081 esac 4082 if $at_failed; then 4083 4084 echo 1 > $at_status_file 4085 exit 1 4086 fi 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 4101 Grammar 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 4116 cat >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 %% 4132 exp: useful; 4133 _ATEOF 4134 4135 4136 $at_traceoff 4137 echo "reduce.at:47: bison input.y" 4138 echo reduce.at:47 >$at_check_line_file 4139 ( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1 4140 at_status=$? 4141 grep '^ *+' $at_stder1 >&2 4142 grep -v '^ *+' $at_stder1 >$at_stderr 4143 at_failed=false 4144 $at_diff $at_devnull $at_stderr || at_failed=: 4145 $at_diff $at_devnull $at_stdout || at_failed=: 4146 case $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=:;; 4152 esac 4153 if $at_failed; then 4154 4155 echo 1 > $at_status_file 4156 exit 1 4157 fi 4158 4159 $at_traceon 4160 4161 4162 $at_traceoff 4163 echo "reduce.at:60: sed -n '/^Grammar/q;/^\$/!p' input.output" 4164 echo reduce.at:60 >$at_check_line_file 4165 ( $at_traceon; sed -n '/^Grammar/q;/^$/!p' input.output ) >$at_stdout 2>$at_stder1 4166 at_status=$? 4167 grep '^ *+' $at_stder1 >&2 4168 grep -v '^ *+' $at_stder1 >$at_stderr 4169 at_failed=false 4170 $at_diff $at_devnull $at_stderr || at_failed=: 4171 echo >>$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=: 4182 case $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=:;; 4188 esac 4189 if $at_failed; then 4190 4191 echo 1 > $at_status_file 4192 exit 1 4193 fi 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 4214 cat >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 %% 4230 exp: useful; 4231 _ATEOF 4232 4233 4234 $at_traceoff 4235 echo "reduce.at:102: bison input.y" 4236 echo reduce.at:102 >$at_check_line_file 4237 ( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1 4238 at_status=$? 4239 grep '^ *+' $at_stder1 >&2 4240 grep -v '^ *+' $at_stder1 >$at_stderr 4241 at_failed=false 4242 echo >>$at_stderr; echo "input.y: warning: 9 useless nonterminals 4243 input.y:4.8-15: warning: useless nonterminal: useless1 4244 input.y:5.8-15: warning: useless nonterminal: useless2 4245 input.y:6.8-15: warning: useless nonterminal: useless3 4246 input.y:7.8-15: warning: useless nonterminal: useless4 4247 input.y:8.8-15: warning: useless nonterminal: useless5 4248 input.y:9.8-15: warning: useless nonterminal: useless6 4249 input.y:10.8-15: warning: useless nonterminal: useless7 4250 input.y:11.8-15: warning: useless nonterminal: useless8 4251 input.y:12.8-15: warning: useless nonterminal: useless9 4252 " | $at_diff - $at_stderr || at_failed=: 4253 $at_diff $at_devnull $at_stdout || at_failed=: 4254 case $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=:;; 4260 esac 4261 if $at_failed; then 4262 4263 echo 1 > $at_status_file 4264 exit 1 4265 fi 4266 4267 $at_traceon 4268 4269 4270 $at_traceoff 4271 echo "reduce.at:115: sed -n '/^Grammar/q;/^\$/!p' input.output" 4272 echo reduce.at:115 >$at_check_line_file 4273 ( $at_traceon; sed -n '/^Grammar/q;/^$/!p' input.output ) >$at_stdout 2>$at_stder1 4274 at_status=$? 4275 grep '^ *+' $at_stder1 >&2 4276 grep -v '^ *+' $at_stder1 >$at_stderr 4277 at_failed=false 4278 $at_diff $at_devnull $at_stderr || at_failed=: 4279 echo >>$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=: 4290 case $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=:;; 4296 esac 4297 if $at_failed; then 4298 4299 echo 1 > $at_status_file 4300 exit 1 4301 fi 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 4324 cat >input.y <<'_ATEOF' 4325 %verbose 4326 %output="input.c" 4327 %token useful 4328 %% 4329 exp: useful; 4330 useless1: '1'; 4331 useless2: '2'; 4332 useless3: '3'; 4333 useless4: '4'; 4334 useless5: '5'; 4335 useless6: '6'; 4336 useless7: '7'; 4337 useless8: '8'; 4338 useless9: '9'; 4339 _ATEOF 4340 4341 4342 $at_traceoff 4343 echo "reduce.at:166: bison input.y" 4344 echo reduce.at:166 >$at_check_line_file 4345 ( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1 4346 at_status=$? 4347 grep '^ *+' $at_stder1 >&2 4348 grep -v '^ *+' $at_stder1 >$at_stderr 4349 at_failed=false 4350 echo >>$at_stderr; echo "input.y: warning: 9 useless nonterminals and 9 useless rules 4351 input.y:6.1-8: warning: useless nonterminal: useless1 4352 input.y:7.1-8: warning: useless nonterminal: useless2 4353 input.y:8.1-8: warning: useless nonterminal: useless3 4354 input.y:9.1-8: warning: useless nonterminal: useless4 4355 input.y:10.1-8: warning: useless nonterminal: useless5 4356 input.y:11.1-8: warning: useless nonterminal: useless6 4357 input.y:12.1-8: warning: useless nonterminal: useless7 4358 input.y:13.1-8: warning: useless nonterminal: useless8 4359 input.y:14.1-8: warning: useless nonterminal: useless9 4360 input.y:6.11-13: warning: useless rule: useless1: '1' 4361 input.y:7.11-13: warning: useless rule: useless2: '2' 4362 input.y:8.11-13: warning: useless rule: useless3: '3' 4363 input.y:9.11-13: warning: useless rule: useless4: '4' 4364 input.y:10.11-13: warning: useless rule: useless5: '5' 4365 input.y:11.11-13: warning: useless rule: useless6: '6' 4366 input.y:12.11-13: warning: useless rule: useless7: '7' 4367 input.y:13.11-13: warning: useless rule: useless8: '8' 4368 input.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=: 4371 case $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=:;; 4377 esac 4378 if $at_failed; then 4379 4380 echo 1 > $at_status_file 4381 exit 1 4382 fi 4383 4384 $at_traceon 4385 4386 4387 $at_traceoff 4388 echo "reduce.at:199: sed -n '/^Grammar/q;/^\$/!p' input.output" 4389 echo reduce.at:199 >$at_check_line_file 4390 ( $at_traceon; sed -n '/^Grammar/q;/^$/!p' input.output ) >$at_stdout 2>$at_stder1 4391 at_status=$? 4392 grep '^ *+' $at_stder1 >&2 4393 grep -v '^ *+' $at_stder1 >$at_stderr 4394 at_failed=false 4395 $at_diff $at_devnull $at_stderr || at_failed=: 4396 echo >>$at_stdout; echo "Useless nonterminals 4397 useless1 4398 useless2 4399 useless3 4400 useless4 4401 useless5 4402 useless6 4403 useless7 4404 useless8 4405 useless9 4406 Terminals which are not used 4407 '1' 4408 '2' 4409 '3' 4410 '4' 4411 '5' 4412 '6' 4413 '7' 4414 '8' 4415 '9' 4416 Useless 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=: 4427 case $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=:;; 4433 esac 4434 if $at_failed; then 4435 4436 echo 1 > $at_status_file 4437 exit 1 4438 fi 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 # ------------------------ 4463 cat >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 4473 exp: useful { /* A useful action. */ } 4474 | non_productive { /* A non productive action. */ } 4475 ; 4476 4477 not_reachable: useful { /* A not reachable action. */ } 4478 ; 4479 4480 non_productive: non_productive useless_token 4481 { /* Another non productive action. */ } 4482 ; 4483 %% 4484 _ATEOF 4485 4486 4487 $at_traceoff 4488 echo "reduce.at:248: bison not-reduced.y" 4489 echo reduce.at:248 >$at_check_line_file 4490 ( $at_traceon; bison not-reduced.y ) >$at_stdout 2>$at_stder1 4491 at_status=$? 4492 grep '^ *+' $at_stder1 >&2 4493 grep -v '^ *+' $at_stder1 >$at_stderr 4494 at_failed=false 4495 echo >>$at_stderr; echo "not-reduced.y: warning: 2 useless nonterminals and 3 useless rules 4496 not-reduced.y:14.1-13: warning: useless nonterminal: not_reachable 4497 not-reduced.y:11.6-19: warning: useless nonterminal: non_productive 4498 not-reduced.y:11.6-57: warning: useless rule: exp: non_productive 4499 not-reduced.y:14.16-56: warning: useless rule: not_reachable: useful 4500 not-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=: 4503 case $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=:;; 4509 esac 4510 if $at_failed; then 4511 4512 echo 1 > $at_status_file 4513 exit 1 4514 fi 4515 4516 $at_traceon 4517 4518 4519 $at_traceoff 4520 echo "reduce.at:260: sed -n '/^Grammar/q;/^\$/!p' not-reduced.output" 4521 echo reduce.at:260 >$at_check_line_file 4522 ( $at_traceon; sed -n '/^Grammar/q;/^$/!p' not-reduced.output ) >$at_stdout 2>$at_stder1 4523 at_status=$? 4524 grep '^ *+' $at_stder1 >&2 4525 grep -v '^ *+' $at_stder1 >$at_stderr 4526 at_failed=false 4527 $at_diff $at_devnull $at_stderr || at_failed=: 4528 echo >>$at_stdout; echo "Useless nonterminals 4529 not_reachable 4530 non_productive 4531 Terminals which are not used 4532 useless_token 4533 Useless 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=: 4538 case $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=:;; 4544 esac 4545 if $at_failed; then 4546 4547 echo 1 > $at_status_file 4548 exit 1 4549 fi 4550 4551 $at_traceon 4552 4553 4554 # The reduced grammar. 4555 # -------------------- 4556 cat >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 4566 exp: 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 4581 echo "reduce.at:287: bison reduced.y" 4582 echo reduce.at:287 >$at_check_line_file 4583 ( $at_traceon; bison reduced.y ) >$at_stdout 2>$at_stder1 4584 at_status=$? 4585 grep '^ *+' $at_stder1 >&2 4586 grep -v '^ *+' $at_stder1 >$at_stderr 4587 at_failed=false 4588 $at_diff $at_devnull $at_stderr || at_failed=: 4589 $at_diff $at_devnull $at_stdout || at_failed=: 4590 case $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=:;; 4596 esac 4597 if $at_failed; then 4598 4599 echo 1 > $at_status_file 4600 exit 1 4601 fi 4602 4603 $at_traceon 4604 4605 4606 # Comparing the parsers. 4607 cp reduced.c expout 4608 $at_traceoff 4609 echo "reduce.at:291: sed 's/not-reduced/reduced/g' not-reduced.c" 4610 echo reduce.at:291 >$at_check_line_file 4611 ( $at_traceon; sed 's/not-reduced/reduced/g' not-reduced.c ) >$at_stdout 2>$at_stder1 4612 at_status=$? 4613 grep '^ *+' $at_stder1 >&2 4614 grep -v '^ *+' $at_stder1 >$at_stderr 4615 at_failed=false 4616 $at_diff $at_devnull $at_stderr || at_failed=: 4617 $at_diff expout $at_stdout || at_failed=: 4618 case $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=:;; 4624 esac 4625 if $at_failed; then 4626 4627 echo 1 > $at_status_file 4628 exit 1 4629 fi 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 4652 cat >input.y <<'_ATEOF' 4653 %verbose 4654 %output="input.c" 4655 %token useful 4656 %% 4657 exp: useful | underivable; 4658 underivable: indirection; 4659 indirection: underivable; 4660 _ATEOF 4661 4662 4663 $at_traceoff 4664 echo "reduce.at:322: bison input.y" 4665 echo reduce.at:322 >$at_check_line_file 4666 ( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1 4667 at_status=$? 4668 grep '^ *+' $at_stder1 >&2 4669 grep -v '^ *+' $at_stder1 >$at_stderr 4670 at_failed=false 4671 echo >>$at_stderr; echo "input.y: warning: 2 useless nonterminals and 3 useless rules 4672 input.y:5.15-25: warning: useless nonterminal: underivable 4673 input.y:6.14-24: warning: useless nonterminal: indirection 4674 input.y:5.15-25: warning: useless rule: exp: underivable 4675 input.y:6.14-24: warning: useless rule: underivable: indirection 4676 input.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=: 4679 case $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=:;; 4685 esac 4686 if $at_failed; then 4687 4688 echo 1 > $at_status_file 4689 exit 1 4690 fi 4691 4692 $at_traceon 4693 4694 4695 $at_traceoff 4696 echo "reduce.at:332: sed -n '/^Grammar/q;/^\$/!p' input.output" 4697 echo reduce.at:332 >$at_check_line_file 4698 ( $at_traceon; sed -n '/^Grammar/q;/^$/!p' input.output ) >$at_stdout 2>$at_stder1 4699 at_status=$? 4700 grep '^ *+' $at_stder1 >&2 4701 grep -v '^ *+' $at_stder1 >$at_stderr 4702 at_failed=false 4703 $at_diff $at_devnull $at_stderr || at_failed=: 4704 echo >>$at_stdout; echo "Useless nonterminals 4705 underivable 4706 indirection 4707 Useless rules 4708 2 exp: underivable 4709 3 underivable: indirection 4710 4 indirection: underivable 4711 " | $at_diff - $at_stdout || at_failed=: 4712 case $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=:;; 4718 esac 4719 if $at_failed; then 4720 4721 echo 1 > $at_status_file 4722 exit 1 4723 fi 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 4744 cat >input.y <<'_ATEOF' 4745 %output="input.c" 4746 %% 4747 exp: exp; 4748 _ATEOF 4749 4750 4751 $at_traceoff 4752 echo "reduce.at:353: bison input.y" 4753 echo reduce.at:353 >$at_check_line_file 4754 ( $at_traceon; bison input.y ) >$at_stdout 2>$at_stder1 4755 at_status=$? 4756 grep '^ *+' $at_stder1 >&2 4757 grep -v '^ *+' $at_stder1 >$at_stderr 4758 at_failed=false 4759 echo >>$at_stderr; echo "input.y: warning: 2 useless nonterminals and 2 useless rules 4760 input.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=: 4763 case $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=:;; 4769 esac 4770 if $at_failed; then 4771 4772 echo 1 > $at_status_file 4773 exit 1 4774 fi 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 4789 User 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 4821 cat >syncline.c <<'_ATEOF' 4822 #error "1" 4823 _ATEOF 4824 4825 4826 $at_traceoff 4827 echo "synclines.at:95: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c" 4828 echo synclines.at:95 >$at_check_line_file 4829 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1 4830 at_status=$? 4831 grep '^ *+' $at_stder1 >&2 4832 grep -v '^ *+' $at_stder1 >$at_stderr 4833 at_failed=false 4834 echo stderr:; tee stderr <$at_stderr 4835 $at_diff $at_devnull $at_stdout || at_failed=: 4836 case $at_status in 4837 77) echo 77 > $at_status_file 4838 exit 77;; 4839 *);; 4840 esac 4841 if $at_failed; then 4842 4843 echo 1 > $at_status_file 4844 exit 1 4845 fi 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 4858 echo "synclines.at:95: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr" 4859 echo 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 4861 at_status=$? 4862 grep '^ *+' $at_stder1 >&2 4863 grep -v '^ *+' $at_stder1 >$at_stderr 4864 at_failed=false 4865 $at_diff $at_devnull $at_stderr || at_failed=: 4866 echo stdout:; tee stdout <$at_stdout 4867 case $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=:;; 4873 esac 4874 if $at_failed; then 4875 4876 echo 1 > $at_status_file 4877 exit 1 4878 fi 4879 4880 $at_traceon 4881 4882 4883 $at_traceoff 4884 echo "synclines.at:95: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77" 4885 echo 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 4887 at_status=$? 4888 grep '^ *+' $at_stder1 >&2 4889 grep -v '^ *+' $at_stder1 >$at_stderr 4890 at_failed=false 4891 $at_diff $at_devnull $at_stderr || at_failed=: 4892 $at_diff $at_devnull $at_stdout || at_failed=: 4893 case $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=:;; 4899 esac 4900 if $at_failed; then 4901 4902 echo 1 > $at_status_file 4903 exit 1 4904 fi 4905 4906 $at_traceon 4907 4908 4909 cat >input.y <<'_ATEOF' 4910 %{ 4911 #error "2" 4912 void yyerror (const char *s); 4913 int yylex (void); 4914 %} 4915 %% 4916 exp: '0'; 4917 _ATEOF 4918 4919 $at_traceoff 4920 echo "synclines.at:95: bison -o input.c input.y" 4921 echo synclines.at:95 >$at_check_line_file 4922 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 4923 at_status=$? 4924 grep '^ *+' $at_stder1 >&2 4925 grep -v '^ *+' $at_stder1 >$at_stderr 4926 at_failed=false 4927 $at_diff $at_devnull $at_stderr || at_failed=: 4928 $at_diff $at_devnull $at_stdout || at_failed=: 4929 case $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=:;; 4935 esac 4936 if $at_failed; then 4937 4938 echo 1 > $at_status_file 4939 exit 1 4940 fi 4941 4942 $at_traceon 4943 4944 $at_traceoff 4945 echo "synclines.at:95: \$CC \$CFLAGS \$CPPFLAGS -c input.c" 4946 echo synclines.at:95 >$at_check_line_file 4947 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1 4948 at_status=$? 4949 grep '^ *+' $at_stder1 >&2 4950 grep -v '^ *+' $at_stder1 >$at_stderr 4951 at_failed=false 4952 echo stderr:; tee stderr <$at_stderr 4953 $at_diff $at_devnull $at_stdout || at_failed=: 4954 case $at_status in 4955 77) echo 77 > $at_status_file 4956 exit 77;; 4957 *);; 4958 esac 4959 if $at_failed; then 4960 4961 echo 1 > $at_status_file 4962 exit 1 4963 fi 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 4976 echo "synclines.at:95: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr" 4977 echo 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 4979 at_status=$? 4980 grep '^ *+' $at_stder1 >&2 4981 grep -v '^ *+' $at_stder1 >$at_stderr 4982 at_failed=false 4983 $at_diff $at_devnull $at_stderr || at_failed=: 4984 echo stdout:; tee stdout <$at_stdout 4985 case $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=:;; 4991 esac 4992 if $at_failed; then 4993 4994 echo 1 > $at_status_file 4995 exit 1 4996 fi 4997 4998 $at_traceon 4999 5000 5001 $at_traceoff 5002 echo "synclines.at:95: cat stdout" 5003 echo synclines.at:95 >$at_check_line_file 5004 ( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1 5005 at_status=$? 5006 grep '^ *+' $at_stder1 >&2 5007 grep -v '^ *+' $at_stder1 >$at_stderr 5008 at_failed=false 5009 $at_diff $at_devnull $at_stderr || at_failed=: 5010 echo >>$at_stdout; echo "input.y:2: #error \"2\" 5011 " | $at_diff - $at_stdout || at_failed=: 5012 case $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=:;; 5018 esac 5019 if $at_failed; then 5020 5021 echo 1 > $at_status_file 5022 exit 1 5023 fi 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 5060 cat >syncline.c <<'_ATEOF' 5061 #error "1" 5062 _ATEOF 5063 5064 5065 $at_traceoff 5066 echo "synclines.at:115: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c" 5067 echo synclines.at:115 >$at_check_line_file 5068 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1 5069 at_status=$? 5070 grep '^ *+' $at_stder1 >&2 5071 grep -v '^ *+' $at_stder1 >$at_stderr 5072 at_failed=false 5073 echo stderr:; tee stderr <$at_stderr 5074 $at_diff $at_devnull $at_stdout || at_failed=: 5075 case $at_status in 5076 77) echo 77 > $at_status_file 5077 exit 77;; 5078 *);; 5079 esac 5080 if $at_failed; then 5081 5082 echo 1 > $at_status_file 5083 exit 1 5084 fi 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 5097 echo "synclines.at:115: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr" 5098 echo 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 5100 at_status=$? 5101 grep '^ *+' $at_stder1 >&2 5102 grep -v '^ *+' $at_stder1 >$at_stderr 5103 at_failed=false 5104 $at_diff $at_devnull $at_stderr || at_failed=: 5105 echo stdout:; tee stdout <$at_stdout 5106 case $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=:;; 5112 esac 5113 if $at_failed; then 5114 5115 echo 1 > $at_status_file 5116 exit 1 5117 fi 5118 5119 $at_traceon 5120 5121 5122 $at_traceoff 5123 echo "synclines.at:115: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77" 5124 echo 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 5126 at_status=$? 5127 grep '^ *+' $at_stder1 >&2 5128 grep -v '^ *+' $at_stder1 >$at_stderr 5129 at_failed=false 5130 $at_diff $at_devnull $at_stderr || at_failed=: 5131 $at_diff $at_devnull $at_stdout || at_failed=: 5132 case $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=:;; 5138 esac 5139 if $at_failed; then 5140 5141 echo 1 > $at_status_file 5142 exit 1 5143 fi 5144 5145 $at_traceon 5146 5147 5148 cat >input.y <<'_ATEOF' 5149 %union { 5150 #error "2" 5151 char dummy; 5152 } 5153 %{ 5154 void yyerror (const char *s); 5155 int yylex (void); 5156 %} 5157 %% 5158 exp: '0'; 5159 _ATEOF 5160 5161 $at_traceoff 5162 echo "synclines.at:115: bison -o input.c input.y" 5163 echo synclines.at:115 >$at_check_line_file 5164 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 5165 at_status=$? 5166 grep '^ *+' $at_stder1 >&2 5167 grep -v '^ *+' $at_stder1 >$at_stderr 5168 at_failed=false 5169 $at_diff $at_devnull $at_stderr || at_failed=: 5170 $at_diff $at_devnull $at_stdout || at_failed=: 5171 case $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=:;; 5177 esac 5178 if $at_failed; then 5179 5180 echo 1 > $at_status_file 5181 exit 1 5182 fi 5183 5184 $at_traceon 5185 5186 $at_traceoff 5187 echo "synclines.at:115: \$CC \$CFLAGS \$CPPFLAGS -c input.c" 5188 echo synclines.at:115 >$at_check_line_file 5189 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1 5190 at_status=$? 5191 grep '^ *+' $at_stder1 >&2 5192 grep -v '^ *+' $at_stder1 >$at_stderr 5193 at_failed=false 5194 echo stderr:; tee stderr <$at_stderr 5195 $at_diff $at_devnull $at_stdout || at_failed=: 5196 case $at_status in 5197 77) echo 77 > $at_status_file 5198 exit 77;; 5199 *);; 5200 esac 5201 if $at_failed; then 5202 5203 echo 1 > $at_status_file 5204 exit 1 5205 fi 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 5218 echo "synclines.at:115: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr" 5219 echo 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 5221 at_status=$? 5222 grep '^ *+' $at_stder1 >&2 5223 grep -v '^ *+' $at_stder1 >$at_stderr 5224 at_failed=false 5225 $at_diff $at_devnull $at_stderr || at_failed=: 5226 echo stdout:; tee stdout <$at_stdout 5227 case $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=:;; 5233 esac 5234 if $at_failed; then 5235 5236 echo 1 > $at_status_file 5237 exit 1 5238 fi 5239 5240 $at_traceon 5241 5242 5243 $at_traceoff 5244 echo "synclines.at:115: cat stdout" 5245 echo synclines.at:115 >$at_check_line_file 5246 ( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1 5247 at_status=$? 5248 grep '^ *+' $at_stder1 >&2 5249 grep -v '^ *+' $at_stder1 >$at_stderr 5250 at_failed=false 5251 $at_diff $at_devnull $at_stderr || at_failed=: 5252 echo >>$at_stdout; echo "input.y:2: #error \"2\" 5253 " | $at_diff - $at_stdout || at_failed=: 5254 case $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=:;; 5260 esac 5261 if $at_failed; then 5262 5263 echo 1 > $at_status_file 5264 exit 1 5265 fi 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 5302 cat >syncline.c <<'_ATEOF' 5303 #error "1" 5304 _ATEOF 5305 5306 5307 $at_traceoff 5308 echo "synclines.at:138: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c" 5309 echo synclines.at:138 >$at_check_line_file 5310 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1 5311 at_status=$? 5312 grep '^ *+' $at_stder1 >&2 5313 grep -v '^ *+' $at_stder1 >$at_stderr 5314 at_failed=false 5315 echo stderr:; tee stderr <$at_stderr 5316 $at_diff $at_devnull $at_stdout || at_failed=: 5317 case $at_status in 5318 77) echo 77 > $at_status_file 5319 exit 77;; 5320 *);; 5321 esac 5322 if $at_failed; then 5323 5324 echo 1 > $at_status_file 5325 exit 1 5326 fi 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 5339 echo "synclines.at:138: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr" 5340 echo 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 5342 at_status=$? 5343 grep '^ *+' $at_stder1 >&2 5344 grep -v '^ *+' $at_stder1 >$at_stderr 5345 at_failed=false 5346 $at_diff $at_devnull $at_stderr || at_failed=: 5347 echo stdout:; tee stdout <$at_stdout 5348 case $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=:;; 5354 esac 5355 if $at_failed; then 5356 5357 echo 1 > $at_status_file 5358 exit 1 5359 fi 5360 5361 $at_traceon 5362 5363 5364 $at_traceoff 5365 echo "synclines.at:138: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77" 5366 echo 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 5368 at_status=$? 5369 grep '^ *+' $at_stder1 >&2 5370 grep -v '^ *+' $at_stder1 >$at_stderr 5371 at_failed=false 5372 $at_diff $at_devnull $at_stderr || at_failed=: 5373 $at_diff $at_devnull $at_stdout || at_failed=: 5374 case $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=:;; 5380 esac 5381 if $at_failed; then 5382 5383 echo 1 > $at_status_file 5384 exit 1 5385 fi 5386 5387 $at_traceon 5388 5389 5390 cat >input.y <<'_ATEOF' 5391 %{ 5392 void yyerror (const char *s); 5393 int yylex (void); 5394 %} 5395 %union 5396 { 5397 int ival; 5398 } 5399 %{ 5400 #error "10" 5401 %} 5402 %% 5403 exp: '0'; 5404 _ATEOF 5405 5406 $at_traceoff 5407 echo "synclines.at:138: bison -o input.c input.y" 5408 echo synclines.at:138 >$at_check_line_file 5409 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 5410 at_status=$? 5411 grep '^ *+' $at_stder1 >&2 5412 grep -v '^ *+' $at_stder1 >$at_stderr 5413 at_failed=false 5414 $at_diff $at_devnull $at_stderr || at_failed=: 5415 $at_diff $at_devnull $at_stdout || at_failed=: 5416 case $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=:;; 5422 esac 5423 if $at_failed; then 5424 5425 echo 1 > $at_status_file 5426 exit 1 5427 fi 5428 5429 $at_traceon 5430 5431 $at_traceoff 5432 echo "synclines.at:138: \$CC \$CFLAGS \$CPPFLAGS -c input.c" 5433 echo synclines.at:138 >$at_check_line_file 5434 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1 5435 at_status=$? 5436 grep '^ *+' $at_stder1 >&2 5437 grep -v '^ *+' $at_stder1 >$at_stderr 5438 at_failed=false 5439 echo stderr:; tee stderr <$at_stderr 5440 $at_diff $at_devnull $at_stdout || at_failed=: 5441 case $at_status in 5442 77) echo 77 > $at_status_file 5443 exit 77;; 5444 *);; 5445 esac 5446 if $at_failed; then 5447 5448 echo 1 > $at_status_file 5449 exit 1 5450 fi 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 5463 echo "synclines.at:138: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr" 5464 echo 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 5466 at_status=$? 5467 grep '^ *+' $at_stder1 >&2 5468 grep -v '^ *+' $at_stder1 >$at_stderr 5469 at_failed=false 5470 $at_diff $at_devnull $at_stderr || at_failed=: 5471 echo stdout:; tee stdout <$at_stdout 5472 case $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=:;; 5478 esac 5479 if $at_failed; then 5480 5481 echo 1 > $at_status_file 5482 exit 1 5483 fi 5484 5485 $at_traceon 5486 5487 5488 $at_traceoff 5489 echo "synclines.at:138: cat stdout" 5490 echo synclines.at:138 >$at_check_line_file 5491 ( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1 5492 at_status=$? 5493 grep '^ *+' $at_stder1 >&2 5494 grep -v '^ *+' $at_stder1 >$at_stderr 5495 at_failed=false 5496 $at_diff $at_devnull $at_stderr || at_failed=: 5497 echo >>$at_stdout; echo "input.y:10: #error \"10\" 5498 " | $at_diff - $at_stdout || at_failed=: 5499 case $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=:;; 5505 esac 5506 if $at_failed; then 5507 5508 echo 1 > $at_status_file 5509 exit 1 5510 fi 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 5547 cat >syncline.c <<'_ATEOF' 5548 #error "1" 5549 _ATEOF 5550 5551 5552 $at_traceoff 5553 echo "synclines.at:157: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c" 5554 echo synclines.at:157 >$at_check_line_file 5555 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1 5556 at_status=$? 5557 grep '^ *+' $at_stder1 >&2 5558 grep -v '^ *+' $at_stder1 >$at_stderr 5559 at_failed=false 5560 echo stderr:; tee stderr <$at_stderr 5561 $at_diff $at_devnull $at_stdout || at_failed=: 5562 case $at_status in 5563 77) echo 77 > $at_status_file 5564 exit 77;; 5565 *);; 5566 esac 5567 if $at_failed; then 5568 5569 echo 1 > $at_status_file 5570 exit 1 5571 fi 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 5584 echo "synclines.at:157: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr" 5585 echo 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 5587 at_status=$? 5588 grep '^ *+' $at_stder1 >&2 5589 grep -v '^ *+' $at_stder1 >$at_stderr 5590 at_failed=false 5591 $at_diff $at_devnull $at_stderr || at_failed=: 5592 echo stdout:; tee stdout <$at_stdout 5593 case $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=:;; 5599 esac 5600 if $at_failed; then 5601 5602 echo 1 > $at_status_file 5603 exit 1 5604 fi 5605 5606 $at_traceon 5607 5608 5609 $at_traceoff 5610 echo "synclines.at:157: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77" 5611 echo 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 5613 at_status=$? 5614 grep '^ *+' $at_stder1 >&2 5615 grep -v '^ *+' $at_stder1 >$at_stderr 5616 at_failed=false 5617 $at_diff $at_devnull $at_stderr || at_failed=: 5618 $at_diff $at_devnull $at_stdout || at_failed=: 5619 case $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=:;; 5625 esac 5626 if $at_failed; then 5627 5628 echo 1 > $at_status_file 5629 exit 1 5630 fi 5631 5632 $at_traceon 5633 5634 5635 cat >input.y <<'_ATEOF' 5636 %{ 5637 void yyerror (const char *s); 5638 int yylex (void); 5639 %} 5640 %% 5641 exp: 5642 { 5643 #error "8" 5644 }; 5645 _ATEOF 5646 5647 $at_traceoff 5648 echo "synclines.at:157: bison -o input.c input.y" 5649 echo synclines.at:157 >$at_check_line_file 5650 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 5651 at_status=$? 5652 grep '^ *+' $at_stder1 >&2 5653 grep -v '^ *+' $at_stder1 >$at_stderr 5654 at_failed=false 5655 $at_diff $at_devnull $at_stderr || at_failed=: 5656 $at_diff $at_devnull $at_stdout || at_failed=: 5657 case $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=:;; 5663 esac 5664 if $at_failed; then 5665 5666 echo 1 > $at_status_file 5667 exit 1 5668 fi 5669 5670 $at_traceon 5671 5672 $at_traceoff 5673 echo "synclines.at:157: \$CC \$CFLAGS \$CPPFLAGS -c input.c" 5674 echo synclines.at:157 >$at_check_line_file 5675 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1 5676 at_status=$? 5677 grep '^ *+' $at_stder1 >&2 5678 grep -v '^ *+' $at_stder1 >$at_stderr 5679 at_failed=false 5680 echo stderr:; tee stderr <$at_stderr 5681 $at_diff $at_devnull $at_stdout || at_failed=: 5682 case $at_status in 5683 77) echo 77 > $at_status_file 5684 exit 77;; 5685 *);; 5686 esac 5687 if $at_failed; then 5688 5689 echo 1 > $at_status_file 5690 exit 1 5691 fi 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 5704 echo "synclines.at:157: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr" 5705 echo 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 5707 at_status=$? 5708 grep '^ *+' $at_stder1 >&2 5709 grep -v '^ *+' $at_stder1 >$at_stderr 5710 at_failed=false 5711 $at_diff $at_devnull $at_stderr || at_failed=: 5712 echo stdout:; tee stdout <$at_stdout 5713 case $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=:;; 5719 esac 5720 if $at_failed; then 5721 5722 echo 1 > $at_status_file 5723 exit 1 5724 fi 5725 5726 $at_traceon 5727 5728 5729 $at_traceoff 5730 echo "synclines.at:157: cat stdout" 5731 echo synclines.at:157 >$at_check_line_file 5732 ( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1 5733 at_status=$? 5734 grep '^ *+' $at_stder1 >&2 5735 grep -v '^ *+' $at_stder1 >$at_stderr 5736 at_failed=false 5737 $at_diff $at_devnull $at_stderr || at_failed=: 5738 echo >>$at_stdout; echo "input.y:8: #error \"8\" 5739 " | $at_diff - $at_stdout || at_failed=: 5740 case $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=:;; 5746 esac 5747 if $at_failed; then 5748 5749 echo 1 > $at_status_file 5750 exit 1 5751 fi 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 5788 cat >syncline.c <<'_ATEOF' 5789 #error "1" 5790 _ATEOF 5791 5792 5793 $at_traceoff 5794 echo "synclines.at:175: \$CC \$CFLAGS \$CPPFLAGS -c syncline.c" 5795 echo synclines.at:175 >$at_check_line_file 5796 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -c syncline.c ) >$at_stdout 2>$at_stder1 5797 at_status=$? 5798 grep '^ *+' $at_stder1 >&2 5799 grep -v '^ *+' $at_stder1 >$at_stderr 5800 at_failed=false 5801 echo stderr:; tee stderr <$at_stderr 5802 $at_diff $at_devnull $at_stdout || at_failed=: 5803 case $at_status in 5804 77) echo 77 > $at_status_file 5805 exit 77;; 5806 *);; 5807 esac 5808 if $at_failed; then 5809 5810 echo 1 > $at_status_file 5811 exit 1 5812 fi 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 5825 echo "synclines.at:175: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr" 5826 echo 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 5828 at_status=$? 5829 grep '^ *+' $at_stder1 >&2 5830 grep -v '^ *+' $at_stder1 >$at_stderr 5831 at_failed=false 5832 $at_diff $at_devnull $at_stderr || at_failed=: 5833 echo stdout:; tee stdout <$at_stdout 5834 case $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=:;; 5840 esac 5841 if $at_failed; then 5842 5843 echo 1 > $at_status_file 5844 exit 1 5845 fi 5846 5847 $at_traceon 5848 5849 5850 $at_traceoff 5851 echo "synclines.at:175: test \"\`cat stdout\`\" = 'syncline.c:1: #error \"1\"' || exit 77" 5852 echo 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 5854 at_status=$? 5855 grep '^ *+' $at_stder1 >&2 5856 grep -v '^ *+' $at_stder1 >$at_stderr 5857 at_failed=false 5858 $at_diff $at_devnull $at_stderr || at_failed=: 5859 $at_diff $at_devnull $at_stdout || at_failed=: 5860 case $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=:;; 5866 esac 5867 if $at_failed; then 5868 5869 echo 1 > $at_status_file 5870 exit 1 5871 fi 5872 5873 $at_traceon 5874 5875 5876 cat >input.y <<'_ATEOF' 5877 %{ 5878 void yyerror (const char *s); 5879 int yylex (void); 5880 %} 5881 %% 5882 exp: '0'; 5883 %% 5884 #error "8" 5885 _ATEOF 5886 5887 $at_traceoff 5888 echo "synclines.at:175: bison -o input.c input.y" 5889 echo synclines.at:175 >$at_check_line_file 5890 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 5891 at_status=$? 5892 grep '^ *+' $at_stder1 >&2 5893 grep -v '^ *+' $at_stder1 >$at_stderr 5894 at_failed=false 5895 $at_diff $at_devnull $at_stderr || at_failed=: 5896 $at_diff $at_devnull $at_stdout || at_failed=: 5897 case $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=:;; 5903 esac 5904 if $at_failed; then 5905 5906 echo 1 > $at_status_file 5907 exit 1 5908 fi 5909 5910 $at_traceon 5911 5912 $at_traceoff 5913 echo "synclines.at:175: \$CC \$CFLAGS \$CPPFLAGS -c input.c" 5914 echo synclines.at:175 >$at_check_line_file 5915 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -c input.c ) >$at_stdout 2>$at_stder1 5916 at_status=$? 5917 grep '^ *+' $at_stder1 >&2 5918 grep -v '^ *+' $at_stder1 >$at_stderr 5919 at_failed=false 5920 echo stderr:; tee stderr <$at_stderr 5921 $at_diff $at_devnull $at_stdout || at_failed=: 5922 case $at_status in 5923 77) echo 77 > $at_status_file 5924 exit 77;; 5925 *);; 5926 esac 5927 if $at_failed; then 5928 5929 echo 1 > $at_status_file 5930 exit 1 5931 fi 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 5944 echo "synclines.at:175: sed -e 's/^\\([^:]*:[^:.]*\\)[.:][^:]*:\\(.*\\)\$/\\1:\\2/' -e 's/^\\([^:]*:[^:]*:\\)[^#]*\\( #error\\)/\\1\\2/' stderr" 5945 echo 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 5947 at_status=$? 5948 grep '^ *+' $at_stder1 >&2 5949 grep -v '^ *+' $at_stder1 >$at_stderr 5950 at_failed=false 5951 $at_diff $at_devnull $at_stderr || at_failed=: 5952 echo stdout:; tee stdout <$at_stdout 5953 case $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=:;; 5959 esac 5960 if $at_failed; then 5961 5962 echo 1 > $at_status_file 5963 exit 1 5964 fi 5965 5966 $at_traceon 5967 5968 5969 $at_traceoff 5970 echo "synclines.at:175: cat stdout" 5971 echo synclines.at:175 >$at_check_line_file 5972 ( $at_traceon; cat stdout ) >$at_stdout 2>$at_stder1 5973 at_status=$? 5974 grep '^ *+' $at_stder1 >&2 5975 grep -v '^ *+' $at_stder1 >$at_stderr 5976 at_failed=false 5977 $at_diff $at_devnull $at_stderr || at_failed=: 5978 echo >>$at_stdout; echo "input.y:8: #error \"8\" 5979 " | $at_diff - $at_stdout || at_failed=: 5980 case $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=:;; 5986 esac 5987 if $at_failed; then 5988 5989 echo 1 > $at_status_file 5990 exit 1 5991 fi 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 6005 Parser 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 6020 cat >input.y <<'_ATEOF' 6021 %union 6022 { 6023 int integer; 6024 char *string ; 6025 } 6026 %% 6027 exp: {}; 6028 _ATEOF 6029 6030 6031 $at_traceoff 6032 echo "headers.at:39: bison --defines input.y" 6033 echo headers.at:39 >$at_check_line_file 6034 ( $at_traceon; bison --defines input.y ) >$at_stdout 2>$at_stder1 6035 at_status=$? 6036 grep '^ *+' $at_stder1 >&2 6037 grep -v '^ *+' $at_stder1 >$at_stderr 6038 at_failed=false 6039 $at_diff $at_devnull $at_stderr || at_failed=: 6040 $at_diff $at_devnull $at_stdout || at_failed=: 6041 case $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=:;; 6047 esac 6048 if $at_failed; then 6049 6050 echo 1 > $at_status_file 6051 exit 1 6052 fi 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. 6074 dirname=`(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 || 6080 echo 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 || 6099 echo 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 6108 echo "$as_me: error: cannot create directory $dirname" >&2;} 6109 { (exit 1); exit 1; }; }; } 6110 6111 6112 cat >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> 6125 void yyerror (const char *); 6126 int yylex (void); 6127 %} 6128 %% 6129 dummy:; 6130 %% 6131 #include <input/input.h> 6132 _ATEOF 6133 6134 6135 6136 $at_traceoff 6137 echo "headers.at:77: bison --defines=input/input.h --output=y.tab.c input/input.y" 6138 echo 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 6140 at_status=$? 6141 grep '^ *+' $at_stder1 >&2 6142 grep -v '^ *+' $at_stder1 >$at_stderr 6143 at_failed=false 6144 $at_diff $at_devnull $at_stderr || at_failed=: 6145 $at_diff $at_devnull $at_stdout || at_failed=: 6146 case $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=:;; 6152 esac 6153 if $at_failed; then 6154 6155 echo 1 > $at_status_file 6156 exit 1 6157 fi 6158 6159 $at_traceon 6160 6161 6162 $at_traceoff 6163 echo "headers.at:77: \$CC \$CFLAGS \$CPPFLAGS -o y.tab.o -I. -c y.tab.c" 6164 echo 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 6166 at_status=$? 6167 grep '^ *+' $at_stder1 >&2 6168 grep -v '^ *+' $at_stder1 >$at_stderr 6169 at_failed=false 6170 echo stderr:; cat $at_stderr 6171 echo stdout:; cat $at_stdout 6172 case $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=:;; 6178 esac 6179 if $at_failed; then 6180 6181 echo 1 > $at_status_file 6182 exit 1 6183 fi 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. 6205 dirname=`(dirname 9foo) 2>/dev/null || 6206 $as_expr X9foo : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 6207 X9foo : 'X\(//\)[^/]' \| \ 6208 X9foo : 'X\(//\)$' \| \ 6209 X9foo : 'X\(/\)' \| \ 6210 . : '\(.\)' 2>/dev/null || 6211 echo 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 || 6230 echo 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 6239 echo "$as_me: error: cannot create directory $dirname" >&2;} 6240 { (exit 1); exit 1; }; }; } 6241 6242 6243 cat >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> 6256 void yyerror (const char *); 6257 int yylex (void); 6258 %} 6259 %% 6260 dummy:; 6261 %% 6262 #include <9foo.h> 6263 _ATEOF 6264 6265 6266 6267 $at_traceoff 6268 echo "headers.at:78: bison --defines=9foo.h --output=y.tab.c 9foo.y" 6269 echo 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 6271 at_status=$? 6272 grep '^ *+' $at_stder1 >&2 6273 grep -v '^ *+' $at_stder1 >$at_stderr 6274 at_failed=false 6275 $at_diff $at_devnull $at_stderr || at_failed=: 6276 $at_diff $at_devnull $at_stdout || at_failed=: 6277 case $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=:;; 6283 esac 6284 if $at_failed; then 6285 6286 echo 1 > $at_status_file 6287 exit 1 6288 fi 6289 6290 $at_traceon 6291 6292 6293 $at_traceoff 6294 echo "headers.at:78: \$CC \$CFLAGS \$CPPFLAGS -o y.tab.o -I. -c y.tab.c" 6295 echo 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 6297 at_status=$? 6298 grep '^ *+' $at_stder1 >&2 6299 grep -v '^ *+' $at_stder1 >$at_stderr 6300 at_failed=false 6301 echo stderr:; cat $at_stderr 6302 echo stdout:; cat $at_stdout 6303 case $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=:;; 6309 esac 6310 if $at_failed; then 6311 6312 echo 1 > $at_status_file 6313 exit 1 6314 fi 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 6335 cat >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 6353 static int 6354 my_lex (void) 6355 { 6356 return EOF; 6357 } 6358 6359 static void 6360 my_error (const char *msg) 6361 { 6362 fprintf (stderr, "%s\n", msg); 6363 } 6364 6365 %} 6366 %% 6367 exp:; 6368 _ATEOF 6369 6370 6371 6372 $at_traceoff 6373 echo "headers.at:114: bison --defines -o input.c input.y" 6374 echo headers.at:114 >$at_check_line_file 6375 ( $at_traceon; bison --defines -o input.c input.y ) >$at_stdout 2>$at_stder1 6376 at_status=$? 6377 grep '^ *+' $at_stder1 >&2 6378 grep -v '^ *+' $at_stder1 >$at_stderr 6379 at_failed=false 6380 $at_diff $at_devnull $at_stderr || at_failed=: 6381 $at_diff $at_devnull $at_stdout || at_failed=: 6382 case $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=:;; 6388 esac 6389 if $at_failed; then 6390 6391 echo 1 > $at_status_file 6392 exit 1 6393 fi 6394 6395 $at_traceon 6396 6397 6398 # YYLTYPE should be defined, and MY_LLOC declared. 6399 cat >caller.c <<'_ATEOF' 6400 #include "input.h" 6401 YYLTYPE *my_llocp = &my_lloc; 6402 6403 int my_parse (void); 6404 6405 int 6406 main (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 6416 echo "headers.at:132: \$CC \$CFLAGS \$CPPFLAGS -o caller.o -c caller.c" 6417 echo headers.at:132 >$at_check_line_file 6418 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -o caller.o -c caller.c ) >$at_stdout 2>$at_stder1 6419 at_status=$? 6420 grep '^ *+' $at_stder1 >&2 6421 grep -v '^ *+' $at_stder1 >$at_stderr 6422 at_failed=false 6423 echo stderr:; cat $at_stderr 6424 echo stdout:; cat $at_stdout 6425 case $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=:;; 6431 esac 6432 if $at_failed; then 6433 6434 echo 1 > $at_status_file 6435 exit 1 6436 fi 6437 6438 $at_traceon 6439 6440 $at_traceoff 6441 echo "headers.at:133: \$CC \$CFLAGS \$CPPFLAGS -o input.o -c input.c" 6442 echo headers.at:133 >$at_check_line_file 6443 ( $at_traceon; $CC $CFLAGS $CPPFLAGS -o input.o -c input.c ) >$at_stdout 2>$at_stder1 6444 at_status=$? 6445 grep '^ *+' $at_stder1 >&2 6446 grep -v '^ *+' $at_stder1 >$at_stderr 6447 at_failed=false 6448 echo stderr:; cat $at_stderr 6449 echo stdout:; cat $at_stdout 6450 case $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=:;; 6456 esac 6457 if $at_failed; then 6458 6459 echo 1 > $at_status_file 6460 exit 1 6461 fi 6462 6463 $at_traceon 6464 6465 $at_traceoff 6466 echo "headers.at:134: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o caller caller.o input.o \$LIBS" 6467 echo 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 6469 at_status=$? 6470 grep '^ *+' $at_stder1 >&2 6471 grep -v '^ *+' $at_stder1 >$at_stderr 6472 at_failed=false 6473 echo stderr:; cat $at_stderr 6474 echo stdout:; cat $at_stdout 6475 case $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=:;; 6481 esac 6482 if $at_failed; then 6483 6484 echo 1 > $at_status_file 6485 exit 1 6486 fi 6487 6488 $at_traceon 6489 6490 $at_traceoff 6491 echo "headers.at:135: \$PREPARSER ./caller" 6492 echo headers.at:135 >$at_check_line_file 6493 ( $at_traceon; $PREPARSER ./caller ) >$at_stdout 2>$at_stder1 6494 at_status=$? 6495 grep '^ *+' $at_stder1 >&2 6496 grep -v '^ *+' $at_stder1 >$at_stderr 6497 at_failed=false 6498 $at_diff $at_devnull $at_stderr || at_failed=: 6499 $at_diff $at_devnull $at_stdout || at_failed=: 6500 case $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=:;; 6506 esac 6507 if $at_failed; then 6508 6509 echo 1 > $at_status_file 6510 exit 1 6511 fi 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 6526 User 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 6546 cat >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 %% 6566 exp: { 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 %% 6579 static int 6580 yylex (void) 6581 { 6582 static const char *input = "123456789"; 6583 return *input++; 6584 } 6585 6586 static void 6587 yyerror (const char *msg) 6588 { 6589 fprintf (stderr, "%s\n", msg); 6590 } 6591 6592 int 6593 main (void) 6594 { 6595 return yyparse (); 6596 } 6597 _ATEOF 6598 6599 6600 6601 $at_traceoff 6602 echo "actions.at:75: bison -d -v -o input.c input.y" 6603 echo actions.at:75 >$at_check_line_file 6604 ( $at_traceon; bison -d -v -o input.c input.y ) >$at_stdout 2>$at_stder1 6605 at_status=$? 6606 grep '^ *+' $at_stder1 >&2 6607 grep -v '^ *+' $at_stder1 >$at_stderr 6608 at_failed=false 6609 $at_diff $at_devnull $at_stderr || at_failed=: 6610 $at_diff $at_devnull $at_stdout || at_failed=: 6611 case $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=:;; 6617 esac 6618 if $at_failed; then 6619 6620 echo 1 > $at_status_file 6621 exit 1 6622 fi 6623 6624 $at_traceon 6625 6626 $at_traceoff 6627 echo "actions.at:76: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS" 6628 echo actions.at:76 >$at_check_line_file 6629 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1 6630 at_status=$? 6631 grep '^ *+' $at_stder1 >&2 6632 grep -v '^ *+' $at_stder1 >$at_stderr 6633 at_failed=false 6634 echo stderr:; cat $at_stderr 6635 echo stdout:; cat $at_stdout 6636 case $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=:;; 6642 esac 6643 if $at_failed; then 6644 6645 echo 1 > $at_status_file 6646 exit 1 6647 fi 6648 6649 $at_traceon 6650 6651 $at_traceoff 6652 echo "actions.at:79: \$PREPARSER ./input" 6653 echo actions.at:79 >$at_check_line_file 6654 ( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1 6655 at_status=$? 6656 grep '^ *+' $at_stder1 >&2 6657 grep -v '^ *+' $at_stder1 >$at_stderr 6658 at_failed=false 6659 $at_diff $at_devnull $at_stderr || at_failed=: 6660 echo >>$at_stdout; echo "0123456789 6661 " | $at_diff - $at_stdout || at_failed=: 6662 case $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=:;; 6668 esac 6669 if $at_failed; then 6670 6671 echo 1 > $at_status_file 6672 exit 1 6673 fi 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 6694 cat >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 %% 6724 exp: 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 ; 6731 a_1: { $$ = 1; }; 6732 a_2: { $$ = 2; }; 6733 a_5: { $$ = 5; }; 6734 6735 sum_of_the_five_previous_values: 6736 { 6737 $$ = $<val>0 + $<val>-1 + $<val>-2 + $<val>-3 + $<val>-4; 6738 } 6739 ; 6740 6741 %% 6742 static int 6743 yylex (void) 6744 { 6745 return EOF; 6746 } 6747 6748 static void 6749 yyerror (const char *msg) 6750 { 6751 fprintf (stderr, "%s\n", msg); 6752 } 6753 6754 int 6755 main (void) 6756 { 6757 return yyparse (); 6758 } 6759 _ATEOF 6760 6761 6762 6763 $at_traceoff 6764 echo "actions.at:150: bison -d -v -o input.c input.y" 6765 echo actions.at:150 >$at_check_line_file 6766 ( $at_traceon; bison -d -v -o input.c input.y ) >$at_stdout 2>$at_stder1 6767 at_status=$? 6768 grep '^ *+' $at_stder1 >&2 6769 grep -v '^ *+' $at_stder1 >$at_stderr 6770 at_failed=false 6771 $at_diff $at_devnull $at_stderr || at_failed=: 6772 $at_diff $at_devnull $at_stdout || at_failed=: 6773 case $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=:;; 6779 esac 6780 if $at_failed; then 6781 6782 echo 1 > $at_status_file 6783 exit 1 6784 fi 6785 6786 $at_traceon 6787 6788 $at_traceoff 6789 echo "actions.at:151: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS" 6790 echo actions.at:151 >$at_check_line_file 6791 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1 6792 at_status=$? 6793 grep '^ *+' $at_stder1 >&2 6794 grep -v '^ *+' $at_stder1 >$at_stderr 6795 at_failed=false 6796 echo stderr:; cat $at_stderr 6797 echo stdout:; cat $at_stdout 6798 case $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=:;; 6804 esac 6805 if $at_failed; then 6806 6807 echo 1 > $at_status_file 6808 exit 1 6809 fi 6810 6811 $at_traceon 6812 6813 $at_traceoff 6814 echo "actions.at:154: \$PREPARSER ./input" 6815 echo actions.at:154 >$at_check_line_file 6816 ( $at_traceon; $PREPARSER ./input ) >$at_stdout 2>$at_stder1 6817 at_status=$? 6818 grep '^ *+' $at_stder1 >&2 6819 grep -v '^ *+' $at_stder1 >$at_stderr 6820 at_failed=false 6821 $at_diff $at_devnull $at_stderr || at_failed=: 6822 echo >>$at_stdout; echo "15 6823 " | $at_diff - $at_stdout || at_failed=: 6824 case $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=:;; 6830 esac 6831 if $at_failed; then 6832 6833 echo 1 > $at_status_file 6834 exit 1 6835 fi 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 6892 cat >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 6923 static int yylex (void); 6924 static 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 6963 input: 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 6978 line: 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 7007 thing: 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]. */ 7017 const char *source = 0; 7018 7019 static int 7020 yylex (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 7038 static void 7039 yyerror (const char *msg) 7040 { 7041 printf ("%d-%d: %s\n", RANGE (yylloc), msg); 7042 } 7043 7044 int 7045 main (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 7065 echo "actions.at:527: bison -o input.c input.y" 7066 echo actions.at:527 >$at_check_line_file 7067 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 7068 at_status=$? 7069 grep '^ *+' $at_stder1 >&2 7070 grep -v '^ *+' $at_stder1 >$at_stderr 7071 at_failed=false 7072 $at_diff $at_devnull $at_stderr || at_failed=: 7073 $at_diff $at_devnull $at_stdout || at_failed=: 7074 case $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=:;; 7080 esac 7081 if $at_failed; then 7082 7083 echo 1 > $at_status_file 7084 exit 1 7085 fi 7086 7087 $at_traceon 7088 7089 $at_traceoff 7090 echo "actions.at:527: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS" 7091 echo actions.at:527 >$at_check_line_file 7092 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1 7093 at_status=$? 7094 grep '^ *+' $at_stder1 >&2 7095 grep -v '^ *+' $at_stder1 >$at_stderr 7096 at_failed=false 7097 echo stderr:; cat $at_stderr 7098 echo stdout:; cat $at_stdout 7099 case $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=:;; 7105 esac 7106 if $at_failed; then 7107 7108 echo 1 > $at_status_file 7109 exit 1 7110 fi 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 7122 echo "actions.at:527: \$PREPARSER ./input '(x)'" 7123 echo actions.at:527 >$at_check_line_file 7124 ( $at_traceon; $PREPARSER ./input '(x)' ) >$at_stdout 2>$at_stder1 7125 at_status=$? 7126 grep '^ *+' $at_stder1 >&2 7127 grep -v '^ *+' $at_stder1 >$at_stderr 7128 at_failed=false 7129 $at_diff $at_devnull $at_stderr || at_failed=: 7130 echo >>$at_stdout; echo "sending: '(' (0@0-9) 7131 sending: 'x' (1@10-19) 7132 thing (1@10-19): 'x' (1@10-19) 7133 sending: ')' (2@20-29) 7134 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29) 7135 sending: EOF (3@30-39) 7136 input (0@29-29): /* Nothing */ 7137 input (2@0-29): line (0@0-29) input (0@29-29) 7138 Freeing nterm input (2@0-29) 7139 Successful parse. 7140 " | $at_diff - $at_stdout || at_failed=: 7141 case $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=:;; 7147 esac 7148 if $at_failed; then 7149 7150 echo 1 > $at_status_file 7151 exit 1 7152 fi 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 7163 echo "actions.at:527: \$PREPARSER ./input '(y)'" 7164 echo actions.at:527 >$at_check_line_file 7165 ( $at_traceon; $PREPARSER ./input '(y)' ) >$at_stdout 2>$at_stder1 7166 at_status=$? 7167 grep '^ *+' $at_stder1 >&2 7168 grep -v '^ *+' $at_stder1 >$at_stderr 7169 at_failed=false 7170 $at_diff $at_devnull $at_stderr || at_failed=: 7171 echo >>$at_stdout; echo "sending: '(' (0@0-9) 7172 sending: 'y' (1@10-19) 7173 10-19: syntax error, unexpected 'y', expecting 'x' 7174 Freeing token 'y' (1@10-19) 7175 sending: ')' (2@20-29) 7176 line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29) 7177 sending: EOF (3@30-39) 7178 input (0@29-29): /* Nothing */ 7179 input (2@0-29): line (-1@0-29) input (0@29-29) 7180 Freeing nterm input (2@0-29) 7181 Successful parse. 7182 " | $at_diff - $at_stdout || at_failed=: 7183 case $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=:;; 7189 esac 7190 if $at_failed; then 7191 7192 echo 1 > $at_status_file 7193 exit 1 7194 fi 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 7215 echo "actions.at:527: \$PREPARSER ./input '(xxxxx)(x)(x)y'" 7216 echo actions.at:527 >$at_check_line_file 7217 ( $at_traceon; $PREPARSER ./input '(xxxxx)(x)(x)y' ) >$at_stdout 2>$at_stder1 7218 at_status=$? 7219 grep '^ *+' $at_stder1 >&2 7220 grep -v '^ *+' $at_stder1 >$at_stderr 7221 at_failed=false 7222 $at_diff $at_devnull $at_stderr || at_failed=: 7223 echo >>$at_stdout; echo "sending: '(' (0@0-9) 7224 sending: 'x' (1@10-19) 7225 thing (1@10-19): 'x' (1@10-19) 7226 sending: 'x' (2@20-29) 7227 thing (2@20-29): 'x' (2@20-29) 7228 sending: 'x' (3@30-39) 7229 30-39: syntax error, unexpected 'x', expecting ')' 7230 Freeing nterm thing (2@20-29) 7231 Freeing nterm thing (1@10-19) 7232 Freeing token 'x' (3@30-39) 7233 sending: 'x' (4@40-49) 7234 Freeing token 'x' (4@40-49) 7235 sending: 'x' (5@50-59) 7236 Freeing token 'x' (5@50-59) 7237 sending: ')' (6@60-69) 7238 line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69) 7239 sending: '(' (7@70-79) 7240 sending: 'x' (8@80-89) 7241 thing (8@80-89): 'x' (8@80-89) 7242 sending: ')' (9@90-99) 7243 line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99) 7244 sending: '(' (10@100-109) 7245 sending: 'x' (11@110-119) 7246 thing (11@110-119): 'x' (11@110-119) 7247 sending: ')' (12@120-129) 7248 line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129) 7249 sending: 'y' (13@130-139) 7250 input (0@129-129): /* Nothing */ 7251 input (2@100-129): line (10@100-129) input (0@129-129) 7252 input (2@70-129): line (7@70-99) input (2@100-129) 7253 input (2@0-129): line (-1@0-69) input (2@70-129) 7254 130-139: syntax error, unexpected 'y', expecting \$end 7255 Freeing nterm input (2@0-129) 7256 Freeing token 'y' (13@130-139) 7257 Parsing FAILED. 7258 " | $at_diff - $at_stdout || at_failed=: 7259 case $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=:;; 7265 esac 7266 if $at_failed; then 7267 7268 echo 1 > $at_status_file 7269 exit 1 7270 fi 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 7281 echo "actions.at:527: \$PREPARSER ./input '(x)(x)(x)(x)(x)(x)(x)'" 7282 echo actions.at:527 >$at_check_line_file 7283 ( $at_traceon; $PREPARSER ./input '(x)(x)(x)(x)(x)(x)(x)' ) >$at_stdout 2>$at_stder1 7284 at_status=$? 7285 grep '^ *+' $at_stder1 >&2 7286 grep -v '^ *+' $at_stder1 >$at_stderr 7287 at_failed=false 7288 $at_diff $at_devnull $at_stderr || at_failed=: 7289 echo >>$at_stdout; echo "sending: '(' (0@0-9) 7290 sending: 'x' (1@10-19) 7291 thing (1@10-19): 'x' (1@10-19) 7292 sending: ')' (2@20-29) 7293 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29) 7294 sending: '(' (3@30-39) 7295 sending: 'x' (4@40-49) 7296 thing (4@40-49): 'x' (4@40-49) 7297 sending: ')' (5@50-59) 7298 line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59) 7299 sending: '(' (6@60-69) 7300 sending: 'x' (7@70-79) 7301 thing (7@70-79): 'x' (7@70-79) 7302 sending: ')' (8@80-89) 7303 line (6@60-89): '(' (6@60-69) thing (7@70-79) ')' (8@80-89) 7304 sending: '(' (9@90-99) 7305 sending: 'x' (10@100-109) 7306 thing (10@100-109): 'x' (10@100-109) 7307 sending: ')' (11@110-119) 7308 line (9@90-119): '(' (9@90-99) thing (10@100-109) ')' (11@110-119) 7309 sending: '(' (12@120-129) 7310 sending: 'x' (13@130-139) 7311 thing (13@130-139): 'x' (13@130-139) 7312 sending: ')' (14@140-149) 7313 line (12@120-149): '(' (12@120-129) thing (13@130-139) ')' (14@140-149) 7314 sending: '(' (15@150-159) 7315 sending: 'x' (16@160-169) 7316 thing (16@160-169): 'x' (16@160-169) 7317 sending: ')' (17@170-179) 7318 line (15@150-179): '(' (15@150-159) thing (16@160-169) ')' (17@170-179) 7319 sending: '(' (18@180-189) 7320 sending: 'x' (19@190-199) 7321 thing (19@190-199): 'x' (19@190-199) 7322 sending: ')' (20@200-209) 7323 200-209: memory exhausted 7324 Freeing nterm thing (19@190-199) 7325 Freeing nterm line (15@150-179) 7326 Freeing nterm line (12@120-149) 7327 Freeing nterm line (9@90-119) 7328 Freeing nterm line (6@60-89) 7329 Freeing nterm line (3@30-59) 7330 Freeing nterm line (0@0-29) 7331 Parsing FAILED (status 2). 7332 " | $at_diff - $at_stdout || at_failed=: 7333 case $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=:;; 7339 esac 7340 if $at_failed; then 7341 7342 echo 1 > $at_status_file 7343 exit 1 7344 fi 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 7404 cat >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 7438 static int yylex (void); 7439 static 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 7478 input: 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 7493 line: 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 7522 thing: 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]. */ 7532 const char *source = 0; 7533 7534 static int 7535 yylex (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 7553 static void 7554 yyerror (const char *msg) 7555 { 7556 printf ("%d-%d: %s\n", RANGE (yylloc), msg); 7557 } 7558 7559 int 7560 main (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 7580 echo "actions.at:528: bison -o input.c input.y" 7581 echo actions.at:528 >$at_check_line_file 7582 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 7583 at_status=$? 7584 grep '^ *+' $at_stder1 >&2 7585 grep -v '^ *+' $at_stder1 >$at_stderr 7586 at_failed=false 7587 $at_diff $at_devnull $at_stderr || at_failed=: 7588 $at_diff $at_devnull $at_stdout || at_failed=: 7589 case $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=:;; 7595 esac 7596 if $at_failed; then 7597 7598 echo 1 > $at_status_file 7599 exit 1 7600 fi 7601 7602 $at_traceon 7603 7604 $at_traceoff 7605 echo "actions.at:528: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS" 7606 echo actions.at:528 >$at_check_line_file 7607 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1 7608 at_status=$? 7609 grep '^ *+' $at_stder1 >&2 7610 grep -v '^ *+' $at_stder1 >$at_stderr 7611 at_failed=false 7612 echo stderr:; cat $at_stderr 7613 echo stdout:; cat $at_stdout 7614 case $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=:;; 7620 esac 7621 if $at_failed; then 7622 7623 echo 1 > $at_status_file 7624 exit 1 7625 fi 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 7637 echo "actions.at:528: \$PREPARSER ./input '(x)'" 7638 echo actions.at:528 >$at_check_line_file 7639 ( $at_traceon; $PREPARSER ./input '(x)' ) >$at_stdout 2>$at_stder1 7640 at_status=$? 7641 grep '^ *+' $at_stder1 >&2 7642 grep -v '^ *+' $at_stder1 >$at_stderr 7643 at_failed=false 7644 $at_diff $at_devnull $at_stderr || at_failed=: 7645 echo >>$at_stdout; echo "sending: '(' (0@0-9) 7646 sending: 'x' (1@10-19) 7647 thing (1@10-19): 'x' (1@10-19) 7648 sending: ')' (2@20-29) 7649 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29) 7650 sending: EOF (3@30-39) 7651 input (0@29-29): /* Nothing */ 7652 input (2@0-29): line (0@0-29) input (0@29-29) 7653 Freeing nterm input (2@0-29) 7654 Successful parse. 7655 " | $at_diff - $at_stdout || at_failed=: 7656 case $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=:;; 7662 esac 7663 if $at_failed; then 7664 7665 echo 1 > $at_status_file 7666 exit 1 7667 fi 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 7678 echo "actions.at:528: \$PREPARSER ./input '(y)'" 7679 echo actions.at:528 >$at_check_line_file 7680 ( $at_traceon; $PREPARSER ./input '(y)' ) >$at_stdout 2>$at_stder1 7681 at_status=$? 7682 grep '^ *+' $at_stder1 >&2 7683 grep -v '^ *+' $at_stder1 >$at_stderr 7684 at_failed=false 7685 $at_diff $at_devnull $at_stderr || at_failed=: 7686 echo >>$at_stdout; echo "sending: '(' (0@0-9) 7687 sending: 'y' (1@10-19) 7688 10-19: syntax error, unexpected 'y', expecting 'x' 7689 Freeing token 'y' (1@10-19) 7690 sending: ')' (2@20-29) 7691 line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29) 7692 sending: EOF (3@30-39) 7693 input (0@29-29): /* Nothing */ 7694 input (2@0-29): line (-1@0-29) input (0@29-29) 7695 Freeing nterm input (2@0-29) 7696 Successful parse. 7697 " | $at_diff - $at_stdout || at_failed=: 7698 case $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=:;; 7704 esac 7705 if $at_failed; then 7706 7707 echo 1 > $at_status_file 7708 exit 1 7709 fi 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 7730 echo "actions.at:528: \$PREPARSER ./input '(xxxxx)(x)(x)y'" 7731 echo actions.at:528 >$at_check_line_file 7732 ( $at_traceon; $PREPARSER ./input '(xxxxx)(x)(x)y' ) >$at_stdout 2>$at_stder1 7733 at_status=$? 7734 grep '^ *+' $at_stder1 >&2 7735 grep -v '^ *+' $at_stder1 >$at_stderr 7736 at_failed=false 7737 $at_diff $at_devnull $at_stderr || at_failed=: 7738 echo >>$at_stdout; echo "sending: '(' (0@0-9) 7739 sending: 'x' (1@10-19) 7740 thing (1@10-19): 'x' (1@10-19) 7741 sending: 'x' (2@20-29) 7742 thing (2@20-29): 'x' (2@20-29) 7743 sending: 'x' (3@30-39) 7744 30-39: syntax error, unexpected 'x', expecting ')' 7745 Freeing nterm thing (2@20-29) 7746 Freeing nterm thing (1@10-19) 7747 Freeing token 'x' (3@30-39) 7748 sending: 'x' (4@40-49) 7749 Freeing token 'x' (4@40-49) 7750 sending: 'x' (5@50-59) 7751 Freeing token 'x' (5@50-59) 7752 sending: ')' (6@60-69) 7753 line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69) 7754 sending: '(' (7@70-79) 7755 sending: 'x' (8@80-89) 7756 thing (8@80-89): 'x' (8@80-89) 7757 sending: ')' (9@90-99) 7758 line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99) 7759 sending: '(' (10@100-109) 7760 sending: 'x' (11@110-119) 7761 thing (11@110-119): 'x' (11@110-119) 7762 sending: ')' (12@120-129) 7763 line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129) 7764 sending: 'y' (13@130-139) 7765 input (0@129-129): /* Nothing */ 7766 input (2@100-129): line (10@100-129) input (0@129-129) 7767 input (2@70-129): line (7@70-99) input (2@100-129) 7768 input (2@0-129): line (-1@0-69) input (2@70-129) 7769 130-139: syntax error, unexpected 'y', expecting \$end 7770 Freeing nterm input (2@0-129) 7771 Freeing token 'y' (13@130-139) 7772 Parsing FAILED. 7773 " | $at_diff - $at_stdout || at_failed=: 7774 case $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=:;; 7780 esac 7781 if $at_failed; then 7782 7783 echo 1 > $at_status_file 7784 exit 1 7785 fi 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 7796 echo "actions.at:528: \$PREPARSER ./input '(x)(x)(x)(x)(x)(x)(x)'" 7797 echo actions.at:528 >$at_check_line_file 7798 ( $at_traceon; $PREPARSER ./input '(x)(x)(x)(x)(x)(x)(x)' ) >$at_stdout 2>$at_stder1 7799 at_status=$? 7800 grep '^ *+' $at_stder1 >&2 7801 grep -v '^ *+' $at_stder1 >$at_stderr 7802 at_failed=false 7803 $at_diff $at_devnull $at_stderr || at_failed=: 7804 echo >>$at_stdout; echo "sending: '(' (0@0-9) 7805 sending: 'x' (1@10-19) 7806 thing (1@10-19): 'x' (1@10-19) 7807 sending: ')' (2@20-29) 7808 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29) 7809 sending: '(' (3@30-39) 7810 sending: 'x' (4@40-49) 7811 thing (4@40-49): 'x' (4@40-49) 7812 sending: ')' (5@50-59) 7813 line (3@30-59): '(' (3@30-39) thing (4@40-49) ')' (5@50-59) 7814 sending: '(' (6@60-69) 7815 sending: 'x' (7@70-79) 7816 thing (7@70-79): 'x' (7@70-79) 7817 sending: ')' (8@80-89) 7818 line (6@60-89): '(' (6@60-69) thing (7@70-79) ')' (8@80-89) 7819 sending: '(' (9@90-99) 7820 sending: 'x' (10@100-109) 7821 thing (10@100-109): 'x' (10@100-109) 7822 sending: ')' (11@110-119) 7823 line (9@90-119): '(' (9@90-99) thing (10@100-109) ')' (11@110-119) 7824 sending: '(' (12@120-129) 7825 sending: 'x' (13@130-139) 7826 thing (13@130-139): 'x' (13@130-139) 7827 sending: ')' (14@140-149) 7828 line (12@120-149): '(' (12@120-129) thing (13@130-139) ')' (14@140-149) 7829 sending: '(' (15@150-159) 7830 sending: 'x' (16@160-169) 7831 thing (16@160-169): 'x' (16@160-169) 7832 sending: ')' (17@170-179) 7833 line (15@150-179): '(' (15@150-159) thing (16@160-169) ')' (17@170-179) 7834 sending: '(' (18@180-189) 7835 sending: 'x' (19@190-199) 7836 thing (19@190-199): 'x' (19@190-199) 7837 sending: ')' (20@200-209) 7838 200-209: memory exhausted 7839 Freeing nterm thing (19@190-199) 7840 Freeing nterm line (15@150-179) 7841 Freeing nterm line (12@120-149) 7842 Freeing nterm line (9@90-119) 7843 Freeing nterm line (6@60-89) 7844 Freeing nterm line (3@30-59) 7845 Freeing nterm line (0@0-29) 7846 Parsing FAILED (status 2). 7847 " | $at_diff - $at_stdout || at_failed=: 7848 case $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=:;; 7854 esac 7855 if $at_failed; then 7856 7857 echo 1 > $at_status_file 7858 exit 1 7859 fi 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 7919 cat >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 %{ 7949 typedef yy::location YYLTYPE; 7950 #define YYSTYPE int 7951 static 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 7991 input: 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 8006 line: 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 8035 thing: 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]. */ 8045 const char *source = 0; 8046 8047 static int 8048 yylex (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. */ 8067 void 8068 yy::parser::error (const location& l, const std::string& m) 8069 { 8070 printf ("%d-%d: %s\n", RANGE (l), m.c_str()); 8071 } 8072 8073 static bool yydebug; 8074 int 8075 yyparse () 8076 { 8077 yy::parser parser; 8078 parser.set_debug_level (yydebug); 8079 return parser.parse (); 8080 } 8081 8082 8083 int 8084 main (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 8104 echo "actions.at:533: bison -o input.cc input.y" 8105 echo actions.at:533 >$at_check_line_file 8106 ( $at_traceon; bison -o input.cc input.y ) >$at_stdout 2>$at_stder1 8107 at_status=$? 8108 grep '^ *+' $at_stder1 >&2 8109 grep -v '^ *+' $at_stder1 >$at_stderr 8110 at_failed=false 8111 $at_diff $at_devnull $at_stderr || at_failed=: 8112 $at_diff $at_devnull $at_stdout || at_failed=: 8113 case $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=:;; 8119 esac 8120 if $at_failed; then 8121 8122 echo 1 > $at_status_file 8123 exit 1 8124 fi 8125 8126 $at_traceon 8127 8128 8129 $at_traceoff 8130 echo "actions.at:533: \$BISON_CXX_WORKS" 8131 echo actions.at:533 >$at_check_line_file 8132 ( $at_traceon; $BISON_CXX_WORKS ) >$at_stdout 2>$at_stder1 8133 at_status=$? 8134 grep '^ *+' $at_stder1 >&2 8135 grep -v '^ *+' $at_stder1 >$at_stderr 8136 at_failed=false 8137 echo stderr:; cat $at_stderr 8138 echo stdout:; cat $at_stdout 8139 case $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=:;; 8145 esac 8146 if $at_failed; then 8147 8148 echo 1 > $at_status_file 8149 exit 1 8150 fi 8151 8152 $at_traceon 8153 8154 $at_traceoff 8155 echo "actions.at:533: \$CXX \$CXXFLAGS \$CPPFLAGS \$LDFLAGS -o input input.cc \$LIBS" 8156 echo actions.at:533 >$at_check_line_file 8157 ( $at_traceon; $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o input input.cc $LIBS ) >$at_stdout 2>$at_stder1 8158 at_status=$? 8159 grep '^ *+' $at_stder1 >&2 8160 grep -v '^ *+' $at_stder1 >$at_stderr 8161 at_failed=false 8162 echo stderr:; cat $at_stderr 8163 echo stdout:; cat $at_stdout 8164 case $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=:;; 8170 esac 8171 if $at_failed; then 8172 8173 echo 1 > $at_status_file 8174 exit 1 8175 fi 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 8187 echo "actions.at:533: \$PREPARSER ./input '(x)'" 8188 echo actions.at:533 >$at_check_line_file 8189 ( $at_traceon; $PREPARSER ./input '(x)' ) >$at_stdout 2>$at_stder1 8190 at_status=$? 8191 grep '^ *+' $at_stder1 >&2 8192 grep -v '^ *+' $at_stder1 >$at_stderr 8193 at_failed=false 8194 $at_diff $at_devnull $at_stderr || at_failed=: 8195 echo >>$at_stdout; echo "sending: '(' (0@0-9) 8196 sending: 'x' (1@10-19) 8197 thing (1@10-19): 'x' (1@10-19) 8198 sending: ')' (2@20-29) 8199 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29) 8200 sending: EOF (3@30-39) 8201 input (0@29-29): /* Nothing */ 8202 input (2@0-29): line (0@0-29) input (0@29-29) 8203 Freeing nterm input (2@0-29) 8204 Successful parse. 8205 " | $at_diff - $at_stdout || at_failed=: 8206 case $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=:;; 8212 esac 8213 if $at_failed; then 8214 8215 echo 1 > $at_status_file 8216 exit 1 8217 fi 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 8228 echo "actions.at:533: \$PREPARSER ./input '(y)'" 8229 echo actions.at:533 >$at_check_line_file 8230 ( $at_traceon; $PREPARSER ./input '(y)' ) >$at_stdout 2>$at_stder1 8231 at_status=$? 8232 grep '^ *+' $at_stder1 >&2 8233 grep -v '^ *+' $at_stder1 >$at_stderr 8234 at_failed=false 8235 $at_diff $at_devnull $at_stderr || at_failed=: 8236 echo >>$at_stdout; echo "sending: '(' (0@0-9) 8237 sending: 'y' (1@10-19) 8238 10-19: syntax error, unexpected 'y', expecting 'x' 8239 Freeing token 'y' (1@10-19) 8240 sending: ')' (2@20-29) 8241 line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29) 8242 sending: EOF (3@30-39) 8243 input (0@29-29): /* Nothing */ 8244 input (2@0-29): line (-1@0-29) input (0@29-29) 8245 Freeing nterm input (2@0-29) 8246 Successful parse. 8247 " | $at_diff - $at_stdout || at_failed=: 8248 case $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=:;; 8254 esac 8255 if $at_failed; then 8256 8257 echo 1 > $at_status_file 8258 exit 1 8259 fi 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 8280 echo "actions.at:533: \$PREPARSER ./input '(xxxxx)(x)(x)y'" 8281 echo actions.at:533 >$at_check_line_file 8282 ( $at_traceon; $PREPARSER ./input '(xxxxx)(x)(x)y' ) >$at_stdout 2>$at_stder1 8283 at_status=$? 8284 grep '^ *+' $at_stder1 >&2 8285 grep -v '^ *+' $at_stder1 >$at_stderr 8286 at_failed=false 8287 $at_diff $at_devnull $at_stderr || at_failed=: 8288 echo >>$at_stdout; echo "sending: '(' (0@0-9) 8289 sending: 'x' (1@10-19) 8290 thing (1@10-19): 'x' (1@10-19) 8291 sending: 'x' (2@20-29) 8292 thing (2@20-29): 'x' (2@20-29) 8293 sending: 'x' (3@30-39) 8294 30-39: syntax error, unexpected 'x', expecting ')' 8295 Freeing nterm thing (2@20-29) 8296 Freeing nterm thing (1@10-19) 8297 Freeing token 'x' (3@30-39) 8298 sending: 'x' (4@40-49) 8299 Freeing token 'x' (4@40-49) 8300 sending: 'x' (5@50-59) 8301 Freeing token 'x' (5@50-59) 8302 sending: ')' (6@60-69) 8303 line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69) 8304 sending: '(' (7@70-79) 8305 sending: 'x' (8@80-89) 8306 thing (8@80-89): 'x' (8@80-89) 8307 sending: ')' (9@90-99) 8308 line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99) 8309 sending: '(' (10@100-109) 8310 sending: 'x' (11@110-119) 8311 thing (11@110-119): 'x' (11@110-119) 8312 sending: ')' (12@120-129) 8313 line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129) 8314 sending: 'y' (13@130-139) 8315 input (0@129-129): /* Nothing */ 8316 input (2@100-129): line (10@100-129) input (0@129-129) 8317 input (2@70-129): line (7@70-99) input (2@100-129) 8318 input (2@0-129): line (-1@0-69) input (2@70-129) 8319 130-139: syntax error, unexpected 'y', expecting \$end 8320 Freeing nterm input (2@0-129) 8321 Freeing token 'y' (13@130-139) 8322 Parsing FAILED. 8323 " | $at_diff - $at_stdout || at_failed=: 8324 case $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=:;; 8330 esac 8331 if $at_failed; then 8332 8333 echo 1 > $at_status_file 8334 exit 1 8335 fi 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 8400 cat >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 %{ 8433 typedef yy::location YYLTYPE; 8434 8435 static 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 8475 input: 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 8490 line: 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 8519 thing: 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]. */ 8529 const char *source = 0; 8530 8531 static int 8532 yylex (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. */ 8551 void 8552 yy::parser::error (const location& l, const std::string& m) 8553 { 8554 printf ("%d-%d: %s\n", RANGE (l), m.c_str()); 8555 } 8556 8557 static bool yydebug; 8558 int 8559 yyparse () 8560 { 8561 yy::parser parser; 8562 parser.set_debug_level (yydebug); 8563 return parser.parse (); 8564 } 8565 8566 8567 int 8568 main (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 8588 echo "actions.at:534: bison -o input.cc input.y" 8589 echo actions.at:534 >$at_check_line_file 8590 ( $at_traceon; bison -o input.cc input.y ) >$at_stdout 2>$at_stder1 8591 at_status=$? 8592 grep '^ *+' $at_stder1 >&2 8593 grep -v '^ *+' $at_stder1 >$at_stderr 8594 at_failed=false 8595 $at_diff $at_devnull $at_stderr || at_failed=: 8596 $at_diff $at_devnull $at_stdout || at_failed=: 8597 case $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=:;; 8603 esac 8604 if $at_failed; then 8605 8606 echo 1 > $at_status_file 8607 exit 1 8608 fi 8609 8610 $at_traceon 8611 8612 8613 $at_traceoff 8614 echo "actions.at:534: \$BISON_CXX_WORKS" 8615 echo actions.at:534 >$at_check_line_file 8616 ( $at_traceon; $BISON_CXX_WORKS ) >$at_stdout 2>$at_stder1 8617 at_status=$? 8618 grep '^ *+' $at_stder1 >&2 8619 grep -v '^ *+' $at_stder1 >$at_stderr 8620 at_failed=false 8621 echo stderr:; cat $at_stderr 8622 echo stdout:; cat $at_stdout 8623 case $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=:;; 8629 esac 8630 if $at_failed; then 8631 8632 echo 1 > $at_status_file 8633 exit 1 8634 fi 8635 8636 $at_traceon 8637 8638 $at_traceoff 8639 echo "actions.at:534: \$CXX \$CXXFLAGS \$CPPFLAGS \$LDFLAGS -o input input.cc \$LIBS" 8640 echo actions.at:534 >$at_check_line_file 8641 ( $at_traceon; $CXX $CXXFLAGS $CPPFLAGS $LDFLAGS -o input input.cc $LIBS ) >$at_stdout 2>$at_stder1 8642 at_status=$? 8643 grep '^ *+' $at_stder1 >&2 8644 grep -v '^ *+' $at_stder1 >$at_stderr 8645 at_failed=false 8646 echo stderr:; cat $at_stderr 8647 echo stdout:; cat $at_stdout 8648 case $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=:;; 8654 esac 8655 if $at_failed; then 8656 8657 echo 1 > $at_status_file 8658 exit 1 8659 fi 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 8671 echo "actions.at:534: \$PREPARSER ./input '(x)'" 8672 echo actions.at:534 >$at_check_line_file 8673 ( $at_traceon; $PREPARSER ./input '(x)' ) >$at_stdout 2>$at_stder1 8674 at_status=$? 8675 grep '^ *+' $at_stder1 >&2 8676 grep -v '^ *+' $at_stder1 >$at_stderr 8677 at_failed=false 8678 $at_diff $at_devnull $at_stderr || at_failed=: 8679 echo >>$at_stdout; echo "sending: '(' (0@0-9) 8680 sending: 'x' (1@10-19) 8681 thing (1@10-19): 'x' (1@10-19) 8682 sending: ')' (2@20-29) 8683 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29) 8684 sending: EOF (3@30-39) 8685 input (0@29-29): /* Nothing */ 8686 input (2@0-29): line (0@0-29) input (0@29-29) 8687 Freeing nterm input (2@0-29) 8688 Successful parse. 8689 " | $at_diff - $at_stdout || at_failed=: 8690 case $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=:;; 8696 esac 8697 if $at_failed; then 8698 8699 echo 1 > $at_status_file 8700 exit 1 8701 fi 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 8712 echo "actions.at:534: \$PREPARSER ./input '(y)'" 8713 echo actions.at:534 >$at_check_line_file 8714 ( $at_traceon; $PREPARSER ./input '(y)' ) >$at_stdout 2>$at_stder1 8715 at_status=$? 8716 grep '^ *+' $at_stder1 >&2 8717 grep -v '^ *+' $at_stder1 >$at_stderr 8718 at_failed=false 8719 $at_diff $at_devnull $at_stderr || at_failed=: 8720 echo >>$at_stdout; echo "sending: '(' (0@0-9) 8721 sending: 'y' (1@10-19) 8722 10-19: syntax error, unexpected 'y', expecting 'x' 8723 Freeing token 'y' (1@10-19) 8724 sending: ')' (2@20-29) 8725 line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29) 8726 sending: EOF (3@30-39) 8727 input (0@29-29): /* Nothing */ 8728 input (2@0-29): line (-1@0-29) input (0@29-29) 8729 Freeing nterm input (2@0-29) 8730 Successful parse. 8731 " | $at_diff - $at_stdout || at_failed=: 8732 case $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=:;; 8738 esac 8739 if $at_failed; then 8740 8741 echo 1 > $at_status_file 8742 exit 1 8743 fi 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 8764 echo "actions.at:534: \$PREPARSER ./input '(xxxxx)(x)(x)y'" 8765 echo actions.at:534 >$at_check_line_file 8766 ( $at_traceon; $PREPARSER ./input '(xxxxx)(x)(x)y' ) >$at_stdout 2>$at_stder1 8767 at_status=$? 8768 grep '^ *+' $at_stder1 >&2 8769 grep -v '^ *+' $at_stder1 >$at_stderr 8770 at_failed=false 8771 $at_diff $at_devnull $at_stderr || at_failed=: 8772 echo >>$at_stdout; echo "sending: '(' (0@0-9) 8773 sending: 'x' (1@10-19) 8774 thing (1@10-19): 'x' (1@10-19) 8775 sending: 'x' (2@20-29) 8776 thing (2@20-29): 'x' (2@20-29) 8777 sending: 'x' (3@30-39) 8778 30-39: syntax error, unexpected 'x', expecting ')' 8779 Freeing nterm thing (2@20-29) 8780 Freeing nterm thing (1@10-19) 8781 Freeing token 'x' (3@30-39) 8782 sending: 'x' (4@40-49) 8783 Freeing token 'x' (4@40-49) 8784 sending: 'x' (5@50-59) 8785 Freeing token 'x' (5@50-59) 8786 sending: ')' (6@60-69) 8787 line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69) 8788 sending: '(' (7@70-79) 8789 sending: 'x' (8@80-89) 8790 thing (8@80-89): 'x' (8@80-89) 8791 sending: ')' (9@90-99) 8792 line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99) 8793 sending: '(' (10@100-109) 8794 sending: 'x' (11@110-119) 8795 thing (11@110-119): 'x' (11@110-119) 8796 sending: ')' (12@120-129) 8797 line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129) 8798 sending: 'y' (13@130-139) 8799 input (0@129-129): /* Nothing */ 8800 input (2@100-129): line (10@100-129) input (0@129-129) 8801 input (2@70-129): line (7@70-99) input (2@100-129) 8802 input (2@0-129): line (-1@0-69) input (2@70-129) 8803 130-139: syntax error, unexpected 'y', expecting \$end 8804 Freeing nterm input (2@0-129) 8805 Freeing token 'y' (13@130-139) 8806 Parsing FAILED. 8807 " | $at_diff - $at_stdout || at_failed=: 8808 case $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=:;; 8814 esac 8815 if $at_failed; then 8816 8817 echo 1 > $at_status_file 8818 exit 1 8819 fi 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 8884 cat >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 8915 static int yylex (void); 8916 static 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 8955 input: 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 8970 line: 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 8999 thing: 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]. */ 9009 const char *source = 0; 9010 9011 static int 9012 yylex (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 9030 static void 9031 yyerror (const char *msg) 9032 { 9033 printf ("%d-%d: %s\n", RANGE (yylloc), msg); 9034 } 9035 9036 int 9037 main (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 9057 echo "actions.at:536: bison -o input.c input.y" 9058 echo actions.at:536 >$at_check_line_file 9059 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 9060 at_status=$? 9061 grep '^ *+' $at_stder1 >&2 9062 grep -v '^ *+' $at_stder1 >$at_stderr 9063 at_failed=false 9064 $at_diff $at_devnull $at_stderr || at_failed=: 9065 $at_diff $at_devnull $at_stdout || at_failed=: 9066 case $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=:;; 9072 esac 9073 if $at_failed; then 9074 9075 echo 1 > $at_status_file 9076 exit 1 9077 fi 9078 9079 $at_traceon 9080 9081 $at_traceoff 9082 echo "actions.at:536: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS" 9083 echo actions.at:536 >$at_check_line_file 9084 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1 9085 at_status=$? 9086 grep '^ *+' $at_stder1 >&2 9087 grep -v '^ *+' $at_stder1 >$at_stderr 9088 at_failed=false 9089 echo stderr:; cat $at_stderr 9090 echo stdout:; cat $at_stdout 9091 case $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=:;; 9097 esac 9098 if $at_failed; then 9099 9100 echo 1 > $at_status_file 9101 exit 1 9102 fi 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 9114 echo "actions.at:536: \$PREPARSER ./input '(x)'" 9115 echo actions.at:536 >$at_check_line_file 9116 ( $at_traceon; $PREPARSER ./input '(x)' ) >$at_stdout 2>$at_stder1 9117 at_status=$? 9118 grep '^ *+' $at_stder1 >&2 9119 grep -v '^ *+' $at_stder1 >$at_stderr 9120 at_failed=false 9121 $at_diff $at_devnull $at_stderr || at_failed=: 9122 echo >>$at_stdout; echo "sending: '(' (0@0-9) 9123 sending: 'x' (1@10-19) 9124 thing (1@10-19): 'x' (1@10-19) 9125 sending: ')' (2@20-29) 9126 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29) 9127 sending: EOF (3@30-39) 9128 input (0@29-29): /* Nothing */ 9129 input (2@0-29): line (0@0-29) input (0@29-29) 9130 Freeing nterm input (2@0-29) 9131 Successful parse. 9132 " | $at_diff - $at_stdout || at_failed=: 9133 case $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=:;; 9139 esac 9140 if $at_failed; then 9141 9142 echo 1 > $at_status_file 9143 exit 1 9144 fi 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 9155 echo "actions.at:536: \$PREPARSER ./input '(y)'" 9156 echo actions.at:536 >$at_check_line_file 9157 ( $at_traceon; $PREPARSER ./input '(y)' ) >$at_stdout 2>$at_stder1 9158 at_status=$? 9159 grep '^ *+' $at_stder1 >&2 9160 grep -v '^ *+' $at_stder1 >$at_stderr 9161 at_failed=false 9162 $at_diff $at_devnull $at_stderr || at_failed=: 9163 echo >>$at_stdout; echo "sending: '(' (0@0-9) 9164 sending: 'y' (1@10-19) 9165 10-19: syntax error, unexpected 'y', expecting 'x' 9166 Freeing token 'y' (1@10-19) 9167 sending: ')' (2@20-29) 9168 line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29) 9169 sending: EOF (3@30-39) 9170 input (0@29-29): /* Nothing */ 9171 input (2@0-29): line (-1@0-29) input (0@29-29) 9172 Freeing nterm input (2@0-29) 9173 Successful parse. 9174 " | $at_diff - $at_stdout || at_failed=: 9175 case $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=:;; 9181 esac 9182 if $at_failed; then 9183 9184 echo 1 > $at_status_file 9185 exit 1 9186 fi 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 9207 echo "actions.at:536: \$PREPARSER ./input '(xxxxx)(x)(x)y'" 9208 echo actions.at:536 >$at_check_line_file 9209 ( $at_traceon; $PREPARSER ./input '(xxxxx)(x)(x)y' ) >$at_stdout 2>$at_stder1 9210 at_status=$? 9211 grep '^ *+' $at_stder1 >&2 9212 grep -v '^ *+' $at_stder1 >$at_stderr 9213 at_failed=false 9214 $at_diff $at_devnull $at_stderr || at_failed=: 9215 echo >>$at_stdout; echo "sending: '(' (0@0-9) 9216 sending: 'x' (1@10-19) 9217 thing (1@10-19): 'x' (1@10-19) 9218 sending: 'x' (2@20-29) 9219 thing (2@20-29): 'x' (2@20-29) 9220 sending: 'x' (3@30-39) 9221 30-39: syntax error, unexpected 'x', expecting ')' 9222 Freeing nterm thing (2@20-29) 9223 Freeing nterm thing (1@10-19) 9224 Freeing token 'x' (3@30-39) 9225 sending: 'x' (4@40-49) 9226 Freeing token 'x' (4@40-49) 9227 sending: 'x' (5@50-59) 9228 Freeing token 'x' (5@50-59) 9229 sending: ')' (6@60-69) 9230 line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69) 9231 sending: '(' (7@70-79) 9232 sending: 'x' (8@80-89) 9233 thing (8@80-89): 'x' (8@80-89) 9234 sending: ')' (9@90-99) 9235 line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99) 9236 sending: '(' (10@100-109) 9237 sending: 'x' (11@110-119) 9238 thing (11@110-119): 'x' (11@110-119) 9239 sending: ')' (12@120-129) 9240 line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129) 9241 sending: 'y' (13@130-139) 9242 input (0@129-129): /* Nothing */ 9243 input (2@100-129): line (10@100-129) input (0@129-129) 9244 input (2@70-129): line (7@70-99) input (2@100-129) 9245 input (2@0-129): line (-1@0-69) input (2@70-129) 9246 130-139: syntax error, unexpected 'y', expecting \$end 9247 Freeing nterm input (2@0-129) 9248 Freeing token 'y' (13@130-139) 9249 Parsing FAILED. 9250 " | $at_diff - $at_stdout || at_failed=: 9251 case $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=:;; 9257 esac 9258 if $at_failed; then 9259 9260 echo 1 > $at_status_file 9261 exit 1 9262 fi 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 9327 cat >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 9361 static int yylex (void); 9362 static 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 9401 input: 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 9416 line: 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 9445 thing: 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]. */ 9455 const char *source = 0; 9456 9457 static int 9458 yylex (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 9476 static void 9477 yyerror (const char *msg) 9478 { 9479 printf ("%d-%d: %s\n", RANGE (yylloc), msg); 9480 } 9481 9482 int 9483 main (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 9503 echo "actions.at:537: bison -o input.c input.y" 9504 echo actions.at:537 >$at_check_line_file 9505 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 9506 at_status=$? 9507 grep '^ *+' $at_stder1 >&2 9508 grep -v '^ *+' $at_stder1 >$at_stderr 9509 at_failed=false 9510 $at_diff $at_devnull $at_stderr || at_failed=: 9511 $at_diff $at_devnull $at_stdout || at_failed=: 9512 case $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=:;; 9518 esac 9519 if $at_failed; then 9520 9521 echo 1 > $at_status_file 9522 exit 1 9523 fi 9524 9525 $at_traceon 9526 9527 $at_traceoff 9528 echo "actions.at:537: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS" 9529 echo actions.at:537 >$at_check_line_file 9530 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1 9531 at_status=$? 9532 grep '^ *+' $at_stder1 >&2 9533 grep -v '^ *+' $at_stder1 >$at_stderr 9534 at_failed=false 9535 echo stderr:; cat $at_stderr 9536 echo stdout:; cat $at_stdout 9537 case $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=:;; 9543 esac 9544 if $at_failed; then 9545 9546 echo 1 > $at_status_file 9547 exit 1 9548 fi 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 9560 echo "actions.at:537: \$PREPARSER ./input '(x)'" 9561 echo actions.at:537 >$at_check_line_file 9562 ( $at_traceon; $PREPARSER ./input '(x)' ) >$at_stdout 2>$at_stder1 9563 at_status=$? 9564 grep '^ *+' $at_stder1 >&2 9565 grep -v '^ *+' $at_stder1 >$at_stderr 9566 at_failed=false 9567 $at_diff $at_devnull $at_stderr || at_failed=: 9568 echo >>$at_stdout; echo "sending: '(' (0@0-9) 9569 sending: 'x' (1@10-19) 9570 thing (1@10-19): 'x' (1@10-19) 9571 sending: ')' (2@20-29) 9572 line (0@0-29): '(' (0@0-9) thing (1@10-19) ')' (2@20-29) 9573 sending: EOF (3@30-39) 9574 input (0@29-29): /* Nothing */ 9575 input (2@0-29): line (0@0-29) input (0@29-29) 9576 Freeing nterm input (2@0-29) 9577 Successful parse. 9578 " | $at_diff - $at_stdout || at_failed=: 9579 case $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=:;; 9585 esac 9586 if $at_failed; then 9587 9588 echo 1 > $at_status_file 9589 exit 1 9590 fi 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 9601 echo "actions.at:537: \$PREPARSER ./input '(y)'" 9602 echo actions.at:537 >$at_check_line_file 9603 ( $at_traceon; $PREPARSER ./input '(y)' ) >$at_stdout 2>$at_stder1 9604 at_status=$? 9605 grep '^ *+' $at_stder1 >&2 9606 grep -v '^ *+' $at_stder1 >$at_stderr 9607 at_failed=false 9608 $at_diff $at_devnull $at_stderr || at_failed=: 9609 echo >>$at_stdout; echo "sending: '(' (0@0-9) 9610 sending: 'y' (1@10-19) 9611 10-19: syntax error, unexpected 'y', expecting 'x' 9612 Freeing token 'y' (1@10-19) 9613 sending: ')' (2@20-29) 9614 line (-1@0-29): '(' (0@0-9) error (@10-19) ')' (2@20-29) 9615 sending: EOF (3@30-39) 9616 input (0@29-29): /* Nothing */ 9617 input (2@0-29): line (-1@0-29) input (0@29-29) 9618 Freeing nterm input (2@0-29) 9619 Successful parse. 9620 " | $at_diff - $at_stdout || at_failed=: 9621 case $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=:;; 9627 esac 9628 if $at_failed; then 9629 9630 echo 1 > $at_status_file 9631 exit 1 9632 fi 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 9653 echo "actions.at:537: \$PREPARSER ./input '(xxxxx)(x)(x)y'" 9654 echo actions.at:537 >$at_check_line_file 9655 ( $at_traceon; $PREPARSER ./input '(xxxxx)(x)(x)y' ) >$at_stdout 2>$at_stder1 9656 at_status=$? 9657 grep '^ *+' $at_stder1 >&2 9658 grep -v '^ *+' $at_stder1 >$at_stderr 9659 at_failed=false 9660 $at_diff $at_devnull $at_stderr || at_failed=: 9661 echo >>$at_stdout; echo "sending: '(' (0@0-9) 9662 sending: 'x' (1@10-19) 9663 thing (1@10-19): 'x' (1@10-19) 9664 sending: 'x' (2@20-29) 9665 thing (2@20-29): 'x' (2@20-29) 9666 sending: 'x' (3@30-39) 9667 30-39: syntax error, unexpected 'x', expecting ')' 9668 Freeing nterm thing (2@20-29) 9669 Freeing nterm thing (1@10-19) 9670 Freeing token 'x' (3@30-39) 9671 sending: 'x' (4@40-49) 9672 Freeing token 'x' (4@40-49) 9673 sending: 'x' (5@50-59) 9674 Freeing token 'x' (5@50-59) 9675 sending: ')' (6@60-69) 9676 line (-1@0-69): '(' (0@0-9) error (@10-59) ')' (6@60-69) 9677 sending: '(' (7@70-79) 9678 sending: 'x' (8@80-89) 9679 thing (8@80-89): 'x' (8@80-89) 9680 sending: ')' (9@90-99) 9681 line (7@70-99): '(' (7@70-79) thing (8@80-89) ')' (9@90-99) 9682 sending: '(' (10@100-109) 9683 sending: 'x' (11@110-119) 9684 thing (11@110-119): 'x' (11@110-119) 9685 sending: ')' (12@120-129) 9686 line (10@100-129): '(' (10@100-109) thing (11@110-119) ')' (12@120-129) 9687 sending: 'y' (13@130-139) 9688 input (0@129-129): /* Nothing */ 9689 input (2@100-129): line (10@100-129) input (0@129-129) 9690 input (2@70-129): line (7@70-99) input (2@100-129) 9691 input (2@0-129): line (-1@0-69) input (2@70-129) 9692 130-139: syntax error, unexpected 'y', expecting \$end 9693 Freeing nterm input (2@0-129) 9694 Freeing token 'y' (13@130-139) 9695 Parsing FAILED. 9696 " | $at_diff - $at_stdout || at_failed=: 9697 case $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=:;; 9703 esac 9704 if $at_failed; then 9705 9706 echo 1 > $at_status_file 9707 exit 1 9708 fi 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 9731 Conflicts. 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 9746 cat >input.y <<'_ATEOF' 9747 %expect 1 9748 %% 9749 exp: e 'e'; 9750 e: 'e' | /* Nothing. */; 9751 _ATEOF 9752 9753 9754 $at_traceoff 9755 echo "conflicts.at:43: bison -o input.c input.y" 9756 echo conflicts.at:43 >$at_check_line_file 9757 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 9758 at_status=$? 9759 grep '^ *+' $at_stder1 >&2 9760 grep -v '^ *+' $at_stder1 >$at_stderr 9761 at_failed=false 9762 echo >>$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=: 9765 case $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=:;; 9771 esac 9772 if $at_failed; then 9773 9774 echo 1 > $at_status_file 9775 exit 1 9776 fi 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 9797 cat >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 9814 static void 9815 yyerror (const char *msg) 9816 { 9817 fprintf (stderr, "%s\n", msg); 9818 } 9819 9820 /* The current argument. */ 9821 static const char *input = NULL; 9822 9823 static int 9824 yylex (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 %% 9838 expr: expr '<' expr 9839 | expr '>' expr 9840 | '0' 9841 ; 9842 %% 9843 int 9844 main (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 9856 echo "conflicts.at:100: bison -o input.c input.y" 9857 echo conflicts.at:100 >$at_check_line_file 9858 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 9859 at_status=$? 9860 grep '^ *+' $at_stder1 >&2 9861 grep -v '^ *+' $at_stder1 >$at_stderr 9862 at_failed=false 9863 $at_diff $at_devnull $at_stderr || at_failed=: 9864 $at_diff $at_devnull $at_stdout || at_failed=: 9865 case $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=:;; 9871 esac 9872 if $at_failed; then 9873 9874 echo 1 > $at_status_file 9875 exit 1 9876 fi 9877 9878 $at_traceon 9879 9880 $at_traceoff 9881 echo "conflicts.at:101: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o input input.c \$LIBS" 9882 echo conflicts.at:101 >$at_check_line_file 9883 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o input input.c $LIBS ) >$at_stdout 2>$at_stder1 9884 at_status=$? 9885 grep '^ *+' $at_stder1 >&2 9886 grep -v '^ *+' $at_stder1 >$at_stderr 9887 at_failed=false 9888 echo stderr:; cat $at_stderr 9889 echo stdout:; cat $at_stdout 9890 case $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=:;; 9896 esac 9897 if $at_failed; then 9898 9899 echo 1 > $at_status_file 9900 exit 1 9901 fi 9902 9903 $at_traceon 9904 9905 9906 $at_traceoff 9907 echo "conflicts.at:103: \$PREPARSER ./input '0<0'" 9908 echo conflicts.at:103 >$at_check_line_file 9909 ( $at_traceon; $PREPARSER ./input '0<0' ) >$at_stdout 2>$at_stder1 9910 at_status=$? 9911 grep '^ *+' $at_stder1 >&2 9912 grep -v '^ *+' $at_stder1 >$at_stderr 9913 at_failed=false 9914 $at_diff $at_devnull $at_stderr || at_failed=: 9915 $at_diff $at_devnull $at_stdout || at_failed=: 9916 case $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=:;; 9922 esac 9923 if $at_failed; then 9924 9925 echo 1 > $at_status_file 9926 exit 1 9927 fi 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 9935 echo "conflicts.at:109: \$PREPARSER ./input '0<0<0'" 9936 echo conflicts.at:109 >$at_check_line_file 9937 ( $at_traceon; $PREPARSER ./input '0<0<0' ) >$at_stdout 2>$at_stder1 9938 at_status=$? 9939 grep '^ *+' $at_stder1 >&2 9940 grep -v '^ *+' $at_stder1 >$at_stderr 9941 at_failed=false 9942 echo >>$at_stderr; echo "syntax error, unexpected '<', expecting '<' or '>' 9943 " | $at_diff - $at_stderr || at_failed=: 9944 $at_diff $at_devnull $at_stdout || at_failed=: 9945 case $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=:;; 9951 esac 9952 if $at_failed; then 9953 9954 echo 1 > $at_status_file 9955 exit 1 9956 fi 9957 9958 $at_traceon 9959 9960 9961 $at_traceoff 9962 echo "conflicts.at:111: \$PREPARSER ./input '0>0'" 9963 echo conflicts.at:111 >$at_check_line_file 9964 ( $at_traceon; $PREPARSER ./input '0>0' ) >$at_stdout 2>$at_stder1 9965 at_status=$? 9966 grep '^ *+' $at_stder1 >&2 9967 grep -v '^ *+' $at_stder1 >$at_stderr 9968 at_failed=false 9969 $at_diff $at_devnull $at_stderr || at_failed=: 9970 $at_diff $at_devnull $at_stdout || at_failed=: 9971 case $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=:;; 9977 esac 9978 if $at_failed; then 9979 9980 echo 1 > $at_status_file 9981 exit 1 9982 fi 9983 9984 $at_traceon 9985 9986 $at_traceoff 9987 echo "conflicts.at:114: \$PREPARSER ./input '0>0>0'" 9988 echo conflicts.at:114 >$at_check_line_file 9989 ( $at_traceon; $PREPARSER ./input '0>0>0' ) >$at_stdout 2>$at_stder1 9990 at_status=$? 9991 grep '^ *+' $at_stder1 >&2 9992 grep -v '^ *+' $at_stder1 >$at_stderr 9993 at_failed=false 9994 echo >>$at_stderr; echo "syntax error, unexpected '>', expecting '<' or '>' 9995 " | $at_diff - $at_stderr || at_failed=: 9996 $at_diff $at_devnull $at_stdout || at_failed=: 9997 case $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=:;; 10003 esac 10004 if $at_failed; then 10005 10006 echo 1 > $at_status_file 10007 exit 1 10008 fi 10009 10010 $at_traceon 10011 10012 10013 $at_traceoff 10014 echo "conflicts.at:118: \$PREPARSER ./input '0<0>0'" 10015 echo conflicts.at:118 >$at_check_line_file 10016 ( $at_traceon; $PREPARSER ./input '0<0>0' ) >$at_stdout 2>$at_stder1 10017 at_status=$? 10018 grep '^ *+' $at_stder1 >&2 10019 grep -v '^ *+' $at_stder1 >$at_stderr 10020 at_failed=false 10021 echo >>$at_stderr; echo "syntax error, unexpected '>', expecting '<' or '>' 10022 " | $at_diff - $at_stderr || at_failed=: 10023 $at_diff $at_devnull $at_stdout || at_failed=: 10024 case $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=:;; 10030 esac 10031 if $at_failed; then 10032 10033 echo 1 > $at_status_file 10034 exit 1 10035 fi 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 10058 cat >input.y <<'_ATEOF' 10059 %token NUM OP 10060 %% 10061 exp: exp OP exp | NUM; 10062 _ATEOF 10063 10064 10065 $at_traceoff 10066 echo "conflicts.at:140: bison -o input.c --report=all input.y" 10067 echo conflicts.at:140 >$at_check_line_file 10068 ( $at_traceon; bison -o input.c --report=all input.y ) >$at_stdout 2>$at_stder1 10069 at_status=$? 10070 grep '^ *+' $at_stder1 >&2 10071 grep -v '^ *+' $at_stder1 >$at_stderr 10072 at_failed=false 10073 echo >>$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=: 10076 case $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=:;; 10082 esac 10083 if $at_failed; then 10084 10085 echo 1 > $at_status_file 10086 exit 1 10087 fi 10088 10089 $at_traceon 10090 10091 10092 # Check the contents of the report. 10093 $at_traceoff 10094 echo "conflicts.at:225: cat input.output" 10095 echo conflicts.at:225 >$at_check_line_file 10096 ( $at_traceon; cat input.output ) >$at_stdout 2>$at_stder1 10097 at_status=$? 10098 grep '^ *+' $at_stder1 >&2 10099 grep -v '^ *+' $at_stder1 >$at_stderr 10100 at_failed=false 10101 $at_diff $at_devnull $at_stderr || at_failed=: 10102 echo >>$at_stdout; echo "State 5 conflicts: 1 shift/reduce 10103 10104 10105 Grammar 10106 10107 0 \$accept: exp \$end 10108 10109 1 exp: exp OP exp 10110 2 | NUM 10111 10112 10113 Terminals, with rules where they appear 10114 10115 \$end (0) 0 10116 error (256) 10117 NUM (258) 2 10118 OP (259) 1 10119 10120 10121 Nonterminals, with rules where they appear 10122 10123 \$accept (5) 10124 on left: 0 10125 exp (6) 10126 on left: 1 2, on right: 0 1 10127 10128 10129 state 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 10140 state 1 10141 10142 2 exp: NUM . 10143 10144 \$default reduce using rule 2 (exp) 10145 10146 10147 state 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 10156 state 3 10157 10158 0 \$accept: exp \$end . 10159 10160 \$default accept 10161 10162 10163 state 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 10174 state 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=: 10184 case $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=:;; 10190 esac 10191 if $at_failed; then 10192 10193 echo 1 > $at_status_file 10194 exit 1 10195 fi 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 10218 cat >input.y <<'_ATEOF' 10219 %token NUM OP 10220 %left OP 10221 %% 10222 exp: exp OP exp | NUM; 10223 _ATEOF 10224 10225 10226 $at_traceoff 10227 echo "conflicts.at:246: bison -o input.c --report=all input.y" 10228 echo conflicts.at:246 >$at_check_line_file 10229 ( $at_traceon; bison -o input.c --report=all input.y ) >$at_stdout 2>$at_stder1 10230 at_status=$? 10231 grep '^ *+' $at_stder1 >&2 10232 grep -v '^ *+' $at_stder1 >$at_stderr 10233 at_failed=false 10234 $at_diff $at_devnull $at_stderr || at_failed=: 10235 $at_diff $at_devnull $at_stdout || at_failed=: 10236 case $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=:;; 10242 esac 10243 if $at_failed; then 10244 10245 echo 1 > $at_status_file 10246 exit 1 10247 fi 10248 10249 $at_traceon 10250 10251 10252 # Check the contents of the report. 10253 $at_traceoff 10254 echo "conflicts.at:327: cat input.output" 10255 echo conflicts.at:327 >$at_check_line_file 10256 ( $at_traceon; cat input.output ) >$at_stdout 2>$at_stder1 10257 at_status=$? 10258 grep '^ *+' $at_stder1 >&2 10259 grep -v '^ *+' $at_stder1 >$at_stderr 10260 at_failed=false 10261 $at_diff $at_devnull $at_stderr || at_failed=: 10262 echo >>$at_stdout; echo "Grammar 10263 10264 0 \$accept: exp \$end 10265 10266 1 exp: exp OP exp 10267 2 | NUM 10268 10269 10270 Terminals, with rules where they appear 10271 10272 \$end (0) 0 10273 error (256) 10274 NUM (258) 2 10275 OP (259) 1 10276 10277 10278 Nonterminals, with rules where they appear 10279 10280 \$accept (5) 10281 on left: 0 10282 exp (6) 10283 on left: 1 2, on right: 0 1 10284 10285 10286 state 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 10297 state 1 10298 10299 2 exp: NUM . 10300 10301 \$default reduce using rule 2 (exp) 10302 10303 10304 state 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 10313 state 3 10314 10315 0 \$accept: exp \$end . 10316 10317 \$default accept 10318 10319 10320 state 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 10331 state 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=: 10340 case $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=:;; 10346 esac 10347 if $at_failed; then 10348 10349 echo 1 > $at_status_file 10350 exit 1 10351 fi 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 10373 cat >input.y <<'_ATEOF' 10374 %% 10375 exp: num | id; 10376 num: '0'; 10377 id : '0'; 10378 %% 10379 _ATEOF 10380 10381 10382 $at_traceoff 10383 echo "conflicts.at:371: bison -o input.c --report=all input.y" 10384 echo conflicts.at:371 >$at_check_line_file 10385 ( $at_traceon; bison -o input.c --report=all input.y ) >$at_stdout 2>$at_stder1 10386 at_status=$? 10387 grep '^ *+' $at_stder1 >&2 10388 grep -v '^ *+' $at_stder1 >$at_stderr 10389 at_failed=false 10390 echo >>$at_stderr; echo "input.y: conflicts: 1 reduce/reduce 10391 input.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=: 10394 case $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=:;; 10400 esac 10401 if $at_failed; then 10402 10403 echo 1 > $at_status_file 10404 exit 1 10405 fi 10406 10407 $at_traceon 10408 10409 10410 # Check the contents of the report. 10411 $at_traceoff 10412 echo "conflicts.at:465: cat input.output" 10413 echo conflicts.at:465 >$at_check_line_file 10414 ( $at_traceon; cat input.output ) >$at_stdout 2>$at_stder1 10415 at_status=$? 10416 grep '^ *+' $at_stder1 >&2 10417 grep -v '^ *+' $at_stder1 >$at_stderr 10418 at_failed=false 10419 $at_diff $at_devnull $at_stderr || at_failed=: 10420 echo >>$at_stdout; echo "Rules never reduced 10421 10422 4 id: '0' 10423 10424 10425 State 1 conflicts: 1 reduce/reduce 10426 10427 10428 Grammar 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 10440 Terminals, with rules where they appear 10441 10442 \$end (0) 0 10443 '0' (48) 3 4 10444 error (256) 10445 10446 10447 Nonterminals, with rules where they appear 10448 10449 \$accept (4) 10450 on left: 0 10451 exp (5) 10452 on left: 1 2, on right: 0 10453 num (6) 10454 on left: 3, on right: 1 10455 id (7) 10456 on left: 4, on right: 2 10457 10458 10459 state 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 10474 state 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 10484 state 2 10485 10486 0 \$accept: exp . \$end 10487 10488 \$end shift, and go to state 5 10489 10490 10491 state 3 10492 10493 1 exp: num . 10494 10495 \$default reduce using rule 1 (exp) 10496 10497 10498 state 4 10499 10500 2 exp: id . 10501 10502 \$default reduce using rule 2 (exp) 10503 10504 10505 state 5 10506 10507 0 \$accept: exp \$end . 10508 10509 \$default accept 10510 " | $at_diff - $at_stdout || at_failed=: 10511 case $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=:;; 10517 esac 10518 if $at_failed; then 10519 10520 echo 1 > $at_status_file 10521 exit 1 10522 fi 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 10543 cat >input.y <<'_ATEOF' 10544 %token NUM OP 10545 %expect 0 10546 %% 10547 exp: exp OP exp | NUM; 10548 _ATEOF 10549 10550 10551 $at_traceoff 10552 echo "conflicts.at:488: bison -o input.c input.y" 10553 echo conflicts.at:488 >$at_check_line_file 10554 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 10555 at_status=$? 10556 grep '^ *+' $at_stder1 >&2 10557 grep -v '^ *+' $at_stder1 >$at_stderr 10558 at_failed=false 10559 echo >>$at_stderr; echo "input.y: conflicts: 1 shift/reduce 10560 input.y: expected 0 shift/reduce conflicts 10561 " | $at_diff - $at_stderr || at_failed=: 10562 $at_diff $at_devnull $at_stdout || at_failed=: 10563 case $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=:;; 10569 esac 10570 if $at_failed; then 10571 10572 echo 1 > $at_status_file 10573 exit 1 10574 fi 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 10594 cat >input.y <<'_ATEOF' 10595 %token NUM OP 10596 %expect 1 10597 %% 10598 exp: exp OP exp | NUM; 10599 _ATEOF 10600 10601 10602 $at_traceoff 10603 echo "conflicts.at:505: bison -o input.c input.y" 10604 echo conflicts.at:505 >$at_check_line_file 10605 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 10606 at_status=$? 10607 grep '^ *+' $at_stder1 >&2 10608 grep -v '^ *+' $at_stder1 >$at_stderr 10609 at_failed=false 10610 $at_diff $at_devnull $at_stderr || at_failed=: 10611 $at_diff $at_devnull $at_stdout || at_failed=: 10612 case $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=:;; 10618 esac 10619 if $at_failed; then 10620 10621 echo 1 > $at_status_file 10622 exit 1 10623 fi 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 10643 cat >input.y <<'_ATEOF' 10644 %token NUM OP 10645 %expect 2 10646 %% 10647 exp: exp OP exp | NUM; 10648 _ATEOF 10649 10650 10651 $at_traceoff 10652 echo "conflicts.at:525: bison -o input.c input.y" 10653 echo conflicts.at:525 >$at_check_line_file 10654 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 10655 at_status=$? 10656 grep '^ *+' $at_stder1 >&2 10657 grep -v '^ *+' $at_stder1 >$at_stderr 10658 at_failed=false 10659 echo >>$at_stderr; echo "input.y: conflicts: 1 shift/reduce 10660 input.y: expected 2 shift/reduce conflicts 10661 " | $at_diff - $at_stderr || at_failed=: 10662 $at_diff $at_devnull $at_stdout || at_failed=: 10663 case $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=:;; 10669 esac 10670 if $at_failed; then 10671 10672 echo 1 > $at_status_file 10673 exit 1 10674 fi 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 10694 cat >input.y <<'_ATEOF' 10695 %expect 0 10696 %% 10697 program: a 'a' | a a; 10698 a: 'a'; 10699 _ATEOF 10700 10701 10702 $at_traceoff 10703 echo "conflicts.at:545: bison -o input.c input.y" 10704 echo conflicts.at:545 >$at_check_line_file 10705 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 10706 at_status=$? 10707 grep '^ *+' $at_stder1 >&2 10708 grep -v '^ *+' $at_stder1 >$at_stderr 10709 at_failed=false 10710 echo >>$at_stderr; echo "input.y: conflicts: 1 reduce/reduce 10711 input.y: expected 0 reduce/reduce conflicts 10712 " | $at_diff - $at_stderr || at_failed=: 10713 $at_diff $at_devnull $at_stdout || at_failed=: 10714 case $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=:;; 10720 esac 10721 if $at_failed; then 10722 10723 echo 1 > $at_status_file 10724 exit 1 10725 fi 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 10745 cat >input.y <<'_ATEOF' 10746 %left '+' 10747 %left '*' 10748 10749 %% 10750 10751 %no-default-prec; 10752 10753 e: e '+' e 10754 | e '*' e 10755 | '0' 10756 ; 10757 _ATEOF 10758 10759 10760 $at_traceoff 10761 echo "conflicts.at:571: bison -o input.c input.y" 10762 echo conflicts.at:571 >$at_check_line_file 10763 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 10764 at_status=$? 10765 grep '^ *+' $at_stder1 >&2 10766 grep -v '^ *+' $at_stder1 >$at_stderr 10767 at_failed=false 10768 echo >>$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=: 10771 case $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=:;; 10777 esac 10778 if $at_failed; then 10779 10780 echo 1 > $at_status_file 10781 exit 1 10782 fi 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 10802 cat >input.y <<'_ATEOF' 10803 %left '+' 10804 %left '*' 10805 10806 %% 10807 10808 %no-default-prec; 10809 10810 e: e '+' e %prec '+' 10811 | e '*' e %prec '*' 10812 | '0' 10813 ; 10814 _ATEOF 10815 10816 10817 $at_traceoff 10818 echo "conflicts.at:595: bison -o input.c input.y" 10819 echo conflicts.at:595 >$at_check_line_file 10820 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 10821 at_status=$? 10822 grep '^ *+' $at_stder1 >&2 10823 grep -v '^ *+' $at_stder1 >$at_stderr 10824 at_failed=false 10825 $at_diff $at_devnull $at_stderr || at_failed=: 10826 $at_diff $at_devnull $at_stdout || at_failed=: 10827 case $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=:;; 10833 esac 10834 if $at_failed; then 10835 10836 echo 1 > $at_status_file 10837 exit 1 10838 fi 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 10858 cat >input.y <<'_ATEOF' 10859 %left '+' 10860 %left '*' 10861 10862 %% 10863 10864 %default-prec; 10865 10866 e: e '+' e 10867 | e '*' e 10868 | '0' 10869 ; 10870 _ATEOF 10871 10872 10873 $at_traceoff 10874 echo "conflicts.at:619: bison -o input.c input.y" 10875 echo conflicts.at:619 >$at_check_line_file 10876 ( $at_traceon; bison -o input.c input.y ) >$at_stdout 2>$at_stder1 10877 at_status=$? 10878 grep '^ *+' $at_stder1 >&2 10879 grep -v '^ *+' $at_stder1 >$at_stderr 10880 at_failed=false 10881 $at_diff $at_devnull $at_stderr || at_failed=: 10882 $at_diff $at_devnull $at_stdout || at_failed=: 10883 case $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=:;; 10889 esac 10890 if $at_failed; then 10891 10892 echo 1 > $at_status_file 10893 exit 1 10894 fi 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 10908 Simple 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 10957 cat >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. */ 10986 typedef int semantic_value; 10987 10988 static semantic_value global_result = 0; 10989 static int global_count = 0; 10990 %} 10991 10992 /* Exercise %union. */ 10993 %union 10994 { 10995 semantic_value ival; 10996 }; 10997 10998 %{ 10999 static int power (int base, int exponent); 11000 /* yyerror receives the location if: 11001 - %location & %pure & %glr 11002 - %location & %pure & %yacc & %parse-param. */ 11003 static void yyerror ( 11004 11005 const char *s 11006 ); 11007 static int yylex (void); 11008 static int get_char (void); 11009 static 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 %% 11027 input: 11028 line 11029 | input line { } 11030 ; 11031 11032 line: 11033 '\n' 11034 | exp '\n' { USE ($1); } 11035 ; 11036 11037 exp: 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. */ 11058 static FILE *input; 11059 11060 static void 11061 yyerror ( 11062 11063 const char *s) 11064 { 11065 11066 11067 fprintf (stderr, "%s\n", s); 11068 } 11069 11070 11071 11072 static int 11073 get_char (void) 11074 { 11075 int res = getc (input); 11076 ; 11077 11078 return res; 11079 } 11080 11081 11082 static void 11083 unget_char ( int c) 11084 { 11085 ; 11086 11087 ungetc (c, input); 11088 } 11089 11090 static int 11091 read_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 11123 static int 11124 yylex (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 11159 static int 11160 power (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 11171 int 11172 main (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 11209 echo "calc.at:550: bison -o calc.c calc.y" 11210 echo calc.at:550 >$at_check_line_file 11211 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 11212 at_status=$? 11213 grep '^ *+' $at_stder1 >&2 11214 grep -v '^ *+' $at_stder1 >$at_stderr 11215 at_failed=false 11216 $at_diff $at_devnull $at_stderr || at_failed=: 11217 $at_diff $at_devnull $at_stdout || at_failed=: 11218 case $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=:;; 11224 esac 11225 if $at_failed; then 11226 11227 echo 1 > $at_status_file 11228 exit 1 11229 fi 11230 11231 $at_traceon 11232 11233 $at_traceoff 11234 echo "calc.at:550: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 11235 echo calc.at:550 >$at_check_line_file 11236 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 11237 at_status=$? 11238 grep '^ *+' $at_stder1 >&2 11239 grep -v '^ *+' $at_stder1 >$at_stderr 11240 at_failed=false 11241 echo stderr:; cat $at_stderr 11242 echo stdout:; cat $at_stdout 11243 case $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=:;; 11249 esac 11250 if $at_failed; then 11251 11252 echo 1 > $at_status_file 11253 exit 1 11254 fi 11255 11256 $at_traceon 11257 11258 11259 # Test the priorities. 11260 cat >input <<'_ATEOF' 11261 1 + 2 * 3 = 7 11262 1 + 2 * -3 = -5 11263 11264 -1^2 = -1 11265 (-1)^2 = 1 11266 11267 ---1 = -1 11268 11269 1 - 2 - 3 = -4 11270 1 - (2 - 3) = 2 11271 11272 2^2^3 = 256 11273 (2^2)^3 = 64 11274 _ATEOF 11275 11276 $at_traceoff 11277 echo "calc.at:550: \$PREPARSER ./calc input" 11278 echo calc.at:550 >$at_check_line_file 11279 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 11280 at_status=$? 11281 grep '^ *+' $at_stder1 >&2 11282 grep -v '^ *+' $at_stder1 >$at_stderr 11283 at_failed=false 11284 echo stderr:; tee stderr <$at_stderr 11285 $at_diff $at_devnull $at_stdout || at_failed=: 11286 case $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=:;; 11292 esac 11293 if $at_failed; then 11294 11295 echo 1 > $at_status_file 11296 exit 1 11297 fi 11298 11299 $at_traceon 11300 11301 11302 11303 # Some syntax errors. 11304 cat >input <<'_ATEOF' 11305 0 0 11306 _ATEOF 11307 11308 $at_traceoff 11309 echo "calc.at:550: \$PREPARSER ./calc input" 11310 echo calc.at:550 >$at_check_line_file 11311 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 11312 at_status=$? 11313 grep '^ *+' $at_stder1 >&2 11314 grep -v '^ *+' $at_stder1 >$at_stderr 11315 at_failed=false 11316 echo stderr:; tee stderr <$at_stderr 11317 $at_diff $at_devnull $at_stdout || at_failed=: 11318 case $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=:;; 11324 esac 11325 if $at_failed; then 11326 11327 echo 1 > $at_status_file 11328 exit 1 11329 fi 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. 11337 sed '/^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 11350 mv at-stderr stderr 11351 # 2. Create the reference error message. 11352 cat >expout <<'_ATEOF' 11353 1.2: syntax error, unexpected number 11354 _ATEOF 11355 11356 # 3. If locations are not used, remove them. 11357 sed 's/^[-0-9.]*: //' expout >at-expout 11358 mv at-expout expout 11359 # 4. If error-verbose is not used, strip the`, unexpected....' part. 11360 sed 's/syntax error, .*$/syntax error/' expout >at-expout 11361 mv at-expout expout 11362 # 5. Check 11363 $at_traceoff 11364 echo "calc.at:550: cat stderr" 11365 echo calc.at:550 >$at_check_line_file 11366 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 11367 at_status=$? 11368 grep '^ *+' $at_stder1 >&2 11369 grep -v '^ *+' $at_stder1 >$at_stderr 11370 at_failed=false 11371 $at_diff $at_devnull $at_stderr || at_failed=: 11372 $at_diff expout $at_stdout || at_failed=: 11373 case $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=:;; 11379 esac 11380 if $at_failed; then 11381 11382 echo 1 > $at_status_file 11383 exit 1 11384 fi 11385 11386 $at_traceon 11387 11388 11389 cat >input <<'_ATEOF' 11390 1//2 11391 _ATEOF 11392 11393 $at_traceoff 11394 echo "calc.at:550: \$PREPARSER ./calc input" 11395 echo calc.at:550 >$at_check_line_file 11396 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 11397 at_status=$? 11398 grep '^ *+' $at_stder1 >&2 11399 grep -v '^ *+' $at_stder1 >$at_stderr 11400 at_failed=false 11401 echo stderr:; tee stderr <$at_stderr 11402 $at_diff $at_devnull $at_stdout || at_failed=: 11403 case $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=:;; 11409 esac 11410 if $at_failed; then 11411 11412 echo 1 > $at_status_file 11413 exit 1 11414 fi 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. 11422 sed '/^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 11435 mv at-stderr stderr 11436 # 2. Create the reference error message. 11437 cat >expout <<'_ATEOF' 11438 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 11439 _ATEOF 11440 11441 # 3. If locations are not used, remove them. 11442 sed 's/^[-0-9.]*: //' expout >at-expout 11443 mv at-expout expout 11444 # 4. If error-verbose is not used, strip the`, unexpected....' part. 11445 sed 's/syntax error, .*$/syntax error/' expout >at-expout 11446 mv at-expout expout 11447 # 5. Check 11448 $at_traceoff 11449 echo "calc.at:550: cat stderr" 11450 echo calc.at:550 >$at_check_line_file 11451 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 11452 at_status=$? 11453 grep '^ *+' $at_stder1 >&2 11454 grep -v '^ *+' $at_stder1 >$at_stderr 11455 at_failed=false 11456 $at_diff $at_devnull $at_stderr || at_failed=: 11457 $at_diff expout $at_stdout || at_failed=: 11458 case $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=:;; 11464 esac 11465 if $at_failed; then 11466 11467 echo 1 > $at_status_file 11468 exit 1 11469 fi 11470 11471 $at_traceon 11472 11473 11474 cat >input <<'_ATEOF' 11475 error 11476 _ATEOF 11477 11478 $at_traceoff 11479 echo "calc.at:550: \$PREPARSER ./calc input" 11480 echo calc.at:550 >$at_check_line_file 11481 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 11482 at_status=$? 11483 grep '^ *+' $at_stder1 >&2 11484 grep -v '^ *+' $at_stder1 >$at_stderr 11485 at_failed=false 11486 echo stderr:; tee stderr <$at_stderr 11487 $at_diff $at_devnull $at_stdout || at_failed=: 11488 case $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=:;; 11494 esac 11495 if $at_failed; then 11496 11497 echo 1 > $at_status_file 11498 exit 1 11499 fi 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. 11507 sed '/^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 11520 mv at-stderr stderr 11521 # 2. Create the reference error message. 11522 cat >expout <<'_ATEOF' 11523 1.0: syntax error, unexpected $undefined 11524 _ATEOF 11525 11526 # 3. If locations are not used, remove them. 11527 sed 's/^[-0-9.]*: //' expout >at-expout 11528 mv at-expout expout 11529 # 4. If error-verbose is not used, strip the`, unexpected....' part. 11530 sed 's/syntax error, .*$/syntax error/' expout >at-expout 11531 mv at-expout expout 11532 # 5. Check 11533 $at_traceoff 11534 echo "calc.at:550: cat stderr" 11535 echo calc.at:550 >$at_check_line_file 11536 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 11537 at_status=$? 11538 grep '^ *+' $at_stder1 >&2 11539 grep -v '^ *+' $at_stder1 >$at_stderr 11540 at_failed=false 11541 $at_diff $at_devnull $at_stderr || at_failed=: 11542 $at_diff expout $at_stdout || at_failed=: 11543 case $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=:;; 11549 esac 11550 if $at_failed; then 11551 11552 echo 1 > $at_status_file 11553 exit 1 11554 fi 11555 11556 $at_traceon 11557 11558 11559 cat >input <<'_ATEOF' 11560 1 = 2 = 3 11561 _ATEOF 11562 11563 $at_traceoff 11564 echo "calc.at:550: \$PREPARSER ./calc input" 11565 echo calc.at:550 >$at_check_line_file 11566 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 11567 at_status=$? 11568 grep '^ *+' $at_stder1 >&2 11569 grep -v '^ *+' $at_stder1 >$at_stderr 11570 at_failed=false 11571 echo stderr:; tee stderr <$at_stderr 11572 $at_diff $at_devnull $at_stdout || at_failed=: 11573 case $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=:;; 11579 esac 11580 if $at_failed; then 11581 11582 echo 1 > $at_status_file 11583 exit 1 11584 fi 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. 11592 sed '/^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 11605 mv at-stderr stderr 11606 # 2. Create the reference error message. 11607 cat >expout <<'_ATEOF' 11608 1.6: syntax error, unexpected '=' 11609 _ATEOF 11610 11611 # 3. If locations are not used, remove them. 11612 sed 's/^[-0-9.]*: //' expout >at-expout 11613 mv at-expout expout 11614 # 4. If error-verbose is not used, strip the`, unexpected....' part. 11615 sed 's/syntax error, .*$/syntax error/' expout >at-expout 11616 mv at-expout expout 11617 # 5. Check 11618 $at_traceoff 11619 echo "calc.at:550: cat stderr" 11620 echo calc.at:550 >$at_check_line_file 11621 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 11622 at_status=$? 11623 grep '^ *+' $at_stder1 >&2 11624 grep -v '^ *+' $at_stder1 >$at_stderr 11625 at_failed=false 11626 $at_diff $at_devnull $at_stderr || at_failed=: 11627 $at_diff expout $at_stdout || at_failed=: 11628 case $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=:;; 11634 esac 11635 if $at_failed; then 11636 11637 echo 1 > $at_status_file 11638 exit 1 11639 fi 11640 11641 $at_traceon 11642 11643 11644 cat >input <<'_ATEOF' 11645 11646 +1 11647 _ATEOF 11648 11649 $at_traceoff 11650 echo "calc.at:550: \$PREPARSER ./calc input" 11651 echo calc.at:550 >$at_check_line_file 11652 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 11653 at_status=$? 11654 grep '^ *+' $at_stder1 >&2 11655 grep -v '^ *+' $at_stder1 >$at_stderr 11656 at_failed=false 11657 echo stderr:; tee stderr <$at_stderr 11658 $at_diff $at_devnull $at_stdout || at_failed=: 11659 case $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=:;; 11665 esac 11666 if $at_failed; then 11667 11668 echo 1 > $at_status_file 11669 exit 1 11670 fi 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. 11678 sed '/^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 11691 mv at-stderr stderr 11692 # 2. Create the reference error message. 11693 cat >expout <<'_ATEOF' 11694 2.0: syntax error, unexpected '+' 11695 _ATEOF 11696 11697 # 3. If locations are not used, remove them. 11698 sed 's/^[-0-9.]*: //' expout >at-expout 11699 mv at-expout expout 11700 # 4. If error-verbose is not used, strip the`, unexpected....' part. 11701 sed 's/syntax error, .*$/syntax error/' expout >at-expout 11702 mv at-expout expout 11703 # 5. Check 11704 $at_traceoff 11705 echo "calc.at:550: cat stderr" 11706 echo calc.at:550 >$at_check_line_file 11707 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 11708 at_status=$? 11709 grep '^ *+' $at_stder1 >&2 11710 grep -v '^ *+' $at_stder1 >$at_stderr 11711 at_failed=false 11712 $at_diff $at_devnull $at_stderr || at_failed=: 11713 $at_diff expout $at_stdout || at_failed=: 11714 case $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=:;; 11720 esac 11721 if $at_failed; then 11722 11723 echo 1 > $at_status_file 11724 exit 1 11725 fi 11726 11727 $at_traceon 11728 11729 11730 # Exercise error messages with EOF: work on an empty file. 11731 $at_traceoff 11732 echo "calc.at:550: \$PREPARSER ./calc /dev/null" 11733 echo calc.at:550 >$at_check_line_file 11734 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 11735 at_status=$? 11736 grep '^ *+' $at_stder1 >&2 11737 grep -v '^ *+' $at_stder1 >$at_stderr 11738 at_failed=false 11739 echo stderr:; tee stderr <$at_stderr 11740 $at_diff $at_devnull $at_stdout || at_failed=: 11741 case $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=:;; 11747 esac 11748 if $at_failed; then 11749 11750 echo 1 > $at_status_file 11751 exit 1 11752 fi 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. 11760 sed '/^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 11773 mv at-stderr stderr 11774 # 2. Create the reference error message. 11775 cat >expout <<'_ATEOF' 11776 1.0: syntax error, unexpected end of input 11777 _ATEOF 11778 11779 # 3. If locations are not used, remove them. 11780 sed 's/^[-0-9.]*: //' expout >at-expout 11781 mv at-expout expout 11782 # 4. If error-verbose is not used, strip the`, unexpected....' part. 11783 sed 's/syntax error, .*$/syntax error/' expout >at-expout 11784 mv at-expout expout 11785 # 5. Check 11786 $at_traceoff 11787 echo "calc.at:550: cat stderr" 11788 echo calc.at:550 >$at_check_line_file 11789 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 11790 at_status=$? 11791 grep '^ *+' $at_stder1 >&2 11792 grep -v '^ *+' $at_stder1 >$at_stderr 11793 at_failed=false 11794 $at_diff $at_devnull $at_stderr || at_failed=: 11795 $at_diff expout $at_stdout || at_failed=: 11796 case $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=:;; 11802 esac 11803 if $at_failed; then 11804 11805 echo 1 > $at_status_file 11806 exit 1 11807 fi 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 # 11829 cat >input <<'_ATEOF' 11830 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 11831 _ATEOF 11832 11833 $at_traceoff 11834 echo "calc.at:550: \$PREPARSER ./calc input" 11835 echo calc.at:550 >$at_check_line_file 11836 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 11837 at_status=$? 11838 grep '^ *+' $at_stder1 >&2 11839 grep -v '^ *+' $at_stder1 >$at_stderr 11840 at_failed=false 11841 echo stderr:; tee stderr <$at_stderr 11842 $at_diff $at_devnull $at_stdout || at_failed=: 11843 case $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=:;; 11849 esac 11850 if $at_failed; then 11851 11852 echo 1 > $at_status_file 11853 exit 1 11854 fi 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. 11862 sed '/^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 11875 mv at-stderr stderr 11876 # 2. Create the reference error message. 11877 cat >expout <<'_ATEOF' 11878 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 11879 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 11880 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 11881 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 11882 calc: error: 4444 != 1 11883 _ATEOF 11884 11885 # 3. If locations are not used, remove them. 11886 sed 's/^[-0-9.]*: //' expout >at-expout 11887 mv at-expout expout 11888 # 4. If error-verbose is not used, strip the`, unexpected....' part. 11889 sed 's/syntax error, .*$/syntax error/' expout >at-expout 11890 mv at-expout expout 11891 # 5. Check 11892 $at_traceoff 11893 echo "calc.at:550: cat stderr" 11894 echo calc.at:550 >$at_check_line_file 11895 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 11896 at_status=$? 11897 grep '^ *+' $at_stder1 >&2 11898 grep -v '^ *+' $at_stder1 >$at_stderr 11899 at_failed=false 11900 $at_diff $at_devnull $at_stderr || at_failed=: 11901 $at_diff expout $at_stdout || at_failed=: 11902 case $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=:;; 11908 esac 11909 if $at_failed; then 11910 11911 echo 1 > $at_status_file 11912 exit 1 11913 fi 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. 11921 cat >input <<'_ATEOF' 11922 (!) + (0 0) = 1 11923 _ATEOF 11924 11925 $at_traceoff 11926 echo "calc.at:550: \$PREPARSER ./calc input" 11927 echo calc.at:550 >$at_check_line_file 11928 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 11929 at_status=$? 11930 grep '^ *+' $at_stder1 >&2 11931 grep -v '^ *+' $at_stder1 >$at_stderr 11932 at_failed=false 11933 echo stderr:; tee stderr <$at_stderr 11934 $at_diff $at_devnull $at_stdout || at_failed=: 11935 case $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=:;; 11941 esac 11942 if $at_failed; then 11943 11944 echo 1 > $at_status_file 11945 exit 1 11946 fi 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. 11954 sed '/^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 11967 mv at-stderr stderr 11968 # 2. Create the reference error message. 11969 cat >expout <<'_ATEOF' 11970 1.9: syntax error, unexpected number 11971 calc: error: 2222 != 1 11972 _ATEOF 11973 11974 # 3. If locations are not used, remove them. 11975 sed 's/^[-0-9.]*: //' expout >at-expout 11976 mv at-expout expout 11977 # 4. If error-verbose is not used, strip the`, unexpected....' part. 11978 sed 's/syntax error, .*$/syntax error/' expout >at-expout 11979 mv at-expout expout 11980 # 5. Check 11981 $at_traceoff 11982 echo "calc.at:550: cat stderr" 11983 echo calc.at:550 >$at_check_line_file 11984 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 11985 at_status=$? 11986 grep '^ *+' $at_stder1 >&2 11987 grep -v '^ *+' $at_stder1 >$at_stderr 11988 at_failed=false 11989 $at_diff $at_devnull $at_stderr || at_failed=: 11990 $at_diff expout $at_stdout || at_failed=: 11991 case $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=:;; 11997 esac 11998 if $at_failed; then 11999 12000 echo 1 > $at_status_file 12001 exit 1 12002 fi 12003 12004 $at_traceon 12005 12006 12007 cat >input <<'_ATEOF' 12008 (- *) + (0 0) = 1 12009 _ATEOF 12010 12011 $at_traceoff 12012 echo "calc.at:550: \$PREPARSER ./calc input" 12013 echo calc.at:550 >$at_check_line_file 12014 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 12015 at_status=$? 12016 grep '^ *+' $at_stder1 >&2 12017 grep -v '^ *+' $at_stder1 >$at_stderr 12018 at_failed=false 12019 echo stderr:; tee stderr <$at_stderr 12020 $at_diff $at_devnull $at_stdout || at_failed=: 12021 case $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=:;; 12027 esac 12028 if $at_failed; then 12029 12030 echo 1 > $at_status_file 12031 exit 1 12032 fi 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. 12040 sed '/^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 12053 mv at-stderr stderr 12054 # 2. Create the reference error message. 12055 cat >expout <<'_ATEOF' 12056 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 12057 1.11: syntax error, unexpected number 12058 calc: error: 2222 != 1 12059 _ATEOF 12060 12061 # 3. If locations are not used, remove them. 12062 sed 's/^[-0-9.]*: //' expout >at-expout 12063 mv at-expout expout 12064 # 4. If error-verbose is not used, strip the`, unexpected....' part. 12065 sed 's/syntax error, .*$/syntax error/' expout >at-expout 12066 mv at-expout expout 12067 # 5. Check 12068 $at_traceoff 12069 echo "calc.at:550: cat stderr" 12070 echo calc.at:550 >$at_check_line_file 12071 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 12072 at_status=$? 12073 grep '^ *+' $at_stder1 >&2 12074 grep -v '^ *+' $at_stder1 >$at_stderr 12075 at_failed=false 12076 $at_diff $at_devnull $at_stderr || at_failed=: 12077 $at_diff expout $at_stdout || at_failed=: 12078 case $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=:;; 12084 esac 12085 if $at_failed; then 12086 12087 echo 1 > $at_status_file 12088 exit 1 12089 fi 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 12166 cat >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. */ 12195 typedef int semantic_value; 12196 12197 static semantic_value global_result = 0; 12198 static int global_count = 0; 12199 %} 12200 12201 /* Exercise %union. */ 12202 %union 12203 { 12204 semantic_value ival; 12205 }; 12206 12207 %{ 12208 static int power (int base, int exponent); 12209 /* yyerror receives the location if: 12210 - %location & %pure & %glr 12211 - %location & %pure & %yacc & %parse-param. */ 12212 static void yyerror ( 12213 12214 const char *s 12215 ); 12216 static int yylex (void); 12217 static int get_char (void); 12218 static 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 %% 12236 input: 12237 line 12238 | input line { } 12239 ; 12240 12241 line: 12242 '\n' 12243 | exp '\n' { USE ($1); } 12244 ; 12245 12246 exp: 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. */ 12267 static FILE *input; 12268 12269 static void 12270 yyerror ( 12271 12272 const char *s) 12273 { 12274 12275 12276 fprintf (stderr, "%s\n", s); 12277 } 12278 12279 12280 12281 static int 12282 get_char (void) 12283 { 12284 int res = getc (input); 12285 ; 12286 12287 return res; 12288 } 12289 12290 12291 static void 12292 unget_char ( int c) 12293 { 12294 ; 12295 12296 ungetc (c, input); 12297 } 12298 12299 static int 12300 read_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 12332 static int 12333 yylex (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 12368 static int 12369 power (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 12380 int 12381 main (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 12418 echo "calc.at:552: bison -o calc.c calc.y" 12419 echo calc.at:552 >$at_check_line_file 12420 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 12421 at_status=$? 12422 grep '^ *+' $at_stder1 >&2 12423 grep -v '^ *+' $at_stder1 >$at_stderr 12424 at_failed=false 12425 $at_diff $at_devnull $at_stderr || at_failed=: 12426 $at_diff $at_devnull $at_stdout || at_failed=: 12427 case $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=:;; 12433 esac 12434 if $at_failed; then 12435 12436 echo 1 > $at_status_file 12437 exit 1 12438 fi 12439 12440 $at_traceon 12441 12442 $at_traceoff 12443 echo "calc.at:552: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 12444 echo calc.at:552 >$at_check_line_file 12445 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 12446 at_status=$? 12447 grep '^ *+' $at_stder1 >&2 12448 grep -v '^ *+' $at_stder1 >$at_stderr 12449 at_failed=false 12450 echo stderr:; cat $at_stderr 12451 echo stdout:; cat $at_stdout 12452 case $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=:;; 12458 esac 12459 if $at_failed; then 12460 12461 echo 1 > $at_status_file 12462 exit 1 12463 fi 12464 12465 $at_traceon 12466 12467 12468 # Test the priorities. 12469 cat >input <<'_ATEOF' 12470 1 + 2 * 3 = 7 12471 1 + 2 * -3 = -5 12472 12473 -1^2 = -1 12474 (-1)^2 = 1 12475 12476 ---1 = -1 12477 12478 1 - 2 - 3 = -4 12479 1 - (2 - 3) = 2 12480 12481 2^2^3 = 256 12482 (2^2)^3 = 64 12483 _ATEOF 12484 12485 $at_traceoff 12486 echo "calc.at:552: \$PREPARSER ./calc input" 12487 echo calc.at:552 >$at_check_line_file 12488 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 12489 at_status=$? 12490 grep '^ *+' $at_stder1 >&2 12491 grep -v '^ *+' $at_stder1 >$at_stderr 12492 at_failed=false 12493 echo stderr:; tee stderr <$at_stderr 12494 $at_diff $at_devnull $at_stdout || at_failed=: 12495 case $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=:;; 12501 esac 12502 if $at_failed; then 12503 12504 echo 1 > $at_status_file 12505 exit 1 12506 fi 12507 12508 $at_traceon 12509 12510 12511 12512 # Some syntax errors. 12513 cat >input <<'_ATEOF' 12514 0 0 12515 _ATEOF 12516 12517 $at_traceoff 12518 echo "calc.at:552: \$PREPARSER ./calc input" 12519 echo calc.at:552 >$at_check_line_file 12520 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 12521 at_status=$? 12522 grep '^ *+' $at_stder1 >&2 12523 grep -v '^ *+' $at_stder1 >$at_stderr 12524 at_failed=false 12525 echo stderr:; tee stderr <$at_stderr 12526 $at_diff $at_devnull $at_stdout || at_failed=: 12527 case $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=:;; 12533 esac 12534 if $at_failed; then 12535 12536 echo 1 > $at_status_file 12537 exit 1 12538 fi 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. 12546 sed '/^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 12559 mv at-stderr stderr 12560 # 2. Create the reference error message. 12561 cat >expout <<'_ATEOF' 12562 1.2: syntax error, unexpected number 12563 _ATEOF 12564 12565 # 3. If locations are not used, remove them. 12566 sed 's/^[-0-9.]*: //' expout >at-expout 12567 mv at-expout expout 12568 # 4. If error-verbose is not used, strip the`, unexpected....' part. 12569 sed 's/syntax error, .*$/syntax error/' expout >at-expout 12570 mv at-expout expout 12571 # 5. Check 12572 $at_traceoff 12573 echo "calc.at:552: cat stderr" 12574 echo calc.at:552 >$at_check_line_file 12575 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 12576 at_status=$? 12577 grep '^ *+' $at_stder1 >&2 12578 grep -v '^ *+' $at_stder1 >$at_stderr 12579 at_failed=false 12580 $at_diff $at_devnull $at_stderr || at_failed=: 12581 $at_diff expout $at_stdout || at_failed=: 12582 case $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=:;; 12588 esac 12589 if $at_failed; then 12590 12591 echo 1 > $at_status_file 12592 exit 1 12593 fi 12594 12595 $at_traceon 12596 12597 12598 cat >input <<'_ATEOF' 12599 1//2 12600 _ATEOF 12601 12602 $at_traceoff 12603 echo "calc.at:552: \$PREPARSER ./calc input" 12604 echo calc.at:552 >$at_check_line_file 12605 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 12606 at_status=$? 12607 grep '^ *+' $at_stder1 >&2 12608 grep -v '^ *+' $at_stder1 >$at_stderr 12609 at_failed=false 12610 echo stderr:; tee stderr <$at_stderr 12611 $at_diff $at_devnull $at_stdout || at_failed=: 12612 case $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=:;; 12618 esac 12619 if $at_failed; then 12620 12621 echo 1 > $at_status_file 12622 exit 1 12623 fi 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. 12631 sed '/^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 12644 mv at-stderr stderr 12645 # 2. Create the reference error message. 12646 cat >expout <<'_ATEOF' 12647 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 12648 _ATEOF 12649 12650 # 3. If locations are not used, remove them. 12651 sed 's/^[-0-9.]*: //' expout >at-expout 12652 mv at-expout expout 12653 # 4. If error-verbose is not used, strip the`, unexpected....' part. 12654 sed 's/syntax error, .*$/syntax error/' expout >at-expout 12655 mv at-expout expout 12656 # 5. Check 12657 $at_traceoff 12658 echo "calc.at:552: cat stderr" 12659 echo calc.at:552 >$at_check_line_file 12660 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 12661 at_status=$? 12662 grep '^ *+' $at_stder1 >&2 12663 grep -v '^ *+' $at_stder1 >$at_stderr 12664 at_failed=false 12665 $at_diff $at_devnull $at_stderr || at_failed=: 12666 $at_diff expout $at_stdout || at_failed=: 12667 case $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=:;; 12673 esac 12674 if $at_failed; then 12675 12676 echo 1 > $at_status_file 12677 exit 1 12678 fi 12679 12680 $at_traceon 12681 12682 12683 cat >input <<'_ATEOF' 12684 error 12685 _ATEOF 12686 12687 $at_traceoff 12688 echo "calc.at:552: \$PREPARSER ./calc input" 12689 echo calc.at:552 >$at_check_line_file 12690 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 12691 at_status=$? 12692 grep '^ *+' $at_stder1 >&2 12693 grep -v '^ *+' $at_stder1 >$at_stderr 12694 at_failed=false 12695 echo stderr:; tee stderr <$at_stderr 12696 $at_diff $at_devnull $at_stdout || at_failed=: 12697 case $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=:;; 12703 esac 12704 if $at_failed; then 12705 12706 echo 1 > $at_status_file 12707 exit 1 12708 fi 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. 12716 sed '/^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 12729 mv at-stderr stderr 12730 # 2. Create the reference error message. 12731 cat >expout <<'_ATEOF' 12732 1.0: syntax error, unexpected $undefined 12733 _ATEOF 12734 12735 # 3. If locations are not used, remove them. 12736 sed 's/^[-0-9.]*: //' expout >at-expout 12737 mv at-expout expout 12738 # 4. If error-verbose is not used, strip the`, unexpected....' part. 12739 sed 's/syntax error, .*$/syntax error/' expout >at-expout 12740 mv at-expout expout 12741 # 5. Check 12742 $at_traceoff 12743 echo "calc.at:552: cat stderr" 12744 echo calc.at:552 >$at_check_line_file 12745 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 12746 at_status=$? 12747 grep '^ *+' $at_stder1 >&2 12748 grep -v '^ *+' $at_stder1 >$at_stderr 12749 at_failed=false 12750 $at_diff $at_devnull $at_stderr || at_failed=: 12751 $at_diff expout $at_stdout || at_failed=: 12752 case $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=:;; 12758 esac 12759 if $at_failed; then 12760 12761 echo 1 > $at_status_file 12762 exit 1 12763 fi 12764 12765 $at_traceon 12766 12767 12768 cat >input <<'_ATEOF' 12769 1 = 2 = 3 12770 _ATEOF 12771 12772 $at_traceoff 12773 echo "calc.at:552: \$PREPARSER ./calc input" 12774 echo calc.at:552 >$at_check_line_file 12775 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 12776 at_status=$? 12777 grep '^ *+' $at_stder1 >&2 12778 grep -v '^ *+' $at_stder1 >$at_stderr 12779 at_failed=false 12780 echo stderr:; tee stderr <$at_stderr 12781 $at_diff $at_devnull $at_stdout || at_failed=: 12782 case $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=:;; 12788 esac 12789 if $at_failed; then 12790 12791 echo 1 > $at_status_file 12792 exit 1 12793 fi 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. 12801 sed '/^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 12814 mv at-stderr stderr 12815 # 2. Create the reference error message. 12816 cat >expout <<'_ATEOF' 12817 1.6: syntax error, unexpected '=' 12818 _ATEOF 12819 12820 # 3. If locations are not used, remove them. 12821 sed 's/^[-0-9.]*: //' expout >at-expout 12822 mv at-expout expout 12823 # 4. If error-verbose is not used, strip the`, unexpected....' part. 12824 sed 's/syntax error, .*$/syntax error/' expout >at-expout 12825 mv at-expout expout 12826 # 5. Check 12827 $at_traceoff 12828 echo "calc.at:552: cat stderr" 12829 echo calc.at:552 >$at_check_line_file 12830 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 12831 at_status=$? 12832 grep '^ *+' $at_stder1 >&2 12833 grep -v '^ *+' $at_stder1 >$at_stderr 12834 at_failed=false 12835 $at_diff $at_devnull $at_stderr || at_failed=: 12836 $at_diff expout $at_stdout || at_failed=: 12837 case $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=:;; 12843 esac 12844 if $at_failed; then 12845 12846 echo 1 > $at_status_file 12847 exit 1 12848 fi 12849 12850 $at_traceon 12851 12852 12853 cat >input <<'_ATEOF' 12854 12855 +1 12856 _ATEOF 12857 12858 $at_traceoff 12859 echo "calc.at:552: \$PREPARSER ./calc input" 12860 echo calc.at:552 >$at_check_line_file 12861 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 12862 at_status=$? 12863 grep '^ *+' $at_stder1 >&2 12864 grep -v '^ *+' $at_stder1 >$at_stderr 12865 at_failed=false 12866 echo stderr:; tee stderr <$at_stderr 12867 $at_diff $at_devnull $at_stdout || at_failed=: 12868 case $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=:;; 12874 esac 12875 if $at_failed; then 12876 12877 echo 1 > $at_status_file 12878 exit 1 12879 fi 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. 12887 sed '/^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 12900 mv at-stderr stderr 12901 # 2. Create the reference error message. 12902 cat >expout <<'_ATEOF' 12903 2.0: syntax error, unexpected '+' 12904 _ATEOF 12905 12906 # 3. If locations are not used, remove them. 12907 sed 's/^[-0-9.]*: //' expout >at-expout 12908 mv at-expout expout 12909 # 4. If error-verbose is not used, strip the`, unexpected....' part. 12910 sed 's/syntax error, .*$/syntax error/' expout >at-expout 12911 mv at-expout expout 12912 # 5. Check 12913 $at_traceoff 12914 echo "calc.at:552: cat stderr" 12915 echo calc.at:552 >$at_check_line_file 12916 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 12917 at_status=$? 12918 grep '^ *+' $at_stder1 >&2 12919 grep -v '^ *+' $at_stder1 >$at_stderr 12920 at_failed=false 12921 $at_diff $at_devnull $at_stderr || at_failed=: 12922 $at_diff expout $at_stdout || at_failed=: 12923 case $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=:;; 12929 esac 12930 if $at_failed; then 12931 12932 echo 1 > $at_status_file 12933 exit 1 12934 fi 12935 12936 $at_traceon 12937 12938 12939 # Exercise error messages with EOF: work on an empty file. 12940 $at_traceoff 12941 echo "calc.at:552: \$PREPARSER ./calc /dev/null" 12942 echo calc.at:552 >$at_check_line_file 12943 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 12944 at_status=$? 12945 grep '^ *+' $at_stder1 >&2 12946 grep -v '^ *+' $at_stder1 >$at_stderr 12947 at_failed=false 12948 echo stderr:; tee stderr <$at_stderr 12949 $at_diff $at_devnull $at_stdout || at_failed=: 12950 case $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=:;; 12956 esac 12957 if $at_failed; then 12958 12959 echo 1 > $at_status_file 12960 exit 1 12961 fi 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. 12969 sed '/^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 12982 mv at-stderr stderr 12983 # 2. Create the reference error message. 12984 cat >expout <<'_ATEOF' 12985 1.0: syntax error, unexpected end of input 12986 _ATEOF 12987 12988 # 3. If locations are not used, remove them. 12989 sed 's/^[-0-9.]*: //' expout >at-expout 12990 mv at-expout expout 12991 # 4. If error-verbose is not used, strip the`, unexpected....' part. 12992 sed 's/syntax error, .*$/syntax error/' expout >at-expout 12993 mv at-expout expout 12994 # 5. Check 12995 $at_traceoff 12996 echo "calc.at:552: cat stderr" 12997 echo calc.at:552 >$at_check_line_file 12998 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 12999 at_status=$? 13000 grep '^ *+' $at_stder1 >&2 13001 grep -v '^ *+' $at_stder1 >$at_stderr 13002 at_failed=false 13003 $at_diff $at_devnull $at_stderr || at_failed=: 13004 $at_diff expout $at_stdout || at_failed=: 13005 case $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=:;; 13011 esac 13012 if $at_failed; then 13013 13014 echo 1 > $at_status_file 13015 exit 1 13016 fi 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 # 13038 cat >input <<'_ATEOF' 13039 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 13040 _ATEOF 13041 13042 $at_traceoff 13043 echo "calc.at:552: \$PREPARSER ./calc input" 13044 echo calc.at:552 >$at_check_line_file 13045 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 13046 at_status=$? 13047 grep '^ *+' $at_stder1 >&2 13048 grep -v '^ *+' $at_stder1 >$at_stderr 13049 at_failed=false 13050 echo stderr:; tee stderr <$at_stderr 13051 $at_diff $at_devnull $at_stdout || at_failed=: 13052 case $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=:;; 13058 esac 13059 if $at_failed; then 13060 13061 echo 1 > $at_status_file 13062 exit 1 13063 fi 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. 13071 sed '/^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 13084 mv at-stderr stderr 13085 # 2. Create the reference error message. 13086 cat >expout <<'_ATEOF' 13087 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 13088 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 13089 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 13090 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 13091 calc: error: 4444 != 1 13092 _ATEOF 13093 13094 # 3. If locations are not used, remove them. 13095 sed 's/^[-0-9.]*: //' expout >at-expout 13096 mv at-expout expout 13097 # 4. If error-verbose is not used, strip the`, unexpected....' part. 13098 sed 's/syntax error, .*$/syntax error/' expout >at-expout 13099 mv at-expout expout 13100 # 5. Check 13101 $at_traceoff 13102 echo "calc.at:552: cat stderr" 13103 echo calc.at:552 >$at_check_line_file 13104 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 13105 at_status=$? 13106 grep '^ *+' $at_stder1 >&2 13107 grep -v '^ *+' $at_stder1 >$at_stderr 13108 at_failed=false 13109 $at_diff $at_devnull $at_stderr || at_failed=: 13110 $at_diff expout $at_stdout || at_failed=: 13111 case $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=:;; 13117 esac 13118 if $at_failed; then 13119 13120 echo 1 > $at_status_file 13121 exit 1 13122 fi 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. 13130 cat >input <<'_ATEOF' 13131 (!) + (0 0) = 1 13132 _ATEOF 13133 13134 $at_traceoff 13135 echo "calc.at:552: \$PREPARSER ./calc input" 13136 echo calc.at:552 >$at_check_line_file 13137 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 13138 at_status=$? 13139 grep '^ *+' $at_stder1 >&2 13140 grep -v '^ *+' $at_stder1 >$at_stderr 13141 at_failed=false 13142 echo stderr:; tee stderr <$at_stderr 13143 $at_diff $at_devnull $at_stdout || at_failed=: 13144 case $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=:;; 13150 esac 13151 if $at_failed; then 13152 13153 echo 1 > $at_status_file 13154 exit 1 13155 fi 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. 13163 sed '/^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 13176 mv at-stderr stderr 13177 # 2. Create the reference error message. 13178 cat >expout <<'_ATEOF' 13179 1.9: syntax error, unexpected number 13180 calc: error: 2222 != 1 13181 _ATEOF 13182 13183 # 3. If locations are not used, remove them. 13184 sed 's/^[-0-9.]*: //' expout >at-expout 13185 mv at-expout expout 13186 # 4. If error-verbose is not used, strip the`, unexpected....' part. 13187 sed 's/syntax error, .*$/syntax error/' expout >at-expout 13188 mv at-expout expout 13189 # 5. Check 13190 $at_traceoff 13191 echo "calc.at:552: cat stderr" 13192 echo calc.at:552 >$at_check_line_file 13193 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 13194 at_status=$? 13195 grep '^ *+' $at_stder1 >&2 13196 grep -v '^ *+' $at_stder1 >$at_stderr 13197 at_failed=false 13198 $at_diff $at_devnull $at_stderr || at_failed=: 13199 $at_diff expout $at_stdout || at_failed=: 13200 case $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=:;; 13206 esac 13207 if $at_failed; then 13208 13209 echo 1 > $at_status_file 13210 exit 1 13211 fi 13212 13213 $at_traceon 13214 13215 13216 cat >input <<'_ATEOF' 13217 (- *) + (0 0) = 1 13218 _ATEOF 13219 13220 $at_traceoff 13221 echo "calc.at:552: \$PREPARSER ./calc input" 13222 echo calc.at:552 >$at_check_line_file 13223 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 13224 at_status=$? 13225 grep '^ *+' $at_stder1 >&2 13226 grep -v '^ *+' $at_stder1 >$at_stderr 13227 at_failed=false 13228 echo stderr:; tee stderr <$at_stderr 13229 $at_diff $at_devnull $at_stdout || at_failed=: 13230 case $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=:;; 13236 esac 13237 if $at_failed; then 13238 13239 echo 1 > $at_status_file 13240 exit 1 13241 fi 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. 13249 sed '/^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 13262 mv at-stderr stderr 13263 # 2. Create the reference error message. 13264 cat >expout <<'_ATEOF' 13265 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 13266 1.11: syntax error, unexpected number 13267 calc: error: 2222 != 1 13268 _ATEOF 13269 13270 # 3. If locations are not used, remove them. 13271 sed 's/^[-0-9.]*: //' expout >at-expout 13272 mv at-expout expout 13273 # 4. If error-verbose is not used, strip the`, unexpected....' part. 13274 sed 's/syntax error, .*$/syntax error/' expout >at-expout 13275 mv at-expout expout 13276 # 5. Check 13277 $at_traceoff 13278 echo "calc.at:552: cat stderr" 13279 echo calc.at:552 >$at_check_line_file 13280 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 13281 at_status=$? 13282 grep '^ *+' $at_stder1 >&2 13283 grep -v '^ *+' $at_stder1 >$at_stderr 13284 at_failed=false 13285 $at_diff $at_devnull $at_stderr || at_failed=: 13286 $at_diff expout $at_stdout || at_failed=: 13287 case $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=:;; 13293 esac 13294 if $at_failed; then 13295 13296 echo 1 > $at_status_file 13297 exit 1 13298 fi 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 13375 cat >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. */ 13404 typedef int semantic_value; 13405 13406 static semantic_value global_result = 0; 13407 static int global_count = 0; 13408 %} 13409 13410 /* Exercise %union. */ 13411 %union 13412 { 13413 semantic_value ival; 13414 }; 13415 13416 %{ 13417 static int power (int base, int exponent); 13418 /* yyerror receives the location if: 13419 - %location & %pure & %glr 13420 - %location & %pure & %yacc & %parse-param. */ 13421 static void yyerror ( 13422 13423 const char *s 13424 ); 13425 static int yylex (void); 13426 static int get_char (void); 13427 static 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 %% 13445 input: 13446 line 13447 | input line { } 13448 ; 13449 13450 line: 13451 '\n' 13452 | exp '\n' { USE ($1); } 13453 ; 13454 13455 exp: 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. */ 13476 static FILE *input; 13477 13478 static void 13479 yyerror ( 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 13499 static YYLTYPE last_yylloc; 13500 13501 static int 13502 get_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 13520 static void 13521 unget_char ( int c) 13522 { 13523 ; 13524 13525 /* Wrong when C == `\n'. */ 13526 (yylloc) = last_yylloc; 13527 13528 ungetc (c, input); 13529 } 13530 13531 static int 13532 read_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 13564 static int 13565 yylex (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 13608 static int 13609 power (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 13620 int 13621 main (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 13658 echo "calc.at:553: bison -o calc.c calc.y" 13659 echo calc.at:553 >$at_check_line_file 13660 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 13661 at_status=$? 13662 grep '^ *+' $at_stder1 >&2 13663 grep -v '^ *+' $at_stder1 >$at_stderr 13664 at_failed=false 13665 $at_diff $at_devnull $at_stderr || at_failed=: 13666 $at_diff $at_devnull $at_stdout || at_failed=: 13667 case $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=:;; 13673 esac 13674 if $at_failed; then 13675 13676 echo 1 > $at_status_file 13677 exit 1 13678 fi 13679 13680 $at_traceon 13681 13682 $at_traceoff 13683 echo "calc.at:553: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 13684 echo calc.at:553 >$at_check_line_file 13685 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 13686 at_status=$? 13687 grep '^ *+' $at_stder1 >&2 13688 grep -v '^ *+' $at_stder1 >$at_stderr 13689 at_failed=false 13690 echo stderr:; cat $at_stderr 13691 echo stdout:; cat $at_stdout 13692 case $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=:;; 13698 esac 13699 if $at_failed; then 13700 13701 echo 1 > $at_status_file 13702 exit 1 13703 fi 13704 13705 $at_traceon 13706 13707 13708 # Test the priorities. 13709 cat >input <<'_ATEOF' 13710 1 + 2 * 3 = 7 13711 1 + 2 * -3 = -5 13712 13713 -1^2 = -1 13714 (-1)^2 = 1 13715 13716 ---1 = -1 13717 13718 1 - 2 - 3 = -4 13719 1 - (2 - 3) = 2 13720 13721 2^2^3 = 256 13722 (2^2)^3 = 64 13723 _ATEOF 13724 13725 $at_traceoff 13726 echo "calc.at:553: \$PREPARSER ./calc input" 13727 echo calc.at:553 >$at_check_line_file 13728 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 13729 at_status=$? 13730 grep '^ *+' $at_stder1 >&2 13731 grep -v '^ *+' $at_stder1 >$at_stderr 13732 at_failed=false 13733 echo stderr:; tee stderr <$at_stderr 13734 $at_diff $at_devnull $at_stdout || at_failed=: 13735 case $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=:;; 13741 esac 13742 if $at_failed; then 13743 13744 echo 1 > $at_status_file 13745 exit 1 13746 fi 13747 13748 $at_traceon 13749 13750 13751 13752 # Some syntax errors. 13753 cat >input <<'_ATEOF' 13754 0 0 13755 _ATEOF 13756 13757 $at_traceoff 13758 echo "calc.at:553: \$PREPARSER ./calc input" 13759 echo calc.at:553 >$at_check_line_file 13760 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 13761 at_status=$? 13762 grep '^ *+' $at_stder1 >&2 13763 grep -v '^ *+' $at_stder1 >$at_stderr 13764 at_failed=false 13765 echo stderr:; tee stderr <$at_stderr 13766 $at_diff $at_devnull $at_stdout || at_failed=: 13767 case $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=:;; 13773 esac 13774 if $at_failed; then 13775 13776 echo 1 > $at_status_file 13777 exit 1 13778 fi 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. 13786 sed '/^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 13799 mv at-stderr stderr 13800 # 2. Create the reference error message. 13801 cat >expout <<'_ATEOF' 13802 1.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. 13808 sed 's/syntax error, .*$/syntax error/' expout >at-expout 13809 mv at-expout expout 13810 # 5. Check 13811 $at_traceoff 13812 echo "calc.at:553: cat stderr" 13813 echo calc.at:553 >$at_check_line_file 13814 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 13815 at_status=$? 13816 grep '^ *+' $at_stder1 >&2 13817 grep -v '^ *+' $at_stder1 >$at_stderr 13818 at_failed=false 13819 $at_diff $at_devnull $at_stderr || at_failed=: 13820 $at_diff expout $at_stdout || at_failed=: 13821 case $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=:;; 13827 esac 13828 if $at_failed; then 13829 13830 echo 1 > $at_status_file 13831 exit 1 13832 fi 13833 13834 $at_traceon 13835 13836 13837 cat >input <<'_ATEOF' 13838 1//2 13839 _ATEOF 13840 13841 $at_traceoff 13842 echo "calc.at:553: \$PREPARSER ./calc input" 13843 echo calc.at:553 >$at_check_line_file 13844 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 13845 at_status=$? 13846 grep '^ *+' $at_stder1 >&2 13847 grep -v '^ *+' $at_stder1 >$at_stderr 13848 at_failed=false 13849 echo stderr:; tee stderr <$at_stderr 13850 $at_diff $at_devnull $at_stdout || at_failed=: 13851 case $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=:;; 13857 esac 13858 if $at_failed; then 13859 13860 echo 1 > $at_status_file 13861 exit 1 13862 fi 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. 13870 sed '/^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 13883 mv at-stderr stderr 13884 # 2. Create the reference error message. 13885 cat >expout <<'_ATEOF' 13886 1.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. 13892 sed 's/syntax error, .*$/syntax error/' expout >at-expout 13893 mv at-expout expout 13894 # 5. Check 13895 $at_traceoff 13896 echo "calc.at:553: cat stderr" 13897 echo calc.at:553 >$at_check_line_file 13898 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 13899 at_status=$? 13900 grep '^ *+' $at_stder1 >&2 13901 grep -v '^ *+' $at_stder1 >$at_stderr 13902 at_failed=false 13903 $at_diff $at_devnull $at_stderr || at_failed=: 13904 $at_diff expout $at_stdout || at_failed=: 13905 case $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=:;; 13911 esac 13912 if $at_failed; then 13913 13914 echo 1 > $at_status_file 13915 exit 1 13916 fi 13917 13918 $at_traceon 13919 13920 13921 cat >input <<'_ATEOF' 13922 error 13923 _ATEOF 13924 13925 $at_traceoff 13926 echo "calc.at:553: \$PREPARSER ./calc input" 13927 echo calc.at:553 >$at_check_line_file 13928 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 13929 at_status=$? 13930 grep '^ *+' $at_stder1 >&2 13931 grep -v '^ *+' $at_stder1 >$at_stderr 13932 at_failed=false 13933 echo stderr:; tee stderr <$at_stderr 13934 $at_diff $at_devnull $at_stdout || at_failed=: 13935 case $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=:;; 13941 esac 13942 if $at_failed; then 13943 13944 echo 1 > $at_status_file 13945 exit 1 13946 fi 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. 13954 sed '/^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 13967 mv at-stderr stderr 13968 # 2. Create the reference error message. 13969 cat >expout <<'_ATEOF' 13970 1.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. 13976 sed 's/syntax error, .*$/syntax error/' expout >at-expout 13977 mv at-expout expout 13978 # 5. Check 13979 $at_traceoff 13980 echo "calc.at:553: cat stderr" 13981 echo calc.at:553 >$at_check_line_file 13982 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 13983 at_status=$? 13984 grep '^ *+' $at_stder1 >&2 13985 grep -v '^ *+' $at_stder1 >$at_stderr 13986 at_failed=false 13987 $at_diff $at_devnull $at_stderr || at_failed=: 13988 $at_diff expout $at_stdout || at_failed=: 13989 case $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=:;; 13995 esac 13996 if $at_failed; then 13997 13998 echo 1 > $at_status_file 13999 exit 1 14000 fi 14001 14002 $at_traceon 14003 14004 14005 cat >input <<'_ATEOF' 14006 1 = 2 = 3 14007 _ATEOF 14008 14009 $at_traceoff 14010 echo "calc.at:553: \$PREPARSER ./calc input" 14011 echo calc.at:553 >$at_check_line_file 14012 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 14013 at_status=$? 14014 grep '^ *+' $at_stder1 >&2 14015 grep -v '^ *+' $at_stder1 >$at_stderr 14016 at_failed=false 14017 echo stderr:; tee stderr <$at_stderr 14018 $at_diff $at_devnull $at_stdout || at_failed=: 14019 case $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=:;; 14025 esac 14026 if $at_failed; then 14027 14028 echo 1 > $at_status_file 14029 exit 1 14030 fi 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. 14038 sed '/^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 14051 mv at-stderr stderr 14052 # 2. Create the reference error message. 14053 cat >expout <<'_ATEOF' 14054 1.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. 14060 sed 's/syntax error, .*$/syntax error/' expout >at-expout 14061 mv at-expout expout 14062 # 5. Check 14063 $at_traceoff 14064 echo "calc.at:553: cat stderr" 14065 echo calc.at:553 >$at_check_line_file 14066 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 14067 at_status=$? 14068 grep '^ *+' $at_stder1 >&2 14069 grep -v '^ *+' $at_stder1 >$at_stderr 14070 at_failed=false 14071 $at_diff $at_devnull $at_stderr || at_failed=: 14072 $at_diff expout $at_stdout || at_failed=: 14073 case $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=:;; 14079 esac 14080 if $at_failed; then 14081 14082 echo 1 > $at_status_file 14083 exit 1 14084 fi 14085 14086 $at_traceon 14087 14088 14089 cat >input <<'_ATEOF' 14090 14091 +1 14092 _ATEOF 14093 14094 $at_traceoff 14095 echo "calc.at:553: \$PREPARSER ./calc input" 14096 echo calc.at:553 >$at_check_line_file 14097 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 14098 at_status=$? 14099 grep '^ *+' $at_stder1 >&2 14100 grep -v '^ *+' $at_stder1 >$at_stderr 14101 at_failed=false 14102 echo stderr:; tee stderr <$at_stderr 14103 $at_diff $at_devnull $at_stdout || at_failed=: 14104 case $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=:;; 14110 esac 14111 if $at_failed; then 14112 14113 echo 1 > $at_status_file 14114 exit 1 14115 fi 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. 14123 sed '/^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 14136 mv at-stderr stderr 14137 # 2. Create the reference error message. 14138 cat >expout <<'_ATEOF' 14139 2.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. 14145 sed 's/syntax error, .*$/syntax error/' expout >at-expout 14146 mv at-expout expout 14147 # 5. Check 14148 $at_traceoff 14149 echo "calc.at:553: cat stderr" 14150 echo calc.at:553 >$at_check_line_file 14151 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 14152 at_status=$? 14153 grep '^ *+' $at_stder1 >&2 14154 grep -v '^ *+' $at_stder1 >$at_stderr 14155 at_failed=false 14156 $at_diff $at_devnull $at_stderr || at_failed=: 14157 $at_diff expout $at_stdout || at_failed=: 14158 case $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=:;; 14164 esac 14165 if $at_failed; then 14166 14167 echo 1 > $at_status_file 14168 exit 1 14169 fi 14170 14171 $at_traceon 14172 14173 14174 # Exercise error messages with EOF: work on an empty file. 14175 $at_traceoff 14176 echo "calc.at:553: \$PREPARSER ./calc /dev/null" 14177 echo calc.at:553 >$at_check_line_file 14178 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 14179 at_status=$? 14180 grep '^ *+' $at_stder1 >&2 14181 grep -v '^ *+' $at_stder1 >$at_stderr 14182 at_failed=false 14183 echo stderr:; tee stderr <$at_stderr 14184 $at_diff $at_devnull $at_stdout || at_failed=: 14185 case $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=:;; 14191 esac 14192 if $at_failed; then 14193 14194 echo 1 > $at_status_file 14195 exit 1 14196 fi 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. 14204 sed '/^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 14217 mv at-stderr stderr 14218 # 2. Create the reference error message. 14219 cat >expout <<'_ATEOF' 14220 1.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. 14226 sed 's/syntax error, .*$/syntax error/' expout >at-expout 14227 mv at-expout expout 14228 # 5. Check 14229 $at_traceoff 14230 echo "calc.at:553: cat stderr" 14231 echo calc.at:553 >$at_check_line_file 14232 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 14233 at_status=$? 14234 grep '^ *+' $at_stder1 >&2 14235 grep -v '^ *+' $at_stder1 >$at_stderr 14236 at_failed=false 14237 $at_diff $at_devnull $at_stderr || at_failed=: 14238 $at_diff expout $at_stdout || at_failed=: 14239 case $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=:;; 14245 esac 14246 if $at_failed; then 14247 14248 echo 1 > $at_status_file 14249 exit 1 14250 fi 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 # 14272 cat >input <<'_ATEOF' 14273 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 14274 _ATEOF 14275 14276 $at_traceoff 14277 echo "calc.at:553: \$PREPARSER ./calc input" 14278 echo calc.at:553 >$at_check_line_file 14279 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 14280 at_status=$? 14281 grep '^ *+' $at_stder1 >&2 14282 grep -v '^ *+' $at_stder1 >$at_stderr 14283 at_failed=false 14284 echo stderr:; tee stderr <$at_stderr 14285 $at_diff $at_devnull $at_stdout || at_failed=: 14286 case $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=:;; 14292 esac 14293 if $at_failed; then 14294 14295 echo 1 > $at_status_file 14296 exit 1 14297 fi 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. 14305 sed '/^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 14318 mv at-stderr stderr 14319 # 2. Create the reference error message. 14320 cat >expout <<'_ATEOF' 14321 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 14322 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 14323 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 14324 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 14325 calc: 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. 14331 sed 's/syntax error, .*$/syntax error/' expout >at-expout 14332 mv at-expout expout 14333 # 5. Check 14334 $at_traceoff 14335 echo "calc.at:553: cat stderr" 14336 echo calc.at:553 >$at_check_line_file 14337 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 14338 at_status=$? 14339 grep '^ *+' $at_stder1 >&2 14340 grep -v '^ *+' $at_stder1 >$at_stderr 14341 at_failed=false 14342 $at_diff $at_devnull $at_stderr || at_failed=: 14343 $at_diff expout $at_stdout || at_failed=: 14344 case $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=:;; 14350 esac 14351 if $at_failed; then 14352 14353 echo 1 > $at_status_file 14354 exit 1 14355 fi 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. 14363 cat >input <<'_ATEOF' 14364 (!) + (0 0) = 1 14365 _ATEOF 14366 14367 $at_traceoff 14368 echo "calc.at:553: \$PREPARSER ./calc input" 14369 echo calc.at:553 >$at_check_line_file 14370 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 14371 at_status=$? 14372 grep '^ *+' $at_stder1 >&2 14373 grep -v '^ *+' $at_stder1 >$at_stderr 14374 at_failed=false 14375 echo stderr:; tee stderr <$at_stderr 14376 $at_diff $at_devnull $at_stdout || at_failed=: 14377 case $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=:;; 14383 esac 14384 if $at_failed; then 14385 14386 echo 1 > $at_status_file 14387 exit 1 14388 fi 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. 14396 sed '/^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 14409 mv at-stderr stderr 14410 # 2. Create the reference error message. 14411 cat >expout <<'_ATEOF' 14412 1.9: syntax error, unexpected number 14413 calc: 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. 14419 sed 's/syntax error, .*$/syntax error/' expout >at-expout 14420 mv at-expout expout 14421 # 5. Check 14422 $at_traceoff 14423 echo "calc.at:553: cat stderr" 14424 echo calc.at:553 >$at_check_line_file 14425 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 14426 at_status=$? 14427 grep '^ *+' $at_stder1 >&2 14428 grep -v '^ *+' $at_stder1 >$at_stderr 14429 at_failed=false 14430 $at_diff $at_devnull $at_stderr || at_failed=: 14431 $at_diff expout $at_stdout || at_failed=: 14432 case $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=:;; 14438 esac 14439 if $at_failed; then 14440 14441 echo 1 > $at_status_file 14442 exit 1 14443 fi 14444 14445 $at_traceon 14446 14447 14448 cat >input <<'_ATEOF' 14449 (- *) + (0 0) = 1 14450 _ATEOF 14451 14452 $at_traceoff 14453 echo "calc.at:553: \$PREPARSER ./calc input" 14454 echo calc.at:553 >$at_check_line_file 14455 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 14456 at_status=$? 14457 grep '^ *+' $at_stder1 >&2 14458 grep -v '^ *+' $at_stder1 >$at_stderr 14459 at_failed=false 14460 echo stderr:; tee stderr <$at_stderr 14461 $at_diff $at_devnull $at_stdout || at_failed=: 14462 case $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=:;; 14468 esac 14469 if $at_failed; then 14470 14471 echo 1 > $at_status_file 14472 exit 1 14473 fi 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. 14481 sed '/^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 14494 mv at-stderr stderr 14495 # 2. Create the reference error message. 14496 cat >expout <<'_ATEOF' 14497 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 14498 1.11: syntax error, unexpected number 14499 calc: 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. 14505 sed 's/syntax error, .*$/syntax error/' expout >at-expout 14506 mv at-expout expout 14507 # 5. Check 14508 $at_traceoff 14509 echo "calc.at:553: cat stderr" 14510 echo calc.at:553 >$at_check_line_file 14511 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 14512 at_status=$? 14513 grep '^ *+' $at_stder1 >&2 14514 grep -v '^ *+' $at_stder1 >$at_stderr 14515 at_failed=false 14516 $at_diff $at_devnull $at_stderr || at_failed=: 14517 $at_diff expout $at_stdout || at_failed=: 14518 case $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=:;; 14524 esac 14525 if $at_failed; then 14526 14527 echo 1 > $at_status_file 14528 exit 1 14529 fi 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 14606 cat >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. */ 14635 typedef int semantic_value; 14636 14637 static semantic_value global_result = 0; 14638 static int global_count = 0; 14639 %} 14640 14641 /* Exercise %union. */ 14642 %union 14643 { 14644 semantic_value ival; 14645 }; 14646 14647 %{ 14648 static int power (int base, int exponent); 14649 /* yyerror receives the location if: 14650 - %location & %pure & %glr 14651 - %location & %pure & %yacc & %parse-param. */ 14652 static void yyerror ( 14653 14654 const char *s 14655 ); 14656 static int yylex (void); 14657 static int get_char (void); 14658 static 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 %% 14676 input: 14677 line 14678 | input line { } 14679 ; 14680 14681 line: 14682 '\n' 14683 | exp '\n' { USE ($1); } 14684 ; 14685 14686 exp: 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. */ 14707 static FILE *input; 14708 14709 static void 14710 yyerror ( 14711 14712 const char *s) 14713 { 14714 14715 14716 fprintf (stderr, "%s\n", s); 14717 } 14718 14719 14720 14721 static int 14722 get_char (void) 14723 { 14724 int res = getc (input); 14725 ; 14726 14727 return res; 14728 } 14729 14730 14731 static void 14732 unget_char ( int c) 14733 { 14734 ; 14735 14736 ungetc (c, input); 14737 } 14738 14739 static int 14740 read_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 14772 static int 14773 yylex (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 14808 static int 14809 power (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 14820 int 14821 main (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 14858 echo "calc.at:554: bison -o calc.c calc.y" 14859 echo calc.at:554 >$at_check_line_file 14860 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 14861 at_status=$? 14862 grep '^ *+' $at_stder1 >&2 14863 grep -v '^ *+' $at_stder1 >$at_stderr 14864 at_failed=false 14865 $at_diff $at_devnull $at_stderr || at_failed=: 14866 $at_diff $at_devnull $at_stdout || at_failed=: 14867 case $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=:;; 14873 esac 14874 if $at_failed; then 14875 14876 echo 1 > $at_status_file 14877 exit 1 14878 fi 14879 14880 $at_traceon 14881 14882 $at_traceoff 14883 echo "calc.at:554: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 14884 echo calc.at:554 >$at_check_line_file 14885 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 14886 at_status=$? 14887 grep '^ *+' $at_stder1 >&2 14888 grep -v '^ *+' $at_stder1 >$at_stderr 14889 at_failed=false 14890 echo stderr:; cat $at_stderr 14891 echo stdout:; cat $at_stdout 14892 case $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=:;; 14898 esac 14899 if $at_failed; then 14900 14901 echo 1 > $at_status_file 14902 exit 1 14903 fi 14904 14905 $at_traceon 14906 14907 14908 # Test the priorities. 14909 cat >input <<'_ATEOF' 14910 1 + 2 * 3 = 7 14911 1 + 2 * -3 = -5 14912 14913 -1^2 = -1 14914 (-1)^2 = 1 14915 14916 ---1 = -1 14917 14918 1 - 2 - 3 = -4 14919 1 - (2 - 3) = 2 14920 14921 2^2^3 = 256 14922 (2^2)^3 = 64 14923 _ATEOF 14924 14925 $at_traceoff 14926 echo "calc.at:554: \$PREPARSER ./calc input" 14927 echo calc.at:554 >$at_check_line_file 14928 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 14929 at_status=$? 14930 grep '^ *+' $at_stder1 >&2 14931 grep -v '^ *+' $at_stder1 >$at_stderr 14932 at_failed=false 14933 echo stderr:; tee stderr <$at_stderr 14934 $at_diff $at_devnull $at_stdout || at_failed=: 14935 case $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=:;; 14941 esac 14942 if $at_failed; then 14943 14944 echo 1 > $at_status_file 14945 exit 1 14946 fi 14947 14948 $at_traceon 14949 14950 14951 14952 # Some syntax errors. 14953 cat >input <<'_ATEOF' 14954 0 0 14955 _ATEOF 14956 14957 $at_traceoff 14958 echo "calc.at:554: \$PREPARSER ./calc input" 14959 echo calc.at:554 >$at_check_line_file 14960 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 14961 at_status=$? 14962 grep '^ *+' $at_stder1 >&2 14963 grep -v '^ *+' $at_stder1 >$at_stderr 14964 at_failed=false 14965 echo stderr:; tee stderr <$at_stderr 14966 $at_diff $at_devnull $at_stdout || at_failed=: 14967 case $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=:;; 14973 esac 14974 if $at_failed; then 14975 14976 echo 1 > $at_status_file 14977 exit 1 14978 fi 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. 14986 sed '/^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 14999 mv at-stderr stderr 15000 # 2. Create the reference error message. 15001 cat >expout <<'_ATEOF' 15002 1.2: syntax error, unexpected number 15003 _ATEOF 15004 15005 # 3. If locations are not used, remove them. 15006 sed 's/^[-0-9.]*: //' expout >at-expout 15007 mv at-expout expout 15008 # 4. If error-verbose is not used, strip the`, unexpected....' part. 15009 sed 's/syntax error, .*$/syntax error/' expout >at-expout 15010 mv at-expout expout 15011 # 5. Check 15012 $at_traceoff 15013 echo "calc.at:554: cat stderr" 15014 echo calc.at:554 >$at_check_line_file 15015 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 15016 at_status=$? 15017 grep '^ *+' $at_stder1 >&2 15018 grep -v '^ *+' $at_stder1 >$at_stderr 15019 at_failed=false 15020 $at_diff $at_devnull $at_stderr || at_failed=: 15021 $at_diff expout $at_stdout || at_failed=: 15022 case $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=:;; 15028 esac 15029 if $at_failed; then 15030 15031 echo 1 > $at_status_file 15032 exit 1 15033 fi 15034 15035 $at_traceon 15036 15037 15038 cat >input <<'_ATEOF' 15039 1//2 15040 _ATEOF 15041 15042 $at_traceoff 15043 echo "calc.at:554: \$PREPARSER ./calc input" 15044 echo calc.at:554 >$at_check_line_file 15045 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 15046 at_status=$? 15047 grep '^ *+' $at_stder1 >&2 15048 grep -v '^ *+' $at_stder1 >$at_stderr 15049 at_failed=false 15050 echo stderr:; tee stderr <$at_stderr 15051 $at_diff $at_devnull $at_stdout || at_failed=: 15052 case $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=:;; 15058 esac 15059 if $at_failed; then 15060 15061 echo 1 > $at_status_file 15062 exit 1 15063 fi 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. 15071 sed '/^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 15084 mv at-stderr stderr 15085 # 2. Create the reference error message. 15086 cat >expout <<'_ATEOF' 15087 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 15088 _ATEOF 15089 15090 # 3. If locations are not used, remove them. 15091 sed 's/^[-0-9.]*: //' expout >at-expout 15092 mv at-expout expout 15093 # 4. If error-verbose is not used, strip the`, unexpected....' part. 15094 sed 's/syntax error, .*$/syntax error/' expout >at-expout 15095 mv at-expout expout 15096 # 5. Check 15097 $at_traceoff 15098 echo "calc.at:554: cat stderr" 15099 echo calc.at:554 >$at_check_line_file 15100 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 15101 at_status=$? 15102 grep '^ *+' $at_stder1 >&2 15103 grep -v '^ *+' $at_stder1 >$at_stderr 15104 at_failed=false 15105 $at_diff $at_devnull $at_stderr || at_failed=: 15106 $at_diff expout $at_stdout || at_failed=: 15107 case $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=:;; 15113 esac 15114 if $at_failed; then 15115 15116 echo 1 > $at_status_file 15117 exit 1 15118 fi 15119 15120 $at_traceon 15121 15122 15123 cat >input <<'_ATEOF' 15124 error 15125 _ATEOF 15126 15127 $at_traceoff 15128 echo "calc.at:554: \$PREPARSER ./calc input" 15129 echo calc.at:554 >$at_check_line_file 15130 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 15131 at_status=$? 15132 grep '^ *+' $at_stder1 >&2 15133 grep -v '^ *+' $at_stder1 >$at_stderr 15134 at_failed=false 15135 echo stderr:; tee stderr <$at_stderr 15136 $at_diff $at_devnull $at_stdout || at_failed=: 15137 case $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=:;; 15143 esac 15144 if $at_failed; then 15145 15146 echo 1 > $at_status_file 15147 exit 1 15148 fi 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. 15156 sed '/^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 15169 mv at-stderr stderr 15170 # 2. Create the reference error message. 15171 cat >expout <<'_ATEOF' 15172 1.0: syntax error, unexpected $undefined 15173 _ATEOF 15174 15175 # 3. If locations are not used, remove them. 15176 sed 's/^[-0-9.]*: //' expout >at-expout 15177 mv at-expout expout 15178 # 4. If error-verbose is not used, strip the`, unexpected....' part. 15179 sed 's/syntax error, .*$/syntax error/' expout >at-expout 15180 mv at-expout expout 15181 # 5. Check 15182 $at_traceoff 15183 echo "calc.at:554: cat stderr" 15184 echo calc.at:554 >$at_check_line_file 15185 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 15186 at_status=$? 15187 grep '^ *+' $at_stder1 >&2 15188 grep -v '^ *+' $at_stder1 >$at_stderr 15189 at_failed=false 15190 $at_diff $at_devnull $at_stderr || at_failed=: 15191 $at_diff expout $at_stdout || at_failed=: 15192 case $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=:;; 15198 esac 15199 if $at_failed; then 15200 15201 echo 1 > $at_status_file 15202 exit 1 15203 fi 15204 15205 $at_traceon 15206 15207 15208 cat >input <<'_ATEOF' 15209 1 = 2 = 3 15210 _ATEOF 15211 15212 $at_traceoff 15213 echo "calc.at:554: \$PREPARSER ./calc input" 15214 echo calc.at:554 >$at_check_line_file 15215 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 15216 at_status=$? 15217 grep '^ *+' $at_stder1 >&2 15218 grep -v '^ *+' $at_stder1 >$at_stderr 15219 at_failed=false 15220 echo stderr:; tee stderr <$at_stderr 15221 $at_diff $at_devnull $at_stdout || at_failed=: 15222 case $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=:;; 15228 esac 15229 if $at_failed; then 15230 15231 echo 1 > $at_status_file 15232 exit 1 15233 fi 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. 15241 sed '/^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 15254 mv at-stderr stderr 15255 # 2. Create the reference error message. 15256 cat >expout <<'_ATEOF' 15257 1.6: syntax error, unexpected '=' 15258 _ATEOF 15259 15260 # 3. If locations are not used, remove them. 15261 sed 's/^[-0-9.]*: //' expout >at-expout 15262 mv at-expout expout 15263 # 4. If error-verbose is not used, strip the`, unexpected....' part. 15264 sed 's/syntax error, .*$/syntax error/' expout >at-expout 15265 mv at-expout expout 15266 # 5. Check 15267 $at_traceoff 15268 echo "calc.at:554: cat stderr" 15269 echo calc.at:554 >$at_check_line_file 15270 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 15271 at_status=$? 15272 grep '^ *+' $at_stder1 >&2 15273 grep -v '^ *+' $at_stder1 >$at_stderr 15274 at_failed=false 15275 $at_diff $at_devnull $at_stderr || at_failed=: 15276 $at_diff expout $at_stdout || at_failed=: 15277 case $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=:;; 15283 esac 15284 if $at_failed; then 15285 15286 echo 1 > $at_status_file 15287 exit 1 15288 fi 15289 15290 $at_traceon 15291 15292 15293 cat >input <<'_ATEOF' 15294 15295 +1 15296 _ATEOF 15297 15298 $at_traceoff 15299 echo "calc.at:554: \$PREPARSER ./calc input" 15300 echo calc.at:554 >$at_check_line_file 15301 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 15302 at_status=$? 15303 grep '^ *+' $at_stder1 >&2 15304 grep -v '^ *+' $at_stder1 >$at_stderr 15305 at_failed=false 15306 echo stderr:; tee stderr <$at_stderr 15307 $at_diff $at_devnull $at_stdout || at_failed=: 15308 case $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=:;; 15314 esac 15315 if $at_failed; then 15316 15317 echo 1 > $at_status_file 15318 exit 1 15319 fi 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. 15327 sed '/^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 15340 mv at-stderr stderr 15341 # 2. Create the reference error message. 15342 cat >expout <<'_ATEOF' 15343 2.0: syntax error, unexpected '+' 15344 _ATEOF 15345 15346 # 3. If locations are not used, remove them. 15347 sed 's/^[-0-9.]*: //' expout >at-expout 15348 mv at-expout expout 15349 # 4. If error-verbose is not used, strip the`, unexpected....' part. 15350 sed 's/syntax error, .*$/syntax error/' expout >at-expout 15351 mv at-expout expout 15352 # 5. Check 15353 $at_traceoff 15354 echo "calc.at:554: cat stderr" 15355 echo calc.at:554 >$at_check_line_file 15356 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 15357 at_status=$? 15358 grep '^ *+' $at_stder1 >&2 15359 grep -v '^ *+' $at_stder1 >$at_stderr 15360 at_failed=false 15361 $at_diff $at_devnull $at_stderr || at_failed=: 15362 $at_diff expout $at_stdout || at_failed=: 15363 case $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=:;; 15369 esac 15370 if $at_failed; then 15371 15372 echo 1 > $at_status_file 15373 exit 1 15374 fi 15375 15376 $at_traceon 15377 15378 15379 # Exercise error messages with EOF: work on an empty file. 15380 $at_traceoff 15381 echo "calc.at:554: \$PREPARSER ./calc /dev/null" 15382 echo calc.at:554 >$at_check_line_file 15383 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 15384 at_status=$? 15385 grep '^ *+' $at_stder1 >&2 15386 grep -v '^ *+' $at_stder1 >$at_stderr 15387 at_failed=false 15388 echo stderr:; tee stderr <$at_stderr 15389 $at_diff $at_devnull $at_stdout || at_failed=: 15390 case $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=:;; 15396 esac 15397 if $at_failed; then 15398 15399 echo 1 > $at_status_file 15400 exit 1 15401 fi 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. 15409 sed '/^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 15422 mv at-stderr stderr 15423 # 2. Create the reference error message. 15424 cat >expout <<'_ATEOF' 15425 1.0: syntax error, unexpected end of input 15426 _ATEOF 15427 15428 # 3. If locations are not used, remove them. 15429 sed 's/^[-0-9.]*: //' expout >at-expout 15430 mv at-expout expout 15431 # 4. If error-verbose is not used, strip the`, unexpected....' part. 15432 sed 's/syntax error, .*$/syntax error/' expout >at-expout 15433 mv at-expout expout 15434 # 5. Check 15435 $at_traceoff 15436 echo "calc.at:554: cat stderr" 15437 echo calc.at:554 >$at_check_line_file 15438 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 15439 at_status=$? 15440 grep '^ *+' $at_stder1 >&2 15441 grep -v '^ *+' $at_stder1 >$at_stderr 15442 at_failed=false 15443 $at_diff $at_devnull $at_stderr || at_failed=: 15444 $at_diff expout $at_stdout || at_failed=: 15445 case $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=:;; 15451 esac 15452 if $at_failed; then 15453 15454 echo 1 > $at_status_file 15455 exit 1 15456 fi 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 # 15478 cat >input <<'_ATEOF' 15479 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 15480 _ATEOF 15481 15482 $at_traceoff 15483 echo "calc.at:554: \$PREPARSER ./calc input" 15484 echo calc.at:554 >$at_check_line_file 15485 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 15486 at_status=$? 15487 grep '^ *+' $at_stder1 >&2 15488 grep -v '^ *+' $at_stder1 >$at_stderr 15489 at_failed=false 15490 echo stderr:; tee stderr <$at_stderr 15491 $at_diff $at_devnull $at_stdout || at_failed=: 15492 case $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=:;; 15498 esac 15499 if $at_failed; then 15500 15501 echo 1 > $at_status_file 15502 exit 1 15503 fi 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. 15511 sed '/^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 15524 mv at-stderr stderr 15525 # 2. Create the reference error message. 15526 cat >expout <<'_ATEOF' 15527 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 15528 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 15529 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 15530 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 15531 calc: error: 4444 != 1 15532 _ATEOF 15533 15534 # 3. If locations are not used, remove them. 15535 sed 's/^[-0-9.]*: //' expout >at-expout 15536 mv at-expout expout 15537 # 4. If error-verbose is not used, strip the`, unexpected....' part. 15538 sed 's/syntax error, .*$/syntax error/' expout >at-expout 15539 mv at-expout expout 15540 # 5. Check 15541 $at_traceoff 15542 echo "calc.at:554: cat stderr" 15543 echo calc.at:554 >$at_check_line_file 15544 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 15545 at_status=$? 15546 grep '^ *+' $at_stder1 >&2 15547 grep -v '^ *+' $at_stder1 >$at_stderr 15548 at_failed=false 15549 $at_diff $at_devnull $at_stderr || at_failed=: 15550 $at_diff expout $at_stdout || at_failed=: 15551 case $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=:;; 15557 esac 15558 if $at_failed; then 15559 15560 echo 1 > $at_status_file 15561 exit 1 15562 fi 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. 15570 cat >input <<'_ATEOF' 15571 (!) + (0 0) = 1 15572 _ATEOF 15573 15574 $at_traceoff 15575 echo "calc.at:554: \$PREPARSER ./calc input" 15576 echo calc.at:554 >$at_check_line_file 15577 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 15578 at_status=$? 15579 grep '^ *+' $at_stder1 >&2 15580 grep -v '^ *+' $at_stder1 >$at_stderr 15581 at_failed=false 15582 echo stderr:; tee stderr <$at_stderr 15583 $at_diff $at_devnull $at_stdout || at_failed=: 15584 case $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=:;; 15590 esac 15591 if $at_failed; then 15592 15593 echo 1 > $at_status_file 15594 exit 1 15595 fi 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. 15603 sed '/^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 15616 mv at-stderr stderr 15617 # 2. Create the reference error message. 15618 cat >expout <<'_ATEOF' 15619 1.9: syntax error, unexpected number 15620 calc: error: 2222 != 1 15621 _ATEOF 15622 15623 # 3. If locations are not used, remove them. 15624 sed 's/^[-0-9.]*: //' expout >at-expout 15625 mv at-expout expout 15626 # 4. If error-verbose is not used, strip the`, unexpected....' part. 15627 sed 's/syntax error, .*$/syntax error/' expout >at-expout 15628 mv at-expout expout 15629 # 5. Check 15630 $at_traceoff 15631 echo "calc.at:554: cat stderr" 15632 echo calc.at:554 >$at_check_line_file 15633 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 15634 at_status=$? 15635 grep '^ *+' $at_stder1 >&2 15636 grep -v '^ *+' $at_stder1 >$at_stderr 15637 at_failed=false 15638 $at_diff $at_devnull $at_stderr || at_failed=: 15639 $at_diff expout $at_stdout || at_failed=: 15640 case $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=:;; 15646 esac 15647 if $at_failed; then 15648 15649 echo 1 > $at_status_file 15650 exit 1 15651 fi 15652 15653 $at_traceon 15654 15655 15656 cat >input <<'_ATEOF' 15657 (- *) + (0 0) = 1 15658 _ATEOF 15659 15660 $at_traceoff 15661 echo "calc.at:554: \$PREPARSER ./calc input" 15662 echo calc.at:554 >$at_check_line_file 15663 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 15664 at_status=$? 15665 grep '^ *+' $at_stder1 >&2 15666 grep -v '^ *+' $at_stder1 >$at_stderr 15667 at_failed=false 15668 echo stderr:; tee stderr <$at_stderr 15669 $at_diff $at_devnull $at_stdout || at_failed=: 15670 case $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=:;; 15676 esac 15677 if $at_failed; then 15678 15679 echo 1 > $at_status_file 15680 exit 1 15681 fi 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. 15689 sed '/^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 15702 mv at-stderr stderr 15703 # 2. Create the reference error message. 15704 cat >expout <<'_ATEOF' 15705 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 15706 1.11: syntax error, unexpected number 15707 calc: error: 2222 != 1 15708 _ATEOF 15709 15710 # 3. If locations are not used, remove them. 15711 sed 's/^[-0-9.]*: //' expout >at-expout 15712 mv at-expout expout 15713 # 4. If error-verbose is not used, strip the`, unexpected....' part. 15714 sed 's/syntax error, .*$/syntax error/' expout >at-expout 15715 mv at-expout expout 15716 # 5. Check 15717 $at_traceoff 15718 echo "calc.at:554: cat stderr" 15719 echo calc.at:554 >$at_check_line_file 15720 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 15721 at_status=$? 15722 grep '^ *+' $at_stder1 >&2 15723 grep -v '^ *+' $at_stder1 >$at_stderr 15724 at_failed=false 15725 $at_diff $at_devnull $at_stderr || at_failed=: 15726 $at_diff expout $at_stdout || at_failed=: 15727 case $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=:;; 15733 esac 15734 if $at_failed; then 15735 15736 echo 1 > $at_status_file 15737 exit 1 15738 fi 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 15815 cat >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. */ 15844 typedef int semantic_value; 15845 15846 static semantic_value global_result = 0; 15847 static int global_count = 0; 15848 %} 15849 15850 /* Exercise %union. */ 15851 %union 15852 { 15853 semantic_value ival; 15854 }; 15855 15856 %{ 15857 static int power (int base, int exponent); 15858 /* yyerror receives the location if: 15859 - %location & %pure & %glr 15860 - %location & %pure & %yacc & %parse-param. */ 15861 static void yyerror ( 15862 15863 const char *s 15864 ); 15865 static int yylex (void); 15866 static int get_char (void); 15867 static 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 %% 15885 input: 15886 line 15887 | input line { } 15888 ; 15889 15890 line: 15891 '\n' 15892 | exp '\n' { USE ($1); } 15893 ; 15894 15895 exp: 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. */ 15916 static FILE *input; 15917 15918 static void 15919 yyerror ( 15920 15921 const char *s) 15922 { 15923 15924 15925 fprintf (stderr, "%s\n", s); 15926 } 15927 15928 15929 15930 static int 15931 get_char (void) 15932 { 15933 int res = getc (input); 15934 ; 15935 15936 return res; 15937 } 15938 15939 15940 static void 15941 unget_char ( int c) 15942 { 15943 ; 15944 15945 ungetc (c, input); 15946 } 15947 15948 static int 15949 read_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 15981 static int 15982 yylex (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 16017 static int 16018 power (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 16029 int 16030 main (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 16067 echo "calc.at:555: bison -o calc.c calc.y" 16068 echo calc.at:555 >$at_check_line_file 16069 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 16070 at_status=$? 16071 grep '^ *+' $at_stder1 >&2 16072 grep -v '^ *+' $at_stder1 >$at_stderr 16073 at_failed=false 16074 $at_diff $at_devnull $at_stderr || at_failed=: 16075 $at_diff $at_devnull $at_stdout || at_failed=: 16076 case $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=:;; 16082 esac 16083 if $at_failed; then 16084 16085 echo 1 > $at_status_file 16086 exit 1 16087 fi 16088 16089 $at_traceon 16090 16091 $at_traceoff 16092 echo "calc.at:555: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 16093 echo calc.at:555 >$at_check_line_file 16094 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 16095 at_status=$? 16096 grep '^ *+' $at_stder1 >&2 16097 grep -v '^ *+' $at_stder1 >$at_stderr 16098 at_failed=false 16099 echo stderr:; cat $at_stderr 16100 echo stdout:; cat $at_stdout 16101 case $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=:;; 16107 esac 16108 if $at_failed; then 16109 16110 echo 1 > $at_status_file 16111 exit 1 16112 fi 16113 16114 $at_traceon 16115 16116 16117 # Test the priorities. 16118 cat >input <<'_ATEOF' 16119 1 + 2 * 3 = 7 16120 1 + 2 * -3 = -5 16121 16122 -1^2 = -1 16123 (-1)^2 = 1 16124 16125 ---1 = -1 16126 16127 1 - 2 - 3 = -4 16128 1 - (2 - 3) = 2 16129 16130 2^2^3 = 256 16131 (2^2)^3 = 64 16132 _ATEOF 16133 16134 $at_traceoff 16135 echo "calc.at:555: \$PREPARSER ./calc input" 16136 echo calc.at:555 >$at_check_line_file 16137 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 16138 at_status=$? 16139 grep '^ *+' $at_stder1 >&2 16140 grep -v '^ *+' $at_stder1 >$at_stderr 16141 at_failed=false 16142 echo stderr:; tee stderr <$at_stderr 16143 $at_diff $at_devnull $at_stdout || at_failed=: 16144 case $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=:;; 16150 esac 16151 if $at_failed; then 16152 16153 echo 1 > $at_status_file 16154 exit 1 16155 fi 16156 16157 $at_traceon 16158 16159 16160 16161 # Some syntax errors. 16162 cat >input <<'_ATEOF' 16163 0 0 16164 _ATEOF 16165 16166 $at_traceoff 16167 echo "calc.at:555: \$PREPARSER ./calc input" 16168 echo calc.at:555 >$at_check_line_file 16169 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 16170 at_status=$? 16171 grep '^ *+' $at_stder1 >&2 16172 grep -v '^ *+' $at_stder1 >$at_stderr 16173 at_failed=false 16174 echo stderr:; tee stderr <$at_stderr 16175 $at_diff $at_devnull $at_stdout || at_failed=: 16176 case $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=:;; 16182 esac 16183 if $at_failed; then 16184 16185 echo 1 > $at_status_file 16186 exit 1 16187 fi 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. 16195 sed '/^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 16208 mv at-stderr stderr 16209 # 2. Create the reference error message. 16210 cat >expout <<'_ATEOF' 16211 1.2: syntax error, unexpected number 16212 _ATEOF 16213 16214 # 3. If locations are not used, remove them. 16215 sed 's/^[-0-9.]*: //' expout >at-expout 16216 mv at-expout expout 16217 # 4. If error-verbose is not used, strip the`, unexpected....' part. 16218 sed 's/syntax error, .*$/syntax error/' expout >at-expout 16219 mv at-expout expout 16220 # 5. Check 16221 $at_traceoff 16222 echo "calc.at:555: cat stderr" 16223 echo calc.at:555 >$at_check_line_file 16224 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 16225 at_status=$? 16226 grep '^ *+' $at_stder1 >&2 16227 grep -v '^ *+' $at_stder1 >$at_stderr 16228 at_failed=false 16229 $at_diff $at_devnull $at_stderr || at_failed=: 16230 $at_diff expout $at_stdout || at_failed=: 16231 case $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=:;; 16237 esac 16238 if $at_failed; then 16239 16240 echo 1 > $at_status_file 16241 exit 1 16242 fi 16243 16244 $at_traceon 16245 16246 16247 cat >input <<'_ATEOF' 16248 1//2 16249 _ATEOF 16250 16251 $at_traceoff 16252 echo "calc.at:555: \$PREPARSER ./calc input" 16253 echo calc.at:555 >$at_check_line_file 16254 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 16255 at_status=$? 16256 grep '^ *+' $at_stder1 >&2 16257 grep -v '^ *+' $at_stder1 >$at_stderr 16258 at_failed=false 16259 echo stderr:; tee stderr <$at_stderr 16260 $at_diff $at_devnull $at_stdout || at_failed=: 16261 case $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=:;; 16267 esac 16268 if $at_failed; then 16269 16270 echo 1 > $at_status_file 16271 exit 1 16272 fi 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. 16280 sed '/^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 16293 mv at-stderr stderr 16294 # 2. Create the reference error message. 16295 cat >expout <<'_ATEOF' 16296 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 16297 _ATEOF 16298 16299 # 3. If locations are not used, remove them. 16300 sed 's/^[-0-9.]*: //' expout >at-expout 16301 mv at-expout expout 16302 # 4. If error-verbose is not used, strip the`, unexpected....' part. 16303 sed 's/syntax error, .*$/syntax error/' expout >at-expout 16304 mv at-expout expout 16305 # 5. Check 16306 $at_traceoff 16307 echo "calc.at:555: cat stderr" 16308 echo calc.at:555 >$at_check_line_file 16309 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 16310 at_status=$? 16311 grep '^ *+' $at_stder1 >&2 16312 grep -v '^ *+' $at_stder1 >$at_stderr 16313 at_failed=false 16314 $at_diff $at_devnull $at_stderr || at_failed=: 16315 $at_diff expout $at_stdout || at_failed=: 16316 case $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=:;; 16322 esac 16323 if $at_failed; then 16324 16325 echo 1 > $at_status_file 16326 exit 1 16327 fi 16328 16329 $at_traceon 16330 16331 16332 cat >input <<'_ATEOF' 16333 error 16334 _ATEOF 16335 16336 $at_traceoff 16337 echo "calc.at:555: \$PREPARSER ./calc input" 16338 echo calc.at:555 >$at_check_line_file 16339 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 16340 at_status=$? 16341 grep '^ *+' $at_stder1 >&2 16342 grep -v '^ *+' $at_stder1 >$at_stderr 16343 at_failed=false 16344 echo stderr:; tee stderr <$at_stderr 16345 $at_diff $at_devnull $at_stdout || at_failed=: 16346 case $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=:;; 16352 esac 16353 if $at_failed; then 16354 16355 echo 1 > $at_status_file 16356 exit 1 16357 fi 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. 16365 sed '/^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 16378 mv at-stderr stderr 16379 # 2. Create the reference error message. 16380 cat >expout <<'_ATEOF' 16381 1.0: syntax error, unexpected $undefined 16382 _ATEOF 16383 16384 # 3. If locations are not used, remove them. 16385 sed 's/^[-0-9.]*: //' expout >at-expout 16386 mv at-expout expout 16387 # 4. If error-verbose is not used, strip the`, unexpected....' part. 16388 sed 's/syntax error, .*$/syntax error/' expout >at-expout 16389 mv at-expout expout 16390 # 5. Check 16391 $at_traceoff 16392 echo "calc.at:555: cat stderr" 16393 echo calc.at:555 >$at_check_line_file 16394 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 16395 at_status=$? 16396 grep '^ *+' $at_stder1 >&2 16397 grep -v '^ *+' $at_stder1 >$at_stderr 16398 at_failed=false 16399 $at_diff $at_devnull $at_stderr || at_failed=: 16400 $at_diff expout $at_stdout || at_failed=: 16401 case $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=:;; 16407 esac 16408 if $at_failed; then 16409 16410 echo 1 > $at_status_file 16411 exit 1 16412 fi 16413 16414 $at_traceon 16415 16416 16417 cat >input <<'_ATEOF' 16418 1 = 2 = 3 16419 _ATEOF 16420 16421 $at_traceoff 16422 echo "calc.at:555: \$PREPARSER ./calc input" 16423 echo calc.at:555 >$at_check_line_file 16424 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 16425 at_status=$? 16426 grep '^ *+' $at_stder1 >&2 16427 grep -v '^ *+' $at_stder1 >$at_stderr 16428 at_failed=false 16429 echo stderr:; tee stderr <$at_stderr 16430 $at_diff $at_devnull $at_stdout || at_failed=: 16431 case $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=:;; 16437 esac 16438 if $at_failed; then 16439 16440 echo 1 > $at_status_file 16441 exit 1 16442 fi 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. 16450 sed '/^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 16463 mv at-stderr stderr 16464 # 2. Create the reference error message. 16465 cat >expout <<'_ATEOF' 16466 1.6: syntax error, unexpected '=' 16467 _ATEOF 16468 16469 # 3. If locations are not used, remove them. 16470 sed 's/^[-0-9.]*: //' expout >at-expout 16471 mv at-expout expout 16472 # 4. If error-verbose is not used, strip the`, unexpected....' part. 16473 sed 's/syntax error, .*$/syntax error/' expout >at-expout 16474 mv at-expout expout 16475 # 5. Check 16476 $at_traceoff 16477 echo "calc.at:555: cat stderr" 16478 echo calc.at:555 >$at_check_line_file 16479 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 16480 at_status=$? 16481 grep '^ *+' $at_stder1 >&2 16482 grep -v '^ *+' $at_stder1 >$at_stderr 16483 at_failed=false 16484 $at_diff $at_devnull $at_stderr || at_failed=: 16485 $at_diff expout $at_stdout || at_failed=: 16486 case $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=:;; 16492 esac 16493 if $at_failed; then 16494 16495 echo 1 > $at_status_file 16496 exit 1 16497 fi 16498 16499 $at_traceon 16500 16501 16502 cat >input <<'_ATEOF' 16503 16504 +1 16505 _ATEOF 16506 16507 $at_traceoff 16508 echo "calc.at:555: \$PREPARSER ./calc input" 16509 echo calc.at:555 >$at_check_line_file 16510 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 16511 at_status=$? 16512 grep '^ *+' $at_stder1 >&2 16513 grep -v '^ *+' $at_stder1 >$at_stderr 16514 at_failed=false 16515 echo stderr:; tee stderr <$at_stderr 16516 $at_diff $at_devnull $at_stdout || at_failed=: 16517 case $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=:;; 16523 esac 16524 if $at_failed; then 16525 16526 echo 1 > $at_status_file 16527 exit 1 16528 fi 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. 16536 sed '/^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 16549 mv at-stderr stderr 16550 # 2. Create the reference error message. 16551 cat >expout <<'_ATEOF' 16552 2.0: syntax error, unexpected '+' 16553 _ATEOF 16554 16555 # 3. If locations are not used, remove them. 16556 sed 's/^[-0-9.]*: //' expout >at-expout 16557 mv at-expout expout 16558 # 4. If error-verbose is not used, strip the`, unexpected....' part. 16559 sed 's/syntax error, .*$/syntax error/' expout >at-expout 16560 mv at-expout expout 16561 # 5. Check 16562 $at_traceoff 16563 echo "calc.at:555: cat stderr" 16564 echo calc.at:555 >$at_check_line_file 16565 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 16566 at_status=$? 16567 grep '^ *+' $at_stder1 >&2 16568 grep -v '^ *+' $at_stder1 >$at_stderr 16569 at_failed=false 16570 $at_diff $at_devnull $at_stderr || at_failed=: 16571 $at_diff expout $at_stdout || at_failed=: 16572 case $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=:;; 16578 esac 16579 if $at_failed; then 16580 16581 echo 1 > $at_status_file 16582 exit 1 16583 fi 16584 16585 $at_traceon 16586 16587 16588 # Exercise error messages with EOF: work on an empty file. 16589 $at_traceoff 16590 echo "calc.at:555: \$PREPARSER ./calc /dev/null" 16591 echo calc.at:555 >$at_check_line_file 16592 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 16593 at_status=$? 16594 grep '^ *+' $at_stder1 >&2 16595 grep -v '^ *+' $at_stder1 >$at_stderr 16596 at_failed=false 16597 echo stderr:; tee stderr <$at_stderr 16598 $at_diff $at_devnull $at_stdout || at_failed=: 16599 case $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=:;; 16605 esac 16606 if $at_failed; then 16607 16608 echo 1 > $at_status_file 16609 exit 1 16610 fi 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. 16618 sed '/^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 16631 mv at-stderr stderr 16632 # 2. Create the reference error message. 16633 cat >expout <<'_ATEOF' 16634 1.0: syntax error, unexpected end of input 16635 _ATEOF 16636 16637 # 3. If locations are not used, remove them. 16638 sed 's/^[-0-9.]*: //' expout >at-expout 16639 mv at-expout expout 16640 # 4. If error-verbose is not used, strip the`, unexpected....' part. 16641 sed 's/syntax error, .*$/syntax error/' expout >at-expout 16642 mv at-expout expout 16643 # 5. Check 16644 $at_traceoff 16645 echo "calc.at:555: cat stderr" 16646 echo calc.at:555 >$at_check_line_file 16647 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 16648 at_status=$? 16649 grep '^ *+' $at_stder1 >&2 16650 grep -v '^ *+' $at_stder1 >$at_stderr 16651 at_failed=false 16652 $at_diff $at_devnull $at_stderr || at_failed=: 16653 $at_diff expout $at_stdout || at_failed=: 16654 case $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=:;; 16660 esac 16661 if $at_failed; then 16662 16663 echo 1 > $at_status_file 16664 exit 1 16665 fi 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 # 16687 cat >input <<'_ATEOF' 16688 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 16689 _ATEOF 16690 16691 $at_traceoff 16692 echo "calc.at:555: \$PREPARSER ./calc input" 16693 echo calc.at:555 >$at_check_line_file 16694 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 16695 at_status=$? 16696 grep '^ *+' $at_stder1 >&2 16697 grep -v '^ *+' $at_stder1 >$at_stderr 16698 at_failed=false 16699 echo stderr:; tee stderr <$at_stderr 16700 $at_diff $at_devnull $at_stdout || at_failed=: 16701 case $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=:;; 16707 esac 16708 if $at_failed; then 16709 16710 echo 1 > $at_status_file 16711 exit 1 16712 fi 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. 16720 sed '/^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 16733 mv at-stderr stderr 16734 # 2. Create the reference error message. 16735 cat >expout <<'_ATEOF' 16736 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 16737 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 16738 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 16739 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 16740 calc: error: 4444 != 1 16741 _ATEOF 16742 16743 # 3. If locations are not used, remove them. 16744 sed 's/^[-0-9.]*: //' expout >at-expout 16745 mv at-expout expout 16746 # 4. If error-verbose is not used, strip the`, unexpected....' part. 16747 sed 's/syntax error, .*$/syntax error/' expout >at-expout 16748 mv at-expout expout 16749 # 5. Check 16750 $at_traceoff 16751 echo "calc.at:555: cat stderr" 16752 echo calc.at:555 >$at_check_line_file 16753 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 16754 at_status=$? 16755 grep '^ *+' $at_stder1 >&2 16756 grep -v '^ *+' $at_stder1 >$at_stderr 16757 at_failed=false 16758 $at_diff $at_devnull $at_stderr || at_failed=: 16759 $at_diff expout $at_stdout || at_failed=: 16760 case $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=:;; 16766 esac 16767 if $at_failed; then 16768 16769 echo 1 > $at_status_file 16770 exit 1 16771 fi 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. 16779 cat >input <<'_ATEOF' 16780 (!) + (0 0) = 1 16781 _ATEOF 16782 16783 $at_traceoff 16784 echo "calc.at:555: \$PREPARSER ./calc input" 16785 echo calc.at:555 >$at_check_line_file 16786 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 16787 at_status=$? 16788 grep '^ *+' $at_stder1 >&2 16789 grep -v '^ *+' $at_stder1 >$at_stderr 16790 at_failed=false 16791 echo stderr:; tee stderr <$at_stderr 16792 $at_diff $at_devnull $at_stdout || at_failed=: 16793 case $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=:;; 16799 esac 16800 if $at_failed; then 16801 16802 echo 1 > $at_status_file 16803 exit 1 16804 fi 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. 16812 sed '/^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 16825 mv at-stderr stderr 16826 # 2. Create the reference error message. 16827 cat >expout <<'_ATEOF' 16828 1.9: syntax error, unexpected number 16829 calc: error: 2222 != 1 16830 _ATEOF 16831 16832 # 3. If locations are not used, remove them. 16833 sed 's/^[-0-9.]*: //' expout >at-expout 16834 mv at-expout expout 16835 # 4. If error-verbose is not used, strip the`, unexpected....' part. 16836 sed 's/syntax error, .*$/syntax error/' expout >at-expout 16837 mv at-expout expout 16838 # 5. Check 16839 $at_traceoff 16840 echo "calc.at:555: cat stderr" 16841 echo calc.at:555 >$at_check_line_file 16842 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 16843 at_status=$? 16844 grep '^ *+' $at_stder1 >&2 16845 grep -v '^ *+' $at_stder1 >$at_stderr 16846 at_failed=false 16847 $at_diff $at_devnull $at_stderr || at_failed=: 16848 $at_diff expout $at_stdout || at_failed=: 16849 case $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=:;; 16855 esac 16856 if $at_failed; then 16857 16858 echo 1 > $at_status_file 16859 exit 1 16860 fi 16861 16862 $at_traceon 16863 16864 16865 cat >input <<'_ATEOF' 16866 (- *) + (0 0) = 1 16867 _ATEOF 16868 16869 $at_traceoff 16870 echo "calc.at:555: \$PREPARSER ./calc input" 16871 echo calc.at:555 >$at_check_line_file 16872 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 16873 at_status=$? 16874 grep '^ *+' $at_stder1 >&2 16875 grep -v '^ *+' $at_stder1 >$at_stderr 16876 at_failed=false 16877 echo stderr:; tee stderr <$at_stderr 16878 $at_diff $at_devnull $at_stdout || at_failed=: 16879 case $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=:;; 16885 esac 16886 if $at_failed; then 16887 16888 echo 1 > $at_status_file 16889 exit 1 16890 fi 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. 16898 sed '/^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 16911 mv at-stderr stderr 16912 # 2. Create the reference error message. 16913 cat >expout <<'_ATEOF' 16914 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 16915 1.11: syntax error, unexpected number 16916 calc: error: 2222 != 1 16917 _ATEOF 16918 16919 # 3. If locations are not used, remove them. 16920 sed 's/^[-0-9.]*: //' expout >at-expout 16921 mv at-expout expout 16922 # 4. If error-verbose is not used, strip the`, unexpected....' part. 16923 sed 's/syntax error, .*$/syntax error/' expout >at-expout 16924 mv at-expout expout 16925 # 5. Check 16926 $at_traceoff 16927 echo "calc.at:555: cat stderr" 16928 echo calc.at:555 >$at_check_line_file 16929 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 16930 at_status=$? 16931 grep '^ *+' $at_stder1 >&2 16932 grep -v '^ *+' $at_stder1 >$at_stderr 16933 at_failed=false 16934 $at_diff $at_devnull $at_stderr || at_failed=: 16935 $at_diff expout $at_stdout || at_failed=: 16936 case $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=:;; 16942 esac 16943 if $at_failed; then 16944 16945 echo 1 > $at_status_file 16946 exit 1 16947 fi 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 17024 cat >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. */ 17053 typedef int semantic_value; 17054 17055 static semantic_value global_result = 0; 17056 static int global_count = 0; 17057 %} 17058 17059 /* Exercise %union. */ 17060 %union 17061 { 17062 semantic_value ival; 17063 }; 17064 17065 %{ 17066 static int power (int base, int exponent); 17067 /* yyerror receives the location if: 17068 - %location & %pure & %glr 17069 - %location & %pure & %yacc & %parse-param. */ 17070 static void yyerror ( 17071 17072 const char *s 17073 ); 17074 static int yylex (void); 17075 static int get_char (void); 17076 static 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 %% 17094 input: 17095 line 17096 | input line { } 17097 ; 17098 17099 line: 17100 '\n' 17101 | exp '\n' { USE ($1); } 17102 ; 17103 17104 exp: 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. */ 17125 static FILE *input; 17126 17127 static void 17128 yyerror ( 17129 17130 const char *s) 17131 { 17132 17133 17134 fprintf (stderr, "%s\n", s); 17135 } 17136 17137 17138 17139 static int 17140 get_char (void) 17141 { 17142 int res = getc (input); 17143 ; 17144 17145 return res; 17146 } 17147 17148 17149 static void 17150 unget_char ( int c) 17151 { 17152 ; 17153 17154 ungetc (c, input); 17155 } 17156 17157 static int 17158 read_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 17190 static int 17191 yylex (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 17226 static int 17227 power (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 17238 int 17239 main (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 17276 echo "calc.at:556: bison -o calc.c calc.y" 17277 echo calc.at:556 >$at_check_line_file 17278 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 17279 at_status=$? 17280 grep '^ *+' $at_stder1 >&2 17281 grep -v '^ *+' $at_stder1 >$at_stderr 17282 at_failed=false 17283 $at_diff $at_devnull $at_stderr || at_failed=: 17284 $at_diff $at_devnull $at_stdout || at_failed=: 17285 case $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=:;; 17291 esac 17292 if $at_failed; then 17293 17294 echo 1 > $at_status_file 17295 exit 1 17296 fi 17297 17298 $at_traceon 17299 17300 $at_traceoff 17301 echo "calc.at:556: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 17302 echo calc.at:556 >$at_check_line_file 17303 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 17304 at_status=$? 17305 grep '^ *+' $at_stder1 >&2 17306 grep -v '^ *+' $at_stder1 >$at_stderr 17307 at_failed=false 17308 echo stderr:; cat $at_stderr 17309 echo stdout:; cat $at_stdout 17310 case $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=:;; 17316 esac 17317 if $at_failed; then 17318 17319 echo 1 > $at_status_file 17320 exit 1 17321 fi 17322 17323 $at_traceon 17324 17325 17326 # Test the priorities. 17327 cat >input <<'_ATEOF' 17328 1 + 2 * 3 = 7 17329 1 + 2 * -3 = -5 17330 17331 -1^2 = -1 17332 (-1)^2 = 1 17333 17334 ---1 = -1 17335 17336 1 - 2 - 3 = -4 17337 1 - (2 - 3) = 2 17338 17339 2^2^3 = 256 17340 (2^2)^3 = 64 17341 _ATEOF 17342 17343 $at_traceoff 17344 echo "calc.at:556: \$PREPARSER ./calc input" 17345 echo calc.at:556 >$at_check_line_file 17346 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 17347 at_status=$? 17348 grep '^ *+' $at_stder1 >&2 17349 grep -v '^ *+' $at_stder1 >$at_stderr 17350 at_failed=false 17351 echo stderr:; tee stderr <$at_stderr 17352 $at_diff $at_devnull $at_stdout || at_failed=: 17353 case $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=:;; 17359 esac 17360 if $at_failed; then 17361 17362 echo 1 > $at_status_file 17363 exit 1 17364 fi 17365 17366 $at_traceon 17367 17368 17369 17370 # Some syntax errors. 17371 cat >input <<'_ATEOF' 17372 0 0 17373 _ATEOF 17374 17375 $at_traceoff 17376 echo "calc.at:556: \$PREPARSER ./calc input" 17377 echo calc.at:556 >$at_check_line_file 17378 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 17379 at_status=$? 17380 grep '^ *+' $at_stder1 >&2 17381 grep -v '^ *+' $at_stder1 >$at_stderr 17382 at_failed=false 17383 echo stderr:; tee stderr <$at_stderr 17384 $at_diff $at_devnull $at_stdout || at_failed=: 17385 case $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=:;; 17391 esac 17392 if $at_failed; then 17393 17394 echo 1 > $at_status_file 17395 exit 1 17396 fi 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. 17404 sed '/^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 17417 mv at-stderr stderr 17418 # 2. Create the reference error message. 17419 cat >expout <<'_ATEOF' 17420 1.2: syntax error, unexpected number 17421 _ATEOF 17422 17423 # 3. If locations are not used, remove them. 17424 sed 's/^[-0-9.]*: //' expout >at-expout 17425 mv at-expout expout 17426 # 4. If error-verbose is not used, strip the`, unexpected....' part. 17427 sed 's/syntax error, .*$/syntax error/' expout >at-expout 17428 mv at-expout expout 17429 # 5. Check 17430 $at_traceoff 17431 echo "calc.at:556: cat stderr" 17432 echo calc.at:556 >$at_check_line_file 17433 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 17434 at_status=$? 17435 grep '^ *+' $at_stder1 >&2 17436 grep -v '^ *+' $at_stder1 >$at_stderr 17437 at_failed=false 17438 $at_diff $at_devnull $at_stderr || at_failed=: 17439 $at_diff expout $at_stdout || at_failed=: 17440 case $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=:;; 17446 esac 17447 if $at_failed; then 17448 17449 echo 1 > $at_status_file 17450 exit 1 17451 fi 17452 17453 $at_traceon 17454 17455 17456 cat >input <<'_ATEOF' 17457 1//2 17458 _ATEOF 17459 17460 $at_traceoff 17461 echo "calc.at:556: \$PREPARSER ./calc input" 17462 echo calc.at:556 >$at_check_line_file 17463 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 17464 at_status=$? 17465 grep '^ *+' $at_stder1 >&2 17466 grep -v '^ *+' $at_stder1 >$at_stderr 17467 at_failed=false 17468 echo stderr:; tee stderr <$at_stderr 17469 $at_diff $at_devnull $at_stdout || at_failed=: 17470 case $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=:;; 17476 esac 17477 if $at_failed; then 17478 17479 echo 1 > $at_status_file 17480 exit 1 17481 fi 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. 17489 sed '/^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 17502 mv at-stderr stderr 17503 # 2. Create the reference error message. 17504 cat >expout <<'_ATEOF' 17505 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 17506 _ATEOF 17507 17508 # 3. If locations are not used, remove them. 17509 sed 's/^[-0-9.]*: //' expout >at-expout 17510 mv at-expout expout 17511 # 4. If error-verbose is not used, strip the`, unexpected....' part. 17512 sed 's/syntax error, .*$/syntax error/' expout >at-expout 17513 mv at-expout expout 17514 # 5. Check 17515 $at_traceoff 17516 echo "calc.at:556: cat stderr" 17517 echo calc.at:556 >$at_check_line_file 17518 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 17519 at_status=$? 17520 grep '^ *+' $at_stder1 >&2 17521 grep -v '^ *+' $at_stder1 >$at_stderr 17522 at_failed=false 17523 $at_diff $at_devnull $at_stderr || at_failed=: 17524 $at_diff expout $at_stdout || at_failed=: 17525 case $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=:;; 17531 esac 17532 if $at_failed; then 17533 17534 echo 1 > $at_status_file 17535 exit 1 17536 fi 17537 17538 $at_traceon 17539 17540 17541 cat >input <<'_ATEOF' 17542 error 17543 _ATEOF 17544 17545 $at_traceoff 17546 echo "calc.at:556: \$PREPARSER ./calc input" 17547 echo calc.at:556 >$at_check_line_file 17548 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 17549 at_status=$? 17550 grep '^ *+' $at_stder1 >&2 17551 grep -v '^ *+' $at_stder1 >$at_stderr 17552 at_failed=false 17553 echo stderr:; tee stderr <$at_stderr 17554 $at_diff $at_devnull $at_stdout || at_failed=: 17555 case $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=:;; 17561 esac 17562 if $at_failed; then 17563 17564 echo 1 > $at_status_file 17565 exit 1 17566 fi 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. 17574 sed '/^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 17587 mv at-stderr stderr 17588 # 2. Create the reference error message. 17589 cat >expout <<'_ATEOF' 17590 1.0: syntax error, unexpected $undefined 17591 _ATEOF 17592 17593 # 3. If locations are not used, remove them. 17594 sed 's/^[-0-9.]*: //' expout >at-expout 17595 mv at-expout expout 17596 # 4. If error-verbose is not used, strip the`, unexpected....' part. 17597 sed 's/syntax error, .*$/syntax error/' expout >at-expout 17598 mv at-expout expout 17599 # 5. Check 17600 $at_traceoff 17601 echo "calc.at:556: cat stderr" 17602 echo calc.at:556 >$at_check_line_file 17603 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 17604 at_status=$? 17605 grep '^ *+' $at_stder1 >&2 17606 grep -v '^ *+' $at_stder1 >$at_stderr 17607 at_failed=false 17608 $at_diff $at_devnull $at_stderr || at_failed=: 17609 $at_diff expout $at_stdout || at_failed=: 17610 case $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=:;; 17616 esac 17617 if $at_failed; then 17618 17619 echo 1 > $at_status_file 17620 exit 1 17621 fi 17622 17623 $at_traceon 17624 17625 17626 cat >input <<'_ATEOF' 17627 1 = 2 = 3 17628 _ATEOF 17629 17630 $at_traceoff 17631 echo "calc.at:556: \$PREPARSER ./calc input" 17632 echo calc.at:556 >$at_check_line_file 17633 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 17634 at_status=$? 17635 grep '^ *+' $at_stder1 >&2 17636 grep -v '^ *+' $at_stder1 >$at_stderr 17637 at_failed=false 17638 echo stderr:; tee stderr <$at_stderr 17639 $at_diff $at_devnull $at_stdout || at_failed=: 17640 case $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=:;; 17646 esac 17647 if $at_failed; then 17648 17649 echo 1 > $at_status_file 17650 exit 1 17651 fi 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. 17659 sed '/^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 17672 mv at-stderr stderr 17673 # 2. Create the reference error message. 17674 cat >expout <<'_ATEOF' 17675 1.6: syntax error, unexpected '=' 17676 _ATEOF 17677 17678 # 3. If locations are not used, remove them. 17679 sed 's/^[-0-9.]*: //' expout >at-expout 17680 mv at-expout expout 17681 # 4. If error-verbose is not used, strip the`, unexpected....' part. 17682 sed 's/syntax error, .*$/syntax error/' expout >at-expout 17683 mv at-expout expout 17684 # 5. Check 17685 $at_traceoff 17686 echo "calc.at:556: cat stderr" 17687 echo calc.at:556 >$at_check_line_file 17688 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 17689 at_status=$? 17690 grep '^ *+' $at_stder1 >&2 17691 grep -v '^ *+' $at_stder1 >$at_stderr 17692 at_failed=false 17693 $at_diff $at_devnull $at_stderr || at_failed=: 17694 $at_diff expout $at_stdout || at_failed=: 17695 case $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=:;; 17701 esac 17702 if $at_failed; then 17703 17704 echo 1 > $at_status_file 17705 exit 1 17706 fi 17707 17708 $at_traceon 17709 17710 17711 cat >input <<'_ATEOF' 17712 17713 +1 17714 _ATEOF 17715 17716 $at_traceoff 17717 echo "calc.at:556: \$PREPARSER ./calc input" 17718 echo calc.at:556 >$at_check_line_file 17719 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 17720 at_status=$? 17721 grep '^ *+' $at_stder1 >&2 17722 grep -v '^ *+' $at_stder1 >$at_stderr 17723 at_failed=false 17724 echo stderr:; tee stderr <$at_stderr 17725 $at_diff $at_devnull $at_stdout || at_failed=: 17726 case $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=:;; 17732 esac 17733 if $at_failed; then 17734 17735 echo 1 > $at_status_file 17736 exit 1 17737 fi 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. 17745 sed '/^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 17758 mv at-stderr stderr 17759 # 2. Create the reference error message. 17760 cat >expout <<'_ATEOF' 17761 2.0: syntax error, unexpected '+' 17762 _ATEOF 17763 17764 # 3. If locations are not used, remove them. 17765 sed 's/^[-0-9.]*: //' expout >at-expout 17766 mv at-expout expout 17767 # 4. If error-verbose is not used, strip the`, unexpected....' part. 17768 sed 's/syntax error, .*$/syntax error/' expout >at-expout 17769 mv at-expout expout 17770 # 5. Check 17771 $at_traceoff 17772 echo "calc.at:556: cat stderr" 17773 echo calc.at:556 >$at_check_line_file 17774 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 17775 at_status=$? 17776 grep '^ *+' $at_stder1 >&2 17777 grep -v '^ *+' $at_stder1 >$at_stderr 17778 at_failed=false 17779 $at_diff $at_devnull $at_stderr || at_failed=: 17780 $at_diff expout $at_stdout || at_failed=: 17781 case $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=:;; 17787 esac 17788 if $at_failed; then 17789 17790 echo 1 > $at_status_file 17791 exit 1 17792 fi 17793 17794 $at_traceon 17795 17796 17797 # Exercise error messages with EOF: work on an empty file. 17798 $at_traceoff 17799 echo "calc.at:556: \$PREPARSER ./calc /dev/null" 17800 echo calc.at:556 >$at_check_line_file 17801 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 17802 at_status=$? 17803 grep '^ *+' $at_stder1 >&2 17804 grep -v '^ *+' $at_stder1 >$at_stderr 17805 at_failed=false 17806 echo stderr:; tee stderr <$at_stderr 17807 $at_diff $at_devnull $at_stdout || at_failed=: 17808 case $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=:;; 17814 esac 17815 if $at_failed; then 17816 17817 echo 1 > $at_status_file 17818 exit 1 17819 fi 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. 17827 sed '/^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 17840 mv at-stderr stderr 17841 # 2. Create the reference error message. 17842 cat >expout <<'_ATEOF' 17843 1.0: syntax error, unexpected end of input 17844 _ATEOF 17845 17846 # 3. If locations are not used, remove them. 17847 sed 's/^[-0-9.]*: //' expout >at-expout 17848 mv at-expout expout 17849 # 4. If error-verbose is not used, strip the`, unexpected....' part. 17850 sed 's/syntax error, .*$/syntax error/' expout >at-expout 17851 mv at-expout expout 17852 # 5. Check 17853 $at_traceoff 17854 echo "calc.at:556: cat stderr" 17855 echo calc.at:556 >$at_check_line_file 17856 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 17857 at_status=$? 17858 grep '^ *+' $at_stder1 >&2 17859 grep -v '^ *+' $at_stder1 >$at_stderr 17860 at_failed=false 17861 $at_diff $at_devnull $at_stderr || at_failed=: 17862 $at_diff expout $at_stdout || at_failed=: 17863 case $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=:;; 17869 esac 17870 if $at_failed; then 17871 17872 echo 1 > $at_status_file 17873 exit 1 17874 fi 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 # 17896 cat >input <<'_ATEOF' 17897 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 17898 _ATEOF 17899 17900 $at_traceoff 17901 echo "calc.at:556: \$PREPARSER ./calc input" 17902 echo calc.at:556 >$at_check_line_file 17903 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 17904 at_status=$? 17905 grep '^ *+' $at_stder1 >&2 17906 grep -v '^ *+' $at_stder1 >$at_stderr 17907 at_failed=false 17908 echo stderr:; tee stderr <$at_stderr 17909 $at_diff $at_devnull $at_stdout || at_failed=: 17910 case $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=:;; 17916 esac 17917 if $at_failed; then 17918 17919 echo 1 > $at_status_file 17920 exit 1 17921 fi 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. 17929 sed '/^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 17942 mv at-stderr stderr 17943 # 2. Create the reference error message. 17944 cat >expout <<'_ATEOF' 17945 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 17946 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 17947 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 17948 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 17949 calc: error: 4444 != 1 17950 _ATEOF 17951 17952 # 3. If locations are not used, remove them. 17953 sed 's/^[-0-9.]*: //' expout >at-expout 17954 mv at-expout expout 17955 # 4. If error-verbose is not used, strip the`, unexpected....' part. 17956 sed 's/syntax error, .*$/syntax error/' expout >at-expout 17957 mv at-expout expout 17958 # 5. Check 17959 $at_traceoff 17960 echo "calc.at:556: cat stderr" 17961 echo calc.at:556 >$at_check_line_file 17962 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 17963 at_status=$? 17964 grep '^ *+' $at_stder1 >&2 17965 grep -v '^ *+' $at_stder1 >$at_stderr 17966 at_failed=false 17967 $at_diff $at_devnull $at_stderr || at_failed=: 17968 $at_diff expout $at_stdout || at_failed=: 17969 case $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=:;; 17975 esac 17976 if $at_failed; then 17977 17978 echo 1 > $at_status_file 17979 exit 1 17980 fi 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. 17988 cat >input <<'_ATEOF' 17989 (!) + (0 0) = 1 17990 _ATEOF 17991 17992 $at_traceoff 17993 echo "calc.at:556: \$PREPARSER ./calc input" 17994 echo calc.at:556 >$at_check_line_file 17995 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 17996 at_status=$? 17997 grep '^ *+' $at_stder1 >&2 17998 grep -v '^ *+' $at_stder1 >$at_stderr 17999 at_failed=false 18000 echo stderr:; tee stderr <$at_stderr 18001 $at_diff $at_devnull $at_stdout || at_failed=: 18002 case $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=:;; 18008 esac 18009 if $at_failed; then 18010 18011 echo 1 > $at_status_file 18012 exit 1 18013 fi 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. 18021 sed '/^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 18034 mv at-stderr stderr 18035 # 2. Create the reference error message. 18036 cat >expout <<'_ATEOF' 18037 1.9: syntax error, unexpected number 18038 calc: error: 2222 != 1 18039 _ATEOF 18040 18041 # 3. If locations are not used, remove them. 18042 sed 's/^[-0-9.]*: //' expout >at-expout 18043 mv at-expout expout 18044 # 4. If error-verbose is not used, strip the`, unexpected....' part. 18045 sed 's/syntax error, .*$/syntax error/' expout >at-expout 18046 mv at-expout expout 18047 # 5. Check 18048 $at_traceoff 18049 echo "calc.at:556: cat stderr" 18050 echo calc.at:556 >$at_check_line_file 18051 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 18052 at_status=$? 18053 grep '^ *+' $at_stder1 >&2 18054 grep -v '^ *+' $at_stder1 >$at_stderr 18055 at_failed=false 18056 $at_diff $at_devnull $at_stderr || at_failed=: 18057 $at_diff expout $at_stdout || at_failed=: 18058 case $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=:;; 18064 esac 18065 if $at_failed; then 18066 18067 echo 1 > $at_status_file 18068 exit 1 18069 fi 18070 18071 $at_traceon 18072 18073 18074 cat >input <<'_ATEOF' 18075 (- *) + (0 0) = 1 18076 _ATEOF 18077 18078 $at_traceoff 18079 echo "calc.at:556: \$PREPARSER ./calc input" 18080 echo calc.at:556 >$at_check_line_file 18081 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 18082 at_status=$? 18083 grep '^ *+' $at_stder1 >&2 18084 grep -v '^ *+' $at_stder1 >$at_stderr 18085 at_failed=false 18086 echo stderr:; tee stderr <$at_stderr 18087 $at_diff $at_devnull $at_stdout || at_failed=: 18088 case $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=:;; 18094 esac 18095 if $at_failed; then 18096 18097 echo 1 > $at_status_file 18098 exit 1 18099 fi 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. 18107 sed '/^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 18120 mv at-stderr stderr 18121 # 2. Create the reference error message. 18122 cat >expout <<'_ATEOF' 18123 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 18124 1.11: syntax error, unexpected number 18125 calc: error: 2222 != 1 18126 _ATEOF 18127 18128 # 3. If locations are not used, remove them. 18129 sed 's/^[-0-9.]*: //' expout >at-expout 18130 mv at-expout expout 18131 # 4. If error-verbose is not used, strip the`, unexpected....' part. 18132 sed 's/syntax error, .*$/syntax error/' expout >at-expout 18133 mv at-expout expout 18134 # 5. Check 18135 $at_traceoff 18136 echo "calc.at:556: cat stderr" 18137 echo calc.at:556 >$at_check_line_file 18138 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 18139 at_status=$? 18140 grep '^ *+' $at_stder1 >&2 18141 grep -v '^ *+' $at_stder1 >$at_stderr 18142 at_failed=false 18143 $at_diff $at_devnull $at_stderr || at_failed=: 18144 $at_diff expout $at_stdout || at_failed=: 18145 case $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=:;; 18151 esac 18152 if $at_failed; then 18153 18154 echo 1 > $at_status_file 18155 exit 1 18156 fi 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 18233 cat >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. */ 18262 typedef int semantic_value; 18263 18264 static semantic_value global_result = 0; 18265 static int global_count = 0; 18266 %} 18267 18268 /* Exercise %union. */ 18269 %union 18270 { 18271 semantic_value ival; 18272 }; 18273 18274 %{ 18275 static int power (int base, int exponent); 18276 /* yyerror receives the location if: 18277 - %location & %pure & %glr 18278 - %location & %pure & %yacc & %parse-param. */ 18279 static void yyerror ( 18280 18281 const char *s 18282 ); 18283 static int yylex (void); 18284 static int get_char (void); 18285 static 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 %% 18303 input: 18304 line 18305 | input line { } 18306 ; 18307 18308 line: 18309 '\n' 18310 | exp '\n' { USE ($1); } 18311 ; 18312 18313 exp: 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. */ 18334 static FILE *input; 18335 18336 static void 18337 yyerror ( 18338 18339 const char *s) 18340 { 18341 18342 18343 fprintf (stderr, "%s\n", s); 18344 } 18345 18346 18347 18348 static int 18349 get_char (void) 18350 { 18351 int res = getc (input); 18352 ; 18353 18354 return res; 18355 } 18356 18357 18358 static void 18359 unget_char ( int c) 18360 { 18361 ; 18362 18363 ungetc (c, input); 18364 } 18365 18366 static int 18367 read_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 18399 static int 18400 yylex (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 18435 static int 18436 power (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 18447 int 18448 main (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 18485 echo "calc.at:557: bison -o calc.c calc.y" 18486 echo calc.at:557 >$at_check_line_file 18487 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 18488 at_status=$? 18489 grep '^ *+' $at_stder1 >&2 18490 grep -v '^ *+' $at_stder1 >$at_stderr 18491 at_failed=false 18492 $at_diff $at_devnull $at_stderr || at_failed=: 18493 $at_diff $at_devnull $at_stdout || at_failed=: 18494 case $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=:;; 18500 esac 18501 if $at_failed; then 18502 18503 echo 1 > $at_status_file 18504 exit 1 18505 fi 18506 18507 $at_traceon 18508 18509 $at_traceoff 18510 echo "calc.at:557: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 18511 echo calc.at:557 >$at_check_line_file 18512 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 18513 at_status=$? 18514 grep '^ *+' $at_stder1 >&2 18515 grep -v '^ *+' $at_stder1 >$at_stderr 18516 at_failed=false 18517 echo stderr:; cat $at_stderr 18518 echo stdout:; cat $at_stdout 18519 case $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=:;; 18525 esac 18526 if $at_failed; then 18527 18528 echo 1 > $at_status_file 18529 exit 1 18530 fi 18531 18532 $at_traceon 18533 18534 18535 # Test the priorities. 18536 cat >input <<'_ATEOF' 18537 1 + 2 * 3 = 7 18538 1 + 2 * -3 = -5 18539 18540 -1^2 = -1 18541 (-1)^2 = 1 18542 18543 ---1 = -1 18544 18545 1 - 2 - 3 = -4 18546 1 - (2 - 3) = 2 18547 18548 2^2^3 = 256 18549 (2^2)^3 = 64 18550 _ATEOF 18551 18552 $at_traceoff 18553 echo "calc.at:557: \$PREPARSER ./calc input" 18554 echo calc.at:557 >$at_check_line_file 18555 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 18556 at_status=$? 18557 grep '^ *+' $at_stder1 >&2 18558 grep -v '^ *+' $at_stder1 >$at_stderr 18559 at_failed=false 18560 echo stderr:; tee stderr <$at_stderr 18561 $at_diff $at_devnull $at_stdout || at_failed=: 18562 case $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=:;; 18568 esac 18569 if $at_failed; then 18570 18571 echo 1 > $at_status_file 18572 exit 1 18573 fi 18574 18575 $at_traceon 18576 18577 18578 18579 # Some syntax errors. 18580 cat >input <<'_ATEOF' 18581 0 0 18582 _ATEOF 18583 18584 $at_traceoff 18585 echo "calc.at:557: \$PREPARSER ./calc input" 18586 echo calc.at:557 >$at_check_line_file 18587 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 18588 at_status=$? 18589 grep '^ *+' $at_stder1 >&2 18590 grep -v '^ *+' $at_stder1 >$at_stderr 18591 at_failed=false 18592 echo stderr:; tee stderr <$at_stderr 18593 $at_diff $at_devnull $at_stdout || at_failed=: 18594 case $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=:;; 18600 esac 18601 if $at_failed; then 18602 18603 echo 1 > $at_status_file 18604 exit 1 18605 fi 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. 18613 sed '/^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 18626 mv at-stderr stderr 18627 # 2. Create the reference error message. 18628 cat >expout <<'_ATEOF' 18629 1.2: syntax error, unexpected number 18630 _ATEOF 18631 18632 # 3. If locations are not used, remove them. 18633 sed 's/^[-0-9.]*: //' expout >at-expout 18634 mv at-expout expout 18635 # 4. If error-verbose is not used, strip the`, unexpected....' part. 18636 18637 # 5. Check 18638 $at_traceoff 18639 echo "calc.at:557: cat stderr" 18640 echo calc.at:557 >$at_check_line_file 18641 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 18642 at_status=$? 18643 grep '^ *+' $at_stder1 >&2 18644 grep -v '^ *+' $at_stder1 >$at_stderr 18645 at_failed=false 18646 $at_diff $at_devnull $at_stderr || at_failed=: 18647 $at_diff expout $at_stdout || at_failed=: 18648 case $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=:;; 18654 esac 18655 if $at_failed; then 18656 18657 echo 1 > $at_status_file 18658 exit 1 18659 fi 18660 18661 $at_traceon 18662 18663 18664 cat >input <<'_ATEOF' 18665 1//2 18666 _ATEOF 18667 18668 $at_traceoff 18669 echo "calc.at:557: \$PREPARSER ./calc input" 18670 echo calc.at:557 >$at_check_line_file 18671 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 18672 at_status=$? 18673 grep '^ *+' $at_stder1 >&2 18674 grep -v '^ *+' $at_stder1 >$at_stderr 18675 at_failed=false 18676 echo stderr:; tee stderr <$at_stderr 18677 $at_diff $at_devnull $at_stdout || at_failed=: 18678 case $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=:;; 18684 esac 18685 if $at_failed; then 18686 18687 echo 1 > $at_status_file 18688 exit 1 18689 fi 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. 18697 sed '/^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 18710 mv at-stderr stderr 18711 # 2. Create the reference error message. 18712 cat >expout <<'_ATEOF' 18713 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 18714 _ATEOF 18715 18716 # 3. If locations are not used, remove them. 18717 sed 's/^[-0-9.]*: //' expout >at-expout 18718 mv at-expout expout 18719 # 4. If error-verbose is not used, strip the`, unexpected....' part. 18720 18721 # 5. Check 18722 $at_traceoff 18723 echo "calc.at:557: cat stderr" 18724 echo calc.at:557 >$at_check_line_file 18725 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 18726 at_status=$? 18727 grep '^ *+' $at_stder1 >&2 18728 grep -v '^ *+' $at_stder1 >$at_stderr 18729 at_failed=false 18730 $at_diff $at_devnull $at_stderr || at_failed=: 18731 $at_diff expout $at_stdout || at_failed=: 18732 case $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=:;; 18738 esac 18739 if $at_failed; then 18740 18741 echo 1 > $at_status_file 18742 exit 1 18743 fi 18744 18745 $at_traceon 18746 18747 18748 cat >input <<'_ATEOF' 18749 error 18750 _ATEOF 18751 18752 $at_traceoff 18753 echo "calc.at:557: \$PREPARSER ./calc input" 18754 echo calc.at:557 >$at_check_line_file 18755 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 18756 at_status=$? 18757 grep '^ *+' $at_stder1 >&2 18758 grep -v '^ *+' $at_stder1 >$at_stderr 18759 at_failed=false 18760 echo stderr:; tee stderr <$at_stderr 18761 $at_diff $at_devnull $at_stdout || at_failed=: 18762 case $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=:;; 18768 esac 18769 if $at_failed; then 18770 18771 echo 1 > $at_status_file 18772 exit 1 18773 fi 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. 18781 sed '/^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 18794 mv at-stderr stderr 18795 # 2. Create the reference error message. 18796 cat >expout <<'_ATEOF' 18797 1.0: syntax error, unexpected $undefined 18798 _ATEOF 18799 18800 # 3. If locations are not used, remove them. 18801 sed 's/^[-0-9.]*: //' expout >at-expout 18802 mv at-expout expout 18803 # 4. If error-verbose is not used, strip the`, unexpected....' part. 18804 18805 # 5. Check 18806 $at_traceoff 18807 echo "calc.at:557: cat stderr" 18808 echo calc.at:557 >$at_check_line_file 18809 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 18810 at_status=$? 18811 grep '^ *+' $at_stder1 >&2 18812 grep -v '^ *+' $at_stder1 >$at_stderr 18813 at_failed=false 18814 $at_diff $at_devnull $at_stderr || at_failed=: 18815 $at_diff expout $at_stdout || at_failed=: 18816 case $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=:;; 18822 esac 18823 if $at_failed; then 18824 18825 echo 1 > $at_status_file 18826 exit 1 18827 fi 18828 18829 $at_traceon 18830 18831 18832 cat >input <<'_ATEOF' 18833 1 = 2 = 3 18834 _ATEOF 18835 18836 $at_traceoff 18837 echo "calc.at:557: \$PREPARSER ./calc input" 18838 echo calc.at:557 >$at_check_line_file 18839 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 18840 at_status=$? 18841 grep '^ *+' $at_stder1 >&2 18842 grep -v '^ *+' $at_stder1 >$at_stderr 18843 at_failed=false 18844 echo stderr:; tee stderr <$at_stderr 18845 $at_diff $at_devnull $at_stdout || at_failed=: 18846 case $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=:;; 18852 esac 18853 if $at_failed; then 18854 18855 echo 1 > $at_status_file 18856 exit 1 18857 fi 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. 18865 sed '/^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 18878 mv at-stderr stderr 18879 # 2. Create the reference error message. 18880 cat >expout <<'_ATEOF' 18881 1.6: syntax error, unexpected '=' 18882 _ATEOF 18883 18884 # 3. If locations are not used, remove them. 18885 sed 's/^[-0-9.]*: //' expout >at-expout 18886 mv at-expout expout 18887 # 4. If error-verbose is not used, strip the`, unexpected....' part. 18888 18889 # 5. Check 18890 $at_traceoff 18891 echo "calc.at:557: cat stderr" 18892 echo calc.at:557 >$at_check_line_file 18893 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 18894 at_status=$? 18895 grep '^ *+' $at_stder1 >&2 18896 grep -v '^ *+' $at_stder1 >$at_stderr 18897 at_failed=false 18898 $at_diff $at_devnull $at_stderr || at_failed=: 18899 $at_diff expout $at_stdout || at_failed=: 18900 case $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=:;; 18906 esac 18907 if $at_failed; then 18908 18909 echo 1 > $at_status_file 18910 exit 1 18911 fi 18912 18913 $at_traceon 18914 18915 18916 cat >input <<'_ATEOF' 18917 18918 +1 18919 _ATEOF 18920 18921 $at_traceoff 18922 echo "calc.at:557: \$PREPARSER ./calc input" 18923 echo calc.at:557 >$at_check_line_file 18924 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 18925 at_status=$? 18926 grep '^ *+' $at_stder1 >&2 18927 grep -v '^ *+' $at_stder1 >$at_stderr 18928 at_failed=false 18929 echo stderr:; tee stderr <$at_stderr 18930 $at_diff $at_devnull $at_stdout || at_failed=: 18931 case $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=:;; 18937 esac 18938 if $at_failed; then 18939 18940 echo 1 > $at_status_file 18941 exit 1 18942 fi 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. 18950 sed '/^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 18963 mv at-stderr stderr 18964 # 2. Create the reference error message. 18965 cat >expout <<'_ATEOF' 18966 2.0: syntax error, unexpected '+' 18967 _ATEOF 18968 18969 # 3. If locations are not used, remove them. 18970 sed 's/^[-0-9.]*: //' expout >at-expout 18971 mv at-expout expout 18972 # 4. If error-verbose is not used, strip the`, unexpected....' part. 18973 18974 # 5. Check 18975 $at_traceoff 18976 echo "calc.at:557: cat stderr" 18977 echo calc.at:557 >$at_check_line_file 18978 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 18979 at_status=$? 18980 grep '^ *+' $at_stder1 >&2 18981 grep -v '^ *+' $at_stder1 >$at_stderr 18982 at_failed=false 18983 $at_diff $at_devnull $at_stderr || at_failed=: 18984 $at_diff expout $at_stdout || at_failed=: 18985 case $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=:;; 18991 esac 18992 if $at_failed; then 18993 18994 echo 1 > $at_status_file 18995 exit 1 18996 fi 18997 18998 $at_traceon 18999 19000 19001 # Exercise error messages with EOF: work on an empty file. 19002 $at_traceoff 19003 echo "calc.at:557: \$PREPARSER ./calc /dev/null" 19004 echo calc.at:557 >$at_check_line_file 19005 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 19006 at_status=$? 19007 grep '^ *+' $at_stder1 >&2 19008 grep -v '^ *+' $at_stder1 >$at_stderr 19009 at_failed=false 19010 echo stderr:; tee stderr <$at_stderr 19011 $at_diff $at_devnull $at_stdout || at_failed=: 19012 case $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=:;; 19018 esac 19019 if $at_failed; then 19020 19021 echo 1 > $at_status_file 19022 exit 1 19023 fi 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. 19031 sed '/^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 19044 mv at-stderr stderr 19045 # 2. Create the reference error message. 19046 cat >expout <<'_ATEOF' 19047 1.0: syntax error, unexpected end of input 19048 _ATEOF 19049 19050 # 3. If locations are not used, remove them. 19051 sed 's/^[-0-9.]*: //' expout >at-expout 19052 mv at-expout expout 19053 # 4. If error-verbose is not used, strip the`, unexpected....' part. 19054 19055 # 5. Check 19056 $at_traceoff 19057 echo "calc.at:557: cat stderr" 19058 echo calc.at:557 >$at_check_line_file 19059 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 19060 at_status=$? 19061 grep '^ *+' $at_stder1 >&2 19062 grep -v '^ *+' $at_stder1 >$at_stderr 19063 at_failed=false 19064 $at_diff $at_devnull $at_stderr || at_failed=: 19065 $at_diff expout $at_stdout || at_failed=: 19066 case $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=:;; 19072 esac 19073 if $at_failed; then 19074 19075 echo 1 > $at_status_file 19076 exit 1 19077 fi 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 # 19099 cat >input <<'_ATEOF' 19100 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 19101 _ATEOF 19102 19103 $at_traceoff 19104 echo "calc.at:557: \$PREPARSER ./calc input" 19105 echo calc.at:557 >$at_check_line_file 19106 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 19107 at_status=$? 19108 grep '^ *+' $at_stder1 >&2 19109 grep -v '^ *+' $at_stder1 >$at_stderr 19110 at_failed=false 19111 echo stderr:; tee stderr <$at_stderr 19112 $at_diff $at_devnull $at_stdout || at_failed=: 19113 case $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=:;; 19119 esac 19120 if $at_failed; then 19121 19122 echo 1 > $at_status_file 19123 exit 1 19124 fi 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. 19132 sed '/^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 19145 mv at-stderr stderr 19146 # 2. Create the reference error message. 19147 cat >expout <<'_ATEOF' 19148 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 19149 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 19150 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 19151 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 19152 calc: error: 4444 != 1 19153 _ATEOF 19154 19155 # 3. If locations are not used, remove them. 19156 sed 's/^[-0-9.]*: //' expout >at-expout 19157 mv at-expout expout 19158 # 4. If error-verbose is not used, strip the`, unexpected....' part. 19159 19160 # 5. Check 19161 $at_traceoff 19162 echo "calc.at:557: cat stderr" 19163 echo calc.at:557 >$at_check_line_file 19164 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 19165 at_status=$? 19166 grep '^ *+' $at_stder1 >&2 19167 grep -v '^ *+' $at_stder1 >$at_stderr 19168 at_failed=false 19169 $at_diff $at_devnull $at_stderr || at_failed=: 19170 $at_diff expout $at_stdout || at_failed=: 19171 case $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=:;; 19177 esac 19178 if $at_failed; then 19179 19180 echo 1 > $at_status_file 19181 exit 1 19182 fi 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. 19190 cat >input <<'_ATEOF' 19191 (!) + (0 0) = 1 19192 _ATEOF 19193 19194 $at_traceoff 19195 echo "calc.at:557: \$PREPARSER ./calc input" 19196 echo calc.at:557 >$at_check_line_file 19197 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 19198 at_status=$? 19199 grep '^ *+' $at_stder1 >&2 19200 grep -v '^ *+' $at_stder1 >$at_stderr 19201 at_failed=false 19202 echo stderr:; tee stderr <$at_stderr 19203 $at_diff $at_devnull $at_stdout || at_failed=: 19204 case $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=:;; 19210 esac 19211 if $at_failed; then 19212 19213 echo 1 > $at_status_file 19214 exit 1 19215 fi 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. 19223 sed '/^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 19236 mv at-stderr stderr 19237 # 2. Create the reference error message. 19238 cat >expout <<'_ATEOF' 19239 1.9: syntax error, unexpected number 19240 calc: error: 2222 != 1 19241 _ATEOF 19242 19243 # 3. If locations are not used, remove them. 19244 sed 's/^[-0-9.]*: //' expout >at-expout 19245 mv at-expout expout 19246 # 4. If error-verbose is not used, strip the`, unexpected....' part. 19247 19248 # 5. Check 19249 $at_traceoff 19250 echo "calc.at:557: cat stderr" 19251 echo calc.at:557 >$at_check_line_file 19252 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 19253 at_status=$? 19254 grep '^ *+' $at_stder1 >&2 19255 grep -v '^ *+' $at_stder1 >$at_stderr 19256 at_failed=false 19257 $at_diff $at_devnull $at_stderr || at_failed=: 19258 $at_diff expout $at_stdout || at_failed=: 19259 case $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=:;; 19265 esac 19266 if $at_failed; then 19267 19268 echo 1 > $at_status_file 19269 exit 1 19270 fi 19271 19272 $at_traceon 19273 19274 19275 cat >input <<'_ATEOF' 19276 (- *) + (0 0) = 1 19277 _ATEOF 19278 19279 $at_traceoff 19280 echo "calc.at:557: \$PREPARSER ./calc input" 19281 echo calc.at:557 >$at_check_line_file 19282 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 19283 at_status=$? 19284 grep '^ *+' $at_stder1 >&2 19285 grep -v '^ *+' $at_stder1 >$at_stderr 19286 at_failed=false 19287 echo stderr:; tee stderr <$at_stderr 19288 $at_diff $at_devnull $at_stdout || at_failed=: 19289 case $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=:;; 19295 esac 19296 if $at_failed; then 19297 19298 echo 1 > $at_status_file 19299 exit 1 19300 fi 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. 19308 sed '/^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 19321 mv at-stderr stderr 19322 # 2. Create the reference error message. 19323 cat >expout <<'_ATEOF' 19324 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 19325 1.11: syntax error, unexpected number 19326 calc: error: 2222 != 1 19327 _ATEOF 19328 19329 # 3. If locations are not used, remove them. 19330 sed 's/^[-0-9.]*: //' expout >at-expout 19331 mv at-expout expout 19332 # 4. If error-verbose is not used, strip the`, unexpected....' part. 19333 19334 # 5. Check 19335 $at_traceoff 19336 echo "calc.at:557: cat stderr" 19337 echo calc.at:557 >$at_check_line_file 19338 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 19339 at_status=$? 19340 grep '^ *+' $at_stder1 >&2 19341 grep -v '^ *+' $at_stder1 >$at_stderr 19342 at_failed=false 19343 $at_diff $at_devnull $at_stderr || at_failed=: 19344 $at_diff expout $at_stdout || at_failed=: 19345 case $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=:;; 19351 esac 19352 if $at_failed; then 19353 19354 echo 1 > $at_status_file 19355 exit 1 19356 fi 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 19433 cat >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. */ 19462 typedef int semantic_value; 19463 19464 static semantic_value global_result = 0; 19465 static int global_count = 0; 19466 %} 19467 19468 /* Exercise %union. */ 19469 %union 19470 { 19471 semantic_value ival; 19472 }; 19473 19474 %{ 19475 static int power (int base, int exponent); 19476 /* yyerror receives the location if: 19477 - %location & %pure & %glr 19478 - %location & %pure & %yacc & %parse-param. */ 19479 static void yyerror ( 19480 19481 const char *s 19482 ); 19483 static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp); 19484 static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp); 19485 static 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 %% 19503 input: 19504 line 19505 | input line { } 19506 ; 19507 19508 line: 19509 '\n' 19510 | exp '\n' { USE ($1); } 19511 ; 19512 19513 exp: 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. */ 19534 static FILE *input; 19535 19536 static void 19537 yyerror ( 19538 19539 const char *s) 19540 { 19541 19542 19543 fprintf (stderr, "%s\n", s); 19544 } 19545 19546 19547 19548 static YYLTYPE last_yylloc; 19549 19550 static int 19551 get_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 19569 static void 19570 unget_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 19580 static int 19581 read_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 19613 static int 19614 yylex (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 19657 static int 19658 power (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 19669 int 19670 main (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 19707 echo "calc.at:559: bison -o calc.c calc.y" 19708 echo calc.at:559 >$at_check_line_file 19709 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 19710 at_status=$? 19711 grep '^ *+' $at_stder1 >&2 19712 grep -v '^ *+' $at_stder1 >$at_stderr 19713 at_failed=false 19714 $at_diff $at_devnull $at_stderr || at_failed=: 19715 $at_diff $at_devnull $at_stdout || at_failed=: 19716 case $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=:;; 19722 esac 19723 if $at_failed; then 19724 19725 echo 1 > $at_status_file 19726 exit 1 19727 fi 19728 19729 $at_traceon 19730 19731 $at_traceoff 19732 echo "calc.at:559: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 19733 echo calc.at:559 >$at_check_line_file 19734 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 19735 at_status=$? 19736 grep '^ *+' $at_stder1 >&2 19737 grep -v '^ *+' $at_stder1 >$at_stderr 19738 at_failed=false 19739 echo stderr:; cat $at_stderr 19740 echo stdout:; cat $at_stdout 19741 case $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=:;; 19747 esac 19748 if $at_failed; then 19749 19750 echo 1 > $at_status_file 19751 exit 1 19752 fi 19753 19754 $at_traceon 19755 19756 19757 # Test the priorities. 19758 cat >input <<'_ATEOF' 19759 1 + 2 * 3 = 7 19760 1 + 2 * -3 = -5 19761 19762 -1^2 = -1 19763 (-1)^2 = 1 19764 19765 ---1 = -1 19766 19767 1 - 2 - 3 = -4 19768 1 - (2 - 3) = 2 19769 19770 2^2^3 = 256 19771 (2^2)^3 = 64 19772 _ATEOF 19773 19774 $at_traceoff 19775 echo "calc.at:559: \$PREPARSER ./calc input" 19776 echo calc.at:559 >$at_check_line_file 19777 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 19778 at_status=$? 19779 grep '^ *+' $at_stder1 >&2 19780 grep -v '^ *+' $at_stder1 >$at_stderr 19781 at_failed=false 19782 echo stderr:; tee stderr <$at_stderr 19783 $at_diff $at_devnull $at_stdout || at_failed=: 19784 case $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=:;; 19790 esac 19791 if $at_failed; then 19792 19793 echo 1 > $at_status_file 19794 exit 1 19795 fi 19796 19797 $at_traceon 19798 19799 19800 19801 # Some syntax errors. 19802 cat >input <<'_ATEOF' 19803 0 0 19804 _ATEOF 19805 19806 $at_traceoff 19807 echo "calc.at:559: \$PREPARSER ./calc input" 19808 echo calc.at:559 >$at_check_line_file 19809 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 19810 at_status=$? 19811 grep '^ *+' $at_stder1 >&2 19812 grep -v '^ *+' $at_stder1 >$at_stderr 19813 at_failed=false 19814 echo stderr:; tee stderr <$at_stderr 19815 $at_diff $at_devnull $at_stdout || at_failed=: 19816 case $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=:;; 19822 esac 19823 if $at_failed; then 19824 19825 echo 1 > $at_status_file 19826 exit 1 19827 fi 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. 19835 sed '/^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 19848 mv at-stderr stderr 19849 # 2. Create the reference error message. 19850 cat >expout <<'_ATEOF' 19851 1.2: syntax error, unexpected number 19852 _ATEOF 19853 19854 # 3. If locations are not used, remove them. 19855 sed 's/^[-0-9.]*: //' expout >at-expout 19856 mv at-expout expout 19857 # 4. If error-verbose is not used, strip the`, unexpected....' part. 19858 sed 's/syntax error, .*$/syntax error/' expout >at-expout 19859 mv at-expout expout 19860 # 5. Check 19861 $at_traceoff 19862 echo "calc.at:559: cat stderr" 19863 echo calc.at:559 >$at_check_line_file 19864 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 19865 at_status=$? 19866 grep '^ *+' $at_stder1 >&2 19867 grep -v '^ *+' $at_stder1 >$at_stderr 19868 at_failed=false 19869 $at_diff $at_devnull $at_stderr || at_failed=: 19870 $at_diff expout $at_stdout || at_failed=: 19871 case $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=:;; 19877 esac 19878 if $at_failed; then 19879 19880 echo 1 > $at_status_file 19881 exit 1 19882 fi 19883 19884 $at_traceon 19885 19886 19887 cat >input <<'_ATEOF' 19888 1//2 19889 _ATEOF 19890 19891 $at_traceoff 19892 echo "calc.at:559: \$PREPARSER ./calc input" 19893 echo calc.at:559 >$at_check_line_file 19894 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 19895 at_status=$? 19896 grep '^ *+' $at_stder1 >&2 19897 grep -v '^ *+' $at_stder1 >$at_stderr 19898 at_failed=false 19899 echo stderr:; tee stderr <$at_stderr 19900 $at_diff $at_devnull $at_stdout || at_failed=: 19901 case $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=:;; 19907 esac 19908 if $at_failed; then 19909 19910 echo 1 > $at_status_file 19911 exit 1 19912 fi 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. 19920 sed '/^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 19933 mv at-stderr stderr 19934 # 2. Create the reference error message. 19935 cat >expout <<'_ATEOF' 19936 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 19937 _ATEOF 19938 19939 # 3. If locations are not used, remove them. 19940 sed 's/^[-0-9.]*: //' expout >at-expout 19941 mv at-expout expout 19942 # 4. If error-verbose is not used, strip the`, unexpected....' part. 19943 sed 's/syntax error, .*$/syntax error/' expout >at-expout 19944 mv at-expout expout 19945 # 5. Check 19946 $at_traceoff 19947 echo "calc.at:559: cat stderr" 19948 echo calc.at:559 >$at_check_line_file 19949 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 19950 at_status=$? 19951 grep '^ *+' $at_stder1 >&2 19952 grep -v '^ *+' $at_stder1 >$at_stderr 19953 at_failed=false 19954 $at_diff $at_devnull $at_stderr || at_failed=: 19955 $at_diff expout $at_stdout || at_failed=: 19956 case $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=:;; 19962 esac 19963 if $at_failed; then 19964 19965 echo 1 > $at_status_file 19966 exit 1 19967 fi 19968 19969 $at_traceon 19970 19971 19972 cat >input <<'_ATEOF' 19973 error 19974 _ATEOF 19975 19976 $at_traceoff 19977 echo "calc.at:559: \$PREPARSER ./calc input" 19978 echo calc.at:559 >$at_check_line_file 19979 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 19980 at_status=$? 19981 grep '^ *+' $at_stder1 >&2 19982 grep -v '^ *+' $at_stder1 >$at_stderr 19983 at_failed=false 19984 echo stderr:; tee stderr <$at_stderr 19985 $at_diff $at_devnull $at_stdout || at_failed=: 19986 case $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=:;; 19992 esac 19993 if $at_failed; then 19994 19995 echo 1 > $at_status_file 19996 exit 1 19997 fi 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. 20005 sed '/^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 20018 mv at-stderr stderr 20019 # 2. Create the reference error message. 20020 cat >expout <<'_ATEOF' 20021 1.0: syntax error, unexpected $undefined 20022 _ATEOF 20023 20024 # 3. If locations are not used, remove them. 20025 sed 's/^[-0-9.]*: //' expout >at-expout 20026 mv at-expout expout 20027 # 4. If error-verbose is not used, strip the`, unexpected....' part. 20028 sed 's/syntax error, .*$/syntax error/' expout >at-expout 20029 mv at-expout expout 20030 # 5. Check 20031 $at_traceoff 20032 echo "calc.at:559: cat stderr" 20033 echo calc.at:559 >$at_check_line_file 20034 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 20035 at_status=$? 20036 grep '^ *+' $at_stder1 >&2 20037 grep -v '^ *+' $at_stder1 >$at_stderr 20038 at_failed=false 20039 $at_diff $at_devnull $at_stderr || at_failed=: 20040 $at_diff expout $at_stdout || at_failed=: 20041 case $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=:;; 20047 esac 20048 if $at_failed; then 20049 20050 echo 1 > $at_status_file 20051 exit 1 20052 fi 20053 20054 $at_traceon 20055 20056 20057 cat >input <<'_ATEOF' 20058 1 = 2 = 3 20059 _ATEOF 20060 20061 $at_traceoff 20062 echo "calc.at:559: \$PREPARSER ./calc input" 20063 echo calc.at:559 >$at_check_line_file 20064 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 20065 at_status=$? 20066 grep '^ *+' $at_stder1 >&2 20067 grep -v '^ *+' $at_stder1 >$at_stderr 20068 at_failed=false 20069 echo stderr:; tee stderr <$at_stderr 20070 $at_diff $at_devnull $at_stdout || at_failed=: 20071 case $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=:;; 20077 esac 20078 if $at_failed; then 20079 20080 echo 1 > $at_status_file 20081 exit 1 20082 fi 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. 20090 sed '/^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 20103 mv at-stderr stderr 20104 # 2. Create the reference error message. 20105 cat >expout <<'_ATEOF' 20106 1.6: syntax error, unexpected '=' 20107 _ATEOF 20108 20109 # 3. If locations are not used, remove them. 20110 sed 's/^[-0-9.]*: //' expout >at-expout 20111 mv at-expout expout 20112 # 4. If error-verbose is not used, strip the`, unexpected....' part. 20113 sed 's/syntax error, .*$/syntax error/' expout >at-expout 20114 mv at-expout expout 20115 # 5. Check 20116 $at_traceoff 20117 echo "calc.at:559: cat stderr" 20118 echo calc.at:559 >$at_check_line_file 20119 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 20120 at_status=$? 20121 grep '^ *+' $at_stder1 >&2 20122 grep -v '^ *+' $at_stder1 >$at_stderr 20123 at_failed=false 20124 $at_diff $at_devnull $at_stderr || at_failed=: 20125 $at_diff expout $at_stdout || at_failed=: 20126 case $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=:;; 20132 esac 20133 if $at_failed; then 20134 20135 echo 1 > $at_status_file 20136 exit 1 20137 fi 20138 20139 $at_traceon 20140 20141 20142 cat >input <<'_ATEOF' 20143 20144 +1 20145 _ATEOF 20146 20147 $at_traceoff 20148 echo "calc.at:559: \$PREPARSER ./calc input" 20149 echo calc.at:559 >$at_check_line_file 20150 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 20151 at_status=$? 20152 grep '^ *+' $at_stder1 >&2 20153 grep -v '^ *+' $at_stder1 >$at_stderr 20154 at_failed=false 20155 echo stderr:; tee stderr <$at_stderr 20156 $at_diff $at_devnull $at_stdout || at_failed=: 20157 case $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=:;; 20163 esac 20164 if $at_failed; then 20165 20166 echo 1 > $at_status_file 20167 exit 1 20168 fi 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. 20176 sed '/^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 20189 mv at-stderr stderr 20190 # 2. Create the reference error message. 20191 cat >expout <<'_ATEOF' 20192 2.0: syntax error, unexpected '+' 20193 _ATEOF 20194 20195 # 3. If locations are not used, remove them. 20196 sed 's/^[-0-9.]*: //' expout >at-expout 20197 mv at-expout expout 20198 # 4. If error-verbose is not used, strip the`, unexpected....' part. 20199 sed 's/syntax error, .*$/syntax error/' expout >at-expout 20200 mv at-expout expout 20201 # 5. Check 20202 $at_traceoff 20203 echo "calc.at:559: cat stderr" 20204 echo calc.at:559 >$at_check_line_file 20205 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 20206 at_status=$? 20207 grep '^ *+' $at_stder1 >&2 20208 grep -v '^ *+' $at_stder1 >$at_stderr 20209 at_failed=false 20210 $at_diff $at_devnull $at_stderr || at_failed=: 20211 $at_diff expout $at_stdout || at_failed=: 20212 case $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=:;; 20218 esac 20219 if $at_failed; then 20220 20221 echo 1 > $at_status_file 20222 exit 1 20223 fi 20224 20225 $at_traceon 20226 20227 20228 # Exercise error messages with EOF: work on an empty file. 20229 $at_traceoff 20230 echo "calc.at:559: \$PREPARSER ./calc /dev/null" 20231 echo calc.at:559 >$at_check_line_file 20232 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 20233 at_status=$? 20234 grep '^ *+' $at_stder1 >&2 20235 grep -v '^ *+' $at_stder1 >$at_stderr 20236 at_failed=false 20237 echo stderr:; tee stderr <$at_stderr 20238 $at_diff $at_devnull $at_stdout || at_failed=: 20239 case $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=:;; 20245 esac 20246 if $at_failed; then 20247 20248 echo 1 > $at_status_file 20249 exit 1 20250 fi 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. 20258 sed '/^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 20271 mv at-stderr stderr 20272 # 2. Create the reference error message. 20273 cat >expout <<'_ATEOF' 20274 1.0: syntax error, unexpected end of input 20275 _ATEOF 20276 20277 # 3. If locations are not used, remove them. 20278 sed 's/^[-0-9.]*: //' expout >at-expout 20279 mv at-expout expout 20280 # 4. If error-verbose is not used, strip the`, unexpected....' part. 20281 sed 's/syntax error, .*$/syntax error/' expout >at-expout 20282 mv at-expout expout 20283 # 5. Check 20284 $at_traceoff 20285 echo "calc.at:559: cat stderr" 20286 echo calc.at:559 >$at_check_line_file 20287 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 20288 at_status=$? 20289 grep '^ *+' $at_stder1 >&2 20290 grep -v '^ *+' $at_stder1 >$at_stderr 20291 at_failed=false 20292 $at_diff $at_devnull $at_stderr || at_failed=: 20293 $at_diff expout $at_stdout || at_failed=: 20294 case $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=:;; 20300 esac 20301 if $at_failed; then 20302 20303 echo 1 > $at_status_file 20304 exit 1 20305 fi 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 # 20327 cat >input <<'_ATEOF' 20328 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 20329 _ATEOF 20330 20331 $at_traceoff 20332 echo "calc.at:559: \$PREPARSER ./calc input" 20333 echo calc.at:559 >$at_check_line_file 20334 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 20335 at_status=$? 20336 grep '^ *+' $at_stder1 >&2 20337 grep -v '^ *+' $at_stder1 >$at_stderr 20338 at_failed=false 20339 echo stderr:; tee stderr <$at_stderr 20340 $at_diff $at_devnull $at_stdout || at_failed=: 20341 case $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=:;; 20347 esac 20348 if $at_failed; then 20349 20350 echo 1 > $at_status_file 20351 exit 1 20352 fi 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. 20360 sed '/^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 20373 mv at-stderr stderr 20374 # 2. Create the reference error message. 20375 cat >expout <<'_ATEOF' 20376 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 20377 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 20378 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 20379 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 20380 calc: error: 4444 != 1 20381 _ATEOF 20382 20383 # 3. If locations are not used, remove them. 20384 sed 's/^[-0-9.]*: //' expout >at-expout 20385 mv at-expout expout 20386 # 4. If error-verbose is not used, strip the`, unexpected....' part. 20387 sed 's/syntax error, .*$/syntax error/' expout >at-expout 20388 mv at-expout expout 20389 # 5. Check 20390 $at_traceoff 20391 echo "calc.at:559: cat stderr" 20392 echo calc.at:559 >$at_check_line_file 20393 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 20394 at_status=$? 20395 grep '^ *+' $at_stder1 >&2 20396 grep -v '^ *+' $at_stder1 >$at_stderr 20397 at_failed=false 20398 $at_diff $at_devnull $at_stderr || at_failed=: 20399 $at_diff expout $at_stdout || at_failed=: 20400 case $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=:;; 20406 esac 20407 if $at_failed; then 20408 20409 echo 1 > $at_status_file 20410 exit 1 20411 fi 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. 20419 cat >input <<'_ATEOF' 20420 (!) + (0 0) = 1 20421 _ATEOF 20422 20423 $at_traceoff 20424 echo "calc.at:559: \$PREPARSER ./calc input" 20425 echo calc.at:559 >$at_check_line_file 20426 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 20427 at_status=$? 20428 grep '^ *+' $at_stder1 >&2 20429 grep -v '^ *+' $at_stder1 >$at_stderr 20430 at_failed=false 20431 echo stderr:; tee stderr <$at_stderr 20432 $at_diff $at_devnull $at_stdout || at_failed=: 20433 case $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=:;; 20439 esac 20440 if $at_failed; then 20441 20442 echo 1 > $at_status_file 20443 exit 1 20444 fi 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. 20452 sed '/^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 20465 mv at-stderr stderr 20466 # 2. Create the reference error message. 20467 cat >expout <<'_ATEOF' 20468 1.9: syntax error, unexpected number 20469 calc: error: 2222 != 1 20470 _ATEOF 20471 20472 # 3. If locations are not used, remove them. 20473 sed 's/^[-0-9.]*: //' expout >at-expout 20474 mv at-expout expout 20475 # 4. If error-verbose is not used, strip the`, unexpected....' part. 20476 sed 's/syntax error, .*$/syntax error/' expout >at-expout 20477 mv at-expout expout 20478 # 5. Check 20479 $at_traceoff 20480 echo "calc.at:559: cat stderr" 20481 echo calc.at:559 >$at_check_line_file 20482 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 20483 at_status=$? 20484 grep '^ *+' $at_stder1 >&2 20485 grep -v '^ *+' $at_stder1 >$at_stderr 20486 at_failed=false 20487 $at_diff $at_devnull $at_stderr || at_failed=: 20488 $at_diff expout $at_stdout || at_failed=: 20489 case $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=:;; 20495 esac 20496 if $at_failed; then 20497 20498 echo 1 > $at_status_file 20499 exit 1 20500 fi 20501 20502 $at_traceon 20503 20504 20505 cat >input <<'_ATEOF' 20506 (- *) + (0 0) = 1 20507 _ATEOF 20508 20509 $at_traceoff 20510 echo "calc.at:559: \$PREPARSER ./calc input" 20511 echo calc.at:559 >$at_check_line_file 20512 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 20513 at_status=$? 20514 grep '^ *+' $at_stder1 >&2 20515 grep -v '^ *+' $at_stder1 >$at_stderr 20516 at_failed=false 20517 echo stderr:; tee stderr <$at_stderr 20518 $at_diff $at_devnull $at_stdout || at_failed=: 20519 case $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=:;; 20525 esac 20526 if $at_failed; then 20527 20528 echo 1 > $at_status_file 20529 exit 1 20530 fi 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. 20538 sed '/^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 20551 mv at-stderr stderr 20552 # 2. Create the reference error message. 20553 cat >expout <<'_ATEOF' 20554 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 20555 1.11: syntax error, unexpected number 20556 calc: error: 2222 != 1 20557 _ATEOF 20558 20559 # 3. If locations are not used, remove them. 20560 sed 's/^[-0-9.]*: //' expout >at-expout 20561 mv at-expout expout 20562 # 4. If error-verbose is not used, strip the`, unexpected....' part. 20563 sed 's/syntax error, .*$/syntax error/' expout >at-expout 20564 mv at-expout expout 20565 # 5. Check 20566 $at_traceoff 20567 echo "calc.at:559: cat stderr" 20568 echo calc.at:559 >$at_check_line_file 20569 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 20570 at_status=$? 20571 grep '^ *+' $at_stder1 >&2 20572 grep -v '^ *+' $at_stder1 >$at_stderr 20573 at_failed=false 20574 $at_diff $at_devnull $at_stderr || at_failed=: 20575 $at_diff expout $at_stdout || at_failed=: 20576 case $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=:;; 20582 esac 20583 if $at_failed; then 20584 20585 echo 1 > $at_status_file 20586 exit 1 20587 fi 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 20664 cat >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. */ 20693 typedef int semantic_value; 20694 20695 static semantic_value global_result = 0; 20696 static int global_count = 0; 20697 %} 20698 20699 /* Exercise %union. */ 20700 %union 20701 { 20702 semantic_value ival; 20703 }; 20704 20705 %{ 20706 static int power (int base, int exponent); 20707 /* yyerror receives the location if: 20708 - %location & %pure & %glr 20709 - %location & %pure & %yacc & %parse-param. */ 20710 static void yyerror ( 20711 20712 const char *s 20713 ); 20714 static int yylex (void); 20715 static int get_char (void); 20716 static 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 %% 20734 input: 20735 line 20736 | input line { } 20737 ; 20738 20739 line: 20740 '\n' 20741 | exp '\n' { USE ($1); } 20742 ; 20743 20744 exp: 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. */ 20765 static FILE *input; 20766 20767 static void 20768 yyerror ( 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 20788 static YYLTYPE last_yylloc; 20789 20790 static int 20791 get_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 20809 static void 20810 unget_char ( int c) 20811 { 20812 ; 20813 20814 /* Wrong when C == `\n'. */ 20815 (yylloc) = last_yylloc; 20816 20817 ungetc (c, input); 20818 } 20819 20820 static int 20821 read_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 20853 static int 20854 yylex (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 20897 static int 20898 power (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 20909 int 20910 main (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 20947 echo "calc.at:560: bison -o calc.c calc.y" 20948 echo calc.at:560 >$at_check_line_file 20949 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 20950 at_status=$? 20951 grep '^ *+' $at_stder1 >&2 20952 grep -v '^ *+' $at_stder1 >$at_stderr 20953 at_failed=false 20954 $at_diff $at_devnull $at_stderr || at_failed=: 20955 $at_diff $at_devnull $at_stdout || at_failed=: 20956 case $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=:;; 20962 esac 20963 if $at_failed; then 20964 20965 echo 1 > $at_status_file 20966 exit 1 20967 fi 20968 20969 $at_traceon 20970 20971 $at_traceoff 20972 echo "calc.at:560: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 20973 echo calc.at:560 >$at_check_line_file 20974 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 20975 at_status=$? 20976 grep '^ *+' $at_stder1 >&2 20977 grep -v '^ *+' $at_stder1 >$at_stderr 20978 at_failed=false 20979 echo stderr:; cat $at_stderr 20980 echo stdout:; cat $at_stdout 20981 case $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=:;; 20987 esac 20988 if $at_failed; then 20989 20990 echo 1 > $at_status_file 20991 exit 1 20992 fi 20993 20994 $at_traceon 20995 20996 20997 # Test the priorities. 20998 cat >input <<'_ATEOF' 20999 1 + 2 * 3 = 7 21000 1 + 2 * -3 = -5 21001 21002 -1^2 = -1 21003 (-1)^2 = 1 21004 21005 ---1 = -1 21006 21007 1 - 2 - 3 = -4 21008 1 - (2 - 3) = 2 21009 21010 2^2^3 = 256 21011 (2^2)^3 = 64 21012 _ATEOF 21013 21014 $at_traceoff 21015 echo "calc.at:560: \$PREPARSER ./calc input" 21016 echo calc.at:560 >$at_check_line_file 21017 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 21018 at_status=$? 21019 grep '^ *+' $at_stder1 >&2 21020 grep -v '^ *+' $at_stder1 >$at_stderr 21021 at_failed=false 21022 echo stderr:; tee stderr <$at_stderr 21023 $at_diff $at_devnull $at_stdout || at_failed=: 21024 case $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=:;; 21030 esac 21031 if $at_failed; then 21032 21033 echo 1 > $at_status_file 21034 exit 1 21035 fi 21036 21037 $at_traceon 21038 21039 21040 21041 # Some syntax errors. 21042 cat >input <<'_ATEOF' 21043 0 0 21044 _ATEOF 21045 21046 $at_traceoff 21047 echo "calc.at:560: \$PREPARSER ./calc input" 21048 echo calc.at:560 >$at_check_line_file 21049 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 21050 at_status=$? 21051 grep '^ *+' $at_stder1 >&2 21052 grep -v '^ *+' $at_stder1 >$at_stderr 21053 at_failed=false 21054 echo stderr:; tee stderr <$at_stderr 21055 $at_diff $at_devnull $at_stdout || at_failed=: 21056 case $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=:;; 21062 esac 21063 if $at_failed; then 21064 21065 echo 1 > $at_status_file 21066 exit 1 21067 fi 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. 21075 sed '/^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 21088 mv at-stderr stderr 21089 # 2. Create the reference error message. 21090 cat >expout <<'_ATEOF' 21091 1.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 21100 echo "calc.at:560: cat stderr" 21101 echo calc.at:560 >$at_check_line_file 21102 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 21103 at_status=$? 21104 grep '^ *+' $at_stder1 >&2 21105 grep -v '^ *+' $at_stder1 >$at_stderr 21106 at_failed=false 21107 $at_diff $at_devnull $at_stderr || at_failed=: 21108 $at_diff expout $at_stdout || at_failed=: 21109 case $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=:;; 21115 esac 21116 if $at_failed; then 21117 21118 echo 1 > $at_status_file 21119 exit 1 21120 fi 21121 21122 $at_traceon 21123 21124 21125 cat >input <<'_ATEOF' 21126 1//2 21127 _ATEOF 21128 21129 $at_traceoff 21130 echo "calc.at:560: \$PREPARSER ./calc input" 21131 echo calc.at:560 >$at_check_line_file 21132 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 21133 at_status=$? 21134 grep '^ *+' $at_stder1 >&2 21135 grep -v '^ *+' $at_stder1 >$at_stderr 21136 at_failed=false 21137 echo stderr:; tee stderr <$at_stderr 21138 $at_diff $at_devnull $at_stdout || at_failed=: 21139 case $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=:;; 21145 esac 21146 if $at_failed; then 21147 21148 echo 1 > $at_status_file 21149 exit 1 21150 fi 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. 21158 sed '/^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 21171 mv at-stderr stderr 21172 # 2. Create the reference error message. 21173 cat >expout <<'_ATEOF' 21174 1.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 21183 echo "calc.at:560: cat stderr" 21184 echo calc.at:560 >$at_check_line_file 21185 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 21186 at_status=$? 21187 grep '^ *+' $at_stder1 >&2 21188 grep -v '^ *+' $at_stder1 >$at_stderr 21189 at_failed=false 21190 $at_diff $at_devnull $at_stderr || at_failed=: 21191 $at_diff expout $at_stdout || at_failed=: 21192 case $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=:;; 21198 esac 21199 if $at_failed; then 21200 21201 echo 1 > $at_status_file 21202 exit 1 21203 fi 21204 21205 $at_traceon 21206 21207 21208 cat >input <<'_ATEOF' 21209 error 21210 _ATEOF 21211 21212 $at_traceoff 21213 echo "calc.at:560: \$PREPARSER ./calc input" 21214 echo calc.at:560 >$at_check_line_file 21215 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 21216 at_status=$? 21217 grep '^ *+' $at_stder1 >&2 21218 grep -v '^ *+' $at_stder1 >$at_stderr 21219 at_failed=false 21220 echo stderr:; tee stderr <$at_stderr 21221 $at_diff $at_devnull $at_stdout || at_failed=: 21222 case $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=:;; 21228 esac 21229 if $at_failed; then 21230 21231 echo 1 > $at_status_file 21232 exit 1 21233 fi 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. 21241 sed '/^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 21254 mv at-stderr stderr 21255 # 2. Create the reference error message. 21256 cat >expout <<'_ATEOF' 21257 1.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 21266 echo "calc.at:560: cat stderr" 21267 echo calc.at:560 >$at_check_line_file 21268 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 21269 at_status=$? 21270 grep '^ *+' $at_stder1 >&2 21271 grep -v '^ *+' $at_stder1 >$at_stderr 21272 at_failed=false 21273 $at_diff $at_devnull $at_stderr || at_failed=: 21274 $at_diff expout $at_stdout || at_failed=: 21275 case $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=:;; 21281 esac 21282 if $at_failed; then 21283 21284 echo 1 > $at_status_file 21285 exit 1 21286 fi 21287 21288 $at_traceon 21289 21290 21291 cat >input <<'_ATEOF' 21292 1 = 2 = 3 21293 _ATEOF 21294 21295 $at_traceoff 21296 echo "calc.at:560: \$PREPARSER ./calc input" 21297 echo calc.at:560 >$at_check_line_file 21298 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 21299 at_status=$? 21300 grep '^ *+' $at_stder1 >&2 21301 grep -v '^ *+' $at_stder1 >$at_stderr 21302 at_failed=false 21303 echo stderr:; tee stderr <$at_stderr 21304 $at_diff $at_devnull $at_stdout || at_failed=: 21305 case $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=:;; 21311 esac 21312 if $at_failed; then 21313 21314 echo 1 > $at_status_file 21315 exit 1 21316 fi 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. 21324 sed '/^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 21337 mv at-stderr stderr 21338 # 2. Create the reference error message. 21339 cat >expout <<'_ATEOF' 21340 1.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 21349 echo "calc.at:560: cat stderr" 21350 echo calc.at:560 >$at_check_line_file 21351 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 21352 at_status=$? 21353 grep '^ *+' $at_stder1 >&2 21354 grep -v '^ *+' $at_stder1 >$at_stderr 21355 at_failed=false 21356 $at_diff $at_devnull $at_stderr || at_failed=: 21357 $at_diff expout $at_stdout || at_failed=: 21358 case $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=:;; 21364 esac 21365 if $at_failed; then 21366 21367 echo 1 > $at_status_file 21368 exit 1 21369 fi 21370 21371 $at_traceon 21372 21373 21374 cat >input <<'_ATEOF' 21375 21376 +1 21377 _ATEOF 21378 21379 $at_traceoff 21380 echo "calc.at:560: \$PREPARSER ./calc input" 21381 echo calc.at:560 >$at_check_line_file 21382 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 21383 at_status=$? 21384 grep '^ *+' $at_stder1 >&2 21385 grep -v '^ *+' $at_stder1 >$at_stderr 21386 at_failed=false 21387 echo stderr:; tee stderr <$at_stderr 21388 $at_diff $at_devnull $at_stdout || at_failed=: 21389 case $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=:;; 21395 esac 21396 if $at_failed; then 21397 21398 echo 1 > $at_status_file 21399 exit 1 21400 fi 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. 21408 sed '/^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 21421 mv at-stderr stderr 21422 # 2. Create the reference error message. 21423 cat >expout <<'_ATEOF' 21424 2.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 21433 echo "calc.at:560: cat stderr" 21434 echo calc.at:560 >$at_check_line_file 21435 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 21436 at_status=$? 21437 grep '^ *+' $at_stder1 >&2 21438 grep -v '^ *+' $at_stder1 >$at_stderr 21439 at_failed=false 21440 $at_diff $at_devnull $at_stderr || at_failed=: 21441 $at_diff expout $at_stdout || at_failed=: 21442 case $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=:;; 21448 esac 21449 if $at_failed; then 21450 21451 echo 1 > $at_status_file 21452 exit 1 21453 fi 21454 21455 $at_traceon 21456 21457 21458 # Exercise error messages with EOF: work on an empty file. 21459 $at_traceoff 21460 echo "calc.at:560: \$PREPARSER ./calc /dev/null" 21461 echo calc.at:560 >$at_check_line_file 21462 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 21463 at_status=$? 21464 grep '^ *+' $at_stder1 >&2 21465 grep -v '^ *+' $at_stder1 >$at_stderr 21466 at_failed=false 21467 echo stderr:; tee stderr <$at_stderr 21468 $at_diff $at_devnull $at_stdout || at_failed=: 21469 case $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=:;; 21475 esac 21476 if $at_failed; then 21477 21478 echo 1 > $at_status_file 21479 exit 1 21480 fi 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. 21488 sed '/^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 21501 mv at-stderr stderr 21502 # 2. Create the reference error message. 21503 cat >expout <<'_ATEOF' 21504 1.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 21513 echo "calc.at:560: cat stderr" 21514 echo calc.at:560 >$at_check_line_file 21515 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 21516 at_status=$? 21517 grep '^ *+' $at_stder1 >&2 21518 grep -v '^ *+' $at_stder1 >$at_stderr 21519 at_failed=false 21520 $at_diff $at_devnull $at_stderr || at_failed=: 21521 $at_diff expout $at_stdout || at_failed=: 21522 case $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=:;; 21528 esac 21529 if $at_failed; then 21530 21531 echo 1 > $at_status_file 21532 exit 1 21533 fi 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 # 21555 cat >input <<'_ATEOF' 21556 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 21557 _ATEOF 21558 21559 $at_traceoff 21560 echo "calc.at:560: \$PREPARSER ./calc input" 21561 echo calc.at:560 >$at_check_line_file 21562 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 21563 at_status=$? 21564 grep '^ *+' $at_stder1 >&2 21565 grep -v '^ *+' $at_stder1 >$at_stderr 21566 at_failed=false 21567 echo stderr:; tee stderr <$at_stderr 21568 $at_diff $at_devnull $at_stdout || at_failed=: 21569 case $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=:;; 21575 esac 21576 if $at_failed; then 21577 21578 echo 1 > $at_status_file 21579 exit 1 21580 fi 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. 21588 sed '/^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 21601 mv at-stderr stderr 21602 # 2. Create the reference error message. 21603 cat >expout <<'_ATEOF' 21604 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 21605 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 21606 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 21607 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 21608 calc: 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 21617 echo "calc.at:560: cat stderr" 21618 echo calc.at:560 >$at_check_line_file 21619 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 21620 at_status=$? 21621 grep '^ *+' $at_stder1 >&2 21622 grep -v '^ *+' $at_stder1 >$at_stderr 21623 at_failed=false 21624 $at_diff $at_devnull $at_stderr || at_failed=: 21625 $at_diff expout $at_stdout || at_failed=: 21626 case $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=:;; 21632 esac 21633 if $at_failed; then 21634 21635 echo 1 > $at_status_file 21636 exit 1 21637 fi 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. 21645 cat >input <<'_ATEOF' 21646 (!) + (0 0) = 1 21647 _ATEOF 21648 21649 $at_traceoff 21650 echo "calc.at:560: \$PREPARSER ./calc input" 21651 echo calc.at:560 >$at_check_line_file 21652 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 21653 at_status=$? 21654 grep '^ *+' $at_stder1 >&2 21655 grep -v '^ *+' $at_stder1 >$at_stderr 21656 at_failed=false 21657 echo stderr:; tee stderr <$at_stderr 21658 $at_diff $at_devnull $at_stdout || at_failed=: 21659 case $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=:;; 21665 esac 21666 if $at_failed; then 21667 21668 echo 1 > $at_status_file 21669 exit 1 21670 fi 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. 21678 sed '/^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 21691 mv at-stderr stderr 21692 # 2. Create the reference error message. 21693 cat >expout <<'_ATEOF' 21694 1.9: syntax error, unexpected number 21695 calc: 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 21704 echo "calc.at:560: cat stderr" 21705 echo calc.at:560 >$at_check_line_file 21706 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 21707 at_status=$? 21708 grep '^ *+' $at_stder1 >&2 21709 grep -v '^ *+' $at_stder1 >$at_stderr 21710 at_failed=false 21711 $at_diff $at_devnull $at_stderr || at_failed=: 21712 $at_diff expout $at_stdout || at_failed=: 21713 case $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=:;; 21719 esac 21720 if $at_failed; then 21721 21722 echo 1 > $at_status_file 21723 exit 1 21724 fi 21725 21726 $at_traceon 21727 21728 21729 cat >input <<'_ATEOF' 21730 (- *) + (0 0) = 1 21731 _ATEOF 21732 21733 $at_traceoff 21734 echo "calc.at:560: \$PREPARSER ./calc input" 21735 echo calc.at:560 >$at_check_line_file 21736 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 21737 at_status=$? 21738 grep '^ *+' $at_stder1 >&2 21739 grep -v '^ *+' $at_stder1 >$at_stderr 21740 at_failed=false 21741 echo stderr:; tee stderr <$at_stderr 21742 $at_diff $at_devnull $at_stdout || at_failed=: 21743 case $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=:;; 21749 esac 21750 if $at_failed; then 21751 21752 echo 1 > $at_status_file 21753 exit 1 21754 fi 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. 21762 sed '/^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 21775 mv at-stderr stderr 21776 # 2. Create the reference error message. 21777 cat >expout <<'_ATEOF' 21778 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 21779 1.11: syntax error, unexpected number 21780 calc: 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 21789 echo "calc.at:560: cat stderr" 21790 echo calc.at:560 >$at_check_line_file 21791 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 21792 at_status=$? 21793 grep '^ *+' $at_stder1 >&2 21794 grep -v '^ *+' $at_stder1 >$at_stderr 21795 at_failed=false 21796 $at_diff $at_devnull $at_stderr || at_failed=: 21797 $at_diff expout $at_stdout || at_failed=: 21798 case $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=:;; 21804 esac 21805 if $at_failed; then 21806 21807 echo 1 > $at_status_file 21808 exit 1 21809 fi 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 21886 cat >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. */ 21915 typedef int semantic_value; 21916 21917 static semantic_value global_result = 0; 21918 static int global_count = 0; 21919 %} 21920 21921 /* Exercise %union. */ 21922 %union 21923 { 21924 semantic_value ival; 21925 }; 21926 21927 %{ 21928 static int power (int base, int exponent); 21929 /* yyerror receives the location if: 21930 - %location & %pure & %glr 21931 - %location & %pure & %yacc & %parse-param. */ 21932 static void yyerror ( 21933 21934 const char *s 21935 ); 21936 static int yylex (void); 21937 static int get_char (void); 21938 static 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 %% 21956 input: 21957 line 21958 | input line { } 21959 ; 21960 21961 line: 21962 '\n' 21963 | exp '\n' { USE ($1); } 21964 ; 21965 21966 exp: 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. */ 21987 static FILE *input; 21988 21989 static void 21990 yyerror ( 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 22010 static YYLTYPE last_yylloc; 22011 22012 static int 22013 get_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 22031 static void 22032 unget_char ( int c) 22033 { 22034 ; 22035 22036 /* Wrong when C == `\n'. */ 22037 (yylloc) = last_yylloc; 22038 22039 ungetc (c, input); 22040 } 22041 22042 static int 22043 read_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 22075 static int 22076 yylex (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 22119 static int 22120 power (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 22131 int 22132 main (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 22169 echo "calc.at:562: bison -o calc.c calc.y" 22170 echo calc.at:562 >$at_check_line_file 22171 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 22172 at_status=$? 22173 grep '^ *+' $at_stder1 >&2 22174 grep -v '^ *+' $at_stder1 >$at_stderr 22175 at_failed=false 22176 $at_diff $at_devnull $at_stderr || at_failed=: 22177 $at_diff $at_devnull $at_stdout || at_failed=: 22178 case $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=:;; 22184 esac 22185 if $at_failed; then 22186 22187 echo 1 > $at_status_file 22188 exit 1 22189 fi 22190 22191 $at_traceon 22192 22193 $at_traceoff 22194 echo "calc.at:562: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 22195 echo calc.at:562 >$at_check_line_file 22196 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 22197 at_status=$? 22198 grep '^ *+' $at_stder1 >&2 22199 grep -v '^ *+' $at_stder1 >$at_stderr 22200 at_failed=false 22201 echo stderr:; cat $at_stderr 22202 echo stdout:; cat $at_stdout 22203 case $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=:;; 22209 esac 22210 if $at_failed; then 22211 22212 echo 1 > $at_status_file 22213 exit 1 22214 fi 22215 22216 $at_traceon 22217 22218 22219 # Test the priorities. 22220 cat >input <<'_ATEOF' 22221 1 + 2 * 3 = 7 22222 1 + 2 * -3 = -5 22223 22224 -1^2 = -1 22225 (-1)^2 = 1 22226 22227 ---1 = -1 22228 22229 1 - 2 - 3 = -4 22230 1 - (2 - 3) = 2 22231 22232 2^2^3 = 256 22233 (2^2)^3 = 64 22234 _ATEOF 22235 22236 $at_traceoff 22237 echo "calc.at:562: \$PREPARSER ./calc input" 22238 echo calc.at:562 >$at_check_line_file 22239 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 22240 at_status=$? 22241 grep '^ *+' $at_stder1 >&2 22242 grep -v '^ *+' $at_stder1 >$at_stderr 22243 at_failed=false 22244 echo stderr:; tee stderr <$at_stderr 22245 $at_diff $at_devnull $at_stdout || at_failed=: 22246 case $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=:;; 22252 esac 22253 if $at_failed; then 22254 22255 echo 1 > $at_status_file 22256 exit 1 22257 fi 22258 22259 $at_traceon 22260 22261 22262 22263 # Some syntax errors. 22264 cat >input <<'_ATEOF' 22265 0 0 22266 _ATEOF 22267 22268 $at_traceoff 22269 echo "calc.at:562: \$PREPARSER ./calc input" 22270 echo calc.at:562 >$at_check_line_file 22271 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 22272 at_status=$? 22273 grep '^ *+' $at_stder1 >&2 22274 grep -v '^ *+' $at_stder1 >$at_stderr 22275 at_failed=false 22276 echo stderr:; tee stderr <$at_stderr 22277 $at_diff $at_devnull $at_stdout || at_failed=: 22278 case $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=:;; 22284 esac 22285 if $at_failed; then 22286 22287 echo 1 > $at_status_file 22288 exit 1 22289 fi 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. 22297 sed '/^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 22310 mv at-stderr stderr 22311 # 2. Create the reference error message. 22312 cat >expout <<'_ATEOF' 22313 1.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 22322 echo "calc.at:562: cat stderr" 22323 echo calc.at:562 >$at_check_line_file 22324 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 22325 at_status=$? 22326 grep '^ *+' $at_stder1 >&2 22327 grep -v '^ *+' $at_stder1 >$at_stderr 22328 at_failed=false 22329 $at_diff $at_devnull $at_stderr || at_failed=: 22330 $at_diff expout $at_stdout || at_failed=: 22331 case $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=:;; 22337 esac 22338 if $at_failed; then 22339 22340 echo 1 > $at_status_file 22341 exit 1 22342 fi 22343 22344 $at_traceon 22345 22346 22347 cat >input <<'_ATEOF' 22348 1//2 22349 _ATEOF 22350 22351 $at_traceoff 22352 echo "calc.at:562: \$PREPARSER ./calc input" 22353 echo calc.at:562 >$at_check_line_file 22354 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 22355 at_status=$? 22356 grep '^ *+' $at_stder1 >&2 22357 grep -v '^ *+' $at_stder1 >$at_stderr 22358 at_failed=false 22359 echo stderr:; tee stderr <$at_stderr 22360 $at_diff $at_devnull $at_stdout || at_failed=: 22361 case $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=:;; 22367 esac 22368 if $at_failed; then 22369 22370 echo 1 > $at_status_file 22371 exit 1 22372 fi 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. 22380 sed '/^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 22393 mv at-stderr stderr 22394 # 2. Create the reference error message. 22395 cat >expout <<'_ATEOF' 22396 1.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 22405 echo "calc.at:562: cat stderr" 22406 echo calc.at:562 >$at_check_line_file 22407 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 22408 at_status=$? 22409 grep '^ *+' $at_stder1 >&2 22410 grep -v '^ *+' $at_stder1 >$at_stderr 22411 at_failed=false 22412 $at_diff $at_devnull $at_stderr || at_failed=: 22413 $at_diff expout $at_stdout || at_failed=: 22414 case $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=:;; 22420 esac 22421 if $at_failed; then 22422 22423 echo 1 > $at_status_file 22424 exit 1 22425 fi 22426 22427 $at_traceon 22428 22429 22430 cat >input <<'_ATEOF' 22431 error 22432 _ATEOF 22433 22434 $at_traceoff 22435 echo "calc.at:562: \$PREPARSER ./calc input" 22436 echo calc.at:562 >$at_check_line_file 22437 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 22438 at_status=$? 22439 grep '^ *+' $at_stder1 >&2 22440 grep -v '^ *+' $at_stder1 >$at_stderr 22441 at_failed=false 22442 echo stderr:; tee stderr <$at_stderr 22443 $at_diff $at_devnull $at_stdout || at_failed=: 22444 case $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=:;; 22450 esac 22451 if $at_failed; then 22452 22453 echo 1 > $at_status_file 22454 exit 1 22455 fi 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. 22463 sed '/^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 22476 mv at-stderr stderr 22477 # 2. Create the reference error message. 22478 cat >expout <<'_ATEOF' 22479 1.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 22488 echo "calc.at:562: cat stderr" 22489 echo calc.at:562 >$at_check_line_file 22490 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 22491 at_status=$? 22492 grep '^ *+' $at_stder1 >&2 22493 grep -v '^ *+' $at_stder1 >$at_stderr 22494 at_failed=false 22495 $at_diff $at_devnull $at_stderr || at_failed=: 22496 $at_diff expout $at_stdout || at_failed=: 22497 case $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=:;; 22503 esac 22504 if $at_failed; then 22505 22506 echo 1 > $at_status_file 22507 exit 1 22508 fi 22509 22510 $at_traceon 22511 22512 22513 cat >input <<'_ATEOF' 22514 1 = 2 = 3 22515 _ATEOF 22516 22517 $at_traceoff 22518 echo "calc.at:562: \$PREPARSER ./calc input" 22519 echo calc.at:562 >$at_check_line_file 22520 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 22521 at_status=$? 22522 grep '^ *+' $at_stder1 >&2 22523 grep -v '^ *+' $at_stder1 >$at_stderr 22524 at_failed=false 22525 echo stderr:; tee stderr <$at_stderr 22526 $at_diff $at_devnull $at_stdout || at_failed=: 22527 case $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=:;; 22533 esac 22534 if $at_failed; then 22535 22536 echo 1 > $at_status_file 22537 exit 1 22538 fi 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. 22546 sed '/^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 22559 mv at-stderr stderr 22560 # 2. Create the reference error message. 22561 cat >expout <<'_ATEOF' 22562 1.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 22571 echo "calc.at:562: cat stderr" 22572 echo calc.at:562 >$at_check_line_file 22573 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 22574 at_status=$? 22575 grep '^ *+' $at_stder1 >&2 22576 grep -v '^ *+' $at_stder1 >$at_stderr 22577 at_failed=false 22578 $at_diff $at_devnull $at_stderr || at_failed=: 22579 $at_diff expout $at_stdout || at_failed=: 22580 case $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=:;; 22586 esac 22587 if $at_failed; then 22588 22589 echo 1 > $at_status_file 22590 exit 1 22591 fi 22592 22593 $at_traceon 22594 22595 22596 cat >input <<'_ATEOF' 22597 22598 +1 22599 _ATEOF 22600 22601 $at_traceoff 22602 echo "calc.at:562: \$PREPARSER ./calc input" 22603 echo calc.at:562 >$at_check_line_file 22604 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 22605 at_status=$? 22606 grep '^ *+' $at_stder1 >&2 22607 grep -v '^ *+' $at_stder1 >$at_stderr 22608 at_failed=false 22609 echo stderr:; tee stderr <$at_stderr 22610 $at_diff $at_devnull $at_stdout || at_failed=: 22611 case $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=:;; 22617 esac 22618 if $at_failed; then 22619 22620 echo 1 > $at_status_file 22621 exit 1 22622 fi 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. 22630 sed '/^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 22643 mv at-stderr stderr 22644 # 2. Create the reference error message. 22645 cat >expout <<'_ATEOF' 22646 2.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 22655 echo "calc.at:562: cat stderr" 22656 echo calc.at:562 >$at_check_line_file 22657 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 22658 at_status=$? 22659 grep '^ *+' $at_stder1 >&2 22660 grep -v '^ *+' $at_stder1 >$at_stderr 22661 at_failed=false 22662 $at_diff $at_devnull $at_stderr || at_failed=: 22663 $at_diff expout $at_stdout || at_failed=: 22664 case $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=:;; 22670 esac 22671 if $at_failed; then 22672 22673 echo 1 > $at_status_file 22674 exit 1 22675 fi 22676 22677 $at_traceon 22678 22679 22680 # Exercise error messages with EOF: work on an empty file. 22681 $at_traceoff 22682 echo "calc.at:562: \$PREPARSER ./calc /dev/null" 22683 echo calc.at:562 >$at_check_line_file 22684 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 22685 at_status=$? 22686 grep '^ *+' $at_stder1 >&2 22687 grep -v '^ *+' $at_stder1 >$at_stderr 22688 at_failed=false 22689 echo stderr:; tee stderr <$at_stderr 22690 $at_diff $at_devnull $at_stdout || at_failed=: 22691 case $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=:;; 22697 esac 22698 if $at_failed; then 22699 22700 echo 1 > $at_status_file 22701 exit 1 22702 fi 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. 22710 sed '/^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 22723 mv at-stderr stderr 22724 # 2. Create the reference error message. 22725 cat >expout <<'_ATEOF' 22726 1.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 22735 echo "calc.at:562: cat stderr" 22736 echo calc.at:562 >$at_check_line_file 22737 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 22738 at_status=$? 22739 grep '^ *+' $at_stder1 >&2 22740 grep -v '^ *+' $at_stder1 >$at_stderr 22741 at_failed=false 22742 $at_diff $at_devnull $at_stderr || at_failed=: 22743 $at_diff expout $at_stdout || at_failed=: 22744 case $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=:;; 22750 esac 22751 if $at_failed; then 22752 22753 echo 1 > $at_status_file 22754 exit 1 22755 fi 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 # 22777 cat >input <<'_ATEOF' 22778 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 22779 _ATEOF 22780 22781 $at_traceoff 22782 echo "calc.at:562: \$PREPARSER ./calc input" 22783 echo calc.at:562 >$at_check_line_file 22784 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 22785 at_status=$? 22786 grep '^ *+' $at_stder1 >&2 22787 grep -v '^ *+' $at_stder1 >$at_stderr 22788 at_failed=false 22789 echo stderr:; tee stderr <$at_stderr 22790 $at_diff $at_devnull $at_stdout || at_failed=: 22791 case $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=:;; 22797 esac 22798 if $at_failed; then 22799 22800 echo 1 > $at_status_file 22801 exit 1 22802 fi 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. 22810 sed '/^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 22823 mv at-stderr stderr 22824 # 2. Create the reference error message. 22825 cat >expout <<'_ATEOF' 22826 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 22827 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 22828 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 22829 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 22830 calc: 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 22839 echo "calc.at:562: cat stderr" 22840 echo calc.at:562 >$at_check_line_file 22841 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 22842 at_status=$? 22843 grep '^ *+' $at_stder1 >&2 22844 grep -v '^ *+' $at_stder1 >$at_stderr 22845 at_failed=false 22846 $at_diff $at_devnull $at_stderr || at_failed=: 22847 $at_diff expout $at_stdout || at_failed=: 22848 case $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=:;; 22854 esac 22855 if $at_failed; then 22856 22857 echo 1 > $at_status_file 22858 exit 1 22859 fi 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. 22867 cat >input <<'_ATEOF' 22868 (!) + (0 0) = 1 22869 _ATEOF 22870 22871 $at_traceoff 22872 echo "calc.at:562: \$PREPARSER ./calc input" 22873 echo calc.at:562 >$at_check_line_file 22874 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 22875 at_status=$? 22876 grep '^ *+' $at_stder1 >&2 22877 grep -v '^ *+' $at_stder1 >$at_stderr 22878 at_failed=false 22879 echo stderr:; tee stderr <$at_stderr 22880 $at_diff $at_devnull $at_stdout || at_failed=: 22881 case $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=:;; 22887 esac 22888 if $at_failed; then 22889 22890 echo 1 > $at_status_file 22891 exit 1 22892 fi 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. 22900 sed '/^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 22913 mv at-stderr stderr 22914 # 2. Create the reference error message. 22915 cat >expout <<'_ATEOF' 22916 1.9: syntax error, unexpected number 22917 calc: 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 22926 echo "calc.at:562: cat stderr" 22927 echo calc.at:562 >$at_check_line_file 22928 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 22929 at_status=$? 22930 grep '^ *+' $at_stder1 >&2 22931 grep -v '^ *+' $at_stder1 >$at_stderr 22932 at_failed=false 22933 $at_diff $at_devnull $at_stderr || at_failed=: 22934 $at_diff expout $at_stdout || at_failed=: 22935 case $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=:;; 22941 esac 22942 if $at_failed; then 22943 22944 echo 1 > $at_status_file 22945 exit 1 22946 fi 22947 22948 $at_traceon 22949 22950 22951 cat >input <<'_ATEOF' 22952 (- *) + (0 0) = 1 22953 _ATEOF 22954 22955 $at_traceoff 22956 echo "calc.at:562: \$PREPARSER ./calc input" 22957 echo calc.at:562 >$at_check_line_file 22958 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 22959 at_status=$? 22960 grep '^ *+' $at_stder1 >&2 22961 grep -v '^ *+' $at_stder1 >$at_stderr 22962 at_failed=false 22963 echo stderr:; tee stderr <$at_stderr 22964 $at_diff $at_devnull $at_stdout || at_failed=: 22965 case $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=:;; 22971 esac 22972 if $at_failed; then 22973 22974 echo 1 > $at_status_file 22975 exit 1 22976 fi 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. 22984 sed '/^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 22997 mv at-stderr stderr 22998 # 2. Create the reference error message. 22999 cat >expout <<'_ATEOF' 23000 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 23001 1.11: syntax error, unexpected number 23002 calc: 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 23011 echo "calc.at:562: cat stderr" 23012 echo calc.at:562 >$at_check_line_file 23013 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 23014 at_status=$? 23015 grep '^ *+' $at_stder1 >&2 23016 grep -v '^ *+' $at_stder1 >$at_stderr 23017 at_failed=false 23018 $at_diff $at_devnull $at_stderr || at_failed=: 23019 $at_diff expout $at_stdout || at_failed=: 23020 case $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=:;; 23026 esac 23027 if $at_failed; then 23028 23029 echo 1 > $at_status_file 23030 exit 1 23031 fi 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 23108 cat >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. */ 23137 typedef int semantic_value; 23138 23139 static semantic_value global_result = 0; 23140 static int global_count = 0; 23141 %} 23142 23143 /* Exercise %union. */ 23144 %union 23145 { 23146 semantic_value ival; 23147 }; 23148 23149 %{ 23150 static int power (int base, int exponent); 23151 /* yyerror receives the location if: 23152 - %location & %pure & %glr 23153 - %location & %pure & %yacc & %parse-param. */ 23154 static void yyerror ( 23155 23156 const char *s 23157 ); 23158 static int yylex (void); 23159 static int get_char (void); 23160 static 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 %% 23178 input: 23179 line 23180 | input line { } 23181 ; 23182 23183 line: 23184 '\n' 23185 | exp '\n' { USE ($1); } 23186 ; 23187 23188 exp: 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. */ 23209 static FILE *input; 23210 23211 static void 23212 yyerror ( 23213 23214 const char *s) 23215 { 23216 23217 23218 fprintf (stderr, "%s\n", s); 23219 } 23220 23221 23222 23223 static int 23224 get_char (void) 23225 { 23226 int res = getc (input); 23227 ; 23228 23229 return res; 23230 } 23231 23232 23233 static void 23234 unget_char ( int c) 23235 { 23236 ; 23237 23238 ungetc (c, input); 23239 } 23240 23241 static int 23242 read_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 23274 static int 23275 yylex (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 23310 static int 23311 power (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 23322 int 23323 main (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 23360 echo "calc.at:564: bison -o calc.c calc.y" 23361 echo calc.at:564 >$at_check_line_file 23362 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 23363 at_status=$? 23364 grep '^ *+' $at_stder1 >&2 23365 grep -v '^ *+' $at_stder1 >$at_stderr 23366 at_failed=false 23367 $at_diff $at_devnull $at_stderr || at_failed=: 23368 $at_diff $at_devnull $at_stdout || at_failed=: 23369 case $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=:;; 23375 esac 23376 if $at_failed; then 23377 23378 echo 1 > $at_status_file 23379 exit 1 23380 fi 23381 23382 $at_traceon 23383 23384 $at_traceoff 23385 echo "calc.at:564: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 23386 echo calc.at:564 >$at_check_line_file 23387 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 23388 at_status=$? 23389 grep '^ *+' $at_stder1 >&2 23390 grep -v '^ *+' $at_stder1 >$at_stderr 23391 at_failed=false 23392 echo stderr:; cat $at_stderr 23393 echo stdout:; cat $at_stdout 23394 case $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=:;; 23400 esac 23401 if $at_failed; then 23402 23403 echo 1 > $at_status_file 23404 exit 1 23405 fi 23406 23407 $at_traceon 23408 23409 23410 # Test the priorities. 23411 cat >input <<'_ATEOF' 23412 1 + 2 * 3 = 7 23413 1 + 2 * -3 = -5 23414 23415 -1^2 = -1 23416 (-1)^2 = 1 23417 23418 ---1 = -1 23419 23420 1 - 2 - 3 = -4 23421 1 - (2 - 3) = 2 23422 23423 2^2^3 = 256 23424 (2^2)^3 = 64 23425 _ATEOF 23426 23427 $at_traceoff 23428 echo "calc.at:564: \$PREPARSER ./calc input" 23429 echo calc.at:564 >$at_check_line_file 23430 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 23431 at_status=$? 23432 grep '^ *+' $at_stder1 >&2 23433 grep -v '^ *+' $at_stder1 >$at_stderr 23434 at_failed=false 23435 echo stderr:; tee stderr <$at_stderr 23436 $at_diff $at_devnull $at_stdout || at_failed=: 23437 case $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=:;; 23443 esac 23444 if $at_failed; then 23445 23446 echo 1 > $at_status_file 23447 exit 1 23448 fi 23449 23450 $at_traceon 23451 23452 23453 23454 # Some syntax errors. 23455 cat >input <<'_ATEOF' 23456 0 0 23457 _ATEOF 23458 23459 $at_traceoff 23460 echo "calc.at:564: \$PREPARSER ./calc input" 23461 echo calc.at:564 >$at_check_line_file 23462 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 23463 at_status=$? 23464 grep '^ *+' $at_stder1 >&2 23465 grep -v '^ *+' $at_stder1 >$at_stderr 23466 at_failed=false 23467 echo stderr:; tee stderr <$at_stderr 23468 $at_diff $at_devnull $at_stdout || at_failed=: 23469 case $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=:;; 23475 esac 23476 if $at_failed; then 23477 23478 echo 1 > $at_status_file 23479 exit 1 23480 fi 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. 23488 sed '/^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 23501 mv at-stderr stderr 23502 # 2. Create the reference error message. 23503 cat >expout <<'_ATEOF' 23504 1.2: syntax error, unexpected number 23505 _ATEOF 23506 23507 # 3. If locations are not used, remove them. 23508 sed 's/^[-0-9.]*: //' expout >at-expout 23509 mv at-expout expout 23510 # 4. If error-verbose is not used, strip the`, unexpected....' part. 23511 sed 's/syntax error, .*$/syntax error/' expout >at-expout 23512 mv at-expout expout 23513 # 5. Check 23514 $at_traceoff 23515 echo "calc.at:564: cat stderr" 23516 echo calc.at:564 >$at_check_line_file 23517 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 23518 at_status=$? 23519 grep '^ *+' $at_stder1 >&2 23520 grep -v '^ *+' $at_stder1 >$at_stderr 23521 at_failed=false 23522 $at_diff $at_devnull $at_stderr || at_failed=: 23523 $at_diff expout $at_stdout || at_failed=: 23524 case $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=:;; 23530 esac 23531 if $at_failed; then 23532 23533 echo 1 > $at_status_file 23534 exit 1 23535 fi 23536 23537 $at_traceon 23538 23539 23540 cat >input <<'_ATEOF' 23541 1//2 23542 _ATEOF 23543 23544 $at_traceoff 23545 echo "calc.at:564: \$PREPARSER ./calc input" 23546 echo calc.at:564 >$at_check_line_file 23547 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 23548 at_status=$? 23549 grep '^ *+' $at_stder1 >&2 23550 grep -v '^ *+' $at_stder1 >$at_stderr 23551 at_failed=false 23552 echo stderr:; tee stderr <$at_stderr 23553 $at_diff $at_devnull $at_stdout || at_failed=: 23554 case $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=:;; 23560 esac 23561 if $at_failed; then 23562 23563 echo 1 > $at_status_file 23564 exit 1 23565 fi 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. 23573 sed '/^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 23586 mv at-stderr stderr 23587 # 2. Create the reference error message. 23588 cat >expout <<'_ATEOF' 23589 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 23590 _ATEOF 23591 23592 # 3. If locations are not used, remove them. 23593 sed 's/^[-0-9.]*: //' expout >at-expout 23594 mv at-expout expout 23595 # 4. If error-verbose is not used, strip the`, unexpected....' part. 23596 sed 's/syntax error, .*$/syntax error/' expout >at-expout 23597 mv at-expout expout 23598 # 5. Check 23599 $at_traceoff 23600 echo "calc.at:564: cat stderr" 23601 echo calc.at:564 >$at_check_line_file 23602 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 23603 at_status=$? 23604 grep '^ *+' $at_stder1 >&2 23605 grep -v '^ *+' $at_stder1 >$at_stderr 23606 at_failed=false 23607 $at_diff $at_devnull $at_stderr || at_failed=: 23608 $at_diff expout $at_stdout || at_failed=: 23609 case $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=:;; 23615 esac 23616 if $at_failed; then 23617 23618 echo 1 > $at_status_file 23619 exit 1 23620 fi 23621 23622 $at_traceon 23623 23624 23625 cat >input <<'_ATEOF' 23626 error 23627 _ATEOF 23628 23629 $at_traceoff 23630 echo "calc.at:564: \$PREPARSER ./calc input" 23631 echo calc.at:564 >$at_check_line_file 23632 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 23633 at_status=$? 23634 grep '^ *+' $at_stder1 >&2 23635 grep -v '^ *+' $at_stder1 >$at_stderr 23636 at_failed=false 23637 echo stderr:; tee stderr <$at_stderr 23638 $at_diff $at_devnull $at_stdout || at_failed=: 23639 case $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=:;; 23645 esac 23646 if $at_failed; then 23647 23648 echo 1 > $at_status_file 23649 exit 1 23650 fi 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. 23658 sed '/^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 23671 mv at-stderr stderr 23672 # 2. Create the reference error message. 23673 cat >expout <<'_ATEOF' 23674 1.0: syntax error, unexpected $undefined 23675 _ATEOF 23676 23677 # 3. If locations are not used, remove them. 23678 sed 's/^[-0-9.]*: //' expout >at-expout 23679 mv at-expout expout 23680 # 4. If error-verbose is not used, strip the`, unexpected....' part. 23681 sed 's/syntax error, .*$/syntax error/' expout >at-expout 23682 mv at-expout expout 23683 # 5. Check 23684 $at_traceoff 23685 echo "calc.at:564: cat stderr" 23686 echo calc.at:564 >$at_check_line_file 23687 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 23688 at_status=$? 23689 grep '^ *+' $at_stder1 >&2 23690 grep -v '^ *+' $at_stder1 >$at_stderr 23691 at_failed=false 23692 $at_diff $at_devnull $at_stderr || at_failed=: 23693 $at_diff expout $at_stdout || at_failed=: 23694 case $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=:;; 23700 esac 23701 if $at_failed; then 23702 23703 echo 1 > $at_status_file 23704 exit 1 23705 fi 23706 23707 $at_traceon 23708 23709 23710 cat >input <<'_ATEOF' 23711 1 = 2 = 3 23712 _ATEOF 23713 23714 $at_traceoff 23715 echo "calc.at:564: \$PREPARSER ./calc input" 23716 echo calc.at:564 >$at_check_line_file 23717 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 23718 at_status=$? 23719 grep '^ *+' $at_stder1 >&2 23720 grep -v '^ *+' $at_stder1 >$at_stderr 23721 at_failed=false 23722 echo stderr:; tee stderr <$at_stderr 23723 $at_diff $at_devnull $at_stdout || at_failed=: 23724 case $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=:;; 23730 esac 23731 if $at_failed; then 23732 23733 echo 1 > $at_status_file 23734 exit 1 23735 fi 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. 23743 sed '/^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 23756 mv at-stderr stderr 23757 # 2. Create the reference error message. 23758 cat >expout <<'_ATEOF' 23759 1.6: syntax error, unexpected '=' 23760 _ATEOF 23761 23762 # 3. If locations are not used, remove them. 23763 sed 's/^[-0-9.]*: //' expout >at-expout 23764 mv at-expout expout 23765 # 4. If error-verbose is not used, strip the`, unexpected....' part. 23766 sed 's/syntax error, .*$/syntax error/' expout >at-expout 23767 mv at-expout expout 23768 # 5. Check 23769 $at_traceoff 23770 echo "calc.at:564: cat stderr" 23771 echo calc.at:564 >$at_check_line_file 23772 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 23773 at_status=$? 23774 grep '^ *+' $at_stder1 >&2 23775 grep -v '^ *+' $at_stder1 >$at_stderr 23776 at_failed=false 23777 $at_diff $at_devnull $at_stderr || at_failed=: 23778 $at_diff expout $at_stdout || at_failed=: 23779 case $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=:;; 23785 esac 23786 if $at_failed; then 23787 23788 echo 1 > $at_status_file 23789 exit 1 23790 fi 23791 23792 $at_traceon 23793 23794 23795 cat >input <<'_ATEOF' 23796 23797 +1 23798 _ATEOF 23799 23800 $at_traceoff 23801 echo "calc.at:564: \$PREPARSER ./calc input" 23802 echo calc.at:564 >$at_check_line_file 23803 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 23804 at_status=$? 23805 grep '^ *+' $at_stder1 >&2 23806 grep -v '^ *+' $at_stder1 >$at_stderr 23807 at_failed=false 23808 echo stderr:; tee stderr <$at_stderr 23809 $at_diff $at_devnull $at_stdout || at_failed=: 23810 case $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=:;; 23816 esac 23817 if $at_failed; then 23818 23819 echo 1 > $at_status_file 23820 exit 1 23821 fi 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. 23829 sed '/^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 23842 mv at-stderr stderr 23843 # 2. Create the reference error message. 23844 cat >expout <<'_ATEOF' 23845 2.0: syntax error, unexpected '+' 23846 _ATEOF 23847 23848 # 3. If locations are not used, remove them. 23849 sed 's/^[-0-9.]*: //' expout >at-expout 23850 mv at-expout expout 23851 # 4. If error-verbose is not used, strip the`, unexpected....' part. 23852 sed 's/syntax error, .*$/syntax error/' expout >at-expout 23853 mv at-expout expout 23854 # 5. Check 23855 $at_traceoff 23856 echo "calc.at:564: cat stderr" 23857 echo calc.at:564 >$at_check_line_file 23858 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 23859 at_status=$? 23860 grep '^ *+' $at_stder1 >&2 23861 grep -v '^ *+' $at_stder1 >$at_stderr 23862 at_failed=false 23863 $at_diff $at_devnull $at_stderr || at_failed=: 23864 $at_diff expout $at_stdout || at_failed=: 23865 case $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=:;; 23871 esac 23872 if $at_failed; then 23873 23874 echo 1 > $at_status_file 23875 exit 1 23876 fi 23877 23878 $at_traceon 23879 23880 23881 # Exercise error messages with EOF: work on an empty file. 23882 $at_traceoff 23883 echo "calc.at:564: \$PREPARSER ./calc /dev/null" 23884 echo calc.at:564 >$at_check_line_file 23885 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 23886 at_status=$? 23887 grep '^ *+' $at_stder1 >&2 23888 grep -v '^ *+' $at_stder1 >$at_stderr 23889 at_failed=false 23890 echo stderr:; tee stderr <$at_stderr 23891 $at_diff $at_devnull $at_stdout || at_failed=: 23892 case $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=:;; 23898 esac 23899 if $at_failed; then 23900 23901 echo 1 > $at_status_file 23902 exit 1 23903 fi 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. 23911 sed '/^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 23924 mv at-stderr stderr 23925 # 2. Create the reference error message. 23926 cat >expout <<'_ATEOF' 23927 1.0: syntax error, unexpected end of input 23928 _ATEOF 23929 23930 # 3. If locations are not used, remove them. 23931 sed 's/^[-0-9.]*: //' expout >at-expout 23932 mv at-expout expout 23933 # 4. If error-verbose is not used, strip the`, unexpected....' part. 23934 sed 's/syntax error, .*$/syntax error/' expout >at-expout 23935 mv at-expout expout 23936 # 5. Check 23937 $at_traceoff 23938 echo "calc.at:564: cat stderr" 23939 echo calc.at:564 >$at_check_line_file 23940 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 23941 at_status=$? 23942 grep '^ *+' $at_stder1 >&2 23943 grep -v '^ *+' $at_stder1 >$at_stderr 23944 at_failed=false 23945 $at_diff $at_devnull $at_stderr || at_failed=: 23946 $at_diff expout $at_stdout || at_failed=: 23947 case $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=:;; 23953 esac 23954 if $at_failed; then 23955 23956 echo 1 > $at_status_file 23957 exit 1 23958 fi 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 # 23980 cat >input <<'_ATEOF' 23981 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 23982 _ATEOF 23983 23984 $at_traceoff 23985 echo "calc.at:564: \$PREPARSER ./calc input" 23986 echo calc.at:564 >$at_check_line_file 23987 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 23988 at_status=$? 23989 grep '^ *+' $at_stder1 >&2 23990 grep -v '^ *+' $at_stder1 >$at_stderr 23991 at_failed=false 23992 echo stderr:; tee stderr <$at_stderr 23993 $at_diff $at_devnull $at_stdout || at_failed=: 23994 case $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=:;; 24000 esac 24001 if $at_failed; then 24002 24003 echo 1 > $at_status_file 24004 exit 1 24005 fi 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. 24013 sed '/^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 24026 mv at-stderr stderr 24027 # 2. Create the reference error message. 24028 cat >expout <<'_ATEOF' 24029 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 24030 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 24031 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 24032 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 24033 calc: error: 4444 != 1 24034 _ATEOF 24035 24036 # 3. If locations are not used, remove them. 24037 sed 's/^[-0-9.]*: //' expout >at-expout 24038 mv at-expout expout 24039 # 4. If error-verbose is not used, strip the`, unexpected....' part. 24040 sed 's/syntax error, .*$/syntax error/' expout >at-expout 24041 mv at-expout expout 24042 # 5. Check 24043 $at_traceoff 24044 echo "calc.at:564: cat stderr" 24045 echo calc.at:564 >$at_check_line_file 24046 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 24047 at_status=$? 24048 grep '^ *+' $at_stder1 >&2 24049 grep -v '^ *+' $at_stder1 >$at_stderr 24050 at_failed=false 24051 $at_diff $at_devnull $at_stderr || at_failed=: 24052 $at_diff expout $at_stdout || at_failed=: 24053 case $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=:;; 24059 esac 24060 if $at_failed; then 24061 24062 echo 1 > $at_status_file 24063 exit 1 24064 fi 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. 24072 cat >input <<'_ATEOF' 24073 (!) + (0 0) = 1 24074 _ATEOF 24075 24076 $at_traceoff 24077 echo "calc.at:564: \$PREPARSER ./calc input" 24078 echo calc.at:564 >$at_check_line_file 24079 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 24080 at_status=$? 24081 grep '^ *+' $at_stder1 >&2 24082 grep -v '^ *+' $at_stder1 >$at_stderr 24083 at_failed=false 24084 echo stderr:; tee stderr <$at_stderr 24085 $at_diff $at_devnull $at_stdout || at_failed=: 24086 case $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=:;; 24092 esac 24093 if $at_failed; then 24094 24095 echo 1 > $at_status_file 24096 exit 1 24097 fi 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. 24105 sed '/^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 24118 mv at-stderr stderr 24119 # 2. Create the reference error message. 24120 cat >expout <<'_ATEOF' 24121 1.9: syntax error, unexpected number 24122 calc: error: 2222 != 1 24123 _ATEOF 24124 24125 # 3. If locations are not used, remove them. 24126 sed 's/^[-0-9.]*: //' expout >at-expout 24127 mv at-expout expout 24128 # 4. If error-verbose is not used, strip the`, unexpected....' part. 24129 sed 's/syntax error, .*$/syntax error/' expout >at-expout 24130 mv at-expout expout 24131 # 5. Check 24132 $at_traceoff 24133 echo "calc.at:564: cat stderr" 24134 echo calc.at:564 >$at_check_line_file 24135 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 24136 at_status=$? 24137 grep '^ *+' $at_stder1 >&2 24138 grep -v '^ *+' $at_stder1 >$at_stderr 24139 at_failed=false 24140 $at_diff $at_devnull $at_stderr || at_failed=: 24141 $at_diff expout $at_stdout || at_failed=: 24142 case $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=:;; 24148 esac 24149 if $at_failed; then 24150 24151 echo 1 > $at_status_file 24152 exit 1 24153 fi 24154 24155 $at_traceon 24156 24157 24158 cat >input <<'_ATEOF' 24159 (- *) + (0 0) = 1 24160 _ATEOF 24161 24162 $at_traceoff 24163 echo "calc.at:564: \$PREPARSER ./calc input" 24164 echo calc.at:564 >$at_check_line_file 24165 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 24166 at_status=$? 24167 grep '^ *+' $at_stder1 >&2 24168 grep -v '^ *+' $at_stder1 >$at_stderr 24169 at_failed=false 24170 echo stderr:; tee stderr <$at_stderr 24171 $at_diff $at_devnull $at_stdout || at_failed=: 24172 case $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=:;; 24178 esac 24179 if $at_failed; then 24180 24181 echo 1 > $at_status_file 24182 exit 1 24183 fi 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. 24191 sed '/^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 24204 mv at-stderr stderr 24205 # 2. Create the reference error message. 24206 cat >expout <<'_ATEOF' 24207 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 24208 1.11: syntax error, unexpected number 24209 calc: error: 2222 != 1 24210 _ATEOF 24211 24212 # 3. If locations are not used, remove them. 24213 sed 's/^[-0-9.]*: //' expout >at-expout 24214 mv at-expout expout 24215 # 4. If error-verbose is not used, strip the`, unexpected....' part. 24216 sed 's/syntax error, .*$/syntax error/' expout >at-expout 24217 mv at-expout expout 24218 # 5. Check 24219 $at_traceoff 24220 echo "calc.at:564: cat stderr" 24221 echo calc.at:564 >$at_check_line_file 24222 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 24223 at_status=$? 24224 grep '^ *+' $at_stder1 >&2 24225 grep -v '^ *+' $at_stder1 >$at_stderr 24226 at_failed=false 24227 $at_diff $at_devnull $at_stderr || at_failed=: 24228 $at_diff expout $at_stdout || at_failed=: 24229 case $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=:;; 24235 esac 24236 if $at_failed; then 24237 24238 echo 1 > $at_status_file 24239 exit 1 24240 fi 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 24317 cat >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. */ 24346 typedef int semantic_value; 24347 24348 static semantic_value global_result = 0; 24349 static int global_count = 0; 24350 %} 24351 24352 /* Exercise %union. */ 24353 %union 24354 { 24355 semantic_value ival; 24356 }; 24357 24358 %{ 24359 static int power (int base, int exponent); 24360 /* yyerror receives the location if: 24361 - %location & %pure & %glr 24362 - %location & %pure & %yacc & %parse-param. */ 24363 static void yyerror ( 24364 24365 const char *s 24366 ); 24367 static int yylex (void); 24368 static int get_char (void); 24369 static 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 %% 24387 input: 24388 line 24389 | input line { } 24390 ; 24391 24392 line: 24393 '\n' 24394 | exp '\n' { USE ($1); } 24395 ; 24396 24397 exp: 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. */ 24418 static FILE *input; 24419 24420 static void 24421 yyerror ( 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 24441 static YYLTYPE last_yylloc; 24442 24443 static int 24444 get_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 24462 static void 24463 unget_char ( int c) 24464 { 24465 ; 24466 24467 /* Wrong when C == `\n'. */ 24468 (yylloc) = last_yylloc; 24469 24470 ungetc (c, input); 24471 } 24472 24473 static int 24474 read_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 24506 static int 24507 yylex (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 24550 static int 24551 power (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 24562 int 24563 main (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 24600 echo "calc.at:565: bison -o calc.c calc.y" 24601 echo calc.at:565 >$at_check_line_file 24602 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 24603 at_status=$? 24604 grep '^ *+' $at_stder1 >&2 24605 grep -v '^ *+' $at_stder1 >$at_stderr 24606 at_failed=false 24607 $at_diff $at_devnull $at_stderr || at_failed=: 24608 $at_diff $at_devnull $at_stdout || at_failed=: 24609 case $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=:;; 24615 esac 24616 if $at_failed; then 24617 24618 echo 1 > $at_status_file 24619 exit 1 24620 fi 24621 24622 $at_traceon 24623 24624 $at_traceoff 24625 echo "calc.at:565: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 24626 echo calc.at:565 >$at_check_line_file 24627 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 24628 at_status=$? 24629 grep '^ *+' $at_stder1 >&2 24630 grep -v '^ *+' $at_stder1 >$at_stderr 24631 at_failed=false 24632 echo stderr:; cat $at_stderr 24633 echo stdout:; cat $at_stdout 24634 case $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=:;; 24640 esac 24641 if $at_failed; then 24642 24643 echo 1 > $at_status_file 24644 exit 1 24645 fi 24646 24647 $at_traceon 24648 24649 24650 # Test the priorities. 24651 cat >input <<'_ATEOF' 24652 1 + 2 * 3 = 7 24653 1 + 2 * -3 = -5 24654 24655 -1^2 = -1 24656 (-1)^2 = 1 24657 24658 ---1 = -1 24659 24660 1 - 2 - 3 = -4 24661 1 - (2 - 3) = 2 24662 24663 2^2^3 = 256 24664 (2^2)^3 = 64 24665 _ATEOF 24666 24667 $at_traceoff 24668 echo "calc.at:565: \$PREPARSER ./calc input" 24669 echo calc.at:565 >$at_check_line_file 24670 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 24671 at_status=$? 24672 grep '^ *+' $at_stder1 >&2 24673 grep -v '^ *+' $at_stder1 >$at_stderr 24674 at_failed=false 24675 echo stderr:; tee stderr <$at_stderr 24676 $at_diff $at_devnull $at_stdout || at_failed=: 24677 case $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=:;; 24683 esac 24684 if $at_failed; then 24685 24686 echo 1 > $at_status_file 24687 exit 1 24688 fi 24689 24690 $at_traceon 24691 24692 24693 24694 # Some syntax errors. 24695 cat >input <<'_ATEOF' 24696 0 0 24697 _ATEOF 24698 24699 $at_traceoff 24700 echo "calc.at:565: \$PREPARSER ./calc input" 24701 echo calc.at:565 >$at_check_line_file 24702 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 24703 at_status=$? 24704 grep '^ *+' $at_stder1 >&2 24705 grep -v '^ *+' $at_stder1 >$at_stderr 24706 at_failed=false 24707 echo stderr:; tee stderr <$at_stderr 24708 $at_diff $at_devnull $at_stdout || at_failed=: 24709 case $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=:;; 24715 esac 24716 if $at_failed; then 24717 24718 echo 1 > $at_status_file 24719 exit 1 24720 fi 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. 24728 sed '/^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 24741 mv at-stderr stderr 24742 # 2. Create the reference error message. 24743 cat >expout <<'_ATEOF' 24744 1.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 24753 echo "calc.at:565: cat stderr" 24754 echo calc.at:565 >$at_check_line_file 24755 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 24756 at_status=$? 24757 grep '^ *+' $at_stder1 >&2 24758 grep -v '^ *+' $at_stder1 >$at_stderr 24759 at_failed=false 24760 $at_diff $at_devnull $at_stderr || at_failed=: 24761 $at_diff expout $at_stdout || at_failed=: 24762 case $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=:;; 24768 esac 24769 if $at_failed; then 24770 24771 echo 1 > $at_status_file 24772 exit 1 24773 fi 24774 24775 $at_traceon 24776 24777 24778 cat >input <<'_ATEOF' 24779 1//2 24780 _ATEOF 24781 24782 $at_traceoff 24783 echo "calc.at:565: \$PREPARSER ./calc input" 24784 echo calc.at:565 >$at_check_line_file 24785 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 24786 at_status=$? 24787 grep '^ *+' $at_stder1 >&2 24788 grep -v '^ *+' $at_stder1 >$at_stderr 24789 at_failed=false 24790 echo stderr:; tee stderr <$at_stderr 24791 $at_diff $at_devnull $at_stdout || at_failed=: 24792 case $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=:;; 24798 esac 24799 if $at_failed; then 24800 24801 echo 1 > $at_status_file 24802 exit 1 24803 fi 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. 24811 sed '/^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 24824 mv at-stderr stderr 24825 # 2. Create the reference error message. 24826 cat >expout <<'_ATEOF' 24827 1.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 24836 echo "calc.at:565: cat stderr" 24837 echo calc.at:565 >$at_check_line_file 24838 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 24839 at_status=$? 24840 grep '^ *+' $at_stder1 >&2 24841 grep -v '^ *+' $at_stder1 >$at_stderr 24842 at_failed=false 24843 $at_diff $at_devnull $at_stderr || at_failed=: 24844 $at_diff expout $at_stdout || at_failed=: 24845 case $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=:;; 24851 esac 24852 if $at_failed; then 24853 24854 echo 1 > $at_status_file 24855 exit 1 24856 fi 24857 24858 $at_traceon 24859 24860 24861 cat >input <<'_ATEOF' 24862 error 24863 _ATEOF 24864 24865 $at_traceoff 24866 echo "calc.at:565: \$PREPARSER ./calc input" 24867 echo calc.at:565 >$at_check_line_file 24868 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 24869 at_status=$? 24870 grep '^ *+' $at_stder1 >&2 24871 grep -v '^ *+' $at_stder1 >$at_stderr 24872 at_failed=false 24873 echo stderr:; tee stderr <$at_stderr 24874 $at_diff $at_devnull $at_stdout || at_failed=: 24875 case $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=:;; 24881 esac 24882 if $at_failed; then 24883 24884 echo 1 > $at_status_file 24885 exit 1 24886 fi 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. 24894 sed '/^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 24907 mv at-stderr stderr 24908 # 2. Create the reference error message. 24909 cat >expout <<'_ATEOF' 24910 1.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 24919 echo "calc.at:565: cat stderr" 24920 echo calc.at:565 >$at_check_line_file 24921 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 24922 at_status=$? 24923 grep '^ *+' $at_stder1 >&2 24924 grep -v '^ *+' $at_stder1 >$at_stderr 24925 at_failed=false 24926 $at_diff $at_devnull $at_stderr || at_failed=: 24927 $at_diff expout $at_stdout || at_failed=: 24928 case $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=:;; 24934 esac 24935 if $at_failed; then 24936 24937 echo 1 > $at_status_file 24938 exit 1 24939 fi 24940 24941 $at_traceon 24942 24943 24944 cat >input <<'_ATEOF' 24945 1 = 2 = 3 24946 _ATEOF 24947 24948 $at_traceoff 24949 echo "calc.at:565: \$PREPARSER ./calc input" 24950 echo calc.at:565 >$at_check_line_file 24951 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 24952 at_status=$? 24953 grep '^ *+' $at_stder1 >&2 24954 grep -v '^ *+' $at_stder1 >$at_stderr 24955 at_failed=false 24956 echo stderr:; tee stderr <$at_stderr 24957 $at_diff $at_devnull $at_stdout || at_failed=: 24958 case $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=:;; 24964 esac 24965 if $at_failed; then 24966 24967 echo 1 > $at_status_file 24968 exit 1 24969 fi 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. 24977 sed '/^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 24990 mv at-stderr stderr 24991 # 2. Create the reference error message. 24992 cat >expout <<'_ATEOF' 24993 1.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 25002 echo "calc.at:565: cat stderr" 25003 echo calc.at:565 >$at_check_line_file 25004 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 25005 at_status=$? 25006 grep '^ *+' $at_stder1 >&2 25007 grep -v '^ *+' $at_stder1 >$at_stderr 25008 at_failed=false 25009 $at_diff $at_devnull $at_stderr || at_failed=: 25010 $at_diff expout $at_stdout || at_failed=: 25011 case $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=:;; 25017 esac 25018 if $at_failed; then 25019 25020 echo 1 > $at_status_file 25021 exit 1 25022 fi 25023 25024 $at_traceon 25025 25026 25027 cat >input <<'_ATEOF' 25028 25029 +1 25030 _ATEOF 25031 25032 $at_traceoff 25033 echo "calc.at:565: \$PREPARSER ./calc input" 25034 echo calc.at:565 >$at_check_line_file 25035 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 25036 at_status=$? 25037 grep '^ *+' $at_stder1 >&2 25038 grep -v '^ *+' $at_stder1 >$at_stderr 25039 at_failed=false 25040 echo stderr:; tee stderr <$at_stderr 25041 $at_diff $at_devnull $at_stdout || at_failed=: 25042 case $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=:;; 25048 esac 25049 if $at_failed; then 25050 25051 echo 1 > $at_status_file 25052 exit 1 25053 fi 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. 25061 sed '/^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 25074 mv at-stderr stderr 25075 # 2. Create the reference error message. 25076 cat >expout <<'_ATEOF' 25077 2.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 25086 echo "calc.at:565: cat stderr" 25087 echo calc.at:565 >$at_check_line_file 25088 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 25089 at_status=$? 25090 grep '^ *+' $at_stder1 >&2 25091 grep -v '^ *+' $at_stder1 >$at_stderr 25092 at_failed=false 25093 $at_diff $at_devnull $at_stderr || at_failed=: 25094 $at_diff expout $at_stdout || at_failed=: 25095 case $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=:;; 25101 esac 25102 if $at_failed; then 25103 25104 echo 1 > $at_status_file 25105 exit 1 25106 fi 25107 25108 $at_traceon 25109 25110 25111 # Exercise error messages with EOF: work on an empty file. 25112 $at_traceoff 25113 echo "calc.at:565: \$PREPARSER ./calc /dev/null" 25114 echo calc.at:565 >$at_check_line_file 25115 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 25116 at_status=$? 25117 grep '^ *+' $at_stder1 >&2 25118 grep -v '^ *+' $at_stder1 >$at_stderr 25119 at_failed=false 25120 echo stderr:; tee stderr <$at_stderr 25121 $at_diff $at_devnull $at_stdout || at_failed=: 25122 case $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=:;; 25128 esac 25129 if $at_failed; then 25130 25131 echo 1 > $at_status_file 25132 exit 1 25133 fi 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. 25141 sed '/^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 25154 mv at-stderr stderr 25155 # 2. Create the reference error message. 25156 cat >expout <<'_ATEOF' 25157 1.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 25166 echo "calc.at:565: cat stderr" 25167 echo calc.at:565 >$at_check_line_file 25168 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 25169 at_status=$? 25170 grep '^ *+' $at_stder1 >&2 25171 grep -v '^ *+' $at_stder1 >$at_stderr 25172 at_failed=false 25173 $at_diff $at_devnull $at_stderr || at_failed=: 25174 $at_diff expout $at_stdout || at_failed=: 25175 case $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=:;; 25181 esac 25182 if $at_failed; then 25183 25184 echo 1 > $at_status_file 25185 exit 1 25186 fi 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 # 25208 cat >input <<'_ATEOF' 25209 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 25210 _ATEOF 25211 25212 $at_traceoff 25213 echo "calc.at:565: \$PREPARSER ./calc input" 25214 echo calc.at:565 >$at_check_line_file 25215 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 25216 at_status=$? 25217 grep '^ *+' $at_stder1 >&2 25218 grep -v '^ *+' $at_stder1 >$at_stderr 25219 at_failed=false 25220 echo stderr:; tee stderr <$at_stderr 25221 $at_diff $at_devnull $at_stdout || at_failed=: 25222 case $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=:;; 25228 esac 25229 if $at_failed; then 25230 25231 echo 1 > $at_status_file 25232 exit 1 25233 fi 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. 25241 sed '/^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 25254 mv at-stderr stderr 25255 # 2. Create the reference error message. 25256 cat >expout <<'_ATEOF' 25257 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 25258 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 25259 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 25260 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 25261 calc: 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 25270 echo "calc.at:565: cat stderr" 25271 echo calc.at:565 >$at_check_line_file 25272 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 25273 at_status=$? 25274 grep '^ *+' $at_stder1 >&2 25275 grep -v '^ *+' $at_stder1 >$at_stderr 25276 at_failed=false 25277 $at_diff $at_devnull $at_stderr || at_failed=: 25278 $at_diff expout $at_stdout || at_failed=: 25279 case $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=:;; 25285 esac 25286 if $at_failed; then 25287 25288 echo 1 > $at_status_file 25289 exit 1 25290 fi 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. 25298 cat >input <<'_ATEOF' 25299 (!) + (0 0) = 1 25300 _ATEOF 25301 25302 $at_traceoff 25303 echo "calc.at:565: \$PREPARSER ./calc input" 25304 echo calc.at:565 >$at_check_line_file 25305 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 25306 at_status=$? 25307 grep '^ *+' $at_stder1 >&2 25308 grep -v '^ *+' $at_stder1 >$at_stderr 25309 at_failed=false 25310 echo stderr:; tee stderr <$at_stderr 25311 $at_diff $at_devnull $at_stdout || at_failed=: 25312 case $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=:;; 25318 esac 25319 if $at_failed; then 25320 25321 echo 1 > $at_status_file 25322 exit 1 25323 fi 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. 25331 sed '/^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 25344 mv at-stderr stderr 25345 # 2. Create the reference error message. 25346 cat >expout <<'_ATEOF' 25347 1.9: syntax error, unexpected number 25348 calc: 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 25357 echo "calc.at:565: cat stderr" 25358 echo calc.at:565 >$at_check_line_file 25359 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 25360 at_status=$? 25361 grep '^ *+' $at_stder1 >&2 25362 grep -v '^ *+' $at_stder1 >$at_stderr 25363 at_failed=false 25364 $at_diff $at_devnull $at_stderr || at_failed=: 25365 $at_diff expout $at_stdout || at_failed=: 25366 case $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=:;; 25372 esac 25373 if $at_failed; then 25374 25375 echo 1 > $at_status_file 25376 exit 1 25377 fi 25378 25379 $at_traceon 25380 25381 25382 cat >input <<'_ATEOF' 25383 (- *) + (0 0) = 1 25384 _ATEOF 25385 25386 $at_traceoff 25387 echo "calc.at:565: \$PREPARSER ./calc input" 25388 echo calc.at:565 >$at_check_line_file 25389 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 25390 at_status=$? 25391 grep '^ *+' $at_stder1 >&2 25392 grep -v '^ *+' $at_stder1 >$at_stderr 25393 at_failed=false 25394 echo stderr:; tee stderr <$at_stderr 25395 $at_diff $at_devnull $at_stdout || at_failed=: 25396 case $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=:;; 25402 esac 25403 if $at_failed; then 25404 25405 echo 1 > $at_status_file 25406 exit 1 25407 fi 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. 25415 sed '/^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 25428 mv at-stderr stderr 25429 # 2. Create the reference error message. 25430 cat >expout <<'_ATEOF' 25431 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 25432 1.11: syntax error, unexpected number 25433 calc: 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 25442 echo "calc.at:565: cat stderr" 25443 echo calc.at:565 >$at_check_line_file 25444 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 25445 at_status=$? 25446 grep '^ *+' $at_stder1 >&2 25447 grep -v '^ *+' $at_stder1 >$at_stderr 25448 at_failed=false 25449 $at_diff $at_devnull $at_stderr || at_failed=: 25450 $at_diff expout $at_stdout || at_failed=: 25451 case $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=:;; 25457 esac 25458 if $at_failed; then 25459 25460 echo 1 > $at_status_file 25461 exit 1 25462 fi 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 25539 cat >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. */ 25568 typedef int semantic_value; 25569 25570 static semantic_value global_result = 0; 25571 static int global_count = 0; 25572 %} 25573 25574 /* Exercise %union. */ 25575 %union 25576 { 25577 semantic_value ival; 25578 }; 25579 25580 %{ 25581 static int power (int base, int exponent); 25582 /* yyerror receives the location if: 25583 - %location & %pure & %glr 25584 - %location & %pure & %yacc & %parse-param. */ 25585 static void yyerror ( 25586 25587 const char *s 25588 ); 25589 static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp); 25590 static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp); 25591 static 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 %% 25609 input: 25610 line 25611 | input line { } 25612 ; 25613 25614 line: 25615 '\n' 25616 | exp '\n' { USE ($1); } 25617 ; 25618 25619 exp: 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. */ 25640 static FILE *input; 25641 25642 static void 25643 yyerror ( 25644 25645 const char *s) 25646 { 25647 25648 25649 fprintf (stderr, "%s\n", s); 25650 } 25651 25652 25653 25654 static YYLTYPE last_yylloc; 25655 25656 static int 25657 get_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 25675 static void 25676 unget_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 25686 static int 25687 read_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 25719 static int 25720 yylex (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 25763 static int 25764 power (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 25775 int 25776 main (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 25813 echo "calc.at:567: bison -o calc.c calc.y" 25814 echo calc.at:567 >$at_check_line_file 25815 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 25816 at_status=$? 25817 grep '^ *+' $at_stder1 >&2 25818 grep -v '^ *+' $at_stder1 >$at_stderr 25819 at_failed=false 25820 $at_diff $at_devnull $at_stderr || at_failed=: 25821 $at_diff $at_devnull $at_stdout || at_failed=: 25822 case $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=:;; 25828 esac 25829 if $at_failed; then 25830 25831 echo 1 > $at_status_file 25832 exit 1 25833 fi 25834 25835 $at_traceon 25836 25837 $at_traceoff 25838 echo "calc.at:567: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 25839 echo calc.at:567 >$at_check_line_file 25840 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 25841 at_status=$? 25842 grep '^ *+' $at_stder1 >&2 25843 grep -v '^ *+' $at_stder1 >$at_stderr 25844 at_failed=false 25845 echo stderr:; cat $at_stderr 25846 echo stdout:; cat $at_stdout 25847 case $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=:;; 25853 esac 25854 if $at_failed; then 25855 25856 echo 1 > $at_status_file 25857 exit 1 25858 fi 25859 25860 $at_traceon 25861 25862 25863 # Test the priorities. 25864 cat >input <<'_ATEOF' 25865 1 + 2 * 3 = 7 25866 1 + 2 * -3 = -5 25867 25868 -1^2 = -1 25869 (-1)^2 = 1 25870 25871 ---1 = -1 25872 25873 1 - 2 - 3 = -4 25874 1 - (2 - 3) = 2 25875 25876 2^2^3 = 256 25877 (2^2)^3 = 64 25878 _ATEOF 25879 25880 $at_traceoff 25881 echo "calc.at:567: \$PREPARSER ./calc input" 25882 echo calc.at:567 >$at_check_line_file 25883 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 25884 at_status=$? 25885 grep '^ *+' $at_stder1 >&2 25886 grep -v '^ *+' $at_stder1 >$at_stderr 25887 at_failed=false 25888 echo stderr:; tee stderr <$at_stderr 25889 $at_diff $at_devnull $at_stdout || at_failed=: 25890 case $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=:;; 25896 esac 25897 if $at_failed; then 25898 25899 echo 1 > $at_status_file 25900 exit 1 25901 fi 25902 25903 $at_traceon 25904 25905 25906 25907 # Some syntax errors. 25908 cat >input <<'_ATEOF' 25909 0 0 25910 _ATEOF 25911 25912 $at_traceoff 25913 echo "calc.at:567: \$PREPARSER ./calc input" 25914 echo calc.at:567 >$at_check_line_file 25915 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 25916 at_status=$? 25917 grep '^ *+' $at_stder1 >&2 25918 grep -v '^ *+' $at_stder1 >$at_stderr 25919 at_failed=false 25920 echo stderr:; tee stderr <$at_stderr 25921 $at_diff $at_devnull $at_stdout || at_failed=: 25922 case $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=:;; 25928 esac 25929 if $at_failed; then 25930 25931 echo 1 > $at_status_file 25932 exit 1 25933 fi 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. 25941 sed '/^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 25954 mv at-stderr stderr 25955 # 2. Create the reference error message. 25956 cat >expout <<'_ATEOF' 25957 1.2: syntax error, unexpected number 25958 _ATEOF 25959 25960 # 3. If locations are not used, remove them. 25961 sed 's/^[-0-9.]*: //' expout >at-expout 25962 mv at-expout expout 25963 # 4. If error-verbose is not used, strip the`, unexpected....' part. 25964 25965 # 5. Check 25966 $at_traceoff 25967 echo "calc.at:567: cat stderr" 25968 echo calc.at:567 >$at_check_line_file 25969 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 25970 at_status=$? 25971 grep '^ *+' $at_stder1 >&2 25972 grep -v '^ *+' $at_stder1 >$at_stderr 25973 at_failed=false 25974 $at_diff $at_devnull $at_stderr || at_failed=: 25975 $at_diff expout $at_stdout || at_failed=: 25976 case $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=:;; 25982 esac 25983 if $at_failed; then 25984 25985 echo 1 > $at_status_file 25986 exit 1 25987 fi 25988 25989 $at_traceon 25990 25991 25992 cat >input <<'_ATEOF' 25993 1//2 25994 _ATEOF 25995 25996 $at_traceoff 25997 echo "calc.at:567: \$PREPARSER ./calc input" 25998 echo calc.at:567 >$at_check_line_file 25999 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 26000 at_status=$? 26001 grep '^ *+' $at_stder1 >&2 26002 grep -v '^ *+' $at_stder1 >$at_stderr 26003 at_failed=false 26004 echo stderr:; tee stderr <$at_stderr 26005 $at_diff $at_devnull $at_stdout || at_failed=: 26006 case $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=:;; 26012 esac 26013 if $at_failed; then 26014 26015 echo 1 > $at_status_file 26016 exit 1 26017 fi 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. 26025 sed '/^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 26038 mv at-stderr stderr 26039 # 2. Create the reference error message. 26040 cat >expout <<'_ATEOF' 26041 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 26042 _ATEOF 26043 26044 # 3. If locations are not used, remove them. 26045 sed 's/^[-0-9.]*: //' expout >at-expout 26046 mv at-expout expout 26047 # 4. If error-verbose is not used, strip the`, unexpected....' part. 26048 26049 # 5. Check 26050 $at_traceoff 26051 echo "calc.at:567: cat stderr" 26052 echo calc.at:567 >$at_check_line_file 26053 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 26054 at_status=$? 26055 grep '^ *+' $at_stder1 >&2 26056 grep -v '^ *+' $at_stder1 >$at_stderr 26057 at_failed=false 26058 $at_diff $at_devnull $at_stderr || at_failed=: 26059 $at_diff expout $at_stdout || at_failed=: 26060 case $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=:;; 26066 esac 26067 if $at_failed; then 26068 26069 echo 1 > $at_status_file 26070 exit 1 26071 fi 26072 26073 $at_traceon 26074 26075 26076 cat >input <<'_ATEOF' 26077 error 26078 _ATEOF 26079 26080 $at_traceoff 26081 echo "calc.at:567: \$PREPARSER ./calc input" 26082 echo calc.at:567 >$at_check_line_file 26083 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 26084 at_status=$? 26085 grep '^ *+' $at_stder1 >&2 26086 grep -v '^ *+' $at_stder1 >$at_stderr 26087 at_failed=false 26088 echo stderr:; tee stderr <$at_stderr 26089 $at_diff $at_devnull $at_stdout || at_failed=: 26090 case $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=:;; 26096 esac 26097 if $at_failed; then 26098 26099 echo 1 > $at_status_file 26100 exit 1 26101 fi 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. 26109 sed '/^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 26122 mv at-stderr stderr 26123 # 2. Create the reference error message. 26124 cat >expout <<'_ATEOF' 26125 1.0: syntax error, unexpected $undefined 26126 _ATEOF 26127 26128 # 3. If locations are not used, remove them. 26129 sed 's/^[-0-9.]*: //' expout >at-expout 26130 mv at-expout expout 26131 # 4. If error-verbose is not used, strip the`, unexpected....' part. 26132 26133 # 5. Check 26134 $at_traceoff 26135 echo "calc.at:567: cat stderr" 26136 echo calc.at:567 >$at_check_line_file 26137 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 26138 at_status=$? 26139 grep '^ *+' $at_stder1 >&2 26140 grep -v '^ *+' $at_stder1 >$at_stderr 26141 at_failed=false 26142 $at_diff $at_devnull $at_stderr || at_failed=: 26143 $at_diff expout $at_stdout || at_failed=: 26144 case $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=:;; 26150 esac 26151 if $at_failed; then 26152 26153 echo 1 > $at_status_file 26154 exit 1 26155 fi 26156 26157 $at_traceon 26158 26159 26160 cat >input <<'_ATEOF' 26161 1 = 2 = 3 26162 _ATEOF 26163 26164 $at_traceoff 26165 echo "calc.at:567: \$PREPARSER ./calc input" 26166 echo calc.at:567 >$at_check_line_file 26167 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 26168 at_status=$? 26169 grep '^ *+' $at_stder1 >&2 26170 grep -v '^ *+' $at_stder1 >$at_stderr 26171 at_failed=false 26172 echo stderr:; tee stderr <$at_stderr 26173 $at_diff $at_devnull $at_stdout || at_failed=: 26174 case $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=:;; 26180 esac 26181 if $at_failed; then 26182 26183 echo 1 > $at_status_file 26184 exit 1 26185 fi 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. 26193 sed '/^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 26206 mv at-stderr stderr 26207 # 2. Create the reference error message. 26208 cat >expout <<'_ATEOF' 26209 1.6: syntax error, unexpected '=' 26210 _ATEOF 26211 26212 # 3. If locations are not used, remove them. 26213 sed 's/^[-0-9.]*: //' expout >at-expout 26214 mv at-expout expout 26215 # 4. If error-verbose is not used, strip the`, unexpected....' part. 26216 26217 # 5. Check 26218 $at_traceoff 26219 echo "calc.at:567: cat stderr" 26220 echo calc.at:567 >$at_check_line_file 26221 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 26222 at_status=$? 26223 grep '^ *+' $at_stder1 >&2 26224 grep -v '^ *+' $at_stder1 >$at_stderr 26225 at_failed=false 26226 $at_diff $at_devnull $at_stderr || at_failed=: 26227 $at_diff expout $at_stdout || at_failed=: 26228 case $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=:;; 26234 esac 26235 if $at_failed; then 26236 26237 echo 1 > $at_status_file 26238 exit 1 26239 fi 26240 26241 $at_traceon 26242 26243 26244 cat >input <<'_ATEOF' 26245 26246 +1 26247 _ATEOF 26248 26249 $at_traceoff 26250 echo "calc.at:567: \$PREPARSER ./calc input" 26251 echo calc.at:567 >$at_check_line_file 26252 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 26253 at_status=$? 26254 grep '^ *+' $at_stder1 >&2 26255 grep -v '^ *+' $at_stder1 >$at_stderr 26256 at_failed=false 26257 echo stderr:; tee stderr <$at_stderr 26258 $at_diff $at_devnull $at_stdout || at_failed=: 26259 case $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=:;; 26265 esac 26266 if $at_failed; then 26267 26268 echo 1 > $at_status_file 26269 exit 1 26270 fi 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. 26278 sed '/^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 26291 mv at-stderr stderr 26292 # 2. Create the reference error message. 26293 cat >expout <<'_ATEOF' 26294 2.0: syntax error, unexpected '+' 26295 _ATEOF 26296 26297 # 3. If locations are not used, remove them. 26298 sed 's/^[-0-9.]*: //' expout >at-expout 26299 mv at-expout expout 26300 # 4. If error-verbose is not used, strip the`, unexpected....' part. 26301 26302 # 5. Check 26303 $at_traceoff 26304 echo "calc.at:567: cat stderr" 26305 echo calc.at:567 >$at_check_line_file 26306 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 26307 at_status=$? 26308 grep '^ *+' $at_stder1 >&2 26309 grep -v '^ *+' $at_stder1 >$at_stderr 26310 at_failed=false 26311 $at_diff $at_devnull $at_stderr || at_failed=: 26312 $at_diff expout $at_stdout || at_failed=: 26313 case $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=:;; 26319 esac 26320 if $at_failed; then 26321 26322 echo 1 > $at_status_file 26323 exit 1 26324 fi 26325 26326 $at_traceon 26327 26328 26329 # Exercise error messages with EOF: work on an empty file. 26330 $at_traceoff 26331 echo "calc.at:567: \$PREPARSER ./calc /dev/null" 26332 echo calc.at:567 >$at_check_line_file 26333 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 26334 at_status=$? 26335 grep '^ *+' $at_stder1 >&2 26336 grep -v '^ *+' $at_stder1 >$at_stderr 26337 at_failed=false 26338 echo stderr:; tee stderr <$at_stderr 26339 $at_diff $at_devnull $at_stdout || at_failed=: 26340 case $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=:;; 26346 esac 26347 if $at_failed; then 26348 26349 echo 1 > $at_status_file 26350 exit 1 26351 fi 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. 26359 sed '/^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 26372 mv at-stderr stderr 26373 # 2. Create the reference error message. 26374 cat >expout <<'_ATEOF' 26375 1.0: syntax error, unexpected end of input 26376 _ATEOF 26377 26378 # 3. If locations are not used, remove them. 26379 sed 's/^[-0-9.]*: //' expout >at-expout 26380 mv at-expout expout 26381 # 4. If error-verbose is not used, strip the`, unexpected....' part. 26382 26383 # 5. Check 26384 $at_traceoff 26385 echo "calc.at:567: cat stderr" 26386 echo calc.at:567 >$at_check_line_file 26387 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 26388 at_status=$? 26389 grep '^ *+' $at_stder1 >&2 26390 grep -v '^ *+' $at_stder1 >$at_stderr 26391 at_failed=false 26392 $at_diff $at_devnull $at_stderr || at_failed=: 26393 $at_diff expout $at_stdout || at_failed=: 26394 case $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=:;; 26400 esac 26401 if $at_failed; then 26402 26403 echo 1 > $at_status_file 26404 exit 1 26405 fi 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 # 26427 cat >input <<'_ATEOF' 26428 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 26429 _ATEOF 26430 26431 $at_traceoff 26432 echo "calc.at:567: \$PREPARSER ./calc input" 26433 echo calc.at:567 >$at_check_line_file 26434 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 26435 at_status=$? 26436 grep '^ *+' $at_stder1 >&2 26437 grep -v '^ *+' $at_stder1 >$at_stderr 26438 at_failed=false 26439 echo stderr:; tee stderr <$at_stderr 26440 $at_diff $at_devnull $at_stdout || at_failed=: 26441 case $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=:;; 26447 esac 26448 if $at_failed; then 26449 26450 echo 1 > $at_status_file 26451 exit 1 26452 fi 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. 26460 sed '/^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 26473 mv at-stderr stderr 26474 # 2. Create the reference error message. 26475 cat >expout <<'_ATEOF' 26476 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 26477 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 26478 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 26479 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 26480 calc: error: 4444 != 1 26481 _ATEOF 26482 26483 # 3. If locations are not used, remove them. 26484 sed 's/^[-0-9.]*: //' expout >at-expout 26485 mv at-expout expout 26486 # 4. If error-verbose is not used, strip the`, unexpected....' part. 26487 26488 # 5. Check 26489 $at_traceoff 26490 echo "calc.at:567: cat stderr" 26491 echo calc.at:567 >$at_check_line_file 26492 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 26493 at_status=$? 26494 grep '^ *+' $at_stder1 >&2 26495 grep -v '^ *+' $at_stder1 >$at_stderr 26496 at_failed=false 26497 $at_diff $at_devnull $at_stderr || at_failed=: 26498 $at_diff expout $at_stdout || at_failed=: 26499 case $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=:;; 26505 esac 26506 if $at_failed; then 26507 26508 echo 1 > $at_status_file 26509 exit 1 26510 fi 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. 26518 cat >input <<'_ATEOF' 26519 (!) + (0 0) = 1 26520 _ATEOF 26521 26522 $at_traceoff 26523 echo "calc.at:567: \$PREPARSER ./calc input" 26524 echo calc.at:567 >$at_check_line_file 26525 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 26526 at_status=$? 26527 grep '^ *+' $at_stder1 >&2 26528 grep -v '^ *+' $at_stder1 >$at_stderr 26529 at_failed=false 26530 echo stderr:; tee stderr <$at_stderr 26531 $at_diff $at_devnull $at_stdout || at_failed=: 26532 case $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=:;; 26538 esac 26539 if $at_failed; then 26540 26541 echo 1 > $at_status_file 26542 exit 1 26543 fi 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. 26551 sed '/^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 26564 mv at-stderr stderr 26565 # 2. Create the reference error message. 26566 cat >expout <<'_ATEOF' 26567 1.9: syntax error, unexpected number 26568 calc: error: 2222 != 1 26569 _ATEOF 26570 26571 # 3. If locations are not used, remove them. 26572 sed 's/^[-0-9.]*: //' expout >at-expout 26573 mv at-expout expout 26574 # 4. If error-verbose is not used, strip the`, unexpected....' part. 26575 26576 # 5. Check 26577 $at_traceoff 26578 echo "calc.at:567: cat stderr" 26579 echo calc.at:567 >$at_check_line_file 26580 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 26581 at_status=$? 26582 grep '^ *+' $at_stder1 >&2 26583 grep -v '^ *+' $at_stder1 >$at_stderr 26584 at_failed=false 26585 $at_diff $at_devnull $at_stderr || at_failed=: 26586 $at_diff expout $at_stdout || at_failed=: 26587 case $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=:;; 26593 esac 26594 if $at_failed; then 26595 26596 echo 1 > $at_status_file 26597 exit 1 26598 fi 26599 26600 $at_traceon 26601 26602 26603 cat >input <<'_ATEOF' 26604 (- *) + (0 0) = 1 26605 _ATEOF 26606 26607 $at_traceoff 26608 echo "calc.at:567: \$PREPARSER ./calc input" 26609 echo calc.at:567 >$at_check_line_file 26610 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 26611 at_status=$? 26612 grep '^ *+' $at_stder1 >&2 26613 grep -v '^ *+' $at_stder1 >$at_stderr 26614 at_failed=false 26615 echo stderr:; tee stderr <$at_stderr 26616 $at_diff $at_devnull $at_stdout || at_failed=: 26617 case $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=:;; 26623 esac 26624 if $at_failed; then 26625 26626 echo 1 > $at_status_file 26627 exit 1 26628 fi 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. 26636 sed '/^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 26649 mv at-stderr stderr 26650 # 2. Create the reference error message. 26651 cat >expout <<'_ATEOF' 26652 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 26653 1.11: syntax error, unexpected number 26654 calc: error: 2222 != 1 26655 _ATEOF 26656 26657 # 3. If locations are not used, remove them. 26658 sed 's/^[-0-9.]*: //' expout >at-expout 26659 mv at-expout expout 26660 # 4. If error-verbose is not used, strip the`, unexpected....' part. 26661 26662 # 5. Check 26663 $at_traceoff 26664 echo "calc.at:567: cat stderr" 26665 echo calc.at:567 >$at_check_line_file 26666 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 26667 at_status=$? 26668 grep '^ *+' $at_stder1 >&2 26669 grep -v '^ *+' $at_stder1 >$at_stderr 26670 at_failed=false 26671 $at_diff $at_devnull $at_stderr || at_failed=: 26672 $at_diff expout $at_stdout || at_failed=: 26673 case $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=:;; 26679 esac 26680 if $at_failed; then 26681 26682 echo 1 > $at_status_file 26683 exit 1 26684 fi 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 26761 cat >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. */ 26790 typedef int semantic_value; 26791 26792 static semantic_value global_result = 0; 26793 static int global_count = 0; 26794 %} 26795 26796 /* Exercise %union. */ 26797 %union 26798 { 26799 semantic_value ival; 26800 }; 26801 26802 %{ 26803 static int power (int base, int exponent); 26804 /* yyerror receives the location if: 26805 - %location & %pure & %glr 26806 - %location & %pure & %yacc & %parse-param. */ 26807 static void yyerror (YYLTYPE *llocp, 26808 semantic_value *result, int *count, 26809 const char *s 26810 ); 26811 static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp); 26812 static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp); 26813 static 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 %% 26831 input: 26832 line 26833 | input line { ++*count; ++global_count; } 26834 ; 26835 26836 line: 26837 '\n' 26838 | exp '\n' { *result = global_result = $1; } 26839 ; 26840 26841 exp: 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. */ 26862 static FILE *input; 26863 26864 static void 26865 yyerror (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 26885 static YYLTYPE last_yylloc; 26886 26887 static int 26888 get_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 26906 static void 26907 unget_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 26917 static int 26918 read_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 26950 static int 26951 yylex (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 26994 static int 26995 power (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 27006 int 27007 main (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 27044 echo "calc.at:569: bison -o calc.c calc.y" 27045 echo calc.at:569 >$at_check_line_file 27046 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 27047 at_status=$? 27048 grep '^ *+' $at_stder1 >&2 27049 grep -v '^ *+' $at_stder1 >$at_stderr 27050 at_failed=false 27051 $at_diff $at_devnull $at_stderr || at_failed=: 27052 $at_diff $at_devnull $at_stdout || at_failed=: 27053 case $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=:;; 27059 esac 27060 if $at_failed; then 27061 27062 echo 1 > $at_status_file 27063 exit 1 27064 fi 27065 27066 $at_traceon 27067 27068 $at_traceoff 27069 echo "calc.at:569: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 27070 echo calc.at:569 >$at_check_line_file 27071 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 27072 at_status=$? 27073 grep '^ *+' $at_stder1 >&2 27074 grep -v '^ *+' $at_stder1 >$at_stderr 27075 at_failed=false 27076 echo stderr:; cat $at_stderr 27077 echo stdout:; cat $at_stdout 27078 case $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=:;; 27084 esac 27085 if $at_failed; then 27086 27087 echo 1 > $at_status_file 27088 exit 1 27089 fi 27090 27091 $at_traceon 27092 27093 27094 # Test the priorities. 27095 cat >input <<'_ATEOF' 27096 1 + 2 * 3 = 7 27097 1 + 2 * -3 = -5 27098 27099 -1^2 = -1 27100 (-1)^2 = 1 27101 27102 ---1 = -1 27103 27104 1 - 2 - 3 = -4 27105 1 - (2 - 3) = 2 27106 27107 2^2^3 = 256 27108 (2^2)^3 = 64 27109 _ATEOF 27110 27111 $at_traceoff 27112 echo "calc.at:569: \$PREPARSER ./calc input" 27113 echo calc.at:569 >$at_check_line_file 27114 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 27115 at_status=$? 27116 grep '^ *+' $at_stder1 >&2 27117 grep -v '^ *+' $at_stder1 >$at_stderr 27118 at_failed=false 27119 echo stderr:; tee stderr <$at_stderr 27120 $at_diff $at_devnull $at_stdout || at_failed=: 27121 case $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=:;; 27127 esac 27128 if $at_failed; then 27129 27130 echo 1 > $at_status_file 27131 exit 1 27132 fi 27133 27134 $at_traceon 27135 27136 27137 27138 # Some syntax errors. 27139 cat >input <<'_ATEOF' 27140 0 0 27141 _ATEOF 27142 27143 $at_traceoff 27144 echo "calc.at:569: \$PREPARSER ./calc input" 27145 echo calc.at:569 >$at_check_line_file 27146 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 27147 at_status=$? 27148 grep '^ *+' $at_stder1 >&2 27149 grep -v '^ *+' $at_stder1 >$at_stderr 27150 at_failed=false 27151 echo stderr:; tee stderr <$at_stderr 27152 $at_diff $at_devnull $at_stdout || at_failed=: 27153 case $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=:;; 27159 esac 27160 if $at_failed; then 27161 27162 echo 1 > $at_status_file 27163 exit 1 27164 fi 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. 27172 sed '/^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 27185 mv at-stderr stderr 27186 # 2. Create the reference error message. 27187 cat >expout <<'_ATEOF' 27188 1.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 27197 echo "calc.at:569: cat stderr" 27198 echo calc.at:569 >$at_check_line_file 27199 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 27200 at_status=$? 27201 grep '^ *+' $at_stder1 >&2 27202 grep -v '^ *+' $at_stder1 >$at_stderr 27203 at_failed=false 27204 $at_diff $at_devnull $at_stderr || at_failed=: 27205 $at_diff expout $at_stdout || at_failed=: 27206 case $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=:;; 27212 esac 27213 if $at_failed; then 27214 27215 echo 1 > $at_status_file 27216 exit 1 27217 fi 27218 27219 $at_traceon 27220 27221 27222 cat >input <<'_ATEOF' 27223 1//2 27224 _ATEOF 27225 27226 $at_traceoff 27227 echo "calc.at:569: \$PREPARSER ./calc input" 27228 echo calc.at:569 >$at_check_line_file 27229 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 27230 at_status=$? 27231 grep '^ *+' $at_stder1 >&2 27232 grep -v '^ *+' $at_stder1 >$at_stderr 27233 at_failed=false 27234 echo stderr:; tee stderr <$at_stderr 27235 $at_diff $at_devnull $at_stdout || at_failed=: 27236 case $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=:;; 27242 esac 27243 if $at_failed; then 27244 27245 echo 1 > $at_status_file 27246 exit 1 27247 fi 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. 27255 sed '/^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 27268 mv at-stderr stderr 27269 # 2. Create the reference error message. 27270 cat >expout <<'_ATEOF' 27271 1.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 27280 echo "calc.at:569: cat stderr" 27281 echo calc.at:569 >$at_check_line_file 27282 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 27283 at_status=$? 27284 grep '^ *+' $at_stder1 >&2 27285 grep -v '^ *+' $at_stder1 >$at_stderr 27286 at_failed=false 27287 $at_diff $at_devnull $at_stderr || at_failed=: 27288 $at_diff expout $at_stdout || at_failed=: 27289 case $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=:;; 27295 esac 27296 if $at_failed; then 27297 27298 echo 1 > $at_status_file 27299 exit 1 27300 fi 27301 27302 $at_traceon 27303 27304 27305 cat >input <<'_ATEOF' 27306 error 27307 _ATEOF 27308 27309 $at_traceoff 27310 echo "calc.at:569: \$PREPARSER ./calc input" 27311 echo calc.at:569 >$at_check_line_file 27312 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 27313 at_status=$? 27314 grep '^ *+' $at_stder1 >&2 27315 grep -v '^ *+' $at_stder1 >$at_stderr 27316 at_failed=false 27317 echo stderr:; tee stderr <$at_stderr 27318 $at_diff $at_devnull $at_stdout || at_failed=: 27319 case $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=:;; 27325 esac 27326 if $at_failed; then 27327 27328 echo 1 > $at_status_file 27329 exit 1 27330 fi 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. 27338 sed '/^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 27351 mv at-stderr stderr 27352 # 2. Create the reference error message. 27353 cat >expout <<'_ATEOF' 27354 1.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 27363 echo "calc.at:569: cat stderr" 27364 echo calc.at:569 >$at_check_line_file 27365 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 27366 at_status=$? 27367 grep '^ *+' $at_stder1 >&2 27368 grep -v '^ *+' $at_stder1 >$at_stderr 27369 at_failed=false 27370 $at_diff $at_devnull $at_stderr || at_failed=: 27371 $at_diff expout $at_stdout || at_failed=: 27372 case $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=:;; 27378 esac 27379 if $at_failed; then 27380 27381 echo 1 > $at_status_file 27382 exit 1 27383 fi 27384 27385 $at_traceon 27386 27387 27388 cat >input <<'_ATEOF' 27389 1 = 2 = 3 27390 _ATEOF 27391 27392 $at_traceoff 27393 echo "calc.at:569: \$PREPARSER ./calc input" 27394 echo calc.at:569 >$at_check_line_file 27395 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 27396 at_status=$? 27397 grep '^ *+' $at_stder1 >&2 27398 grep -v '^ *+' $at_stder1 >$at_stderr 27399 at_failed=false 27400 echo stderr:; tee stderr <$at_stderr 27401 $at_diff $at_devnull $at_stdout || at_failed=: 27402 case $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=:;; 27408 esac 27409 if $at_failed; then 27410 27411 echo 1 > $at_status_file 27412 exit 1 27413 fi 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. 27421 sed '/^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 27434 mv at-stderr stderr 27435 # 2. Create the reference error message. 27436 cat >expout <<'_ATEOF' 27437 1.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 27446 echo "calc.at:569: cat stderr" 27447 echo calc.at:569 >$at_check_line_file 27448 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 27449 at_status=$? 27450 grep '^ *+' $at_stder1 >&2 27451 grep -v '^ *+' $at_stder1 >$at_stderr 27452 at_failed=false 27453 $at_diff $at_devnull $at_stderr || at_failed=: 27454 $at_diff expout $at_stdout || at_failed=: 27455 case $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=:;; 27461 esac 27462 if $at_failed; then 27463 27464 echo 1 > $at_status_file 27465 exit 1 27466 fi 27467 27468 $at_traceon 27469 27470 27471 cat >input <<'_ATEOF' 27472 27473 +1 27474 _ATEOF 27475 27476 $at_traceoff 27477 echo "calc.at:569: \$PREPARSER ./calc input" 27478 echo calc.at:569 >$at_check_line_file 27479 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 27480 at_status=$? 27481 grep '^ *+' $at_stder1 >&2 27482 grep -v '^ *+' $at_stder1 >$at_stderr 27483 at_failed=false 27484 echo stderr:; tee stderr <$at_stderr 27485 $at_diff $at_devnull $at_stdout || at_failed=: 27486 case $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=:;; 27492 esac 27493 if $at_failed; then 27494 27495 echo 1 > $at_status_file 27496 exit 1 27497 fi 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. 27505 sed '/^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 27518 mv at-stderr stderr 27519 # 2. Create the reference error message. 27520 cat >expout <<'_ATEOF' 27521 2.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 27530 echo "calc.at:569: cat stderr" 27531 echo calc.at:569 >$at_check_line_file 27532 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 27533 at_status=$? 27534 grep '^ *+' $at_stder1 >&2 27535 grep -v '^ *+' $at_stder1 >$at_stderr 27536 at_failed=false 27537 $at_diff $at_devnull $at_stderr || at_failed=: 27538 $at_diff expout $at_stdout || at_failed=: 27539 case $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=:;; 27545 esac 27546 if $at_failed; then 27547 27548 echo 1 > $at_status_file 27549 exit 1 27550 fi 27551 27552 $at_traceon 27553 27554 27555 # Exercise error messages with EOF: work on an empty file. 27556 $at_traceoff 27557 echo "calc.at:569: \$PREPARSER ./calc /dev/null" 27558 echo calc.at:569 >$at_check_line_file 27559 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 27560 at_status=$? 27561 grep '^ *+' $at_stder1 >&2 27562 grep -v '^ *+' $at_stder1 >$at_stderr 27563 at_failed=false 27564 echo stderr:; tee stderr <$at_stderr 27565 $at_diff $at_devnull $at_stdout || at_failed=: 27566 case $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=:;; 27572 esac 27573 if $at_failed; then 27574 27575 echo 1 > $at_status_file 27576 exit 1 27577 fi 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. 27585 sed '/^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 27598 mv at-stderr stderr 27599 # 2. Create the reference error message. 27600 cat >expout <<'_ATEOF' 27601 1.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 27610 echo "calc.at:569: cat stderr" 27611 echo calc.at:569 >$at_check_line_file 27612 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 27613 at_status=$? 27614 grep '^ *+' $at_stder1 >&2 27615 grep -v '^ *+' $at_stder1 >$at_stderr 27616 at_failed=false 27617 $at_diff $at_devnull $at_stderr || at_failed=: 27618 $at_diff expout $at_stdout || at_failed=: 27619 case $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=:;; 27625 esac 27626 if $at_failed; then 27627 27628 echo 1 > $at_status_file 27629 exit 1 27630 fi 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 # 27652 cat >input <<'_ATEOF' 27653 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 27654 _ATEOF 27655 27656 $at_traceoff 27657 echo "calc.at:569: \$PREPARSER ./calc input" 27658 echo calc.at:569 >$at_check_line_file 27659 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 27660 at_status=$? 27661 grep '^ *+' $at_stder1 >&2 27662 grep -v '^ *+' $at_stder1 >$at_stderr 27663 at_failed=false 27664 echo stderr:; tee stderr <$at_stderr 27665 $at_diff $at_devnull $at_stdout || at_failed=: 27666 case $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=:;; 27672 esac 27673 if $at_failed; then 27674 27675 echo 1 > $at_status_file 27676 exit 1 27677 fi 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. 27685 sed '/^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 27698 mv at-stderr stderr 27699 # 2. Create the reference error message. 27700 cat >expout <<'_ATEOF' 27701 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 27702 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 27703 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 27704 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 27705 calc: 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 27714 echo "calc.at:569: cat stderr" 27715 echo calc.at:569 >$at_check_line_file 27716 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 27717 at_status=$? 27718 grep '^ *+' $at_stder1 >&2 27719 grep -v '^ *+' $at_stder1 >$at_stderr 27720 at_failed=false 27721 $at_diff $at_devnull $at_stderr || at_failed=: 27722 $at_diff expout $at_stdout || at_failed=: 27723 case $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=:;; 27729 esac 27730 if $at_failed; then 27731 27732 echo 1 > $at_status_file 27733 exit 1 27734 fi 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. 27742 cat >input <<'_ATEOF' 27743 (!) + (0 0) = 1 27744 _ATEOF 27745 27746 $at_traceoff 27747 echo "calc.at:569: \$PREPARSER ./calc input" 27748 echo calc.at:569 >$at_check_line_file 27749 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 27750 at_status=$? 27751 grep '^ *+' $at_stder1 >&2 27752 grep -v '^ *+' $at_stder1 >$at_stderr 27753 at_failed=false 27754 echo stderr:; tee stderr <$at_stderr 27755 $at_diff $at_devnull $at_stdout || at_failed=: 27756 case $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=:;; 27762 esac 27763 if $at_failed; then 27764 27765 echo 1 > $at_status_file 27766 exit 1 27767 fi 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. 27775 sed '/^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 27788 mv at-stderr stderr 27789 # 2. Create the reference error message. 27790 cat >expout <<'_ATEOF' 27791 1.9: syntax error, unexpected number 27792 calc: 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 27801 echo "calc.at:569: cat stderr" 27802 echo calc.at:569 >$at_check_line_file 27803 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 27804 at_status=$? 27805 grep '^ *+' $at_stder1 >&2 27806 grep -v '^ *+' $at_stder1 >$at_stderr 27807 at_failed=false 27808 $at_diff $at_devnull $at_stderr || at_failed=: 27809 $at_diff expout $at_stdout || at_failed=: 27810 case $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=:;; 27816 esac 27817 if $at_failed; then 27818 27819 echo 1 > $at_status_file 27820 exit 1 27821 fi 27822 27823 $at_traceon 27824 27825 27826 cat >input <<'_ATEOF' 27827 (- *) + (0 0) = 1 27828 _ATEOF 27829 27830 $at_traceoff 27831 echo "calc.at:569: \$PREPARSER ./calc input" 27832 echo calc.at:569 >$at_check_line_file 27833 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 27834 at_status=$? 27835 grep '^ *+' $at_stder1 >&2 27836 grep -v '^ *+' $at_stder1 >$at_stderr 27837 at_failed=false 27838 echo stderr:; tee stderr <$at_stderr 27839 $at_diff $at_devnull $at_stdout || at_failed=: 27840 case $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=:;; 27846 esac 27847 if $at_failed; then 27848 27849 echo 1 > $at_status_file 27850 exit 1 27851 fi 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. 27859 sed '/^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 27872 mv at-stderr stderr 27873 # 2. Create the reference error message. 27874 cat >expout <<'_ATEOF' 27875 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 27876 1.11: syntax error, unexpected number 27877 calc: 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 27886 echo "calc.at:569: cat stderr" 27887 echo calc.at:569 >$at_check_line_file 27888 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 27889 at_status=$? 27890 grep '^ *+' $at_stder1 >&2 27891 grep -v '^ *+' $at_stder1 >$at_stderr 27892 at_failed=false 27893 $at_diff $at_devnull $at_stderr || at_failed=: 27894 $at_diff expout $at_stdout || at_failed=: 27895 case $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=:;; 27901 esac 27902 if $at_failed; then 27903 27904 echo 1 > $at_status_file 27905 exit 1 27906 fi 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 27943 Simple 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 27992 cat >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. */ 28021 typedef int semantic_value; 28022 28023 static semantic_value global_result = 0; 28024 static int global_count = 0; 28025 %} 28026 28027 /* Exercise %union. */ 28028 %union 28029 { 28030 semantic_value ival; 28031 }; 28032 28033 %{ 28034 static int power (int base, int exponent); 28035 /* yyerror receives the location if: 28036 - %location & %pure & %glr 28037 - %location & %pure & %yacc & %parse-param. */ 28038 static void yyerror ( 28039 28040 const char *s 28041 ); 28042 static int yylex (void); 28043 static int get_char (void); 28044 static 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 %% 28062 input: 28063 line 28064 | input line { } 28065 ; 28066 28067 line: 28068 '\n' 28069 | exp '\n' { USE ($1); } 28070 ; 28071 28072 exp: 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. */ 28093 static FILE *input; 28094 28095 static void 28096 yyerror ( 28097 28098 const char *s) 28099 { 28100 28101 28102 fprintf (stderr, "%s\n", s); 28103 } 28104 28105 28106 28107 static int 28108 get_char (void) 28109 { 28110 int res = getc (input); 28111 ; 28112 28113 return res; 28114 } 28115 28116 28117 static void 28118 unget_char ( int c) 28119 { 28120 ; 28121 28122 ungetc (c, input); 28123 } 28124 28125 static int 28126 read_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 28158 static int 28159 yylex (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 28194 static int 28195 power (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 28206 int 28207 main (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 28244 echo "calc.at:586: bison -o calc.c calc.y" 28245 echo calc.at:586 >$at_check_line_file 28246 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 28247 at_status=$? 28248 grep '^ *+' $at_stder1 >&2 28249 grep -v '^ *+' $at_stder1 >$at_stderr 28250 at_failed=false 28251 $at_diff $at_devnull $at_stderr || at_failed=: 28252 $at_diff $at_devnull $at_stdout || at_failed=: 28253 case $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=:;; 28259 esac 28260 if $at_failed; then 28261 28262 echo 1 > $at_status_file 28263 exit 1 28264 fi 28265 28266 $at_traceon 28267 28268 $at_traceoff 28269 echo "calc.at:586: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 28270 echo calc.at:586 >$at_check_line_file 28271 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 28272 at_status=$? 28273 grep '^ *+' $at_stder1 >&2 28274 grep -v '^ *+' $at_stder1 >$at_stderr 28275 at_failed=false 28276 echo stderr:; cat $at_stderr 28277 echo stdout:; cat $at_stdout 28278 case $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=:;; 28284 esac 28285 if $at_failed; then 28286 28287 echo 1 > $at_status_file 28288 exit 1 28289 fi 28290 28291 $at_traceon 28292 28293 28294 # Test the priorities. 28295 cat >input <<'_ATEOF' 28296 1 + 2 * 3 = 7 28297 1 + 2 * -3 = -5 28298 28299 -1^2 = -1 28300 (-1)^2 = 1 28301 28302 ---1 = -1 28303 28304 1 - 2 - 3 = -4 28305 1 - (2 - 3) = 2 28306 28307 2^2^3 = 256 28308 (2^2)^3 = 64 28309 _ATEOF 28310 28311 $at_traceoff 28312 echo "calc.at:586: \$PREPARSER ./calc input" 28313 echo calc.at:586 >$at_check_line_file 28314 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 28315 at_status=$? 28316 grep '^ *+' $at_stder1 >&2 28317 grep -v '^ *+' $at_stder1 >$at_stderr 28318 at_failed=false 28319 echo stderr:; tee stderr <$at_stderr 28320 $at_diff $at_devnull $at_stdout || at_failed=: 28321 case $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=:;; 28327 esac 28328 if $at_failed; then 28329 28330 echo 1 > $at_status_file 28331 exit 1 28332 fi 28333 28334 $at_traceon 28335 28336 28337 28338 # Some syntax errors. 28339 cat >input <<'_ATEOF' 28340 0 0 28341 _ATEOF 28342 28343 $at_traceoff 28344 echo "calc.at:586: \$PREPARSER ./calc input" 28345 echo calc.at:586 >$at_check_line_file 28346 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 28347 at_status=$? 28348 grep '^ *+' $at_stder1 >&2 28349 grep -v '^ *+' $at_stder1 >$at_stderr 28350 at_failed=false 28351 echo stderr:; tee stderr <$at_stderr 28352 $at_diff $at_devnull $at_stdout || at_failed=: 28353 case $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=:;; 28359 esac 28360 if $at_failed; then 28361 28362 echo 1 > $at_status_file 28363 exit 1 28364 fi 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. 28372 sed '/^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 28385 mv at-stderr stderr 28386 # 2. Create the reference error message. 28387 cat >expout <<'_ATEOF' 28388 1.2: syntax error, unexpected number 28389 _ATEOF 28390 28391 # 3. If locations are not used, remove them. 28392 sed 's/^[-0-9.]*: //' expout >at-expout 28393 mv at-expout expout 28394 # 4. If error-verbose is not used, strip the`, unexpected....' part. 28395 sed 's/syntax error, .*$/syntax error/' expout >at-expout 28396 mv at-expout expout 28397 # 5. Check 28398 $at_traceoff 28399 echo "calc.at:586: cat stderr" 28400 echo calc.at:586 >$at_check_line_file 28401 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 28402 at_status=$? 28403 grep '^ *+' $at_stder1 >&2 28404 grep -v '^ *+' $at_stder1 >$at_stderr 28405 at_failed=false 28406 $at_diff $at_devnull $at_stderr || at_failed=: 28407 $at_diff expout $at_stdout || at_failed=: 28408 case $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=:;; 28414 esac 28415 if $at_failed; then 28416 28417 echo 1 > $at_status_file 28418 exit 1 28419 fi 28420 28421 $at_traceon 28422 28423 28424 cat >input <<'_ATEOF' 28425 1//2 28426 _ATEOF 28427 28428 $at_traceoff 28429 echo "calc.at:586: \$PREPARSER ./calc input" 28430 echo calc.at:586 >$at_check_line_file 28431 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 28432 at_status=$? 28433 grep '^ *+' $at_stder1 >&2 28434 grep -v '^ *+' $at_stder1 >$at_stderr 28435 at_failed=false 28436 echo stderr:; tee stderr <$at_stderr 28437 $at_diff $at_devnull $at_stdout || at_failed=: 28438 case $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=:;; 28444 esac 28445 if $at_failed; then 28446 28447 echo 1 > $at_status_file 28448 exit 1 28449 fi 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. 28457 sed '/^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 28470 mv at-stderr stderr 28471 # 2. Create the reference error message. 28472 cat >expout <<'_ATEOF' 28473 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 28474 _ATEOF 28475 28476 # 3. If locations are not used, remove them. 28477 sed 's/^[-0-9.]*: //' expout >at-expout 28478 mv at-expout expout 28479 # 4. If error-verbose is not used, strip the`, unexpected....' part. 28480 sed 's/syntax error, .*$/syntax error/' expout >at-expout 28481 mv at-expout expout 28482 # 5. Check 28483 $at_traceoff 28484 echo "calc.at:586: cat stderr" 28485 echo calc.at:586 >$at_check_line_file 28486 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 28487 at_status=$? 28488 grep '^ *+' $at_stder1 >&2 28489 grep -v '^ *+' $at_stder1 >$at_stderr 28490 at_failed=false 28491 $at_diff $at_devnull $at_stderr || at_failed=: 28492 $at_diff expout $at_stdout || at_failed=: 28493 case $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=:;; 28499 esac 28500 if $at_failed; then 28501 28502 echo 1 > $at_status_file 28503 exit 1 28504 fi 28505 28506 $at_traceon 28507 28508 28509 cat >input <<'_ATEOF' 28510 error 28511 _ATEOF 28512 28513 $at_traceoff 28514 echo "calc.at:586: \$PREPARSER ./calc input" 28515 echo calc.at:586 >$at_check_line_file 28516 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 28517 at_status=$? 28518 grep '^ *+' $at_stder1 >&2 28519 grep -v '^ *+' $at_stder1 >$at_stderr 28520 at_failed=false 28521 echo stderr:; tee stderr <$at_stderr 28522 $at_diff $at_devnull $at_stdout || at_failed=: 28523 case $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=:;; 28529 esac 28530 if $at_failed; then 28531 28532 echo 1 > $at_status_file 28533 exit 1 28534 fi 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. 28542 sed '/^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 28555 mv at-stderr stderr 28556 # 2. Create the reference error message. 28557 cat >expout <<'_ATEOF' 28558 1.0: syntax error, unexpected $undefined 28559 _ATEOF 28560 28561 # 3. If locations are not used, remove them. 28562 sed 's/^[-0-9.]*: //' expout >at-expout 28563 mv at-expout expout 28564 # 4. If error-verbose is not used, strip the`, unexpected....' part. 28565 sed 's/syntax error, .*$/syntax error/' expout >at-expout 28566 mv at-expout expout 28567 # 5. Check 28568 $at_traceoff 28569 echo "calc.at:586: cat stderr" 28570 echo calc.at:586 >$at_check_line_file 28571 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 28572 at_status=$? 28573 grep '^ *+' $at_stder1 >&2 28574 grep -v '^ *+' $at_stder1 >$at_stderr 28575 at_failed=false 28576 $at_diff $at_devnull $at_stderr || at_failed=: 28577 $at_diff expout $at_stdout || at_failed=: 28578 case $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=:;; 28584 esac 28585 if $at_failed; then 28586 28587 echo 1 > $at_status_file 28588 exit 1 28589 fi 28590 28591 $at_traceon 28592 28593 28594 cat >input <<'_ATEOF' 28595 1 = 2 = 3 28596 _ATEOF 28597 28598 $at_traceoff 28599 echo "calc.at:586: \$PREPARSER ./calc input" 28600 echo calc.at:586 >$at_check_line_file 28601 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 28602 at_status=$? 28603 grep '^ *+' $at_stder1 >&2 28604 grep -v '^ *+' $at_stder1 >$at_stderr 28605 at_failed=false 28606 echo stderr:; tee stderr <$at_stderr 28607 $at_diff $at_devnull $at_stdout || at_failed=: 28608 case $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=:;; 28614 esac 28615 if $at_failed; then 28616 28617 echo 1 > $at_status_file 28618 exit 1 28619 fi 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. 28627 sed '/^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 28640 mv at-stderr stderr 28641 # 2. Create the reference error message. 28642 cat >expout <<'_ATEOF' 28643 1.6: syntax error, unexpected '=' 28644 _ATEOF 28645 28646 # 3. If locations are not used, remove them. 28647 sed 's/^[-0-9.]*: //' expout >at-expout 28648 mv at-expout expout 28649 # 4. If error-verbose is not used, strip the`, unexpected....' part. 28650 sed 's/syntax error, .*$/syntax error/' expout >at-expout 28651 mv at-expout expout 28652 # 5. Check 28653 $at_traceoff 28654 echo "calc.at:586: cat stderr" 28655 echo calc.at:586 >$at_check_line_file 28656 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 28657 at_status=$? 28658 grep '^ *+' $at_stder1 >&2 28659 grep -v '^ *+' $at_stder1 >$at_stderr 28660 at_failed=false 28661 $at_diff $at_devnull $at_stderr || at_failed=: 28662 $at_diff expout $at_stdout || at_failed=: 28663 case $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=:;; 28669 esac 28670 if $at_failed; then 28671 28672 echo 1 > $at_status_file 28673 exit 1 28674 fi 28675 28676 $at_traceon 28677 28678 28679 cat >input <<'_ATEOF' 28680 28681 +1 28682 _ATEOF 28683 28684 $at_traceoff 28685 echo "calc.at:586: \$PREPARSER ./calc input" 28686 echo calc.at:586 >$at_check_line_file 28687 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 28688 at_status=$? 28689 grep '^ *+' $at_stder1 >&2 28690 grep -v '^ *+' $at_stder1 >$at_stderr 28691 at_failed=false 28692 echo stderr:; tee stderr <$at_stderr 28693 $at_diff $at_devnull $at_stdout || at_failed=: 28694 case $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=:;; 28700 esac 28701 if $at_failed; then 28702 28703 echo 1 > $at_status_file 28704 exit 1 28705 fi 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. 28713 sed '/^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 28726 mv at-stderr stderr 28727 # 2. Create the reference error message. 28728 cat >expout <<'_ATEOF' 28729 2.0: syntax error, unexpected '+' 28730 _ATEOF 28731 28732 # 3. If locations are not used, remove them. 28733 sed 's/^[-0-9.]*: //' expout >at-expout 28734 mv at-expout expout 28735 # 4. If error-verbose is not used, strip the`, unexpected....' part. 28736 sed 's/syntax error, .*$/syntax error/' expout >at-expout 28737 mv at-expout expout 28738 # 5. Check 28739 $at_traceoff 28740 echo "calc.at:586: cat stderr" 28741 echo calc.at:586 >$at_check_line_file 28742 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 28743 at_status=$? 28744 grep '^ *+' $at_stder1 >&2 28745 grep -v '^ *+' $at_stder1 >$at_stderr 28746 at_failed=false 28747 $at_diff $at_devnull $at_stderr || at_failed=: 28748 $at_diff expout $at_stdout || at_failed=: 28749 case $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=:;; 28755 esac 28756 if $at_failed; then 28757 28758 echo 1 > $at_status_file 28759 exit 1 28760 fi 28761 28762 $at_traceon 28763 28764 28765 # Exercise error messages with EOF: work on an empty file. 28766 $at_traceoff 28767 echo "calc.at:586: \$PREPARSER ./calc /dev/null" 28768 echo calc.at:586 >$at_check_line_file 28769 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 28770 at_status=$? 28771 grep '^ *+' $at_stder1 >&2 28772 grep -v '^ *+' $at_stder1 >$at_stderr 28773 at_failed=false 28774 echo stderr:; tee stderr <$at_stderr 28775 $at_diff $at_devnull $at_stdout || at_failed=: 28776 case $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=:;; 28782 esac 28783 if $at_failed; then 28784 28785 echo 1 > $at_status_file 28786 exit 1 28787 fi 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. 28795 sed '/^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 28808 mv at-stderr stderr 28809 # 2. Create the reference error message. 28810 cat >expout <<'_ATEOF' 28811 1.0: syntax error, unexpected end of input 28812 _ATEOF 28813 28814 # 3. If locations are not used, remove them. 28815 sed 's/^[-0-9.]*: //' expout >at-expout 28816 mv at-expout expout 28817 # 4. If error-verbose is not used, strip the`, unexpected....' part. 28818 sed 's/syntax error, .*$/syntax error/' expout >at-expout 28819 mv at-expout expout 28820 # 5. Check 28821 $at_traceoff 28822 echo "calc.at:586: cat stderr" 28823 echo calc.at:586 >$at_check_line_file 28824 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 28825 at_status=$? 28826 grep '^ *+' $at_stder1 >&2 28827 grep -v '^ *+' $at_stder1 >$at_stderr 28828 at_failed=false 28829 $at_diff $at_devnull $at_stderr || at_failed=: 28830 $at_diff expout $at_stdout || at_failed=: 28831 case $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=:;; 28837 esac 28838 if $at_failed; then 28839 28840 echo 1 > $at_status_file 28841 exit 1 28842 fi 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 # 28864 cat >input <<'_ATEOF' 28865 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 28866 _ATEOF 28867 28868 $at_traceoff 28869 echo "calc.at:586: \$PREPARSER ./calc input" 28870 echo calc.at:586 >$at_check_line_file 28871 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 28872 at_status=$? 28873 grep '^ *+' $at_stder1 >&2 28874 grep -v '^ *+' $at_stder1 >$at_stderr 28875 at_failed=false 28876 echo stderr:; tee stderr <$at_stderr 28877 $at_diff $at_devnull $at_stdout || at_failed=: 28878 case $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=:;; 28884 esac 28885 if $at_failed; then 28886 28887 echo 1 > $at_status_file 28888 exit 1 28889 fi 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. 28897 sed '/^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 28910 mv at-stderr stderr 28911 # 2. Create the reference error message. 28912 cat >expout <<'_ATEOF' 28913 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 28914 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 28915 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 28916 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 28917 calc: error: 4444 != 1 28918 _ATEOF 28919 28920 # 3. If locations are not used, remove them. 28921 sed 's/^[-0-9.]*: //' expout >at-expout 28922 mv at-expout expout 28923 # 4. If error-verbose is not used, strip the`, unexpected....' part. 28924 sed 's/syntax error, .*$/syntax error/' expout >at-expout 28925 mv at-expout expout 28926 # 5. Check 28927 $at_traceoff 28928 echo "calc.at:586: cat stderr" 28929 echo calc.at:586 >$at_check_line_file 28930 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 28931 at_status=$? 28932 grep '^ *+' $at_stder1 >&2 28933 grep -v '^ *+' $at_stder1 >$at_stderr 28934 at_failed=false 28935 $at_diff $at_devnull $at_stderr || at_failed=: 28936 $at_diff expout $at_stdout || at_failed=: 28937 case $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=:;; 28943 esac 28944 if $at_failed; then 28945 28946 echo 1 > $at_status_file 28947 exit 1 28948 fi 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. 28956 cat >input <<'_ATEOF' 28957 (!) + (0 0) = 1 28958 _ATEOF 28959 28960 $at_traceoff 28961 echo "calc.at:586: \$PREPARSER ./calc input" 28962 echo calc.at:586 >$at_check_line_file 28963 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 28964 at_status=$? 28965 grep '^ *+' $at_stder1 >&2 28966 grep -v '^ *+' $at_stder1 >$at_stderr 28967 at_failed=false 28968 echo stderr:; tee stderr <$at_stderr 28969 $at_diff $at_devnull $at_stdout || at_failed=: 28970 case $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=:;; 28976 esac 28977 if $at_failed; then 28978 28979 echo 1 > $at_status_file 28980 exit 1 28981 fi 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. 28989 sed '/^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 29002 mv at-stderr stderr 29003 # 2. Create the reference error message. 29004 cat >expout <<'_ATEOF' 29005 1.9: syntax error, unexpected number 29006 calc: error: 2222 != 1 29007 _ATEOF 29008 29009 # 3. If locations are not used, remove them. 29010 sed 's/^[-0-9.]*: //' expout >at-expout 29011 mv at-expout expout 29012 # 4. If error-verbose is not used, strip the`, unexpected....' part. 29013 sed 's/syntax error, .*$/syntax error/' expout >at-expout 29014 mv at-expout expout 29015 # 5. Check 29016 $at_traceoff 29017 echo "calc.at:586: cat stderr" 29018 echo calc.at:586 >$at_check_line_file 29019 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 29020 at_status=$? 29021 grep '^ *+' $at_stder1 >&2 29022 grep -v '^ *+' $at_stder1 >$at_stderr 29023 at_failed=false 29024 $at_diff $at_devnull $at_stderr || at_failed=: 29025 $at_diff expout $at_stdout || at_failed=: 29026 case $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=:;; 29032 esac 29033 if $at_failed; then 29034 29035 echo 1 > $at_status_file 29036 exit 1 29037 fi 29038 29039 $at_traceon 29040 29041 29042 cat >input <<'_ATEOF' 29043 (- *) + (0 0) = 1 29044 _ATEOF 29045 29046 $at_traceoff 29047 echo "calc.at:586: \$PREPARSER ./calc input" 29048 echo calc.at:586 >$at_check_line_file 29049 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 29050 at_status=$? 29051 grep '^ *+' $at_stder1 >&2 29052 grep -v '^ *+' $at_stder1 >$at_stderr 29053 at_failed=false 29054 echo stderr:; tee stderr <$at_stderr 29055 $at_diff $at_devnull $at_stdout || at_failed=: 29056 case $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=:;; 29062 esac 29063 if $at_failed; then 29064 29065 echo 1 > $at_status_file 29066 exit 1 29067 fi 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. 29075 sed '/^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 29088 mv at-stderr stderr 29089 # 2. Create the reference error message. 29090 cat >expout <<'_ATEOF' 29091 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 29092 1.11: syntax error, unexpected number 29093 calc: error: 2222 != 1 29094 _ATEOF 29095 29096 # 3. If locations are not used, remove them. 29097 sed 's/^[-0-9.]*: //' expout >at-expout 29098 mv at-expout expout 29099 # 4. If error-verbose is not used, strip the`, unexpected....' part. 29100 sed 's/syntax error, .*$/syntax error/' expout >at-expout 29101 mv at-expout expout 29102 # 5. Check 29103 $at_traceoff 29104 echo "calc.at:586: cat stderr" 29105 echo calc.at:586 >$at_check_line_file 29106 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 29107 at_status=$? 29108 grep '^ *+' $at_stder1 >&2 29109 grep -v '^ *+' $at_stder1 >$at_stderr 29110 at_failed=false 29111 $at_diff $at_devnull $at_stderr || at_failed=: 29112 $at_diff expout $at_stdout || at_failed=: 29113 case $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=:;; 29119 esac 29120 if $at_failed; then 29121 29122 echo 1 > $at_status_file 29123 exit 1 29124 fi 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 29201 cat >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. */ 29230 typedef int semantic_value; 29231 29232 static semantic_value global_result = 0; 29233 static int global_count = 0; 29234 %} 29235 29236 /* Exercise %union. */ 29237 %union 29238 { 29239 semantic_value ival; 29240 }; 29241 29242 %{ 29243 static int power (int base, int exponent); 29244 /* yyerror receives the location if: 29245 - %location & %pure & %glr 29246 - %location & %pure & %yacc & %parse-param. */ 29247 static void yyerror ( 29248 29249 const char *s 29250 ); 29251 static int yylex (void); 29252 static int get_char (void); 29253 static 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 %% 29271 input: 29272 line 29273 | input line { } 29274 ; 29275 29276 line: 29277 '\n' 29278 | exp '\n' { USE ($1); } 29279 ; 29280 29281 exp: 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. */ 29302 static FILE *input; 29303 29304 static void 29305 yyerror ( 29306 29307 const char *s) 29308 { 29309 29310 29311 fprintf (stderr, "%s\n", s); 29312 } 29313 29314 29315 29316 static int 29317 get_char (void) 29318 { 29319 int res = getc (input); 29320 ; 29321 29322 return res; 29323 } 29324 29325 29326 static void 29327 unget_char ( int c) 29328 { 29329 ; 29330 29331 ungetc (c, input); 29332 } 29333 29334 static int 29335 read_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 29367 static int 29368 yylex (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 29403 static int 29404 power (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 29415 int 29416 main (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 29453 echo "calc.at:588: bison -o calc.c calc.y" 29454 echo calc.at:588 >$at_check_line_file 29455 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 29456 at_status=$? 29457 grep '^ *+' $at_stder1 >&2 29458 grep -v '^ *+' $at_stder1 >$at_stderr 29459 at_failed=false 29460 $at_diff $at_devnull $at_stderr || at_failed=: 29461 $at_diff $at_devnull $at_stdout || at_failed=: 29462 case $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=:;; 29468 esac 29469 if $at_failed; then 29470 29471 echo 1 > $at_status_file 29472 exit 1 29473 fi 29474 29475 $at_traceon 29476 29477 $at_traceoff 29478 echo "calc.at:588: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 29479 echo calc.at:588 >$at_check_line_file 29480 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 29481 at_status=$? 29482 grep '^ *+' $at_stder1 >&2 29483 grep -v '^ *+' $at_stder1 >$at_stderr 29484 at_failed=false 29485 echo stderr:; cat $at_stderr 29486 echo stdout:; cat $at_stdout 29487 case $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=:;; 29493 esac 29494 if $at_failed; then 29495 29496 echo 1 > $at_status_file 29497 exit 1 29498 fi 29499 29500 $at_traceon 29501 29502 29503 # Test the priorities. 29504 cat >input <<'_ATEOF' 29505 1 + 2 * 3 = 7 29506 1 + 2 * -3 = -5 29507 29508 -1^2 = -1 29509 (-1)^2 = 1 29510 29511 ---1 = -1 29512 29513 1 - 2 - 3 = -4 29514 1 - (2 - 3) = 2 29515 29516 2^2^3 = 256 29517 (2^2)^3 = 64 29518 _ATEOF 29519 29520 $at_traceoff 29521 echo "calc.at:588: \$PREPARSER ./calc input" 29522 echo calc.at:588 >$at_check_line_file 29523 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 29524 at_status=$? 29525 grep '^ *+' $at_stder1 >&2 29526 grep -v '^ *+' $at_stder1 >$at_stderr 29527 at_failed=false 29528 echo stderr:; tee stderr <$at_stderr 29529 $at_diff $at_devnull $at_stdout || at_failed=: 29530 case $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=:;; 29536 esac 29537 if $at_failed; then 29538 29539 echo 1 > $at_status_file 29540 exit 1 29541 fi 29542 29543 $at_traceon 29544 29545 29546 29547 # Some syntax errors. 29548 cat >input <<'_ATEOF' 29549 0 0 29550 _ATEOF 29551 29552 $at_traceoff 29553 echo "calc.at:588: \$PREPARSER ./calc input" 29554 echo calc.at:588 >$at_check_line_file 29555 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 29556 at_status=$? 29557 grep '^ *+' $at_stder1 >&2 29558 grep -v '^ *+' $at_stder1 >$at_stderr 29559 at_failed=false 29560 echo stderr:; tee stderr <$at_stderr 29561 $at_diff $at_devnull $at_stdout || at_failed=: 29562 case $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=:;; 29568 esac 29569 if $at_failed; then 29570 29571 echo 1 > $at_status_file 29572 exit 1 29573 fi 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. 29581 sed '/^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 29594 mv at-stderr stderr 29595 # 2. Create the reference error message. 29596 cat >expout <<'_ATEOF' 29597 1.2: syntax error, unexpected number 29598 _ATEOF 29599 29600 # 3. If locations are not used, remove them. 29601 sed 's/^[-0-9.]*: //' expout >at-expout 29602 mv at-expout expout 29603 # 4. If error-verbose is not used, strip the`, unexpected....' part. 29604 sed 's/syntax error, .*$/syntax error/' expout >at-expout 29605 mv at-expout expout 29606 # 5. Check 29607 $at_traceoff 29608 echo "calc.at:588: cat stderr" 29609 echo calc.at:588 >$at_check_line_file 29610 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 29611 at_status=$? 29612 grep '^ *+' $at_stder1 >&2 29613 grep -v '^ *+' $at_stder1 >$at_stderr 29614 at_failed=false 29615 $at_diff $at_devnull $at_stderr || at_failed=: 29616 $at_diff expout $at_stdout || at_failed=: 29617 case $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=:;; 29623 esac 29624 if $at_failed; then 29625 29626 echo 1 > $at_status_file 29627 exit 1 29628 fi 29629 29630 $at_traceon 29631 29632 29633 cat >input <<'_ATEOF' 29634 1//2 29635 _ATEOF 29636 29637 $at_traceoff 29638 echo "calc.at:588: \$PREPARSER ./calc input" 29639 echo calc.at:588 >$at_check_line_file 29640 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 29641 at_status=$? 29642 grep '^ *+' $at_stder1 >&2 29643 grep -v '^ *+' $at_stder1 >$at_stderr 29644 at_failed=false 29645 echo stderr:; tee stderr <$at_stderr 29646 $at_diff $at_devnull $at_stdout || at_failed=: 29647 case $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=:;; 29653 esac 29654 if $at_failed; then 29655 29656 echo 1 > $at_status_file 29657 exit 1 29658 fi 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. 29666 sed '/^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 29679 mv at-stderr stderr 29680 # 2. Create the reference error message. 29681 cat >expout <<'_ATEOF' 29682 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 29683 _ATEOF 29684 29685 # 3. If locations are not used, remove them. 29686 sed 's/^[-0-9.]*: //' expout >at-expout 29687 mv at-expout expout 29688 # 4. If error-verbose is not used, strip the`, unexpected....' part. 29689 sed 's/syntax error, .*$/syntax error/' expout >at-expout 29690 mv at-expout expout 29691 # 5. Check 29692 $at_traceoff 29693 echo "calc.at:588: cat stderr" 29694 echo calc.at:588 >$at_check_line_file 29695 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 29696 at_status=$? 29697 grep '^ *+' $at_stder1 >&2 29698 grep -v '^ *+' $at_stder1 >$at_stderr 29699 at_failed=false 29700 $at_diff $at_devnull $at_stderr || at_failed=: 29701 $at_diff expout $at_stdout || at_failed=: 29702 case $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=:;; 29708 esac 29709 if $at_failed; then 29710 29711 echo 1 > $at_status_file 29712 exit 1 29713 fi 29714 29715 $at_traceon 29716 29717 29718 cat >input <<'_ATEOF' 29719 error 29720 _ATEOF 29721 29722 $at_traceoff 29723 echo "calc.at:588: \$PREPARSER ./calc input" 29724 echo calc.at:588 >$at_check_line_file 29725 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 29726 at_status=$? 29727 grep '^ *+' $at_stder1 >&2 29728 grep -v '^ *+' $at_stder1 >$at_stderr 29729 at_failed=false 29730 echo stderr:; tee stderr <$at_stderr 29731 $at_diff $at_devnull $at_stdout || at_failed=: 29732 case $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=:;; 29738 esac 29739 if $at_failed; then 29740 29741 echo 1 > $at_status_file 29742 exit 1 29743 fi 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. 29751 sed '/^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 29764 mv at-stderr stderr 29765 # 2. Create the reference error message. 29766 cat >expout <<'_ATEOF' 29767 1.0: syntax error, unexpected $undefined 29768 _ATEOF 29769 29770 # 3. If locations are not used, remove them. 29771 sed 's/^[-0-9.]*: //' expout >at-expout 29772 mv at-expout expout 29773 # 4. If error-verbose is not used, strip the`, unexpected....' part. 29774 sed 's/syntax error, .*$/syntax error/' expout >at-expout 29775 mv at-expout expout 29776 # 5. Check 29777 $at_traceoff 29778 echo "calc.at:588: cat stderr" 29779 echo calc.at:588 >$at_check_line_file 29780 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 29781 at_status=$? 29782 grep '^ *+' $at_stder1 >&2 29783 grep -v '^ *+' $at_stder1 >$at_stderr 29784 at_failed=false 29785 $at_diff $at_devnull $at_stderr || at_failed=: 29786 $at_diff expout $at_stdout || at_failed=: 29787 case $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=:;; 29793 esac 29794 if $at_failed; then 29795 29796 echo 1 > $at_status_file 29797 exit 1 29798 fi 29799 29800 $at_traceon 29801 29802 29803 cat >input <<'_ATEOF' 29804 1 = 2 = 3 29805 _ATEOF 29806 29807 $at_traceoff 29808 echo "calc.at:588: \$PREPARSER ./calc input" 29809 echo calc.at:588 >$at_check_line_file 29810 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 29811 at_status=$? 29812 grep '^ *+' $at_stder1 >&2 29813 grep -v '^ *+' $at_stder1 >$at_stderr 29814 at_failed=false 29815 echo stderr:; tee stderr <$at_stderr 29816 $at_diff $at_devnull $at_stdout || at_failed=: 29817 case $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=:;; 29823 esac 29824 if $at_failed; then 29825 29826 echo 1 > $at_status_file 29827 exit 1 29828 fi 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. 29836 sed '/^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 29849 mv at-stderr stderr 29850 # 2. Create the reference error message. 29851 cat >expout <<'_ATEOF' 29852 1.6: syntax error, unexpected '=' 29853 _ATEOF 29854 29855 # 3. If locations are not used, remove them. 29856 sed 's/^[-0-9.]*: //' expout >at-expout 29857 mv at-expout expout 29858 # 4. If error-verbose is not used, strip the`, unexpected....' part. 29859 sed 's/syntax error, .*$/syntax error/' expout >at-expout 29860 mv at-expout expout 29861 # 5. Check 29862 $at_traceoff 29863 echo "calc.at:588: cat stderr" 29864 echo calc.at:588 >$at_check_line_file 29865 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 29866 at_status=$? 29867 grep '^ *+' $at_stder1 >&2 29868 grep -v '^ *+' $at_stder1 >$at_stderr 29869 at_failed=false 29870 $at_diff $at_devnull $at_stderr || at_failed=: 29871 $at_diff expout $at_stdout || at_failed=: 29872 case $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=:;; 29878 esac 29879 if $at_failed; then 29880 29881 echo 1 > $at_status_file 29882 exit 1 29883 fi 29884 29885 $at_traceon 29886 29887 29888 cat >input <<'_ATEOF' 29889 29890 +1 29891 _ATEOF 29892 29893 $at_traceoff 29894 echo "calc.at:588: \$PREPARSER ./calc input" 29895 echo calc.at:588 >$at_check_line_file 29896 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 29897 at_status=$? 29898 grep '^ *+' $at_stder1 >&2 29899 grep -v '^ *+' $at_stder1 >$at_stderr 29900 at_failed=false 29901 echo stderr:; tee stderr <$at_stderr 29902 $at_diff $at_devnull $at_stdout || at_failed=: 29903 case $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=:;; 29909 esac 29910 if $at_failed; then 29911 29912 echo 1 > $at_status_file 29913 exit 1 29914 fi 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. 29922 sed '/^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 29935 mv at-stderr stderr 29936 # 2. Create the reference error message. 29937 cat >expout <<'_ATEOF' 29938 2.0: syntax error, unexpected '+' 29939 _ATEOF 29940 29941 # 3. If locations are not used, remove them. 29942 sed 's/^[-0-9.]*: //' expout >at-expout 29943 mv at-expout expout 29944 # 4. If error-verbose is not used, strip the`, unexpected....' part. 29945 sed 's/syntax error, .*$/syntax error/' expout >at-expout 29946 mv at-expout expout 29947 # 5. Check 29948 $at_traceoff 29949 echo "calc.at:588: cat stderr" 29950 echo calc.at:588 >$at_check_line_file 29951 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 29952 at_status=$? 29953 grep '^ *+' $at_stder1 >&2 29954 grep -v '^ *+' $at_stder1 >$at_stderr 29955 at_failed=false 29956 $at_diff $at_devnull $at_stderr || at_failed=: 29957 $at_diff expout $at_stdout || at_failed=: 29958 case $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=:;; 29964 esac 29965 if $at_failed; then 29966 29967 echo 1 > $at_status_file 29968 exit 1 29969 fi 29970 29971 $at_traceon 29972 29973 29974 # Exercise error messages with EOF: work on an empty file. 29975 $at_traceoff 29976 echo "calc.at:588: \$PREPARSER ./calc /dev/null" 29977 echo calc.at:588 >$at_check_line_file 29978 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 29979 at_status=$? 29980 grep '^ *+' $at_stder1 >&2 29981 grep -v '^ *+' $at_stder1 >$at_stderr 29982 at_failed=false 29983 echo stderr:; tee stderr <$at_stderr 29984 $at_diff $at_devnull $at_stdout || at_failed=: 29985 case $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=:;; 29991 esac 29992 if $at_failed; then 29993 29994 echo 1 > $at_status_file 29995 exit 1 29996 fi 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. 30004 sed '/^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 30017 mv at-stderr stderr 30018 # 2. Create the reference error message. 30019 cat >expout <<'_ATEOF' 30020 1.0: syntax error, unexpected end of input 30021 _ATEOF 30022 30023 # 3. If locations are not used, remove them. 30024 sed 's/^[-0-9.]*: //' expout >at-expout 30025 mv at-expout expout 30026 # 4. If error-verbose is not used, strip the`, unexpected....' part. 30027 sed 's/syntax error, .*$/syntax error/' expout >at-expout 30028 mv at-expout expout 30029 # 5. Check 30030 $at_traceoff 30031 echo "calc.at:588: cat stderr" 30032 echo calc.at:588 >$at_check_line_file 30033 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 30034 at_status=$? 30035 grep '^ *+' $at_stder1 >&2 30036 grep -v '^ *+' $at_stder1 >$at_stderr 30037 at_failed=false 30038 $at_diff $at_devnull $at_stderr || at_failed=: 30039 $at_diff expout $at_stdout || at_failed=: 30040 case $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=:;; 30046 esac 30047 if $at_failed; then 30048 30049 echo 1 > $at_status_file 30050 exit 1 30051 fi 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 # 30073 cat >input <<'_ATEOF' 30074 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 30075 _ATEOF 30076 30077 $at_traceoff 30078 echo "calc.at:588: \$PREPARSER ./calc input" 30079 echo calc.at:588 >$at_check_line_file 30080 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 30081 at_status=$? 30082 grep '^ *+' $at_stder1 >&2 30083 grep -v '^ *+' $at_stder1 >$at_stderr 30084 at_failed=false 30085 echo stderr:; tee stderr <$at_stderr 30086 $at_diff $at_devnull $at_stdout || at_failed=: 30087 case $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=:;; 30093 esac 30094 if $at_failed; then 30095 30096 echo 1 > $at_status_file 30097 exit 1 30098 fi 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. 30106 sed '/^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 30119 mv at-stderr stderr 30120 # 2. Create the reference error message. 30121 cat >expout <<'_ATEOF' 30122 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 30123 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 30124 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 30125 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 30126 calc: error: 4444 != 1 30127 _ATEOF 30128 30129 # 3. If locations are not used, remove them. 30130 sed 's/^[-0-9.]*: //' expout >at-expout 30131 mv at-expout expout 30132 # 4. If error-verbose is not used, strip the`, unexpected....' part. 30133 sed 's/syntax error, .*$/syntax error/' expout >at-expout 30134 mv at-expout expout 30135 # 5. Check 30136 $at_traceoff 30137 echo "calc.at:588: cat stderr" 30138 echo calc.at:588 >$at_check_line_file 30139 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 30140 at_status=$? 30141 grep '^ *+' $at_stder1 >&2 30142 grep -v '^ *+' $at_stder1 >$at_stderr 30143 at_failed=false 30144 $at_diff $at_devnull $at_stderr || at_failed=: 30145 $at_diff expout $at_stdout || at_failed=: 30146 case $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=:;; 30152 esac 30153 if $at_failed; then 30154 30155 echo 1 > $at_status_file 30156 exit 1 30157 fi 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. 30165 cat >input <<'_ATEOF' 30166 (!) + (0 0) = 1 30167 _ATEOF 30168 30169 $at_traceoff 30170 echo "calc.at:588: \$PREPARSER ./calc input" 30171 echo calc.at:588 >$at_check_line_file 30172 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 30173 at_status=$? 30174 grep '^ *+' $at_stder1 >&2 30175 grep -v '^ *+' $at_stder1 >$at_stderr 30176 at_failed=false 30177 echo stderr:; tee stderr <$at_stderr 30178 $at_diff $at_devnull $at_stdout || at_failed=: 30179 case $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=:;; 30185 esac 30186 if $at_failed; then 30187 30188 echo 1 > $at_status_file 30189 exit 1 30190 fi 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. 30198 sed '/^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 30211 mv at-stderr stderr 30212 # 2. Create the reference error message. 30213 cat >expout <<'_ATEOF' 30214 1.9: syntax error, unexpected number 30215 calc: error: 2222 != 1 30216 _ATEOF 30217 30218 # 3. If locations are not used, remove them. 30219 sed 's/^[-0-9.]*: //' expout >at-expout 30220 mv at-expout expout 30221 # 4. If error-verbose is not used, strip the`, unexpected....' part. 30222 sed 's/syntax error, .*$/syntax error/' expout >at-expout 30223 mv at-expout expout 30224 # 5. Check 30225 $at_traceoff 30226 echo "calc.at:588: cat stderr" 30227 echo calc.at:588 >$at_check_line_file 30228 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 30229 at_status=$? 30230 grep '^ *+' $at_stder1 >&2 30231 grep -v '^ *+' $at_stder1 >$at_stderr 30232 at_failed=false 30233 $at_diff $at_devnull $at_stderr || at_failed=: 30234 $at_diff expout $at_stdout || at_failed=: 30235 case $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=:;; 30241 esac 30242 if $at_failed; then 30243 30244 echo 1 > $at_status_file 30245 exit 1 30246 fi 30247 30248 $at_traceon 30249 30250 30251 cat >input <<'_ATEOF' 30252 (- *) + (0 0) = 1 30253 _ATEOF 30254 30255 $at_traceoff 30256 echo "calc.at:588: \$PREPARSER ./calc input" 30257 echo calc.at:588 >$at_check_line_file 30258 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 30259 at_status=$? 30260 grep '^ *+' $at_stder1 >&2 30261 grep -v '^ *+' $at_stder1 >$at_stderr 30262 at_failed=false 30263 echo stderr:; tee stderr <$at_stderr 30264 $at_diff $at_devnull $at_stdout || at_failed=: 30265 case $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=:;; 30271 esac 30272 if $at_failed; then 30273 30274 echo 1 > $at_status_file 30275 exit 1 30276 fi 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. 30284 sed '/^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 30297 mv at-stderr stderr 30298 # 2. Create the reference error message. 30299 cat >expout <<'_ATEOF' 30300 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 30301 1.11: syntax error, unexpected number 30302 calc: error: 2222 != 1 30303 _ATEOF 30304 30305 # 3. If locations are not used, remove them. 30306 sed 's/^[-0-9.]*: //' expout >at-expout 30307 mv at-expout expout 30308 # 4. If error-verbose is not used, strip the`, unexpected....' part. 30309 sed 's/syntax error, .*$/syntax error/' expout >at-expout 30310 mv at-expout expout 30311 # 5. Check 30312 $at_traceoff 30313 echo "calc.at:588: cat stderr" 30314 echo calc.at:588 >$at_check_line_file 30315 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 30316 at_status=$? 30317 grep '^ *+' $at_stder1 >&2 30318 grep -v '^ *+' $at_stder1 >$at_stderr 30319 at_failed=false 30320 $at_diff $at_devnull $at_stderr || at_failed=: 30321 $at_diff expout $at_stdout || at_failed=: 30322 case $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=:;; 30328 esac 30329 if $at_failed; then 30330 30331 echo 1 > $at_status_file 30332 exit 1 30333 fi 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 30410 cat >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. */ 30439 typedef int semantic_value; 30440 30441 static semantic_value global_result = 0; 30442 static int global_count = 0; 30443 %} 30444 30445 /* Exercise %union. */ 30446 %union 30447 { 30448 semantic_value ival; 30449 }; 30450 30451 %{ 30452 static int power (int base, int exponent); 30453 /* yyerror receives the location if: 30454 - %location & %pure & %glr 30455 - %location & %pure & %yacc & %parse-param. */ 30456 static void yyerror ( 30457 30458 const char *s 30459 ); 30460 static int yylex (void); 30461 static int get_char (void); 30462 static 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 %% 30480 input: 30481 line 30482 | input line { } 30483 ; 30484 30485 line: 30486 '\n' 30487 | exp '\n' { USE ($1); } 30488 ; 30489 30490 exp: 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. */ 30511 static FILE *input; 30512 30513 static void 30514 yyerror ( 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 30534 static YYLTYPE last_yylloc; 30535 30536 static int 30537 get_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 30555 static void 30556 unget_char ( int c) 30557 { 30558 ; 30559 30560 /* Wrong when C == `\n'. */ 30561 (yylloc) = last_yylloc; 30562 30563 ungetc (c, input); 30564 } 30565 30566 static int 30567 read_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 30599 static int 30600 yylex (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 30643 static int 30644 power (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 30655 int 30656 main (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 30693 echo "calc.at:589: bison -o calc.c calc.y" 30694 echo calc.at:589 >$at_check_line_file 30695 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 30696 at_status=$? 30697 grep '^ *+' $at_stder1 >&2 30698 grep -v '^ *+' $at_stder1 >$at_stderr 30699 at_failed=false 30700 $at_diff $at_devnull $at_stderr || at_failed=: 30701 $at_diff $at_devnull $at_stdout || at_failed=: 30702 case $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=:;; 30708 esac 30709 if $at_failed; then 30710 30711 echo 1 > $at_status_file 30712 exit 1 30713 fi 30714 30715 $at_traceon 30716 30717 $at_traceoff 30718 echo "calc.at:589: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 30719 echo calc.at:589 >$at_check_line_file 30720 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 30721 at_status=$? 30722 grep '^ *+' $at_stder1 >&2 30723 grep -v '^ *+' $at_stder1 >$at_stderr 30724 at_failed=false 30725 echo stderr:; cat $at_stderr 30726 echo stdout:; cat $at_stdout 30727 case $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=:;; 30733 esac 30734 if $at_failed; then 30735 30736 echo 1 > $at_status_file 30737 exit 1 30738 fi 30739 30740 $at_traceon 30741 30742 30743 # Test the priorities. 30744 cat >input <<'_ATEOF' 30745 1 + 2 * 3 = 7 30746 1 + 2 * -3 = -5 30747 30748 -1^2 = -1 30749 (-1)^2 = 1 30750 30751 ---1 = -1 30752 30753 1 - 2 - 3 = -4 30754 1 - (2 - 3) = 2 30755 30756 2^2^3 = 256 30757 (2^2)^3 = 64 30758 _ATEOF 30759 30760 $at_traceoff 30761 echo "calc.at:589: \$PREPARSER ./calc input" 30762 echo calc.at:589 >$at_check_line_file 30763 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 30764 at_status=$? 30765 grep '^ *+' $at_stder1 >&2 30766 grep -v '^ *+' $at_stder1 >$at_stderr 30767 at_failed=false 30768 echo stderr:; tee stderr <$at_stderr 30769 $at_diff $at_devnull $at_stdout || at_failed=: 30770 case $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=:;; 30776 esac 30777 if $at_failed; then 30778 30779 echo 1 > $at_status_file 30780 exit 1 30781 fi 30782 30783 $at_traceon 30784 30785 30786 30787 # Some syntax errors. 30788 cat >input <<'_ATEOF' 30789 0 0 30790 _ATEOF 30791 30792 $at_traceoff 30793 echo "calc.at:589: \$PREPARSER ./calc input" 30794 echo calc.at:589 >$at_check_line_file 30795 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 30796 at_status=$? 30797 grep '^ *+' $at_stder1 >&2 30798 grep -v '^ *+' $at_stder1 >$at_stderr 30799 at_failed=false 30800 echo stderr:; tee stderr <$at_stderr 30801 $at_diff $at_devnull $at_stdout || at_failed=: 30802 case $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=:;; 30808 esac 30809 if $at_failed; then 30810 30811 echo 1 > $at_status_file 30812 exit 1 30813 fi 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. 30821 sed '/^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 30834 mv at-stderr stderr 30835 # 2. Create the reference error message. 30836 cat >expout <<'_ATEOF' 30837 1.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. 30843 sed 's/syntax error, .*$/syntax error/' expout >at-expout 30844 mv at-expout expout 30845 # 5. Check 30846 $at_traceoff 30847 echo "calc.at:589: cat stderr" 30848 echo calc.at:589 >$at_check_line_file 30849 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 30850 at_status=$? 30851 grep '^ *+' $at_stder1 >&2 30852 grep -v '^ *+' $at_stder1 >$at_stderr 30853 at_failed=false 30854 $at_diff $at_devnull $at_stderr || at_failed=: 30855 $at_diff expout $at_stdout || at_failed=: 30856 case $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=:;; 30862 esac 30863 if $at_failed; then 30864 30865 echo 1 > $at_status_file 30866 exit 1 30867 fi 30868 30869 $at_traceon 30870 30871 30872 cat >input <<'_ATEOF' 30873 1//2 30874 _ATEOF 30875 30876 $at_traceoff 30877 echo "calc.at:589: \$PREPARSER ./calc input" 30878 echo calc.at:589 >$at_check_line_file 30879 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 30880 at_status=$? 30881 grep '^ *+' $at_stder1 >&2 30882 grep -v '^ *+' $at_stder1 >$at_stderr 30883 at_failed=false 30884 echo stderr:; tee stderr <$at_stderr 30885 $at_diff $at_devnull $at_stdout || at_failed=: 30886 case $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=:;; 30892 esac 30893 if $at_failed; then 30894 30895 echo 1 > $at_status_file 30896 exit 1 30897 fi 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. 30905 sed '/^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 30918 mv at-stderr stderr 30919 # 2. Create the reference error message. 30920 cat >expout <<'_ATEOF' 30921 1.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. 30927 sed 's/syntax error, .*$/syntax error/' expout >at-expout 30928 mv at-expout expout 30929 # 5. Check 30930 $at_traceoff 30931 echo "calc.at:589: cat stderr" 30932 echo calc.at:589 >$at_check_line_file 30933 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 30934 at_status=$? 30935 grep '^ *+' $at_stder1 >&2 30936 grep -v '^ *+' $at_stder1 >$at_stderr 30937 at_failed=false 30938 $at_diff $at_devnull $at_stderr || at_failed=: 30939 $at_diff expout $at_stdout || at_failed=: 30940 case $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=:;; 30946 esac 30947 if $at_failed; then 30948 30949 echo 1 > $at_status_file 30950 exit 1 30951 fi 30952 30953 $at_traceon 30954 30955 30956 cat >input <<'_ATEOF' 30957 error 30958 _ATEOF 30959 30960 $at_traceoff 30961 echo "calc.at:589: \$PREPARSER ./calc input" 30962 echo calc.at:589 >$at_check_line_file 30963 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 30964 at_status=$? 30965 grep '^ *+' $at_stder1 >&2 30966 grep -v '^ *+' $at_stder1 >$at_stderr 30967 at_failed=false 30968 echo stderr:; tee stderr <$at_stderr 30969 $at_diff $at_devnull $at_stdout || at_failed=: 30970 case $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=:;; 30976 esac 30977 if $at_failed; then 30978 30979 echo 1 > $at_status_file 30980 exit 1 30981 fi 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. 30989 sed '/^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 31002 mv at-stderr stderr 31003 # 2. Create the reference error message. 31004 cat >expout <<'_ATEOF' 31005 1.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. 31011 sed 's/syntax error, .*$/syntax error/' expout >at-expout 31012 mv at-expout expout 31013 # 5. Check 31014 $at_traceoff 31015 echo "calc.at:589: cat stderr" 31016 echo calc.at:589 >$at_check_line_file 31017 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 31018 at_status=$? 31019 grep '^ *+' $at_stder1 >&2 31020 grep -v '^ *+' $at_stder1 >$at_stderr 31021 at_failed=false 31022 $at_diff $at_devnull $at_stderr || at_failed=: 31023 $at_diff expout $at_stdout || at_failed=: 31024 case $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=:;; 31030 esac 31031 if $at_failed; then 31032 31033 echo 1 > $at_status_file 31034 exit 1 31035 fi 31036 31037 $at_traceon 31038 31039 31040 cat >input <<'_ATEOF' 31041 1 = 2 = 3 31042 _ATEOF 31043 31044 $at_traceoff 31045 echo "calc.at:589: \$PREPARSER ./calc input" 31046 echo calc.at:589 >$at_check_line_file 31047 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 31048 at_status=$? 31049 grep '^ *+' $at_stder1 >&2 31050 grep -v '^ *+' $at_stder1 >$at_stderr 31051 at_failed=false 31052 echo stderr:; tee stderr <$at_stderr 31053 $at_diff $at_devnull $at_stdout || at_failed=: 31054 case $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=:;; 31060 esac 31061 if $at_failed; then 31062 31063 echo 1 > $at_status_file 31064 exit 1 31065 fi 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. 31073 sed '/^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 31086 mv at-stderr stderr 31087 # 2. Create the reference error message. 31088 cat >expout <<'_ATEOF' 31089 1.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. 31095 sed 's/syntax error, .*$/syntax error/' expout >at-expout 31096 mv at-expout expout 31097 # 5. Check 31098 $at_traceoff 31099 echo "calc.at:589: cat stderr" 31100 echo calc.at:589 >$at_check_line_file 31101 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 31102 at_status=$? 31103 grep '^ *+' $at_stder1 >&2 31104 grep -v '^ *+' $at_stder1 >$at_stderr 31105 at_failed=false 31106 $at_diff $at_devnull $at_stderr || at_failed=: 31107 $at_diff expout $at_stdout || at_failed=: 31108 case $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=:;; 31114 esac 31115 if $at_failed; then 31116 31117 echo 1 > $at_status_file 31118 exit 1 31119 fi 31120 31121 $at_traceon 31122 31123 31124 cat >input <<'_ATEOF' 31125 31126 +1 31127 _ATEOF 31128 31129 $at_traceoff 31130 echo "calc.at:589: \$PREPARSER ./calc input" 31131 echo calc.at:589 >$at_check_line_file 31132 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 31133 at_status=$? 31134 grep '^ *+' $at_stder1 >&2 31135 grep -v '^ *+' $at_stder1 >$at_stderr 31136 at_failed=false 31137 echo stderr:; tee stderr <$at_stderr 31138 $at_diff $at_devnull $at_stdout || at_failed=: 31139 case $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=:;; 31145 esac 31146 if $at_failed; then 31147 31148 echo 1 > $at_status_file 31149 exit 1 31150 fi 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. 31158 sed '/^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 31171 mv at-stderr stderr 31172 # 2. Create the reference error message. 31173 cat >expout <<'_ATEOF' 31174 2.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. 31180 sed 's/syntax error, .*$/syntax error/' expout >at-expout 31181 mv at-expout expout 31182 # 5. Check 31183 $at_traceoff 31184 echo "calc.at:589: cat stderr" 31185 echo calc.at:589 >$at_check_line_file 31186 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 31187 at_status=$? 31188 grep '^ *+' $at_stder1 >&2 31189 grep -v '^ *+' $at_stder1 >$at_stderr 31190 at_failed=false 31191 $at_diff $at_devnull $at_stderr || at_failed=: 31192 $at_diff expout $at_stdout || at_failed=: 31193 case $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=:;; 31199 esac 31200 if $at_failed; then 31201 31202 echo 1 > $at_status_file 31203 exit 1 31204 fi 31205 31206 $at_traceon 31207 31208 31209 # Exercise error messages with EOF: work on an empty file. 31210 $at_traceoff 31211 echo "calc.at:589: \$PREPARSER ./calc /dev/null" 31212 echo calc.at:589 >$at_check_line_file 31213 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 31214 at_status=$? 31215 grep '^ *+' $at_stder1 >&2 31216 grep -v '^ *+' $at_stder1 >$at_stderr 31217 at_failed=false 31218 echo stderr:; tee stderr <$at_stderr 31219 $at_diff $at_devnull $at_stdout || at_failed=: 31220 case $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=:;; 31226 esac 31227 if $at_failed; then 31228 31229 echo 1 > $at_status_file 31230 exit 1 31231 fi 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. 31239 sed '/^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 31252 mv at-stderr stderr 31253 # 2. Create the reference error message. 31254 cat >expout <<'_ATEOF' 31255 1.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. 31261 sed 's/syntax error, .*$/syntax error/' expout >at-expout 31262 mv at-expout expout 31263 # 5. Check 31264 $at_traceoff 31265 echo "calc.at:589: cat stderr" 31266 echo calc.at:589 >$at_check_line_file 31267 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 31268 at_status=$? 31269 grep '^ *+' $at_stder1 >&2 31270 grep -v '^ *+' $at_stder1 >$at_stderr 31271 at_failed=false 31272 $at_diff $at_devnull $at_stderr || at_failed=: 31273 $at_diff expout $at_stdout || at_failed=: 31274 case $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=:;; 31280 esac 31281 if $at_failed; then 31282 31283 echo 1 > $at_status_file 31284 exit 1 31285 fi 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 # 31307 cat >input <<'_ATEOF' 31308 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 31309 _ATEOF 31310 31311 $at_traceoff 31312 echo "calc.at:589: \$PREPARSER ./calc input" 31313 echo calc.at:589 >$at_check_line_file 31314 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 31315 at_status=$? 31316 grep '^ *+' $at_stder1 >&2 31317 grep -v '^ *+' $at_stder1 >$at_stderr 31318 at_failed=false 31319 echo stderr:; tee stderr <$at_stderr 31320 $at_diff $at_devnull $at_stdout || at_failed=: 31321 case $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=:;; 31327 esac 31328 if $at_failed; then 31329 31330 echo 1 > $at_status_file 31331 exit 1 31332 fi 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. 31340 sed '/^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 31353 mv at-stderr stderr 31354 # 2. Create the reference error message. 31355 cat >expout <<'_ATEOF' 31356 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 31357 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 31358 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 31359 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 31360 calc: 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. 31366 sed 's/syntax error, .*$/syntax error/' expout >at-expout 31367 mv at-expout expout 31368 # 5. Check 31369 $at_traceoff 31370 echo "calc.at:589: cat stderr" 31371 echo calc.at:589 >$at_check_line_file 31372 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 31373 at_status=$? 31374 grep '^ *+' $at_stder1 >&2 31375 grep -v '^ *+' $at_stder1 >$at_stderr 31376 at_failed=false 31377 $at_diff $at_devnull $at_stderr || at_failed=: 31378 $at_diff expout $at_stdout || at_failed=: 31379 case $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=:;; 31385 esac 31386 if $at_failed; then 31387 31388 echo 1 > $at_status_file 31389 exit 1 31390 fi 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. 31398 cat >input <<'_ATEOF' 31399 (!) + (0 0) = 1 31400 _ATEOF 31401 31402 $at_traceoff 31403 echo "calc.at:589: \$PREPARSER ./calc input" 31404 echo calc.at:589 >$at_check_line_file 31405 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 31406 at_status=$? 31407 grep '^ *+' $at_stder1 >&2 31408 grep -v '^ *+' $at_stder1 >$at_stderr 31409 at_failed=false 31410 echo stderr:; tee stderr <$at_stderr 31411 $at_diff $at_devnull $at_stdout || at_failed=: 31412 case $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=:;; 31418 esac 31419 if $at_failed; then 31420 31421 echo 1 > $at_status_file 31422 exit 1 31423 fi 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. 31431 sed '/^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 31444 mv at-stderr stderr 31445 # 2. Create the reference error message. 31446 cat >expout <<'_ATEOF' 31447 1.9: syntax error, unexpected number 31448 calc: 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. 31454 sed 's/syntax error, .*$/syntax error/' expout >at-expout 31455 mv at-expout expout 31456 # 5. Check 31457 $at_traceoff 31458 echo "calc.at:589: cat stderr" 31459 echo calc.at:589 >$at_check_line_file 31460 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 31461 at_status=$? 31462 grep '^ *+' $at_stder1 >&2 31463 grep -v '^ *+' $at_stder1 >$at_stderr 31464 at_failed=false 31465 $at_diff $at_devnull $at_stderr || at_failed=: 31466 $at_diff expout $at_stdout || at_failed=: 31467 case $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=:;; 31473 esac 31474 if $at_failed; then 31475 31476 echo 1 > $at_status_file 31477 exit 1 31478 fi 31479 31480 $at_traceon 31481 31482 31483 cat >input <<'_ATEOF' 31484 (- *) + (0 0) = 1 31485 _ATEOF 31486 31487 $at_traceoff 31488 echo "calc.at:589: \$PREPARSER ./calc input" 31489 echo calc.at:589 >$at_check_line_file 31490 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 31491 at_status=$? 31492 grep '^ *+' $at_stder1 >&2 31493 grep -v '^ *+' $at_stder1 >$at_stderr 31494 at_failed=false 31495 echo stderr:; tee stderr <$at_stderr 31496 $at_diff $at_devnull $at_stdout || at_failed=: 31497 case $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=:;; 31503 esac 31504 if $at_failed; then 31505 31506 echo 1 > $at_status_file 31507 exit 1 31508 fi 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. 31516 sed '/^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 31529 mv at-stderr stderr 31530 # 2. Create the reference error message. 31531 cat >expout <<'_ATEOF' 31532 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 31533 1.11: syntax error, unexpected number 31534 calc: 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. 31540 sed 's/syntax error, .*$/syntax error/' expout >at-expout 31541 mv at-expout expout 31542 # 5. Check 31543 $at_traceoff 31544 echo "calc.at:589: cat stderr" 31545 echo calc.at:589 >$at_check_line_file 31546 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 31547 at_status=$? 31548 grep '^ *+' $at_stder1 >&2 31549 grep -v '^ *+' $at_stder1 >$at_stderr 31550 at_failed=false 31551 $at_diff $at_devnull $at_stderr || at_failed=: 31552 $at_diff expout $at_stdout || at_failed=: 31553 case $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=:;; 31559 esac 31560 if $at_failed; then 31561 31562 echo 1 > $at_status_file 31563 exit 1 31564 fi 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 31641 cat >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. */ 31670 typedef int semantic_value; 31671 31672 static semantic_value global_result = 0; 31673 static int global_count = 0; 31674 %} 31675 31676 /* Exercise %union. */ 31677 %union 31678 { 31679 semantic_value ival; 31680 }; 31681 31682 %{ 31683 static int power (int base, int exponent); 31684 /* yyerror receives the location if: 31685 - %location & %pure & %glr 31686 - %location & %pure & %yacc & %parse-param. */ 31687 static void yyerror ( 31688 31689 const char *s 31690 ); 31691 static int yylex (void); 31692 static int get_char (void); 31693 static 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 %% 31711 input: 31712 line 31713 | input line { } 31714 ; 31715 31716 line: 31717 '\n' 31718 | exp '\n' { USE ($1); } 31719 ; 31720 31721 exp: 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. */ 31742 static FILE *input; 31743 31744 static void 31745 yyerror ( 31746 31747 const char *s) 31748 { 31749 31750 31751 fprintf (stderr, "%s\n", s); 31752 } 31753 31754 31755 31756 static int 31757 get_char (void) 31758 { 31759 int res = getc (input); 31760 ; 31761 31762 return res; 31763 } 31764 31765 31766 static void 31767 unget_char ( int c) 31768 { 31769 ; 31770 31771 ungetc (c, input); 31772 } 31773 31774 static int 31775 read_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 31807 static int 31808 yylex (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 31843 static int 31844 power (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 31855 int 31856 main (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 31893 echo "calc.at:590: bison -o calc.c calc.y" 31894 echo calc.at:590 >$at_check_line_file 31895 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 31896 at_status=$? 31897 grep '^ *+' $at_stder1 >&2 31898 grep -v '^ *+' $at_stder1 >$at_stderr 31899 at_failed=false 31900 $at_diff $at_devnull $at_stderr || at_failed=: 31901 $at_diff $at_devnull $at_stdout || at_failed=: 31902 case $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=:;; 31908 esac 31909 if $at_failed; then 31910 31911 echo 1 > $at_status_file 31912 exit 1 31913 fi 31914 31915 $at_traceon 31916 31917 $at_traceoff 31918 echo "calc.at:590: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 31919 echo calc.at:590 >$at_check_line_file 31920 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 31921 at_status=$? 31922 grep '^ *+' $at_stder1 >&2 31923 grep -v '^ *+' $at_stder1 >$at_stderr 31924 at_failed=false 31925 echo stderr:; cat $at_stderr 31926 echo stdout:; cat $at_stdout 31927 case $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=:;; 31933 esac 31934 if $at_failed; then 31935 31936 echo 1 > $at_status_file 31937 exit 1 31938 fi 31939 31940 $at_traceon 31941 31942 31943 # Test the priorities. 31944 cat >input <<'_ATEOF' 31945 1 + 2 * 3 = 7 31946 1 + 2 * -3 = -5 31947 31948 -1^2 = -1 31949 (-1)^2 = 1 31950 31951 ---1 = -1 31952 31953 1 - 2 - 3 = -4 31954 1 - (2 - 3) = 2 31955 31956 2^2^3 = 256 31957 (2^2)^3 = 64 31958 _ATEOF 31959 31960 $at_traceoff 31961 echo "calc.at:590: \$PREPARSER ./calc input" 31962 echo calc.at:590 >$at_check_line_file 31963 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 31964 at_status=$? 31965 grep '^ *+' $at_stder1 >&2 31966 grep -v '^ *+' $at_stder1 >$at_stderr 31967 at_failed=false 31968 echo stderr:; tee stderr <$at_stderr 31969 $at_diff $at_devnull $at_stdout || at_failed=: 31970 case $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=:;; 31976 esac 31977 if $at_failed; then 31978 31979 echo 1 > $at_status_file 31980 exit 1 31981 fi 31982 31983 $at_traceon 31984 31985 31986 31987 # Some syntax errors. 31988 cat >input <<'_ATEOF' 31989 0 0 31990 _ATEOF 31991 31992 $at_traceoff 31993 echo "calc.at:590: \$PREPARSER ./calc input" 31994 echo calc.at:590 >$at_check_line_file 31995 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 31996 at_status=$? 31997 grep '^ *+' $at_stder1 >&2 31998 grep -v '^ *+' $at_stder1 >$at_stderr 31999 at_failed=false 32000 echo stderr:; tee stderr <$at_stderr 32001 $at_diff $at_devnull $at_stdout || at_failed=: 32002 case $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=:;; 32008 esac 32009 if $at_failed; then 32010 32011 echo 1 > $at_status_file 32012 exit 1 32013 fi 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. 32021 sed '/^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 32034 mv at-stderr stderr 32035 # 2. Create the reference error message. 32036 cat >expout <<'_ATEOF' 32037 1.2: syntax error, unexpected number 32038 _ATEOF 32039 32040 # 3. If locations are not used, remove them. 32041 sed 's/^[-0-9.]*: //' expout >at-expout 32042 mv at-expout expout 32043 # 4. If error-verbose is not used, strip the`, unexpected....' part. 32044 sed 's/syntax error, .*$/syntax error/' expout >at-expout 32045 mv at-expout expout 32046 # 5. Check 32047 $at_traceoff 32048 echo "calc.at:590: cat stderr" 32049 echo calc.at:590 >$at_check_line_file 32050 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 32051 at_status=$? 32052 grep '^ *+' $at_stder1 >&2 32053 grep -v '^ *+' $at_stder1 >$at_stderr 32054 at_failed=false 32055 $at_diff $at_devnull $at_stderr || at_failed=: 32056 $at_diff expout $at_stdout || at_failed=: 32057 case $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=:;; 32063 esac 32064 if $at_failed; then 32065 32066 echo 1 > $at_status_file 32067 exit 1 32068 fi 32069 32070 $at_traceon 32071 32072 32073 cat >input <<'_ATEOF' 32074 1//2 32075 _ATEOF 32076 32077 $at_traceoff 32078 echo "calc.at:590: \$PREPARSER ./calc input" 32079 echo calc.at:590 >$at_check_line_file 32080 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 32081 at_status=$? 32082 grep '^ *+' $at_stder1 >&2 32083 grep -v '^ *+' $at_stder1 >$at_stderr 32084 at_failed=false 32085 echo stderr:; tee stderr <$at_stderr 32086 $at_diff $at_devnull $at_stdout || at_failed=: 32087 case $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=:;; 32093 esac 32094 if $at_failed; then 32095 32096 echo 1 > $at_status_file 32097 exit 1 32098 fi 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. 32106 sed '/^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 32119 mv at-stderr stderr 32120 # 2. Create the reference error message. 32121 cat >expout <<'_ATEOF' 32122 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 32123 _ATEOF 32124 32125 # 3. If locations are not used, remove them. 32126 sed 's/^[-0-9.]*: //' expout >at-expout 32127 mv at-expout expout 32128 # 4. If error-verbose is not used, strip the`, unexpected....' part. 32129 sed 's/syntax error, .*$/syntax error/' expout >at-expout 32130 mv at-expout expout 32131 # 5. Check 32132 $at_traceoff 32133 echo "calc.at:590: cat stderr" 32134 echo calc.at:590 >$at_check_line_file 32135 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 32136 at_status=$? 32137 grep '^ *+' $at_stder1 >&2 32138 grep -v '^ *+' $at_stder1 >$at_stderr 32139 at_failed=false 32140 $at_diff $at_devnull $at_stderr || at_failed=: 32141 $at_diff expout $at_stdout || at_failed=: 32142 case $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=:;; 32148 esac 32149 if $at_failed; then 32150 32151 echo 1 > $at_status_file 32152 exit 1 32153 fi 32154 32155 $at_traceon 32156 32157 32158 cat >input <<'_ATEOF' 32159 error 32160 _ATEOF 32161 32162 $at_traceoff 32163 echo "calc.at:590: \$PREPARSER ./calc input" 32164 echo calc.at:590 >$at_check_line_file 32165 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 32166 at_status=$? 32167 grep '^ *+' $at_stder1 >&2 32168 grep -v '^ *+' $at_stder1 >$at_stderr 32169 at_failed=false 32170 echo stderr:; tee stderr <$at_stderr 32171 $at_diff $at_devnull $at_stdout || at_failed=: 32172 case $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=:;; 32178 esac 32179 if $at_failed; then 32180 32181 echo 1 > $at_status_file 32182 exit 1 32183 fi 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. 32191 sed '/^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 32204 mv at-stderr stderr 32205 # 2. Create the reference error message. 32206 cat >expout <<'_ATEOF' 32207 1.0: syntax error, unexpected $undefined 32208 _ATEOF 32209 32210 # 3. If locations are not used, remove them. 32211 sed 's/^[-0-9.]*: //' expout >at-expout 32212 mv at-expout expout 32213 # 4. If error-verbose is not used, strip the`, unexpected....' part. 32214 sed 's/syntax error, .*$/syntax error/' expout >at-expout 32215 mv at-expout expout 32216 # 5. Check 32217 $at_traceoff 32218 echo "calc.at:590: cat stderr" 32219 echo calc.at:590 >$at_check_line_file 32220 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 32221 at_status=$? 32222 grep '^ *+' $at_stder1 >&2 32223 grep -v '^ *+' $at_stder1 >$at_stderr 32224 at_failed=false 32225 $at_diff $at_devnull $at_stderr || at_failed=: 32226 $at_diff expout $at_stdout || at_failed=: 32227 case $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=:;; 32233 esac 32234 if $at_failed; then 32235 32236 echo 1 > $at_status_file 32237 exit 1 32238 fi 32239 32240 $at_traceon 32241 32242 32243 cat >input <<'_ATEOF' 32244 1 = 2 = 3 32245 _ATEOF 32246 32247 $at_traceoff 32248 echo "calc.at:590: \$PREPARSER ./calc input" 32249 echo calc.at:590 >$at_check_line_file 32250 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 32251 at_status=$? 32252 grep '^ *+' $at_stder1 >&2 32253 grep -v '^ *+' $at_stder1 >$at_stderr 32254 at_failed=false 32255 echo stderr:; tee stderr <$at_stderr 32256 $at_diff $at_devnull $at_stdout || at_failed=: 32257 case $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=:;; 32263 esac 32264 if $at_failed; then 32265 32266 echo 1 > $at_status_file 32267 exit 1 32268 fi 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. 32276 sed '/^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 32289 mv at-stderr stderr 32290 # 2. Create the reference error message. 32291 cat >expout <<'_ATEOF' 32292 1.6: syntax error, unexpected '=' 32293 _ATEOF 32294 32295 # 3. If locations are not used, remove them. 32296 sed 's/^[-0-9.]*: //' expout >at-expout 32297 mv at-expout expout 32298 # 4. If error-verbose is not used, strip the`, unexpected....' part. 32299 sed 's/syntax error, .*$/syntax error/' expout >at-expout 32300 mv at-expout expout 32301 # 5. Check 32302 $at_traceoff 32303 echo "calc.at:590: cat stderr" 32304 echo calc.at:590 >$at_check_line_file 32305 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 32306 at_status=$? 32307 grep '^ *+' $at_stder1 >&2 32308 grep -v '^ *+' $at_stder1 >$at_stderr 32309 at_failed=false 32310 $at_diff $at_devnull $at_stderr || at_failed=: 32311 $at_diff expout $at_stdout || at_failed=: 32312 case $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=:;; 32318 esac 32319 if $at_failed; then 32320 32321 echo 1 > $at_status_file 32322 exit 1 32323 fi 32324 32325 $at_traceon 32326 32327 32328 cat >input <<'_ATEOF' 32329 32330 +1 32331 _ATEOF 32332 32333 $at_traceoff 32334 echo "calc.at:590: \$PREPARSER ./calc input" 32335 echo calc.at:590 >$at_check_line_file 32336 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 32337 at_status=$? 32338 grep '^ *+' $at_stder1 >&2 32339 grep -v '^ *+' $at_stder1 >$at_stderr 32340 at_failed=false 32341 echo stderr:; tee stderr <$at_stderr 32342 $at_diff $at_devnull $at_stdout || at_failed=: 32343 case $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=:;; 32349 esac 32350 if $at_failed; then 32351 32352 echo 1 > $at_status_file 32353 exit 1 32354 fi 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. 32362 sed '/^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 32375 mv at-stderr stderr 32376 # 2. Create the reference error message. 32377 cat >expout <<'_ATEOF' 32378 2.0: syntax error, unexpected '+' 32379 _ATEOF 32380 32381 # 3. If locations are not used, remove them. 32382 sed 's/^[-0-9.]*: //' expout >at-expout 32383 mv at-expout expout 32384 # 4. If error-verbose is not used, strip the`, unexpected....' part. 32385 sed 's/syntax error, .*$/syntax error/' expout >at-expout 32386 mv at-expout expout 32387 # 5. Check 32388 $at_traceoff 32389 echo "calc.at:590: cat stderr" 32390 echo calc.at:590 >$at_check_line_file 32391 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 32392 at_status=$? 32393 grep '^ *+' $at_stder1 >&2 32394 grep -v '^ *+' $at_stder1 >$at_stderr 32395 at_failed=false 32396 $at_diff $at_devnull $at_stderr || at_failed=: 32397 $at_diff expout $at_stdout || at_failed=: 32398 case $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=:;; 32404 esac 32405 if $at_failed; then 32406 32407 echo 1 > $at_status_file 32408 exit 1 32409 fi 32410 32411 $at_traceon 32412 32413 32414 # Exercise error messages with EOF: work on an empty file. 32415 $at_traceoff 32416 echo "calc.at:590: \$PREPARSER ./calc /dev/null" 32417 echo calc.at:590 >$at_check_line_file 32418 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 32419 at_status=$? 32420 grep '^ *+' $at_stder1 >&2 32421 grep -v '^ *+' $at_stder1 >$at_stderr 32422 at_failed=false 32423 echo stderr:; tee stderr <$at_stderr 32424 $at_diff $at_devnull $at_stdout || at_failed=: 32425 case $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=:;; 32431 esac 32432 if $at_failed; then 32433 32434 echo 1 > $at_status_file 32435 exit 1 32436 fi 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. 32444 sed '/^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 32457 mv at-stderr stderr 32458 # 2. Create the reference error message. 32459 cat >expout <<'_ATEOF' 32460 1.0: syntax error, unexpected end of input 32461 _ATEOF 32462 32463 # 3. If locations are not used, remove them. 32464 sed 's/^[-0-9.]*: //' expout >at-expout 32465 mv at-expout expout 32466 # 4. If error-verbose is not used, strip the`, unexpected....' part. 32467 sed 's/syntax error, .*$/syntax error/' expout >at-expout 32468 mv at-expout expout 32469 # 5. Check 32470 $at_traceoff 32471 echo "calc.at:590: cat stderr" 32472 echo calc.at:590 >$at_check_line_file 32473 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 32474 at_status=$? 32475 grep '^ *+' $at_stder1 >&2 32476 grep -v '^ *+' $at_stder1 >$at_stderr 32477 at_failed=false 32478 $at_diff $at_devnull $at_stderr || at_failed=: 32479 $at_diff expout $at_stdout || at_failed=: 32480 case $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=:;; 32486 esac 32487 if $at_failed; then 32488 32489 echo 1 > $at_status_file 32490 exit 1 32491 fi 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 # 32513 cat >input <<'_ATEOF' 32514 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 32515 _ATEOF 32516 32517 $at_traceoff 32518 echo "calc.at:590: \$PREPARSER ./calc input" 32519 echo calc.at:590 >$at_check_line_file 32520 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 32521 at_status=$? 32522 grep '^ *+' $at_stder1 >&2 32523 grep -v '^ *+' $at_stder1 >$at_stderr 32524 at_failed=false 32525 echo stderr:; tee stderr <$at_stderr 32526 $at_diff $at_devnull $at_stdout || at_failed=: 32527 case $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=:;; 32533 esac 32534 if $at_failed; then 32535 32536 echo 1 > $at_status_file 32537 exit 1 32538 fi 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. 32546 sed '/^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 32559 mv at-stderr stderr 32560 # 2. Create the reference error message. 32561 cat >expout <<'_ATEOF' 32562 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 32563 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 32564 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 32565 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 32566 calc: error: 4444 != 1 32567 _ATEOF 32568 32569 # 3. If locations are not used, remove them. 32570 sed 's/^[-0-9.]*: //' expout >at-expout 32571 mv at-expout expout 32572 # 4. If error-verbose is not used, strip the`, unexpected....' part. 32573 sed 's/syntax error, .*$/syntax error/' expout >at-expout 32574 mv at-expout expout 32575 # 5. Check 32576 $at_traceoff 32577 echo "calc.at:590: cat stderr" 32578 echo calc.at:590 >$at_check_line_file 32579 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 32580 at_status=$? 32581 grep '^ *+' $at_stder1 >&2 32582 grep -v '^ *+' $at_stder1 >$at_stderr 32583 at_failed=false 32584 $at_diff $at_devnull $at_stderr || at_failed=: 32585 $at_diff expout $at_stdout || at_failed=: 32586 case $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=:;; 32592 esac 32593 if $at_failed; then 32594 32595 echo 1 > $at_status_file 32596 exit 1 32597 fi 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. 32605 cat >input <<'_ATEOF' 32606 (!) + (0 0) = 1 32607 _ATEOF 32608 32609 $at_traceoff 32610 echo "calc.at:590: \$PREPARSER ./calc input" 32611 echo calc.at:590 >$at_check_line_file 32612 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 32613 at_status=$? 32614 grep '^ *+' $at_stder1 >&2 32615 grep -v '^ *+' $at_stder1 >$at_stderr 32616 at_failed=false 32617 echo stderr:; tee stderr <$at_stderr 32618 $at_diff $at_devnull $at_stdout || at_failed=: 32619 case $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=:;; 32625 esac 32626 if $at_failed; then 32627 32628 echo 1 > $at_status_file 32629 exit 1 32630 fi 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. 32638 sed '/^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 32651 mv at-stderr stderr 32652 # 2. Create the reference error message. 32653 cat >expout <<'_ATEOF' 32654 1.9: syntax error, unexpected number 32655 calc: error: 2222 != 1 32656 _ATEOF 32657 32658 # 3. If locations are not used, remove them. 32659 sed 's/^[-0-9.]*: //' expout >at-expout 32660 mv at-expout expout 32661 # 4. If error-verbose is not used, strip the`, unexpected....' part. 32662 sed 's/syntax error, .*$/syntax error/' expout >at-expout 32663 mv at-expout expout 32664 # 5. Check 32665 $at_traceoff 32666 echo "calc.at:590: cat stderr" 32667 echo calc.at:590 >$at_check_line_file 32668 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 32669 at_status=$? 32670 grep '^ *+' $at_stder1 >&2 32671 grep -v '^ *+' $at_stder1 >$at_stderr 32672 at_failed=false 32673 $at_diff $at_devnull $at_stderr || at_failed=: 32674 $at_diff expout $at_stdout || at_failed=: 32675 case $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=:;; 32681 esac 32682 if $at_failed; then 32683 32684 echo 1 > $at_status_file 32685 exit 1 32686 fi 32687 32688 $at_traceon 32689 32690 32691 cat >input <<'_ATEOF' 32692 (- *) + (0 0) = 1 32693 _ATEOF 32694 32695 $at_traceoff 32696 echo "calc.at:590: \$PREPARSER ./calc input" 32697 echo calc.at:590 >$at_check_line_file 32698 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 32699 at_status=$? 32700 grep '^ *+' $at_stder1 >&2 32701 grep -v '^ *+' $at_stder1 >$at_stderr 32702 at_failed=false 32703 echo stderr:; tee stderr <$at_stderr 32704 $at_diff $at_devnull $at_stdout || at_failed=: 32705 case $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=:;; 32711 esac 32712 if $at_failed; then 32713 32714 echo 1 > $at_status_file 32715 exit 1 32716 fi 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. 32724 sed '/^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 32737 mv at-stderr stderr 32738 # 2. Create the reference error message. 32739 cat >expout <<'_ATEOF' 32740 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 32741 1.11: syntax error, unexpected number 32742 calc: error: 2222 != 1 32743 _ATEOF 32744 32745 # 3. If locations are not used, remove them. 32746 sed 's/^[-0-9.]*: //' expout >at-expout 32747 mv at-expout expout 32748 # 4. If error-verbose is not used, strip the`, unexpected....' part. 32749 sed 's/syntax error, .*$/syntax error/' expout >at-expout 32750 mv at-expout expout 32751 # 5. Check 32752 $at_traceoff 32753 echo "calc.at:590: cat stderr" 32754 echo calc.at:590 >$at_check_line_file 32755 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 32756 at_status=$? 32757 grep '^ *+' $at_stder1 >&2 32758 grep -v '^ *+' $at_stder1 >$at_stderr 32759 at_failed=false 32760 $at_diff $at_devnull $at_stderr || at_failed=: 32761 $at_diff expout $at_stdout || at_failed=: 32762 case $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=:;; 32768 esac 32769 if $at_failed; then 32770 32771 echo 1 > $at_status_file 32772 exit 1 32773 fi 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 32850 cat >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. */ 32879 typedef int semantic_value; 32880 32881 static semantic_value global_result = 0; 32882 static int global_count = 0; 32883 %} 32884 32885 /* Exercise %union. */ 32886 %union 32887 { 32888 semantic_value ival; 32889 }; 32890 32891 %{ 32892 static int power (int base, int exponent); 32893 /* yyerror receives the location if: 32894 - %location & %pure & %glr 32895 - %location & %pure & %yacc & %parse-param. */ 32896 static void yyerror ( 32897 32898 const char *s 32899 ); 32900 static int yylex (void); 32901 static int get_char (void); 32902 static 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 %% 32920 input: 32921 line 32922 | input line { } 32923 ; 32924 32925 line: 32926 '\n' 32927 | exp '\n' { USE ($1); } 32928 ; 32929 32930 exp: 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. */ 32951 static FILE *input; 32952 32953 static void 32954 yyerror ( 32955 32956 const char *s) 32957 { 32958 32959 32960 fprintf (stderr, "%s\n", s); 32961 } 32962 32963 32964 32965 static int 32966 get_char (void) 32967 { 32968 int res = getc (input); 32969 ; 32970 32971 return res; 32972 } 32973 32974 32975 static void 32976 unget_char ( int c) 32977 { 32978 ; 32979 32980 ungetc (c, input); 32981 } 32982 32983 static int 32984 read_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 33016 static int 33017 yylex (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 33052 static int 33053 power (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 33064 int 33065 main (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 33102 echo "calc.at:591: bison -o calc.c calc.y" 33103 echo calc.at:591 >$at_check_line_file 33104 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 33105 at_status=$? 33106 grep '^ *+' $at_stder1 >&2 33107 grep -v '^ *+' $at_stder1 >$at_stderr 33108 at_failed=false 33109 $at_diff $at_devnull $at_stderr || at_failed=: 33110 $at_diff $at_devnull $at_stdout || at_failed=: 33111 case $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=:;; 33117 esac 33118 if $at_failed; then 33119 33120 echo 1 > $at_status_file 33121 exit 1 33122 fi 33123 33124 $at_traceon 33125 33126 $at_traceoff 33127 echo "calc.at:591: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 33128 echo calc.at:591 >$at_check_line_file 33129 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 33130 at_status=$? 33131 grep '^ *+' $at_stder1 >&2 33132 grep -v '^ *+' $at_stder1 >$at_stderr 33133 at_failed=false 33134 echo stderr:; cat $at_stderr 33135 echo stdout:; cat $at_stdout 33136 case $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=:;; 33142 esac 33143 if $at_failed; then 33144 33145 echo 1 > $at_status_file 33146 exit 1 33147 fi 33148 33149 $at_traceon 33150 33151 33152 # Test the priorities. 33153 cat >input <<'_ATEOF' 33154 1 + 2 * 3 = 7 33155 1 + 2 * -3 = -5 33156 33157 -1^2 = -1 33158 (-1)^2 = 1 33159 33160 ---1 = -1 33161 33162 1 - 2 - 3 = -4 33163 1 - (2 - 3) = 2 33164 33165 2^2^3 = 256 33166 (2^2)^3 = 64 33167 _ATEOF 33168 33169 $at_traceoff 33170 echo "calc.at:591: \$PREPARSER ./calc input" 33171 echo calc.at:591 >$at_check_line_file 33172 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 33173 at_status=$? 33174 grep '^ *+' $at_stder1 >&2 33175 grep -v '^ *+' $at_stder1 >$at_stderr 33176 at_failed=false 33177 echo stderr:; tee stderr <$at_stderr 33178 $at_diff $at_devnull $at_stdout || at_failed=: 33179 case $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=:;; 33185 esac 33186 if $at_failed; then 33187 33188 echo 1 > $at_status_file 33189 exit 1 33190 fi 33191 33192 $at_traceon 33193 33194 33195 33196 # Some syntax errors. 33197 cat >input <<'_ATEOF' 33198 0 0 33199 _ATEOF 33200 33201 $at_traceoff 33202 echo "calc.at:591: \$PREPARSER ./calc input" 33203 echo calc.at:591 >$at_check_line_file 33204 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 33205 at_status=$? 33206 grep '^ *+' $at_stder1 >&2 33207 grep -v '^ *+' $at_stder1 >$at_stderr 33208 at_failed=false 33209 echo stderr:; tee stderr <$at_stderr 33210 $at_diff $at_devnull $at_stdout || at_failed=: 33211 case $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=:;; 33217 esac 33218 if $at_failed; then 33219 33220 echo 1 > $at_status_file 33221 exit 1 33222 fi 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. 33230 sed '/^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 33243 mv at-stderr stderr 33244 # 2. Create the reference error message. 33245 cat >expout <<'_ATEOF' 33246 1.2: syntax error, unexpected number 33247 _ATEOF 33248 33249 # 3. If locations are not used, remove them. 33250 sed 's/^[-0-9.]*: //' expout >at-expout 33251 mv at-expout expout 33252 # 4. If error-verbose is not used, strip the`, unexpected....' part. 33253 sed 's/syntax error, .*$/syntax error/' expout >at-expout 33254 mv at-expout expout 33255 # 5. Check 33256 $at_traceoff 33257 echo "calc.at:591: cat stderr" 33258 echo calc.at:591 >$at_check_line_file 33259 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 33260 at_status=$? 33261 grep '^ *+' $at_stder1 >&2 33262 grep -v '^ *+' $at_stder1 >$at_stderr 33263 at_failed=false 33264 $at_diff $at_devnull $at_stderr || at_failed=: 33265 $at_diff expout $at_stdout || at_failed=: 33266 case $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=:;; 33272 esac 33273 if $at_failed; then 33274 33275 echo 1 > $at_status_file 33276 exit 1 33277 fi 33278 33279 $at_traceon 33280 33281 33282 cat >input <<'_ATEOF' 33283 1//2 33284 _ATEOF 33285 33286 $at_traceoff 33287 echo "calc.at:591: \$PREPARSER ./calc input" 33288 echo calc.at:591 >$at_check_line_file 33289 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 33290 at_status=$? 33291 grep '^ *+' $at_stder1 >&2 33292 grep -v '^ *+' $at_stder1 >$at_stderr 33293 at_failed=false 33294 echo stderr:; tee stderr <$at_stderr 33295 $at_diff $at_devnull $at_stdout || at_failed=: 33296 case $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=:;; 33302 esac 33303 if $at_failed; then 33304 33305 echo 1 > $at_status_file 33306 exit 1 33307 fi 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. 33315 sed '/^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 33328 mv at-stderr stderr 33329 # 2. Create the reference error message. 33330 cat >expout <<'_ATEOF' 33331 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 33332 _ATEOF 33333 33334 # 3. If locations are not used, remove them. 33335 sed 's/^[-0-9.]*: //' expout >at-expout 33336 mv at-expout expout 33337 # 4. If error-verbose is not used, strip the`, unexpected....' part. 33338 sed 's/syntax error, .*$/syntax error/' expout >at-expout 33339 mv at-expout expout 33340 # 5. Check 33341 $at_traceoff 33342 echo "calc.at:591: cat stderr" 33343 echo calc.at:591 >$at_check_line_file 33344 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 33345 at_status=$? 33346 grep '^ *+' $at_stder1 >&2 33347 grep -v '^ *+' $at_stder1 >$at_stderr 33348 at_failed=false 33349 $at_diff $at_devnull $at_stderr || at_failed=: 33350 $at_diff expout $at_stdout || at_failed=: 33351 case $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=:;; 33357 esac 33358 if $at_failed; then 33359 33360 echo 1 > $at_status_file 33361 exit 1 33362 fi 33363 33364 $at_traceon 33365 33366 33367 cat >input <<'_ATEOF' 33368 error 33369 _ATEOF 33370 33371 $at_traceoff 33372 echo "calc.at:591: \$PREPARSER ./calc input" 33373 echo calc.at:591 >$at_check_line_file 33374 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 33375 at_status=$? 33376 grep '^ *+' $at_stder1 >&2 33377 grep -v '^ *+' $at_stder1 >$at_stderr 33378 at_failed=false 33379 echo stderr:; tee stderr <$at_stderr 33380 $at_diff $at_devnull $at_stdout || at_failed=: 33381 case $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=:;; 33387 esac 33388 if $at_failed; then 33389 33390 echo 1 > $at_status_file 33391 exit 1 33392 fi 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. 33400 sed '/^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 33413 mv at-stderr stderr 33414 # 2. Create the reference error message. 33415 cat >expout <<'_ATEOF' 33416 1.0: syntax error, unexpected $undefined 33417 _ATEOF 33418 33419 # 3. If locations are not used, remove them. 33420 sed 's/^[-0-9.]*: //' expout >at-expout 33421 mv at-expout expout 33422 # 4. If error-verbose is not used, strip the`, unexpected....' part. 33423 sed 's/syntax error, .*$/syntax error/' expout >at-expout 33424 mv at-expout expout 33425 # 5. Check 33426 $at_traceoff 33427 echo "calc.at:591: cat stderr" 33428 echo calc.at:591 >$at_check_line_file 33429 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 33430 at_status=$? 33431 grep '^ *+' $at_stder1 >&2 33432 grep -v '^ *+' $at_stder1 >$at_stderr 33433 at_failed=false 33434 $at_diff $at_devnull $at_stderr || at_failed=: 33435 $at_diff expout $at_stdout || at_failed=: 33436 case $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=:;; 33442 esac 33443 if $at_failed; then 33444 33445 echo 1 > $at_status_file 33446 exit 1 33447 fi 33448 33449 $at_traceon 33450 33451 33452 cat >input <<'_ATEOF' 33453 1 = 2 = 3 33454 _ATEOF 33455 33456 $at_traceoff 33457 echo "calc.at:591: \$PREPARSER ./calc input" 33458 echo calc.at:591 >$at_check_line_file 33459 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 33460 at_status=$? 33461 grep '^ *+' $at_stder1 >&2 33462 grep -v '^ *+' $at_stder1 >$at_stderr 33463 at_failed=false 33464 echo stderr:; tee stderr <$at_stderr 33465 $at_diff $at_devnull $at_stdout || at_failed=: 33466 case $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=:;; 33472 esac 33473 if $at_failed; then 33474 33475 echo 1 > $at_status_file 33476 exit 1 33477 fi 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. 33485 sed '/^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 33498 mv at-stderr stderr 33499 # 2. Create the reference error message. 33500 cat >expout <<'_ATEOF' 33501 1.6: syntax error, unexpected '=' 33502 _ATEOF 33503 33504 # 3. If locations are not used, remove them. 33505 sed 's/^[-0-9.]*: //' expout >at-expout 33506 mv at-expout expout 33507 # 4. If error-verbose is not used, strip the`, unexpected....' part. 33508 sed 's/syntax error, .*$/syntax error/' expout >at-expout 33509 mv at-expout expout 33510 # 5. Check 33511 $at_traceoff 33512 echo "calc.at:591: cat stderr" 33513 echo calc.at:591 >$at_check_line_file 33514 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 33515 at_status=$? 33516 grep '^ *+' $at_stder1 >&2 33517 grep -v '^ *+' $at_stder1 >$at_stderr 33518 at_failed=false 33519 $at_diff $at_devnull $at_stderr || at_failed=: 33520 $at_diff expout $at_stdout || at_failed=: 33521 case $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=:;; 33527 esac 33528 if $at_failed; then 33529 33530 echo 1 > $at_status_file 33531 exit 1 33532 fi 33533 33534 $at_traceon 33535 33536 33537 cat >input <<'_ATEOF' 33538 33539 +1 33540 _ATEOF 33541 33542 $at_traceoff 33543 echo "calc.at:591: \$PREPARSER ./calc input" 33544 echo calc.at:591 >$at_check_line_file 33545 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 33546 at_status=$? 33547 grep '^ *+' $at_stder1 >&2 33548 grep -v '^ *+' $at_stder1 >$at_stderr 33549 at_failed=false 33550 echo stderr:; tee stderr <$at_stderr 33551 $at_diff $at_devnull $at_stdout || at_failed=: 33552 case $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=:;; 33558 esac 33559 if $at_failed; then 33560 33561 echo 1 > $at_status_file 33562 exit 1 33563 fi 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. 33571 sed '/^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 33584 mv at-stderr stderr 33585 # 2. Create the reference error message. 33586 cat >expout <<'_ATEOF' 33587 2.0: syntax error, unexpected '+' 33588 _ATEOF 33589 33590 # 3. If locations are not used, remove them. 33591 sed 's/^[-0-9.]*: //' expout >at-expout 33592 mv at-expout expout 33593 # 4. If error-verbose is not used, strip the`, unexpected....' part. 33594 sed 's/syntax error, .*$/syntax error/' expout >at-expout 33595 mv at-expout expout 33596 # 5. Check 33597 $at_traceoff 33598 echo "calc.at:591: cat stderr" 33599 echo calc.at:591 >$at_check_line_file 33600 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 33601 at_status=$? 33602 grep '^ *+' $at_stder1 >&2 33603 grep -v '^ *+' $at_stder1 >$at_stderr 33604 at_failed=false 33605 $at_diff $at_devnull $at_stderr || at_failed=: 33606 $at_diff expout $at_stdout || at_failed=: 33607 case $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=:;; 33613 esac 33614 if $at_failed; then 33615 33616 echo 1 > $at_status_file 33617 exit 1 33618 fi 33619 33620 $at_traceon 33621 33622 33623 # Exercise error messages with EOF: work on an empty file. 33624 $at_traceoff 33625 echo "calc.at:591: \$PREPARSER ./calc /dev/null" 33626 echo calc.at:591 >$at_check_line_file 33627 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 33628 at_status=$? 33629 grep '^ *+' $at_stder1 >&2 33630 grep -v '^ *+' $at_stder1 >$at_stderr 33631 at_failed=false 33632 echo stderr:; tee stderr <$at_stderr 33633 $at_diff $at_devnull $at_stdout || at_failed=: 33634 case $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=:;; 33640 esac 33641 if $at_failed; then 33642 33643 echo 1 > $at_status_file 33644 exit 1 33645 fi 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. 33653 sed '/^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 33666 mv at-stderr stderr 33667 # 2. Create the reference error message. 33668 cat >expout <<'_ATEOF' 33669 1.0: syntax error, unexpected end of input 33670 _ATEOF 33671 33672 # 3. If locations are not used, remove them. 33673 sed 's/^[-0-9.]*: //' expout >at-expout 33674 mv at-expout expout 33675 # 4. If error-verbose is not used, strip the`, unexpected....' part. 33676 sed 's/syntax error, .*$/syntax error/' expout >at-expout 33677 mv at-expout expout 33678 # 5. Check 33679 $at_traceoff 33680 echo "calc.at:591: cat stderr" 33681 echo calc.at:591 >$at_check_line_file 33682 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 33683 at_status=$? 33684 grep '^ *+' $at_stder1 >&2 33685 grep -v '^ *+' $at_stder1 >$at_stderr 33686 at_failed=false 33687 $at_diff $at_devnull $at_stderr || at_failed=: 33688 $at_diff expout $at_stdout || at_failed=: 33689 case $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=:;; 33695 esac 33696 if $at_failed; then 33697 33698 echo 1 > $at_status_file 33699 exit 1 33700 fi 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 # 33722 cat >input <<'_ATEOF' 33723 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 33724 _ATEOF 33725 33726 $at_traceoff 33727 echo "calc.at:591: \$PREPARSER ./calc input" 33728 echo calc.at:591 >$at_check_line_file 33729 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 33730 at_status=$? 33731 grep '^ *+' $at_stder1 >&2 33732 grep -v '^ *+' $at_stder1 >$at_stderr 33733 at_failed=false 33734 echo stderr:; tee stderr <$at_stderr 33735 $at_diff $at_devnull $at_stdout || at_failed=: 33736 case $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=:;; 33742 esac 33743 if $at_failed; then 33744 33745 echo 1 > $at_status_file 33746 exit 1 33747 fi 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. 33755 sed '/^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 33768 mv at-stderr stderr 33769 # 2. Create the reference error message. 33770 cat >expout <<'_ATEOF' 33771 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 33772 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 33773 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 33774 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 33775 calc: error: 4444 != 1 33776 _ATEOF 33777 33778 # 3. If locations are not used, remove them. 33779 sed 's/^[-0-9.]*: //' expout >at-expout 33780 mv at-expout expout 33781 # 4. If error-verbose is not used, strip the`, unexpected....' part. 33782 sed 's/syntax error, .*$/syntax error/' expout >at-expout 33783 mv at-expout expout 33784 # 5. Check 33785 $at_traceoff 33786 echo "calc.at:591: cat stderr" 33787 echo calc.at:591 >$at_check_line_file 33788 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 33789 at_status=$? 33790 grep '^ *+' $at_stder1 >&2 33791 grep -v '^ *+' $at_stder1 >$at_stderr 33792 at_failed=false 33793 $at_diff $at_devnull $at_stderr || at_failed=: 33794 $at_diff expout $at_stdout || at_failed=: 33795 case $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=:;; 33801 esac 33802 if $at_failed; then 33803 33804 echo 1 > $at_status_file 33805 exit 1 33806 fi 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. 33814 cat >input <<'_ATEOF' 33815 (!) + (0 0) = 1 33816 _ATEOF 33817 33818 $at_traceoff 33819 echo "calc.at:591: \$PREPARSER ./calc input" 33820 echo calc.at:591 >$at_check_line_file 33821 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 33822 at_status=$? 33823 grep '^ *+' $at_stder1 >&2 33824 grep -v '^ *+' $at_stder1 >$at_stderr 33825 at_failed=false 33826 echo stderr:; tee stderr <$at_stderr 33827 $at_diff $at_devnull $at_stdout || at_failed=: 33828 case $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=:;; 33834 esac 33835 if $at_failed; then 33836 33837 echo 1 > $at_status_file 33838 exit 1 33839 fi 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. 33847 sed '/^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 33860 mv at-stderr stderr 33861 # 2. Create the reference error message. 33862 cat >expout <<'_ATEOF' 33863 1.9: syntax error, unexpected number 33864 calc: error: 2222 != 1 33865 _ATEOF 33866 33867 # 3. If locations are not used, remove them. 33868 sed 's/^[-0-9.]*: //' expout >at-expout 33869 mv at-expout expout 33870 # 4. If error-verbose is not used, strip the`, unexpected....' part. 33871 sed 's/syntax error, .*$/syntax error/' expout >at-expout 33872 mv at-expout expout 33873 # 5. Check 33874 $at_traceoff 33875 echo "calc.at:591: cat stderr" 33876 echo calc.at:591 >$at_check_line_file 33877 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 33878 at_status=$? 33879 grep '^ *+' $at_stder1 >&2 33880 grep -v '^ *+' $at_stder1 >$at_stderr 33881 at_failed=false 33882 $at_diff $at_devnull $at_stderr || at_failed=: 33883 $at_diff expout $at_stdout || at_failed=: 33884 case $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=:;; 33890 esac 33891 if $at_failed; then 33892 33893 echo 1 > $at_status_file 33894 exit 1 33895 fi 33896 33897 $at_traceon 33898 33899 33900 cat >input <<'_ATEOF' 33901 (- *) + (0 0) = 1 33902 _ATEOF 33903 33904 $at_traceoff 33905 echo "calc.at:591: \$PREPARSER ./calc input" 33906 echo calc.at:591 >$at_check_line_file 33907 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 33908 at_status=$? 33909 grep '^ *+' $at_stder1 >&2 33910 grep -v '^ *+' $at_stder1 >$at_stderr 33911 at_failed=false 33912 echo stderr:; tee stderr <$at_stderr 33913 $at_diff $at_devnull $at_stdout || at_failed=: 33914 case $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=:;; 33920 esac 33921 if $at_failed; then 33922 33923 echo 1 > $at_status_file 33924 exit 1 33925 fi 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. 33933 sed '/^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 33946 mv at-stderr stderr 33947 # 2. Create the reference error message. 33948 cat >expout <<'_ATEOF' 33949 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 33950 1.11: syntax error, unexpected number 33951 calc: error: 2222 != 1 33952 _ATEOF 33953 33954 # 3. If locations are not used, remove them. 33955 sed 's/^[-0-9.]*: //' expout >at-expout 33956 mv at-expout expout 33957 # 4. If error-verbose is not used, strip the`, unexpected....' part. 33958 sed 's/syntax error, .*$/syntax error/' expout >at-expout 33959 mv at-expout expout 33960 # 5. Check 33961 $at_traceoff 33962 echo "calc.at:591: cat stderr" 33963 echo calc.at:591 >$at_check_line_file 33964 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 33965 at_status=$? 33966 grep '^ *+' $at_stder1 >&2 33967 grep -v '^ *+' $at_stder1 >$at_stderr 33968 at_failed=false 33969 $at_diff $at_devnull $at_stderr || at_failed=: 33970 $at_diff expout $at_stdout || at_failed=: 33971 case $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=:;; 33977 esac 33978 if $at_failed; then 33979 33980 echo 1 > $at_status_file 33981 exit 1 33982 fi 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 34059 cat >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. */ 34088 typedef int semantic_value; 34089 34090 static semantic_value global_result = 0; 34091 static int global_count = 0; 34092 %} 34093 34094 /* Exercise %union. */ 34095 %union 34096 { 34097 semantic_value ival; 34098 }; 34099 34100 %{ 34101 static int power (int base, int exponent); 34102 /* yyerror receives the location if: 34103 - %location & %pure & %glr 34104 - %location & %pure & %yacc & %parse-param. */ 34105 static void yyerror ( 34106 34107 const char *s 34108 ); 34109 static int yylex (void); 34110 static int get_char (void); 34111 static 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 %% 34129 input: 34130 line 34131 | input line { } 34132 ; 34133 34134 line: 34135 '\n' 34136 | exp '\n' { USE ($1); } 34137 ; 34138 34139 exp: 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. */ 34160 static FILE *input; 34161 34162 static void 34163 yyerror ( 34164 34165 const char *s) 34166 { 34167 34168 34169 fprintf (stderr, "%s\n", s); 34170 } 34171 34172 34173 34174 static int 34175 get_char (void) 34176 { 34177 int res = getc (input); 34178 ; 34179 34180 return res; 34181 } 34182 34183 34184 static void 34185 unget_char ( int c) 34186 { 34187 ; 34188 34189 ungetc (c, input); 34190 } 34191 34192 static int 34193 read_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 34225 static int 34226 yylex (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 34261 static int 34262 power (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 34273 int 34274 main (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 34311 echo "calc.at:592: bison -o calc.c calc.y" 34312 echo calc.at:592 >$at_check_line_file 34313 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 34314 at_status=$? 34315 grep '^ *+' $at_stder1 >&2 34316 grep -v '^ *+' $at_stder1 >$at_stderr 34317 at_failed=false 34318 $at_diff $at_devnull $at_stderr || at_failed=: 34319 $at_diff $at_devnull $at_stdout || at_failed=: 34320 case $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=:;; 34326 esac 34327 if $at_failed; then 34328 34329 echo 1 > $at_status_file 34330 exit 1 34331 fi 34332 34333 $at_traceon 34334 34335 $at_traceoff 34336 echo "calc.at:592: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 34337 echo calc.at:592 >$at_check_line_file 34338 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 34339 at_status=$? 34340 grep '^ *+' $at_stder1 >&2 34341 grep -v '^ *+' $at_stder1 >$at_stderr 34342 at_failed=false 34343 echo stderr:; cat $at_stderr 34344 echo stdout:; cat $at_stdout 34345 case $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=:;; 34351 esac 34352 if $at_failed; then 34353 34354 echo 1 > $at_status_file 34355 exit 1 34356 fi 34357 34358 $at_traceon 34359 34360 34361 # Test the priorities. 34362 cat >input <<'_ATEOF' 34363 1 + 2 * 3 = 7 34364 1 + 2 * -3 = -5 34365 34366 -1^2 = -1 34367 (-1)^2 = 1 34368 34369 ---1 = -1 34370 34371 1 - 2 - 3 = -4 34372 1 - (2 - 3) = 2 34373 34374 2^2^3 = 256 34375 (2^2)^3 = 64 34376 _ATEOF 34377 34378 $at_traceoff 34379 echo "calc.at:592: \$PREPARSER ./calc input" 34380 echo calc.at:592 >$at_check_line_file 34381 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 34382 at_status=$? 34383 grep '^ *+' $at_stder1 >&2 34384 grep -v '^ *+' $at_stder1 >$at_stderr 34385 at_failed=false 34386 echo stderr:; tee stderr <$at_stderr 34387 $at_diff $at_devnull $at_stdout || at_failed=: 34388 case $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=:;; 34394 esac 34395 if $at_failed; then 34396 34397 echo 1 > $at_status_file 34398 exit 1 34399 fi 34400 34401 $at_traceon 34402 34403 34404 34405 # Some syntax errors. 34406 cat >input <<'_ATEOF' 34407 0 0 34408 _ATEOF 34409 34410 $at_traceoff 34411 echo "calc.at:592: \$PREPARSER ./calc input" 34412 echo calc.at:592 >$at_check_line_file 34413 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 34414 at_status=$? 34415 grep '^ *+' $at_stder1 >&2 34416 grep -v '^ *+' $at_stder1 >$at_stderr 34417 at_failed=false 34418 echo stderr:; tee stderr <$at_stderr 34419 $at_diff $at_devnull $at_stdout || at_failed=: 34420 case $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=:;; 34426 esac 34427 if $at_failed; then 34428 34429 echo 1 > $at_status_file 34430 exit 1 34431 fi 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. 34439 sed '/^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 34452 mv at-stderr stderr 34453 # 2. Create the reference error message. 34454 cat >expout <<'_ATEOF' 34455 1.2: syntax error, unexpected number 34456 _ATEOF 34457 34458 # 3. If locations are not used, remove them. 34459 sed 's/^[-0-9.]*: //' expout >at-expout 34460 mv at-expout expout 34461 # 4. If error-verbose is not used, strip the`, unexpected....' part. 34462 sed 's/syntax error, .*$/syntax error/' expout >at-expout 34463 mv at-expout expout 34464 # 5. Check 34465 $at_traceoff 34466 echo "calc.at:592: cat stderr" 34467 echo calc.at:592 >$at_check_line_file 34468 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 34469 at_status=$? 34470 grep '^ *+' $at_stder1 >&2 34471 grep -v '^ *+' $at_stder1 >$at_stderr 34472 at_failed=false 34473 $at_diff $at_devnull $at_stderr || at_failed=: 34474 $at_diff expout $at_stdout || at_failed=: 34475 case $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=:;; 34481 esac 34482 if $at_failed; then 34483 34484 echo 1 > $at_status_file 34485 exit 1 34486 fi 34487 34488 $at_traceon 34489 34490 34491 cat >input <<'_ATEOF' 34492 1//2 34493 _ATEOF 34494 34495 $at_traceoff 34496 echo "calc.at:592: \$PREPARSER ./calc input" 34497 echo calc.at:592 >$at_check_line_file 34498 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 34499 at_status=$? 34500 grep '^ *+' $at_stder1 >&2 34501 grep -v '^ *+' $at_stder1 >$at_stderr 34502 at_failed=false 34503 echo stderr:; tee stderr <$at_stderr 34504 $at_diff $at_devnull $at_stdout || at_failed=: 34505 case $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=:;; 34511 esac 34512 if $at_failed; then 34513 34514 echo 1 > $at_status_file 34515 exit 1 34516 fi 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. 34524 sed '/^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 34537 mv at-stderr stderr 34538 # 2. Create the reference error message. 34539 cat >expout <<'_ATEOF' 34540 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 34541 _ATEOF 34542 34543 # 3. If locations are not used, remove them. 34544 sed 's/^[-0-9.]*: //' expout >at-expout 34545 mv at-expout expout 34546 # 4. If error-verbose is not used, strip the`, unexpected....' part. 34547 sed 's/syntax error, .*$/syntax error/' expout >at-expout 34548 mv at-expout expout 34549 # 5. Check 34550 $at_traceoff 34551 echo "calc.at:592: cat stderr" 34552 echo calc.at:592 >$at_check_line_file 34553 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 34554 at_status=$? 34555 grep '^ *+' $at_stder1 >&2 34556 grep -v '^ *+' $at_stder1 >$at_stderr 34557 at_failed=false 34558 $at_diff $at_devnull $at_stderr || at_failed=: 34559 $at_diff expout $at_stdout || at_failed=: 34560 case $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=:;; 34566 esac 34567 if $at_failed; then 34568 34569 echo 1 > $at_status_file 34570 exit 1 34571 fi 34572 34573 $at_traceon 34574 34575 34576 cat >input <<'_ATEOF' 34577 error 34578 _ATEOF 34579 34580 $at_traceoff 34581 echo "calc.at:592: \$PREPARSER ./calc input" 34582 echo calc.at:592 >$at_check_line_file 34583 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 34584 at_status=$? 34585 grep '^ *+' $at_stder1 >&2 34586 grep -v '^ *+' $at_stder1 >$at_stderr 34587 at_failed=false 34588 echo stderr:; tee stderr <$at_stderr 34589 $at_diff $at_devnull $at_stdout || at_failed=: 34590 case $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=:;; 34596 esac 34597 if $at_failed; then 34598 34599 echo 1 > $at_status_file 34600 exit 1 34601 fi 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. 34609 sed '/^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 34622 mv at-stderr stderr 34623 # 2. Create the reference error message. 34624 cat >expout <<'_ATEOF' 34625 1.0: syntax error, unexpected $undefined 34626 _ATEOF 34627 34628 # 3. If locations are not used, remove them. 34629 sed 's/^[-0-9.]*: //' expout >at-expout 34630 mv at-expout expout 34631 # 4. If error-verbose is not used, strip the`, unexpected....' part. 34632 sed 's/syntax error, .*$/syntax error/' expout >at-expout 34633 mv at-expout expout 34634 # 5. Check 34635 $at_traceoff 34636 echo "calc.at:592: cat stderr" 34637 echo calc.at:592 >$at_check_line_file 34638 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 34639 at_status=$? 34640 grep '^ *+' $at_stder1 >&2 34641 grep -v '^ *+' $at_stder1 >$at_stderr 34642 at_failed=false 34643 $at_diff $at_devnull $at_stderr || at_failed=: 34644 $at_diff expout $at_stdout || at_failed=: 34645 case $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=:;; 34651 esac 34652 if $at_failed; then 34653 34654 echo 1 > $at_status_file 34655 exit 1 34656 fi 34657 34658 $at_traceon 34659 34660 34661 cat >input <<'_ATEOF' 34662 1 = 2 = 3 34663 _ATEOF 34664 34665 $at_traceoff 34666 echo "calc.at:592: \$PREPARSER ./calc input" 34667 echo calc.at:592 >$at_check_line_file 34668 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 34669 at_status=$? 34670 grep '^ *+' $at_stder1 >&2 34671 grep -v '^ *+' $at_stder1 >$at_stderr 34672 at_failed=false 34673 echo stderr:; tee stderr <$at_stderr 34674 $at_diff $at_devnull $at_stdout || at_failed=: 34675 case $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=:;; 34681 esac 34682 if $at_failed; then 34683 34684 echo 1 > $at_status_file 34685 exit 1 34686 fi 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. 34694 sed '/^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 34707 mv at-stderr stderr 34708 # 2. Create the reference error message. 34709 cat >expout <<'_ATEOF' 34710 1.6: syntax error, unexpected '=' 34711 _ATEOF 34712 34713 # 3. If locations are not used, remove them. 34714 sed 's/^[-0-9.]*: //' expout >at-expout 34715 mv at-expout expout 34716 # 4. If error-verbose is not used, strip the`, unexpected....' part. 34717 sed 's/syntax error, .*$/syntax error/' expout >at-expout 34718 mv at-expout expout 34719 # 5. Check 34720 $at_traceoff 34721 echo "calc.at:592: cat stderr" 34722 echo calc.at:592 >$at_check_line_file 34723 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 34724 at_status=$? 34725 grep '^ *+' $at_stder1 >&2 34726 grep -v '^ *+' $at_stder1 >$at_stderr 34727 at_failed=false 34728 $at_diff $at_devnull $at_stderr || at_failed=: 34729 $at_diff expout $at_stdout || at_failed=: 34730 case $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=:;; 34736 esac 34737 if $at_failed; then 34738 34739 echo 1 > $at_status_file 34740 exit 1 34741 fi 34742 34743 $at_traceon 34744 34745 34746 cat >input <<'_ATEOF' 34747 34748 +1 34749 _ATEOF 34750 34751 $at_traceoff 34752 echo "calc.at:592: \$PREPARSER ./calc input" 34753 echo calc.at:592 >$at_check_line_file 34754 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 34755 at_status=$? 34756 grep '^ *+' $at_stder1 >&2 34757 grep -v '^ *+' $at_stder1 >$at_stderr 34758 at_failed=false 34759 echo stderr:; tee stderr <$at_stderr 34760 $at_diff $at_devnull $at_stdout || at_failed=: 34761 case $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=:;; 34767 esac 34768 if $at_failed; then 34769 34770 echo 1 > $at_status_file 34771 exit 1 34772 fi 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. 34780 sed '/^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 34793 mv at-stderr stderr 34794 # 2. Create the reference error message. 34795 cat >expout <<'_ATEOF' 34796 2.0: syntax error, unexpected '+' 34797 _ATEOF 34798 34799 # 3. If locations are not used, remove them. 34800 sed 's/^[-0-9.]*: //' expout >at-expout 34801 mv at-expout expout 34802 # 4. If error-verbose is not used, strip the`, unexpected....' part. 34803 sed 's/syntax error, .*$/syntax error/' expout >at-expout 34804 mv at-expout expout 34805 # 5. Check 34806 $at_traceoff 34807 echo "calc.at:592: cat stderr" 34808 echo calc.at:592 >$at_check_line_file 34809 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 34810 at_status=$? 34811 grep '^ *+' $at_stder1 >&2 34812 grep -v '^ *+' $at_stder1 >$at_stderr 34813 at_failed=false 34814 $at_diff $at_devnull $at_stderr || at_failed=: 34815 $at_diff expout $at_stdout || at_failed=: 34816 case $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=:;; 34822 esac 34823 if $at_failed; then 34824 34825 echo 1 > $at_status_file 34826 exit 1 34827 fi 34828 34829 $at_traceon 34830 34831 34832 # Exercise error messages with EOF: work on an empty file. 34833 $at_traceoff 34834 echo "calc.at:592: \$PREPARSER ./calc /dev/null" 34835 echo calc.at:592 >$at_check_line_file 34836 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 34837 at_status=$? 34838 grep '^ *+' $at_stder1 >&2 34839 grep -v '^ *+' $at_stder1 >$at_stderr 34840 at_failed=false 34841 echo stderr:; tee stderr <$at_stderr 34842 $at_diff $at_devnull $at_stdout || at_failed=: 34843 case $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=:;; 34849 esac 34850 if $at_failed; then 34851 34852 echo 1 > $at_status_file 34853 exit 1 34854 fi 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. 34862 sed '/^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 34875 mv at-stderr stderr 34876 # 2. Create the reference error message. 34877 cat >expout <<'_ATEOF' 34878 1.0: syntax error, unexpected end of input 34879 _ATEOF 34880 34881 # 3. If locations are not used, remove them. 34882 sed 's/^[-0-9.]*: //' expout >at-expout 34883 mv at-expout expout 34884 # 4. If error-verbose is not used, strip the`, unexpected....' part. 34885 sed 's/syntax error, .*$/syntax error/' expout >at-expout 34886 mv at-expout expout 34887 # 5. Check 34888 $at_traceoff 34889 echo "calc.at:592: cat stderr" 34890 echo calc.at:592 >$at_check_line_file 34891 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 34892 at_status=$? 34893 grep '^ *+' $at_stder1 >&2 34894 grep -v '^ *+' $at_stder1 >$at_stderr 34895 at_failed=false 34896 $at_diff $at_devnull $at_stderr || at_failed=: 34897 $at_diff expout $at_stdout || at_failed=: 34898 case $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=:;; 34904 esac 34905 if $at_failed; then 34906 34907 echo 1 > $at_status_file 34908 exit 1 34909 fi 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 # 34931 cat >input <<'_ATEOF' 34932 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 34933 _ATEOF 34934 34935 $at_traceoff 34936 echo "calc.at:592: \$PREPARSER ./calc input" 34937 echo calc.at:592 >$at_check_line_file 34938 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 34939 at_status=$? 34940 grep '^ *+' $at_stder1 >&2 34941 grep -v '^ *+' $at_stder1 >$at_stderr 34942 at_failed=false 34943 echo stderr:; tee stderr <$at_stderr 34944 $at_diff $at_devnull $at_stdout || at_failed=: 34945 case $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=:;; 34951 esac 34952 if $at_failed; then 34953 34954 echo 1 > $at_status_file 34955 exit 1 34956 fi 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. 34964 sed '/^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 34977 mv at-stderr stderr 34978 # 2. Create the reference error message. 34979 cat >expout <<'_ATEOF' 34980 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 34981 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 34982 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 34983 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 34984 calc: error: 4444 != 1 34985 _ATEOF 34986 34987 # 3. If locations are not used, remove them. 34988 sed 's/^[-0-9.]*: //' expout >at-expout 34989 mv at-expout expout 34990 # 4. If error-verbose is not used, strip the`, unexpected....' part. 34991 sed 's/syntax error, .*$/syntax error/' expout >at-expout 34992 mv at-expout expout 34993 # 5. Check 34994 $at_traceoff 34995 echo "calc.at:592: cat stderr" 34996 echo calc.at:592 >$at_check_line_file 34997 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 34998 at_status=$? 34999 grep '^ *+' $at_stder1 >&2 35000 grep -v '^ *+' $at_stder1 >$at_stderr 35001 at_failed=false 35002 $at_diff $at_devnull $at_stderr || at_failed=: 35003 $at_diff expout $at_stdout || at_failed=: 35004 case $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=:;; 35010 esac 35011 if $at_failed; then 35012 35013 echo 1 > $at_status_file 35014 exit 1 35015 fi 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. 35023 cat >input <<'_ATEOF' 35024 (!) + (0 0) = 1 35025 _ATEOF 35026 35027 $at_traceoff 35028 echo "calc.at:592: \$PREPARSER ./calc input" 35029 echo calc.at:592 >$at_check_line_file 35030 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 35031 at_status=$? 35032 grep '^ *+' $at_stder1 >&2 35033 grep -v '^ *+' $at_stder1 >$at_stderr 35034 at_failed=false 35035 echo stderr:; tee stderr <$at_stderr 35036 $at_diff $at_devnull $at_stdout || at_failed=: 35037 case $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=:;; 35043 esac 35044 if $at_failed; then 35045 35046 echo 1 > $at_status_file 35047 exit 1 35048 fi 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. 35056 sed '/^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 35069 mv at-stderr stderr 35070 # 2. Create the reference error message. 35071 cat >expout <<'_ATEOF' 35072 1.9: syntax error, unexpected number 35073 calc: error: 2222 != 1 35074 _ATEOF 35075 35076 # 3. If locations are not used, remove them. 35077 sed 's/^[-0-9.]*: //' expout >at-expout 35078 mv at-expout expout 35079 # 4. If error-verbose is not used, strip the`, unexpected....' part. 35080 sed 's/syntax error, .*$/syntax error/' expout >at-expout 35081 mv at-expout expout 35082 # 5. Check 35083 $at_traceoff 35084 echo "calc.at:592: cat stderr" 35085 echo calc.at:592 >$at_check_line_file 35086 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 35087 at_status=$? 35088 grep '^ *+' $at_stder1 >&2 35089 grep -v '^ *+' $at_stder1 >$at_stderr 35090 at_failed=false 35091 $at_diff $at_devnull $at_stderr || at_failed=: 35092 $at_diff expout $at_stdout || at_failed=: 35093 case $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=:;; 35099 esac 35100 if $at_failed; then 35101 35102 echo 1 > $at_status_file 35103 exit 1 35104 fi 35105 35106 $at_traceon 35107 35108 35109 cat >input <<'_ATEOF' 35110 (- *) + (0 0) = 1 35111 _ATEOF 35112 35113 $at_traceoff 35114 echo "calc.at:592: \$PREPARSER ./calc input" 35115 echo calc.at:592 >$at_check_line_file 35116 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 35117 at_status=$? 35118 grep '^ *+' $at_stder1 >&2 35119 grep -v '^ *+' $at_stder1 >$at_stderr 35120 at_failed=false 35121 echo stderr:; tee stderr <$at_stderr 35122 $at_diff $at_devnull $at_stdout || at_failed=: 35123 case $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=:;; 35129 esac 35130 if $at_failed; then 35131 35132 echo 1 > $at_status_file 35133 exit 1 35134 fi 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. 35142 sed '/^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 35155 mv at-stderr stderr 35156 # 2. Create the reference error message. 35157 cat >expout <<'_ATEOF' 35158 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 35159 1.11: syntax error, unexpected number 35160 calc: error: 2222 != 1 35161 _ATEOF 35162 35163 # 3. If locations are not used, remove them. 35164 sed 's/^[-0-9.]*: //' expout >at-expout 35165 mv at-expout expout 35166 # 4. If error-verbose is not used, strip the`, unexpected....' part. 35167 sed 's/syntax error, .*$/syntax error/' expout >at-expout 35168 mv at-expout expout 35169 # 5. Check 35170 $at_traceoff 35171 echo "calc.at:592: cat stderr" 35172 echo calc.at:592 >$at_check_line_file 35173 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 35174 at_status=$? 35175 grep '^ *+' $at_stder1 >&2 35176 grep -v '^ *+' $at_stder1 >$at_stderr 35177 at_failed=false 35178 $at_diff $at_devnull $at_stderr || at_failed=: 35179 $at_diff expout $at_stdout || at_failed=: 35180 case $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=:;; 35186 esac 35187 if $at_failed; then 35188 35189 echo 1 > $at_status_file 35190 exit 1 35191 fi 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 35268 cat >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. */ 35297 typedef int semantic_value; 35298 35299 static semantic_value global_result = 0; 35300 static int global_count = 0; 35301 %} 35302 35303 /* Exercise %union. */ 35304 %union 35305 { 35306 semantic_value ival; 35307 }; 35308 35309 %{ 35310 static int power (int base, int exponent); 35311 /* yyerror receives the location if: 35312 - %location & %pure & %glr 35313 - %location & %pure & %yacc & %parse-param. */ 35314 static void yyerror ( 35315 35316 const char *s 35317 ); 35318 static int yylex (void); 35319 static int get_char (void); 35320 static 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 %% 35338 input: 35339 line 35340 | input line { } 35341 ; 35342 35343 line: 35344 '\n' 35345 | exp '\n' { USE ($1); } 35346 ; 35347 35348 exp: 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. */ 35369 static FILE *input; 35370 35371 static void 35372 yyerror ( 35373 35374 const char *s) 35375 { 35376 35377 35378 fprintf (stderr, "%s\n", s); 35379 } 35380 35381 35382 35383 static int 35384 get_char (void) 35385 { 35386 int res = getc (input); 35387 ; 35388 35389 return res; 35390 } 35391 35392 35393 static void 35394 unget_char ( int c) 35395 { 35396 ; 35397 35398 ungetc (c, input); 35399 } 35400 35401 static int 35402 read_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 35434 static int 35435 yylex (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 35470 static int 35471 power (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 35482 int 35483 main (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 35520 echo "calc.at:593: bison -o calc.c calc.y" 35521 echo calc.at:593 >$at_check_line_file 35522 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 35523 at_status=$? 35524 grep '^ *+' $at_stder1 >&2 35525 grep -v '^ *+' $at_stder1 >$at_stderr 35526 at_failed=false 35527 $at_diff $at_devnull $at_stderr || at_failed=: 35528 $at_diff $at_devnull $at_stdout || at_failed=: 35529 case $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=:;; 35535 esac 35536 if $at_failed; then 35537 35538 echo 1 > $at_status_file 35539 exit 1 35540 fi 35541 35542 $at_traceon 35543 35544 $at_traceoff 35545 echo "calc.at:593: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 35546 echo calc.at:593 >$at_check_line_file 35547 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 35548 at_status=$? 35549 grep '^ *+' $at_stder1 >&2 35550 grep -v '^ *+' $at_stder1 >$at_stderr 35551 at_failed=false 35552 echo stderr:; cat $at_stderr 35553 echo stdout:; cat $at_stdout 35554 case $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=:;; 35560 esac 35561 if $at_failed; then 35562 35563 echo 1 > $at_status_file 35564 exit 1 35565 fi 35566 35567 $at_traceon 35568 35569 35570 # Test the priorities. 35571 cat >input <<'_ATEOF' 35572 1 + 2 * 3 = 7 35573 1 + 2 * -3 = -5 35574 35575 -1^2 = -1 35576 (-1)^2 = 1 35577 35578 ---1 = -1 35579 35580 1 - 2 - 3 = -4 35581 1 - (2 - 3) = 2 35582 35583 2^2^3 = 256 35584 (2^2)^3 = 64 35585 _ATEOF 35586 35587 $at_traceoff 35588 echo "calc.at:593: \$PREPARSER ./calc input" 35589 echo calc.at:593 >$at_check_line_file 35590 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 35591 at_status=$? 35592 grep '^ *+' $at_stder1 >&2 35593 grep -v '^ *+' $at_stder1 >$at_stderr 35594 at_failed=false 35595 echo stderr:; tee stderr <$at_stderr 35596 $at_diff $at_devnull $at_stdout || at_failed=: 35597 case $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=:;; 35603 esac 35604 if $at_failed; then 35605 35606 echo 1 > $at_status_file 35607 exit 1 35608 fi 35609 35610 $at_traceon 35611 35612 35613 35614 # Some syntax errors. 35615 cat >input <<'_ATEOF' 35616 0 0 35617 _ATEOF 35618 35619 $at_traceoff 35620 echo "calc.at:593: \$PREPARSER ./calc input" 35621 echo calc.at:593 >$at_check_line_file 35622 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 35623 at_status=$? 35624 grep '^ *+' $at_stder1 >&2 35625 grep -v '^ *+' $at_stder1 >$at_stderr 35626 at_failed=false 35627 echo stderr:; tee stderr <$at_stderr 35628 $at_diff $at_devnull $at_stdout || at_failed=: 35629 case $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=:;; 35635 esac 35636 if $at_failed; then 35637 35638 echo 1 > $at_status_file 35639 exit 1 35640 fi 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. 35648 sed '/^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 35661 mv at-stderr stderr 35662 # 2. Create the reference error message. 35663 cat >expout <<'_ATEOF' 35664 1.2: syntax error, unexpected number 35665 _ATEOF 35666 35667 # 3. If locations are not used, remove them. 35668 sed 's/^[-0-9.]*: //' expout >at-expout 35669 mv at-expout expout 35670 # 4. If error-verbose is not used, strip the`, unexpected....' part. 35671 35672 # 5. Check 35673 $at_traceoff 35674 echo "calc.at:593: cat stderr" 35675 echo calc.at:593 >$at_check_line_file 35676 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 35677 at_status=$? 35678 grep '^ *+' $at_stder1 >&2 35679 grep -v '^ *+' $at_stder1 >$at_stderr 35680 at_failed=false 35681 $at_diff $at_devnull $at_stderr || at_failed=: 35682 $at_diff expout $at_stdout || at_failed=: 35683 case $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=:;; 35689 esac 35690 if $at_failed; then 35691 35692 echo 1 > $at_status_file 35693 exit 1 35694 fi 35695 35696 $at_traceon 35697 35698 35699 cat >input <<'_ATEOF' 35700 1//2 35701 _ATEOF 35702 35703 $at_traceoff 35704 echo "calc.at:593: \$PREPARSER ./calc input" 35705 echo calc.at:593 >$at_check_line_file 35706 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 35707 at_status=$? 35708 grep '^ *+' $at_stder1 >&2 35709 grep -v '^ *+' $at_stder1 >$at_stderr 35710 at_failed=false 35711 echo stderr:; tee stderr <$at_stderr 35712 $at_diff $at_devnull $at_stdout || at_failed=: 35713 case $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=:;; 35719 esac 35720 if $at_failed; then 35721 35722 echo 1 > $at_status_file 35723 exit 1 35724 fi 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. 35732 sed '/^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 35745 mv at-stderr stderr 35746 # 2. Create the reference error message. 35747 cat >expout <<'_ATEOF' 35748 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 35749 _ATEOF 35750 35751 # 3. If locations are not used, remove them. 35752 sed 's/^[-0-9.]*: //' expout >at-expout 35753 mv at-expout expout 35754 # 4. If error-verbose is not used, strip the`, unexpected....' part. 35755 35756 # 5. Check 35757 $at_traceoff 35758 echo "calc.at:593: cat stderr" 35759 echo calc.at:593 >$at_check_line_file 35760 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 35761 at_status=$? 35762 grep '^ *+' $at_stder1 >&2 35763 grep -v '^ *+' $at_stder1 >$at_stderr 35764 at_failed=false 35765 $at_diff $at_devnull $at_stderr || at_failed=: 35766 $at_diff expout $at_stdout || at_failed=: 35767 case $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=:;; 35773 esac 35774 if $at_failed; then 35775 35776 echo 1 > $at_status_file 35777 exit 1 35778 fi 35779 35780 $at_traceon 35781 35782 35783 cat >input <<'_ATEOF' 35784 error 35785 _ATEOF 35786 35787 $at_traceoff 35788 echo "calc.at:593: \$PREPARSER ./calc input" 35789 echo calc.at:593 >$at_check_line_file 35790 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 35791 at_status=$? 35792 grep '^ *+' $at_stder1 >&2 35793 grep -v '^ *+' $at_stder1 >$at_stderr 35794 at_failed=false 35795 echo stderr:; tee stderr <$at_stderr 35796 $at_diff $at_devnull $at_stdout || at_failed=: 35797 case $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=:;; 35803 esac 35804 if $at_failed; then 35805 35806 echo 1 > $at_status_file 35807 exit 1 35808 fi 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. 35816 sed '/^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 35829 mv at-stderr stderr 35830 # 2. Create the reference error message. 35831 cat >expout <<'_ATEOF' 35832 1.0: syntax error, unexpected $undefined 35833 _ATEOF 35834 35835 # 3. If locations are not used, remove them. 35836 sed 's/^[-0-9.]*: //' expout >at-expout 35837 mv at-expout expout 35838 # 4. If error-verbose is not used, strip the`, unexpected....' part. 35839 35840 # 5. Check 35841 $at_traceoff 35842 echo "calc.at:593: cat stderr" 35843 echo calc.at:593 >$at_check_line_file 35844 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 35845 at_status=$? 35846 grep '^ *+' $at_stder1 >&2 35847 grep -v '^ *+' $at_stder1 >$at_stderr 35848 at_failed=false 35849 $at_diff $at_devnull $at_stderr || at_failed=: 35850 $at_diff expout $at_stdout || at_failed=: 35851 case $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=:;; 35857 esac 35858 if $at_failed; then 35859 35860 echo 1 > $at_status_file 35861 exit 1 35862 fi 35863 35864 $at_traceon 35865 35866 35867 cat >input <<'_ATEOF' 35868 1 = 2 = 3 35869 _ATEOF 35870 35871 $at_traceoff 35872 echo "calc.at:593: \$PREPARSER ./calc input" 35873 echo calc.at:593 >$at_check_line_file 35874 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 35875 at_status=$? 35876 grep '^ *+' $at_stder1 >&2 35877 grep -v '^ *+' $at_stder1 >$at_stderr 35878 at_failed=false 35879 echo stderr:; tee stderr <$at_stderr 35880 $at_diff $at_devnull $at_stdout || at_failed=: 35881 case $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=:;; 35887 esac 35888 if $at_failed; then 35889 35890 echo 1 > $at_status_file 35891 exit 1 35892 fi 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. 35900 sed '/^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 35913 mv at-stderr stderr 35914 # 2. Create the reference error message. 35915 cat >expout <<'_ATEOF' 35916 1.6: syntax error, unexpected '=' 35917 _ATEOF 35918 35919 # 3. If locations are not used, remove them. 35920 sed 's/^[-0-9.]*: //' expout >at-expout 35921 mv at-expout expout 35922 # 4. If error-verbose is not used, strip the`, unexpected....' part. 35923 35924 # 5. Check 35925 $at_traceoff 35926 echo "calc.at:593: cat stderr" 35927 echo calc.at:593 >$at_check_line_file 35928 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 35929 at_status=$? 35930 grep '^ *+' $at_stder1 >&2 35931 grep -v '^ *+' $at_stder1 >$at_stderr 35932 at_failed=false 35933 $at_diff $at_devnull $at_stderr || at_failed=: 35934 $at_diff expout $at_stdout || at_failed=: 35935 case $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=:;; 35941 esac 35942 if $at_failed; then 35943 35944 echo 1 > $at_status_file 35945 exit 1 35946 fi 35947 35948 $at_traceon 35949 35950 35951 cat >input <<'_ATEOF' 35952 35953 +1 35954 _ATEOF 35955 35956 $at_traceoff 35957 echo "calc.at:593: \$PREPARSER ./calc input" 35958 echo calc.at:593 >$at_check_line_file 35959 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 35960 at_status=$? 35961 grep '^ *+' $at_stder1 >&2 35962 grep -v '^ *+' $at_stder1 >$at_stderr 35963 at_failed=false 35964 echo stderr:; tee stderr <$at_stderr 35965 $at_diff $at_devnull $at_stdout || at_failed=: 35966 case $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=:;; 35972 esac 35973 if $at_failed; then 35974 35975 echo 1 > $at_status_file 35976 exit 1 35977 fi 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. 35985 sed '/^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 35998 mv at-stderr stderr 35999 # 2. Create the reference error message. 36000 cat >expout <<'_ATEOF' 36001 2.0: syntax error, unexpected '+' 36002 _ATEOF 36003 36004 # 3. If locations are not used, remove them. 36005 sed 's/^[-0-9.]*: //' expout >at-expout 36006 mv at-expout expout 36007 # 4. If error-verbose is not used, strip the`, unexpected....' part. 36008 36009 # 5. Check 36010 $at_traceoff 36011 echo "calc.at:593: cat stderr" 36012 echo calc.at:593 >$at_check_line_file 36013 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 36014 at_status=$? 36015 grep '^ *+' $at_stder1 >&2 36016 grep -v '^ *+' $at_stder1 >$at_stderr 36017 at_failed=false 36018 $at_diff $at_devnull $at_stderr || at_failed=: 36019 $at_diff expout $at_stdout || at_failed=: 36020 case $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=:;; 36026 esac 36027 if $at_failed; then 36028 36029 echo 1 > $at_status_file 36030 exit 1 36031 fi 36032 36033 $at_traceon 36034 36035 36036 # Exercise error messages with EOF: work on an empty file. 36037 $at_traceoff 36038 echo "calc.at:593: \$PREPARSER ./calc /dev/null" 36039 echo calc.at:593 >$at_check_line_file 36040 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 36041 at_status=$? 36042 grep '^ *+' $at_stder1 >&2 36043 grep -v '^ *+' $at_stder1 >$at_stderr 36044 at_failed=false 36045 echo stderr:; tee stderr <$at_stderr 36046 $at_diff $at_devnull $at_stdout || at_failed=: 36047 case $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=:;; 36053 esac 36054 if $at_failed; then 36055 36056 echo 1 > $at_status_file 36057 exit 1 36058 fi 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. 36066 sed '/^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 36079 mv at-stderr stderr 36080 # 2. Create the reference error message. 36081 cat >expout <<'_ATEOF' 36082 1.0: syntax error, unexpected end of input 36083 _ATEOF 36084 36085 # 3. If locations are not used, remove them. 36086 sed 's/^[-0-9.]*: //' expout >at-expout 36087 mv at-expout expout 36088 # 4. If error-verbose is not used, strip the`, unexpected....' part. 36089 36090 # 5. Check 36091 $at_traceoff 36092 echo "calc.at:593: cat stderr" 36093 echo calc.at:593 >$at_check_line_file 36094 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 36095 at_status=$? 36096 grep '^ *+' $at_stder1 >&2 36097 grep -v '^ *+' $at_stder1 >$at_stderr 36098 at_failed=false 36099 $at_diff $at_devnull $at_stderr || at_failed=: 36100 $at_diff expout $at_stdout || at_failed=: 36101 case $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=:;; 36107 esac 36108 if $at_failed; then 36109 36110 echo 1 > $at_status_file 36111 exit 1 36112 fi 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 # 36134 cat >input <<'_ATEOF' 36135 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 36136 _ATEOF 36137 36138 $at_traceoff 36139 echo "calc.at:593: \$PREPARSER ./calc input" 36140 echo calc.at:593 >$at_check_line_file 36141 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 36142 at_status=$? 36143 grep '^ *+' $at_stder1 >&2 36144 grep -v '^ *+' $at_stder1 >$at_stderr 36145 at_failed=false 36146 echo stderr:; tee stderr <$at_stderr 36147 $at_diff $at_devnull $at_stdout || at_failed=: 36148 case $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=:;; 36154 esac 36155 if $at_failed; then 36156 36157 echo 1 > $at_status_file 36158 exit 1 36159 fi 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. 36167 sed '/^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 36180 mv at-stderr stderr 36181 # 2. Create the reference error message. 36182 cat >expout <<'_ATEOF' 36183 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 36184 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 36185 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 36186 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 36187 calc: error: 4444 != 1 36188 _ATEOF 36189 36190 # 3. If locations are not used, remove them. 36191 sed 's/^[-0-9.]*: //' expout >at-expout 36192 mv at-expout expout 36193 # 4. If error-verbose is not used, strip the`, unexpected....' part. 36194 36195 # 5. Check 36196 $at_traceoff 36197 echo "calc.at:593: cat stderr" 36198 echo calc.at:593 >$at_check_line_file 36199 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 36200 at_status=$? 36201 grep '^ *+' $at_stder1 >&2 36202 grep -v '^ *+' $at_stder1 >$at_stderr 36203 at_failed=false 36204 $at_diff $at_devnull $at_stderr || at_failed=: 36205 $at_diff expout $at_stdout || at_failed=: 36206 case $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=:;; 36212 esac 36213 if $at_failed; then 36214 36215 echo 1 > $at_status_file 36216 exit 1 36217 fi 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. 36225 cat >input <<'_ATEOF' 36226 (!) + (0 0) = 1 36227 _ATEOF 36228 36229 $at_traceoff 36230 echo "calc.at:593: \$PREPARSER ./calc input" 36231 echo calc.at:593 >$at_check_line_file 36232 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 36233 at_status=$? 36234 grep '^ *+' $at_stder1 >&2 36235 grep -v '^ *+' $at_stder1 >$at_stderr 36236 at_failed=false 36237 echo stderr:; tee stderr <$at_stderr 36238 $at_diff $at_devnull $at_stdout || at_failed=: 36239 case $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=:;; 36245 esac 36246 if $at_failed; then 36247 36248 echo 1 > $at_status_file 36249 exit 1 36250 fi 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. 36258 sed '/^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 36271 mv at-stderr stderr 36272 # 2. Create the reference error message. 36273 cat >expout <<'_ATEOF' 36274 1.9: syntax error, unexpected number 36275 calc: error: 2222 != 1 36276 _ATEOF 36277 36278 # 3. If locations are not used, remove them. 36279 sed 's/^[-0-9.]*: //' expout >at-expout 36280 mv at-expout expout 36281 # 4. If error-verbose is not used, strip the`, unexpected....' part. 36282 36283 # 5. Check 36284 $at_traceoff 36285 echo "calc.at:593: cat stderr" 36286 echo calc.at:593 >$at_check_line_file 36287 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 36288 at_status=$? 36289 grep '^ *+' $at_stder1 >&2 36290 grep -v '^ *+' $at_stder1 >$at_stderr 36291 at_failed=false 36292 $at_diff $at_devnull $at_stderr || at_failed=: 36293 $at_diff expout $at_stdout || at_failed=: 36294 case $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=:;; 36300 esac 36301 if $at_failed; then 36302 36303 echo 1 > $at_status_file 36304 exit 1 36305 fi 36306 36307 $at_traceon 36308 36309 36310 cat >input <<'_ATEOF' 36311 (- *) + (0 0) = 1 36312 _ATEOF 36313 36314 $at_traceoff 36315 echo "calc.at:593: \$PREPARSER ./calc input" 36316 echo calc.at:593 >$at_check_line_file 36317 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 36318 at_status=$? 36319 grep '^ *+' $at_stder1 >&2 36320 grep -v '^ *+' $at_stder1 >$at_stderr 36321 at_failed=false 36322 echo stderr:; tee stderr <$at_stderr 36323 $at_diff $at_devnull $at_stdout || at_failed=: 36324 case $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=:;; 36330 esac 36331 if $at_failed; then 36332 36333 echo 1 > $at_status_file 36334 exit 1 36335 fi 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. 36343 sed '/^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 36356 mv at-stderr stderr 36357 # 2. Create the reference error message. 36358 cat >expout <<'_ATEOF' 36359 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 36360 1.11: syntax error, unexpected number 36361 calc: error: 2222 != 1 36362 _ATEOF 36363 36364 # 3. If locations are not used, remove them. 36365 sed 's/^[-0-9.]*: //' expout >at-expout 36366 mv at-expout expout 36367 # 4. If error-verbose is not used, strip the`, unexpected....' part. 36368 36369 # 5. Check 36370 $at_traceoff 36371 echo "calc.at:593: cat stderr" 36372 echo calc.at:593 >$at_check_line_file 36373 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 36374 at_status=$? 36375 grep '^ *+' $at_stder1 >&2 36376 grep -v '^ *+' $at_stder1 >$at_stderr 36377 at_failed=false 36378 $at_diff $at_devnull $at_stderr || at_failed=: 36379 $at_diff expout $at_stdout || at_failed=: 36380 case $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=:;; 36386 esac 36387 if $at_failed; then 36388 36389 echo 1 > $at_status_file 36390 exit 1 36391 fi 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 36468 cat >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. */ 36497 typedef int semantic_value; 36498 36499 static semantic_value global_result = 0; 36500 static int global_count = 0; 36501 %} 36502 36503 /* Exercise %union. */ 36504 %union 36505 { 36506 semantic_value ival; 36507 }; 36508 36509 %{ 36510 static int power (int base, int exponent); 36511 /* yyerror receives the location if: 36512 - %location & %pure & %glr 36513 - %location & %pure & %yacc & %parse-param. */ 36514 static void yyerror (YYLTYPE *llocp, 36515 36516 const char *s 36517 ); 36518 static int yylex (YYSTYPE *lvalp, YYLTYPE *llocp); 36519 static int get_char (YYSTYPE *lvalp, YYLTYPE *llocp); 36520 static 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 %% 36538 input: 36539 line 36540 | input line { } 36541 ; 36542 36543 line: 36544 '\n' 36545 | exp '\n' { USE ($1); } 36546 ; 36547 36548 exp: 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. */ 36569 static FILE *input; 36570 36571 static void 36572 yyerror (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 36592 static YYLTYPE last_yylloc; 36593 36594 static int 36595 get_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 36613 static void 36614 unget_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 36624 static int 36625 read_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 36657 static int 36658 yylex (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 36701 static int 36702 power (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 36713 int 36714 main (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 36751 echo "calc.at:595: bison -o calc.c calc.y" 36752 echo calc.at:595 >$at_check_line_file 36753 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 36754 at_status=$? 36755 grep '^ *+' $at_stder1 >&2 36756 grep -v '^ *+' $at_stder1 >$at_stderr 36757 at_failed=false 36758 $at_diff $at_devnull $at_stderr || at_failed=: 36759 $at_diff $at_devnull $at_stdout || at_failed=: 36760 case $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=:;; 36766 esac 36767 if $at_failed; then 36768 36769 echo 1 > $at_status_file 36770 exit 1 36771 fi 36772 36773 $at_traceon 36774 36775 $at_traceoff 36776 echo "calc.at:595: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 36777 echo calc.at:595 >$at_check_line_file 36778 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 36779 at_status=$? 36780 grep '^ *+' $at_stder1 >&2 36781 grep -v '^ *+' $at_stder1 >$at_stderr 36782 at_failed=false 36783 echo stderr:; cat $at_stderr 36784 echo stdout:; cat $at_stdout 36785 case $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=:;; 36791 esac 36792 if $at_failed; then 36793 36794 echo 1 > $at_status_file 36795 exit 1 36796 fi 36797 36798 $at_traceon 36799 36800 36801 # Test the priorities. 36802 cat >input <<'_ATEOF' 36803 1 + 2 * 3 = 7 36804 1 + 2 * -3 = -5 36805 36806 -1^2 = -1 36807 (-1)^2 = 1 36808 36809 ---1 = -1 36810 36811 1 - 2 - 3 = -4 36812 1 - (2 - 3) = 2 36813 36814 2^2^3 = 256 36815 (2^2)^3 = 64 36816 _ATEOF 36817 36818 $at_traceoff 36819 echo "calc.at:595: \$PREPARSER ./calc input" 36820 echo calc.at:595 >$at_check_line_file 36821 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 36822 at_status=$? 36823 grep '^ *+' $at_stder1 >&2 36824 grep -v '^ *+' $at_stder1 >$at_stderr 36825 at_failed=false 36826 echo stderr:; tee stderr <$at_stderr 36827 $at_diff $at_devnull $at_stdout || at_failed=: 36828 case $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=:;; 36834 esac 36835 if $at_failed; then 36836 36837 echo 1 > $at_status_file 36838 exit 1 36839 fi 36840 36841 $at_traceon 36842 36843 36844 36845 # Some syntax errors. 36846 cat >input <<'_ATEOF' 36847 0 0 36848 _ATEOF 36849 36850 $at_traceoff 36851 echo "calc.at:595: \$PREPARSER ./calc input" 36852 echo calc.at:595 >$at_check_line_file 36853 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 36854 at_status=$? 36855 grep '^ *+' $at_stder1 >&2 36856 grep -v '^ *+' $at_stder1 >$at_stderr 36857 at_failed=false 36858 echo stderr:; tee stderr <$at_stderr 36859 $at_diff $at_devnull $at_stdout || at_failed=: 36860 case $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=:;; 36866 esac 36867 if $at_failed; then 36868 36869 echo 1 > $at_status_file 36870 exit 1 36871 fi 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. 36879 sed '/^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 36892 mv at-stderr stderr 36893 # 2. Create the reference error message. 36894 cat >expout <<'_ATEOF' 36895 1.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. 36901 sed 's/syntax error, .*$/syntax error/' expout >at-expout 36902 mv at-expout expout 36903 # 5. Check 36904 $at_traceoff 36905 echo "calc.at:595: cat stderr" 36906 echo calc.at:595 >$at_check_line_file 36907 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 36908 at_status=$? 36909 grep '^ *+' $at_stder1 >&2 36910 grep -v '^ *+' $at_stder1 >$at_stderr 36911 at_failed=false 36912 $at_diff $at_devnull $at_stderr || at_failed=: 36913 $at_diff expout $at_stdout || at_failed=: 36914 case $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=:;; 36920 esac 36921 if $at_failed; then 36922 36923 echo 1 > $at_status_file 36924 exit 1 36925 fi 36926 36927 $at_traceon 36928 36929 36930 cat >input <<'_ATEOF' 36931 1//2 36932 _ATEOF 36933 36934 $at_traceoff 36935 echo "calc.at:595: \$PREPARSER ./calc input" 36936 echo calc.at:595 >$at_check_line_file 36937 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 36938 at_status=$? 36939 grep '^ *+' $at_stder1 >&2 36940 grep -v '^ *+' $at_stder1 >$at_stderr 36941 at_failed=false 36942 echo stderr:; tee stderr <$at_stderr 36943 $at_diff $at_devnull $at_stdout || at_failed=: 36944 case $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=:;; 36950 esac 36951 if $at_failed; then 36952 36953 echo 1 > $at_status_file 36954 exit 1 36955 fi 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. 36963 sed '/^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 36976 mv at-stderr stderr 36977 # 2. Create the reference error message. 36978 cat >expout <<'_ATEOF' 36979 1.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. 36985 sed 's/syntax error, .*$/syntax error/' expout >at-expout 36986 mv at-expout expout 36987 # 5. Check 36988 $at_traceoff 36989 echo "calc.at:595: cat stderr" 36990 echo calc.at:595 >$at_check_line_file 36991 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 36992 at_status=$? 36993 grep '^ *+' $at_stder1 >&2 36994 grep -v '^ *+' $at_stder1 >$at_stderr 36995 at_failed=false 36996 $at_diff $at_devnull $at_stderr || at_failed=: 36997 $at_diff expout $at_stdout || at_failed=: 36998 case $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=:;; 37004 esac 37005 if $at_failed; then 37006 37007 echo 1 > $at_status_file 37008 exit 1 37009 fi 37010 37011 $at_traceon 37012 37013 37014 cat >input <<'_ATEOF' 37015 error 37016 _ATEOF 37017 37018 $at_traceoff 37019 echo "calc.at:595: \$PREPARSER ./calc input" 37020 echo calc.at:595 >$at_check_line_file 37021 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 37022 at_status=$? 37023 grep '^ *+' $at_stder1 >&2 37024 grep -v '^ *+' $at_stder1 >$at_stderr 37025 at_failed=false 37026 echo stderr:; tee stderr <$at_stderr 37027 $at_diff $at_devnull $at_stdout || at_failed=: 37028 case $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=:;; 37034 esac 37035 if $at_failed; then 37036 37037 echo 1 > $at_status_file 37038 exit 1 37039 fi 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. 37047 sed '/^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 37060 mv at-stderr stderr 37061 # 2. Create the reference error message. 37062 cat >expout <<'_ATEOF' 37063 1.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. 37069 sed 's/syntax error, .*$/syntax error/' expout >at-expout 37070 mv at-expout expout 37071 # 5. Check 37072 $at_traceoff 37073 echo "calc.at:595: cat stderr" 37074 echo calc.at:595 >$at_check_line_file 37075 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 37076 at_status=$? 37077 grep '^ *+' $at_stder1 >&2 37078 grep -v '^ *+' $at_stder1 >$at_stderr 37079 at_failed=false 37080 $at_diff $at_devnull $at_stderr || at_failed=: 37081 $at_diff expout $at_stdout || at_failed=: 37082 case $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=:;; 37088 esac 37089 if $at_failed; then 37090 37091 echo 1 > $at_status_file 37092 exit 1 37093 fi 37094 37095 $at_traceon 37096 37097 37098 cat >input <<'_ATEOF' 37099 1 = 2 = 3 37100 _ATEOF 37101 37102 $at_traceoff 37103 echo "calc.at:595: \$PREPARSER ./calc input" 37104 echo calc.at:595 >$at_check_line_file 37105 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 37106 at_status=$? 37107 grep '^ *+' $at_stder1 >&2 37108 grep -v '^ *+' $at_stder1 >$at_stderr 37109 at_failed=false 37110 echo stderr:; tee stderr <$at_stderr 37111 $at_diff $at_devnull $at_stdout || at_failed=: 37112 case $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=:;; 37118 esac 37119 if $at_failed; then 37120 37121 echo 1 > $at_status_file 37122 exit 1 37123 fi 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. 37131 sed '/^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 37144 mv at-stderr stderr 37145 # 2. Create the reference error message. 37146 cat >expout <<'_ATEOF' 37147 1.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. 37153 sed 's/syntax error, .*$/syntax error/' expout >at-expout 37154 mv at-expout expout 37155 # 5. Check 37156 $at_traceoff 37157 echo "calc.at:595: cat stderr" 37158 echo calc.at:595 >$at_check_line_file 37159 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 37160 at_status=$? 37161 grep '^ *+' $at_stder1 >&2 37162 grep -v '^ *+' $at_stder1 >$at_stderr 37163 at_failed=false 37164 $at_diff $at_devnull $at_stderr || at_failed=: 37165 $at_diff expout $at_stdout || at_failed=: 37166 case $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=:;; 37172 esac 37173 if $at_failed; then 37174 37175 echo 1 > $at_status_file 37176 exit 1 37177 fi 37178 37179 $at_traceon 37180 37181 37182 cat >input <<'_ATEOF' 37183 37184 +1 37185 _ATEOF 37186 37187 $at_traceoff 37188 echo "calc.at:595: \$PREPARSER ./calc input" 37189 echo calc.at:595 >$at_check_line_file 37190 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 37191 at_status=$? 37192 grep '^ *+' $at_stder1 >&2 37193 grep -v '^ *+' $at_stder1 >$at_stderr 37194 at_failed=false 37195 echo stderr:; tee stderr <$at_stderr 37196 $at_diff $at_devnull $at_stdout || at_failed=: 37197 case $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=:;; 37203 esac 37204 if $at_failed; then 37205 37206 echo 1 > $at_status_file 37207 exit 1 37208 fi 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. 37216 sed '/^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 37229 mv at-stderr stderr 37230 # 2. Create the reference error message. 37231 cat >expout <<'_ATEOF' 37232 2.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. 37238 sed 's/syntax error, .*$/syntax error/' expout >at-expout 37239 mv at-expout expout 37240 # 5. Check 37241 $at_traceoff 37242 echo "calc.at:595: cat stderr" 37243 echo calc.at:595 >$at_check_line_file 37244 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 37245 at_status=$? 37246 grep '^ *+' $at_stder1 >&2 37247 grep -v '^ *+' $at_stder1 >$at_stderr 37248 at_failed=false 37249 $at_diff $at_devnull $at_stderr || at_failed=: 37250 $at_diff expout $at_stdout || at_failed=: 37251 case $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=:;; 37257 esac 37258 if $at_failed; then 37259 37260 echo 1 > $at_status_file 37261 exit 1 37262 fi 37263 37264 $at_traceon 37265 37266 37267 # Exercise error messages with EOF: work on an empty file. 37268 $at_traceoff 37269 echo "calc.at:595: \$PREPARSER ./calc /dev/null" 37270 echo calc.at:595 >$at_check_line_file 37271 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 37272 at_status=$? 37273 grep '^ *+' $at_stder1 >&2 37274 grep -v '^ *+' $at_stder1 >$at_stderr 37275 at_failed=false 37276 echo stderr:; tee stderr <$at_stderr 37277 $at_diff $at_devnull $at_stdout || at_failed=: 37278 case $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=:;; 37284 esac 37285 if $at_failed; then 37286 37287 echo 1 > $at_status_file 37288 exit 1 37289 fi 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. 37297 sed '/^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 37310 mv at-stderr stderr 37311 # 2. Create the reference error message. 37312 cat >expout <<'_ATEOF' 37313 1.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. 37319 sed 's/syntax error, .*$/syntax error/' expout >at-expout 37320 mv at-expout expout 37321 # 5. Check 37322 $at_traceoff 37323 echo "calc.at:595: cat stderr" 37324 echo calc.at:595 >$at_check_line_file 37325 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 37326 at_status=$? 37327 grep '^ *+' $at_stder1 >&2 37328 grep -v '^ *+' $at_stder1 >$at_stderr 37329 at_failed=false 37330 $at_diff $at_devnull $at_stderr || at_failed=: 37331 $at_diff expout $at_stdout || at_failed=: 37332 case $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=:;; 37338 esac 37339 if $at_failed; then 37340 37341 echo 1 > $at_status_file 37342 exit 1 37343 fi 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 # 37365 cat >input <<'_ATEOF' 37366 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 37367 _ATEOF 37368 37369 $at_traceoff 37370 echo "calc.at:595: \$PREPARSER ./calc input" 37371 echo calc.at:595 >$at_check_line_file 37372 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 37373 at_status=$? 37374 grep '^ *+' $at_stder1 >&2 37375 grep -v '^ *+' $at_stder1 >$at_stderr 37376 at_failed=false 37377 echo stderr:; tee stderr <$at_stderr 37378 $at_diff $at_devnull $at_stdout || at_failed=: 37379 case $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=:;; 37385 esac 37386 if $at_failed; then 37387 37388 echo 1 > $at_status_file 37389 exit 1 37390 fi 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. 37398 sed '/^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 37411 mv at-stderr stderr 37412 # 2. Create the reference error message. 37413 cat >expout <<'_ATEOF' 37414 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 37415 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 37416 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 37417 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 37418 calc: 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. 37424 sed 's/syntax error, .*$/syntax error/' expout >at-expout 37425 mv at-expout expout 37426 # 5. Check 37427 $at_traceoff 37428 echo "calc.at:595: cat stderr" 37429 echo calc.at:595 >$at_check_line_file 37430 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 37431 at_status=$? 37432 grep '^ *+' $at_stder1 >&2 37433 grep -v '^ *+' $at_stder1 >$at_stderr 37434 at_failed=false 37435 $at_diff $at_devnull $at_stderr || at_failed=: 37436 $at_diff expout $at_stdout || at_failed=: 37437 case $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=:;; 37443 esac 37444 if $at_failed; then 37445 37446 echo 1 > $at_status_file 37447 exit 1 37448 fi 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. 37456 cat >input <<'_ATEOF' 37457 (!) + (0 0) = 1 37458 _ATEOF 37459 37460 $at_traceoff 37461 echo "calc.at:595: \$PREPARSER ./calc input" 37462 echo calc.at:595 >$at_check_line_file 37463 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 37464 at_status=$? 37465 grep '^ *+' $at_stder1 >&2 37466 grep -v '^ *+' $at_stder1 >$at_stderr 37467 at_failed=false 37468 echo stderr:; tee stderr <$at_stderr 37469 $at_diff $at_devnull $at_stdout || at_failed=: 37470 case $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=:;; 37476 esac 37477 if $at_failed; then 37478 37479 echo 1 > $at_status_file 37480 exit 1 37481 fi 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. 37489 sed '/^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 37502 mv at-stderr stderr 37503 # 2. Create the reference error message. 37504 cat >expout <<'_ATEOF' 37505 1.9: syntax error, unexpected number 37506 calc: 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. 37512 sed 's/syntax error, .*$/syntax error/' expout >at-expout 37513 mv at-expout expout 37514 # 5. Check 37515 $at_traceoff 37516 echo "calc.at:595: cat stderr" 37517 echo calc.at:595 >$at_check_line_file 37518 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 37519 at_status=$? 37520 grep '^ *+' $at_stder1 >&2 37521 grep -v '^ *+' $at_stder1 >$at_stderr 37522 at_failed=false 37523 $at_diff $at_devnull $at_stderr || at_failed=: 37524 $at_diff expout $at_stdout || at_failed=: 37525 case $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=:;; 37531 esac 37532 if $at_failed; then 37533 37534 echo 1 > $at_status_file 37535 exit 1 37536 fi 37537 37538 $at_traceon 37539 37540 37541 cat >input <<'_ATEOF' 37542 (- *) + (0 0) = 1 37543 _ATEOF 37544 37545 $at_traceoff 37546 echo "calc.at:595: \$PREPARSER ./calc input" 37547 echo calc.at:595 >$at_check_line_file 37548 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 37549 at_status=$? 37550 grep '^ *+' $at_stder1 >&2 37551 grep -v '^ *+' $at_stder1 >$at_stderr 37552 at_failed=false 37553 echo stderr:; tee stderr <$at_stderr 37554 $at_diff $at_devnull $at_stdout || at_failed=: 37555 case $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=:;; 37561 esac 37562 if $at_failed; then 37563 37564 echo 1 > $at_status_file 37565 exit 1 37566 fi 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. 37574 sed '/^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 37587 mv at-stderr stderr 37588 # 2. Create the reference error message. 37589 cat >expout <<'_ATEOF' 37590 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 37591 1.11: syntax error, unexpected number 37592 calc: 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. 37598 sed 's/syntax error, .*$/syntax error/' expout >at-expout 37599 mv at-expout expout 37600 # 5. Check 37601 $at_traceoff 37602 echo "calc.at:595: cat stderr" 37603 echo calc.at:595 >$at_check_line_file 37604 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 37605 at_status=$? 37606 grep '^ *+' $at_stder1 >&2 37607 grep -v '^ *+' $at_stder1 >$at_stderr 37608 at_failed=false 37609 $at_diff $at_devnull $at_stderr || at_failed=: 37610 $at_diff expout $at_stdout || at_failed=: 37611 case $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=:;; 37617 esac 37618 if $at_failed; then 37619 37620 echo 1 > $at_status_file 37621 exit 1 37622 fi 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 37699 cat >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. */ 37728 typedef int semantic_value; 37729 37730 static semantic_value global_result = 0; 37731 static int global_count = 0; 37732 %} 37733 37734 /* Exercise %union. */ 37735 %union 37736 { 37737 semantic_value ival; 37738 }; 37739 37740 %{ 37741 static int power (int base, int exponent); 37742 /* yyerror receives the location if: 37743 - %location & %pure & %glr 37744 - %location & %pure & %yacc & %parse-param. */ 37745 static void yyerror ( 37746 37747 const char *s 37748 ); 37749 static int yylex (void); 37750 static int get_char (void); 37751 static 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 %% 37769 input: 37770 line 37771 | input line { } 37772 ; 37773 37774 line: 37775 '\n' 37776 | exp '\n' { USE ($1); } 37777 ; 37778 37779 exp: 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. */ 37800 static FILE *input; 37801 37802 static void 37803 yyerror ( 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 37823 static YYLTYPE last_yylloc; 37824 37825 static int 37826 get_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 37844 static void 37845 unget_char ( int c) 37846 { 37847 ; 37848 37849 /* Wrong when C == `\n'. */ 37850 (yylloc) = last_yylloc; 37851 37852 ungetc (c, input); 37853 } 37854 37855 static int 37856 read_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 37888 static int 37889 yylex (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 37932 static int 37933 power (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 37944 int 37945 main (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 37982 echo "calc.at:596: bison -o calc.c calc.y" 37983 echo calc.at:596 >$at_check_line_file 37984 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 37985 at_status=$? 37986 grep '^ *+' $at_stder1 >&2 37987 grep -v '^ *+' $at_stder1 >$at_stderr 37988 at_failed=false 37989 $at_diff $at_devnull $at_stderr || at_failed=: 37990 $at_diff $at_devnull $at_stdout || at_failed=: 37991 case $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=:;; 37997 esac 37998 if $at_failed; then 37999 38000 echo 1 > $at_status_file 38001 exit 1 38002 fi 38003 38004 $at_traceon 38005 38006 $at_traceoff 38007 echo "calc.at:596: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 38008 echo calc.at:596 >$at_check_line_file 38009 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 38010 at_status=$? 38011 grep '^ *+' $at_stder1 >&2 38012 grep -v '^ *+' $at_stder1 >$at_stderr 38013 at_failed=false 38014 echo stderr:; cat $at_stderr 38015 echo stdout:; cat $at_stdout 38016 case $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=:;; 38022 esac 38023 if $at_failed; then 38024 38025 echo 1 > $at_status_file 38026 exit 1 38027 fi 38028 38029 $at_traceon 38030 38031 38032 # Test the priorities. 38033 cat >input <<'_ATEOF' 38034 1 + 2 * 3 = 7 38035 1 + 2 * -3 = -5 38036 38037 -1^2 = -1 38038 (-1)^2 = 1 38039 38040 ---1 = -1 38041 38042 1 - 2 - 3 = -4 38043 1 - (2 - 3) = 2 38044 38045 2^2^3 = 256 38046 (2^2)^3 = 64 38047 _ATEOF 38048 38049 $at_traceoff 38050 echo "calc.at:596: \$PREPARSER ./calc input" 38051 echo calc.at:596 >$at_check_line_file 38052 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 38053 at_status=$? 38054 grep '^ *+' $at_stder1 >&2 38055 grep -v '^ *+' $at_stder1 >$at_stderr 38056 at_failed=false 38057 echo stderr:; tee stderr <$at_stderr 38058 $at_diff $at_devnull $at_stdout || at_failed=: 38059 case $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=:;; 38065 esac 38066 if $at_failed; then 38067 38068 echo 1 > $at_status_file 38069 exit 1 38070 fi 38071 38072 $at_traceon 38073 38074 38075 38076 # Some syntax errors. 38077 cat >input <<'_ATEOF' 38078 0 0 38079 _ATEOF 38080 38081 $at_traceoff 38082 echo "calc.at:596: \$PREPARSER ./calc input" 38083 echo calc.at:596 >$at_check_line_file 38084 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 38085 at_status=$? 38086 grep '^ *+' $at_stder1 >&2 38087 grep -v '^ *+' $at_stder1 >$at_stderr 38088 at_failed=false 38089 echo stderr:; tee stderr <$at_stderr 38090 $at_diff $at_devnull $at_stdout || at_failed=: 38091 case $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=:;; 38097 esac 38098 if $at_failed; then 38099 38100 echo 1 > $at_status_file 38101 exit 1 38102 fi 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. 38110 sed '/^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 38123 mv at-stderr stderr 38124 # 2. Create the reference error message. 38125 cat >expout <<'_ATEOF' 38126 1.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 38135 echo "calc.at:596: cat stderr" 38136 echo calc.at:596 >$at_check_line_file 38137 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 38138 at_status=$? 38139 grep '^ *+' $at_stder1 >&2 38140 grep -v '^ *+' $at_stder1 >$at_stderr 38141 at_failed=false 38142 $at_diff $at_devnull $at_stderr || at_failed=: 38143 $at_diff expout $at_stdout || at_failed=: 38144 case $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=:;; 38150 esac 38151 if $at_failed; then 38152 38153 echo 1 > $at_status_file 38154 exit 1 38155 fi 38156 38157 $at_traceon 38158 38159 38160 cat >input <<'_ATEOF' 38161 1//2 38162 _ATEOF 38163 38164 $at_traceoff 38165 echo "calc.at:596: \$PREPARSER ./calc input" 38166 echo calc.at:596 >$at_check_line_file 38167 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 38168 at_status=$? 38169 grep '^ *+' $at_stder1 >&2 38170 grep -v '^ *+' $at_stder1 >$at_stderr 38171 at_failed=false 38172 echo stderr:; tee stderr <$at_stderr 38173 $at_diff $at_devnull $at_stdout || at_failed=: 38174 case $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=:;; 38180 esac 38181 if $at_failed; then 38182 38183 echo 1 > $at_status_file 38184 exit 1 38185 fi 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. 38193 sed '/^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 38206 mv at-stderr stderr 38207 # 2. Create the reference error message. 38208 cat >expout <<'_ATEOF' 38209 1.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 38218 echo "calc.at:596: cat stderr" 38219 echo calc.at:596 >$at_check_line_file 38220 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 38221 at_status=$? 38222 grep '^ *+' $at_stder1 >&2 38223 grep -v '^ *+' $at_stder1 >$at_stderr 38224 at_failed=false 38225 $at_diff $at_devnull $at_stderr || at_failed=: 38226 $at_diff expout $at_stdout || at_failed=: 38227 case $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=:;; 38233 esac 38234 if $at_failed; then 38235 38236 echo 1 > $at_status_file 38237 exit 1 38238 fi 38239 38240 $at_traceon 38241 38242 38243 cat >input <<'_ATEOF' 38244 error 38245 _ATEOF 38246 38247 $at_traceoff 38248 echo "calc.at:596: \$PREPARSER ./calc input" 38249 echo calc.at:596 >$at_check_line_file 38250 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 38251 at_status=$? 38252 grep '^ *+' $at_stder1 >&2 38253 grep -v '^ *+' $at_stder1 >$at_stderr 38254 at_failed=false 38255 echo stderr:; tee stderr <$at_stderr 38256 $at_diff $at_devnull $at_stdout || at_failed=: 38257 case $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=:;; 38263 esac 38264 if $at_failed; then 38265 38266 echo 1 > $at_status_file 38267 exit 1 38268 fi 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. 38276 sed '/^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 38289 mv at-stderr stderr 38290 # 2. Create the reference error message. 38291 cat >expout <<'_ATEOF' 38292 1.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 38301 echo "calc.at:596: cat stderr" 38302 echo calc.at:596 >$at_check_line_file 38303 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 38304 at_status=$? 38305 grep '^ *+' $at_stder1 >&2 38306 grep -v '^ *+' $at_stder1 >$at_stderr 38307 at_failed=false 38308 $at_diff $at_devnull $at_stderr || at_failed=: 38309 $at_diff expout $at_stdout || at_failed=: 38310 case $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=:;; 38316 esac 38317 if $at_failed; then 38318 38319 echo 1 > $at_status_file 38320 exit 1 38321 fi 38322 38323 $at_traceon 38324 38325 38326 cat >input <<'_ATEOF' 38327 1 = 2 = 3 38328 _ATEOF 38329 38330 $at_traceoff 38331 echo "calc.at:596: \$PREPARSER ./calc input" 38332 echo calc.at:596 >$at_check_line_file 38333 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 38334 at_status=$? 38335 grep '^ *+' $at_stder1 >&2 38336 grep -v '^ *+' $at_stder1 >$at_stderr 38337 at_failed=false 38338 echo stderr:; tee stderr <$at_stderr 38339 $at_diff $at_devnull $at_stdout || at_failed=: 38340 case $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=:;; 38346 esac 38347 if $at_failed; then 38348 38349 echo 1 > $at_status_file 38350 exit 1 38351 fi 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. 38359 sed '/^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 38372 mv at-stderr stderr 38373 # 2. Create the reference error message. 38374 cat >expout <<'_ATEOF' 38375 1.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 38384 echo "calc.at:596: cat stderr" 38385 echo calc.at:596 >$at_check_line_file 38386 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 38387 at_status=$? 38388 grep '^ *+' $at_stder1 >&2 38389 grep -v '^ *+' $at_stder1 >$at_stderr 38390 at_failed=false 38391 $at_diff $at_devnull $at_stderr || at_failed=: 38392 $at_diff expout $at_stdout || at_failed=: 38393 case $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=:;; 38399 esac 38400 if $at_failed; then 38401 38402 echo 1 > $at_status_file 38403 exit 1 38404 fi 38405 38406 $at_traceon 38407 38408 38409 cat >input <<'_ATEOF' 38410 38411 +1 38412 _ATEOF 38413 38414 $at_traceoff 38415 echo "calc.at:596: \$PREPARSER ./calc input" 38416 echo calc.at:596 >$at_check_line_file 38417 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 38418 at_status=$? 38419 grep '^ *+' $at_stder1 >&2 38420 grep -v '^ *+' $at_stder1 >$at_stderr 38421 at_failed=false 38422 echo stderr:; tee stderr <$at_stderr 38423 $at_diff $at_devnull $at_stdout || at_failed=: 38424 case $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=:;; 38430 esac 38431 if $at_failed; then 38432 38433 echo 1 > $at_status_file 38434 exit 1 38435 fi 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. 38443 sed '/^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 38456 mv at-stderr stderr 38457 # 2. Create the reference error message. 38458 cat >expout <<'_ATEOF' 38459 2.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 38468 echo "calc.at:596: cat stderr" 38469 echo calc.at:596 >$at_check_line_file 38470 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 38471 at_status=$? 38472 grep '^ *+' $at_stder1 >&2 38473 grep -v '^ *+' $at_stder1 >$at_stderr 38474 at_failed=false 38475 $at_diff $at_devnull $at_stderr || at_failed=: 38476 $at_diff expout $at_stdout || at_failed=: 38477 case $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=:;; 38483 esac 38484 if $at_failed; then 38485 38486 echo 1 > $at_status_file 38487 exit 1 38488 fi 38489 38490 $at_traceon 38491 38492 38493 # Exercise error messages with EOF: work on an empty file. 38494 $at_traceoff 38495 echo "calc.at:596: \$PREPARSER ./calc /dev/null" 38496 echo calc.at:596 >$at_check_line_file 38497 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 38498 at_status=$? 38499 grep '^ *+' $at_stder1 >&2 38500 grep -v '^ *+' $at_stder1 >$at_stderr 38501 at_failed=false 38502 echo stderr:; tee stderr <$at_stderr 38503 $at_diff $at_devnull $at_stdout || at_failed=: 38504 case $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=:;; 38510 esac 38511 if $at_failed; then 38512 38513 echo 1 > $at_status_file 38514 exit 1 38515 fi 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. 38523 sed '/^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 38536 mv at-stderr stderr 38537 # 2. Create the reference error message. 38538 cat >expout <<'_ATEOF' 38539 1.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 38548 echo "calc.at:596: cat stderr" 38549 echo calc.at:596 >$at_check_line_file 38550 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 38551 at_status=$? 38552 grep '^ *+' $at_stder1 >&2 38553 grep -v '^ *+' $at_stder1 >$at_stderr 38554 at_failed=false 38555 $at_diff $at_devnull $at_stderr || at_failed=: 38556 $at_diff expout $at_stdout || at_failed=: 38557 case $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=:;; 38563 esac 38564 if $at_failed; then 38565 38566 echo 1 > $at_status_file 38567 exit 1 38568 fi 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 # 38590 cat >input <<'_ATEOF' 38591 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 38592 _ATEOF 38593 38594 $at_traceoff 38595 echo "calc.at:596: \$PREPARSER ./calc input" 38596 echo calc.at:596 >$at_check_line_file 38597 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 38598 at_status=$? 38599 grep '^ *+' $at_stder1 >&2 38600 grep -v '^ *+' $at_stder1 >$at_stderr 38601 at_failed=false 38602 echo stderr:; tee stderr <$at_stderr 38603 $at_diff $at_devnull $at_stdout || at_failed=: 38604 case $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=:;; 38610 esac 38611 if $at_failed; then 38612 38613 echo 1 > $at_status_file 38614 exit 1 38615 fi 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. 38623 sed '/^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 38636 mv at-stderr stderr 38637 # 2. Create the reference error message. 38638 cat >expout <<'_ATEOF' 38639 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 38640 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 38641 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 38642 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 38643 calc: 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 38652 echo "calc.at:596: cat stderr" 38653 echo calc.at:596 >$at_check_line_file 38654 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 38655 at_status=$? 38656 grep '^ *+' $at_stder1 >&2 38657 grep -v '^ *+' $at_stder1 >$at_stderr 38658 at_failed=false 38659 $at_diff $at_devnull $at_stderr || at_failed=: 38660 $at_diff expout $at_stdout || at_failed=: 38661 case $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=:;; 38667 esac 38668 if $at_failed; then 38669 38670 echo 1 > $at_status_file 38671 exit 1 38672 fi 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. 38680 cat >input <<'_ATEOF' 38681 (!) + (0 0) = 1 38682 _ATEOF 38683 38684 $at_traceoff 38685 echo "calc.at:596: \$PREPARSER ./calc input" 38686 echo calc.at:596 >$at_check_line_file 38687 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 38688 at_status=$? 38689 grep '^ *+' $at_stder1 >&2 38690 grep -v '^ *+' $at_stder1 >$at_stderr 38691 at_failed=false 38692 echo stderr:; tee stderr <$at_stderr 38693 $at_diff $at_devnull $at_stdout || at_failed=: 38694 case $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=:;; 38700 esac 38701 if $at_failed; then 38702 38703 echo 1 > $at_status_file 38704 exit 1 38705 fi 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. 38713 sed '/^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 38726 mv at-stderr stderr 38727 # 2. Create the reference error message. 38728 cat >expout <<'_ATEOF' 38729 1.9: syntax error, unexpected number 38730 calc: 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 38739 echo "calc.at:596: cat stderr" 38740 echo calc.at:596 >$at_check_line_file 38741 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 38742 at_status=$? 38743 grep '^ *+' $at_stder1 >&2 38744 grep -v '^ *+' $at_stder1 >$at_stderr 38745 at_failed=false 38746 $at_diff $at_devnull $at_stderr || at_failed=: 38747 $at_diff expout $at_stdout || at_failed=: 38748 case $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=:;; 38754 esac 38755 if $at_failed; then 38756 38757 echo 1 > $at_status_file 38758 exit 1 38759 fi 38760 38761 $at_traceon 38762 38763 38764 cat >input <<'_ATEOF' 38765 (- *) + (0 0) = 1 38766 _ATEOF 38767 38768 $at_traceoff 38769 echo "calc.at:596: \$PREPARSER ./calc input" 38770 echo calc.at:596 >$at_check_line_file 38771 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 38772 at_status=$? 38773 grep '^ *+' $at_stder1 >&2 38774 grep -v '^ *+' $at_stder1 >$at_stderr 38775 at_failed=false 38776 echo stderr:; tee stderr <$at_stderr 38777 $at_diff $at_devnull $at_stdout || at_failed=: 38778 case $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=:;; 38784 esac 38785 if $at_failed; then 38786 38787 echo 1 > $at_status_file 38788 exit 1 38789 fi 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. 38797 sed '/^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 38810 mv at-stderr stderr 38811 # 2. Create the reference error message. 38812 cat >expout <<'_ATEOF' 38813 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 38814 1.11: syntax error, unexpected number 38815 calc: 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 38824 echo "calc.at:596: cat stderr" 38825 echo calc.at:596 >$at_check_line_file 38826 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 38827 at_status=$? 38828 grep '^ *+' $at_stder1 >&2 38829 grep -v '^ *+' $at_stder1 >$at_stderr 38830 at_failed=false 38831 $at_diff $at_devnull $at_stderr || at_failed=: 38832 $at_diff expout $at_stdout || at_failed=: 38833 case $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=:;; 38839 esac 38840 if $at_failed; then 38841 38842 echo 1 > $at_status_file 38843 exit 1 38844 fi 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 38921 cat >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. */ 38950 typedef int semantic_value; 38951 38952 static semantic_value global_result = 0; 38953 static int global_count = 0; 38954 %} 38955 38956 /* Exercise %union. */ 38957 %union 38958 { 38959 semantic_value ival; 38960 }; 38961 38962 %{ 38963 static int power (int base, int exponent); 38964 /* yyerror receives the location if: 38965 - %location & %pure & %glr 38966 - %location & %pure & %yacc & %parse-param. */ 38967 static void yyerror ( 38968 38969 const char *s 38970 ); 38971 static int yylex (void); 38972 static int get_char (void); 38973 static 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 %% 38991 input: 38992 line 38993 | input line { } 38994 ; 38995 38996 line: 38997 '\n' 38998 | exp '\n' { USE ($1); } 38999 ; 39000 39001 exp: 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. */ 39022 static FILE *input; 39023 39024 static void 39025 yyerror ( 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 39045 static YYLTYPE last_yylloc; 39046 39047 static int 39048 get_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 39066 static void 39067 unget_char ( int c) 39068 { 39069 ; 39070 39071 /* Wrong when C == `\n'. */ 39072 (yylloc) = last_yylloc; 39073 39074 ungetc (c, input); 39075 } 39076 39077 static int 39078 read_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 39110 static int 39111 yylex (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 39154 static int 39155 power (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 39166 int 39167 main (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 39204 echo "calc.at:598: bison -o calc.c calc.y" 39205 echo calc.at:598 >$at_check_line_file 39206 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 39207 at_status=$? 39208 grep '^ *+' $at_stder1 >&2 39209 grep -v '^ *+' $at_stder1 >$at_stderr 39210 at_failed=false 39211 $at_diff $at_devnull $at_stderr || at_failed=: 39212 $at_diff $at_devnull $at_stdout || at_failed=: 39213 case $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=:;; 39219 esac 39220 if $at_failed; then 39221 39222 echo 1 > $at_status_file 39223 exit 1 39224 fi 39225 39226 $at_traceon 39227 39228 $at_traceoff 39229 echo "calc.at:598: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 39230 echo calc.at:598 >$at_check_line_file 39231 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 39232 at_status=$? 39233 grep '^ *+' $at_stder1 >&2 39234 grep -v '^ *+' $at_stder1 >$at_stderr 39235 at_failed=false 39236 echo stderr:; cat $at_stderr 39237 echo stdout:; cat $at_stdout 39238 case $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=:;; 39244 esac 39245 if $at_failed; then 39246 39247 echo 1 > $at_status_file 39248 exit 1 39249 fi 39250 39251 $at_traceon 39252 39253 39254 # Test the priorities. 39255 cat >input <<'_ATEOF' 39256 1 + 2 * 3 = 7 39257 1 + 2 * -3 = -5 39258 39259 -1^2 = -1 39260 (-1)^2 = 1 39261 39262 ---1 = -1 39263 39264 1 - 2 - 3 = -4 39265 1 - (2 - 3) = 2 39266 39267 2^2^3 = 256 39268 (2^2)^3 = 64 39269 _ATEOF 39270 39271 $at_traceoff 39272 echo "calc.at:598: \$PREPARSER ./calc input" 39273 echo calc.at:598 >$at_check_line_file 39274 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 39275 at_status=$? 39276 grep '^ *+' $at_stder1 >&2 39277 grep -v '^ *+' $at_stder1 >$at_stderr 39278 at_failed=false 39279 echo stderr:; tee stderr <$at_stderr 39280 $at_diff $at_devnull $at_stdout || at_failed=: 39281 case $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=:;; 39287 esac 39288 if $at_failed; then 39289 39290 echo 1 > $at_status_file 39291 exit 1 39292 fi 39293 39294 $at_traceon 39295 39296 39297 39298 # Some syntax errors. 39299 cat >input <<'_ATEOF' 39300 0 0 39301 _ATEOF 39302 39303 $at_traceoff 39304 echo "calc.at:598: \$PREPARSER ./calc input" 39305 echo calc.at:598 >$at_check_line_file 39306 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 39307 at_status=$? 39308 grep '^ *+' $at_stder1 >&2 39309 grep -v '^ *+' $at_stder1 >$at_stderr 39310 at_failed=false 39311 echo stderr:; tee stderr <$at_stderr 39312 $at_diff $at_devnull $at_stdout || at_failed=: 39313 case $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=:;; 39319 esac 39320 if $at_failed; then 39321 39322 echo 1 > $at_status_file 39323 exit 1 39324 fi 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. 39332 sed '/^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 39345 mv at-stderr stderr 39346 # 2. Create the reference error message. 39347 cat >expout <<'_ATEOF' 39348 1.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 39357 echo "calc.at:598: cat stderr" 39358 echo calc.at:598 >$at_check_line_file 39359 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 39360 at_status=$? 39361 grep '^ *+' $at_stder1 >&2 39362 grep -v '^ *+' $at_stder1 >$at_stderr 39363 at_failed=false 39364 $at_diff $at_devnull $at_stderr || at_failed=: 39365 $at_diff expout $at_stdout || at_failed=: 39366 case $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=:;; 39372 esac 39373 if $at_failed; then 39374 39375 echo 1 > $at_status_file 39376 exit 1 39377 fi 39378 39379 $at_traceon 39380 39381 39382 cat >input <<'_ATEOF' 39383 1//2 39384 _ATEOF 39385 39386 $at_traceoff 39387 echo "calc.at:598: \$PREPARSER ./calc input" 39388 echo calc.at:598 >$at_check_line_file 39389 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 39390 at_status=$? 39391 grep '^ *+' $at_stder1 >&2 39392 grep -v '^ *+' $at_stder1 >$at_stderr 39393 at_failed=false 39394 echo stderr:; tee stderr <$at_stderr 39395 $at_diff $at_devnull $at_stdout || at_failed=: 39396 case $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=:;; 39402 esac 39403 if $at_failed; then 39404 39405 echo 1 > $at_status_file 39406 exit 1 39407 fi 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. 39415 sed '/^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 39428 mv at-stderr stderr 39429 # 2. Create the reference error message. 39430 cat >expout <<'_ATEOF' 39431 1.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 39440 echo "calc.at:598: cat stderr" 39441 echo calc.at:598 >$at_check_line_file 39442 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 39443 at_status=$? 39444 grep '^ *+' $at_stder1 >&2 39445 grep -v '^ *+' $at_stder1 >$at_stderr 39446 at_failed=false 39447 $at_diff $at_devnull $at_stderr || at_failed=: 39448 $at_diff expout $at_stdout || at_failed=: 39449 case $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=:;; 39455 esac 39456 if $at_failed; then 39457 39458 echo 1 > $at_status_file 39459 exit 1 39460 fi 39461 39462 $at_traceon 39463 39464 39465 cat >input <<'_ATEOF' 39466 error 39467 _ATEOF 39468 39469 $at_traceoff 39470 echo "calc.at:598: \$PREPARSER ./calc input" 39471 echo calc.at:598 >$at_check_line_file 39472 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 39473 at_status=$? 39474 grep '^ *+' $at_stder1 >&2 39475 grep -v '^ *+' $at_stder1 >$at_stderr 39476 at_failed=false 39477 echo stderr:; tee stderr <$at_stderr 39478 $at_diff $at_devnull $at_stdout || at_failed=: 39479 case $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=:;; 39485 esac 39486 if $at_failed; then 39487 39488 echo 1 > $at_status_file 39489 exit 1 39490 fi 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. 39498 sed '/^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 39511 mv at-stderr stderr 39512 # 2. Create the reference error message. 39513 cat >expout <<'_ATEOF' 39514 1.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 39523 echo "calc.at:598: cat stderr" 39524 echo calc.at:598 >$at_check_line_file 39525 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 39526 at_status=$? 39527 grep '^ *+' $at_stder1 >&2 39528 grep -v '^ *+' $at_stder1 >$at_stderr 39529 at_failed=false 39530 $at_diff $at_devnull $at_stderr || at_failed=: 39531 $at_diff expout $at_stdout || at_failed=: 39532 case $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=:;; 39538 esac 39539 if $at_failed; then 39540 39541 echo 1 > $at_status_file 39542 exit 1 39543 fi 39544 39545 $at_traceon 39546 39547 39548 cat >input <<'_ATEOF' 39549 1 = 2 = 3 39550 _ATEOF 39551 39552 $at_traceoff 39553 echo "calc.at:598: \$PREPARSER ./calc input" 39554 echo calc.at:598 >$at_check_line_file 39555 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 39556 at_status=$? 39557 grep '^ *+' $at_stder1 >&2 39558 grep -v '^ *+' $at_stder1 >$at_stderr 39559 at_failed=false 39560 echo stderr:; tee stderr <$at_stderr 39561 $at_diff $at_devnull $at_stdout || at_failed=: 39562 case $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=:;; 39568 esac 39569 if $at_failed; then 39570 39571 echo 1 > $at_status_file 39572 exit 1 39573 fi 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. 39581 sed '/^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 39594 mv at-stderr stderr 39595 # 2. Create the reference error message. 39596 cat >expout <<'_ATEOF' 39597 1.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 39606 echo "calc.at:598: cat stderr" 39607 echo calc.at:598 >$at_check_line_file 39608 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 39609 at_status=$? 39610 grep '^ *+' $at_stder1 >&2 39611 grep -v '^ *+' $at_stder1 >$at_stderr 39612 at_failed=false 39613 $at_diff $at_devnull $at_stderr || at_failed=: 39614 $at_diff expout $at_stdout || at_failed=: 39615 case $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=:;; 39621 esac 39622 if $at_failed; then 39623 39624 echo 1 > $at_status_file 39625 exit 1 39626 fi 39627 39628 $at_traceon 39629 39630 39631 cat >input <<'_ATEOF' 39632 39633 +1 39634 _ATEOF 39635 39636 $at_traceoff 39637 echo "calc.at:598: \$PREPARSER ./calc input" 39638 echo calc.at:598 >$at_check_line_file 39639 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 39640 at_status=$? 39641 grep '^ *+' $at_stder1 >&2 39642 grep -v '^ *+' $at_stder1 >$at_stderr 39643 at_failed=false 39644 echo stderr:; tee stderr <$at_stderr 39645 $at_diff $at_devnull $at_stdout || at_failed=: 39646 case $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=:;; 39652 esac 39653 if $at_failed; then 39654 39655 echo 1 > $at_status_file 39656 exit 1 39657 fi 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. 39665 sed '/^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 39678 mv at-stderr stderr 39679 # 2. Create the reference error message. 39680 cat >expout <<'_ATEOF' 39681 2.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 39690 echo "calc.at:598: cat stderr" 39691 echo calc.at:598 >$at_check_line_file 39692 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 39693 at_status=$? 39694 grep '^ *+' $at_stder1 >&2 39695 grep -v '^ *+' $at_stder1 >$at_stderr 39696 at_failed=false 39697 $at_diff $at_devnull $at_stderr || at_failed=: 39698 $at_diff expout $at_stdout || at_failed=: 39699 case $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=:;; 39705 esac 39706 if $at_failed; then 39707 39708 echo 1 > $at_status_file 39709 exit 1 39710 fi 39711 39712 $at_traceon 39713 39714 39715 # Exercise error messages with EOF: work on an empty file. 39716 $at_traceoff 39717 echo "calc.at:598: \$PREPARSER ./calc /dev/null" 39718 echo calc.at:598 >$at_check_line_file 39719 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 39720 at_status=$? 39721 grep '^ *+' $at_stder1 >&2 39722 grep -v '^ *+' $at_stder1 >$at_stderr 39723 at_failed=false 39724 echo stderr:; tee stderr <$at_stderr 39725 $at_diff $at_devnull $at_stdout || at_failed=: 39726 case $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=:;; 39732 esac 39733 if $at_failed; then 39734 39735 echo 1 > $at_status_file 39736 exit 1 39737 fi 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. 39745 sed '/^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 39758 mv at-stderr stderr 39759 # 2. Create the reference error message. 39760 cat >expout <<'_ATEOF' 39761 1.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 39770 echo "calc.at:598: cat stderr" 39771 echo calc.at:598 >$at_check_line_file 39772 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 39773 at_status=$? 39774 grep '^ *+' $at_stder1 >&2 39775 grep -v '^ *+' $at_stder1 >$at_stderr 39776 at_failed=false 39777 $at_diff $at_devnull $at_stderr || at_failed=: 39778 $at_diff expout $at_stdout || at_failed=: 39779 case $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=:;; 39785 esac 39786 if $at_failed; then 39787 39788 echo 1 > $at_status_file 39789 exit 1 39790 fi 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 # 39812 cat >input <<'_ATEOF' 39813 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 39814 _ATEOF 39815 39816 $at_traceoff 39817 echo "calc.at:598: \$PREPARSER ./calc input" 39818 echo calc.at:598 >$at_check_line_file 39819 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 39820 at_status=$? 39821 grep '^ *+' $at_stder1 >&2 39822 grep -v '^ *+' $at_stder1 >$at_stderr 39823 at_failed=false 39824 echo stderr:; tee stderr <$at_stderr 39825 $at_diff $at_devnull $at_stdout || at_failed=: 39826 case $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=:;; 39832 esac 39833 if $at_failed; then 39834 39835 echo 1 > $at_status_file 39836 exit 1 39837 fi 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. 39845 sed '/^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 39858 mv at-stderr stderr 39859 # 2. Create the reference error message. 39860 cat >expout <<'_ATEOF' 39861 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 39862 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 39863 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 39864 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 39865 calc: 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 39874 echo "calc.at:598: cat stderr" 39875 echo calc.at:598 >$at_check_line_file 39876 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 39877 at_status=$? 39878 grep '^ *+' $at_stder1 >&2 39879 grep -v '^ *+' $at_stder1 >$at_stderr 39880 at_failed=false 39881 $at_diff $at_devnull $at_stderr || at_failed=: 39882 $at_diff expout $at_stdout || at_failed=: 39883 case $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=:;; 39889 esac 39890 if $at_failed; then 39891 39892 echo 1 > $at_status_file 39893 exit 1 39894 fi 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. 39902 cat >input <<'_ATEOF' 39903 (!) + (0 0) = 1 39904 _ATEOF 39905 39906 $at_traceoff 39907 echo "calc.at:598: \$PREPARSER ./calc input" 39908 echo calc.at:598 >$at_check_line_file 39909 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 39910 at_status=$? 39911 grep '^ *+' $at_stder1 >&2 39912 grep -v '^ *+' $at_stder1 >$at_stderr 39913 at_failed=false 39914 echo stderr:; tee stderr <$at_stderr 39915 $at_diff $at_devnull $at_stdout || at_failed=: 39916 case $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=:;; 39922 esac 39923 if $at_failed; then 39924 39925 echo 1 > $at_status_file 39926 exit 1 39927 fi 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. 39935 sed '/^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 39948 mv at-stderr stderr 39949 # 2. Create the reference error message. 39950 cat >expout <<'_ATEOF' 39951 1.9: syntax error, unexpected number 39952 calc: 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 39961 echo "calc.at:598: cat stderr" 39962 echo calc.at:598 >$at_check_line_file 39963 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 39964 at_status=$? 39965 grep '^ *+' $at_stder1 >&2 39966 grep -v '^ *+' $at_stder1 >$at_stderr 39967 at_failed=false 39968 $at_diff $at_devnull $at_stderr || at_failed=: 39969 $at_diff expout $at_stdout || at_failed=: 39970 case $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=:;; 39976 esac 39977 if $at_failed; then 39978 39979 echo 1 > $at_status_file 39980 exit 1 39981 fi 39982 39983 $at_traceon 39984 39985 39986 cat >input <<'_ATEOF' 39987 (- *) + (0 0) = 1 39988 _ATEOF 39989 39990 $at_traceoff 39991 echo "calc.at:598: \$PREPARSER ./calc input" 39992 echo calc.at:598 >$at_check_line_file 39993 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 39994 at_status=$? 39995 grep '^ *+' $at_stder1 >&2 39996 grep -v '^ *+' $at_stder1 >$at_stderr 39997 at_failed=false 39998 echo stderr:; tee stderr <$at_stderr 39999 $at_diff $at_devnull $at_stdout || at_failed=: 40000 case $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=:;; 40006 esac 40007 if $at_failed; then 40008 40009 echo 1 > $at_status_file 40010 exit 1 40011 fi 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. 40019 sed '/^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 40032 mv at-stderr stderr 40033 # 2. Create the reference error message. 40034 cat >expout <<'_ATEOF' 40035 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 40036 1.11: syntax error, unexpected number 40037 calc: 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 40046 echo "calc.at:598: cat stderr" 40047 echo calc.at:598 >$at_check_line_file 40048 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 40049 at_status=$? 40050 grep '^ *+' $at_stder1 >&2 40051 grep -v '^ *+' $at_stder1 >$at_stderr 40052 at_failed=false 40053 $at_diff $at_devnull $at_stderr || at_failed=: 40054 $at_diff expout $at_stdout || at_failed=: 40055 case $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=:;; 40061 esac 40062 if $at_failed; then 40063 40064 echo 1 > $at_status_file 40065 exit 1 40066 fi 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 40143 cat >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. */ 40172 typedef int semantic_value; 40173 40174 static semantic_value global_result = 0; 40175 static int global_count = 0; 40176 %} 40177 40178 /* Exercise %union. */ 40179 %union 40180 { 40181 semantic_value ival; 40182 }; 40183 40184 %{ 40185 static int power (int base, int exponent); 40186 /* yyerror receives the location if: 40187 - %location & %pure & %glr 40188 - %location & %pure & %yacc & %parse-param. */ 40189 static void yyerror ( 40190 40191 const char *s 40192 ); 40193 static int yylex (void); 40194 static int get_char (void); 40195 static 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 %% 40213 input: 40214 line 40215 | input line { } 40216 ; 40217 40218 line: 40219 '\n' 40220 | exp '\n' { USE ($1); } 40221 ; 40222 40223 exp: 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. */ 40244 static FILE *input; 40245 40246 static void 40247 yyerror ( 40248 40249 const char *s) 40250 { 40251 40252 40253 fprintf (stderr, "%s\n", s); 40254 } 40255 40256 40257 40258 static int 40259 get_char (void) 40260 { 40261 int res = getc (input); 40262 ; 40263 40264 return res; 40265 } 40266 40267 40268 static void 40269 unget_char ( int c) 40270 { 40271 ; 40272 40273 ungetc (c, input); 40274 } 40275 40276 static int 40277 read_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 40309 static int 40310 yylex (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 40345 static int 40346 power (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 40357 int 40358 main (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 40395 echo "calc.at:600: bison -o calc.c calc.y" 40396 echo calc.at:600 >$at_check_line_file 40397 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 40398 at_status=$? 40399 grep '^ *+' $at_stder1 >&2 40400 grep -v '^ *+' $at_stder1 >$at_stderr 40401 at_failed=false 40402 $at_diff $at_devnull $at_stderr || at_failed=: 40403 $at_diff $at_devnull $at_stdout || at_failed=: 40404 case $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=:;; 40410 esac 40411 if $at_failed; then 40412 40413 echo 1 > $at_status_file 40414 exit 1 40415 fi 40416 40417 $at_traceon 40418 40419 $at_traceoff 40420 echo "calc.at:600: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 40421 echo calc.at:600 >$at_check_line_file 40422 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 40423 at_status=$? 40424 grep '^ *+' $at_stder1 >&2 40425 grep -v '^ *+' $at_stder1 >$at_stderr 40426 at_failed=false 40427 echo stderr:; cat $at_stderr 40428 echo stdout:; cat $at_stdout 40429 case $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=:;; 40435 esac 40436 if $at_failed; then 40437 40438 echo 1 > $at_status_file 40439 exit 1 40440 fi 40441 40442 $at_traceon 40443 40444 40445 # Test the priorities. 40446 cat >input <<'_ATEOF' 40447 1 + 2 * 3 = 7 40448 1 + 2 * -3 = -5 40449 40450 -1^2 = -1 40451 (-1)^2 = 1 40452 40453 ---1 = -1 40454 40455 1 - 2 - 3 = -4 40456 1 - (2 - 3) = 2 40457 40458 2^2^3 = 256 40459 (2^2)^3 = 64 40460 _ATEOF 40461 40462 $at_traceoff 40463 echo "calc.at:600: \$PREPARSER ./calc input" 40464 echo calc.at:600 >$at_check_line_file 40465 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 40466 at_status=$? 40467 grep '^ *+' $at_stder1 >&2 40468 grep -v '^ *+' $at_stder1 >$at_stderr 40469 at_failed=false 40470 echo stderr:; tee stderr <$at_stderr 40471 $at_diff $at_devnull $at_stdout || at_failed=: 40472 case $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=:;; 40478 esac 40479 if $at_failed; then 40480 40481 echo 1 > $at_status_file 40482 exit 1 40483 fi 40484 40485 $at_traceon 40486 40487 40488 40489 # Some syntax errors. 40490 cat >input <<'_ATEOF' 40491 0 0 40492 _ATEOF 40493 40494 $at_traceoff 40495 echo "calc.at:600: \$PREPARSER ./calc input" 40496 echo calc.at:600 >$at_check_line_file 40497 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 40498 at_status=$? 40499 grep '^ *+' $at_stder1 >&2 40500 grep -v '^ *+' $at_stder1 >$at_stderr 40501 at_failed=false 40502 echo stderr:; tee stderr <$at_stderr 40503 $at_diff $at_devnull $at_stdout || at_failed=: 40504 case $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=:;; 40510 esac 40511 if $at_failed; then 40512 40513 echo 1 > $at_status_file 40514 exit 1 40515 fi 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. 40523 sed '/^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 40536 mv at-stderr stderr 40537 # 2. Create the reference error message. 40538 cat >expout <<'_ATEOF' 40539 1.2: syntax error, unexpected number 40540 _ATEOF 40541 40542 # 3. If locations are not used, remove them. 40543 sed 's/^[-0-9.]*: //' expout >at-expout 40544 mv at-expout expout 40545 # 4. If error-verbose is not used, strip the`, unexpected....' part. 40546 sed 's/syntax error, .*$/syntax error/' expout >at-expout 40547 mv at-expout expout 40548 # 5. Check 40549 $at_traceoff 40550 echo "calc.at:600: cat stderr" 40551 echo calc.at:600 >$at_check_line_file 40552 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 40553 at_status=$? 40554 grep '^ *+' $at_stder1 >&2 40555 grep -v '^ *+' $at_stder1 >$at_stderr 40556 at_failed=false 40557 $at_diff $at_devnull $at_stderr || at_failed=: 40558 $at_diff expout $at_stdout || at_failed=: 40559 case $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=:;; 40565 esac 40566 if $at_failed; then 40567 40568 echo 1 > $at_status_file 40569 exit 1 40570 fi 40571 40572 $at_traceon 40573 40574 40575 cat >input <<'_ATEOF' 40576 1//2 40577 _ATEOF 40578 40579 $at_traceoff 40580 echo "calc.at:600: \$PREPARSER ./calc input" 40581 echo calc.at:600 >$at_check_line_file 40582 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 40583 at_status=$? 40584 grep '^ *+' $at_stder1 >&2 40585 grep -v '^ *+' $at_stder1 >$at_stderr 40586 at_failed=false 40587 echo stderr:; tee stderr <$at_stderr 40588 $at_diff $at_devnull $at_stdout || at_failed=: 40589 case $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=:;; 40595 esac 40596 if $at_failed; then 40597 40598 echo 1 > $at_status_file 40599 exit 1 40600 fi 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. 40608 sed '/^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 40621 mv at-stderr stderr 40622 # 2. Create the reference error message. 40623 cat >expout <<'_ATEOF' 40624 1.2: syntax error, unexpected '/', expecting number or '-' or '(' or '!' 40625 _ATEOF 40626 40627 # 3. If locations are not used, remove them. 40628 sed 's/^[-0-9.]*: //' expout >at-expout 40629 mv at-expout expout 40630 # 4. If error-verbose is not used, strip the`, unexpected....' part. 40631 sed 's/syntax error, .*$/syntax error/' expout >at-expout 40632 mv at-expout expout 40633 # 5. Check 40634 $at_traceoff 40635 echo "calc.at:600: cat stderr" 40636 echo calc.at:600 >$at_check_line_file 40637 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 40638 at_status=$? 40639 grep '^ *+' $at_stder1 >&2 40640 grep -v '^ *+' $at_stder1 >$at_stderr 40641 at_failed=false 40642 $at_diff $at_devnull $at_stderr || at_failed=: 40643 $at_diff expout $at_stdout || at_failed=: 40644 case $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=:;; 40650 esac 40651 if $at_failed; then 40652 40653 echo 1 > $at_status_file 40654 exit 1 40655 fi 40656 40657 $at_traceon 40658 40659 40660 cat >input <<'_ATEOF' 40661 error 40662 _ATEOF 40663 40664 $at_traceoff 40665 echo "calc.at:600: \$PREPARSER ./calc input" 40666 echo calc.at:600 >$at_check_line_file 40667 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 40668 at_status=$? 40669 grep '^ *+' $at_stder1 >&2 40670 grep -v '^ *+' $at_stder1 >$at_stderr 40671 at_failed=false 40672 echo stderr:; tee stderr <$at_stderr 40673 $at_diff $at_devnull $at_stdout || at_failed=: 40674 case $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=:;; 40680 esac 40681 if $at_failed; then 40682 40683 echo 1 > $at_status_file 40684 exit 1 40685 fi 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. 40693 sed '/^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 40706 mv at-stderr stderr 40707 # 2. Create the reference error message. 40708 cat >expout <<'_ATEOF' 40709 1.0: syntax error, unexpected $undefined 40710 _ATEOF 40711 40712 # 3. If locations are not used, remove them. 40713 sed 's/^[-0-9.]*: //' expout >at-expout 40714 mv at-expout expout 40715 # 4. If error-verbose is not used, strip the`, unexpected....' part. 40716 sed 's/syntax error, .*$/syntax error/' expout >at-expout 40717 mv at-expout expout 40718 # 5. Check 40719 $at_traceoff 40720 echo "calc.at:600: cat stderr" 40721 echo calc.at:600 >$at_check_line_file 40722 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 40723 at_status=$? 40724 grep '^ *+' $at_stder1 >&2 40725 grep -v '^ *+' $at_stder1 >$at_stderr 40726 at_failed=false 40727 $at_diff $at_devnull $at_stderr || at_failed=: 40728 $at_diff expout $at_stdout || at_failed=: 40729 case $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=:;; 40735 esac 40736 if $at_failed; then 40737 40738 echo 1 > $at_status_file 40739 exit 1 40740 fi 40741 40742 $at_traceon 40743 40744 40745 cat >input <<'_ATEOF' 40746 1 = 2 = 3 40747 _ATEOF 40748 40749 $at_traceoff 40750 echo "calc.at:600: \$PREPARSER ./calc input" 40751 echo calc.at:600 >$at_check_line_file 40752 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 40753 at_status=$? 40754 grep '^ *+' $at_stder1 >&2 40755 grep -v '^ *+' $at_stder1 >$at_stderr 40756 at_failed=false 40757 echo stderr:; tee stderr <$at_stderr 40758 $at_diff $at_devnull $at_stdout || at_failed=: 40759 case $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=:;; 40765 esac 40766 if $at_failed; then 40767 40768 echo 1 > $at_status_file 40769 exit 1 40770 fi 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. 40778 sed '/^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 40791 mv at-stderr stderr 40792 # 2. Create the reference error message. 40793 cat >expout <<'_ATEOF' 40794 1.6: syntax error, unexpected '=' 40795 _ATEOF 40796 40797 # 3. If locations are not used, remove them. 40798 sed 's/^[-0-9.]*: //' expout >at-expout 40799 mv at-expout expout 40800 # 4. If error-verbose is not used, strip the`, unexpected....' part. 40801 sed 's/syntax error, .*$/syntax error/' expout >at-expout 40802 mv at-expout expout 40803 # 5. Check 40804 $at_traceoff 40805 echo "calc.at:600: cat stderr" 40806 echo calc.at:600 >$at_check_line_file 40807 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 40808 at_status=$? 40809 grep '^ *+' $at_stder1 >&2 40810 grep -v '^ *+' $at_stder1 >$at_stderr 40811 at_failed=false 40812 $at_diff $at_devnull $at_stderr || at_failed=: 40813 $at_diff expout $at_stdout || at_failed=: 40814 case $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=:;; 40820 esac 40821 if $at_failed; then 40822 40823 echo 1 > $at_status_file 40824 exit 1 40825 fi 40826 40827 $at_traceon 40828 40829 40830 cat >input <<'_ATEOF' 40831 40832 +1 40833 _ATEOF 40834 40835 $at_traceoff 40836 echo "calc.at:600: \$PREPARSER ./calc input" 40837 echo calc.at:600 >$at_check_line_file 40838 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 40839 at_status=$? 40840 grep '^ *+' $at_stder1 >&2 40841 grep -v '^ *+' $at_stder1 >$at_stderr 40842 at_failed=false 40843 echo stderr:; tee stderr <$at_stderr 40844 $at_diff $at_devnull $at_stdout || at_failed=: 40845 case $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=:;; 40851 esac 40852 if $at_failed; then 40853 40854 echo 1 > $at_status_file 40855 exit 1 40856 fi 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. 40864 sed '/^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 40877 mv at-stderr stderr 40878 # 2. Create the reference error message. 40879 cat >expout <<'_ATEOF' 40880 2.0: syntax error, unexpected '+' 40881 _ATEOF 40882 40883 # 3. If locations are not used, remove them. 40884 sed 's/^[-0-9.]*: //' expout >at-expout 40885 mv at-expout expout 40886 # 4. If error-verbose is not used, strip the`, unexpected....' part. 40887 sed 's/syntax error, .*$/syntax error/' expout >at-expout 40888 mv at-expout expout 40889 # 5. Check 40890 $at_traceoff 40891 echo "calc.at:600: cat stderr" 40892 echo calc.at:600 >$at_check_line_file 40893 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 40894 at_status=$? 40895 grep '^ *+' $at_stder1 >&2 40896 grep -v '^ *+' $at_stder1 >$at_stderr 40897 at_failed=false 40898 $at_diff $at_devnull $at_stderr || at_failed=: 40899 $at_diff expout $at_stdout || at_failed=: 40900 case $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=:;; 40906 esac 40907 if $at_failed; then 40908 40909 echo 1 > $at_status_file 40910 exit 1 40911 fi 40912 40913 $at_traceon 40914 40915 40916 # Exercise error messages with EOF: work on an empty file. 40917 $at_traceoff 40918 echo "calc.at:600: \$PREPARSER ./calc /dev/null" 40919 echo calc.at:600 >$at_check_line_file 40920 ( $at_traceon; $PREPARSER ./calc /dev/null ) >$at_stdout 2>$at_stder1 40921 at_status=$? 40922 grep '^ *+' $at_stder1 >&2 40923 grep -v '^ *+' $at_stder1 >$at_stderr 40924 at_failed=false 40925 echo stderr:; tee stderr <$at_stderr 40926 $at_diff $at_devnull $at_stdout || at_failed=: 40927 case $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=:;; 40933 esac 40934 if $at_failed; then 40935 40936 echo 1 > $at_status_file 40937 exit 1 40938 fi 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. 40946 sed '/^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 40959 mv at-stderr stderr 40960 # 2. Create the reference error message. 40961 cat >expout <<'_ATEOF' 40962 1.0: syntax error, unexpected end of input 40963 _ATEOF 40964 40965 # 3. If locations are not used, remove them. 40966 sed 's/^[-0-9.]*: //' expout >at-expout 40967 mv at-expout expout 40968 # 4. If error-verbose is not used, strip the`, unexpected....' part. 40969 sed 's/syntax error, .*$/syntax error/' expout >at-expout 40970 mv at-expout expout 40971 # 5. Check 40972 $at_traceoff 40973 echo "calc.at:600: cat stderr" 40974 echo calc.at:600 >$at_check_line_file 40975 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 40976 at_status=$? 40977 grep '^ *+' $at_stder1 >&2 40978 grep -v '^ *+' $at_stder1 >$at_stderr 40979 at_failed=false 40980 $at_diff $at_devnull $at_stderr || at_failed=: 40981 $at_diff expout $at_stdout || at_failed=: 40982 case $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=:;; 40988 esac 40989 if $at_failed; then 40990 40991 echo 1 > $at_status_file 40992 exit 1 40993 fi 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 # 41015 cat >input <<'_ATEOF' 41016 () + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1 41017 _ATEOF 41018 41019 $at_traceoff 41020 echo "calc.at:600: \$PREPARSER ./calc input" 41021 echo calc.at:600 >$at_check_line_file 41022 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 41023 at_status=$? 41024 grep '^ *+' $at_stder1 >&2 41025 grep -v '^ *+' $at_stder1 >$at_stderr 41026 at_failed=false 41027 echo stderr:; tee stderr <$at_stderr 41028 $at_diff $at_devnull $at_stdout || at_failed=: 41029 case $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=:;; 41035 esac 41036 if $at_failed; then 41037 41038 echo 1 > $at_status_file 41039 exit 1 41040 fi 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. 41048 sed '/^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 41061 mv at-stderr stderr 41062 # 2. Create the reference error message. 41063 cat >expout <<'_ATEOF' 41064 1.1: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 41065 1.17: syntax error, unexpected ')', expecting number or '-' or '(' or '!' 41066 1.22: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 41067 1.40: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 41068 calc: error: 4444 != 1 41069 _ATEOF 41070 41071 # 3. If locations are not used, remove them. 41072 sed 's/^[-0-9.]*: //' expout >at-expout 41073 mv at-expout expout 41074 # 4. If error-verbose is not used, strip the`, unexpected....' part. 41075 sed 's/syntax error, .*$/syntax error/' expout >at-expout 41076 mv at-expout expout 41077 # 5. Check 41078 $at_traceoff 41079 echo "calc.at:600: cat stderr" 41080 echo calc.at:600 >$at_check_line_file 41081 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 41082 at_status=$? 41083 grep '^ *+' $at_stder1 >&2 41084 grep -v '^ *+' $at_stder1 >$at_stderr 41085 at_failed=false 41086 $at_diff $at_devnull $at_stderr || at_failed=: 41087 $at_diff expout $at_stdout || at_failed=: 41088 case $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=:;; 41094 esac 41095 if $at_failed; then 41096 41097 echo 1 > $at_status_file 41098 exit 1 41099 fi 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. 41107 cat >input <<'_ATEOF' 41108 (!) + (0 0) = 1 41109 _ATEOF 41110 41111 $at_traceoff 41112 echo "calc.at:600: \$PREPARSER ./calc input" 41113 echo calc.at:600 >$at_check_line_file 41114 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 41115 at_status=$? 41116 grep '^ *+' $at_stder1 >&2 41117 grep -v '^ *+' $at_stder1 >$at_stderr 41118 at_failed=false 41119 echo stderr:; tee stderr <$at_stderr 41120 $at_diff $at_devnull $at_stdout || at_failed=: 41121 case $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=:;; 41127 esac 41128 if $at_failed; then 41129 41130 echo 1 > $at_status_file 41131 exit 1 41132 fi 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. 41140 sed '/^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 41153 mv at-stderr stderr 41154 # 2. Create the reference error message. 41155 cat >expout <<'_ATEOF' 41156 1.9: syntax error, unexpected number 41157 calc: error: 2222 != 1 41158 _ATEOF 41159 41160 # 3. If locations are not used, remove them. 41161 sed 's/^[-0-9.]*: //' expout >at-expout 41162 mv at-expout expout 41163 # 4. If error-verbose is not used, strip the`, unexpected....' part. 41164 sed 's/syntax error, .*$/syntax error/' expout >at-expout 41165 mv at-expout expout 41166 # 5. Check 41167 $at_traceoff 41168 echo "calc.at:600: cat stderr" 41169 echo calc.at:600 >$at_check_line_file 41170 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 41171 at_status=$? 41172 grep '^ *+' $at_stder1 >&2 41173 grep -v '^ *+' $at_stder1 >$at_stderr 41174 at_failed=false 41175 $at_diff $at_devnull $at_stderr || at_failed=: 41176 $at_diff expout $at_stdout || at_failed=: 41177 case $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=:;; 41183 esac 41184 if $at_failed; then 41185 41186 echo 1 > $at_status_file 41187 exit 1 41188 fi 41189 41190 $at_traceon 41191 41192 41193 cat >input <<'_ATEOF' 41194 (- *) + (0 0) = 1 41195 _ATEOF 41196 41197 $at_traceoff 41198 echo "calc.at:600: \$PREPARSER ./calc input" 41199 echo calc.at:600 >$at_check_line_file 41200 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 41201 at_status=$? 41202 grep '^ *+' $at_stder1 >&2 41203 grep -v '^ *+' $at_stder1 >$at_stderr 41204 at_failed=false 41205 echo stderr:; tee stderr <$at_stderr 41206 $at_diff $at_devnull $at_stdout || at_failed=: 41207 case $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=:;; 41213 esac 41214 if $at_failed; then 41215 41216 echo 1 > $at_status_file 41217 exit 1 41218 fi 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. 41226 sed '/^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 41239 mv at-stderr stderr 41240 # 2. Create the reference error message. 41241 cat >expout <<'_ATEOF' 41242 1.3: syntax error, unexpected '*', expecting number or '-' or '(' or '!' 41243 1.11: syntax error, unexpected number 41244 calc: error: 2222 != 1 41245 _ATEOF 41246 41247 # 3. If locations are not used, remove them. 41248 sed 's/^[-0-9.]*: //' expout >at-expout 41249 mv at-expout expout 41250 # 4. If error-verbose is not used, strip the`, unexpected....' part. 41251 sed 's/syntax error, .*$/syntax error/' expout >at-expout 41252 mv at-expout expout 41253 # 5. Check 41254 $at_traceoff 41255 echo "calc.at:600: cat stderr" 41256 echo calc.at:600 >$at_check_line_file 41257 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 41258 at_status=$? 41259 grep '^ *+' $at_stder1 >&2 41260 grep -v '^ *+' $at_stder1 >$at_stderr 41261 at_failed=false 41262 $at_diff $at_devnull $at_stderr || at_failed=: 41263 $at_diff expout $at_stdout || at_failed=: 41264 case $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=:;; 41270 esac 41271 if $at_failed; then 41272 41273 echo 1 > $at_status_file 41274 exit 1 41275 fi 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 41352 cat >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. */ 41381 typedef int semantic_value; 41382 41383 static semantic_value global_result = 0; 41384 static int global_count = 0; 41385 %} 41386 41387 /* Exercise %union. */ 41388 %union 41389 { 41390 semantic_value ival; 41391 }; 41392 41393 %{ 41394 static int power (int base, int exponent); 41395 /* yyerror receives the location if: 41396 - %location & %pure & %glr 41397 - %location & %pure & %yacc & %parse-param. */ 41398 static void yyerror ( 41399 41400 const char *s 41401 ); 41402 static int yylex (void); 41403 static int get_char (void); 41404 static 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 %% 41422 input: 41423 line 41424 | input line { } 41425 ; 41426 41427 line: 41428 '\n' 41429 | exp '\n' { USE ($1); } 41430 ; 41431 41432 exp: 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. */ 41453 static FILE *input; 41454 41455 static void 41456 yyerror ( 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 41476 static YYLTYPE last_yylloc; 41477 41478 static int 41479 get_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 41497 static void 41498 unget_char ( int c) 41499 { 41500 ; 41501 41502 /* Wrong when C == `\n'. */ 41503 (yylloc) = last_yylloc; 41504 41505 ungetc (c, input); 41506 } 41507 41508 static int 41509 read_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 41541 static int 41542 yylex (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 41585 static int 41586 power (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 41597 int 41598 main (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 41635 echo "calc.at:601: bison -o calc.c calc.y" 41636 echo calc.at:601 >$at_check_line_file 41637 ( $at_traceon; bison -o calc.c calc.y ) >$at_stdout 2>$at_stder1 41638 at_status=$? 41639 grep '^ *+' $at_stder1 >&2 41640 grep -v '^ *+' $at_stder1 >$at_stderr 41641 at_failed=false 41642 $at_diff $at_devnull $at_stderr || at_failed=: 41643 $at_diff $at_devnull $at_stdout || at_failed=: 41644 case $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=:;; 41650 esac 41651 if $at_failed; then 41652 41653 echo 1 > $at_status_file 41654 exit 1 41655 fi 41656 41657 $at_traceon 41658 41659 $at_traceoff 41660 echo "calc.at:601: \$CC \$CFLAGS \$CPPFLAGS \$LDFLAGS -o calc calc.c \$LIBS" 41661 echo calc.at:601 >$at_check_line_file 41662 ( $at_traceon; $CC $CFLAGS $CPPFLAGS $LDFLAGS -o calc calc.c $LIBS ) >$at_stdout 2>$at_stder1 41663 at_status=$? 41664 grep '^ *+' $at_stder1 >&2 41665 grep -v '^ *+' $at_stder1 >$at_stderr 41666 at_failed=false 41667 echo stderr:; cat $at_stderr 41668 echo stdout:; cat $at_stdout 41669 case $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=:;; 41675 esac 41676 if $at_failed; then 41677 41678 echo 1 > $at_status_file 41679 exit 1 41680 fi 41681 41682 $at_traceon 41683 41684 41685 # Test the priorities. 41686 cat >input <<'_ATEOF' 41687 1 + 2 * 3 = 7 41688 1 + 2 * -3 = -5 41689 41690 -1^2 = -1 41691 (-1)^2 = 1 41692 41693 ---1 = -1 41694 41695 1 - 2 - 3 = -4 41696 1 - (2 - 3) = 2 41697 41698 2^2^3 = 256 41699 (2^2)^3 = 64 41700 _ATEOF 41701 41702 $at_traceoff 41703 echo "calc.at:601: \$PREPARSER ./calc input" 41704 echo calc.at:601 >$at_check_line_file 41705 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 41706 at_status=$? 41707 grep '^ *+' $at_stder1 >&2 41708 grep -v '^ *+' $at_stder1 >$at_stderr 41709 at_failed=false 41710 echo stderr:; tee stderr <$at_stderr 41711 $at_diff $at_devnull $at_stdout || at_failed=: 41712 case $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=:;; 41718 esac 41719 if $at_failed; then 41720 41721 echo 1 > $at_status_file 41722 exit 1 41723 fi 41724 41725 $at_traceon 41726 41727 41728 41729 # Some syntax errors. 41730 cat >input <<'_ATEOF' 41731 0 0 41732 _ATEOF 41733 41734 $at_traceoff 41735 echo "calc.at:601: \$PREPARSER ./calc input" 41736 echo calc.at:601 >$at_check_line_file 41737 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 41738 at_status=$? 41739 grep '^ *+' $at_stder1 >&2 41740 grep -v '^ *+' $at_stder1 >$at_stderr 41741 at_failed=false 41742 echo stderr:; tee stderr <$at_stderr 41743 $at_diff $at_devnull $at_stdout || at_failed=: 41744 case $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=:;; 41750 esac 41751 if $at_failed; then 41752 41753 echo 1 > $at_status_file 41754 exit 1 41755 fi 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. 41763 sed '/^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 41776 mv at-stderr stderr 41777 # 2. Create the reference error message. 41778 cat >expout <<'_ATEOF' 41779 1.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 41788 echo "calc.at:601: cat stderr" 41789 echo calc.at:601 >$at_check_line_file 41790 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 41791 at_status=$? 41792 grep '^ *+' $at_stder1 >&2 41793 grep -v '^ *+' $at_stder1 >$at_stderr 41794 at_failed=false 41795 $at_diff $at_devnull $at_stderr || at_failed=: 41796 $at_diff expout $at_stdout || at_failed=: 41797 case $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=:;; 41803 esac 41804 if $at_failed; then 41805 41806 echo 1 > $at_status_file 41807 exit 1 41808 fi 41809 41810 $at_traceon 41811 41812 41813 cat >input <<'_ATEOF' 41814 1//2 41815 _ATEOF 41816 41817 $at_traceoff 41818 echo "calc.at:601: \$PREPARSER ./calc input" 41819 echo calc.at:601 >$at_check_line_file 41820 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 41821 at_status=$? 41822 grep '^ *+' $at_stder1 >&2 41823 grep -v '^ *+' $at_stder1 >$at_stderr 41824 at_failed=false 41825 echo stderr:; tee stderr <$at_stderr 41826 $at_diff $at_devnull $at_stdout || at_failed=: 41827 case $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=:;; 41833 esac 41834 if $at_failed; then 41835 41836 echo 1 > $at_status_file 41837 exit 1 41838 fi 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. 41846 sed '/^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 41859 mv at-stderr stderr 41860 # 2. Create the reference error message. 41861 cat >expout <<'_ATEOF' 41862 1.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 41871 echo "calc.at:601: cat stderr" 41872 echo calc.at:601 >$at_check_line_file 41873 ( $at_traceon; cat stderr ) >$at_stdout 2>$at_stder1 41874 at_status=$? 41875 grep '^ *+' $at_stder1 >&2 41876 grep -v '^ *+' $at_stder1 >$at_stderr 41877 at_failed=false 41878 $at_diff $at_devnull $at_stderr || at_failed=: 41879 $at_diff expout $at_stdout || at_failed=: 41880 case $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=:;; 41886 esac 41887 if $at_failed; then 41888 41889 echo 1 > $at_status_file 41890 exit 1 41891 fi 41892 41893 $at_traceon 41894 41895 41896 cat >input <<'_ATEOF' 41897 error 41898 _ATEOF 41899 41900 $at_traceoff 41901 echo "calc.at:601: \$PREPARSER ./calc input" 41902 echo calc.at:601 >$at_check_line_file 41903 ( $at_traceon; $PREPARSER ./calc input ) >$at_stdout 2>$at_stder1 41904 at_status=$? 41905 grep '^ *+' $at_stder1 >&2 41906 grep -v '^ *+' $at_stder1 >$at_stderr 41907 at_failed=false 41908 echo stderr:; tee stderr <$at_stderr 41909 $at_diff $at_devnull $at_stdout || at_failed=: 41910 case $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=:;; 41916 esac 41917 if $at_failed; then 41918 41919 echo 1 > $at_status_file 41920 exit 1 41921 fi 4