Objects in Space

As we all know, Firefly is one of the examples of episodic sci-fi writing ever. When I say "As we all know," it's kinda like "so say we all," except that's some other sci-fi show. No, you just have to agree. Best not to argue.

firefly_objects_in_spaceThe last episode in the series was called Objects in Space. There are a number of entertaining (and maddeningly unresolved) aspects to the episode. Here, the only thing that matters, really, is that the title contains the word objects, and the final laboratory in CMPSC220 has to do with implementing classes and objects in your interpreter.


This is very fortunate. Up until now, we have been working with languages called things like AE, WAE, and CFWAE. With this laboratory, we add References and Objects. As a result, our new language is called... FEARCOW

Finally, a language we can be proud of implementing. 

Starting Points

The starting point for this work is the extended interpreter. If you have not completed the extended interpreter, fear not. The starter code includes a complete, compiled version of this interpreter, and you only need to focus on the object-oriented portion of the lab.

Download this zip file and decompress it. (It will create a directory called lab6-single.) In that directory, open up lab6.ss, and you should be able to get started.

What to Do?

The file lab6.ss should be largely self-explanatory. If you are implementing single bindings (a good starting point), you should follow the grammar given below for single bindings/single fields/single methods. Completing this, in addition to all the normal rules for a good laboratory (testing all your functions, extending the given test suite appropriately, etc.) is good for a B.

If you go on to multiple fields/multiple methods/multiple arguments in methods in class definitions, the lab is worth an A in your final portfolio.

(A starter file will be provided for multiple fields/etc., but is not up as of March 25th. In short, you can get an A on this laboratory without having implemented multiples in the previous laboratory.)

If this all seems brief, it is because I'm sleep deprived. Also, don't forget that the lectures from this week are available online (Monday and Wednesday).

Single field/method grammar

The grammar (BNF) for single-field and single-method classes is given below:

<FEARCOW> ::= <num>
    | {+ <FEARCOW> <FEARCOW>}
    | {- <FEARCOW> <FEARCOW>}
    | {* <FEARCOW> <FEARCOW>}
    | {/ <FEARCOW> <FEARCOW>}
    | <id>
    | {if0 <FEARCOW> <FEARCOW> <FEARCOW>}
    | {with {<id> <FEARCOW>} <FEARCOW>}
    | {fun {<id>} <FEARCOW>}
    | {<FEARCOW> <FEARCOW>}
    ;; ADDED BY THE PROF
    | {seq <FEARCOW> ...}
    | {change <id> <FEARCOW>}
    ;; FOR YOUR ENJOYMENT
    | {blueprint {field {<id> <FEARCOW>}} {method {<id> <FEARCOW>}}}
    | {create <id>}
    | {invoke <id> <id> <FEARCOW>}
where an id is not +, -, *, /, with, if0, fun,
                   blueprint, create, or invoke.