10

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.

Community
  • 1
  • 1
Sage Mitchell
  • 1,563
  • 8
  • 31
  • +1 Higher order language -> higher order language compilation is always interesting. – Orbling Dec 11 '10 at 01: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 Dec 11 '10 at 14:25

7 Answers7

6

CoffeeScript is a programming language that compiles to JavaScript.

calvinf
  • 3,754
  • 3
  • 28
  • 41
4

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.

  • @RA Added Emscripten link from you, that compiles from LLVM :-) Feel free to add more information. –  Dec 11 '10 at 01:15
4
  • 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
  • 1
  • 1
Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
2

some more or less toy interpreters in pure javascript

and of course the obligatory

user187291
  • 53,363
  • 19
  • 95
  • 127
1

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

Jean-Philippe Pellet
  • 59,296
  • 21
  • 173
  • 234
1

List of languages that compile to JS

clyfe
  • 23,695
  • 8
  • 85
  • 109
0

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.

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215