ANN: cpphs-0.1 (was: #ifdef considered harmful)

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Wed Apr 7 19:11:38 EDT 2004


I wrote:
> >                         Half of the cpp parsing/selection code is
> > already available within hmake.  I would take on the project myself,
> > if I had time.

OK, that was a fatal statement on my part I fear....  I have hacked
on the hmake code a bit today, and can now announce the first release of:


				cpphs 0.1
	a standalone replacement for cpp, written in Haskell'98

		http://www.cs.york.ac.uk/fp/cpphs

Needless to say, it doesn't do everything you would want yet.
In summary, it can cope with conditionals and inclusion, but not
parametrised macro expansion.

This is definitely prototype code, so please try it out and report
any bugs.  Suggestions for a better name, and for positioning of
the worker modules in the hierarchical libraries would be welcome.
We can think about putting it in CVS and getting compilers to use it
at a later date.

Here is an excerpt from the README:

USAGE
-----
        cpphs  [ filename | -Dsym | -Dsym=val | -Ipath ]+
                                                                                
You can give any number of filenames on the command-line.  The
results are catenated on standard output.
                                                                                
Options:
    -Dsym       define a symbol
    -Dsym=val   define a symbol with a specific value
    -Ipath      add a directory to the search path for #include's
                                                                                
There are NO symbols defined by default.  Could easily be changed
in the source code though.
                                                                                
The search path is searched in order of the -I options, except that
the current directory is always searched first.

Features that do work:
    #ifdef      simple conditional compilation
    #if         the full boolean language of defined(), &&, ||, ==, etc.
    #elif       chained conditionals
    #define     in-line definitions (symbols only, not macros)
    #undef      in-line revocation of definitions
    #include    file inclusion
    #line       line number directives
                                                                                
Numbering of lines in the output is preserved so that any later
processor can give meaningful error messages.  When a file is
#include'd, cpphs inserts #line directives for the same reason.
                                                                                
Any syntax errors in cpp directives, and any failure to find a
#include'd file, gives a message to standard error and halts the
program.

Features that don't work:
    #define	parametrised macro definitions
    \		especially those that extend over several lines
		with line continuation characters


Regards,
    Malcolm


More information about the Libraries mailing list