c++ - Lex 解析器 : (end of buffer or a NUL) segfault

标签 c++ parsing bison lex flex-lexer

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

--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

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

最佳答案

(我将其标记为“不可复制”,however it timed-out/aged awayIt has been answered in the comments 。)

@LokiAstari 写道:

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 写道:

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 写道:

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

关于c++ - Lex 解析器 : (end of buffer or a NUL) segfault,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7060993/

相关文章:

c# - C# 中的解析器 FxCop 结果 Xml 文件

c - 在 YACC 规则中使用预定义 token (%token) 和使用单个字符之间的区别

bison - 轮类减少冲突

c++ - vs10 C++ $(MyLibrary) 与 %(MyLibrary)

c++ - std::exception 的 What() 方法不是虚拟的?

java - ANTLR 帮助 - 无法解析普通文本,但所有其他更复杂的规则都可以工作

c - strptime() 在 C 中产生垃圾时间

c++ - 使用迭代器从两端开始在列表中移动并在中间停止

c++ - 指向二维数组的特定行

grammar - Flex/Bison (Lex/Yacc) 无法比拟的简单正则表达式模式