Imported Upstream version 20100610 upstream/20100610
authorDongHun Kwak <dh0128.kwak@samsung.com>
Fri, 1 Oct 2021 05:44:51 +0000 (14:44 +0900)
committerDongHun Kwak <dh0128.kwak@samsung.com>
Fri, 1 Oct 2021 05:44:51 +0000 (14:44 +0900)
75 files changed:
.@-RCS [deleted symlink]
AUTHORS [new file with mode: 0644]
CHANGES
VERSION
aclocal.m4
closure.c
configure
configure.in
defs.h
error.c
lr0.c
main.c
makefile.in
mkdirs.sh [deleted file]
mkpar.c
output.c
package/byacc.spec [new file with mode: 0644]
package/debian/changelog [new file with mode: 0644]
package/debian/compat [new file with mode: 0644]
package/debian/control [new file with mode: 0644]
package/debian/copyright [new file with mode: 0644]
package/debian/docs [new file with mode: 0644]
package/debian/postinst [new file with mode: 0644]
package/debian/prerm [new file with mode: 0644]
package/debian/rules [new file with mode: 0755]
package/debian/source/format [new file with mode: 0644]
package/debian/watch [new file with mode: 0644]
package/pkgsrc/DESCR [new file with mode: 0644]
package/pkgsrc/Makefile [new file with mode: 0644]
package/pkgsrc/PLIST [new file with mode: 0644]
package/pkgsrc/distinfo [new file with mode: 0644]
reader.c
skeleton.c
symtab.c
test/.@-RCS [deleted symlink]
test/calc.tab.c
test/calc.y
test/calc2.output [new file with mode: 0644]
test/calc2.tab.c [new file with mode: 0644]
test/calc2.tab.h [new file with mode: 0644]
test/calc2.y [new file with mode: 0644]
test/calc3.output [new file with mode: 0644]
test/calc3.tab.c [new file with mode: 0644]
test/calc3.tab.h [new file with mode: 0644]
test/calc3.y [new file with mode: 0644]
test/code_calc.code.c [new file with mode: 0644]
test/code_calc.output [new file with mode: 0644]
test/code_calc.tab.c [new file with mode: 0644]
test/code_calc.tab.h [new file with mode: 0644]
test/code_calc.y [new file with mode: 0644]
test/code_error.code.c [new file with mode: 0644]
test/code_error.output [new file with mode: 0644]
test/code_error.tab.c [new file with mode: 0644]
test/code_error.tab.h [new file with mode: 0644]
test/code_error.y [new file with mode: 0644]
test/error.tab.c
test/error.y
test/ftp.tab.c
test/ftp.y
test/grammar.tab.c
test/grammar.y
test/pure_calc.output [new file with mode: 0644]
test/pure_calc.tab.c [new file with mode: 0644]
test/pure_calc.tab.h [new file with mode: 0644]
test/pure_calc.y [new file with mode: 0644]
test/pure_error.output [new file with mode: 0644]
test/pure_error.tab.c [new file with mode: 0644]
test/pure_error.tab.h [new file with mode: 0644]
test/pure_error.y [new file with mode: 0644]
test/run_lint.sh [new file with mode: 0755]
test/run_make.sh [new file with mode: 0755]
test/run_test.sh
verbose.c
warshall.c
yacc.1

diff --git a/.@-RCS b/.@-RCS
deleted file mode 120000 (symlink)
index 4743d7f..0000000
--- a/.@-RCS
+++ /dev/null
@@ -1 +0,0 @@
-/usr/build/VCS/byacc/RCS
\ No newline at end of file
diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..6d75337
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,7 @@
+-- $Id: AUTHORS,v 1.1 2010/06/06 20:31:51 tom Exp $
+-- vile:txtmode
+-- This file is used by a script that collects contributor information and
+-- resolves nicknames vs fullnames.
+dickey Thomas Dickey
+schmitz        Sylvain Schmitz
+unknown        Robert Corbett
diff --git a/CHANGES b/CHANGES
index 49065897e352f92197e37e910b39e4ecabb0ef6c..3333eec18c1bdeae704d8328278f5b97cc808905 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,179 @@
+2010-06-10  Thomas Dickey  <tom@crayon>
+
+       * yacc.1, package/debian/changelog, package/byacc.spec, VERSION:
+       bump to 2010/06/10
+
+2010-06-09  Thomas Dickey  <tom@crayon>
+
+       * reader.c: free declarations in leak-testing code.
+
+       * main.c: close code_file if -r option used, for leak-testing
+
+       * defs.h, reader.c:
+       improve %lex-param / %parse-param implementation by allowing for arrays to
+       be passed as parameters, e.g., "int regs[26]".
+
+       * test/calc3.tab.c, test/calc3.y, test/calc3.output, test/calc3.tab.h, test/calc2.tab.c, test/calc2.y, test/calc2.tab.h, test/calc2.output:
+       RCS_BASE
+
+       * output.c:
+       improve %lex-param / %parse-param implementation by allowing for arrays to
+       be passed as parameters, e.g., "int regs[26]".
+
+       * test/calc.tab.c, test/calc.y:
+       test-cases and reference files for %lex-param / %parse-param
+
+       * makefile.in: add docs-rule, for html/pdf/txt form of manpage
+
+       * configure: regen
+
+       * aclocal.m4: add CF_XOPEN_SOURCE, etc.
+
+       * configure.in:
+       use CF_XOPEN_SOURCE check to ensure that strdup is in scope, e.g., for c89
+
+       * test/ftp.tab.c, test/ftp.y, reader.c, symtab.c, verbose.c, lr0.c, main.c, mkpar.c, output.c, defs.h, closure.c:
+       fix warnings from clang --analyze
+
+2010-06-08  Thomas Dickey  <tom@crayon>
+
+       * output.c: fix to build with c89, etc.
+
+       * reader.c: gcc warning
+
+       * test/ftp.tab.c, test/ftp.y, test/calc.tab.c, test/code_calc.code.c, test/code_error.code.c, test/code_error.y, test/code_calc.y, test/calc.y, test/pure_error.tab.c, test/error.tab.c, test/error.y, test/pure_error.y, test/pure_calc.tab.c, test/pure_calc.y:
+       modified test-cases to allow them to compile, to validate pure-parser changes.
+       updated reference files to match.
+
+       * output.c:
+       move call for output_stype() earlier since it is used in pure-parser declarations
+
+       * test/grammar.tab.c, test/grammar.y:
+       modified test-cases to allow them to compile, to validate pure-parser changes.
+       updated reference files to match.
+
+       * test/calc.tab.c, test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c:
+       regen
+
+       * yacc.1: document %lex-param and %parse-param
+
+       * test/run_lint.sh, test/run_make.sh: RCS_BASE
+
+       * test/run_test.sh:
+       further modify to allow build-directory to be in a different location by
+       passing this directory's location as a parameter to the script.
+
+       * makefile.in:
+       add check_make and check_lint rules to help validate the generated files
+       in the test-directory
+
+2010-06-07  Thomas Dickey  <tom@crayon>
+
+       * test/pure_calc.tab.c, test/pure_error.tab.c: RCS_BASE
+
+       * test/run_test.sh:
+       provide for testing -r and -P options by checking if the ".y" filename
+       begins with "code_" or "pure_", respectively.
+
+       * test/code_error.code.c, test/code_error.tab.c, test/code_error.tab.h, test/code_calc.code.c, test/code_calc.tab.c, test/code_calc.tab.h, test/pure_calc.output, test/pure_calc.tab.h, test/pure_error.output, test/pure_error.tab.h, test/code_calc.output, test/code_error.output:
+       RCS_BASE
+
+       * test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c: regen
+
+       * test/run_test.sh:
+       changes to support running "make check" in a separate build-tree
+
+       * main.c: add "-P" to usage message
+
+       * reader.c: use UCH() macro to hide casts.
+
+2010-06-07  Andres.Mejia
+
+       * main.c, output.c, reader.c, defs.h, skeleton.c:
+       Fix the output order of the generated parse code file.  This allows for
+       the use of YYPARSE_PARAM, by having the output that checks for
+       YYPARSE_PARAM to be defined come after the C code block in the
+       definitions section of a yacc file.
+
+       Implement support for YYLEX_PARAM, similar to bison.  This is useful for
+       support for building reentrant lexers with flex.
+
+       Fix a compatibility issue with bison's pure-parser option.  Bison
+       defines yylex as sending at least one parameter, &yylval, as the first
+       parameter and doesn't seem to have an easy way to remove that parameter.
+       This on the other hand is rather convenient to support saving to yylval
+       from flex when building reentrant lexers and parsers.
+
+       Add support for the %parse-param and %lex-param directives used in
+       bison.  This change bears some similarity to NetBSD's changes to byacc
+       at http://www.mail-archive.com/source-changes-full@netbsd.org/msg08143.html
+
+       Bison allows for POSIX yacc emulation via a yacc directive in the yacc
+       file, and also via a command line switch.  Implement this feature as a
+       no-op for byacc, since byacc is designed to be POSIX yacc compatible
+       anyway.  This allows for better compatibility with yacc sources written
+       for bison.
+
+2010-06-07  Thomas Dickey  <tom@crayon>
+
+       * VERSION: bump to 2010/06/07
+
+2010-06-06  Thomas Dickey  <tom@crayon>
+
+       * test/calc.tab.c, configure: regen
+
+       * skeleton.c:
+       move #include's down into the generated code, to allow user-defined code
+       to override feature definitions, particularly with stdlib.h (request by
+       Marcus Kool).
+
+       * lr0.c, error.c, reader.c, defs.h:
+       strict gcc 3.4.6 warnings on 64-bit platform
+
+       * aclocal.m4, configure.in: add check for lint
+
+       * makefile.in: add lint rule
+
+       * defs.h, closure.c, lr0.c, warshall.c, main.c:
+       fix gcc warnings, mostly for 64-bit platform
+
+       * aclocal.m4:
+       add macros for checking ctags/etags, e.g., to work with NetBSD pkgsrc
+
+       * makefile.in: add etags/TAGS if available
+
+       * configure.in: add configure check for actual ctags and etags programs
+
+       * package/debian/copyright: add copyright notices for non-PD files
+
+       * package/debian/changelog:
+       incorporated scripts in upstream to use for test-builds
+
+       * makefile.in: drop mkdirs.sh, just use "mkdir -p"
+
+       * AUTHORS: nicknames for some contributors (see CHANGES for details)
+
+       * package/byacc.spec: RPM file for byacc
+
+       * VERSION: bump to 2010/06/06
+
+       * aclocal.m4: add copyright notice, from "my-autoconf" macros
+               http://invisible-island.net/autoconf/autoconf.html
+
+       * package/RCS, package/debian/RCS, package/debian/source/RCS, package/pkgsrc/RCS:
+       PERMIT FILE
+
+       * aclocal.m4: resync with my-autoconf.  summary of changes:
+               a) CF_ADD_CFLAGS, etc., improve quoting of ifelse() parameter
+               b) CF_DISABLE_ECHO, change indent-convention for substituted makefile
+               c) CF_GCC_VERSION, ignore stderr
+               d) CF_GCC_WARNINGS, adjust options to work with c89 wrapper of gcc
+
+2010-04-20  Thomas Dickey  <tom@crayon>
+
+       * package/debian/changelog, package/debian/compat, package/debian/control, package/debian/copyright, package/debian/docs, package/debian/postinst, package/debian/prerm, package/debian/rules, package/debian/watch:
+       scripts from Debian package
+
 2010-02-16  Thomas Dickey  <tom@crayon>
 
        * yacc.1: document -P and bison-extensions
 
        * skeleton.c: fix a memory leak in the generated skeleton
 
+2010-01-01  Thomas Dickey  <tom@crayon>
+
+       * package/debian/source/format: scripts from Debian package
+
 2009-12-31  Thomas Dickey  <tom@crayon>
 
        * config.guess: 2009-12-30
 
        * aclocal.m4: resync with my-autoconf (no major changes)
 
+2008-07-24  Thomas Dickey  <tom@crayon>
+
+       * package/pkgsrc/Makefile, package/pkgsrc/distinfo:
+       scripts from NetBSD pkgsrc, for test-builds
+
 2008-03-14  Thomas Dickey  <tom@crayon>
 
        * config.sub: update to 2008-03-08
 
        * config.guess: 2005/3/24
 
+2005-04-13  Thomas Dickey  <tom@crayon>
+
+       * package/pkgsrc/PLIST: scripts from NetBSD pkgsrc, for test-builds
+
+2005-03-21  Thomas Dickey  <tom@crayon>
+
+       * package/pkgsrc/DESCR: scripts from NetBSD pkgsrc, for test-builds
+
 2004-03-28  Thomas Dickey  <tom@crayon>
 
        * test/calc.tab.c, test/error.tab.c, test/ftp.tab.c, test/grammar.tab.c:
 
 2000-11-20  Thomas Dickey  <tom@crayon>
 
-       * test/calc.y: RCS_BASE
+       * test/calc.y, test/code_calc.y, test/pure_calc.y: RCS_BASE
 
        * vmsbuild.com: original version
 
 
        * symtab.c, lalr.c, error.c: original version
 
+1990-01-16  Thomas Dickey  <tom@crayon>
+
+       * test/code_error.y, test/pure_error.y: RCS_BASE
+
 1990-01-16  unknown
 
        * test/error.y: RCS_BASE
diff --git a/VERSION b/VERSION
index 553ae2cbf5212c97a83982f68f1eac77822f9857..447410744a4e14e6997176edd2a1b2ff60f8d663 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-20100216
+20100610
index 4fdffdd0d88872e98d4afd3e8ee9a5f08b2e02be..3f7b5e707c57d310f562cfc3746a288f622c7202 100644 (file)
@@ -1,9 +1,34 @@
-dnl $Id: aclocal.m4,v 1.10 2010/02/16 09:59:33 tom Exp $
-dnl
+dnl $Id: aclocal.m4,v 1.15 2010/06/09 09:30:08 tom Exp $
 dnl Macros for byacc configure script (Thomas E. Dickey)
 dnl ---------------------------------------------------------------------------
+dnl Copyright 2004-2009,2010 Thomas E. Dickey
+dnl 
+dnl Permission is hereby granted, free of charge, to any person obtaining a
+dnl copy of this software and associated documentation files (the
+dnl "Software"), to deal in the Software without restriction, including
+dnl without limitation the rights to use, copy, modify, merge, publish,
+dnl distribute, distribute with modifications, sublicense, and/or sell
+dnl copies of the Software, and to permit persons to whom the Software is
+dnl furnished to do so, subject to the following conditions:
+dnl 
+dnl The above copyright notice and this permission notice shall be included
+dnl in all copies or portions of the Software.
+dnl 
+dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+dnl OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+dnl MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+dnl IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+dnl DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+dnl OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
+dnl THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+dnl 
+dnl Except as contained in this notice, the name(s) of the above copyright
+dnl holders shall not be used in advertising or otherwise to promote the
+dnl sale, use or other dealings in this Software without prior written
+dnl authorization.
+dnl ---------------------------------------------------------------------------
 dnl ---------------------------------------------------------------------------
-dnl CF_ADD_CFLAGS version: 9 updated: 2010/01/09 11:05:50
+dnl CF_ADD_CFLAGS version: 10 updated: 2010/05/26 05:38:42
 dnl -------------
 dnl Copy non-preprocessor flags to $CFLAGS, preprocessor flags to $CPPFLAGS
 dnl The second parameter if given makes this macro verbose.
@@ -73,17 +98,17 @@ esac
 done
 
 if test -n "$cf_new_cflags" ; then
-       ifelse($2,,,[CF_VERBOSE(add to \$CFLAGS $cf_new_cflags)])
+       ifelse([$2],,,[CF_VERBOSE(add to \$CFLAGS $cf_new_cflags)])
        CFLAGS="$CFLAGS $cf_new_cflags"
 fi
 
 if test -n "$cf_new_cppflags" ; then
-       ifelse($2,,,[CF_VERBOSE(add to \$CPPFLAGS $cf_new_cppflags)])
+       ifelse([$2],,,[CF_VERBOSE(add to \$CPPFLAGS $cf_new_cppflags)])
        CPPFLAGS="$CPPFLAGS $cf_new_cppflags"
 fi
 
 if test -n "$cf_new_extra_cppflags" ; then
-       ifelse($2,,,[CF_VERBOSE(add to \$EXTRA_CPPFLAGS $cf_new_extra_cppflags)])
+       ifelse([$2],,,[CF_VERBOSE(add to \$EXTRA_CPPFLAGS $cf_new_extra_cppflags)])
        EXTRA_CPPFLAGS="$cf_new_extra_cppflags $EXTRA_CPPFLAGS"
 fi
 
@@ -167,7 +192,7 @@ dnl Allow user to disable a normally-on option.
 AC_DEFUN([CF_ARG_DISABLE],
 [CF_ARG_OPTION($1,[$2],[$3],[$4],yes)])dnl
 dnl ---------------------------------------------------------------------------
-dnl CF_ARG_OPTION version: 3 updated: 1997/10/18 14:42:41
+dnl CF_ARG_OPTION version: 4 updated: 2010/05/26 05:38:42
 dnl -------------
 dnl Restricted form of AC_ARG_ENABLE that ensures user doesn't give bogus
 dnl values.
@@ -179,13 +204,13 @@ dnl $3 = action to perform if option is not default
 dnl $4 = action if perform if option is default
 dnl $5 = default option value (either 'yes' or 'no')
 AC_DEFUN([CF_ARG_OPTION],
-[AC_ARG_ENABLE($1,[$2],[test "$enableval" != ifelse($5,no,yes,no) && enableval=ifelse($5,no,no,yes)
+[AC_ARG_ENABLE([$1],[$2],[test "$enableval" != ifelse([$5],no,yes,no) && enableval=ifelse([$5],no,no,yes)
   if test "$enableval" != "$5" ; then
-ifelse($3,,[    :]dnl
-,[    $3]) ifelse($4,,,[
+ifelse([$3],,[    :]dnl
+,[    $3]) ifelse([$4],,,[
   else
     $4])
-  fi],[enableval=$5 ifelse($4,,,[
+  fi],[enableval=$5 ifelse([$4],,,[
   $4
 ])dnl
   ])])dnl
@@ -262,7 +287,7 @@ AC_SUBST(SHOW_CC)
 AC_SUBST(ECHO_CC)
 ])dnl
 dnl ---------------------------------------------------------------------------
-dnl CF_DISABLE_LEAKS version: 4 updated: 2006/12/16 15:10:42
+dnl CF_DISABLE_LEAKS version: 5 updated: 2010/03/13 15:14:55
 dnl ----------------
 dnl Combine no-leak checks with the libraries or tools that are used for the
 dnl checks.
@@ -275,7 +300,7 @@ AC_REQUIRE([CF_WITH_VALGRIND])
 AC_MSG_CHECKING(if you want to perform memory-leak testing)
 AC_ARG_ENABLE(leaks,
        [  --disable-leaks         test: free permanent memory, analyze leaks],
-       [with_no_leaks=yes],
+       [if test "x$enableval" = xno; then with_no_leaks=yes; else with_no_leaks=no; fi],
        : ${with_no_leaks:=no})
 AC_MSG_RESULT($with_no_leaks)
 
@@ -394,7 +419,7 @@ rm -rf conftest*
 fi
 ])dnl
 dnl ---------------------------------------------------------------------------
-dnl CF_GCC_VERSION version: 4 updated: 2005/08/27 09:53:42
+dnl CF_GCC_VERSION version: 5 updated: 2010/04/24 11:02:31
 dnl --------------
 dnl Find version of gcc
 AC_DEFUN([CF_GCC_VERSION],[
@@ -402,13 +427,13 @@ AC_REQUIRE([AC_PROG_CC])
 GCC_VERSION=none
 if test "$GCC" = yes ; then
        AC_MSG_CHECKING(version of $CC)
-       GCC_VERSION="`${CC} --version| sed -e '2,$d' -e 's/^.*(GCC) //' -e 's/^[[^0-9.]]*//' -e 's/[[^0-9.]].*//'`"
+       GCC_VERSION="`${CC} --version 2>/dev/null | sed -e '2,$d' -e 's/^.*(GCC) //' -e 's/^[[^0-9.]]*//' -e 's/[[^0-9.]].*//'`"
        test -z "$GCC_VERSION" && GCC_VERSION=unknown
        AC_MSG_RESULT($GCC_VERSION)
 fi
 ])dnl
 dnl ---------------------------------------------------------------------------
-dnl CF_GCC_WARNINGS version: 24 updated: 2009/02/01 15:21:00
+dnl CF_GCC_WARNINGS version: 25 updated: 2010/04/24 11:03:31
 dnl ---------------
 dnl Check if the compiler supports useful warning options.  There's a few that
 dnl we don't use, simply because they're too noisy:
@@ -476,10 +501,10 @@ elif test "$GCC" = yes
 then
        AC_CHECKING([for $CC warning options])
        cf_save_CFLAGS="$CFLAGS"
-       EXTRA_CFLAGS="-W -Wall"
+       EXTRA_CFLAGS=
        cf_warn_CONST=""
        test "$with_ext_const" = yes && cf_warn_CONST="Wwrite-strings"
-       for cf_opt in \
+       for cf_opt in W Wall \
                Wbad-function-cast \
                Wcast-align \
                Wcast-qual \
@@ -517,7 +542,37 @@ rm -f conftest*
 AC_SUBST(EXTRA_CFLAGS)
 ])dnl
 dnl ---------------------------------------------------------------------------
-dnl CF_INTEL_COMPILER version: 3 updated: 2005/08/06 18:37:29
+dnl CF_GNU_SOURCE version: 6 updated: 2005/07/09 13:23:07
+dnl -------------
+dnl Check if we must define _GNU_SOURCE to get a reasonable value for
+dnl _XOPEN_SOURCE, upon which many POSIX definitions depend.  This is a defect
+dnl (or misfeature) of glibc2, which breaks portability of many applications,
+dnl since it is interwoven with GNU extensions.
+dnl
+dnl Well, yes we could work around it...
+AC_DEFUN([CF_GNU_SOURCE],
+[
+AC_CACHE_CHECK(if we must define _GNU_SOURCE,cf_cv_gnu_source,[
+AC_TRY_COMPILE([#include <sys/types.h>],[
+#ifndef _XOPEN_SOURCE
+make an error
+#endif],
+       [cf_cv_gnu_source=no],
+       [cf_save="$CPPFLAGS"
+        CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
+        AC_TRY_COMPILE([#include <sys/types.h>],[
+#ifdef _XOPEN_SOURCE
+make an error
+#endif],
+       [cf_cv_gnu_source=no],
+       [cf_cv_gnu_source=yes])
+       CPPFLAGS="$cf_save"
+       ])
+])
+test "$cf_cv_gnu_source" = yes && CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
+])dnl
+dnl ---------------------------------------------------------------------------
+dnl CF_INTEL_COMPILER version: 4 updated: 2010/05/26 05:38:42
 dnl -----------------
 dnl Check if the given compiler is really the Intel compiler for Linux.  It
 dnl tries to imitate gcc, but does not return an error when it finds a mismatch
@@ -531,29 +586,96 @@ dnl $1 = GCC (default) or GXX
 dnl $2 = INTEL_COMPILER (default) or INTEL_CPLUSPLUS
 dnl $3 = CFLAGS (default) or CXXFLAGS
 AC_DEFUN([CF_INTEL_COMPILER],[
-ifelse($2,,INTEL_COMPILER,[$2])=no
+ifelse([$2],,INTEL_COMPILER,[$2])=no
 
-if test "$ifelse($1,,[$1],GCC)" = yes ; then
+if test "$ifelse([$1],,[$1],GCC)" = yes ; then
        case $host_os in
        linux*|gnu*)
-               AC_MSG_CHECKING(if this is really Intel ifelse($1,GXX,C++,C) compiler)
-               cf_save_CFLAGS="$ifelse($3,,CFLAGS,[$3])"
-               ifelse($3,,CFLAGS,[$3])="$ifelse($3,,CFLAGS,[$3]) -no-gcc"
+               AC_MSG_CHECKING(if this is really Intel ifelse([$1],GXX,C++,C) compiler)
+               cf_save_CFLAGS="$ifelse([$3],,CFLAGS,[$3])"
+               ifelse([$3],,CFLAGS,[$3])="$ifelse([$3],,CFLAGS,[$3]) -no-gcc"
                AC_TRY_COMPILE([],[
 #ifdef __INTEL_COMPILER
 #else
 make an error
 #endif
-],[ifelse($2,,INTEL_COMPILER,[$2])=yes
+],[ifelse([$2],,INTEL_COMPILER,[$2])=yes
 cf_save_CFLAGS="$cf_save_CFLAGS -we147 -no-gcc"
 ],[])
-               ifelse($3,,CFLAGS,[$3])="$cf_save_CFLAGS"
-               AC_MSG_RESULT($ifelse($2,,INTEL_COMPILER,[$2]))
+               ifelse([$3],,CFLAGS,[$3])="$cf_save_CFLAGS"
+               AC_MSG_RESULT($ifelse([$2],,INTEL_COMPILER,[$2]))
                ;;
        esac
 fi
 ])dnl
 dnl ---------------------------------------------------------------------------
+dnl CF_MAKE_TAGS version: 5 updated: 2010/04/03 20:07:32
+dnl ------------
+dnl Generate tags/TAGS targets for makefiles.  Do not generate TAGS if we have
+dnl a monocase filesystem.
+AC_DEFUN([CF_MAKE_TAGS],[
+AC_REQUIRE([CF_MIXEDCASE_FILENAMES])
+
+AC_CHECK_PROGS(CTAGS, exctags ctags)
+AC_CHECK_PROGS(ETAGS, exetags etags)
+
+AC_CHECK_PROG(MAKE_LOWER_TAGS, ${CTAGS-ctags}, yes, no)
+
+if test "$cf_cv_mixedcase" = yes ; then
+       AC_CHECK_PROG(MAKE_UPPER_TAGS, ${ETAGS-etags}, yes, no)
+else
+       MAKE_UPPER_TAGS=no
+fi
+
+if test "$MAKE_UPPER_TAGS" = yes ; then
+       MAKE_UPPER_TAGS=
+else
+       MAKE_UPPER_TAGS="#"
+fi
+
+if test "$MAKE_LOWER_TAGS" = yes ; then
+       MAKE_LOWER_TAGS=
+else
+       MAKE_LOWER_TAGS="#"
+fi
+
+AC_SUBST(CTAGS)
+AC_SUBST(ETAGS)
+
+AC_SUBST(MAKE_UPPER_TAGS)
+AC_SUBST(MAKE_LOWER_TAGS)
+])dnl
+dnl ---------------------------------------------------------------------------
+dnl CF_MIXEDCASE_FILENAMES version: 3 updated: 2003/09/20 17:07:55
+dnl ----------------------
+dnl Check if the file-system supports mixed-case filenames.  If we're able to
+dnl create a lowercase name and see it as uppercase, it doesn't support that.
+AC_DEFUN([CF_MIXEDCASE_FILENAMES],
+[
+AC_CACHE_CHECK(if filesystem supports mixed-case filenames,cf_cv_mixedcase,[
+if test "$cross_compiling" = yes ; then
+       case $target_alias in #(vi
+       *-os2-emx*|*-msdosdjgpp*|*-cygwin*|*-mingw32*|*-uwin*) #(vi
+               cf_cv_mixedcase=no
+               ;;
+       *)
+               cf_cv_mixedcase=yes
+               ;;
+       esac
+else
+       rm -f conftest CONFTEST
+       echo test >conftest
+       if test -f CONFTEST ; then
+               cf_cv_mixedcase=no
+       else
+               cf_cv_mixedcase=yes
+       fi
+       rm -f conftest CONFTEST
+fi
+])
+test "$cf_cv_mixedcase" = yes && AC_DEFINE(MIXEDCASE_FILENAMES)
+])dnl
+dnl ---------------------------------------------------------------------------
 dnl CF_MSG_LOG version: 4 updated: 2007/07/29 09:55:12
 dnl ----------
 dnl Write a debug message to config.log, along with the line number in the
@@ -589,6 +711,79 @@ case .$with_cflags in #(vi
        esac
        ;;
 esac
+])dnl
+dnl ---------------------------------------------------------------------------
+dnl CF_POSIX_C_SOURCE version: 8 updated: 2010/05/26 05:38:42
+dnl -----------------
+dnl Define _POSIX_C_SOURCE to the given level, and _POSIX_SOURCE if needed.
+dnl
+dnl    POSIX.1-1990                            _POSIX_SOURCE
+dnl    POSIX.1-1990 and                        _POSIX_SOURCE and
+dnl            POSIX.2-1992 C-Language                 _POSIX_C_SOURCE=2
+dnl            Bindings Option
+dnl    POSIX.1b-1993                           _POSIX_C_SOURCE=199309L
+dnl    POSIX.1c-1996                           _POSIX_C_SOURCE=199506L
+dnl    X/Open 2000                             _POSIX_C_SOURCE=200112L
+dnl
+dnl Parameters:
+dnl    $1 is the nominal value for _POSIX_C_SOURCE
+AC_DEFUN([CF_POSIX_C_SOURCE],
+[
+cf_POSIX_C_SOURCE=ifelse([$1],,199506L,[$1])
+
+cf_save_CFLAGS="$CFLAGS"
+cf_save_CPPFLAGS="$CPPFLAGS"
+
+CF_REMOVE_DEFINE(cf_trim_CFLAGS,$cf_save_CFLAGS,_POSIX_C_SOURCE)
+CF_REMOVE_DEFINE(cf_trim_CPPFLAGS,$cf_save_CPPFLAGS,_POSIX_C_SOURCE)
+
+AC_CACHE_CHECK(if we should define _POSIX_C_SOURCE,cf_cv_posix_c_source,[
+       CF_MSG_LOG(if the symbol is already defined go no further)
+       AC_TRY_COMPILE([#include <sys/types.h>],[
+#ifndef _POSIX_C_SOURCE
+make an error
+#endif],
+       [cf_cv_posix_c_source=no],
+       [cf_want_posix_source=no
+        case .$cf_POSIX_C_SOURCE in #(vi
+        .[[12]]??*) #(vi
+               cf_cv_posix_c_source="-D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE"
+               ;;
+        .2) #(vi
+               cf_cv_posix_c_source="-D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE"
+               cf_want_posix_source=yes
+               ;;
+        .*)
+               cf_want_posix_source=yes
+               ;;
+        esac
+        if test "$cf_want_posix_source" = yes ; then
+               AC_TRY_COMPILE([#include <sys/types.h>],[
+#ifdef _POSIX_SOURCE
+make an error
+#endif],[],
+               cf_cv_posix_c_source="$cf_cv_posix_c_source -D_POSIX_SOURCE")
+        fi
+        CF_MSG_LOG(ifdef from value $cf_POSIX_C_SOURCE)
+        CFLAGS="$cf_trim_CFLAGS"
+        CPPFLAGS="$cf_trim_CPPFLAGS $cf_cv_posix_c_source"
+        CF_MSG_LOG(if the second compile does not leave our definition intact error)
+        AC_TRY_COMPILE([#include <sys/types.h>],[
+#ifndef _POSIX_C_SOURCE
+make an error
+#endif],,
+        [cf_cv_posix_c_source=no])
+        CFLAGS="$cf_save_CFLAGS"
+        CPPFLAGS="$cf_save_CPPFLAGS"
+       ])
+])
+
+if test "$cf_cv_posix_c_source" != no ; then
+       CFLAGS="$cf_trim_CFLAGS"
+       CPPFLAGS="$cf_trim_CPPFLAGS"
+       CF_ADD_CFLAGS($cf_cv_posix_c_source)
+fi
+
 ])dnl
 dnl ---------------------------------------------------------------------------
 dnl CF_PROG_EXT version: 10 updated: 2004/01/03 19:28:18
@@ -616,6 +811,14 @@ AC_SUBST(PROG_EXT)
 test -n "$PROG_EXT" && AC_DEFINE_UNQUOTED(PROG_EXT,"$PROG_EXT")
 ])dnl
 dnl ---------------------------------------------------------------------------
+dnl CF_PROG_LINT version: 2 updated: 2009/08/12 04:43:14
+dnl ------------
+AC_DEFUN([CF_PROG_LINT],
+[
+AC_CHECK_PROGS(LINT, tdlint lint alint splint lclint)
+AC_SUBST(LINT_OPTS)
+])dnl
+dnl ---------------------------------------------------------------------------
 dnl CF_REMOVE_DEFINE version: 3 updated: 2010/01/09 11:05:50
 dnl ----------------
 dnl Remove all -U and -D options that refer to the given symbol from a list
@@ -710,3 +913,105 @@ if test "$cf_opt_with_warnings" != no ; then
 fi
 fi
 ])dnl
+dnl ---------------------------------------------------------------------------
+dnl CF_XOPEN_SOURCE version: 34 updated: 2010/05/26 05:38:42
+dnl ---------------
+dnl Try to get _XOPEN_SOURCE defined properly that we can use POSIX functions,
+dnl or adapt to the vendor's definitions to get equivalent functionality,
+dnl without losing the common non-POSIX features.
+dnl
+dnl Parameters:
+dnl    $1 is the nominal value for _XOPEN_SOURCE
+dnl    $2 is the nominal value for _POSIX_C_SOURCE
+AC_DEFUN([CF_XOPEN_SOURCE],[
+
+cf_XOPEN_SOURCE=ifelse([$1],,500,[$1])
+cf_POSIX_C_SOURCE=ifelse([$2],,199506L,[$2])
+cf_xopen_source=
+
+case $host_os in #(vi
+aix[[456]]*) #(vi
+       cf_xopen_source="-D_ALL_SOURCE"
+       ;;
+darwin[[0-8]].*) #(vi
+       cf_xopen_source="-D_APPLE_C_SOURCE"
+       ;;
+darwin*) #(vi
+       cf_xopen_source="-D_DARWIN_C_SOURCE"
+       ;;
+freebsd*|dragonfly*) #(vi
+       # 5.x headers associate
+       #       _XOPEN_SOURCE=600 with _POSIX_C_SOURCE=200112L
+       #       _XOPEN_SOURCE=500 with _POSIX_C_SOURCE=199506L
+       cf_POSIX_C_SOURCE=200112L
+       cf_XOPEN_SOURCE=600
+       cf_xopen_source="-D_BSD_TYPES -D__BSD_VISIBLE -D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
+       ;;
+hpux11*) #(vi
+       cf_xopen_source="-D_HPUX_SOURCE -D_XOPEN_SOURCE=500"
+       ;;
+hpux*) #(vi
+       cf_xopen_source="-D_HPUX_SOURCE"
+       ;;
+irix[[56]].*) #(vi
+       cf_xopen_source="-D_SGI_SOURCE"
+       ;;
+linux*|gnu*|mint*|k*bsd*-gnu) #(vi
+       CF_GNU_SOURCE
+       ;;
+mirbsd*) #(vi
+       # setting _XOPEN_SOURCE or _POSIX_SOURCE breaks <arpa/inet.h>
+       ;;
+netbsd*) #(vi
+       # setting _XOPEN_SOURCE breaks IPv6 for lynx on NetBSD 1.6, breaks xterm, is not needed for ncursesw
+       ;;
+openbsd*) #(vi
+       # setting _XOPEN_SOURCE breaks xterm on OpenBSD 2.8, is not needed for ncursesw
+       ;;
+osf[[45]]*) #(vi
+       cf_xopen_source="-D_OSF_SOURCE"
+       ;;
+nto-qnx*) #(vi
+       cf_xopen_source="-D_QNX_SOURCE"
+       ;;
+sco*) #(vi
+       # setting _XOPEN_SOURCE breaks Lynx on SCO Unix / OpenServer
+       ;;
+solaris2.1[[0-9]]) #(vi
+       cf_xopen_source="-D__EXTENSIONS__ -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
+       ;;
+solaris2.[[1-9]]) #(vi
+       cf_xopen_source="-D__EXTENSIONS__"
+       ;;
+*)
+       AC_CACHE_CHECK(if we should define _XOPEN_SOURCE,cf_cv_xopen_source,[
+       AC_TRY_COMPILE([#include <sys/types.h>],[
+#ifndef _XOPEN_SOURCE
+make an error
+#endif],
+       [cf_cv_xopen_source=no],
+       [cf_save="$CPPFLAGS"
+        CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
+        AC_TRY_COMPILE([#include <sys/types.h>],[
+#ifdef _XOPEN_SOURCE
+make an error
+#endif],
+       [cf_cv_xopen_source=no],
+       [cf_cv_xopen_source=$cf_XOPEN_SOURCE])
+       CPPFLAGS="$cf_save"
+       ])
+])
+       if test "$cf_cv_xopen_source" != no ; then
+               CF_REMOVE_DEFINE(CFLAGS,$CFLAGS,_XOPEN_SOURCE)
+               CF_REMOVE_DEFINE(CPPFLAGS,$CPPFLAGS,_XOPEN_SOURCE)
+               cf_temp_xopen_source="-D_XOPEN_SOURCE=$cf_cv_xopen_source"
+               CF_ADD_CFLAGS($cf_temp_xopen_source)
+       fi
+       CF_POSIX_C_SOURCE($cf_POSIX_C_SOURCE)
+       ;;
+esac
+
+if test -n "$cf_xopen_source" ; then
+       CF_ADD_CFLAGS($cf_xopen_source)
+fi
+])
index 6a86579dd93482a2c54437f05491fe5a3a9331ab..7573ff5bbd3fb4057b29edf2f00b6c5ccc241eda 100644 (file)
--- a/closure.c
+++ b/closure.c
@@ -1,4 +1,4 @@
-/* $Id: closure.c,v 1.7 2009/10/27 09:30:14 tom Exp $ */
+/* $Id: closure.c,v 1.9 2010/06/09 08:21:47 tom Exp $ */
 
 #include "defs.h"
 
@@ -79,7 +79,7 @@ set_first_derives(void)
                k = 0;
            }
 
-           if (cword & (1 << k))
+           if (cword & (unsigned)(1 << k))
            {
                rp = derives[j];
                while ((rule = *rp++) >= 0)
@@ -89,7 +89,6 @@ set_first_derives(void)
            }
        }
 
-       vrow += varsetsize;
        rrow += rulesetsize;
     }
 
@@ -117,7 +116,6 @@ closure(short *nucleus, int n)
     Value_t itemno;
 
     rulesetsize = WORDSIZE(nrules);
-    rsp = ruleset;
     rsend = ruleset + rulesetsize;
     for (rsp = ruleset; rsp < rsend; rsp++)
        *rsp = 0;
@@ -145,7 +143,7 @@ closure(short *nucleus, int n)
        {
            for (i = 0; i < BITS_PER_WORD; ++i)
            {
-               if (word & (1 << i))
+               if (word & (unsigned)(1 << i))
                {
                    itemno = rrhs[ruleno + i];
                    while (csp < csend && *csp < itemno)
index 259544522dcb22e5977740a03edce4f3360e9cc1..88efb45fbe3f6c5b3210196d62f7efb4aad92b6f 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,7 +1,7 @@
 #! /bin/sh
-# From configure.in Revision: 1.6 .
+# From configure.in Revision: 1.9 .
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by Autoconf 2.52.20081225.
+# Generated by Autoconf 2.52.20100530.
 #
 # Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
 # Free Software Foundation, Inc.
@@ -718,7 +718,7 @@ This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
 It was created by $as_me, which was
-generated by GNU Autoconf 2.52.20081225.  Invocation command line was
+generated by GNU Autoconf 2.52.20100530.  Invocation command line was
 
   $ $0 $@
 
@@ -2077,37 +2077,727 @@ test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
 
 test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
 
-echo "$as_me:2080: checking for ${CC-cc} option to accept ANSI C" >&5
+echo "$as_me:2080: checking if filesystem supports mixed-case filenames" >&5
+echo $ECHO_N "checking if filesystem supports mixed-case filenames... $ECHO_C" >&6
+if test "${cf_cv_mixedcase+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+if test "$cross_compiling" = yes ; then
+       case $target_alias in #(vi
+       *-os2-emx*|*-msdosdjgpp*|*-cygwin*|*-mingw32*|*-uwin*) #(vi
+               cf_cv_mixedcase=no
+               ;;
+       *)
+               cf_cv_mixedcase=yes
+               ;;
+       esac
+else
+       rm -f conftest CONFTEST
+       echo test >conftest
+       if test -f CONFTEST ; then
+               cf_cv_mixedcase=no
+       else
+               cf_cv_mixedcase=yes
+       fi
+       rm -f conftest CONFTEST
+fi
+
+fi
+echo "$as_me:2107: result: $cf_cv_mixedcase" >&5
+echo "${ECHO_T}$cf_cv_mixedcase" >&6
+test "$cf_cv_mixedcase" = yes && cat >>confdefs.h <<\EOF
+#define MIXEDCASE_FILENAMES 1
+EOF
+
+for ac_prog in exctags ctags
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:2117: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CTAGS+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$CTAGS"; then
+  ac_cv_prog_CTAGS="$CTAGS" # Let the user override the test.
+else
+  ac_save_IFS=$IFS; IFS=$ac_path_separator
+ac_dummy="$PATH"
+for ac_dir in $ac_dummy; do
+  IFS=$ac_save_IFS
+  test -z "$ac_dir" && ac_dir=.
+  $as_executable_p "$ac_dir/$ac_word" || continue
+ac_cv_prog_CTAGS="$ac_prog"
+echo "$as_me:2132: found $ac_dir/$ac_word" >&5
+break
+done
+
+fi
+fi
+CTAGS=$ac_cv_prog_CTAGS
+if test -n "$CTAGS"; then
+  echo "$as_me:2140: result: $CTAGS" >&5
+echo "${ECHO_T}$CTAGS" >&6
+else
+  echo "$as_me:2143: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  test -n "$CTAGS" && break
+done
+
+for ac_prog in exetags etags
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:2154: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ETAGS+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$ETAGS"; then
+  ac_cv_prog_ETAGS="$ETAGS" # Let the user override the test.
+else
+  ac_save_IFS=$IFS; IFS=$ac_path_separator
+ac_dummy="$PATH"
+for ac_dir in $ac_dummy; do
+  IFS=$ac_save_IFS
+  test -z "$ac_dir" && ac_dir=.
+  $as_executable_p "$ac_dir/$ac_word" || continue
+ac_cv_prog_ETAGS="$ac_prog"
+echo "$as_me:2169: found $ac_dir/$ac_word" >&5
+break
+done
+
+fi
+fi
+ETAGS=$ac_cv_prog_ETAGS
+if test -n "$ETAGS"; then
+  echo "$as_me:2177: result: $ETAGS" >&5
+echo "${ECHO_T}$ETAGS" >&6
+else
+  echo "$as_me:2180: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  test -n "$ETAGS" && break
+done
+
+# Extract the first word of "${CTAGS-ctags}", so it can be a program name with args.
+set dummy ${CTAGS-ctags}; ac_word=$2
+echo "$as_me:2189: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_MAKE_LOWER_TAGS+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$MAKE_LOWER_TAGS"; then
+  ac_cv_prog_MAKE_LOWER_TAGS="$MAKE_LOWER_TAGS" # Let the user override the test.
+else
+  ac_save_IFS=$IFS; IFS=$ac_path_separator
+ac_dummy="$PATH"
+for ac_dir in $ac_dummy; do
+  IFS=$ac_save_IFS
+  test -z "$ac_dir" && ac_dir=.
+  $as_executable_p "$ac_dir/$ac_word" || continue
+ac_cv_prog_MAKE_LOWER_TAGS="yes"
+echo "$as_me:2204: found $ac_dir/$ac_word" >&5
+break
+done
+
+  test -z "$ac_cv_prog_MAKE_LOWER_TAGS" && ac_cv_prog_MAKE_LOWER_TAGS="no"
+fi
+fi
+MAKE_LOWER_TAGS=$ac_cv_prog_MAKE_LOWER_TAGS
+if test -n "$MAKE_LOWER_TAGS"; then
+  echo "$as_me:2213: result: $MAKE_LOWER_TAGS" >&5
+echo "${ECHO_T}$MAKE_LOWER_TAGS" >&6
+else
+  echo "$as_me:2216: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+if test "$cf_cv_mixedcase" = yes ; then
+       # Extract the first word of "${ETAGS-etags}", so it can be a program name with args.
+set dummy ${ETAGS-etags}; ac_word=$2
+echo "$as_me:2223: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_MAKE_UPPER_TAGS+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$MAKE_UPPER_TAGS"; then
+  ac_cv_prog_MAKE_UPPER_TAGS="$MAKE_UPPER_TAGS" # Let the user override the test.
+else
+  ac_save_IFS=$IFS; IFS=$ac_path_separator
+ac_dummy="$PATH"
+for ac_dir in $ac_dummy; do
+  IFS=$ac_save_IFS
+  test -z "$ac_dir" && ac_dir=.
+  $as_executable_p "$ac_dir/$ac_word" || continue
+ac_cv_prog_MAKE_UPPER_TAGS="yes"
+echo "$as_me:2238: found $ac_dir/$ac_word" >&5
+break
+done
+
+  test -z "$ac_cv_prog_MAKE_UPPER_TAGS" && ac_cv_prog_MAKE_UPPER_TAGS="no"
+fi
+fi
+MAKE_UPPER_TAGS=$ac_cv_prog_MAKE_UPPER_TAGS
+if test -n "$MAKE_UPPER_TAGS"; then
+  echo "$as_me:2247: result: $MAKE_UPPER_TAGS" >&5
+echo "${ECHO_T}$MAKE_UPPER_TAGS" >&6
+else
+  echo "$as_me:2250: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+else
+       MAKE_UPPER_TAGS=no
+fi
+
+if test "$MAKE_UPPER_TAGS" = yes ; then
+       MAKE_UPPER_TAGS=
+else
+       MAKE_UPPER_TAGS="#"
+fi
+
+if test "$MAKE_LOWER_TAGS" = yes ; then
+       MAKE_LOWER_TAGS=
+else
+       MAKE_LOWER_TAGS="#"
+fi
+
+for ac_prog in tdlint lint alint splint lclint
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:2274: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_LINT+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test -n "$LINT"; then
+  ac_cv_prog_LINT="$LINT" # Let the user override the test.
+else
+  ac_save_IFS=$IFS; IFS=$ac_path_separator
+ac_dummy="$PATH"
+for ac_dir in $ac_dummy; do
+  IFS=$ac_save_IFS
+  test -z "$ac_dir" && ac_dir=.
+  $as_executable_p "$ac_dir/$ac_word" || continue
+ac_cv_prog_LINT="$ac_prog"
+echo "$as_me:2289: found $ac_dir/$ac_word" >&5
+break
+done
+
+fi
+fi
+LINT=$ac_cv_prog_LINT
+if test -n "$LINT"; then
+  echo "$as_me:2297: result: $LINT" >&5
+echo "${ECHO_T}$LINT" >&6
+else
+  echo "$as_me:2300: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+  test -n "$LINT" && break
+done
+
+echo "$as_me:2307: checking for ${CC-cc} option to accept ANSI C" >&5
 echo $ECHO_N "checking for ${CC-cc} option to accept ANSI C... $ECHO_C" >&6
 if test "${cf_cv_ansi_cc+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
 
-cf_cv_ansi_cc=no
-cf_save_CFLAGS="$CFLAGS"
-cf_save_CPPFLAGS="$CPPFLAGS"
-# Don't try gcc -ansi; that turns off useful extensions and
-# breaks some systems' header files.
-# AIX                  -qlanglvl=ansi
-# Ultrix and OSF/1     -std1
-# HP-UX                        -Aa -D_HPUX_SOURCE
-# SVR4                 -Xc
-# UnixWare 1.2         (cannot use -Xc, since ANSI/POSIX clashes)
-for cf_arg in "-DCC_HAS_PROTOS" \
-       "" \
-       -qlanglvl=ansi \
-       -std1 \
-       -Ae \
-       "-Aa -D_HPUX_SOURCE" \
-       -Xc
-do
+cf_cv_ansi_cc=no
+cf_save_CFLAGS="$CFLAGS"
+cf_save_CPPFLAGS="$CPPFLAGS"
+# Don't try gcc -ansi; that turns off useful extensions and
+# breaks some systems' header files.
+# AIX                  -qlanglvl=ansi
+# Ultrix and OSF/1     -std1
+# HP-UX                        -Aa -D_HPUX_SOURCE
+# SVR4                 -Xc
+# UnixWare 1.2         (cannot use -Xc, since ANSI/POSIX clashes)
+for cf_arg in "-DCC_HAS_PROTOS" \
+       "" \
+       -qlanglvl=ansi \
+       -std1 \
+       -Ae \
+       "-Aa -D_HPUX_SOURCE" \
+       -Xc
+do
+
+cf_fix_cppflags=no
+cf_new_cflags=
+cf_new_cppflags=
+cf_new_extra_cppflags=
+
+for cf_add_cflags in $cf_arg
+do
+case $cf_fix_cppflags in
+no)
+       case $cf_add_cflags in #(vi
+       -undef|-nostdinc*|-I*|-D*|-U*|-E|-P|-C) #(vi
+               case $cf_add_cflags in
+               -D*)
+                       cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^-D[^=]*='\''\"[^"]*//'`
+
+                       test "${cf_add_cflags}" != "${cf_tst_cflags}" \
+                               && test -z "${cf_tst_cflags}" \
+                               && cf_fix_cppflags=yes
+
+                       if test $cf_fix_cppflags = yes ; then
+                               cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
+                               continue
+                       elif test "${cf_tst_cflags}" = "\"'" ; then
+                               cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
+                               continue
+                       fi
+                       ;;
+               esac
+               case "$CPPFLAGS" in
+               *$cf_add_cflags) #(vi
+                       ;;
+               *) #(vi
+                       case $cf_add_cflags in #(vi
+                       -D*)
+                               cf_tst_cppflags=`echo "x$cf_add_cflags" | sed -e 's/^...//' -e 's/=.*//'`
+
+CPPFLAGS=`echo "$CPPFLAGS" | \
+       sed     -e 's/-[UD]'"$cf_tst_cppflags"'\(=[^    ]*\)\?[         ]/ /g' \
+               -e 's/-[UD]'"$cf_tst_cppflags"'\(=[^    ]*\)\?$//g'`
+
+                               ;;
+                       esac
+                       cf_new_cppflags="$cf_new_cppflags $cf_add_cflags"
+                       ;;
+               esac
+               ;;
+       *)
+               cf_new_cflags="$cf_new_cflags $cf_add_cflags"
+               ;;
+       esac
+       ;;
+yes)
+       cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
+
+       cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^[^"]*"'\''//'`
+
+       test "${cf_add_cflags}" != "${cf_tst_cflags}" \
+               && test -z "${cf_tst_cflags}" \
+               && cf_fix_cppflags=no
+       ;;
+esac
+done
+
+if test -n "$cf_new_cflags" ; then
+
+       CFLAGS="$CFLAGS $cf_new_cflags"
+fi
+
+if test -n "$cf_new_cppflags" ; then
+
+       CPPFLAGS="$CPPFLAGS $cf_new_cppflags"
+fi
+
+if test -n "$cf_new_extra_cppflags" ; then
+
+       EXTRA_CPPFLAGS="$cf_new_extra_cppflags $EXTRA_CPPFLAGS"
+fi
+
+       cat >conftest.$ac_ext <<_ACEOF
+#line 2411 "configure"
+#include "confdefs.h"
+
+#ifndef CC_HAS_PROTOS
+#if !defined(__STDC__) || (__STDC__ != 1)
+choke me
+#endif
+#endif
+
+int
+main ()
+{
+
+       int test (int i, double x);
+       struct s1 {int (*f) (int a);};
+       struct s2 {int (*f) (double a);};
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:2432: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:2435: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:2438: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:2441: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  cf_cv_ansi_cc="$cf_arg"; break
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+done
+CFLAGS="$cf_save_CFLAGS"
+CPPFLAGS="$cf_save_CPPFLAGS"
+
+fi
+echo "$as_me:2454: result: $cf_cv_ansi_cc" >&5
+echo "${ECHO_T}$cf_cv_ansi_cc" >&6
+
+if test "$cf_cv_ansi_cc" != "no"; then
+if test ".$cf_cv_ansi_cc" != ".-DCC_HAS_PROTOS"; then
+
+cf_fix_cppflags=no
+cf_new_cflags=
+cf_new_cppflags=
+cf_new_extra_cppflags=
+
+for cf_add_cflags in $cf_cv_ansi_cc
+do
+case $cf_fix_cppflags in
+no)
+       case $cf_add_cflags in #(vi
+       -undef|-nostdinc*|-I*|-D*|-U*|-E|-P|-C) #(vi
+               case $cf_add_cflags in
+               -D*)
+                       cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^-D[^=]*='\''\"[^"]*//'`
+
+                       test "${cf_add_cflags}" != "${cf_tst_cflags}" \
+                               && test -z "${cf_tst_cflags}" \
+                               && cf_fix_cppflags=yes
+
+                       if test $cf_fix_cppflags = yes ; then
+                               cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
+                               continue
+                       elif test "${cf_tst_cflags}" = "\"'" ; then
+                               cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
+                               continue
+                       fi
+                       ;;
+               esac
+               case "$CPPFLAGS" in
+               *$cf_add_cflags) #(vi
+                       ;;
+               *) #(vi
+                       case $cf_add_cflags in #(vi
+                       -D*)
+                               cf_tst_cppflags=`echo "x$cf_add_cflags" | sed -e 's/^...//' -e 's/=.*//'`
+
+CPPFLAGS=`echo "$CPPFLAGS" | \
+       sed     -e 's/-[UD]'"$cf_tst_cppflags"'\(=[^    ]*\)\?[         ]/ /g' \
+               -e 's/-[UD]'"$cf_tst_cppflags"'\(=[^    ]*\)\?$//g'`
+
+                               ;;
+                       esac
+                       cf_new_cppflags="$cf_new_cppflags $cf_add_cflags"
+                       ;;
+               esac
+               ;;
+       *)
+               cf_new_cflags="$cf_new_cflags $cf_add_cflags"
+               ;;
+       esac
+       ;;
+yes)
+       cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
+
+       cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^[^"]*"'\''//'`
+
+       test "${cf_add_cflags}" != "${cf_tst_cflags}" \
+               && test -z "${cf_tst_cflags}" \
+               && cf_fix_cppflags=no
+       ;;
+esac
+done
+
+if test -n "$cf_new_cflags" ; then
+
+       CFLAGS="$CFLAGS $cf_new_cflags"
+fi
+
+if test -n "$cf_new_cppflags" ; then
+
+       CPPFLAGS="$CPPFLAGS $cf_new_cppflags"
+fi
+
+if test -n "$cf_new_extra_cppflags" ; then
+
+       EXTRA_CPPFLAGS="$cf_new_extra_cppflags $EXTRA_CPPFLAGS"
+fi
+
+else
+       cat >>confdefs.h <<\EOF
+#define CC_HAS_PROTOS 1
+EOF
+
+fi
+fi
+
+if test "$cf_cv_ansi_cc" = "no"; then
+       { { echo "$as_me:2547: error: Your compiler does not appear to recognize prototypes.
+You have the following choices:
+       a. adjust your compiler options
+       b. get an up-to-date compiler
+       c. use a wrapper such as unproto" >&5
+echo "$as_me: error: Your compiler does not appear to recognize prototypes.
+You have the following choices:
+       a. adjust your compiler options
+       b. get an up-to-date compiler
+       c. use a wrapper such as unproto" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+cf_XOPEN_SOURCE=500
+cf_POSIX_C_SOURCE=199506L
+cf_xopen_source=
+
+case $host_os in #(vi
+aix[456]*) #(vi
+       cf_xopen_source="-D_ALL_SOURCE"
+       ;;
+darwin[0-8].*) #(vi
+       cf_xopen_source="-D_APPLE_C_SOURCE"
+       ;;
+darwin*) #(vi
+       cf_xopen_source="-D_DARWIN_C_SOURCE"
+       ;;
+freebsd*|dragonfly*) #(vi
+       # 5.x headers associate
+       #       _XOPEN_SOURCE=600 with _POSIX_C_SOURCE=200112L
+       #       _XOPEN_SOURCE=500 with _POSIX_C_SOURCE=199506L
+       cf_POSIX_C_SOURCE=200112L
+       cf_XOPEN_SOURCE=600
+       cf_xopen_source="-D_BSD_TYPES -D__BSD_VISIBLE -D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
+       ;;
+hpux11*) #(vi
+       cf_xopen_source="-D_HPUX_SOURCE -D_XOPEN_SOURCE=500"
+       ;;
+hpux*) #(vi
+       cf_xopen_source="-D_HPUX_SOURCE"
+       ;;
+irix[56].*) #(vi
+       cf_xopen_source="-D_SGI_SOURCE"
+       ;;
+linux*|gnu*|mint*|k*bsd*-gnu) #(vi
+
+echo "$as_me:2593: checking if we must define _GNU_SOURCE" >&5
+echo $ECHO_N "checking if we must define _GNU_SOURCE... $ECHO_C" >&6
+if test "${cf_cv_gnu_source+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+cat >conftest.$ac_ext <<_ACEOF
+#line 2600 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+int
+main ()
+{
+
+#ifndef _XOPEN_SOURCE
+make an error
+#endif
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:2615: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:2618: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:2621: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:2624: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  cf_cv_gnu_source=no
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+cf_save="$CPPFLAGS"
+        CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
+        cat >conftest.$ac_ext <<_ACEOF
+#line 2633 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+int
+main ()
+{
+
+#ifdef _XOPEN_SOURCE
+make an error
+#endif
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:2648: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:2651: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:2654: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:2657: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  cf_cv_gnu_source=no
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+cf_cv_gnu_source=yes
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+       CPPFLAGS="$cf_save"
+
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+
+fi
+echo "$as_me:2672: result: $cf_cv_gnu_source" >&5
+echo "${ECHO_T}$cf_cv_gnu_source" >&6
+test "$cf_cv_gnu_source" = yes && CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
+
+       ;;
+mirbsd*) #(vi
+       # setting _XOPEN_SOURCE or _POSIX_SOURCE breaks <arpa/inet.h>
+       ;;
+netbsd*) #(vi
+       # setting _XOPEN_SOURCE breaks IPv6 for lynx on NetBSD 1.6, breaks xterm, is not needed for ncursesw
+       ;;
+openbsd*) #(vi
+       # setting _XOPEN_SOURCE breaks xterm on OpenBSD 2.8, is not needed for ncursesw
+       ;;
+osf[45]*) #(vi
+       cf_xopen_source="-D_OSF_SOURCE"
+       ;;
+nto-qnx*) #(vi
+       cf_xopen_source="-D_QNX_SOURCE"
+       ;;
+sco*) #(vi
+       # setting _XOPEN_SOURCE breaks Lynx on SCO Unix / OpenServer
+       ;;
+solaris2.1[0-9]) #(vi
+       cf_xopen_source="-D__EXTENSIONS__ -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
+       ;;
+solaris2.[1-9]) #(vi
+       cf_xopen_source="-D__EXTENSIONS__"
+       ;;
+*)
+       echo "$as_me:2702: checking if we should define _XOPEN_SOURCE" >&5
+echo $ECHO_N "checking if we should define _XOPEN_SOURCE... $ECHO_C" >&6
+if test "${cf_cv_xopen_source+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+       cat >conftest.$ac_ext <<_ACEOF
+#line 2709 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+int
+main ()
+{
+
+#ifndef _XOPEN_SOURCE
+make an error
+#endif
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:2724: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:2727: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:2730: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:2733: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  cf_cv_xopen_source=no
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+cf_save="$CPPFLAGS"
+        CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=$cf_XOPEN_SOURCE"
+        cat >conftest.$ac_ext <<_ACEOF
+#line 2742 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+int
+main ()
+{
+
+#ifdef _XOPEN_SOURCE
+make an error
+#endif
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:2757: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:2760: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:2763: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:2766: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  cf_cv_xopen_source=no
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+cf_cv_xopen_source=$cf_XOPEN_SOURCE
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+       CPPFLAGS="$cf_save"
+
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+
+fi
+echo "$as_me:2781: result: $cf_cv_xopen_source" >&5
+echo "${ECHO_T}$cf_cv_xopen_source" >&6
+       if test "$cf_cv_xopen_source" != no ; then
+
+CFLAGS=`echo "$CFLAGS" | \
+       sed     -e 's/-[UD]'"_XOPEN_SOURCE"'\(=[^       ]*\)\?[         ]/ /g' \
+               -e 's/-[UD]'"_XOPEN_SOURCE"'\(=[^       ]*\)\?$//g'`
+
+CPPFLAGS=`echo "$CPPFLAGS" | \
+       sed     -e 's/-[UD]'"_XOPEN_SOURCE"'\(=[^       ]*\)\?[         ]/ /g' \
+               -e 's/-[UD]'"_XOPEN_SOURCE"'\(=[^       ]*\)\?$//g'`
+
+               cf_temp_xopen_source="-D_XOPEN_SOURCE=$cf_cv_xopen_source"
 
 cf_fix_cppflags=no
 cf_new_cflags=
 cf_new_cppflags=
 cf_new_extra_cppflags=
 
-for cf_add_cflags in $cf_arg
+for cf_add_cflags in $cf_temp_xopen_source
 do
 case $cf_fix_cppflags in
 no)
@@ -2180,62 +2870,171 @@ if test -n "$cf_new_extra_cppflags" ; then
        EXTRA_CPPFLAGS="$cf_new_extra_cppflags $EXTRA_CPPFLAGS"
 fi
 
+       fi
+
+cf_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE
+
+cf_save_CFLAGS="$CFLAGS"
+cf_save_CPPFLAGS="$CPPFLAGS"
+
+cf_trim_CFLAGS=`echo "$cf_save_CFLAGS" | \
+       sed     -e 's/-[UD]'"_POSIX_C_SOURCE"'\(=[^     ]*\)\?[         ]/ /g' \
+               -e 's/-[UD]'"_POSIX_C_SOURCE"'\(=[^     ]*\)\?$//g'`
+
+cf_trim_CPPFLAGS=`echo "$cf_save_CPPFLAGS" | \
+       sed     -e 's/-[UD]'"_POSIX_C_SOURCE"'\(=[^     ]*\)\?[         ]/ /g' \
+               -e 's/-[UD]'"_POSIX_C_SOURCE"'\(=[^     ]*\)\?$//g'`
+
+echo "$as_me:2888: checking if we should define _POSIX_C_SOURCE" >&5
+echo $ECHO_N "checking if we should define _POSIX_C_SOURCE... $ECHO_C" >&6
+if test "${cf_cv_posix_c_source+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+echo "${as_me-configure}:2894: testing if the symbol is already defined go no further ..." 1>&5
+
        cat >conftest.$ac_ext <<_ACEOF
-#line 2184 "configure"
+#line 2897 "configure"
 #include "confdefs.h"
+#include <sys/types.h>
+int
+main ()
+{
 
-#ifndef CC_HAS_PROTOS
-#if !defined(__STDC__) || (__STDC__ != 1)
-choke me
+#ifndef _POSIX_C_SOURCE
+make an error
 #endif
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:2912: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:2915: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:2918: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:2921: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  cf_cv_posix_c_source=no
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+cf_want_posix_source=no
+        case .$cf_POSIX_C_SOURCE in #(vi
+        .[12]??*) #(vi
+               cf_cv_posix_c_source="-D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE"
+               ;;
+        .2) #(vi
+               cf_cv_posix_c_source="-D_POSIX_C_SOURCE=$cf_POSIX_C_SOURCE"
+               cf_want_posix_source=yes
+               ;;
+        .*)
+               cf_want_posix_source=yes
+               ;;
+        esac
+        if test "$cf_want_posix_source" = yes ; then
+               cat >conftest.$ac_ext <<_ACEOF
+#line 2942 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
+int
+main ()
+{
+
+#ifdef _POSIX_SOURCE
+make an error
 #endif
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:2957: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:2960: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:2963: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:2966: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  :
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+cf_cv_posix_c_source="$cf_cv_posix_c_source -D_POSIX_SOURCE"
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+        fi
+
+echo "${as_me-configure}:2977: testing ifdef from value $cf_POSIX_C_SOURCE ..." 1>&5
 
+        CFLAGS="$cf_trim_CFLAGS"
+        CPPFLAGS="$cf_trim_CPPFLAGS $cf_cv_posix_c_source"
+
+echo "${as_me-configure}:2982: testing if the second compile does not leave our definition intact error ..." 1>&5
+
+        cat >conftest.$ac_ext <<_ACEOF
+#line 2985 "configure"
+#include "confdefs.h"
+#include <sys/types.h>
 int
 main ()
 {
 
-       int test (int i, double x);
-       struct s1 {int (*f) (int a);};
-       struct s2 {int (*f) (double a);};
+#ifndef _POSIX_C_SOURCE
+make an error
+#endif
   ;
   return 0;
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:2205: \"$ac_compile\"") >&5
+if { (eval echo "$as_me:3000: \"$ac_compile\"") >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
-  echo "$as_me:2208: \$? = $ac_status" >&5
+  echo "$as_me:3003: \$? = $ac_status" >&5
   (exit $ac_status); } &&
          { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:2211: \"$ac_try\"") >&5
+  { (eval echo "$as_me:3006: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
-  echo "$as_me:2214: \$? = $ac_status" >&5
+  echo "$as_me:3009: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  cf_cv_ansi_cc="$cf_arg"; break
+  :
 else
   echo "$as_me: failed program was:" >&5
 cat conftest.$ac_ext >&5
+cf_cv_posix_c_source=no
 fi
 rm -f conftest.$ac_objext conftest.$ac_ext
-done
-CFLAGS="$cf_save_CFLAGS"
-CPPFLAGS="$cf_save_CPPFLAGS"
+        CFLAGS="$cf_save_CFLAGS"
+        CPPFLAGS="$cf_save_CPPFLAGS"
 
 fi
-echo "$as_me:2227: result: $cf_cv_ansi_cc" >&5
-echo "${ECHO_T}$cf_cv_ansi_cc" >&6
+rm -f conftest.$ac_objext conftest.$ac_ext
 
-if test "$cf_cv_ansi_cc" != "no"; then
-if test ".$cf_cv_ansi_cc" != ".-DCC_HAS_PROTOS"; then
+fi
+echo "$as_me:3025: result: $cf_cv_posix_c_source" >&5
+echo "${ECHO_T}$cf_cv_posix_c_source" >&6
+
+if test "$cf_cv_posix_c_source" != no ; then
+       CFLAGS="$cf_trim_CFLAGS"
+       CPPFLAGS="$cf_trim_CPPFLAGS"
 
 cf_fix_cppflags=no
 cf_new_cflags=
 cf_new_cppflags=
 cf_new_extra_cppflags=
 
-for cf_add_cflags in $cf_cv_ansi_cc
+for cf_add_cflags in $cf_cv_posix_c_source
 do
 case $cf_fix_cppflags in
 no)
@@ -2308,41 +3107,106 @@ if test -n "$cf_new_extra_cppflags" ; then
        EXTRA_CPPFLAGS="$cf_new_extra_cppflags $EXTRA_CPPFLAGS"
 fi
 
-else
-       cat >>confdefs.h <<\EOF
-#define CC_HAS_PROTOS 1
-EOF
+fi
+
+       ;;
+esac
+
+if test -n "$cf_xopen_source" ; then
+
+cf_fix_cppflags=no
+cf_new_cflags=
+cf_new_cppflags=
+cf_new_extra_cppflags=
+
+for cf_add_cflags in $cf_xopen_source
+do
+case $cf_fix_cppflags in
+no)
+       case $cf_add_cflags in #(vi
+       -undef|-nostdinc*|-I*|-D*|-U*|-E|-P|-C) #(vi
+               case $cf_add_cflags in
+               -D*)
+                       cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^-D[^=]*='\''\"[^"]*//'`
+
+                       test "${cf_add_cflags}" != "${cf_tst_cflags}" \
+                               && test -z "${cf_tst_cflags}" \
+                               && cf_fix_cppflags=yes
+
+                       if test $cf_fix_cppflags = yes ; then
+                               cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
+                               continue
+                       elif test "${cf_tst_cflags}" = "\"'" ; then
+                               cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
+                               continue
+                       fi
+                       ;;
+               esac
+               case "$CPPFLAGS" in
+               *$cf_add_cflags) #(vi
+                       ;;
+               *) #(vi
+                       case $cf_add_cflags in #(vi
+                       -D*)
+                               cf_tst_cppflags=`echo "x$cf_add_cflags" | sed -e 's/^...//' -e 's/=.*//'`
+
+CPPFLAGS=`echo "$CPPFLAGS" | \
+       sed     -e 's/-[UD]'"$cf_tst_cppflags"'\(=[^    ]*\)\?[         ]/ /g' \
+               -e 's/-[UD]'"$cf_tst_cppflags"'\(=[^    ]*\)\?$//g'`
+
+                               ;;
+                       esac
+                       cf_new_cppflags="$cf_new_cppflags $cf_add_cflags"
+                       ;;
+               esac
+               ;;
+       *)
+               cf_new_cflags="$cf_new_cflags $cf_add_cflags"
+               ;;
+       esac
+       ;;
+yes)
+       cf_new_extra_cppflags="$cf_new_extra_cppflags $cf_add_cflags"
+
+       cf_tst_cflags=`echo ${cf_add_cflags} |sed -e 's/^[^"]*"'\''//'`
+
+       test "${cf_add_cflags}" != "${cf_tst_cflags}" \
+               && test -z "${cf_tst_cflags}" \
+               && cf_fix_cppflags=no
+       ;;
+esac
+done
 
+if test -n "$cf_new_cflags" ; then
+
+       CFLAGS="$CFLAGS $cf_new_cflags"
 fi
+
+if test -n "$cf_new_cppflags" ; then
+
+       CPPFLAGS="$CPPFLAGS $cf_new_cppflags"
+fi
+
+if test -n "$cf_new_extra_cppflags" ; then
+
+       EXTRA_CPPFLAGS="$cf_new_extra_cppflags $EXTRA_CPPFLAGS"
 fi
 
-if test "$cf_cv_ansi_cc" = "no"; then
-       { { echo "$as_me:2320: error: Your compiler does not appear to recognize prototypes.
-You have the following choices:
-       a. adjust your compiler options
-       b. get an up-to-date compiler
-       c. use a wrapper such as unproto" >&5
-echo "$as_me: error: Your compiler does not appear to recognize prototypes.
-You have the following choices:
-       a. adjust your compiler options
-       b. get an up-to-date compiler
-       c. use a wrapper such as unproto" >&2;}
-   { (exit 1); exit 1; }; }
 fi
 
 GCC_VERSION=none
 if test "$GCC" = yes ; then
-       echo "$as_me:2335: checking version of $CC" >&5
+       echo "$as_me:3199: checking version of $CC" >&5
 echo $ECHO_N "checking version of $CC... $ECHO_C" >&6
-       GCC_VERSION="`${CC} --version| sed -e '2,$d' -e 's/^.*(GCC) //' -e 's/^[^0-9.]*//' -e 's/[^0-9.].*//'`"
+       GCC_VERSION="`${CC} --version 2>/dev/null | sed -e '2,$d' -e 's/^.*(GCC) //' -e 's/^[^0-9.]*//' -e 's/[^0-9.].*//'`"
        test -z "$GCC_VERSION" && GCC_VERSION=unknown
-       echo "$as_me:2339: result: $GCC_VERSION" >&5
+       echo "$as_me:3203: result: $GCC_VERSION" >&5
 echo "${ECHO_T}$GCC_VERSION" >&6
 fi
 
 if ( test "$GCC" = yes || test "$GXX" = yes )
 then
-echo "$as_me:2345: checking if you want to check for gcc warnings" >&5
+echo "$as_me:3209: checking if you want to check for gcc warnings" >&5
 echo $ECHO_N "checking if you want to check for gcc warnings... $ECHO_C" >&6
 
 # Check whether --with-warnings or --without-warnings was given.
@@ -2352,7 +3216,7 @@ if test "${with_warnings+set}" = set; then
 else
   cf_opt_with_warnings=no
 fi;
-echo "$as_me:2355: result: $cf_opt_with_warnings" >&5
+echo "$as_me:3219: result: $cf_opt_with_warnings" >&5
 echo "${ECHO_T}$cf_opt_with_warnings" >&6
 if test "$cf_opt_with_warnings" != no ; then
 
@@ -2374,10 +3238,10 @@ cat > conftest.i <<EOF
 EOF
 if test "$GCC" = yes
 then
-       { echo "$as_me:2377: checking for $CC __attribute__ directives..." >&5
+       { echo "$as_me:3241: checking for $CC __attribute__ directives..." >&5
 echo "$as_me: checking for $CC __attribute__ directives..." >&6;}
 cat > conftest.$ac_ext <<EOF
-#line 2380 "${as_me-configure}"
+#line 3244 "${as_me-configure}"
 #include "confdefs.h"
 #include "conftest.h"
 #include "conftest.i"
@@ -2426,12 +3290,12 @@ EOF
                        ;;
                esac
 
-               if { (eval echo "$as_me:2429: \"$ac_compile\"") >&5
+               if { (eval echo "$as_me:3293: \"$ac_compile\"") >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
-  echo "$as_me:2432: \$? = $ac_status" >&5
+  echo "$as_me:3296: \$? = $ac_status" >&5
   (exit $ac_status); }; then
-                       test -n "$verbose" && echo "$as_me:2434: result: ... $cf_attribute" >&5
+                       test -n "$verbose" && echo "$as_me:3298: result: ... $cf_attribute" >&5
 echo "${ECHO_T}... $cf_attribute" >&6
                        cat conftest.h >>confdefs.h
                        case $cf_attribute in #(vi
@@ -2471,12 +3335,12 @@ INTEL_COMPILER=no
 if test "$GCC" = yes ; then
        case $host_os in
        linux*|gnu*)
-               echo "$as_me:2474: checking if this is really Intel C compiler" >&5
+               echo "$as_me:3338: checking if this is really Intel C compiler" >&5
 echo $ECHO_N "checking if this is really Intel C compiler... $ECHO_C" >&6
                cf_save_CFLAGS="$CFLAGS"
                CFLAGS="$CFLAGS -no-gcc"
                cat >conftest.$ac_ext <<_ACEOF
-#line 2479 "configure"
+#line 3343 "configure"
 #include "confdefs.h"
 
 int
@@ -2493,16 +3357,16 @@ make an error
 }
 _ACEOF
 rm -f conftest.$ac_objext
-if { (eval echo "$as_me:2496: \"$ac_compile\"") >&5
+if { (eval echo "$as_me:3360: \"$ac_compile\"") >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
-  echo "$as_me:2499: \$? = $ac_status" >&5
+  echo "$as_me:3363: \$? = $ac_status" >&5
   (exit $ac_status); } &&
          { ac_try='test -s conftest.$ac_objext'
-  { (eval echo "$as_me:2502: \"$ac_try\"") >&5
+  { (eval echo "$as_me:3366: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
-  echo "$as_me:2505: \$? = $ac_status" >&5
+  echo "$as_me:3369: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
   INTEL_COMPILER=yes
 cf_save_CFLAGS="$cf_save_CFLAGS -we147 -no-gcc"
@@ -2513,14 +3377,14 @@ cat conftest.$ac_ext >&5
 fi
 rm -f conftest.$ac_objext conftest.$ac_ext
                CFLAGS="$cf_save_CFLAGS"
-               echo "$as_me:2516: result: $INTEL_COMPILER" >&5
+               echo "$as_me:3380: result: $INTEL_COMPILER" >&5
 echo "${ECHO_T}$INTEL_COMPILER" >&6
                ;;
        esac
 fi
 
 cat > conftest.$ac_ext <<EOF
-#line 2523 "${as_me-configure}"
+#line 3387 "${as_me-configure}"
 int main(int argc, char *argv[]) { return (argv[argc-1] == 0) ; }
 EOF
 
@@ -2537,7 +3401,7 @@ then
 # remark #981: operands are evaluated in unspecified order
 # warning #279: controlling expression is constant
 
-       { echo "$as_me:2540: checking for $CC warning options..." >&5
+       { echo "$as_me:3404: checking for $CC warning options..." >&5
 echo "$as_me: checking for $CC warning options..." >&6;}
        cf_save_CFLAGS="$CFLAGS"
        EXTRA_CFLAGS="-Wall"
@@ -2553,12 +3417,12 @@ echo "$as_me: checking for $CC warning options..." >&6;}
                wd981
        do
                CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
-               if { (eval echo "$as_me:2556: \"$ac_compile\"") >&5
+               if { (eval echo "$as_me:3420: \"$ac_compile\"") >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
-  echo "$as_me:2559: \$? = $ac_status" >&5
+  echo "$as_me:3423: \$? = $ac_status" >&5
   (exit $ac_status); }; then
-                       test -n "$verbose" && echo "$as_me:2561: result: ... -$cf_opt" >&5
+                       test -n "$verbose" && echo "$as_me:3425: result: ... -$cf_opt" >&5
 echo "${ECHO_T}... -$cf_opt" >&6
                        EXTRA_CFLAGS="$EXTRA_CFLAGS -$cf_opt"
                fi
@@ -2567,13 +3431,13 @@ echo "${ECHO_T}... -$cf_opt" >&6
 
 elif test "$GCC" = yes
 then
-       { echo "$as_me:2570: checking for $CC warning options..." >&5
+       { echo "$as_me:3434: checking for $CC warning options..." >&5
 echo "$as_me: checking for $CC warning options..." >&6;}
        cf_save_CFLAGS="$CFLAGS"
-       EXTRA_CFLAGS="-W -Wall"
+       EXTRA_CFLAGS=
        cf_warn_CONST=""
        test "$with_ext_const" = yes && cf_warn_CONST="Wwrite-strings"
-       for cf_opt in \
+       for cf_opt in W Wall \
                Wbad-function-cast \
                Wcast-align \
                Wcast-qual \
@@ -2587,12 +3451,12 @@ echo "$as_me: checking for $CC warning options..." >&6;}
                Wundef $cf_warn_CONST Wwrite-strings
        do
                CFLAGS="$cf_save_CFLAGS $EXTRA_CFLAGS -$cf_opt"
-               if { (eval echo "$as_me:2590: \"$ac_compile\"") >&5
+               if { (eval echo "$as_me:3454: \"$ac_compile\"") >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
-  echo "$as_me:2593: \$? = $ac_status" >&5
+  echo "$as_me:3457: \$? = $ac_status" >&5
   (exit $ac_status); }; then
-                       test -n "$verbose" && echo "$as_me:2595: result: ... -$cf_opt" >&5
+                       test -n "$verbose" && echo "$as_me:3459: result: ... -$cf_opt" >&5
 echo "${ECHO_T}... -$cf_opt" >&6
                        case $cf_opt in #(vi
                        Wcast-qual) #(vi
@@ -2603,7 +3467,7 @@ echo "${ECHO_T}... -$cf_opt" >&6
                                [34].*)
                                        test -n "$verbose" && echo "    feature is broken in gcc $GCC_VERSION" 1>&6
 
-echo "${as_me-configure}:2606: testing feature is broken in gcc $GCC_VERSION ..." 1>&5
+echo "${as_me-configure}:3470: testing feature is broken in gcc $GCC_VERSION ..." 1>&5
 
                                        continue;;
                                esac
@@ -2619,7 +3483,7 @@ rm -f conftest*
 fi
 fi
 
-echo "$as_me:2622: checking if you want to see long compiling messages" >&5
+echo "$as_me:3486: checking if you want to see long compiling messages" >&5
 echo $ECHO_N "checking if you want to see long compiling messages... $ECHO_C" >&6
 
 # Check whether --enable-echo or --disable-echo was given.
@@ -2653,7 +3517,7 @@ else
     ECHO_CC=''
 
 fi;
-echo "$as_me:2656: result: $enableval" >&5
+echo "$as_me:3520: result: $enableval" >&5
 echo "${ECHO_T}$enableval" >&6
 
 case $cf_cv_system_name in
@@ -2679,7 +3543,7 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 ac_main_return=return
-echo "$as_me:2682: checking how to run the C preprocessor" >&5
+echo "$as_me:3546: checking how to run the C preprocessor" >&5
 echo $ECHO_N "checking how to run the C preprocessor... $ECHO_C" >&6
 # On Suns, sometimes $CPP names a directory.
 if test -n "$CPP" && test -d "$CPP"; then
@@ -2700,18 +3564,18 @@ do
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp. "Syntax error" is here to catch this case.
   cat >conftest.$ac_ext <<_ACEOF
-#line 2703 "configure"
+#line 3567 "configure"
 #include "confdefs.h"
 #include <assert.h>
                      Syntax error
 _ACEOF
-if { (eval echo "$as_me:2708: \"$ac_cpp conftest.$ac_ext\"") >&5
+if { (eval echo "$as_me:3572: \"$ac_cpp conftest.$ac_ext\"") >&5
   (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
   ac_status=$?
   egrep -v '^ *\+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
-  echo "$as_me:2714: \$? = $ac_status" >&5
+  echo "$as_me:3578: \$? = $ac_status" >&5
   (exit $ac_status); } >/dev/null; then
   if test -s conftest.err; then
     ac_cpp_err=$ac_c_preproc_warn_flag
@@ -2734,17 +3598,17 @@ rm -f conftest.err conftest.$ac_ext
   # OK, works on sane cases.  Now check whether non-existent headers
   # can be detected and how.
   cat >conftest.$ac_ext <<_ACEOF
-#line 2737 "configure"
+#line 3601 "configure"
 #include "confdefs.h"
 #include <ac_nonexistent.h>
 _ACEOF
-if { (eval echo "$as_me:2741: \"$ac_cpp conftest.$ac_ext\"") >&5
+if { (eval echo "$as_me:3605: \"$ac_cpp conftest.$ac_ext\"") >&5
   (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
   ac_status=$?
   egrep -v '^ *\+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
-  echo "$as_me:2747: \$? = $ac_status" >&5
+  echo "$as_me:3611: \$? = $ac_status" >&5
   (exit $ac_status); } >/dev/null; then
   if test -s conftest.err; then
     ac_cpp_err=$ac_c_preproc_warn_flag
@@ -2781,7 +3645,7 @@ fi
 else
   ac_cv_prog_CPP=$CPP
 fi
-echo "$as_me:2784: result: $CPP" >&5
+echo "$as_me:3648: result: $CPP" >&5
 echo "${ECHO_T}$CPP" >&6
 ac_preproc_ok=false
 for ac_c_preproc_warn_flag in '' yes
@@ -2791,18 +3655,18 @@ do
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp. "Syntax error" is here to catch this case.
   cat >conftest.$ac_ext <<_ACEOF
-#line 2794 "configure"
+#line 3658 "configure"
 #include "confdefs.h"
 #include <assert.h>
                      Syntax error
 _ACEOF
-if { (eval echo "$as_me:2799: \"$ac_cpp conftest.$ac_ext\"") >&5
+if { (eval echo "$as_me:3663: \"$ac_cpp conftest.$ac_ext\"") >&5
   (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
   ac_status=$?
   egrep -v '^ *\+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
-  echo "$as_me:2805: \$? = $ac_status" >&5
+  echo "$as_me:3669: \$? = $ac_status" >&5
   (exit $ac_status); } >/dev/null; then
   if test -s conftest.err; then
     ac_cpp_err=$ac_c_preproc_warn_flag
@@ -2825,17 +3689,17 @@ rm -f conftest.err conftest.$ac_ext
   # OK, works on sane cases.  Now check whether non-existent headers
   # can be detected and how.
   cat >conftest.$ac_ext <<_ACEOF
-#line 2828 "configure"
+#line 3692 "configure"
 #include "confdefs.h"
 #include <ac_nonexistent.h>
 _ACEOF
-if { (eval echo "$as_me:2832: \"$ac_cpp conftest.$ac_ext\"") >&5
+if { (eval echo "$as_me:3696: \"$ac_cpp conftest.$ac_ext\"") >&5
   (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
   ac_status=$?
   egrep -v '^ *\+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
-  echo "$as_me:2838: \$? = $ac_status" >&5
+  echo "$as_me:3702: \$? = $ac_status" >&5
   (exit $ac_status); } >/dev/null; then
   if test -s conftest.err; then
     ac_cpp_err=$ac_c_preproc_warn_flag
@@ -2863,7 +3727,7 @@ rm -f conftest.err conftest.$ac_ext
 if $ac_preproc_ok; then
   :
 else
-  { { echo "$as_me:2866: error: C preprocessor \"$CPP\" fails sanity check" >&5
+  { { echo "$as_me:3730: error: C preprocessor \"$CPP\" fails sanity check" >&5
 echo "$as_me: error: C preprocessor \"$CPP\" fails sanity check" >&2;}
    { (exit 1); exit 1; }; }
 fi
@@ -2875,7 +3739,7 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 ac_main_return=return
 
-echo "$as_me:2878: checking if you want to use dmalloc for testing" >&5
+echo "$as_me:3742: checking if you want to use dmalloc for testing" >&5
 echo $ECHO_N "checking if you want to use dmalloc for testing... $ECHO_C" >&6
 
 # Check whether --with-dmalloc or --without-dmalloc was given.
@@ -2891,7 +3755,7 @@ EOF
 else
   with_dmalloc=
 fi;
-echo "$as_me:2894: result: ${with_dmalloc:-no}" >&5
+echo "$as_me:3758: result: ${with_dmalloc:-no}" >&5
 echo "${ECHO_T}${with_dmalloc:-no}" >&6
 
 case .$with_cflags in #(vi
@@ -2985,23 +3849,23 @@ fi
 esac
 
 if test "$with_dmalloc" = yes ; then
-       echo "$as_me:2988: checking for dmalloc.h" >&5
+       echo "$as_me:3852: checking for dmalloc.h" >&5
 echo $ECHO_N "checking for dmalloc.h... $ECHO_C" >&6
 if test "${ac_cv_header_dmalloc_h+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
-#line 2994 "configure"
+#line 3858 "configure"
 #include "confdefs.h"
 #include <dmalloc.h>
 _ACEOF
-if { (eval echo "$as_me:2998: \"$ac_cpp conftest.$ac_ext\"") >&5
+if { (eval echo "$as_me:3862: \"$ac_cpp conftest.$ac_ext\"") >&5
   (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
   ac_status=$?
   egrep -v '^ *\+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
-  echo "$as_me:3004: \$? = $ac_status" >&5
+  echo "$as_me:3868: \$? = $ac_status" >&5
   (exit $ac_status); } >/dev/null; then
   if test -s conftest.err; then
     ac_cpp_err=$ac_c_preproc_warn_flag
@@ -3020,11 +3884,11 @@ else
 fi
 rm -f conftest.err conftest.$ac_ext
 fi
-echo "$as_me:3023: result: $ac_cv_header_dmalloc_h" >&5
+echo "$as_me:3887: result: $ac_cv_header_dmalloc_h" >&5
 echo "${ECHO_T}$ac_cv_header_dmalloc_h" >&6
 if test $ac_cv_header_dmalloc_h = yes; then
 
-echo "$as_me:3027: checking for dmalloc_debug in -ldmalloc" >&5
+echo "$as_me:3891: checking for dmalloc_debug in -ldmalloc" >&5
 echo $ECHO_N "checking for dmalloc_debug in -ldmalloc... $ECHO_C" >&6
 if test "${ac_cv_lib_dmalloc_dmalloc_debug+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
@@ -3032,7 +3896,7 @@ else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-ldmalloc  $LIBS"
 cat >conftest.$ac_ext <<_ACEOF
-#line 3035 "configure"
+#line 3899 "configure"
 #include "confdefs.h"
 
 /* Override any gcc2 internal prototype to avoid an error.  */
@@ -3051,16 +3915,16 @@ dmalloc_debug ();
 }
 _ACEOF
 rm -f conftest.$ac_objext conftest$ac_exeext
-if { (eval echo "$as_me:3054: \"$ac_link\"") >&5
+if { (eval echo "$as_me:3918: \"$ac_link\"") >&5
   (eval $ac_link) 2>&5
   ac_status=$?
-  echo "$as_me:3057: \$? = $ac_status" >&5
+  echo "$as_me:3921: \$? = $ac_status" >&5
   (exit $ac_status); } &&
          { ac_try='test -s conftest$ac_exeext'
-  { (eval echo "$as_me:3060: \"$ac_try\"") >&5
+  { (eval echo "$as_me:3924: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
-  echo "$as_me:3063: \$? = $ac_status" >&5
+  echo "$as_me:3927: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
   ac_cv_lib_dmalloc_dmalloc_debug=yes
 else
@@ -3071,7 +3935,7 @@ fi
 rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-echo "$as_me:3074: result: $ac_cv_lib_dmalloc_dmalloc_debug" >&5
+echo "$as_me:3938: result: $ac_cv_lib_dmalloc_dmalloc_debug" >&5
 echo "${ECHO_T}$ac_cv_lib_dmalloc_dmalloc_debug" >&6
 if test $ac_cv_lib_dmalloc_dmalloc_debug = yes; then
   cat >>confdefs.h <<EOF
@@ -3086,7 +3950,7 @@ fi
 
 fi
 
-echo "$as_me:3089: checking if you want to use dbmalloc for testing" >&5
+echo "$as_me:3953: checking if you want to use dbmalloc for testing" >&5
 echo $ECHO_N "checking if you want to use dbmalloc for testing... $ECHO_C" >&6
 
 # Check whether --with-dbmalloc or --without-dbmalloc was given.
@@ -3102,7 +3966,7 @@ EOF
 else
   with_dbmalloc=
 fi;
-echo "$as_me:3105: result: ${with_dbmalloc:-no}" >&5
+echo "$as_me:3969: result: ${with_dbmalloc:-no}" >&5
 echo "${ECHO_T}${with_dbmalloc:-no}" >&6
 
 case .$with_cflags in #(vi
@@ -3196,23 +4060,23 @@ fi
 esac
 
 if test "$with_dbmalloc" = yes ; then
-       echo "$as_me:3199: checking for dbmalloc.h" >&5
+       echo "$as_me:4063: checking for dbmalloc.h" >&5
 echo $ECHO_N "checking for dbmalloc.h... $ECHO_C" >&6
 if test "${ac_cv_header_dbmalloc_h+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
 else
   cat >conftest.$ac_ext <<_ACEOF
-#line 3205 "configure"
+#line 4069 "configure"
 #include "confdefs.h"
 #include <dbmalloc.h>
 _ACEOF
-if { (eval echo "$as_me:3209: \"$ac_cpp conftest.$ac_ext\"") >&5
+if { (eval echo "$as_me:4073: \"$ac_cpp conftest.$ac_ext\"") >&5
   (eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
   ac_status=$?
   egrep -v '^ *\+' conftest.er1 >conftest.err
   rm -f conftest.er1
   cat conftest.err >&5
-  echo "$as_me:3215: \$? = $ac_status" >&5
+  echo "$as_me:4079: \$? = $ac_status" >&5
   (exit $ac_status); } >/dev/null; then
   if test -s conftest.err; then
     ac_cpp_err=$ac_c_preproc_warn_flag
@@ -3231,11 +4095,11 @@ else
 fi
 rm -f conftest.err conftest.$ac_ext
 fi
-echo "$as_me:3234: result: $ac_cv_header_dbmalloc_h" >&5
+echo "$as_me:4098: result: $ac_cv_header_dbmalloc_h" >&5
 echo "${ECHO_T}$ac_cv_header_dbmalloc_h" >&6
 if test $ac_cv_header_dbmalloc_h = yes; then
 
-echo "$as_me:3238: checking for debug_malloc in -ldbmalloc" >&5
+echo "$as_me:4102: checking for debug_malloc in -ldbmalloc" >&5
 echo $ECHO_N "checking for debug_malloc in -ldbmalloc... $ECHO_C" >&6
 if test "${ac_cv_lib_dbmalloc_debug_malloc+set}" = set; then
   echo $ECHO_N "(cached) $ECHO_C" >&6
@@ -3243,7 +4107,7 @@ else
   ac_check_lib_save_LIBS=$LIBS
 LIBS="-ldbmalloc  $LIBS"
 cat >conftest.$ac_ext <<_ACEOF
-#line 3246 "configure"
+#line 4110 "configure"
 #include "confdefs.h"
 
 /* Override any gcc2 internal prototype to avoid an error.  */
@@ -3262,16 +4126,16 @@ debug_malloc ();
 }
 _ACEOF
 rm -f conftest.$ac_objext conftest$ac_exeext
-if { (eval echo "$as_me:3265: \"$ac_link\"") >&5
+if { (eval echo "$as_me:4129: \"$ac_link\"") >&5
   (eval $ac_link) 2>&5
   ac_status=$?
-  echo "$as_me:3268: \$? = $ac_status" >&5
+  echo "$as_me:4132: \$? = $ac_status" >&5
   (exit $ac_status); } &&
          { ac_try='test -s conftest$ac_exeext'
-  { (eval echo "$as_me:3271: \"$ac_try\"") >&5
+  { (eval echo "$as_me:4135: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
-  echo "$as_me:3274: \$? = $ac_status" >&5
+  echo "$as_me:4138: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
   ac_cv_lib_dbmalloc_debug_malloc=yes
 else
@@ -3282,7 +4146,7 @@ fi
 rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
 LIBS=$ac_check_lib_save_LIBS
 fi
-echo "$as_me:3285: result: $ac_cv_lib_dbmalloc_debug_malloc" >&5
+echo "$as_me:4149: result: $ac_cv_lib_dbmalloc_debug_malloc" >&5
 echo "${ECHO_T}$ac_cv_lib_dbmalloc_debug_malloc" >&6
 if test $ac_cv_lib_dbmalloc_debug_malloc = yes; then
   cat >>confdefs.h <<EOF
@@ -3297,7 +4161,7 @@ fi
 
 fi
 
-echo "$as_me:3300: checking if you want to use valgrind for testing" >&5
+echo "$as_me:4164: checking if you want to use valgrind for testing" >&5
 echo $ECHO_N "checking if you want to use valgrind for testing... $ECHO_C" >&6
 
 # Check whether --with-valgrind or --without-valgrind was given.
@@ -3313,7 +4177,7 @@ EOF
 else
   with_valgrind=
 fi;
-echo "$as_me:3316: result: ${with_valgrind:-no}" >&5
+echo "$as_me:4180: result: ${with_valgrind:-no}" >&5
 echo "${ECHO_T}${with_valgrind:-no}" >&6
 
 case .$with_cflags in #(vi
@@ -3406,17 +4270,17 @@ fi
        ;;
 esac
 
-echo "$as_me:3409: checking if you want to perform memory-leak testing" >&5
+echo "$as_me:4273: checking if you want to perform memory-leak testing" >&5
 echo $ECHO_N "checking if you want to perform memory-leak testing... $ECHO_C" >&6
 
 # Check whether --enable-leaks or --disable-leaks was given.
 if test "${enable_leaks+set}" = set; then
   enableval="$enable_leaks"
-  with_no_leaks=yes
+  if test "x$enableval" = xno; then with_no_leaks=yes; else with_no_leaks=no; fi
 else
   : ${with_no_leaks:=no}
 fi;
-echo "$as_me:3419: result: $with_no_leaks" >&5
+echo "$as_me:4283: result: $with_no_leaks" >&5
 echo "${ECHO_T}$with_no_leaks" >&6
 
 if test "$with_no_leaks" = yes ; then
@@ -3508,7 +4372,7 @@ DEFS=-DHAVE_CONFIG_H
 : ${CONFIG_STATUS=./config.status}
 ac_clean_files_save=$ac_clean_files
 ac_clean_files="$ac_clean_files $CONFIG_STATUS"
-{ echo "$as_me:3511: creating $CONFIG_STATUS" >&5
+{ echo "$as_me:4375: creating $CONFIG_STATUS" >&5
 echo "$as_me: creating $CONFIG_STATUS" >&6;}
 cat >$CONFIG_STATUS <<_ACEOF
 #! $SHELL
@@ -3640,7 +4504,7 @@ EOF
 cat >>$CONFIG_STATUS <<EOF
 ac_cs_version="\\
 config.status
-configured by $0, generated by GNU Autoconf 2.52.20081225,
+configured by $0, generated by GNU Autoconf 2.52.20100530,
   with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
 
 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001
@@ -3684,7 +4548,7 @@ cat >>$CONFIG_STATUS <<\EOF
     echo "$ac_cs_version"; exit 0 ;;
   --he | --h)
     # Conflict between --help and --header
-    { { echo "$as_me:3687: error: ambiguous option: $1
+    { { echo "$as_me:4551: error: ambiguous option: $1
 Try \`$0 --help' for more information." >&5
 echo "$as_me: error: ambiguous option: $1
 Try \`$0 --help' for more information." >&2;}
@@ -3703,7 +4567,7 @@ Try \`$0 --help' for more information." >&2;}
     ac_need_defaults=false;;
 
   # This is an error.
-  -*) { { echo "$as_me:3706: error: unrecognized option: $1
+  -*) { { echo "$as_me:4570: error: unrecognized option: $1
 Try \`$0 --help' for more information." >&5
 echo "$as_me: error: unrecognized option: $1
 Try \`$0 --help' for more information." >&2;}
@@ -3722,7 +4586,7 @@ cat >&5 << _ACEOF
 ## Running config.status.  ##
 ## ----------------------- ##
 
-This file was extended by $as_me 2.52.20081225, executed with
+This file was extended by $as_me 2.52.20100530, executed with
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_HEADERS  = $CONFIG_HEADERS
   CONFIG_LINKS    = $CONFIG_LINKS
@@ -3741,7 +4605,7 @@ do
   "makefile" ) CONFIG_FILES="$CONFIG_FILES makefile" ;;
   "default" ) CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;;
   "config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h:config_h.in" ;;
-  *) { { echo "$as_me:3744: error: invalid argument: $ac_config_target" >&5
+  *) { { echo "$as_me:4608: error: invalid argument: $ac_config_target" >&5
 echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
    { (exit 1); exit 1; }; };;
   esac
@@ -3846,6 +4710,12 @@ s,@SET_MAKE@,$SET_MAKE,;t t
 s,@INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t
 s,@INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t
 s,@INSTALL_DATA@,$INSTALL_DATA,;t t
+s,@CTAGS@,$CTAGS,;t t
+s,@ETAGS@,$ETAGS,;t t
+s,@MAKE_LOWER_TAGS@,$MAKE_LOWER_TAGS,;t t
+s,@MAKE_UPPER_TAGS@,$MAKE_UPPER_TAGS,;t t
+s,@LINT@,$LINT,;t t
+s,@LINT_OPTS@,$LINT_OPTS,;t t
 s,@EXTRA_CPPFLAGS@,$EXTRA_CPPFLAGS,;t t
 s,@EXTRA_CFLAGS@,$EXTRA_CFLAGS,;t t
 s,@ECHO_LT@,$ECHO_LT,;t t
@@ -3969,7 +4839,7 @@ done; }
   esac
 
   if test x"$ac_file" != x-; then
-    { echo "$as_me:3972: creating $ac_file" >&5
+    { echo "$as_me:4842: creating $ac_file" >&5
 echo "$as_me: creating $ac_file" >&6;}
     rm -f "$ac_file"
   fi
@@ -3987,7 +4857,7 @@ echo "$as_me: creating $ac_file" >&6;}
       -) echo $tmp/stdin ;;
       [\\/$]*)
          # Absolute (can't be DOS-style, as IFS=:)
-         test -f "$f" || { { echo "$as_me:3990: error: cannot find input file: $f" >&5
+         test -f "$f" || { { echo "$as_me:4860: error: cannot find input file: $f" >&5
 echo "$as_me: error: cannot find input file: $f" >&2;}
    { (exit 1); exit 1; }; }
          echo $f;;
@@ -4000,7 +4870,7 @@ echo "$as_me: error: cannot find input file: $f" >&2;}
            echo $srcdir/$f
          else
            # /dev/null tree
-           { { echo "$as_me:4003: error: cannot find input file: $f" >&5
+           { { echo "$as_me:4873: error: cannot find input file: $f" >&5
 echo "$as_me: error: cannot find input file: $f" >&2;}
    { (exit 1); exit 1; }; }
          fi;;
@@ -4066,7 +4936,7 @@ for ac_file in : $CONFIG_HEADERS; do test "x$ac_file" = x: && continue
   * )   ac_file_in=$ac_file.in ;;
   esac
 
-  test x"$ac_file" != x- && { echo "$as_me:4069: creating $ac_file" >&5
+  test x"$ac_file" != x- && { echo "$as_me:4939: creating $ac_file" >&5
 echo "$as_me: creating $ac_file" >&6;}
 
   # First look for the input files in the build tree, otherwise in the
@@ -4077,7 +4947,7 @@ echo "$as_me: creating $ac_file" >&6;}
       -) echo $tmp/stdin ;;
       [\\/$]*)
          # Absolute (can't be DOS-style, as IFS=:)
-         test -f "$f" || { { echo "$as_me:4080: error: cannot find input file: $f" >&5
+         test -f "$f" || { { echo "$as_me:4950: error: cannot find input file: $f" >&5
 echo "$as_me: error: cannot find input file: $f" >&2;}
    { (exit 1); exit 1; }; }
          echo $f;;
@@ -4090,7 +4960,7 @@ echo "$as_me: error: cannot find input file: $f" >&2;}
            echo $srcdir/$f
          else
            # /dev/null tree
-           { { echo "$as_me:4093: error: cannot find input file: $f" >&5
+           { { echo "$as_me:4963: error: cannot find input file: $f" >&5
 echo "$as_me: error: cannot find input file: $f" >&2;}
    { (exit 1); exit 1; }; }
          fi;;
@@ -4148,7 +5018,7 @@ cat >>$CONFIG_STATUS <<\EOF
   rm -f $tmp/in
   if test x"$ac_file" != x-; then
     if cmp -s $ac_file $tmp/config.h 2>/dev/null; then
-      { echo "$as_me:4151: $ac_file is unchanged" >&5
+      { echo "$as_me:5021: $ac_file is unchanged" >&5
 echo "$as_me: $ac_file is unchanged" >&6;}
     else
       ac_dir=`$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
@@ -4189,19 +5059,6 @@ done; }
   fi
 done
 EOF
-cat >>$CONFIG_STATUS <<\EOF
-
-#
-# CONFIG_COMMANDS section.
-#
-for ac_file in : $CONFIG_COMMANDS; do test "x$ac_file" = x: && continue
-  ac_dest=`echo "$ac_file" | sed 's,:.*,,'`
-  ac_source=`echo "$ac_file" | sed 's,[^:]*:,,'`
-
-  case $ac_dest in
-  esac
-done
-EOF
 
 cat >>$CONFIG_STATUS <<\EOF
 
index 5a0129afc67a462f0894585f6e873cfe77bf14d7..598801276f0042975cdac1c762c6801af4953a99 100644 (file)
@@ -1,7 +1,7 @@
 dnl Process this file with 'autoconf' to produce a 'configure' script
-dnl $Id: configure.in,v 1.6 2008/08/27 23:38:10 tom Exp $
+dnl $Id: configure.in,v 1.9 2010/06/09 09:29:49 tom Exp $
 AC_PREREQ(2.13.20020210)
-AC_REVISION($Revision: 1.6 $)
+AC_REVISION($Revision: 1.9 $)
 AC_INIT(main.c)
 AC_CONFIG_HEADER(config.h:config_h.in)
 
@@ -12,8 +12,11 @@ AC_PROG_CC
 AC_CONST
 AC_PROG_MAKE_SET
 AC_PROG_INSTALL
+CF_MAKE_TAGS
+CF_PROG_LINT
 
 CF_ANSI_CC_REQD
+CF_XOPEN_SOURCE
 
 CF_WITH_WARNINGS(Wwrite-strings)
 CF_DISABLE_ECHO
diff --git a/defs.h b/defs.h
index 8444e6d8251e43dea398cb8a877aacc69c7fea14..18350aa26674a86af7d2a570543732448abe380c 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -1,4 +1,4 @@
-/* $Id: defs.h,v 1.23 2010/02/17 00:48:59 tom Exp $ */
+/* $Id: defs.h,v 1.28 2010/06/10 00:09:42 tom Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -64,6 +64,8 @@
 #define        DOUBLE_QUOTE    '\"'    /*  double quote  */
 #define        BACKSLASH       '\\'    /*  backslash  */
 
+#define UCH(c)          (unsigned char)(c)
+
 /* defines for constructing filenames */
 
 #if defined(VMS)
@@ -93,6 +95,9 @@
 #define EXPECT 10
 #define EXPECT_RR 11
 #define PURE_PARSER 12
+#define PARSE_PARAM 13
+#define LEX_PARAM 14
+#define POSIX_YACC 15
 
 /*  symbol classes  */
 
 
 /*  storage allocation macros  */
 
-#define CALLOC(k,n)    (calloc((unsigned)(k),(unsigned)(n)))
+#define CALLOC(k,n)    (calloc((size_t)(k),(size_t)(n)))
 #define        FREE(x)         (free((char*)(x)))
-#define MALLOC(n)      (malloc((unsigned)(n)))
+#define MALLOC(n)      (malloc((size_t)(n)))
 #define        NEW(t)          ((t*)allocate(sizeof(t)))
-#define        NEW2(n,t)       ((t*)allocate(((unsigned)(n)*sizeof(t))))
-#define REALLOC(p,n)   (realloc((char*)(p),(unsigned)(n)))
+#define        NEW2(n,t)       ((t*)allocate(((size_t)(n)*sizeof(t))))
+#define REALLOC(p,n)   (realloc((char*)(p),(size_t)(n)))
 
 #define DO_FREE(x)     if (x) { FREE(x); x = 0; }
 
+#define NO_SPACE(p)    if (p == 0) no_space(); assert(p != 0)
+
 /* messages */
 #define PLURAL(n) ((n) > 1 ? "s" : "")
 
@@ -204,6 +211,16 @@ struct action
     char suppressed;
 };
 
+/*  the structure used to store parse/lex parameters  */
+typedef struct param param;
+struct param
+{
+    struct param *next;
+    char *name;                /* parameter name */
+    char *type;                /* everything before parameter name */
+    char *type2;       /* everything after parameter name */
+};
+
 /* global variables */
 
 extern char dflag;
@@ -220,6 +237,7 @@ extern char *line;
 extern int lineno;
 extern int outline;
 extern int exit_code;
+extern int pure_parser;
 
 extern const char *banner[];
 extern const char *xdecls[];
@@ -309,6 +327,9 @@ extern Value_t *itemset;
 extern Value_t *itemsetend;
 extern unsigned *ruleset;
 
+extern param *lex_param;
+extern param *parse_param;
+
 /* global functions */
 
 extern bucket *lookup(const char *);
@@ -323,7 +344,7 @@ extern bucket *make_bucket(const char *);
 #endif
 
 /* closure.c */
-extern void closure(Value_t *nucleus, int n);
+extern void closure(Value_t * nucleus, int n);
 extern void finalize_closure(void);
 extern void set_first_derives(void);
 
@@ -381,7 +402,7 @@ extern void show_rrhs(void);
 extern void show_shifts(void);
 
 /* main.c */
-extern char *allocate(unsigned n);
+extern char *allocate(size_t n);
 extern void done(int k) GCC_NORETURN;
 
 /* mkpar.c */
diff --git a/error.c b/error.c
index 314ff24cad55dc3e27253a863ea0ed43ea256b5c..71f959b01af1c45f3d7bedec23d2e6515586a328 100644 (file)
--- a/error.c
+++ b/error.c
@@ -1,4 +1,4 @@
-/* $Id: error.c,v 1.6 2008/11/24 21:30:35 tom Exp $ */
+/* $Id: error.c,v 1.7 2010/06/06 23:13:17 tom Exp $ */
 
 /* routines for printing error messages  */
 
@@ -42,7 +42,7 @@ print_pos(char *st_line, char *st_cptr)
        return;
     for (s = st_line; *s != '\n'; ++s)
     {
-       if (isprint(*s) || *s == '\t')
+       if (isprint(UCH(*s)) || *s == '\t')
            putc(*s, stderr);
        else
            putc('?', stderr);
diff --git a/lr0.c b/lr0.c
index 391a65070146c12a9d3019c789746d5826a6a176..07599734b35efe1e40c3a029ecd9d8ab8857250e 100644 (file)
--- a/lr0.c
+++ b/lr0.c
@@ -1,4 +1,4 @@
-/* $Id: lr0.c,v 1.9 2009/10/27 09:20:39 tom Exp $ */
+/* $Id: lr0.c,v 1.12 2010/06/09 08:53:17 tom Exp $ */
 
 #include "defs.h"
 
@@ -171,7 +171,7 @@ get_state(int symbol)
 
     isp1 = kernel_base[symbol];
     iend = kernel_end[symbol];
-    n = iend - isp1;
+    n = (int)(iend - isp1);
 
     key = *isp1;
     assert(0 <= key && key < nitems);
@@ -228,8 +228,7 @@ initialize_states(void)
        continue;
 
     p = (core *)MALLOC(sizeof(core) + i * sizeof(short));
-    if (p == 0)
-       no_space();
+    NO_SPACE(p);
 
     p->next = 0;
     p->link = 0;
@@ -299,7 +298,7 @@ new_state(int symbol)
     iend = kernel_end[symbol];
     n = (unsigned)(iend - isp1);
 
-    p = (core *)allocate((unsigned)(sizeof(core) + (n - 1) * sizeof(short)));
+    p = (core *)allocate((sizeof(core) + (n - 1) * sizeof(short)));
     p->accessing_symbol = (Value_t) symbol;
     p->number = (Value_t) nstates;
     p->nitems = (Value_t) n;
@@ -403,8 +402,8 @@ save_shifts(void)
     short *sp2;
     short *send;
 
-    p = (shifts *)allocate((unsigned)(sizeof(shifts) +
-                                       (unsigned)(nshifts - 1) * sizeof(short)));
+    p = (shifts *)allocate((sizeof(shifts) +
+                             (unsigned)(nshifts - 1) * sizeof(short)));
 
     p->number = this_state->number;
     p->nshifts = (Value_t) nshifts;
@@ -451,9 +450,9 @@ save_reductions(void)
 
     if (count)
     {
-       p = (reductions *)allocate((unsigned)(sizeof(reductions) +
-                                               (unsigned)(count - 1) *
-                                             sizeof(short)));
+       p = (reductions *)allocate((sizeof(reductions) +
+                                     (unsigned)(count - 1) *
+                                   sizeof(short)));
 
        p->number = this_state->number;
        p->nreds = count;
@@ -540,8 +539,7 @@ set_nullable(void)
     int done_flag;
 
     nullable = MALLOC(nsyms);
-    if (nullable == 0)
-       no_space();
+    NO_SPACE(nullable);
 
     for (i = 0; i < nsyms; ++i)
        nullable[i] = 0;
diff --git a/main.c b/main.c
index a019a5af5b784c4285780a7ba55b65455f59d8fe..f83d83227237a774365c08385fd56246d9a50b21 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.24 2010/02/17 00:43:08 tom Exp $ */
+/* $Id: main.c,v 1.29 2010/06/10 00:39:13 tom Exp $ */
 
 #include <signal.h>
 #include <unistd.h>            /* for _exit() */
@@ -121,6 +121,9 @@ done(int k)
     reader_leaks();
 #endif
 
+    if (rflag)
+       DO_CLOSE(code_file);
+
     exit(k);
 }
 
@@ -161,6 +164,7 @@ usage(void)
        ,"  -l                    suppress #line directives"
        ,"  -o output_file        (default \"y.tab.c\")"
        ,"  -p symbol_prefix      set symbol prefix (default \"yy\")"
+       ,"  -P                    create a reentrant parser, e.g., \"%pure-parser\""
        ,"  -r                    produce separate code and table files (y.code.c)"
        ,"  -t                    add debugging support"
        ,"  -v                    write description (y.output)"
@@ -213,6 +217,11 @@ setflag(int ch)
        printf("%s - %s\n", myname, VERSION);
        exit(EXIT_SUCCESS);
 
+    case 'y':
+       /* noop for bison compatibility. byacc is already designed to be posix
+        * yacc compatible. */
+       break;
+
     default:
        usage();
     }
@@ -299,7 +308,7 @@ getargs(int argc, char *argv[])
 }
 
 char *
-allocate(unsigned n)
+allocate(size_t n)
 {
     char *p;
 
@@ -307,16 +316,14 @@ allocate(unsigned n)
     if (n)
     {
        p = CALLOC(1, n);
-       if (!p)
-           no_space();
+       NO_SPACE(p);
     }
     return (p);
 }
 
 #define CREATE_FILE_NAME(dest, suffix) \
        dest = MALLOC(len + strlen(suffix) + 1); \
-       if (dest == 0) \
-           no_space(); \
+       NO_SPACE(dest); \
        strcpy(dest, file_prefix); \
        strcpy(dest + len, suffix)
 
@@ -342,8 +349,7 @@ create_file_names(void)
     {
        len = (size_t) (prefix - output_file_name);
        file_prefix = (char *)MALLOC(len + 1);
-       if (file_prefix == 0)
-           no_space();
+       NO_SPACE(file_prefix);
        strncpy(file_prefix, output_file_name, len)[len] = 0;
     }
     else
index ea4657e83adf23148193bedd7ce3c2236ab1bb00..61fd49041dcc6d5ed5c1da22a1dc74323ac8d937 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: makefile.in,v 1.11 2009/10/26 23:49:57 tom Exp $
+# $Id: makefile.in,v 1.16 2010/06/09 09:46:37 tom Exp $
 #
 # UNIX template-makefile for Berkeley Yacc
 
@@ -24,6 +24,10 @@ CFLAGS               = @CFLAGS@ $(CPPFLAGS) $(EXTRA_CFLAGS)
 LDFLAGS                = @LDFLAGS@
 LIBS           = @LIBS@
 
+CTAGS          = @CTAGS@
+ETAGS          = @ETAGS@
+LINT           = @LINT@
+
 prefix         = @prefix@
 exec_prefix    = @exec_prefix@
 
@@ -31,6 +35,8 @@ bindir                = $(DESTDIR)@bindir@
 mandir         = $(DESTDIR)@mandir@/man1
 manext         = 1
 
+testdir                = $(srcdir)/test
+
 x              = @EXEEXT@
 o              = .@OBJEXT@
 
@@ -85,41 +91,85 @@ install: all installdirs
        - $(INSTALL_DATA) $(srcdir)/$(THIS).1 $(mandir)/$(actual_man)
 
 installdirs:
-       $(SHELL) ${srcdir}/mkdirs.sh $(bindir)
-       - $(SHELL) ${srcdir}/mkdirs.sh $(mandir)
+       mkdir -p $(bindir)
+       - mkdir -p $(mandir)
 
 uninstall:
        - rm -f $(bindir)/$(actual_bin)
        - rm -f $(mandir)/$(actual_man)
 
+################################################################################
+.SUFFIXES : $o .i .html .$(manext) .cat .ps .pdf .txt
+
 .c$o:
        @RULE_CC@
        @ECHO_CC@$(CC) -c $(CFLAGS) $<
 
+.c.i :
+       @RULE_CC@
+       @ECHO_CC@$(CPP) -C $(CPPFLAGS) $*.c >$@
+
+.$(manext).cat :
+       - nroff -man $(srcdir)/$(THIS).$(manext) >$@
+
+.$(manext).html :
+       GROFF_NO_SGR=stupid $(SHELL) -c "tbl $*.$(manext) | groff -Thtml -man" >$@
+
+.$(manext).ps :
+       $(SHELL) -c "tbl $*.$(manext) | groff -man" >$@
+
+.$(manext).txt :
+       GROFF_NO_SGR=stupid $(SHELL) -c "tbl $*.$(manext) | nroff -Tascii -man | col -bx" >$@
+
+.ps.pdf :
+       ps2pdf $*.ps
+
+################################################################################
+
 $(THIS)$x : $(OBJS)
        @ECHO_LD@$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJS) $(LIBS)
 
-$(THIS).man : $(THIS).1
-       - nroff -man $(srcdir)/$(THIS).1 >$@
-
 mostlyclean :
-       - rm -f core .nfs* *$o *.bak *.BAK *.man *.out
+       - rm -f core .nfs* *$o *.bak *.BAK *.out
 
 clean : mostlyclean
        - rm -f $(THIS)$x
 
 distclean : clean
        - rm -f config.log config.cache config.status config.h makefile
+       - rm -f *.html *.cat *.pdf *.ps *.txt
        - cd test && rm -f test-*
 
 realclean: distclean
-       - rm -f tags
-
+       - rm -f tags TAGS
+
+################################################################################
+docs :: $(THIS).html \
+       $(THIS).pdf \
+       $(THIS).ps \
+       $(THIS).txt
+$(THIS).html : $(THIS).$(manext)
+$(THIS).pdf : $(THIS).ps
+$(THIS).ps : $(THIS).$(manext)
+$(THIS).txt : $(THIS).$(manext)
+################################################################################
 check: $(THIS)$x
-       cd test && $(SHELL) ./run_test.sh
+       $(SHELL) $(testdir)/run_test.sh $(testdir)
+
+check_make:
+       $(SHELL) $(testdir)/run_make.sh $(testdir)
 
+check_lint:
+       $(SHELL) $(testdir)/run_lint.sh $(testdir)
+################################################################################
 tags: $(H_FILES) $(C_FILES) 
-       ctags $(C_FILES) $(H_FILES)
+       $(CTAGS) $(C_FILES) $(H_FILES)
+
+lint: $(C_FILES) 
+       $(LINT) $(CPPFLAGS) $(C_FILES)
+
+@MAKE_UPPER_TAGS@TAGS: $(H_FILES) $(C_FILES) 
+@MAKE_UPPER_TAGS@      $(ETAGS) $(C_FILES) $(H_FILES)
 
 depend:
        makedepend -- $(CPPFLAGS) -- $(C_FILES)
diff --git a/mkdirs.sh b/mkdirs.sh
deleted file mode 100755 (executable)
index aadffed..0000000
--- a/mkdirs.sh
+++ /dev/null
@@ -1,51 +0,0 @@
-#! /bin/sh
-# $Id: mkdirs.sh,v 1.3 2007/03/25 22:29:46 tom Exp $
-# -----------------------------------------------------------------------------
-# mkinstalldirs --- make directory hierarchy
-# Author: Noah Friedman <friedman@prep.ai.mit.edu>
-# Created: 1993-05-16
-# Last modified: 1994-03-25
-# Public domain
-# -----------------------------------------------------------------------------
-
-errstatus=0
-umask 022
-
-for file in ${1+"$@"} ; do
-   set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'`
-   shift
-
-   pathcomp=
-   for d in ${1+"$@"} ; do
-     pathcomp="$pathcomp$d"
-     case "$pathcomp" in
-       -* ) pathcomp=./$pathcomp ;;
-     esac
-
-     if test ! -d "$pathcomp"; then
-        echo "mkdir $pathcomp" 1>&2
-        case "$pathcomp" in
-          [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]: )
-            ;;               # DOSISH systems
-          * )
-            mkdir "$pathcomp"
-            errstatus=$?
-            if test $errstatus != 0
-            then
-               # may have failed if invoked in a parallel "make -j# install"
-               if test -d "$pathcomp"
-               then
-                  errstatus=0
-               fi
-            fi
-            ;;
-        esac
-     fi
-
-     pathcomp="$pathcomp/"
-   done
-done
-
-exit $errstatus
-
-# mkinstalldirs ends here
diff --git a/mkpar.c b/mkpar.c
index 58cc592c07d29edf6831afb61085bd07571e2f81..f9f2b5c2e85da0a06cdb1f81338d6e45de0cead0 100644 (file)
--- a/mkpar.c
+++ b/mkpar.c
@@ -1,4 +1,4 @@
-/* $Id: mkpar.c,v 1.10 2009/10/27 10:50:13 tom Exp $ */
+/* $Id: mkpar.c,v 1.11 2010/06/09 08:53:17 tom Exp $ */
 
 #include "defs.h"
 
@@ -181,8 +181,7 @@ unused_rules(void)
     action *p;
 
     rules_used = (Value_t *) MALLOC((unsigned)nrules * sizeof(Value_t));
-    if (rules_used == 0)
-       no_space();
+    NO_SPACE(rules_used);
 
     for (i = 0; i < nrules; ++i)
        rules_used[i] = 0;
@@ -238,7 +237,7 @@ remove_conflicts(void)
                SRcount++;
                p->suppressed = 1;
            }
-           else if (pref->action_code == SHIFT)
+           else if (pref != 0 && pref->action_code == SHIFT)
            {
                if (pref->prec > 0 && p->prec > 0)
                {
index 51bf59d0cc9d7b8950a141f5e006b3d8587f71c1..73840f720726dc19fa42957c8b073631f7e0e1e6 100644 (file)
--- a/output.c
+++ b/output.c
@@ -1,4 +1,4 @@
-/* $Id: output.c,v 1.24 2010/02/17 01:48:22 tom Exp $ */
+/* $Id: output.c,v 1.29 2010/06/09 21:25:18 tom Exp $ */
 
 #include "defs.h"
 
@@ -532,12 +532,13 @@ pack_vector(int vector)
                    newmax += 200;
                }
                while (newmax <= loc);
+
                table = (Value_t *) REALLOC(table, (unsigned)newmax * sizeof(Value_t));
-               if (table == 0)
-                   no_space();
+               NO_SPACE(table);
+
                check = (Value_t *) REALLOC(check, (unsigned)newmax * sizeof(Value_t));
-               if (check == 0)
-                   no_space();
+               NO_SPACE(check);
+
                for (l = maxtable; l < newmax; ++l)
                {
                    table[l] = 0;
@@ -897,8 +898,7 @@ output_debug(void)
     fprintf(code_file, "#define YYMAXTOKEN %d\n", max);
 
     symnam = (const char **)MALLOC((unsigned)(max + 1) * sizeof(char *));
-    if (symnam == 0)
-       no_space();
+    NO_SPACE(symnam);
 
     /* Note that it is  not necessary to initialize the element         */
     /* symnam[max].                                                     */
@@ -1099,8 +1099,9 @@ output_stype(void)
 {
     if (!unionized && ntags == 0)
     {
-       outline += 3;
-       fprintf(code_file, "#ifndef YYSTYPE\ntypedef int YYSTYPE;\n#endif\n");
+       outline += 5;
+       fprintf(code_file,
+               "\n#ifndef YYSTYPE\ntypedef int YYSTYPE;\n#endif\n\n");
     }
 }
 
@@ -1177,6 +1178,122 @@ output_semantic_actions(void)
     write_code_lineno(out);
 }
 
+static void
+output_parse_decl(void)
+{
+    ++outline;
+    fprintf(code_file, "/* compatibility with bison */\n");
+    ++outline;
+    fprintf(code_file, "#ifdef YYPARSE_PARAM\n");
+    ++outline;
+    fprintf(code_file, "/* compatibility with FreeBSD */\n");
+    ++outline;
+    fprintf(code_file, "# ifdef YYPARSE_PARAM_TYPE\n");
+    ++outline;
+    fprintf(code_file, "#  define YYPARSE_DECL() "
+           "yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)\n");
+    ++outline;
+    fprintf(code_file, "# else\n");
+    ++outline;
+    fprintf(code_file, "#  define YYPARSE_DECL() "
+           "yyparse(void *YYPARSE_PARAM)\n");
+    ++outline;
+    fprintf(code_file, "# endif\n");
+    ++outline;
+    fprintf(code_file, "#else\n");
+    ++outline;
+    fprintf(code_file, "# define YYPARSE_DECL() yyparse(");
+    if (!parse_param)
+       fprintf(code_file, "void");
+    else
+    {
+       param *p;
+       for (p = parse_param; p; p = p->next)
+           fprintf(code_file, "%s %s%s%s", p->type, p->name, p->type2,
+                   p->next ? ", " : "");
+    }
+    fprintf(code_file, ")\n");
+    outline += 2;
+    fprintf(code_file, "#endif\n\n");
+}
+
+static void
+output_lex_decl(void)
+{
+    ++outline;
+    fprintf(code_file, "/* Parameters sent to lex. */\n");
+    ++outline;
+    fprintf(code_file, "#ifdef YYLEX_PARAM\n");
+    if (pure_parser)
+    {
+       ++outline;
+       fprintf(code_file, "# define YYLEX_DECL() yylex(YYSTYPE *yylval, "
+               "void *YYLEX_PARAM)\n");
+       ++outline;
+       fprintf(code_file, "# define YYLEX yylex(&yylval, YYLEX_PARAM)\n");
+    }
+    else
+    {
+       ++outline;
+       fprintf(code_file,
+               "# define YYLEX_DECL() yylex(void *YYLEX_PARAM)\n");
+       ++outline;
+       fprintf(code_file, "# define YYLEX yylex(YYLEX_PARAM)\n");
+    }
+    ++outline;
+    fprintf(code_file, "#else\n");
+    if (pure_parser && lex_param)
+    {
+       param *p;
+       fprintf(code_file, "# define YYLEX_DECL() yylex(YYSTYPE *yylval, ");
+       for (p = lex_param; p; p = p->next)
+           fprintf(code_file, "%s %s%s%s", p->type, p->name, p->type2,
+                   p->next ? ", " : "");
+       ++outline;
+       fprintf(code_file, ")\n");
+
+       fprintf(code_file, "# define YYLEX yylex(&yylval, ");
+       for (p = lex_param; p; p = p->next)
+           fprintf(code_file, "%s%s", p->name, p->next ? ", " : "");
+       ++outline;
+       fprintf(code_file, ")\n");
+    }
+    else if (pure_parser)
+    {
+       ++outline;
+       fprintf(code_file, "# define YYLEX_DECL() yylex(YYSTYPE *yylval)\n");
+
+       ++outline;
+       fprintf(code_file, "# define YYLEX yylex(&yylval)\n");
+    }
+    else if (lex_param)
+    {
+       param *p;
+       fprintf(code_file, "# define YYLEX_DECL() yylex(");
+       for (p = lex_param; p; p = p->next)
+           fprintf(code_file, "%s %s%s%s", p->type, p->name, p->type2,
+                   p->next ? ", " : "");
+       ++outline;
+       fprintf(code_file, ")\n");
+
+       fprintf(code_file, "# define YYLEX yylex(");
+       for (p = lex_param; p; p = p->next)
+           fprintf(code_file, "%s%s", p->name, p->next ? ", " : "");
+       ++outline;
+       fprintf(code_file, ")\n");
+    }
+    else
+    {
+       ++outline;
+       fprintf(code_file, "# define YYLEX_DECL() yylex(void)\n");
+
+       ++outline;
+       fprintf(code_file, "# define YYLEX yylex()\n");
+    }
+    outline += 2;
+    fprintf(code_file, "#endif\n\n");
+}
+
 static void
 free_itemsets(void)
 {
@@ -1223,15 +1340,18 @@ output(void)
     free_shifts();
     free_reductions();
     output_prefix(output_file);
-    write_section(xdecls);
+    output_pure_parser();
     output_stored_text();
+    output_stype();
+    output_parse_decl();
+    output_lex_decl();
+    write_section(xdecls);
     output_defines();
     output_rule_data();
     output_yydefred();
     output_actions();
     free_parser();
     output_debug();
-    output_stype();
     if (rflag)
     {
        output_prefix(code_file);
@@ -1239,7 +1359,6 @@ output(void)
        write_section(tables);
     }
     write_section(hdr_defs);
-    output_pure_parser();
     if (!pure_parser)
     {
        write_section(hdr_vars);
diff --git a/package/byacc.spec b/package/byacc.spec
new file mode 100644 (file)
index 0000000..f1c970f
--- /dev/null
@@ -0,0 +1,60 @@
+Summary: byacc - public domain Berkeley LALR Yacc parser generator
+%define AppProgram byacc
+%define AppVersion 20100610
+%define UseProgram yacc
+# $XTermId: byacc.spec,v 1.2 2010/06/10 12:35:23 tom Exp $
+Name: %{AppProgram}
+Version: %{AppVersion}
+Release: 1
+License: Public Domain, MIT
+Group: Applications/Development
+URL: ftp://invisible-island.net/%{AppProgram}
+Source0: %{AppProgram}-%{AppVersion}.tgz
+Packager: Thomas Dickey <dickey@invisible-island.net>
+
+%description
+This package provides a parser generator utility that reads a grammar
+specification from a file and generates an LR(1) parser for it.  The
+parsers consist of a set of LALR(1) parsing tables and a driver
+routine written in the C programming language.  It has a public domain
+license which includes the generated C.
+
+%prep
+
+%setup -q -n %{AppProgram}-%{AppVersion}
+
+%build
+
+INSTALL_PROGRAM='${INSTALL}' \
+       ./configure \
+               --program-prefix=b \
+               --target %{_target_platform} \
+               --prefix=%{_prefix} \
+               --bindir=%{_bindir} \
+               --libdir=%{_libdir} \
+               --mandir=%{_mandir}
+
+make
+
+%install
+[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT
+
+make install                    DESTDIR=$RPM_BUILD_ROOT
+( cd $RPM_BUILD_ROOT%{_bindir} && ln -s %{AppProgram} %{UseProgram} )
+
+strip $RPM_BUILD_ROOT%{_bindir}/%{AppProgram}
+
+%clean
+[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(-,root,root)
+%{_prefix}/bin/%{AppProgram}
+%{_prefix}/bin/%{UseProgram}
+%{_mandir}/man1/%{AppProgram}.*
+
+%changelog
+# each patch should add its ChangeLog entries here
+
+* Sun Jun 06 2010 Thomas Dickey
+- initial version
diff --git a/package/debian/changelog b/package/debian/changelog
new file mode 100644 (file)
index 0000000..0f5f92b
--- /dev/null
@@ -0,0 +1,168 @@
+byacc (20100610) unstable; urgency=low
+
+  * Add package scripts to upstream source, for test-builds.
+
+ -- Thomas E. Dickey <dickey@invisible-island.net>  Thu, 10 Jun 2010 08:59:11 -0400
+
+byacc (20100216-1) unstable; urgency=low
+
+  * New upstream release
+  * debian/source/format: Added using format "3.0 (quilt)"
+
+ -- Dave Beckett <dajobe@debian.org>  Tue, 20 Apr 2010 12:56:11 -0700
+
+byacc (20091027-1) unstable; urgency=low
+
+  * New upstream release
+  * debian/control:
+    - Updated to policy 3.8.4
+    - Add ${misc:Depends}
+
+ -- Dave Beckett <dajobe@debian.org>  Tue, 02 Feb 2010 21:36:34 -0800
+
+byacc (20090221-1) unstable; urgency=low
+
+  * New upstream release
+
+ -- Dave Beckett <dajobe@debian.org>  Thu, 26 Feb 2009 21:06:20 -0800
+
+byacc (20080826-1) unstable; urgency=high
+
+  * New upstream release
+  * debian/patches/02-skeleton.patch: Removed - merged upstream
+  * debian/control: Updated to policy 3.8.0
+  * debian/preinst, debian/postrm: removed - empty (lintian)
+  * debian/watch: version 3 and make FTP passive
+  * Acknowledge NMU - thanks.
+
+ -- Dave Beckett <dajobe@debian.org>  Wed, 11 Sep 2008 23:58:00 -0700
+
+byacc (20070509-1.1) unstable; urgency=high
+
+  * Non-maintainer upload.
+  * Fix stack overflow in skeleton.c with upstream patch.
+    Closes: #491182 aka CVE-2008-3196
+
+ -- Thomas Viehmann <tv@beamnet.de>  Sun, 24 Aug 2008 23:13:07 +0200
+
+byacc (20070509-1) unstable; urgency=low
+
+  * New upstream release
+  * debian/watch: Fix to use passive FTP
+  * debian/compat: added instead of use of DH_COMPAT in debian/rules
+
+ -- Dave Beckett <dajobe@debian.org>  Tue, 26 Jun 2007 22:39:45 -0700
+
+byacc (20050813-1) unstable; urgency=low
+
+  * New upstream release:
+    - Do not close union_file for -d option (Closes: #322858)
+
+ -- Dave Beckett <dajobe@debian.org>  Sun, 14 Aug 2005 10:14:12 +0100
+
+byacc (20050505-1) unstable; urgency=low
+
+  * New maintainer (Closes: #321377)
+  * Switch to new upstream and new source (Closes: #240662)
+  * debian/copyright: Update to new upstream and add source information
+    (Closes: #166300)
+  * Acknowledge fix in NMUs (Closes: #283174)
+  * New manual page does not have the formatting problem (Closes: #100947)
+  * Added debian/watch file.
+
+ -- Dave Beckett <dajobe@debian.org>  Fri,  5 Aug 2005 22:50:20 +0100
+
+byacc (1.9.1-1.1) unstable; urgency=low
+
+  * Remove alternative in prerm.  Closes: #283174
+
+ -- LaMont Jones <lamont@debian.org>  Fri, 26 Nov 2004 18:49:09 -0700
+
+byacc (1.9.1-1) unstable; urgency=low
+
+  * Maintainer upload.
+  * Fixed alternatives entry, closes: Bug#146195;
+  * Changed priority to "extra" at behest of Daniel Bungert,
+    closes: Bug#142271.
+  * Fixed awful packaging error which meant the test/ directory was excluded
+    from the orig.tar.gz.
+
+ -- Jason Henry Parker <henry@debian.org>  Fri, 27 Sep 2002 16:25:27 -0400
+
+byacc (1.9-13.1) unstable; urgency=low
+
+  * Non-maintainer upload
+  * Removed erraneous escapes in manpage - some data wasn't visable,
+    closes: Bug#100947
+  * Alternatives entry added, closes: Bug#113168
+  * Standards-version: 3.5.6
+  * Maintainer script cleaning
+
+ -- Daniel Bungert <drb@debian.org>  Fri, 29 Mar 2002 16:58:30 -0500
+
+byacc (1.9-13) unstable; urgency=low
+
+  * Applied patch from "Randolph Chung" <tausq@debian.org> to fix build problems
+    on ia64, closes: Bug#91966
+
+ -- Jason Henry Parker <henry@debian.org>  Thu, 29 Mar 2001 21:41:19 +1000
+
+byacc (1.9-12) unstable; urgency=low
+
+  * Updated to latest version of debhelper, and Standards-Version: 3.2.1.0, closes: Bug#81444
+  * Added Build-Depends: debhelper, closes: Bug#70207
+  * Removed mktemp() calls in main.c
+  
+ -- Jason Henry Parker <henry@debian.org>  Mon, 18 Dec 2000 08:02:54 +1000
+
+byacc (1.9-11.7) unstable; urgency=low
+
+  * New maintainer.
+  * Updated to dh_make and standards version 2.4.0.0, no lintian errors
+    or warnings.
+  * Added several more files from the upstream distribution to
+    /usr/doc/byacc.
+
+ -- Jason Henry Parker <henry@debian.org>  Sat,  2 Jan 1999 03:04:17 +1000
+
+byacc (1.9-11.6) unstable; urgency=low
+
+  * Patch by <mdorman@law.miami.edu> to remove some
+    superfluous files that can interfere with the build process on other
+    architectures. (Bug #21607).
+
+ -- Vincent Renardias <vincent@waw.com>  Fri, 24 Apr 1998 19:56:58 +0200
+
+byacc (1.9-11.5) unstable; urgency=low
+
+  * Added 'binary-arch' target in debian/rules (Bug #12742).
+
+ -- Vincent Renardias <vincent@waw.com>  Sun, 9 Nov 1997 23:37:31 +0100
+
+byacc (1.9-11.4) unstable; urgency=low
+
+  * Cosmetic change (Fix bug #9623).
+
+ -- Vincent Renardias <vincent@waw.com>  Fri, 9 May 1997 16:30:24 +0200
+
+byacc (1.9-11.3) unstable; urgency=low
+
+  * Rebuilt with libc6.
+
+ -- Debian QA Group <debian-qa@lists.debian.org>  Thu, 1 May 1997 22:02:04 +0200
+
+byacc (1.9-11.2) unstable; urgency=low
+
+  * Orphaned the package at his maintainer's request (dgregor@coil.com).
+
+ -- Debian QA Group <debian-qa@lists.debian.org>  Sun, 20 Apr 1997 20:03:03 +0200
+
+byacc (1.9-11.1) unstable; urgency=low
+
+  * Converted to new source format (Fixes #8085).
+  * Compressed manpage.
+  * Fixed to allow compilation on non-i386 (Fixes #3361).
+  * Added extended description (Fixes #3567).
+  * Added diversion to avoid conflict with bison (Fixes #8086). 
+
+ -- Vincent Renardias <vincent@waw.com>  Sun, 20 Apr 1997 15:59:28 +0200
diff --git a/package/debian/compat b/package/debian/compat
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/package/debian/control b/package/debian/control
new file mode 100644 (file)
index 0000000..720aada
--- /dev/null
@@ -0,0 +1,17 @@
+Source: byacc
+Maintainer: Dave Beckett <dajobe@debian.org>
+Section: devel
+Priority: extra
+Standards-Version: 3.8.4
+Build-Depends: debhelper (>= 5)
+Homepage: http://invisible-island.net/byacc/
+
+Package: byacc
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: public domain Berkeley LALR Yacc parser generator
+ This package provides a parser generator utility that reads a grammar
+ specification from a file and generates an LR(1) parser for it.  The
+ parsers consist of a set of LALR(1) parsing tables and a driver
+ routine written in the C programming language.  It has a public domain
+ license which includes the generated C.
diff --git a/package/debian/copyright b/package/debian/copyright
new file mode 100644 (file)
index 0000000..2bce2fc
--- /dev/null
@@ -0,0 +1,120 @@
+Upstream source http://dickey.his.com/byacc/byacc.html
+
+Berkeley Yacc is in the public domain; changes made to it by the current
+maintainer are likewise unrestricted.  That applies to most of the files.
+A few files (currently those related to autoconf scripting) have other
+licenses as noted here.
+
+Current byacc upstream maintainer: Thomas Dickey <dickey@invisible-island.net>
+
+Public domain notice and no warranty:
+-------------------------------------------------------------------------------
+    Berkeley Yacc is an LALR(1) parser generator.  Berkeley Yacc has been made
+as compatible as possible with AT&T Yacc.  Berkeley Yacc can accept any input
+specification that conforms to the AT&T Yacc documentation.  Specifications
+that take advantage of undocumented features of AT&T Yacc will probably be
+rejected.
+
+    Berkeley Yacc is distributed with no warranty whatever.  The code
+is certain to contain errors.  Neither the author nor any contributor
+takes responsibility for any consequences of its use.
+
+    Berkeley Yacc is in the public domain.  The data structures and algorithms
+used in Berkeley Yacc are all either taken from documents available to the
+general public or are inventions of the author.  Anyone may freely distribute
+source or binary forms of Berkeley Yacc whether unchanged or modified.
+Distributers may charge whatever fees they can obtain for Berkeley Yacc.
+Programs generated by Berkeley Yacc may be distributed freely.
+
+    Please report bugs to
+
+                       robert.corbett@eng.Sun.COM
+
+Include a small example if possible.  Please include the banner string from
+skeleton.c with the bug report.  Do not expect rapid responses.
+-------------------------------------------------------------------------------
+
+Files: aclocal.m4
+Licence: other-BSD
+Copyright:  2004-2009,2010 by Thomas E. Dickey
+    Permission is hereby granted, free of charge, to any person obtaining a
+    copy of this software and associated documentation files (the
+    "Software"), to deal in the Software without restriction, including
+    without limitation the rights to use, copy, modify, merge, publish,
+    distribute, distribute with modifications, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+    
+    The above copyright notice and this permission notice shall be included
+    in all copies or portions of the Software.
+    
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+    IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+    DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+    OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
+    THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+    
+    Except as contained in this notice, the name(s) of the above copyright
+    holders shall not be used in advertising or otherwise to promote the
+    sale, use or other dealings in this Software without prior written
+    authorization.
+
+Files: install-sh
+Copyright:  1994 X Consortium
+Licence: other-BSD
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to
+    deal in the Software without restriction, including without limitation the
+    rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+    sell copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+    X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+    AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
+    TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+    Except as contained in this notice, the name of the X Consortium shall not
+    be used in advertising or otherwise to promote the sale, use or other deal-
+    ings in this Software without prior written authorization from the X Consor-
+    tium.
+
+    FSF changes to this file are in the public domain.
+
+    Calling this script install-sh is preferred over install.sh, to prevent
+    `make' implicit rules from creating a file called install from it
+    when there is no Makefile.
+
+    This script is compatible with the BSD install script, but was written
+    from scratch.  It can only install one file at a time, a restriction
+    shared with many OS's install programs.
+
+Files: debian/*
+Copyright:  2010 Thomas E. Dickey
+Licence: other-BSD
+    Permission to use, copy, modify, and distribute this software and its
+    documentation for any purpose and without fee is hereby granted,
+    provided that the above copyright notice appear in all copies and that
+    both that copyright notice and this permission notice appear in
+    supporting documentation, and that the name of the above listed
+    copyright holder(s) not be used in advertising or publicity pertaining
+    to distribution of the software without specific, written prior
+    permission.
+
+    THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM ALL WARRANTIES WITH REGARD
+    TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+    AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
+    LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+On Debian systems, the complete text of the GNU General
+Public License can be found in '/usr/share/common-licenses/GPL-2'
diff --git a/package/debian/docs b/package/debian/docs
new file mode 100644 (file)
index 0000000..cbda209
--- /dev/null
@@ -0,0 +1,4 @@
+README
+ACKNOWLEDGEMENTS
+NEW_FEATURES
+NOTES
diff --git a/package/debian/postinst b/package/debian/postinst
new file mode 100644 (file)
index 0000000..ca6276d
--- /dev/null
@@ -0,0 +1,15 @@
+#! /bin/sh
+# postinst script for byacc
+
+set -e
+
+if [ $1 != "upgrade" ] ; then
+       update-alternatives \
+               --install /usr/bin/yacc yacc /usr/bin/byacc 80 \
+               --slave /usr/share/man/man1/yacc.1.gz yaccman \
+                       /usr/share/man/man1/byacc.1.gz
+fi
+
+#DEBHELPER#
+
+exit 0
diff --git a/package/debian/prerm b/package/debian/prerm
new file mode 100644 (file)
index 0000000..f3889d7
--- /dev/null
@@ -0,0 +1,12 @@
+#! /bin/sh
+# prerm script for byacc
+
+set -e
+
+if [ $1 != "upgrade" ]; then
+       update-alternatives --remove yacc /usr/bin/byacc
+fi
+
+#DEBHELPER#
+
+exit 0
diff --git a/package/debian/rules b/package/debian/rules
new file mode 100755 (executable)
index 0000000..f9424ac
--- /dev/null
@@ -0,0 +1,93 @@
+#!/usr/bin/make -f
+# MAde with the aid of dh_make, by Craig Small
+# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
+# Some lines taken from debmake, by Cristoph Lameter.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+# These are used for cross-compiling and for saving the configure script
+# from having to guess our platform (since we know it already)
+DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
+DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
+
+CFLAGS =
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+        CFLAGS += -O0
+else
+        CFLAGS += -O2
+endif
+ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
+        INSTALL_PROGRAM += -s
+endif
+
+
+configure: configure-stamp
+configure-stamp:
+       dh_testdir
+
+       CFLAGS="$(CFLAGS)" ./configure \
+               --host=$(DEB_HOST_GNU_TYPE) \
+               --build=$(DEB_BUILD_GNU_TYPE) \
+               --prefix=/usr \
+               --mandir=\$${prefix}/share/man \
+               --sysconfdir=/etc \
+               --program-transform-name='s,^,b,'
+
+       touch configure-stamp
+
+build: build-stamp
+build-stamp: configure-stamp
+       dh_testdir
+
+       $(MAKE)
+
+       touch build-stamp
+
+clean:
+       dh_testdir
+       dh_testroot
+
+       [ ! -f Makefile ] || $(MAKE) clean
+
+       rm -f configure-stamp build-stamp install-stamp \
+               config.cache config.h config.status config.log makefile
+
+       rm -f *.o yacc
+
+       dh_clean
+
+install: install-stamp
+install-stamp: build-stamp
+       dh_testdir
+       dh_testroot
+       dh_clean -k
+       dh_installdirs
+
+       $(MAKE) install DESTDIR=$(CURDIR)/debian/byacc
+
+       touch install-stamp
+
+# Build architecture-independent files here.
+binary-indep: build install
+# No binary-indep target.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+       dh_testdir
+       dh_testroot
+       dh_installdocs
+       dh_installexamples
+       dh_installchangelogs CHANGES
+       dh_strip
+       dh_compress
+       dh_fixperms
+       dh_installdeb
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install install-stamp
diff --git a/package/debian/source/format b/package/debian/source/format
new file mode 100644 (file)
index 0000000..163aaf8
--- /dev/null
@@ -0,0 +1 @@
+3.0 (quilt)
diff --git a/package/debian/watch b/package/debian/watch
new file mode 100644 (file)
index 0000000..de083b0
--- /dev/null
@@ -0,0 +1,4 @@
+version=3
+
+opts=passive ftp://invisible-island.net/byacc/byacc-(\d+)\.tgz \
+ debian  uupdate
diff --git a/package/pkgsrc/DESCR b/package/pkgsrc/DESCR
new file mode 100644 (file)
index 0000000..fe01865
--- /dev/null
@@ -0,0 +1,6 @@
+Berkeley Yacc (byacc) is a LALR(1) parser generator.  Berkeley Yacc
+has been made as compatible as possible with AT&T Yacc.  Berkeley
+Yacc can accept any input specification that conforms to the AT&T
+Yacc documentation.
+
+Some programs depend on a byacc (instead of bison).
diff --git a/package/pkgsrc/Makefile b/package/pkgsrc/Makefile
new file mode 100644 (file)
index 0000000..416ea85
--- /dev/null
@@ -0,0 +1,19 @@
+# $NetBSD: Makefile,v 1.9 2008/07/24 17:13:00 tonnerre Exp $
+#
+
+DISTNAME=      byacc-20050813
+PKGREVISION=   1
+CATEGORIES=    devel
+MASTER_SITES=  ftp://invisible-island.net/byacc/
+EXTRACT_SUFX=  .tgz
+
+MAINTAINER=    pkgsrc-users@NetBSD.org
+HOMEPAGE=      http://dickey.his.com/byacc/byacc.html
+COMMENT=       Berkeley Yacc
+
+PKG_DESTDIR_SUPPORT=   user-destdir
+
+GNU_CONFIGURE= YES
+MAKE_FILE=     makefile
+
+.include "../../mk/bsd.pkg.mk"
diff --git a/package/pkgsrc/PLIST b/package/pkgsrc/PLIST
new file mode 100644 (file)
index 0000000..5bcfece
--- /dev/null
@@ -0,0 +1,3 @@
+@comment $NetBSD: PLIST,v 1.2 2005/04/13 14:11:54 wiz Exp $
+bin/yacc
+man/man1/yacc.1
diff --git a/package/pkgsrc/distinfo b/package/pkgsrc/distinfo
new file mode 100644 (file)
index 0000000..99252a6
--- /dev/null
@@ -0,0 +1,6 @@
+$NetBSD: distinfo,v 1.4 2008/07/24 17:13:00 tonnerre Exp $
+
+SHA1 (byacc-20050813.tgz) = 3258494f3422eb3150944c1823af1c9c2c386062
+RMD160 (byacc-20050813.tgz) = 3ee159857a79025a83e2b0807577925fe460f816
+Size (byacc-20050813.tgz) = 138684 bytes
+SHA1 (patch-aa) = decae78775a5e0f1e1f7aaaa258da53903aa1f7a
index edec4ac2a5118c79fa0959134b281e77e0d4edce..72ee01ad8589b159840a165f89d295532fde3726 100644 (file)
--- a/reader.c
+++ b/reader.c
@@ -1,4 +1,4 @@
-/* $Id: reader.c,v 1.19 2010/02/17 01:41:35 tom Exp $ */
+/* $Id: reader.c,v 1.26 2010/06/10 00:44:38 tom Exp $ */
 
 #include "defs.h"
 
@@ -42,6 +42,9 @@ static char *name_pool;
 
 char line_format[] = "#line %d \"%s\"\n";
 
+param *lex_param;
+param *parse_param;
+
 static void
 cachec(int c)
 {
@@ -50,8 +53,7 @@ cachec(int c)
     {
        cache_size += 256;
        cache = REALLOC(cache, cache_size);
-       if (cache == 0)
-           no_space();
+       NO_SPACE(cache);
     }
     cache[cinc] = (char)c;
     ++cinc;
@@ -82,8 +84,7 @@ get_line(void)
            FREE(line);
        linesize = LINESIZE + 1;
        line = MALLOC(linesize);
-       if (line == 0)
-           no_space();
+       NO_SPACE(line);
     }
 
     i = 0;
@@ -100,8 +101,7 @@ get_line(void)
        {
            linesize += LINESIZE;
            line = REALLOC(line, linesize);
-           if (line == 0)
-               no_space();
+           NO_SPACE(line);
        }
        c = getc(f);
        if (c == EOF)
@@ -125,8 +125,7 @@ dup_line(void)
     while (*s != '\n')
        ++s;
     p = MALLOC(s - line + 1);
-    if (p == 0)
-       no_space();
+    NO_SPACE(p);
 
     s = line;
     t = p;
@@ -276,6 +275,12 @@ keyword(void)
            return (EXPECT_RR);
        if (strcmp(cache, "pure-parser") == 0)
            return (PURE_PARSER);
+       if (strcmp(cache, "parse-param") == 0)
+           return (PARSE_PARAM);
+       if (strcmp(cache, "lex-param") == 0)
+           return (LEX_PARAM);
+       if (strcmp(cache, "yacc") == 0)
+           return (POSIX_YACC);
     }
     else
     {
@@ -615,6 +620,116 @@ copy_union(void)
     }
 }
 
+/*
+ * Keep a linked list of parameters
+ */
+static void
+copy_param(int k)
+{
+    char *buf;
+    int c;
+    param *head, *p;
+    int i;
+    int name, type2;
+
+    c = nextc();
+    if (c == EOF)
+       unexpected_EOF();
+    if (c != '{')
+       goto out;
+    cptr++;
+
+    c = nextc();
+    if (c == EOF)
+       unexpected_EOF();
+    if (c == '}')
+       goto out;
+
+    buf = MALLOC(linesize);
+    NO_SPACE(buf);
+
+    for (i = 0; (c = *cptr++) != '}'; i++)
+    {
+       if (c == EOF)
+           unexpected_EOF();
+       buf[i] = (char)c;
+    }
+
+    if (i == 0)
+       goto out;
+
+    buf[i--] = '\0';
+    while (i >= 0 && isspace(UCH(buf[i])))
+       buf[i--] = '\0';
+
+    if (buf[i] == ']')
+    {
+       int level = 1;
+       while (i >= 0 && level > 0 && buf[i] != '[')
+       {
+           if (buf[i] == ']')
+               ++level;
+           else if (buf[i] == '[')
+               --level;
+           i--;
+       }
+       if (i <= 0)
+           unexpected_EOF();
+       type2 = i--;
+    }
+    else
+    {
+       type2 = i + 1;
+    }
+
+    while (i >= 0 && (isalnum(UCH(buf[i])) ||
+                     UCH(buf[i]) == '_'))
+       i--;
+
+    if (!isspace(UCH(buf[i])) && buf[i] != '*')
+       goto out;
+
+    name = i + 1;
+
+    p = MALLOC(sizeof(*p));
+    NO_SPACE(p);
+
+    p->type2 = strdup(buf + type2);
+    NO_SPACE(p->type2);
+
+    buf[type2] = '\0';
+
+    p->name = strdup(buf + name);
+    NO_SPACE(p->name);
+
+    buf[name] = '\0';
+    p->type = buf;
+
+    if (k == LEX_PARAM)
+       head = lex_param;
+    else
+       head = parse_param;
+
+    if (head != NULL)
+    {
+       while (head->next)
+           head = head->next;
+       head->next = p;
+    }
+    else
+    {
+       if (k == LEX_PARAM)
+           lex_param = p;
+       else
+           parse_param = p;
+    }
+    p->next = NULL;
+    return;
+
+  out:
+    syntax_error(lineno, line, cptr);
+}
+
 static int
 hexval(int c)
 {
@@ -734,8 +849,7 @@ get_literal(void)
 
     n = cinc;
     s = MALLOC(n);
-    if (s == 0)
-       no_space();
+    NO_SPACE(s);
 
     for (i = 0; i < n; ++i)
        s[i] = cache[i];
@@ -748,7 +862,7 @@ get_literal(void)
 
     for (i = 0; i < n; ++i)
     {
-       c = ((unsigned char *)s)[i];
+       c = UCH(s[i]);
        if (c == '\\' || c == cache[0])
        {
            cachec('\\');
@@ -800,7 +914,7 @@ get_literal(void)
     bp = lookup(cache);
     bp->class = TERM;
     if (n == 1 && bp->value == UNDEFINED)
-       bp->value = *(unsigned char *)s;
+       bp->value = UCH(*s);
     FREE(s);
 
     return (bp);
@@ -816,10 +930,10 @@ is_reserved(char *name)
        strcmp(name, "$end") == 0)
        return (1);
 
-    if (name[0] == '$' && name[1] == '$' && isdigit(name[2]))
+    if (name[0] == '$' && name[1] == '$' && isdigit(UCH(name[2])))
     {
        s = name + 3;
-       while (isdigit(*s))
+       while (isdigit(UCH(*s)))
            ++s;
        if (*s == NUL)
            return (1);
@@ -906,13 +1020,12 @@ get_tag(void)
            (tag_table
             ? REALLOC(tag_table, (unsigned)tagmax * sizeof(char *))
             : MALLOC((unsigned)tagmax * sizeof(char *)));
-       if (tag_table == 0)
-           no_space();
+       NO_SPACE(tag_table);
     }
 
     s = MALLOC(cinc);
-    if (s == 0)
-       no_space();
+    NO_SPACE(s);
+
     strcpy(s, cache);
     tag_table[ntags] = s;
     ++ntags;
@@ -973,7 +1086,7 @@ declare_tokens(int assoc)
        c = nextc();
        if (c == EOF)
            unexpected_EOF();
-       value = UNDEFINED;
+
        if (isdigit(c))
        {
            value = get_number();
@@ -1092,8 +1205,7 @@ read_declarations(void)
 
     cache_size = 256;
     cache = MALLOC(cache_size);
-    if (cache == 0)
-       no_space();
+    NO_SPACE(cache);
 
     for (;;)
     {
@@ -1142,6 +1254,16 @@ read_declarations(void)
        case PURE_PARSER:
            pure_parser = 1;
            break;
+
+       case PARSE_PARAM:
+       case LEX_PARAM:
+           copy_param(k);
+           break;
+
+       case POSIX_YACC:
+           /* noop for bison compatibility. byacc is already designed to be posix
+            * yacc compatible. */
+           break;
        }
     }
 }
@@ -1151,9 +1273,10 @@ initialize_grammar(void)
 {
     nitems = 4;
     maxitems = 300;
+
     pitem = (bucket **)MALLOC((unsigned)maxitems * sizeof(bucket *));
-    if (pitem == 0)
-       no_space();
+    NO_SPACE(pitem);
+
     pitem[0] = 0;
     pitem[1] = 0;
     pitem[2] = 0;
@@ -1161,21 +1284,24 @@ initialize_grammar(void)
 
     nrules = 3;
     maxrules = 100;
+
     plhs = (bucket **)MALLOC((unsigned)maxrules * sizeof(bucket *));
-    if (plhs == 0)
-       no_space();
+    NO_SPACE(plhs);
+
     plhs[0] = 0;
     plhs[1] = 0;
     plhs[2] = 0;
+
     rprec = (short *)MALLOC((unsigned)maxrules * sizeof(short));
-    if (rprec == 0)
-       no_space();
+    NO_SPACE(rprec);
+
     rprec[0] = 0;
     rprec[1] = 0;
     rprec[2] = 0;
+
     rassoc = (char *)MALLOC((unsigned)maxrules * sizeof(char));
-    if (rassoc == 0)
-       no_space();
+    NO_SPACE(rassoc);
+
     rassoc[0] = TOKEN;
     rassoc[1] = TOKEN;
     rassoc[2] = TOKEN;
@@ -1186,23 +1312,22 @@ expand_items(void)
 {
     maxitems += 300;
     pitem = (bucket **)REALLOC(pitem, (unsigned)maxitems * sizeof(bucket *));
-    if (pitem == 0)
-       no_space();
+    NO_SPACE(pitem);
 }
 
 static void
 expand_rules(void)
 {
     maxrules += 100;
+
     plhs = (bucket **)REALLOC(plhs, (unsigned)maxrules * sizeof(bucket *));
-    if (plhs == 0)
-       no_space();
+    NO_SPACE(plhs);
+
     rprec = (short *)REALLOC(rprec, (unsigned)maxrules * sizeof(short));
-    if (rprec == 0)
-       no_space();
+    NO_SPACE(rprec);
+
     rassoc = (char *)REALLOC(rassoc, (unsigned)maxrules * sizeof(char));
-    if (rassoc == 0)
-       no_space();
+    NO_SPACE(rassoc);
 }
 
 static void
@@ -1359,7 +1484,7 @@ add_symbol(void)
 static char *
 after_blanks(char *s)
 {
-    while (*s != '\0' && isspace(*s))
+    while (*s != '\0' && isspace(UCH(*s)))
        ++s;
     return s;
 }
@@ -1428,7 +1553,7 @@ copy_action(void)
                FREE(d_line);
                goto loop;
            }
-           else if (c == '-' && isdigit(cptr[1]))
+           else if (c == '-' && isdigit(UCH(cptr[1])))
            {
                ++cptr;
                i = -get_number() - n;
@@ -1453,7 +1578,7 @@ copy_action(void)
            cptr += 2;
            goto loop;
        }
-       else if (isdigit(cptr[1]))
+       else if (isdigit(UCH(cptr[1])))
        {
            ++cptr;
            i = get_number();
@@ -1712,9 +1837,9 @@ pack_names(void)
     name_pool_size = 13;       /* 13 == sizeof("$end") + sizeof("$accept") */
     for (bp = first_symbol; bp; bp = bp->next)
        name_pool_size += strlen(bp->name) + 1;
+
     name_pool = MALLOC(name_pool_size);
-    if (name_pool == 0)
-       no_space();
+    NO_SPACE(name_pool);
 
     strcpy(name_pool, "$accept");
     strcpy(name_pool + 8, "$end");
@@ -1767,9 +1892,10 @@ protect_string(char *src, char **des)
            s++;
            len++;
        }
+
        *des = d = (char *)MALLOC(len);
-       if (0 == *des)
-           no_space();
+       NO_SPACE(d);
+
        s = src;
        while (*s)
        {
@@ -1800,21 +1926,19 @@ pack_symbols(void)
     nvars = nsyms - ntokens;
 
     symbol_name = (char **)MALLOC((unsigned)nsyms * sizeof(char *));
-    if (symbol_name == 0)
-       no_space();
+    NO_SPACE(symbol_name);
+
     symbol_value = (short *)MALLOC((unsigned)nsyms * sizeof(short));
-    if (symbol_value == 0)
-       no_space();
+    NO_SPACE(symbol_value);
+
     symbol_prec = (short *)MALLOC((unsigned)nsyms * sizeof(short));
-    if (symbol_prec == 0)
-       no_space();
+    NO_SPACE(symbol_prec);
+
     symbol_assoc = MALLOC(nsyms);
-    if (symbol_assoc == 0)
-       no_space();
+    NO_SPACE(symbol_assoc);
 
     v = (bucket **)MALLOC((unsigned)nsyms * sizeof(bucket *));
-    if (v == 0)
-       no_space();
+    NO_SPACE(v);
 
     v[0] = 0;
     v[start_symbol] = 0;
@@ -1865,6 +1989,8 @@ pack_symbols(void)
        }
     }
 
+    assert(v[1] != 0);
+
     if (v[1]->value == UNDEFINED)
        v[1]->value = 256;
 
@@ -1912,8 +2038,7 @@ pack_symbols(void)
     if (gflag)
     {
        symbol_pname = (char **)MALLOC((unsigned)nsyms * sizeof(char *));
-       if (symbol_pname == 0)
-           no_space();
+       NO_SPACE(symbol_pname);
 
        for (i = 0; i < nsyms; ++i)
            protect_string(symbol_name[i], &(symbol_pname[i]));
@@ -1931,20 +2056,19 @@ pack_grammar(void)
     Value_t prec2;
 
     ritem = (short *)MALLOC((unsigned)nitems * sizeof(short));
-    if (ritem == 0)
-       no_space();
+    NO_SPACE(ritem);
+
     rlhs = (short *)MALLOC((unsigned)nrules * sizeof(short));
-    if (rlhs == 0)
-       no_space();
+    NO_SPACE(rlhs);
+
     rrhs = (short *)MALLOC((unsigned)(nrules + 1) * sizeof(short));
-    if (rrhs == 0)
-       no_space();
+    NO_SPACE(rrhs);
+
     rprec = (short *)REALLOC(rprec, (unsigned)nrules * sizeof(short));
-    if (rprec == 0)
-       no_space();
+    NO_SPACE(rprec);
+
     rassoc = REALLOC(rassoc, nrules);
-    if (rassoc == 0)
-       no_space();
+    NO_SPACE(rassoc);
 
     ritem[0] = -1;
     ritem[1] = goal->index;
@@ -2045,9 +2169,27 @@ reader(void)
 }
 
 #ifdef NO_LEAKS
+static param *
+free_declarations(param * list)
+{
+    while (list != 0)
+    {
+       param *next = list->next;
+       free(list->type);
+       free(list->name);
+       free(list->type2);
+       free(list);
+       list = next;
+    }
+    return list;
+}
+
 void
 reader_leaks(void)
 {
+    lex_param = free_declarations(lex_param);
+    parse_param = free_declarations(parse_param);
+
     DO_FREE(line);
     DO_FREE(rrhs);
     DO_FREE(rlhs);
index 2203de6d3395e0829e08e18c7c08cbe708c69b56..4ea3b56301cb0bbe551b4553e4d763961d3a8b95 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: skeleton.c,v 1.23 2010/02/17 01:44:23 tom Exp $ */
+/* $Id: skeleton.c,v 1.25 2010/06/07 21:24:58 Andres.Mejia Exp $ */
 
 #include "defs.h"
 
@@ -20,9 +20,6 @@ const char *banner[] =
     "static const char yysccsid[] = \"@(#)yaccpar      1.9 (Berkeley) 02/21/93\";",
     "#endif",
     "",
-    "#include <stdlib.h>",
-    "#include <string.h>",
-    "",
     "#define YYBYACC 1",
     CONCAT1("#define YYMAJOR ", YYMAJOR),
     CONCAT1("#define YYMINOR ", YYMINOR),
@@ -40,20 +37,8 @@ const char *banner[] =
 
 const char *xdecls[] =
 {
-    "",
-    "/* compatibility with bison */",
-    "#ifdef YYPARSE_PARAM",
-    "/* compatibility with FreeBSD */",
-    "#ifdef YYPARSE_PARAM_TYPE",
-    "#define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)",
-    "#else",
-    "#define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)",
-    "#endif",
-    "#else",
-    "#define YYPARSE_DECL() yyparse(void)",
-    "#endif /* YYPARSE_PARAM */",
-    "",
     "extern int YYPARSE_DECL();",
+    "extern int YYLEX_DECL();",
     "",
     0
 };
@@ -79,10 +64,6 @@ const char *tables[] =
 
 const char *hdr_defs[] =
 {
-    "#if YYDEBUG",
-    "#include <stdio.h>",
-    "#endif",
-    "",
     "/* define the initial stack-sizes */",
     "#ifdef YYSTACKSIZE",
     "#undef YYMAXDEPTH",
@@ -138,6 +119,14 @@ const char *body_vars[] =
 
 const char *body_1[] =
 {
+    "",
+    "#if YYDEBUG",
+    "#include <stdio.h>                /* needed for printf */",
+    "#endif",
+    "",
+    "#include <stdlib.h>       /* needed for malloc, etc */",
+    "#include <string.h>       /* needed for memset */",
+    "",
     "/* allocate initial stack or double stack size, up to YYMAXDEPTH */",
     "static int yygrowstack(YYSTACKDATA *data)",
     "{",
@@ -160,7 +149,7 @@ const char *body_1[] =
     "    if (newss == 0)",
     "        return -1;",
     "",
-    "    data->s_base  = newss;",
+    "    data->s_base = newss;",
     "    data->s_mark = newss + i;",
     "",
     "    newvs = (data->l_base != 0)",
@@ -232,7 +221,7 @@ const char *body_2[] =
     "    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;",
     "    if (yychar < 0)",
     "    {",
-    "        if ((yychar = yylex()) < 0) yychar = 0;",
+    "        if ((yychar = YYLEX) < 0) yychar = 0;",
     "#if YYDEBUG",
     "        if (yydebug)",
     "        {",
@@ -368,7 +357,7 @@ const char *trailer[] =
     "        *++yystack.l_mark = yyval;",
     "        if (yychar < 0)",
     "        {",
-    "            if ((yychar = yylex()) < 0) yychar = 0;",
+    "            if ((yychar = YYLEX) < 0) yychar = 0;",
     "#if YYDEBUG",
     "            if (yydebug)",
     "            {",
index 43084877ea59c2b1ca244b79d539b84a2bd77f53..acbc065ef7246d585a6d82c3bf9e46bbae939e85 100644 (file)
--- a/symtab.c
+++ b/symtab.c
@@ -1,4 +1,4 @@
-/* $Id: symtab.c,v 1.7 2008/11/24 21:30:35 tom Exp $ */
+/* $Id: symtab.c,v 1.8 2010/06/09 08:58:29 tom Exp $ */
 
 #include "defs.h"
 
@@ -31,24 +31,23 @@ make_bucket(const char *name)
 {
     bucket *bp;
 
-    assert(name);
+    assert(name != 0);
+
     bp = (bucket *)MALLOC(sizeof(bucket));
-    if (bp == 0)
-       no_space();
+    NO_SPACE(bp);
+
     bp->link = 0;
     bp->next = 0;
+
     bp->name = MALLOC(strlen(name) + 1);
-    if (bp->name == 0)
-       no_space();
+    NO_SPACE(bp->name);
+
     bp->tag = 0;
     bp->value = UNDEFINED;
     bp->index = 0;
     bp->prec = 0;
     bp->class = UNKNOWN;
     bp->assoc = TOKEN;
-
-    if (bp->name == 0)
-       no_space();
     strcpy(bp->name, name);
 
     return (bp);
@@ -84,8 +83,8 @@ create_symbol_table(void)
     bucket *bp;
 
     symbol_table = (bucket **)MALLOC(TABLE_SIZE * sizeof(bucket *));
-    if (symbol_table == 0)
-       no_space();
+    NO_SPACE(symbol_table);
+
     for (i = 0; i < TABLE_SIZE; i++)
        symbol_table[i] = 0;
 
diff --git a/test/.@-RCS b/test/.@-RCS
deleted file mode 120000 (symlink)
index 3bab960..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/usr/build/VCS/byacc/test/RCS
\ No newline at end of file
index 54bc7e459db77895c7eee92cee0d4055b4e89e93..3d8f198cc9bd71771eec624e4dea939f6bdaf982 100644 (file)
@@ -2,9 +2,6 @@
 static const char yysccsid[] = "@(#)yaccpar    1.9 (Berkeley) 02/21/93";
 #endif
 
-#include <stdlib.h>
-#include <string.h>
-
 #define YYBYACC 1
 #define YYMAJOR 1
 #define YYMINOR 9
@@ -96,28 +93,45 @@ static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
 #endif /* yyrule */
 #define YYPREFIX "calc_"
 
+#define YYPURE 0
+
+#line 2 "calc.y"
+# include <stdio.h>
+# include <ctype.h>
+
+int regs[26];
+int base;
+
+#line 106 "calc.tab.c"
+
+#ifndef YYSTYPE
+typedef int YYSTYPE;
+#endif
+
 /* compatibility with bison */
 #ifdef YYPARSE_PARAM
 /* compatibility with FreeBSD */
-#ifdef YYPARSE_PARAM_TYPE
-#define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
+# ifdef YYPARSE_PARAM_TYPE
+#  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
+# else
+#  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
+# endif
 #else
-#define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
+# define YYPARSE_DECL() yyparse(void)
 #endif
+
+/* Parameters sent to lex. */
+#ifdef YYLEX_PARAM
+# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
+# define YYLEX yylex(YYLEX_PARAM)
 #else
-#define YYPARSE_DECL() yyparse(void)
-#endif /* YYPARSE_PARAM */
+# define YYLEX_DECL() yylex(void)
+# define YYLEX yylex()
+#endif
 
 extern int YYPARSE_DECL();
+extern int YYLEX_DECL();
 
-#line 2 "calc.y"
-# include <stdio.h>
-# include <ctype.h>
-
-int regs[26];
-int base;
-
-#line 121 "calc.tab.c"
 #define DIGIT 257
 #define LETTER 258
 #define UMINUS 259
@@ -243,13 +257,6 @@ static const char *yyrule[] = {
 
 };
 #endif
-#ifndef YYSTYPE
-typedef int YYSTYPE;
-#endif
-#if YYDEBUG
-#include <stdio.h>
-#endif
-
 /* define the initial stack-sizes */
 #ifdef YYSTACKSIZE
 #undef YYMAXDEPTH
@@ -276,9 +283,6 @@ typedef struct {
     YYSTYPE  *l_base;
     YYSTYPE  *l_mark;
 } YYSTACKDATA;
-
-#define YYPURE 0
-
 int      yyerrflag;
 int      yychar;
 YYSTYPE  yyval;
@@ -289,42 +293,54 @@ static YYSTACKDATA yystack;
 #line 63 "calc.y"
  /* start of programs */
 
-main ()
-
+int
+main (void)
 {
     while(!feof(stdin)) {
-      yyparse();
-   }
+       yyparse();
+    }
+    return 0;
 }
 
-yyerror(char *s)
-{  
-   fprintf(stderr, "%s\n", s);
+static void
+yyerror(const char *s)
+{
+    fprintf(stderr, "%s\n", s);
 }
 
+int
+yylex(void)
+{
+       /* lexical analysis routine */
+       /* returns LETTER for a lower case letter, yylval = 0 through 25 */
+       /* return DIGIT for a digit, yylval = 0 through 9 */
+       /* all other characters are returned immediately */
+
+    int c;
 
-yylex() {   /* lexical analysis routine */
-            /* returns LETTER for a lower case letter, yylval = 0 through 25 */
-            /* return DIGIT for a digit, yylval = 0 through 9 */
-            /* all other characters are returned immediately */
+    while( (c=getchar()) == ' ' )   { /* skip blanks */ }
 
-      int c;
+    /* c is now nonblank */
 
-      while( (c=getchar()) == ' ' )   { /* skip blanks */ }
+    if( islower( c )) {
+       yylval = c - 'a';
+       return ( LETTER );
+    }
+    if( isdigit( c )) {
+       yylval = c - '0';
+       return ( DIGIT );
+    }
+    return( c );
+}
+#line 336 "calc.tab.c"
+
+#if YYDEBUG
+#include <stdio.h>             /* needed for printf */
+#endif
 
-      /* c is now nonblank */
+#include <stdlib.h>    /* needed for malloc, etc */
+#include <string.h>    /* needed for memset */
 
-      if( islower( c )) {
-         yylval = c - 'a';
-         return ( LETTER );
-         }
-      if( isdigit( c )) {
-         yylval = c - '0';
-         return ( DIGIT );
-         }
-      return( c );
-      }
-#line 328 "calc.tab.c"
 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
 static int yygrowstack(YYSTACKDATA *data)
 {
@@ -347,7 +363,7 @@ static int yygrowstack(YYSTACKDATA *data)
     if (newss == 0)
         return -1;
 
-    data->s_base  = newss;
+    data->s_base = newss;
     data->s_mark = newss + i;
 
     newvs = (data->l_base != 0)
@@ -414,7 +430,7 @@ yyloop:
     if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
     if (yychar < 0)
     {
-        if ((yychar = yylex()) < 0) yychar = 0;
+        if ((yychar = YYLEX) < 0) yychar = 0;
 #if YYDEBUG
         if (yydebug)
         {
@@ -586,7 +602,7 @@ case 18:
 #line 60 "calc.y"
        {  yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
 break;
-#line 590 "calc.tab.c"
+#line 606 "calc.tab.c"
     }
     yystack.s_mark -= yym;
     yystate = *yystack.s_mark;
@@ -604,7 +620,7 @@ break;
         *++yystack.l_mark = yyval;
         if (yychar < 0)
         {
-            if ((yychar = yylex()) < 0) yychar = 0;
+            if ((yychar = YYLEX) < 0) yychar = 0;
 #if YYDEBUG
             if (yydebug)
             {
index 28b865c88dae0963fa2ce181165d1c8276e984a3..da02c19d3857db88eda162aadab236088e66b8f8 100644 (file)
@@ -62,38 +62,42 @@ number:  DIGIT
 
 %% /* start of programs */
 
-main ()
-
+int
+main (void)
 {
     while(!feof(stdin)) {
-      yyparse();
-   }
+       yyparse();
+    }
+    return 0;
 }
 
-yyerror(char *s)
-{  
-   fprintf(stderr, "%s\n", s);
+static void
+yyerror(const char *s)
+{
+    fprintf(stderr, "%s\n", s);
 }
 
-
-yylex() {   /* lexical analysis routine */
-            /* returns LETTER for a lower case letter, yylval = 0 through 25 */
-            /* return DIGIT for a digit, yylval = 0 through 9 */
-            /* all other characters are returned immediately */
-
-      int c;
-
-      while( (c=getchar()) == ' ' )   { /* skip blanks */ }
-
-      /* c is now nonblank */
-
-      if( islower( c )) {
-         yylval = c - 'a';
-         return ( LETTER );
-         }
-      if( isdigit( c )) {
-         yylval = c - '0';
-         return ( DIGIT );
-         }
-      return( c );
-      }
+int
+yylex(void)
+{
+       /* lexical analysis routine */
+       /* returns LETTER for a lower case letter, yylval = 0 through 25 */
+       /* return DIGIT for a digit, yylval = 0 through 9 */
+       /* all other characters are returned immediately */
+
+    int c;
+
+    while( (c=getchar()) == ' ' )   { /* skip blanks */ }
+
+    /* c is now nonblank */
+
+    if( islower( c )) {
+       yylval = c - 'a';
+       return ( LETTER );
+    }
+    if( isdigit( c )) {
+       yylval = c - '0';
+       return ( DIGIT );
+    }
+    return( c );
+}
diff --git a/test/calc2.output b/test/calc2.output
new file mode 100644 (file)
index 0000000..3aed475
--- /dev/null
@@ -0,0 +1,461 @@
+   0  $accept : list $end
+
+   1  list :
+   2       | list stat '\n'
+   3       | list error '\n'
+
+   4  stat : expr
+   5       | LETTER '=' expr
+
+   6  expr : '(' expr ')'
+   7       | expr '+' expr
+   8       | expr '-' expr
+   9       | expr '*' expr
+  10       | expr '/' expr
+  11       | expr '%' expr
+  12       | expr '&' expr
+  13       | expr '|' expr
+  14       | '-' expr
+  15       | LETTER
+  16       | number
+
+  17  number : DIGIT
+  18         | number DIGIT
+\f
+state 0
+       $accept : . list $end  (0)
+       list : .  (1)
+
+       .  reduce 1
+
+       list  goto 1
+
+
+state 1
+       $accept : list . $end  (0)
+       list : list . stat '\n'  (2)
+       list : list . error '\n'  (3)
+
+       $end  accept
+       error  shift 2
+       DIGIT  shift 3
+       LETTER  shift 4
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       stat  goto 7
+       expr  goto 8
+       number  goto 9
+
+
+state 2
+       list : list error . '\n'  (3)
+
+       '\n'  shift 10
+       .  error
+
+
+state 3
+       number : DIGIT .  (17)
+
+       .  reduce 17
+
+
+state 4
+       stat : LETTER . '=' expr  (5)
+       expr : LETTER .  (15)
+
+       '='  shift 11
+       '|'  reduce 15
+       '&'  reduce 15
+       '+'  reduce 15
+       '-'  reduce 15
+       '*'  reduce 15
+       '/'  reduce 15
+       '%'  reduce 15
+       '\n'  reduce 15
+
+
+state 5
+       expr : '-' . expr  (14)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 13
+       number  goto 9
+
+
+state 6
+       expr : '(' . expr ')'  (6)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 14
+       number  goto 9
+
+
+state 7
+       list : list stat . '\n'  (2)
+
+       '\n'  shift 15
+       .  error
+
+
+state 8
+       stat : expr .  (4)
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '|'  shift 16
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '\n'  reduce 4
+
+
+state 9
+       expr : number .  (16)
+       number : number . DIGIT  (18)
+
+       DIGIT  shift 23
+       '|'  reduce 16
+       '&'  reduce 16
+       '+'  reduce 16
+       '-'  reduce 16
+       '*'  reduce 16
+       '/'  reduce 16
+       '%'  reduce 16
+       '\n'  reduce 16
+       ')'  reduce 16
+
+
+state 10
+       list : list error '\n' .  (3)
+
+       .  reduce 3
+
+
+state 11
+       stat : LETTER '=' . expr  (5)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 24
+       number  goto 9
+
+
+state 12
+       expr : LETTER .  (15)
+
+       .  reduce 15
+
+
+state 13
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+       expr : '-' expr .  (14)
+
+       .  reduce 14
+
+
+state 14
+       expr : '(' expr . ')'  (6)
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '|'  shift 16
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       ')'  shift 25
+       .  error
+
+
+state 15
+       list : list stat '\n' .  (2)
+
+       .  reduce 2
+
+
+state 16
+       expr : expr '|' . expr  (13)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 26
+       number  goto 9
+
+
+state 17
+       expr : expr '&' . expr  (12)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 27
+       number  goto 9
+
+
+state 18
+       expr : expr '+' . expr  (7)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 28
+       number  goto 9
+
+
+state 19
+       expr : expr '-' . expr  (8)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 29
+       number  goto 9
+
+
+state 20
+       expr : expr '*' . expr  (9)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 30
+       number  goto 9
+
+
+state 21
+       expr : expr '/' . expr  (10)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 31
+       number  goto 9
+
+
+state 22
+       expr : expr '%' . expr  (11)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 32
+       number  goto 9
+
+
+state 23
+       number : number DIGIT .  (18)
+
+       .  reduce 18
+
+
+state 24
+       stat : LETTER '=' expr .  (5)
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '|'  shift 16
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '\n'  reduce 5
+
+
+state 25
+       expr : '(' expr ')' .  (6)
+
+       .  reduce 6
+
+
+state 26
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+       expr : expr '|' expr .  (13)
+
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 13
+       '\n'  reduce 13
+       ')'  reduce 13
+
+
+state 27
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr '&' expr .  (12)
+       expr : expr . '|' expr  (13)
+
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 12
+       '&'  reduce 12
+       '\n'  reduce 12
+       ')'  reduce 12
+
+
+state 28
+       expr : expr . '+' expr  (7)
+       expr : expr '+' expr .  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 7
+       '&'  reduce 7
+       '+'  reduce 7
+       '-'  reduce 7
+       '\n'  reduce 7
+       ')'  reduce 7
+
+
+state 29
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr '-' expr .  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 8
+       '&'  reduce 8
+       '+'  reduce 8
+       '-'  reduce 8
+       '\n'  reduce 8
+       ')'  reduce 8
+
+
+state 30
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr '*' expr .  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       .  reduce 9
+
+
+state 31
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr '/' expr .  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       .  reduce 10
+
+
+state 32
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr '%' expr .  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       .  reduce 11
+
+
+16 terminals, 5 nonterminals
+19 grammar rules, 33 states
diff --git a/test/calc2.tab.c b/test/calc2.tab.c
new file mode 100644 (file)
index 0000000..1be4d2d
--- /dev/null
@@ -0,0 +1,666 @@
+#ifndef lint
+static const char yysccsid[] = "@(#)yaccpar    1.9 (Berkeley) 02/21/93";
+#endif
+
+#define YYBYACC 1
+#define YYMAJOR 1
+#define YYMINOR 9
+
+#define YYEMPTY        (-1)
+#define yyclearin      (yychar = YYEMPTY)
+#define yyerrok        (yyerrflag = 0)
+#define YYRECOVERING() (yyerrflag != 0)
+
+
+#ifndef yyparse
+#define yyparse    calc2_parse
+#endif /* yyparse */
+
+#ifndef yylex
+#define yylex      calc2_lex
+#endif /* yylex */
+
+#ifndef yyerror
+#define yyerror    calc2_error
+#endif /* yyerror */
+
+#ifndef yychar
+#define yychar     calc2_char
+#endif /* yychar */
+
+#ifndef yyval
+#define yyval      calc2_val
+#endif /* yyval */
+
+#ifndef yylval
+#define yylval     calc2_lval
+#endif /* yylval */
+
+#ifndef yydebug
+#define yydebug    calc2_debug
+#endif /* yydebug */
+
+#ifndef yynerrs
+#define yynerrs    calc2_nerrs
+#endif /* yynerrs */
+
+#ifndef yyerrflag
+#define yyerrflag  calc2_errflag
+#endif /* yyerrflag */
+
+#ifndef yylhs
+#define yylhs      calc2_lhs
+#endif /* yylhs */
+
+#ifndef yylen
+#define yylen      calc2_len
+#endif /* yylen */
+
+#ifndef yydefred
+#define yydefred   calc2_defred
+#endif /* yydefred */
+
+#ifndef yydgoto
+#define yydgoto    calc2_dgoto
+#endif /* yydgoto */
+
+#ifndef yysindex
+#define yysindex   calc2_sindex
+#endif /* yysindex */
+
+#ifndef yyrindex
+#define yyrindex   calc2_rindex
+#endif /* yyrindex */
+
+#ifndef yygindex
+#define yygindex   calc2_gindex
+#endif /* yygindex */
+
+#ifndef yytable
+#define yytable    calc2_table
+#endif /* yytable */
+
+#ifndef yycheck
+#define yycheck    calc2_check
+#endif /* yycheck */
+
+#ifndef yyname
+#define yyname     calc2_name
+#endif /* yyname */
+
+#ifndef yyrule
+#define yyrule     calc2_rule
+#endif /* yyrule */
+#define YYPREFIX "calc2_"
+
+#define YYPURE 0
+
+#line 7 "calc2.y"
+# include <stdio.h>
+# include <ctype.h>
+
+#line 103 "calc2.tab.c"
+
+#ifndef YYSTYPE
+typedef int YYSTYPE;
+#endif
+
+/* compatibility with bison */
+#ifdef YYPARSE_PARAM
+/* compatibility with FreeBSD */
+# ifdef YYPARSE_PARAM_TYPE
+#  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
+# else
+#  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
+# endif
+#else
+# define YYPARSE_DECL() yyparse(int  regs[26], int * base)
+#endif
+
+/* Parameters sent to lex. */
+#ifdef YYLEX_PARAM
+# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
+# define YYLEX yylex(YYLEX_PARAM)
+#else
+# define YYLEX_DECL() yylex(int * base)
+# define YYLEX yylex(base)
+#endif
+
+extern int YYPARSE_DECL();
+extern int YYLEX_DECL();
+
+#define DIGIT 257
+#define LETTER 258
+#define UMINUS 259
+#define YYERRCODE 256
+static const short calc2_lhs[] = {                       -1,
+    0,    0,    0,    1,    1,    2,    2,    2,    2,    2,
+    2,    2,    2,    2,    2,    2,    3,    3,
+};
+static const short calc2_len[] = {                        2,
+    0,    3,    3,    1,    3,    3,    3,    3,    3,    3,
+    3,    3,    3,    2,    1,    1,    1,    2,
+};
+static const short calc2_defred[] = {                     1,
+    0,    0,   17,    0,    0,    0,    0,    0,    0,    3,
+    0,   15,   14,    0,    2,    0,    0,    0,    0,    0,
+    0,    0,   18,    0,    6,    0,    0,    0,    0,    9,
+   10,   11,
+};
+static const short calc2_dgoto[] = {                      1,
+    7,    8,    9,
+};
+static const short calc2_sindex[] = {                     0,
+  -40,   -7,    0,  -55,  -38,  -38,    1,  -29, -247,    0,
+  -38,    0,    0,   22,    0,  -38,  -38,  -38,  -38,  -38,
+  -38,  -38,    0,  -29,    0,   51,   60,  -20,  -20,    0,
+    0,    0,
+};
+static const short calc2_rindex[] = {                     0,
+    0,    0,    0,    2,    0,    0,    0,    9,   -9,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,   10,    0,   -6,   14,    5,   13,    0,
+    0,    0,
+};
+static const short calc2_gindex[] = {                     0,
+    0,   65,    0,
+};
+#define YYTABLESIZE 220
+static const short calc2_table[] = {                      6,
+   16,    6,   10,   13,    5,   11,    5,   22,   17,   23,
+   15,   15,   20,   18,    7,   19,   22,   21,    4,    5,
+    0,   20,    8,   12,    0,    0,   21,   16,   16,    0,
+    0,   16,   16,   16,   13,   16,    0,   16,   15,   15,
+    0,    0,    7,   15,   15,    7,   15,    7,   15,    7,
+    8,   12,    0,    8,   12,    8,    0,    8,   22,   17,
+    0,    0,   25,   20,   18,    0,   19,    0,   21,   13,
+   14,    0,    0,    0,    0,   24,    0,    0,    0,    0,
+   26,   27,   28,   29,   30,   31,   32,   22,   17,    0,
+    0,    0,   20,   18,   16,   19,   22,   21,    0,    0,
+    0,   20,   18,    0,   19,    0,   21,    0,    0,    0,
+    0,    0,    0,    0,   16,    0,    0,   13,    0,    0,
+    0,    0,    0,    0,    0,   15,    0,    0,    7,    0,
+    0,    0,    0,    0,    0,    0,    8,   12,    0,    0,
+    0,    0,    0,    0,    0,   16,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    2,    3,    4,    3,   12,
+};
+static const short calc2_check[] = {                     40,
+   10,   40,   10,   10,   45,   61,   45,   37,   38,  257,
+   10,   10,   42,   43,   10,   45,   37,   47,   10,   10,
+   -1,   42,   10,   10,   -1,   -1,   47,   37,   38,   -1,
+   -1,   41,   42,   43,   41,   45,   -1,   47,   37,   38,
+   -1,   -1,   38,   42,   43,   41,   45,   43,   47,   45,
+   38,   38,   -1,   41,   41,   43,   -1,   45,   37,   38,
+   -1,   -1,   41,   42,   43,   -1,   45,   -1,   47,    5,
+    6,   -1,   -1,   -1,   -1,   11,   -1,   -1,   -1,   -1,
+   16,   17,   18,   19,   20,   21,   22,   37,   38,   -1,
+   -1,   -1,   42,   43,  124,   45,   37,   47,   -1,   -1,
+   -1,   42,   43,   -1,   45,   -1,   47,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  124,   -1,   -1,  124,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,  124,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  124,  124,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  256,  257,  258,  257,  258,
+};
+#define YYFINAL 1
+#ifndef YYDEBUG
+#define YYDEBUG 0
+#endif
+#define YYMAXTOKEN 259
+#if YYDEBUG
+static const char *yyname[] = {
+
+"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
+0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
+};
+static const char *yyrule[] = {
+"$accept : list",
+"list :",
+"list : list stat '\\n'",
+"list : list error '\\n'",
+"stat : expr",
+"stat : LETTER '=' expr",
+"expr : '(' expr ')'",
+"expr : expr '+' expr",
+"expr : expr '-' expr",
+"expr : expr '*' expr",
+"expr : expr '/' expr",
+"expr : expr '%' expr",
+"expr : expr '&' expr",
+"expr : expr '|' expr",
+"expr : '-' expr",
+"expr : LETTER",
+"expr : number",
+"number : DIGIT",
+"number : number DIGIT",
+
+};
+#endif
+/* define the initial stack-sizes */
+#ifdef YYSTACKSIZE
+#undef YYMAXDEPTH
+#define YYMAXDEPTH  YYSTACKSIZE
+#else
+#ifdef YYMAXDEPTH
+#define YYSTACKSIZE YYMAXDEPTH
+#else
+#define YYSTACKSIZE 500
+#define YYMAXDEPTH  500
+#endif
+#endif
+
+#define YYINITSTACKSIZE 500
+
+int      yydebug;
+int      yynerrs;
+
+typedef struct {
+    unsigned stacksize;
+    short    *s_base;
+    short    *s_mark;
+    short    *s_last;
+    YYSTYPE  *l_base;
+    YYSTYPE  *l_mark;
+} YYSTACKDATA;
+int      yyerrflag;
+int      yychar;
+YYSTYPE  yyval;
+YYSTYPE  yylval;
+
+/* variables for the parser stack */
+static YYSTACKDATA yystack;
+#line 65 "calc2.y"
+ /* start of programs */
+
+int
+main (void)
+{
+    int regs[26];
+    int base;
+
+    while(!feof(stdin)) {
+       yyparse(regs, &base);
+    }
+    return 0;
+}
+
+static void
+yyerror(const char *s)
+{
+    fprintf(stderr, "%s\n", s);
+}
+
+int
+yylex(int *base)
+{
+       /* lexical analysis routine */
+       /* returns LETTER for a lower case letter, yylval = 0 through 25 */
+       /* return DIGIT for a digit, yylval = 0 through 9 */
+       /* all other characters are returned immediately */
+
+    int c;
+
+    while( (c=getchar()) == ' ' )   { /* skip blanks */ }
+
+    /* c is now nonblank */
+
+    if( islower( c )) {
+       yylval = c - 'a';
+       return ( LETTER );
+    }
+    if( isdigit( c )) {
+       yylval = (c - '0') % (*base);
+       return ( DIGIT );
+    }
+    return( c );
+}
+#line 336 "calc2.tab.c"
+
+#if YYDEBUG
+#include <stdio.h>             /* needed for printf */
+#endif
+
+#include <stdlib.h>    /* needed for malloc, etc */
+#include <string.h>    /* needed for memset */
+
+/* allocate initial stack or double stack size, up to YYMAXDEPTH */
+static int yygrowstack(YYSTACKDATA *data)
+{
+    int i;
+    unsigned newsize;
+    short *newss;
+    YYSTYPE *newvs;
+
+    if ((newsize = data->stacksize) == 0)
+        newsize = YYINITSTACKSIZE;
+    else if (newsize >= YYMAXDEPTH)
+        return -1;
+    else if ((newsize *= 2) > YYMAXDEPTH)
+        newsize = YYMAXDEPTH;
+
+    i = data->s_mark - data->s_base;
+    newss = (data->s_base != 0)
+          ? (short *)realloc(data->s_base, newsize * sizeof(*newss))
+          : (short *)malloc(newsize * sizeof(*newss));
+    if (newss == 0)
+        return -1;
+
+    data->s_base = newss;
+    data->s_mark = newss + i;
+
+    newvs = (data->l_base != 0)
+          ? (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs))
+          : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
+    if (newvs == 0)
+        return -1;
+
+    data->l_base = newvs;
+    data->l_mark = newvs + i;
+
+    data->stacksize = newsize;
+    data->s_last = data->s_base + newsize - 1;
+    return 0;
+}
+
+#if YYPURE || defined(YY_NO_LEAKS)
+static void yyfreestack(YYSTACKDATA *data)
+{
+    free(data->s_base);
+    free(data->l_base);
+    memset(data, 0, sizeof(*data));
+}
+#else
+#define yyfreestack(data) /* nothing */
+#endif
+
+#define YYABORT  goto yyabort
+#define YYREJECT goto yyabort
+#define YYACCEPT goto yyaccept
+#define YYERROR  goto yyerrlab
+
+int
+YYPARSE_DECL()
+{
+    int yym, yyn, yystate;
+#if YYDEBUG
+    const char *yys;
+
+    if ((yys = getenv("YYDEBUG")) != 0)
+    {
+        yyn = *yys;
+        if (yyn >= '0' && yyn <= '9')
+            yydebug = yyn - '0';
+    }
+#endif
+
+    yynerrs = 0;
+    yyerrflag = 0;
+    yychar = YYEMPTY;
+    yystate = 0;
+
+#if YYPURE
+    memset(&yystack, 0, sizeof(yystack));
+#endif
+
+    if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
+    yystack.s_mark = yystack.s_base;
+    yystack.l_mark = yystack.l_base;
+    yystate = 0;
+    *yystack.s_mark = 0;
+
+yyloop:
+    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
+    if (yychar < 0)
+    {
+        if ((yychar = YYLEX) < 0) yychar = 0;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, reading %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+    }
+    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: state %d, shifting to state %d\n",
+                    YYPREFIX, yystate, yytable[yyn]);
+#endif
+        if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+        {
+            goto yyoverflow;
+        }
+        yystate = yytable[yyn];
+        *++yystack.s_mark = yytable[yyn];
+        *++yystack.l_mark = yylval;
+        yychar = YYEMPTY;
+        if (yyerrflag > 0)  --yyerrflag;
+        goto yyloop;
+    }
+    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+        yyn = yytable[yyn];
+        goto yyreduce;
+    }
+    if (yyerrflag) goto yyinrecovery;
+
+    yyerror("syntax error");
+
+    goto yyerrlab;
+
+yyerrlab:
+    ++yynerrs;
+
+yyinrecovery:
+    if (yyerrflag < 3)
+    {
+        yyerrflag = 3;
+        for (;;)
+        {
+            if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
+                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: state %d, error recovery shifting\
+ to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
+#endif
+                if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+                {
+                    goto yyoverflow;
+                }
+                yystate = yytable[yyn];
+                *++yystack.s_mark = yytable[yyn];
+                *++yystack.l_mark = yylval;
+                goto yyloop;
+            }
+            else
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: error recovery discarding state %d\n",
+                            YYPREFIX, *yystack.s_mark);
+#endif
+                if (yystack.s_mark <= yystack.s_base) goto yyabort;
+                --yystack.s_mark;
+                --yystack.l_mark;
+            }
+        }
+    }
+    else
+    {
+        if (yychar == 0) goto yyabort;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+        yychar = YYEMPTY;
+        goto yyloop;
+    }
+
+yyreduce:
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
+                YYPREFIX, yystate, yyn, yyrule[yyn]);
+#endif
+    yym = yylen[yyn];
+    if (yym)
+        yyval = yystack.l_mark[1-yym];
+    else
+        memset(&yyval, 0, sizeof yyval);
+    switch (yyn)
+    {
+case 3:
+#line 27 "calc2.y"
+       {  yyerrok ; }
+break;
+case 4:
+#line 31 "calc2.y"
+       {  printf("%d\n",yystack.l_mark[0]);}
+break;
+case 5:
+#line 33 "calc2.y"
+       {  regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
+break;
+case 6:
+#line 37 "calc2.y"
+       {  yyval = yystack.l_mark[-1]; }
+break;
+case 7:
+#line 39 "calc2.y"
+       {  yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
+break;
+case 8:
+#line 41 "calc2.y"
+       {  yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
+break;
+case 9:
+#line 43 "calc2.y"
+       {  yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
+break;
+case 10:
+#line 45 "calc2.y"
+       {  yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
+break;
+case 11:
+#line 47 "calc2.y"
+       {  yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
+break;
+case 12:
+#line 49 "calc2.y"
+       {  yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
+break;
+case 13:
+#line 51 "calc2.y"
+       {  yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
+break;
+case 14:
+#line 53 "calc2.y"
+       {  yyval = - yystack.l_mark[0]; }
+break;
+case 15:
+#line 55 "calc2.y"
+       {  yyval = regs[yystack.l_mark[0]]; }
+break;
+case 17:
+#line 60 "calc2.y"
+       {  yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
+break;
+case 18:
+#line 62 "calc2.y"
+       {  yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
+break;
+#line 606 "calc2.tab.c"
+    }
+    yystack.s_mark -= yym;
+    yystate = *yystack.s_mark;
+    yystack.l_mark -= yym;
+    yym = yylhs[yyn];
+    if (yystate == 0 && yym == 0)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: after reduction, shifting from state 0 to\
+ state %d\n", YYPREFIX, YYFINAL);
+#endif
+        yystate = YYFINAL;
+        *++yystack.s_mark = YYFINAL;
+        *++yystack.l_mark = yyval;
+        if (yychar < 0)
+        {
+            if ((yychar = YYLEX) < 0) yychar = 0;
+#if YYDEBUG
+            if (yydebug)
+            {
+                yys = 0;
+                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+                if (!yys) yys = "illegal-symbol";
+                printf("%sdebug: state %d, reading %d (%s)\n",
+                        YYPREFIX, YYFINAL, yychar, yys);
+            }
+#endif
+        }
+        if (yychar == 0) goto yyaccept;
+        goto yyloop;
+    }
+    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
+        yystate = yytable[yyn];
+    else
+        yystate = yydgoto[yym];
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: after reduction, shifting from state %d \
+to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
+#endif
+    if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+    {
+        goto yyoverflow;
+    }
+    *++yystack.s_mark = (short) yystate;
+    *++yystack.l_mark = yyval;
+    goto yyloop;
+
+yyoverflow:
+    yyerror("yacc stack overflow");
+
+yyabort:
+    yyfreestack(&yystack);
+    return (1);
+
+yyaccept:
+    yyfreestack(&yystack);
+    return (0);
+}
diff --git a/test/calc2.tab.h b/test/calc2.tab.h
new file mode 100644 (file)
index 0000000..1921118
--- /dev/null
@@ -0,0 +1,3 @@
+#define DIGIT 257
+#define LETTER 258
+#define UMINUS 259
diff --git a/test/calc2.y b/test/calc2.y
new file mode 100644 (file)
index 0000000..393a38e
--- /dev/null
@@ -0,0 +1,108 @@
+%parse-param { int regs[26] }
+%parse-param { int *base }
+
+%lex-param { int *base }
+
+%{
+# include <stdio.h>
+# include <ctype.h>
+
+%}
+
+%start list
+
+%token DIGIT LETTER
+
+%left '|'
+%left '&'
+%left '+' '-'
+%left '*' '/' '%'
+%left UMINUS   /* supplies precedence for unary minus */
+
+%% /* beginning of rules section */
+
+list  :  /* empty */
+      |  list stat '\n'
+      |  list error '\n'
+            {  yyerrok ; }
+      ;
+
+stat  :  expr
+            {  printf("%d\n",$1);}
+      |  LETTER '=' expr
+            {  regs[$1] = $3; }
+      ;
+
+expr  :  '(' expr ')'
+            {  $$ = $2; }
+      |  expr '+' expr
+            {  $$ = $1 + $3; }
+      |  expr '-' expr
+            {  $$ = $1 - $3; }
+      |  expr '*' expr
+            {  $$ = $1 * $3; }
+      |  expr '/' expr
+            {  $$ = $1 / $3; }
+      |  expr '%' expr
+            {  $$ = $1 % $3; }
+      |  expr '&' expr
+            {  $$ = $1 & $3; }
+      |  expr '|' expr
+            {  $$ = $1 | $3; }
+      |  '-' expr %prec UMINUS
+            {  $$ = - $2; }
+      |  LETTER
+            {  $$ = regs[$1]; }
+      |  number
+      ;
+
+number:  DIGIT
+         {  $$ = $1; (*base) = ($1==0) ? 8 : 10; }
+      |  number DIGIT
+         {  $$ = (*base) * $1 + $2; }
+      ;
+
+%% /* start of programs */
+
+int
+main (void)
+{
+    int regs[26];
+    int base;
+
+    while(!feof(stdin)) {
+       yyparse(regs, &base);
+    }
+    return 0;
+}
+
+static void
+yyerror(const char *s)
+{
+    fprintf(stderr, "%s\n", s);
+}
+
+int
+yylex(int *base)
+{
+       /* lexical analysis routine */
+       /* returns LETTER for a lower case letter, yylval = 0 through 25 */
+       /* return DIGIT for a digit, yylval = 0 through 9 */
+       /* all other characters are returned immediately */
+
+    int c;
+
+    while( (c=getchar()) == ' ' )   { /* skip blanks */ }
+
+    /* c is now nonblank */
+
+    if( islower( c )) {
+       yylval = c - 'a';
+       return ( LETTER );
+    }
+    if( isdigit( c )) {
+       yylval = (c - '0') % (*base);
+       return ( DIGIT );
+    }
+    return( c );
+}
diff --git a/test/calc3.output b/test/calc3.output
new file mode 100644 (file)
index 0000000..3aed475
--- /dev/null
@@ -0,0 +1,461 @@
+   0  $accept : list $end
+
+   1  list :
+   2       | list stat '\n'
+   3       | list error '\n'
+
+   4  stat : expr
+   5       | LETTER '=' expr
+
+   6  expr : '(' expr ')'
+   7       | expr '+' expr
+   8       | expr '-' expr
+   9       | expr '*' expr
+  10       | expr '/' expr
+  11       | expr '%' expr
+  12       | expr '&' expr
+  13       | expr '|' expr
+  14       | '-' expr
+  15       | LETTER
+  16       | number
+
+  17  number : DIGIT
+  18         | number DIGIT
+\f
+state 0
+       $accept : . list $end  (0)
+       list : .  (1)
+
+       .  reduce 1
+
+       list  goto 1
+
+
+state 1
+       $accept : list . $end  (0)
+       list : list . stat '\n'  (2)
+       list : list . error '\n'  (3)
+
+       $end  accept
+       error  shift 2
+       DIGIT  shift 3
+       LETTER  shift 4
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       stat  goto 7
+       expr  goto 8
+       number  goto 9
+
+
+state 2
+       list : list error . '\n'  (3)
+
+       '\n'  shift 10
+       .  error
+
+
+state 3
+       number : DIGIT .  (17)
+
+       .  reduce 17
+
+
+state 4
+       stat : LETTER . '=' expr  (5)
+       expr : LETTER .  (15)
+
+       '='  shift 11
+       '|'  reduce 15
+       '&'  reduce 15
+       '+'  reduce 15
+       '-'  reduce 15
+       '*'  reduce 15
+       '/'  reduce 15
+       '%'  reduce 15
+       '\n'  reduce 15
+
+
+state 5
+       expr : '-' . expr  (14)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 13
+       number  goto 9
+
+
+state 6
+       expr : '(' . expr ')'  (6)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 14
+       number  goto 9
+
+
+state 7
+       list : list stat . '\n'  (2)
+
+       '\n'  shift 15
+       .  error
+
+
+state 8
+       stat : expr .  (4)
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '|'  shift 16
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '\n'  reduce 4
+
+
+state 9
+       expr : number .  (16)
+       number : number . DIGIT  (18)
+
+       DIGIT  shift 23
+       '|'  reduce 16
+       '&'  reduce 16
+       '+'  reduce 16
+       '-'  reduce 16
+       '*'  reduce 16
+       '/'  reduce 16
+       '%'  reduce 16
+       '\n'  reduce 16
+       ')'  reduce 16
+
+
+state 10
+       list : list error '\n' .  (3)
+
+       .  reduce 3
+
+
+state 11
+       stat : LETTER '=' . expr  (5)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 24
+       number  goto 9
+
+
+state 12
+       expr : LETTER .  (15)
+
+       .  reduce 15
+
+
+state 13
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+       expr : '-' expr .  (14)
+
+       .  reduce 14
+
+
+state 14
+       expr : '(' expr . ')'  (6)
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '|'  shift 16
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       ')'  shift 25
+       .  error
+
+
+state 15
+       list : list stat '\n' .  (2)
+
+       .  reduce 2
+
+
+state 16
+       expr : expr '|' . expr  (13)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 26
+       number  goto 9
+
+
+state 17
+       expr : expr '&' . expr  (12)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 27
+       number  goto 9
+
+
+state 18
+       expr : expr '+' . expr  (7)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 28
+       number  goto 9
+
+
+state 19
+       expr : expr '-' . expr  (8)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 29
+       number  goto 9
+
+
+state 20
+       expr : expr '*' . expr  (9)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 30
+       number  goto 9
+
+
+state 21
+       expr : expr '/' . expr  (10)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 31
+       number  goto 9
+
+
+state 22
+       expr : expr '%' . expr  (11)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 32
+       number  goto 9
+
+
+state 23
+       number : number DIGIT .  (18)
+
+       .  reduce 18
+
+
+state 24
+       stat : LETTER '=' expr .  (5)
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '|'  shift 16
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '\n'  reduce 5
+
+
+state 25
+       expr : '(' expr ')' .  (6)
+
+       .  reduce 6
+
+
+state 26
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+       expr : expr '|' expr .  (13)
+
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 13
+       '\n'  reduce 13
+       ')'  reduce 13
+
+
+state 27
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr '&' expr .  (12)
+       expr : expr . '|' expr  (13)
+
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 12
+       '&'  reduce 12
+       '\n'  reduce 12
+       ')'  reduce 12
+
+
+state 28
+       expr : expr . '+' expr  (7)
+       expr : expr '+' expr .  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 7
+       '&'  reduce 7
+       '+'  reduce 7
+       '-'  reduce 7
+       '\n'  reduce 7
+       ')'  reduce 7
+
+
+state 29
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr '-' expr .  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 8
+       '&'  reduce 8
+       '+'  reduce 8
+       '-'  reduce 8
+       '\n'  reduce 8
+       ')'  reduce 8
+
+
+state 30
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr '*' expr .  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       .  reduce 9
+
+
+state 31
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr '/' expr .  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       .  reduce 10
+
+
+state 32
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr '%' expr .  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       .  reduce 11
+
+
+16 terminals, 5 nonterminals
+19 grammar rules, 33 states
diff --git a/test/calc3.tab.c b/test/calc3.tab.c
new file mode 100644 (file)
index 0000000..f3d3ee6
--- /dev/null
@@ -0,0 +1,666 @@
+#ifndef lint
+static const char yysccsid[] = "@(#)yaccpar    1.9 (Berkeley) 02/21/93";
+#endif
+
+#define YYBYACC 1
+#define YYMAJOR 1
+#define YYMINOR 9
+
+#define YYEMPTY        (-1)
+#define yyclearin      (yychar = YYEMPTY)
+#define yyerrok        (yyerrflag = 0)
+#define YYRECOVERING() (yyerrflag != 0)
+
+
+#ifndef yyparse
+#define yyparse    calc3_parse
+#endif /* yyparse */
+
+#ifndef yylex
+#define yylex      calc3_lex
+#endif /* yylex */
+
+#ifndef yyerror
+#define yyerror    calc3_error
+#endif /* yyerror */
+
+#ifndef yychar
+#define yychar     calc3_char
+#endif /* yychar */
+
+#ifndef yyval
+#define yyval      calc3_val
+#endif /* yyval */
+
+#ifndef yylval
+#define yylval     calc3_lval
+#endif /* yylval */
+
+#ifndef yydebug
+#define yydebug    calc3_debug
+#endif /* yydebug */
+
+#ifndef yynerrs
+#define yynerrs    calc3_nerrs
+#endif /* yynerrs */
+
+#ifndef yyerrflag
+#define yyerrflag  calc3_errflag
+#endif /* yyerrflag */
+
+#ifndef yylhs
+#define yylhs      calc3_lhs
+#endif /* yylhs */
+
+#ifndef yylen
+#define yylen      calc3_len
+#endif /* yylen */
+
+#ifndef yydefred
+#define yydefred   calc3_defred
+#endif /* yydefred */
+
+#ifndef yydgoto
+#define yydgoto    calc3_dgoto
+#endif /* yydgoto */
+
+#ifndef yysindex
+#define yysindex   calc3_sindex
+#endif /* yysindex */
+
+#ifndef yyrindex
+#define yyrindex   calc3_rindex
+#endif /* yyrindex */
+
+#ifndef yygindex
+#define yygindex   calc3_gindex
+#endif /* yygindex */
+
+#ifndef yytable
+#define yytable    calc3_table
+#endif /* yytable */
+
+#ifndef yycheck
+#define yycheck    calc3_check
+#endif /* yycheck */
+
+#ifndef yyname
+#define yyname     calc3_name
+#endif /* yyname */
+
+#ifndef yyrule
+#define yyrule     calc3_rule
+#endif /* yyrule */
+#define YYPREFIX "calc3_"
+
+#define YYPURE 1
+
+#line 9 "calc3.y"
+# include <stdio.h>
+# include <ctype.h>
+
+#line 103 "calc3.tab.c"
+
+#ifndef YYSTYPE
+typedef int YYSTYPE;
+#endif
+
+/* compatibility with bison */
+#ifdef YYPARSE_PARAM
+/* compatibility with FreeBSD */
+# ifdef YYPARSE_PARAM_TYPE
+#  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
+# else
+#  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
+# endif
+#else
+# define YYPARSE_DECL() yyparse(int  regs[26], int * base)
+#endif
+
+/* Parameters sent to lex. */
+#ifdef YYLEX_PARAM
+# define YYLEX_DECL() yylex(YYSTYPE *yylval, void *YYLEX_PARAM)
+# define YYLEX yylex(&yylval, YYLEX_PARAM)
+#else
+# define YYLEX_DECL() yylex(YYSTYPE *yylval, int * base)
+# define YYLEX yylex(&yylval, base)
+#endif
+
+extern int YYPARSE_DECL();
+extern int YYLEX_DECL();
+
+#define DIGIT 257
+#define LETTER 258
+#define UMINUS 259
+#define YYERRCODE 256
+static const short calc3_lhs[] = {                       -1,
+    0,    0,    0,    1,    1,    2,    2,    2,    2,    2,
+    2,    2,    2,    2,    2,    2,    3,    3,
+};
+static const short calc3_len[] = {                        2,
+    0,    3,    3,    1,    3,    3,    3,    3,    3,    3,
+    3,    3,    3,    2,    1,    1,    1,    2,
+};
+static const short calc3_defred[] = {                     1,
+    0,    0,   17,    0,    0,    0,    0,    0,    0,    3,
+    0,   15,   14,    0,    2,    0,    0,    0,    0,    0,
+    0,    0,   18,    0,    6,    0,    0,    0,    0,    9,
+   10,   11,
+};
+static const short calc3_dgoto[] = {                      1,
+    7,    8,    9,
+};
+static const short calc3_sindex[] = {                     0,
+  -40,   -7,    0,  -55,  -38,  -38,    1,  -29, -247,    0,
+  -38,    0,    0,   22,    0,  -38,  -38,  -38,  -38,  -38,
+  -38,  -38,    0,  -29,    0,   51,   60,  -20,  -20,    0,
+    0,    0,
+};
+static const short calc3_rindex[] = {                     0,
+    0,    0,    0,    2,    0,    0,    0,    9,   -9,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,   10,    0,   -6,   14,    5,   13,    0,
+    0,    0,
+};
+static const short calc3_gindex[] = {                     0,
+    0,   65,    0,
+};
+#define YYTABLESIZE 220
+static const short calc3_table[] = {                      6,
+   16,    6,   10,   13,    5,   11,    5,   22,   17,   23,
+   15,   15,   20,   18,    7,   19,   22,   21,    4,    5,
+    0,   20,    8,   12,    0,    0,   21,   16,   16,    0,
+    0,   16,   16,   16,   13,   16,    0,   16,   15,   15,
+    0,    0,    7,   15,   15,    7,   15,    7,   15,    7,
+    8,   12,    0,    8,   12,    8,    0,    8,   22,   17,
+    0,    0,   25,   20,   18,    0,   19,    0,   21,   13,
+   14,    0,    0,    0,    0,   24,    0,    0,    0,    0,
+   26,   27,   28,   29,   30,   31,   32,   22,   17,    0,
+    0,    0,   20,   18,   16,   19,   22,   21,    0,    0,
+    0,   20,   18,    0,   19,    0,   21,    0,    0,    0,
+    0,    0,    0,    0,   16,    0,    0,   13,    0,    0,
+    0,    0,    0,    0,    0,   15,    0,    0,    7,    0,
+    0,    0,    0,    0,    0,    0,    8,   12,    0,    0,
+    0,    0,    0,    0,    0,   16,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    2,    3,    4,    3,   12,
+};
+static const short calc3_check[] = {                     40,
+   10,   40,   10,   10,   45,   61,   45,   37,   38,  257,
+   10,   10,   42,   43,   10,   45,   37,   47,   10,   10,
+   -1,   42,   10,   10,   -1,   -1,   47,   37,   38,   -1,
+   -1,   41,   42,   43,   41,   45,   -1,   47,   37,   38,
+   -1,   -1,   38,   42,   43,   41,   45,   43,   47,   45,
+   38,   38,   -1,   41,   41,   43,   -1,   45,   37,   38,
+   -1,   -1,   41,   42,   43,   -1,   45,   -1,   47,    5,
+    6,   -1,   -1,   -1,   -1,   11,   -1,   -1,   -1,   -1,
+   16,   17,   18,   19,   20,   21,   22,   37,   38,   -1,
+   -1,   -1,   42,   43,  124,   45,   37,   47,   -1,   -1,
+   -1,   42,   43,   -1,   45,   -1,   47,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  124,   -1,   -1,  124,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,  124,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  124,  124,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  256,  257,  258,  257,  258,
+};
+#define YYFINAL 1
+#ifndef YYDEBUG
+#define YYDEBUG 0
+#endif
+#define YYMAXTOKEN 259
+#if YYDEBUG
+static const char *yyname[] = {
+
+"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
+0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
+};
+static const char *yyrule[] = {
+"$accept : list",
+"list :",
+"list : list stat '\\n'",
+"list : list error '\\n'",
+"stat : expr",
+"stat : LETTER '=' expr",
+"expr : '(' expr ')'",
+"expr : expr '+' expr",
+"expr : expr '-' expr",
+"expr : expr '*' expr",
+"expr : expr '/' expr",
+"expr : expr '%' expr",
+"expr : expr '&' expr",
+"expr : expr '|' expr",
+"expr : '-' expr",
+"expr : LETTER",
+"expr : number",
+"number : DIGIT",
+"number : number DIGIT",
+
+};
+#endif
+/* define the initial stack-sizes */
+#ifdef YYSTACKSIZE
+#undef YYMAXDEPTH
+#define YYMAXDEPTH  YYSTACKSIZE
+#else
+#ifdef YYMAXDEPTH
+#define YYSTACKSIZE YYMAXDEPTH
+#else
+#define YYSTACKSIZE 500
+#define YYMAXDEPTH  500
+#endif
+#endif
+
+#define YYINITSTACKSIZE 500
+
+int      yydebug;
+int      yynerrs;
+
+typedef struct {
+    unsigned stacksize;
+    short    *s_base;
+    short    *s_mark;
+    short    *s_last;
+    YYSTYPE  *l_base;
+    YYSTYPE  *l_mark;
+} YYSTACKDATA;
+#line 67 "calc3.y"
+ /* start of programs */
+
+int
+main (void)
+{
+    int regs[26];
+    int base;
+
+    while(!feof(stdin)) {
+       yyparse(regs, &base);
+    }
+    return 0;
+}
+
+static void
+yyerror(const char *s)
+{
+    fprintf(stderr, "%s\n", s);
+}
+
+int
+YYLEX_DECL()
+{
+       /* lexical analysis routine */
+       /* returns LETTER for a lower case letter, yylval = 0 through 25 */
+       /* return DIGIT for a digit, yylval = 0 through 9 */
+       /* all other characters are returned immediately */
+
+    int c;
+
+    while( (c=getchar()) == ' ' )   { /* skip blanks */ }
+
+    /* c is now nonblank */
+
+    if( islower( c )) {
+       *yylval = (c - 'a');
+       return ( LETTER );
+    }
+    if( isdigit( c )) {
+       *yylval = (c - '0') % (*base);
+       return ( DIGIT );
+    }
+    return( c );
+}
+#line 329 "calc3.tab.c"
+
+#if YYDEBUG
+#include <stdio.h>             /* needed for printf */
+#endif
+
+#include <stdlib.h>    /* needed for malloc, etc */
+#include <string.h>    /* needed for memset */
+
+/* allocate initial stack or double stack size, up to YYMAXDEPTH */
+static int yygrowstack(YYSTACKDATA *data)
+{
+    int i;
+    unsigned newsize;
+    short *newss;
+    YYSTYPE *newvs;
+
+    if ((newsize = data->stacksize) == 0)
+        newsize = YYINITSTACKSIZE;
+    else if (newsize >= YYMAXDEPTH)
+        return -1;
+    else if ((newsize *= 2) > YYMAXDEPTH)
+        newsize = YYMAXDEPTH;
+
+    i = data->s_mark - data->s_base;
+    newss = (data->s_base != 0)
+          ? (short *)realloc(data->s_base, newsize * sizeof(*newss))
+          : (short *)malloc(newsize * sizeof(*newss));
+    if (newss == 0)
+        return -1;
+
+    data->s_base = newss;
+    data->s_mark = newss + i;
+
+    newvs = (data->l_base != 0)
+          ? (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs))
+          : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
+    if (newvs == 0)
+        return -1;
+
+    data->l_base = newvs;
+    data->l_mark = newvs + i;
+
+    data->stacksize = newsize;
+    data->s_last = data->s_base + newsize - 1;
+    return 0;
+}
+
+#if YYPURE || defined(YY_NO_LEAKS)
+static void yyfreestack(YYSTACKDATA *data)
+{
+    free(data->s_base);
+    free(data->l_base);
+    memset(data, 0, sizeof(*data));
+}
+#else
+#define yyfreestack(data) /* nothing */
+#endif
+
+#define YYABORT  goto yyabort
+#define YYREJECT goto yyabort
+#define YYACCEPT goto yyaccept
+#define YYERROR  goto yyerrlab
+
+int
+YYPARSE_DECL()
+{
+    int      yyerrflag;
+    int      yychar;
+    YYSTYPE  yyval;
+    YYSTYPE  yylval;
+
+    /* variables for the parser stack */
+    YYSTACKDATA yystack;
+    int yym, yyn, yystate;
+#if YYDEBUG
+    const char *yys;
+
+    if ((yys = getenv("YYDEBUG")) != 0)
+    {
+        yyn = *yys;
+        if (yyn >= '0' && yyn <= '9')
+            yydebug = yyn - '0';
+    }
+#endif
+
+    yynerrs = 0;
+    yyerrflag = 0;
+    yychar = YYEMPTY;
+    yystate = 0;
+
+#if YYPURE
+    memset(&yystack, 0, sizeof(yystack));
+#endif
+
+    if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
+    yystack.s_mark = yystack.s_base;
+    yystack.l_mark = yystack.l_base;
+    yystate = 0;
+    *yystack.s_mark = 0;
+
+yyloop:
+    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
+    if (yychar < 0)
+    {
+        if ((yychar = YYLEX) < 0) yychar = 0;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, reading %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+    }
+    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: state %d, shifting to state %d\n",
+                    YYPREFIX, yystate, yytable[yyn]);
+#endif
+        if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+        {
+            goto yyoverflow;
+        }
+        yystate = yytable[yyn];
+        *++yystack.s_mark = yytable[yyn];
+        *++yystack.l_mark = yylval;
+        yychar = YYEMPTY;
+        if (yyerrflag > 0)  --yyerrflag;
+        goto yyloop;
+    }
+    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+        yyn = yytable[yyn];
+        goto yyreduce;
+    }
+    if (yyerrflag) goto yyinrecovery;
+
+    yyerror("syntax error");
+
+    goto yyerrlab;
+
+yyerrlab:
+    ++yynerrs;
+
+yyinrecovery:
+    if (yyerrflag < 3)
+    {
+        yyerrflag = 3;
+        for (;;)
+        {
+            if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
+                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: state %d, error recovery shifting\
+ to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
+#endif
+                if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+                {
+                    goto yyoverflow;
+                }
+                yystate = yytable[yyn];
+                *++yystack.s_mark = yytable[yyn];
+                *++yystack.l_mark = yylval;
+                goto yyloop;
+            }
+            else
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: error recovery discarding state %d\n",
+                            YYPREFIX, *yystack.s_mark);
+#endif
+                if (yystack.s_mark <= yystack.s_base) goto yyabort;
+                --yystack.s_mark;
+                --yystack.l_mark;
+            }
+        }
+    }
+    else
+    {
+        if (yychar == 0) goto yyabort;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+        yychar = YYEMPTY;
+        goto yyloop;
+    }
+
+yyreduce:
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
+                YYPREFIX, yystate, yyn, yyrule[yyn]);
+#endif
+    yym = yylen[yyn];
+    if (yym)
+        yyval = yystack.l_mark[1-yym];
+    else
+        memset(&yyval, 0, sizeof yyval);
+    switch (yyn)
+    {
+case 3:
+#line 29 "calc3.y"
+       {  yyerrok ; }
+break;
+case 4:
+#line 33 "calc3.y"
+       {  printf("%d\n",yystack.l_mark[0]);}
+break;
+case 5:
+#line 35 "calc3.y"
+       {  regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
+break;
+case 6:
+#line 39 "calc3.y"
+       {  yyval = yystack.l_mark[-1]; }
+break;
+case 7:
+#line 41 "calc3.y"
+       {  yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
+break;
+case 8:
+#line 43 "calc3.y"
+       {  yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
+break;
+case 9:
+#line 45 "calc3.y"
+       {  yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
+break;
+case 10:
+#line 47 "calc3.y"
+       {  yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
+break;
+case 11:
+#line 49 "calc3.y"
+       {  yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
+break;
+case 12:
+#line 51 "calc3.y"
+       {  yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
+break;
+case 13:
+#line 53 "calc3.y"
+       {  yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
+break;
+case 14:
+#line 55 "calc3.y"
+       {  yyval = - yystack.l_mark[0]; }
+break;
+case 15:
+#line 57 "calc3.y"
+       {  yyval = regs[yystack.l_mark[0]]; }
+break;
+case 17:
+#line 62 "calc3.y"
+       {  yyval = yystack.l_mark[0]; (*base) = (yystack.l_mark[0]==0) ? 8 : 10; }
+break;
+case 18:
+#line 64 "calc3.y"
+       {  yyval = (*base) * yystack.l_mark[-1] + yystack.l_mark[0]; }
+break;
+#line 606 "calc3.tab.c"
+    }
+    yystack.s_mark -= yym;
+    yystate = *yystack.s_mark;
+    yystack.l_mark -= yym;
+    yym = yylhs[yyn];
+    if (yystate == 0 && yym == 0)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: after reduction, shifting from state 0 to\
+ state %d\n", YYPREFIX, YYFINAL);
+#endif
+        yystate = YYFINAL;
+        *++yystack.s_mark = YYFINAL;
+        *++yystack.l_mark = yyval;
+        if (yychar < 0)
+        {
+            if ((yychar = YYLEX) < 0) yychar = 0;
+#if YYDEBUG
+            if (yydebug)
+            {
+                yys = 0;
+                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+                if (!yys) yys = "illegal-symbol";
+                printf("%sdebug: state %d, reading %d (%s)\n",
+                        YYPREFIX, YYFINAL, yychar, yys);
+            }
+#endif
+        }
+        if (yychar == 0) goto yyaccept;
+        goto yyloop;
+    }
+    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
+        yystate = yytable[yyn];
+    else
+        yystate = yydgoto[yym];
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: after reduction, shifting from state %d \
+to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
+#endif
+    if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+    {
+        goto yyoverflow;
+    }
+    *++yystack.s_mark = (short) yystate;
+    *++yystack.l_mark = yyval;
+    goto yyloop;
+
+yyoverflow:
+    yyerror("yacc stack overflow");
+
+yyabort:
+    yyfreestack(&yystack);
+    return (1);
+
+yyaccept:
+    yyfreestack(&yystack);
+    return (0);
+}
diff --git a/test/calc3.tab.h b/test/calc3.tab.h
new file mode 100644 (file)
index 0000000..1921118
--- /dev/null
@@ -0,0 +1,3 @@
+#define DIGIT 257
+#define LETTER 258
+#define UMINUS 259
diff --git a/test/calc3.y b/test/calc3.y
new file mode 100644 (file)
index 0000000..4ce1773
--- /dev/null
@@ -0,0 +1,110 @@
+%pure-parser
+
+%parse-param { int regs[26] }
+%parse-param { int *base }
+
+%lex-param { int *base }
+
+%{
+# include <stdio.h>
+# include <ctype.h>
+
+%}
+
+%start list
+
+%token DIGIT LETTER
+
+%left '|'
+%left '&'
+%left '+' '-'
+%left '*' '/' '%'
+%left UMINUS   /* supplies precedence for unary minus */
+
+%% /* beginning of rules section */
+
+list  :  /* empty */
+      |  list stat '\n'
+      |  list error '\n'
+            {  yyerrok ; }
+      ;
+
+stat  :  expr
+            {  printf("%d\n",$1);}
+      |  LETTER '=' expr
+            {  regs[$1] = $3; }
+      ;
+
+expr  :  '(' expr ')'
+            {  $$ = $2; }
+      |  expr '+' expr
+            {  $$ = $1 + $3; }
+      |  expr '-' expr
+            {  $$ = $1 - $3; }
+      |  expr '*' expr
+            {  $$ = $1 * $3; }
+      |  expr '/' expr
+            {  $$ = $1 / $3; }
+      |  expr '%' expr
+            {  $$ = $1 % $3; }
+      |  expr '&' expr
+            {  $$ = $1 & $3; }
+      |  expr '|' expr
+            {  $$ = $1 | $3; }
+      |  '-' expr %prec UMINUS
+            {  $$ = - $2; }
+      |  LETTER
+            {  $$ = regs[$1]; }
+      |  number
+      ;
+
+number:  DIGIT
+         {  $$ = $1; (*base) = ($1==0) ? 8 : 10; }
+      |  number DIGIT
+         {  $$ = (*base) * $1 + $2; }
+      ;
+
+%% /* start of programs */
+
+int
+main (void)
+{
+    int regs[26];
+    int base;
+
+    while(!feof(stdin)) {
+       yyparse(regs, &base);
+    }
+    return 0;
+}
+
+static void
+yyerror(const char *s)
+{
+    fprintf(stderr, "%s\n", s);
+}
+
+int
+YYLEX_DECL()
+{
+       /* lexical analysis routine */
+       /* returns LETTER for a lower case letter, yylval = 0 through 25 */
+       /* return DIGIT for a digit, yylval = 0 through 9 */
+       /* all other characters are returned immediately */
+
+    int c;
+
+    while( (c=getchar()) == ' ' )   { /* skip blanks */ }
+
+    /* c is now nonblank */
+
+    if( islower( c )) {
+       *yylval = (c - 'a');
+       return ( LETTER );
+    }
+    if( isdigit( c )) {
+       *yylval = (c - '0') % (*base);
+       return ( DIGIT );
+    }
+    return( c );
+}
diff --git a/test/code_calc.code.c b/test/code_calc.code.c
new file mode 100644 (file)
index 0000000..38a45b5
--- /dev/null
@@ -0,0 +1,567 @@
+#ifndef lint
+static const char yysccsid[] = "@(#)yaccpar    1.9 (Berkeley) 02/21/93";
+#endif
+
+#define YYBYACC 1
+#define YYMAJOR 1
+#define YYMINOR 9
+
+#define YYEMPTY        (-1)
+#define yyclearin      (yychar = YYEMPTY)
+#define yyerrok        (yyerrflag = 0)
+#define YYRECOVERING() (yyerrflag != 0)
+
+
+#define YYPURE 0
+
+#line 2 "code_calc.y"
+# include <stdio.h>
+# include <ctype.h>
+
+int regs[26];
+int base;
+
+#line 106 "code_calc.code.c"
+
+#ifndef YYSTYPE
+typedef int YYSTYPE;
+#endif
+
+/* compatibility with bison */
+#ifdef YYPARSE_PARAM
+/* compatibility with FreeBSD */
+# ifdef YYPARSE_PARAM_TYPE
+#  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
+# else
+#  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
+# endif
+#else
+# define YYPARSE_DECL() yyparse(void)
+#endif
+
+/* Parameters sent to lex. */
+#ifdef YYLEX_PARAM
+# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
+# define YYLEX yylex(YYLEX_PARAM)
+#else
+# define YYLEX_DECL() yylex(void)
+# define YYLEX yylex()
+#endif
+
+extern int YYPARSE_DECL();
+extern int YYLEX_DECL();
+
+#define DIGIT 257
+#define LETTER 258
+#define UMINUS 259
+#define YYERRCODE 256
+#define YYTABLESIZE 220
+#define YYFINAL 1
+#ifndef YYDEBUG
+#define YYDEBUG 0
+#endif
+#define YYMAXTOKEN 259
+
+#ifndef yyparse
+#define yyparse    calc_parse
+#endif /* yyparse */
+
+#ifndef yylex
+#define yylex      calc_lex
+#endif /* yylex */
+
+#ifndef yyerror
+#define yyerror    calc_error
+#endif /* yyerror */
+
+#ifndef yychar
+#define yychar     calc_char
+#endif /* yychar */
+
+#ifndef yyval
+#define yyval      calc_val
+#endif /* yyval */
+
+#ifndef yylval
+#define yylval     calc_lval
+#endif /* yylval */
+
+#ifndef yydebug
+#define yydebug    calc_debug
+#endif /* yydebug */
+
+#ifndef yynerrs
+#define yynerrs    calc_nerrs
+#endif /* yynerrs */
+
+#ifndef yyerrflag
+#define yyerrflag  calc_errflag
+#endif /* yyerrflag */
+
+#ifndef yylhs
+#define yylhs      calc_lhs
+#endif /* yylhs */
+
+#ifndef yylen
+#define yylen      calc_len
+#endif /* yylen */
+
+#ifndef yydefred
+#define yydefred   calc_defred
+#endif /* yydefred */
+
+#ifndef yydgoto
+#define yydgoto    calc_dgoto
+#endif /* yydgoto */
+
+#ifndef yysindex
+#define yysindex   calc_sindex
+#endif /* yysindex */
+
+#ifndef yyrindex
+#define yyrindex   calc_rindex
+#endif /* yyrindex */
+
+#ifndef yygindex
+#define yygindex   calc_gindex
+#endif /* yygindex */
+
+#ifndef yytable
+#define yytable    calc_table
+#endif /* yytable */
+
+#ifndef yycheck
+#define yycheck    calc_check
+#endif /* yycheck */
+
+#ifndef yyname
+#define yyname     calc_name
+#endif /* yyname */
+
+#ifndef yyrule
+#define yyrule     calc_rule
+#endif /* yyrule */
+#define YYPREFIX "calc_"
+extern int YYPARSE_DECL();
+extern int YYLEX_DECL();
+
+extern short yylhs[];
+extern short yylen[];
+extern short yydefred[];
+extern short yydgoto[];
+extern short yysindex[];
+extern short yyrindex[];
+extern short yygindex[];
+extern short yytable[];
+extern short yycheck[];
+
+#if YYDEBUG
+extern char *yyname[];
+extern char *yyrule[];
+#endif
+/* define the initial stack-sizes */
+#ifdef YYSTACKSIZE
+#undef YYMAXDEPTH
+#define YYMAXDEPTH  YYSTACKSIZE
+#else
+#ifdef YYMAXDEPTH
+#define YYSTACKSIZE YYMAXDEPTH
+#else
+#define YYSTACKSIZE 500
+#define YYMAXDEPTH  500
+#endif
+#endif
+
+#define YYINITSTACKSIZE 500
+
+int      yydebug;
+int      yynerrs;
+
+typedef struct {
+    unsigned stacksize;
+    short    *s_base;
+    short    *s_mark;
+    short    *s_last;
+    YYSTYPE  *l_base;
+    YYSTYPE  *l_mark;
+} YYSTACKDATA;
+int      yyerrflag;
+int      yychar;
+YYSTYPE  yyval;
+YYSTYPE  yylval;
+
+/* variables for the parser stack */
+static YYSTACKDATA yystack;
+#line 63 "code_calc.y"
+ /* start of programs */
+
+int
+main (void)
+{
+    while(!feof(stdin)) {
+       yyparse();
+    }
+    return 0;
+}
+
+static void
+yyerror(const char *s)
+{
+    fprintf(stderr, "%s\n", s);
+}
+
+int
+yylex(void) {
+       /* lexical analysis routine */
+       /* returns LETTER for a lower case letter, yylval = 0 through 25 */
+       /* return DIGIT for a digit, yylval = 0 through 9 */
+       /* all other characters are returned immediately */
+
+    int c;
+
+    while( (c=getchar()) == ' ' )   { /* skip blanks */ }
+
+    /* c is now nonblank */
+
+    if( islower( c )) {
+       yylval = c - 'a';
+       return ( LETTER );
+    }
+    if( isdigit( c )) {
+       yylval = c - '0';
+       return ( DIGIT );
+    }
+    return( c );
+}
+#line 318 "code_calc.code.c"
+
+#if YYDEBUG
+#include <stdio.h>             /* needed for printf */
+#endif
+
+#include <stdlib.h>    /* needed for malloc, etc */
+#include <string.h>    /* needed for memset */
+
+/* allocate initial stack or double stack size, up to YYMAXDEPTH */
+static int yygrowstack(YYSTACKDATA *data)
+{
+    int i;
+    unsigned newsize;
+    short *newss;
+    YYSTYPE *newvs;
+
+    if ((newsize = data->stacksize) == 0)
+        newsize = YYINITSTACKSIZE;
+    else if (newsize >= YYMAXDEPTH)
+        return -1;
+    else if ((newsize *= 2) > YYMAXDEPTH)
+        newsize = YYMAXDEPTH;
+
+    i = data->s_mark - data->s_base;
+    newss = (data->s_base != 0)
+          ? (short *)realloc(data->s_base, newsize * sizeof(*newss))
+          : (short *)malloc(newsize * sizeof(*newss));
+    if (newss == 0)
+        return -1;
+
+    data->s_base = newss;
+    data->s_mark = newss + i;
+
+    newvs = (data->l_base != 0)
+          ? (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs))
+          : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
+    if (newvs == 0)
+        return -1;
+
+    data->l_base = newvs;
+    data->l_mark = newvs + i;
+
+    data->stacksize = newsize;
+    data->s_last = data->s_base + newsize - 1;
+    return 0;
+}
+
+#if YYPURE || defined(YY_NO_LEAKS)
+static void yyfreestack(YYSTACKDATA *data)
+{
+    free(data->s_base);
+    free(data->l_base);
+    memset(data, 0, sizeof(*data));
+}
+#else
+#define yyfreestack(data) /* nothing */
+#endif
+
+#define YYABORT  goto yyabort
+#define YYREJECT goto yyabort
+#define YYACCEPT goto yyaccept
+#define YYERROR  goto yyerrlab
+
+int
+YYPARSE_DECL()
+{
+    int yym, yyn, yystate;
+#if YYDEBUG
+    const char *yys;
+
+    if ((yys = getenv("YYDEBUG")) != 0)
+    {
+        yyn = *yys;
+        if (yyn >= '0' && yyn <= '9')
+            yydebug = yyn - '0';
+    }
+#endif
+
+    yynerrs = 0;
+    yyerrflag = 0;
+    yychar = YYEMPTY;
+    yystate = 0;
+
+#if YYPURE
+    memset(&yystack, 0, sizeof(yystack));
+#endif
+
+    if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
+    yystack.s_mark = yystack.s_base;
+    yystack.l_mark = yystack.l_base;
+    yystate = 0;
+    *yystack.s_mark = 0;
+
+yyloop:
+    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
+    if (yychar < 0)
+    {
+        if ((yychar = YYLEX) < 0) yychar = 0;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, reading %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+    }
+    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: state %d, shifting to state %d\n",
+                    YYPREFIX, yystate, yytable[yyn]);
+#endif
+        if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+        {
+            goto yyoverflow;
+        }
+        yystate = yytable[yyn];
+        *++yystack.s_mark = yytable[yyn];
+        *++yystack.l_mark = yylval;
+        yychar = YYEMPTY;
+        if (yyerrflag > 0)  --yyerrflag;
+        goto yyloop;
+    }
+    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+        yyn = yytable[yyn];
+        goto yyreduce;
+    }
+    if (yyerrflag) goto yyinrecovery;
+
+    yyerror("syntax error");
+
+    goto yyerrlab;
+
+yyerrlab:
+    ++yynerrs;
+
+yyinrecovery:
+    if (yyerrflag < 3)
+    {
+        yyerrflag = 3;
+        for (;;)
+        {
+            if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
+                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: state %d, error recovery shifting\
+ to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
+#endif
+                if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+                {
+                    goto yyoverflow;
+                }
+                yystate = yytable[yyn];
+                *++yystack.s_mark = yytable[yyn];
+                *++yystack.l_mark = yylval;
+                goto yyloop;
+            }
+            else
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: error recovery discarding state %d\n",
+                            YYPREFIX, *yystack.s_mark);
+#endif
+                if (yystack.s_mark <= yystack.s_base) goto yyabort;
+                --yystack.s_mark;
+                --yystack.l_mark;
+            }
+        }
+    }
+    else
+    {
+        if (yychar == 0) goto yyabort;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+        yychar = YYEMPTY;
+        goto yyloop;
+    }
+
+yyreduce:
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
+                YYPREFIX, yystate, yyn, yyrule[yyn]);
+#endif
+    yym = yylen[yyn];
+    if (yym)
+        yyval = yystack.l_mark[1-yym];
+    else
+        memset(&yyval, 0, sizeof yyval);
+    switch (yyn)
+    {
+case 3:
+#line 25 "code_calc.y"
+       {  yyerrok ; }
+break;
+case 4:
+#line 29 "code_calc.y"
+       {  printf("%d\n",yystack.l_mark[0]);}
+break;
+case 5:
+#line 31 "code_calc.y"
+       {  regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
+break;
+case 6:
+#line 35 "code_calc.y"
+       {  yyval = yystack.l_mark[-1]; }
+break;
+case 7:
+#line 37 "code_calc.y"
+       {  yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
+break;
+case 8:
+#line 39 "code_calc.y"
+       {  yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
+break;
+case 9:
+#line 41 "code_calc.y"
+       {  yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
+break;
+case 10:
+#line 43 "code_calc.y"
+       {  yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
+break;
+case 11:
+#line 45 "code_calc.y"
+       {  yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
+break;
+case 12:
+#line 47 "code_calc.y"
+       {  yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
+break;
+case 13:
+#line 49 "code_calc.y"
+       {  yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
+break;
+case 14:
+#line 51 "code_calc.y"
+       {  yyval = - yystack.l_mark[0]; }
+break;
+case 15:
+#line 53 "code_calc.y"
+       {  yyval = regs[yystack.l_mark[0]]; }
+break;
+case 17:
+#line 58 "code_calc.y"
+       {  yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
+break;
+case 18:
+#line 60 "code_calc.y"
+       {  yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
+break;
+#line 588 "code_calc.code.c"
+    }
+    yystack.s_mark -= yym;
+    yystate = *yystack.s_mark;
+    yystack.l_mark -= yym;
+    yym = yylhs[yyn];
+    if (yystate == 0 && yym == 0)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: after reduction, shifting from state 0 to\
+ state %d\n", YYPREFIX, YYFINAL);
+#endif
+        yystate = YYFINAL;
+        *++yystack.s_mark = YYFINAL;
+        *++yystack.l_mark = yyval;
+        if (yychar < 0)
+        {
+            if ((yychar = YYLEX) < 0) yychar = 0;
+#if YYDEBUG
+            if (yydebug)
+            {
+                yys = 0;
+                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+                if (!yys) yys = "illegal-symbol";
+                printf("%sdebug: state %d, reading %d (%s)\n",
+                        YYPREFIX, YYFINAL, yychar, yys);
+            }
+#endif
+        }
+        if (yychar == 0) goto yyaccept;
+        goto yyloop;
+    }
+    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
+        yystate = yytable[yyn];
+    else
+        yystate = yydgoto[yym];
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: after reduction, shifting from state %d \
+to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
+#endif
+    if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+    {
+        goto yyoverflow;
+    }
+    *++yystack.s_mark = (short) yystate;
+    *++yystack.l_mark = yyval;
+    goto yyloop;
+
+yyoverflow:
+    yyerror("yacc stack overflow");
+
+yyabort:
+    yyfreestack(&yystack);
+    return (1);
+
+yyaccept:
+    yyfreestack(&yystack);
+    return (0);
+}
diff --git a/test/code_calc.output b/test/code_calc.output
new file mode 100644 (file)
index 0000000..3aed475
--- /dev/null
@@ -0,0 +1,461 @@
+   0  $accept : list $end
+
+   1  list :
+   2       | list stat '\n'
+   3       | list error '\n'
+
+   4  stat : expr
+   5       | LETTER '=' expr
+
+   6  expr : '(' expr ')'
+   7       | expr '+' expr
+   8       | expr '-' expr
+   9       | expr '*' expr
+  10       | expr '/' expr
+  11       | expr '%' expr
+  12       | expr '&' expr
+  13       | expr '|' expr
+  14       | '-' expr
+  15       | LETTER
+  16       | number
+
+  17  number : DIGIT
+  18         | number DIGIT
+\f
+state 0
+       $accept : . list $end  (0)
+       list : .  (1)
+
+       .  reduce 1
+
+       list  goto 1
+
+
+state 1
+       $accept : list . $end  (0)
+       list : list . stat '\n'  (2)
+       list : list . error '\n'  (3)
+
+       $end  accept
+       error  shift 2
+       DIGIT  shift 3
+       LETTER  shift 4
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       stat  goto 7
+       expr  goto 8
+       number  goto 9
+
+
+state 2
+       list : list error . '\n'  (3)
+
+       '\n'  shift 10
+       .  error
+
+
+state 3
+       number : DIGIT .  (17)
+
+       .  reduce 17
+
+
+state 4
+       stat : LETTER . '=' expr  (5)
+       expr : LETTER .  (15)
+
+       '='  shift 11
+       '|'  reduce 15
+       '&'  reduce 15
+       '+'  reduce 15
+       '-'  reduce 15
+       '*'  reduce 15
+       '/'  reduce 15
+       '%'  reduce 15
+       '\n'  reduce 15
+
+
+state 5
+       expr : '-' . expr  (14)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 13
+       number  goto 9
+
+
+state 6
+       expr : '(' . expr ')'  (6)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 14
+       number  goto 9
+
+
+state 7
+       list : list stat . '\n'  (2)
+
+       '\n'  shift 15
+       .  error
+
+
+state 8
+       stat : expr .  (4)
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '|'  shift 16
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '\n'  reduce 4
+
+
+state 9
+       expr : number .  (16)
+       number : number . DIGIT  (18)
+
+       DIGIT  shift 23
+       '|'  reduce 16
+       '&'  reduce 16
+       '+'  reduce 16
+       '-'  reduce 16
+       '*'  reduce 16
+       '/'  reduce 16
+       '%'  reduce 16
+       '\n'  reduce 16
+       ')'  reduce 16
+
+
+state 10
+       list : list error '\n' .  (3)
+
+       .  reduce 3
+
+
+state 11
+       stat : LETTER '=' . expr  (5)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 24
+       number  goto 9
+
+
+state 12
+       expr : LETTER .  (15)
+
+       .  reduce 15
+
+
+state 13
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+       expr : '-' expr .  (14)
+
+       .  reduce 14
+
+
+state 14
+       expr : '(' expr . ')'  (6)
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '|'  shift 16
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       ')'  shift 25
+       .  error
+
+
+state 15
+       list : list stat '\n' .  (2)
+
+       .  reduce 2
+
+
+state 16
+       expr : expr '|' . expr  (13)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 26
+       number  goto 9
+
+
+state 17
+       expr : expr '&' . expr  (12)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 27
+       number  goto 9
+
+
+state 18
+       expr : expr '+' . expr  (7)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 28
+       number  goto 9
+
+
+state 19
+       expr : expr '-' . expr  (8)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 29
+       number  goto 9
+
+
+state 20
+       expr : expr '*' . expr  (9)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 30
+       number  goto 9
+
+
+state 21
+       expr : expr '/' . expr  (10)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 31
+       number  goto 9
+
+
+state 22
+       expr : expr '%' . expr  (11)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 32
+       number  goto 9
+
+
+state 23
+       number : number DIGIT .  (18)
+
+       .  reduce 18
+
+
+state 24
+       stat : LETTER '=' expr .  (5)
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '|'  shift 16
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '\n'  reduce 5
+
+
+state 25
+       expr : '(' expr ')' .  (6)
+
+       .  reduce 6
+
+
+state 26
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+       expr : expr '|' expr .  (13)
+
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 13
+       '\n'  reduce 13
+       ')'  reduce 13
+
+
+state 27
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr '&' expr .  (12)
+       expr : expr . '|' expr  (13)
+
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 12
+       '&'  reduce 12
+       '\n'  reduce 12
+       ')'  reduce 12
+
+
+state 28
+       expr : expr . '+' expr  (7)
+       expr : expr '+' expr .  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 7
+       '&'  reduce 7
+       '+'  reduce 7
+       '-'  reduce 7
+       '\n'  reduce 7
+       ')'  reduce 7
+
+
+state 29
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr '-' expr .  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 8
+       '&'  reduce 8
+       '+'  reduce 8
+       '-'  reduce 8
+       '\n'  reduce 8
+       ')'  reduce 8
+
+
+state 30
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr '*' expr .  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       .  reduce 9
+
+
+state 31
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr '/' expr .  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       .  reduce 10
+
+
+state 32
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr '%' expr .  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       .  reduce 11
+
+
+16 terminals, 5 nonterminals
+19 grammar rules, 33 states
diff --git a/test/code_calc.tab.c b/test/code_calc.tab.c
new file mode 100644 (file)
index 0000000..37a17ef
--- /dev/null
@@ -0,0 +1,199 @@
+
+#ifndef yyparse
+#define yyparse    calc_parse
+#endif /* yyparse */
+
+#ifndef yylex
+#define yylex      calc_lex
+#endif /* yylex */
+
+#ifndef yyerror
+#define yyerror    calc_error
+#endif /* yyerror */
+
+#ifndef yychar
+#define yychar     calc_char
+#endif /* yychar */
+
+#ifndef yyval
+#define yyval      calc_val
+#endif /* yyval */
+
+#ifndef yylval
+#define yylval     calc_lval
+#endif /* yylval */
+
+#ifndef yydebug
+#define yydebug    calc_debug
+#endif /* yydebug */
+
+#ifndef yynerrs
+#define yynerrs    calc_nerrs
+#endif /* yynerrs */
+
+#ifndef yyerrflag
+#define yyerrflag  calc_errflag
+#endif /* yyerrflag */
+
+#ifndef yylhs
+#define yylhs      calc_lhs
+#endif /* yylhs */
+
+#ifndef yylen
+#define yylen      calc_len
+#endif /* yylen */
+
+#ifndef yydefred
+#define yydefred   calc_defred
+#endif /* yydefred */
+
+#ifndef yydgoto
+#define yydgoto    calc_dgoto
+#endif /* yydgoto */
+
+#ifndef yysindex
+#define yysindex   calc_sindex
+#endif /* yysindex */
+
+#ifndef yyrindex
+#define yyrindex   calc_rindex
+#endif /* yyrindex */
+
+#ifndef yygindex
+#define yygindex   calc_gindex
+#endif /* yygindex */
+
+#ifndef yytable
+#define yytable    calc_table
+#endif /* yytable */
+
+#ifndef yycheck
+#define yycheck    calc_check
+#endif /* yycheck */
+
+#ifndef yyname
+#define yyname     calc_name
+#endif /* yyname */
+
+#ifndef yyrule
+#define yyrule     calc_rule
+#endif /* yyrule */
+#define YYPREFIX "calc_"
+const short calc_lhs[] = {                        -1,
+    0,    0,    0,    1,    1,    2,    2,    2,    2,    2,
+    2,    2,    2,    2,    2,    2,    3,    3,
+};
+const short calc_len[] = {                         2,
+    0,    3,    3,    1,    3,    3,    3,    3,    3,    3,
+    3,    3,    3,    2,    1,    1,    1,    2,
+};
+const short calc_defred[] = {                      1,
+    0,    0,   17,    0,    0,    0,    0,    0,    0,    3,
+    0,   15,   14,    0,    2,    0,    0,    0,    0,    0,
+    0,    0,   18,    0,    6,    0,    0,    0,    0,    9,
+   10,   11,
+};
+const short calc_dgoto[] = {                       1,
+    7,    8,    9,
+};
+const short calc_sindex[] = {                      0,
+  -40,   -7,    0,  -55,  -38,  -38,    1,  -29, -247,    0,
+  -38,    0,    0,   22,    0,  -38,  -38,  -38,  -38,  -38,
+  -38,  -38,    0,  -29,    0,   51,   60,  -20,  -20,    0,
+    0,    0,
+};
+const short calc_rindex[] = {                      0,
+    0,    0,    0,    2,    0,    0,    0,    9,   -9,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,   10,    0,   -6,   14,    5,   13,    0,
+    0,    0,
+};
+const short calc_gindex[] = {                      0,
+    0,   65,    0,
+};
+const short calc_table[] = {                       6,
+   16,    6,   10,   13,    5,   11,    5,   22,   17,   23,
+   15,   15,   20,   18,    7,   19,   22,   21,    4,    5,
+    0,   20,    8,   12,    0,    0,   21,   16,   16,    0,
+    0,   16,   16,   16,   13,   16,    0,   16,   15,   15,
+    0,    0,    7,   15,   15,    7,   15,    7,   15,    7,
+    8,   12,    0,    8,   12,    8,    0,    8,   22,   17,
+    0,    0,   25,   20,   18,    0,   19,    0,   21,   13,
+   14,    0,    0,    0,    0,   24,    0,    0,    0,    0,
+   26,   27,   28,   29,   30,   31,   32,   22,   17,    0,
+    0,    0,   20,   18,   16,   19,   22,   21,    0,    0,
+    0,   20,   18,    0,   19,    0,   21,    0,    0,    0,
+    0,    0,    0,    0,   16,    0,    0,   13,    0,    0,
+    0,    0,    0,    0,    0,   15,    0,    0,    7,    0,
+    0,    0,    0,    0,    0,    0,    8,   12,    0,    0,
+    0,    0,    0,    0,    0,   16,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    2,    3,    4,    3,   12,
+};
+const short calc_check[] = {                      40,
+   10,   40,   10,   10,   45,   61,   45,   37,   38,  257,
+   10,   10,   42,   43,   10,   45,   37,   47,   10,   10,
+   -1,   42,   10,   10,   -1,   -1,   47,   37,   38,   -1,
+   -1,   41,   42,   43,   41,   45,   -1,   47,   37,   38,
+   -1,   -1,   38,   42,   43,   41,   45,   43,   47,   45,
+   38,   38,   -1,   41,   41,   43,   -1,   45,   37,   38,
+   -1,   -1,   41,   42,   43,   -1,   45,   -1,   47,    5,
+    6,   -1,   -1,   -1,   -1,   11,   -1,   -1,   -1,   -1,
+   16,   17,   18,   19,   20,   21,   22,   37,   38,   -1,
+   -1,   -1,   42,   43,  124,   45,   37,   47,   -1,   -1,
+   -1,   42,   43,   -1,   45,   -1,   47,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  124,   -1,   -1,  124,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,  124,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  124,  124,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  256,  257,  258,  257,  258,
+};
+#ifndef YYDEBUG
+#define YYDEBUG 0
+#endif
+#if YYDEBUG
+const char *yyname[] = {
+
+"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
+0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
+};
+const char *yyrule[] = {
+"$accept : list",
+"list :",
+"list : list stat '\\n'",
+"list : list error '\\n'",
+"stat : expr",
+"stat : LETTER '=' expr",
+"expr : '(' expr ')'",
+"expr : expr '+' expr",
+"expr : expr '-' expr",
+"expr : expr '*' expr",
+"expr : expr '/' expr",
+"expr : expr '%' expr",
+"expr : expr '&' expr",
+"expr : expr '|' expr",
+"expr : '-' expr",
+"expr : LETTER",
+"expr : number",
+"number : DIGIT",
+"number : number DIGIT",
+
+};
+#endif
diff --git a/test/code_calc.tab.h b/test/code_calc.tab.h
new file mode 100644 (file)
index 0000000..1921118
--- /dev/null
@@ -0,0 +1,3 @@
+#define DIGIT 257
+#define LETTER 258
+#define UMINUS 259
diff --git a/test/code_calc.y b/test/code_calc.y
new file mode 100644 (file)
index 0000000..9644e07
--- /dev/null
@@ -0,0 +1,102 @@
+%{
+# include <stdio.h>
+# include <ctype.h>
+
+int regs[26];
+int base;
+
+%}
+
+%start list
+
+%token DIGIT LETTER
+
+%left '|'
+%left '&'
+%left '+' '-'
+%left '*' '/' '%'
+%left UMINUS   /* supplies precedence for unary minus */
+
+%% /* beginning of rules section */
+
+list  :  /* empty */
+      |  list stat '\n'
+      |  list error '\n'
+            {  yyerrok ; }
+      ;
+
+stat  :  expr
+            {  printf("%d\n",$1);}
+      |  LETTER '=' expr
+            {  regs[$1] = $3; }
+      ;
+
+expr  :  '(' expr ')'
+            {  $$ = $2; }
+      |  expr '+' expr
+            {  $$ = $1 + $3; }
+      |  expr '-' expr
+            {  $$ = $1 - $3; }
+      |  expr '*' expr
+            {  $$ = $1 * $3; }
+      |  expr '/' expr
+            {  $$ = $1 / $3; }
+      |  expr '%' expr
+            {  $$ = $1 % $3; }
+      |  expr '&' expr
+            {  $$ = $1 & $3; }
+      |  expr '|' expr
+            {  $$ = $1 | $3; }
+      |  '-' expr %prec UMINUS
+            {  $$ = - $2; }
+      |  LETTER
+            {  $$ = regs[$1]; }
+      |  number
+      ;
+
+number:  DIGIT
+         {  $$ = $1; base = ($1==0) ? 8 : 10; }
+      |  number DIGIT
+         {  $$ = base * $1 + $2; }
+      ;
+
+%% /* start of programs */
+
+int
+main (void)
+{
+    while(!feof(stdin)) {
+       yyparse();
+    }
+    return 0;
+}
+
+static void
+yyerror(const char *s)
+{
+    fprintf(stderr, "%s\n", s);
+}
+
+int
+yylex(void) {
+       /* lexical analysis routine */
+       /* returns LETTER for a lower case letter, yylval = 0 through 25 */
+       /* return DIGIT for a digit, yylval = 0 through 9 */
+       /* all other characters are returned immediately */
+
+    int c;
+
+    while( (c=getchar()) == ' ' )   { /* skip blanks */ }
+
+    /* c is now nonblank */
+
+    if( islower( c )) {
+       yylval = c - 'a';
+       return ( LETTER );
+    }
+    if( isdigit( c )) {
+       yylval = c - '0';
+       return ( DIGIT );
+    }
+    return( c );
+}
diff --git a/test/code_error.code.c b/test/code_error.code.c
new file mode 100644 (file)
index 0000000..d45b8a4
--- /dev/null
@@ -0,0 +1,476 @@
+#ifndef lint
+static const char yysccsid[] = "@(#)yaccpar    1.9 (Berkeley) 02/21/93";
+#endif
+
+#define YYBYACC 1
+#define YYMAJOR 1
+#define YYMINOR 9
+
+#define YYEMPTY        (-1)
+#define yyclearin      (yychar = YYEMPTY)
+#define yyerrok        (yyerrflag = 0)
+#define YYRECOVERING() (yyerrflag != 0)
+
+
+#define YYPURE 0
+
+
+#ifndef YYSTYPE
+typedef int YYSTYPE;
+#endif
+
+/* compatibility with bison */
+#ifdef YYPARSE_PARAM
+/* compatibility with FreeBSD */
+# ifdef YYPARSE_PARAM_TYPE
+#  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
+# else
+#  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
+# endif
+#else
+# define YYPARSE_DECL() yyparse(void)
+#endif
+
+/* Parameters sent to lex. */
+#ifdef YYLEX_PARAM
+# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
+# define YYLEX yylex(YYLEX_PARAM)
+#else
+# define YYLEX_DECL() yylex(void)
+# define YYLEX yylex()
+#endif
+
+extern int YYPARSE_DECL();
+extern int YYLEX_DECL();
+
+#define YYERRCODE 256
+#define YYTABLESIZE 0
+#define YYFINAL 2
+#ifndef YYDEBUG
+#define YYDEBUG 0
+#endif
+#define YYMAXTOKEN 0
+
+#ifndef yyparse
+#define yyparse    error_parse
+#endif /* yyparse */
+
+#ifndef yylex
+#define yylex      error_lex
+#endif /* yylex */
+
+#ifndef yyerror
+#define yyerror    error_error
+#endif /* yyerror */
+
+#ifndef yychar
+#define yychar     error_char
+#endif /* yychar */
+
+#ifndef yyval
+#define yyval      error_val
+#endif /* yyval */
+
+#ifndef yylval
+#define yylval     error_lval
+#endif /* yylval */
+
+#ifndef yydebug
+#define yydebug    error_debug
+#endif /* yydebug */
+
+#ifndef yynerrs
+#define yynerrs    error_nerrs
+#endif /* yynerrs */
+
+#ifndef yyerrflag
+#define yyerrflag  error_errflag
+#endif /* yyerrflag */
+
+#ifndef yylhs
+#define yylhs      error_lhs
+#endif /* yylhs */
+
+#ifndef yylen
+#define yylen      error_len
+#endif /* yylen */
+
+#ifndef yydefred
+#define yydefred   error_defred
+#endif /* yydefred */
+
+#ifndef yydgoto
+#define yydgoto    error_dgoto
+#endif /* yydgoto */
+
+#ifndef yysindex
+#define yysindex   error_sindex
+#endif /* yysindex */
+
+#ifndef yyrindex
+#define yyrindex   error_rindex
+#endif /* yyrindex */
+
+#ifndef yygindex
+#define yygindex   error_gindex
+#endif /* yygindex */
+
+#ifndef yytable
+#define yytable    error_table
+#endif /* yytable */
+
+#ifndef yycheck
+#define yycheck    error_check
+#endif /* yycheck */
+
+#ifndef yyname
+#define yyname     error_name
+#endif /* yyname */
+
+#ifndef yyrule
+#define yyrule     error_rule
+#endif /* yyrule */
+#define YYPREFIX "error_"
+extern int YYPARSE_DECL();
+extern int YYLEX_DECL();
+
+extern short yylhs[];
+extern short yylen[];
+extern short yydefred[];
+extern short yydgoto[];
+extern short yysindex[];
+extern short yyrindex[];
+extern short yygindex[];
+extern short yytable[];
+extern short yycheck[];
+
+#if YYDEBUG
+extern char *yyname[];
+extern char *yyrule[];
+#endif
+/* define the initial stack-sizes */
+#ifdef YYSTACKSIZE
+#undef YYMAXDEPTH
+#define YYMAXDEPTH  YYSTACKSIZE
+#else
+#ifdef YYMAXDEPTH
+#define YYSTACKSIZE YYMAXDEPTH
+#else
+#define YYSTACKSIZE 500
+#define YYMAXDEPTH  500
+#endif
+#endif
+
+#define YYINITSTACKSIZE 500
+
+int      yydebug;
+int      yynerrs;
+
+typedef struct {
+    unsigned stacksize;
+    short    *s_base;
+    short    *s_mark;
+    short    *s_last;
+    YYSTYPE  *l_base;
+    YYSTYPE  *l_mark;
+} YYSTACKDATA;
+int      yyerrflag;
+int      yychar;
+YYSTYPE  yyval;
+YYSTYPE  yylval;
+
+/* variables for the parser stack */
+static YYSTACKDATA yystack;
+#line 4 "code_error.y"
+
+#include <stdio.h>
+
+int
+main(void)
+{
+    printf("yyparse() = %d\n", yyparse());
+    return 0;
+}
+
+int
+yylex(void)
+{
+    return -1;
+}
+
+static void
+yyerror(const char* s)
+{
+    printf("%s\n", s);
+}
+#line 288 "code_error.code.c"
+
+#if YYDEBUG
+#include <stdio.h>             /* needed for printf */
+#endif
+
+#include <stdlib.h>    /* needed for malloc, etc */
+#include <string.h>    /* needed for memset */
+
+/* allocate initial stack or double stack size, up to YYMAXDEPTH */
+static int yygrowstack(YYSTACKDATA *data)
+{
+    int i;
+    unsigned newsize;
+    short *newss;
+    YYSTYPE *newvs;
+
+    if ((newsize = data->stacksize) == 0)
+        newsize = YYINITSTACKSIZE;
+    else if (newsize >= YYMAXDEPTH)
+        return -1;
+    else if ((newsize *= 2) > YYMAXDEPTH)
+        newsize = YYMAXDEPTH;
+
+    i = data->s_mark - data->s_base;
+    newss = (data->s_base != 0)
+          ? (short *)realloc(data->s_base, newsize * sizeof(*newss))
+          : (short *)malloc(newsize * sizeof(*newss));
+    if (newss == 0)
+        return -1;
+
+    data->s_base = newss;
+    data->s_mark = newss + i;
+
+    newvs = (data->l_base != 0)
+          ? (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs))
+          : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
+    if (newvs == 0)
+        return -1;
+
+    data->l_base = newvs;
+    data->l_mark = newvs + i;
+
+    data->stacksize = newsize;
+    data->s_last = data->s_base + newsize - 1;
+    return 0;
+}
+
+#if YYPURE || defined(YY_NO_LEAKS)
+static void yyfreestack(YYSTACKDATA *data)
+{
+    free(data->s_base);
+    free(data->l_base);
+    memset(data, 0, sizeof(*data));
+}
+#else
+#define yyfreestack(data) /* nothing */
+#endif
+
+#define YYABORT  goto yyabort
+#define YYREJECT goto yyabort
+#define YYACCEPT goto yyaccept
+#define YYERROR  goto yyerrlab
+
+int
+YYPARSE_DECL()
+{
+    int yym, yyn, yystate;
+#if YYDEBUG
+    const char *yys;
+
+    if ((yys = getenv("YYDEBUG")) != 0)
+    {
+        yyn = *yys;
+        if (yyn >= '0' && yyn <= '9')
+            yydebug = yyn - '0';
+    }
+#endif
+
+    yynerrs = 0;
+    yyerrflag = 0;
+    yychar = YYEMPTY;
+    yystate = 0;
+
+#if YYPURE
+    memset(&yystack, 0, sizeof(yystack));
+#endif
+
+    if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
+    yystack.s_mark = yystack.s_base;
+    yystack.l_mark = yystack.l_base;
+    yystate = 0;
+    *yystack.s_mark = 0;
+
+yyloop:
+    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
+    if (yychar < 0)
+    {
+        if ((yychar = YYLEX) < 0) yychar = 0;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, reading %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+    }
+    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: state %d, shifting to state %d\n",
+                    YYPREFIX, yystate, yytable[yyn]);
+#endif
+        if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+        {
+            goto yyoverflow;
+        }
+        yystate = yytable[yyn];
+        *++yystack.s_mark = yytable[yyn];
+        *++yystack.l_mark = yylval;
+        yychar = YYEMPTY;
+        if (yyerrflag > 0)  --yyerrflag;
+        goto yyloop;
+    }
+    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+        yyn = yytable[yyn];
+        goto yyreduce;
+    }
+    if (yyerrflag) goto yyinrecovery;
+
+    yyerror("syntax error");
+
+    goto yyerrlab;
+
+yyerrlab:
+    ++yynerrs;
+
+yyinrecovery:
+    if (yyerrflag < 3)
+    {
+        yyerrflag = 3;
+        for (;;)
+        {
+            if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
+                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: state %d, error recovery shifting\
+ to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
+#endif
+                if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+                {
+                    goto yyoverflow;
+                }
+                yystate = yytable[yyn];
+                *++yystack.s_mark = yytable[yyn];
+                *++yystack.l_mark = yylval;
+                goto yyloop;
+            }
+            else
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: error recovery discarding state %d\n",
+                            YYPREFIX, *yystack.s_mark);
+#endif
+                if (yystack.s_mark <= yystack.s_base) goto yyabort;
+                --yystack.s_mark;
+                --yystack.l_mark;
+            }
+        }
+    }
+    else
+    {
+        if (yychar == 0) goto yyabort;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+        yychar = YYEMPTY;
+        goto yyloop;
+    }
+
+yyreduce:
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
+                YYPREFIX, yystate, yyn, yyrule[yyn]);
+#endif
+    yym = yylen[yyn];
+    if (yym)
+        yyval = yystack.l_mark[1-yym];
+    else
+        memset(&yyval, 0, sizeof yyval);
+    switch (yyn)
+    {
+    }
+    yystack.s_mark -= yym;
+    yystate = *yystack.s_mark;
+    yystack.l_mark -= yym;
+    yym = yylhs[yyn];
+    if (yystate == 0 && yym == 0)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: after reduction, shifting from state 0 to\
+ state %d\n", YYPREFIX, YYFINAL);
+#endif
+        yystate = YYFINAL;
+        *++yystack.s_mark = YYFINAL;
+        *++yystack.l_mark = yyval;
+        if (yychar < 0)
+        {
+            if ((yychar = YYLEX) < 0) yychar = 0;
+#if YYDEBUG
+            if (yydebug)
+            {
+                yys = 0;
+                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+                if (!yys) yys = "illegal-symbol";
+                printf("%sdebug: state %d, reading %d (%s)\n",
+                        YYPREFIX, YYFINAL, yychar, yys);
+            }
+#endif
+        }
+        if (yychar == 0) goto yyaccept;
+        goto yyloop;
+    }
+    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
+        yystate = yytable[yyn];
+    else
+        yystate = yydgoto[yym];
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: after reduction, shifting from state %d \
+to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
+#endif
+    if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+    {
+        goto yyoverflow;
+    }
+    *++yystack.s_mark = (short) yystate;
+    *++yystack.l_mark = yyval;
+    goto yyloop;
+
+yyoverflow:
+    yyerror("yacc stack overflow");
+
+yyabort:
+    yyfreestack(&yystack);
+    return (1);
+
+yyaccept:
+    yyfreestack(&yystack);
+    return (0);
+}
diff --git a/test/code_error.output b/test/code_error.output
new file mode 100644 (file)
index 0000000..0c4db62
--- /dev/null
@@ -0,0 +1,27 @@
+   0  $accept : S $end
+
+   1  S : error
+\f
+state 0
+       $accept : . S $end  (0)
+
+       error  shift 1
+       .  error
+
+       S  goto 2
+
+
+state 1
+       S : error .  (1)
+
+       .  reduce 1
+
+
+state 2
+       $accept : S . $end  (0)
+
+       $end  accept
+
+
+2 terminals, 2 nonterminals
+2 grammar rules, 3 states
diff --git a/test/code_error.tab.c b/test/code_error.tab.c
new file mode 100644 (file)
index 0000000..eb4db12
--- /dev/null
@@ -0,0 +1,118 @@
+
+#ifndef yyparse
+#define yyparse    error_parse
+#endif /* yyparse */
+
+#ifndef yylex
+#define yylex      error_lex
+#endif /* yylex */
+
+#ifndef yyerror
+#define yyerror    error_error
+#endif /* yyerror */
+
+#ifndef yychar
+#define yychar     error_char
+#endif /* yychar */
+
+#ifndef yyval
+#define yyval      error_val
+#endif /* yyval */
+
+#ifndef yylval
+#define yylval     error_lval
+#endif /* yylval */
+
+#ifndef yydebug
+#define yydebug    error_debug
+#endif /* yydebug */
+
+#ifndef yynerrs
+#define yynerrs    error_nerrs
+#endif /* yynerrs */
+
+#ifndef yyerrflag
+#define yyerrflag  error_errflag
+#endif /* yyerrflag */
+
+#ifndef yylhs
+#define yylhs      error_lhs
+#endif /* yylhs */
+
+#ifndef yylen
+#define yylen      error_len
+#endif /* yylen */
+
+#ifndef yydefred
+#define yydefred   error_defred
+#endif /* yydefred */
+
+#ifndef yydgoto
+#define yydgoto    error_dgoto
+#endif /* yydgoto */
+
+#ifndef yysindex
+#define yysindex   error_sindex
+#endif /* yysindex */
+
+#ifndef yyrindex
+#define yyrindex   error_rindex
+#endif /* yyrindex */
+
+#ifndef yygindex
+#define yygindex   error_gindex
+#endif /* yygindex */
+
+#ifndef yytable
+#define yytable    error_table
+#endif /* yytable */
+
+#ifndef yycheck
+#define yycheck    error_check
+#endif /* yycheck */
+
+#ifndef yyname
+#define yyname     error_name
+#endif /* yyname */
+
+#ifndef yyrule
+#define yyrule     error_rule
+#endif /* yyrule */
+#define YYPREFIX "error_"
+const short error_lhs[] = {                       -1,
+    0,
+};
+const short error_len[] = {                        2,
+    1,
+};
+const short error_defred[] = {                     0,
+    1,    0,
+};
+const short error_dgoto[] = {                      2,
+};
+const short error_sindex[] = {                  -256,
+    0,    0,
+};
+const short error_rindex[] = {                     0,
+    0,    0,
+};
+const short error_gindex[] = {                     0,
+};
+const short error_table[] = {                      1,
+};
+const short error_check[] = {                    256,
+};
+#ifndef YYDEBUG
+#define YYDEBUG 0
+#endif
+#if YYDEBUG
+const char *yyname[] = {
+
+"end-of-file",
+};
+const char *yyrule[] = {
+"$accept : S",
+"S : error",
+
+};
+#endif
diff --git a/test/code_error.tab.h b/test/code_error.tab.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/code_error.y b/test/code_error.y
new file mode 100644 (file)
index 0000000..e25ff83
--- /dev/null
@@ -0,0 +1,24 @@
+%%
+S: error
+%%
+
+#include <stdio.h>
+
+int
+main(void)
+{
+    printf("yyparse() = %d\n", yyparse());
+    return 0;
+}
+
+int
+yylex(void)
+{
+    return -1;
+}
+
+static void
+yyerror(const char* s)
+{
+    printf("%s\n", s);
+}
index c84e42b2ed3acb78c29b767dbd7bd0c507380c73..fd80e4efb60f9244e4002151f5ab0f55baee73b5 100644 (file)
@@ -2,9 +2,6 @@
 static const char yysccsid[] = "@(#)yaccpar    1.9 (Berkeley) 02/21/93";
 #endif
 
-#include <stdlib.h>
-#include <string.h>
-
 #define YYBYACC 1
 #define YYMAJOR 1
 #define YYMINOR 9
@@ -96,19 +93,36 @@ static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
 #endif /* yyrule */
 #define YYPREFIX "error_"
 
+#define YYPURE 0
+
+
+#ifndef YYSTYPE
+typedef int YYSTYPE;
+#endif
+
 /* compatibility with bison */
 #ifdef YYPARSE_PARAM
 /* compatibility with FreeBSD */
-#ifdef YYPARSE_PARAM_TYPE
-#define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
+# ifdef YYPARSE_PARAM_TYPE
+#  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
+# else
+#  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
+# endif
 #else
-#define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
+# define YYPARSE_DECL() yyparse(void)
 #endif
+
+/* Parameters sent to lex. */
+#ifdef YYLEX_PARAM
+# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
+# define YYLEX yylex(YYLEX_PARAM)
 #else
-#define YYPARSE_DECL() yyparse(void)
-#endif /* YYPARSE_PARAM */
+# define YYLEX_DECL() yylex(void)
+# define YYLEX yylex()
+#endif
 
 extern int YYPARSE_DECL();
+extern int YYLEX_DECL();
 
 #define YYERRCODE 256
 static const short error_lhs[] = {                       -1,
@@ -151,13 +165,6 @@ static const char *yyrule[] = {
 
 };
 #endif
-#ifndef YYSTYPE
-typedef int YYSTYPE;
-#endif
-#if YYDEBUG
-#include <stdio.h>
-#endif
-
 /* define the initial stack-sizes */
 #ifdef YYSTACKSIZE
 #undef YYMAXDEPTH
@@ -184,9 +191,6 @@ typedef struct {
     YYSTYPE  *l_base;
     YYSTYPE  *l_mark;
 } YYSTACKDATA;
-
-#define YYPURE 0
-
 int      yyerrflag;
 int      yychar;
 YYSTYPE  yyval;
@@ -195,10 +199,36 @@ YYSTYPE  yylval;
 /* variables for the parser stack */
 static YYSTACKDATA yystack;
 #line 4 "error.y"
-main(){printf("yyparse() = %d\n",yyparse());}
-yylex(){return-1;}
-yyerror(s)char*s;{printf("%s\n",s);}
-#line 202 "error.tab.c"
+
+#include <stdio.h>
+
+int
+main(void)
+{
+    printf("yyparse() = %d\n", yyparse());
+    return 0;
+}
+
+int
+yylex(void)
+{
+    return -1;
+}
+
+static void
+yyerror(const char* s)
+{
+    printf("%s\n", s);
+}
+#line 224 "error.tab.c"
+
+#if YYDEBUG
+#include <stdio.h>             /* needed for printf */
+#endif
+
+#include <stdlib.h>    /* needed for malloc, etc */
+#include <string.h>    /* needed for memset */
+
 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
 static int yygrowstack(YYSTACKDATA *data)
 {
@@ -221,7 +251,7 @@ static int yygrowstack(YYSTACKDATA *data)
     if (newss == 0)
         return -1;
 
-    data->s_base  = newss;
+    data->s_base = newss;
     data->s_mark = newss + i;
 
     newvs = (data->l_base != 0)
@@ -288,7 +318,7 @@ yyloop:
     if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
     if (yychar < 0)
     {
-        if ((yychar = yylex()) < 0) yychar = 0;
+        if ((yychar = YYLEX) < 0) yychar = 0;
 #if YYDEBUG
         if (yydebug)
         {
@@ -417,7 +447,7 @@ yyreduce:
         *++yystack.l_mark = yyval;
         if (yychar < 0)
         {
-            if ((yychar = yylex()) < 0) yychar = 0;
+            if ((yychar = YYLEX) < 0) yychar = 0;
 #if YYDEBUG
             if (yydebug)
             {
index 41148ea92dba0a278fd902609692a6d089bf9526..e25ff8335b4c8a75d4d53a522eca025c2371461a 100644 (file)
@@ -1,6 +1,24 @@
 %%
 S: error
 %%
-main(){printf("yyparse() = %d\n",yyparse());}
-yylex(){return-1;}
-yyerror(s)char*s;{printf("%s\n",s);}
+
+#include <stdio.h>
+
+int
+main(void)
+{
+    printf("yyparse() = %d\n", yyparse());
+    return 0;
+}
+
+int
+yylex(void)
+{
+    return -1;
+}
+
+static void
+yyerror(const char* s)
+{
+    printf("%s\n", s);
+}
index 082093377ba601a9a4af0eef92fd24f0f7c147ee..3f074366b0e376f5a0607ed234f1953bb5fe57f3 100644 (file)
@@ -2,9 +2,6 @@
 static const char yysccsid[] = "@(#)yaccpar    1.9 (Berkeley) 02/21/93";
 #endif
 
-#include <stdlib.h>
-#include <string.h>
-
 #define YYBYACC 1
 #define YYMAJOR 1
 #define YYMINOR 9
@@ -96,25 +93,11 @@ static const char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
 #endif /* yyrule */
 #define YYPREFIX "ftp_"
 
-/* compatibility with bison */
-#ifdef YYPARSE_PARAM
-/* compatibility with FreeBSD */
-#ifdef YYPARSE_PARAM_TYPE
-#define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
-#else
-#define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
-#endif
-#else
-#define YYPARSE_DECL() yyparse(void)
-#endif /* YYPARSE_PARAM */
-
-extern int YYPARSE_DECL();
+#define YYPURE 0
 
 #line 26 "ftp.y"
 
-#ifndef lint
-static char sccsid[] = "@(#)ftpcmd.y   5.20.1.1 (Berkeley) 3/2/89";
-#endif /* not lint */
+/* sccsid[] = "@(#)ftpcmd.y    5.20.1.1 (Berkeley) 3/2/89"; */
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -123,6 +106,8 @@ static char sccsid[] = "@(#)ftpcmd.y        5.20.1.1 (Berkeley) 3/2/89";
 
 #include <arpa/ftp.h>
 
+#include <stdlib.h>
+#include <unistd.h>
 #include <stdio.h>
 #include <signal.h>
 #include <ctype.h>
@@ -130,7 +115,9 @@ static char sccsid[] = "@(#)ftpcmd.y        5.20.1.1 (Berkeley) 3/2/89";
 #include <setjmp.h>
 #include <syslog.h>
 #include <sys/stat.h>
+#include <string.h>
 #include <time.h>
+#include <assert.h>
 
 extern struct sockaddr_in data_dest;
 extern int logged_in;
@@ -149,7 +136,30 @@ extern     char *globerr;
 extern int usedefault;
 extern  int transflag;
 extern  char tmpline[];
-char   **glob();
+
+extern char **glob(char *);
+extern char *renamefrom(char *);
+extern void cwd(const char *);
+extern void delete(const char *);
+extern void dologout(int);
+extern void fatal(const char *);
+extern void makedir(const char *);
+extern void nack(const char *);
+extern void pass(const char *);
+extern void passive(void);
+extern void pwd(void);
+extern void removedir(char *);
+extern void renamecmd(char *, char *);
+extern void retrieve(const char *, const char *);
+extern void send_file_list(const char *);
+extern void statcmd(void);
+extern void statfilecmd(const char *);
+extern void store(char *, const char *, int);
+extern void user(const char *);
+
+extern void perror_reply(int, const char *, ...);
+extern void reply(int, const char *, ...);
+extern void lreply(int, const char *, ...);
 
 static int cmd_type;
 static int cmd_form;
@@ -157,8 +167,45 @@ static     int cmd_bytesz;
 char   cbuf[512];
 char   *fromname;
 
-char   *index();
-#line 162 "ftp.tab.c"
+extern char *index(const char *, int);
+
+static char * copy(const char *);
+
+static void
+yyerror(const char *msg)
+{
+       perror(msg);
+}
+#line 180 "ftp.tab.c"
+
+#ifndef YYSTYPE
+typedef int YYSTYPE;
+#endif
+
+/* compatibility with bison */
+#ifdef YYPARSE_PARAM
+/* compatibility with FreeBSD */
+# ifdef YYPARSE_PARAM_TYPE
+#  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
+# else
+#  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
+# endif
+#else
+# define YYPARSE_DECL() yyparse(void)
+#endif
+
+/* Parameters sent to lex. */
+#ifdef YYLEX_PARAM
+# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
+# define YYLEX yylex(YYLEX_PARAM)
+#else
+# define YYLEX_DECL() yylex(void)
+# define YYLEX yylex()
+#endif
+
+extern int YYPARSE_DECL();
+extern int YYLEX_DECL();
+
 #define A 257
 #define B 258
 #define C 259
@@ -459,13 +506,6 @@ static const char *yyrule[] = {
 
 };
 #endif
-#ifndef YYSTYPE
-typedef int YYSTYPE;
-#endif
-#if YYDEBUG
-#include <stdio.h>
-#endif
-
 /* define the initial stack-sizes */
 #ifdef YYSTACKSIZE
 #undef YYMAXDEPTH
@@ -492,9 +532,6 @@ typedef struct {
     YYSTYPE  *l_base;
     YYSTYPE  *l_mark;
 } YYSTACKDATA;
-
-#define YYPURE 0
-
 int      yyerrflag;
 int      yychar;
 YYSTYPE  yyval;
@@ -502,10 +539,12 @@ YYSTYPE  yylval;
 
 /* variables for the parser stack */
 static YYSTACKDATA yystack;
-#line 658 "ftp.y"
+#line 688 "ftp.y"
 
 extern jmp_buf errcatch;
 
+static void upper(char *);
+
 #define        CMD     0       /* beginning of command */
 #define        ARGS    1       /* expect miscellaneous arguments */
 #define        STR1    2       /* expect SP followed by STRING */
@@ -517,11 +556,11 @@ extern jmp_buf errcatch;
 #define        NSTR    8       /* Number followed by a string */
 
 struct tab {
-       char    *name;
+       const char *name;
        short   token;
        short   state;
        short   implemented;    /* 1 if command is implemented */
-       char    *help;
+       const char *help;
 };
 
 struct tab cmdtab[] = {                /* In order defined in RFC 765 */
@@ -572,7 +611,7 @@ struct tab cmdtab[] = {             /* In order defined in RFC 765 */
        { "STOU", STOU, STR1, 1,        "<sp> file-name" },
        { "SIZE", SIZE, OSTR, 1,        "<sp> path-name" },
        { "MDTM", MDTM, OSTR, 1,        "<sp> path-name" },
-       { NULL,   0,    0,    0,        0 }
+       { 0,   0,    0,    0,   0 }
 };
 
 struct tab sitetab[] = {
@@ -580,16 +619,14 @@ struct tab sitetab[] = {
        { "IDLE", IDLE, ARGS, 1,        "[ <sp> maximum-idle-time ]" },
        { "CHMOD", CHMOD, NSTR, 1,      "<sp> mode <sp> file-name" },
        { "HELP", HELP, OSTR, 1,        "[ <sp> <string> ]" },
-       { NULL,   0,    0,    0,        0 }
+       { 0,   0,    0,    0,   0 }
 };
 
-struct tab *
-lookup(p, cmd)
-       register struct tab *p;
-       char *cmd;
+static struct tab *
+lookup(struct tab *p, char *cmd)
 {
 
-       for (; p->name != NULL; p++)
+       for (; p->name != 0; p++)
                if (strcmp(cmd, p->name) == 0)
                        return (p);
        return (0);
@@ -598,14 +635,12 @@ lookup(p, cmd)
 #include <arpa/telnet.h>
 
 /*
- * getline - a hacked up version of fgets to ignore TELNET escape codes.
+ * get_line - a hacked up version of fgets to ignore TELNET escape codes.
  */
-char *
-getline(s, n, iop)
-       char *s;
-       register FILE *iop;
+static char *
+get_line(char *s, int n, FILE *iop)
 {
-       register c;
+       register int c;
        register char *cs;
 
        cs = s;
@@ -613,7 +648,7 @@ getline(s, n, iop)
        for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
                *cs++ = tmpline[c];
                if (tmpline[c] == '\n') {
-                       *cs++ = '\0';
+                       *cs = '\0';
                        if (debug)
                                syslog(LOG_DEBUG, "command: %s", s);
                        tmpline[0] = '\0';
@@ -652,20 +687,19 @@ getline(s, n, iop)
                        break;
        }
        if (c == EOF && cs == s)
-               return (NULL);
-       *cs++ = '\0';
+               return (0);
+       *cs = '\0';
        if (debug)
                syslog(LOG_DEBUG, "command: %s", s);
        return (s);
 }
 
-static int
-toolong()
+static void
+toolong(int sig)
 {
        time_t now;
-       extern char *ctime();
-       extern time_t time();
 
+       (void) sig;
        reply(421,
          "Timeout (%d seconds): closing control connection.", timeout);
        (void) time(&now);
@@ -677,14 +711,14 @@ toolong()
        dologout(1);
 }
 
-yylex()
+int
+yylex(void)
 {
        static int cpos, state;
        register char *cp, *cp2;
        register struct tab *p;
        int n;
-       char c, *strpbrk();
-       char *copy();
+       char c;
 
        for (;;) {
                switch (state) {
@@ -692,13 +726,13 @@ yylex()
                case CMD:
                        (void) signal(SIGALRM, toolong);
                        (void) alarm((unsigned) timeout);
-                       if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
+                       if (get_line(cbuf, sizeof(cbuf)-1, stdin) == 0) {
                                reply(221, "You could at least say goodbye.");
                                dologout(0);
                        }
                        (void) alarm(0);
 #ifdef SETPROCTITLE
-                       if (strncasecmp(cbuf, "PASS", 4) != NULL)
+                       if (strncasecmp(cbuf, "PASS", 4) != 0)
                                setproctitle("%s: %s", proctitle, cbuf);
 #endif /* SETPROCTITLE */
                        if ((cp = index(cbuf, '\r'))) {
@@ -721,7 +755,7 @@ yylex()
                                        /* NOTREACHED */
                                }
                                state = p->state;
-                               *(char **)&yylval = p->name;
+                               *(const char **)(&yylval) = p->name;
                                return (p->token);
                        }
                        break;
@@ -747,7 +781,7 @@ yylex()
                                        /* NOTREACHED */
                                }
                                state = p->state;
-                               *(char **)&yylval = p->name;
+                               *(const char **)(&yylval) = p->name;
                                return (p->token);
                        }
                        state = CMD;
@@ -765,7 +799,10 @@ yylex()
                dostr1:
                        if (cbuf[cpos] == ' ') {
                                cpos++;
-                               state = state == OSTR ? STR2 : ++state;
+                               if (state == OSTR)
+                                       state = STR2;
+                               else
+                                       ++state;
                                return (SP);
                        }
                        break;
@@ -895,8 +932,8 @@ yylex()
        }
 }
 
-upper(s)
-       register char *s;
+static void
+upper(char *s)
 {
        while (*s != '\0') {
                if (islower(*s))
@@ -905,34 +942,32 @@ upper(s)
        }
 }
 
-char *
-copy(s)
-       char *s;
+static char *
+copy(const char *s)
 {
        char *p;
-       extern char *malloc(), *strcpy();
 
        p = malloc((unsigned) strlen(s) + 1);
-       if (p == NULL)
+       if (p == 0)
                fatal("Ran out of memory.");
-       (void) strcpy(p, s);
+       else
+               (void) strcpy(p, s);
        return (p);
 }
 
-help(ctab, s)
-       struct tab *ctab;
-       char *s;
+static void
+help(struct tab *ctab, char *s)
 {
        register struct tab *c;
        register int width, NCMDS;
-       char *type;
+       const char *help_type;
 
        if (ctab == sitetab)
-               type = "SITE ";
+               help_type = "SITE ";
        else
-               type = "";
+               help_type = "";
        width = 0, NCMDS = 0;
-       for (c = ctab; c->name != NULL; c++) {
+       for (c = ctab; c->name != 0; c++) {
                int len = strlen(c->name);
 
                if (len > width)
@@ -945,7 +980,7 @@ help(ctab, s)
                int columns, lines;
 
                lreply(214, "The following %scommands are recognized %s.",
-                   type, "(* =>'s unimplemented)");
+                   help_type, "(* =>'s unimplemented)");
                columns = 76 / width;
                if (columns == 0)
                        columns = 1;
@@ -954,6 +989,7 @@ help(ctab, s)
                        printf("   ");
                        for (j = 0; j < columns; j++) {
                                c = ctab + j * lines + i;
+                               assert(c->name != 0);
                                printf("%s%c", c->name,
                                        c->implemented ? ' ' : '*');
                                if (c + lines >= &ctab[NCMDS])
@@ -977,14 +1013,14 @@ help(ctab, s)
                return;
        }
        if (c->implemented)
-               reply(214, "Syntax: %s%s %s", type, c->name, c->help);
+               reply(214, "Syntax: %s%s %s", help_type, c->name, c->help);
        else
-               reply(214, "%s%-*s\t%s; unimplemented.", type, width,
+               reply(214, "%s%-*s\t%s; unimplemented.", help_type, width,
                    c->name, c->help);
 }
 
-sizecmd(filename)
-char *filename;
+static void
+sizecmd(char *filename)
 {
        switch (type) {
        case TYPE_L:
@@ -1001,7 +1037,7 @@ char *filename;
                register int c, count;
                struct stat stbuf;
                fin = fopen(filename, "r");
-               if (fin == NULL) {
+               if (fin == 0) {
                        perror_reply(550, filename);
                        return;
                }
@@ -1026,7 +1062,15 @@ char *filename;
                reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
        }
 }
-#line 1030 "ftp.tab.c"
+#line 1066 "ftp.tab.c"
+
+#if YYDEBUG
+#include <stdio.h>             /* needed for printf */
+#endif
+
+#include <stdlib.h>    /* needed for malloc, etc */
+#include <string.h>    /* needed for memset */
+
 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
 static int yygrowstack(YYSTACKDATA *data)
 {
@@ -1049,7 +1093,7 @@ static int yygrowstack(YYSTACKDATA *data)
     if (newss == 0)
         return -1;
 
-    data->s_base  = newss;
+    data->s_base = newss;
     data->s_mark = newss + i;
 
     newvs = (data->l_base != 0)
@@ -1116,7 +1160,7 @@ yyloop:
     if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
     if (yychar < 0)
     {
-        if ((yychar = yylex()) < 0) yychar = 0;
+        if ((yychar = YYLEX) < 0) yychar = 0;
 #if YYDEBUG
         if (yydebug)
         {
@@ -1229,27 +1273,27 @@ yyreduce:
     switch (yyn)
     {
 case 2:
-#line 99 "ftp.y"
+#line 132 "ftp.y"
        {
                        fromname = (char *) 0;
                }
 break;
 case 4:
-#line 106 "ftp.y"
+#line 139 "ftp.y"
        {
                        user((char *) yystack.l_mark[-1]);
                        free((char *) yystack.l_mark[-1]);
                }
 break;
 case 5:
-#line 111 "ftp.y"
+#line 144 "ftp.y"
        {
                        pass((char *) yystack.l_mark[-1]);
                        free((char *) yystack.l_mark[-1]);
                }
 break;
 case 6:
-#line 116 "ftp.y"
+#line 149 "ftp.y"
        {
                        usedefault = 0;
                        if (pdata >= 0) {
@@ -1260,13 +1304,13 @@ case 6:
                }
 break;
 case 7:
-#line 125 "ftp.y"
+#line 158 "ftp.y"
        {
                        passive();
                }
 break;
 case 8:
-#line 129 "ftp.y"
+#line 162 "ftp.y"
        {
                        switch (cmd_type) {
 
@@ -1303,7 +1347,7 @@ case 8:
                }
 break;
 case 9:
-#line 164 "ftp.y"
+#line 197 "ftp.y"
        {
                        switch (yystack.l_mark[-1]) {
 
@@ -1317,7 +1361,7 @@ case 9:
                }
 break;
 case 10:
-#line 176 "ftp.y"
+#line 209 "ftp.y"
        {
                        switch (yystack.l_mark[-1]) {
 
@@ -1331,102 +1375,102 @@ case 10:
                }
 break;
 case 11:
-#line 188 "ftp.y"
+#line 221 "ftp.y"
        {
                        reply(202, "ALLO command ignored.");
                }
 break;
 case 12:
-#line 192 "ftp.y"
+#line 225 "ftp.y"
        {
                        reply(202, "ALLO command ignored.");
                }
 break;
 case 13:
-#line 196 "ftp.y"
+#line 229 "ftp.y"
        {
-                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0)
                                retrieve((char *) 0, (char *) yystack.l_mark[-1]);
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 14:
-#line 203 "ftp.y"
+#line 236 "ftp.y"
        {
-                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0)
                                store((char *) yystack.l_mark[-1], "w", 0);
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 15:
-#line 210 "ftp.y"
+#line 243 "ftp.y"
        {
-                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0)
                                store((char *) yystack.l_mark[-1], "a", 0);
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 16:
-#line 217 "ftp.y"
+#line 250 "ftp.y"
        {
                        if (yystack.l_mark[-1])
                                send_file_list(".");
                }
 break;
 case 17:
-#line 222 "ftp.y"
+#line 255 "ftp.y"
        {
-                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != NULL
+                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0
                                send_file_list((char *) yystack.l_mark[-1]);
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 18:
-#line 229 "ftp.y"
+#line 262 "ftp.y"
        {
                        if (yystack.l_mark[-1])
                                retrieve("/bin/ls -lgA", "");
                }
 break;
 case 19:
-#line 234 "ftp.y"
+#line 267 "ftp.y"
        {
-                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0)
                                retrieve("/bin/ls -lgA %s", (char *) yystack.l_mark[-1]);
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 20:
-#line 241 "ftp.y"
+#line 274 "ftp.y"
        {
-                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0)
                                statfilecmd((char *) yystack.l_mark[-1]);
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 21:
-#line 248 "ftp.y"
+#line 281 "ftp.y"
        {
                        statcmd();
                }
 break;
 case 22:
-#line 252 "ftp.y"
+#line 285 "ftp.y"
        {
-                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0)
                                delete((char *) yystack.l_mark[-1]);
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 23:
-#line 259 "ftp.y"
+#line 292 "ftp.y"
        {
                        if (fromname) {
                                renamecmd(fromname, (char *) yystack.l_mark[-1]);
@@ -1439,35 +1483,35 @@ case 23:
                }
 break;
 case 24:
-#line 270 "ftp.y"
+#line 303 "ftp.y"
        {
                        reply(225, "ABOR command successful.");
                }
 break;
 case 25:
-#line 274 "ftp.y"
+#line 307 "ftp.y"
        {
                        if (yystack.l_mark[-1])
                                cwd(pw->pw_dir);
                }
 break;
 case 26:
-#line 279 "ftp.y"
+#line 312 "ftp.y"
        {
-                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0)
                                cwd((char *) yystack.l_mark[-1]);
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 27:
-#line 286 "ftp.y"
+#line 319 "ftp.y"
        {
                        help(cmdtab, (char *) 0);
                }
 break;
 case 28:
-#line 290 "ftp.y"
+#line 323 "ftp.y"
        {
                        register char *cp = (char *)yystack.l_mark[-1];
 
@@ -1484,57 +1528,57 @@ case 28:
                }
 break;
 case 29:
-#line 305 "ftp.y"
+#line 338 "ftp.y"
        {
                        reply(200, "NOOP command successful.");
                }
 break;
 case 30:
-#line 309 "ftp.y"
+#line 342 "ftp.y"
        {
-                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0)
                                makedir((char *) yystack.l_mark[-1]);
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 31:
-#line 316 "ftp.y"
+#line 349 "ftp.y"
        {
-                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0)
                                removedir((char *) yystack.l_mark[-1]);
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 32:
-#line 323 "ftp.y"
+#line 356 "ftp.y"
        {
                        if (yystack.l_mark[-1])
                                pwd();
                }
 break;
 case 33:
-#line 328 "ftp.y"
+#line 361 "ftp.y"
        {
                        if (yystack.l_mark[-1])
                                cwd("..");
                }
 break;
 case 34:
-#line 333 "ftp.y"
+#line 366 "ftp.y"
        {
                        help(sitetab, (char *) 0);
                }
 break;
 case 35:
-#line 337 "ftp.y"
+#line 370 "ftp.y"
        {
                        help(sitetab, (char *) yystack.l_mark[-1]);
                }
 break;
 case 36:
-#line 341 "ftp.y"
+#line 374 "ftp.y"
        {
                        int oldmask;
 
@@ -1546,7 +1590,7 @@ case 36:
                }
 break;
 case 37:
-#line 351 "ftp.y"
+#line 384 "ftp.y"
        {
                        int oldmask;
 
@@ -1563,9 +1607,9 @@ case 37:
                }
 break;
 case 38:
-#line 366 "ftp.y"
+#line 399 "ftp.y"
        {
-                       if (yystack.l_mark[-5] && (yystack.l_mark[-1] != NULL)) {
+                       if (yystack.l_mark[-5] && (yystack.l_mark[-1] != 0)) {
                                if (yystack.l_mark[-3] > 0777)
                                        reply(501,
                                "CHMOD: Mode value must be between 0 and 0777");
@@ -1574,12 +1618,12 @@ case 38:
                                else
                                        reply(200, "CHMOD command successful.");
                        }
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 39:
-#line 380 "ftp.y"
+#line 413 "ftp.y"
        {
                        reply(200,
                            "Current IDLE time limit is %d seconds; max %d",
@@ -1587,7 +1631,7 @@ case 39:
                }
 break;
 case 40:
-#line 386 "ftp.y"
+#line 419 "ftp.y"
        {
                        if (yystack.l_mark[-1] < 30 || yystack.l_mark[-1] > maxtimeout) {
                                reply(501,
@@ -1603,16 +1647,16 @@ case 40:
                }
 break;
 case 41:
-#line 400 "ftp.y"
+#line 433 "ftp.y"
        {
-                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0)
                                store((char *) yystack.l_mark[-1], "w", 1);
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 42:
-#line 407 "ftp.y"
+#line 440 "ftp.y"
        {
 #ifdef unix
 #ifdef BSD
@@ -1627,18 +1671,18 @@ case 42:
                }
 break;
 case 43:
-#line 428 "ftp.y"
+#line 461 "ftp.y"
        {
-                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0)
                                sizecmd((char *) yystack.l_mark[-1]);
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 44:
-#line 445 "ftp.y"
+#line 478 "ftp.y"
        {
-                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != NULL) {
+                       if (yystack.l_mark[-3] && yystack.l_mark[-1] != 0) {
                                struct stat stbuf;
                                if (stat((char *) yystack.l_mark[-1], &stbuf) < 0)
                                        perror_reply(550, "%s", (char *) yystack.l_mark[-1]);
@@ -1647,7 +1691,6 @@ case 44:
                                                (char *) yystack.l_mark[-1]);
                                } else {
                                        register struct tm *t;
-                                       struct tm *gmtime();
                                        t = gmtime(&stbuf.st_mtime);
                                        reply(213,
                                            "19%02d%02d%02d%02d%02d%02d",
@@ -1655,28 +1698,26 @@ case 44:
                                            t->tm_hour, t->tm_min, t->tm_sec);
                                }
                        }
-                       if (yystack.l_mark[-1] != NULL)
+                       if (yystack.l_mark[-1] != 0)
                                free((char *) yystack.l_mark[-1]);
                }
 break;
 case 45:
-#line 467 "ftp.y"
+#line 499 "ftp.y"
        {
                        reply(221, "Goodbye.");
                        dologout(0);
                }
 break;
 case 46:
-#line 472 "ftp.y"
+#line 504 "ftp.y"
        {
                        yyerrok;
                }
 break;
 case 47:
-#line 477 "ftp.y"
+#line 509 "ftp.y"
        {
-                       char *renamefrom();
-
                        if (yystack.l_mark[-3] && yystack.l_mark[-1]) {
                                fromname = renamefrom((char *) yystack.l_mark[-1]);
                                if (fromname == (char *) 0 && yystack.l_mark[-1]) {
@@ -1686,13 +1727,13 @@ case 47:
                }
 break;
 case 49:
-#line 493 "ftp.y"
+#line 523 "ftp.y"
        {
-                       *(char **)&(yyval) = "";
+                       *(const char **)(&(yyval)) = "";
                }
 break;
 case 52:
-#line 504 "ftp.y"
+#line 534 "ftp.y"
        {
                        register char *a, *p;
 
@@ -1704,116 +1745,116 @@ case 52:
                }
 break;
 case 53:
-#line 516 "ftp.y"
+#line 546 "ftp.y"
        {
                yyval = FORM_N;
        }
 break;
 case 54:
-#line 520 "ftp.y"
+#line 550 "ftp.y"
        {
                yyval = FORM_T;
        }
 break;
 case 55:
-#line 524 "ftp.y"
+#line 554 "ftp.y"
        {
                yyval = FORM_C;
        }
 break;
 case 56:
-#line 530 "ftp.y"
+#line 560 "ftp.y"
        {
                cmd_type = TYPE_A;
                cmd_form = FORM_N;
        }
 break;
 case 57:
-#line 535 "ftp.y"
+#line 565 "ftp.y"
        {
                cmd_type = TYPE_A;
                cmd_form = yystack.l_mark[0];
        }
 break;
 case 58:
-#line 540 "ftp.y"
+#line 570 "ftp.y"
        {
                cmd_type = TYPE_E;
                cmd_form = FORM_N;
        }
 break;
 case 59:
-#line 545 "ftp.y"
+#line 575 "ftp.y"
        {
                cmd_type = TYPE_E;
                cmd_form = yystack.l_mark[0];
        }
 break;
 case 60:
-#line 550 "ftp.y"
+#line 580 "ftp.y"
        {
                cmd_type = TYPE_I;
        }
 break;
 case 61:
-#line 554 "ftp.y"
+#line 584 "ftp.y"
        {
                cmd_type = TYPE_L;
                cmd_bytesz = NBBY;
        }
 break;
 case 62:
-#line 559 "ftp.y"
+#line 589 "ftp.y"
        {
                cmd_type = TYPE_L;
                cmd_bytesz = yystack.l_mark[0];
        }
 break;
 case 63:
-#line 565 "ftp.y"
+#line 595 "ftp.y"
        {
                cmd_type = TYPE_L;
                cmd_bytesz = yystack.l_mark[0];
        }
 break;
 case 64:
-#line 572 "ftp.y"
+#line 602 "ftp.y"
        {
                yyval = STRU_F;
        }
 break;
 case 65:
-#line 576 "ftp.y"
+#line 606 "ftp.y"
        {
                yyval = STRU_R;
        }
 break;
 case 66:
-#line 580 "ftp.y"
+#line 610 "ftp.y"
        {
                yyval = STRU_P;
        }
 break;
 case 67:
-#line 586 "ftp.y"
+#line 616 "ftp.y"
        {
                yyval = MODE_S;
        }
 break;
 case 68:
-#line 590 "ftp.y"
+#line 620 "ftp.y"
        {
                yyval = MODE_B;
        }
 break;
 case 69:
-#line 594 "ftp.y"
+#line 624 "ftp.y"
        {
                yyval = MODE_C;
        }
 break;
 case 70:
-#line 600 "ftp.y"
+#line 630 "ftp.y"
        {
                /*
                 * Problem: this production is used for all pathname
@@ -1822,9 +1863,9 @@ case 70:
                 */
                if (logged_in && yystack.l_mark[0] && strncmp((char *) yystack.l_mark[0], "~", 1) == 0) {
                        *(char **)&(yyval) = *glob((char *) yystack.l_mark[0]);
-                       if (globerr != NULL) {
+                       if (globerr != 0) {
                                reply(550, globerr);
-                               yyval = NULL;
+                               yyval = 0;
                        }
                        free((char *) yystack.l_mark[0]);
                } else
@@ -1832,7 +1873,7 @@ case 70:
        }
 break;
 case 72:
-#line 622 "ftp.y"
+#line 652 "ftp.y"
        {
                register int ret, dec, multby, digit;
 
@@ -1857,7 +1898,7 @@ case 72:
        }
 break;
 case 73:
-#line 647 "ftp.y"
+#line 677 "ftp.y"
        {
                if (logged_in)
                        yyval = 1;
@@ -1867,7 +1908,7 @@ case 73:
                }
        }
 break;
-#line 1871 "ftp.tab.c"
+#line 1912 "ftp.tab.c"
     }
     yystack.s_mark -= yym;
     yystate = *yystack.s_mark;
@@ -1885,7 +1926,7 @@ break;
         *++yystack.l_mark = yyval;
         if (yychar < 0)
         {
-            if ((yychar = yylex()) < 0) yychar = 0;
+            if ((yychar = YYLEX) < 0) yychar = 0;
 #if YYDEBUG
             if (yydebug)
             {
index a9ee9cd95c3e43e0141b49eb4044d318338d66a4..6ef70c26ae7ed64fa6b25935a0bd40be92b62f9e 100644 (file)
@@ -24,9 +24,7 @@
 
 %{
 
-#ifndef lint
-static char sccsid[] = "@(#)ftpcmd.y   5.20.1.1 (Berkeley) 3/2/89";
-#endif /* not lint */
+/* sccsid[] = "@(#)ftpcmd.y    5.20.1.1 (Berkeley) 3/2/89"; */
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -35,6 +33,8 @@ static char sccsid[] = "@(#)ftpcmd.y  5.20.1.1 (Berkeley) 3/2/89";
 
 #include <arpa/ftp.h>
 
+#include <stdlib.h>
+#include <unistd.h>
 #include <stdio.h>
 #include <signal.h>
 #include <ctype.h>
@@ -42,7 +42,9 @@ static char sccsid[] = "@(#)ftpcmd.y  5.20.1.1 (Berkeley) 3/2/89";
 #include <setjmp.h>
 #include <syslog.h>
 #include <sys/stat.h>
+#include <string.h>
 #include <time.h>
+#include <assert.h>
 
 extern struct sockaddr_in data_dest;
 extern int logged_in;
@@ -61,7 +63,30 @@ extern       char *globerr;
 extern int usedefault;
 extern  int transflag;
 extern  char tmpline[];
-char   **glob();
+
+extern char **glob(char *);
+extern char *renamefrom(char *);
+extern void cwd(const char *);
+extern void delete(const char *);
+extern void dologout(int);
+extern void fatal(const char *);
+extern void makedir(const char *);
+extern void nack(const char *);
+extern void pass(const char *);
+extern void passive(void);
+extern void pwd(void);
+extern void removedir(char *);
+extern void renamecmd(char *, char *);
+extern void retrieve(const char *, const char *);
+extern void send_file_list(const char *);
+extern void statcmd(void);
+extern void statfilecmd(const char *);
+extern void store(char *, const char *, int);
+extern void user(const char *);
+
+extern void perror_reply(int, const char *, ...);
+extern void reply(int, const char *, ...);
+extern void lreply(int, const char *, ...);
 
 static int cmd_type;
 static int cmd_form;
@@ -69,7 +94,15 @@ static       int cmd_bytesz;
 char   cbuf[512];
 char   *fromname;
 
-char   *index();
+extern char *index(const char *, int);
+
+static char * copy(const char *);
+
+static void
+yyerror(const char *msg)
+{
+       perror(msg);
+}
 %}
 
 %token
@@ -194,23 +227,23 @@ cmd:              USER SP username CRLF
                }
        |       RETR check_login SP pathname CRLF
                = {
-                       if ($2 && $4 != NULL)
+                       if ($2 && $4 != 0)
                                retrieve((char *) 0, (char *) $4);
-                       if ($4 != NULL)
+                       if ($4 != 0)
                                free((char *) $4);
                }
        |       STOR check_login SP pathname CRLF
                = {
-                       if ($2 && $4 != NULL)
+                       if ($2 && $4 != 0)
                                store((char *) $4, "w", 0);
-                       if ($4 != NULL)
+                       if ($4 != 0)
                                free((char *) $4);
                }
        |       APPE check_login SP pathname CRLF
                = {
-                       if ($2 && $4 != NULL)
+                       if ($2 && $4 != 0)
                                store((char *) $4, "a", 0);
-                       if ($4 != NULL)
+                       if ($4 != 0)
                                free((char *) $4);
                }
        |       NLST check_login CRLF
@@ -220,9 +253,9 @@ cmd:                USER SP username CRLF
                }
        |       NLST check_login SP STRING CRLF
                = {
-                       if ($2 && $4 != NULL
+                       if ($2 && $4 != 0
                                send_file_list((char *) $4);
-                       if ($4 != NULL)
+                       if ($4 != 0)
                                free((char *) $4);
                }
        |       LIST check_login CRLF
@@ -232,16 +265,16 @@ cmd:              USER SP username CRLF
                }
        |       LIST check_login SP pathname CRLF
                = {
-                       if ($2 && $4 != NULL)
+                       if ($2 && $4 != 0)
                                retrieve("/bin/ls -lgA %s", (char *) $4);
-                       if ($4 != NULL)
+                       if ($4 != 0)
                                free((char *) $4);
                }
        |       STAT check_login SP pathname CRLF
                = {
-                       if ($2 && $4 != NULL)
+                       if ($2 && $4 != 0)
                                statfilecmd((char *) $4);
-                       if ($4 != NULL)
+                       if ($4 != 0)
                                free((char *) $4);
                }
        |       STAT CRLF
@@ -250,9 +283,9 @@ cmd:                USER SP username CRLF
                }
        |       DELE check_login SP pathname CRLF
                = {
-                       if ($2 && $4 != NULL)
+                       if ($2 && $4 != 0)
                                delete((char *) $4);
-                       if ($4 != NULL)
+                       if ($4 != 0)
                                free((char *) $4);
                }
        |       RNTO SP pathname CRLF
@@ -277,9 +310,9 @@ cmd:                USER SP username CRLF
                }
        |       CWD check_login SP pathname CRLF
                = {
-                       if ($2 && $4 != NULL)
+                       if ($2 && $4 != 0)
                                cwd((char *) $4);
-                       if ($4 != NULL)
+                       if ($4 != 0)
                                free((char *) $4);
                }
        |       HELP CRLF
@@ -307,16 +340,16 @@ cmd:              USER SP username CRLF
                }
        |       MKD check_login SP pathname CRLF
                = {
-                       if ($2 && $4 != NULL)
+                       if ($2 && $4 != 0)
                                makedir((char *) $4);
-                       if ($4 != NULL)
+                       if ($4 != 0)
                                free((char *) $4);
                }
        |       RMD check_login SP pathname CRLF
                = {
-                       if ($2 && $4 != NULL)
+                       if ($2 && $4 != 0)
                                removedir((char *) $4);
-                       if ($4 != NULL)
+                       if ($4 != 0)
                                free((char *) $4);
                }
        |       PWD check_login CRLF
@@ -364,7 +397,7 @@ cmd:                USER SP username CRLF
                }
        |       SITE SP CHMOD check_login SP octal_number SP pathname CRLF
                = {
-                       if ($4 && ($8 != NULL)) {
+                       if ($4 && ($8 != 0)) {
                                if ($6 > 0777)
                                        reply(501,
                                "CHMOD: Mode value must be between 0 and 0777");
@@ -373,7 +406,7 @@ cmd:                USER SP username CRLF
                                else
                                        reply(200, "CHMOD command successful.");
                        }
-                       if ($8 != NULL)
+                       if ($8 != 0)
                                free((char *) $8);
                }
        |       SITE SP IDLE CRLF
@@ -398,9 +431,9 @@ cmd:                USER SP username CRLF
                }
        |       STOU check_login SP pathname CRLF
                = {
-                       if ($2 && $4 != NULL)
+                       if ($2 && $4 != 0)
                                store((char *) $4, "w", 1);
-                       if ($4 != NULL)
+                       if ($4 != 0)
                                free((char *) $4);
                }
        |       SYST CRLF
@@ -426,9 +459,9 @@ cmd:                USER SP username CRLF
                 */
        |       SIZE check_login SP pathname CRLF
                = {
-                       if ($2 && $4 != NULL)
+                       if ($2 && $4 != 0)
                                sizecmd((char *) $4);
-                       if ($4 != NULL)
+                       if ($4 != 0)
                                free((char *) $4);
                }
 
@@ -443,7 +476,7 @@ cmd:                USER SP username CRLF
                 */
        |       MDTM check_login SP pathname CRLF
                = {
-                       if ($2 && $4 != NULL) {
+                       if ($2 && $4 != 0) {
                                struct stat stbuf;
                                if (stat((char *) $4, &stbuf) < 0)
                                        perror_reply(550, "%s", (char *) $4);
@@ -452,7 +485,6 @@ cmd:                USER SP username CRLF
                                                (char *) $4);
                                } else {
                                        register struct tm *t;
-                                       struct tm *gmtime();
                                        t = gmtime(&stbuf.st_mtime);
                                        reply(213,
                                            "19%02d%02d%02d%02d%02d%02d",
@@ -460,7 +492,7 @@ cmd:                USER SP username CRLF
                                            t->tm_hour, t->tm_min, t->tm_sec);
                                }
                        }
-                       if ($4 != NULL)
+                       if ($4 != 0)
                                free((char *) $4);
                }
        |       QUIT CRLF
@@ -475,8 +507,6 @@ cmd:                USER SP username CRLF
        ;
 rcmd:          RNFR check_login SP pathname CRLF
                = {
-                       char *renamefrom();
-
                        if ($2 && $4) {
                                fromname = renamefrom((char *) $4);
                                if (fromname == (char *) 0 && $4) {
@@ -491,7 +521,7 @@ username:   STRING
 
 password:      /* empty */
                = {
-                       *(char **)&($$) = "";
+                       *(const char **)(&($$)) = "";
                }
        |       STRING
        ;
@@ -605,9 +635,9 @@ pathname:   pathstring
                 */
                if (logged_in && $1 && strncmp((char *) $1, "~", 1) == 0) {
                        *(char **)&($$) = *glob((char *) $1);
-                       if (globerr != NULL) {
+                       if (globerr != 0) {
                                reply(550, globerr);
-                               $$ = NULL;
+                               $$ = 0;
                        }
                        free((char *) $1);
                } else
@@ -658,6 +688,8 @@ check_login:        /* empty */
 
 extern jmp_buf errcatch;
 
+static void upper(char *);
+
 #define        CMD     0       /* beginning of command */
 #define        ARGS    1       /* expect miscellaneous arguments */
 #define        STR1    2       /* expect SP followed by STRING */
@@ -669,11 +701,11 @@ extern jmp_buf errcatch;
 #define        NSTR    8       /* Number followed by a string */
 
 struct tab {
-       char    *name;
+       const char *name;
        short   token;
        short   state;
        short   implemented;    /* 1 if command is implemented */
-       char    *help;
+       const char *help;
 };
 
 struct tab cmdtab[] = {                /* In order defined in RFC 765 */
@@ -724,7 +756,7 @@ struct tab cmdtab[] = {             /* In order defined in RFC 765 */
        { "STOU", STOU, STR1, 1,        "<sp> file-name" },
        { "SIZE", SIZE, OSTR, 1,        "<sp> path-name" },
        { "MDTM", MDTM, OSTR, 1,        "<sp> path-name" },
-       { NULL,   0,    0,    0,        0 }
+       { 0,   0,    0,    0,   0 }
 };
 
 struct tab sitetab[] = {
@@ -732,16 +764,14 @@ struct tab sitetab[] = {
        { "IDLE", IDLE, ARGS, 1,        "[ <sp> maximum-idle-time ]" },
        { "CHMOD", CHMOD, NSTR, 1,      "<sp> mode <sp> file-name" },
        { "HELP", HELP, OSTR, 1,        "[ <sp> <string> ]" },
-       { NULL,   0,    0,    0,        0 }
+       { 0,   0,    0,    0,   0 }
 };
 
-struct tab *
-lookup(p, cmd)
-       register struct tab *p;
-       char *cmd;
+static struct tab *
+lookup(struct tab *p, char *cmd)
 {
 
-       for (; p->name != NULL; p++)
+       for (; p->name != 0; p++)
                if (strcmp(cmd, p->name) == 0)
                        return (p);
        return (0);
@@ -750,14 +780,12 @@ lookup(p, cmd)
 #include <arpa/telnet.h>
 
 /*
- * getline - a hacked up version of fgets to ignore TELNET escape codes.
+ * get_line - a hacked up version of fgets to ignore TELNET escape codes.
  */
-char *
-getline(s, n, iop)
-       char *s;
-       register FILE *iop;
+static char *
+get_line(char *s, int n, FILE *iop)
 {
-       register c;
+       register int c;
        register char *cs;
 
        cs = s;
@@ -765,7 +793,7 @@ getline(s, n, iop)
        for (c = 0; tmpline[c] != '\0' && --n > 0; ++c) {
                *cs++ = tmpline[c];
                if (tmpline[c] == '\n') {
-                       *cs++ = '\0';
+                       *cs = '\0';
                        if (debug)
                                syslog(LOG_DEBUG, "command: %s", s);
                        tmpline[0] = '\0';
@@ -804,20 +832,19 @@ getline(s, n, iop)
                        break;
        }
        if (c == EOF && cs == s)
-               return (NULL);
-       *cs++ = '\0';
+               return (0);
+       *cs = '\0';
        if (debug)
                syslog(LOG_DEBUG, "command: %s", s);
        return (s);
 }
 
-static int
-toolong()
+static void
+toolong(int sig)
 {
        time_t now;
-       extern char *ctime();
-       extern time_t time();
 
+       (void) sig;
        reply(421,
          "Timeout (%d seconds): closing control connection.", timeout);
        (void) time(&now);
@@ -829,14 +856,14 @@ toolong()
        dologout(1);
 }
 
-yylex()
+int
+yylex(void)
 {
        static int cpos, state;
        register char *cp, *cp2;
        register struct tab *p;
        int n;
-       char c, *strpbrk();
-       char *copy();
+       char c;
 
        for (;;) {
                switch (state) {
@@ -844,13 +871,13 @@ yylex()
                case CMD:
                        (void) signal(SIGALRM, toolong);
                        (void) alarm((unsigned) timeout);
-                       if (getline(cbuf, sizeof(cbuf)-1, stdin) == NULL) {
+                       if (get_line(cbuf, sizeof(cbuf)-1, stdin) == 0) {
                                reply(221, "You could at least say goodbye.");
                                dologout(0);
                        }
                        (void) alarm(0);
 #ifdef SETPROCTITLE
-                       if (strncasecmp(cbuf, "PASS", 4) != NULL)
+                       if (strncasecmp(cbuf, "PASS", 4) != 0)
                                setproctitle("%s: %s", proctitle, cbuf);
 #endif /* SETPROCTITLE */
                        if ((cp = index(cbuf, '\r'))) {
@@ -873,7 +900,7 @@ yylex()
                                        /* NOTREACHED */
                                }
                                state = p->state;
-                               *(char **)&yylval = p->name;
+                               *(const char **)(&yylval) = p->name;
                                return (p->token);
                        }
                        break;
@@ -899,7 +926,7 @@ yylex()
                                        /* NOTREACHED */
                                }
                                state = p->state;
-                               *(char **)&yylval = p->name;
+                               *(const char **)(&yylval) = p->name;
                                return (p->token);
                        }
                        state = CMD;
@@ -917,7 +944,10 @@ yylex()
                dostr1:
                        if (cbuf[cpos] == ' ') {
                                cpos++;
-                               state = state == OSTR ? STR2 : ++state;
+                               if (state == OSTR)
+                                       state = STR2;
+                               else
+                                       ++state;
                                return (SP);
                        }
                        break;
@@ -1047,8 +1077,8 @@ yylex()
        }
 }
 
-upper(s)
-       register char *s;
+static void
+upper(char *s)
 {
        while (*s != '\0') {
                if (islower(*s))
@@ -1057,34 +1087,32 @@ upper(s)
        }
 }
 
-char *
-copy(s)
-       char *s;
+static char *
+copy(const char *s)
 {
        char *p;
-       extern char *malloc(), *strcpy();
 
        p = malloc((unsigned) strlen(s) + 1);
-       if (p == NULL)
+       if (p == 0)
                fatal("Ran out of memory.");
-       (void) strcpy(p, s);
+       else
+               (void) strcpy(p, s);
        return (p);
 }
 
-help(ctab, s)
-       struct tab *ctab;
-       char *s;
+static void
+help(struct tab *ctab, char *s)
 {
        register struct tab *c;
        register int width, NCMDS;
-       char *type;
+       const char *help_type;
 
        if (ctab == sitetab)
-               type = "SITE ";
+               help_type = "SITE ";
        else
-               type = "";
+               help_type = "";
        width = 0, NCMDS = 0;
-       for (c = ctab; c->name != NULL; c++) {
+       for (c = ctab; c->name != 0; c++) {
                int len = strlen(c->name);
 
                if (len > width)
@@ -1097,7 +1125,7 @@ help(ctab, s)
                int columns, lines;
 
                lreply(214, "The following %scommands are recognized %s.",
-                   type, "(* =>'s unimplemented)");
+                   help_type, "(* =>'s unimplemented)");
                columns = 76 / width;
                if (columns == 0)
                        columns = 1;
@@ -1106,6 +1134,7 @@ help(ctab, s)
                        printf("   ");
                        for (j = 0; j < columns; j++) {
                                c = ctab + j * lines + i;
+                               assert(c->name != 0);
                                printf("%s%c", c->name,
                                        c->implemented ? ' ' : '*');
                                if (c + lines >= &ctab[NCMDS])
@@ -1129,14 +1158,14 @@ help(ctab, s)
                return;
        }
        if (c->implemented)
-               reply(214, "Syntax: %s%s %s", type, c->name, c->help);
+               reply(214, "Syntax: %s%s %s", help_type, c->name, c->help);
        else
-               reply(214, "%s%-*s\t%s; unimplemented.", type, width,
+               reply(214, "%s%-*s\t%s; unimplemented.", help_type, width,
                    c->name, c->help);
 }
 
-sizecmd(filename)
-char *filename;
+static void
+sizecmd(char *filename)
 {
        switch (type) {
        case TYPE_L:
@@ -1153,7 +1182,7 @@ char *filename;
                register int c, count;
                struct stat stbuf;
                fin = fopen(filename, "r");
-               if (fin == NULL) {
+               if (fin == 0) {
                        perror_reply(550, filename);
                        return;
                }
index e15f3215083e54fd914ca739f328d786fb3fc093..f2d8b158f3c854b43a9986d2f77b81e7343854c2 100644 (file)
@@ -2,9 +2,6 @@
 static const char yysccsid[] = "@(#)yaccpar    1.9 (Berkeley) 02/21/93";
 #endif
 
-#include <stdlib.h>
-#include <string.h>
-
 #define YYBYACC 1
 #define YYMAJOR 1
 #define YYMINOR 9
@@ -96,26 +93,210 @@ static const char yysccsid[] = "@(#)yaccpar        1.9 (Berkeley) 02/21/93";
 #endif /* yyrule */
 #define YYPREFIX "grammar_"
 
-/* compatibility with bison */
-#ifdef YYPARSE_PARAM
-/* compatibility with FreeBSD */
-#ifdef YYPARSE_PARAM_TYPE
-#define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
-#else
-#define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
-#endif
-#else
-#define YYPARSE_DECL() yyparse(void)
-#endif /* YYPARSE_PARAM */
-
-extern int YYPARSE_DECL();
+#define YYPURE 0
 
 #line 69 "grammar.y"
 #include <stdio.h>
 #include <ctype.h>
-#include "cproto.h"
-#include "symbol.h"
-#include "semantic.h"
+#include <string.h>
+
+#define OPT_LINTLIBRARY 1
+
+#ifndef TRUE
+#define        TRUE    (1)
+#endif
+
+#ifndef FALSE
+#define        FALSE   (0)
+#endif
+
+/* #include "cproto.h" */
+#define MAX_TEXT_SIZE 1024
+
+/* Prototype styles */
+#if OPT_LINTLIBRARY
+#define PROTO_ANSI_LLIB                -2      /* form ANSI lint-library source */
+#define PROTO_LINTLIBRARY      -1      /* form lint-library source */
+#endif
+#define PROTO_NONE             0       /* do not output any prototypes */
+#define PROTO_TRADITIONAL      1       /* comment out parameters */
+#define PROTO_ABSTRACT         2       /* comment out parameter names */
+#define PROTO_ANSI             3       /* ANSI C prototype */
+
+typedef int PrototypeStyle;
+
+typedef char boolean;
+
+extern boolean types_out;
+extern PrototypeStyle proto_style;
+
+#define ansiLintLibrary() (proto_style == PROTO_ANSI_LLIB)
+#define knrLintLibrary()  (proto_style == PROTO_LINTLIBRARY)
+#define lintLibrary()     (knrLintLibrary() || ansiLintLibrary())
+
+#if OPT_LINTLIBRARY
+#define FUNC_UNKNOWN           -1      /* unspecified */
+#else
+#define FUNC_UNKNOWN           0       /* unspecified (same as FUNC_NONE) */
+#endif
+#define FUNC_NONE              0       /* not a function definition */
+#define FUNC_TRADITIONAL       1       /* traditional style */
+#define FUNC_ANSI              2       /* ANSI style */
+#define FUNC_BOTH              3       /* both styles */
+
+typedef int FuncDefStyle;
+
+/* Source file text */
+typedef struct text {
+    char text[MAX_TEXT_SIZE];  /* source text */
+    long begin;                /* offset in temporary file */
+} Text;
+
+/* Declaration specifier flags */
+#define DS_NONE        0       /* default */
+#define DS_EXTERN      1       /* contains "extern" specifier */
+#define DS_STATIC      2       /* contains "static" specifier */
+#define DS_CHAR        4       /* contains "char" type specifier */
+#define DS_SHORT       8       /* contains "short" type specifier */
+#define DS_FLOAT       16      /* contains "float" type specifier */
+#define DS_INLINE      32      /* contains "inline" specifier */
+#define DS_JUNK        64      /* we're not interested in this declaration */
+
+/* This structure stores information about a declaration specifier. */
+typedef struct decl_spec {
+    unsigned short flags;      /* flags defined above */
+    char *text;                /* source text */
+    long begin;                /* offset in temporary file */
+} DeclSpec;
+
+/* This is a list of function parameters. */
+typedef struct _ParameterList {
+    struct parameter *first;   /* pointer to first parameter in list */
+    struct parameter *last;    /* pointer to last parameter in list */  
+    long begin_comment;        /* begin offset of comment */
+    long end_comment;          /* end offset of comment */
+    char *comment;             /* comment at start of parameter list */
+} ParameterList;
+
+/* This structure stores information about a declarator. */
+typedef struct _Declarator {
+    char *name;                        /* name of variable or function */
+    char *text;                        /* source text */
+    long begin;                        /* offset in temporary file */
+    long begin_comment;                /* begin offset of comment */
+    long end_comment;                  /* end offset of comment */
+    FuncDefStyle func_def;             /* style of function definition */
+    ParameterList params;              /* function parameters */
+    boolean pointer;                   /* TRUE if it declares a pointer */
+    struct _Declarator *head;          /* head function declarator */
+    struct _Declarator *func_stack;    /* stack of function declarators */
+    struct _Declarator *next;          /* next declarator in list */
+} Declarator;
+
+/* This structure stores information about a function parameter. */
+typedef struct parameter {
+    struct parameter *next;    /* next parameter in list */
+    DeclSpec decl_spec;
+    Declarator *declarator;
+    char *comment;             /* comment following the parameter */
+} Parameter;
+
+/* This is a list of declarators. */
+typedef struct declarator_list {
+    Declarator *first;         /* pointer to first declarator in list */
+    Declarator *last;          /* pointer to last declarator in list */  
+} DeclaratorList;
+
+/* #include "symbol.h" */
+typedef struct symbol {
+    struct symbol *next;       /* next symbol in list */
+    char *name;                /* name of symbol */
+    char *value;               /* value of symbol (for defines) */
+    short flags;               /* symbol attributes */
+} Symbol;
+
+/* parser stack entry type */
+typedef union {
+    Text text;
+    DeclSpec decl_spec;
+    Parameter *parameter;
+    ParameterList param_list;
+    Declarator *declarator;
+    DeclaratorList decl_list;
+} YYSTYPE;
+
+/* The hash table length should be a prime number. */
+#define SYM_MAX_HASH 251
+
+typedef struct symbol_table {
+    Symbol *bucket[SYM_MAX_HASH];      /* hash buckets */
+} SymbolTable;
+
+extern SymbolTable *new_symbol_table   /* Create symbol table */
+       (void);
+extern void free_symbol_table          /* Destroy symbol table */
+       (SymbolTable *s);
+extern Symbol *find_symbol             /* Lookup symbol name */
+       (SymbolTable *s, const char *n);
+extern Symbol *new_symbol              /* Define new symbol */
+       (SymbolTable *s, const char *n, const char *v, int f);
+
+/* #include "semantic.h" */
+extern void new_decl_spec (DeclSpec *, const char *, long, int);
+extern void free_decl_spec (DeclSpec *);
+extern void join_decl_specs (DeclSpec *, DeclSpec *, DeclSpec *);
+extern void check_untagged (DeclSpec *);
+extern Declarator *new_declarator (const char *, const char *, long);
+extern void free_declarator (Declarator *);
+extern void new_decl_list (DeclaratorList *, Declarator *);
+extern void free_decl_list (DeclaratorList *);
+extern void add_decl_list (DeclaratorList *, DeclaratorList *, Declarator *);
+extern Parameter *new_parameter (DeclSpec *, Declarator *);
+extern void free_parameter (Parameter *);
+extern void new_param_list (ParameterList *, Parameter *);
+extern void free_param_list (ParameterList *);
+extern void add_param_list (ParameterList *, ParameterList *, Parameter *);
+extern void new_ident_list (ParameterList *);
+extern void add_ident_list (ParameterList *, ParameterList *, const char *);
+extern void set_param_types (ParameterList *, DeclSpec *, DeclaratorList *);
+extern void gen_declarations (DeclSpec *, DeclaratorList *);
+extern void gen_prototype (DeclSpec *, Declarator *);
+extern void gen_func_declarator (Declarator *);
+extern void gen_func_definition (DeclSpec *, Declarator *);
+
+extern void init_parser     (void);
+extern void process_file    (FILE *infile, char *name);
+extern char *cur_text       (void);
+extern char *cur_file_name  (void);
+extern char *implied_typedef (void);
+extern void include_file    (char *name, int convert);
+extern char *supply_parm    (int count);
+extern char *xstrdup        (const char *);
+extern int already_declared (char *name);
+extern int is_actual_func   (Declarator *d);
+extern int lint_ellipsis    (Parameter *p);
+extern int want_typedef     (void);
+extern void begin_tracking  (void);
+extern void begin_typedef   (void);
+extern void copy_typedef    (char *s);
+extern void ellipsis_varargs (Declarator *d);
+extern void end_typedef     (void);
+extern void flush_varargs   (void);
+extern void fmt_library     (int code);
+extern void imply_typedef   (const char *s);
+extern void indent          (FILE *outf);
+extern void put_blankline   (FILE *outf);
+extern void put_body        (FILE *outf, DeclSpec *decl_spec, Declarator *declarator);
+extern void put_char        (FILE *outf, int c);
+extern void put_error       (void);
+extern void put_newline     (FILE *outf);
+extern void put_padded      (FILE *outf, const char *s);
+extern void put_string      (FILE *outf, const char *s);
+extern void track_in        (void);
+
+extern boolean file_comments;
+extern FuncDefStyle func_style;
+extern char base_file[];
 
 #define YYMAXDEPTH 150
 
@@ -165,29 +346,21 @@ typedef struct {
 
 static IncludeStack *cur_file; /* current input file */
 
-#include "yyerror.c"
+/* #include "yyerror.c" */
 
 static int haveAnsiParam (void);
 
 
 /* Flags to enable us to find if a procedure returns a value.
  */
-static int return_val, /* nonzero on BRACES iff return-expression found */
-          returned_at; /* marker for token-number to set 'return_val' */
+static int return_val; /* nonzero on BRACES iff return-expression found */
 
-#if OPT_LINTLIBRARY
-static char *dft_decl_spec (void);
-
-static char *
+static const char *
 dft_decl_spec (void)
 {
     return (lintLibrary() && !return_val) ? "void" : "int";
 }
 
-#else
-#define dft_decl_spec() "int"
-#endif
-
 static int
 haveAnsiParam (void)
 {
@@ -201,7 +374,31 @@ haveAnsiParam (void)
     }
     return FALSE;
 }
-#line 205 "grammar.tab.c"
+#line 378 "grammar.tab.c"
+/* compatibility with bison */
+#ifdef YYPARSE_PARAM
+/* compatibility with FreeBSD */
+# ifdef YYPARSE_PARAM_TYPE
+#  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
+# else
+#  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
+# endif
+#else
+# define YYPARSE_DECL() yyparse(void)
+#endif
+
+/* Parameters sent to lex. */
+#ifdef YYLEX_PARAM
+# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
+# define YYLEX yylex(YYLEX_PARAM)
+#else
+# define YYLEX_DECL() yylex(void)
+# define YYLEX yylex()
+#endif
+
+extern int YYPARSE_DECL();
+extern int YYLEX_DECL();
+
 #define T_IDENTIFIER 257
 #define T_TYPEDEF_NAME 258
 #define T_DEFINE_NAME 259
@@ -663,10 +860,6 @@ static const char *yyrule[] = {
 
 };
 #endif
-#if YYDEBUG
-#include <stdio.h>
-#endif
-
 /* define the initial stack-sizes */
 #ifdef YYSTACKSIZE
 #undef YYMAXDEPTH
@@ -693,9 +886,6 @@ typedef struct {
     YYSTYPE  *l_base;
     YYSTYPE  *l_mark;
 } YYSTACKDATA;
-
-#define YYPURE 0
-
 int      yyerrflag;
 int      yychar;
 YYSTYPE  yyval;
@@ -703,20 +893,32 @@ YYSTYPE  yylval;
 
 /* variables for the parser stack */
 static YYSTACKDATA yystack;
-#line 816 "grammar.y"
+#line 1004 "grammar.y"
 
-#if defined(__EMX__) || defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(vms)
-# ifdef USE_flex
-#  include "lexyy.c"
-# else
-#  include "lex_yy.c"
-# endif
-#else
-# include "lex.yy.c"
-#endif
+/* lex.yy.c */
+#define BEGIN yy_start = 1 + 2 *
+
+#define CPP1 1
+#define INIT1 2
+#define INIT2 3
+#define CURLY 4
+#define LEXYACC 5
+#define ASM 6
+#define CPP_INLINE 7
+
+extern char *yytext;
+extern FILE *yyin, *yyout;
+
+static int curly;                      /* number of curly brace nesting levels */
+static int ly_count;                   /* number of occurances of %% */
+static int inc_depth;                  /* include nesting level */
+static SymbolTable *included_files;    /* files already included */
+static int yy_start = 0;               /* start state number */
+
+#define grammar_error(s) yaccError(s)
 
 static void
-yaccError (char *msg)
+yaccError (const char *msg)
 {
     func_params = NULL;
     put_error();               /* tell what line we're on, and what file */
@@ -729,7 +931,7 @@ yaccError (char *msg)
 void
 init_parser (void)
 {
-    static char *keywords[] = {
+    static const char *keywords[] = {
        "const",
        "restrict",
        "volatile",
@@ -862,7 +1064,15 @@ free_parser(void)
 #endif
 }
 #endif
-#line 866 "grammar.tab.c"
+#line 1068 "grammar.tab.c"
+
+#if YYDEBUG
+#include <stdio.h>             /* needed for printf */
+#endif
+
+#include <stdlib.h>    /* needed for malloc, etc */
+#include <string.h>    /* needed for memset */
+
 /* allocate initial stack or double stack size, up to YYMAXDEPTH */
 static int yygrowstack(YYSTACKDATA *data)
 {
@@ -885,7 +1095,7 @@ static int yygrowstack(YYSTACKDATA *data)
     if (newss == 0)
         return -1;
 
-    data->s_base  = newss;
+    data->s_base = newss;
     data->s_mark = newss + i;
 
     newvs = (data->l_base != 0)
@@ -952,7 +1162,7 @@ yyloop:
     if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
     if (yychar < 0)
     {
-        if ((yychar = yylex()) < 0) yychar = 0;
+        if ((yychar = YYLEX) < 0) yychar = 0;
 #if YYDEBUG
         if (yydebug)
         {
@@ -1065,19 +1275,19 @@ yyreduce:
     switch (yyn)
     {
 case 10:
-#line 179 "grammar.y"
+#line 367 "grammar.y"
        {
            yyerrok;
        }
 break;
 case 11:
-#line 183 "grammar.y"
+#line 371 "grammar.y"
        {
            yyerrok;
        }
 break;
 case 13:
-#line 194 "grammar.y"
+#line 382 "grammar.y"
        {
            /* Provide an empty action here so bison will not complain about
             * incompatible types in the default action it normally would
@@ -1086,13 +1296,13 @@ case 13:
        }
 break;
 case 14:
-#line 201 "grammar.y"
+#line 389 "grammar.y"
        {
            /* empty */
        }
 break;
 case 15:
-#line 208 "grammar.y"
+#line 396 "grammar.y"
        {
 #if OPT_LINTLIBRARY
            if (types_out && want_typedef()) {
@@ -1105,7 +1315,7 @@ case 15:
        }
 break;
 case 16:
-#line 219 "grammar.y"
+#line 407 "grammar.y"
        {
            if (func_params != NULL) {
                set_param_types(func_params, &yystack.l_mark[-2].decl_spec, &yystack.l_mark[-1].decl_list);
@@ -1121,32 +1331,32 @@ case 16:
        }
 break;
 case 17:
-#line 233 "grammar.y"
+#line 421 "grammar.y"
        {
            cur_decl_spec_flags = yystack.l_mark[0].decl_spec.flags;
            free_decl_spec(&yystack.l_mark[0].decl_spec);
        }
 break;
 case 18:
-#line 238 "grammar.y"
+#line 426 "grammar.y"
        {
            end_typedef();
        }
 break;
 case 19:
-#line 245 "grammar.y"
+#line 433 "grammar.y"
        {
            begin_typedef();
        }
 break;
 case 20:
-#line 249 "grammar.y"
+#line 437 "grammar.y"
        {
            begin_typedef();
        }
 break;
 case 23:
-#line 261 "grammar.y"
+#line 449 "grammar.y"
        {
            int flags = cur_decl_spec_flags;
 
@@ -1160,7 +1370,7 @@ case 23:
        }
 break;
 case 24:
-#line 273 "grammar.y"
+#line 461 "grammar.y"
        {
            int flags = cur_decl_spec_flags;
 
@@ -1171,7 +1381,7 @@ case 24:
        }
 break;
 case 25:
-#line 285 "grammar.y"
+#line 473 "grammar.y"
        {
            check_untagged(&yystack.l_mark[-1].decl_spec);
            if (yystack.l_mark[0].declarator->func_def == FUNC_NONE) {
@@ -1184,7 +1394,7 @@ case 25:
        }
 break;
 case 26:
-#line 296 "grammar.y"
+#line 484 "grammar.y"
        {
            /* If we're converting to K&R and we've got a nominally K&R
             * function which has a parameter which is ANSI (i.e., a prototyped
@@ -1210,7 +1420,7 @@ case 26:
        }
 break;
 case 28:
-#line 321 "grammar.y"
+#line 509 "grammar.y"
        {
            if (yystack.l_mark[0].declarator->func_def == FUNC_NONE) {
                yyerror("syntax error");
@@ -1222,7 +1432,7 @@ case 28:
        }
 break;
 case 29:
-#line 331 "grammar.y"
+#line 519 "grammar.y"
        {
            DeclSpec decl_spec;
 
@@ -1240,7 +1450,7 @@ case 29:
        }
 break;
 case 36:
-#line 362 "grammar.y"
+#line 550 "grammar.y"
        {
            join_decl_specs(&yyval.decl_spec, &yystack.l_mark[-1].decl_spec, &yystack.l_mark[0].decl_spec);
            free(yystack.l_mark[-1].decl_spec.text);
@@ -1248,115 +1458,115 @@ case 36:
        }
 break;
 case 40:
-#line 377 "grammar.y"
+#line 565 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE);
        }
 break;
 case 41:
-#line 381 "grammar.y"
+#line 569 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_EXTERN);
        }
 break;
 case 42:
-#line 385 "grammar.y"
+#line 573 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE);
        }
 break;
 case 43:
-#line 389 "grammar.y"
+#line 577 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_STATIC);
        }
 break;
 case 44:
-#line 393 "grammar.y"
+#line 581 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_INLINE);
        }
 break;
 case 45:
-#line 397 "grammar.y"
+#line 585 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_JUNK);
        }
 break;
 case 46:
-#line 404 "grammar.y"
+#line 592 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_CHAR);
        }
 break;
 case 47:
-#line 408 "grammar.y"
+#line 596 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE);
        }
 break;
 case 48:
-#line 412 "grammar.y"
+#line 600 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_FLOAT);
        }
 break;
 case 49:
-#line 416 "grammar.y"
+#line 604 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE);
        }
 break;
 case 50:
-#line 420 "grammar.y"
+#line 608 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE);
        }
 break;
 case 51:
-#line 424 "grammar.y"
+#line 612 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_SHORT);
        }
 break;
 case 52:
-#line 428 "grammar.y"
+#line 616 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE);
        }
 break;
 case 53:
-#line 432 "grammar.y"
+#line 620 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE);
        }
 break;
 case 54:
-#line 436 "grammar.y"
+#line 624 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE);
        }
 break;
 case 55:
-#line 440 "grammar.y"
+#line 628 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_CHAR);
        }
 break;
 case 56:
-#line 444 "grammar.y"
+#line 632 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE);
        }
 break;
 case 57:
-#line 448 "grammar.y"
+#line 636 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE);
        }
 break;
 case 58:
-#line 452 "grammar.y"
+#line 640 "grammar.y"
        {
            Symbol *s;
            s = find_symbol(typedef_names, yystack.l_mark[0].text.text);
@@ -1365,13 +1575,13 @@ case 58:
        }
 break;
 case 61:
-#line 464 "grammar.y"
+#line 652 "grammar.y"
        {
            new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE);
        }
 break;
 case 62:
-#line 468 "grammar.y"
+#line 656 "grammar.y"
        {
            /* This rule allows the <pointer> nonterminal to scan #define
             * names as if they were type modifiers.
@@ -1383,7 +1593,7 @@ case 62:
        }
 break;
 case 63:
-#line 481 "grammar.y"
+#line 669 "grammar.y"
        {
            char *s;
            if ((s = implied_typedef()) == 0)
@@ -1392,7 +1602,7 @@ case 63:
        }
 break;
 case 64:
-#line 488 "grammar.y"
+#line 676 "grammar.y"
        {
            char *s;
            if ((s = implied_typedef()) == 0)
@@ -1401,38 +1611,38 @@ case 64:
        }
 break;
 case 65:
-#line 495 "grammar.y"
+#line 683 "grammar.y"
        {
            (void)sprintf(buf, "%s %s", yystack.l_mark[-1].text.text, yystack.l_mark[0].text.text);
            new_decl_spec(&yyval.decl_spec, buf, yystack.l_mark[-1].text.begin, DS_NONE);
        }
 break;
 case 66:
-#line 503 "grammar.y"
+#line 691 "grammar.y"
        {
            imply_typedef(yyval.text.text);
        }
 break;
 case 67:
-#line 507 "grammar.y"
+#line 695 "grammar.y"
        {
            imply_typedef(yyval.text.text);
        }
 break;
 case 68:
-#line 514 "grammar.y"
+#line 702 "grammar.y"
        {
            new_decl_list(&yyval.decl_list, yystack.l_mark[0].declarator);
        }
 break;
 case 69:
-#line 518 "grammar.y"
+#line 706 "grammar.y"
        {
            add_decl_list(&yyval.decl_list, &yystack.l_mark[-2].decl_list, yystack.l_mark[0].declarator);
        }
 break;
 case 70:
-#line 525 "grammar.y"
+#line 713 "grammar.y"
        {
            if (yystack.l_mark[0].declarator->func_def != FUNC_NONE && func_params == NULL &&
                func_style == FUNC_TRADITIONAL && cur_file->convert) {
@@ -1443,7 +1653,7 @@ case 70:
        }
 break;
 case 71:
-#line 534 "grammar.y"
+#line 722 "grammar.y"
        {
            if (yystack.l_mark[-1].declarator->func_def != FUNC_NONE && func_params == NULL &&
                func_style == FUNC_TRADITIONAL && cur_file->convert) {
@@ -1453,7 +1663,7 @@ case 71:
        }
 break;
 case 73:
-#line 546 "grammar.y"
+#line 734 "grammar.y"
        {
            char *s;
            if ((s = implied_typedef()) == 0)
@@ -1462,7 +1672,7 @@ case 73:
        }
 break;
 case 74:
-#line 553 "grammar.y"
+#line 741 "grammar.y"
        {
            char *s;
            if ((s = implied_typedef()) == 0)
@@ -1471,21 +1681,21 @@ case 74:
        }
 break;
 case 75:
-#line 560 "grammar.y"
+#line 748 "grammar.y"
        {
            (void)sprintf(buf, "enum %s", yystack.l_mark[0].text.text);
            new_decl_spec(&yyval.decl_spec, buf, yystack.l_mark[-1].text.begin, DS_NONE);
        }
 break;
 case 76:
-#line 568 "grammar.y"
+#line 756 "grammar.y"
        {
            imply_typedef("enum");
            yyval.text = yystack.l_mark[0].text;
        }
 break;
 case 79:
-#line 581 "grammar.y"
+#line 769 "grammar.y"
        {
            yyval.declarator = yystack.l_mark[0].declarator;
            (void)sprintf(buf, "%s%s", yystack.l_mark[-1].text.text, yyval.declarator->text);
@@ -1496,13 +1706,13 @@ case 79:
        }
 break;
 case 81:
-#line 594 "grammar.y"
+#line 782 "grammar.y"
        {
            yyval.declarator = new_declarator(yystack.l_mark[0].text.text, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin);
        }
 break;
 case 82:
-#line 598 "grammar.y"
+#line 786 "grammar.y"
        {
            yyval.declarator = yystack.l_mark[-1].declarator;
            (void)sprintf(buf, "(%s)", yyval.declarator->text);
@@ -1512,7 +1722,7 @@ case 82:
        }
 break;
 case 83:
-#line 606 "grammar.y"
+#line 794 "grammar.y"
        {
            yyval.declarator = yystack.l_mark[-1].declarator;
            (void)sprintf(buf, "%s%s", yyval.declarator->text, yystack.l_mark[0].text.text);
@@ -1521,7 +1731,7 @@ case 83:
        }
 break;
 case 84:
-#line 613 "grammar.y"
+#line 801 "grammar.y"
        {
            yyval.declarator = new_declarator("%s()", yystack.l_mark[-3].declarator->name, yystack.l_mark[-3].declarator->begin);
            yyval.declarator->params = yystack.l_mark[-1].param_list;
@@ -1531,7 +1741,7 @@ case 84:
        }
 break;
 case 85:
-#line 621 "grammar.y"
+#line 809 "grammar.y"
        {
            yyval.declarator = new_declarator("%s()", yystack.l_mark[-3].declarator->name, yystack.l_mark[-3].declarator->begin);
            yyval.declarator->params = yystack.l_mark[-1].param_list;
@@ -1541,28 +1751,28 @@ case 85:
        }
 break;
 case 86:
-#line 632 "grammar.y"
+#line 820 "grammar.y"
        {
            (void)sprintf(yyval.text.text, "*%s", yystack.l_mark[0].text.text);
            yyval.text.begin = yystack.l_mark[-1].text.begin;
        }
 break;
 case 87:
-#line 637 "grammar.y"
+#line 825 "grammar.y"
        {
            (void)sprintf(yyval.text.text, "*%s%s", yystack.l_mark[-1].text.text, yystack.l_mark[0].text.text);
            yyval.text.begin = yystack.l_mark[-2].text.begin;
        }
 break;
 case 88:
-#line 645 "grammar.y"
+#line 833 "grammar.y"
        {
            strcpy(yyval.text.text, "");
            yyval.text.begin = 0L;
        }
 break;
 case 90:
-#line 654 "grammar.y"
+#line 842 "grammar.y"
        {
            (void)sprintf(yyval.text.text, "%s ", yystack.l_mark[0].decl_spec.text);
            yyval.text.begin = yystack.l_mark[0].decl_spec.begin;
@@ -1570,7 +1780,7 @@ case 90:
        }
 break;
 case 91:
-#line 660 "grammar.y"
+#line 848 "grammar.y"
        {
            (void)sprintf(yyval.text.text, "%s%s ", yystack.l_mark[-1].text.text, yystack.l_mark[0].decl_spec.text);
            yyval.text.begin = yystack.l_mark[-1].text.begin;
@@ -1578,71 +1788,71 @@ case 91:
        }
 break;
 case 93:
-#line 670 "grammar.y"
+#line 858 "grammar.y"
        {
            add_ident_list(&yyval.param_list, &yystack.l_mark[-2].param_list, "...");
        }
 break;
 case 94:
-#line 677 "grammar.y"
+#line 865 "grammar.y"
        {
            new_param_list(&yyval.param_list, yystack.l_mark[0].parameter);
        }
 break;
 case 95:
-#line 681 "grammar.y"
+#line 869 "grammar.y"
        {
            add_param_list(&yyval.param_list, &yystack.l_mark[-2].param_list, yystack.l_mark[0].parameter);
        }
 break;
 case 96:
-#line 688 "grammar.y"
+#line 876 "grammar.y"
        {
            check_untagged(&yystack.l_mark[-1].decl_spec);
            yyval.parameter = new_parameter(&yystack.l_mark[-1].decl_spec, yystack.l_mark[0].declarator);
        }
 break;
 case 97:
-#line 693 "grammar.y"
+#line 881 "grammar.y"
        {
            check_untagged(&yystack.l_mark[-1].decl_spec);
            yyval.parameter = new_parameter(&yystack.l_mark[-1].decl_spec, yystack.l_mark[0].declarator);
        }
 break;
 case 98:
-#line 698 "grammar.y"
+#line 886 "grammar.y"
        {
            check_untagged(&yystack.l_mark[0].decl_spec);
            yyval.parameter = new_parameter(&yystack.l_mark[0].decl_spec, (Declarator *)0);
        }
 break;
 case 99:
-#line 706 "grammar.y"
+#line 894 "grammar.y"
        {
            new_ident_list(&yyval.param_list);
        }
 break;
 case 101:
-#line 714 "grammar.y"
+#line 902 "grammar.y"
        {
            new_ident_list(&yyval.param_list);
            add_ident_list(&yyval.param_list, &yyval.param_list, yystack.l_mark[0].text.text);
        }
 break;
 case 102:
-#line 719 "grammar.y"
+#line 907 "grammar.y"
        {
            add_ident_list(&yyval.param_list, &yystack.l_mark[-2].param_list, yystack.l_mark[0].text.text);
        }
 break;
 case 103:
-#line 726 "grammar.y"
+#line 914 "grammar.y"
        {
            yyval.text = yystack.l_mark[0].text;
        }
 break;
 case 104:
-#line 730 "grammar.y"
+#line 918 "grammar.y"
        {
 #if OPT_LINTLIBRARY
            if (lintLibrary()) { /* Lint doesn't grok C++ ref variables */
@@ -1654,13 +1864,13 @@ case 104:
        }
 break;
 case 105:
-#line 743 "grammar.y"
+#line 931 "grammar.y"
        {
            yyval.declarator = new_declarator(yystack.l_mark[0].text.text, "", yystack.l_mark[0].text.begin);
        }
 break;
 case 106:
-#line 747 "grammar.y"
+#line 935 "grammar.y"
        {
            yyval.declarator = yystack.l_mark[0].declarator;
            (void)sprintf(buf, "%s%s", yystack.l_mark[-1].text.text, yyval.declarator->text);
@@ -1670,7 +1880,7 @@ case 106:
        }
 break;
 case 108:
-#line 759 "grammar.y"
+#line 947 "grammar.y"
        {
            yyval.declarator = yystack.l_mark[-1].declarator;
            (void)sprintf(buf, "(%s)", yyval.declarator->text);
@@ -1680,7 +1890,7 @@ case 108:
        }
 break;
 case 109:
-#line 767 "grammar.y"
+#line 955 "grammar.y"
        {
            yyval.declarator = yystack.l_mark[-1].declarator;
            (void)sprintf(buf, "%s%s", yyval.declarator->text, yystack.l_mark[0].text.text);
@@ -1689,13 +1899,13 @@ case 109:
        }
 break;
 case 110:
-#line 774 "grammar.y"
+#line 962 "grammar.y"
        {
            yyval.declarator = new_declarator(yystack.l_mark[0].text.text, "", yystack.l_mark[0].text.begin);
        }
 break;
 case 111:
-#line 778 "grammar.y"
+#line 966 "grammar.y"
        {
            yyval.declarator = new_declarator("%s()", "", yystack.l_mark[-3].declarator->begin);
            yyval.declarator->params = yystack.l_mark[-1].param_list;
@@ -1705,7 +1915,7 @@ case 111:
        }
 break;
 case 112:
-#line 786 "grammar.y"
+#line 974 "grammar.y"
        {
            yyval.declarator = new_declarator("%s()", "", yystack.l_mark[-2].declarator->begin);
            yyval.declarator->func_stack = yystack.l_mark[-2].declarator;
@@ -1714,7 +1924,7 @@ case 112:
        }
 break;
 case 113:
-#line 793 "grammar.y"
+#line 981 "grammar.y"
        {
            Declarator *d;
 
@@ -1727,7 +1937,7 @@ case 113:
        }
 break;
 case 114:
-#line 804 "grammar.y"
+#line 992 "grammar.y"
        {
            Declarator *d;
 
@@ -1738,7 +1948,7 @@ case 114:
            yyval.declarator->func_def = FUNC_ANSI;
        }
 break;
-#line 1742 "grammar.tab.c"
+#line 1952 "grammar.tab.c"
     }
     yystack.s_mark -= yym;
     yystate = *yystack.s_mark;
@@ -1756,7 +1966,7 @@ break;
         *++yystack.l_mark = yyval;
         if (yychar < 0)
         {
-            if ((yychar = yylex()) < 0) yychar = 0;
+            if ((yychar = YYLEX) < 0) yychar = 0;
 #if YYDEBUG
             if (yydebug)
             {
index 606bb81f9420c6719597983795556a8554532da1..d28f6b8b7901c0c9b39d3ca903b70fd5a2ef70af 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: grammar.y,v 1.1 2004/03/24 21:29:23 tom Exp $
+/* $Id: grammar.y,v 1.2 2010/06/08 22:31:28 tom Exp $
  *
  * yacc grammar for C function prototype generator
  * This was derived from the grammar in Appendix A of
 %{
 #include <stdio.h>
 #include <ctype.h>
-#include "cproto.h"
-#include "symbol.h"
-#include "semantic.h"
+#include <string.h>
+
+#define OPT_LINTLIBRARY 1
+
+#ifndef TRUE
+#define        TRUE    (1)
+#endif
+
+#ifndef FALSE
+#define        FALSE   (0)
+#endif
+
+/* #include "cproto.h" */
+#define MAX_TEXT_SIZE 1024
+
+/* Prototype styles */
+#if OPT_LINTLIBRARY
+#define PROTO_ANSI_LLIB                -2      /* form ANSI lint-library source */
+#define PROTO_LINTLIBRARY      -1      /* form lint-library source */
+#endif
+#define PROTO_NONE             0       /* do not output any prototypes */
+#define PROTO_TRADITIONAL      1       /* comment out parameters */
+#define PROTO_ABSTRACT         2       /* comment out parameter names */
+#define PROTO_ANSI             3       /* ANSI C prototype */
+
+typedef int PrototypeStyle;
+
+typedef char boolean;
+
+extern boolean types_out;
+extern PrototypeStyle proto_style;
+
+#define ansiLintLibrary() (proto_style == PROTO_ANSI_LLIB)
+#define knrLintLibrary()  (proto_style == PROTO_LINTLIBRARY)
+#define lintLibrary()     (knrLintLibrary() || ansiLintLibrary())
+
+#if OPT_LINTLIBRARY
+#define FUNC_UNKNOWN           -1      /* unspecified */
+#else
+#define FUNC_UNKNOWN           0       /* unspecified (same as FUNC_NONE) */
+#endif
+#define FUNC_NONE              0       /* not a function definition */
+#define FUNC_TRADITIONAL       1       /* traditional style */
+#define FUNC_ANSI              2       /* ANSI style */
+#define FUNC_BOTH              3       /* both styles */
+
+typedef int FuncDefStyle;
+
+/* Source file text */
+typedef struct text {
+    char text[MAX_TEXT_SIZE];  /* source text */
+    long begin;                /* offset in temporary file */
+} Text;
+
+/* Declaration specifier flags */
+#define DS_NONE        0       /* default */
+#define DS_EXTERN      1       /* contains "extern" specifier */
+#define DS_STATIC      2       /* contains "static" specifier */
+#define DS_CHAR        4       /* contains "char" type specifier */
+#define DS_SHORT       8       /* contains "short" type specifier */
+#define DS_FLOAT       16      /* contains "float" type specifier */
+#define DS_INLINE      32      /* contains "inline" specifier */
+#define DS_JUNK        64      /* we're not interested in this declaration */
+
+/* This structure stores information about a declaration specifier. */
+typedef struct decl_spec {
+    unsigned short flags;      /* flags defined above */
+    char *text;                /* source text */
+    long begin;                /* offset in temporary file */
+} DeclSpec;
+
+/* This is a list of function parameters. */
+typedef struct _ParameterList {
+    struct parameter *first;   /* pointer to first parameter in list */
+    struct parameter *last;    /* pointer to last parameter in list */  
+    long begin_comment;        /* begin offset of comment */
+    long end_comment;          /* end offset of comment */
+    char *comment;             /* comment at start of parameter list */
+} ParameterList;
+
+/* This structure stores information about a declarator. */
+typedef struct _Declarator {
+    char *name;                        /* name of variable or function */
+    char *text;                        /* source text */
+    long begin;                        /* offset in temporary file */
+    long begin_comment;                /* begin offset of comment */
+    long end_comment;                  /* end offset of comment */
+    FuncDefStyle func_def;             /* style of function definition */
+    ParameterList params;              /* function parameters */
+    boolean pointer;                   /* TRUE if it declares a pointer */
+    struct _Declarator *head;          /* head function declarator */
+    struct _Declarator *func_stack;    /* stack of function declarators */
+    struct _Declarator *next;          /* next declarator in list */
+} Declarator;
+
+/* This structure stores information about a function parameter. */
+typedef struct parameter {
+    struct parameter *next;    /* next parameter in list */
+    DeclSpec decl_spec;
+    Declarator *declarator;
+    char *comment;             /* comment following the parameter */
+} Parameter;
+
+/* This is a list of declarators. */
+typedef struct declarator_list {
+    Declarator *first;         /* pointer to first declarator in list */
+    Declarator *last;          /* pointer to last declarator in list */  
+} DeclaratorList;
+
+/* #include "symbol.h" */
+typedef struct symbol {
+    struct symbol *next;       /* next symbol in list */
+    char *name;                /* name of symbol */
+    char *value;               /* value of symbol (for defines) */
+    short flags;               /* symbol attributes */
+} Symbol;
+
+/* parser stack entry type */
+typedef union {
+    Text text;
+    DeclSpec decl_spec;
+    Parameter *parameter;
+    ParameterList param_list;
+    Declarator *declarator;
+    DeclaratorList decl_list;
+} YYSTYPE;
+
+/* The hash table length should be a prime number. */
+#define SYM_MAX_HASH 251
+
+typedef struct symbol_table {
+    Symbol *bucket[SYM_MAX_HASH];      /* hash buckets */
+} SymbolTable;
+
+extern SymbolTable *new_symbol_table   /* Create symbol table */
+       (void);
+extern void free_symbol_table          /* Destroy symbol table */
+       (SymbolTable *s);
+extern Symbol *find_symbol             /* Lookup symbol name */
+       (SymbolTable *s, const char *n);
+extern Symbol *new_symbol              /* Define new symbol */
+       (SymbolTable *s, const char *n, const char *v, int f);
+
+/* #include "semantic.h" */
+extern void new_decl_spec (DeclSpec *, const char *, long, int);
+extern void free_decl_spec (DeclSpec *);
+extern void join_decl_specs (DeclSpec *, DeclSpec *, DeclSpec *);
+extern void check_untagged (DeclSpec *);
+extern Declarator *new_declarator (const char *, const char *, long);
+extern void free_declarator (Declarator *);
+extern void new_decl_list (DeclaratorList *, Declarator *);
+extern void free_decl_list (DeclaratorList *);
+extern void add_decl_list (DeclaratorList *, DeclaratorList *, Declarator *);
+extern Parameter *new_parameter (DeclSpec *, Declarator *);
+extern void free_parameter (Parameter *);
+extern void new_param_list (ParameterList *, Parameter *);
+extern void free_param_list (ParameterList *);
+extern void add_param_list (ParameterList *, ParameterList *, Parameter *);
+extern void new_ident_list (ParameterList *);
+extern void add_ident_list (ParameterList *, ParameterList *, const char *);
+extern void set_param_types (ParameterList *, DeclSpec *, DeclaratorList *);
+extern void gen_declarations (DeclSpec *, DeclaratorList *);
+extern void gen_prototype (DeclSpec *, Declarator *);
+extern void gen_func_declarator (Declarator *);
+extern void gen_func_definition (DeclSpec *, Declarator *);
+
+extern void init_parser     (void);
+extern void process_file    (FILE *infile, char *name);
+extern char *cur_text       (void);
+extern char *cur_file_name  (void);
+extern char *implied_typedef (void);
+extern void include_file    (char *name, int convert);
+extern char *supply_parm    (int count);
+extern char *xstrdup        (const char *);
+extern int already_declared (char *name);
+extern int is_actual_func   (Declarator *d);
+extern int lint_ellipsis    (Parameter *p);
+extern int want_typedef     (void);
+extern void begin_tracking  (void);
+extern void begin_typedef   (void);
+extern void copy_typedef    (char *s);
+extern void ellipsis_varargs (Declarator *d);
+extern void end_typedef     (void);
+extern void flush_varargs   (void);
+extern void fmt_library     (int code);
+extern void imply_typedef   (const char *s);
+extern void indent          (FILE *outf);
+extern void put_blankline   (FILE *outf);
+extern void put_body        (FILE *outf, DeclSpec *decl_spec, Declarator *declarator);
+extern void put_char        (FILE *outf, int c);
+extern void put_error       (void);
+extern void put_newline     (FILE *outf);
+extern void put_padded      (FILE *outf, const char *s);
+extern void put_string      (FILE *outf, const char *s);
+extern void track_in        (void);
+
+extern boolean file_comments;
+extern FuncDefStyle func_style;
+extern char base_file[];
 
 #define YYMAXDEPTH 150
 
@@ -120,29 +316,21 @@ typedef struct {
 
 static IncludeStack *cur_file; /* current input file */
 
-#include "yyerror.c"
+/* #include "yyerror.c" */
 
 static int haveAnsiParam (void);
 
 
 /* Flags to enable us to find if a procedure returns a value.
  */
-static int return_val, /* nonzero on BRACES iff return-expression found */
-          returned_at; /* marker for token-number to set 'return_val' */
+static int return_val; /* nonzero on BRACES iff return-expression found */
 
-#if OPT_LINTLIBRARY
-static char *dft_decl_spec (void);
-
-static char *
+static const char *
 dft_decl_spec (void)
 {
     return (lintLibrary() && !return_val) ? "void" : "int";
 }
 
-#else
-#define dft_decl_spec() "int"
-#endif
-
 static int
 haveAnsiParam (void)
 {
@@ -814,18 +1002,30 @@ direct_abs_declarator
 
 %%
 
-#if defined(__EMX__) || defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(vms)
-# ifdef USE_flex
-#  include "lexyy.c"
-# else
-#  include "lex_yy.c"
-# endif
-#else
-# include "lex.yy.c"
-#endif
+/* lex.yy.c */
+#define BEGIN yy_start = 1 + 2 *
+
+#define CPP1 1
+#define INIT1 2
+#define INIT2 3
+#define CURLY 4
+#define LEXYACC 5
+#define ASM 6
+#define CPP_INLINE 7
+
+extern char *yytext;
+extern FILE *yyin, *yyout;
+
+static int curly;                      /* number of curly brace nesting levels */
+static int ly_count;                   /* number of occurances of %% */
+static int inc_depth;                  /* include nesting level */
+static SymbolTable *included_files;    /* files already included */
+static int yy_start = 0;               /* start state number */
+
+#define grammar_error(s) yaccError(s)
 
 static void
-yaccError (char *msg)
+yaccError (const char *msg)
 {
     func_params = NULL;
     put_error();               /* tell what line we're on, and what file */
@@ -838,7 +1038,7 @@ yaccError (char *msg)
 void
 init_parser (void)
 {
-    static char *keywords[] = {
+    static const char *keywords[] = {
        "const",
        "restrict",
        "volatile",
diff --git a/test/pure_calc.output b/test/pure_calc.output
new file mode 100644 (file)
index 0000000..3aed475
--- /dev/null
@@ -0,0 +1,461 @@
+   0  $accept : list $end
+
+   1  list :
+   2       | list stat '\n'
+   3       | list error '\n'
+
+   4  stat : expr
+   5       | LETTER '=' expr
+
+   6  expr : '(' expr ')'
+   7       | expr '+' expr
+   8       | expr '-' expr
+   9       | expr '*' expr
+  10       | expr '/' expr
+  11       | expr '%' expr
+  12       | expr '&' expr
+  13       | expr '|' expr
+  14       | '-' expr
+  15       | LETTER
+  16       | number
+
+  17  number : DIGIT
+  18         | number DIGIT
+\f
+state 0
+       $accept : . list $end  (0)
+       list : .  (1)
+
+       .  reduce 1
+
+       list  goto 1
+
+
+state 1
+       $accept : list . $end  (0)
+       list : list . stat '\n'  (2)
+       list : list . error '\n'  (3)
+
+       $end  accept
+       error  shift 2
+       DIGIT  shift 3
+       LETTER  shift 4
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       stat  goto 7
+       expr  goto 8
+       number  goto 9
+
+
+state 2
+       list : list error . '\n'  (3)
+
+       '\n'  shift 10
+       .  error
+
+
+state 3
+       number : DIGIT .  (17)
+
+       .  reduce 17
+
+
+state 4
+       stat : LETTER . '=' expr  (5)
+       expr : LETTER .  (15)
+
+       '='  shift 11
+       '|'  reduce 15
+       '&'  reduce 15
+       '+'  reduce 15
+       '-'  reduce 15
+       '*'  reduce 15
+       '/'  reduce 15
+       '%'  reduce 15
+       '\n'  reduce 15
+
+
+state 5
+       expr : '-' . expr  (14)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 13
+       number  goto 9
+
+
+state 6
+       expr : '(' . expr ')'  (6)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 14
+       number  goto 9
+
+
+state 7
+       list : list stat . '\n'  (2)
+
+       '\n'  shift 15
+       .  error
+
+
+state 8
+       stat : expr .  (4)
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '|'  shift 16
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '\n'  reduce 4
+
+
+state 9
+       expr : number .  (16)
+       number : number . DIGIT  (18)
+
+       DIGIT  shift 23
+       '|'  reduce 16
+       '&'  reduce 16
+       '+'  reduce 16
+       '-'  reduce 16
+       '*'  reduce 16
+       '/'  reduce 16
+       '%'  reduce 16
+       '\n'  reduce 16
+       ')'  reduce 16
+
+
+state 10
+       list : list error '\n' .  (3)
+
+       .  reduce 3
+
+
+state 11
+       stat : LETTER '=' . expr  (5)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 24
+       number  goto 9
+
+
+state 12
+       expr : LETTER .  (15)
+
+       .  reduce 15
+
+
+state 13
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+       expr : '-' expr .  (14)
+
+       .  reduce 14
+
+
+state 14
+       expr : '(' expr . ')'  (6)
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '|'  shift 16
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       ')'  shift 25
+       .  error
+
+
+state 15
+       list : list stat '\n' .  (2)
+
+       .  reduce 2
+
+
+state 16
+       expr : expr '|' . expr  (13)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 26
+       number  goto 9
+
+
+state 17
+       expr : expr '&' . expr  (12)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 27
+       number  goto 9
+
+
+state 18
+       expr : expr '+' . expr  (7)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 28
+       number  goto 9
+
+
+state 19
+       expr : expr '-' . expr  (8)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 29
+       number  goto 9
+
+
+state 20
+       expr : expr '*' . expr  (9)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 30
+       number  goto 9
+
+
+state 21
+       expr : expr '/' . expr  (10)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 31
+       number  goto 9
+
+
+state 22
+       expr : expr '%' . expr  (11)
+
+       DIGIT  shift 3
+       LETTER  shift 12
+       '-'  shift 5
+       '('  shift 6
+       .  error
+
+       expr  goto 32
+       number  goto 9
+
+
+state 23
+       number : number DIGIT .  (18)
+
+       .  reduce 18
+
+
+state 24
+       stat : LETTER '=' expr .  (5)
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '|'  shift 16
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '\n'  reduce 5
+
+
+state 25
+       expr : '(' expr ')' .  (6)
+
+       .  reduce 6
+
+
+state 26
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+       expr : expr '|' expr .  (13)
+
+       '&'  shift 17
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 13
+       '\n'  reduce 13
+       ')'  reduce 13
+
+
+state 27
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr '&' expr .  (12)
+       expr : expr . '|' expr  (13)
+
+       '+'  shift 18
+       '-'  shift 19
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 12
+       '&'  reduce 12
+       '\n'  reduce 12
+       ')'  reduce 12
+
+
+state 28
+       expr : expr . '+' expr  (7)
+       expr : expr '+' expr .  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 7
+       '&'  reduce 7
+       '+'  reduce 7
+       '-'  reduce 7
+       '\n'  reduce 7
+       ')'  reduce 7
+
+
+state 29
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr '-' expr .  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       '*'  shift 20
+       '/'  shift 21
+       '%'  shift 22
+       '|'  reduce 8
+       '&'  reduce 8
+       '+'  reduce 8
+       '-'  reduce 8
+       '\n'  reduce 8
+       ')'  reduce 8
+
+
+state 30
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr '*' expr .  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       .  reduce 9
+
+
+state 31
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr '/' expr .  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       .  reduce 10
+
+
+state 32
+       expr : expr . '+' expr  (7)
+       expr : expr . '-' expr  (8)
+       expr : expr . '*' expr  (9)
+       expr : expr . '/' expr  (10)
+       expr : expr . '%' expr  (11)
+       expr : expr '%' expr .  (11)
+       expr : expr . '&' expr  (12)
+       expr : expr . '|' expr  (13)
+
+       .  reduce 11
+
+
+16 terminals, 5 nonterminals
+19 grammar rules, 33 states
diff --git a/test/pure_calc.tab.c b/test/pure_calc.tab.c
new file mode 100644 (file)
index 0000000..41c8e0f
--- /dev/null
@@ -0,0 +1,666 @@
+#ifndef lint
+static const char yysccsid[] = "@(#)yaccpar    1.9 (Berkeley) 02/21/93";
+#endif
+
+#define YYBYACC 1
+#define YYMAJOR 1
+#define YYMINOR 9
+
+#define YYEMPTY        (-1)
+#define yyclearin      (yychar = YYEMPTY)
+#define yyerrok        (yyerrflag = 0)
+#define YYRECOVERING() (yyerrflag != 0)
+
+
+#ifndef yyparse
+#define yyparse    calc_parse
+#endif /* yyparse */
+
+#ifndef yylex
+#define yylex      calc_lex
+#endif /* yylex */
+
+#ifndef yyerror
+#define yyerror    calc_error
+#endif /* yyerror */
+
+#ifndef yychar
+#define yychar     calc_char
+#endif /* yychar */
+
+#ifndef yyval
+#define yyval      calc_val
+#endif /* yyval */
+
+#ifndef yylval
+#define yylval     calc_lval
+#endif /* yylval */
+
+#ifndef yydebug
+#define yydebug    calc_debug
+#endif /* yydebug */
+
+#ifndef yynerrs
+#define yynerrs    calc_nerrs
+#endif /* yynerrs */
+
+#ifndef yyerrflag
+#define yyerrflag  calc_errflag
+#endif /* yyerrflag */
+
+#ifndef yylhs
+#define yylhs      calc_lhs
+#endif /* yylhs */
+
+#ifndef yylen
+#define yylen      calc_len
+#endif /* yylen */
+
+#ifndef yydefred
+#define yydefred   calc_defred
+#endif /* yydefred */
+
+#ifndef yydgoto
+#define yydgoto    calc_dgoto
+#endif /* yydgoto */
+
+#ifndef yysindex
+#define yysindex   calc_sindex
+#endif /* yysindex */
+
+#ifndef yyrindex
+#define yyrindex   calc_rindex
+#endif /* yyrindex */
+
+#ifndef yygindex
+#define yygindex   calc_gindex
+#endif /* yygindex */
+
+#ifndef yytable
+#define yytable    calc_table
+#endif /* yytable */
+
+#ifndef yycheck
+#define yycheck    calc_check
+#endif /* yycheck */
+
+#ifndef yyname
+#define yyname     calc_name
+#endif /* yyname */
+
+#ifndef yyrule
+#define yyrule     calc_rule
+#endif /* yyrule */
+#define YYPREFIX "calc_"
+
+#define YYPURE 1
+
+#line 2 "pure_calc.y"
+# include <stdio.h>
+# include <ctype.h>
+
+int regs[26];
+int base;
+
+#line 106 "pure_calc.tab.c"
+
+#ifndef YYSTYPE
+typedef int YYSTYPE;
+#endif
+
+/* compatibility with bison */
+#ifdef YYPARSE_PARAM
+/* compatibility with FreeBSD */
+# ifdef YYPARSE_PARAM_TYPE
+#  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
+# else
+#  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
+# endif
+#else
+# define YYPARSE_DECL() yyparse(void)
+#endif
+
+/* Parameters sent to lex. */
+#ifdef YYLEX_PARAM
+# define YYLEX_DECL() yylex(YYSTYPE *yylval, void *YYLEX_PARAM)
+# define YYLEX yylex(&yylval, YYLEX_PARAM)
+#else
+# define YYLEX_DECL() yylex(YYSTYPE *yylval)
+# define YYLEX yylex(&yylval)
+#endif
+
+extern int YYPARSE_DECL();
+extern int YYLEX_DECL();
+
+#define DIGIT 257
+#define LETTER 258
+#define UMINUS 259
+#define YYERRCODE 256
+static const short calc_lhs[] = {                        -1,
+    0,    0,    0,    1,    1,    2,    2,    2,    2,    2,
+    2,    2,    2,    2,    2,    2,    3,    3,
+};
+static const short calc_len[] = {                         2,
+    0,    3,    3,    1,    3,    3,    3,    3,    3,    3,
+    3,    3,    3,    2,    1,    1,    1,    2,
+};
+static const short calc_defred[] = {                      1,
+    0,    0,   17,    0,    0,    0,    0,    0,    0,    3,
+    0,   15,   14,    0,    2,    0,    0,    0,    0,    0,
+    0,    0,   18,    0,    6,    0,    0,    0,    0,    9,
+   10,   11,
+};
+static const short calc_dgoto[] = {                       1,
+    7,    8,    9,
+};
+static const short calc_sindex[] = {                      0,
+  -40,   -7,    0,  -55,  -38,  -38,    1,  -29, -247,    0,
+  -38,    0,    0,   22,    0,  -38,  -38,  -38,  -38,  -38,
+  -38,  -38,    0,  -29,    0,   51,   60,  -20,  -20,    0,
+    0,    0,
+};
+static const short calc_rindex[] = {                      0,
+    0,    0,    0,    2,    0,    0,    0,    9,   -9,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,   10,    0,   -6,   14,    5,   13,    0,
+    0,    0,
+};
+static const short calc_gindex[] = {                      0,
+    0,   65,    0,
+};
+#define YYTABLESIZE 220
+static const short calc_table[] = {                       6,
+   16,    6,   10,   13,    5,   11,    5,   22,   17,   23,
+   15,   15,   20,   18,    7,   19,   22,   21,    4,    5,
+    0,   20,    8,   12,    0,    0,   21,   16,   16,    0,
+    0,   16,   16,   16,   13,   16,    0,   16,   15,   15,
+    0,    0,    7,   15,   15,    7,   15,    7,   15,    7,
+    8,   12,    0,    8,   12,    8,    0,    8,   22,   17,
+    0,    0,   25,   20,   18,    0,   19,    0,   21,   13,
+   14,    0,    0,    0,    0,   24,    0,    0,    0,    0,
+   26,   27,   28,   29,   30,   31,   32,   22,   17,    0,
+    0,    0,   20,   18,   16,   19,   22,   21,    0,    0,
+    0,   20,   18,    0,   19,    0,   21,    0,    0,    0,
+    0,    0,    0,    0,   16,    0,    0,   13,    0,    0,
+    0,    0,    0,    0,    0,   15,    0,    0,    7,    0,
+    0,    0,    0,    0,    0,    0,    8,   12,    0,    0,
+    0,    0,    0,    0,    0,   16,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    2,    3,    4,    3,   12,
+};
+static const short calc_check[] = {                      40,
+   10,   40,   10,   10,   45,   61,   45,   37,   38,  257,
+   10,   10,   42,   43,   10,   45,   37,   47,   10,   10,
+   -1,   42,   10,   10,   -1,   -1,   47,   37,   38,   -1,
+   -1,   41,   42,   43,   41,   45,   -1,   47,   37,   38,
+   -1,   -1,   38,   42,   43,   41,   45,   43,   47,   45,
+   38,   38,   -1,   41,   41,   43,   -1,   45,   37,   38,
+   -1,   -1,   41,   42,   43,   -1,   45,   -1,   47,    5,
+    6,   -1,   -1,   -1,   -1,   11,   -1,   -1,   -1,   -1,
+   16,   17,   18,   19,   20,   21,   22,   37,   38,   -1,
+   -1,   -1,   42,   43,  124,   45,   37,   47,   -1,   -1,
+   -1,   42,   43,   -1,   45,   -1,   47,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,  124,   -1,   -1,  124,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,  124,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,  124,  124,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  124,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  256,  257,  258,  257,  258,
+};
+#define YYFINAL 1
+#ifndef YYDEBUG
+#define YYDEBUG 0
+#endif
+#define YYMAXTOKEN 259
+#if YYDEBUG
+static const char *yyname[] = {
+
+"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,"'%'","'&'",0,"'('","')'","'*'","'+'",0,"'-'",0,"'/'",0,0,0,0,0,0,0,
+0,0,0,0,0,0,"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"'|'",0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,"DIGIT","LETTER","UMINUS",
+};
+static const char *yyrule[] = {
+"$accept : list",
+"list :",
+"list : list stat '\\n'",
+"list : list error '\\n'",
+"stat : expr",
+"stat : LETTER '=' expr",
+"expr : '(' expr ')'",
+"expr : expr '+' expr",
+"expr : expr '-' expr",
+"expr : expr '*' expr",
+"expr : expr '/' expr",
+"expr : expr '%' expr",
+"expr : expr '&' expr",
+"expr : expr '|' expr",
+"expr : '-' expr",
+"expr : LETTER",
+"expr : number",
+"number : DIGIT",
+"number : number DIGIT",
+
+};
+#endif
+/* define the initial stack-sizes */
+#ifdef YYSTACKSIZE
+#undef YYMAXDEPTH
+#define YYMAXDEPTH  YYSTACKSIZE
+#else
+#ifdef YYMAXDEPTH
+#define YYSTACKSIZE YYMAXDEPTH
+#else
+#define YYSTACKSIZE 500
+#define YYMAXDEPTH  500
+#endif
+#endif
+
+#define YYINITSTACKSIZE 500
+
+int      yydebug;
+int      yynerrs;
+
+typedef struct {
+    unsigned stacksize;
+    short    *s_base;
+    short    *s_mark;
+    short    *s_last;
+    YYSTYPE  *l_base;
+    YYSTYPE  *l_mark;
+} YYSTACKDATA;
+#line 63 "pure_calc.y"
+ /* start of programs */
+
+int
+main (void)
+{
+    while(!feof(stdin)) {
+       yyparse();
+    }
+    return 0;
+}
+
+static void
+yyerror(const char *s)
+{
+    fprintf(stderr, "%s\n", s);
+}
+
+int
+yylex(YYSTYPE *value)
+{
+       /* lexical analysis routine */
+       /* returns LETTER for a lower case letter, yylval = 0 through 25 */
+       /* return DIGIT for a digit, yylval = 0 through 9 */
+       /* all other characters are returned immediately */
+
+    int c;
+
+    while( (c=getchar()) == ' ' )   { /* skip blanks */ }
+
+    /* c is now nonblank */
+
+    if( islower( c )) {
+       *value = c - 'a';
+       return ( LETTER );
+    }
+    if( isdigit( c )) {
+       *value = c - '0';
+       return ( DIGIT );
+    }
+    return( c );
+}
+#line 329 "pure_calc.tab.c"
+
+#if YYDEBUG
+#include <stdio.h>             /* needed for printf */
+#endif
+
+#include <stdlib.h>    /* needed for malloc, etc */
+#include <string.h>    /* needed for memset */
+
+/* allocate initial stack or double stack size, up to YYMAXDEPTH */
+static int yygrowstack(YYSTACKDATA *data)
+{
+    int i;
+    unsigned newsize;
+    short *newss;
+    YYSTYPE *newvs;
+
+    if ((newsize = data->stacksize) == 0)
+        newsize = YYINITSTACKSIZE;
+    else if (newsize >= YYMAXDEPTH)
+        return -1;
+    else if ((newsize *= 2) > YYMAXDEPTH)
+        newsize = YYMAXDEPTH;
+
+    i = data->s_mark - data->s_base;
+    newss = (data->s_base != 0)
+          ? (short *)realloc(data->s_base, newsize * sizeof(*newss))
+          : (short *)malloc(newsize * sizeof(*newss));
+    if (newss == 0)
+        return -1;
+
+    data->s_base = newss;
+    data->s_mark = newss + i;
+
+    newvs = (data->l_base != 0)
+          ? (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs))
+          : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
+    if (newvs == 0)
+        return -1;
+
+    data->l_base = newvs;
+    data->l_mark = newvs + i;
+
+    data->stacksize = newsize;
+    data->s_last = data->s_base + newsize - 1;
+    return 0;
+}
+
+#if YYPURE || defined(YY_NO_LEAKS)
+static void yyfreestack(YYSTACKDATA *data)
+{
+    free(data->s_base);
+    free(data->l_base);
+    memset(data, 0, sizeof(*data));
+}
+#else
+#define yyfreestack(data) /* nothing */
+#endif
+
+#define YYABORT  goto yyabort
+#define YYREJECT goto yyabort
+#define YYACCEPT goto yyaccept
+#define YYERROR  goto yyerrlab
+
+int
+YYPARSE_DECL()
+{
+    int      yyerrflag;
+    int      yychar;
+    YYSTYPE  yyval;
+    YYSTYPE  yylval;
+
+    /* variables for the parser stack */
+    YYSTACKDATA yystack;
+    int yym, yyn, yystate;
+#if YYDEBUG
+    const char *yys;
+
+    if ((yys = getenv("YYDEBUG")) != 0)
+    {
+        yyn = *yys;
+        if (yyn >= '0' && yyn <= '9')
+            yydebug = yyn - '0';
+    }
+#endif
+
+    yynerrs = 0;
+    yyerrflag = 0;
+    yychar = YYEMPTY;
+    yystate = 0;
+
+#if YYPURE
+    memset(&yystack, 0, sizeof(yystack));
+#endif
+
+    if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
+    yystack.s_mark = yystack.s_base;
+    yystack.l_mark = yystack.l_base;
+    yystate = 0;
+    *yystack.s_mark = 0;
+
+yyloop:
+    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
+    if (yychar < 0)
+    {
+        if ((yychar = YYLEX) < 0) yychar = 0;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, reading %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+    }
+    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: state %d, shifting to state %d\n",
+                    YYPREFIX, yystate, yytable[yyn]);
+#endif
+        if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+        {
+            goto yyoverflow;
+        }
+        yystate = yytable[yyn];
+        *++yystack.s_mark = yytable[yyn];
+        *++yystack.l_mark = yylval;
+        yychar = YYEMPTY;
+        if (yyerrflag > 0)  --yyerrflag;
+        goto yyloop;
+    }
+    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+        yyn = yytable[yyn];
+        goto yyreduce;
+    }
+    if (yyerrflag) goto yyinrecovery;
+
+    yyerror("syntax error");
+
+    goto yyerrlab;
+
+yyerrlab:
+    ++yynerrs;
+
+yyinrecovery:
+    if (yyerrflag < 3)
+    {
+        yyerrflag = 3;
+        for (;;)
+        {
+            if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
+                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: state %d, error recovery shifting\
+ to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
+#endif
+                if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+                {
+                    goto yyoverflow;
+                }
+                yystate = yytable[yyn];
+                *++yystack.s_mark = yytable[yyn];
+                *++yystack.l_mark = yylval;
+                goto yyloop;
+            }
+            else
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: error recovery discarding state %d\n",
+                            YYPREFIX, *yystack.s_mark);
+#endif
+                if (yystack.s_mark <= yystack.s_base) goto yyabort;
+                --yystack.s_mark;
+                --yystack.l_mark;
+            }
+        }
+    }
+    else
+    {
+        if (yychar == 0) goto yyabort;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+        yychar = YYEMPTY;
+        goto yyloop;
+    }
+
+yyreduce:
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
+                YYPREFIX, yystate, yyn, yyrule[yyn]);
+#endif
+    yym = yylen[yyn];
+    if (yym)
+        yyval = yystack.l_mark[1-yym];
+    else
+        memset(&yyval, 0, sizeof yyval);
+    switch (yyn)
+    {
+case 3:
+#line 25 "pure_calc.y"
+       {  yyerrok ; }
+break;
+case 4:
+#line 29 "pure_calc.y"
+       {  printf("%d\n",yystack.l_mark[0]);}
+break;
+case 5:
+#line 31 "pure_calc.y"
+       {  regs[yystack.l_mark[-2]] = yystack.l_mark[0]; }
+break;
+case 6:
+#line 35 "pure_calc.y"
+       {  yyval = yystack.l_mark[-1]; }
+break;
+case 7:
+#line 37 "pure_calc.y"
+       {  yyval = yystack.l_mark[-2] + yystack.l_mark[0]; }
+break;
+case 8:
+#line 39 "pure_calc.y"
+       {  yyval = yystack.l_mark[-2] - yystack.l_mark[0]; }
+break;
+case 9:
+#line 41 "pure_calc.y"
+       {  yyval = yystack.l_mark[-2] * yystack.l_mark[0]; }
+break;
+case 10:
+#line 43 "pure_calc.y"
+       {  yyval = yystack.l_mark[-2] / yystack.l_mark[0]; }
+break;
+case 11:
+#line 45 "pure_calc.y"
+       {  yyval = yystack.l_mark[-2] % yystack.l_mark[0]; }
+break;
+case 12:
+#line 47 "pure_calc.y"
+       {  yyval = yystack.l_mark[-2] & yystack.l_mark[0]; }
+break;
+case 13:
+#line 49 "pure_calc.y"
+       {  yyval = yystack.l_mark[-2] | yystack.l_mark[0]; }
+break;
+case 14:
+#line 51 "pure_calc.y"
+       {  yyval = - yystack.l_mark[0]; }
+break;
+case 15:
+#line 53 "pure_calc.y"
+       {  yyval = regs[yystack.l_mark[0]]; }
+break;
+case 17:
+#line 58 "pure_calc.y"
+       {  yyval = yystack.l_mark[0]; base = (yystack.l_mark[0]==0) ? 8 : 10; }
+break;
+case 18:
+#line 60 "pure_calc.y"
+       {  yyval = base * yystack.l_mark[-1] + yystack.l_mark[0]; }
+break;
+#line 606 "pure_calc.tab.c"
+    }
+    yystack.s_mark -= yym;
+    yystate = *yystack.s_mark;
+    yystack.l_mark -= yym;
+    yym = yylhs[yyn];
+    if (yystate == 0 && yym == 0)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: after reduction, shifting from state 0 to\
+ state %d\n", YYPREFIX, YYFINAL);
+#endif
+        yystate = YYFINAL;
+        *++yystack.s_mark = YYFINAL;
+        *++yystack.l_mark = yyval;
+        if (yychar < 0)
+        {
+            if ((yychar = YYLEX) < 0) yychar = 0;
+#if YYDEBUG
+            if (yydebug)
+            {
+                yys = 0;
+                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+                if (!yys) yys = "illegal-symbol";
+                printf("%sdebug: state %d, reading %d (%s)\n",
+                        YYPREFIX, YYFINAL, yychar, yys);
+            }
+#endif
+        }
+        if (yychar == 0) goto yyaccept;
+        goto yyloop;
+    }
+    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
+        yystate = yytable[yyn];
+    else
+        yystate = yydgoto[yym];
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: after reduction, shifting from state %d \
+to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
+#endif
+    if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+    {
+        goto yyoverflow;
+    }
+    *++yystack.s_mark = (short) yystate;
+    *++yystack.l_mark = yyval;
+    goto yyloop;
+
+yyoverflow:
+    yyerror("yacc stack overflow");
+
+yyabort:
+    yyfreestack(&yystack);
+    return (1);
+
+yyaccept:
+    yyfreestack(&yystack);
+    return (0);
+}
diff --git a/test/pure_calc.tab.h b/test/pure_calc.tab.h
new file mode 100644 (file)
index 0000000..1921118
--- /dev/null
@@ -0,0 +1,3 @@
+#define DIGIT 257
+#define LETTER 258
+#define UMINUS 259
diff --git a/test/pure_calc.y b/test/pure_calc.y
new file mode 100644 (file)
index 0000000..462f04c
--- /dev/null
@@ -0,0 +1,103 @@
+%{
+# include <stdio.h>
+# include <ctype.h>
+
+int regs[26];
+int base;
+
+%}
+
+%start list
+
+%token DIGIT LETTER
+
+%left '|'
+%left '&'
+%left '+' '-'
+%left '*' '/' '%'
+%left UMINUS   /* supplies precedence for unary minus */
+
+%% /* beginning of rules section */
+
+list  :  /* empty */
+      |  list stat '\n'
+      |  list error '\n'
+            {  yyerrok ; }
+      ;
+
+stat  :  expr
+            {  printf("%d\n",$1);}
+      |  LETTER '=' expr
+            {  regs[$1] = $3; }
+      ;
+
+expr  :  '(' expr ')'
+            {  $$ = $2; }
+      |  expr '+' expr
+            {  $$ = $1 + $3; }
+      |  expr '-' expr
+            {  $$ = $1 - $3; }
+      |  expr '*' expr
+            {  $$ = $1 * $3; }
+      |  expr '/' expr
+            {  $$ = $1 / $3; }
+      |  expr '%' expr
+            {  $$ = $1 % $3; }
+      |  expr '&' expr
+            {  $$ = $1 & $3; }
+      |  expr '|' expr
+            {  $$ = $1 | $3; }
+      |  '-' expr %prec UMINUS
+            {  $$ = - $2; }
+      |  LETTER
+            {  $$ = regs[$1]; }
+      |  number
+      ;
+
+number:  DIGIT
+         {  $$ = $1; base = ($1==0) ? 8 : 10; }
+      |  number DIGIT
+         {  $$ = base * $1 + $2; }
+      ;
+
+%% /* start of programs */
+
+int
+main (void)
+{
+    while(!feof(stdin)) {
+       yyparse();
+    }
+    return 0;
+}
+
+static void
+yyerror(const char *s)
+{
+    fprintf(stderr, "%s\n", s);
+}
+
+int
+yylex(YYSTYPE *value)
+{
+       /* lexical analysis routine */
+       /* returns LETTER for a lower case letter, yylval = 0 through 25 */
+       /* return DIGIT for a digit, yylval = 0 through 9 */
+       /* all other characters are returned immediately */
+
+    int c;
+
+    while( (c=getchar()) == ' ' )   { /* skip blanks */ }
+
+    /* c is now nonblank */
+
+    if( islower( c )) {
+       *value = c - 'a';
+       return ( LETTER );
+    }
+    if( isdigit( c )) {
+       *value = c - '0';
+       return ( DIGIT );
+    }
+    return( c );
+}
diff --git a/test/pure_error.output b/test/pure_error.output
new file mode 100644 (file)
index 0000000..0c4db62
--- /dev/null
@@ -0,0 +1,27 @@
+   0  $accept : S $end
+
+   1  S : error
+\f
+state 0
+       $accept : . S $end  (0)
+
+       error  shift 1
+       .  error
+
+       S  goto 2
+
+
+state 1
+       S : error .  (1)
+
+       .  reduce 1
+
+
+state 2
+       $accept : S . $end  (0)
+
+       $end  accept
+
+
+2 terminals, 2 nonterminals
+2 grammar rules, 3 states
diff --git a/test/pure_error.tab.c b/test/pure_error.tab.c
new file mode 100644 (file)
index 0000000..9076dd0
--- /dev/null
@@ -0,0 +1,493 @@
+#ifndef lint
+static const char yysccsid[] = "@(#)yaccpar    1.9 (Berkeley) 02/21/93";
+#endif
+
+#define YYBYACC 1
+#define YYMAJOR 1
+#define YYMINOR 9
+
+#define YYEMPTY        (-1)
+#define yyclearin      (yychar = YYEMPTY)
+#define yyerrok        (yyerrflag = 0)
+#define YYRECOVERING() (yyerrflag != 0)
+
+
+#ifndef yyparse
+#define yyparse    error_parse
+#endif /* yyparse */
+
+#ifndef yylex
+#define yylex      error_lex
+#endif /* yylex */
+
+#ifndef yyerror
+#define yyerror    error_error
+#endif /* yyerror */
+
+#ifndef yychar
+#define yychar     error_char
+#endif /* yychar */
+
+#ifndef yyval
+#define yyval      error_val
+#endif /* yyval */
+
+#ifndef yylval
+#define yylval     error_lval
+#endif /* yylval */
+
+#ifndef yydebug
+#define yydebug    error_debug
+#endif /* yydebug */
+
+#ifndef yynerrs
+#define yynerrs    error_nerrs
+#endif /* yynerrs */
+
+#ifndef yyerrflag
+#define yyerrflag  error_errflag
+#endif /* yyerrflag */
+
+#ifndef yylhs
+#define yylhs      error_lhs
+#endif /* yylhs */
+
+#ifndef yylen
+#define yylen      error_len
+#endif /* yylen */
+
+#ifndef yydefred
+#define yydefred   error_defred
+#endif /* yydefred */
+
+#ifndef yydgoto
+#define yydgoto    error_dgoto
+#endif /* yydgoto */
+
+#ifndef yysindex
+#define yysindex   error_sindex
+#endif /* yysindex */
+
+#ifndef yyrindex
+#define yyrindex   error_rindex
+#endif /* yyrindex */
+
+#ifndef yygindex
+#define yygindex   error_gindex
+#endif /* yygindex */
+
+#ifndef yytable
+#define yytable    error_table
+#endif /* yytable */
+
+#ifndef yycheck
+#define yycheck    error_check
+#endif /* yycheck */
+
+#ifndef yyname
+#define yyname     error_name
+#endif /* yyname */
+
+#ifndef yyrule
+#define yyrule     error_rule
+#endif /* yyrule */
+#define YYPREFIX "error_"
+
+#define YYPURE 1
+
+
+#ifndef YYSTYPE
+typedef int YYSTYPE;
+#endif
+
+/* compatibility with bison */
+#ifdef YYPARSE_PARAM
+/* compatibility with FreeBSD */
+# ifdef YYPARSE_PARAM_TYPE
+#  define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
+# else
+#  define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
+# endif
+#else
+# define YYPARSE_DECL() yyparse(void)
+#endif
+
+/* Parameters sent to lex. */
+#ifdef YYLEX_PARAM
+# define YYLEX_DECL() yylex(YYSTYPE *yylval, void *YYLEX_PARAM)
+# define YYLEX yylex(&yylval, YYLEX_PARAM)
+#else
+# define YYLEX_DECL() yylex(YYSTYPE *yylval)
+# define YYLEX yylex(&yylval)
+#endif
+
+extern int YYPARSE_DECL();
+extern int YYLEX_DECL();
+
+#define YYERRCODE 256
+static const short error_lhs[] = {                       -1,
+    0,
+};
+static const short error_len[] = {                        2,
+    1,
+};
+static const short error_defred[] = {                     0,
+    1,    0,
+};
+static const short error_dgoto[] = {                      2,
+};
+static const short error_sindex[] = {                  -256,
+    0,    0,
+};
+static const short error_rindex[] = {                     0,
+    0,    0,
+};
+static const short error_gindex[] = {                     0,
+};
+#define YYTABLESIZE 0
+static const short error_table[] = {                      1,
+};
+static const short error_check[] = {                    256,
+};
+#define YYFINAL 2
+#ifndef YYDEBUG
+#define YYDEBUG 0
+#endif
+#define YYMAXTOKEN 0
+#if YYDEBUG
+static const char *yyname[] = {
+
+"end-of-file",
+};
+static const char *yyrule[] = {
+"$accept : S",
+"S : error",
+
+};
+#endif
+/* define the initial stack-sizes */
+#ifdef YYSTACKSIZE
+#undef YYMAXDEPTH
+#define YYMAXDEPTH  YYSTACKSIZE
+#else
+#ifdef YYMAXDEPTH
+#define YYSTACKSIZE YYMAXDEPTH
+#else
+#define YYSTACKSIZE 500
+#define YYMAXDEPTH  500
+#endif
+#endif
+
+#define YYINITSTACKSIZE 500
+
+int      yydebug;
+int      yynerrs;
+
+typedef struct {
+    unsigned stacksize;
+    short    *s_base;
+    short    *s_mark;
+    short    *s_last;
+    YYSTYPE  *l_base;
+    YYSTYPE  *l_mark;
+} YYSTACKDATA;
+#line 4 "pure_error.y"
+
+#include <stdio.h>
+
+int
+main(void)
+{
+    printf("yyparse() = %d\n", yyparse());
+    return 0;
+}
+
+int
+yylex(YYSTYPE *value)
+{
+    return value ? 0 : -1;
+}
+
+static void
+yyerror(const char* s)
+{
+    printf("%s\n", s);
+}
+#line 217 "pure_error.tab.c"
+
+#if YYDEBUG
+#include <stdio.h>             /* needed for printf */
+#endif
+
+#include <stdlib.h>    /* needed for malloc, etc */
+#include <string.h>    /* needed for memset */
+
+/* allocate initial stack or double stack size, up to YYMAXDEPTH */
+static int yygrowstack(YYSTACKDATA *data)
+{
+    int i;
+    unsigned newsize;
+    short *newss;
+    YYSTYPE *newvs;
+
+    if ((newsize = data->stacksize) == 0)
+        newsize = YYINITSTACKSIZE;
+    else if (newsize >= YYMAXDEPTH)
+        return -1;
+    else if ((newsize *= 2) > YYMAXDEPTH)
+        newsize = YYMAXDEPTH;
+
+    i = data->s_mark - data->s_base;
+    newss = (data->s_base != 0)
+          ? (short *)realloc(data->s_base, newsize * sizeof(*newss))
+          : (short *)malloc(newsize * sizeof(*newss));
+    if (newss == 0)
+        return -1;
+
+    data->s_base = newss;
+    data->s_mark = newss + i;
+
+    newvs = (data->l_base != 0)
+          ? (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs))
+          : (YYSTYPE *)malloc(newsize * sizeof(*newvs));
+    if (newvs == 0)
+        return -1;
+
+    data->l_base = newvs;
+    data->l_mark = newvs + i;
+
+    data->stacksize = newsize;
+    data->s_last = data->s_base + newsize - 1;
+    return 0;
+}
+
+#if YYPURE || defined(YY_NO_LEAKS)
+static void yyfreestack(YYSTACKDATA *data)
+{
+    free(data->s_base);
+    free(data->l_base);
+    memset(data, 0, sizeof(*data));
+}
+#else
+#define yyfreestack(data) /* nothing */
+#endif
+
+#define YYABORT  goto yyabort
+#define YYREJECT goto yyabort
+#define YYACCEPT goto yyaccept
+#define YYERROR  goto yyerrlab
+
+int
+YYPARSE_DECL()
+{
+    int      yyerrflag;
+    int      yychar;
+    YYSTYPE  yyval;
+    YYSTYPE  yylval;
+
+    /* variables for the parser stack */
+    YYSTACKDATA yystack;
+    int yym, yyn, yystate;
+#if YYDEBUG
+    const char *yys;
+
+    if ((yys = getenv("YYDEBUG")) != 0)
+    {
+        yyn = *yys;
+        if (yyn >= '0' && yyn <= '9')
+            yydebug = yyn - '0';
+    }
+#endif
+
+    yynerrs = 0;
+    yyerrflag = 0;
+    yychar = YYEMPTY;
+    yystate = 0;
+
+#if YYPURE
+    memset(&yystack, 0, sizeof(yystack));
+#endif
+
+    if (yystack.s_base == NULL && yygrowstack(&yystack)) goto yyoverflow;
+    yystack.s_mark = yystack.s_base;
+    yystack.l_mark = yystack.l_base;
+    yystate = 0;
+    *yystack.s_mark = 0;
+
+yyloop:
+    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
+    if (yychar < 0)
+    {
+        if ((yychar = YYLEX) < 0) yychar = 0;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, reading %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+    }
+    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: state %d, shifting to state %d\n",
+                    YYPREFIX, yystate, yytable[yyn]);
+#endif
+        if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+        {
+            goto yyoverflow;
+        }
+        yystate = yytable[yyn];
+        *++yystack.s_mark = yytable[yyn];
+        *++yystack.l_mark = yylval;
+        yychar = YYEMPTY;
+        if (yyerrflag > 0)  --yyerrflag;
+        goto yyloop;
+    }
+    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
+    {
+        yyn = yytable[yyn];
+        goto yyreduce;
+    }
+    if (yyerrflag) goto yyinrecovery;
+
+    yyerror("syntax error");
+
+    goto yyerrlab;
+
+yyerrlab:
+    ++yynerrs;
+
+yyinrecovery:
+    if (yyerrflag < 3)
+    {
+        yyerrflag = 3;
+        for (;;)
+        {
+            if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 &&
+                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: state %d, error recovery shifting\
+ to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]);
+#endif
+                if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+                {
+                    goto yyoverflow;
+                }
+                yystate = yytable[yyn];
+                *++yystack.s_mark = yytable[yyn];
+                *++yystack.l_mark = yylval;
+                goto yyloop;
+            }
+            else
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("%sdebug: error recovery discarding state %d\n",
+                            YYPREFIX, *yystack.s_mark);
+#endif
+                if (yystack.s_mark <= yystack.s_base) goto yyabort;
+                --yystack.s_mark;
+                --yystack.l_mark;
+            }
+        }
+    }
+    else
+    {
+        if (yychar == 0) goto yyabort;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
+                    YYPREFIX, yystate, yychar, yys);
+        }
+#endif
+        yychar = YYEMPTY;
+        goto yyloop;
+    }
+
+yyreduce:
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
+                YYPREFIX, yystate, yyn, yyrule[yyn]);
+#endif
+    yym = yylen[yyn];
+    if (yym)
+        yyval = yystack.l_mark[1-yym];
+    else
+        memset(&yyval, 0, sizeof yyval);
+    switch (yyn)
+    {
+    }
+    yystack.s_mark -= yym;
+    yystate = *yystack.s_mark;
+    yystack.l_mark -= yym;
+    yym = yylhs[yyn];
+    if (yystate == 0 && yym == 0)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("%sdebug: after reduction, shifting from state 0 to\
+ state %d\n", YYPREFIX, YYFINAL);
+#endif
+        yystate = YYFINAL;
+        *++yystack.s_mark = YYFINAL;
+        *++yystack.l_mark = yyval;
+        if (yychar < 0)
+        {
+            if ((yychar = YYLEX) < 0) yychar = 0;
+#if YYDEBUG
+            if (yydebug)
+            {
+                yys = 0;
+                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+                if (!yys) yys = "illegal-symbol";
+                printf("%sdebug: state %d, reading %d (%s)\n",
+                        YYPREFIX, YYFINAL, yychar, yys);
+            }
+#endif
+        }
+        if (yychar == 0) goto yyaccept;
+        goto yyloop;
+    }
+    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
+            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
+        yystate = yytable[yyn];
+    else
+        yystate = yydgoto[yym];
+#if YYDEBUG
+    if (yydebug)
+        printf("%sdebug: after reduction, shifting from state %d \
+to state %d\n", YYPREFIX, *yystack.s_mark, yystate);
+#endif
+    if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack))
+    {
+        goto yyoverflow;
+    }
+    *++yystack.s_mark = (short) yystate;
+    *++yystack.l_mark = yyval;
+    goto yyloop;
+
+yyoverflow:
+    yyerror("yacc stack overflow");
+
+yyabort:
+    yyfreestack(&yystack);
+    return (1);
+
+yyaccept:
+    yyfreestack(&yystack);
+    return (0);
+}
diff --git a/test/pure_error.tab.h b/test/pure_error.tab.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/pure_error.y b/test/pure_error.y
new file mode 100644 (file)
index 0000000..8c308d2
--- /dev/null
@@ -0,0 +1,24 @@
+%%
+S: error
+%%
+
+#include <stdio.h>
+
+int
+main(void)
+{
+    printf("yyparse() = %d\n", yyparse());
+    return 0;
+}
+
+int
+yylex(YYSTYPE *value)
+{
+    return value ? 0 : -1;
+}
+
+static void
+yyerror(const char* s)
+{
+    printf("%s\n", s);
+}
diff --git a/test/run_lint.sh b/test/run_lint.sh
new file mode 100755 (executable)
index 0000000..3230551
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+# $Id: run_lint.sh,v 1.1 2010/06/08 09:00:58 tom Exp $
+# vi:ts=4 sw=4:
+
+# run lint on each of the ".c" files in the test directory
+
+if test $# = 1
+then
+       PROG_DIR=`pwd`
+       TEST_DIR=$1
+else
+       PROG_DIR=..
+       TEST_DIR=.
+fi
+
+echo '** '`date`
+for i in ${TEST_DIR}/*.c
+do
+       make -f $PROG_DIR/makefile lint C_FILES=$i srcdir=$PROG_DIR
+done
diff --git a/test/run_make.sh b/test/run_make.sh
new file mode 100755 (executable)
index 0000000..2e61a69
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+# $Id: run_make.sh,v 1.1 2010/06/08 09:00:39 tom Exp $
+# vi:ts=4 sw=4:
+
+# do a test-compile on each of the ".c" files in the test-directory
+
+if test $# = 1
+then
+       PROG_DIR=`pwd`
+       TEST_DIR=$1
+else
+       PROG_DIR=..
+       TEST_DIR=.
+fi
+
+echo '** '`date`
+for i in ${TEST_DIR}/*.c
+do
+       obj=`echo "$i" |sed -e 's/\.c$/.o/'`
+       make -f $PROG_DIR/makefile $obj C_FILES=$i srcdir=$PROG_DIR
+       test -f $obj && rm $obj
+done
index 56f23f453c6a53aee3dcb56a762594bb37523e7c..59dbca01e7d03f1607a05ed6164e25f7b38badb6 100755 (executable)
@@ -1,8 +1,22 @@
 #!/bin/sh
-# $Id: run_test.sh,v 1.3 2008/08/25 20:22:14 tom Exp $
-#
+# $Id: run_test.sh,v 1.6 2010/06/08 08:53:38 tom Exp $
+# vi:ts=4 sw=4:
+
+if test $# = 1
+then
+       PROG_DIR=`pwd`
+       TEST_DIR=$1
+else
+       PROG_DIR=..
+       TEST_DIR=.
+fi
+
+YACC=$PROG_DIR/yacc
+
+tmpfile=temp$$
+
 echo '** '`date`
-for i in *.y
+for i in ${TEST_DIR}/*.y
 do
        case $i in
        test*)
@@ -11,25 +25,47 @@ do
        *)
                root=`basename $i .y`
                ROOT="test-$root"
-               ../yacc -v -d -p ${root}_ -b $ROOT $i
-               for type in .output .tab.c .tab.h
+               prefix=${root}_
+
+               OPTS=
+               TYPE=".output .tab.c .tab.h"
+               case $i in
+               ${TEST_DIR}/code_*)
+                       OPTS="$OPTS -r"
+                       TYPE="$TYPE .code.c"
+                       prefix=`echo "$prefix" | sed -e 's/^code_//'`
+                       ;;
+               ${TEST_DIR}/pure_*)
+                       OPTS="$OPTS -P"
+                       prefix=`echo "$prefix" | sed -e 's/^pure_//'`
+                       ;;
+               esac
+
+               $YACC $OPTS -v -d -p $prefix -b $ROOT $i
+               for type in $TYPE
                do
-                       REF=${root}${type}
+                       REF=${TEST_DIR}/${root}${type}
                        CMP=${ROOT}${type}
                        if test ! -f $CMP ; then
                                echo "...not found $CMP"
                                continue
                        fi
-                       sed     -e s/$CMP/$REF/ \
+                       sed     -e s,$CMP,$REF, \
                                -e /YYPATCH/d \
-                               < $CMP >temp$$ \
-                               && mv temp$$ $CMP
-                       if ( cmp -s $REF $CMP )
+                               -e 's,#line \([1-9][0-9]*\) "'$TEST_DIR'/,#line \1 ",' \
+                               < $CMP >$tmpfile \
+                               && mv $tmpfile $CMP
+                       if test ! -f $REF
+                       then
+                               mv $CMP $REF
+                               echo "...saved $REF"
+                       elif ( cmp -s $REF $CMP )
                        then
                                echo "...ok $REF"
                                rm -f $CMP
                        else
                                echo "...diff $REF"
+                               diff -u $REF $CMP
                        fi
                done
                ;;
index 55a08aec0175a62ffea5214e29f5b4e66f451457..118f8b4027996cfae17d1bbd8271610a659c3b7a 100644 (file)
--- a/verbose.c
+++ b/verbose.c
@@ -1,4 +1,4 @@
-/* $Id: verbose.c,v 1.8 2009/10/27 09:12:43 tom Exp $ */
+/* $Id: verbose.c,v 1.9 2010/06/09 08:58:29 tom Exp $ */
 
 #include "defs.h"
 
@@ -24,8 +24,8 @@ verbose(void)
        return;
 
     null_rules = (short *)MALLOC((unsigned)nrules * sizeof(short));
-    if (null_rules == 0)
-       no_space();
+    NO_SPACE(null_rules);
+
     fprintf(verbose_file, "\f\n");
     for (i = 0; i < nstates; i++)
        print_state(i);
index b97879d9c480dfadd6b13fefa78d1b126b24be2d..efb7cf447974d04d007d90d629463c2e9425e9e2 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: warshall.c,v 1.6 2008/11/24 21:30:35 tom Exp $ */
+/* $Id: warshall.c,v 1.7 2010/06/06 22:48:51 tom Exp $ */
 
 #include "defs.h"
 
@@ -28,7 +28,7 @@ transitive_closure(unsigned *R, int n)
 
        while (rowj < relend)
        {
-           if (*ccol & (1 << i))
+           if (*ccol & (unsigned)(1 << i))
            {
                rp = rowi;
                rend = rowj + rowsize;
@@ -70,7 +70,7 @@ reflexive_transitive_closure(unsigned *R, int n)
     rp = R;
     while (rp < relend)
     {
-       *rp |= (1 << i);
+       *rp |= (unsigned)(1 << i);
        if (++i >= BITS_PER_WORD)
        {
            i = 0;
diff --git a/yacc.1 b/yacc.1
index c33fbf2cc0b01eb674574a237b89924d3bfd96b3..3ee0d3d54812ed6f996f3878cb7900645a147210 100644 (file)
--- a/yacc.1
+++ b/yacc.1
@@ -1,8 +1,8 @@
-.\" $Id: yacc.1,v 1.7 2010/02/17 02:01:24 tom Exp $
+.\" $Id: yacc.1,v 1.9 2010/06/10 20:50:08 tom Exp $
 .\"
 .\" .TH YACC 1 "July\ 15,\ 1990"
 .\" .UC 6
-.TH YACC 1 "February 16, 2010" "Berkeley Yacc" "User Commands"
+.TH YACC 1 "June 10, 2010" "Berkeley Yacc" "User Commands"
 .SH NAME
 Yacc \- an LALR(1) parser generator
 .SH SYNOPSIS
@@ -119,6 +119,14 @@ tell \fByacc\fP the expected number of reduce/reduce conflicts.
 That makes it only report the number if it differs.
 This is (unlike bison) allowable in LALR parsers.
 .TP
+\fB %lex-param\fP { \fIargument-declaration\fP }
+By default, the lexer accepts no parameters, e.g., \fByylex()\fP.
+Use this directive to add parameter declarations for your customized lexer.
+.TP
+\fB %parse-param\fP { \fIargument-declaration\fP }
+By default, the parser accepts no parameters, e.g., \fByyparse()\fP. 
+Use this directive to add parameter declarations for your customized parser.
+.TP
 \fB %pure-parser\fP
 Most variables (other than \fByydebug\fP and \fByynerrs\fP) are
 allocated on the stack within \fByyparse\fP, making the parser reasonably