Transformation of Applicative Specifications into Imperative ...

Transformation of Applicative Specifications into Imperative ... Transformation of Applicative Specifications into Imperative ...

26.09.2013 Views

CHAPTER 9. IMPLEMENTATION OF THE TRANSFORMER 1 RSLAstVisitor +visitValueInfixExpr(ind valueInfixExpr : ValueInfixExpr) +visitPLUS(ind plus : PLUS) +visitValueInfixExpr(ind valueInfixExpr : ValueInfixExpr) +visitPLUS(ind plus : PLUS) ValueInfixExpr +accept(ind visitor : RSLAstVisitor) * StringRSLAstVisitor RSLElement +accept(ind visitor : RSLAstVisitor) PLUS +accept(ind visitor : RSLAstVisitor) Figure 9.6: The use of the visitor design pattern in the transformer Example 9.2 – Code snippet of the StringRSLAstVisitor.java public void v i s i t V a l u e I n f i x E x p r ( ValueInfixExpr v a l u e I n f i x E x p r ) { v a l u e I n f i x E x p r . l e f t ( ) . accept ( this ) ; r e s u l t . append ( " " ) ; v a l u e I n f i x E x p r . op ( ) . accept ( this ) ; r e s u l t . append ( " " ) ; v a l u e I n f i x E x p r . r i g h t ( ) . accept ( this ) ; } public void v i s i t L e t E x p r ( LetExpr letExpr ) { r e s u l t . append ( " l e t " ) ; for ( LetDef l e t D e f : letExpr . l e t _ d e f _ l i s t ( ) . g e t L i s t ( ) ) { l e t D e f . accept ( this ) ; r e s u l t . append ( " , " ) ; } i f ( letExpr . l e t _ d e f _ l i s t ( ) . l e n ( ) > 0) { r e s u l t . d e l e t e ( r e s u l t . l ength ( ) − 2 , r e s u l t . length ( ) ) ; } r e s u l t . append ( " in " ) ; letExpr . let_value_expr ( ) . accept ( this ) ; 104

} 9.7. DISADVANTAGES IN USING THE RSL2JAVA TOOL r e s u l t . append ( " end" ) ; public void visitPLUS (PLUS r s l _ p l u s ) { r e s u l t . append ( "+" ) ; } public void visitMINUS (MINUS rsl_minus ) { r e s u l t . append ( "−" ) ; } 9.7 Disadvantages In Using the RSL2Java Tool As mentioned in this chapter there have been some advantages involved by choosing to use the RSL2Java tool in the implementation of the transformer. However, it turned out during the development process that there were also some disadvantages. In this section some of the disadvantages will be discussed. The RSL2Java tool can only translate a subset RSL1 of RSL into Java. This made the specification written in RSL1 very long and messy. Especially the lack of let expressions, maps, some operators and the fact that functions are only allowed to have one return value complicated the matter. Furthermore, some errors connected to the type decoration of the RSL2Java tool required the introduction of extra functions. These problems led to the idea, that a specification of the transformation should be written in both RSL and RSL1. This was necessary in order to offer a readable specification for the reader and at the same time to be able to use the RSL2Java tool. This choice led to a lot of effort in keeping the two specifications up to date, both during the implementation phase and during the process of correcting errors. The method for obtaining this was first to correct the RSL specification and then transfer the corrections to the RSL1 specification. The approach may have complicated the RSL1 specification more than necessary but were necessary in order to keep both of the two specifications up to date. The resulting transformer works as expected, but in some cases the transformation process is rather slow, especially in cases of specifications containing nested product expressions. To give an example, it takes a few seconds to transform a specification without nested product expressions, whereas it can take up to several minutes to transform a specification of the same size containing one nested product expression. This is due to the fact that no code optimization is done in the RSL2Java tool and at the same time it is very difficult to optimize the code by optimizing the specification in RSL1. Due to these difficulties no effort is put into optimizing the transformer. 105

}<br />

9.7. DISADVANTAGES IN USING THE RSL2JAVA TOOL<br />

r e s u l t . append ( " end" ) ;<br />

public void visitPLUS (PLUS r s l _ p l u s ) {<br />

r e s u l t . append ( "+" ) ;<br />

}<br />

public void visitMINUS (MINUS rsl_minus ) {<br />

r e s u l t . append ( "−" ) ;<br />

}<br />

9.7 Disadvantages In Using the RSL2Java Tool<br />

As mentioned in this chapter there have been some advantages involved by<br />

choosing to use the RSL2Java tool in the implementation <strong>of</strong> the transformer.<br />

However, it turned out during the development process that there were also<br />

some disadvantages. In this section some <strong>of</strong> the disadvantages will be discussed.<br />

The RSL2Java tool can only translate a subset RSL1 <strong>of</strong> RSL <strong>into</strong> Java.<br />

This made the specification written in RSL1 very long and messy. Especially<br />

the lack <strong>of</strong> let expressions, maps, some operators and the fact that functions<br />

are only allowed to have one return value complicated the matter. Furthermore,<br />

some errors connected to the type decoration <strong>of</strong> the RSL2Java tool<br />

required the introduction <strong>of</strong> extra functions.<br />

These problems led to the idea, that a specification <strong>of</strong> the transformation<br />

should be written in both RSL and RSL1. This was necessary in order to<br />

<strong>of</strong>fer a readable specification for the reader and at the same time to be able<br />

to use the RSL2Java tool. This choice led to a lot <strong>of</strong> effort in keeping the two<br />

specifications up to date, both during the implementation phase and during<br />

the process <strong>of</strong> correcting errors. The method for obtaining this was first to<br />

correct the RSL specification and then transfer the corrections to the RSL1<br />

specification. The approach may have complicated the RSL1 specification<br />

more than necessary but were necessary in order to keep both <strong>of</strong> the two<br />

specifications up to date.<br />

The resulting transformer works as expected, but in some cases the transformation<br />

process is rather slow, especially in cases <strong>of</strong> specifications containing<br />

nested product expressions. To give an example, it takes a few seconds<br />

to transform a specification without nested product expressions, whereas it<br />

can take up to several minutes to transform a specification <strong>of</strong> the same size<br />

containing one nested product expression. This is due to the fact that no<br />

code optimization is done in the RSL2Java tool and at the same time it is<br />

very difficult to optimize the code by optimizing the specification in RSL1.<br />

Due to these difficulties no effort is put <strong>into</strong> optimizing the transformer.<br />

105

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!