Lox is a simple programming language created by Bob Nystrom for his book Crafting Interpreters. I implemented it in C++. Atleast I tried to. I am still working on it :) Also many thanks to Replit for making this weird web-stack easily hostable. Under the hood there is C++, Python, CMake, Make and HTML running all in the same repo.
print("Hello World");
// -------------------------------------
fun pow(base, exp) {
if (exp == 1) {
return base;
}
return base * pow(base, exp - 1);
}
// -------------------------------------
fun print10() {
var print_str = "";
fun print_rec(i) {
if (i > 0) {
print_str = print_str + str(i) + " ";
print_rec(i-1);
}
}
print_rec(10);
return print_str;
}
print(print10());
print("2 raised to 10 is ", pow(2,10));
// -------------------------------------
{
print("-------------------FOR--------------------");
for (var a = 1; a < 10; a = a+1) {
print(a);
}
print("------------------------------------------");
}