From aac7b0599fc077ad1a0cabcb85bb26197107252d Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Fri, 7 Apr 2017 05:12:51 -0700 Subject: Basic AST dumping sample --- examples/dump_ast.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/dump_ast.py (limited to 'examples/dump_ast.py') diff --git a/examples/dump_ast.py b/examples/dump_ast.py new file mode 100644 index 0000000..3b6aae4 --- /dev/null +++ b/examples/dump_ast.py @@ -0,0 +1,25 @@ +#----------------------------------------------------------------- +# pycparser: dump_ast.py +# +# Basic example of parsing a file and dumping its parsed AST. +# +# Eli Bendersky [http://eli.thegreenplace.net] +# License: BSD +#----------------------------------------------------------------- +from __future__ import print_function +import argparse +import sys + +# This is not required if you've installed pycparser into +# your site-packages/ with setup.py +sys.path.extend(['.', '..']) + +from pycparser import c_parser, c_ast, parse_file + +if __name__ == "__main__": + argparser = argparse.ArgumentParser('Dump AST') + argparser.add_argument('filename', help='name of file to parse') + args = argparser.parse_args() + + ast = parse_file(args.filename, use_cpp=False) + ast.show() -- cgit v1.2.3