从C#程序创建Intermidate代码 [英] Create Intermidate Code From C# program

查看:311
本文介绍了从C#程序创建Intermidate代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,

我想将以下代码转换为中间形式。我怎么能这样做?

C#代码:

Dear all,
I want to convert the following code to intermidate form. How can I do this?
C# code:

class B
{         A a;
    C f;
   public B( )
    {a = new A( );
     }
   public void Method1(int i){}

    return ();
    }
}





互联网代码:

级B级

类型A

类型C

方法B

对象A

EndMethod B

方法方法1

EndMethod方法1



EndClass B



Interemidate code:
Class B
Type A
Type C
Method B
Object A
EndMethod B
Method Method1
EndMethod Method1

EndClass B

推荐答案

要创建中间代码,您需要编译程序。

然后您可以使用ildasm.exe(VS附带)来检查生成的dll或exe

(可以在例如C:\Program Files \ MicroSoft SDKs \ Windows \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\链接了解更多详情 http://msdn.microsoft.com/en-us/library/f7dy01k1.aspx [ ^ ]





从你的转发问题我收集你想编写一个程序来解析你的代码并将其转换为IL。编译器理论在这里有一个很大的主题 - 在编译器和解析器上的一些研究(例如通过谷歌)将指向正确的方向。您可能会发现c#语言规范以及CLI规范很有用。您还应该使用ildasm.exe学习简单的程序,并使用它来为您的程序生成预期的测试结果。



警告 - 鉴于您提供的示例程序的简单性(正如richcb所指出的那样甚至不能编译)我怀疑编译器编写可能是你现在的桥梁。



如果这不是你的意图然后使用改善问题链接为您的问题添加更多详细信息并发布对此解决方案的回复 - 后一个操作将生成一条消息让我返回此处。
To create the intermediate code you will need to compile your program.
You can then use ildasm.exe (comes shipped with VS) to examine the resulting dll or exe
(can be found in e.g. C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\ildasm.exe)
See this link for further details http://msdn.microsoft.com/en-us/library/f7dy01k1.aspx[^]


From your repost question I gather you want to write a program to parse your code and convert it into IL. Compiler theory is a bit of a large subject to cover here - some research (e.g. via Google) on compilers and parsers will point you in the right direction. You may find the c# language specfication useful as well as the CLI specification. You should also study simple programs using ildasm.exe and use it to generate expected test results for your program.

Warning - Given the simplicity of the sample program you provided (which as richcb points out won''t even compile) I suspect compiler writing may be a bridge too far for you at the moment.

If this was not your intention then use the Improve Question link to add further detail to your question and post a reply to this solution - the latter action will generate a message for me to return here.


您应该阅读:

http://en.wikipedia.org/wiki/Intermediate_language [ ^ ],

http://en.wikipedia.org/wiki/Common_Intermediate_Language [ ^ ],

http://en.wikipedia.org/wiki/Common_Language_Runtime [ ^ ],

http:// en。 wikipedia.org/wiki/.NET_Framework [ ^ ]。



一些交叉引用的文章也很有用。



- SA
You should read this:
http://en.wikipedia.org/wiki/Intermediate_language[^],
http://en.wikipedia.org/wiki/Common_Intermediate_Language[^],
http://en.wikipedia.org/wiki/Common_Language_Runtime[^],
http://en.wikipedia.org/wiki/.NET_Framework[^].

Some of the cross-referenced article can also be useful.

—SA


这是一个 Antlr [ ^ ] c#语法: http:// antlrcsharp.codeplex.com/ [ ^ ]



这可用于从c#代码生成中间代码,或者其他任何内容。



祝你好运

Espen Harlinn
Here is an Antlr[^] c# grammar:http://antlrcsharp.codeplex.com/[^]

This can be used to generate intermediate code, or whatever really, from c# code.

Best regards
Espen Harlinn


这篇关于从C#程序创建Intermidate代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆