pycparser

C parser and AST generator written in pure Python

brewmacoslinux
Try with needOr install directly
Source

About

C parser in Python

Commands

pycparser

Examples

Parse a C file and generate an abstract syntax tree$ pycparser example.c
Parse C code with fake libc includes for preprocessing$ python -c "from pycparser import parse_file; ast = parse_file('code.c', use_cpp=True)"
Show AST representation of parsed C code$ python -c "from pycparser import c_parser; parser = c_parser.CParser(); ast = parser.parse('int x = 5;'); ast.show()"