Meh, I got bored on this stormy day with my team absent, so I'm playing with some syntax creation.
class Vec2
{
float x
float y
function bool SomeLogic()
if self.x > 1
return true
end
end
}
class Vec3 extends Vec2{
float x
float y
float z
function vec3()
return self
end
function vec3(x)
self.x = x
return self
end
function vec3(x, y, z = 0)
self.x = x
self.y = y
self.z = z
end
function vec3 normalize()
vec3 v
float m
m = sqrt(x * x + y * y + z * z)
v.x = self.x / m
v.y = self.y / m
v.z = self.z / m
return v
end
function float dot(vec3 v)
return self.x * v.x + self.y * v.y + self.z * v.z
end
function string ToString()
return self.x + ", "+self.y+", "+self.z
end
function bool SomeLogic()
if self.x > 0
if self.x == 1
return true
else
if self.x >= 2
return false
end
end
end
return false
end
function bool SomeLogic(int x)
if x > 0
return self.SomeLogic()
else
return super.SomeLogic() // calls Vec2.SomeLogic()
end
end
}
vec3 a
vec3 b
string c
a = new vec3(1, 2, 3)
a.normalize()
if a.SomeLogic() == true
print a.ToString()
end
c = a.ToString()
b = a
b.x = 5
b.y = 8.2
print a
print b
print c
array<int> d
array<int>[5] e
array<int>[5,5] f
d[foo] = 5
d[0] = 2
f[0][1] = 2
' - comment
// - comment
/* */ - comment block
; - allowed and simply stripped out
{} - allowed and simply stripped out
if(a > 0){ return true; }
if(a > 0) return true end
if a > 0 return true
case insensitive
associate and dynamic arrays
function overloading
I use to do syntax creation a lot when attempting to build better PHP templating libraries like Smarty. Of course, this is different, but the end result is the same. It parses everything and spits out what it really should do.