CS558 Homework #8
Due 4:00 PM, Tuesday, March 11, 2014

Homework must be submitted via D2L. All submitted files (2 for this assignment sol8A.e8 and sol8B.e8) must be submitted in the appropriate D2L directory in the drop box HW8. It is your responsibility to submit the homework in the proper format with the proper names.

All programs mentioned can be downloaded from the this document

In this homework we consider a variant of simple un typed object oriented language we call E8. The language, E8, has the following features:

  1. First class objects which implement encapsulation. Every object is solely characterized by the requests it can respond to.
  2. Inheritance. Objects can inherit behavior from other objects.
  3. Dynamic binding. The binding of behaviors to an object is done dynamically at run time.
  4. Naming. The language separates the naming of things from the encapsulation of things in objects.
  5. A simple exception system, along the lines of Homework4
  6. he use of dynamic typing. Typing issues are checked at run time

E8's concretized abstract syntax is given by the following grammar:

prog := { decl }  'init' exp

decl := '(' 'val' exp ')'                                -- a variable
      | '(' 'ref' [ exp ] ')'                            -- mutable variable
      | '(' 'fun' '(' {var } ')' exp ')'                 -- function
      | '(' { 'left' | 'right' | 'non' } operator ')'    -- associativity of operator

field := '(' 'def' exp ')'                               -- a constant field
      |  '(' 'var' [ exp ] ')'                           -- a mutable field
      |  '(' 'method' '(' {var } ')' exp ')'             -- a method

exp :=
  var
| int
| bool
| string
|
| '(' 'local' { decl } exp ')'         -- Binding or naming mechanism
| '(' 'write' string exp ')'           -- output
| '(' 'block' { exp } ')'              -- sequencing
| '(' ':=' var exp ')'                 -- assigment to mutable variables

| '(' object [ 'inherits' exp ] { field } [ 'init' exp ] '}'  -- object construtction
| '(' exp '.' fieldselection { exp } ')'                      -- message request
| 'self'                                                      -- the current ject
| 'done'                                                      -- the unit object
| 'super'                                                     -- the super class of the current object
| '(' 'return'  var exp ')'                                   -- An exception, non-standard return from a method.

| '(' 'if' exp exp exp ')'
| '(' 'while' exp exp ')'
| '(' '@' exp { exp } ')'            -- function application
| '(' '\' '(' { var } ')' exp ')'    -- lambda abstraction
| '(' operator { exp } ')'           -- associative "infix" operators application
| '[]'                               -- the object with no behaviors


fieldselection := var | '(' var { exp } ')'

var := letter { letter | digit }
operator = ["+*-/!@#$%^&~=?<>:]+     -- a sequence of these operator characters

As before, comments may be included by enclosing them between '{' and '}' characters, and they may be nested.

Note that the syntax for expressions has been divided into groups, where each group supports one aspect of the language.

A sample file, which illustrates many of E8's features can be found here test1.e8. This file illustrates several key points of the language