我正在尝试使用boost :: spirit为类C语言编写解析器,它使用继承的属性来传输有关变量范围的信息.例如,"namespace a {var b}"会将"a"作为属性传递给"var b"的解析器.
我在使用继承属性编译此代码时遇到基本解析器时遇到问题:
#ifndef CPARSER_DEF_HPP #define CPARSER_DEF_HPP #include#include namespace encoding = boost::spirit::ascii; using boost::spirit::unused_type; using boost::spirit::qi::rule; template struct cparser : boost::spirit::qi::grammar< Iterator, std::string(std::string), encoding::space_type > { rule start; rule sym_list; cparser() : cparser::base_type(start) { sym_list = encoding::string(boost::spirit::qi::_r1); start = sym_list(boost::spirit::qi::_r1); } }; #endif
此解析器在main()中实例化cparser
.
我相信这个解析器应该接受一个std :: string作为它的继承属性,解析匹配该字符串的输入,然后将该字符串作为合成属性返回.这个示例代码没有编译,我无法弄清楚原因.我一直在使用GCC和Clang编译,启用了C++ 11.任何一个编译器的输出都是巨大的(大约1000行),我无法理解它.使用有问题boost::spirit::qi::_r1
吗?std::string(std::string)
规则声明中的问题是什么?
在此先感谢您的帮助.