【发布时间】:2015-02-01 19:41:17
【问题描述】:
这是来自 .lex 文件的 sn-p:
/* Empty line just with the newline character signs end of
the title block
*/
<title>^[\n]{1} {
yymore(); ECHO;
// std::cout << "Text: " << yytext << std::endl;
// ... do something with yytext
BEGIN(INITIAL);
}
/* Reads everything up to the end of line. */
<title>.+ {
ECHO; yymore();
//std::cout << "yymore: " << yytext << std::endl;
}
/* Every title starts with # and text follows. */
#[\t\ ] {
// ... prepare for html output
BEGIN(title);
}
目标是阅读“#”之后的整个文本。根据在线教程,yymore() 应该将当前 yytext 的内容附加到最后一个。在<title>.+ 部分中使用ECHO; yymore(); 组合可显示整个文本。但是删除 ECHO 并使用 cout 会使 yymore() 损坏。不附加文本。
此外,我无法在<title>^[\n]{1} 部分中获取标题文本。我得到的只是“\n”。
我做错了什么?
【问题讨论】:
标签: c++ g++ flex-lexer