[Python-3000] AST access (WAS: Adaptation vs. Generic Functions)

Guido van Rossum guido at python.org
Mon Apr 10 17:39:36 CEST 2006


On 4/10/06, Talin <talin at acm.org> wrote:
> I have a rather odd use case for this. A while back, I decided I wanted to
> write an algebraic solver, similar to what Mathematica does, except that
> I wanted to write it in Python. Not just implement it in Python, but have
> Python be the language in which the rules of formula manipulation were
> expressed.
[...]
> You can immediately see the problem - since I don't have syntactical
> support, I have to manually enter in the expression in an AST-like form,
> which is clumsy to say the least.

I've seen other packages like this (for different solvers) that solved
this by overloading various operators to produce a parse tree. All you
need is some primitive objects named X, Y, Z etc. and then X**2+Y**2
produces the appropriate parse tree.  Then the analyzer can walk the
parse tree.

Anyway, I'm not sure I consider this a strong use case for needing
access to Python's AST; the language you need to parse is much smaller
than Python and a custom parser would probably do just as well.

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list