Term rewriting

Simon Burton simonb at webone.com.au
Fri Jan 3 21:58:44 EST 2003


Has anyone (knowingly) implemented a 'term rewriting' framework in python?
Perhaps as part of another project?

I am implementing something along these lines for a parser project
(cdecl.py); have decided to manipulate the parse tree *after* building it,
rather than trying to do it all at once (too brittle).

So, to keep the tree-transformations separate from the parsing.
Here is what is going on so far:

class Node(list):
  " node in the parse tree "

and for each syntactic unit, a class derived (perhaps indirectly) from Node.

The 'operators' are Nodes, and the 'terms' are Node(list) instances.
This means that operators are varadic, but still, things like
distributivity, commutativity, make sense.

Two ideas now.
CRUDE) each operator has one (or more) appropriate 'act' method(s) that accept a parent argument.
FANCY) a whole new class heirarchy of general Node(list) transforms.
Instances would respond to specified class instances (term types) only.

Well, i'd like to see any relevant code people have.

bye,

Simon Burton.





More information about the Python-list mailing list