Record Types. A record is a possibly heterogeneous aggregate of data elements in which the individual elements are identified by names Design issues:

Similar documents
Array Initialization. Rectangular and Jagged Arrays. Arrays Operations. ICOM 4036 Programming Languages. Data Types

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types

Chapter 6. Data Types

Chapter 6. Data Types ISBN

Chapter 6. Data Types ISBN

A data type defines a collection of data objects and a set of predefined operations on those objects

Software II: Principles of Programming Languages

Chapter 6. Structured Data Types. Topics. Structured Data Types. Vectors and Arrays. Vectors. Vectors: subscripts

For each of the following variables named x, specify whether they are static, stack-dynamic, or heapdynamic:

Organization of Programming Languages CS3200 / 5200N. Lecture 06

Chapter 6. Data Types. *modified by Stephanie Schwartz ISBN

Chapter 6. Data Types ISBN

Data Types In Text: Ch C apter 6 1

CPSC 3740 Programming Languages University of Lethbridge. Data Types

Concepts of Programming Languages (750321)

Data Types. Outline. In Text: Chapter 6. What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 5-1. Chapter 6: Data Types 2

CSE 452: Programming Languages. Where are we? Types: Intuitive Perspective. Data Types. High-level Programming Languages.

Organization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science

COSC252: Programming Languages: Basic Semantics: Data Types. Jeremy Bolton, PhD Asst Teaching Professor

Chapter 6 Data Types 1

Data Types. Data Types. Introduction. Data Types. Data Types. Data Types. Introduction

Nets and Drawings for Visualizing Geometry. Unit 1 Lesson 1

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

Example: Haskell algebraic data types (1)

Chapter 7:: Data Types. Mid-Term Test. Mid-Term Test (cont.) Administrative Notes

Introduction. Primitive Data Types: Integer. Primitive Data Types. ICOM 4036 Programming Languages

4 Bindings and Scope. Bindings and environments. Scope, block structure, and visibility. Declarations. Blocks. 2004, D.A. Watt, University of Glasgow

Fundamentals of Programming Languages

Basic Types & User Defined Types

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Chapter 8. Statement-Level Control Structures

Chapter 10. Implementing Subprograms ISBN

Chapter 6 part 1. Data Types. (updated based on 11th edition) ISBN

Topic 7: Algebraic Data Types

Programming Languages

Fundamentals of Programming Languages. Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila

Chapter 8. Statement-Level Control Structures

Chapter 5 Names, Bindings, Type Checking, and Scopes

CS 314 Principles of Programming Languages. Lecture 13

Chapter 6: Programming Languages

CSCI312 Principles of Programming Languages!

CS 230 Programming Languages

CS558 Programming Languages

Programming Languages

22c:111 Programming Language Concepts. Fall Types I

Announcements/Follow-ups

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

Note first midterm date: Wed. evening, Feb. 23 Today's class: Types in OCaml and abstract syntax

Type Bindings. Static Type Binding

Control Flow February 9, Lecture 7

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

History. used in early Mac development notable systems in Pascal Skype TeX embedded systems

IV Unit Second Part STRUCTURES

Chapter 7. Expressions and Assignment Statements ISBN

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

NOTE: Answer ANY FOUR of the following 6 sections:

MIDTERM EXAMINATION - CS130 - Spring 2005

Information Systems. Database System Architecture. Relational Databases. Nikolaj Popov

UNIT-V. Structures. The general syntax of structure is given below: Struct <tagname> { datatype membername1; datatype membername2; };

C-LANGUAGE CURRICULAM

Beginning Programming (Two Semesters) Semester One. Module One: Intro to Beginning Programming. Module Two: Computer Careers

Chapter 5. Names, Bindings, and Scopes

Types. What is a type?

IDENTIFY WAYS OF REPRESENTING ALGORITHMS.

LECTURE 18. Control Flow

Chapter 8. Statement-Level Control Structures ISBN

Data Structures Unit 02

COS 140: Foundations of Computer Science

CA341 - Comparative Programming Languages

CSC 467 Lecture 13-14: Semantic Analysis

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

MIDTERM EXAMINATION - CS130 - Spring 2003

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 6 Outline. Unary Relational Operations: SELECT and

Chapter 2 Exercise Solutions

Programming Languages Third Edition. Chapter 7 Basic Semantics

Aim: How do we find the volume of a figure with a given base? Get Ready: The region R is bounded by the curves. y = x 2 + 1

SE352b: Roadmap. SE352b Software Engineering Design Tools. W3: Programming Paradigms

COSC 2P90 Programming Languages & Object-Orientation

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Example of Objective Test Questions for Test 4

Fundamental Concepts and Definitions

Subprograms. Copyright 2015 Pearson. All rights reserved. 1-1

Concepts of Programming Languages

Typed Racket: Racket with Static Types

G Programming Languages - Fall 2012

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

C# and Java. C# and Java are both modern object-oriented languages

CISC 1600 Lecture 3.1 Introduction to Processing

Advanced features of Functional Programming (Haskell)

CSc 520 Principles of Programming Languages. 26 : Control Structures Introduction

The New C Standard (Excerpted material)

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

Chapter 8. Statement-Level Control Structures

Programming Languages CRN Test 2 Version 1 CMSC 4023 Autumn 2013

COS 140: Foundations of Computer Science

Chapter 8 :: Composite Types

CS 314 Principles of Programming Languages

CSC 533: Organization of Programming Languages. Spring 2005

LECTURE 17. Expressions and Assignment

Transcription:

Record Types A record is a possibly heterogeneous aggregate of data elements in which the individual elements are identified by names Design issues: o What is the syntactic form of references to the field? o Are elliptical references allowed 6-37

Definition of Records in 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. 6-38

Definition of Records in Ada Record structures are indicated in an orthogonal way 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; 6-39

References to Records Record field references 1. COBOL field_name OF record_name_1 OF... OF record_name_n 2. Others (dot notation) record_name_1.record_name_2.... record_name_n.field_name Fully qualified references must include all record names Elliptical references allow leaving out record names as long as the reference is unambiguous, for example in COBOL FIRST, FIRST OF EMP-NAME, and FIRST of EMP- REC are elliptical references to the employee s first name 6-40

Operations on Records Assignment is a common operation o if the types are identical Ada allows record comparison COBOL provides MOVE CORRESPONDING o Copies a field of the source record to the corresponding field in the target record 6-41

Evaluation and Comparison to Arrays Access to array elements is much slower than access to record fields, because subscripts are dynamic (field names are static) Dynamic subscripts could be used with record field access, but it would disallow type checking and it would be much slower 6-42

Implementation of Record Type Offset address relative to the beginning of the records is associated with each field 6-43

Union Types A union is a type whose variables are allowed to store different type values at different times during execution Design issues o Should type checking be required? o Should unions be embedded in records? 6-44

Discriminated vs. Free Unions Fortran, C, and C++ provide union constructs in which there is no language support for type checking; o Called free union Type checking of unions require that each union include a type indicator called a discriminant o Supported by Ada 6-45

Ada Union Types 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, Rightside: Integer; Angle: Float; when Rectangle => Side1, Side2: Integer; end case; end record; 6-46

Ada Union Type Illustrated A discriminated union of three shape variables 6-47 Copyright 2009 Addison- Wesley. All rights reserved.

Evaluation of Unions Free unions are unsafe o Do not allow type checking Java and C# do not support unions o Reflective of growing concerns for safety in programming language 6-48

Name Type Equivalence Name type equivalence means the two variables have equivalent types if they are in either the same declaration or in declarations that use the same type name 6-49

Structure Type Equivalence Structure type equivalence means that two variables have equivalent types if their types have identical structures More flexible, but harder to implement 6-50

Type Equivalence (continued) Consider the problem of two structured types: o Are two record types equivalent if they are structurally the same but use different field names? o Are two array types equivalent if they are the same except that the subscripts are different? (e.g. [1..10] and [0..9]) 6-51

Type Equivalence (continued) o Are two enumeration types equivalent if their components are spelled differently? o With structural type equivalence, you cannot differentiate between types of the same structure (e.g. different units of speed, both float) Copyright 2009 Addison Wesley. All rights reserved. 1 52