Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!know!zaphod.mps.ohio-state.edu!rpi!bu.edu!husc6!spdcc!ima!esegue!compilers-sender From: wsineel@info.win.tue.nl (e.vriezekolk) Newsgroups: comp.compilers Subject: Two pass compiler using YACC? Keywords: yacc, parse, question Message-ID: <1364@svin02.info.win.tue.nl> Date: 22 Aug 90 21:42:19 GMT Sender: compilers-sender@esegue.segue.boston.ma.us Reply-To: wsineel@info.win.tue.nl (e.vriezekolk) Organization: Eindhoven University of Technology, The Netherlands Lines: 24 Approved: compilers@esegue.segue.boston.ma.us Hi, We are working on a compiler, using yacc. The compiler will be two-pass, and we have a different .y file for both passes. Each .y file is translated by yacc to pass.1.C and pass.2.C (we are using C++). 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? -- Eelco Vriezekolk, wsineel@win.tue.nl [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] -- Send compilers articles to compilers@esegue.segue.boston.ma.us {ima | spdcc | world}!esegue. Meta-mail to compilers-request@esegue.