Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Can anyone tell how we can create our own compiler using C#.NET through which I can execute any program?
Posted
Updated 13-Apr-14 5:56am
v2
Comments
[no name] 13-Apr-14 10:51am    
Did you try doing any research at all?
mayank.bhuvnesh 13-Apr-14 10:56am    
Hi wes

Yes i did some rsearch and foud some useful, but i am not able to understand how its working. Take a look at the below link
http://www.cl.cam.ac.uk/teaching/0910/CompConstr/NEJ/
[no name] 13-Apr-14 11:00am    
Why? What possible reason would I need to go look at that? Even if we knew what is was that you are unable to understand, we cannot possibly explain to you how to create a compiler in a forum posting. There is tons and tons of information about this very subject out there, you just need to go look for it. Come back here if you have a specific question about a specific error or line of code.
Nelek 13-Apr-14 11:17am    
Is that not a bit too ambitious for your level at this moment?
mayank.bhuvnesh 13-Apr-14 11:20am    
Do i hv to w8 for sumthing????

Creating your own compiler is not a trivial job: it's a lot of careful design and coding, if you want it to be any use in the real world.

There are a lot of books on compiler design: Google[^] can help you get started.
Some of the stuff there is "Free" - I don't know if that means "stolen" - and some of it is background material, but there should be enough to get you started thinking anyway.

But don't expect this to be a "one weekend" project: a modern compiler is written by a team of people, and can still take years to produce!
 
Share this answer
 
Comments
Manas Bhardwaj 13-Apr-14 11:38am    
Or just go an download Roslyn :)

http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx

Btw, agree to what you said +5!
Sergey Alexandrovich Kryukov 13-Apr-14 12:39pm    
Roslyn does not help to create a compiler, it just is set of available open-source compilers. Well, one could learn how compiler works, but it's hard to use as a tool for learning how to create your own.

For creation of a compiler, one could use, say, a compiler-compiler. Please see Solution 3.

—SA
Sergey Alexandrovich Kryukov 13-Apr-14 12:45pm    
Wasn't that Manas Bhardwaj, not you?
Thank you.
—SA
Maciej Los 13-Apr-14 12:18pm    
+5
This is easier than with the languages targeting native platform, because you would need to generate machine code. With .NET, there is no machine code. You can parse code and translate it to CodeDOM. Please see:
http://msdn.microsoft.com/en-us/library/y2k85ax6%28v=vs.110%29.aspx[^].

In other words, you can implement this method: http://msdn.microsoft.com/en-us/library/system.codedom.compiler.codedomprovider.parse%28v=vs.110%29.aspx[^]. But you don't have to; you can just populate DOM the way you want and CodeDOM will generated the assembly for you.

Parsing is a separate topic. Well, you can invent your own parser from scratch, learn the parsing techniques, or use some available compiler-compiler. With a compiler-compiler, you would need to formally define the input language; and the compiler components will be generated for you. Please see: http://en.wikipedia.org/wiki/Compiler-compiler[^].

See also this article: http://msdn.microsoft.com/en-us/magazine/cc136756.aspx[^].

This CodeProject article even suggests a Compiler Construction Kit for .NET: Irony - .NET Compiler Construction Kit[^].

—SA
 
Share this answer
 
Comments
Maciej Los 13-Apr-14 12:19pm    
+5
Sergey Alexandrovich Kryukov 13-Apr-14 12:23pm    
Thank you, Maciej.
—SA
MoneyDude 13-Apr-14 12:43pm    
That's correct +5!
Sergey Alexandrovich Kryukov 13-Apr-14 12:45pm    
Thank you.
—SA

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