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.

Slides:



Advertisements
Similar presentations
Symbol Table.
Advertisements

Arrays and records Programming Language Design and Implementation
Names and Bindings.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Chapter 9 Subprograms Specification: name, signature, actions Signature: number and types of input arguments, number and types of output results –Book.
Chapter 7:: Data Types Programming Language Pragmatics
Various languages….  Could affect performance  Could affect reliability  Could affect language choice.
Elementary Data Types Prof. Alamdeep Singh. Scalar Data Types Scalar data types represent a single object, i.e. only one value can be derived. In general,
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Type Checking.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
Chapter 6 Structured Data Types Arrays Records. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Definitions data type –collection of data objects.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
Names, Bindings, Type Checking, and Scopes
1 Names, Scopes and Bindings. 2 Names Kinds of names Kinds of names Variables, functions, classes, types, labels, blocks, operators, tasks, etc. Variables,
ISBN Chapter 6 Data Types: Structured types.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes Names Variables The Concept of Binding Type Checking Strong Typing Type Compatibility.
G. Levine Chapter 6 Chapter 6 Encapsulation –Why do we want encapsulation? Programmer friendliness- programmer need not know about these details –Easier.
Copyright © 1995 by Addison-Wesley Publishing Co. 1 Names - Design issues: - Maximum length? - Are connector characters allowed? - Are names case sensitive?
CS 330 Programming Languages 10 / 24 / 2006 Instructor: Michael Eckmann.
Elementary Data Types Scalar Data Types Numerical Data Types Other
PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ04A - Scalar and composite data Programming Language.
Structured Data Types and Encapsulation Mechanisms to create new data types: –Structured data Homogeneous: arrays, lists, sets, Non-homogeneous: records.
Names and Bindings Introduction Names Variables The concept of binding Chapter 5-a.
Chapter 6 Structured Data Types Arrays Records. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Definitions data type –collection of data objects.
MT311 Java Application Programming and Programming Languages Li Tak Sing ( 李德成 )
1 Chapter 5: Names, Bindings and Scopes Lionel Williams Jr. and Victoria Yan CSci 210, Advanced Software Paradigms September 26, 2010.
1 Programming Languages Implementation of Data Structures Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
1 CS Programming Languages Class 07 September 14, 2000.
Names Variables Type Checking Strong Typing Type Compatibility 1.
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 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Elsa Gunter who’s.
March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341)
Compiler Construction
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.
CSE 425: Data Types I Data and Data Types Data may be more abstract than their representation –E.g., integer (unbounded) vs. 64-bit int (bounded) A language.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
1 Records Record aggregate of data elements –Possibly heterogeneous –Elements/slots are identified by names –Elements in same fixed order in all records.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 9.
PZ06C Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06C - Polymorphism Programming Language Design and.
Polymorphism Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 7.3.
COMP3190: Principle of Programming Languages
Chapter 4 of Programming Languages by Ravi Sethi.
Structure of Programming Languages Names, Bindings, Type Checking, and Scopes.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
Names and Binding In Text: Chapter 4.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
Implementing Subprograms
Overview: Lecture 6: Dolores Zage. What is a program? n Operations that are to be applied to certain data in a certain sequence (definition holds for.
Names, Scope, and Bindings Programming Languages and Paradigms.
Names, Bindings, Type Checking and Scopes. Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Type Equivalence.
1 Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSI 3125, Data Types, page 1 Data types Outline Primitive data types Structured data types Strings Enumerated types Arrays Records Pointers Reading assignment.
Dr. M. Al-Mulhem Introduction 1 Chapter 6 Type Systems.
Object Lifetime and Pointers
Data Types In Text: Chapter 6.
Chapter 6 – Data Types CSCE 343.
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Type Checking, and Scopes
Data Structures Interview / VIVA Questions and Answers
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.
Names and Binding In Text: Chapter 5.
Presentation transcript:

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 defined –programmer defined

3 Attributes and Bindings Type Location Value Name

4 Data Types A data type is a class of data objects together with a set of operations for creating and manipulating them. Specification of a data type: –attributes –valid values –valid operations example: specification of an array

5 Data Types Implementation of a data type –storage representation of data object –algorithms of valid operations Syntactic representation

6 Elementary Data Types Elementary data object contains a single data value. A class of such data objects and the valid operations: elementary data type.

7 Operations Signature of an operation: op name: arg type * arg type * … *arg type --> result type

8 Operations as Mathematical Functions Undefined for certain inputs. –Underflow, overflow Implicit arguments. Side effects (implicit results). Self-modification (history sensitive)

9 Implementation Storage representation. –Attributes: not stored in the runtime storage representation run time descriptor implementation of operations

10 Declarations Choice of storage representation Storage management Polymorphic operations Type checking

11 Type Checking Checking that each operation executed by a program receives the proper number of arguments of the proper data type. Dynamic type checking: run-time (type tags for data objects) Static type checking: compile-time

12 Dynamic Type Checking Advantage: Flexibility Disadvantages: –difficult debugging, some paths never checked. –Extra storage for type information during program execution. –Software simulated type checking, reducing speed.

13 Static Type Checking Information required: –For each operation, the number, order, and data types of its arguments and results. –For each variable, the type of data object named. Always A has the same type (a formal parameter). –The type of each constant data object.

14 Strong Typing. –Detect all type errors statically. f f : S --> R f R. –A function f, with signature f : S --> R, is type safe if execution of f cannot generate a value outside of R. –Type inference. ML (p.124)

15 Type Conversion and Coercion A type mismatch can cause : –error –coercion (implicit type conversion) type conversion: –conversion-op : type1 --> type2 coercions if no loss of information. –Widening or promotion –Narrowing

16 What about Coercion – for dynamic type checking? – for static type checking? ( Code inserted during compilation) (p. 126)

17 Two Opposed Philosophies No coercions (Pascal, Ada) Coercion as a rule (C)

18 Assignment Assignment is the basic operation for changing the binding of a value to a data object. In Pascal: – assignment: integer * integer --> void In C: – assignment:integer * integer-->integer (p 127)

19 Initialization An uninitialized variable: an l-value with no corresponding r-value. A serious source of programming errors. Explicit, implicit.

20 Elementary Data Types Numeric Data Types –Integers –Subranges –Floating-point Real Numbers –Fixed-point Real Numbers Enumerations (one of a small number of symbolic values) Booleans Characters

21 Internationalization Sorting Case Scanning direction Country-specific data format Country-specific time format

22 Structured Data Objects and Data Types Structured data object or data structure: a data object that is constructed as an aggregate of other data objects, called components. Particular aspects of structured data types: –how to indicate the component data objects of a data structure and their relationships. –storage management.

23 Specification of data structure types Number of components. Type of each component. Names to be used for selecting components. Maximum number of components. Organization of the components.

24 Number of Components Fixed size. –Arrays, records, character strings. Variable size. –Stacks, lists, sets, tables, files, character strings. –Use a pointer data type. –Insert and delete operations.

25 Type of Each Component Homogeneous. –Arrays, character strings, sets, files. Heterogeneous. –Records, lists.

26 Names to be used for selecting components Array: an integer subscript or a sequence of subscripts. Record: a programmer defined identifier. Stacks and files: ?

27 Maximum number of components For a variable size data structure.

28 Organization of the components Simple linear sequence. –Vectors, records, strings, stacks, lists, files. Multidimensional. –Arrays, record, lists.

29 Operations on Data Structures Component selection operations. –Random selection –Sequential selection. How you select a component? Whole-data-structure operations. –Addition(arrays), assignment(records), union(sets). Insertion/deletion of components. Creation/deletion of data structures.

30 Implementation of Data Structure Types Storage Representation : affected by –efficient selection of components. –efficient overall storage management. Includes –storage for the components, –an optional descriptor (for the attributes).

31 Storage Representation Sequential representation. –Descriptor and components. –Fixed size. Linked representation. –By pointers. –Variable size.

32 Implementation of Operations Sequential representation –base-address-plus-offset using an accessing formula. (p. 146) Linked representation –following a chain of pointers

33 Storage Management Access path : its name, a pointer. Life time of a data object: binding to a storage location. Two problems: garbage dangling references

34 garbage: all access paths to a data object are destroyed but the data object continues to exist (the binding of data object to storage location has not been broken), dangling references: an access path that continues to exist after the lifetime of the associated data object. (p. 149)

35 Type Checking Existence of a selected component. Type of a selected component.

36 Data Structures Vectors and Arrays Records Variant Records Lists Character Strings Pointers Sets Files