Re: Two pass compiler using YACC?

tbr@virgil.tfic.bc.ca (Tom Rushworth)
Fri, 24 Aug 90 13:36:19 PDT

          From comp.compilers

Related articles
Two pass compiler using YACC? wsineel@info.win.tue.nl (1990-08-22)
Re: Two pass compiler using YACC? mkie@vlsivie.at (1990-08-23)
Re: Two pass compiler using YACC? tbr@virgil.tfic.bc.ca (1990-08-24)
Re: Two pass compiler using YACC? bart@videovax.tv.tek.com (Bart Massey) (1990-08-25)
Re: Two pass compiler using YACC? sja@sirius.hut.fi (1990-08-25)
Re: Two pass compiler using YACC? meissner@osf.org (1990-08-27)
Two pass compiler using YACC? jar@florida.eng.ileaf.com (1990-09-02)
Two pass compiler using YACC? meissner@osf.org (1990-09-06)
| List of all articles for this month |

Newsgroups: comp.compilers
From: tbr@virgil.tfic.bc.ca (Tom Rushworth)
Keywords: yacc
Organization: Compilers Central
Date: Fri, 24 Aug 90 13:36:19 PDT

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 <y.tab.c >$@
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.
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.