用户对变量的动态控制(嵌入式语言?)

发布于 2024-09-28 20:08:43 字数 462 浏览 1 评论 0原文

我正在创建一个软件(用 C# 编写,将是一个 Windows 应用程序),我遇到了这个问题 -

我有一组变量,我需要允许用户定义各种数学函数关于这些变量。

但我的用户不一定需要具备任何有关编程的先验知识。

我考虑过的选项是:

  • 创建某种 GUI 来定义数学“函数”。但这是非常有限的。
  • 实现一种非常简单的嵌入式语言,它将提供灵活性,同时保持相对容易理解。我研究了 Lua,但问题是你非常需要具备编程方面的先验知识。我正在考虑一些更具可读性的东西(有点类似于 SQL),例如“将 3 分配给 X;”

欢迎其他想法。

假设我的用户没有任何编程知识,我基本上正在寻找到达这里的最佳方式。

但是,请注意,这不是我的软件的主要功能,因此我假设如果用户想要/需要使用此功能,他会花时间查看手册并学习如何操作所以,只要不是太复杂就可以。

谢谢,马尔基:)

I'm creating a piece of software (written in C#, will be a windows application) and I ran into this problem-

I've got a set of variables, and I need to allow the user to define a wide range of mathematical functions on those variables.

But my users don't necessarily have to have any prior knowledge about programming.

The options I've considered are:

  • Create some sort of GUI for defining the mathematical "functions". But that is very limiting.
  • Implement a very simple embedded language, that will offer flexibility while remaining relatively easy to understand. I looked at Lua, but the problem with that is that you pretty much need to have prior knowledge in programming. I was thinking about something more readable (somewhat similar to SQL), for example "assign 3 to X;"

Other ideas are welcome.

I'm basically looking for the best way to go here, under the assumption that my users don't have any knowledge in programming.

However, note that this is not the main feature of my software, so I'm assuming that if a user wants/needs to use this feature, he will take the time to look at the manual for a few minutes and learn how to do so, as long as it's not too complicated.

Thanks, Malki :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

却一份温柔 2024-10-05 20:08:43

您想要的是域特定语言。我发现您已经尝试过 Lua,但发现它不可接受——我假设大多数预构建的脚本语言都已经过时了。

根据您预期的函数复杂性,我建议您尝试实现一个小型递归下降解析器 以便您可以准确指定您的语言。通过这种方式,您可以实现以下目标:

assign 3 to X
show sin(X * 5)

如果这有点超出您愿意做的范围,您可以从诸如 讽刺;这将使您专注于使用抽象语法树,而不是花一段时间玩标记/词法分析。

如果您愿意,您甚至可以查看 FLEE,它将解析并评估一些相当复杂的表达式。门。

What you want is a domain specific language. I see you've tried Lua and didn't find that acceptable--I'll assume that most pre-built scripting languages are out then.

Depending on your expected function complexity, I would recommend that you give a shot at implementing a small recursive-descent parser so that you can exactly specify your language. This way you can realize something like:

assign 3 to X
show sin(X * 5)

If this is a bit beyond what you're willing to do, you can get some parsing assistance from a library such as Irony; this will let you focus on using the abstract syntax tree rather than playing with tokenizing/lexing for some time.

If you want, you can even look at FLEE, which will parse and evaluate some pretty complex expressions right out of the gate.

爱你不解释 2024-10-05 20:08:43

如果你想创建自己的语言,ANTLR 是一个很棒的解析器

ANTLR is a greate parser if you want to make your own language

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文