Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageHi > 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
Post Follow-up to this messageSiddharth 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.
Post Follow-up to this message"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.
Post Follow-up to this messageSiddharth 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.
Post Follow-up to this messageSiddharth 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.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.