It really sounds to me that this problem would be better addressed byOn 13-05-30 08:35 AM, Simon wrote:
> Hi,
> For one part of a large project, I need to parse math and turn the
> "mathematical objects" into a C++ abstraction of them. Is it possible
> that a nested pattern hold semantic values within itself and can be
> queried for that value somehow? As if a match were a function of its
> sub-patterns' matches, if that makes sense...
>
> Code might speak better than my english:
>
> class math_number {...};
> class math_addition {...};
> class math_arglist {...};
> class math_funcdef {...};
>
> sregex integer = (s1= +_d)
> [ return math_number( as<int>(s1) ) ];
>
> sregex addition = (s1= integer) >> '+' >> (s2= integer)
> [ return math_addition( as<math_number>(s1), as<math_number>(s2) ) ];
>
> sregex arglist = (s1= identifier) >> *( ',' >> (s2= arglist))
> [ std::vector<math_id> ids( as<math_arglist>(s2).begin(),
> as<math_arglist>(s2).end() );
> ids.push_back(as<math_id>(s1));
> return ids; ]
>
> sregex funcdef = ((s1= identifier) >> '(' >> (s2= arglist) >> ")=" >>
> (s3= addition))
> [ return math_funcdef( as<math_id>(s1), as<math_arglist>(s2),
> as<math_addition>(s3) ) ];
>
> I just want to avoid the funcdef above to be responsible for the
> construction of the various math_* objects the funcdef will hold (some
> of which will be complex to construct). And if I really must store the
> objects in an external stack, how should the parent-objects find their
> child-objects?
Boost.Spirit and its attributed parsers.
--
Eric Niebler
Boost.org
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users