This project has moved and is read-only. For the latest updates, please go here.

ParseTree Compiler

Apr 8, 2010 at 5:54 PM


thanks for the Irony tool. It's proved to be quite fast to get productive with.

Are there any good examples / design patterns / or rules of thumb for coding the compilation phase of pushing a parse tree into different target languages? I'm not doing anything that major. It's just a simple domain specific idea I had to be implemented (dynamically) in similar but different 3rd party products. I figure it's an adaptive way to achieve inversion of controll.

The only example I've found so far is the Google Search to SQL Server Full Text Search code. Their approach seemed to be a bunch of case statements. I'm looking for something a little more elegant. I had a problem with their code on an AST node to (Token) casting. Not quite sure what they wanted to achieve there. Probably it worked fine against an earlier version of Irony.


Apr 9, 2010 at 12:35 AM


are you talking about IL code generation or about interpreting the code? As you mention DSL, I think interpreting would be more appropriate. 

Google-To-SQL example - the code in the article is for very old version of Irony. There is an updated version in Irony.Samples project and you can run it from Grammar Explorer. This sample works directly from ParseTree - no need for more complex thing. As for doing an interpreter, you need to first produce an AST tree - a tree of abstract syntax, this is a standard way desribed in text books. For this look at expression evaluator sample - how to specify AST node types and produce AST tree. Then you interpret the tree. Irony's interpreter in the current version is rudimentary, I'm currently working on a real one, will upload it some time in the future. But I guess for DSL you need to create your own AST nodes (classes) that encode the semantics of DSL constructs

Hope this helps



Apr 13, 2010 at 9:15 AM


thanks for replying.

I guess what I'm doing is a high level cross compiler/translator for a limited grammer.

Here's a couple of low-level references:


Apr 13, 2010 at 9:21 AM

BTW: your reply helped me piece together a strategy. all-be-it a simple one.

I could

1. inherit from an AST + implement some behaviours in different classes.

2. Walk the AST and either clone a node or cast it to a more specific AST.

3. Finally, I could execute a compile or translate behaviour on each node.


Apr 14, 2010 at 5:57 AM

Well, sounds interesting. Good luck!