A tree-walking Lox interpreter in Python - based on the book "Crafting Interpreters" by Robert Nystrom
- Programming language implementations are interesting!
- Get better at OOP (the book uses Java already, but I don't know Java)
- Get better at Python
Py-lox is a fully-featured interpreter for the Lox programming language. The lox language is very similar to Java, with focus on object-oriented design.
- Variables (
var
) - Conditionals (
if
,else if
,else
) - Iteration (
for
,while
) - Functions (
fun
) - Classes (
class
,super
) - Printing (
print
) - Comments (
//
)
git clone https://github.com/kris-gaudel/py-lox.git
cd py-lox
cd pylox
cd src
python3 lox.py
python3 lox.py [path to file]
print "Hello, world!";
var a = 1;
if (a == 1) {
print "1";
} else {
print "not 1";
}
var b = 1;
while (b < 5) {
print b;
b = b + 1;
}
for (var b = 1; b < 5; b = b + 1) {
print b;
}
fun say_hello(name) {
return "Hello" + name + "!";
}
print say_hello("Kris");
class Breakfast {
init(meat, bread) {
this.meat = meat;
this.bread = bread;
}
}
class Brunch < Breakfast {
init(meat, bread, drink) {
super.init(meat, bread);
this.drink = drink;
}
}