|
|
| mudassir 2007-07-05, 1: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.
| |
| Pascal Bourguignon 2007-07-05, 1: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.
| |
| David T. Ashley 2007-07-05, 1: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)
| |
| Thomas Dickey 2007-07-06, 1: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
| |
|
|
"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)
>
| |
| Alex Colvin 2007-07-09, 1: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
| |
|
| 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.
|
|
|
|