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

lgcraymer lgc at mail1.jpl.nasa.gov
Wed May 14 11:41:35 PDT 2003


I'll echo Monty's comment.  Function calls can appear in enough places 
(including complex expressions and argument lists to functions) that 
it would be difficult to identify a subset grammar.  It is much easier 
to prune, even when you are dealing with a language as cumbersome as 
C++.

--Loring

--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> 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 s...]
> 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