by ratboy666 · 8y ago · 0 comments
: fred@dejah sql $; cdecl
Type `help' or `?' for help
cdecl> declare x as pointer to function returning int
int (*x)()
cdecl> declare x as pointer to function returning pointer to function returning int
int (*(*x)())()
cdecl>I tried looking at cdecl's source code but everything is implemented as a big yacc grammar, which obscures the control flow of the algorithm. While this is necessary for the parsing feature, I suspect that for producing declarations it might be possible to use a simple recursive algorithm instead...
I found that to be trickier than it sounds.
If anyone can help me find a way to convert a tree representing a C data type into a string with a syntactically valid C declaration for it I would be very grateful. I suspect that it should be possible to do this via a clean recursive algorithm, but the only implementation of this I could find so far was cdecl's LALR-based one.
apt install cdecl