创建编程语言和编译器设计。他们有关系吗?

发布于 2024-09-18 08:06:46 字数 197 浏览 4 评论 0原文

好吧,我想这个问题已经被问过很多次了。

我想创建一种编程语言,不一定是从今天开始,而是需要 2-3 年的时间。我不是一个很好的程序员,但我正在进步。我想问的是创建一种语言和编写一个编译器的关系有多紧密?

因为编译器将一种语言从一种形式翻译成另一种形式,所以我想这都是关于为特定文本编写编译器的。那么如果我学习编译器设计,我能够编写自己的编程语言吗?

Alright, I guess this question has been asked a lot of times here.

I want to create a programming language, not necessarily starting today, but over a span of 2-3 yrs. I'm not a very good programmer, but I'm improving. What I wanted to ask is how closely creating a language and writing a compiler related?

Since, a compiler translates a language from one form into another, I guess it's all about writing a compiler for a particular piece of text. SO if I learn compiler design, will I be able to write my own programming language?

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

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

发布评论

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

评论(4

野却迷人 2024-09-25 08:06:47

这取决于“编译器”的含义。编译器/解释器通常由两大部分组成:解析器部分,它读取您语言中的文本并从中构建内部结构(AST);以及代码生成/解释部分,它读取 AST 并将其翻译为机器或字节码。虽然您肯定需要知道如何为您的语言编写解析器,但代码生成并不那么重要,至少在早期阶段是这样。您可以先将您的语言简单地翻译成 C,然后看看接下来会发生什么。

It depends on what you mean by "compiler". Compilers/interpreters usually consist of two big parts: a parser part, which reads a text in your language and builds an internal structure (AST) out of it, and a code generation/interpretation part, which reads the AST and translates it to machine or byte codes. While you definitely will need to know how to write a parser for your language, code generation is less important, at least, at the early stages. You can start by simply translating your language to C and see where you go from there.

Hello爱情风 2024-09-25 08:06:46

您可以在不了解有关实现编译器的任何信息的情况下设计一种编程语言,反之亦然。语言设计者可以为该语言编写规范,然后编译器实现者可以采用该规范并创建编译器。

但是,如果这是一个个人项目,那么您可能必须学习如何做到这两点。没有编译器的编程语言纯粹是理论性的,如果不使用它编写和执行真实的程序,就很难弄清楚一种编程语言有多好。即使您确实找到愿意为您实现编译器的人,您可能也不想每次有新想法尝试时都必须等待那个人,因此您会想知道如何自己去做。

实现编译器是一个非常高级的编程项目,因此如果您刚刚开始成为一名程序员,那么您将面临一个陡峭的学习曲线。您可能想首先查看 LLVM 的教程和示例,尽管这实际上可能不是合适的编译器基础架构为您的语言。

You can design a programming language without knowing anything about implementing compilers, and vice versa. The language designer can write a specification for the language, and a compiler implementor can then take that and create the compiler.

However, if this is a personal project, then you will probably have to learn how to do both. A programming language for which there is no compiler is purely theoretical, and it is difficult to figure out how good a programming language is without writing and executing real programs with it. Even if you do find someone willing to implement the compiler for you, you might not want to have to wait for that person every time you have a new idea to try, so you will want to know how to do it yourself.

Implementing a compiler is a pretty advanced programming project, so if you are just getting started as a programmer, you have a steep learning curve ahead of you. You might want to start by looking at the tutorials and examples for LLVM, although that might not actually be a suitable compiler infrastructure for your language.

天赋异禀 2024-09-25 08:06:46

鸣人,就看你想创造什么样的“语言”了。如果它是一种简单的、仅供学习的语言,并且您选择了语法等,那么您不需要了解很多有关编程的知识。但是,如果你要处理一个严肃的问题,你将必须深入学习至少一种计算机编程语言,不仅是为了使用它,而且是为了尝试理解它的几个概念,例如 OO、泛型、lambda 。

相信我,这不是几个月的任务,而是一次认真的旅程 不管怎样,我祝你好运;)

Naruto, it depends on what kind of "Language" you want to create. If it is a simple, just-for-learning language, and you choose the grammar, etc, etc, you won't need to know a lot about programming. BUT, if you are going to deal with a serious one, you will have to study at least one computer programming language deep not only to use it, but to try to reach several of its concepts, for example, like OO, generics, lambda expressions, etc, etc.

Believe me, this is not a task of months, but a serious journey. Anyway, I wish you luck ;)

弄潮 2024-09-25 08:06:46

密切相关。除非您有办法将其解释/编译为可执行形式,否则您实际上没有一种语言。

Intimately related. You really don't have a language unless you have a way to interpret/compile it into an executable form.

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