Wednesday, July 3, 2013

Single pass compilers

Multi-pass compilers seem bad to many, so the single pass compiler is very seductive. Both are the dark side. In my mind, the perfect compiler is two-pass, no more or less. The first pass collects and organizes names. The second pass is similar to a single pass compiler, but now has more intelligence and doesn't force a specific order on code. Scope rules are kept simple. You only need two: everything declared in a routine is private to that routine. Everything in a file outside a routine is private to that file unless declare public. A file is either a class or it is not. That's one line at the top of your file: Class ClassName. You don't need namespaces. A class is a namespace. Ok, if you want, a third pass could remove the vectors introduced in the second pass, but isn't really needed because the second pass could do that at the cost of being a bit slower. I think it may be possible to do even that in a way that doesn't slow the second pass down much. Getting rid of the vectors means your executable doesn't retain any names (keeping is small) unless it's a library and then only the public names are retained.

Get rid of everything else related to this. It isn't need and just makes a mess of your compiler. Keep it simple and your mind will have room to consider if other elements should or should not be part of your language. One day I hope to be in a position to show rather than just tell. But first I must complete a simple project that provides me with a bit of income. One definite element my language will have is Euphoria type sequences. Nothing else allows an algorithm to be so clear and simple.

No comments: