我无法在Boost Spirit的词法分析器功能中进行语义操作来编译

时间:2011-10-03 16:30:40

标签: c++ boost boost-spirit boost-spirit-lex

所以,我正在使用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.

1 个答案:

答案 0 :(得分:5)

http://www.boost.org/doc/libs/1_47_0/libs/spirit/doc/html/spirit/lex/abstracts/lexer_semantic_actions.html说以下内容:

  

重要

     

要使用词法分析器语义操作,您需要使用类型lexertl :: actor_lexer&lt;&gt;作为lexer类(而不是前面示例中描述的类型lexertl :: lexer&lt;&gt;)。