"Lonnie Princehouse" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

> If you try this sort of inheritance, I'd recommend writing down the
> formal grammar before you start writing classes.  Don't try to define
> the grammar through the inheritance hierarchy; it's too easy to
> accidentally build a hierarchy that can't be translated into a
> single-pass-parsable grammar...

Understood.  I was using expression trees as a contrived example, and really 
want to know about the Python community's stylistic preferences for defing 
such hierarchies that don't absolutely need a root.

> I usually skip the inheritance and make everything an instance of the
> same class, e.g.
>
> class ASTNode(object): ...
>
> class Stmt(ASTNode): ...
> class Expr(ASTNode): ...
> class UnaryExpr(ASTNode): ...
> class BinaryExpr(ASTNode): ...

Eh?  There's still inheritance here: Everything is derived from ASTNode.  I 
understand that there is a separate design issue whether to make the 
hierarchy deep or shallow, but it's still a hierarchy.



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to