[comp.sw.components] two

leland@cs (12/07/90)

I have an application that requires two discrete uses of both lex and
yacc.  Since both lex and yacc have hardcoded names (all with the 'yy'
prefix) for a whole bunch of global symbols, there is an immediate
problem:  somehow the two sets must be hidden from each other and
distinguished for any other code that accesses them.

I've tried this kludge:  create a header file that re-#define's all the
names 'yyfoo' in lex/yacc set #1 to be named, say, set1yyfoo, and all
those in set #2 to be named set2yyfoo.  This has worked for me in the
past, but won't in this particular instance because the generated
code includes calls to yyless() and yywrap(), which are in the LEX
library (-ll), the contents of which I cannot rename.  So that doesn't
work.

I've also investigated GNU's replacements for these programs, flex and
bison.  I haven't gotten to the bison documentation yet, but a
quick look at the flex man page implies that these programs still
have the hardcoded global symbol names.  Flex eliminates the need
for the external library, however, so this may solve my problem.  But
it's still a horrible kludge, and it would require that others to whom
I distribute the software maintain flex and/or bison.  I'm looking
for something better.

I may be able to use some special loader options to 'hide' the yy*
symbols when compiling the object modules that contain them, but
the procedure for doing is not obvious nor it is standardized across
loader versions.

Has anybody listening gotten into this before?  Can you offer any
suggestions?  Thanks for whatever you may know.

It is difficult to accept that, considering how long these programs have
been around, none of the implementers ever thought to make these globals
static or to add a command-line option to rename them.

Leland Woodbury
-- 
ARPANET/INTERNET: leland@cs.columbia.edu
	  USENET: ...!columbia!cs.columbia.edu!leland
	  BITNET: leland%cs.columbia.edu@cuvmb
	  USMAIL: Columbia Univ., 457 CS, 500 W. 120 St., NYC 10027-6699

blakemor@software.org (Alex Blakemore) (12/10/90)

In article <1990Dec6.201421.13444@cs.columbia.edu> leland@cs () writes:
> I have an application that requires two discrete uses of both lex and
> yacc.  Since both lex and yacc have hardcoded names (all with the 'yy'
> prefix) for a whole bunch of global symbols, there is an immediate
> problem:  somehow the two sets must be hidden from each other and
> distinguished for any other code that accesses them.

If you are willing to use another language at least for this part
you may consider the Ada versions of lex and yacc from UC Irvine,
called ayacc and alex.  They generate the same hard coded names, but
they have Ada packages surrounding them that take their names from
the yacc input files base names. That way there are no linker
conflicts. You also get the pleasure (or pain) of programming in Ada,
depending upon your point of view.

They take virtually identical input as lex and yacc 
(of course the action rules have to change to Ada or 
Ada calls to C functions).  We have two parsers and scanners linked
into the same executable and it works fine - of course only one is
ever used at a time.  Good luck.

  I dont have access to my files with the exact addresses now but
you can get info from UCI CS dept whch is part of the Arcadia group
The net addresses are something like :
     arcadia-request@uci.cs.edu
     ayacc-info@uci.cs.edu
     alex-info@uci.cs.edu
---------------------------------------------------------------------
Alex Blakemore           blakemore@software.org        (703) 742-7125
Software Productivity Consortium  2214 Rock Hill Rd, Herndon VA 22070