Re: preprocessing C++ with new features

bonzini@gnu.org (Paolo Bonzini)
13 Apr 2003 12:38:50 -0400

          From comp.compilers

Related articles
preprocessing C++ with new features bettini@dsi.unifi.it (Lorenzo Bettini) (2003-03-30)
Re: preprocessing C++ with new features haberg@math.su.se (2003-03-30)
Re: preprocessing C++ with new features idbaxter@semdesigns.com (Ira Baxter) (2003-03-30)
Re: preprocessing C++ with new features Nicola.Musatti@ObjectWay.it (2003-03-31)
Re: preprocessing C++ with new features bonzini@gnu.org (2003-04-13)
Re: preprocessing C++ with new features bettini@dsi.unifi.it (Lorenzo Bettini) (2003-04-15)
Re: preprocessing C++ with new features Thomas.Aigner@bfd-r.bayern.de (Thomas Aigner) (2003-05-23)
| List of all articles for this month |

From: bonzini@gnu.org (Paolo Bonzini)
Newsgroups: comp.compilers
Date: 13 Apr 2003 12:38:50 -0400
Organization: http://groups.google.com/
References: 03-03-159
Keywords: C++, tools
Posted-Date: 13 Apr 2003 12:38:50 EDT

> I would like to add some new features to C++ and so I'd need mechanisms
> for preprocessing C++ code in order to handle only the new features and
> thus to generate new (translated) C++ code.
>
> Are there any tools for helping me do this (apart from Open C++)?


Flex and Bison can be used; you can have the lexer output the generic
C++ code and pass the new features to Bison. If you can be sure that
the new keywords are not used as variable names and the like (which
you should be unless you want to write PL/1...) it is very easy.


I used this approach in GNU Smalltalk where I have a primitive
definitions file that's something like


primitive VMpr_Float_arith:
          prim_id VMpr_Float_plus [succeed],
          prim_id VMpr_Float_minus [succeed],
          prim_id VMpr_Float_divide [succeed,fail],
{
    ...
    switch (id)
        {
              case prim_id (VMpr_Float_plus): ...
              ...
        }
}


The 'primitive' declaration is turned into a prototype, the
declaration of an array (with the attributes that were specified into
square brackets) and the routine with the body. The 'prim_id'
expressions in the routine are turned into numbers (-1, -2, -3, ...)


You can find it in ftp://alpha.gnu.org/gnu/smalltalk-2.1-pre.tar.gz
(files libgst/genpr*).


Hope this helps,


Paolo


Post a followup to this message

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