C/C++ File Parser
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > C/C++ File Parser




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    C/C++ File Parser  
mudassir


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-05-07 06:21 PM

Hi All,

I am in search of a snippet that could parse a C/C++ source file and
give out as output different information on it. For example

1. Signature of function defined in a file.
2. Name of Global Variables declared.
3. Files dependencies..(#include).

Can you help?

thanks,
mudassir.






[ Post a follow-up to this message ]



    Re: C/C++ File Parser  
Pascal Bourguignon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-05-07 06:21 PM

mudassir <mudassir.shabbir@gmail.com> writes:

> Hi All,
>
> I am in search of a snippet that could parse a C/C++ source file and
> give out as output different information on it. For example
>
> 1. Signature of function defined in a file.
> 2. Name of Global Variables declared.
> 3. Files dependencies..(#include).
>
> Can you help?

You could use gccxml.  It's a gcc patched to extract the parse tree as
xml. Then you can do whatever you want with the xml.

--
__Pascal Bourguignon__                     http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.





[ Post a follow-up to this message ]



    Re: C/C++ File Parser  
David T. Ashley


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-05-07 06:21 PM

"mudassir" <mudassir.shabbir@gmail.com> wrote in message
news:1183638442.251575.301970@w5g2000hsg.googlegroups.com...
> I am in search of a snippet that could parse a C/C++ source file and
> give out as output different information on it. For example
>
> 1. Signature of function defined in a file.
> 2. Name of Global Variables declared.
> 3. Files dependencies..(#include).
>
> Can you help?

Parsing programming languages is now science rather than art.

Check out lex and yacc:

http://en.wikipedia.org/wiki/Lex_programming_tool

http://en.wikipedia.org/wiki/Parser_generator

You also may want to take one or two compiler design classes at a local
university.

In any case, least-cost approach is probably to:

a)Get familiar with the parsing theory.

b)Obtain C++ grammar from the GCC folks or elsewhere to use in lex/yacc.

c)It is my understanding that certain functions are called as certain
structures are parsed ... you would need to do the job you want to do in
those.

The task you proposed is not trivial.  There is a lot of potential
complexity there, especially with using the preprocessor and with TYPEDEF'
and so on.  This is not a "count the number of lines" kind of parsing task.

Dave.
--
David T. Ashley              (dta@e3ft.com)
http://www.e3ft.com          (Consulting Home Page)
http://www.dtashley.com      (Personal Home Page)
http://gpl.e3ft.com          (GPL Publications and Projects)







[ Post a follow-up to this message ]



    Re: C/C++ File Parser  
Thomas Dickey


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-06-07 06:21 PM

Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
 
[vbcol=seagreen]
> makedepend does that.

> Of course, you may not have these on your system but they are both
> available as free (i.e. GPL) source.

makedepend uses the X11 license...

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net





[ Post a follow-up to this message ]



    Re: C/C++ File Parser  
Barry


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-07-07 12:21 AM


"David T. Ashley" <dta@e3ft.com> wrote in message
 news:LPidnTl5NbhUvxDbnZ2dnUVZ_sSmnZ2d@gi
ganews.com...
> "mudassir" <mudassir.shabbir@gmail.com> wrote in message
> news:1183638442.251575.301970@w5g2000hsg.googlegroups.com... 
>
> Parsing programming languages is now science rather than art.

The "now" is funny. :-)
>
> Check out lex and yacc:
>
> http://en.wikipedia.org/wiki/Lex_programming_tool
>
> http://en.wikipedia.org/wiki/Parser_generator
>
> You also may want to take one or two compiler design classes at a local
> university.
>
> In any case, least-cost approach is probably to:
>
> a)Get familiar with the parsing theory.
>
> b)Obtain C++ grammar from the GCC folks or elsewhere to use in lex/yacc.
>
> c)It is my understanding that certain functions are called as certain
> structures are parsed ... you would need to do the job you want to do in
> those.
>
> The task you proposed is not trivial.  There is a lot of potential
> complexity there, especially with using the preprocessor and with TYPEDEF'
> and so on.  This is not a "count the number of lines" kind of parsing
> task.
>
> Dave.
> --
> David T. Ashley              (dta@e3ft.com)
> http://www.e3ft.com          (Consulting Home Page)
> http://www.dtashley.com      (Personal Home Page)
> http://gpl.e3ft.com          (GPL Publications and Projects)
>







[ Post a follow-up to this message ]



    Re: C/C++ File Parser  
Alex Colvin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-09-07 06:26 PM

>>> I am in search of a snippet that could parse a C/C++ source file and[vbcol=seagreen] 
[vbcol=seagreen] 

Unfortunately, parsing C requires more than lex&yacc. It also requires a
scoped symbol table to distinguish
(A)*B
where A is a typename, making this a cast of a pointer reference, from
simple multiplication. It's not hard, but it's not trivial.

Parsing C++ remains more of an art than a science. I doubt it can be done
with yacc without deep wizardry.


--
mac the naïf





[ Post a follow-up to this message ]



    Re: C/C++ File Parser  
toby


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
07-09-07 06:26 PM

On Jul 6, 1:19 pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> Thomas Dickey <dic...@saltmine.radix.net> writes: 
> 
> 
> 
> 
>
> Thank you for the correction.  If it maters to the OP, makedep does a
> similar job and is available under the LGPL.

gcc does too and may be closer to hand.

>
> --
> Ben.







[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:56 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register