Blog archive Contact the blog

Change, my Dear. And it Seems not a Moment too Soon.

Written by: Jesse Phillips on: 2021-12-31 18:22:17. Tags: Python, AST, GitHub.

A section of VAST Source Code

Two years! And what a strange two years it’s been since I last posted on here. As you can imagine, I’ve been rather busy, completing my Bachelors’ degree whilst under lockdown due to the COVID-19 pandemic (with a first-class degree with honours), applying for – and beginning – research towards my PhD, and working on several other projects alongside that. And it’s one of those projects I’m writing about today!

Abstract Syntax Trees are often a useful tool for developers, when it comes to analysing code. These data structures contain the structure of a text in a formal grammar. In most cases, the structure of a piece of source code. ASTs may be used in compilation as the result of syntax analysis to be used for semantic analysis, in program transformation for generating semantic equivalents, or even in program documentation as a visualisation showing the structure of some code.

That’s where this project comes in. According to TIOBE [1], Python is the most popular programming language of December 2021, up from third place last year, following a steady increase since about 2017. A powerful feature of Python is the in-built AST class [2], which allows you to generate and parse the AST of any given Python code. Which is where I encountered an issue. Around October, I was trying to analyse the AST of a script when I realised that the ASTs produced by the AST class, whilst good for walking in code, aren’t very user-friendly in text format; being full of extraneous data and punctuation. I looked for a way to plot the AST as a graph on-the-fly, which could be saved as an image – but there were no solutions that did the job.

So, I made one! VAST (VisAST on PyPI) is a Python package which generates and visualises ASTs for Python scripts. It’s still a bit rough around the edges but should be fully-functioning. Why not give it a go?

If you enjoyed reading this article as much as I enjoyed writing it, you can help keep this blog going by showing me some love and donating on PayPal.Me!




[1] Tiobe.com. 2021. Home | TIOBE - The Software Quality Company. [online] Available at: <https://tiobe.com> [Accessed 31 December 2021].
[2] Docs.python.org. 2021. ast — Abstract Syntax Trees — Python 3.10.1 documentation. [online] Available at: <https://docs.python.org/3/library/ast.html> [Accessed 31 December 2021].



By using this site, you agree to