Records Design Issues: 1. What is the form of references?

Slides:



Advertisements
Similar presentations
ICE1341 Programming Languages Spring 2005 Lecture #13 Lecture #13 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Advertisements

CS 355 – 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.
ISBN Lecture 06 Data Types. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Lecture 06 Topics Introduction Primitive Data.
ISBN Chapter 7 Expressions and Assignment Statements.
ISBN Chapter 6 Data Types: Structured types.
CSE 452: Programming Languages Expressions and Control Flow.
ISBN Chapter 7 Expressions and Assignment Statements.
ISBN Lecture 07 Expressions and Assignment Statements.
Chapter 6 Structured Data Types Arrays Records. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Definitions data type –collection of data objects.
College of Computer Science and Engineering
Copyright © 1998 by Addison -Wesley Longman, Inc. 1 Chapter 6 Arithmetic Expressions - Their evaluation was one of the motivations for the development.
1-1 University of Hail College of Computer Science and Engineering Department of computer Science and Software Engineering Course: ICS313: Fundamentals.
7-1 Chapter 7: Expressions and Assignment Statements Arithmetic Expressions –the fundamental means of specifying computations in a programming language.
COMP4730/2002/lec7/H.Melikian Arithmetic Expressions Overloaded Operators Type Conversations Relational and Boolean Expressions Short Circuit Evaluation.
CS 363 Comparative Programming Languages Expressions and Assignment Statements.
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.
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.
Arithmetic Expressions
Chapter 7 © 1998 by Addison -Wesley Longman, Inc Arithmetic Expressions - Their evaluation was one of the motivations for the development of the.
Chapter 7 Expressions and Assignment Statements. Outline Introduction Arithmetic Expressions Overloaded Operators Type Conversions Assignment Statements.
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 © 2004 Pearson Addison-Wesley. All rights reserved.6-2 Chapter 6 Topics Introduction Primitive Data.
ISBN Chapter 7 Expressions and Assignment Statements.
CS 363 Comparative Programming Languages Data Types.
1 CS Programming Languages Class 09 September 21, 2000.
ISBN Chapter 6 Data Types Pointer Types Reference Types Memory Management.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
1 CS Programming Languages Class 08 September 19, 2000.
ISBN Chapter 6 Structured Data Types Array Types Associative Arrays Record Types Union 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.
Chapter 6 © 2002 by Addison Wesley Longman, Inc Introduction - Evolution of Data Types: FORTRAN I (1957) - INTEGER, REAL, arrays … Ada (1983) -
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 6 Chapter 6 Data Types. Data Types  A data type defines  a collection of data objects, and  a set of predefined operations on the objects type:
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.
Data Types Chapter 6: Data Types Lectures # 12. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.
7-1/27 Chapter 7 Expressions and Assignment Statements Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean.
Data Types Chapter 6: Data Types Lectures # 13. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.
5.2 Names - We discuss all user-defined names here
Expressions and Assignment Statements
Expressions and Assignment Statements
7.2 Arithmetic Expressions
6.1 Introduction 6.2 Primitive Data Types - Evolution of Data Types:
Data Types In Text: Chapter 6.
Chapter 6 – Data Types CSCE 343.
CMP 339/692 Programming Languages Day 14 Tuesday, March 20, 2012
Chapter 6 Data Types.
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
Expressions and Assignment Statements
Structure of Programming Language
CSE 452: Programming Languages
Expressions and Assignment Statements
Chapter 6 Data Types.
Data Types In Text: Chapter 6.
Arithmetic Expressions
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.
Expressions and Assignment Statements
College of Computer Science and Engineering
Names and Binding In Text: Chapter 5.
Chapter 6 Data Types.
Chapter 7 Expressions and Assignment Statements.
PRESENTED BY ADNAN M. UZAIR NOMAN
Chapter 6 Data Types Introduction:
Presentation transcript:

Records Design Issues: 1. What is the form of references? 2. What unit operations are defined?

Record Definition Syntax - COBOL uses level numbers to show nested records; others use recursive definitions 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 - Pascal and Modula-2 provide a with clause to abbreviate references

Record Operations 1. Assignment - Pascal, Ada, and C allow it if the types are identical - In Ada, the RHS can be an aggregate constant 2. Initialization - Allowed in Ada, using an aggregate constant 3. Comparison - In Ada, = and /=; one operand can be an aggregate constant

Comparing records and arrays 1. Access to array elements is much slower than access to record fields, because subscripts are dynamic (field names are static) 2. Dynamic subscripts could be used with record field access, but it would disallow type checking and it would be much slower

Pointers 1. Assignment of an address to a pointer A pointer type is a type in which the range of values consists of memory addresses and a special value, nil (or null) Uses: 1. Addressing flexibility 2. Dynamic storage management Fundamental Pointer Operations: 1. Assignment of an address to a pointer 2. References (explicit versus implicit dereferencing)

Design Issues 1. What is the scope and lifetime of pointer variables? 2. What is the lifetime of heap-dynamic variables? 3. Are pointers restricted to pointing at a particular type? 4. Are pointers used for dynamic storage management, indirect addressing, or both? 5. Should a language support pointer types, reference types, or both? 6. Pointer arithmetic?

Evaluation of Pointers 1. Dangling pointers and dangling objects are problems, as is heap management 2. Pointers are like goto's - they widen the range of cells that can be accessed by a variable 3. Pointers are necessary - so we can't design a language without them

Unions A union is a type whose variables are allowed to store different type values at different times during execution Design Issues for unions: 1. What kind of type checking, if any, must be done? 2. Should unions be integrated with records?

Examples: 1. FORTRAN - EQUIVALENCE 2. Algol has “discriminated unions” - Use a hidden tag to maintain the current type - Tag is implicitly set by assignment - References are legal only in conformity clauses - This runtime type selection is a safe method of accessing union objects 3. Pascal - both discriminated and non-discriminated unions are used e.g. type intreal = record tag : Boolean of true : (blint : integer); false : (blreal : real); end;

- Problem with Pascal’s design is that type checking is ineffective - Reasons: a. User can create inconsistent unions (because the tag can be individually assigned) var blurb : intreal; x : real; blurb.tagg := true; { it is an integer } blurb.blint := 47; { ok } blurb.tagg := false; { it is a real } x := blurb.blreal; { assigns an integer to a real } b. The tag is optional!

- Discriminated unions are safer than Pascal & Modula-2 - Reasons 4. Ada - Discriminated unions are safer than Pascal & Modula-2 - Reasons a. Tag must be present b. It is impossible for the user to create an inconsistent union (because tag cannot be assigned by itself) - All assignments to the union must include the tag value) 5. C and C++ have free unions (no tags) - Not part of their records - No type checking of references 6. Java has neither records nor unions - Unions are potentially unsafe in most languages (except Ada)

Arithmetic Expressions Arithmetic expressions consist of operators, operands, parentheses, and function calls

Design issues for arithmetic expressions: 1. What are the operator precedence rules? 2. What are the operator associativity rules? 3. What is the order of operand evaluation? 4. Are there restrictions on operand evaluation side effects? 5. Does the language allow user-defined operator overloading? 6. What mode mixing is allowed in expressions? 7. Conditional expressions?