Linking two yacc (y.tab.o) files
Ronnie Kon
kon at mycroft.Stanford.EDU
Fri Feb 23 15:18:36 AEST 1990
In article <25E34681.3787 at deimos.cis.ksu.edu> jxf at phobos.cis.ksu.edu (Jerry Frain) writes:
> Since yacc creates a lot of global variables when it makes the
>y.tab.c files, there were many conflict errors when I tried to link the two
>files.
Not only does it make a lot of global variables, but the two
routines are both named yyparse, and both call yylex for scanning input.
There are two approaches to dealing with this, one correct and tedious to
implement, one a kludge that works every bit as well and is much, much, easier.
The correct way to do this is to run the yacc output through a sed
script which replaces all the globals with unique names. This will be a
pain to implement.
The kludge is to simply sed with the command
sed 's/\<yy/parser1_yy/g' < y.tab.c > parser1.c
for the first parser. (The sed script for the second parser is left as an
exercize for the reader :-)).
You then call these as parser1_yyparse() and parser2_yyparse(), and
you set up the scanners to be parser1_yylex() and parser2_yylex(). (If you
are using lex, you simply use the same sed scripts as for the yacc files,
and it all just works). Note that the yytext and yylval variables (which you
are probably using) need not be changed. The sed's will catch all instances
of them.
--
-------------------------------------------------------------------------------
Ronnie Kon | "I don't know about your brain,
ronnie at mindcraft.com | but mine is really bossy"
...!{decwrl,hpda}!mindcrf!ronnie | -- Laurie Anderson
-------------------------------------------------------------------------------
More information about the Comp.unix.wizards
mailing list