1#----------------------------------------------------------------- 2# pycparser: dump_ast.py 3# 4# Basic example of parsing a file and dumping its parsed AST. 5# 6# Eli Bendersky [https://eli.thegreenplace.net/] 7# License: BSD 8#----------------------------------------------------------------- 9from __future__ import print_function 10import argparse 11import sys 12 13# This is not required if you've installed pycparser into 14# your site-packages/ with setup.py 15sys.path.extend(['.', '..']) 16 17from pycparser import c_parser, c_ast, parse_file 18 19if __name__ == "__main__": 20 argparser = argparse.ArgumentParser('Dump AST') 21 argparser.add_argument('filename', help='name of file to parse') 22 argparser.add_argument('--coord', help='show coordinates in the dump', 23 action='store_true') 24 args = argparser.parse_args() 25 26 ast = parse_file(args.filename, use_cpp=False) 27 ast.show(showcoord=args.coord) 28