可以解释为 Javascript 的语言吗?

发布于 2024-10-07 06:24:26 字数 718 浏览 1 评论 0原文

另一篇文章质疑将语言编译为 Javascript 的实用性。除了实用性之外,哪些解释器从某种语言 X 翻译成 Javascript 并在 Javascript 中实现?我对 X 的设计目的不是针对 Javascript 的情况特别感兴趣。即使口译员没有完全完成,我也想听听。

您可能对这个问题的动机感到好奇。 Javascript 当然无法利用与汇编程序一样多的功能,但代码分发和执行的灵活性有时可能会超过该成本。

这些解释器的一个用例是教学和学习编程语言的模型。想想交互式书籍 Eloquent Javascript 中的 Javascript 解释器有多么有用。当然,与本地编译相比,性能可能会受到影响,但在某些情况下,成本肯定是值得的。是的,我意识到依赖服务器来编译或解释代码始终是一种选择,但我对客户端方法特别感兴趣。


更新:很多回复都包含对未在 Javascript 中实现的编译器的引用。我只是想强调解释器本身应该用 JavaScript 实现,这样它和源语言代码都可以在你祖父母计算机上的浏览器上运行。

Another post questioned how practical it is to compile languages into Javascript. Practicality aside, what interpreters translate from some language X to Javascript and were implemented in Javascript? I'm especially interested in the cases where X wasn't designed with the intention of targeting Javascript. Even if the interpreter isn't totally finished I'd like to hear about it.

You may be curious about the motivation for this question. Javascript certainly can't leverage as much power as assembler, but the flexibility for code distribution and execution may sometimes outweigh that cost.

One use case for these interpreters is a model for teaching and learning programming languages. Consider how useful it is to have a Javascript interpreter in the interactive book Eloquent Javascript. Sure, there may be a performance hit over compiling it natively, but in some situations the cost is certainly worth it. And yes, I realize it's always an option to rely on the server to compile or interpret code, but I'm specifically interested in client-side approaches.


UPDATE: A lot of responses include references to compilers that weren't implemented in Javascript. I just want to stress that the interpreter itself should be implemented in Javascript so that both it and the source language code could run on the browser on your grandparent's computer.

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

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

发布评论

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

评论(7

森林迷了鹿 2024-10-14 06:24:26

CoffeeScript 是一种编译为 JavaScript 的编程语言。

CoffeeScript is a programming language that compiles to JavaScript.

梦晓ヶ微光ヅ倾城 2024-10-14 06:24:26
  • Objective-J 是一种基本上采用 Objective-C 的“目标”部分并将其粘合到 ECMAScript 的语言
  • Clamato 是一种受 Smalltalk 启发的客户端 Web 脚本语言

另请参阅此问题:除了 Objective-J 之外,还有其他语言可以在浏览器中“编译”为 JavaScript 吗?

  • Objective-J is a language that basically takes the "Objective" part of Objective-C and glues it to ECMAScript
  • Clamato is a Smalltalk-inspired language for client-side web scripting

See also this question: Are there other languages than Objective-J that get “compiled” to JavaScript in the browser?

々眼睛长脚气 2024-10-14 06:24:26

社区 Wiki,让我们将其混搭起来 :-)

jsc - 从 CIL 重新编译(从 VB.NET 编译的 CIL 、C# 等)

Script# - 从 C# 编译(源代码)。

GWT:Google Web Toolkit - 从 Java 编译。

Emscripten - 从 LLVM 编译。应该能够工作(语言 X)-> LLVM-> JavaScript,减去问题,其中语言 X 有一个 LLVM 编译器。

Community Wiki, let's mash this out :-)

jsc - re-compiles from CIL (CIL compiled from VB.NET, C#, etc.)

Script# - compiles from C# (source-code).

GWT: Google Web Toolkit - compiles from Java.

Emscripten - compiles from LLVM. Should be able to work (Language X)->LLVM->JavaScript, minus issues, where Language X has an LLVM compiler.

合久必婚 2024-10-14 06:24:26

j2js 将 Java 字节码编译为 Javascript(例如 Java、Scala 等)。

j2js compiles Java bytecode to Javascript (e.g., Java, Scala, etc.).

如歌彻婉言 2024-10-14 06:24:26

Pyjamas 可以将 Python 编译为 JavaScript。这是服务器类型的翻译; Pyjamas 尚未用于编译自身,因此还没有 JavaScript Python 解释器。

Pyjamas can compile Python to JavaScript. That's a server-type translation; Pyjamas has not yet been used to compile itself so there is no JavaScript Python interpreter.

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