Information Technology Projects
A Tcl Compiler Generator
In this course we write a compiler generator in the Tcl language. Compiler generators exist written in C and C++ on virtually every hardware platform. The standard program used today in Bison. But for those who do not want to maintain a C/C++ development environment, but still want to play around with syntax and parsing, either from a teaching or an experimental viewpoint a Tcl compiler generator is a useful program. As such it will only ever be a toy. When an industrial strength compiler is required recourse must be made to Bison.
A compiler generator is a very complex program computationally. Indeed it is one of the more testing computational tasks, so this is not a trivial exercise. In order to cut the task into small manageable pieces we take the same approach as the early writers of compiler compilers. This is a bootstrap approach which assumes we may have to write the language in assembly code. Fortunately we dont have to do this. The process is split into two stages, following the early work of McKeeman, Horning and Wortman , "A Compiler Generator" (Prentice Hall 1970), probably long since out of print. In this model the syntax analyser reads the syntax rules and outputs a table. The compiler consists of a scanner which uses the table to check the syntax of the program, together with an attached list of instructions saying what to do when each syntax element has been completely recognised. This can be a collection of user supplied procedures. In this model the syntax rules are seperated from the semantic rules which say how the syntax structure is to be interpreted.