您将如何编写一种简单的编程语言?

发布于 2024-10-01 05:02:18 字数 511 浏览 6 评论 0原文

可能的重复:
设计简单编程语言的方法
学习编写编译器

我想编写一种语法类似于以下内容的编程语言QBasic,但更简单。我希望它适合初学者。它的简单性将鼓励有抱负的程序员不要放弃并让他们对编程产生兴趣。例如: 而不是 QBasic 的 打印“你好世界!”

我会用

写“Hello World!”

或者更像 VB

Write(“Hello World”)

我将如何调整基本语法来创建我的语言?

Possible Duplicates:
Methodologies for designing a simple programming language
Learning to write a compiler

I would like to write a programming language with a syntax similar to QBasic but even simpler. I want it to be for beginning programmers. Its simplicity will encourage aspiring programmers not to give up and get them interested in programming. For example:
Instead of QBasic's
PRINT "Hello World!"

I would use

Write "Hello World!"

or a little more like VB

Write ("Hello World")

How would I go about adapting the basic syntax to make my language?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦途 2024-10-08 05:02:18

这不是一个简单的任务。语言解析和编译器理论是相当重要的主题。很多数学。您还必须决定您想要的目标平台,这也将决定您的语言是完全编译(例如 C/C++、Pascal)、编译为字节码(例如 Python、Java)还是在运行时解释(例如 VBScript) ,JavaScript)。要指定语言本身,请温习Backus-Naur 格式

为了帮助您,有几个强大的解析器生成器,包括:

  • Lex/Yacc(Flex/Bison 是 GNU 版本)- 老派的行业标准。用于开发 C/C++ 编译器
  • ANTLR - 如果您有兴趣使用 Java 创建编译器
  • Boost.Spirit - 一种不同的方法,允许使用 C++ 本身来规范语言。

还有更多。可以在此处找到比较,还可以在此处

如果您确实对完整的理论感兴趣,则需要查看龙之书

但我必须重申:这是一个大课题。有很多很多工具可以帮助你,但兔子洞却相当深。

This is not a simple task. Language parsing and compiler theory are pretty hefty subjects. Lots o' math. You also have to decide what platform you want to target, which will also determine whether your language is fully compiled (eg. C/C++, Pascal), compiled into bytecode (e.g. Python, Java), or interpreted at runtime (eg. VBScript, JavaScript). For specifying the language itself, brush up on the Backus-Naur format.

To help you along, there are several robust parser generators out there, including:

  • Lex/Yacc (Flex/Bison are the GNU Versions) - The old school industry standard. For developing a compiler in C/C++
  • ANTLR - If you're interested in creating a compiler using Java
  • Boost.Spirit - A different approach, allowing specification of the language using C++ itself.

And many more. A comparison can be found here, while yet another list can be found here

If you're really interested in the full theory, you want to check out The Dragon Book.

But I must reiterate: This is a big subject. There are many, many tools to help you along the way, but the rabbit hole goes pretty deep.

呢古 2024-10-08 05:02:18

我认为这样做的好处是:

  1. 使用简单。
  2. 设计/实施简单。
  3. 表达能力强。

选择其中的 1.9。

很可能获得其中任何两个的合理程度。充分完成其中任何两项都是非常困难的,而尝试同时完成这三项会让你陷入无人区,你根本做不好。

ps 我是根据 #1+#3 的经验说的

I think the up shot of this is:

  1. Simple to use.
  2. Simple to design/implement.
  3. Strong expressive abilities.

Pick 1.9 of them.

It's very possible to get a reasonable degree of any two of those. Doing any two fully is very hard and trying to get all three leaves you in a no-mans-land where you don't do any well.

p.s. I speek from experiance for #1+#3

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文