这是一个示例代码
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <iostream>
#include <string>
namespace qi = boost::spirit::qi;
template <typename Iterator>
struct input : qi::grammar<Iterator, unsigned()>
{
input() : input::base_type(start)
{
using qi::lit;
using qi::double_;
start = lit("ADD")
>> +(
+lit(" ")
>> double_
>> +lit(" ")
>> double_
);
}
qi::rule<Iterator, unsigned()> start;
};
int main()
{
input<std::string::const_iterator> input_parser; // Our grammar
std::string str = "ADD 1132.324 2342.234";
unsigned result;
std::string::const_iterator iter = str.begin();
std::string::const_iterator end = str.end();
bool r = qi::parse(iter, end, input_parser, result);
}
我收到以下错误。
/usr/local/include/boost/spirit/home/qi/nonterminal/rule.hpp:201: 实例化自‘boost::spirit::qi::rule& boost::spirit::qi::rule:: operator=(const Expr&) [with Expr = boost::proto::exprns_::expr&, const boost::proto::exprns_::expr&>, 1l>&, const boost::spirit::terminal&>, 2l> &, const boost::proto::exprns_::expr&>, 1l>&>, 2l>&, const boost::spirit::terminal&>, 2l>&>, 1l>&>, 2l>, Iterator = __gnu_cxx ::__normal_iterator, std::allocator >>, T1 = unsigned int ()(), T2 = boost::fusion::unused_type, T3 = boost::fusion::unused_type, T4 = boost::fusion::unused_type] ’ mini.c++:34:从“input::input() [with Iterator = __gnu_cxx::__normal_iterator, std::allocator >]” mini 实例化。c++:49: 从这里实例化 /usr/local/include/boost/spirit/home/qi/operator/plus.hpp:62: error: no type named 'type' in 'struct boost::spirit ::traits::container_value——</p>
奇怪的是,如果我使用减号(-)操作,即
start = lit("ADD")
>> -(
+lit(" ")
>> double_
>> +lit(" ")
>> double_
);
...它编译得很好!
在 gcc 4.3.4 上编译。