Home > Archive > Compilers > August 2004 > C parser
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Siddharth Choudhuri 2004-07-28, 9:08 pm |
| 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
| |
| Rajaram 2004-08-04, 3:57 am |
| 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
| |
| Daniel C. Wang 2004-08-04, 3:57 am |
| 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.
| |
| jacob navia 2004-08-04, 3:57 am |
| "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.
| |
| Michael Tiomkin 2004-08-05, 3:59 pm |
| Siddharth Choudhuri <sid@claudius.ics.uci.edu> wrote in message news:<04-07-079@comp.compilers>...
> 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.
| |
| Cedric LEMAIRE 2004-08-10, 9:03 pm |
| 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.
|
|
|
|
|