Transformation of Applicative Specifications into Imperative ...
Transformation of Applicative Specifications into Imperative ... Transformation of Applicative Specifications into Imperative ...
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
- Page 70 and 71: CHAPTER 6. TRANSFORMATIONS 6.4.4 Tr
- Page 72 and 73: CHAPTER 6. TRANSFORMATIONS 56
- Page 74 and 75: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 76 and 77: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 78 and 79: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 80 and 81: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 82 and 83: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 84 and 85: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 86 and 87: CHAPTER 7. CORRECTNESS OF TRANSFORM
- Page 88 and 89: CHAPTER 8. SPECIFICATIONS The rewri
- Page 90 and 91: CHAPTER 8. SPECIFICATIONS RSL speci
- Page 92 and 93: CHAPTER 8. SPECIFICATIONS The FUNC
- Page 94 and 95: CHAPTER 8. SPECIFICATIONS out, that
- Page 96 and 97: CHAPTER 8. SPECIFICATIONS construct
- Page 98 and 99: CHAPTER 8. SPECIFICATIONS 8.4.1 Mor
- Page 100 and 101: CHAPTER 8. SPECIFICATIONS PRECOND_T
- Page 102 and 103: CHAPTER 8. SPECIFICATIONS if length
- Page 104 and 105: CHAPTER 8. SPECIFICATIONS subtypes.
- Page 106 and 107: CHAPTER 8. SPECIFICATIONS 8.5.2 Cha
- Page 108 and 109: CHAPTER 8. SPECIFICATIONS axiom [ m
- Page 110 and 111: CHAPTER 8. SPECIFICATIONS Specifica
- Page 112 and 113: CHAPTER 8. SPECIFICATIONS the lack
- Page 114 and 115: CHAPTER 9. IMPLEMENTATION OF THE TR
- Page 116 and 117: CHAPTER 9. IMPLEMENTATION OF THE TR
- Page 118 and 119: CHAPTER 9. IMPLEMENTATION OF THE TR
- Page 122 and 123: CHAPTER 9. IMPLEMENTATION OF THE TR
- Page 124 and 125: CHAPTER 9. IMPLEMENTATION OF THE TR
- Page 126 and 127: CHAPTER 10. EXAMPLES OF TRANSFORMAT
- Page 128 and 129: CHAPTER 10. EXAMPLES OF TRANSFORMAT
- Page 130 and 131: CHAPTER 10. EXAMPLES OF TRANSFORMAT
- Page 132 and 133: CHAPTER 10. EXAMPLES OF TRANSFORMAT
- Page 134 and 135: CHAPTER 10. EXAMPLES OF TRANSFORMAT
- Page 136 and 137: CHAPTER 11. TEST 11.1.1 Lexer and P
- Page 138 and 139: CHAPTER 11. TEST An overview of the
- Page 140 and 141: CHAPTER 12. POSSIBLE EXTENSIONS OF
- Page 142 and 143: CHAPTER 12. POSSIBLE EXTENSIONS OF
- Page 144 and 145: CHAPTER 12. POSSIBLE EXTENSIONS OF
- Page 146 and 147: CHAPTER 13. CONCLUSION RSL AST and
- Page 148 and 149: CHAPTER 13. CONCLUSION 132
- Page 150 and 151: BIBLIOGRAPHY [ST02] Donald Sannello
- Page 152 and 153: APPENDIX A. USING AND EXTENDING THE
- Page 154 and 155: APPENDIX A. USING AND EXTENDING THE
- Page 156 and 157: APPENDIX B. CONTENTS OF CD-ROM 140
- Page 158 and 159: APPENDIX C. FORMAL SPECIFICATIONS O
- Page 160 and 161: APPENDIX C. FORMAL SPECIFICATIONS O
- Page 162 and 163: APPENDIX C. FORMAL SPECIFICATIONS O
- Page 164 and 165: APPENDIX C. FORMAL SPECIFICATIONS O
- Page 166 and 167: APPENDIX C. FORMAL SPECIFICATIONS O
- Page 168 and 169: APPENDIX C. FORMAL SPECIFICATIONS O
}<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