我正在考虑使用 boost::spirit::lex 编写词法分析器,但我能找到的所有示例似乎都假设您已先将整个文件读入 RAM。我想编写一个不需要整个字符串都在 RAM 中的词法分析器,这可能吗?还是我需要使用其他东西?
我尝试使用 istream_iterator,但除非我使用 const char* 作为迭代器类型,否则 boost 会给我一个编译错误。
例如,我能找到的所有示例基本上都是这样做的:
lex_functor_type< lex::lexertl::lexer<> > lex_functor;
// assumes entire file is in memory
char const* first = str.c_str();
char const* last = &first[str.size()];
bool r = lex::tokenize(first, last, lex_functor,
boost::bind(lex_callback_functor(), _1, ... ));
另外,是否有可能以某种方式从 lex 标记中确定行号/列号?
谢谢!