This page is an accumulation of (we hope) helpful notes, hints, etc., that might be useful to you in doing Project #3.
a[i] += 3
That is, there is no rewrite corresponding to the conversion of
a[i] = 3 => __setitem__ (a, i, 3)
SO: assume (don't bother to check) that all augmented assignments have the form
<simple variable or selection> = <expr>
That is, no indexing or slices on the left-hand side of an augmented assignment (tuples on the left-hand side are already illegal).
Given the node
(aug_assign (id ... "__...__" ) LHS RHS)just decorate the first child (the id node) as if this were
(call (id ... "__...__") [ LHS RHS ])
A ()
and render it as an ordinary call in which the "function" is the type A and the type of A() is A (i.e., (type (id .... "A"))). Likewise, don't do anything special with __init__ for this project (treat as an ordinary def).
The intent was that in a definition like this:
class A (Object): x = 3 y = x + 2 # OK def g (self): return x*2 # ILLEGAL: should be self.x for the # instance variable, or A.x for the # class variable.with the way I've set up the suggested skeleton, this can be a bit awkward to get right.
SO: we won't test uses of unqualified members of classes (e.g., as in x + 2 or x*2 above). You have to handle selection of members (e.g., self.x) and definitions of members (e.g., x = 3), but not uses of the simple identifiers. Operationally, this means that you do the addSimpleDecls pass after having done gatherMembers, and that during addSimpleDecls on the class A, you don't have to add anything to the symbol table from the statements in A's bodies (just when you process the body of a method). It's not terribly difficult to do it right, and you're welcome to get it right if you want, but don't expect cases such as the commented lines above to be tested.
Q: Is "x = 3" a declaration (such that x is declared as of type Any)?
A: Yes, except in situations where x is already declared. For example, only one x is declared in
def f (): x = 3 x = x+y # Same xor in
x = 3 def f (): global x x = 42 # NOT a new x.or in
def f (x): x = 42 # Same as parameter x.
Q: By my understanding i:T does not get populated into the symbol table—it is there for the type checking phase of the semantic analyzer.
A: Well, you can use the symbol table as you like, but in my suggested outline, you are correct that one does not need to put this i into the symbol table: it will have been decorated with the appropriate decl elsewhere and you simply have to update the static type on that decl when you do the typing pass.
Q: In the prelude there were these two lines
None: Void def None = Void.__None__ ()now would this be declaring the symbol "None" twice and thus cause an error when populating the symbol table?
A: No. Type declarations do not define symbols. For example, the program consisting solely of
Foo: Intis illegal, since Foo is not defined.
[CS164 Homework]   [CS164 Home Page]
Page was last modified on Thu Nov 9 19:23:57 2006.