Programming Languages Implementation of Data Structures. Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM. Contents. Fundamentals Elementary data types Structured data types Subprograms. Fundamentals. Data objects Data types Type specification and implementation
01 / 87Programming Languages Implementation of Data Structures
1 / 17
Télécharger la présentation
Programming Languages Implementation of Data Structures
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation
Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement.Téléchargez la présentation en cliquant sur ce lien.Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.
Contents • Fundamentals • Elementary data types • Structured data types • Subprograms
Fundamentals • Data objects • Data types • Type specification and implementation • Declaration • Type checking, compatibility, and conversion • Assignment and initialisation
Data Objects • A run-time grouping of one or more pieces of data • A container for data values • Block of storage • Programmer-defined and system-defined • Lifetime • Variables and constants
Fundamentals • Data objects • Data types • Type specification and implementation • Declaration • Type checking, compatibility, and conversion • Assignment and initialisation
Data Types • A class of objects having the same properties • Primitive data types
Fundamentals • Data objects • Data types • Type specification and implementation • Declaration • Type checking, compatibility, and conversion • Assignment and initialisation
Specification • Attributes • Values • Operations: op_name: arg_type x arg_type x … result_type x result_type x …
Examples: Arrays • Attributes: • number of dimensions • subscript range for each dimension • data types of the components • Values: valid values for the components • Operations: subscripting, creating, accessing attributes
Fundamentals • Data objects • Data types • Type specification and implementation • Declaration • Type checking, compatibility, and conversion • Assignment and initialisation
Declaration • To provide information about data objects: • number and type • name and position • lifetime • constant and initialised value
Declaration • Data type declaration: • by name varA:integer • by specification varA:array [1..20]of integer
Declaration • Operation declaration: • argument number, order, data types • result number, order, data types functionFOO(X:integer; Y: real): real; FOO: integer x real real
Declaration • Purposes: • choice of storage representations • storage management • generic operations • type checking
Fundamentals • Data objects • Data types • Type specification and implementation • Declaration • Type checking, compatibility, and conversion • Assignment and initialisation
Type Checking • Checking if each operation receives the proper number of arguments of the proper data types • Dynamic (run time) vs. static (compile time) type checking
Type Checking • Dynamic type checking: • no declarations required • types of data objects may change as needed • programmers have no concerns about data types • difficult to debug and remove type errors • extra storage required for keeping type information • reduction of execution speed
Type Compatibility • T1 and T2 are compatible if data objects of type T1 can occur in the positions of data objects of type T2, and vice versa: name or structural equivalence typeVECT1:array [1..10] of real; VECT2:array [1..10] of real; varX, Y:VECT1; Z:VECT2; Y := X; Z := Y;
Type Compatibility • Name equivalence: • no anonymous types allowed • global type definitions used varX:array [1..10] of real;
Type Compatibility • Structural equivalence: • difficult to define • static type checking compromised • cost to check typeMETERS = integer; LITERS = integer; var LEN:METERS; VOL:LITERS; LEN + VOL
Type Conversion • When types are mismatched: • type error • type conversion (coercion) varA:integer; int I; B, C: real; unsigned U; float F; C := A + B I = - 1; U = 1; F = U * I; /* I = - 1 65535 */
Fundamentals • Data objects • Data types • Type specification and implementation • Declaration • Type checking, compatibility, and conversion • Assignment and initialisation
Assignment • Basic operation for changing values of data objects • Specification: := : type1 x type2 void = : type1 x type2 type3 Z := X + Y Z = X + (Y = W * 2) A = B = C
Initialisation • To set a value in the storage of an data object • Un-initialised data object • Explicit and implicit initialisation
Subranges • Smaller storage requirements • fewer bits than a general integer • software-simulated operations • Better type checking var A: 1..10
Floating-Point Real Numbers 6.7510 = 110.112 = 0.110112 x 23 = 0.110112 x 00112 Sign bit for exponent exponent 0 0 0011 11011 mantissa Sign bit for mantissa
Contents • Fundamentals • Elementary data types • Structured data types • Subprograms
Structured Data Types • Fundamentals • Vectors and arrays • Records • Character strings • Pointers • Sets • Files
Fundamentals • Specification • Implementation • Type checking
Specification • Attributes: • Number of components • Type of each component • Names for selecting components • Maximum number of components • Organization of components