Click here to Skip to main content
13,355,726 members (59,434 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 ();

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

EndClass B
Posted 14-Feb-13 6:00am
richcb 14-Feb-13 11:23am
That code would not even compile in C#.
Sergey Alexandrovich Kryukov 14-Feb-13 14:32pm
Read on the very basics before you write any code...
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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[^]

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.
Sergey Alexandrovich Kryukov 14-Feb-13 14:35pm
Explained and (in principle) can direct the OP. My 5.
I suggested some more reading, please see.
Espen Harlinn 14-Feb-13 15:20pm
Would work - a 5
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Espen Harlinn 14-Feb-13 15:20pm
Nice links :-D
Sergey Alexandrovich Kryukov 14-Feb-13 15:32pm
Thank you, Espen.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Here is an Antlr[^] c# grammar:[^]

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

Best regards
Espen Harlinn
Sergey Alexandrovich Kryukov 14-Feb-13 16:35pm
Interesting product, a 5, but not sure this is what OP really needs...
Espen Harlinn 14-Feb-13 16:40pm
Thank you, Sergey :-D
>> not sure this is what OP really needs...
Me. neither - but it will help OP along the traditional route towards some sort of intermediate code.
Sergey Alexandrovich Kryukov 14-Feb-13 16:42pm
This is just one more interesting product to bookmark :-) Thank you for sharing.
CHill60 15-Feb-13 12:10pm
Nice one - bookmarked and +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180111.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100