Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 12-Apr-11 2:49am
Edited 12-Apr-11 6:13am
v3
Comments
justme89 at 12-Apr-11 7:53am
   
I need to code it myself.
justme89 at 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...
   
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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Third link of the first page in Google when I search for "C# simple compiler":
 
http://msdn.microsoft.com/en-us/magazine/cc136756.aspx[^]
  Permalink  
Comments
Manfred R. Bihy at 12-Apr-11 8:02am
   
Nice link! 5+
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 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.
  Permalink  
v2
Comments
justme89 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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!
  Permalink  
Comments
Manfred R. Bihy at 12-Apr-11 8:02am
   
Good answer! 5+
BobJanova at 12-Apr-11 8:39am
   
This is true, but for an assembler, the structure part is very simple.
E.F. Nijboer at 12-Apr-11 8:49am
   
Yes I know, but when I wrote this the question was about a compiler :-)
CPallini at 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).
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
Smile | :)
  Permalink  
Comments
   
He's not interested in doing it himself...
BobJanova at 12-Apr-11 8:40am
   
Interesting link, might save that one for evening reading ;)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
BobJanova at 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)

  Print Answers RSS
0 OriginalGriff 365
1 Sergey Alexandrovich Kryukov 319
2 CPallini 275
3 DamithSL 214
4 Maciej Los 185
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 12 Apr 2011
Copyright © CodeProject, 1999-2014
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