Re: Two pass compiler using YACC?

Bart Massey <bart@videovax.tv.tek.com>
25 Aug 90 04:41:58 GMT

          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: Bart Massey <bart@videovax.tv.tek.com>
Keywords: C, yacc, parse, design
Organization: Tektronix TV Measurement Systems, Beaverton OR
References: <1364@svin02.info.win.tue.nl>
Date: 25 Aug 90 04:41:58 GMT

In article <1364@svin02.info.win.tue.nl> wsineel@info.win.tue.nl (e.vriezekolk) writes:
> We are working on a compiler, using yacc. The compiler will be two-pass,
> and we have a different .y file for both passes.
...
> The problems come during link-time, for ld, obviously, complains about
> multiple defined symbols (such as yylval and yyparse).
...
> [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 ... > it is a big problem to keep the two files in
> sync when you make a grammar change. -John]


Hmmm. It seems to me to depend a lot on what is meant by "two-pass". In the
traditional usage, where the second pass is merely used to resolve forward
references, I'd agree completely. However, I have heard the phrase
"two-pass" used to describe compilers where the first pass outputs a very
different intermediate form which the second pass parses. In this case, one
could legitimately want two entirely different grammars.


There are several ways to accomplish this, none of them trivial. One is to
get a copy of GNU BISON and use the "semantic parsers" feature, which does
what you want. It needs some slight debugging, however, and is really hard
to figure out. Another is to get a copy of Berkeley YACC, and hack it up to
do the right thing, which would probably be easy, and would probably be
greatly appreciated by others. The third, and by far the most traditional,
is to write a sed script which hacks the YACC output so that all the names
are unique. This is usually some baroque variant on replacing "yy" with
some more unique prefix.


Finally, and this is my favorite, you can just hose the intermediate form
through a pipe to a separate program. This opens up a lot of other neat
possibilities...


It really is a shame that none of the 3 parser generators mentioned above
generates modular parsers very well. Ah well. Hope this helps,


Bart Massey
..tektronix!videovax.tv.tek.com!bart
..tektronix!reed.bitnet!bart
--


Post a followup to this message

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