Boost logo

Boost Users :

Subject: Re: [Boost-users] spirit::qi action with Variant
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2010-06-30 21:55:55


> I want to write a const-expression parser which calculate the result while
> parsing. When do it with double and int, I don't know how to do, my code
> like:
>
> namespace b=boost;
> namespace bs=boost::spirit;
> namespace bsq=boost::spirit::qi;
> namespace bp=boost::phoenix;
>
> bsq::real_parser<double,bsq::strict_real_policies<double> > bnf_double;
> bsq::int_parser<int, 8, 1, -1> bnf_int8; bsq::int_parser<int, 10, 1, -1>
> bnf_int10; bsq::int_parser<int, 16, 1, -1> bnf_int16;
>
> template <typename Iterator>
> struct const_expression: bsq::grammar<Iterator,b::variant<int,double>()>
> {
>     typedef b::variant<int,double> result_type;
>     const_expression() : const_expression::base_type(rstart)
>     {
>         using bsq::_val;
>         using bsq::_1;
>         using bsq::_a;
>         result_type result;
>         rstart =
>             bnf_double[_val=_1] >>
>                 *(
>                     bsq::lit('+') >> bnf_double[how to write here]

                                                  [_val += _1] ?
>                 )
>             | rint [_val=_1]
>             ;
>
>         rint =
>             bsq::lit('0') >> bsq::char_("xX") >> bnf_int16[_val=_1]
>             | bsq::lit('0') >> bnf_int8[_val=_1]
>             | bnf_int10[_val=_1]
>             ;
>     }
>
>     bsq::rule<Iterator, result_type()> rstart;
>     bsq::rule<Iterator, int()> rint;
> };

Regards Hartmut

---------------
Meet me at BoostCon
www.boostcon.com


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