Generic implementation which works with any input code given in the new language format (using Func, Stmt, Expr classes)
Samples: Factorial and Fibonacci
// Sample factorial function in Java
public class Fac {
public static void main(String[] args) {
int n = Integer.parseInt(args[0]);
System.out.println(fac(n));
}
public static int fac(int n) {
if (n <= 1) {
return 1;
}
return n * fac(n-1);
}
}
// Sample fibonacci function in Java
public class Fib {
public static void main(String[] args) {
int n = Integer.parseInt(args[0]);
System.out.println(fib(n));
}
public static int fib(int n) {
if (n <= 1) {
return n;
}
return fib(n-1) + fib(n-2);
}
}