Skip to content

First Syntax Tree

Choose a tag to compare

@JDCodeWork JDCodeWork released this 16 Apr 00:27
· 74 commits to main since this release

📦 Release 0.5.0First Syntax Tree

✨ Features

First version of rslox capable of generating syntax trees!

rslox is a Rust implementation of the Lox language, based on the book Crafting Interpreters. This release completes the Parsing Expressions section, allowing the language to convert a sequence of tokens into a correctly structured AST (Abstract Syntax Tree).

✅ Highlights:

  • 📖 Implemented the Parsing Expressions section from Crafting Interpreters.
  • 📝 Support for arithmetic expressions with correct operator precedence and associativity.
  • 🛠️ The run command now prints the generated AST for each entered expression.
  • 🎨 Significant CLI improvements, including:
    • New parameters and commands
    • Colored output for better readability
    • Improved command-line feedback and structure

📚 Example:

Expression:

1 + 2 * (3 - 4) / 5

AST:

(+ 1 (/ (* 2 (group (- 3 4))) 5))

⚠️ Warnings

  • rslox currently does not support keywords.
  • If a keyword (such as print, fun, if, return…) is found during interpretation, the program will raise an error and exit immediately with exit code 1.
  • Because of this, the example file located in the playground will fail to run, as it contains unsupported keywords.

🛠️ Usage

Run an expression and print its AST:

cargo run -- run

Then enter expressions like:

(1 + 2) * 3

🚀 Next Steps (0.5.1)

  • Add a debug command with the --ast option to optionally print the AST, moving this functionality out of the run command.

✍️ Based on: Crafting Interpreters by Bob Nystrom