[Mono-list] Re: First Snapshot of MonoBASIC

Miguel de Icaza miguel@ximian.com
16 Aug 2001 14:12:22 -0400

Hello Rafael!

   Wow, you are a quick hacker!

   Let me explain a few interesting things about how the C# compiler
works, and maybe you could explain me how the VB.NET language works
and we can work from there.

   The C# parser can not perform many checks while it is parsing
because the way C# allows declarations to happen afterwards (that is
why for example, you get compiler errors in `waves').  These are all
legal C# constructs:

	// Notice how `a' is declared after it is used.
	class X {
		void Y ()
			a = 1;
		int a;

	enum Blah {
		a = c + 1,
		b = 10,
		d = a + 4

	const int c = 14;

	// In this example class A is defined in terms of a class that
	// is found later on the input stream.
	class A : B {

	class B {

   This means that you wont have all the type information as you
encouter constructs.  The best you can do is to parse the program,
keep it on a tree, and then construct what the programmer actually

   The C# compiler currently is crafted in this way:

	* Parse all the input, and perform the simple error checking
          (variable arguments can be catched here for example).

	* Create interfaces recursively, find base interfaces. 

	* Create classes and structs recursively, find base classes,
          interfaces implemented.

	* Populate interfaces, and classes with fields, constants,

	* Actually compile methods.  Only at this point we can perform
          the actual compilation, as we now have all the type
          information, a complete list of methods and arguments,
          constants have been defined and registered.

   If you use my C# parser, you will be creating the tree in the first
step.  Here is where I do need your help, since I do not know anything
about VB.  You could do more syntax checking or even code generation
if VB is radically different from C#, or you could have a different
set of routines that perform the later stages of the compiler (in my
code the later stages are done in `PopulateClasses', called from the
main driver).