Reputation: 110201
We currently use ILOG BRMS for .NET to allow business users to create logic in our system without knowing how to program. This rule is created by a business user (ie: It's a part of the system, not a part of the specification) :
definitions
set 'the letter event' to the scheduled DelinquentLetterEvent on the invoice;
set 'final notice possibility1' to the bill date of the invoice + 36 days;
set 'final notice possibility2' to the time of 'the letter event' + 7 days;
set 'final notice result' to the most future date from these values {
'final notice possibility1', 'final notice possibility2' };
then
in the event that 'final notice result' is not a mailing date,
change it to the next available mailing date;
add a new FinalNoticeEvent scheduled for 'final notice result' to the invoice;
The system performs the equivalent in .Net (here showing psuedo C#):
//variable declarations
ScheduledEvent theLetterEvent = theInvoice.GetScheduledEvent(
KnownEventType.DelinquentLetterEvent);
DateTime noticePossibility1 = theInvoice.BillDate.AddDays(36);
DateTime noticePossibility2 = theLetterEvent.Time.AddDays(7);
DateTime[] possibilities = new DateTime[]()
{ noticePossibility1, noticePossibility2 };
DateTime noticeResult = CustomClass.Max(possibilities);
//actions
CustomClass2.MakeNextMailingDate(ref noticeResult);
theInvoice.AddScheduledEvent(KnownEventType.FinalNoticeEvent, noticeResult);
Programmers specify at design time what text is used for each class/method/property. For example, the text for that last method is:
add a new {0} scheduled for {1} to {this}
It's slowly dawning on me that I don't need a BRMS at all. The concept of matching of rules to asserted instances is just as alien to business users as it is to programmers. Our business users are somewhat familiar with SQL scripting (and some know a bit of VBA), so they are comfortable with sequential execution.
What I really want is a way to specify text at design time (a DSL) that maps to classes/methods/properties for natural language programming, preferably outside of a BRMS.
Does such a thing exist? What is the proper name for this concept?
Responses:
We have considered scripting languages to fill this need broadly. In specific, they do not offer the text substitution/mapping to .NET code that I seek. I want to write a c# method, then declare some sensible phrases by which one might invoke it.
ANTLR - thanks for the tip. This is a generic parser. I will no doubt require a parser if I want to implement this myself.
Any artificial language you invent with a stilted vocabulary focused in a problem area is by definition a "domain specific langauge".
I feel this statement is as good as an answer as I can get to my questions. Thanks.
If you need fully general computation, you're going to end up with a typical computer language. If you can narrow the scope a lot, you might end with something useful.
I can narrow the scope all the way down to calling the methods I've implemented, but the catch is that as I add more methods, I want to attach more vocabulary for those new methods.
The DSL will evolve whether we continue to use ILOG or something else as the supporting infrastructure for the language.
Upvotes: 2
Views: 701
Reputation: 95410
As a practical matter, you can't write a tool that accepts real natural language and maps it to working code. Nobody knows how to do this. (Hence C# instead of English).
The best you can hope for is a stilted set of phrases (much like the BRML you exhibited), which always has the advantage of being better defined, and a lot harder for "business users" to learn because they don't (want to) know what to say to start, let alone what the limits of expressiveness are. Any artificial language you invent with a stilted vocabulary focused in a problem area is by definition a "domain specific langauge".
The real arguments are, what range of activities does your language need to encompass? How educable are your "business" users (if they can code, I wonder about the characterization of them as "business users")? Do they agree on the range of things they are willing to say (bet not). If you need fully general computation, you're going to end up with a typical computer language (actually worse, because you'll end up sandcastling on programming features, producing a truly ugly baby). If you can narrow the scope a lot, you might end with something useful.
The question is, can you design such a language, which is better than the BRML you intend to displace, for what the users expect to be able to do? [I have no opinions about how good ILOG's BRML is, but you have to assume they've been trying to solve this problem for awhile, and since they still exist, they must not have a stupid solution].
If you are confident you can, then you can use parser-based code generator tools to implement the DSL. Its quite the experiment; if you start now you won't know for a year if your approach is successful, and it might fail.
Good language design, whether procedural, or DSL, is hard.
What usually happens with workable DSLs is they manage to address an interesting part of the original problem, leaving the rest to address "somehow". One way to handle this is to evolve the DSL: new syntax, new semantics, etc.; this does happen with successful DSLs. Expect yours to evolve, too. Another typical way is to provide a few standard escape mechanisms (e.g., some kind of procedure call, arbitrary expressions, ...) and then somebody adds extra subroutines on demand.
Even you get the DSL right, it may not become socially accepted. [Ada was a really good language, and it got displaced by C and C++ because the programmers simply didn't want to learn it].
Upvotes: 3
Reputation: 29640
You have many choices on how to accomplish this. Let's name a few:
Integrate a scripting language. You can e.g. use VBScript or Lua. You create wrappers for your own objects and make them available to the scripting language. The advantage of this is that a parser and executable engine have already been implemented for you;
Use XAML. XAML is a way to define object structures in XML. You can use the markup extensions for formulas so you can assign a date using e.g. BillDate="{DateFormula +1 days}"
;
Use ANTLR to define a parser for your own DSL. With ANTLR, it's relatively easy to write a parser. You can create the objects in your grammar from the matched constructs.
Upvotes: 2