[antlr-interest] special c/c++ parsing

Joakim Bodin joabo552 at student.liu.se
Wed May 14 02:04:43 PDT 2003


Hi, my name is Joakim Bodin and at the moment I'm writing a tool for
my thesis that involves taking C/C++ real-time components as an input.
>>From these components I need to parse out for each function which
other function that function calls and how many times. So for example:

void foo::bar1(int param) {
    fie1();
    for(int i=0;i < param; i++) {
        for(int j=0;j < param; j++) {
            fie2();
        }
    }
    bar2();
    fie1();
}

void foo::bar2() {
    bar1();
    int i=0;
    while(i < 5) {
        fie2();
    }
}

Should produce the output of:
void foo::bar1(param):
    fie1() 2;
    fie2() param*param;
    bar2() 1;

void foo::bar2():
    bar1() 1;
    fie2() 5;

Right now I'm thinking a C++ grammar subset would suffice to produce a
AST that I could use to obtain the information I want. But as I've
never used a parser before I'd like some input to this before I start.
Is this sufficient or would it be better to use the full C++ grammar
and then prune everything I'm not interested in?

Some help to construct the needed C++ grammar subset would also be
appreciated. Conditional statements could also enlarge the problem but
I've ignored that for the time being.

/Joakim Bodin


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list