Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL vs File execution #3

Open
mbmcmullen27 opened this issue Jun 16, 2021 · 1 comment
Open

REPL vs File execution #3

mbmcmullen27 opened this issue Jun 16, 2021 · 1 comment

Comments

@mbmcmullen27
Copy link
Owner

mbmcmullen27 commented Jun 16, 2021

We're printing all expressions still when we execute a file, this works how we expect when we're actively typing in the REPL, but when run from a file output is not what we expect.

  • this was a challenge implementation from an earlier chapter
  • need a mechanism to know whether or not we're executing from a file. (runFile() method is a good candidate)

java com/craftinginterpreters/lox/Lox tests/while

testfile prints numbers 1-10

while (x<10)
{ 
    x = x+1;
    print x;
}

image

@mbmcmullen27
Copy link
Owner Author

Closer to an implementation that works with this commit, we detect when we're called from a file and set a public static var in the interpreter before we execute.
b077953

image

HOWEVER...
that doesn't get us all the way, we don't print anything for statements, consider JS console will print undefined for var statements, and we still print twice in the example loop above. We should consider extending this to only print the resulting expression or last expression instead of every expression, OR no printing when you're inside a block statement. I think the former is what most interpreters do.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant