Lex 解析器:(缓冲区末尾或 NUL)段错误

发布于 2024-11-29 10:39:14 字数 615 浏览 5 评论 0原文

我在编写 lex 解析器时遇到了分段错误问题。因此,我在构建程序时将调试开关 -d 添加到 Makefile 中。 这是我从中得到的输出。

--accepting rule at line 180 ("bxz")
--accepting rule at line 61 (" ")
--accepting rule at line 180 ("e")
--accepting rule at line 68 ("
")
--accepting rule at line 180 ("0L")
--accepting rule at line 193 ("!")
--accepting rule at line 68 ("
")
--accepting rule at line 180 ("0x")
--accepting rule at line 193 (""")
--accepting rule at line 68 ("
")
--(end of buffer or a NUL)
Segmentation fault

当我通过调试工具运行它时,我发现错误发生在 lex.yy.c:1324 处的 yy_get_next_buffer () 处,这是从我的手编码的 lex 文件自动生成的 C 文件。我该如何解决这个问题? 提前致谢。

I have been experiencing segmentation fault problem problem with the lex parser written. Therefore i have added in debugging switch -d to the Makefile when building my program.
This is the output I get from it.

--accepting rule at line 180 ("bxz")
--accepting rule at line 61 (" ")
--accepting rule at line 180 ("e")
--accepting rule at line 68 ("
")
--accepting rule at line 180 ("0L")
--accepting rule at line 193 ("!")
--accepting rule at line 68 ("
")
--accepting rule at line 180 ("0x")
--accepting rule at line 193 (""")
--accepting rule at line 68 ("
")
--(end of buffer or a NUL)
Segmentation fault

When I run this through a debugging tool, I found that the error occur at yy_get_next_buffer () at lex.yy.c:1324 which is the C file automatically generated from my handcoded lex file. How can I resolve this issue?
Thanks in advance.

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

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

发布评论

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

评论(1

千纸鹤带着心事 2024-12-06 10:39:14

(我将其标记为“不可重现”,但是它计时- 。 href="https://meta.stackoverflow.com/questions/251597/question-with-no-answers-but-issue-solved-in-the-comments">已在评论中回答。 )

@LokiAstari 写道:

该错误不太可能出现在 lex 代码中。因此,听起来您正在注销缓冲区的末尾或以其他方式错误地滥用内存。 Valgrind 可能有助于查找内存错误

@AK 写道:

尝试在最后一个标记字符串后添加换行符。您的解析器可能会尝试在最后一个符号之后找到一些终止字符。

@ChrisDodd 写道:

你可能以某种方式损坏了flex的内部缓冲区指针,通过注销数组的末尾或类似的东西。如果您查看崩溃的 lex 代码,您也许可以在包含不正确数据的数据结构上放置一个数据断点,并找出是谁在修改它

(I flagged this as "not reproducible", however it timed-out/aged away. It has been answered in the comments.)

@LokiAstari wrote:

It is unlikely that the bug is in the lex code. Therefore it sounds like you are writing off the end of a buffer or abusing memory incorrectly in some other way. Valgrind may help in finding memory errors

@AK wrote:

try to put a newline after your last tokenstring. It might be that your parser tries to find some terminating character after the last symbol.

@ChrisDodd wrote:

You've probably corrupted flex's internal buffer pointer somehow, by writing off the end of an array or some such. If you look at the lex code that is crashing, you might be able to put a data breakpoint on the datastructure that has the incorrect data and figure out who is modifying it

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