Functional languages like Haskell are ideal for implementing compilers. Complemented with a lexer and parser generator, they provide much of the functionality and ease-of-use associated with specialized compiler tools (aka compiler compilers) while being more flexible, better supported, and guaranteeing better long time availability.
There is a significant set of functionality that is required in each compiler like symbol table management, input-output operations, error management, and so on, which are good candidates for code reuse. The Compiler Toolkit is an attempt to provide an open collection of modules for these recurring tasks in a popular functional language. The toolkit is used for the interface generator C->Haskell.
Although the toolkit is developed with the Glasgow Haskell Compiler (GHC), a special effort is made to keep the system portable. In fact, all code that is either not Haskell 98 is located in a single module. Furthermore, the code is well commented, additional documentation is provided in a technical report, and the source code of two compilers currently developed on top of the toolkit is available.
A subset of the toolkit, called CTKlight, that essentially provides support for implementing syntactical analysis plus some utilities without the other, more heavy-weight features of the toolkit is available separately. It works with both GHC and Hugs 98.
The latest news:
Currently, the toolkit provides functionality in three main areas plus some infrastructure like a sophisticated makefile system and some utility routines.
In a small compiler project, these two modules can be used without the state handling (to make for a more light-weight system). See Chapter 5 in the documentation and CTKlight.
Of special interest might be the implementation of structure tree attributes, as it is rather different from the "traditional way" of building compilers in functional languages. Instead of being stored directly in the structure tree, the attributes are located in separate attribute tables that are indexed by attribute identifiers contained in each tree node. This minimizes the need to modify the structure tree during attribute evaluation and makes it easy to discard no longer needed attributes.
In its current state, the Compiler Toolkit already provides a significant amount of core functionality, which is reasonably well tested. While it is still consider to be a beta and has not undergone much performance debugging, it is already expected it to be helpful to somebody starting a new compiler effort.
To build the code, you need a reasonably recent version of the Glasgow Haskell Compiler.
The following releases of the Compiler Toolkit Light are available:
The code is covered by the GPL (GNU General Public
License); CTKlight is available under the LGPL (GNU Library General
Public License). Bug reports, comments, suggestions, and code
contributions should be directed to
Panne authored the module
GetOpt.hs for processing
command-line arguments. Gabriele Keller,
Pfannenstiel, and Martin Simons provided
feedback in the context of the Nepal compiler project. Simon L. Peyton
Jones suggested a number of valuable improvements to the
self-optimising lexer library.
This page is part of Manuel Chakravarty's WWW-stuff.
Last modified: Wed May 18 14:50:56 EST 2005