• Ingen resultater fundet

Translation of a Subset of RSL into Java

N/A
N/A
Info
Hent
Protected

Academic year: 2022

Del "Translation of a Subset of RSL into Java"

Copied!
82
0
0

Indlæser.... (se fuldtekst nu)

Hele teksten

(1)

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

(2)

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

(3)

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

(4)

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

(5)

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

(6)

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

(7)

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

(8)

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

(9)

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

(10)

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

(11)

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

(12)

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

(13)

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

(14)

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

(15)

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

(16)

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

(17)

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

(18)

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

(19)

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

(20)

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

(21)

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

(22)

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

(23)

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

(24)

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

(25)

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

(26)

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

(27)

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

(28)

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

(29)

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

(30)

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

(31)

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

(32)

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

(33)

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

(34)

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

(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

(36)

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

(37)

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

(38)

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

(39)

Variant definitions, record constructor, RSL

RSL:

type t = a(t2)

Translation of a Subset of RSL into Java – p.13/35

(40)

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

(41)

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

(42)

Example of variant definition, RSL

typeCollection == empty | add(Elem, Collection), Elem

Translation of a Subset of RSL into Java – p.16/35

(43)

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

(44)

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

(45)

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

(46)

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

(47)

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

(48)

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

(49)

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

(50)

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

(51)

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

(52)

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

(53)

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

(54)

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

(55)

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

(56)

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

(57)

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

(58)

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

(59)

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

(60)

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

(61)

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

(62)

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

(63)

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

(64)

Bootstrapping

Bootstrapping step 1

Translation of a Subset of RSL into Java – p.31/35

(65)

Bootstrapping

Front End

RSL0 RSLAST0

Java

Translation of a Subset of RSL into Java – p.31/35

(66)

Bootstrapping

Translation Module

RSLAST0 JavaAST

Java

Translation of a Subset of RSL into Java – p.31/35

(67)

Bootstrapping

Back End

JavaAST Java

Java

Translation of a Subset of RSL into Java – p.31/35

(68)

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

(69)

Bootstrapping

Result, the first version of the translator

RSL0 Java

Java

Translation of a Subset of RSL into Java – p.31/35

(70)

Bootstrapping

Bootstrapping step 2

Translation of a Subset of RSL into Java – p.31/35

(71)

Bootstrapping

New development in step 2

RSLAST1 JavaAST

RSL0

Translation of a Subset of RSL into Java – p.31/35

(72)

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

(73)

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

(74)

Bootstrapping

Result, the second version of the translator

RSL1 Java

Java

Translation of a Subset of RSL into Java – p.31/35

(75)

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

(76)

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

(77)

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

(78)

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

(79)

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

(80)

Conclusion, Using the tool for creating new tools

New development

RSLAST RSLAST

RSL

Translation of a Subset of RSL into Java – p.35/35

(81)

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

(82)

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

Referencer

RELATEREDE DOKUMENTER

This means that they are translations of a translation (the 1949 edition) of a translation (Joyce’s work being a translation of Homer’s Odyssey), suggesting that the Danish

Dür , Tanja Stamm &amp; Hanne Kaae Kristensen (2020): Danish translation and validation of the Occupational Balance Questionnaire, Scandinavian Journal of Occupational Therapy.

If Internet technology is to become a counterpart to the VANS-based health- care data network, it is primarily neces- sary for it to be possible to pass on the structured EDI

Most specific to our sample, in 2006, there were about 40% of long-term individuals who after the termination of the subsidised contract in small firms were employed on

Copyright and moral rights for the publications made accessible in the public portal are retained by the authors and/or other copyright owners and it is a condition of

The application of the developed software has also been demonstrated, by performing bounded model checking on an RSL specification, using both the RSL translator and the

A number of recent research tendencies in Translation Studies focus explicitly on the translator in some way, rather than on translations as texts.. These trends might be

The product pattern could be translated like the record pattern by check- ing the type using an instanceof expression and to define local variables for each part of the product