[Haskell-cafe] Re: Module for parsing C (pre-processed header files
benjovi at gmx.net
Tue Apr 15 12:02:41 EDT 2008
Magnus Therning schrieb:
> Is there such a beast out there?
> If this were a list on some OO language I'd ask for something that
> created an AST and then offered an API based around a visitor pattern.
> The pre-processor (platform specific most likely, but could be cpphs of
> course) would be run prior to the tool I'm considering writing. After
> that I only need access to declarations of C functions and definitions
> of types (structs, enums, other typedefs).
> I had a quick look at the code in c2hs yesterday, but found it a little
> hard to make heads or tails of it without some guidance, so I couldn't
> tell whether it would be suitable. Would it?
the C parser in c2hs is able to parse preprocessed C and build an AST
for you. As c2hs also needs to extract function declarations and type
definitions, there is also code to do that.
Actually I applied for soc project to prepare a more general library
from c2hs' code base, which would also provide what you are asking for.
Right now, you can download the source code and have a look at
c2hs/c/tests/CCWrapper.hs on how to invoke to parser, at c2hs/c/CAST.hs
for the syntax tree datatypes, c2hs/c/CTrav.hs for syntax tree traversal
and in gen/GenBind.hs to see how c2hs uses this functionality.
best regards, benedikt
More information about the Haskell-Cafe