编译解释语言

发布于 2024-09-08 03:01:57 字数 41 浏览 1 评论 0原文

是否有一种编程语言,具有可用的交互式解释器,甚至可以编译为机器代码?

Is there a programming language, having usable interactive interpreter, even as it can be compiled to machine code?

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

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

发布评论

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

评论(16

月竹挽风 2024-09-15 03:01:57

编译与“解释”本质上是实现的问题,而不是语言本身。例如,MRI Ruby 1.8 被解释,而 MacRuby 被编译为本机机器代码。两者都包含交互式 REPL。我所知道的所有语言都至少有一个机器代码编译器和至少一个 REPL:

  • Ruby
  • Python
  • 几乎所有 Lisp(据我所知,Lisp 是开创这项技术的语言)
  • OCaml
  • Haskell
  • Forth

如果我们也将编译计算为字节码作为机器代码,绝大多数流行的字节码编译语言都是如此:

  • Java
  • Scala
  • Groovy
  • Erlang
  • C#
  • F#
  • Smalltalk

Compilation vs. "interpretation" is essentially a matter of implementation, not the language itself. For example, MRI Ruby 1.8 is interpreted, while MacRuby is compiled to native machine code. Both include an interactive REPL. All the languages I know that have at least one machine-code compiler and at least one REPL:

  • Ruby
  • Python
  • Almost all Lisps (Lisp was the language that pioneered this technique, AFAIK)
  • OCaml
  • Haskell
  • Forth

If we're counting compilation to bytecode as well as machine code, it's true of the vast majority of popular bytecode-compiled languages:

  • Java
  • Scala
  • Groovy
  • Erlang
  • C#
  • F#
  • Smalltalk
江城子 2024-09-15 03:01:57

Haskell,使用 Glasgow Haskell 编译器,它有一个名为 GHCi 的交互式“shell”。

Haskell, using the Glasgow Haskell Compiler which has an interactive "shell" called GHCi.

等风也等你 2024-09-15 03:01:57

许多 Lisp 风格都提供这两种选择,包括 Clojure。

Many flavors of Lisp offer both options, including Clojure.

糖果控 2024-09-15 03:01:57

我想到了两个:ocaml 和 scala (~= java),但我确信肯定还有更多。

Two come to my mind : ocaml and scala (~= java), but I'm sure there must be a lot more out there.

命硬 2024-09-15 03:01:57

还有另一个可以烧毁你的房子的:

x86 Assembly

是的,也有这方面的解释器。

此时,您确实处于模拟器领域,但它确实满足您声明的要求。

我想知道是否更容易命名那些尚未编写出可用解释器的编译语言。 :-)

And here's another one to burn your house down:

x86 Assembly

Yup, there are interpreters for this as well.

At this point you're really in emulator land, but it does meet the requirements you state.

I'm wondering if it's easier to name compiled languages that someone hasn't cobbled up a working interpreter for. :-)

他是夢罘是命 2024-09-15 03:01:57

Lua 有一种用于单行和实验的交互模式。它通常编译为字节码供其虚拟机执行。 LuaJIT 是 Lua VM 的独立实现,它还可以即时编译到 32 位 x86。对 64 位的支持正在进行中,并且经常请求对 ARM 的支持。

编译为字节码通常是纯解释器和纯编译器之间的合理折衷。 VM 可以根据语言的需要进行调整,并且 JIT 技术可以在执行时分析 VM 代码,并集中于频繁执行的代码路径和内部循环。

Lua has an interactive mode for one-liners and experimentation. It normally compiles to bytecode for its VM for execution. LuaJIT is an independent implementation of a Lua VM that also does just-in-time compilation to 32-bit x86. Support for 64-bit is underway, and support for ARM is frequently requested.

Compilation to a bytecode is often a reasonable compromise between a pure interpreter and a pure compiler. The VM can be tuned to the needs of the language, and JIT techniques can analyze the VM code as it executes and concentrate on frequently executed code paths and inner loops.

冷情妓 2024-09-15 03:01:57

正如其他人提到的,OCaml。

如果托管代码 (.NET CLI) 足够接近机器代码,F# 也将是一个候选者。可能还有其他 .NET/Mono 语言也满足要求。

As others have mentioned, OCaml.

If managed code (.NET CLI) is close enough to machine code, F# would be a candidate as well. There are probably other .NET/Mono languages which meet the requirement as well.

蘸点软妹酱 2024-09-15 03:01:57

你可能会后悔你问了:

C 和 C++。

为什么?

可能还有其他的。

You may regret you asked:

C and C++.

Why?

and there are probably others out there as well.

囚我心虐我身 2024-09-15 03:01:57

许多语言都提供了既可以交互又可以编译为机器代码的实现,但同时实现这两种功能的情况很少见。 新泽西州标准 ML 是一个具有交互式循环但没有字节码的模型:它只是编译为机器代码记忆,然后分支到它。

Plenty of languages offer an implementation that both interacts and compiles to machine code, but it's rare to do both at once. Standard ML of New Jersey is one that has an interactive loop but no bytecode: it simply compiles to machine code in memory and then branches to it.

孤芳又自赏 2024-09-15 03:01:57

不完全是机器代码,但 Java 可以通过 BeanShell 进行编译和使用。

Not exactly machine code, but Java can be compiled and also used via BeanShell.

笑红尘 2024-09-15 03:01:57

我已经将 Ruby 与解释器一起使用,这里似乎有一个编译器

I've used Ruby with an interpreter, and there seems to be a compiler here.

忆梦 2024-09-15 03:01:57

Icon曾经有一个编译器,但它时常停止维护。它可能仍然有效。

Icon used to have a compiler, but it falls in and out of maintenence. It may still work.

终止放荡 2024-09-15 03:01:57

Python 可以编译为 Windows 可执行文件。

Python can be compiled to windows executables.

新雨望断虹 2024-09-15 03:01:57

C# 可以使用 SnippetCompiler 进行编译,也许这可以作为您的交互式解释器?

C# can be compiled by using SnippetCompiler, maybe this would act as an interactive interpreter for you?

傲鸠 2024-09-15 03:01:57

你的问题有点模糊。甚至 Java 也适合它:

通过交互式解释器,我的意思是
类似 shell 的环境,您可以
在运行时以交互方式工作。

Java 具有此功能,例如在 Eclipse“剪贴簿页面”中,您可以在其中输入 Java 表达式并立即对它们求值。 Java 当然也是一种编译语言(虽然它通常编译为字节码,但有多种编译器可以输出机器代码)。

那么你在寻找什么?也许你可以解释一下你的问题或兴趣。

Your question is a bit vague. Even Java would fit it:

by interactive interpreter, i mean
shell-like environment, where you can
work in the runtime interactively.

Java has this, e.g. in the Eclipse "scrapbook pages", where you can enter Java expressions and have them evaluated right away. Java is of course also a compiled language (and while it's usually compiled to bytecode, there are various compilers that output machine code).

So what are you looking for? Maybe you could explain your problem or interest.

嘿嘿嘿 2024-09-15 03:01:57

我尝试使用 mono/.net 一段时间,发现随机 GC 暂停很令人讨厌(至少在我那破旧的笔记本电脑上)。我研究过使用 gambit-c 一种可以编译为 C 的方案的实现,但它似乎很难使用,因为文档有些有限,而且软件包不太容易安装和使用。

我通常只是坚持使用一种解释性语言,例如与 C/C++ 绑定的 python,这更痛苦,但至少我知道我在做什么。

I tried using mono/.net for a bit and found random GC pauses to be disagreeable (at least on my crusty old laptop). I looked at using gambit-c an implementation of scheme that can compile to C but it seemed difficult to work with because the docs were somewhat limited and the packages where not very easy to install and use.

I usually just stick to having an interpreted language such as python bound to C/C++ which is more painful but at least I know what I am in for.

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