[29] | 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
---|
| 2 | <html> |
---|
| 3 | <head> |
---|
| 4 | <title>Introduction</title> |
---|
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
| 6 | <link href="theme/style.css" rel="stylesheet" type="text/css"> |
---|
| 7 | </head> |
---|
| 8 | |
---|
| 9 | <body text="#000000" background="theme/bkd.gif"> |
---|
| 10 | <table width="100%" border="0" cellspacing="2" background="theme/bkd2.gif"> |
---|
| 11 | <tr> |
---|
| 12 | <td width="21"> <h1></h1></td> |
---|
| 13 | <td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Introduction</font></b></font></td> |
---|
| 14 | <td width="96"><a href="http://www.boost.org"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td> |
---|
| 15 | </tr> |
---|
| 16 | </table> |
---|
| 17 | <br> |
---|
| 18 | <table border="0"> |
---|
| 19 | <tr> |
---|
| 20 | <td width="10"></td> |
---|
| 21 | <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td> |
---|
| 22 | <td width="30"><a href="preface.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td> |
---|
| 23 | <td width="30"><a href="quickstart.html"><img src="theme/r_arr.gif" border="0"></a></td> |
---|
| 24 | </tr> |
---|
| 25 | </table> |
---|
| 26 | <P dir="ltr">The <tt>Wave</tt> C++ preprocessor library is a Standards conformant |
---|
| 27 | implementation of the mandated C99/C++ preprocessor functionality packed behind |
---|
| 28 | a simple to use interface, which integrates well with the well known idioms |
---|
| 29 | of the Standard Template Library (STL).</P> |
---|
| 30 | <P dir="ltr">The <tt>Wave</tt> C++ preprocessor is not a monolithic application, |
---|
| 31 | it's rather a modular library, which exposes mainly a context object and an |
---|
| 32 | iterator interface. The context object helps to configure the actual preprocessing |
---|
| 33 | process (as search path's, predefined macros, etc.). The exposed iterators are |
---|
| 34 | generated by this context object too. Iterating over the sequence defined by |
---|
| 35 | the two iterators will return the preprocessed tokens, which are to be built |
---|
| 36 | on the fly from the given input stream. </P> |
---|
| 37 | <P dir="ltr"> The C++ preprocessor iterator itself is fed by a C++ lexer iterator, |
---|
| 38 | which implements an abstract interface. The C++ lexers packaged with the |
---|
| 39 | <tt>Wave</tt> library may be used standalone, too, and are not tied to the C++ |
---|
| 40 | preprocessor iterator at all. </P> |
---|
| 41 | <P dir="ltr">To make the C++ preprocessing library modular, the C++ lexer is held |
---|
| 42 | completely separate and independent from the preprocessor. To prove this concept, |
---|
| 43 | two different, but functionally identical C++ lexers were |
---|
| 44 | implemented. Additionally there is implemented a IDL lexer, which allows to use the preprocessor library as the lexing component of a IDL oriented tool. All these lexers implement the mentioned abstract interface, |
---|
| 45 | so that the C++ preprocessor iterator may be used with all of them. The abstraction |
---|
| 46 | of the lexer from the preprocessor iterator library was done to allow |
---|
| 47 | plugging in different lexers without the need to reimplement the preprocessor. |
---|
| 48 | This will allow for benchmarking and specific fine tuning of the process of preprocessing |
---|
| 49 | itself.</P> |
---|
| 50 | <P dir="ltr">The first of these C++ lexers is implemented with the help of the |
---|
| 51 | well known <tt>Re2C</tt> <a href="references.html#re2c">[3]</a> tool, which generates |
---|
| 52 | C code from given regular expressions. The lexers generated with <tt>Re2C</tt> |
---|
| 53 | are known to be very fast, because they are not table driven but directly code the token building logic |
---|
| 54 | (very similar to hand coded lexers). |
---|
| 55 | </P> |
---|
| 56 | <P dir="ltr">The second of these C++ lexers is built around a table driven lexer, |
---|
| 57 | where the DFA tables (discrete finite automaton tables) are generated from regular expressions with the help of |
---|
| 58 | a Spirit-based lexer generating framework named <tt>Slex</tt> <a href="references.html#slex">[5]</a>. |
---|
| 59 | The <tt>Slex</tt> is fed during runtime with the token definitions (regular |
---|
| 60 | expressions) and generates the resulting DFA table. This table is used to combine |
---|
| 61 | the input characters into corresponding lexemes (tokens). The generated DFA table |
---|
| 62 | can be saved to disk to avoid the generation process at program startup.</P> |
---|
| 63 | <P dir="ltr">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 <tt>Wave</tt> preprocessor library contains also an IDL lexer. The IDL lexer is also based on the <tt>Re2C</tt> tool, but recognizes a different set of tokens. So this lexer does not recognize any keywords (except <tt>true</tt> and <tt>false</tt>, which are needed by the preprocessor itself). This is needed because there exist different IDL language flavours, where identifiers of one flavour may be keywords of others - Ok, this requires postponement of keyword identification until after the |
---|
| 64 | preprocessing, but allows to use Wave for all of the IDL derivatives. </P> |
---|
| 65 | <P dir="ltr">It is possible to build other C++ lexers if needed. Currently there |
---|
| 66 | are plans to adapt the <tt>Spirit</tt> C++ lexer example <tt>cpplexer</tt> <a href="references.html#cpplexer">[6]</a>, |
---|
| 67 | which is completely based on static <tt>Spirit<a href="references.html#spirit">[4]</a></tt> |
---|
| 68 | grammars.</P> |
---|
| 69 | <P dir="ltr">Both of the included lexers and the library itself are able |
---|
| 70 | to act in a C99 compliant mode. In this mode the lexers reject C++-only tokens |
---|
| 71 | (<tt>'::'</tt>, <tt>'->*'</tt>, <tt>'.*'</tt> and the alternate keywords |
---|
| 72 | such as <tt>'and'</tt>, etc.). The preprocessor additionally handles placemarkers |
---|
| 73 | (empty macro arguments) and variadics (macros with variable parameter counts). |
---|
| 74 | As an extension to the C++ Standard, the library can be enabled to handle placemarkers |
---|
| 75 | and variadics in C++ mode too.</P> |
---|
| 76 | <table border="0"> |
---|
| 77 | <tr> |
---|
| 78 | <td width="10"></td> |
---|
| 79 | <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td> |
---|
| 80 | <td width="30"><a href="preface.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td> |
---|
| 81 | <td width="30"><a href="quickstart.html"><img src="theme/r_arr.gif" border="0"></a></td> |
---|
| 82 | </tr> |
---|
| 83 | </table> |
---|
| 84 | <hr size="1"> |
---|
| 85 | <p class="copyright">Copyright © 2003-2007 Hartmut Kaiser<br> |
---|
| 86 | <br> |
---|
| 87 | <font size="2">Distributed under 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> |
---|
| 88 | <span class="updated"></span> |
---|
| 89 | <p class="copyright"><span class="updated">Last updated: |
---|
| 90 | <!-- #BeginDate format:fcAm1m -->Wednesday, December 14, 2005 10:58<!-- #EndDate --> |
---|
| 91 | </span> </p> |
---|
| 92 | </body> |
---|
| 93 | </html> |
---|