C# 解释器执行的最佳方式
我正在编写一种脚本语言,我已经完成了词法分析器和解析器,我想在内存中动态执行。
可以说我有类似的东西,
function Hello(World)
{
Print(world);
}
var world = "World";
var boolean = true;
if(boolean == true)
{
Print("True is True");
}
else
{
Print("False is True");
}
Hello(world);
什么是执行我尝试过的这个代码片段的最佳方式
1)OpCode Il Generation(我无法让 if 语句工作或除打印功能之外的任何东西) 2)RunSharp,我无法执行这些功能,因为我不知道如何执行该功能。
如果有人能指出我正确的方向!
小代码会有所帮助 链接到资源(不是像 IronPython 这样的东西)也很好
I am writing a scripting language, i've done the lexer and parser and i want to dynamically execute in the memory.
Lets say i have something like
function Hello(World)
{
Print(world);
}
var world = "World";
var boolean = true;
if(boolean == true)
{
Print("True is True");
}
else
{
Print("False is True");
}
Hello(world);
what would be the best way to execute this snippet i'ved tried
1) OpCode Il Generation (i couldn't get if statement to work or anything other than Print function)
2) RunSharp, i cannot do the functions cause the way i can do it i have no idea how.
If anyone could point me to the right direction!
Alittle Code will help
Link to resource (not something like IronPython) would be also good
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的脚本语言,比如 JavaScript,如果它在内存中动态编译。
例子:
your script language like JavaScript,if it dynamic compile in memory.
example:
生成 C# 源并编译它:-)
http://support.microsoft.com/kb/304655
generate c# source and compile it :-)
http://support.microsoft.com/kb/304655
如果我理解正确的话,您想在运行时编译并运行代码吗?那么你可以尝试 http://www.csscript.net/index.html ,它是一个例子在链接的同一页面上。
If I understand you right, you want to compile and run the code on runtime? then you could try http://www.csscript.net/index.html , its an example on the same page linked.