人们如何创建自己的编程语言?

发布于 2024-10-04 06:24:38 字数 1459 浏览 0 评论 0原文

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

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

发布评论

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

评论(3

只有一腔孤勇 2024-10-11 06:24:38

(尽管是很久以前的事了)并且知道编译器的创建是一项艰巨的重大任务,至少对于像 C++ 这样的语言来说是这样。

许多因素共同使事情变得更容易:

  1. 计算机拥有更多的 RAM 和速度。编写早期编译器的大部分挑战是能够以最少的成本高效地完成此任务。记忆。这就是 C 可以一次性编译的原因:当时,您可能没有足够的内存来容纳整个源文件。以前,编译器编写的许多魔力在于优化符号表表示并尽可能快地进行解析,而现在您可以更简单、更容易地完成事情。

  2. 基础技术已经变得更好。大多数语言都有易于使用的解析器库、高级数据结构(如果您已经有了一个很好的哈希表实现,那么符号表就是小菜一碟!)和其他工具使编译器或解释器的启动和运行变得更加容易。

  3. GC 无处不在。当今创建的大多数新语言都是垃圾收集的。这使得设计语言变得更容易(您不必指定详细的内存语义)。同时,您可以针对一些现有的 GC 平台,如 CLR 或 JVM,这样作为语言作者,您不必编写自己的 GC。事实上,以 CLR 或 JVM 为目标通常可以使您作为编译器编写者的工作变得更加轻松:作为一个更高级别的平台,字节码会向您妥协。

  4. 大多数新语言都是动态类型的。大多数正在创建的新语言都是动态类型的。这些更容易设计和实现。我发现语言设计中的大部分挑战是设计类型系统。同样,编译或解释静态语言更是一个挑战。一切都只是一个属性包的动态语言非常容易启动和运行。

  5. 同样,计算机拥有更多的 RAM 和速度。 在过去,如果您的语言想要有成功的机会,它需要编译为高效的机器代码,有效地使用内存并且跑得快。否则会慢得无法使用。现在计算机的速度已经快得多了,即使像 Ruby 这样的慢速语言对于许多实际用途来说仍然足够快。作为编译器编写者,您不需要像以前那样多的优化技能。

还值得注意的是,目前没有人正在创造一种像 C++ 一样复杂的新语言。 C++ 确实接近语言复杂性的顶端。

(although a long time ago) and know that the creation of a compiler is an enormous major undertaking, at least for a language such as C++.

A lot of things have conspired to make things easier:

  1. Computers have a lot more RAM and speed. Much of the challenge of writing early compilers was being able to do so efficiently and with a minimum of memory. That's why C can compile in a single pass: at the time, you may not have had enough memory to even fit an entire source file in it. Where before a lot of the magic of compiler-writing was optimizing your symbol table representation and parsing as fast as physically possible, now you can get by doing things much simpler and easier.

  2. Base technology has gotten better. Most languages have nice easy to use parser libraries, high-level data structures (symbol tables are a snap if you already have a nice hashtable implementation!) and other tools to make getting a compiler or interpreter up and running much easier.

  3. GC is ubiquitous. Most new languages being created today are garbage collected. That makes it easier to design the language (you don't have to specify detailed memory semantics). At the same time, you can target some existing GC platform like the CLR or the JVM so as the language author, you don't have to write your own GC. In fact, targeting the CLR or JVM makes your job as a compiler writer much easier in general: as a higher-level platform, the bytecode meets you halfway.

  4. Most new languages are dynamically-typed. The majority of new languages being created are dynamically typed. Those are much easier to design and implement. I've found that a majority of the challenge in language design is designing a type system. Likewise, compiling or interpreting a static language is more of a challenge. Dynamic languages where everything is just a property bag are surprisingly easy to get up and running.

  5. Again, computers have a lot more RAM and speed. Back in the day, if your language was to have any chance of success, it needed to compile down to efficient machine code, use memory efficiently and run fast. Otherwise it would be unusably slow. Now that computers are so much faster, even a slow language like Ruby is still fast enough for many real uses. As a compiler writer you don't need as much optimization skill as you used to.

It's also worth noting that no one is making a new language as complex as C++ these days. C++ really is near the top end of language complexity.

顾挽 2024-10-11 06:24:38

我在创建自己的语言的道路上已经走了一段路。我开始这样做是为了代表需求、分析和设计构造,而不是代码编译器。为此,即使是非常简单的语言也很有用。我发现能够在非常受限的英语版本(主要是模板句子)中阅读和编写此类结构很有价值。然后让语言机器可读变得很有用,所以我构建了词法分析器和解析器来使用 Lex 和 Yacc 读取语言。当我离开时,我扩展了语言及其解析器来处理扩展。

我知道对于像 C++ 这样广泛的语言来说,距离一个强大的编译器还有很长的路要走,但说明了走这条路的一个动机。我认为您认为简单语言毫无用处的观点是言过其实。即使是非常有限的语言也可以有很大的用处。

I have gone a little way down the route of creating my own language. I started off doing this to represent requirements, analysis and design constructs, rather than a code compiler. For this purpose even a very simple language can be useful. I found it valuable to be able to read and write such constructs in a very constrained version of English - template sentences mainly. Then it became useful to have the language machine readable and so I constructed lexers and parsers to read the language using Lex and Yacc. As I have gone I have expanded the language and its parsers to deal with the expansions.

I am aware that this is a very long way from a robust compiler for a language as extensive as C++, but illustrates one motivation for going down this route. I would suggest that your view of simple languages as being pretty useless is an overstatement. Even a very limited language can be of substantial use.

[浮城] 2024-10-11 06:24:38

虽然我基本上没有创建自己的语言的经验,但我确实有大量学习新语言的经验,所以我可以这样建议——

编程行业是语言的市场。语言受欢迎程度的上升和下降取决于其学习和使用的简单性、缺乏商业和法律限制、对现实生活情况的适用性、灵活性和功能。如果您希望您的语言有一天变得流行,请尝试使用这些语言。

如果您为了自己的目的而设计一种玩具语言(正如许多计算机科学家所做的那样),那么这是一个有趣的理论练习,并且仍然相当有效,但您可能不会期望它会变得如此广泛。

Though I have basically no experience in making languages of my own, I do have a good amount of experience learning new ones, so I could suggest this -

The programming industry is a marketplace of languages. Languages rise and fall in popularity based on their simplicity to learn and use, lack of commercial and legal restriction, applicability to real-life situations, flexibility, and power. If you want your language to be popular one day, try to go for these.

If you're designing a toy language for its own sake (as many computer scientists do), it's a interesting theoretical exercise and still quite valid, but you might not expect it to become quite as widespread.

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