tags:

views:

133

answers:

3

I have written a DSL using Antlr to generate a lexer and parser from my grammar file. The parser generates an abstract syntax tree which contains various nodes (e.g. a function node) which I can calculate. In the code for the function nodes I take care of binding - checking function names and parameter types for matches from a library of functions. I have some simple caching here to optimize the function look up (if I call A+B with two ints then there is a strong chance the next time I use the plus operator it will be with 2 ints).

Recently I have been reading about the DLR and it seems to be designed to accomodate this type of scripting language implementation. At first blush it doesnt look to me like it generates the parser or lexer but it seems it does assist with the other parts of the implementation. I was wondering what would be the main advantages to me of switching to using the DLR.

+2  A: 

Full access to the .NET framework is the big one.

Lou Franco
+2  A: 
  • Access to the .Net base class library and types
  • Access to third party libraries written for .Net
  • You can let Microsoft worry about servicing the API (security updates, etc)
  • You can host the language in Visual Studio
Joel Coehoorn
+4  A: 

If you implement the binding carefully, the DLR will give you a very powerful caching mechanism - probably more heavily optimised than you'd be realistically able to do on your own. Also, you're more likely to get good interoperability with other languages, as you'll be using a "standard" dynamic object protocol.

For example, C# 4 would be able to call into your language without any extra work, just by using the dynamic type. In order to do that without the DLR, you'd have to generate "normal" static CLR types.

It's hard to know for sure how much advantage there'd be because we don't know what you want to use your language for, or how much it already does. However, there are obviously lots of very smart people working on the DLR - it seems to me that if you're creating a dynamic language to run on .NET, it would make sense to take advantage of their work.

Jon Skeet
Thanks Jon, several good motivations there especially the dynamic type. Wish I could have made it to your presentation at the open-source-jam.
Jason
It was only 5 minutes - no detail at all. I'm nearly finished with the dynamic chapter of C# in Depth though, so that should be available soon.
Jon Skeet