Transformation of Applicative Specifications into Imperative ...

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

26.09.2013 Views

CHAPTER 8. SPECIFICATIONS The rewriting of the specification from RSL to RSL1 requires some changes. The correctness of these changes is discussed in Section 8.5. 8.2 Specification of the RSL AST The specification of the RSL AST RSLAst_Module2.rsl, which can be found in Appendix D, is written in RSL1, such that the specification can be transformed into Java using the RSL2Java tool and thereby be used as part of the transformer. The specification of the RSL AST consists purely of type definitions that are either variant definitions or short record definitions. These type definitions describe the structure of an RSL AST. The specification of the RSL AST is based on the concrete syntax summary of RSL offered in [Gro92, pp. 371-380] and the changes to RSL which can be found in [Gro95]. The construction of the RSL AST is straight forward when following these syntax summaries. In RSL graphical symbols like parenthesizes and commas are used to distinguish between the different kinds of RSL constructs. When the type of an RSL construct is determined these symbols are superfluous and can be discarded. This is exploited in the specification of the RSL AST where only the necessary information is kept. Otherwise the syntax of RSL consists of terminals T and nonterminals NT. Terminals are indivisible entities, whereas nonterminals are symbols that can be expressed in terms of other symbols, terminals or nonterminals. The relationship between the RSL syntax and the RSL AST specification is described in the following. Syntax of the form becomes whereas becomes NT ::= NT1 . . . NTn NT :: nt1 : NT1 . . . ntn : NTn NT ::= NT1| . . . |NTn NT1 ::= NT11 . . . NT1n . NTn ::= NTn1 . . . NTnn 72

NT == 8.2. SPECIFICATION OF THE RSL AST NT1(nt11 : NT11 ... nt1n : NT1n) | . NTn(ntn1 : NTn1 ... ntnn : NTnn), NT11 :: . . ., . NTnn :: . . . When the alternatives are terminals as in it is specified as NT ::= T1| . . . |Tn NT == T1 | . . . | Tn An example of some RSL syntax and the corresponding RSL AST specification can be found in Example 8.1. Example 8.1 – Specification of the RSL AST based on the syntax of RSL RSL syntax: value_expr ::= value_or_variable − name | name ::= id product_expr | infix_expr product_expr ::= (value_expr−list) infix_expr ::= value_expr infix_op value_expr infix_op ::= + | − | = 73

NT ==<br />

8.2. SPECIFICATION OF THE RSL AST<br />

NT1(nt11 : NT11 ... nt1n : NT1n) |<br />

.<br />

NTn(ntn1 : NTn1 ... ntnn : NTnn),<br />

NT11 :: . . .,<br />

.<br />

NTnn :: . . .<br />

When the alternatives are terminals as in<br />

it is specified as<br />

NT ::= T1| . . . |Tn<br />

NT == T1 | . . . | Tn<br />

An example <strong>of</strong> some RSL syntax and the corresponding RSL AST specification<br />

can be found in Example 8.1.<br />

Example 8.1 – Specification <strong>of</strong> the RSL AST based on the syntax <strong>of</strong> RSL<br />

RSL syntax:<br />

value_expr ::= value_or_variable − name |<br />

name ::= id<br />

product_expr |<br />

infix_expr<br />

product_expr ::= (value_expr−list)<br />

infix_expr ::= value_expr infix_op value_expr<br />

infix_op ::= + |<br />

− |<br />

=<br />

73

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

Saved successfully!

Ooh no, something went wrong!