CIS 400 LECTURE 14
Data
type specification(class of objects with operations)
·
Attributes
(stored descriptor), provided it has no hardware equivalent, (i.e. int, char,
float)
·
Values
(ordered set)
·
Operations
(domain and range)
Implementation:
·
Storage
representation
·
Procedures
to manipulate
Syntactic
representation
Operations,
(concerns):
·
Operations
undefined for a certain input,(i.e. divide by zero)
·
Implicit
arguments
·
Side
effects
·
Self-modification/history
sensitivity
Storage
representation
Int
Float
Char
Anything
else, (i.e. string, array, bool, etc.) is simulated
Attributes
·
Used
by compiler to determine run-time representation, (translation)
·
Stored
descriptor, used at run-time to determine meaning of bit-stream
Type
checking
Operators-
right number of arguments
-
arguments
are of the right type
Static
type checking: if type check isn't done at run-time, you don't need to deep
storage descriptor
Dynamic
type checking: done at run-time, (complicates debugging), storage descriptor is
essential
Remember:
type checking and type binding are different
Type
checking, errors:
·
Flag
error, take appropriate action, (i.e. correct, prompt for correction, program
cessation)
·
Conversion/coercion/
type-cast:
v
Auto-convert,
(i.e. int to float)
v
Built
in coercion function, (this, of course, may not always give desired result)
Type
equivalence:
Type
equivalence decides, provided that the types are equivalent, what operations
are permissible?
·
Name
equivalence
In
Pascal:
type
vec1 = array[1…10] of integers;
vec2
= array[1…10] of integers;
var x,y
= vec1
z
= vec2
x
== y; // ACCEPTABLE
x
== z; // NOT ACCEPTABLE
a,
w = array[1…10] of integers
//anonymous
b = array[1…10] of integers // also anonymous
a
== w //ACCEPTABLE
a
== z //NOT ACCEPTABLE
a
== b //NOT ACCEPTABLE
·
Structure
equivalence- same memory block size and same bit pattern
(in
above x and y are structurally equivalent, but so are a and b)
another
example of structural equivalence:
type
meter = integer
type
liter = integer
var
length = meter
volume
= liter
unfortunately
under structural equivalence the assignment length = volume is permissible
another
example of structural equivalence:
Numeric
data types:
Integers:
must chose minint and maxint
Z +
Z ® Z
Binary
operators; +, -, *, ' (plus and minus
have hardware implementations, multiply
may, divide does not)
Unary
operators; +, - (positive and negative)
Relational; =, <, <, £, ³, ¹
(no hardware implementation)
Z + Z ® boolean
1
word, (32 bit)
Half
word
In
"half word" numeric representation, it is necessary to devise a way
to access and manipulate the 16 bits
Floating
point
·
Single
precision
·
Double
precision, (increases accuracy by increasing the number of digits allowed to
the right of the decimal point)
·
Long
real
Fixed
point number:
Currency
would be a common example
Complex
numbers:
Represented
by a pair of reals
Rational
numbers, (fractions):
Represented
by a pair of reals
Enumerations:
Example:
Type gender(male, female)
Var x gender;
Operations:
·
Assignment
·
Relational,
(i.e. "!=")
·
Successor/predecessor
(implied order based on a set of intergers)
Set
of integers:
Boolean:
·
Operators:
'and', 'or', 'not', (also 'equivalence', 'nand', 'nor', 'xor')
·
Implementation:
manipulated at the smallest addressable level…the word…so 31 bits are wasted
Character:
1
byte used to store, but the whole word must be used
a
"packing/unpacking" application may be used to improve efficiency of
word usage
·
Assignment
·
Comparison,
(not equal)
·
Relational,
(necessary for sorting)