geertguldentops / jlox

Java implementation of the Lox programming language from the book "Crafting Interpreters"
MIT License
2 stars 1 forks source link

Doubt: How do I run a file with lox code? #1

Open kvnandula04 opened 4 years ago

kvnandula04 commented 4 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 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!

geertguldentops commented 4 years ago

Hi @kvnandula04,

Thanks for showing interest! Did you find the information in the README.md file? It gives a brief overview of how you can run a lox program.

To answer your specific questions:

  1. The file extension does not matter, the Java interpreter does not check this. I use .lox by convention.
  2. The easiest way to run a program is by using an IDE, I recommend using IntelliJ IDEA. Just run the main program (LoxMain). You were already able to do this successfully, this gives you the REPL functionality. Just pass in the absolute path to a Lox program as the first program argument and it will interpret that file as a Lox program.
  3. You need to compile the Java program (the interpreter itself) but the Lox code itself does not need to be compiled, it is immediately interpreted by the Java program.

I wrote a bunch of acceptance tests that run Lox programs. You can find those Lox programs here: src/main/resources/lox/src for instance: HelloWorld.lox

Hope this explanation helps. Happy coding!

kvnandula04 commented 4 years ago

Hi @geertguldentops,

Wow! Thanks for the help! Getting some things cleared up now. For point 2, I'm still uncertain. Would you mind sharing a code snippet or a screenshot of how to do it please?

For some context, I'm currently building an IDE for a lox dialect that I'm working on called Krystal. It's expected to look something like this...

image

And I plan to make it an executable file which I can upload online so that people can download that and start using Krystal(don't know if that's possible in Java). So any help with this would also be much appreciated!

Thanks in advance!