Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Library for programming Abstract Syntax Trees in Python

I'm creating a tree to represent a simple language. I'm very familiar with Abstract Syntax Trees, and have worked on frameworks for building and using them in C++. Is there a standard python library for specifying or manipulating arbitrary ASTs? Failing that, is there a tree library which is useful for the same purpose?

Note, I am not manipulating Python ASTs, so I think the AST module isn't suitable.

like image 564
Paul Biggar Avatar asked Dec 23 '09 03:12

Paul Biggar


2 Answers

ASTs are very simple to implement in Python. For example, for my pycparser project (a complete C parser in Python) I've implemented ASTs based on ideas borrowed from Python's modules. The various AST nodes are specified in a YAML configuration file, and I generate Python code for these nodes in Python itself.

like image 74
Eli Bendersky Avatar answered Sep 20 '22 17:09

Eli Bendersky


pyast is a package for building declarative abstract syntax trees.

like image 45
Ioannis Filippidis Avatar answered Sep 22 '22 17:09

Ioannis Filippidis