Reverse preprocessor

[Sourceforge project page] [CVS repository]

This is the first version of the homepage of the reverse preprocessor

What is reverse ?

reverse is a preprocessor that turns various programming languages like C,C++,java into powerful templating languages.
Reverse comes under the LGPL (Lesser Gnu Public License). For details about this license see
Reverse is focussed on code generation tools that need to generate source code. In such tools, reverse eliminates the printf() - overhead in the output functions and makes the code much more cleaner and readable. See the simple class-generator for an example.

The main idea is to have two independant languages and mix them together by embedding one language into the other. The main language of the input file is called the source language (SL), the other one the embedded language (EL). The SL is then translated into EL statements, and output in between the embedded EL-statements.

Here is some very basic example

      Hello reverse world {@
        for (int i=1;i<=5;i++) <@ !($i$)@>
      Output of the generated C++ program:
      Hello reverse world !(1) !(2) !(3) !(4) !(5)

In this example, the source language is plaintext, and the embedded language is C++. The plaintext is translated into C++ output statements. This is the standard reverse mode plaintext_cpp.

Simple class generator example

Consider the following two fragments of code

      void outputClass(CClass *cls) {
        cout<<"class "<<cls->name<<" :public "<<cls->baseClassName<<endl;
        for (CClass::FieldList::const_iterator i=cls->getFields().begin();i!=cls->getFields().end()) {
          cout<<"  "<<(*i)->datatype<<" "<<(*i)->name<<";"<<endl;
      void outputClass(CClass *cls) {
          class $cls->name$ :public $cls->baseClassName$
              for (CClass::FieldList::const_iterator i=cls->getFields().begin();i!=cls->getFields().end())
                $(*i)->datatype$ $(*i)->name$;

Both code fragments implement some (simple and hypothetical) code generator that output C++ code to declare a class with a baseclass and some fields. The first code fragment is realized in pure C++, while the second code fragment does the same, but is realized using the reverse preprocessor in inverse mode with the plaintext_cpp adaptor. The first code fragment suffers from becoming nearly unreadable due to a large overhead involved with the output statements. The second code fragment is much clearer to read once you get used to the context operator tags ([@@], $$, {@@} and <@@>)


Planned features

Supported platforms

Reverse is currently only tested on a gcc/Linux system with a gcc 3.2. But it should run on all suitable platforms that have gcc.

How to get it ?

Check out the current code from the CVS repository
You should check out both modules reverse and supp++
Alternatively, you may get the latest release from the download page


Reverse is developped by Peter Lammich. For questions and comments you may contact me via email:
views AT (The @ was left out too fool spambots)

Hosted by Logo

Valid XHTML 1.0!