如何评估作为一个字符串在F#中存储的前pression作为一个、字符串、pression

2023-09-02 01:58:56 作者:╰ゝ时光斑驳了容颜°

我想要做的排序是这样的:

I want to do something sort of like this:

令x = 5 让Y = 10

let x = 5 let y = 10

让EXPR =到Console.ReadLine()

let expr = Console.ReadLine()

EXPR

如果有人可能会在控制台存储expr中输入X + Y。

Where one might type "x+y" in the console to store in expr.

一个人如何评价这样的F#中声明?

How does one evaluate a statement like this in F#?

最终,我希望用户能够进入前pressions,或为一系统的一组规则,在网页上并将它们保存在数据库中,在适当的时间被应用在F#库。我只是不知道如何将输入的字符串转换到在F#中的函数值。

Ultimately, I want a user to be able to enter expressions, or a set of rules for a system, on a webpage and have them saved in a database to be applied at appropriate times in an F# library. I just don't know how to convert the entered string in to a function value in F#.

感谢您的帮助,您可以提供!

Thanks for any help you may provide!

亚当

推荐答案

F#不具备的eval,如前所述,但如果你能定义的语法,你可以利用F#中Lex和Yacc实现(fslex和和fsyacc )。

F# doesn't have eval, as mentioned, but if you can define the grammar, you can utilize the Lex and Yacc implementations in F# (fslex and and fsyacc).

编辑:的

作为一个快速跟进,我知道在OCaml中你可以利用交互式控制台将用户与 ocamlmktop 。我不能确定在F#等效的。这一点,虽然,似乎不符合你想要的网页界面(正确吗?)。

As a quick follow up, I know in ocaml you can exploit the interactive console to your users with ocamlmktop. I am unsure of an equivalent in F#. This, although, doesn't seem to match what you want with a web interface (correct?).