如何设计和实现编程语言?

发布于 2024-09-29 11:28:08 字数 1437 浏览 0 评论 0原文

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

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

发布评论

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

评论(4

独行侠 2024-10-06 11:28:08

现在怎么办?我从哪里开始?我需要知道什么?

从学习更多编程语言开始。

学习了几种语言后,买一本关于编译器的书。有许多。谷歌会提供帮助。您购买哪一款并不重要。你需要几个。读很多书还是可以的。

一旦您学习了语言并阅读了编译器,请执行以下操作。

  1. 构建您需要的运行时库。使用某种合适的语言(例如 C 或 Python 或其他语言)实现它们。

  2. 一旦您拥有真正有效的运行时库。 真的完全有效。完全。你可以考虑语法和词法扫描和编译。这些都是难题,但还没有让你的运行时库工作起来困难一半。

滥用语法(即领域特定语言)是一个很有吸引力的麻烦。许多人有“改进”的语法,但没有可用的运行时库。所以他们的“语言”是不完整的,因为它没有任何事情。

首先让你的语言去做某事。

Now what? Where do I start? What do I need to know?

Start by learning more programming languages.

After learning several languages, buy a book on compilers. There are many. Google will help. It doesn't matter which one you buy. You'll need several. It's okay to read many books.

Once you've learned languages and read up on compilers, do the following.

  1. Build the run-time libraries you need. Implement them in some suitable language like C or Python or whatever.

  2. Once you have run-time libraries which really work. Really totally work. Totally. You can think about syntax and lexical scanning and compiling. Those are hard problems, but not half as hard as getting your run-time libraries to work.

Fooling around with syntax (i.e., a Domain Specific Language) is an attractive nuisance. Many people have "improved" syntax but no usable run-time libraries. So their "language" is incomplete because it doesn't do anything.

Get your language to do something first.

ゞ记忆︶ㄣ 2024-10-06 11:28:08

最简单的途径是使用串联编程语言,例如Forth因素,或者您自己设计的因素。

Forth解释器非常容易实现,不需要占用超过几KB;对于乐高设备来说很重要。您需要了解 Forth 解释器的工作原理。例如,开始

The easiest route is using a concatenative programming language, like Forth, Factor, or your own design of one.

The Forth interpreter is very easy to implement and does not need to take up more than a few KB; important for the Lego device. You need to understand how the Forth interpreter works. This is covered, for instance, in chapter 9 of Starting Forth.

羅雙樹 2024-10-06 11:28:08

阅读有关语言设计的有趣书籍!

Clojure 的作者推荐遵循 Christian Queinnec 的书“lisp in Small Pieces”。 Clojure 阅读列表涵盖了许多影响 Clojure 语言设计的书籍。

Read fun books about language design!

the author of Clojure recommended following the book "lisp in small Pieces" by Christian Queinnec. The Clojure Reading list covers many books that incluenced the design of the Clojure language.

長街聽風 2024-10-06 11:28:08

不要害怕编写一个编译器,它可以编译为现有语言,而不是目标代码。例如,轻量级C++是C++->轻量级C++。 C 编译器基于这个想法(尽管 C++ 在某处做同样的工作): http://linux.wareseeker.com/Programming/lightweight-c-1.3.2.zip/331414

如果您对如何改进编程有一个小而聪明的想法,那么这是一个快速的胜利方式。

搜索引擎也有类似的情况。如果我说,我可以比 Google 做得更好,也许我可以使用 Google mashup 来做到这一点,它会重新组织 Google 的结果集,而且我不需要购买 343 Zigabytes 的存储空间来设置第二个 Google,只是为了更改结果数量从 10 到 15。(不幸的是,如果我有不同的排名或爬行想法,它就不起作用。)

也许 Twitter 是一个更好的例子。使用 Twitter API 编写您自己的 Twitter。 (当然,前提是您的想法符合 Twitter 的基本模型。)

我们现在正在开发数据流引擎(请参阅维基百科:基于流的编程、数据流编程)。我们开发了一种非常精简的新语言,它有 3 种指令类型(组件创建、参数设置、消息声明)和 2 种块类型(组件声明和实现)。它被编译为C++代码,因此编译器很简单,并且结果是快速优化的。另外,有几种情况,我们的语言脚本是从配置生成的,或者更优雅的是,它支持元编程。

我们应该打破1步(源代码->可执行文件)和0步(源脚本是可执行文件)编译语言; 3-4 级很容易概述,并且 - 如果我们做得正确 - 它可以使开发更加有效。

Don't afraid to write a compiler, which compiles to an existing language, and not to object code. For example, Lightweight C++ is a C++ -> C compiler is based on this idea (altough, C++ does the same job somewhere): http://linux.wareseeker.com/Programming/lightweight-c-1.3.2.zip/331414

If you have a small-but-smart idea on how to improve programming, it's a quick win way.

There's a similar situation with search engines. If I say, that I can do better than Google, maybe I can do it with a Google mashup, which reorganizes Google's result set, and I don't need to buy 343 Zigabytes of storage to set up a second Google just for changing the number of results from 10 to 15. (Unfortunatelly, it does not works if I have different ranking or crawling ideas.)

Maybe, Twitter is a better example. Write your own Twitter by using Twitter API. (Of course, only if your idea fits into the Twitter's base model.)

We're now working on a dataflow engine (see Wikipedia: flow-based programming, dataflow programming). We've developed a very lite new language, which has 3 instruction types (component creation, parameter setting, message declaration), and 2 block types (component declaration and implementation). It's compiled to C++ code, so the compiler is simple, and result is optimal fast. Also, there're several cases, when our language script is generated from configurations, or, more elegant, it supports metaprogramming.

We should break off the 1-step (source->executable) and 0-step (the source script is the executable) complilation languages; 3-4 level is easy yet to overview, and - if we do it right - it can make the developement more effective.

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