Click here to Skip to main content
15,860,972 members
Articles / Programming Languages / C++

Wave: a Standard conformant C++ preprocessor library

Rate me:
Please Sign up or sign in to vote.
4.96/5 (58 votes)
10 Jan 200413 min read 392.1K   4.4K   81  
Describes a free and fully Standard conformant C++ preprocessor library
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Preface</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">Preface</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"><img src="theme/l_arr_disabled.gif" width="20" height="19" border="0"></td>
    <td width="20"><a href="introduction.html"><img src="theme/r_arr.gif" border="0"></a></td>
  </tr>
</table>
<p>During the last time many new features were developed as additions to the <tt>Spirit</tt> 
  <a href="references.html#spirit">[4]</a> parser construction framework and we 
  felt more and more, that it would be very helpful, to have a 'real world' example, 
  which could be used as a sandbox for testing the usability of certain features. 
  Additionally&nbsp;a recent discussion on the Boost mailing list showed the widespread 
  interest of developers to have a modern, open source C++ preprocessor library 
  to play with.&nbsp; So we had the idea to implement a C++ preprocessor to fit 
  this needs&nbsp;-&nbsp;<tt>Wave</tt> was born.</p>
<p align="justify">The <tt>Wave</tt> C++ preprocessor library uses the <a href="http://spirit.sourceforge.net/"> 
  </a> <tt>Spirit<a href="references.html#spirit">[4]</a></tt> parser construction 
  library to implement a C++ lexer with ISO/ANSI standard conformant preprocessing 
  capabilities. It exposes an iterator interface, which returns the current preprocessed 
  token from the input stream. This preprocessed token is generated on the fly 
  while iterating over the preprocessor iterator sequence (in the terminology 
  of the STL these iterators are forward iterators). </p>
<p align="justify"> The C++ preprocessor is a macro processor that under normal 
  circumstances is used automatically by your C++ compiler to transform your program 
  before actual compilation. It is called a macro processor because it allows 
  you to define macros, which are brief abbreviations for longer constructs. The 
  C++ preprocessor provides four separate facilities that you can use as you see 
  fit: </p>
<blockquote> 
  <p><b><img src="theme/bullet.gif" width="13" height="13" id="IMG1">&nbsp;</b>Inclusion 
    of header files<br>
    <b><img src="theme/bullet.gif" width="13" height="13" id="IMG1">&nbsp;</b>Macro 
    expansion<br>
    <b><img src="theme/bullet.gif" width="13" height="13" id="IMG1">&nbsp;</b>Conditional 
    compilation<br>
    <b><img src="theme/bullet.gif" width="13" height="13" id="IMG1">&nbsp;</b>Line 
    control</p>
</blockquote>
<p>These features are greatly underestimated today, even more, the preprocessor 
  has been frowned on for so long that its usage just hasn't been effectively 
  pushed until the Boost preprocessor library <a href="references.html#pp_lib">[7]</a> 
  came into being a few years ago. Only today we begin to understand, that preprocessor 
  generative metaprogramming combined with template metaprogramming in C++ is 
  by far one of the most powerful compile-time reflection/metaprogramming facilities 
  that any language has ever supported.</p>
<p align="justify">The main goals for the <tt>Wave</tt> project are:</p>
<blockquote> 
  <p><b><img src="theme/bullet.gif" width="13" height="13" id="IMG1">&nbsp;</b>full 
    conformance with the C++ standard (ISO/IEC 14882:1998) <a href="references.html#iso_cpp">[1]</a> 
    and with the C99 standard (INCITS/ISO/IEC 9899:1999) <a href="references.html#iso_c">[2]</a><br>
    <b><img src="theme/bullet.gif" width="13" height="13">&nbsp;</b>usage of <tt>Spirit<a href="references.html#spirit">[4]</a></tt> 
    for the parsing parts of the game (certainly :-)<br>
    <b><img src="theme/bullet.gif" width="13" height="13">&nbsp;</b>maximal usage 
    of STL and/or <tt>Boost</tt> libraries (for compactness and maintainability)<br>
    <b><img src="theme/bullet.gif" width="13" height="13">&nbsp;</b>straightforward 
    extendability for the implementation of additional features<br>
    <b><img src="theme/bullet.gif" width="13" height="13">&nbsp;</b>building a 
    flexible library for different C++ lexing and preprocessing needs</p>
</blockquote>
<p>At the first steps it is not planned to make a very high performance or very 
  small C++ preprocessor. If you are looking for these objectives you probably 
  have to look at other places. Although our C++ preprocessor iterator should 
  work as expected and will be usable as a reference implementation, for instance 
  for testing of other preprocessor oriented libraries as the Boost Preprocessor 
  library <a href="references.html#pp_lib">[7]</a> et.al.</p>
<p>As tests showed, the <tt>Wave</tt> library is very conformant to the C++ Standard, 
  such that it compiles several strict conformant macro definitions, which are 
  not even compilable with EDG based preprocessors (i.e. Comeau or Intel). It 
  is shown further, that the EDG preprocessor will outperform the <tt>Wave</tt> 
  preprocessor in simple cases. However, as complexity increases, time dilates 
  expontentially on EDG. Preprocessing time dilates linearly under <tt>Wave</tt>, 
  which causes it to easily outperform EDG based preprocessors when complexity 
  increases.</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"><img src="theme/l_arr_disabled.gif" width="20" height="19" border="0"></td>
    <td width="20"><a href="introduction.html"><img src="theme/r_arr.gif" border="0"></a></td>
  </tr>
</table>
<hr size="1">
<p class="copyright">Copyright &copy; 2003 Hartmut Kaiser<br>
  <br>
  <font size="2">Permission to copy, use, modify, sell and distribute this document 
  is granted provided this copyright notice appears in all copies. This document 
  is provided &quot;as is&quot; without express or implied warranty, and with 
  no claim as to its suitability for any purpose. </font> </p>
<span class="updated">Last updated: 
  <!-- #BeginDate format:fcAm1m -->Saturday, May 10, 2003  21:49<!-- #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


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

Comments and Discussions