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

Integration with .NET4 Expression framework

Apr 25, 2012 at 11:02 AM


Has anyone worked on using Irony together with the new System.Linq.Expressions classes? It seems this contains all the stuff necessary for the run-time interpretation of an arbitrary complex statement., and I wonder how to use it from an Irony AST...

As I see it, there are several approaches:

- Have the AST directly use the the Expression classes for it's various nodes... I am not sure about the feasability of this since the Expression class has it's own tree representation (with a Visitor pattern and all), and I do not see how to make it worrk with Irony' AST construction

- Have some code that traverse the AST node and generate a corresponding Expression for execution. This step would allow things like loop transformation to match the LoopExpression semantic, etc...

- Other ideas?


I cannot help but compare this Expressions framework with the Irony built-in interpreter... Any advice/comparison between the two? Thanks.


Apr 26, 2012 at 1:07 AM

>Have the AST directly use the the Expression classes for it's various nodes

I think it's impossible for two reasons:

  1. all constructors are private, so Activator.CreateInstance() is unable to create AST nodes
  2. expression instances are immutable: you cannot change anything after they are created.

So you'll have to use the second approach.
Roll your own AST visitor if you need to build a LINQ expression.

>Any advice/comparison between the two?

I think that they serve different purposes :)

Irony AST nodes are linked to the source code.
You can find the exact position of every node in the source (try clicking the «Locate» button in GrammarExplorer).
Irony AST nodes are interpretable: you can evaluate your AST node by node.

LINQ expressions don't have any information about their origin.
They cannot be interpreted (at least, out-of-the-box), but they can be compiled into MSIL.