Question

I am trying to make my own programming language by making an interpreter for it in Java, but lately people have been telling me that an interpreter needs to be in the same language as the one it is interpreting. Is this true? Then what am I building?

Was it helpful?

Solution

No, it isn't true.

To use the same language, you would also need to have a compiler for that language, so that you could compile the interpreter to machine code.

If all you have is an interpreter, then you would just end up with interpreters all the way down. To run the interpreter, you would need an interpreter. To run that second interpreter, you would need a third one, and so on.

OTHER TIPS

The Factor programming language started as a Java interpreter, as have many others. For encouragement and enlightenment, I suggest studying or at least looking at, the following books: Seven Languages in Seven Weeks, Seven More Languages in Seven Weeks, and Masterminds of Programming: Conversations with the Creators of Major Programming Languages. I'm constantly researching languages, and trying to learn about them, and what I've listed are some of my favorite books on the subject, but by no means the only ones of course.

Also, I'm currently writing a Forth-like concatenative interpreter in C#. That's one of the easiest interpreters to make, because it's strictly space-delimited, strictly left-to-right, postfix, and homoiconic, like LISP, so any macros or metaprogramming is the same shape as the language itself, not an additional language bolted-on like the preprocessor macros of C and C++. (Not that I'm against them, but it is a whole new langauge to learn on top of the main language, instead of like Lisp, where the macros are written in the language itself, and have the full power thereof.)

Finally, this book, Let over Lambda, is a mind-blower that covers the power of Lisp macros. I found most of it online on Doug's web site. There's a chapter, "Lisp Moving Forth Moving Lisp", which I still haven't read that has really piqued my interest.

Keep writing your interpreter in Java. Don't let the stinkers hold you down!

Also, if you look in the "Seven More Languages" book in the Factor language chapter, at the interview with Slava Pestov, the inventor of Factor, which at first was written in Java, he describes how he ultimately transitioned his language to being separate from Java. He used an image model for compiled code, and gave his language the ability to write out the image. Then he created a virtual machine, and REPL interpreter in the C language, and finally gave his new C kernel the ability to load an image, wrote out the image from Java, read the image into his C-kernel version, and presto, eureka, he suddenly had a new language no longer dependent on JAVA. Not that you have to go that way. But it was way interesting. Keep going!

You want a language that’s good for writing interpreters. You might want to write a COBOL interpreter. Never in a million years would you write one in COBOL.

So this statement is utter nonsense. Go ahead and write your interpreter in Java.

Licensed under: CC-BY-SA with attribution
scroll top