Introduction

The Wave C++ preprocessor is not a monolitic application, it's rather a modular library, which exposes mainly a context object and an iterator interface. The context object helps to configure the actual preprocessing process (as search path's, predefined macros, etc.). The exposed iterators are generated by this context object too. Iterating over the sequence defined by the two iterators will return the preprocessed tokens, which are to be built on the fly from the given input stream.

The C++ preprocessor iterator itself is feeded by a C++ lexer iterator, which implements an unified interface. BTW, the C++ lexers contained with the Wave library may be used standalone too and are not tied to the C++ preprocessor iterator at all.

To make the C++ preprocessing library modular, the C++ lexer is held completely separate and independend from the preprocessor. To proof this concept, there are two different C++ lexers implemented by now, which are functionally completely identical. The C++ lexers expose the mentioned unified interface, so that the C++ preprocessor iterator may be used with both of them. The abstraction of the C++ lexer from the C++ preprocessor iterator library was done to allow to plug in different C++ lexers without the need to reimplement the preprocessor. This will allow for benchmarking and specific finetuning of the process of preprocessing itself.

The first of this C++ lexers is implemented with the help of the wellknown re2c [3] tool, which generates C code from given regular expressions. The lexers generated with re2c are known to be very fast, because they are not table driven but the whole token building logic is coded directly (very similar to hand coded lexers).

The second of this C++ lexers is build around a table driven lexer, where the DFA tables are generated from regular expressions with the help of a Spirit based lexer generating framework named Slex [5]. The Slex is feeded during runtime with the token definitions (regular expressions) and generates the resulting DFA table. This table is used to combine the input characters into corresponding lexems (tokens). The generated DFA table can be saved to disc to avoid the generation process at program startup.

It is possible to build other C++ lexers if needed. Currently there are plans to adapt the Spirit C++ lexer example cpplexer [6], which is completely based on static Spirit[4] grammars.

In fact both of the embedded lexers and the library itself is able to act in a C99 compliant mode. In this mode the lexers reject C++ only tokens ('::', '->*', '.*' and the alternate keywords as 'and' etc.). The preprocessor additionally handles placemarkers (empty macro arguments) and variadics (macros with variable parameter count). As an extension to the C++ Standard the library can be enabled to handle placemarkers and variadics in the C++ mode too.


Last updated: Tuesday, April 1, 2003 12:25