I am looking for a good DSL Tool / Framework that meets the following criteria:
- Can be used with / from C#
- Runs on Windows Azure – the compiler can be generated anywhere, but the actual parsing takes place in the cloud
- As fast and resource efficient as possible
I want u开发者_开发知识库sers to be able to specify rules that are then interpreted by the program.
The DSL is basically a subset of any scripting language - math operations, if-statements, string manipulation etc. - that works with domain objects (e.g. if (SomeComponent.Child3.SomeProperty > 3) SomethingElse.Color = Color(50,0,0)
).
The tools I stumpled upon till now are:
- FsLex / FsYacc. I have no F# experience but from what I've heard I can integrate it in C# solutions, so this sounds quite good.
- Visualization and Modeling SDK - Domain-Specific Languages. Not sure about this one - seems to be the same as the above one + a UI desigenr, which I don't need / want.
... plus many more I've read about here on SO but didn't look at yet in detail (like Oslo/MGrammar, Boo, Antlr...)
What exactly am I asking?
1. Which tools for creating a DSL in C# (or .NET) should I look at in detail, which do you suggest I should use? 2. Wich DSLs do you have experience with, what is your opinion? Is a certain technology cumbersome, slow, outdated, soon-to-be-replaced / cancelled? Let me know please.You seem to have done a good bit of research, and I see what you mean about the M language looking like it's going to be discarded. However, i don't think it will truly be on the way out, as it seems to have been swallowed up by the sqlserver team. ( Who of late, have come out with what I belive to be the most interesting developments for .net -> Reactive Extensions, IQbservable, Linq to Anything )
I would watch : http://channel9.msdn.com/Blogs/Charles/Jeffrey-Snover-Martin-Fowler-and-Neil-Ford-Domain-Specific-Languages and have a quick read of http://blogs.msdn.com/b/powershell/archive/2008/10/09/domain-specific-languages-dsls-in-general-and-how-powershell-relates.aspx
A bit of background here, Jeffry Snover is the creator of Powershell, and that has earned him a promotion of Head of Window Server. Snover, Eini and Fowler all agree that an External DSL takes significantly more effort to write than an internal DSL. There is also the argument that External DSL's are essentially dead-end skills. This is because they are only applicable to their area. In the same way frameworks are. It tends to be the external language that holds extrinsic value.
Moreso, it is the distinction between a DSL Syntax and a DSL Vocabulary. By writing an external DSL, you are in effect writing both aspects, whereas if you embed your DSL into another language you are only needing to specify the DSL Vocabulary.
As such Powershell is extremely well suited for a DSL, as it handles closures as first class objects (scriptblocks). It's future is also assured, what with existing in all versons of windows. Hosting powershell within an application only takes a couple of references and a couple of lines of code, and it has full access to .net type system. The actual act of writing a DSL in powershell is trivial.
Douglas Finke MVP, is an excellent resource with regards to both DSL's and Powershell
An older DSL post : http://www.dougfinke.com/blog/index.php/2009/07/01/powershell-powerboots-and-an-oslo-dsl-grammar/ An example of how trivial it is to create decent DSL's. http://www.dougfinke.com/blog/index.php/2009/03/18/powershell-dsl-for-deploying-biztalk-applications/
http://www.dougfinke.com/blog/index.php/2008/03/24/fluent-interfaces-dsl-and-language-oriented-programming/
If you're new to powershell then he has a quick primer here : http://www.dougfinke.com/blog/index.php/2011/01/10/how-to-practice-powershell/ though I'd recommend getting 'Powershell in Action, 2nd Edition', as a full reference, there is a section dedicated to writing DSL's in powershell in it ( it was written by Snover's right hand man on the powershell team ).
You do seem to be describing writing a full external DSL: essentially a language. You might want to take a look at the somewhat verbose CodeDom, as well as the DLR (http://dlr.codeplex.com )
For a background into the basis for a lot of this stuff, you would be well advised to start looking into impmenting continuations, and other techniques pioneered in LISP/Scheme. The Venerable SICP http://mitpress.mit.edu/sicp/ and http://www.cs.brown.edu/~sk/Publications/Books/ProgLangs/ and http://www.ccs.neu.edu/home/matthias/HtDP2e/index.html As it happens, LISP/Scheme are the perfect languages for writing DSL's and other languages in, and if you haven't already, merely learning them, will improve your programming in exactly the areas you are looking for right now.
You also mention that you would like to do some azure cloud work. As an aside, but very informative background piece, I would recommend watching Bart De Smet's description of how microsoft have expanded their 'enumerable ecosystem' to cater for scaling and distributed systems. http://community.bartdesmet.net/blogs/bart/archive/2008/10/20/linq-to-anything-channel-9-interview-and-a-few-more-thoughts.aspx
If you are going to do any development of powershell, the Bart's blog has some seminal articles ( with full and clear code examples ) on this subject, including how to take them and put an MMC 3 interface on top of them.
Regardless of what you finally choose, from painful personal experience : write internal DSL's, they're faster, easier, less outlay, lower learning curve, you're not deskilling in areas that are in demand on CV's. As you can tell, I recommend Powershell, for all those previous reasons, plus access to all the .Net/COM/WMI/Webservice resources you need. Plus it's future is guarenteed.
Anyway I hope this helps, and good luck.
Have you looked at DSLs in Boo: Domain Specific Languages in .NET
The Boo Language
Have you tried ANTLR?
You could try http://www.meta-alternative.net/mbase.html
精彩评论