tags:

views:

239

answers:

9

Can anyone suggest me a helpful programming language which can be used to create a tool which will analyse the given C program and generate a txt report or html report containing information about the given program (function list, variable list etc). The program I intend to build is similar to doxygen but i want it for my personal use.

+1  A: 

Look into scripting languages. I'd recommend Python or Perl.

Matthew Cole
+3  A: 

ctags, perhaps?

Ctags generates an index (or tag) file of language objects found in source files that allows these items to be quickly and easily located by a text editor or other utility. A tag signifies a language object for which an index entry is available (or, alternatively, the index entry created for that object).

Denis Bueno
A: 

If it's a programming language you want then I'd say something which is known for string processing power so that would mean perl.

However the task you require can be rather complicated since you need to 'know' the language, so you would require to follow the same steps the compiler does, being lexical and grammatical analyses on the language (think flex, think yacc) in order to truly 'know' what meaning those strings have.

Perhaps the best starting point is to take a look at doxygen and try to reuses as much of the work done there as possible

amo-ej1
+1  A: 

Haskell has a relatively recent language-c project http://www.sivity.net/projects/language.c which allows the analysis of C code.

If you are familiar with Haskell, then it might be worth a look. Even if you are not, it might be interesting to have a go.

benefactual
+1  A: 

You're opening a big can of worms, this isn't an effective use of your time, blah blah blah, etc.

Moving on to an answer, if you're talking about anything beyond trivial analysis and you need accuracy, you will need to parse the C source code. You can do that in any language, but you will almost certainly want to generate your parser from a high-level grammar. There are any number of tools for that. A modern and particularly powerful parser generator is ANTLR; there are a number of ANTLR grammars for C, including easier-to-work-with subsets.

Larry OBrien
A: 

Lex/yacc are appropriate for building parsers.

theschmitzer
+3  A: 

Both Python and Perl have excellent string processing capabilities.

I'd suggest using something like ctags to parse the program, and just create a script to read the ctags file and output in txt/html.

The file format used by ctags is well-defined so that other programs can read it. See http://ctags.sourceforge.net for more information on ctags itself and the file it uses.

Branan
A: 

For a tool that provides with a vast amount of raw information about C, e.g., parses a wide variety of C dialects, builds ASTs, builds symbol table and control flow graphs, and can process thousands of compilation units in a single image, see http://www.semanticdesigns.com/Products/FrontEnds/CFrontEnd.html

Ira Baxter
A: 

pycparser is a complete parser for ANSI C89/C90 written in pure Python. It's being widely used to analyze C source code for various needs. It comes with some example code, such as listing all the function definitions in files, etc.

Eli Bendersky