summaryrefslogtreecommitdiff
path: root/examples/dump_ast.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/dump_ast.py')
-rw-r--r--examples/dump_ast.py25
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()