An implementation of the Lox programming language in Dart.
This implementation used Crafting Interpreters as a guide.
It includes a couple of features from the end of chapter challenges:
- Ternary operator (?)
print ? true "true" : "false; - Read builtin
// Declare variable and read into it
var a;
read a;
// Or declare and assign in one step
read var a;
- Lambda functions
fun thrice(fn) {
for (var i = 1; i <= 3; i = i + 1) {
fn(i);
}
}
thrice(fun (a) {
print a;
});
// "1".
// "2".
// "3".
dart run
Building package executable...
Built dlox:dlox.
>
print "Hello World";
Hello World
>
dart run bin/dlox.dart run test/test_cases/hello_world.dlox
Hello World
dart run bin/dlox.dart format test/test_cases/hello_world.dlox
print "Hello World";
Powers the Dlotter project