News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Problem with parenthesis in definition

Started by daniloz, March 22, 2011, 02:04:05 PM

Previous topic - Next topic

daniloz

Hi,

The following code is not correctly parsed by CC (see screenshot):

void main ()
{
int* aaa;
int *aab;
int* aac[10];
int (*aad);
int (*aae)[10];


aa
}


Actually, what I want done is "int (*aae)[10]"... I know it's a bit obscure, but that what I need... ;-)

ollydbg

#1
dear daniloz, you need to know how the cc's parser works.
it just do some heuristic pattern match (with out any type information), thus from my point of view, it is hard to parse these definitions. though you can fix someone( some pattern, you still lose in other ones), you can look at the cc's code, mostly parserthread.cpp.

That's why I suggest use a full parser framework, either clang or gcc to get all the information(we say AST in compiler theory :D)
But this may have some other cost.

clang sounds good, but I prefer gcc :D

PS:
to parse this statement:
int (*aae)[10];

you need at least a tree structure and using some shunting-yard like algorithm.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.