[Scons-users] yacc vs bison

Bill Deegan bill at baddogconsulting.com
Wed Dec 11 10:51:49 EST 2019

Not sure I understand your yaccing logic.
Is there another file extension other than .y which you'd want to use bison?
Are you calling yaccing with files which aren't .y's?

Ahh I see you're misunderstanding.
You're setting LEXFLAGS, then calling a builder then reseting LEXFLAGS then
calling a builder expecting that the first call will have any affect.
It won't. It's setting the flags for all lex calls in that environment
which doesn't happen until all SConscripts/SConstruct are processed.

Roughly SCons process is this:

   1. SCons initializes
   2. SCons processes SConstruct (and all SConscripts and other logic
   sconstruct uses) <--- This doesn't do any part of the build, but just
   instructs SCons HOW to.
   3. After processing SConstruct, then SCons will walk the graph of all
   the specified dependencies and figure out the order to build. It will also
   use information specified by SConstruct/SConscript to figure out HOW to

What you likely want is:

env.CFile('atc_co_lex.l', LEXFLAGS= '-Patc_co_')
env.CFile('atc_co_yacc.y', YACCFLAGS = '-t -p atc_co_ -d')
env.CFile('atc_db_lex.l', LEXFLAGS= '-Patc_db_')
env.CFile('atc_db_yacc.y', YACCFLAGS = '-t -p atc_db_ -d')

SCons allows you to specialize the Environment variables per builder
invocation. This creates an OverideEnvironment() which is a shallow copy of
the env with just the specified variables overwritten.

On Tue, Dec 10, 2019 at 10:19 PM Pierre-Luc Boily <pierreluc.boily at gmail.com>

> Thx,
> I ended up doing this :
> def yaccing(env, source):
>     """ Generate c file and header file from yacc file.  """
>     if str(source).endswith('.y'):
>         env['YACC'] = 'yacc'  # By default, scons use Bison tool for
> yaccing
> file.  Change the tool for yacc
>         return
> env.CFile(target=env.create_target_name(env.get_filename(str(source))),
>                          source=source)
>     else:
>         print(str(source) + ' is not a yacc file.')
>         exit(1)
> Regarding your comment about overwriting the FLAGS, I agree with you.  But
> I
> do have a strange behavior, probably something I do not understand about
> scons yet (or just another stupid mistake).  See my Sconscript :
> env['YACCFLAGS'] = ['-t', '-p', 'atc_co_', '-d']
> env['LEXFLAGS'] = ['-Patc_co_']
> env.lexing('atc_co_lex.l')
> env.yaccing('atc_co_yacc.y')
> env['YACCFLAGS'] = ['-t', '-p', 'atc_db_', '-d']
> env['LEXFLAGS'] = ['-Patc_db_']
> env.lexing('atc_db_lex.l')
> env.yaccing('atc_db_yacc.y')
> This gives this output :
> flex -Patc_db_ -t atm_common/libdb/src/atc_co_lex.l >
> build/atm_common/libdb/src/linux.x86.debug/atc_co_lex.c
> yacc -t -p atc_db_ -d -o
> build/atm_common/libdb/src/linux.x86.debug/atc_co_yacc.c
> atm_common/libdb/src/atc_co_yacc.y
> flex -Patc_db_ -t atm_common/libdb/src/atc_db_lex.l >
> build/atm_common/libdb/src/linux.x86.debug/atc_db_lex.c
> yacc -t -p atc_db_ -d -o
> build/atm_common/libdb/src/linux.x86.debug/atc_db_yacc.c
> atm_common/libdb/src/atc_db_yacc.y
> As you can see only "atc_db_" is used as flags.  I think a workaround could
> be to clone two environments, but I feel I do something wrong.
> --
> Sent from: http://scons.1086193.n5.nabble.com/Users-f16930.html
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20191211/efb8698b/attachment.html>

More information about the Scons-users mailing list