boost::当词法分析器令牌> 10 时出现精神编译错误
boost::spirit compile error when lexer tokens > 10
当我尝试编译以下代码时,当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
放在代码的开头来增加它。然后它就可以毫无问题地编译了。
相关文章:
- std::is_base_of表示ctor编译错误
- Qt5:使用QCommandLineParser类时出现奇怪的编译错误
- 如何修复sfml c++代码编译错误
- 使用 MATLAB 编码器生成C++代码:编译错误"undefined reference to `rgb2gray_tbb_real64'"
- 使用外部SDK工具链文件在VisualStudio上生成项目编译错误
- vscode下的Arduino代码出现意外编译错误
- 第三方 API 中的编译错误 - Visual Studio
- std::cout输出int时出现编译错误
- 奇怪的代码抛出编译错误模板< J,int aSize=10> C2143:语法错误:在"<"之前缺少";"
- 提升图广度优先搜索前置编译错误
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 使用带有 ref 参数的成员函数创建线程时出现编译错误
- 我在C++中遇到了这个奇怪的编译错误
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- 使用 std::enable_if 限制派生类的模板参数时出现编译错误
- 现代OpenGL和GLEW Libraray的编译错误
- C++ 编译错误:意外的类型名称"字符串":预期的表达式
- C ++程序编译错误,找不到/访问文件
- 使用直接大括号初始化时,C++ 编译错误"声明末尾的预期";"
- 为什么传递非静态成员函数会导致编译错误?