|
Boost Users : |
Subject: Re: [Boost-users] Tree traversal in boost spirit
From: Nat Goodspeed (nat_at_[hidden])
Date: 2013-09-30 11:16:55
On Sun, Sep 29, 2013 at 2:12 PM, Olivier Austina
<olivier.austina_at_[hidden]>wrote:
I would like to traverse a parsed tree. The parsing is fine. I am using
> this tutorial :
> http://en.highscore.de/cpp/boost/parser.html
>
> I would like to traverse the parsed tree like classical tree (Pre-order,
> In-order, Post-order) to have data in a given order. Any suggestion will be
> appreciated. Thank you.
>
So if I understand correctly, this is no longer a question about parsing,
it's a question about tree traversal.
Are you saying you want to flatten the tree to process its elements by
iteration, in a particular order?
Consider the same_fringe.cpp example in the coroutine library in the
Subversion trunk:
http://svn.boost.org/svn/boost/trunk/libs/coroutine/example/cpp03/same_fringe.cpp
Look at the traverse() function. This is bound to a particular tree of
nodes and launched as a coroutine. You can then use boost::begin() and
boost::end() on the coroutine object. This permits use with BOOST_FOREACH,
standard algorithms, ...
You can alter processing order simply by writing a traversal function whose
body processes the node's value in different places relative to the
subtrees.
Apologies if I've completely misunderstood your question.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net