24-09-2013, 02:03 PM
Programming Language Theory ICS313
Programming Language .pdf (Size: 585.67 KB / Downloads: 14)
Data Types
Views of data types:
Collection of values from a "domain" (the
denotational approach)
Internal structure of a bunch of data,
described down to the level of a small set of
fundamental types (the structural approach)
Equivalence class of objects (the
implementer's approach)
Collection of well-defined operations that
can be applied to objects of that type (the
abstraction approach)
Typing
Type checking -- ensuring that the
operands of an operator are of
compatible types
A type error occurs when an operator
is applied to an operand of an
inappropriate type
A programming language is strongly
typed if type errors are always
detected
Type Checking
Performed on subprograms, assignment
statements, operands and operators
A compatible type is
• legal for the operator, or
• allowed under language rules to be implicitly converted,
by compiler- generated code, to a legal type
Static typing means that the compiler can do all
the checking at compile time
Dynamic typing is done at run-time
Advantage of strong typing: allows the detection
of the misuses of variables that result in type
errors
Primitive Data Types
Not defined in terms of other data types
1. Integer
• Almost always an exact reflection of the
hardware, so the mapping is trivial
• There may be as many as eight different integer
types in a language (diff. size, signed/unsigned)
2. Floating Point
• Model real numbers, but only as approximations
• Languages for scientific applications support at
least two floating-point types; sometimes more
• Usually exactly like the hardware, but not always
Coercion
Many languages allow a value to be
coerced to the proper type if found in
an expression expecting that type
Coercion can be based just on types of
operands, or can take into account
expected type from the surrounding
context as well
Fortran has lots of coercions, all based
on operand type
Arrays
Arrays are the most common and
important composite data type
Arrays are usually homogeneous (all
elements have the same type)
Semantically, they can be thought of
as a mapping from an index type (often
integers) to a component or element
type
A slice or section is a rectangular
portion of an array (See figure 7.4)