4

I want to implement another debugger (language) for .NET (it's just for academic reason, so that it can implement just a part of a language). I myself like to implement NS2 (network Simlator 2) script for .NET in which anybody can write ns2 script and debug it with .NET

I read this article in stackoverflow and it is far from what I'm looking for.

Here is the requirement

  • have some predefined keywords (e.g: for, while, if ...)
  • check the correct form of the statements (e.g: for(start;end;counter){commands} ...)
  • diffferent colour for different types of statements
  • ability to add to any IDE (e.g: implementatin like add-in or as a dll or ...(I have no idea))
  • many other thing that is not necessary for now

How can I do this?

Update : I'm not sure that you got my point, take a look at this, it is very close to what I am looking for.

Community
  • 1
  • 1
Nasser Hadjloo
  • 12,312
  • 15
  • 69
  • 100
  • @BoltClock, as I told, it's just for academic reason and I can neglect some part of it (including hard sections), I just want to get some input from user and compile|debug it with clr. is it really hard? – Nasser Hadjloo May 10 '11 at 04:15
  • Got here wit the same bloody question for a completely different reason. I want to attach as debugger and wait for an unhandled exception and do something useful with the process state before it goes away. – Joshua May 11 '16 at 18:50

2 Answers2

5

It will not be an easy task. However: The Dragon Book is probably a good place to start (assuming you've got sufficient computer science background for a compiler theory book to make much sense to you). Compiler Construction: Principles and Practice is also a good text.

You'll want to compile to CIL (common intermediary language). This handy wiki article outlines the CIL instruction set. Debugging your intermediate code against the CLR... well, that's where the StackOverflow article you've linked will come in handy =)

That'll cover your first two bullets (and consume a big chunk of your life).

The next two are different issues, but the easiest way to 'make it go' would probably be to define a syntax for an existing text editor, and set up a macro in the program to call your compiler. I'd recommend TextPad, though I'm sure opinions on a configurable general-purpose text editor will vary among the community ;)

Designing a full IDE with all of the features you've come to know and love in your environment could be quite a task ... or you could try to build an eclipse plugin. Personally (assuming you can design your language and learn something from it), I'd just stick with syntax highlighting in TextPad.

Joe
  • 800
  • 4
  • 15
  • 1
    I suppose you could use some .NET language to write a .NET app that acts as an interpreter for NS2 (rather than compiling down to CIL), but you'll still need to do your lexing and parsing... – Joe May 10 '11 at 04:26
1

There is more and more interest in this area and in fact there is an active project by Microsoft Research that is looking at this on building a common infrastructure to build compiler (and debugger) for custom languages targetting .NET

http://cciast.codeplex.com/

I have used the infrastructure myself but not an expert in compiler technology. Hope this gives you a good starting point and you may find the discussion forum useful to share idea with like minded people.

Fadrian Sudaman
  • 6,405
  • 21
  • 29