Two pass compiler using YACC?

jar@florida.eng.ileaf.com (Jim Roskind x5570)
Sun, 2 Sep 90 21:04:55 EDT

          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: jar@florida.eng.ileaf.com (Jim Roskind x5570)
Keywords: yacc, parse
Organization: Compilers Central
Date: Sun, 2 Sep 90 21:04:55 EDT

> From: wsineel@info.win.tue.nl (e.vriezekolk)
>
> 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?


IMHO the cleanest solution lies in use of the C preprocessor (as do so
many solutions :-) ).


Suppose that the only multiply defined external were yyparse and yyerror.


Create a file called "pass1.h" containing the lines:


#define yyparse pass1_yyparse
#define yyerror pass1_yyerror


Then simply #include this file into the initial section of your yacc
grammar. This placement will cause the #include directive to appear
sufficiently early in the y.tab.c file that *all* references to
yyparse will be translated appropriately. External calls to the first
pass should use the new name.


> [I hope the grammars for the two passes are the same, and just the { }
> actions are different. ... -John]


I actually have examples where the grammar are distinct phases of
processing, and have very little connection. For example, in parsing
C, there is 1) the preprocessing parser, 2) the preprocessing
expression evaluation parser, and 3) the C syntax parser. I actually
implement each of the phases using a yacc based parser, and hence the
grammars are quite distinct. In the most general case, when the
phases of translation are very "orthogonal", there is a need for
multiple distinct parsers, and the trick for making yacc work in such
an environment is quite useful. (It also applies to multiple flex/lex
based lexers).




Jim Roskind
Independent Consultant
(407)729-4348 or (617)577-9813 x5570
jar@hq.ileaf.com or ...!uunet!leafusa!jar
--


Post a followup to this message

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