[comp.compilers] Yacc++, was Re: Seeking parser generator topics

mike@vlsivie.at (08/27/90)

In article <9008241906.AA11285@cssun.tamu.edu>, terry@cs.tamu.edu (Terry Escamilla) writes:
> - making every component of the grammar an object with multiple attributes
>   for grammar symbols (contrary to YACC), thus giving a very fine grain of
>   reusability (though I don't know what one would do with this).

Stephen C. Johnson proposed something of the kind. There was a paper in
the Proceedings of the EUUG Spring '88 Conference called "Yacc meets C++"
introducing Y++. In y++, every grammar symbol is associated with a class
which may have any number of members. 

It is implemented as two passes from what I gather from the papaer, one 
doing the parsing, the second the evaluation, by executing all members defined
on the start symbol. (this has to be done by the user)

What it boils down to seems to be this:

%start expr

%%

expr : expr '+' expr 
       { postfix() { $1.postfix(); $3.postfix(); putchar('+'); }
         prefix () { putchar('+'); $1.prefix(); $3.prefix(); }       
       }
     | NUM
       { postfix () { $1.print(); }
         prefix ()  { $1.print(); }
       }


/* I doubt that this is the syntax, but either there was none specified or
   I don't recall */

Now if you wanted to print the expression in prefix and postfix you would do
something like 

main()
{
	/* somehow define return value */

	return_value = yyparse();

 	printf("Prefix:\n");
	return_value.prefix();
	
 	printf("Postfix:\n");
	return_value.postfix();
}

Neat concept, isn't it? Does anybody know whatever happened to y++?

It was supposed to be a research tool, no finished program....

BTW,
this brings us full circle back to two pass compilers; what do you think 
about this:

main()
{
        /* somehow define return value */

        return_value = yyparse();

        return_value.pass_1();

        return_value.pass_2();
}

I think it is as clean as you can ever do it with YACC ....

			bye,
				mike
Michael K. Gschwind             mike@vlsivie.at
Technical University, Vienna    mike@vlsivie.uucp
Voice: (++43).1.58801 8144      e182202@awituw01.bitnet
Fax:   (++43).1.569697
-- 
Send compilers articles to compilers@esegue.segue.boston.ma.us
{ima | spdcc | world}!esegue.  Meta-mail to compilers-request@esegue.