4 ms·
I think the most straightforward recursive-descent approach is just to parse the expression part of the type as an expression and then turn it inside out to get
by foldr 2y ago
I think the most straightforward recursive-descent approach is just to parse the expression part of the type as an expression and then turn it inside out to get the type. So if you have e.g. 'int (*(p[5]))(char)', then your parse tree is something like
declaration
int
function call
*
[]
p
5
char
and you need to turn that inside out to get something like
array
pointer to
function
int
(char)
This way you have a simple expression parser combined with a simple recursive tree transformation function. (The tree transformation took about 50 LOC when I implemented it for a toy parser.)