Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!ncar!ico!haddock!ima!esegue!compilers-sender From: mkie@vlsivie.at (Inst.f.Techn.Informatik) Newsgroups: comp.compilers Subject: Re: Two pass compiler using YACC? Keywords: yacc, parse, question Message-ID: <1763@tuvie> Date: 23 Aug 90 11:08:58 GMT References: <1364@svin02.info.win.tue.nl> Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: mkie@vlsivie.at (Inst.f.Techn.Informatik) Organization: Technical University of Vienna, AUSTRIA Lines: 41 Approved: compilers@esegue.segue.boston.ma.us In article <1364@svin02.info.win.tue.nl>, wsineel@info.win.tue.nl (e.vriezekolk) writes: > The problems come during link-time, for ld, obviously, complains about > multiple defined symbols (such as yylval and yyparse). > > This must be a traditional problem. How is it solved? The symbols which make you clash can be renamed by a simple sed script sed -e 's/yyparse/something_parse/g' \ -e 's/yylex/something_lex/g' \ -e 's/yylval/something_lval/g' \ -e 's/YYSTYPE/something_TYPE/g' \ [...] you get the idea. You will also have to modify the y.tab.h file and the file with yylex() > [I hope the grammars for the two passes are the same, and just the { } > actions are different. I always do the obvious thing, if(pass1)... else ... > in the action routines. In about half the cases, the action routines do > something simple like look up an identifier in the symbol table, so the > conditional code is buried in the lower level routine. Having separate yacc > grammars seems to me to be a poor idea if for no other reason than that it is > a big problem to keep the two files in sync when you make a grammar change. > -John] That's the way I do it also, but sometimes you need two parsers in the same executable, so this problem does exist at times bye, mike Michael K. Gschwind mike@vlsivie.at Technical University, Vienna mike@vlsivie.uucp Voice: (++43).1.58801 8144 e182202@awituw01.bitnet Fax: (++43).1.569697 [Similar suggestions from zs@munginya.cs.mu.OZ.AU (Zoltan Somogyi), jouvelot@brokaw.lcs.mit.edu (Pierre Jouvelot), and vramsey@NCoast.ORG (Cedric Ramsey).] -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.