First of all I want to say that the book is amazing. I am implementing my version of the language in Rust, and trying to mimic Java implementation has been quite fun.
I have been thinking how to solve challenge 1 of chapter 2.6 (statements and state). After implementing statements, REPL is unable to interpret expressions and return (or print) their values (as interpreter takes list of statements as an argument). In fact, it is a syntax error to enter an expression into a REPL now (since parser thinks expressions are part of expression statements and need to have semicolon at the end).
The only solution I could come up with for now is to merge expressions and statements (where statements are expressions which return nil), would this be the correct approach? Could someone nudge me into a correct direction?
First of all I want to say that the book is amazing. I am implementing my version of the language in Rust, and trying to mimic Java implementation has been quite fun.
I have been thinking how to solve challenge 1 of chapter 2.6 (statements and state). After implementing statements, REPL is unable to interpret expressions and return (or print) their values (as interpreter takes list of statements as an argument). In fact, it is a syntax error to enter an expression into a REPL now (since parser thinks expressions are part of expression statements and need to have semicolon at the end).
The only solution I could come up with for now is to merge expressions and statements (where statements are expressions which return
nil
), would this be the correct approach? Could someone nudge me into a correct direction?