blob: 63f5e2d5437e0e0f78e830d7fd4d41970ce677a4 [file] [log] [blame]
Eli Benderskyaac7b052017-04-07 05:12:51 -07001#-----------------------------------------------------------------
2# pycparser: dump_ast.py
3#
4# Basic example of parsing a file and dumping its parsed AST.
5#
Jon Dufresne1d866992018-06-26 13:49:35 -07006# Eli Bendersky [https://eli.thegreenplace.net/]
Eli Benderskyaac7b052017-04-07 05:12:51 -07007# 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')
Eli Bendersky04119632018-09-30 05:30:03 -070022 argparser.add_argument('--coord', help='show coordinates in the dump',
23 action='store_true')
Eli Benderskyaac7b052017-04-07 05:12:51 -070024 args = argparser.parse_args()
25
26 ast = parse_file(args.filename, use_cpp=False)
Eli Bendersky04119632018-09-30 05:30:03 -070027 ast.show(showcoord=args.coord)