




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Syntax:
P ::= CL e program CL ::= class C extends C {C f ; K m} class definition K ::= C (C f ){super (f ); this.f = f ; } constructor M ::= C m(C x){return e; } method e ::= expressions x variables e.f field access e.m(e) method invocation new C (e) object creation (C )e cast
Notes: C is for class names, m is for method names, and f is for field names. This syntax is literally a subset of Java. A Featherweight Java program can be run by a standard Java interpreter.
CT (C ) = class C extends D{.. .} C <: D
mtype(m, C) = let CT(C) = class C extends D {C f ; K M} if B m(B x){return e; } โ M then return B โ B else return mtype(m, D)
override(m,D,C โ C 0 ) = if mtype(m,D) = D โ D 0 then return C = D and C 0 = D 0 else return true
Values: v ::= new C (v )
Evaluation contexts: E ::= [] | E .f | E .m(e) | v .m(v , E , e) | new C (v , E , e) | (C )E
Reduction rules:
(E-Proj)
fields(C ) = C f new C (v ).fi โโ vi
(E-Invk)
mbody (m, C ) = (x, e) (new C (v )).m(u) โโ [x 7 โ u, this 7 โ new C (v )]e
(E-Cast) C^ <:^ D (D)(new C (v )) โโ new C (v )
M OK in C
x : C , this : C ` e : Ce Ce <: Cr CT (C ) = class C extends D{.. .} override(m, D, C โ Cr ) Cr m(C x){return e; } OK in C
C OK
K = C (D g , C f ){super (g ); this.f = f ; } fields(D) = D g M OK in C class C extends D{C f ; K M} OK
If ฮ e : C and e 7 โโ eโฒ^ then ฮ eโฒ^ : C โฒ^ for some D where C โฒ^ <: C.
A bad cast is an expression of the form (C )(new D(v )) where D 6 <: C.
Suppose e is closed, well-typed, and in normal form. Then either e is a value or there is an evaluation context E such that e = E [b] where b is a bad cast.