About Me

I am a computer programmer. I do programming professionally and for a laugh.

Technical stuff on programming, java, DSLs, etc...

Tuesday, 30 March 2010

Embedded Translation

A little semantics goes a long way. I never thought Language Processor as a means of Embedded Translation until I read the article by Martin Fowler.

That is exactly what it does. In a very nice way. Because the language definition and the translation and the interpretation is all in Java, there are no external BNF files of any kind. You even do not ordinarily need to generate a parse tree.

Define you grammar and semantic model together. No Foreign Code or Embedded Helper. Happy Days.

    addProduction("T -> / T T", new Semantic() {
          public Object evaluate(List<Object> childEvals) {
         return ((BigInteger) childEvals.get(1)).divide((BigInteger) childEvals.get(2));

No comments:

Post a Comment