Evaluator for a Simple Language with Hidden Type Variables and Conditional Extension

Here you can run our evaluator on some existing programs, or enter your own.

Try a "Canned" Example

Choose one of the examples below and click Go to see the result.

Write Your Own Program (see syntax description below)

Our language is a core fragment of the Fortress programming language. As such, all programs in this language are valid Fortress programs. Note that Fortress supports unicode characters. However, this evaluator does not. In particular, we use [\ and \] as the ASCII equivalent of white square brackets.

For questions and comments, and to report problems, please contact jhallett at cs dot bu dot edu.

Syntax

The terminals of the syntax grammar are either variables or keywords.
We use x, m, X, T, and O as variables.
We use self, trait, object, extends, bounds, where, end, as, typecase, in, else, and Object as keywords.

We use empty as the empty string.

We place * around parts of the syntax that are optional.


The syntax grammar follows:
p := ds e  (program)

d := td 
   | od

ds := empty 
    | d ds

td := trait T *tps* *extends supers* *where htvs* mds end  (trait declaration)

od := object O *tps* *vps* *extends supers* *where htvs* mds end  (object declaration)

tps := [\ bnds \]  (type parameters)

vps := [\ params \]  (value parameters)

supers := { exts }  (supertypes)

htvs := { bnds }  (hidden type variables)

bnds := empty
      | X extends A        (upper bound)
      | X bounds A         (lower bound)
      | X extends A, bnds
      | X bounds A, bnds 

params := empty
        | x : A
        | x : A, params

exts := empty
      | M *where htvs*
      | M *where htvs*, exts

md := m *tps* vps : A = e  (method declaration)

mds := empty
     | md mds

e := x                                        (program variable)
   | self                                     (self reference)
   | O *[\ As \]* ( es )                      (object instance)
   | e.x                                      (field access)
   | e.m *[\ As \]* ( es )                    (method call)
   | e as A                                   (type ascription)
   | typecase x = e of cases else => e end    (typecase)

es := empty
    | e
    | e, es

A := X          (type variable)
   | O [\ A \]  (object type)
   | M

As := empty
    | A
    | A, As

M := T [\ As \]  (trait type)
   | Object      (type of object)

cases := empty
       | A => e
       | A => e, cases