Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

A Nonterminal is a symbol in a Parsing Expression Grammar production that represents a grammar fragment. Nonterminals may self reference to specify recursion. This is one of the most important concepts and the reason behind the word "recursive" in recursive descent generation.

Refinement of



Nonterminals can have both consumed and inherited attributes. The Nonterminal's Signature specifies both the consumed and inherited attributes. The specification uses the function declarator syntax:

RT(A0, A1, A2, ..., AN)

where RT is the Nonterminal's consumed attribute and A0 ... AN are the Nonterminal's inherited attributes.

The default value is void() (no consumed and inherited attributes).


The Nonterminal models a C++ function. The Nonterminal's consumed attribute is analogous to the function return value as it is the type -exposed- by the Nonterminal. Its inherited attributes are analogous to function arguments. The inherited attributes (arguments) can be passed in just like any Lazy Argument, e.g.:

r(expr) // Evaluate expr at parse time and pass the result to the Nonterminal r

The boost::spirit::karma::_val placeholder can be used in Boost.Phoenix semantic actions anywhere in the Nonterminal's definition. This Boost.Phoenix placeholder refers to the Nonterminal's (consumed) attribute. The _val placeholder acts like an immutable reference to the Nonterminal's attribute.

[Note] Note

Starting with Spirit V2.5 (distributed with Boost V1.47) the placeholder _val can be used in semantic actions attached to top level generator components as well. See The Generator API for more information.


The boost::spirit::_r1...boost::spirit::r10 placeholders can be used in Boost.Phoenix semantic actions anywhere in the Nonterminal's definition. These Boost.Phoenix placeholders refer to the Nonterminal's inherited attributes.


Nonterminals can have local variables that will be created on the stack at runtime. A locals descriptor added to the Nonterminal declaration will give the Nonterminal local variables:

template <typename T0, typename T1, typename T2, ..., typename TN>
struct locals;

where T0 ... TN are the types of local variables accessible in your Boost.Phoenix semantic actions using the placeholders:

which correspond to the Nonterminal's local variables T0 ... T9.



A Nonterminal


A Nonterminal type

arg1, arg2, ..., argN

Lazy Arguments that evaluate to each of the Nonterminal's inherited attributes.

Valid Expressions

In addition to the requirements defined in Generator, for any Nonterminal the following must be met:



Return type


In a generator expression, invoke Nonterminal x


x(arg1, arg2, ..., argN)

In a generator expression, invoke Nonterminal x passing in inherited attributes arg1...argN


Set the name of a Nonterminal


Get the name of a Nonterminal


Type Expressions




The Signature of X: In a function signature form as described above in the Signature paragraph.


The local variables of X: An MPL Forward Sequence.