Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the main advantages of switching to DLR for my scripting language?

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.

like image 290
Jason Avatar asked Nov 17 '25 00:11

Jason


2 Answers

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.

like image 199
Jon Skeet Avatar answered Nov 19 '25 16:11

Jon Skeet


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

like image 21
Lou Franco Avatar answered Nov 19 '25 17:11

Lou Franco