Dienstag, 1. Juli 2008

First things first ?

This summer I'm working on a C99 parser and pretty printer library for haskell, coined Language.C - which might sound a little boring and like a lot of work.
The good (and sometimes tricky) thing about it is that there was already an almost complete parser for C99 available - written for the c2hs project and  buried within a large framework. The complexity of the framework made it really hard to use for anyone outside c2hs.
The goal of the GSoC project I'm working on is to pull out the C related components from c2hs and to create a complete, well-tested library for parsing and pretty printing, with a usable and documented API. 
Complete ?  One thing I did was to precisely define which subset of C the library will handle (currently, that's almost all of -std=gnu99). Furthermore, the parser should record everything parsed in such a way that it is possible to reconstruct the source file from the AST (including the somewhat nasty __attribute__ annotations).
Well-tested ? We use round-trip tests (parse = parse . prettyPrint . parse) on both real world libraries and the gcc-dg test-suite. Hereby, a Data.Generics-based AST comparison helps to avoid mistakes in the tests themselves.  Furthermore, automated measurements should prevent performance bugs - it is easy to introduce them in haskell.
Of course it would also be nice to have a rich analysis framework, quasi-quotation, and similar things - of which only some can be implemented by me. But I hope that it will be easy to work on and extend the library in the future.
For now, I'd like to release a preview of the library soon, as I believe it is already usable for some tasks (the repo is at http://code.haskell.org/language-c/).


Anonym hat gesagt…

Great work, Benedict! I'm looking forward to playing with the alpha release on hackage.

Neil Mitchell hat gesagt…

That is fantastic! Well done :-)