Hey /prog/riders,
for a school project i must write a LISP interpreter in JAVA. I've read SICP but there's no implementation of the interpreter in J2EE.
How can i do that?
Just write a simple recursive descent parser, it's rather simple for lisp. If you end up with more than about 500 lines of C code for the entire interpreter you are doing something wrong. As far as doing it in java, private static final String code = "
#include <stdio.h>
#include <stdlib.h>
FILE* f;
int main(int argc, char **argv) {
if(argc <= 1) {
fprintf(stdout, \"Usage: %s [filename]\", argv);
exit(1);
}
f = fopen(*argv++);
if(f == null) exit(1);
readFile(f);
sExpression();
interpret();
return 0;
}";
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileOutputStream("lisperu.c")));
pw.write(code);
pw.close();
Runtime.getRuntime().exec("gcc -O3 -o lisperu ./lisperu.c");
Runtime.getRuntime().exec("./lisperu testProgram.lisp");