Computer Science - Engineering - Principles of Programming Languages - Specification Implementation - Notes
Computer Science - Engineering - Principles of Programming Languages - Specification Implementation - Notes
com
UNIT 2
Presentation Outline
www.getmyuni.com
:Data Objects
Constants:
Data objects with a name that is permanently bound to a
value for its lifetime.
Literals: constants whose name is the written
representation of their value.
A programmer-defined constant: the name is
chosen by the programmer in a definition of data object.
Persistence: existence of data beyond run time
www.getmyuni.com
Data Types
•Attributes
•Values
•Operations
www.getmyuni.com
Attributes
Values
Operations
Operations
• Storage representation
• Implementation of operations
www.getmyuni.com
Storage representation
Implementation of operations
Integers
Specification
Maximal and minimal values
Operations:
Arithmetic
Relational
Assignment
Bit operations
Implementation - hardware defined
www.getmyuni.com
Sub-ranges
Implementation
Mantissa - exponent model.
Example: 10.5 = 0.105 x 102,
Mantissa: 105, Exponent: 2
www.getmyuni.com
Specification:
real numbers with predefined decimal places
Implementation :
directly supported by hardware or simulated by
software
Other Scalar Data Types
www.getmyuni.com
Enumerations
Example:
enum StudentClass
{Fresh, Soph, Junior, Senior}
the variable StudentClass may accept only one of the
four listed values.
Implementation: represented during run time as
integers, corresponding to the listed values.
Booleans
www.getmyuni.com
Character Strings
Pointers and Programmer- Constructed
Objects
Files
Character Strings
www.getmyuni.com
Specification:
Fixed declared length : storage allocation at
translation time. Strings longer than the declared
length are truncated.
Variable length to a declared bound: storage
allocation at translation time. An upper bound for
length is set and any string over that length is
truncated
Unbounded length: storage allocation at run
time. String can be any length
www.getmyuni.com
implementation
• Fixed declared length: A packed vector of characters
• Variable length to a declared bound: a descriptor that contains the
maximum length and the current length
• Unbounded length: Either a linked storage of fixed-length data objects or a
contiguous array of characters with dynamic run-time storage allocation
Pointers and Programmer-Constructed
www.getmyuni.com
Objects
Specification:
Reference data objects only of a single type – C,
Pascal, Ada.
Reference data objects of any type – Smalltalk
C, C++: pointers are data objects and can be
manipulated by the program
Java: pointers are hidden data structures, managed by
the language implementation
www.getmyuni.com
Pointers - implementation
Absolute addresses stored in the pointer. Allows for storing
the new object anywhere in the memory
Relative addresses: offset with respect to some base
address.
Advantages: the entire block can be moved to
another location without invalidating the addresses in the
pointers, since they are relative, not absolute.
www.getmyuni.com
Characteristics:
• Usually reside on secondary storage devices as
disks, tapes.
• Lifetime is greater than the lifetime of the program
that has created the files.
Implementation – as part of the operating system
Types of files
www.getmyuni.com
Data specifications
Selection mechanism
Data specifications
Two-step process:
referencing the structure
selection of a particular component
www.getmyuni.com
• Storage representations
• Storage management
www.getmyuni.com
Storage representation
• Sequential representation
• Linked representation
www.getmyuni.com
Sequential representation
Linked representation
structures
Storage management
data structures
What is to be checked:
Name equivalence
Issues
Every object must have an assigned type, there can
be no anonymous types.
Structural equivalence
Issues
Do components need to be exact duplicates?
Can field order be different in records?
Can field sizes vary?
www.getmyuni.com
Multidimensional arrays
Records