Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!sun-barr!apple!snorkelwacker!spdcc!ima!esegue!compilers-sender From: tbr@virgil.tfic.bc.ca (Tom Rushworth) Newsgroups: comp.compilers Subject: Re: Two pass compiler using YACC? Keywords: yacc Message-ID: <9008242036.AA10670@virgil.tfic.bc.ca> Date: 24 Aug 90 20:36:19 GMT Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: tbr@virgil.tfic.bc.ca (Tom Rushworth) Organization: Compilers Central Lines: 43 Approved: compilers@esegue.segue.boston.ma.us In article <1364@svin02.info.win.tue.nl> wsineel@info.win.tue.nl (e.vriezekolk) says: >The problems come during link-time, for ld, obviously, complains about >multiple defined symbols (such as yylval and yyparse). I have a number of library routines that need to parse different forms of input, and I ran into the same problem (multiple yacc parsers in one program). The brute force solution I used was in my makefile : #------------------------------------------------------- parse.c: definition.y yacc definition.y sed -f Makestatic $@ rm y.tab.c #------------------------------------------------------- where Makestatic is: #------------------------------------------------------- /^extern int yychar/d /^extern short yyerrflag/d /^YYSTYPE/s//static &/ /^short yyexca/s//static &/ /^short yyact/s//static &/ /^short yypact/s//static &/ /^short yypgo/s//static &/ /^short yyr1/s//static &/ /^short yyr2/s//static &/ /^short yychk/s//static &/ /^short yydef/s//static &/ /^int yydebug/s//static &/ /^int yychar/s//static &/ /^int yynerrs/s//static &/ /^short yyerrflag/s//static &/ /^yyparse()/s//static &/ #------------------------------------------------------- I then #include "parse.c" in the controlling code (instead of compiling it as a separate module) and supply static versions of any of the externs deleted in the script. This all works (at least on my Sun3s & 4s), the only price you pay is two (or more) copies of the parsing code. -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.