最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Languages that interpret down to Javascript? - Stack Overflow

programmeradmin1浏览0评论

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.

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.

Share Improve this question edited May 23, 2017 at 12:09 CommunityBot 11 silver badge asked Dec 11, 2010 at 0:54 Sage MitchellSage Mitchell 1,5838 silver badges31 bronze badges 2
  • +1 Higher order language -> higher order language compilation is always interesting. – Orbling Commented Dec 11, 2010 at 1:05
  • Re: your update: the compiler doesn't have to implemented in JavaScript, only in a language that can run in JavaScript. The CoffeeScript compiler, for example, is written in CoffeeScript. But since the CoffeeScript compiler compiles CoffeeScript to JavaScript, it can compile itself to JavaScript and thus run in the browser. The same applies to any compiler written in C (since there is a compiler which compiles C to JavaScript), Java, any .NET language that compiles to CIL, any JVM language that compiles to JVML, any language that compiles to LLVM Bitcode or LLVM IR, ... – Jörg W Mittag Commented Dec 11, 2010 at 14:25
Add a comment  | 

7 Answers 7

Reset to default 6

CoffeeScript is a programming language that compiles to 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?

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.

some more or less toy interpreters in pure javascript

  • ruby http://hotruby.yukoba.jp/
  • logo http://www.calormen.com/logo/
  • lisp http://joeganley.com/code/jslisp.html
  • forth http://www.forthfreak.net/jsforth.html

and of course the obligatory

  • http://www.iamcal.com/misc/bf_debug/

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

List of languages that compile to JS

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.

发布评论

评论列表(0)

  1. 暂无评论