All statements must be followed by ;
.
Statements are assignments, expressions, returns, empty, or loops.
x = 3;
x = if (y == null) 3 else 4;
x = if (y == null) {
print("y is null");
3;
} else {
print("y is not null");
4;
};
x = if (y == null) { y = init(); y; }
for (i = 0; i != 5; i = i + 1) {
print(i);
}
Literal: null
.
Literal: 123
(decimal) / 0xbeef
(hex)
Literal: 0.123
Literal: "abc\ndef\tgh"
function (a, b, c) { return a + b + c; }
[1, 2, "hi", 4, 5]
Get an element using the []
operator.
Support <
, >
, <=
, >=
, &
, |
, []
.
Operator | Call fun if on objects |
---|---|
< , > , <= , >= , == , != |
Class.__cmp(x, y) |
&& |
Class.__land(x, y) |
` | |
! |
Class.__lnot(x) |
+ |
Class.__plus(x, y) , Class.__uplus(x) |
& |
Class.__band(x, y) |
[] , []= |
Class.__get(k) , Class.__set(k, v) |
class C {
x = 5;
f = function(this) { this.y = 6; };
};
Classes are also objects. Usage: C["x"]
or C.x
(equivalent).
The above class is equivalent to the object
{
"__type": "class",
"__classname": "C",
"x": 5,
"f": function (this) { this.y = 6; }
}
Use builtin function new(class)
.
c = new(C);
new
will call the __new(this)
function defined in the class object.
new(class)
basically returns an object of the form
{
"__type": class.__classname
}
Only supports single inheritance. The inherited class is defined in the class object
with the __superclass
field.
{
"__type": "class",
"__classname": "Dog",
"__superclass": "Animal"
}
h = {"x": 5, "y": 6};
o = {
"__type": "AClass",
"instancevar": 123
};
If a hashtable is used as a hashtable, it's just like above.
If a hashtable is used as an object, it has to have a __type
field.
If it is used as an class object, it has to have a __classname
field.
Any lookup on an object will first lookup through the inheritance stack
(using __type
).