A C# implementation of a Lox interpreter (adapted from jlox, credit to "Crafting Interpreters" (book, repo) by Robert Nystrom)
- Language supports nill equality comparison
var a = nil;
var b = nil;
print a == b;
>> True
var c = "not nil";
print a == c;
>> False
- Static methods are supported:
class Greeter{
class SayHello(){
print "Hello, I am a static method."
}
}
Greeter.SayHello();
>> Hello, I am a static method.
var a = Greeter();
a.SayHello();
>> Hello, I am a static method.
- "Getter" propeties are supported:
class Person{
init(name, surname){
this.name = name;
this.surname = surname;
}
fullname{
return this.name + " " + this.surname;
}
}
var john = Person("John", "Smith");
print john.fullname;
>> John Smith
Furthermore, a compile-error is thrown if the getter never returns a value.
- Other features: ternary conditional (a ? b : c), comma operator support, breaking out of loops, C-style block comments (
/*...*/
)
- jlox uses the Void type for its Statement Visitor:
class Interpreter implements Expr.Visitor<Object>,
Stmt.Visitor<Void> {
void interpret(Expr expression) {
C#, however, does not allow this, so I instead opted to use a Unit return type (I used a handy one I saw in UniRx).
- jlox uses an anonymous object to implement the native 'clock' function. However, C# does not allow anonymous types to implement interfaces, so I manually created a separate Clock type.