Re: Bison

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On 12/01/11 06:24, John Calcote wrote:
On 01/11/2011 04:31 AM, Russell Shaw wrote:
Hi,
On debian, there is /usr/bin/bison, and
/usr/bin/bison.yacc just does:

   exec '/usr/bin/bison' -y "$@"

How can i get autoconf to use bison?

The problem with yacc is that you can't rename
the output files and always get: y.tab.h y.tab.c

Is there a way i can get yacc to give better output
file names like myproj.tab.h myproj.tab.c ?

Hi Russell - try the techniques listed here:
http://www.mail-archive.com/help-bison@xxxxxxx/msg01897.html

Hi J.C,
It's close to what i'm looking for, but not complete enough.
I'm not good at autoconf stuff. Why is descriptor "5" used?

ac_compile_yacc='$CC -c $CFLAGS $CPPFLAGS $ac_cv_prog_yacc_root.c >&5'

If you're using automake-1.10+, that should provide a YACC variable override: ./configure YACC=/my/yacc ...

I've attached my m4 macro for testing whether $YACC is really bison or yacc, not just relying on the program name.

automake also provides a helper script 'ylwrap' to deal with yacc/bison compilations and do some file renaming.

Fang

David Fang
http://www.csl.cornell.edu/~fang/
http://www.achronix.com/
dnl @synopsis HACKT_ARG_VAR_YACC
dnl
dnl Enables YACC as a configurable variable.  
dnl This usually picks up bison by default if found, 
dnl but can be manually overridden.
dnl Note: automake-1.10+ already provides YACC variable
dnl This macro now runs some test to detect certain traits
dnl of the parser generator.
dnl
dnl @category InstalledPackages
dnl @version 2008-03-14
dnl @author David Fang <fangism@xxxxxxxxxxxxxxxxxxxxx>
dnl @license AllPermissive
dnl
AC_DEFUN([HACKT_ARG_VAR_YACC],
[AC_REQUIRE([AC_PROG_YACC])
AC_ARG_VAR(YACC, [parser generator, requires LALR(1), such as yacc/bison])
cat > conftest.y <<ACEOF
%token  FIRST_TOK
%token  LAST_TOK
%start top
%%
top: FIRST_TOK LAST_TOK
%%
ACEOF
dnl fake cache variable< should probably use different name prefix
ac_cv_prog_yacc_root="y.tab"
ac_compile_yacc='$CC -c $CFLAGS $CPPFLAGS $ac_cv_prog_yacc_root.c >&5'

dnl test 1: find the enumeral value of the first token
if $YACC -d -t -v conftest.y && eval "$ac_compile_yacc"
then
if ! test -f $ac_cv_prog_yacc_root.c
then AC_MSG_ERROR([$YACC does not produce $ac_cv_prog_yacc_root.c.])
fi
if ! test -f $ac_cv_prog_yacc_root.h
then AC_MSG_ERROR([$YACC does not produce $ac_cv_prog_yacc_root.h.])
fi
YACC_FIRST_TOKEN_ENUM=`grep "^#define.*FIRST_TOK" $ac_cv_prog_yacc_root.h | cut -d\  -f3`
fi
AC_SUBST(YACC_FIRST_TOKEN_ENUM)

dnl test 2: if yacc, get the version string of the skeleton
dnl eventually pass this into YACC_VERSION
yacc_skeleton_version=`grep "skeleton" $ac_cv_prog_yacc_root.c | \
        cut -d\" -f2 | sed 's/[$]//g'`

dnl test 3: find name of preprocessor symbol for MAXTOK
dnl is YYMAXTOKEN for yacc, YYMAXUTOK for bison

dnl test 4: what is the real underlying parser generator?
ac_for_real_yacc=
if grep -q YYBISON $ac_cv_prog_yacc_root.c ; then
        ac_for_real_yacc=bison
        AC_DEFINE(USING_BISON, 1, [Define to 1 if we're using bison.])
elif grep -q YYBYACC $ac_cv_prog_yacc_root.c ; then
        ac_for_real_yacc=byacc
        AC_DEFINE(USING_BYACC, 1, [Define to 1 if we're using byacc.])
else
        dnl is YACC
        ac_for_real_yacc=yacc
        AC_DEFINE(USING_YACC, 1, [Define to 1 if we're using yacc.])
fi
AC_MSG_NOTICE(parser generator is really $ac_for_real_yacc)
AM_CONDITIONAL(HAVE_BISON, test $ac_for_real_yacc = bison)
AM_CONDITIONAL(HAVE_BYACC, test $ac_for_real_yacc = byacc)
AM_CONDITIONAL(HAVE_YACC, test $ac_for_real_yacc = yacc)

dnl test 5: directive support
case $ac_for_real_yacc in
dnl (
bison ) YACC_PURE_PARSER=%pure_parser ;;
dnl (
*)      YACC_PURE_PARSER="" ;;
esac
AC_SUBST(YACC_PURE_PARSER)

dnl test 6: version string
case $ac_for_real_yacc in
dnl (
bison )
        YACC_VERSION=`$YACC --version 2>&1 | head -n 1`
        [BISON_VERSION=`echo x$YACC_VERSION | sed 's/[^.0-9]//g'`]
        AC_MSG_NOTICE([found bison version $BISON_VERSION.]) ;;
dnl (
*)      YACC_VERSION="$yacc_skeleton_version" ;;
esac
AC_SUBST(YACC_VERSION)

dnl TODO: run more tests
dnl clean up files: y.tab.c y.tab.h y.output
rm -f y.*
dnl for use in Makefile
])dnl

_______________________________________________
Autoconf mailing list
Autoconf@xxxxxxx
http://lists.gnu.org/mailman/listinfo/autoconf

[Index of Archives]     [GCC Help]     [Kernel Discussion]     [RPM Discussion]     [Red Hat Development]     [Yosemite News]     [Linux USB]     [Samba]

  Powered by Linux