you can use pycparser to write your own parser, you can find more examples here
from pycparser import c_parser parser = c_parser.CParser() text = 'int x; int y; float z;' ast = parser.parse(text, filename='<none>') ast.show() FileAST: Decl: x, [], [], [] TypeDecl: x, [] IdentifierType: ['int'] Decl: y, [], [], [] TypeDecl: y, [] IdentifierType: ['int'] Decl: z, [], [], [] TypeDecl: z, [] IdentifierType: ['float']
source share