Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

C parser
I am looking for a C parser that can generate a list of all variable
names, their type (int, char...) and scope (auto, static, ...) by reading
a C source file.

Also, is there any way to generate this information using an option to the
compiler (say, using gcc) ?

TIA
-siddharth

Report this thread to moderator Post Follow-up to this message
Old Post
Siddharth Choudhuri
07-29-04 02:08 AM


Re: C parser
Hi

> I am looking for a C parser that can generate a list of all variable
> names, their type (int, char...) and scope (auto, static, ...) by reading
> a C source file.

I think your requirement is a source analyzer. There are many source
analyzers available in the net.
Checkout UnderstandC++ from www.scitools.com

> Also, is there any way to generate this information using an option to the
> compiler (say, using gcc) ?

Do they ??

RERA


Report this thread to moderator Post Follow-up to this message
Old Post
Rajaram
08-04-04 08:57 AM


Re: C parser
Siddharth Choudhuri wrote:
> I am looking for a C parser that can generate a list of all variable
> names, their type (int, char...) and scope (auto, static, ...) by reading
> a C source file.

you maybe, able to use gcc and just reverse engineer the .stabs debugging
output in the assembly output. I vaguely remember the existance of a perl
hack that did just the above.


Report this thread to moderator Post Follow-up to this message
Old Post
Daniel C. Wang
08-04-04 08:57 AM


Re: C parser
"Siddharth Choudhuri" <sid@claudius.ics.uci.edu> a écrit
> I am looking for a C parser that can generate a list of all variable
> names, their type (int, char...) and scope (auto, static, ...) by reading
> a C source file.
>
> Also, is there any way to generate this information using an option to the
> compiler (say, using gcc) ?

Download the lcc-win32 compiler
(http://www.cs.virginia.edu/~lcc-win32)

then type
\lcc\bin\browsegen myfile.c

then look at the generated text file myfile.xrf

All variables, #defines, types, globals, etc etc are
there with the line where they are defined.


Report this thread to moderator Post Follow-up to this message
Old Post
jacob navia
08-04-04 08:57 AM


Re: C parser
Siddharth Choudhuri <sid@claudius.ics.uci.edu> wrote in message news:<04-07-079@comp.compil
ers>...
> I am looking for a C parser that can generate a list of all variable
> names, their type (int, char...) and scope (auto, static, ...) by reading
> a C source file.

You'd like to run this parser with the same -D definitions as your
original compiler. I would prefer to use the same compiler with the
same options because some of these options can introduce additional
#define's and change your source.
Instead of reading the source file you can read the object file (.o
or .obj) after compilation. For example, 'nm file.o' will give you
some info about external variables, but not about the automatic vars.
For better info you'd like to compile your source with symbol table
and/or debug info, and read this info from the object file. Notice
that some of the variables would have a complex type, e.g. structures,
unions and functions. You would have to find a way to deal with
definitions of these complex types together with definitions of the
variables.

Report this thread to moderator Post Follow-up to this message
Old Post
Michael Tiomkin
08-05-04 08:59 PM


Re: C parser
Siddharth Choudhuri <sid@claudius.ics.uci.edu> wrote
> I am looking for a C parser that can generate a list of all variable
> names, their type (int, char...) and scope (auto, static, ...) by reading
> a C source file.

I wrote a C parser, which is still incomplete for parsing, and which
doesn't take into account the preprocessing rigourously. It gives you
functions, statements, variable declarations, typedefs, structs,
unions and so on.

The C parser is implemented as a extended-BNF script in CodeWorker, a
parsing tool and a universal source code generator available at
"http://www.codeworker.org".
If you are interested, I could send you the C parser. It may not work
on every C file properly, and may need some adjustments or corrections
that I will do as soon as you will detect some mistakes.

Report this thread to moderator Post Follow-up to this message
Old Post
Cedric LEMAIRE
08-11-04 02:03 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Compilers archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:31 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.