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?
ps : Sensei love enterprise quality code.
Name:
Anonymous2009-10-20 6:20
this is one of the strangest requests i've seen on /prog/ all week.
It's easy to write a metacircular one in Lisp, in only about a page of code. If you want to do it in Java or C, be prepared to write a few hundred lines at least. There's many of them floating around on the internet. Which Lisp to be precise? There's many of them, and they have different semantics and features, some easier and some harder to implement.
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");
>>5 f = fopen(*argv++);
fail (I noticed you also wrote null instead of NULL but that is not enough for me to assume you're a retard; maybe you're coming from a lisp background or other, which is O.K. doing shitty mistakes with pointers is just newbiefucktastic. fuck off from /prog/