创建解释性语言的过程是怎样的?
我想创建一种非常简单的实验性编程语言。我可以查看哪些资源来概述创建解释语言的过程。我将使用 C++ 来构建和编译解释器。
I want to create a very simple experimental programming language. What are some resources can i check out to get an overview of the process of creating an interpreted language. I will be using c++ to build and compile the interpreter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看一下 boost 库“spirit”LL 解析器。
Take a look at the boost library "spirit" LL parser.
要创建解释性语言,您需要创建两件事:
定义了语言本身后,可以使用多种工具来帮助创建语言解析器。经典工具是 lex 和 yacc 及其开源版本 flex 和 bison。
To create an interpreted language, you need to create two things:
Once you have defined the language itself, there are several tools available to assist in creating a language parser. The classic tools are lex and yacc, and their open-source versions flex and bison.
几个步骤:
首先,构建词法分析器和解析器。使用 lex 和 yacc 等常用工具,或者使用 Antlr 等更现代的框架(这是我推荐的),这确实很容易做到。这些工具将为您的目标语言生成源代码,然后您可以对其进行编译并包含在您的项目中。
词法分析器和解析器将构建源文件的内部表示。有几种不同的方法可以解决此问题:
Exec()
(根对象又在其子对象上调用Exec()
等)。这基本上就是我用于解释型域特定语言 Phonix 的方法。A few steps:
First, build the lexer and parser. This is really easy to do with common tools such as lex and yacc, or using a more modern framework such as Antlr (which is what I recommend). These tools will generate source code for your target language that you can then compile and include in your project.
The lexer and parser will build the internal representation of the source file. There are a few different ways of approaching this:
Exec()
on the root object (which in turn callsExec()
on its children, etc.). This is basically the method that I use for my interpreted domain-specific language Phonix.您需要实现解析器和解释器。
有一本很棒的免费教科书,名为“编程语言:应用程序和解释”,它使用方案来构建越来越复杂的解释器。它还可以很好地介绍编程语言的功能。
在这里查看:http://www.cs.brown.edu/ ~sk/Publications/Books/ProgLangs/
如果您不喜欢Scheme,那么它可能值得研究一下。
You need to implement both a parser and an interpreter.
There is a great free text book called "Programming Languages: Application and Interpretation" that uses scheme to build increasingly more complex interpreters. It also serves as a great introduction to programming language features.
Check it out here: http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/
If Scheme isn't your cup of tea it may be worth looking into.