|
Project Information
Featured
Downloads
Links
|
pycparser is a complete parser for the C language, written in pure Python. It is a module designed to be easily integrated into applications that need to parse C source code. The following are some uses for pycparser, taken from real user reports:
pycparser is also referenced in a few academic theses and papers, mainly on the topic of parallel computing, where it's being used to translate a set of parallel extensions for the C language, down to plain C. An example of using pycparser: parser = CParser()
buf = '''
static void foo(int k)
{
j = p && r || q;
return j;
}
'''
t = parser.parse(buf, 'x.c')
t.show()Prints: FileAST:
FuncDef:
Decl: foo, [], ['static'], []
FuncDecl:
ParamList:
Decl: k, [], [], []
TypeDecl: k, []
IdentifierType: ['int']
TypeDecl: foo, []
IdentifierType: ['void']
Compound:
Assignment: =
ID: j
BinaryOp: ||
BinaryOp: &&
ID: p
ID: r
ID: q
Return:
ID: j
|