Transformation of Applicative Specifications into Imperative ...

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

26.09.2013 Views

APPENDIX C. FORMAL SPECIFICATIONS OF TRANSFORMATIONS ======= ListPattern: the imperative version of the list pattern ∗/ TRListPattern : ListPattern × FUNC × TRANS × TYPES → ListPattern × TYPES TRListPattern(lp, func, trans, types) ≡ case lp of Make_EnumeratedListPattern(elp) → let (elp ′ , types ′ ) = TROptInnerPattern( inner_pattern(elp), func, trans, types) in (Make_EnumeratedListPattern( mk_EnumeratedListPattern(elp ′ )), types ′ ) end, ConcatenatedListPattern(elp, p) → let (elp ′ , types1) = TROptInnerPattern( inner_pattern(elp), func, trans, types), (p ′ , types2) = TRPattern(p, func, trans, types1) in (ConcatenatedListPattern( mk_EnumeratedListPattern(elp ′ ), p ′ ), types2 ) end end, /∗Transforms an optional inner pattern.∗/ /∗ Arguments: ======= oip: optional inner pattern Results: ======= OptionalInnerPattern: the imperative version of the optional inner pattern ∗/ TROptInnerPattern : OptionalInnerPattern × FUNC × TRANS × TYPES → 220

C.1. FORMAL SPECIFICATION OF THE TRANSFORMER OptionalInnerPattern × TYPES TROptInnerPattern(oip, func, trans, types) ≡ case oip of InnerPatternList(pl) → let (pl ′ , types ′ ) = TRPatternList(pl, func, trans, types) in (InnerPatternList(pl ′ ), types ′ ) end, NoInnerPattern → (oip, types) end, /∗Establishes an assignment expression.∗/ /∗ Arguments: ======= ve: the value expression et: the corresponding expected type Results: ======= ValueExpr: the resulting value expression ∗/ makeAssignExpr : ValueExpr × ExpType × TRANS → ValueExpr makeAssignExpr(ve, et, trans) ≡ case et of Known(te) → case te of TypeName(tn) → if tn ∈ dom trans then /∗Type of interest.∗/ AssignExpr(trans(tn), ve) else /∗Not type of interest.∗/ ve end, → ve end, Unknown → ve end, /∗**** TypeExpr ****∗/ 221

C.1. FORMAL SPECIFICATION OF THE TRANSFORMER<br />

OptionalInnerPattern × TYPES<br />

TROptInnerPattern(oip, func, trans, types) ≡<br />

case oip <strong>of</strong><br />

InnerPatternList(pl) →<br />

let<br />

(pl ′ , types ′ ) =<br />

TRPatternList(pl, func, trans, types)<br />

in<br />

(InnerPatternList(pl ′ ), types ′ )<br />

end,<br />

NoInnerPattern → (oip, types)<br />

end,<br />

/∗Establishes an assignment expression.∗/<br />

/∗<br />

Arguments:<br />

=======<br />

ve: the value expression<br />

et: the corresponding expected type<br />

Results:<br />

=======<br />

ValueExpr: the resulting value expression<br />

∗/<br />

makeAssignExpr :<br />

ValueExpr × ExpType × TRANS → ValueExpr<br />

makeAssignExpr(ve, et, trans) ≡<br />

case et <strong>of</strong><br />

Known(te) →<br />

case te <strong>of</strong><br />

TypeName(tn) →<br />

if tn ∈ dom trans<br />

then<br />

/∗Type <strong>of</strong> interest.∗/<br />

AssignExpr(trans(tn), ve)<br />

else<br />

/∗Not type <strong>of</strong> interest.∗/<br />

ve<br />

end,<br />

→ ve<br />

end,<br />

Unknown → ve<br />

end,<br />

/∗**** TypeExpr ****∗/<br />

221

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

Saved successfully!

Ooh no, something went wrong!