如何编写代码生成器/编译器
我想知道如何从抽象语法树生成某种字节码。
我已经在互联网上搜索过,但找不到任何有用的信息。
我见过一些关于使用模板的提及,但找不到真正解释它是什么、它如何工作或如何实现它的人。
但有一件事,我没有任何真正的编程经验,而且我完全是自学成才,所以我不是在寻找一本 800 页的关于编写编译器理论的书,我正在寻找更多的东西实用的,某种通过实际示例进行操作的教程。
I would like to know how you would generate some kind of bytecode from an abstract syntax tree.
I've searched the internet but I cannot find anything helpful.
I've seen some mention of using templates but cannot find someone that actually explains what it is, how it works or how to implement it.
Just one thing though, I don't have any real programming experience and I'm completely self-taught so I'm not looking for an 800 page book on the theory of writing a compiler, I'm looking for something a little more practical, some kind of tutorial working through an actual example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
许多个月前,我通过关注 Jack Crenshaw 的《让我们构建一个编译器》,学到了很多东西。它使用 Turbo Pascal 进行实现并生成 68000 个汇编程序,因此需要一些步骤才能使其在现代主机上运行,但它通过许多步骤仍然有效。
I learned a lot by following Let's Build a Compiler, by Jack Crenshaw many moons ago. It uses Turbo Pascal for implementation and generates 68000 assembler, so there is some steps to get it running on a modern host but it works through a lot of steps that is still valid.
查看 LLVM 中的 Kaleidoscopy 教程:http://llvm.org/docs/tutorial/
和对于有些不同的观点,http://community.schemewiki.org/?90min-scheme2c
Take a look at Kaleidoscope tutorial in LLVM: http://llvm.org/docs/tutorial/
and for a somewhat different perspective, http://community.schemewiki.org/?90min-scheme2c