Project #3 Notes, Fall 2006 (updated 5 Nov 2006)

This page is an accumulation of (we hope) helpful notes, hints, etc., that might be useful to you in doing Project #3.

  1. Changes in project specifications
  2. Answers to some questions


Changes or clarifications in project specifications

  1. We didn't say what to do with constructors. Handle the parameterless case only:
            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).

  2. The type of `E0 and E1' and of `E0 or E1' ought to be the least upper bound of the operands' types (say T0 and T1), as indicated in the lecture segment on typing the conditional (if-then-else) expression. However, that answer is going to cause a lot of grief (consider function types), so I'll test only a simpler alternative: if T0 is a subtype of T1, the type of either the "and" or "or" operation is T1; if T1 is a subtype of T0, then it is T0; and otherwise it is Any.
  3. You should rewrite the setselect analogously to select when selecting from a type. That is,
           (setselect (id I) T E)
    
    becomes simply
           (assign (id I) E)
    
  4. We've updated the Pyth manual's discussion of the special cases involving calls, as follows:
    [For a call f(a1,...,an)]:

    A. When f is a simple identifier (i.e, no dots), there is no definition of f in scope, n>=1, and there is an instance method of a1 named f, then the function that is called is (a1).f. So, if foo is not otherwise defined, foo(x) becomes ((x).foo)(x), but rewrite rule B, below is {\it not subsequently applied.

    B. When f is a selection of the form E.g, E is a value (not a type), and g is defined as an instance method..., a copy of the value of E is inserted as the first parameter of g. That is, E.g. (a1,\dots,an) becomes in effect (E.g)(E,a1,\dots,an), where E is evaluated only once. This rewrite rule applies at most once (so as not to cause an infinite regress).

  5. The specific contexts requiring "coerce" nodes are as follows:
  6. A "for" statement implicitly assigns to, and therefore declares, its control variable, as suggested by the functionally equivalent "while" statement given in the Pyth manual. Thus
        for x in L:
           ...
    
    assigns to "x", and should count as a declaration, just like an assignment statement.
  7. Although the standard prelude lists the superclass of Any as Any (as stated in the project handout), it actually has no superclass, so please set its superclass to null internally so that its decl shows "0" as the parent class.
  8. Compare nodes should have type "Bool".
  9. The "global" declaration applies only to assignable variables, so something like
       def a = 3
       def f (x):
           global a
    
    is illegal.

Answers to some questions

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 x
or 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: Int
is illegal, since Foo is not defined.

Q: What are the "members of a class" that should be listed in classdecls? A: All instance variables, constants, defs, and class defs in the body of the class (not including inherited ones).

Q: The pretest wouldn't work until I had manually set SemanticTest (and ParsePyth) to be executable. Should I have to do that, am I doing something wrong?

A: You must have done something wrong at some point. When you "svn co" or "svn copy" the skeleton, these files are marked executable. I presume that what happened is that you entered these files in the first place by copying them without their executable bits and then svn adding them (or by some means other than svn copy).

To correct the situation, first chmod them to be executable in your working directory:

        chmod u+rx ParsePyth SemanticTest
and then inform Subversion:
        svn propset svn:executable "*" ParsePyth SemanticTest
        svn commit

This last step is unnecessary when (1) the files are executable when you first svn add them, or (2) you check out or copy files that have the executable property.

[CS164 Homework]    [CS164 Home Page]

Page was last modified on Sun Mar 30 15:43:15 2008.
Address comments and questions to cs164@eecs.berkeley.edu