1 / 87

Programming Languages Implementation of Data Structures

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

merlin
Download Presentation

Programming Languages Implementation of Data Structures

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming LanguagesImplementation of Data Structures Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

  2. Contents • Fundamentals • Elementary data types • Structured data types • Subprograms

  3. Fundamentals • Data objects • Data types • Type specification and implementation • Declaration • Type checking, compatibility, and conversion • Assignment and initialisation

  4. 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

  5. Fundamentals • Data objects • Data types • Type specification and implementation • Declaration • Type checking, compatibility, and conversion • Assignment and initialisation

  6. Data Types • A class of objects having the same properties • Primitive data types

  7. Fundamentals • Data objects • Data types • Type specification and implementation • Declaration • Type checking, compatibility, and conversion • Assignment and initialisation

  8. Specification • Attributes • Values • Operations: op_name: arg_type x arg_type x …  result_type x result_type x …

  9. 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

  10. Implementation • Storage representation • Operation definitions: • hardware operations • subprograms • in-line codes

  11. Fundamentals • Data objects • Data types • Type specification and implementation • Declaration • Type checking, compatibility, and conversion • Assignment and initialisation

  12. Declaration • To provide information about data objects: • number and type • name and position • lifetime • constant and initialised value

  13. Declaration • Data type declaration: • by name varA:integer • by specification varA:array [1..20]of integer

  14. Declaration • Operation declaration: • argument number, order, data types • result number, order, data types functionFOO(X:integer; Y: real): real; FOO: integer x real  real

  15. Declaration • Purposes: • choice of storage representations • storage management • generic operations • type checking

  16. Fundamentals • Data objects • Data types • Type specification and implementation • Declaration • Type checking, compatibility, and conversion • Assignment and initialisation

  17. 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

  18. 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

  19. 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;

  20. Type Compatibility • Name equivalence: • no anonymous types allowed • global type definitions used varX:array [1..10] of real;

  21. 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

  22. 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 */

  23. Fundamentals • Data objects • Data types • Type specification and implementation • Declaration • Type checking, compatibility, and conversion • Assignment and initialisation

  24. 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

  25. Initialisation • To set a value in the storage of an data object • Un-initialised data object • Explicit and implicit initialisation

  26. Programming LanguagesImplementation of Data Structures Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM

  27. Contents • Fundamentals • Elementary data types • Structured data types • Subprograms

  28. Elementary Data Types • Numeric data types • Enumerations • Booleans • Characters

  29. Numeric Data Types • Integers • Subranges • Floating-point real numbers • Fixed-point real numbers • Complex numbers • Rational numbers

  30. Integers -32768  32768 2 bytes -65536  65536 4 bytes

  31. Subranges • Smaller storage requirements • fewer bits than a general integer • software-simulated operations • Better type checking var A: 1..10

  32. 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

  33. Fixed-Point Real Numbers 6.7510 = 110.112 Sign bit integer part fractional part 0 110 11

  34. Complex Numbers real part imaginary part

  35. Rational Numbers • To avoid roundoff and truncation • Pairs of integers of unbounded length numerator denominator Sign bit

  36. Elementary Data Types • Numeric data types • Enumerations • Booleans • Characters

  37. Enumerations type DEGREE = (bachelor, master, doctor) 0 1 2

  38. Elementary Data Types • Numeric data types • Enumerations • Booleans • Characters

  39. Booleans • A particular bit • Zero/non-zero value 1 byte

  40. Elementary Data Types • Numeric data types • Enumerations • Booleans • Characters

  41. Characters 1 byte 2 byte

  42. Contents • Fundamentals • Elementary data types • Structured data types • Subprograms

  43. Structured Data Types • Fundamentals • Vectors and arrays • Records • Character strings • Pointers • Sets • Files

  44. Fundamentals • Specification • Implementation • Type checking

  45. Specification • Attributes: • Number of components • Type of each component • Names for selecting components • Maximum number of components • Organization of components

  46. Specification • Operations: • Component selection (random/sequential) • Whole-data-structure operations • Insertion/deletion • Creation/destruction

  47. Implementation • Storage representation: Decriptor Decriptor Component Component Component Component Sequential Linked

  48. Implementation • Selection operation: • Sequential  base-address-plus-offset • Linked  pointer following

  49. Implementation • Storage management: object object Dangling References Garbage

  50. Type Checking • Existence of a selected component: A[I] • Type of a selected component: A[2].link.item var A: array [1..10] ofreal;

More Related