编译成可执行文件

发布于 2024-09-09 04:27:53 字数 181 浏览 3 评论 0原文

我目前正在用 C/C++ 编写一种编程语言作为练习(但主要是为了好玩)。目前,它会编译成一个命令列表,然后执行(有点像低级 API)。它的工作非常出色,但是,我认为如果不是使用解释器可执行文件,而是将语言实际编译成 .exe 文件,那会更令人兴奋。我不知道这是否可能,也不知道这有多具有挑战性。我找不到任何资源来帮助我解决这个问题。 - 提前致谢。

I am currently writing a programming language in C/C++ as an exercise (but mostly for fun). At the moment it compiles into a list of commands that are then executed (kind of like a low-level API). Its working fantastically, however, I think it would be more exciting if instead of having a interpreter executable, having the language actually compile into a .exe file. I don't know if it is possible or how challenging this might be. I could not find any resources to help me with this. - Thanks in advance.

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

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

发布评论

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

评论(3

烟柳画桥 2024-09-16 04:27:53

您可以考虑为 LLVM 编写前端 (教程) 或 GCC (来自 Linux 杂志的文章) - 如果这对你来说仍然很有趣,那就是另一个问题了。

You could consider writing a frontend for LLVM (tutorial) or GCC (article from linux journal) - if thats still fun for you is a different question.

心病无药医 2024-09-16 04:27:53

这当然是可能的,尽管生成可运行的二进制文件的所有必要部分可能需要相当多的工作。如果这就是您想要学习的内容,那么这可能是一个很好的练习。

但是,如果您只是想让它运行得更快,还有其他选择。例如,您可以根据输入程序发出 C/C++ 代码,然后对其进行编译/链接。

It would certainly be possible, although it could be a fair bit of work to produce all of the necessary parts to make a runnable binary. If that is what you are trying to learn about, then it could be a great exercise.

However, if you are simply looking to make it run faster, there are other options. For example, you could possibly emit C/C++ code based on the input program and then compile/link that.

何止钟意 2024-09-16 04:27:53

首先,你必须以正式的方式清楚你的语言代码的语法和词汇。
然后,您可以查看 lex
这构建了一个词法分析器,您可以使用它来生成您需要的 C 代码(或其他代码)。

如果您的语言不使用动态类型,那么您可以轻松实现。

First, you have to be clear about the syntax and lexical of your language code in a formal way.
Then, you could take a look on lex.
That builds a lexical analyzer, that you can use to generate the C code (or whatever) you need.

If your language doesn't use dynamic types, then you could get it easy.

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