Data Types Chapter 6: Data Types Lectures # 12. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.

Slides:



Advertisements
Similar presentations
Slide: 1 Copyright © AdaCore Record Types Presented by Quentin Ochem university.adacore.com.
Advertisements

Chapter 6 Type Checking. The compiler should report an error if an operator is applied to an incompatible operand. Type checking can be performed without.
Programming Languages and Paradigms
Chapter 7:: Data Types Programming Language Pragmatics
Data Types Programming languages need a variety of data types in order to better model/match the world more data types make programming easier but too.
CSCI 330: Programming Language Concepts Instructor: Pranava K. Jha
Chapter Four Data Types Pratt 2 Data Objects A run-time grouping of one or more pieces of data in a virtual machine a container for data it can be –system.
CS 331, Principles of Programming Languages Chapter 4 Types: Data Representation.
Type Checking.
Chapter 6 Structured Data Types Arrays Records. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Definitions data type –collection of data objects.
ISBN Chapter 6 Data Types: Structured types.
G. Levine Chapter 6 Chapter 6 Encapsulation –Why do we want encapsulation? Programmer friendliness- programmer need not know about these details –Easier.
ISBN 0-321— Chapter 6 Data Types. Copyright © 2007 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
Lecture 6 Concepts of Programming Languages
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.
Programming Language Concepts
More High-Level Concepts
ISBN 0-321— Chapter 6 Data Types. Copyright © 2007 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Topics Associative Arrays Record Types Tuple Types List Types Union Types.
Names Variables Type Checking Strong Typing Type Compatibility 1.
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.
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.
Ch. 5 Ch. 51 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (more notes) Dr. Carter Tiernan.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
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.
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
ISBN 0-321— Chapter 6 Data Types. Copyright © 2007 Addison-Wesley. All rights reserved.1-2 Chapter 6 Topics Introduction Primitive Data Types Character.
Structure of Programming Language Data Types. 2 A data type defines a collection of data objects and a set of predefined operations on those objects An.
C H A P T E R S I X Data Types.
Various languages….  Union Types Ada – compare to classes  Coroutines  Nested methods  Lexical (static) vs. Dynamic Scope  Referencing Environments.
1 CS Programming Languages Class 08 September 19, 2000.
ISBN Chapter 6 Structured Data Types Array Types Associative Arrays Record Types Union Types.
Ch. 5 Ch. 51 jcmt Summer 2003Programming Languages CSE3302 Programming Languages (more notes) Summer 2003 Dr. Carter Tiernan.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved. 6-2 Chapter 6 Topics Introduction Primitive Data 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.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Chapter 6 © 2002 by Addison Wesley Longman, Inc Introduction - Evolution of Data Types: FORTRAN I (1957) - INTEGER, REAL, arrays … Ada (1983) -
Names and Binding In Text: Chapter 4.
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.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Structure of Programming Language Data Types. 2 A data type defines a collection of data objects and a set of predefined operations on those objects An.
Records type city is record -- Ada Name: String (1..10); Country : String (1..20); Population: integer; Capital : Boolean; end record; struct city { --
Data Types Chapter 6: Data Types Lectures # 13. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.
Data Types Chapter 6: Data Types Lectures # 11. Topics Introduction Primitive Data Types Character String Types Array Types Associative Arrays Record.
More High-Level Concepts
Data Types In Text: Chapter 6.
Dr. Vamsi Paruchuri University of Central Arkansas
Chapter 6 Data Types.
Chapter 6 – Data Types CSCE 343.
CMP 339/692 Programming Languages Day 14 Tuesday, March 20, 2012
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:
Chapter 6: Data Types Lectures # 10.
Structure of Programming Language
Records Design Issues: 1. What is the form of references?
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.
Here are four triangles. What do all of these triangles have in common
Chapter 6 Data Types.
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Presentation transcript:

Data Types Chapter 6: Data Types Lectures # 12

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

Record types A record is a possibly heterogeneous aggregate of data elements in which the individual elements are identified by names. Records were introduced in COBOL and are implemented in most modern programming languages. Chapter 6: Data Types 3

Definition of Records :COBOL COBOL uses level numbers to show nested records; others use recursive definition. 01 EMP-REC. 02 EMP-NAME. 05 FIRST PIC X(20). 05 MID PIC X(10). 05 LAST PIC X(20). 02 HOURLY-RATE PIC 99V99. Chapter 6: Data Types 4

Definition of Records : Ada type Emp_Rec_Type is record First: String (1..20); Mid: String (1..10); Last: String (1..20); Hourly_Rate: Float; end record; Emp_Rec: Emp_Rec_Type; Chapter 6: Data Types 5

References to Records Fully qualified references must include all record names. Elliptical references allow leaving out record names as long as the reference is unambiguous, Example in COBOL: FIRST, FIRST OF EMP-NAME, and FIRST of EMP-REC are elliptical references to the employee’s first name. Pascal and Modula 02 provide a with clause to abbreviate references. Chapter 6: Data Types 6

Records vs. Arrays Array elements all have the same type and are processed in the same way. Record elements may have different types and are processed using operations unique to that type. Access to array elements is slower than access to record fields, because:  Subscripts are dynamically calculated.  Field offsets are statically calculated. Chapter 6: Data Types 7

Unions Types A union is a type whose variables are allowed to store different type values at different times during execution. A free union is a union for which there is no language support for type checking. Programmers are allowed complete freedom from type checking in their use. FORTRAN, C, and C++ have this kind of union. A discriminated union has a field that indicates the type of the data in the union. This field is called a discriminant. Pascal and Ada have discriminated unions.  Algol 68 was the first language provide discriminated union. Chapter 6: Data Types 8

Pascal variant records Example of a Pascal record with a variant part: type shape = (circle, triangle, rectangle); colors = (red, green, blue); figure = record filled : boolean; color : colors; case form : shape of circle : (diameter : real); triangle : (leftside : integer; rightside : integer; angle : real); rectangle: (side1, side2 : integer); end; var myfigure : figure; Variant part Chapter 6: Data Types 9

Pascal does no runtime type checking of variant records, so inconsistent unions can be created: myfigure.filled := true; myfigure.color := red; myfigure.form := circle; myfigure.side1 := 5; It is the programmer’s responsibility to ensure that the data remains consistent. Furthermore, the tag field is optional! Ada’s discriminated records are type-safe because:  Tag field must be present.  All assignments to the union must include the tag field. Pascal variant records (cont.) Chapter 6: Data Types 10

Ada discriminated unions type shape is (circle, triangle, rectangle); type colors is (red, green, blue); type figure (form : shape) is record filled : boolean; color : colors; case form is when circle => diameter : float; when triangle => leftside : integer; rightside : integer; angle : float; rectangle: side1, side2 : integer; end case; end record; Chapter 6: Data Types 11

Ada discriminated union (cont.) Figure_1 : figure; Figure_2 : Figure(form => triangle); Figure_1 := (filled => true,color => blue,form => rectangle, side_1 => 12,side_2 => 3); Figure_1 is declared to be unconstrained variant record that has no initial value. Figure_2 is constrained to be a triangle and cannot be changed to another variant. Chapter 6: Data Types 12

Evaluation of Unions Potentially unsafe construct:  Do not allow type checking. Java and C# do not support unions.  Reflective of growing concerns for safety in programming language. Chapter 6: Data Types 13