Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/wave/doc/samples.html @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 10.0 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2<html>
3<head>
4<title>Samples</title>
5<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
6<link rel="stylesheet" href="theme/style.css" 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">
13      <h1></h1></td>
14    <td width="885"> <font face="Verdana, Arial, Helvetica, sans-serif"><b><font size="6">Samples</font></b></font></td>
15    <td width="96"><a href="http://www.boost.org"><img src="theme/wave.gif" width="93" height="68" align="right" border="0"></a></td>
16  </tr>
17</table>
18<br>
19<table border="0">
20  <tr>
21    <td width="10"></td>
22    <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
23    <td width="30"><a href="wave_driver.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
24    <td width="30"><a href="references.html"><img src="theme/r_arr.gif" border="0"></a></td>
25  </tr>
26</table>
27<p dir="ltr">The <tt>Wave</tt> library contains several samples illustrating how to use the different features. This section describes these samples and its main characteristics. </p>
28<h2 dir="ltr">The quick_start sample</h2>
29 <p>The <tt>quick_start</tt> sample shows a minimal way to use the <tt>Wave</tt> preprocessor library. It simply opens the file given as the first command line argument, preprocesses it assuming that there aren't any additional include paths or macros defined and outputs the textual representation of the tokens generated from the given input file. This sample may be used to introduce yourself to <tt>Wave</tt>, because it does not contain all the potential additional complexity exposed by more complex samples. </p>
30 <h2>The lexed_tokens sample</h2>
31 <p>The <tt>lexed_tokens</tt> sample shows a minimal way to use the C++ lexing component of Wave without using the preprocessor. It opens the file specified as the first command line argument and prints out the contents of the tokens returned from the lexer. </p>
32 <h2>The <strong>cpp_tokens sample </strong></h2>
33<p dir="ltr">The <tt>cpp_tokens</tt> sample dumps out the information contained within the tokens returned from the iterator supplied by the <tt>Wave</tt> library. It shows, how to use the <tt>Wave</tt> library in conjunction with custom lexer and custom token types. The lexer used within this sample is <tt>SLex</tt> <a href="references.html#slex">[5]</a> based, i.e. it <tt></tt> is feeded during runtime (at startup) with the token definitions (regular expressions) and generates a resulting DFA table. This table is used for token identification and is saved to disc afterwards to avoid the table generation process at the next program startup. The name of the file to which the DFA table is saved is <tt>wave_slex_lexer.dfa</tt>. </p>
34<p dir="ltr">The main advantage of this <tt>SLex</tt> based lexer if compared to the default <tt>Re2C</tt> <a href="references.html#re2c">[3]</a> generated lexer is, that it provides not only the line information, where a particular token was recognized, but also the related column position. Otherwise the <tt>SLex</tt> based lexer is functionally fully compatible to the <tt>Re2C</tt> based one, i.e. you always may switch your application to use it, if you additionally need to get the column information back from the preprocessing. </p>
35<p dir="ltr">Since no additional command line parameters are supported by this sample, it won't work well with include files, which aren't located in the same directory as the inspected input file. The command line syntax is straight forward:</p>
36<pre>    cpp_tokens input_file</pre>
37<h2 dir="ltr">The list_includes sample </h2>
38<p dir="ltr">The <tt>list_includes</tt> sample shows how the <tt>Wave</tt> library may be used to generate a include file dependency list for a particular input file. It completely depends on the default library configuration. The command line syntax for this sample is given below: </p>
39<pre>    Usage: list_includes [options] file ...:
40        -h [ --help ]        : print out program usage (this message)
41        -v [ --version ]     : print the version number
42        -I [ --path ] dir    : specify additional include directory
43        -S [ --syspath ] dir : specify additional system include directory
44</pre>
45<p dir="ltr">Please note though, that this sample will output only those include file names, which are visible to the preprocessor, i.e. given the following code snippet, only one of the two include file directives is triggered during preprocessing and for this reason only the corresponding file name is reported by the <tt>list_includes</tt> sample:
46<pre><span class="preprocessor">    #if</span> <span class="keyword">defined</span></span><span class="special">(</span>INCLUDE_FILE_A<span class="special">)</span>
47<span class="preprocessor">    #  include</span> <span class="literal">&quot;file_a.h&quot;</span> 
48<span class="preprocessor">    #else</span>
49<span class="preprocessor">    #  include</span> <span class="literal">&quot;file_b.h&quot;</span>
50<span class="preprocessor">    #endif</span></pre>
51<h2 dir="ltr">The advanced_hooks sample</h2>
52<p dir="ltr">The <tt>advanced_hooks</tt> sample is based on the <tt>quick_start</tt> sample mentioned above. It shows how you may want to use the advanced preprocessing hooks of the <tt>Wave</tt> library to get in the output not only the preprocessed tokens from the evaluated conditional blocks, but also the tokens recognized inside the non-evaluated conditional blocks. To make the generated token stream useful for further processing the tokens from the non-evaluated conditional blocks are commented out. </p>
53<p dir="ltr">Here is a small sample what the <tt>advanced_hooks</tt> sample does. Consider the following input: </p>
54<pre>    <span class="preprocessor">#define</span> TEST 1
55<span class="preprocessor">    #if</span> <span class="keyword">defined</span>(TEST)
56    <span class="string">&quot;TEST was defined: &quot;</span> TEST
57    <span class="preprocessor">#else</span>
58    <span class="string">&quot;TEST was not defined!&quot;</span>
59    <span class="preprocessor">#endif</span></pre>
60<p>which will produce as its output:</p>
61<pre><span class="comment">    //&quot;#if defined(TEST)</span>
62    <span class="string">&quot;TEST was defined: &quot;</span> 1
63    <span class="comment">//&quot;#else</span>
64    <span class="comment">//&quot;TEST was not defined!&quot;</span>
65    <span class="comment">//&quot;#endif</span></pre>
66<p dir="ltr">As you can see, the sample application prints out the conditional directives in a commented out manner as well. </p>
67<h2 dir="ltr">The  wave sample</h2>
68<p dir="ltr">Because of its general usefulness the <tt>wave</tt> sample is not located in the sample directory of the library, but inside the tools directory of Boost. The wave sample is usable as a full fledged preprocessor executable
69  on top of any other C++ compiler. It outputs the textual representation of the
70preprocessed tokens generated from a given input file. It is described in more details <a href="wave_driver.html">here</a>. </p>
71<h2 dir="ltr">The  waveidl sample </h2>
72<p dir="ltr">The main point of the <tt>waveidl</tt> sample is to show, how a completely independent lexer type may be used in conjunction with the default token type of the <tt>Wave</tt> library. The lexer used in this sample is supposed to be used for an IDL language based preprocessor. It is based on the <tt>Re2C</tt> tool too, but recognizes a different set of tokens as the default C++ lexer contained within the <tt>Wave</tt> library. 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 languages, where identifiers of one language may be keywords of others. Certainly this implies to postpone keyword identification after the preprocessing, but allows to use <tt>Wave</tt> for all of the IDL derivatives. </p>
73<p dir="ltr">It is only possible to use the <tt>Wave</tt> library to write an IDL preprocessor, because the token sets for both languages are very similar. The tokens to be recognized by the <tt>waveidl</tt> IDL language preprocessor is nearly a complete subset of the full C++ token set. </p>
74<p dir="ltr">The command line syntax usable for this sample is shown below:</p>
75<pre>  Usage: waveidl [options] [@config-file(s)] file:
76
77
78    Options allowed on the command line only:
79      -h [ --help ]           : print out program usage (this message)
80      -v [ --version ]        : print the version number
81      -c [ --copyright ]      : print out the copyright statement
82      --config-file filepath  : specify a config file (alternatively: @filepath)
83
84       
85    Options allowed additionally in a config file:
86      -o [ --output ] path    : specify a file to use for output instead of stdout
87      -I [ --include ] path   : specify an additional include directory
88      -S [ --sysinclude ] syspath : specify an additional system include directory
89      -D [ --define ] macro[=[value]] : specify a macro to define
90      -P [ --predefine ] macro[=[value]] : specify a macro to predefine
91      -U [ --undefine ] macro : specify a macro to undefine
92</pre>
93<table border="0">
94  <tr>
95    <td width="10"></td>
96    <td width="30"><a href="../index.html"><img src="theme/u_arr.gif" border="0"></a></td>
97    <td width="30"><a href="wave_driver.html"><img src="theme/l_arr.gif" width="20" height="19" border="0"></a></td>
98    <td width="30"><a href="references.html"><img src="theme/r_arr.gif" border="0"></a></td>
99  </tr>
100</table>
101<hr size="1">
102<p class="copyright">Copyright &copy; 2003-2007 Hartmut Kaiser<br>
103    <br>
104<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>
105<span class="updated"></span>
106<p class="copyright"><span class="updated">Last updated:
107  <!-- #BeginDate format:fcAm1m -->Thursday, November 3, 2005  21:32<!-- #EndDate -->
108  </span></p>
109<p>&nbsp;</p>
110</body>
111</html>
Note: See TracBrowser for help on using the repository browser.