munificent / craftinginterpreters

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

How to run a file with lox code? #833

Closed kvnandula04 closed 3 years ago

kvnandula04 commented 3 years ago

Hi, so, I'm new to all of this but I am trying to run a file with lox code and am not sure how to do it. I cloned the java interpreter to try it out and I feel so constrained as I can only type single line code snippets in the REPL. So, I was wondering about how to run a file with multiline code. I have a few questions:

  1. What file extension do I use?
  2. How do I run it? Is it using the terminal?
  3. Do I need to compile the code before running it?

Any help would be much appreciated! Thanks a lot!

munificent commented 3 years ago

What file extension do I use?

It doesn't matter. The interpreter will accept anything. But by convention, it's .lox.

How do I run it? Is it using the terminal?

Yes, it runs on the command line. You run it the same way you start the REPL except you also pass the path to the file you want to run.

Do I need to compile the code before running it?

No, Lox is a scripting language and runs from source.

kvnandula04 commented 3 years ago

Would you be able to share a script to run it from command line please?

munificent commented 3 years ago

It's literally just:

jlox your_lox_program.lox