I have been working through the tutorial at http://bkiers.blogspot.de/2011/03/creating-your-own-programming-language.html. In short, a small language is developed that has a minimal set of arithmetic operations. “println” and “print” are directly mapped functions that call System.out.print().
From this I am trying to implement my own DSL by changing some properties of the language that has been developed in that article series. I want to make java.lang.Math accessible from within my DSL, but can’t think of a good way without having to map each function manually.
The language does not support imports whatsoever. I could introduce a new grammar rule to match Math.<function>(<parameters>).
You could do that by making
Matha reserved word and make the following changes:grammar additions
tree grammar addition
new Math-node class
Now you don’t need to implement all the separate method in their own class, but will still need to check which method is invoked in the
evaluate()method ofMathCallNode, of course.If you now evaluate:
the following will be printed: