diff options
author | Eli Bendersky <eliben@gmail.com> | 2017-04-07 05:12:51 -0700 |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2017-04-07 05:12:51 -0700 |
commit | aac7b0599fc077ad1a0cabcb85bb26197107252d (patch) | |
tree | 11e319b63e6134089ade6483e2e2a0a7e8e06c22 /examples | |
parent | 0cf73e461111519fdbd9e42249c9674ec8c78ce6 (diff) | |
download | pycparser-aac7b0599fc077ad1a0cabcb85bb26197107252d.tar.gz |
Basic AST dumping sample
Diffstat (limited to 'examples')
-rw-r--r-- | examples/dump_ast.py | 25 |
1 files changed, 25 insertions, 0 deletions
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() |