Module for parsing C (pre-processed header files only)?

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? Any help or pointers appreciated. /M

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? Hi Markus,
Magnus Therning schrieb: 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

magnus:
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?
Any help or pointers appreciated.
I think the main option for parsing C now is the c2hs parser -- there's a summer of code project to wrap it up as a suitable C manipulation, printing and parsing library, so we should see a good standalone solution in a few months. -- Don

On Wed, Apr 16, 2008 at 4:01 PM, Don Stewart
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
magnus: little
hard to make heads or tails of it without some guidance, so I couldn't tell whether it would be suitable. Would it?
Any help or pointers appreciated.
I think the main option for parsing C now is the c2hs parser -- there's a summer of code project to wrap it up as a suitable C manipulation, printing and parsing library, so we should see a good standalone solution in a few months.
Will it be delivered with good documentation? ;-) This is /very/ interesting for me and my job (what I'm talking about above is not for work though). I would love to see something that would allow me to spend more time using Haskell while being paid for it :-) /M

magnus:
On Wed, Apr 16, 2008 at 4:01 PM, Don Stewart <[1]dons@galois.com> wrote:
magnus: > 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? > > Any help or pointers appreciated.
I think the main option for parsing C now is the c2hs parser -- there's a summer of code project to wrap it up as a suitable C manipulation, printing and parsing library, so we should see a good standalone solution in a few months.
Will it be delivered with good documentation? ;-)
This is /very/ interesting for me and my job (what I'm talking about above is not for work though). I would love to see something that would allow me to spend more time using Haskell while being paid for it :-)
Exactly, its potentially a new leading project for Haskell, if we do a good job here. An exciting niche waiting to be exploited. -- Don
participants (3)
-
benedikth
-
Don Stewart
-
Magnus Therning