Currently I am working on a Java-to-.Net-Compiler. In addition to using
ANTLR and Micosoft's Phoenix framework I have to write a lot of C# code that lends itself to be generated.
Besides the need for a java grammar, which can be found here, we need an AST (Abstract Syntax Tree) to accomplish the semantic analysis. ANTLR offers an AST construction mechanism and generates an AST walker from a tree grammar. Basically the semantic analysis can be done solely with ANTLR. But, we are facing the challenge that each teammate needs to work with the AST and not everyone knows ANTLR. Thus we need an ANTLR independent AST.
The basis of our Java AST is the Eclipse JDT AST. My task is to implement the AST using C#. So, to implement means to copy since the JDT AST seems be a good model.
Did I say model? This sounds like feeding the JDT AST code into a code generator and letting the generator create the C# implementation.
Consequently we create a generator using openArchitectureWare that will take an UML2 class model, yes we decided to create an UML model of the AST ;), and generate C# classes.
I sat down with a teammate having C# experiences to create the generator templates for generating C# code.
Perfect! Now, our generator knows how to create C# classes .. and my teammate can go home :D. Furthermore we generate the basic visitor code for the AST from its model.
By the way .. a language grammar lends itself to automatic AST generation .. check out this paper.
Generators are knowledge containers!