cpphs-0.2 --------- Cpphs is a re-implementation (in Haskell) of the C pre-processor. Version 0.1 dealt only with conditional compilation (#if and friends) and file inclusion (#include). Version 0.2 now also implements the rest of cpp's functionality, namely in-line symbol replacement and macro expansion (#define and friends). I believe this to be a reasonably complete and correct implementation, and have tested it on some non-trivial examples from the standard libraries (e.g. Foreign.Storable and HOpenGL). Nevertheless, there will be bugs and I encourage you to find them and report them. http://www.cs.york.ac.uk/fp/cpphs/ ---- Why re-implement cpp? Rightly or wrongly, the C pre-processor is widely used in Haskell source code. It enables conditional compilation for different compilers, different versions of the same compiler, and different OS platforms. It is also occasionally used for its macro language, which can enable certain forms of platform-specific detail-filling, such as the tedious boilerplate generation of instance definitions and FFI declarations. However, there are two problems with cpp, aside from the obvious aesthetic ones: * For some Haskell systems, notably Hugs on Windows, a true cpp is not available by default. * Even for the other Haskell systems, the common cpp provided by the gcc 3.x series is changing subtly in ways that are incompatible with Haskell's syntax. There have always been problems with, for instance, string gaps, and prime characters in identifiers. These problems are only going to get worse. So, it seemed right to attempt to provide an alternative to cpp, both more compatible with Haskell, and itself written in Haskell so that it can be distributed with compilers. Share and Enjoy, Malcolm
On Sat, May 15, 2004 at 09:30:47PM +0100, Malcolm Wallace wrote:
I believe this to be a reasonably complete and correct implementation, and have tested it on some non-trivial examples from the standard libraries (e.g. Foreign.Storable and HOpenGL). Nevertheless, there will be bugs and I encourage you to find them and report them.
If you want to really stress your program, check Boost.Preprocessor library. This is a library of arithmetic operations, data structures, looping constructs, etc. all implemented entirely in C preprocessor. http://www.boost.org/libs/preprocessor/index.html The distribution of Boost contains regression tests for preprocessor library. It's placed in libs/preprocessor/test/. Right now cpphs doesn't pass any test, because it trips on comments after #. And now two error reports from me. 1. #define C D D #define B C C #define A B B A should expand to D D D D D D D D not D D C B 2. #define F(x) #x F(abcd efg) should expand to "abcd efg" not #abcd efg Best regards, Tom -- .signature: Too many levels of symbolic links
participants (3)
-
Malcolm Wallace -
Ross Paterson -
Tomasz Zielonka