zz_parse.py 487 B

123456789101112131415161718192021
  1. from __future__ import print_function
  2. import sys
  3. from pycparser import c_parser, c_generator, c_ast, parse_file
  4. if __name__ == "__main__":
  5. parser = c_parser.CParser()
  6. code = r'''
  7. void* ptr = (int[ ]){0};
  8. '''
  9. print(code)
  10. ast = parser.parse(code)
  11. ast.show(attrnames=True, nodenames=True)
  12. print(ast.ext[0].__slots__)
  13. print(dir(ast.ext[0]))
  14. print("==== From C generator:")
  15. generator = c_generator.CGenerator()
  16. print(generator.visit(ast))