Python complaints

Greg Ewing greg.ewing at
Thu Nov 25 11:57:13 CET 1999

Gareth McCaughan wrote:
>     if you adopt an OO approach to the
>     parse tree (with things like "class IfStatement(ParseNode):")
>     then you can't separate out very different operations like
>     foo.print(), foo.compile() and foo.evaluate(). (That is,
>     you can't group all the print methods together, and group
>     all the compile methods together somewhere else, etc.)

There is a way to do this. Instead of defining just one class
for each parse node, you define classes PrintIfStatement,
CompileIfStatement, EvaluateIfStatement, etc. which contain
the appropriate methods. Then you define the main IfStatement
class so that it inherits all of these.

The individual classes can then be grouped however you want,
e.g. you could put all the Compile* classes in a Compile
module, etc.


More information about the Python-list mailing list