如何从字符串而不是文件中解析
我想从字符串而不是文件中进行解析。我知道 v 可以使用 yy_scan_string fn 来做到这一点。但对我来说它不能正常工作,所以请帮助我
Possible Duplicate:
How to make YY_INPUT point to a string rather than stdin in Lex & Yacc (Solaris)
i want to parse from a string rather than a file. i know that v can use yy_scan_string fn to do it.but for me it's not working properly so pls help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近自己解决了这个问题。关于这个主题的 Flex 文档还有一些不足之处。
我立即发现有两件事可能会让你绊倒。首先,请注意您的字符串需要以双 NULL 结尾。也就是说,您需要采用常规的 NULL 终止字符串,并在其末尾添加另一个 NULL 终止符。这个事实隐藏在 Flex 文档中,我也花了一段时间才找到。
其次,您停止了对“yy_switch_to_buffer”的调用。从文档中也不是特别清楚。如果您将代码更改为类似的内容,它应该可以工作。
I fought through this problem myself very recently. The flex documentation on the subject leaves a bit to be desired.
I see two things right off the bat that might be tripping you up. First, note that your string needs to be double NULL terminated. That is, you need to take a regular, NULL terminated string and add ANOTHER NULL terminator at the end of it. That fact is buried in the flex documentation, and it took me a while to find as well.
Second, you've left off a call to "yy_switch_to_buffer". This is also not particularly clear from the documentation. If you change your code to something like this, it should work.