C# Compilers

Started by
10 comments, last by mntlinstituteflr 16 years, 11 months ago
Alright. I'm attempting to learn C# and i've been going at it for a few days now. I have previous experience in other programming languages, so I'm probably not going over the top. And I want to make a game suite, just a small one. However, I want to implement a compiler (or many). Are there any free open-source compilers (for any language) written in C#?
Advertisement
Have a look at Coco/R.
Mono's C# compiler is written in C#. Might be a fun bit of circular work to look at.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
I was looking at the Coco thing. And I mean it looks cool, but what the hell does it do! Sorry, this might be an easy question for you to answer, but this whole Coco thing is complete jibberish to me. I tried the ICSharpCode compiler and have too been lost for two days, partly because it doesn't even come with the correct dlls...

As for the Mono's compiler, I will try that, but is there a compiler for multiple languages that's written in C#, or is that impossible or is that what the Coco thing is? Might be stupid questions, but then again, this is the "For Beginners" forum after all.
Coco is a compiler/parser generator written in (among others) C#. In principle it generates the compiler and parser for your language of choice. Usually you don't want to write them "by hand" because it's a tedious and error-prone procedure, especially for people who are not experienced in the field.

Basically, you feed the generator with the grammar of your language (represented in a special form) and get a parser/compiler for it as output (i.e. the source code for it).

If you really want to write both, parser and compiler from the ground up, be warned that this is a non-trivial task. Considering you haven't mastered C# yet - let alone compiler and language theory - I would strongly recommend against it. Don't be tempted to think that by just looking at the source code of something as complex and sophisticated as an optimising compiler, you learn how to write one.

Writing a compiler can be a fun, educating and challenging journey, but don't underestimate the required effort.

Good luck,
Pat
Quote:Original post by darookie
If you really want to write both, parser and compiler from the ground up, be warned that this is a non-trivial task.
Forget non-trivial -- it's tedious, boring, error prone, and unrewarding.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Quote:Original post by Promit
Forget non-trivial -- it's tedious, boring, error prone, and unrewarding.

I remember it being quite fun for a while, but then again that was 9 years ago[rolleyes].
Quote:Original post by mntlinstituteflr
I tried the ICSharpCode compiler and have too been lost for two days, partly because it doesn't even come with the correct dlls...


huh? There's no such thing as "the ICSharpCode compiler". There's a website called ICSharpCode, but all it has is a bunch of tools for .Net languages, mainly SharpDevelop which is an IDE. What exactly are you looking for?
Sorry Scet, yes that's what I meant. I used (or did whatever) the ICSharp tools. And it led to more confusion. Now, I don't know if anybody understands my question clearly. Or maybe I still don't get it. Here' my question:

I want to be able to include a text editor inside of the application I'm making and when you hit compile it compiles the code you have in the text box in the language you selected. Does this make any sence?

Thanks for the help everyone!
Is your goal to write a compiler, or just to be able to compile from within your own application rather than from visual studio, or someone else's IDE?

If you don't necessarily want to write your own entire compiler, have a look at This thread... for some C# code that lets you compile other C# code from text into memory entirely within your own app.

The title of that thread is deceptive "easy scripting in .net" - you CAN use the technique for scripting, or you can modify it slightly to output EXE or DLLs to disk.

This topic is closed to new replies.

Advertisement