This page provides access to our implementation files for a simple functional OO Java-like language, FOOP. The implementation uses DemeterF and is described with respect to traversals in our OOPSLA 2008 submission.The FOOP example shown in the paper is factorial:
Another more complicated example is a mini functional expression "interpreter":class F{ F(){ } int fact(int i){ return if (i < 2) then 1 else i * this.fact(i + -1); } } new F().fact(7) // ==> 5040class B{ boolean b; B(boolean a){ b = a; } boolean toBool(){ return b; } B and(B a){ return new B(b && a.toBool()); } B or(B a){ return new B( if(b) then true else if(a.toBool()) then true else false ); } B not(){ return new B( if(b) then false else true ); } } class I{ int i; I(int j){ i = j; } int toInt(){ return i; } I incr(){ return this.add(new I(1)); } I add(I j){ return new I(i+j.toInt()); } B less(I j){ return new B(i < j.toInt()); } B equal(I j){ return new B( if(i < j.toInt()) then false else if(j.toInt() < i) then false else true ); } } (((new I(5).add(new I(14))).add(new I(-6))).less(new I(15))).not()).toBool() // ==> false
The files listed below make up the entire type checker and interpreter for FOOP. DemeterJ is used (the program.* files) to generate data structures and a parser. The Java files are DemeterF based traversal classes that transform the parse tree and type check and evaluate FOOP programs.
Eval.java is the most important file; containing a series of evaluators for various features of the language. Because DemeterF traversals are dynamic, we tested the evaluators iteratively adding methods to the classes to support each feature.