Title: Refill a generative java dialect
1Refill a generative java dialect
- Kasper Østerbye
- IT University Copenhagen
2Goals of refill project
- Goal of this project is to provide a framework
for language extension - Add new language constructs
- add new sub/embedded languages
- extend/change existing name binding rules
- extend static type checking mechanism
- extend compile time semantics
- change the code generation
- transform the new constructs into base language
- multi-target compilation
- Focus on two aspects of this
- Achieving the functionality to do the above
- Specification style matters
3An extensible Java
- There are two parties to a language extension,
the language extender, and the language user. - The language user is assumed to have knowledge of
the base programming language, and knowledge on
the domain of the language extension. - The language extender is assumed to be an expert
in the base language, and expert in the domain of
the language extension. - but not necessarily an expert in compiler
construction
import mycontrolstructures.ForEach import
java.util.Vector class Test Vector employees
new Vector() public void printAllEmplees()
foreach Person p in employees
System.out.println(p.name
p.address)
4Defining foreach, syntax and name binding
- package controlstructures
- import refill.java.Statement
- import refill.java. NameAppl
- import refill.java. NameDecl
- class ForEach extends Statement
- // foreach Person p in collection do statement
- syntax "foreach" NameAppl type NameDecl element
"in" NameAppl col "do" Statement stmt
Environment binding(Environment e) // create
a new environment based in e. Environment newE
e.extendEmpty() type.findFrom(e) newE.bind
(element, type) stmt.binding(newE) col.bindF
rom(e) return e
5Static semantics
- void check()
- if (! col.isBound() )
- check.error(col, col.name
- " is not defined, or is misspelled")
- if ( !type.isKindOf(Collection) )
- check.error(col, col.name
- " should be a Collection")
- stmt.check()
-
-
6Transformation
- void transform()
- // Person p Iterator i col.iterator()
- // while (i.hasNext() )
- // p (Person)i.next()
- // stmt
- //
- String iteratorID newIdentifier()
- Statement substitution new Block(
- " " type " " element " Iterator "
- iteratorID " " col ".iterator()\n"
- "while (" iteratorID ".hasNext() )\n"
- element " (" type ")" iteratorID
".next()\n" - stmt ""
- this.replace(substitution)
-
7Issues further directions
- How to extend with sub-languages rather than
single constructs - How to make sure that sub-languages do not
interfere - Better ways to specify transformations
- Get it all implemented
- Find the formal limitations of how to add new
constructs to the language with the present
algorithm.