Data Types Chapter 6: Data Types Lectures # 11. Topics Introduction Primitive Data Types Character String Types Array Types Associative Arrays Record.

Slides:



Advertisements
Similar presentations
Names and Bindings.
Advertisements

ICE1341 Programming Languages Spring 2005 Lecture #9 Lecture #9 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Chapter 6 Structured Data Types Arrays Records. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Definitions data type –collection of data objects.
ISBN Lecture 06 Data Types. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Lecture 06 Topics Introduction Primitive Data.
CS 330 Programming Languages 11 / 06 / 2007 Instructor: Michael Eckmann.
Lifetime “The lifetime of a variable is the time during which the variable is bound to a specific memory location.” [p. 219] “…the lifetime of a variable.
ISBN Chapter 6 Data Types: Structured types.
CS 330 Programming Languages 11 / 07 / 2006 Election Day Instructor: Michael Eckmann.
CS 330 Programming Languages 11 / 08 / 2007 Instructor: Michael Eckmann.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Definitions A data type defines a collection of data.
ISBN 0-321— Chapter 6 Data Types. Copyright © 2007 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
Chapter 6 Structured Data Types Arrays Records. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Definitions data type –collection of data objects.
Data Types. Primitives Integer Float Character Boolean Pointers Aggregates Strings Records Enumerated Arrays Objects.
CS 355 – Programming Languages
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
ISBN 0-321— Chapter 6 Data Types. Copyright © 2007 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
College of Computer Science and Engineering
CS 355 – PROGRAMMING LANGUAGES Dr. X. Topics Associative Arrays Record Types Tuple Types List Types Union Types.
ISBN 0-321— Chapter 6 Data Types. Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley.
5-1 Chapter 5: Names, Bindings, Type Checking, and Scopes Variables The Concept of Binding Type Checking Strong Typing Type Compatibility Scope and Lifetime.
1 Data Types In Text: Chapter 5. 2 Chapter 5: Data Types Outline What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers.
6-1 Chapter 6: Data Types Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types.
Storage Bindings Allocation is the process by which the memory cell or collection of memory cells is assigned to a variable. These cells are taken from.
Introduction A variable can be characterized by a collection of properties, or attributes, the most important of which is type, a fundamental concept in.
Basic Semantics Associating meaning with language entities.
ISBN 0-321— Chapter 6 Structured Data Types Arrays Associated Arrays Records Unions.
1 Records Record aggregate of data elements –Possibly heterogeneous –Elements/slots are identified by names –Elements in same fixed order in all records.
CS 330 Programming Languages 11 / 04 / 2008 Election Day Instructor: Michael Eckmann.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
CS 330 Programming Languages 11 / 09 / 2006 Instructor: Michael Eckmann.
ISBN Chapter 6 Data Types. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Chapter 6 Topics Introduction Primitive Data.
ISBN 0-321— Chapter 6 Data Types. Copyright © 2007 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
C H A P T E R S I X Data Types.
CS 363 Comparative Programming Languages Data Types.
1 CS Programming Languages Class 08 September 19, 2000.
ISBN Chapter 6 Structured Data Types Array Types Associative Arrays Record Types Union Types.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
1 Data Types Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer Types.
Data Types W E E K F O U R. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character String.
Copyright © 2006 Addison-Wesley. All rights reserved. 6-1 Subscript Bindings and Array Categories In some languages the lower bound of the subscript range.
Chapter 6 © 2002 by Addison Wesley Longman, Inc Introduction - Evolution of Data Types: FORTRAN I (1957) - INTEGER, REAL, arrays … Ada (1983) -
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved.2 Primitive Data Types Almost all programming languages.
Copyright © 1998 by Addison Wesley Longman, Inc. 1 Chapter 5 Evolution of Data Types: FORTRAN I (1956) - INTEGER, REAL, arrays … Ada (1983) - User can.
CHAPTER 4 VARIABLES & BINDING SUNG-DONG KIM DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
CSI 3125, Data Types, page 1 Data types Outline Primitive data types Structured data types Strings Enumerated types Arrays Records Pointers Reading assignment.
Data Types Chapter 6: Data Types Lectures # 13. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.
Chapter 5 Names, Bindings, Type Checking CSCE 343.
CSC 533: Programming Languages Spring 2016
Data Types In Text: Chapter 6.
Dr. Vamsi Paruchuri University of Central Arkansas
Chapter 6 – Data Types CSCE 343.
CSC 533: Programming Languages Spring 2015
CMP 339/692 Programming Languages Day 14 Tuesday, March 20, 2012
Chapter 6 Data Types.
Concepts of Programming Languages
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
6.1 Introduction 6.2 Primitive Data Types - Evolution of Data Types:
Type Checking, and Scopes
Chapter 6: Data Types Lectures # 10.
Concepts of programming languages Names, Bindings, and Scopes
Data Types In Text: Chapter 6.
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.
Chapter 6 Data Types.
Chapter 6 Data Types.
Chapter 6 Data Types.
Chapter 6 Data Types.
Chapter 6 Data Types.
Presentation transcript:

Data Types Chapter 6: Data Types Lectures # 11

Topics Introduction Primitive Data Types Character String Types Array Types Associative Arrays Record Types Union Types Pointer and Reference Types Chapter 6: Data Types 2

Array Types An array is a homogeneous aggregate of data elements in which an element is identified by its position in the aggregate, relative to the first element. References to elements include one or more subscripts. References require a runtime computation to determine the location being referenced. Array types are implemented in most programming languages. Chapter 6: Data Types 3

Categories of Arrays Five categories of arrays based on subscript range binding and storage binding:  Static.  Fixed stack dynamic.  Stack dynamic.  Fixed heap dynamic.  Heap dynamic. Chapter 6: Data Types 4

Categories of Arrays: Static Arrays Static arrays are those in which:  Subscript ranges are statically bound.  Storage bindings are static. Advantage: execution efficiency since no dynamically allocation/deallocation is required. FORTRAN arrays are static. Chapter 6: Data Types 5

Categories of Arrays: Fixed Stack-Dynamic Arrays Fixed stack-dynamic arrays are those in which:  Subscript ranges are statically bound.  Allocation is done at declaration elaboration time. Advantage is space efficiency.  Storage is allocated only while block in which array is declared is active. Pascal local arrays. Chapter 6: Data Types 6

Categories of Arrays: Stack-dynamic arrays A stack-dynamic array is one in which:  Subscript ranges are dynamically bound.  Storage allocation is done at runtime.  Both remain fixed during the lifetime of the variable. Advantage: flexibility. Ada has this kind of array: get N declare ARR : array(1..N) of INTEGER; begin … end;  In this example the user inputs N. The elements are then dynamically allocated when execution reaches the declare block. Chapter 6: Data Types 7

Categories of Arrays: Fixed Heap-dynamic arrays Fixed Heap-dynamic array is similar to fixed stack-dynamic array in which:  Storage binding is dynamic but fixed after allocation. Difference between fixed heap and fixed stack:  Binding is done when requested rather than at elaboration time.  Storage is allocated from heap not stack. C and C++ allow dynamic arrays via:  malloc and free.  new and delete. Chapter 6: Data Types 8

Categories of Arrays: Fixed Heap-dynamic arrays (cont.) In Java all arrays are fixed-heap dynamic. C# includes a second array class ArrayList that provides fixed heap-dynamic. Fortran 95 support fixed-heap dynamic. INTEGER ALLOCATABLE, ARRAY(:,:) :: MAT ALLOCATE (MAT(10, 20)) …… DEALLOCATE(MAT(10, 20)) Chapter 6: Data Types 9

Categories of Arrays: Heap-dynamic Arrays A heap-dynamic array is one in which:  Subscript range binding is dynamic.  Storage allocation is dynamic.  Either can change any number of times during execution. Arrays can grow and shrink as the need arises. C# provides heap dynamic arrays.  Object of this class is created without any elements as in: ArrayList intList = new arrayList(); Perl and JavaScript also support heap-dynamic arrays. Chapter 6: Data Types 10

Array initialization FORTRAN: INTEGER LIST(3) DATA LIST /10, 20, 30/ C, C++: int list[] = {10, 20, 30}; char name[] = “bob”; char* names[] = {“bob”,”sue”,”tom”}; Java: String[]names = {“bob”,”sue”,”tom”}; Ada: LIST: array(1..5) of INTEGER := (1,2,3,4,5); LIST2: array(1..10) of INTGEGER := (1 => 10, 2..5 => 100, others => 0); Chapter 6: Data Types 11

Array implementation Compile-time descriptor for a 1 -dimensional array may include:  Element type.  Index type.  Index lower bound.  Index upper bound.  Address. For multi-dimensional arrays, information about each index range must be stored. Chapter 6: Data Types 12

Row- vs Column-major order Chapter 6: Data Types 13

Associative arrays An associative array is an unordered collection of data elements that are indexed by an equal number of values called keys. The keys are stored in the structure. Thus, element is a (key, value) pair. Design issues:  What is the form of references to elements. Chapter 6: Data Types 14

Associative Arrays in Perl Names begin with %; literals are delimited by parentheses %hi_temps = ("Mon" => 77, "Tue" => 79, “Wed” => 65, … );  Subscripting is done using braces and keys: $hi_temps{"Wed"} = 83;  Elements can be removed with delete : delete $hi_temps{"Tue"};  The entire hash can be emptied by assigning the empty literal to it: $hi_temps = (); Chapter 6: Data Types 15