boost::当词法分析器令牌> 10 时出现精神编译错误

boost::spirit compile error when lexer tokens > 10

本文关键字:编译 错误 词法分析器 令牌 boost gt      更新时间:2023-10-16

当我尝试编译以下代码时,当token_list>10个标记时,我会遇到编译失败(错误C2903:"apply":符号既不是类模板也不是函数模板…)。

当标记<=10.代币数量有限制吗?

#define BOOST_VARIANT_MINIMIZE_SIZE
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/lex_lexertl.hpp>
#include <iostream>
#include <string>
namespace qi  = boost::spirit::qi;
namespace lex = boost::spirit::lex;
template <typename Lexer>
struct token_list : lex::lexer<Lexer>
{
    token_list()
    {
    cs1   = "tok1";
    cs2   = "tok2";  
    cs3   = "tok3";
    cs4   = "tok4";
    cs5   = "tok5";
    cs6   = "tok6"; 
    cs7   = "tok7";
    cs8   = "tok8";
    cs9   = "tok9";
    cs10  = "tok10";
    cs11  = "tok11";
     this->self.add
    (cs1) (cs2) (cs3) (cs4) (cs5) (cs6) (cs7) (cs8) (cs9) (cs10) (cs11);
   }
    lex::token_def<std::string>  cs1, cs2, cs3, cs4, cs5, cs6, cs7, cs8, 
                                 cs9, cs10, cs11;
};
template <typename Iterator>
struct Grammar : qi::grammar<Iterator>
{
    template <typename TokenDef>
    Grammar(TokenDef const& tok) : Grammar::base_type(call_setup)
    {
        call_setup = tok.cs1>>tok.cs2>>tok.cs3>>tok.cs4>>tok.cs5>>
                     tok.cs6>>tok.cs7>>tok.cs8>>-tok.cs9>>tok.cs10>>
                     tok.cs11;
    }
    qi::rule<Iterator> call_setup;
};
int main()
{
    typedef std::string::const_iterator It;
    typedef lex::lexertl::token<It, boost::mpl::vector<std::string>> token_type;
    typedef lex::lexertl::lexer<token_type> lexer_type;
    typedef token_list<lexer_type>::iterator_type iterator_type;
    token_list<lexer_type> Call_Setup;         
    Grammar<iterator_type> g(Call_Setup); 
    std::cout<<"Enter string to parsen";
    std::cout<<"Type [q or Q] to quitnn";
    std::string str;
    while (getline(std::cin, str)){
    if (str.empty() || str[0] == 'q' || str[0] == 'Q')
            break;
    It first = str.begin();
    It last  = str.end();
    bool r = lex::tokenize_and_parse(first, last, Call_Setup, g);
    if (r) {
        std::cout << "Parsing passed"<< "n";
    }
    else {
        std::string rest(first, last);
        std::cerr << "Parsing failedn" << "stopped at: "" << rest << ""n";
    }
  }
    system("PAUSE");
}

规则call_setup在您的案例中存储一个序列,这是一个增强融合向量。默认情况下,该对象的最大长度为10。

通过将#define FUSION_MAX_VECTOR_SIZE 20放在代码的开头来增加它。然后它就可以毫无问题地编译了。