I am reading Crafting Interpreters by Robert Nystrom This is an implementation of the first interpreter in C++
var x = 5;
var y; // Sets to null
y = 4;
if (condition) {
// statement body
} else {
// optional else clause
}
while (condition) {
// statement body
}
for (init; condition; increment) {
// statement body
}
fun myFunction(arg1, arg2) {
// do stuff
}
// function call
myFunction(x, y);
class Car {
//python-style initializer function
init(color) {
this.color = color
}
}
myCar = Car("green");
print myCar.color; //green
fun fib(n) {
if (n <= 0) return 0;
if (n == 1 or n == 2) return 1;
return fib(n - 1) + fib(n - 2);
}