我无法在 Boost Spirit 的词法分析器功能中获得语义操作来编译
I can't get Semantic actions in Boost Spirit's lexer functionality to compile
所以,我使用boost 1.47.0,我一直试图把一个词法分析器。
我的目标是向词法分析器的一些令牌添加一个语义操作,该操作包含spirit::lex::_pass = spirit::lex::pass_flags::pass_ignore
。然而,我还没有能够得到任何语义操作来编译。我在下面附上了一个(或多或少)最小的例子。我在OS X 10.7.1上用clang编译。
clang++ -DBOOST_SPIRIT_DEBUG -DBOOST_SPIRIT_LEXERTL_DEBUG -DBOOST_SPIRIT_USE_PHOENIX_V3 -c input.cc
编译
的代码#include <boost/phoenix.hpp>
#include <boost/spirit/home/lex.hpp>
#include <boost/spirit/home/lex/lexer/lexertl/lexer.hpp>
namespace phoenix = boost::phoenix;
namespace spirit = boost::spirit;
struct vhdl_lexer : spirit::lex::lexer< spirit::lex::lexertl::lexer<> > {
vhdl_lexer() {
num = "[0-9]";
any = ".";
this->self
= num
| any
;
}
spirit::lex::token_def<> num, any;
};
无法编译的代码
#include <boost/phoenix.hpp>
#include <boost/spirit/home/lex.hpp>
#include <boost/spirit/home/lex/lexer/lexertl/lexer.hpp>
namespace phoenix = boost::phoenix;
namespace spirit = boost::spirit;
struct vhdl_lexer : spirit::lex::lexer< spirit::lex::lexertl::lexer<> > {
vhdl_lexer() {
num = "[0-9]";
any = ".";
this->self
= num [ ++phoenix::ref(x) ]
| any
;
}
int x;
spirit::lex::token_def<> num, any;
};
无法编译的代码报告错误。
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/lexer/lexertl/lexer.hpp:309:34: error: no member named 'add_action' in 'boost::spirit::unused_type'
actions_.add_action(unique_id + j, s.second, wrapper_type::call(act));
~~~~~~~~ ^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/lexer/action.hpp:48:20: note: in instantiation of function template specialization
'boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, const char *,
boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, lexertl::detail::data, const char *,
mpl_::bool_<false>, mpl_::bool_<true> > >::add_action<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc,
boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >' requested
here
lexdef.add_action(subject.unique_id(), subject.state(), f);
^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/detail/sequence_function.hpp:50:23: note: in instantiation of function template specialization
'boost::spirit::lex::action<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>,
boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc, boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >::add_actions<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *,
boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>,
mpl_::bool_<true>, unsigned long>, lexertl::detail::data, const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >' requested here
component.add_actions(def);
^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/fusion/algorithm/query/detail/any.hpp:37:16: note: in instantiation of function template specialization
'boost::spirit::lex::detail::sequence_add_actions_function<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>,
mpl_::bool_<true>, unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>,
lexertl::detail::data, const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >::operator()<boost::spirit::lex::action<boost::spirit::lex::reference<const
boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc,
boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > > >' requested
here
return f(x) ||
^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/fusion/algorithm/query/detail/any.hpp:49:16: note: in instantiation of function template specialization
'boost::fusion::detail::linear_any<boost::fusion::cons_iterator<const boost::fusion::cons<boost::spirit::lex::action<boost::spirit::lex::reference<const
boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc,
boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >,
boost::fusion::cons<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>, boost::fusion::nil> > >,
boost::fusion::cons_iterator<const boost::fusion::nil>,
boost::spirit::lex::detail::sequence_add_actions_function<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>,
mpl_::bool_<true>, unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>,
lexertl::detail::data, const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > > >' requested here
return detail::linear_any(
^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/fusion/algorithm/query/any.hpp:30:16: note: in instantiation of function template specialization
'boost::fusion::detail::any<boost::fusion::cons<boost::spirit::lex::action<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned
long>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc, boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >, boost::fusion::cons<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char,
unsigned long>, unsigned long>, boost::fusion::nil> >,
boost::spirit::lex::detail::sequence_add_actions_function<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>,
mpl_::bool_<true>, unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>,
lexertl::detail::data, const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >, boost::fusion::forward_traversal_tag>' requested here
return detail::any(seq, f, typename traits::category_of<Sequence>::type());
^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/lexer/sequence.hpp:56:13: note: in instantiation of function template specialization
'boost::fusion::any<boost::fusion::cons<boost::spirit::lex::action<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>,
boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc, boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >, boost::fusion::cons<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char,
unsigned long>, unsigned long>, boost::fusion::nil> >,
boost::spirit::lex::detail::sequence_add_actions_function<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>,
mpl_::bool_<true>, unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>,
lexertl::detail::data, const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > > >' requested here
fusion::any(elements, f);
^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/lexer/lexer.hpp:219:22: note: in instantiation of function template specialization
'boost::spirit::lex::sequence<boost::fusion::cons<boost::spirit::lex::action<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned
long>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc, boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >, boost::fusion::cons<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char,
unsigned long>, unsigned long>, boost::fusion::nil> > >::add_actions<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *,
boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>,
mpl_::bool_<true>, unsigned long>, lexertl::detail::data, const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >' requested here
expr.add_actions(def);
^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/lexer/lexer.hpp:227:17: note: in instantiation of function template specialization
'boost::spirit::lex::detail::lexer_def_<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>,
unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, lexertl::detail::data,
const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >::compile2pass<boost::spirit::lex::sequence<boost::fusion::cons<boost::spirit::lex::action<boost::spirit::lex::reference<const
boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>, boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc,
boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal, boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > >,
boost::fusion::cons<boost::spirit::lex::reference<const boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long>, unsigned long>, boost::fusion::nil> > > >' requested here
compile2pass(compile<lex::domain>(expr));
^
/Users/wlynch/Homebrew/Cellar/boost/1.47.0/include/boost/spirit/home/lex/lexer/lexer.hpp:264:17: note: in instantiation of function template specialization
'boost::spirit::lex::detail::lexer_def_<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>,
unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, lexertl::detail::data,
const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >::define<boost::proto::exprns_::expr<boost::proto::tag::bitwise_or, boost::proto::argsns_::list2<const
boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long> &, const
boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc, boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > &>, 2> &, boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long> &>, 2> >' requested here
define(xpr);
^
foo.cc:14:4: note: in instantiation of function template specialization
'boost::spirit::lex::detail::lexer_def_<boost::spirit::lex::lexer<boost::spirit::lex::lexertl::lexer<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>,
unsigned long>, const char *, boost::spirit::lex::lexertl::functor<boost::spirit::lex::lexertl::token<const char *, boost::mpl::vector0<mpl_::na>, mpl_::bool_<true>, unsigned long>, lexertl::detail::data,
const char *, mpl_::bool_<false>, mpl_::bool_<true> > > > >::operator=<boost::proto::exprns_::expr<boost::proto::tag::bitwise_or, boost::proto::argsns_::list2<const
boost::proto::exprns_::expr<boost::proto::tag::subscript, boost::proto::argsns_::list2<boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long> &, const
boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::pre_inc, boost::proto::argsns_::list1<boost::phoenix::actor<boost::proto::exprns_::basic_expr<boost::proto::tag::terminal,
boost::proto::argsns_::term<boost::reference_wrapper<int> >, 0> > >, 1> > &>, 2> &, boost::spirit::lex::token_def<boost::spirit::unused_type, char, unsigned long> &>, 2> >' requested here
= num [ ++phoenix::ref(x) ]
^
1 error generated.
http://www.boost.org/doc/libs/1_47_0/libs/spirit/doc/html/spirit/lex/abstracts/lexer_semantic_actions.html表示:
重要为了使用词法分析器语义操作,需要使用类型lexertl::actor_lexer<>作为词法分析器类(而不是前面示例中描述的类型lexertl::lexer<>)。
相关文章:
- 如何在 boost::spirit::qi 中将某些语义操作排除在 AST 之外
- 在理解移动语义的同时混淆 c++ 程序中的操作
- 使用">"运算符增强语义操作
- 在'string=string+s1'和"string+=s1"之间移动语义可以保存多少个复制操作?
- 使用语义操作填充嵌套结构
- 如何在语义操作中访问元组的元素
- Boost.Spirit解析字符串的语义操作不起作用
- boost::精神访问从语义操作定位迭代器
- Spirit X3 与 boost::string_ref 从语义操作构建
- 在语法构造函数中评估的语义操作(或不评估?
- 不对Error Bison执行任何语义操作
- 为传递到qi::phrase_parse的表达式设置语义操作的属性
- 使用语义操作分析逗号分隔的范围和数字列表
- 为什么当我使用 boost::bind 时,boost::spirit::qi 语义操作不能使用两个参数?
- 如何使用boost::expression-static在语义操作中引用可选子匹配
- 如何在 boost::xpressive 语义操作中使用 "new" 运算符?
- 为什么我不能在语义操作中访问值
- 从语义操作返回的值会干扰规则属性
- 我无法在 Boost Spirit 的词法分析器功能中获得语义操作来编译
- 使用Spirit的语义操作顺序(参考Phoenix)