[Compiler-sig] Assign nodes

Finn Bock bckfnn@worldonline.dk
Tue, 16 Apr 2002 09:56:59 GMT


[Jeremy, in a checkin msg]

>Instead of extra Lvalue production, have separate constructors for the
>assign type.  This makes sense because the code generate for an
>expression as the target of an assignment is quite different than an
>expression elsewhere.

An assign node in a 'del' statement is also quite different from an
assignment so you would want a special set of nodes for deletions as
well (DelAttribute, DelSubscript, DelName, DelList and DelTuple) ?

>+ 	-- the subset of expressions that are valid as the target of
>+ 	-- assignments. 
>+ 	assign = AssignAttribute(expr value, identifier attr)
>+ 	     | AssignSubscript(expr value, slice slice)
>+ 	     | AssignName(identifier id)
>+ 	     | AssignList(expr* elts) | AssignTuple(expr *elts)

I think that should be:

>+ 	     | AssignList(assign* elts) | AssignTuple(assign *elts)


And I don't like this change one single bit. Yes sure, it looks prettier
than using Lvalue and it captures useful information, but it makes a
one-pass AST builder a lot harder to do. You probably don't care because
you have an intermediate parse tree with all the context needed to know
if you must create a Name node or a AssignName node. When my parser
detect a name, I have no way of knowing if an equal sign will turn up
later. So I'll have to pick one node type (like Name) and rebuild that
part of the tree later if it turned out that it was part of an
assignment or deletion. Ugly.

As I have said before, I think the desire for correct typing in the tree
is overrated and I would rather remove the 'assign' sum altogether and
add a flag to the Attribute, Subscript, Name, List and Tuple nodes that
captured the use of the node (like 'Get', 'Set' and 'Del').

regards,
finn