Need help with interpreter
JamaicanFriedChicken opened this issue · comments
Hi Franci, I would like to ask how did you test each component of the interpreter as you were following the crafting interpreter's book, I really like the book and would also like to learn how to make one, finding it hard to set up the first part and trying to test the Scanner feature of the interpreter.
Would I have to build and use the lox interpreter to test each component? or is there another way? I have kept trying to compile it in Java with javac
but kept getting many errors.
Hi, I followed the code in the book and tested each added step manually. For the unit tests, I mostly used the tests present in https://github.com/munificent/craftinginterpreters/tree/master/test. But yeah the interpreter needs to be built first, then you run the python script in the utils folder. For compiling I used the IntelliJ IDE.
Ahh, alright. May I ask how did you test each step manually, did you test it on a string? like
var a = 100;
I am having trouble finding a way to test it on IntelliJ. Sorry I am quite new to this, spent a few hours trying to compile it only to receive tons of errors.
You need to build the jar file and put it in build/java/jfail.jar. This should be pretty straight forward as the project doesn't have external dependencies.
For the manual testing, I just ran the jar file as it has REPL once you run it.
You need to build the jar file and put it in build/java/jfail.jar. This should be pretty straight forward as the project doesn't have external dependencies.
build/java/jfail.jar in IntelliJ? or rather the interpreter's project folder?
For the manual testing, I just ran the jar file as it has REPL once you run it.
Oh! this! I have been constantly trying to import custom libraries into a Jshell console to try run and testing each step...wow! you are a lifesaver.
build/java/jfail.jar in IntelliJ? or rather the interpreter's project folder?
relative to the project folder, once in project root you run ./util/test.py
.
build/java/jfail.jar in IntelliJ? or rather the interpreter's project folder?
relative to the project folder, once in project root you run
./util/test.py
.
ok, so I put the.jar
file in the project root folder then run the test.py
. This .jar
file would be similar to a Makefile? where it seems you compile the .java
file then jar
it?
I have another question though, once you add more features to the interpreter, I will basically have to make a new jar file right or I don't need to?
No, you need to build jar
artifact of the project and put it in build/java/jfail.jar relative to project root. jar
is very different from Makefile, it acts as a zip folder of binaries (more on the format here https://en.wikipedia.org/wiki/JAR_(file_format)). With IntelliJ is simpler to build the jar artifact.
Yes, you would have to rebuild jar every time.
No, you need to build
jar
artifact of the project and put it in build/java/jfail.jar relative to project root.jar
is very different from Makefile, it acts as a zip folder of binaries (more on the format here https://en.wikipedia.org/wiki/JAR_(file_format)). With IntelliJ is simpler to build the jar artifact.
Ahh, so I have built the jar
artifact of the project then I put it in thebuild/java/
folder as you said, which is located in the src
folder (my project root directory). Whenever I would try to run it as a REPL (using the command in the terminal : java -jar Jar.jar
), it'd always come up as (I named it Jam in place of lox)
Error: Could not find or load main class com.jam.Jam
Caused by: java.lang.ClassNotFoundException: com.jam.Jam
I had to move the .jar file out of the build/java/
to see if i was able to run it as a REPL. It'd always end up as an error.
Even after I selected the main class as com.jam.Jam
but didn't specify the class path in IntelliJ. I will go use the test.py
and see how it goes.
Should I just run the test.py
file? I wanted to see try run it as a REPL to manually test it out as you said but it isn't working as I thought it would.
Yes, you would have to rebuild jar every time.
ok, this makes sense.