Click here to Skip to main content
15,891,762 members
Please Sign up or sign in to vote.
2.00/5 (4 votes)
See more:
Hi,

I need a very simple compiler for a project at school. Could you please help me out with some links to mini compilers in C#?

I didn't express myself in the right way. The compiler needs to be written in C# but it needs to compile assembly language. Sorry...

Thanks a lot!
Posted
Updated 12-Apr-11 5:13am
v3
Comments
justme89 12-Apr-11 7:53am    
I need to code it myself.
justme89 12-Apr-11 8:00am    
I didn't express myself in the right way. The compiler needs to be written in C# but it needs to compile assembly language. Sorry...
#realJSOP 12-Apr-11 8:20am    
Well then, you need to modifuy your vote for my answer (if it was you that voted it a 1). I answered it based on your original (and still unchanged) question.

Third link of the first page in Google when I search for "C# simple compiler":

http://msdn.microsoft.com/en-us/magazine/cc136756.aspx[^]
 
Share this answer
 
Comments
Manfred Rudolf Bihy 12-Apr-11 8:02am    
Nice link! 5+
You can down-vote this one if you like, because I'm about to sound kinda harsh.

First, your nomenclature is wrong. You don't "compile" assembly code - you "assemble" it, and you therefore need an "assembler". Terminology aside...

Second - this sounds like a homework assignment - you have to write an assembler in C#. The reason I'm calling it homework is because nobody in the corporate world would waste their time reinventing the wheel that is MASM (Microsoft's Assembler). Why? It's freakin' free , as in no charge, as in download it and use it.

Third, you're asking for code to fulfill your homework assignment. How are you going to learn anything if you don't do the work yourself?

Fourth, when lazy know-nothing programmers enter the workforce, they threaten EVERYBODY'S job that came before them, and that will follow them into the industry.

If you can prove me wrong about this being homework, I'll delete this answer.
 
Share this answer
 
v2
Comments
justme89 12-Apr-11 8:47am    
Haha, well I actually agree with you. However, programming in C# is not what I want to do after school, so I won't threaten anybody's job. All the best.
The compiler is actually the last step. You first start with a scanner that scans the input (also detects syntax errors). A parser that creates corresponding structures, which is usually a tree (and also detects grammatical errors). The corresponding structures (or tree items) are the most easy when they are objects of a class that has a compile method. After parsing the complete input you simply call the compile at the root (that will compile itself and every branch) and that way produce the output. You can also choose to implement an execute method instead of compile and that way create an interpreter. Just look for "How to build your own compiler/interpreter" with google and you will get lots of results.

Here you have some links that might get you started:
http://msdn.microsoft.com/en-us/magazine/cc136756.aspx[^]

http://blogs.microsoft.co.il/blogs/sasha/archive/2010/10/06/writing-a-compiler-in-c-lexical-analysis.aspx[^]

Good luck!
 
Share this answer
 
Comments
Manfred Rudolf Bihy 12-Apr-11 8:02am    
Good answer! 5+
BobJanova 12-Apr-11 8:39am    
This is true, but for an assembler, the structure part is very simple.
E.F. Nijboer 12-Apr-11 8:49am    
Yes I know, but when I wrote this the question was about a compiler :-)
CPallini 12-Apr-11 8:54am    
What you call 'compiler' I call 'code generation' part of the compiler (the latter including the lexer as well the scanner).
An oldie-goldie is the Crenshaw's series Let's build a compiler[^], inspired by the KISS[^] principle. He used Turbo Pascal and wrote the compiler for Motorola 68000 CPU, but, you know, in compiler contruction good ideas really matters.
:-)
 
Share this answer
 
Comments
#realJSOP 12-Apr-11 8:29am    
He's not interested in doing it himself...
BobJanova 12-Apr-11 8:40am    
Interesting link, might save that one for evening reading ;)
Just download Visual Studio 2010 Express. It's free. When you're done with it, uninstall it from your machine. If you don't like that option, google "C# comnpiler" and see if one of the 890,000 results gives you something you can use.
 
Share this answer
 
Comments
BobJanova 12-Apr-11 8:38am    
This is actually not the most efficient way to get csc, it's included with the .Net framework runtime.

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