0

What additional data structures should be organized in order to take the first derivative of an abstract source tree (for string math expression)? Let's say, we have a tree for the string expression, which was built using boost::spirit. I.e each node have appropriate BOOST_FUSION_ADAPT_STRUCT/BOOST_FUSION_ADAPT_TPL_STRUCT definition. So, how to store an additional produced data struct-s to each node of primary AST and how they should be constructed?

I think, that they should be constructed via std::reference_wrapper< T const & > or boost::optional< T const & > to the fields (of type T) of original struct-s with the same layout. And they should form the arrays/vectors/deques for each node of source tree (where index is equal to n-th derivative of corresponding node of source tree). Each tree traverse with "derivator-visitor" should push_backs the next expression to each array for each node. In order to establish the correspondence of source nodes to arrays of theirs derivatives we can make they tagged.

Tomilov Anatoliy
  • 15,657
  • 10
  • 64
  • 169
  • 4
    It's hard to follow your sentences. – dhein Sep 26 '13 at 10:58
  • 3
    A sample speaks a thousand words – sehe Sep 26 '13 at 12:18
  • Are you trying to attach "extra" information to AST nodes? Perhaps see [Boost::Spirit::QI parser: index of parsed element](http://stackoverflow.com/a/12772075/85371). There are more examples (e.g. the compiler tutorials use `on_error(success,...)` to attach source locations to AST nodes) – sehe Sep 26 '13 at 12:52
  • @sehe I know, that I can tag every node, that I want as showed in `annotation.hpp` in **conjure** example. But it's not much easier task. – Tomilov Anatoliy Sep 26 '13 at 14:03
  • @Zaibis You can skip the second part of the question (my own proposal), as it is written to formally comply with the topical rules. – Tomilov Anatoliy Sep 26 '13 at 14:05
  • @sehe `on_error< success >(...)` is correct – Tomilov Anatoliy Sep 26 '13 at 16:48

0 Answers0