A Tree-walk Interpreter implementation as shown in Crafting Interpreters.
- Intro
- A Map of thr Territory
- The Arsenic(Lox) language
- Scanning
- Represening code
- Parsing Expressions
- Evaluating Expressions
- Statements and State
- Control flow
- Functions
- Resolving and Binding (in progress)
- Classes (in progress)
- Inheritance (in progress)
For normal build run:
# in build dir
cmake <src-dir>
For debug build run:
# in build dir
cmake -DCMAKE_BUILD_TYPE=Debug <src-dir>
and then
cmake --build .
Below program prints Fibonacci sequence till 20th number.
fun fib(n) {
if (n <= 1)
return n;
return fib(n - 2) + fib(n - 1);
}
for (var i = 0; i < 20; i = i + 1) {
print fib(i);
}
To run above code, do:
arsenic test.nic
Classes with basic Inheritance
class Doughnut {
cook() {
print "Fry until golden brown.";
}
}
class BostonCream < Doughnut {}
BostonCream().cook();