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

mzukowski at yci.com mzukowski at yci.com
Wed May 14 08:47:40 PDT 2003


It's actually kind of hard to write a parser that parses just a subset of a
language.  The question becomes how to recognize what you want to ignore....
It would be better to use the full C++ grammar and then prune your tree to
just what you need.

Monty

-----Original Message-----
From: Joakim Bodin [mailto:joabo552 at student.liu.se]
Sent: Wednesday, May 14, 2003 2:05 AM
To: antlr-interest at yahoogroups.com
Subject: [antlr-interest] special c/c++ parsing


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/ 


 

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




More information about the antlr-interest mailing list