Search code examples
javainterpreterforth

Forth Interpreter in Java


Here I found a Simple Forth Interpreter implemented in Java.
However I don't understand the significance of it if I want to use it?

What could be the advantage of the Forth Interpreter:

  • If the final compiled code to be executed by the JVM is still "Byte code" what would we the Forth Interpreter be doing?
  • Will it help in writing efficient/tight programs?
  • Will I be writing my code in Forth and the interpreter will convert it to Java?

Your thoughts...


Solution

  • Will it help in writing efficient/tight programs?

    That's debatable.

    I'm sure that FORTH folks will tell you that it is fast. But I doubt that the execution speed of a FORTH program running on a FORTH interpreter implemented in Java will line up against the speed of an equivalent program implemented directly in Java. For a start, the JIT compiler won't be able to do as a good job of optimizing the FORTH interpreter as it can for the plain Java version.

    If by "tight" you mean "using less memory", I think that the difference will be marginal. Remember that in both the "FORTH in Java" and "plain Java" cases you have all of the memory overheads of a Java JVM. This is likely to swamp any comparison of FORTH code density versus equivalent compiled Java code density.