Damian Conway > Parse-RecDescent-1.966_000 > csourceparser.pl


Annotate this POD


New  1
Open  10
View/Report Bugs
Source   Latest Release: Parse-RecDescent-1.967013


csourceparser.pl - extract components from sourcecode written in the C programming language


This documentation refers to csourceparser.pl version 0.1.0


./csourceparser.pl [OPTION] ... FILE ...


Print signatures of functions defined in a C-file:

./csourceparser.pl -f myprog.c

Print all declarations in a C-file:

./csourceparser.pl -d myprog.c

Print all structures in a C-file:

./csourceparser.pl -u myheader.h


One or more C-Sourcefiles to parse.


-c, --code

Show parsed source code with line numbers

-d, --declarations

Prints (global) declarations in the sourcefile to stdout

-e, --errors

Print error messages generated by Parse::RecDescent to the file 'errfile'

-f, --functions

Prints the signatures of functions defined in the source file to stdout (the function bodys are ommited)

-h, --help

Print this help

-p, --precompile

Generate precompiled parsers Cgrammar.pm and DecommentGrammar.pm in the current working directory. Precompiled parsers will speed up parsing. If these files are available in the current working directory they will be used automatically. Every time the --precompile option is set the precompiled parsers are generateted newly so this option should only be used only once. Also, don't forget to recreate the precompiled parseres if you modify the grammar.

-s, --skippedlines

Show which lines had been skipped during parse due to parser errors or unrecognized tokens in the C source code

-t, --trace

Print full tracecode generated by Parse::RecDescent. Note: this can be a lot

-u, --structs

Print all structs and unions defined in the C sourcefile

-v, --verbose

Each use encreases verbosity level by one.

Level 1:

Print parsed sourcecode and skipped lines (same as -sc)

Level 2:

Print tracecode of parse level 3 (C code without preprocessor directives and comments)

Level 3:

Print full tracecode.


If you don't get the output you expect try to set the -sc options to see what happens. When the parser can't handle the input it will silently get skipped (for empty lines this is a normal behaviour).

If the parser doesn't behave as you expect take a look at the tracecode, e.g. ./csourceparser -t file.c 2> trace for full tracecode or ./csourceparser -vv file.c 2> trace to see only parser level 3 (C-parser) trace code. Depending on the size of the input file(s) this could take some time and may occupy some hd-space.

Please refer to the Parse::RecDescent documentation if you get errors after modifying the grammar.



Macros in C-Files could not be parsed at this time. Any declarations and definitions containing macros my cause errors. Perhaps this feature could be implemented in the future by using a "real" preprocessor like m4.

Please report problems to Hendrik Sirges (hendrik.sirges at fh-swf.de) Patches are welcome.


 Hendrik Sirges  <hendrik.sirges[at]fh-swf.de>


This program is Copyright 2005 by Hendrik Sirges. This program is free software; you can redistribute it and/or modify it under the terms of the Perl Artistic License or the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

If you do not have a copy of the GNU General Public License write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

syntax highlighting: