tslox is an interpreter of Lox language written entirely in TypeScript.
Lox is a scripting language created by Robert Nystrom for Crafting Interpreters book. tslox is the Tree-Walk Interpreter implemented in TypeScript.
- Main parts implemented
- Challenges
- Personally interested features
Some differences to basic Lox implemented in the book
Check test file for more detail
var n = 10 ;
var fib = [0, 1] ;
for(var i = 2; i < 20; i = i + 1){
fib[i] = fib[ i-1 ] + fib[ i-2 ] ;
}
print fib ; // [ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181 ]
print fib.length ; // 20
print 5 > 3 ? "yes" : "no" ; // "yes"
fun thrice(fn) {
for (var i = 1; i <= 3; i = i + 1) {
fn(i);
}
}
thrice(fun (a) {
print a ;
});
Install dependencies
$ yarn
$ yarn lox <file name>
For example
$ yarn lox ex/helloWorld.lox
Hello world!
$ yarn lox
For example
$ yarn lox
[lox]: var cookie = 5 ;
[lox]: print cookie ;
5
[lox]: Bye! # cmd + c to exit
yarn test # immediately in watch mode