data structure for ASTs in Python-written parsers

E

eliben

Hello,

The Python interpreter uses ASDL (http://www.cs.princeton.edu/~danwang/
Papers/dsl97/dsl97.html) to describe the AST resulting from parsing.
In previous versions, there was another AST being used by the compiler
module - ast.txt and astgen.py in tools/compiler in the Python 2.5
source. However, as far as I understand this has been discontinued in
later Pythons.

I'm writing parsers in pure Python (with PLY), and wonder about the
best representation to use for the AST. So far I've been using a self-
cooked solution similar to ast.txt/astgen.py, but I was wondering
about ASDL.

Looking at it closely, it seems to me that ASDL is much more suitable
for statically-typed languages like C and Java than the duck-typed
Python. The assignment of types of nodes seems superfluous when "real"
Node classes can be used. Wherever dispatching is needed on the type
enum, in Python we can dispatch on isinstance(), and traversal using
reflection (automatic AST walkers) is possible in Python on the simple
representation, while ASDL just adds another complexity level.

Does this make sense? I realize Python itself uses ASDL because its
parser is coded in C. But what would you prefer as a representation
for parsers written *in* Python?

Thanks in advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top