This one understands c declarations as found in header files.
The output is valid python code; the parse tree, in fact, along with the source and an explanation.
[simon@arrow]$ ./cdecl.py "int foo;" #int foo; Declaration( Declarator( Identifier('foo'), DeclarationSpecifiers(BasicType('int')))) # explanation : foo is int. #-----------------------------------------------# [simon@arrow]$ ./cdecl.py "void (*signal(void(*)(int)))(int);" #void (*signal(void(*)(int)))(int); Declaration( Declarator( Identifier('signal'), Function( ParameterDeclaration( AbstractDeclarator( Pointer(), Function( ParameterDeclaration( AbstractDeclarator(TypeSpecifiers(BasicType('int'))))), TypeSpecifiers(BasicType('void'))))), Pointer(), Function( ParameterDeclaration( AbstractDeclarator(TypeSpecifiers(BasicType('int'))))), DeclarationSpecifiers(BasicType('void')))) # explanation : signal is function (pointer to function (int), returning void), returning pointer to function (int), returning void. #-----------------------------------------------#He doesn't inspect (non-trivial) expressions, as found in array sizes, enums, initializers etc.
int wont_look_at_this_next_bit[sizeof(struct foo)*3];
There are also some hacks so that (gcc) standard include files can be parsed:
[simon@arrow]$ ./harvest.py /usr/include/stdio.h ...
Maybe someone will extend the grammar to understand all of ANSI-C.
cdecl-0.45.tar.gz - 22nd january
cdecl-0.41.tar.gz - some type manipulations
cdecl-0.38.tar.gz - explanations broken, but now produces c code from parse tree.
cdecl-0.29.tar.gz - explanations work, but has some other bugs that have since been cleaned out.