Well, since my pycparser project is nearing completion, I’ve decided to implement cdecl on top of it. As pycparser is a complete parser and produces ASTs from ANSI C, I figured this shouldn’t be too complicated.
Indeed, it turned out to be quite simple. The core of the implementation (which you can see here) is a 30-line function that traverses the AST recursively and spits out the explanation.
Here are a couple of sample results:
char *(*(**foo )());
=> foo is a array of array of pointer to pointer to function() returning pointer to array of pointer to char
static const char* const cptr;
=> cptr is a static array of const pointer to const char
The cdecl is a simple and fun way to experiment with pycparser. It teaches how to explore the AST created by pycparser an traverse it correctly.