Re: Two pass compiler using YACC?

meissner@osf.org
Mon, 27 Aug 90 13:32:01 -0400

          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: meissner@osf.org
In-Reply-To: bart@videovax.tv.tek.com's message of 25 Aug 90 04:41:58 GMT
Keywords: yacc, design, parse
Organization: Compilers Central
Date: Mon, 27 Aug 90 13:32:01 -0400

In terms of ways of having two or more parsers within a program, one
way that I haven't seen mentioned is the way I did it when
implementing Data General's AOS/VS C compiler. I implemented the
compiler and preprocessor as one integrated program, and was left with
the decision on how to handle #if. I didn't particularly want to have
two sets of parser tables in the compiler, because of difficulities in
convincing the parser generator to cooperate (this was a home grown
parser generator that had it's own share of problems).


The solution I came up with was to make the top level rule, something
like:


top: grammar1
| SPECIAL_TOKEN grammar2 ;


That is, having the lexer spit out a special token to go to second
grammar rather than the first.


Of course if you have a recursive parser (such as my case processing
#if's within the normal handling of the grammar), you have to save all
of the parser state and restore it when you exit the parser. Given
that the parser generator I used just spit out the tables, and I had
to write the parser skeleton, it was easy to do. With YACC where the
skeleton is provided for you, and it doesn't support multiple grammars
like BISON does, you have some work to do....


--
Michael Meissner email: meissner@osf.org phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142
[Good point, I once did that too. Making yacc support recursive parsing
isn't very hard, you just have to make a bunch of static arrays and
variables automatics. -John]
--


Post a followup to this message

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