UT Dallas CS 4337 - #Sebesta ch06 data type - short version cs4337 (84 pages)

Previewing pages 1, 2, 3, 4, 5, 6, 39, 40, 41, 42, 43, 79, 80, 81, 82, 83, 84 of 84 page document View the full content.
View Full Document

#Sebesta ch06 data type - short version cs4337



Previewing pages 1, 2, 3, 4, 5, 6, 39, 40, 41, 42, 43, 79, 80, 81, 82, 83, 84 of actual document.

View the full content.
View Full Document
View Full Document

#Sebesta ch06 data type - short version cs4337

30 views


Pages:
84
School:
University of Texas at Dallas
Course:
Cs 4337 - Organization of Programming Languages
Unformatted text preview:

Chapter 6 Data Types Chapter 6 Topics Introduction Primitive Data Types Character String Types User Defined Ordinal Types Array Types Associative Arrays Record Types Tuple Types List Types Union Types Pointer and Reference Types Type Checking Strong Typing Type Equivalence Theory and Data Types Copyright 2012 Addison Wesley All rights reserved 1 2 Introduction A Data type defines a collection of data objects and a set of predefined operations on those objects A Descriptor is the collection of the attributes of a variable An Object represents an instance of a userdefined abstract data type One design issue for all data types What operations are defined How are they specified Copyright 2012 Addison Wesley All rights reserved 1 3 Primitive Data Types Almost all programming languages provide a set of primitive data types Primitive data types Those not defined in terms of other data types Some primitive data types are merely reflections of the hardware Others require only a little non hardware support for their implementation Copyright 2012 Addison Wesley All rights reserved 1 4 Primitive Data Types 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 Java s signed integer sizes byte short int long Copyright 2012 Addison Wesley All rights reserved 1 5 Primitive Data Types Floating Point Model real numbers but only as approximations Languages for scientific use support at least two floating point types e g float and double sometimes more Usually exactly like the hardware but not always IEEE Floating Point Standard 754 Copyright 2012 Addison Wesley All rights reserved 1 6 Primitive Data Types Complex Number Some languages support a complex type e g C99 Fortran and Python Each value consists of two floats the real part and the imaginary part Literal form in Python 7 3j where 7 is the real part and 3 is the imaginary part In Lisp C 7 3 Copyright 2012 Addison Wesley All rights reserved 1 7 Primitive Data Types Decimal For business applications money Essential to COBOL Using 4 bits as a nibble So 1 byte for 2 decimal digits C offers a decimal data type Store a fixed number of decimal digits in coded form BCD Using 1 byte for a digit where 4 bits for a decimal digit and 4 bits for sign Advantage accuracy Copyright 2012 Addison Wesley All rights reserved 1 8 Primitive Data Types Boolean Simplest of all Range of values two elements one for true and one for false Could be implemented as bits but often as bytes Advantage readability Copyright 2012 Addison Wesley All rights reserved 1 9 Primitive Data Types Character Stored as numeric coding Most commonly used coding ASCII An alternative 16 bit coding Unicode UCS2 Includes characters from most natural languages Originally used in Java C and JavaScript also support Unicode 32 bit Unicode UCS 4 Supported by Fortran starting with 2003 Copyright 2012 Addison Wesley All rights reserved 1 10 Character String Types Values are sequences of characters Design issues Is it a primitive type or just a special kind of array Should the length of strings be static or dynamic Copyright 2012 Addison Wesley All rights reserved 1 11 Character String Types Operations Typical operations Assignment and copying Comparison etc Concatenation Substring reference Pattern matching Copyright 2012 Addison Wesley All rights reserved 1 12 Character String Type in Certain Languages C and C Not primitive Use char arrays and a library of functions that provide operations SNOBOL4 a string manipulation language Primitive Many operations including elaborate pattern matching Fortran and Python Primitive type with assignment and several operations Java Primitive via the String class Perl JavaScript Ruby and PHP Provide built in pattern matching using regular expressions Copyright 2012 Addison Wesley All rights reserved 1 13 Character String Length Options 1 Static COBOL Java s String class 2 Limited Dynamic Length C and C In these languages a special character is used to indicate the end of a string s characters rather than maintaining the length 3 Dynamic no maximum SNOBOL4 Perl JavaScript Ada supports all three string length options Copyright 2012 Addison Wesley All rights reserved 1 14 Compile Time Run Time Descriptors Compile time descriptor for static strings Copyright 2012 Addison Wesley All rights reserved Run time descriptor for limited dynamic strings 1 15 Character String 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 run time overhead allocation deallocation is the biggest implementation problem e g fragmentation which chunk to be allocated best fit first fit Copyright 2012 Addison Wesley All rights reserved 1 16 User Defined Ordinal Types An ordinal type is one in which the range of possible values can be easily associated with the set of positive integers Examples of primitive ordinal types in Java integer char boolean Copyright 2012 Addison Wesley All rights reserved 1 17 Enumeration Types All possible values which are named constants are provided in the definition C example enum days mon tue wed thu fri sat sun Design issues Is an enumeration constant allowed to appear in more than one type definition and if so how is the type of an occurrence of that constant checked Are enumeration values coerced to integer Any other type coerced to an enumeration type Copyright 2012 Addison Wesley All rights reserved 1 18 Subrange Types operator An ordered contiguous subsequence of an ordinal type Example 12 18 is a subrange of integer type Ada s design type Days is mon tue wed thu fri sat sun subtype Weekdays is Days range mon fri subtype Index is Integer range 1 100 Day1 Days Day2 Weekday Day2 Day1 Copyright 2012 Addison Wesley All rights reserved 1 19 Array Types An array is a homogeneous aggregate of data elements in which an individual element is identified by its position in the aggregate relative to the first element Copyright 2012 Addison Wesley All rights reserved 1 20 Array Design Issues What types are legal for subscripts Are subscripting expressions in element references range checked When are subscript ranges bound When does allocation take place Are ragged or rectangular multidimensional arrays allowed or both What is the maximum number of subscripts Can array objects be initialized Are any kind of slices supported Copyright 2012 Addison Wesley


View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view #Sebesta ch06 data type - short version cs4337 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view #Sebesta ch06 data type - short version cs4337 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?