Compound Data Structures - PowerPoint PPT Presentation

About This Presentation
Title:

Compound Data Structures

Description:

access array is represented by an infinite function expression. ... A declaration activates the storage allocation strategy specified by its type structure. ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 17
Provided by: scie85
Category:

less

Transcript and Presenter's Notes

Title: Compound Data Structures


1
Compound Data Structures
  • Structural decomposition into other values.
  • Lists domain A
  • Constructors NIL, CONS.
  • Selectors HEAD, TAIL.
  • Tuples domain A x B x C
  • Constructor (, , )
  • Selector ? i
  • Problem imperative languages
  • Variable forms of the objects exist.
  • Objects subcomponents can be altered.
  • Several versions of arrays variables.

2
Arrays
  • Collection of homogeneous objects indexed by a
    set of scalar values.
  • Homogeneity ? all components have same structure.
  • Allocation of storage and typechecking easy.
  • Both tasks can be performed by compiler.
  • Selector operation indexing.
  • Scalar index set primitive domain with
    relational and arithmetic operations.
  • Restricted by lower and upper bounds.

3
Linear Vector of Values
  • IDArray (Index ? Location) x Lowerbound x
    UpperBound
  • Index is index set
  • lessthan, greaterthan, equals.
  • Lowerbound Upperbound Index.
  • First component maps indices to the locations
    that contain the storable values.
  • Second and third component denote the bounds
    allowed on array indices.

4
Multidimensional Arrays
  • Array may contain other arrays.
  • Threedimensional array is vector whose
    components are twodimensional vectors.
  • Hierarchy of arrays defined as infinite sum
  • 1DArray (Index ? Location) x Index x Index.
  • (n1)DArray (Index ? nDArray) x Index x Index.
  • 1DArray maps indices to locations, 2DArray maps
    indices to 1D arrays, . . . .

5
Multidimensional Arrays
  • a ? MDArray
  • inkDArray(map, lower, upper) for some k gt 1
  • accessarray
  • Index ? MDArray ?(Location MDArray Errvalue)
  • accessarray ?i. ?r. cases r of
  • is1DArray(a) ? index1 a i
  • is2DArray(a) ? index2 a i
  • . . .
  • iskDArray(a) ? indexK a i
  • . . .
  • end

6
  • index m ?(map, lower, upper). ? i.
  • (i lessthan lower) or (i greaterthan upper) ?
  • inErrvalue() MInject(map(i))
  • 1Inject ? l.inLocation(l)
  • . . .
  • (n1)Inject ? a. inMDArray( innDArray(a))

7
Multidimensional Arrays
  • accessarray is represented by an infinite
    function expression.
  • By using pair representation of disjoint union
    elements, operation is convertible to finite,
    computable format.
  • Operation performs onelevel indexing upon array
    a returning another array if a has more than one
    dimension.
  • Still model is to clumsy to be used in practice.
  • Real programming languages allow arrays of
    numbers, record structures, sets, . . . !

8
System of Type Declarations
  • T ? Typestructure
  • S ? Subscript
  • T nat bool array N1... N2 of T record D
    end
  • D D1D2var IT
  • C IS E ...
  • E ... IS ...
  • S E E, S

9
  • Denotablevalue
  • (Natlocn Boollocn Array Record
    Errvalue)?
  • l ? Natlocn Boollocn Location
  • a ? Array (Nat ? Denotablevalue) x Nat x Nat
  • r ? Record Environment Id ? Denotablevalue

10
Semantics of Type Declarations
  • T Typestructure ? Store ? (Denotablevalue x
    Poststore)
  • Tnat ? s
  • let (l,p) (allocatelocn s)
  • in (inNatlocn(l), p)
  • Tbool ? s
  • let (l,p) (allocatelocn s)
  • in (inBoollocn(l), p)

11
  • Tarray N1... N2of T ? s
  • let n1 NN1 in let n2 NN2
  • in n1 greaterthan n2 (inErrvalue(), (signalerr
    s))
  • getstorage n1 (emptyarray n1 n2 ) s
  • Trecord D end ? s let (e, p) (DD
    emptyenv s)
  • in (inRecord(e), p)
  • Type structure expressions are mapped to storage
    allocation
  • actions!

12
Semantics of Type Declarations
  • getstorage Nat ? Array ? Store ?
    (Denotablevalue x Poststore)
  • getstorage ? n ? a ? s n greater n 2 ?
  • (inArray(a), return s)
  • let (d, p) TTs
  • in (check(getstorage (n plus one)
  • (augmentarray n d a)))(p)

13
  • augmentarray Nat ? Denotablevalue ? Array ?
    Array
  • augmentarray ? n ? d ?(map, lower, upper)
  • (n ? d map, lower, upper)
  • emptyarray Nat ? Nat ? Array
  • emptyarray ? n1 ? n2 ((? ninErrvalue())
    n1 n2 )
  • getstorage iterates from lower bound of array to
    upper bound allocating the proper amount of
    storage for a component.
  • augmentarray inserts the component into the
    array.

14
Declarations
  • D Declaration ? Environment ? Store ?
  • (Environment x Poststore)
  • DD1D2 ? e ? s
  • let (e, p) (DD1e s) in (check (DD2
    e))(p)
  • Dvar IT ? e ? s
  • let (d, p) TTs in ((updateenv I d e),
    p)
  • A declaration activates the storage allocation
    strategy specified by its type structure.

15
Array Indexing
  • S Subscript ?Array ? Environment ? Store ?
    Storablevalue
  • SE ? a?e ? s
  • cases (EEe s) of . . .
  • isNat(n) accessarray n a end
  • SE, S ? a ? e ? s
  • cases (EEe s) of
  • isNat(n) ? (cases (accessarray n a) of
  • isArray(a ) ? SSa e s ...end) ...
  • end

16
Array Assignment
  • CIS E ? e ? s
  • cases (accessenv I e) of ...
  • isArray(a) ? (cases (SSa e s) of ...
  • isNatlocn(l) ?(cases (EEe s) of
  • ... isNat(n) ? return(update l inNat(n) s)
    ...end)
  • ...end)
  • ...end
  • Assignment is first order (location, not an
    array, is on lefthandside).
Write a Comment
User Comments (0)
About PowerShow.com