| Introduction | ![]() |
![]() |
![]() |
The Wave C++ preprocessor library is a Standards conformant implementation of the mandated C++ preprocessor functionality packed behind a simple to use interface, which integrates well with the well known idioms of the Standard Template Library (STL).
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 and aIDL lexer 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.
Wave may be used for preprocessing IDL files too, since the token set needed for the IDL language is very similar to the C++ token set. That's the reason, why the Wave preprocessor library contains also an IDL lexer. The IDL lexer is based on the re2c tool too, but recognizes a different set of tokens. So this lexer does not recognize any keywords (except true and false, which are needed by the preprocessor itself). This is needed because there exist different IDL languages, where identifiers of one language may be keywords of others. Ok, this implies to postpone keyword identification after the preprocessing, but allows to use Wave for all of the IDL derivatives.
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.
![]() |
![]() |
Copyright © 2003-2004 Hartmut Kaiser
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)