Nut-in-nut


This is my gift to all students on the occasion of the teacher's day, 22 June 2006.  As a teacher who taught in the department of computer engineering, the best prose I can write is an executable code.  I am very happy to hear all poems that students read to me today.  This is my reply.  Nut-in-nut is a compiler written in the target language, Nut.  It is a complete program which can be executed.  Please read how to use it in "more detail" link.  I wrote it to teach the class "Embedded Processors" in 2006.  I finished the last parenthesis last night and thought it is such a nice piece of program that I wish to share with all of you.

Nut-in-nut is a compiler in 500 lines of Nut itself.  The beauty is in its simplicity.  Usually a working compiler will require a program which is an order of magnitude larger than this.  The secret of its beauty lies partly in the target language itself.  I "borrow" a lot of ideas on language design from our older generation, LISP (for its eternal beauty).  To try it you need a virtual machine (written in C) that executes the N-code (an executable code compiled from Nut source code).  You can find more explanation how to make it run here. The intriguing idea is to "compile" itself and run its own object (compiler) to compile itself (an infinite recursion).  That is what we call self-generating system.  You may ask "but the virtual machine is written in C".  But the virtual machine can be written in Nut too. The only way to appreciate it is to try it out.

Enjoy the lasting beauty!