我试图简单地在这个答案中找到精神解析器:
删除xor
运算符和逻辑。我看不到该怎么做,我尝试使用
expr_ = or_.alias();
or_ = (and__ >> "or" >> or_ )[ _val = phx::construct<binop<op_or >>(_1, _2) ] | and_ [ _val = _1 ];
and_ = (not_ >> "and" >> and_) [ _val = phx::construct<binop<op_and>>(_1, _2) ] | not_ [ _val = _1 ];
not_ = ("not" > simple ) [ _val = phx::construct<unop <op_not>>(_1) ] | simple [ _val = _1 ];
对于规则定义,但我收到一条我不明白的神秘编译器消息:
test\test.cpp `boost::spirit::_2' cannot appear in a constant-expression
如果有人能提供一些启示,我将不胜感激。
这是日志:
compiler: Default compiler Building Makefile:
"D:\Dev-Cpp\test\Makefile.win" Executing make... make.exe -f
"D:\Dev-Cpp\test\Makefile.win" all g++.exe -c test.cpp -o test.o
-I"D:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"D:/Dev-Cpp/include/c++/3.4.2/backward" -I"D:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"D:/Dev-Cpp/include/c++/3.4.2" -I"D:/Dev-Cpp/include"
test.cpp: In constructor `parser<It, Skipper>::parser()':
test.cpp:76: error: `boost::spirit::_1' cannot appear in a
constant-expression test.cpp:76: error: a comma operator cannot
appear in a constant-expression test.cpp:76: error:
`boost::spirit::_2' cannot appear in a constant-expression
test.cpp:76: error: `>>' should be `> >' within a nested template
argument list
test.cpp:77: error: `boost::spirit::_1' cannot appear in a
constant-expression
test.cpp:77: error: a comma operator cannot appear in a
constant-expression test.cpp:77: error: `boost::spirit::_2' cannot
appear in a constant-expression test.cpp:77: error: `>>' should be `>
>' within a nested template argument list
test.cpp:78: error: `boost::spirit::_1' cannot appear in a
constant-expression
test.cpp:78: error: `>>' should be `> >' within a nested template
argument list
test.cpp: In function `int main()': test.cpp:98: error: expected
primary-expression before "auto" test.cpp:98: error: expected `;'
before "auto"
test.cpp:111: error: expected primary-expression before ')' token
test.cpp:111: error: expected `;' before ')' token test.cpp:113:
error: ISO C++ forbids declaration of `f' with no type test.cpp:113:
error: `begin' is not a member of `std' test.cpp:113: error: `input'
undeclared (first use this function) test.cpp:113: error: (Each
undeclared identifier is reported only once for each function it
appears in.) test.cpp:113: error: ISO C++ forbids declaration of `l'
with no type test.cpp:113: error: `end' is not a member of `std'
test.cpp:114: error: `f' cannot appear in a constant-expression
test.cpp:114: error: a function call cannot appear in a
constant-expression test.cpp:114: error: template argument 1 is
invalid test.cpp:114: error: invalid type in declaration before ';'
token
test.cpp:126: error: `f' cannot appear in a constant-expression
test.cpp:126: error: a function call cannot appear in a
constant-expression test.cpp:126: error: template argument 1 is
invalid test.cpp:126: error: ISO C++ forbids declaration of `e' with
no type
test.cpp:128: error: expected primary-expression before '(' token
test.cpp:128: error: `first' has not been declared test.cpp:128:
error: request for member of non-aggregate type before ',' token
test.cpp:128: error: `last' has not been declared test.cpp:128:
error: request for member of non-aggregate type before ')' token
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h: At
global scope:
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h: In
instantiation of `std::iterator_traits<int>':
D:/Dev-Cpp/include/boost/detail/iterator.hpp:83: instantiated from
`boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:509: instantiated from
`boost::InputIterator<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:545: instantiated from
`boost::ForwardIterator<int>'
D:/Dev-Cpp/include/boost/concept/detail/has_constraints.hpp:42:
instantiated from
`boost::concepts::not_satisfied<boost::ForwardIterator<int> >'
D:/Dev-Cpp/include/boost/mpl/if.hpp:67: instantiated from
`boost::mpl::if_<boost::concepts::not_satisfied<boost::ForwardIterator<int>
>, boost::concepts::constraint<boost::ForwardIterator<int> >, boost::concepts::requirement<boost::concepts::failed************boost::ForwardIterator<int>::************>
>' D:/Dev-Cpp/include/boost/concept/detail/general.hpp:56: instantiated from `boost::concepts::requirement_<void
(*)(boost::ForwardIterator<int>)>'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:149: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type,
Attr&) [with Iterator = int, Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h:129:
error: `int' is not a class, struct, or union type
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h:130:
error: `int' is not a class, struct, or union type
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h:131:
error: `int' is not a class, struct, or union type
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h:132:
error: `int' is not a class, struct, or union type
D:/Dev-Cpp/include/c++/3.4.2/bits/stl_iterator_base_types.h:133:
error: `int' is not a class, struct, or union type
D:/Dev-Cpp/include/boost/concept_check.hpp: In instantiation of
`boost::InputIterator<int>':
D:/Dev-Cpp/include/boost/concept_check.hpp:545: instantiated from
`boost::ForwardIterator<int>'
D:/Dev-Cpp/include/boost/concept/detail/has_constraints.hpp:42:
instantiated from
`boost::concepts::not_satisfied<boost::ForwardIterator<int> >'
D:/Dev-Cpp/include/boost/mpl/if.hpp:67: instantiated from
`boost::mpl::if_<boost::concepts::not_satisfied<boost::ForwardIterator<int>
>, boost::concepts::constraint<boost::ForwardIterator<int> >, boost::concepts::requirement<boost::concepts::failed************boost::ForwardIterator<int>::************>
>' D:/Dev-Cpp/include/boost/concept/detail/general.hpp:56: instantiated from `boost::concepts::requirement_<void
(*)(boost::ForwardIterator<int>)>'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:149: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type,
Attr&) [with Iterator = int, Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/boost/concept_check.hpp:509: error: no type named
`value_type' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:510: error: no type named
`difference_type' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:511: error: no type named
`reference' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:512: error: no type named
`pointer' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:513: error: no type named
`iterator_category' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp: In function `bool
boost::spirit::qi::phrase_parse(Iterator&, Iterator, const Expr&,
const Skipper&, boost::spirit::qi::skip_flag::enum_type, Attr&) [with
Iterator = int, Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>]':
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:155: error:
conversion from
`mpl_::failed************(boost::spirit::qi::phrase_parse(Iterator&,
Iterator, const Expr&, const Skipper&,
boost::spirit::qi::skip_flag::enum_type, Attr&) [with Iterator = int,
Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_,
boost::detail::variant::void_>]::error_invalid_expression::************)(bool)'
to non-scalar type `mpl_::assert< false>' requested
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:155: error:
enumerator value for `mpl_assertion_in_line_155' not integer constant
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:164: error: request
for member `parse' in `boost::spirit::compile [with Domain =
boost::spirit::qi::domain, Expr = bool](((const bool&)(+expr)))',
which is of non-class type `bool'
D:/Dev-Cpp/include/boost/concept_check.hpp: In destructor
`boost::ForwardIterator<TT>::~ForwardIterator() [with TT = int]':
D:/Dev-Cpp/include/boost/concept/detail/general.hpp:38:
instantiated from `static void
boost::concepts::requirement<boost::concepts::failed************Model::************>::failed()
[with Model = boost::ForwardIterator<int>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:149: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type,
Attr&) [with Iterator = int, Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/boost/concept_check.hpp:548: error: no type named
`iterator_category' in `struct boost::ForwardIterator<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:548: error: `failed' is
not a member of `<declaration error>'
D:/Dev-Cpp/include/boost/concept_check.hpp:553: error: no type named
`reference' in `struct boost::InputIterator<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:554: error: no type named
`reference' in `struct boost::InputIterator<int>'
D:/Dev-Cpp/include/boost/spirit/home/qi/char/char_parser.hpp: In
member function `bool boost::spirit::qi::char_parser<Derived, Char,
Attr>::parse(Iterator&, const Iterator&, Context&, const Skipper&,
Attribute&) const [with Iterator = int, Context = const
boost::spirit::unused_type, Skipper = boost::spirit::unused_type,
Attribute = const boost::spirit::unused_type, Derived =
boost::spirit::qi::char_class<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, Char = char, Attr =
char]': D:/Dev-Cpp/include/boost/spirit/home/qi/skip_over.hpp:27:
instantiated from `void boost::spirit::qi::skip_over(Iterator&, const
Iterator&, const T&) [with Iterator = int, T =
boost::spirit::qi::char_class<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:169: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type,
Attr&) [with Iterator = int, Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/boost/spirit/home/qi/char/char_parser.hpp:68:
error: invalid type argument of `unary *'
D:/Dev-Cpp/include/boost/spirit/home/qi/char/char_parser.hpp:70:
error: invalid type argument of `unary *'
D:/Dev-Cpp/include/boost/concept_check.hpp: In destructor
`boost::InputIterator<TT>::~InputIterator() [with TT = int]':
D:/Dev-Cpp/include/boost/concept_check.hpp:547: instantiated from
`boost::ForwardIterator<TT>::~ForwardIterator() [with TT = int]'
D:/Dev-Cpp/include/boost/concept/detail/general.hpp:38:
instantiated from `static void
boost::concepts::requirement<boost::concepts::failed************Model::************>::failed()
[with Model = boost::ForwardIterator<int>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:149: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, boost::spirit::qi::skip_flag::enum_type,
Attr&) [with Iterator = int, Expr = bool, Skipper =
boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal,
boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::space,
boost::spirit::char_encoding::standard> >, 0l>, Attr =
boost::variant<var, boost::recursive_wrapper<unop<op_not> >,
boost::recursive_wrapper<binop<op_and> >,
boost::recursive_wrapper<binop<op_or> >,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_,
boost::detail::variant::void_, boost::detail::variant::void_>]'
D:/Dev-Cpp/include/boost/spirit/home/qi/parse.hpp:197: instantiated
from `bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, const
Expr&, const Skipper&, Attr&) [with Iterator = int, Expr = bool,
Skipper = boost::spirit::standard::space_type, Attr = expr]'
test.cpp:119: instantiated from here
D:/Dev-Cpp/include/boost/concept_check.hpp:517: error: no type named
`difference_type' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:517: error: `failed' is
not a member of `<declaration error>'
D:/Dev-Cpp/include/boost/concept_check.hpp:518: error: no type named
`iterator_category' in `struct boost::detail::iterator_traits<int>'
D:/Dev-Cpp/include/boost/concept_check.hpp:518: error: `failed' is
not a member of `<declaration error>'
D:/Dev-Cpp/include/boost/concept_check.hpp:521: error: invalid type
argument of `unary *'
make.exe: *** [test.o] Error 1
Execution terminated