更改 yyparse() 内部的缓冲区;
我试图在解析另一个字符串的过程中使用预定义的语法解析常量字符串。
我的 main()
调用 yyparse()
,用户开始输入,当匹配某种语法时,例如 MACRO
或其他东西,我想要执行 yy_scan_string("..."); 我遇到了几个问题
- 我需要的所有常量都是由flex创建的,然后我需要在我的bison文件中,这取决于flex输出
- 我通过从已编译的 Flex 部分复制
#ifndef
语句解决了这个问题
- 我通过从已编译的 Flex 部分复制
- 我尝试调用
yyparse()
但这引发了 我就会陷入无限循环, - 如果我调用 yy_delete_buffer ,
然后我终止主解析,并且代码退出。我缺少什么?看起来像是一个简单的任务,我只想在解析文件的过程中解析存储的字符串,然后返回到常规解析。
I'm attempting to parse a constant string, using predefined grammar, in the middle of parsing another string.
My main()
calls yyparse()
, user start typing, and when a certain grammar is matched, such as MACRO
or something, I wanted to execute yy_scan_string("...");
I ran into several problems
- All the constants that I need are created by flex, and I need then in my bison file, which depends on flex output
- i solved this by copying
#ifndef
statements from the compiled flex portions
- i solved this by copying
- after calling
yy_scan_string
I tried callingyyparse()
but this threw me into an infinite loop - if I call
yy_delete_buffer
then I terminate my main parsing, and the code quits.
What am I missing? Seems like a simple task, I just want to parse a stored string, in the middle of parsing a file, and then return to regular parsing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您要使用 yy_scan_string() 来 lex 一个新字符串,最好同时使用 yypush_buffer_state() 和 yypop_buffer_state() 保存当前解析状态的上下文。 (有关示例实现,请参阅多输入缓冲区。)
If you're going to use
yy_scan_string()
to lex a new string, it would be a good idea to also use theyypush_buffer_state()
andyypop_buffer_state()
to save the context of the current parsing state. (For a sample implementation, see Multiple Input Buffers.)您是否尝试在另一个解析过程中调用野牛生成的解析器?请记住,解析器是有状态的——如果您想以可重入的方式使用 bison,则必须专门请求 bison 生成可重入的解析器,这不是默认的。野牛手册中有文档解释了如何请求。例如,请参见: http://www.gnu.org/ software/bison/manual/bison.html#Pure-Decl
顺便说一下,我要注意的是,flex 默认情况下也是不可重入的,您可能必须在那里做类似的事情。
Are you attempting to call the bison generated parser while in the middle of another parse? Bear in mind that the parser is stateful -- if you want to use bison in a reentrant manner, you have to specifically request that bison generate a reentrant parser, which is not the default. There is documentation in the bison manual explaining how to request that. See, for example: http://www.gnu.org/software/bison/manual/bison.html#Pure-Decl
I'll note, by the way, that flex is also not reentrant by default, and you may have to do similarly there.