Transformation of Applicative Specifications into Imperative ...
Transformation of Applicative Specifications into Imperative ... Transformation of Applicative Specifications into Imperative ...
CHAPTER 9. IMPLEMENTATION OF THE TRANSFORMER Furthermore, the specification of the RSL AST, named RSLAst_Module.rsl, which is translated into Java using the RSL2Java tool, has to be extended to deal with RSLI in order to conform to the output from the lexer, the parser and the transformer module. The structure and workings of the lexer and parser are described in Section 9.5 and a description of the specification of the RSL AST can be found in Chapter 8. 9.3.2 Transformer Module The specification of the transformer, named TransformerRSL1.rsl, which can transform an applicative RSL specification into an imperative one has to be written and translated using the RSL2Java tool. Unlike the RSL2Java tool, no type decoration is done explicitly before the transformation. This means that the type decorator visitor, the parent visitor and the wrapper modules of the RSL2Java tool are no longer needed. The specification of the transformer is described in Chapter 8. 9.3.3 Back End The back end consists of a revised version of the super class of the visitor modules, named RSLAstVisitor.java, and the RSL AST to RSL visitor, named StringRSLAstVisitor.java, provided by the RSL2Java tool. These visitors have to be extended in order to deal with all the constructs of RSLI. The abstract class RSLElement.java, which is the super class of all classes generated by the RSL2Java tool when translating the RSL AST specification, is adapted to the changes done. It does not need any fields used by the type decorator and the parent visitor in the RSL2Java tool. The only thing it has to offer is the abstract method accept which is used to visit the RSL AST nodes. Further description of the visitors can be found in Section 9.6. 9.3.4 Control Module The control module, RSLRunner.java, is completely altered in order to reflect the above changes. The module takes care of reading the user input, which consists of the name of the applicative specification to transform, the name of the new imperative specification and a list of type names and corresponding variable names, which is used to determine the types of interest and corresponding variable names. It then uses the above parts to make the actual transformation. The result of the transformation is written to a file. The source code of the control module can be found in Appendix F. See Appendix A for more details on the use of the transformer. 100
9.4. THE TRANSFORMER The classes in the rsllib package containing functionality for sets, lists and maps are not altered. The list functionality is used when implementing the transformer. 9.4 The Transformer The result of the process described above is a transformer, which can transform a transformable applicative RSL specification into an imperative RSL specification according to the transformation rules given in Chapter 6. If the applicative specification not is transformable or not within RSLA this is reported to the user through error messages. The transformation is done in 3 steps as shown in Figure 9.5. First of all the applicative RSL specification is transformed into the corresponding RSL AST using the lexer and parser. The RSL AST is transformed into an imperative version of the RSL AST. Finally, the RSL AST is turned into an imperative RSL specification using the string visitor StringRSLAstVisitor.java. Applicative RSL specification RSLLexer RSLParser AST of applicative RSL specification TransformerRSL1 StringRSLAstVisitor AST of imperative RSL specification Figure 9.5: The flow of a transformation 9.5 The Lexer and Parser Imperative RSL specification The lexer and parser which transforms an RSL ASCII file into an RSL AST is made using the ANTLR tool, [Par]. This tool generates a lexer and a parser in Java based on a grammar file. The grammar file can be found in Appendix E. The grammar file contains both the grammar of the lexer and the parser. The lexer performs a lexical analysis of the specification, which means that it reads the specification and turns it into tokens. The parser then determines the syntactic structure of these tokens and turns them into an RSL AST if the parsing is successful. The specification of the parser very much resembles that of a BNF grammar. The grammar is built according to the syntax of RSL, which is illustrated in Example 9.1. The example shows the part of the parser grammar 101
- Page 66 and 67: CHAPTER 6. TRANSFORMATIONS A case e
- Page 68 and 69: CHAPTER 6. TRANSFORMATIONS is due t
- 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 118 and 119: CHAPTER 9. IMPLEMENTATION OF THE TR
- Page 120 and 121: 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
9.4. THE TRANSFORMER<br />
The classes in the rsllib package containing functionality for sets, lists and<br />
maps are not altered. The list functionality is used when implementing the<br />
transformer.<br />
9.4 The Transformer<br />
The result <strong>of</strong> the process described above is a transformer, which can transform<br />
a transformable applicative RSL specification <strong>into</strong> an imperative RSL<br />
specification according to the transformation rules given in Chapter 6. If<br />
the applicative specification not is transformable or not within RSLA this is<br />
reported to the user through error messages.<br />
The transformation is done in 3 steps as shown in Figure 9.5. First <strong>of</strong><br />
all the applicative RSL specification is transformed <strong>into</strong> the corresponding<br />
RSL AST using the lexer and parser. The RSL AST is transformed <strong>into</strong> an<br />
imperative version <strong>of</strong> the RSL AST. Finally, the RSL AST is turned <strong>into</strong> an<br />
imperative RSL specification using the string visitor StringRSLAstVisitor.java.<br />
<strong>Applicative</strong> RSL<br />
specification<br />
RSLLexer<br />
RSLParser<br />
AST <strong>of</strong> applicative<br />
RSL specification<br />
TransformerRSL1<br />
StringRSLAstVisitor<br />
AST <strong>of</strong> imperative<br />
RSL specification<br />
Figure 9.5: The flow <strong>of</strong> a transformation<br />
9.5 The Lexer and Parser<br />
<strong>Imperative</strong> RSL<br />
specification<br />
The lexer and parser which transforms an RSL ASCII file <strong>into</strong> an RSL AST<br />
is made using the ANTLR tool, [Par]. This tool generates a lexer and a<br />
parser in Java based on a grammar file. The grammar file can be found in<br />
Appendix E. The grammar file contains both the grammar <strong>of</strong> the lexer and<br />
the parser.<br />
The lexer performs a lexical analysis <strong>of</strong> the specification, which means<br />
that it reads the specification and turns it <strong>into</strong> tokens. The parser then<br />
determines the syntactic structure <strong>of</strong> these tokens and turns them <strong>into</strong> an<br />
RSL AST if the parsing is successful.<br />
The specification <strong>of</strong> the parser very much resembles that <strong>of</strong> a BNF grammar.<br />
The grammar is built according to the syntax <strong>of</strong> RSL, which is illustrated<br />
in Example 9.1. The example shows the part <strong>of</strong> the parser grammar<br />
101