C# 解释语言
我想用 C# 编写一种解释性语言,我应该从哪里开始? 我知道如何使用有趣的字符串解析来做到这一点,但正确的方法是什么?
I am looking to write an interpreted language in C#, where should I start? I know how I would do it using fun string parsing, but what is the correct way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要做正确的事可能是一项相当困难的努力。
如果您对编译器理论了解不多,您可能应该首先开始阅读它。
如果我正确理解这个术语,仅仅使用“有趣的字符串解析”根本不会让你走得太远。
第一个基本步骤是编写定义该语言的有效语法的语言语法。
像 ANTLR 这样的工具将帮助您将各个部分组合在一起,但我建议阅读 龙之书,因为它是快速了解该主题的规范起点。
It can be a pretty difficult endeavour to do right.
If you don't have much knowledge in compiler theory you should probably first start reading about it.
Just using "fun string parsing", if I understand that term correctly, isn't going to get you very far at all.
The first basic step is to write your language grammar that defines the valid syntax for the language.
A tool like ANTLR will help you get the pieces together, but I would suggest reading the Dragon book as it is the canonical starting point to get up to speed on the subject.
如果您想在 .NET 上构建解释语言,DLR 是最佳选择 - 请查看 Martin Maly 的 LOLCODE 示例,网址为 http://www.iunknown.com/2007/11/lolcode-on-dlr.html
编辑:这是 Scott Hanselman 提供的更多信息的另一个链接:http://www.hanselman.com/blog/TheWeeklySourceCode11LOLCodeDLREdition.aspx
If you want to build an interpreted language on .NET, the DLR is the way to go - check out Martin Maly's LOLCODE sample at http://www.iunknown.com/2007/11/lolcode-on-dlr.html
Edit: Here's another link with more information from Scott Hanselman: http://www.hanselman.com/blog/TheWeeklySourceCode11LOLCodeDLREdition.aspx
查看 Microsoft 的 Phoenix 编译器。 这将提供构建针对本机或托管环境的编译器所需的许多工具。 在这些工具中,我们有一个优化后端。
我赞同 Cycnus 关于阅读 Aho Sethi 和 Ullman 的《龙书》的建议 (Wikipedia< /a>,亚马逊)。
RGR
Checkout the Phoenix compiler from Microsoft. This will provide many of the tools you will need to build a compiler targeting native or managed environments. Among these tools us a optimizing back end.
I second Cycnus' suggestion on reading Aho Sethi and Ullman's "Dragon Book" (Wikipedia, Amazon).
RGR