Bison 传回结果 AST
在 lemon 中,我能够使用解析函数的第三个参数将结果传递回当起始符号减少时调用者。
我如何在野牛中做同样的事情?在最终调用 yypush_parse() 之后,在起始符号的操作代码中将该值分配给 $$ 并从调用者处将其视为“yy 小”值是否足够?
解析器是推送的且纯粹的。线程安全是必须的。
In lemon I was able to use the third parameter of the parsing function to pass back the result to the caller when the starting symbol was reduced.
How would I do the same in bison? Is it enough to assign that value to $$ within the starting symbol's action code, and from the caller to take it as the "yy minor" value, after the final call to yypush_parse()
?
The parser is push and pure. Thread-safety is a must.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想要一个 AST,你几乎必须自己使用 bison/yacc 来创建你自己的节点并将它们分配给 $$。
http://epaperpress.com/lexandyacc/ 中的示例(查看 Calculator-> 中的 .y 文件;Yacc 输入)或 http://www.progtools.org/compilers/tutorials/cxx_and_bison/cxx_and_bison.html 可能会给您有关如何做到这一点的想法。
You'll pretty much have to do-it-yourself with bison/yacc if you want an AST, by creating your own nodes and assigning them to $$.
The example at http://epaperpress.com/lexandyacc/ (look at the .y file in Calculator->Yacc input) or http://www.progtools.org/compilers/tutorials/cxx_and_bison/cxx_and_bison.html might give you ideas on how to do that.