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 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

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

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

Saved successfully!

Ooh no, something went wrong!