[comp.unix.wizards] [unix-wizards] Re: Linking two yacc

bobg+@andrew.cmu.edu (Robert Steven Glickstein) (03/11/90)

Excerpts from netnews.alt.sources: 9-Mar-90 [unix-wizards] Re: Linking
.. Gregory N. Bond@bby.oz.a (2435)

> Here is a script I use for making yacc output files static, so you can
> link n of them in one binary.  I use it on the output of getdate.y to
> make a general gate-parsing library.  Tried only on SunOs 3.5 and 4.0.3.
> (It assumes the .y file contains a global routine that calls the
> yyparse routine).

> Usage: sed -f yaccstaticize.sed < y.tab.c > file.c

> [...]

> echo shar: Extracting \"'yaccstaticize.sed'\" \(93 characters\)
> sed "s/^X//" >'yaccstaticize.sed' <<'END_OF_FILE'
> Xs/^short yy/static &/
> Xs/^int[ 	]*yy/static &/
> Xs/^YY[LS]TYPE/static &/
> Xs/^yyparse()/static &/

Unfortunately, this is a highly non-portable approach whose success
depends on zillions of factors, such as whether your C compiler allows
static objects not to be forward-declared, and what the exact form of
your /usr/lib/yaccpar is.  I discovered the inadequacy of this approach
when I needed a tool to do the very same thing.

I have written a considerably more robust version of this, called
"yyhide".  Yyhide will not only make everything static, but it will
topographically sort the definitions of functions and variables within
the yacc output.

Yyhide is part of the Andrew distribution, which in turn is available in
the X11r4 distribution (under contrib/toolkits/andrew [yyhide itself
lives in contrib/toolkits/andrew/overhead/parsec]).

Please contact me if you have any questions.

______________
Bob Glickstein                | Internet: bobg@andrew.cmu.edu
Information Technology Center | Bitnet:   bobg%andrew@cmuccvma.bitnet
Carnegie Mellon University    | UUCP:     ...!harvard!andrew.cmu.edu!bobg
Pittsburgh, PA  15213-3890    |
(412) 268-6743                | Sinners can repent, but stupid is forever

rich@sendai.sendai.ann-arbor.mi.us (K. Richard Magill) (03/12/90)

It should be noted that bison, from Free Software Foundation has the
ability to produce reentrant parsers which sounds like what you really
want.