可以解释为 Javascript 的语言吗?
另一篇文章质疑将语言编译为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
CoffeeScript 是一种编译为 JavaScript 的编程语言。
CoffeeScript is a programming language that compiles to JavaScript.
另请参阅此问题:除了 Objective-J 之外,还有其他语言可以在浏览器中“编译”为 JavaScript 吗?
See also this question: Are there other languages than Objective-J that get “compiled” to JavaScript in the browser?
社区 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.
纯 javascript ruby 中的一些或多或少的玩具解释器
当然还有强制性的
some more or less toy interpreters in pure javascript
and of course the obligatory
j2js 将 Java 字节码编译为 Javascript(例如 Java、Scala 等)。
j2js compiles Java bytecode to Javascript (e.g., Java, Scala, etc.).
编译为 JS 的语言列表
List of languages that compile to JS
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.