How do you write a programming language interpreter in its own language?

It’s been done. Heck, Wikipedia lists enough of them you really have a choice if you want to go that route. Don’t entirely know why you would.

Worse than that: The Java programming model does a lot of type checking in the JVM, meaning values are type tagged (as floats, doubles, integers, object references, etc.) and the virtual machine will throw exceptions if you try to do the kinds of casting C programmers expect to be able to do unless the compiler has made arrangements otherwise somehow.

Here’s an old-fashioned-style bootstrap where someone starts by inputting raw machine code into a file and iteratively improves the language by writing the compiler for the next version in the version he’s just written. You might call it the Tony Stark Method, in that he begins [del]IN A CAVE, WITH A BOX OF SCRAPS[/del] with nearly nothing most programmers would call a ‘development tool’ and ends up with as good of a compiler as he desires.

I wonder if there’s a way in Java itself to intercept the JIT output, if so you could (theoretically) use some severe finagling to “compile” your Java code (or at least very simple programs), bypassing the JVM entirely (except for the first run of the program), for verification/completeness you’d also probably have to use reflection, especially when dealing with complicated listener structures.

I’m not sure why you’d want to do this, since the JVM is part of the point of Java (and the JIT compiler honestly does some really cool optimizations at runtime), but it would be an interesting experiment – if intercepting the JIT output is possible in Java.

So you can easily port stuff written in C, and have one binary that will run on any system. Heck, if it’s been implemented well enough, you might even be able to use it to create Java Applets, so you could run these programs in a browser. I know that sort of thing is really popular with emulators.