COSC 152 Programming Languages

Fall 2007

Homework Assignment #10

Objects
Due: Friday, Dec 07, 12:00PM CST
Submit: E-mail electronic copy to professor, with a subject header "COSC 152 HW#10".
Work may be completed in pairs. Each team should submit only once. Be certain to put both team member names on work submitted. It would be courteous to carbon-copy your partner when e-mailing the final submission.

The Grammar

This assignment is largely the grammar from HW #8, plus forms similar to Figure 5.7 on page 180 in EoPL.

The total grammar, in summary, should be:

<program>    ::=    { <class-decl> }* <statement>
<class-decl>    ::=    class <identifier> extends < identifier> { { field <identifier> ; }* { <method-decl> }* }
<method-decl>    ::=    method <identifier> ( { <identifier> }*(,) ) { { <statement> ; }* return <expression > ; }
<statement>    ::=    <identifier> = < expression>
   |    print <expression>
   |    {{<statement>}*(;) }
   |    if <expression> < statement> else <statement>
   |    while <expression> <statement>
   |    var <identifier> = <expression> ; <statement>
<expr>    ::=    <number>
   |    <identifier>
   |    <boolean>
   |    new <identifier> ( { <expression> }*(,) )
   |    send <expression> . < identifier> ( { <expression> }*(,) )
   |    super . < identifier> ( { <expression> }*(,) )
   |    ( lambda ( {<identifier>}* ) <expr> )
   |    ( if <expr> <expr> <expr> )
   |    ( cond { ( <expr> <expr> ) }* ( else <expr> ) )
   |    ( let ( { ( <id> <expr> ) }* ) <expr> )
   |    ( let* ( { ( <id> <expr> ) }* ) <expr> )
   |    ( letrec ( { ( <id> ( lambda ( { <id> }* ) <expr> ) }* ) <expr> )
   |    ( <expression> { <expression>}* )

With primitive operators add, sub, mul, div, mod, cons, car, cdr, list, empty-list, empty?, equal, lesser, greater, and, or, xor.

Interpreter

Modify your existing parse and execute functions to handle programs in the new language.

Notes:

  • We will not be implementing type checking for this language, although I encourage you to consider what it would entail (EoPL Ch 6.)
  • Most of the code required for this project is outlined in section 5.4.1 of EoPL, the "Simple Implementation".
  • All of your existing testcases from previous phases of the interpreter should work in this new interpreter, with the exception of the statements "proc" and "call", which have been removed for simplicity.
  • Examples of object-oriented test cases are given throughout EoPL Chapter 5, and all of these should work with only slight modifications. (Our langauge has a little more of a Java feel to it.) As an example, Figure 5.2 (EoPL p. 173) looks like this in our variant.
  • The behavior of our language is as described in the text. We are implementing single-inheritance, single dynamic dispatch, subclass polymorphism. Methods can be overridden in child classes, and fields are to be shadowed.
  • The top of the inheritance chain is a default class, "object", methods bodies have an object pointer "self" in scope, and all classes are assumed to implement a method "initialize" that is called when new objects are allocated. Our grammar enforces that all methods end with a return statement, so any method without a meaningful return value should simply return a dummy expression, like 0.

  • Back
    [Revised 2007 Nov 29 19:35 DWB]