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 end, /∗Returns the length of a let binding.∗/ /∗ Arguments: ======= lb: the let binding Results: ======= Int: the length of the let binding ∗/ getLengthLetBinding : LetBinding → Int getLengthLetBinding(lb) ≡ case lb of MakeBinding(b) → getLengthBinding(b), MakeRecordPattern(vn, p) → 1, MakeListPatternLet(lp) → 1 end, /∗Returns the length of a binding.∗/ /∗ Arguments: ======= b: the binding Results: ======= Int: the length of the binding ∗/ getLengthBinding : Binding → Int getLengthBinding(b) ≡ case b of IdBinding(id) → 1, Make_ProductBinding(pb) → getLengthBindingList(binding_list(pb)) end, /∗Returns the number of parameters of a binding list.∗/ /∗ Arguments: ======= bl: the binding list Results: ===== 274

C.1. FORMAL SPECIFICATION OF THE TRANSFORMER Int: the number of parameters ∗/ getLengthBindingList : Binding ∗ → Int getLengthBindingList(bl) ≡ if bl = 〈〉 then 0 else case hd bl of IdBinding(id) → 1 + getLengthBindingList(tl bl), Make_ProductBinding(pb) → getLengthBindingList(binding_list(pb)) + getLengthBindingList(tl bl) end end, /∗Checks if a binding is in a binding set.∗/ /∗ Arguments: ======= b: the binding bl: the binding set Results: ===== Bool: true if the binding is in the binding set, false otherwise ∗/ isinBinding : Binding × Binding-set → Bool isinBinding(b, bl) ≡ if bl = {} then false else case hd bl of IdBinding(id) → if getText(id) = getTextBinding(b) then true else isinBinding(b, bl \ {hd bl}) end, Make_ProductBinding(pb) → isinBinding(b, elems binding_list(pb)) ∨ isinBinding(b, bl \ {hd bl}) end end, /∗Returns the text of an id binding.∗/ /∗ Arguments: ======= 275

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

Int: the number <strong>of</strong> parameters<br />

∗/<br />

getLengthBindingList : Binding ∗ → Int<br />

getLengthBindingList(bl) ≡<br />

if bl = 〈〉 then 0<br />

else<br />

case hd bl <strong>of</strong><br />

IdBinding(id) → 1 + getLengthBindingList(tl bl),<br />

Make_ProductBinding(pb) →<br />

getLengthBindingList(binding_list(pb)) +<br />

getLengthBindingList(tl bl)<br />

end<br />

end,<br />

/∗Checks if a binding is in a binding set.∗/<br />

/∗<br />

Arguments:<br />

=======<br />

b: the binding<br />

bl: the binding set<br />

Results:<br />

=====<br />

Bool: true if the binding is in the binding set,<br />

false otherwise<br />

∗/<br />

isinBinding : Binding × Binding-set → Bool<br />

isinBinding(b, bl) ≡<br />

if bl = {} then false<br />

else<br />

case hd bl <strong>of</strong><br />

IdBinding(id) →<br />

if getText(id) = getTextBinding(b) then true<br />

else isinBinding(b, bl \ {hd bl})<br />

end,<br />

Make_ProductBinding(pb) →<br />

isinBinding(b, elems binding_list(pb)) ∨<br />

isinBinding(b, bl \ {hd bl})<br />

end<br />

end,<br />

/∗Returns the text <strong>of</strong> an id binding.∗/<br />

/∗<br />

Arguments:<br />

=======<br />

275

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

Saved successfully!

Ooh no, something went wrong!