为什么 Flex 扫描器在匹配 NUL 字符时速度很慢?

发布于 2024-12-18 04:30:31 字数 275 浏览 3 评论 0原文

我有一个由其他人编写的词法分析器,他使用 flex 生成了它。它可以工作,但在包含字符串文字和大量 NUL 字符的示例中,扫描速度非常慢。

经过一番谷歌搜索后,我在 Flex 文档中找到了这段文字,毫无理由地说明了这一点:

最后一点:当匹配 NUL 时,flex 很慢,特别是当 令牌包含多个 NUL。最好编写匹配的规则 如果预计文本经常会出现,则使用少量文本 包括 NUL。

Flex 对 NUL 字符有什么问题?

I have a lexer written by someone else, who generated it using flex. It works, but in a sample which contains a string literal, and a lot of NUL characters in it, the scanning is very slow.

After some googling I found this paragraph in the flex docs, that states this, without reason:

A final note: flex is slow when matching NUL's, particularly when a
token contains multiple NUL's. It's best to write rules which match
short amounts of text if it's anticipated that the text will often
include NUL's.

What's flex's problem with NUL characters?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡淡離愁欲言轉身 2024-12-25 04:30:31

(这个问题在 @Rhymoid 和 @Kaz 的评论中得到了回答。它们被复制到这里。另请参阅 没有答案的问题,但问题已在评论中解决(或在聊天中扩展)

也许它使用它作为字符串终止符(这在 C 中是正常的) ,以及需要以某种方式逃避它。此外,yytext 将包含什么?

(The question is answered in the comments from @Rhymoid and @Kaz. The are copied here. See also Question with no answers, but issue solved in the comments (or extended in chat) )

Perhaps it uses it as a string termination character (which is normal in C), and needs to escape it in some way. Moreover, what will yytext contain?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文