Translation of a Subset of RSL into Java
Ulrik Hjarnaa Supervisors:
Anne Elisabeth Haxthausen (DTU)
Hans Bruun (DTU)
Computer Science and Engineering Informatics and Mathematical Modelling
Technical University of Denmark
Translation of a Subset of RSL into Java – p.1/35
Agenda
◆ Introduction & objectives
◆ Translation of RSL into Java
n Discussion of specific constructs
n Discussion of generel issues
◆ Process of developing a translator
n Design of a translator
n Development process
n Implementation & test
◆ Conclusion
Translation of a Subset of RSL into Java – p.2/35
Agenda
◆ Introduction & objectives
◆ Translation of RSL into Java
n Discussion of specific constructs
n Discussion of generel issues
◆ Process of developing a translator
n Design of a translator
n Development process
n Implementation & test
◆ Conclusion
Translation of a Subset of RSL into Java – p.3/35
Introduction
◆ There exists a number of formal methods for designing and specifying software
◆ There exists a number of programming languages for implementing software
◆ Typically a step of a formal method for software development is implementing a specification in the accompanying notation in a programming language
◆ Parts of a speficication language is implemented in the same way in a programming language
◆ This work focusses on:
n The specification language RSL which is part of RAISE
n The programming language Java
Translation of a Subset of RSL into Java – p.4/35
Introduction
◆ There exists a number of formal methods for designing and specifying software
◆ There exists a number of programming languages for implementing software
◆ Typically a step of a formal method for software development is implementing a specification in the accompanying notation in a programming language
◆ Parts of a speficication language is implemented in the same way in a programming language
◆ This work focusses on:
n The specification language RSL which is part of RAISE
n The programming language Java
Translation of a Subset of RSL into Java – p.4/35
Introduction
◆ There exists a number of formal methods for designing and specifying software
◆ There exists a number of programming languages for implementing software
◆ Typically a step of a formal method for software development is implementing a specification in the accompanying notation in a programming language
◆ Parts of a speficication language is implemented in the same way in a programming language
◆ This work focusses on:
n The specification language RSL which is part of RAISE
n The programming language Java
Translation of a Subset of RSL into Java – p.4/35
Introduction
◆ There exists a number of formal methods for designing and specifying software
◆ There exists a number of programming languages for implementing software
◆ Typically a step of a formal method for software development is implementing a specification in the accompanying notation in a programming language
◆ Parts of a speficication language is implemented in the same way in a programming language
◆ This work focusses on:
n The specification language RSL which is part of RAISE
n The programming language Java
Translation of a Subset of RSL into Java – p.4/35
Introduction
◆ There exists a number of formal methods for designing and specifying software
◆ There exists a number of programming languages for implementing software
◆ Typically a step of a formal method for software development is implementing a specification in the accompanying notation in a programming language
◆ Parts of a speficication language is implemented in the same way in a programming language
◆ This work focusses on:
n The specification language RSL which is part of RAISE
n The programming language Java
Translation of a Subset of RSL into Java – p.4/35
Introduction
◆ There exists a number of formal methods for designing and specifying software
◆ There exists a number of programming languages for implementing software
◆ Typically a step of a formal method for software development is implementing a specification in the accompanying notation in a programming language
◆ Parts of a speficication language is implemented in the same way in a programming language
◆ This work focusses on:
n The specification language RSL which is part of RAISE
n The programming language Java
Translation of a Subset of RSL into Java – p.4/35
Introduction
◆ There exists a number of formal methods for designing and specifying software
◆ There exists a number of programming languages for implementing software
◆ Typically a step of a formal method for software development is implementing a specification in the accompanying notation in a programming language
◆ Parts of a speficication language is implemented in the same way in a programming language
◆ This work focusses on:
n The specification language RSL which is part of RAISE
n The programming language Java
Translation of a Subset of RSL into Java – p.4/35
Objectives
Objectives:
◆ Define a translation of subset of RSL into Java
◆ Develop a tool for translating a subset of RSL into Java, (translator)
Requirements of translation:
◆ The translation from RSL into Java must be semantically equivalent to the specification in RSL
◆ In the Java translated from the specification it should be possible to recognize the specification
Requirements of translator:
◆ The translator must translate a subset of RSL into Java according to the translation defined
◆ The translator must provide extensibility
Translation of a Subset of RSL into Java – p.5/35
Objectives
Objectives:
◆ Define a translation of subset of RSL into Java
◆ Develop a tool for translating a subset of RSL into Java, (translator)
Requirements of translation:
◆ The translation from RSL into Java must be semantically equivalent to the specification in RSL
◆ In the Java translated from the specification it should be possible to recognize the specification
Requirements of translator:
◆ The translator must translate a subset of RSL into Java according to the translation defined
◆ The translator must provide extensibility
Translation of a Subset of RSL into Java – p.5/35
Objectives
Objectives:
◆ Define a translation of subset of RSL into Java
◆ Develop a tool for translating a subset of RSL into Java, (translator)
Requirements of translation:
◆ The translation from RSL into Java must be semantically equivalent to the specification in RSL
◆ In the Java translated from the specification it should be possible to recognize the specification
Requirements of translator:
◆ The translator must translate a subset of RSL into Java according to the translation defined
◆ The translator must provide extensibility
Translation of a Subset of RSL into Java – p.5/35
Objectives
Objectives:
◆ Define a translation of subset of RSL into Java
◆ Develop a tool for translating a subset of RSL into Java, (translator)
Requirements of translation:
◆ The translation from RSL into Java must be semantically equivalent to the specification in RSL
◆ In the Java translated from the specification it should be possible to recognize the specification
Requirements of translator:
◆ The translator must translate a subset of RSL into Java according to the translation defined
◆ The translator must provide extensibility
Translation of a Subset of RSL into Java – p.5/35
Objectives
Objectives:
◆ Define a translation of subset of RSL into Java
◆ Develop a tool for translating a subset of RSL into Java, (translator)
Requirements of translation:
◆ The translation from RSL into Java must be semantically equivalent to the specification in RSL
◆ In the Java translated from the specification it should be possible to recognize the specification
Requirements of translator:
◆ The translator must translate a subset of RSL into Java according to the translation defined
◆ The translator must provide extensibility
Translation of a Subset of RSL into Java – p.5/35
Objectives
Objectives:
◆ Define a translation of subset of RSL into Java
◆ Develop a tool for translating a subset of RSL into Java, (translator)
Requirements of translation:
◆ The translation from RSL into Java must be semantically equivalent to the specification in RSL
◆ In the Java translated from the specification it should be possible to recognize the specification
Requirements of translator:
◆ The translator must translate a subset of RSL into Java according to the translation defined
◆ The translator must provide extensibility
Translation of a Subset of RSL into Java – p.5/35
Objectives
Objectives:
◆ Define a translation of subset of RSL into Java
◆ Develop a tool for translating a subset of RSL into Java, (translator)
Requirements of translation:
◆ The translation from RSL into Java must be semantically equivalent to the specification in RSL
◆ In the Java translated from the specification it should be possible to recognize the specification
Requirements of translator:
◆ The translator must translate a subset of RSL into Java according to the translation defined
◆ The translator must provide extensibility
Translation of a Subset of RSL into Java – p.5/35
Objectives
Objectives:
◆ Define a translation of subset of RSL into Java
◆ Develop a tool for translating a subset of RSL into Java, (translator)
Requirements of translation:
◆ The translation from RSL into Java must be semantically equivalent to the specification in RSL
◆ In the Java translated from the specification it should be possible to recognize the specification
Requirements of translator:
◆ The translator must translate a subset of RSL into Java according to the translation defined
◆ The translator must provide extensibility
Translation of a Subset of RSL into Java – p.5/35
Objectives
Objectives:
◆ Define a translation of subset of RSL into Java
◆ Develop a tool for translating a subset of RSL into Java, (translator)
Requirements of translation:
◆ The translation from RSL into Java must be semantically equivalent to the specification in RSL
◆ In the Java translated from the specification it should be possible to recognize the specification
Requirements of translator:
◆ The translator must translate a subset of RSL into Java according to the translation defined
◆ The translator must provide extensibility
Translation of a Subset of RSL into Java – p.5/35
Agenda
◆ Introduction
◆ Translation of RSL into Java
n Discussion of specific constructs
n Discussion of generel issues
◆ Process of developing a translator
n Design of translator
n Development process
n Implementation & test
◆ Conclusion
Translation of a Subset of RSL into Java – p.6/35
Translation of RSL into Java
◆ Translation of types & type definitions
◆ Translation of value expressions & value definitions Types & type definitions:
◆ Translation of built–in types
◆ Translation of complex types
◆ Translation of type definitions
Translation of a Subset of RSL into Java – p.7/35
Translation of RSL into Java
◆ Translation of types & type definitions
◆ Translation of value expressions & value definitions Types & type definitions:
◆ Translation of built–in types
◆ Translation of complex types
◆ Translation of type definitions
Translation of a Subset of RSL into Java – p.7/35
Built–in types
◆ The built–in types are: Bool, Nat, Int, Real, Char, Text
◆ These built–in types must be represented in some way in Java
◆ Two possibilities were considered:
n Primitive types and library classes in Java
n A collection of classes implemented RSL Java
Bool boolean or Boolean Int int or Integer
Nat No translation.
Real double or Double Char char or Character
Text String
Translation of a Subset of RSL into Java – p.8/35
Built–in types
◆ The built–in types are: Bool, Nat, Int, Real, Char, Text
◆ These built–in types must be represented in some way in Java
◆ Two possibilities were considered:
n Primitive types and library classes in Java
n A collection of classes implemented RSL Java
Bool boolean or Boolean Int int or Integer
Nat No translation.
Real double or Double Char char or Character
Text String
Translation of a Subset of RSL into Java – p.8/35
Built–in types
◆ The built–in types are: Bool, Nat, Int, Real, Char, Text
◆ These built–in types must be represented in some way in Java
◆ Two possibilities were considered:
n Primitive types and library classes in Java
n A collection of classes implemented RSL Java
Bool boolean or Boolean Int int or Integer
Nat No translation.
Real double or Double Char char or Character
Text String
Translation of a Subset of RSL into Java – p.8/35
Built–in types
◆ The built–in types are: Bool, Nat, Int, Real, Char, Text
◆ These built–in types must be represented in some way in Java
◆ Two possibilities were considered:
n Primitive types and library classes in Java
n A collection of classes implemented RSL Java
Bool boolean or Boolean Int int or Integer
Nat No translation.
Real double or Double Char char or Character
Text String
Translation of a Subset of RSL into Java – p.8/35
Built–in types
◆ The built–in types are: Bool, Nat, Int, Real, Char, Text
◆ These built–in types must be represented in some way in Java
◆ Two possibilities were considered:
n Primitive types and library classes in Java
n A collection of classes implemented RSL Java
Bool boolean or Boolean Int int or Integer
Nat No translation.
Real double or Double Char char or Character
Text String
Translation of a Subset of RSL into Java – p.8/35
Built–in types
◆ The built–in types are: Bool, Nat, Int, Real, Char, Text
◆ These built–in types must be represented in some way in Java
◆ Two possibilities were considered:
n Primitive types and library classes in Java
n A collection of classes implemented RSL Java
Bool boolean or Boolean Int int or Integer
Nat No translation.
Real double or Double Char char or Character
Text String
Translation of a Subset of RSL into Java – p.8/35
Complex types
◆ The complex types considered here are: list, set, and map
◆ These types may in RSL be of infinite size and non–deterministic
◆ In Java there exists a number of interfaces and classes for representing: Lists, sets and maps
◆ To represent the RSL lists, sets, maps in Java a number of interfaces and classes has been implemented
RSL Java
t? RSLListDefault<T>, where T is the translation of t t-set RSLSetDefault<T>, where T is the translation of t.
t1 →m t2 RSLMapDefault<T1 , T2>, where T1 is the translation of t1 and T2 is the translation of t2.
Translation of a Subset of RSL into Java – p.9/35
Complex types
◆ The complex types considered here are: list, set, and map
◆ These types may in RSL be of infinite size and non–deterministic
◆ In Java there exists a number of interfaces and classes for representing: Lists, sets and maps
◆ To represent the RSL lists, sets, maps in Java a number of interfaces and classes has been implemented
RSL Java
t? RSLListDefault<T>, where T is the translation of t t-set RSLSetDefault<T>, where T is the translation of t.
t1 →m t2 RSLMapDefault<T1 , T2>, where T1 is the translation of t1 and T2 is the translation of t2.
Translation of a Subset of RSL into Java – p.9/35
Complex types
◆ The complex types considered here are: list, set, and map
◆ These types may in RSL be of infinite size and non–deterministic
◆ In Java there exists a number of interfaces and classes for representing: Lists, sets and maps
◆ To represent the RSL lists, sets, maps in Java a number of interfaces and classes has been implemented
RSL Java
t? RSLListDefault<T>, where T is the translation of t t-set RSLSetDefault<T>, where T is the translation of t.
t1 →m t2 RSLMapDefault<T1 , T2>, where T1 is the translation of t1 and T2 is the translation of t2.
Translation of a Subset of RSL into Java – p.9/35
Complex types
◆ The complex types considered here are: list, set, and map
◆ These types may in RSL be of infinite size and non–deterministic
◆ In Java there exists a number of interfaces and classes for representing: Lists, sets and maps
◆ To represent the RSL lists, sets, maps in Java a number of interfaces and classes has been implemented
RSL Java
t? RSLListDefault<T>, where T is the translation of t t-set RSLSetDefault<T>, where T is the translation of t.
t1 →m t2 RSLMapDefault<T1 , T2>, where T1 is the translation of t1 and T2 is the translation of t2.
Translation of a Subset of RSL into Java – p.9/35
Complex types
◆ The complex types considered here are: list, set, and map
◆ These types may in RSL be of infinite size and non–deterministic
◆ In Java there exists a number of interfaces and classes for representing: Lists, sets and maps
◆ To represent the RSL lists, sets, maps in Java a number of interfaces and classes has been implemented
RSL Java
t? RSLListDefault<T>, where T is the translation of t t-set RSLSetDefault<T>, where T is the translation of t.
t1 →m t2 RSLMapDefault<T1 , T2>, where T1 is the translation of t1 and T2 is the translation of t2.
Translation of a Subset of RSL into Java – p.9/35
Type definition
◆ Type definitions in RSL is a way to create new types either abstract or based on existing or other defined types
◆ In Java there is only one way to create new types and that is through classes and interfaces
◆ Therefore translation of type definitions in RSL involve creation of one or more classes in Java
Translation of a Subset of RSL into Java – p.10/35
Type definition
◆ Type definitions in RSL is a way to create new types either abstract or based on existing or other defined types
◆ In Java there is only one way to create new types and that is through classes and interfaces
◆ Therefore translation of type definitions in RSL involve creation of one or more classes in Java
Translation of a Subset of RSL into Java – p.10/35
Type definition
◆ Type definitions in RSL is a way to create new types either abstract or based on existing or other defined types
◆ In Java there is only one way to create new types and that is through classes and interfaces
◆ Therefore translation of type definitions in RSL involve creation of one or more classes in Java
Translation of a Subset of RSL into Java – p.10/35
Variant definitions
RSL:
type t1 == a1 | . . .| an Java:
public abstract class T1 {
public abstract boolean equals ( Object o ) ; public abstract S t r i n g t o S t r i n g ( ) ;
}
public class A1 extends T1 { . . . } ...
public class An extends T1 { . . . }
Translation of a Subset of RSL into Java – p.11/35
Variant definitions, constant
RSL:
type t == a Java:
public class A extends T {
public boolean equals ( Object o ) { i f ( o instanceof A)
return true ; else
return false ; }
public S t r i n g t o S t r i n g ( ) { return "A" ;
} }
Translation of a Subset of RSL into Java – p.12/35
Variant definitions, record constructor, RSL
RSL:
type t = a(t2)
Translation of a Subset of RSL into Java – p.13/35
Variant definitions, record constructor, Java
public class A extends T { public T2 _v1 ;
public A ( T2 _v1 ) { this . _v1 = _v1 ; }
public boolean equals ( Object o ) { i f ( o instanceof A) {
i f ( ! _v1 . equals ( ( ( T2) o ) . _v1 ) ) { return false ;
}
return true ; }
return false ; }
public S t r i n g t o S t r i n g ( ) { return "A( " + _v1 + " ) " ; } }
Translation of a Subset of RSL into Java – p.14/35
Variant definitions, destructors and reconstructors
RSL:
type t1 == a(get_t : t2 ↔ replace_t), Java:
public class A extends T1 { private T2 _v1 ;
public A( T2 _v1 ) { this . _v1 = _v1 ; }
public T2 g e t _ t ( ) { return _v1 ;
}
public T1 r e p l a c e _ t ( T2 _n1 ) { return new A( _n1 ) ;
} }
Translation of a Subset of RSL into Java – p.15/35
Example of variant definition, RSL
typeCollection == empty | add(Elem, Collection), Elem
Translation of a Subset of RSL into Java – p.16/35
Example of variant definition, Java 1
public abstract class C o l l e c t i o n { public abstract S t r i n g t o S t r i n g ( ) ;
public abstract boolean equals ( Object o ) ; }
public class empty extends C o l l e c t i o n { public boolean equals ( Object o ) {
i f ( o instanceof empty ) return true ;
else
return false ; } ;
public S t r i n g t o S t r i n g ( ) { return " empty " ;
}
} Translation of a Subset of RSL into Java – p.17/35
Example of variant definition, Java 2
public class add extends C o l l e c t i o n { private Elem _v1 ;
private C o l l e c t i o n _v2 ;
public add ( Elem _v1 , C o l l e c t i o n _v2 ) { this . _v1 = _v1 ;
this . _v2 = _v2 ; }
Translation of a Subset of RSL into Java – p.18/35
Example of variant definition, Java 3
public boolean equals ( Object o ) { i f ( o instanceof empty ) {
i f ( ! ( this . _v1 . equals ( ( ( add ) o ) . _v1 ) ) ) { return false ;
}
i f ( ! ( this . _v2 . equals ( ( ( add ) o ) . _v1 ) ) ) { return false ;
}
return true ; }
return false ; }
/∗ t o S t r i n g method omitted ∗/ }
public class Elem { }
Translation of a Subset of RSL into Java – p.19/35
Translation of value definitions and value expressions
◆ RSL have value expressions, Java have expressions, statements, and blocks
◆ In Java blocks consist of a collection of statements
◆ In Java there is one statement, an expression statement, which wraps an expression as a statement
◆ If a block is needed but the translation of an RSL value expression is a Java expression. The Java expression can be wrapped in an expression statement which again can be wrapped in a block
◆ If an expression is needed but the translation of an RSL value expression is a Java statement. The translation of the RSL value expression is to put the Java statement into an auxiliary method and then insert an application expression of the auxiliary method in the translation
Translation of a Subset of RSL into Java – p.20/35
Translation of value definitions and value expressions
◆ RSL have value expressions, Java have expressions, statements, and blocks
◆ In Java blocks consist of a collection of statements
◆ In Java there is one statement, an expression statement, which wraps an expression as a statement
◆ If a block is needed but the translation of an RSL value expression is a Java expression. The Java expression can be wrapped in an expression statement which again can be wrapped in a block
◆ If an expression is needed but the translation of an RSL value expression is a Java statement. The translation of the RSL value expression is to put the Java statement into an auxiliary method and then insert an application expression of the auxiliary method in the translation
Translation of a Subset of RSL into Java – p.20/35
Translation of value definitions and value expressions
◆ RSL have value expressions, Java have expressions, statements, and blocks
◆ In Java blocks consist of a collection of statements
◆ In Java there is one statement, an expression statement, which wraps an expression as a statement
◆ If a block is needed but the translation of an RSL value expression is a Java expression. The Java expression can be wrapped in an expression statement which again can be wrapped in a block
◆ If an expression is needed but the translation of an RSL value expression is a Java statement. The translation of the RSL value expression is to put the Java statement into an auxiliary method and then insert an application expression of the auxiliary method in the translation
Translation of a Subset of RSL into Java – p.20/35
Translation of value definitions and value expressions
◆ RSL have value expressions, Java have expressions, statements, and blocks
◆ In Java blocks consist of a collection of statements
◆ In Java there is one statement, an expression statement, which wraps an expression as a statement
◆ If a block is needed but the translation of an RSL value expression is a Java expression. The Java expression can be wrapped in an expression statement which again can be wrapped in a block
◆ If an expression is needed but the translation of an RSL value expression is a Java statement. The translation of the RSL value expression is to put the Java statement into an auxiliary method and then insert an application expression of the auxiliary method in the translation
Translation of a Subset of RSL into Java – p.20/35
Translation of value definitions and value expressions
◆ RSL have value expressions, Java have expressions, statements, and blocks
◆ In Java blocks consist of a collection of statements
◆ In Java there is one statement, an expression statement, which wraps an expression as a statement
◆ If a block is needed but the translation of an RSL value expression is a Java expression. The Java expression can be wrapped in an expression statement which again can be wrapped in a block
◆ If an expression is needed but the translation of an RSL value expression is a Java statement. The translation of the RSL value expression is to put the Java statement into an auxiliary method and then insert an application expression of the auxiliary method in the translation
Translation of a Subset of RSL into Java – p.20/35
Explicit function definition
An explicit function definition has the form:
single_typing formal_function_application ≡
value_expression [pre_condition] Limitations:
◆ Only id applications are considered
◆ Pre conditions disallowed
◆ Product type expression are not allowed in the result description RSL:
id : type_expr1 × . . . × type_exprn → type_exprn+1 id(binding1,. . . ,bindingn) ≡ value_expr
Java:
public [ s t a t i c ] Tn+1 Id ( T1 b1 ,. . . ,Tn bn ) V
Translation of a Subset of RSL into Java – p.21/35
if–then–else expression
RSL:
if a then elseb
endc Java:
i f (A) { B
}
else { C }
Translation of a Subset of RSL into Java – p.22/35
Example of an explicit function definition, RSL
listSum : Int∗ → Int listSum(il) ≡
if il = hi then else0
hd il + listSum(tl il) end
Translation of a Subset of RSL into Java – p.23/35
Example of an explicit function definition, Java
public s t a t i c i n t listSum ( RSLList < Integer > i l ) { i n t _v0 = 0 ;
i f ( i l . equals (new RSLListDefault < Integer > ( ) ) ) { i n t _v1 = 0 ;
_v1 = 0 ; _v0 = _v1 }
else {
i n t _v1 = 0 ;
_v1 = i l . hd ( ) + listSum ( i l . t l ( ) ) ; _v0 = _v1
}
return _v0 ; }
Translation of a Subset of RSL into Java – p.24/35
Agenda
◆ Introduction
◆ Translation of RSL into Java
n Discussion of specific constructs
n Discussion of generel issues
◆ Process of developing a translator
n Design of Translator
n Development process
n Implementation & Test
◆ Conclusion
Translation of a Subset of RSL into Java – p.25/35
Developing a translator
◆ Complex task
◆ Decomposed into:
n Parsing the source language into a data structure which can be used in a program, a translator.
n Do the actual translation by creating a new data structure
n Unparsing the new data structure into the target language Modules:
◆ Front End
◆ Translation Module
◆ Back End
◆ Control Module
Translation of a Subset of RSL into Java – p.26/35
Developing a translator
◆ Complex task
◆ Decomposed into:
n Parsing the source language into a data structure which can be used in a program, a translator.
n Do the actual translation by creating a new data structure
n Unparsing the new data structure into the target language Modules:
◆ Front End
◆ Translation Module
◆ Back End
◆ Control Module
Translation of a Subset of RSL into Java – p.26/35
Front End
◆ Tool vs. not tool
◆ Developing a lexer and parser from scratch represent a complex task in itself
◆ A number of tools considered: Gentle, Lex & Yacc, SableCC, Javacc, and ANTLR
◆ ANTLR was chosen
Translation of a Subset of RSL into Java – p.27/35
Translation Module
The task of the translation module consist of two parts:
◆ Decorating the tree received from the front end
◆ Creating a new tree from the tree received The two task solved using two strategies:
◆ Decorating the tree is done using that the tree implements the visitor design pattern
◆ Creating the tree is done using a bootstrapping process.
Bootstrapping:
◆ Allows for incremental development
◆ Allows for expressing the module in RSL
Translation of a Subset of RSL into Java – p.28/35
Translation Module
The task of the translation module consist of two parts:
◆ Decorating the tree received from the front end
◆ Creating a new tree from the tree received The two task solved using two strategies:
◆ Decorating the tree is done using that the tree implements the visitor design pattern
◆ Creating the tree is done using a bootstrapping process.
Bootstrapping:
◆ Allows for incremental development
◆ Allows for expressing the module in RSL
Translation of a Subset of RSL into Java – p.28/35
Translation Module
The task of the translation module consist of two parts:
◆ Decorating the tree received from the front end
◆ Creating a new tree from the tree received The two task solved using two strategies:
◆ Decorating the tree is done using that the tree implements the visitor design pattern
◆ Creating the tree is done using a bootstrapping process.
Bootstrapping:
◆ Allows for incremental development
◆ Allows for expressing the module in RSL
Translation of a Subset of RSL into Java – p.28/35
Back End & Control Module
◆ The Back End is implemented using the visitor design pattern
◆ The Control Module is a module binding the other modules together
Translation of a Subset of RSL into Java – p.29/35
Modular design
Overview
BasicClass
Class LISTSUM.rsl
RSLParser RSLLexer
RSLAST
LISTSUM SchemeDef
Translator
JavaAST
LISTSUM
CompilationUnit
StringJavaVisitor LISTSUM.java
Translation of a Subset of RSL into Java – p.30/35
Bootstrapping
Bootstrapping step 1
Translation of a Subset of RSL into Java – p.31/35
Bootstrapping
Front End
RSL0 RSLAST0
Java
Translation of a Subset of RSL into Java – p.31/35
Bootstrapping
Translation Module
RSLAST0 JavaAST
Java
Translation of a Subset of RSL into Java – p.31/35
Bootstrapping
Back End
JavaAST Java
Java
Translation of a Subset of RSL into Java – p.31/35
Bootstrapping
Combining the three parts
P RSL0
P RSLAST0
P JavaAST
P RSL0 RSLAST0 Java
Java
RSLAST0 JavaAST
Java
JavaAST Java
Java
Translation of a Subset of RSL into Java – p.31/35
Bootstrapping
Result, the first version of the translator
RSL0 Java
Java
Translation of a Subset of RSL into Java – p.31/35
Bootstrapping
Bootstrapping step 2
Translation of a Subset of RSL into Java – p.31/35
Bootstrapping
New development in step 2
RSLAST1 JavaAST
RSL0
Translation of a Subset of RSL into Java – p.31/35
Bootstrapping
Translating the new translation module
RSL0 Java
Java RSLAST1 JavaAST
RSL0
RSLAST1 JavaAST
Java
Translation of a Subset of RSL into Java – p.31/35
Bootstrapping
Combining the new translation module with the other parts
P RSL1
P RSLAST1
P JavaAST
P RSL1 RSLAST1 Java
Java
RSLAST1 JavaAST
Java
JavaAST Java
Java
Translation of a Subset of RSL into Java – p.31/35
Bootstrapping
Result, the second version of the translator
RSL1 Java
Java
Translation of a Subset of RSL into Java – p.31/35
Implementation & Test
Translator implemented in a number of packages:
◆ translator
◆ translator.javaast
◆ translator.lib
◆ translator.rslast
◆ translator.rsllib
◆ translator.syntacticanalyzer Testing:
◆ Using different strategies for the different modules
◆ The fact that the translated module is able to translate it self is a good indicator that it works
Translation of a Subset of RSL into Java – p.32/35
Agenda
◆ Introduction
◆ Translation of RSL into Java
n Discussion of specific constructs
n Discussion of generel issues
◆ Process of developing a translator
n Design of Translator
n Development process
n Implementation & Test
◆ Conclusion
Translation of a Subset of RSL into Java – p.33/35
Conclusion
The objectives were:
◆ To define a translation of a subset of RSL into Java
◆ To develop a tool, translator, for translating from RSL into Java according to a subset of the defined translation
Requirements of the translation:
◆ The translation into Java must be semantically equivalent to the specification in RSL
◆ In the Java translated from a specification it should be possible to recognize the specification
Requirements of the translator:
◆ The translator should translate a subset of RSL into Java according to the translation defined
◆ The translator should provide extensibility
Translation of a Subset of RSL into Java – p.34/35
Conclusion
The objectives were:
◆ To define a translation of a subset of RSL into Java
◆ To develop a tool, translator, for translating from RSL into Java according to a subset of the defined translation
Requirements of the translation:
◆ The translation into Java must be semantically equivalent to the specification in RSL
◆ In the Java translated from a specification it should be possible to recognize the specification
Requirements of the translator:
◆ The translator should translate a subset of RSL into Java according to the translation defined
◆ The translator should provide extensibility
Translation of a Subset of RSL into Java – p.34/35
Conclusion
The objectives were:
◆ To define a translation of a subset of RSL into Java
◆ To develop a tool, translator, for translating from RSL into Java according to a subset of the defined translation
Requirements of the translation:
◆ The translation into Java must be semantically equivalent to the specification in RSL
◆ In the Java translated from a specification it should be possible to recognize the specification
Requirements of the translator:
◆ The translator should translate a subset of RSL into Java according to the translation defined
◆ The translator should provide extensibility
Translation of a Subset of RSL into Java – p.34/35
Conclusion, Using the tool for creating new tools
New development
RSLAST RSLAST
RSL
Translation of a Subset of RSL into Java – p.35/35
Conclusion, Using the tool for creating new tools
Tranlation using existing translator
RSL Java
Java
RSLAST RSLAST
RSL
RSLAST RSLAST
Java
Tool developed
Translator
Executable Tool
Translation of a Subset of RSL into Java – p.35/35
Conclusion, Using the tool for creating new tools
Combining existing parts and the translated part
RSL RSLAST
Java
RSLAST RSLAST
Java
RSLAST RSL
Java RSL Visitor Tool developed
Front end
Translation of a Subset of RSL into Java – p.35/35