Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Dear all,
I want to convert the following code to intermidate form. How can I do this?
C# code:
C#
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
Comments
Richard C Bishop 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...
—SA

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

[Edit]
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.
 
Share this answer
 
v2
Comments
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.
—SA
Espen Harlinn 14-Feb-13 15:20pm    
Would work - a 5
 
Share this answer
 
Comments
Espen Harlinn 14-Feb-13 15:20pm    
Nice links :-D
Sergey Alexandrovich Kryukov 14-Feb-13 15:32pm    
Thank you, Espen.
—SA
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
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Feb-13 16:35pm    
Interesting product, a 5, but not sure this is what OP really needs...
—SA
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.
—SA
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900