190 likes | 280 Views
Learn about data modeling, syntax for variables, compiler descriptors, primitive types, character strings, numeric types, and handling arrays and records. Dive into pointers and sets in various programming languages.
E N D
Complex Data Types • One very important measure of the “goodness” of a PL is the capability of its data types to model the problem space variables • Design issues for all data types • what is the syntax of references to variables? • what operations are defined and how are they specified? • Compilers use descriptors to maintain information about instances of types in a program • actually part of the symbol table • what’s needed in descriptor depends on particular type • when the descriptor is needed depends on the kind of type checking required • static, compile time only • dynamic, run-time as well
Primitive types • Numeric • Boolean • Character strings • Ordinal
Numeric Types • Range and Precision • Integer • Real • Decimal
Character String Issues • Primitive or not • Snobol, Java primitive • Ada, F77, F90, Basic “somewhat” primitive • Pascal, C, C++ not primitive • Static or dynamic • Or limited length dynamic • Operations
Strings (continued) • Evaluation • aid to writability • as a primitive type with static length, they are inexpensive to provide--why not have them? • dynamic length is nice, but is it worth the expense? • Implementation • static length - compile-time descriptor • limited dynamic length - may need a run-time descriptor for length (but not in C and C++) • dynamic length - need run-time descriptor; allocation/deallocation is the biggest problem
Ordinal • Enumeration • Subrange
Arrays • Definition • Mapping • Row major or column major • Memory allocation • Static • Fixed stack dynamic • Stack dynamic • Heap dynamic • Slices • Associative arrays • Operations
Records • Definition • Mapping • Faster than array subscripts • Elliptical references (COBOL, PL/I) • Operations • Move corresponding
Unions • Definition • Not in Java • Type checking? • Ada yes, others no • Useful but dangerous
Sets • Pascal, Java
Pointers • Operations • Assignment and dereferencing • Dynamic storage management or indirect addressing? • Scope/lifetime of pointers and associated dynamic objects? • Problems • Dangling references, lost objects • Storage management • Reference counts, garbage collection • Java allows only references • Implicit deallocation