PageRenderTime 41ms CodeModel.GetById 16ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/phoenix/doc/html/phoenix/inside/expression/boost_phoenix_define_expression.html

http://hadesmem.googlecode.com/
HTML | 137 lines | 134 code | 3 blank | 0 comment | 0 complexity | cc813e6b6971faa1467227f3523cd1a1 MD5 | raw file
  1<html>
  2<head>
  3<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
  4<title>BOOST_PHOENIX_DEFINE_EXPRESSION</title>
  5<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
  6<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
  7<link rel="home" href="../../../index.html" title="Chapter&#160;1.&#160;Phoenix 3.0">
  8<link rel="up" href="../expression.html" title="Phoenix Expressions">
  9<link rel="prev" href="../expression.html" title="Phoenix Expressions">
 10<link rel="next" href="boost_phoenix_define_expression_vararg.html" title="BOOST_PHOENIX_DEFINE_EXPRESSION_VARARG">
 11</head>
 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
 13<table cellpadding="2" width="100%"><tr>
 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
 15<td align="center"><a href="../../../../../../../index.html">Home</a></td>
 16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
 19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
 20</tr></table>
 21<hr>
 22<div class="spirit-nav">
 23<a accesskey="p" href="../expression.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../expression.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="boost_phoenix_define_expression_vararg.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
 24</div>
 25<div class="section">
 26<div class="titlepage"><div><div><h4 class="title">
 27<a name="phoenix.inside.expression.boost_phoenix_define_expression"></a><a class="link" href="boost_phoenix_define_expression.html" title="BOOST_PHOENIX_DEFINE_EXPRESSION">BOOST_PHOENIX_DEFINE_EXPRESSION</a>
 28</h4></div></div></div>
 29<a name="phoenix.inside.expression.boost_phoenix_define_expression.description"></a><h6>
 30<a name="id623241"></a>
 31          <a class="link" href="boost_phoenix_define_expression.html#phoenix.inside.expression.boost_phoenix_define_expression.description">Description</a>
 32        </h6>
 33<p>
 34          <code class="computeroutput"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION</span></code>
 35          is a macro that can be used to generate all the necessary boilerplate to
 36          create Phoenix Expressions
 37        </p>
 38<a name="phoenix.inside.expression.boost_phoenix_define_expression.synopsis"></a><h6>
 39<a name="id623276"></a>
 40          <a class="link" href="boost_phoenix_define_expression.html#phoenix.inside.expression.boost_phoenix_define_expression.synopsis">Synopsis</a>
 41        </h6>
 42<pre class="programlisting"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION</span><span class="special">(</span>
 43    <span class="special">(</span><span class="identifier">namespace_seq</span><span class="special">)(</span><span class="identifier">name</span><span class="special">)</span>
 44  <span class="special">,</span> <span class="special">(</span><span class="identifier">child_grammar0</span><span class="special">)</span>
 45    <span class="special">(</span><span class="identifier">child_grammar1</span><span class="special">)</span>
 46    <span class="special">...</span>
 47<span class="special">)</span>
 48</pre>
 49<a name="phoenix.inside.expression.boost_phoenix_define_expression.semantics"></a><h6>
 50<a name="id623381"></a>
 51          <a class="link" href="boost_phoenix_define_expression.html#phoenix.inside.expression.boost_phoenix_define_expression.semantics">Semantics</a>
 52        </h6>
 53<p>
 54          The above macro generates the necessary code for an expression <code class="computeroutput"><span class="identifier">name</span></code> in namespace <code class="computeroutput"><span class="identifier">namespace_seq</span></code>.
 55          The sequence of <code class="computeroutput"><span class="special">(</span><span class="identifier">child_grammarN</span><span class="special">)</span></code> declares how many children the expression
 56          will have and what <code class="computeroutput"><span class="identifier">proto</span><span class="special">::</span><span class="identifier">grammar</span></code>
 57          they match.
 58        </p>
 59<p>
 60          The macro should be used at global scope. <code class="computeroutput"><span class="identifier">namespace_seq</span></code>
 61          shall be the sequence of namespaces under which the following symbols will
 62          be defined:
 63        </p>
 64<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">tag</span>
 65<span class="special">{</span>
 66    <span class="keyword">struct</span> <span class="identifier">name</span><span class="special">;</span>
 67<span class="special">}</span>
 68
 69<span class="keyword">namespace</span> <span class="identifier">expression</span>
 70<span class="special">{</span>
 71    <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">A0</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">A1</span> <span class="special">...</span> <span class="keyword">typename</span> <span class="identifier">AN</span><span class="special">&gt;</span>
 72    <span class="keyword">struct</span> <span class="identifier">name</span>
 73        <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">expr</span><span class="special">&lt;</span>
 74            <span class="identifier">tag</span><span class="special">::</span><span class="identifier">name</span>
 75          <span class="special">,</span> <span class="identifier">A0</span>
 76          <span class="special">,</span> <span class="identifier">A1</span>
 77            <span class="special">...</span>
 78          <span class="special">,</span> <span class="identifier">AN</span>
 79        <span class="special">&gt;</span>
 80<span class="special">}</span>
 81
 82<span class="keyword">namespace</span> <span class="identifier">rule</span>
 83<span class="special">{</span>
 84    <span class="keyword">struct</span> <span class="identifier">name</span>
 85        <span class="special">:</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">expr</span><span class="special">&lt;</span>
 86            <span class="identifier">child_grammar0</span>
 87          <span class="special">,</span> <span class="identifier">child_grammar1</span>
 88            <span class="special">...</span>
 89          <span class="special">,</span> <span class="identifier">child_grammarN</span>
 90        <span class="special">&gt;</span>
 91    <span class="special">{};</span>
 92<span class="special">}</span>
 93</pre>
 94<p>
 95          This macros also adds a specialization for <code class="computeroutput"><span class="identifier">meta_grammar</span><span class="special">::</span><span class="identifier">case_</span><span class="special">&lt;</span><span class="identifier">tag</span><span class="special">::</span><span class="identifier">name</span><span class="special">&gt;</span></code>.
 96        </p>
 97<a name="phoenix.inside.expression.boost_phoenix_define_expression.header"></a><h6>
 98<a name="id623869"></a>
 99          <a class="link" href="boost_phoenix_define_expression.html#phoenix.inside.expression.boost_phoenix_define_expression.header">Header</a>
100        </h6>
101<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">phoenix</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">expression</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
102</pre>
103<a name="phoenix.inside.expression.boost_phoenix_define_expression.example"></a><h6>
104<a name="id623951"></a>
105          <a class="link" href="boost_phoenix_define_expression.html#phoenix.inside.expression.boost_phoenix_define_expression.example">Example</a>
106        </h6>
107<p>
108          The example from the previous section can be rewritten as:
109        </p>
110<pre class="programlisting"><span class="identifier">BOOST_PHOENIX_DEFINE_EXPRESSION</span><span class="special">(</span>
111    <span class="special">(</span><span class="identifier">plus</span><span class="special">)</span>
112  <span class="special">,</span> <span class="special">(</span><span class="identifier">meta_grammar</span><span class="special">)</span>               <span class="comment">// Lhs
113</span>    <span class="special">(</span><span class="identifier">meta_grammar</span><span class="special">)</span>               <span class="comment">// Rhs
114</span><span class="special">)</span>
115
116<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">Lhs</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">Rhs</span><span class="special">&gt;</span>
117<span class="keyword">typename</span> <span class="identifier">plus</span><span class="special">&lt;</span><span class="identifier">Lhs</span><span class="special">,</span> <span class="identifier">Rhs</span><span class="special">&gt;::</span><span class="identifier">type</span>
118<span class="identifier">plus</span><span class="special">(</span><span class="identifier">Lhs</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">lhs</span><span class="special">,</span> <span class="identifier">Rhs</span> <span class="keyword">const</span> <span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">)</span>
119<span class="special">{</span>
120    <span class="keyword">return</span> <span class="identifier">expression</span><span class="special">::</span><span class="identifier">plus</span><span class="special">&lt;</span><span class="identifier">Lhs</span><span class="special">,</span> <span class="identifier">Rhs</span><span class="special">&gt;::</span><span class="identifier">make</span><span class="special">(</span><span class="identifier">lhs</span><span class="special">,</span> <span class="identifier">rhs</span><span class="special">);</span>
121<span class="special">}</span>
122</pre>
123</div>
124<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
125<td align="left"></td>
126<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2010 Joel de Guzman, Dan Marsden, Thomas Heller<p>
127        Distributed under the Boost Software License, Version 1.0. (See accompanying
128        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
129      </p>
130</div></td>
131</tr></table>
132<hr>
133<div class="spirit-nav">
134<a accesskey="p" href="../expression.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../expression.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="boost_phoenix_define_expression_vararg.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
135</div>
136</body>
137</html>