Sunday, December 19, 2010

Making Software Literate: Teaching Code to Read Itself

My previous post introduces the concept of Grammar, Template, and the Metamodel.

Creating metamodel is easy for humans, there is Ecore editor and Ecore Tools for that.

Generating artifacts from a model is also relatively easier... When compared to "reading" artifacts and generating a model.

In the machine world, almost everything is harder to read than to write.

For example, it is easy for a generator to output this:

lastName = "Irawan"
name = "Hendy " + lastName

However, it's not easy to "read" the above artifact. By that I mean that the parser software should "understand" that 'name' contains "Hendy Irawan".

And it brings us to... Interpreter.

Interpreter is an enhanced parser that knows what to do with a model. Advanced interpreters may have behaviors, but the most commonly used functionality is Evaluating Expressions.

An Evaluator transforms expressions in the metamodel to actual values (which are still expressions, called value expression, but do not need further processing). After the example artifact above are parsed AND interpreted/evaluated, the 'name' object will rightly contain 'Hendy Irawan'.

No comments:

Post a Comment