CS558 Homework #8
Due 8:00 AM, Monday, March 07, 2016

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. For example include a comment at the very top with your name and email address.

-- Homework 7  Tom Smith   tom_smith@gmail.com

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. The 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' id exp ')'                            -- a named value (immutable variable)
      | '(' 'ref' id [ exp ] ')'                        -- mutable variable
      | '(' 'fun' id '(' {id } ')' exp ')'              -- function
      | '(' { 'left' | 'right' | 'non' } operator ')'   -- associativity of operator

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

exp :=
  id
| int
| bool
| string
|
| '(' 'local' { decl } exp ')'        -- Binding or naming mechanism
| '(' 'write' string exp ')'          -- output
| '(' 'block' { exp } ')'             -- sequencing
| '(' ':=' id 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'  id exp ')'                                    -- An exception, non-standard return from a method.

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


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

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

As before, comments may be included by enclosing them between comment braces '{-' and '-}', 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