Saving/restoring bison parse state

Stephane Some <ssome@csi.UOttawa.CA>
29 Oct 1997 23:11:11 -0500

          From comp.compilers

Related articles
Saving/restoring bison parse state tim@wagner.Princeton.EDU (1997-10-14)
Re: Saving/restoring bison parse state (1997-10-26)
Saving/restoring bison parse state ssome@csi.UOttawa.CA (Stephane Some) (1997-10-29)
| List of all articles for this month |

From: Stephane Some <ssome@csi.UOttawa.CA>
Newsgroups: comp.compilers
Date: 29 Oct 1997 23:11:11 -0500
Organization: Compilers Central
References: 97-10-075
Keywords: yacc

From: tim@wagner.Princeton.EDU (Tim Hollebeek)

> I'm writing a C documentation tool based on a bison grammar for C. One of
> the things I want to do is handle BOTH blocks of #ifdef/#else/#endif
> constructs.
> I have the practical aspects down as far as my program is concerned, so
> I just need to get bison to cooperate. I.e.:

> /* some C code */
> /***** save all bison state info here *****/
> #ifdef FOO
> /* branch 1 */
> /***** restore bison state info here *****/
> #else
> /* branch 2 */
> #endif
> Has anyone tried something like this before? A quick look at the bison
> output suggests it should work fine if I simply save the globals in the
> YYPURE ifdef, as well as all the local variables in yyparse (probably using
> a hacked version of bison.simple).

We face the same problem with conditional compilation as we are
working on re-engineering of existing programs. One of our first idea
was saving and restoring parse state. What we did with a quite easy
hacking of bison.simple.

> Are there any disadvantages to this approach I have missed? Any better
> ways of accomplishing the same thing?

In our case it simply didn't work because of situations such as:

#ifdef SUNOS
/* source code for SUNOS */
/* common code */
#ifdef SOLARIS
/* source code for SOLARIS */
/* common code */
#ifdef SUNOS
/* source code for SUNOS */

Where we want to consider all the code related to SUNOS or SOLARIS
together and independantly. In a such case you simply can't say when
to save and restore the parsing state (conditions can be more
complicated than what is above with #if).

We also have problem with the fact that our saving and restoring
primitives are completely dependant on bison implementation, and then,
may not work with different (futur) versions.

Just send me a mail if you are interessed on our hack.
Stéphane S. Somé
SITE: School of Information Technology and Engineering
University of/d'Ottawa
Ottawa, Canada, K1N 6N5

Post a followup to this message

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