Pnuts to Java Translation

pnuts.trans package provides a Pnuts-to-Java translator. Make sure that pnuts.trans package is included in your CLASSPATH.

Creating Java code

translate(scriptFile or inputStream [, className [ , printWriter ]] )

The function translate() converts Pnuts scripts to a Java class className and saves into printWriter. If className is omitted, the class name will be "NoName". If printWriter is omitted, the Java code is saved in className + ".java" file.

Generated Java code include a method 'public static void main(Context)', which is the entry point to the compiled code. 'public static void main(String a[])' is also included so that it can be executed by the 'java' command.

> load("trans")
> translate("function fib(n) if (n < 2) n else fib(n - 1) + fib(n - 2)", "Fib")
> exit()
C:\> javac -O Fib.java
C:\> pnuts
> Fib::main(getContext())
function fib(n)
> fib(25)
75025

The Command Line Interface

C:\> pnuts2java scriptFile className
C:\> pnuts2java pystone.pnut Pystone
C:\> javac Pystone.java
C:\> java Pystone
...

Back