• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Nonterminals</title>
5<link rel="stylesheet" href="../../../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../index.html" title="Spirit 2.5.8">
8<link rel="up" href="../quick_reference.html" title="Quick Reference">
9<link rel="prev" href="compound_attribute_rules.html" title="Compound Attribute Rules">
10<link rel="next" href="semantic_actions.html" title="Generator Semantic Actions">
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="compound_attribute_rules.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../quick_reference.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="semantic_actions.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="spirit.karma.quick_reference.non_terminals"></a><a class="link" href="non_terminals.html" title="Nonterminals">Nonterminals</a>
28</h4></div></div></div>
29<p>
30          See here for more information about <a class="link" href="../reference/nonterminal.html" title="Nonterminal Generators"><code class="computeroutput"><span class="identifier">Nonterminals</span></code></a>.
31        </p>
32<div class="variablelist">
33<p class="title"><b>Notation</b></p>
34<dl class="variablelist">
35<dt><span class="term"><code class="computeroutput"><span class="identifier">RT</span></code></span></dt>
36<dd><p>
37                Synthesized attribute. The rule or grammar's return type.
38              </p></dd>
39<dt><span class="term"><code class="computeroutput"><span class="identifier">Arg1</span></code>, <code class="computeroutput"><span class="identifier">Arg2</span></code>, <code class="computeroutput"><span class="identifier">ArgN</span></code></span></dt>
40<dd><p>
41                Inherited attributes. Zero or more arguments.
42              </p></dd>
43<dt><span class="term"><code class="computeroutput"><span class="identifier">L1</span></code>, <code class="computeroutput"><span class="identifier">L2</span></code>, <code class="computeroutput"><span class="identifier">LN</span></code></span></dt>
44<dd><p>
45                Zero or more local variables.
46              </p></dd>
47<dt><span class="term"><code class="computeroutput"><span class="identifier">r</span><span class="special">,</span>
48            <span class="identifier">r2</span></code></span></dt>
49<dd><p>
50                Rules
51              </p></dd>
52<dt><span class="term"><code class="computeroutput"><span class="identifier">g</span></code></span></dt>
53<dd><p>
54                A grammar
55              </p></dd>
56<dt><span class="term"><code class="computeroutput"><span class="identifier">p</span></code></span></dt>
57<dd><p>
58                A generator expression
59              </p></dd>
60<dt><span class="term"><code class="computeroutput"><span class="identifier">my_grammar</span></code></span></dt>
61<dd><p>
62                A user defined grammar
63              </p></dd>
64</dl>
65</div>
66<div class="variablelist">
67<p class="title"><b>Terminology</b></p>
68<dl class="variablelist">
69<dt><span class="term">Signature</span></dt>
70<dd><p>
71                <code class="computeroutput"><span class="identifier">RT</span><span class="special">(</span><span class="identifier">Arg1</span><span class="special">,</span>
72                <span class="identifier">Arg2</span><span class="special">,</span>
73                <span class="special">...</span> <span class="special">,</span><span class="identifier">ArgN</span><span class="special">)</span></code>.
74                The signature specifies the synthesized (return value) and inherited
75                (arguments) attributes.
76              </p></dd>
77<dt><span class="term">Locals</span></dt>
78<dd><p>
79                <code class="computeroutput"><span class="identifier">locals</span><span class="special">&lt;</span><span class="identifier">L1</span><span class="special">,</span> <span class="identifier">L2</span><span class="special">,</span> <span class="special">...,</span> <span class="identifier">LN</span><span class="special">&gt;</span></code>. The local variables.
80              </p></dd>
81<dt><span class="term">Delimiter</span></dt>
82<dd><p>
83                The delimit-generator type
84              </p></dd>
85</dl>
86</div>
87<div class="variablelist">
88<p class="title"><b>Template Arguments</b></p>
89<dl class="variablelist">
90<dt><span class="term"><code class="computeroutput"><span class="identifier">Iterator</span></code></span></dt>
91<dd><p>
92                The iterator type you will use for parsing.
93              </p></dd>
94<dt><span class="term"><code class="computeroutput"><span class="identifier">A1</span></code>, <code class="computeroutput"><span class="identifier">A2</span></code>, <code class="computeroutput"><span class="identifier">A3</span></code></span></dt>
95<dd><p>
96                Can be one of 1) Signature 2) Locals 3) Delimiter.
97              </p></dd>
98</dl>
99</div>
100<div class="informaltable"><table class="table">
101<colgroup>
102<col>
103<col>
104</colgroup>
105<thead><tr>
106<th>
107                  <p>
108                    Expression
109                  </p>
110                </th>
111<th>
112                  <p>
113                    Description
114                  </p>
115                </th>
116</tr></thead>
117<tbody>
118<tr>
119<td>
120                  <p>
121                    <code class="computeroutput"><span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">OutputIterator</span><span class="special">,</span>
122                    <span class="identifier">A1</span><span class="special">,</span>
123                    <span class="identifier">A2</span><span class="special">,</span>
124                    <span class="identifier">A3</span><span class="special">&gt;</span>
125                    <span class="identifier">r</span><span class="special">(</span><span class="identifier">name</span><span class="special">);</span></code>
126                  </p>
127                </td>
128<td>
129                  <p>
130                    Rule declaration. <code class="computeroutput"><span class="identifier">OutputIterator</span></code>
131                    is required. <code class="computeroutput"><span class="identifier">A1</span><span class="special">,</span> <span class="identifier">A2</span><span class="special">,</span> <span class="identifier">A3</span></code>
132                    are optional and can be specified in any order. <code class="computeroutput"><span class="identifier">name</span></code> is an optional string
133                    that gives the rule its name, useful for debugging.
134                  </p>
135                </td>
136</tr>
137<tr>
138<td>
139                  <p>
140                    <code class="computeroutput"><span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">OutputIterator</span><span class="special">,</span>
141                    <span class="identifier">A1</span><span class="special">,</span>
142                    <span class="identifier">A2</span><span class="special">,</span>
143                    <span class="identifier">A3</span><span class="special">&gt;</span>
144                    <span class="identifier">r</span><span class="special">(</span><span class="identifier">r2</span><span class="special">);</span></code>
145                  </p>
146                </td>
147<td>
148                  <p>
149                    Copy construct rule <code class="computeroutput"><span class="identifier">r</span></code>
150                    from rule <code class="computeroutput"><span class="identifier">r2</span></code>.
151                  </p>
152                </td>
153</tr>
154<tr>
155<td>
156                  <p>
157                    <code class="computeroutput"><span class="identifier">r</span> <span class="special">=</span>
158                    <span class="identifier">r2</span><span class="special">;</span></code>
159                  </p>
160                </td>
161<td>
162                  <p>
163                    Assign rule <code class="computeroutput"><span class="identifier">r2</span></code>
164                    to <code class="computeroutput"><span class="identifier">r</span></code>. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">shared_ptr</span></code> semantics.
165                  </p>
166                </td>
167</tr>
168<tr>
169<td>
170                  <p>
171                    <code class="computeroutput"><span class="identifier">r</span><span class="special">.</span><span class="identifier">alias</span><span class="special">()</span></code>
172                  </p>
173                </td>
174<td>
175                  <p>
176                    Return an alias of <code class="computeroutput"><span class="identifier">r</span></code>.
177                    The alias is a generator that holds a reference to <code class="computeroutput"><span class="identifier">r</span></code>. Reference semantics.
178                  </p>
179                </td>
180</tr>
181<tr>
182<td>
183                  <p>
184                    <code class="computeroutput"><span class="identifier">r</span><span class="special">.</span><span class="identifier">copy</span><span class="special">()</span></code>
185                  </p>
186                </td>
187<td>
188                  <p>
189                    Get a copy of <code class="computeroutput"><span class="identifier">r</span></code>.
190                  </p>
191                </td>
192</tr>
193<tr>
194<td>
195                  <p>
196                    <code class="computeroutput"><span class="identifier">r</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</span></code>
197                  </p>
198                </td>
199<td>
200                  <p>
201                    Set the name of a rule
202                  </p>
203                </td>
204</tr>
205<tr>
206<td>
207                  <p>
208                    <code class="computeroutput"><span class="identifier">r</span><span class="special">.</span><span class="identifier">name</span><span class="special">()</span></code>
209                  </p>
210                </td>
211<td>
212                  <p>
213                    Get the name of a rule
214                  </p>
215                </td>
216</tr>
217<tr>
218<td>
219                  <p>
220                    debug(r)
221                  </p>
222                </td>
223<td>
224                  <p>
225                    Debug rule <code class="computeroutput"><span class="identifier">r</span></code>
226                  </p>
227                </td>
228</tr>
229<tr>
230<td>
231                  <p>
232                    <code class="computeroutput"><span class="identifier">r</span> <span class="special">=</span>
233                    <span class="identifier">g</span><span class="special">;</span></code>
234                  </p>
235                </td>
236<td>
237                  <p>
238                    Rule definition
239                  </p>
240                </td>
241</tr>
242<tr>
243<td>
244                  <p>
245                    <code class="computeroutput"><span class="identifier">r</span> <span class="special">%=</span>
246                    <span class="identifier">g</span><span class="special">;</span></code>
247                  </p>
248                </td>
249<td>
250                  <p>
251                    Auto-rule definition. The attribute of <code class="computeroutput"><span class="identifier">g</span></code>
252                    should be compatible with the synthesized attribute of <code class="computeroutput"><span class="identifier">r</span></code>. When <code class="computeroutput"><span class="identifier">g</span></code>
253                    is successful, its attribute is automatically propagated to
254                    <code class="computeroutput"><span class="identifier">r</span></code>'s synthesized
255                    attribute.
256                  </p>
257                </td>
258</tr>
259<tr>
260<td>
261                  <p>
262</p>
263<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">OutputIterator</span><span class="special">&gt;</span>
264<span class="keyword">struct</span> <span class="identifier">my_grammar</span> <span class="special">:</span> <span class="identifier">grammar</span><span class="special">&lt;</span><span class="identifier">OutputIterator</span><span class="special">,</span> <span class="identifier">A1</span><span class="special">,</span> <span class="identifier">A2</span><span class="special">,</span> <span class="identifier">A3</span><span class="special">&gt;</span>
265<span class="special">{</span>
266    <span class="identifier">my_grammar</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">my_grammar</span><span class="special">::</span><span class="identifier">base_type</span><span class="special">(</span><span class="identifier">start</span><span class="special">,</span> <span class="identifier">name</span><span class="special">)</span>
267    <span class="special">{</span>
268        <span class="comment">// Rule definitions</span>
269        <span class="identifier">start</span> <span class="special">=</span> <span class="comment">/* ... */</span><span class="special">;</span>
270    <span class="special">}</span>
271
272    <span class="identifier">rule</span><span class="special">&lt;</span><span class="identifier">OutputIterator</span><span class="special">,</span> <span class="identifier">A1</span><span class="special">,</span> <span class="identifier">A2</span><span class="special">,</span> <span class="identifier">A3</span><span class="special">&gt;</span> <span class="identifier">start</span><span class="special">;</span>
273    <span class="comment">// more rule declarations...</span>
274<span class="special">};</span>
275</pre>
276<p>
277                  </p>
278                </td>
279<td>
280                  <p>
281                    Grammar definition. <code class="computeroutput"><span class="identifier">name</span></code>
282                    is an optional string that gives the grammar its name, useful
283                    for debugging.
284                  </p>
285                </td>
286</tr>
287<tr>
288<td>
289                  <p>
290                    my_grammar&lt;OutputIterator&gt; g
291                  </p>
292                </td>
293<td>
294                  <p>
295                    Instantiate a grammar
296                  </p>
297                </td>
298</tr>
299<tr>
300<td>
301                  <p>
302                    <code class="computeroutput"><span class="identifier">g</span><span class="special">.</span><span class="identifier">name</span><span class="special">(</span><span class="identifier">name</span><span class="special">)</span></code>
303                  </p>
304                </td>
305<td>
306                  <p>
307                    Set the name of a grammar
308                  </p>
309                </td>
310</tr>
311<tr>
312<td>
313                  <p>
314                    <code class="computeroutput"><span class="identifier">g</span><span class="special">.</span><span class="identifier">name</span><span class="special">()</span></code>
315                  </p>
316                </td>
317<td>
318                  <p>
319                    Get the name of a grammar
320                  </p>
321                </td>
322</tr>
323</tbody>
324</table></div>
325</div>
326<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
327<td align="left"></td>
328<td align="right"><div class="copyright-footer">Copyright © 2001-2011 Joel de Guzman, Hartmut Kaiser<p>
329        Distributed under the Boost Software License, Version 1.0. (See accompanying
330        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>)
331      </p>
332</div></td>
333</tr></table>
334<hr>
335<div class="spirit-nav">
336<a accesskey="p" href="compound_attribute_rules.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../quick_reference.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="semantic_actions.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
337</div>
338</body>
339</html>
340