【发布时间】:2011-02-03 21:55:51
【问题描述】:
我们目前使用 ILOG BRMS for .NET 来允许业务用户在不知道如何编程的情况下在我们的系统中创建逻辑。此规则由业务用户创建(即:它是系统的一部分,而不是规范的一部分):
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;
系统在 .Net 中执行等效(此处显示伪 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);
程序员在设计时指定用于每个类/方法/属性的文本。例如,最后一个方法的文本是:
add a new {0} scheduled for {1} to {this}
我逐渐意识到我根本不需要 BRMS。将规则匹配到断言实例的概念对于业务用户和程序员一样陌生。我们的业务用户对 SQL 脚本有些熟悉(有些人对 VBA 有所了解),因此他们对顺序执行感到满意。
我真正想要的是一种在设计时指定文本的方法(DSL),它映射到自然语言编程的类/方法/属性,最好是在 BRMS 之外。
这样的事情存在吗?这个概念的正确名称是什么?
回复:
我们已经考虑使用脚本语言来广泛满足这一需求。具体来说,他们不提供文本替换/映射到我寻求的 .NET 代码。 我想编写一个 c# 方法,然后声明一些可以调用它的合理短语。
ANTLR - 感谢您的提示。这是一个通用解析器。如果我想自己实现它,我无疑需要一个解析器。
根据定义,您发明的任何用生硬词汇集中在问题领域的人工语言都是“特定领域的语言”。
我觉得这个陈述就像我可以回答我的问题一样好。谢谢。
如果您需要完全通用的计算,您最终会得到一种典型的计算机语言。如果你能把范围缩小很多,你可能会得到一些有用的东西。
我可以将范围一直缩小到调用我已实现的方法,但问题是随着我添加更多方法,我想为这些新方法附加更多词汇。
无论我们继续使用 ILOG 还是其他东西作为语言的支持基础设施,DSL 都会不断发展。
【问题讨论】: