Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwm.edu!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!decwrl!shelby!kon@mycroft.Stanford.EDU From: kon@mycroft.Stanford.EDU (Ronnie Kon) Newsgroups: comp.unix.wizards Subject: Re: Linking two yacc (y.tab.o) files Message-ID: <39@mycroft.stanford.edu> Date: 23 Feb 90 04:18:36 GMT References: <25E34681.3787@deimos.cis.ksu.edu> Sender: kon@mycroft.STANFORD.EDU (Ronnie Kon) Distribution: usa Organization: Mindcraft Inc. Lines: 33 In article <25E34681.3787@deimos.cis.ksu.edu> jxf@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/\ 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@mindcraft.com | but mine is really bossy" ...!{decwrl,hpda}!mindcrf!ronnie | -- Laurie Anderson -------------------------------------------------------------------------------