Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse C files [closed]

Tags:

c

parsing

I am looking for a Windows based library which can be used for parsing a bunch of C files to list global and local variables. The global and local variables may be declared using typedef. The output (i.e. list of global and local variables) can then be used for post processing (e.g. replacing the variable names with a new name).

Is such a library available?

like image 505
bhadra Avatar asked Nov 17 '08 17:11

bhadra


2 Answers

Some of the methods available:

  • Elsa: The Elkhound-based C/C++ Parser
  • CIL - Infrastructure for C Program Analysis and Transformation
  • Sparse - a Semantic Parser for C
  • clang: a C language family frontend for LLVM
  • pycparser: C parser and AST generator written in Python

Alternately you could write your own using lex and yacc (or their kin- flex and bison) using a public lex specification and a yacc grammar.

like image 128
luke Avatar answered Nov 06 '22 23:11

luke


Possibly overkill, but there's a complete ANSI C parser written with Boost.Spirit: http://spirit.sourceforge.net/repository/applications/c.zip

Maybe you'll be able to model it to suit your needs.

like image 3
Martin Cote Avatar answered Nov 06 '22 22:11

Martin Cote