ParseTree Compiler

Apr 8, 2010 at 5:54 PM

Hi,

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.

thanks,
Steven

Coordinator
Apr 9, 2010 at 12:35 AM

Hi,

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

Roman

 

Apr 13, 2010 at 9:15 AM

Hi,

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:

http://www.springerlink.com/content/uacar19mm8xj9q7m/

http://en.wikipedia.org/wiki/Cross_compiler

Steven

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.

Steven

Coordinator
Apr 14, 2010 at 5:57 AM

Well, sounds interesting. Good luck!