Tuesday, February 26, 2008

Context-free in Scala

With less code than in Java the AbLanguage in Scala:
object AbLanguage {  
def a = new AOpenedBase()

protected class AOpenedBase {
def a = new AOpened[AOpenedBase](this)
def b = {}
}

protected class AOpened[T](surroundingExpression : T) {
def a = new AOpened[AOpened[T]](this)
def b = surroundingExpression
}

def main(args : Array[String]) : Unit = {
a b;
((a a) b) b;
a.a.b.b;
}
}

No comments: