Author Topic: Problem with parenthesis in definition  (Read 7125 times)

Offline daniloz

  • Regular
  • ***
  • Posts: 268
Problem with parenthesis in definition
« on: March 22, 2011, 02:04:05 pm »
Hi,

The following code is not correctly parsed by CC (see screenshot):
Code
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... ;-)

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Problem with parenthesis in definition
« Reply #1 on: March 22, 2011, 03:20:55 pm »
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:
Code
int (*aae)[10];

you need at least a tree structure and using some shunting-yard like algorithm.
« Last Edit: March 22, 2011, 03:22:30 pm by ollydbg »
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.