难道.NET进行分析,并在运行时进行评估 [英] Could .NET be parsed and evaluated at runtime
问题描述
我认为这将是有趣的,如果我能写vb.net或C#code运行时与各国preTER会自动解析它像Python做,所以我做了一个小程序,它会做类似的话。基本上,它看起来是这样的:
I thought it would be fun if I could write vb.net or c# code at runtime and the interpreter would automatically parse it like python does it, so I made a little program, which would do something similar. Basically it looks like this:
InputArgs = Console.ReadLine()
ParseInput(InputArgs.Split(" "))
Private Sub ParseInput(Args as List(Of String), Optional TempArgs as List(Of String))
Dim arg as string = Args(0)
If arg = ".." then
...
elseif arg = ".." then
...
end if
End Sub
我知道这不是一个很好的制度,但它显示的基础。所以我的问题是:是否有可能使vb.net或C#如Python - PTED在运行时除$ P $
I know it's not a good system, but it show's the basics. So my question is: Is it possible to make vb.net or c# like python - interpreted at runtime?
推荐答案
本已存在的形状和形式相当数量的:
This already exists in a fair number of shapes and forms:
单有 Mono.CSharp
组件,您可以参考做任何 CSharp.exe(AC #跨preTER'或交互shell,如果你会)可以做的:
void ReadEvalPrintLoopWith (ReadLiner readline)
{
string expr = null;
while (!InteractiveBase.QuitRequested){
string input = readline (expr == null);
if (input == null)
return;
if (input == "")
continue;
expr = expr == null ? input : expr + "\n" + input;
expr = Evaluate (expr);
}
}
毋庸置疑的这个工程上MS.Net过(当然,这是关于便携式净点)。
Needless to say this works on MS.Net too (of course, that's the point about portable .Net).
全部来源这里在github - 就像休息单声道的,其实
Full sources here on github - just as the rest of Mono, in fact.
若干DLR的语言已实施,包括但不限于
Several DLR languages have been implemented, including but not limited to
- IronRuby的
- IronPython的
- Jint上(http://jint.$c$cplex.com/) - 不上NET 2.0的JavaScript
- IronRuby
- IronPython
- Jint (http://jint.codeplex.com/) - does javascript on .Net 2.0
这将让你评价对在.NET框架飞蟒蛇/红宝石code。
It will allow you to evaluate python/ruby code on the fly in the .NET framework.
微软发布了罗斯林作为一个CTP(preVIEW)。它基本上可以做同样的东西,为一REPL(第一项),和(多)了。但它是一个preVIEW还在。
Microsoft has published Roslyn as a CTP (preview). It can basically do the same stuff as the Mono REPL (first item), and (much) more. But it is a preview still.
这篇关于难道.NET进行分析,并在运行时进行评估的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!