Skip to content

Latest commit

 

History

History
60 lines (50 loc) · 849 Bytes

readme.md

File metadata and controls

60 lines (50 loc) · 849 Bytes

Lax - A Lox interpreter

Examples

// Operations
print(1 + 2);
print(2 - 1);
print(2 * 2);
print(2 / 2);

// Comparison
print(2 == 2);
print(2 != 1);
print(2 > 1);
print(1 < 2);
print(2 >= 2);
print(2 =< 2);

// Strings
print("Hiya!");
print("Hello, " + "world!");

// Booleans
print(true or false);
print(true and false);

// Null values
nil

// Variables
var a = 0;
print(a);
a = a + 1;
print(a);

// Conditionals
if (2 > 1) {
  print("The universe still works!");
} else {
  print("oh what")
}
// Looping
var i = 0;
while (i < 100) {
  print(i);
  i = i + 1;
}

for(var i = 0; i < 100; i = i + 1;) {
  print(i);
}

// Functions
fun plus_one(i) {
  return i + 1;
}

print(plus_one(1));

// Note: Functions are like variables, witch means you can pass them to other functions. You cant do this though: function(fun (i) { return i + 1; })