#TH5 Parser output specification for strings

I just realized that since strings are not quoted in the ./prog parse output, there is no way to disambiguate between strings and expressions. Thus

(- 2.0 1.0)

could be a subtraction AST node with children 2.0 and 1.0, or it could be a single string node.

Could this be a design flaw in the specification?

Hey @yinchi, that’s a great question! This is just an intermediate representation. Your interpreter should retain the correct tokens internally.

Just to clarify: we follow the same AST formatting as the official Lox implementation. You can verify the expected output by running the reference implementation locally:

  1. Clone GitHub - munificent/craftinginterpreters: Repository for the book "Crafting Interpreters" · GitHub

  2. Run make java_chapters

  3. Edit test/expressions/parse.lox

  4. Run java -cp build/gen/chap06_parsing com.craftinginterpreters.lox.Lox test/expressions/parse.lox

1 Like