data structure for ASTs in Python-written parsers

Discussion in 'Python' started by eliben, Feb 14, 2009.

  1. eliben

    eliben Guest

    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
     
    eliben, Feb 14, 2009
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve C. Orr, MCSD
    Replies:
    1
    Views:
    563
    reaway lee
    Aug 24, 2003
  2. Snyke
    Replies:
    1
    Views:
    2,974
    Christopher Benson-Manica
    Aug 5, 2004
  3. John J. Lee
    Replies:
    3
    Views:
    914
    John J. Lee
    Jun 26, 2003
  4. Gordon Fraser
    Replies:
    0
    Views:
    261
    Gordon Fraser
    Oct 7, 2008
  5. KaiWen
    Replies:
    102
    Views:
    2,738
    Jorgen Grahn
    Sep 15, 2011
Loading...

Share This Page