munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.43k stars 1.01k forks source link

How do I build and run the code from individual chapters? #1110

Closed edbird closed 1 year ago

edbird commented 1 year ago

Currently trying to build and run the code for Chapter 4.

So far I have installed the prerequisites and got as far as: make java_chapters.

I can see the code under /gen/chap04_scanning/com/craftinginterpreters/lox/

I can see the compiled .class files under /build/gen/chap04_scanning/com/craftinginterpreters/lox/

However I am now not sure what to do with the files produced from the build output. Can I run Lox.class with java somehow?

I am using Linux. Although I have a good understanding of C and C++, including build systems like CMake, I haven't used Java for years, so I really don't know what I am doing.

I have managed to compile and run a version of Hello World in Java, which I did by first building the Main.java file with javac and then running the Main.class file with java Main.

But it seems this doesn't work with the file Lox.class. I am not sure why exactly, but I believe it relates to the fact that packages are being used, whereas I don't use this in my < 10 line Hello World example.

Can anyone point me in the right direction? Thanks

edbird commented 1 year ago

Cracked it:

Navigate to /build/gen/chap04_scanning

Run: java com.craftinginterpreters.lox.Lox test.lox