[Python-Dev] AST branch is in?
nas at arctrix.com
Fri Oct 21 20:32:22 CEST 2005
Anthony Baxter <anthony at interlink.com.au> wrote:
> Could someone involved give a short email laying out what concrete (no
> pun intended) advantages this new compiler gives us?
One advantage is that it decreases the coupling between the parser
and the backend of the compiler. For example, it should be possible
to replace the parser without modifying a lot of the compiler.
Also, the concrete syntax tree (CST) generated by Python's parser is
not a convenient data structure to deal with. Anyone who's used the
'parser' module probably experienced the pain:
>>> parser.ast2list(parser.suite('a = 1'))
[257, [266, [267, [268, [269, [320, [298, [299, [300, [301,
[303, [304, [305, [306, [307, [308, [309, [310, [311, [1,
'a']]]]]]]]]]]]]]], [22, '='], [320, [298, [299, [300, [301, [303,
[304, [305, [306, [307, [308, [309, [310, [311, [2,
'1']]]]]]]]]]]]]]]]], [4, '']]], [0, '']]
> Does it just allow us to do new and interesting manipulations of
> the code during compilation?
Well, that's a pretty big deal, IMHO. For example, adding
pychecker-like functionality should be straight forward now. I also
hope some of the namespace optimizations get explored (e.g. PEP
> Cleaner, easier to maintain, or the like?
At this point, the old and new compiler are pretty similar in terms
of complexity. However, the new compiler is a much better base to
More information about the Python-Dev