E
eliben
Hello,
I'm building a parser in Python, and while pondering on the design of
my ASTs had the idea to see what Python uses. I quickly got to the
compiler.ast module, and understood it's automatically generated. So I
went to the source, ast.txt and tools/compiler/astgen.py, where I was
this unexpected message:
"""Generate ast module from specification
This script generates the ast module from a simple specification,
which makes it easy to accomodate changes in the grammar. This
approach would be quite reasonable if the grammar changed often.
Instead, it is rather complex to generate the appropriate code. And
the Node interface has changed more often than the grammar.
"""
Now, to me the design of the AST in Python looks quite elegant,
especially from the point of view of the AST's user (using Visitors to
walk the AST). And astgen.py looks like a nice approach to generate
tons of boilerplate code.
So, my questions:
1) Is the compiler.ast module really employed during the compilation
of Python into .pyc files ?
2) What is the meaning of the comment in astgen.py ? Are the Python
maintainers unhappy with the design of the AST ?
3) What other approach would be recommended to generate a very
detailed AST hierarchy, if the one in astgen.py is dissapointing ?
Thanks in advance
Eli
I'm building a parser in Python, and while pondering on the design of
my ASTs had the idea to see what Python uses. I quickly got to the
compiler.ast module, and understood it's automatically generated. So I
went to the source, ast.txt and tools/compiler/astgen.py, where I was
this unexpected message:
"""Generate ast module from specification
This script generates the ast module from a simple specification,
which makes it easy to accomodate changes in the grammar. This
approach would be quite reasonable if the grammar changed often.
Instead, it is rather complex to generate the appropriate code. And
the Node interface has changed more often than the grammar.
"""
Now, to me the design of the AST in Python looks quite elegant,
especially from the point of view of the AST's user (using Visitors to
walk the AST). And astgen.py looks like a nice approach to generate
tons of boilerplate code.
So, my questions:
1) Is the compiler.ast module really employed during the compilation
of Python into .pyc files ?
2) What is the meaning of the comment in astgen.py ? Are the Python
maintainers unhappy with the design of the AST ?
3) What other approach would be recommended to generate a very
detailed AST hierarchy, if the one in astgen.py is dissapointing ?
Thanks in advance
Eli