views:

788

answers:

5

I am seeing all these new languages for .NET and JVM. How does one begin to make one?

I can't find any good documentation on JVM or MSIL specifications.

Edit

I already know how to parse, I am more interested in how there are so many people making new languages that are based on those platforms.

+2  A: 

The Java Virtual Machine Specifications, Second Edition is available online.

One can target the JVM by having a writing a compiler that produces Java bytecode (which is defined in the JVM specifications.)

Or, by utilizing existing libraries such as Apache BCEL, one can produce valid class files through a Java program without having to actually manipulate the bytecode at the byte-level.

coobird
+5  A: 

You're kind of in luck. There is an explosion of languages being developed for .NET, and there are articles / resources targeted at individuals such as yourself (not just large corporations with tons of money to invest).

Search for "dynamic language runtime", and go from there.

Here are some links:

Blog of the guy who is the brain behind IronPython

The home of the Dynamic Language Runtime

An article about how IronPython was implemented

A blog posting talking about abstract syntax trees and the DLR

Charlie Flowers
+3  A: 

MSIL isn't called MSIL any more, as a public standard it's CIL (Common Intermediate Language), part of the CLI (Common Language Infrastructure) standard.

Here's the ECMA-335 CLI standard specification.

Guffa
A: 

For .NET you can use the DLR's expression trees or even compile to an existing high-level langauge like C# or Java and then compile that. Some high-level non-VM languages (liek Haskell and Eiffel) compile to C. If you want to compile to MSIL or JVM bytecode, you can use Mono.Cecil or BCEL to make that easier to do.

Mark Cidade
+1  A: 

Answer to updated question:

I already know how to parse, I am more interested in how there are so many people making new languages that are based on those platforms.

What enables so many people to develop languages for these platforms is probably the availability of several very complete examples with publically available source code.

The specifications of the platforms are available to download, and it didn't take long for people already experienced in writing compilers to produce new backends for their existing compilers that would target the new platforms.

Microsoft themselves published Rotor, there is also Mono of course. There are also many popular techniques for runtime code generation which build simple wrapper classes on the fly - these too are mini compilers.

The C# compiler is pretty fast and exposes most of the CLR's facilities in a direct way, so you could write a compiler that simply produced temporary C# files and then got the C# compiler to finish the job.

Daniel Earwicker