Simple DLR language

As Script.NET project had evolved, I was more oftenly being asked to employ DLR for its engine.

DLR stands for Dynamic Language Runtime – a Microsoft’s library which provides services for building dynamic (script) languages such as IronPython and IronRuby. It is employing DynamicMethod technology to produce IL code. The benefit of DynamicMethod is that it may be garbagge collected.

After my first glance at DLR library I have been scared a little bit about it’s design. But, now I came to it again with a strong wish to get deeper.

After some unsuccessfull attempts a I have finaly got it to work. The language is simply arithmetic expressions which then being compiled and evaluated. The source codes and binaries may be downloaded: DLR Calculator.

I am planning to write more detailed article describing this solution soon.

For now consider a list of classes in the order in which they had been implemented.

  • 1. MyConsoleHost
  • 2. MyLanguageProvider
  • 3. MyLEngine
  • 4. MyLOptionsParser
  • 5. MyLConsoleOptions
  • 6. MyLEngineOptions
  • 7. MyLLanguageContext
  • 8. MyLEngine.PrintIteractiveCodeResult
  • 9. Classes in Compiler directory

The solution has the following structure:

  • Compiler – a custom classes with parser, lexer, etc. which will generate DLR Ast for compilation
  • Hosting – a set of classes for hosting a new language, interaction with console, options, etc
  • Runtime – a set of classes using during code execution, such as language context

For testing try following expressions: 1+2, 3+3*2, 1+(2+3*(1+1))+1

This entry was posted in .NET Corner, Script.NET. Bookmark the permalink.

9 Responses to Simple DLR language

  1. Rafal Gwizdala says:

    Hello Peter, I am really interested in and will be evaluating it in near future (depends on my busy-ness). There is an area where such interpreted language has great advantage over compiled scripts – remote procedure calls and integration between different platforms. Good example – AJAX applications. Whenever a javascript in browser needs to call the server object it needs to use some RPC mechanism, such as xml-rpc, or ‘extended’ json or soap. But it also can use expressions and just send them to the server to be executed. The expressions are not known a priori, and compilation is not an option here (performance, leaking memory…)
    But such expressions can cause security problems, and this is where DLR could be of some use. You could use DLR standard for providing ‘hooks’ for controlling what script expressions are executed and applying security rules.

    Another good material for DLR is use of OR mappers. OR mappers for .Net rely on static schema definitions (database schemas don’t change at runtime). And therefore they are lacking the support of modification of data structure at runtime (for example, user-added fields in data objects). Dynamic object structure would allow that and by using DLR we could handle underlying database updates.

    Best regards

  2. Pit says:

    More information about Dynamic Language Runtime

  3. Pingback: ?????????? - Noticias externas

  4. Pingback: ?????????? - Noticias externas

  5. Pingback: » Blog Archive » DLR Language with Generated parser (Part 3)

  6. Brytney says:

    Nice! Thanks!

  7. Pingback: Dynamic Code Execution & Scripting in .NET 4.0 | Code First Blog

Leave a Reply