Parser, Interpreter & Runtime Error Handling
📦 Release 0.6.0 — Parser, Interpreter & Runtime Error Handling
✨ Major Features
This major release marks a significant milestone for rslox — the language can now parse and evaluate expressions!
🎯 Core Language Features:
✅ Full Expression Parser:
- Binary operators: arithmetic (
+,-,*,/), comparison (>,>=,<,<=), equality (==,!=) - Unary operators: negation (
-), logical NOT (!) - Grouping expressions with parentheses
- Literal support: numbers, strings, booleans,
nil - Proper operator precedence and associativity
🚀 Interpreter with Evaluation:
- Complete expression evaluation system
- String concatenation support (
"hello" + " world") - Type checking for operations
- Runtime error detection:
- Division by zero prevention
- Type validation (e.g., can't negate a string)
- Invalid operation detection
🛡️ Robust Error System:
- Separated error types for better debugging:
ScanErr— Lexical analysis errorsParseErr— Syntax errorsRuntimeErr— Execution errorsSystemErr— File and IO errors
- Detailed error messages with line/position information
- Parse error recovery with
synchronize()for REPL resilience
🧪 Quality Improvements:
✅ Unit Tests:
- Comprehensive interpreter tests
- Type error validation tests
🔄 Type System Refactor:
Literalrefactored from struct to enum with typed variants:Literal::Number(f64)Literal::String(String)Literal::Boolean(bool)Literal::Nil
- Better type safety and pattern matching
📚 Usage Examples:
Evaluate arithmetic expressions:
echo "1 + 2 * 3" | cargo run -- run
# Output: Number(7.0)String concatenation:
echo '"Hello" + " " + "World"' | cargo run -- run
# Output: String("Hello World")Runtime error handling:
echo "10 / 0" | cargo run -- run
# ERROR RUNTIME | Division by zero.Debug mode with AST:
cargo run -- run -p playground/factorial.lox --show-ast