Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Wave: a Standard conformant C++ preprocessor library

, 10 Jan 2004
Describes a free and fully Standard conformant C++ preprocessor library
wave_preprocessor_demo.zip
wave.exe
wave_preprocessor_demo1.zip
wave.exe
wave_preprocessor_src.zip
wave
doc
theme
bkd.gif
bkd2.gif
bullet.gif
l_arr.gif
l_arr_disabled.gif
r_arr.gif
r_arr_disabled.gif
uc.gif
u_arr.gif
wave.gif
test
boost-build.jam
cpp_tokens
Jamfile.v2
list_includes
project-root.jam
wave
Jamfile
Jamfile.v2
runtests.sh
test_files
wave
cpplexer
re2clex
cpp.re
test
lextest.in
lextest.output
run_tests.sh
test_lexer.in
test_lexer.output
slex
test
lextest.in
lextest.re2c.output
lextest.slex.output
run_tests.sh
grammars
idllexer
re2clex
idl.re
util
wave_preprocessor_src1.zip
bkd.gif
bkd2.gif
bullet.gif
l_arr.gif
l_arr_disabled.gif
r_arr.gif
r_arr_disabled.gif
u_arr.gif
uc.gif
wave.gif
boost-build.jam
Jamfile.v2
project-root.jam
Jamfile
Jamfile.v2
runtests.sh
cpp.re
lextest.in
lextest.output
run_tests.sh
test_lexer.in
test_lexer.output
lextest.in
lextest.re2c.output
lextest.slex.output
run_tests.sh
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Introduction</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="theme/style.css" rel="stylesheet" type="text/css">
</head>

<body text="#000000" background="theme/bkd.gif">
<table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif">
  <tr> 
    <td width="21"> <h1></h1></td>
    <td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Introduction</font></b></font></td>
    <td width="96"><a href="http://spirit.sf.net"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
  </tr>
</table>
<br>
<table border="0">
  <tr> 
    <td width="10"></td>
    <td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
    <td width="30"><a href="preface.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
    <td width="30"><a href="quickstart.html"><img src="theme/r_arr.gif" border="0"></a></td>
  </tr>
</table>
<P dir="ltr">The <tt>Wave</tt> 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).</P>
<P dir="ltr">The <tt>Wave</tt> 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. </P>
<P dir="ltr"> The C++ preprocessor iterator itself is feeded by a C++ lexer iterator, 
  which implements an unified interface. BTW, the C++ lexers contained with the 
  <tt>Wave</tt> library may be used standalone too and are not tied to the C++ 
  preprocessor iterator at all. </P>
<P dir="ltr">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,&nbsp;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.</P>
<P dir="ltr">The first of this C++ lexers is implemented with the help of the 
  wellknown <tt>re2c</tt> <a href="references.html#re2c">[3]</a> tool, which generates 
  C code from given regular expressions. The lexers generated with <tt>re2c</tt> 
  are known to be very fast, because they are not&nbsp;table driven but the whole 
  token building logic is coded directly (very similar to hand coded lexers). 
</P>
<P dir="ltr">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 <tt>Slex</tt> <a href="references.html#slex">[5]</a>. 
  The <tt>Slex</tt> 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.</P>
<P dir="ltr">It is possible to build other C++ lexers if needed. Currently there 
  are plans to adapt the <tt>Spirit</tt> C++ lexer example <tt>cpplexer</tt> <a href="references.html#cpplexer">[6]</a>, 
  which is completely based on static <tt>Spirit<a href="references.html#spirit">[4]</a></tt> 
  grammars.</P>
<P dir="ltr">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 
  (<tt>'::'</tt>, <tt>'-&gt;*'</tt>, <tt>'.*'</tt> and the alternate keywords 
  as <tt>'and'</tt> 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.</P>
<table border="0">
  <tr> 
    <td width="10"></td>
    <td width="30"><a href="index.html"><img src="theme/u_arr.gif" border="0"></a></td>
    <td width="30"><a href="preface.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
    <td width="30"><a href="quickstart.html"><img src="theme/r_arr.gif" border="0"></a></td>
  </tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003-2004 Hartmut Kaiser<br>
  <br>
  <font size="2">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) 
  </font> </p>
<span class="updated">Last updated: 
  <!-- #BeginDate format:fcAm1m -->Monday, January 5, 2004  14:57<!-- #EndDate -->
  </span>  </body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Hartmut Kaiser

United States United States
Actively involved in Boost and the development of the Spirit parser construction framework.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 11 Jan 2004
Article Copyright 2003 by Hartmut Kaiser
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid