我想簡單地在這個答案找到了精神解析器:布爾表達式使用Boost
要刪除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
我對這裏的佔位符是如何工作了解不多,但也許它是從錯誤的命名空間拉取_1和_2?您可以嘗試更具體一些,如phx :: _ 1或qi :: _ 1。 –
使用'#include #include 編譯好g ++ 4.7.1和boost 1.51 #include #include #include #include '。它顯然不起作用,因爲xor_規則尚未實現。 –
2012-09-25 19:12:24
Ohai CJAN.LEE :)我認識到了這個問題。你在那裏的評論中看過我的回答嗎? – sehe