PZ04A - Scalar and composite data

Slides:



Advertisements
Similar presentations
PZ04B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ04B - Arrays and records Programming Language Design.
Advertisements

Names and Bindings.
PZ10B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10B - Garbage collection Programming Language Design.
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.
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.
COEN Expressions and Assignment
PZ05A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ05A - Abstract data types Programming Language Design.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
PZ10A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10A - Heap storage Programming Language Design and.
PZ07B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ07B - Basic statements Programming Language Design.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes Names Variables The Concept of Binding Type Checking Strong Typing Type Compatibility.
PZ02A - Language translation
PZ06A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06A - Inheritance Programming Language Design and Implementation.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
PZ09A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ09A - Activation records Programming Language Design.
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.
PZ05B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ05B - Type equality Programming Language Design and.
1 CS 2104 Prog. Lang. Concepts Lecture 3 Dr. Abhik Roychoudhury School of Computing.
Names Variables Type Checking Strong Typing Type Compatibility 1.
Arithmetic Expressions
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.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
PZ09A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ09A - Activation records Programming Language Design.
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
Chapter 5 Names, Bindings, Type Checking CSCE 343.
5.2 Names - We discuss all user-defined names here
5.2 Names - We discuss all user-defined names here
7.2 Arithmetic Expressions
Data Types In Text: Chapter 6.
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
Lecture 16: Introduction to Data Types
CS 326 Programming Languages, Concepts and Implementation
Scope, Objects, Strings, Numbers
Names, Bindings, and Scopes
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.
PZ06C - Polymorphism Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 7.3 PZ06C.
PZ05A - Abstract data types
Introduction to Abstract Data Types
CS 3304 Comparative Languages
PZ09A - Activation records
Polymorphism Programming Language Design and Implementation
Arrays and records Programming Language Design and Implementation
Parameter transmission
Arrays and records Programming Language Design and Implementation
Polymorphism Programming Language Design and Implementation
PZ09B - Parameter transmission
Arrays and records Programming Language Design and Implementation
Type equality Programming Language Design and Implementation
Type equality Programming Language Design and Implementation
Arrays and records Programming Language Design and Implementation
Type equality Programming Language Design and Implementation
Parameter transmission
Polymorphism Programming Language Design and Implementation
PZ07A - Expressions Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section PZ07A.
Type equality Programming Language Design and Implementation
Type equality Programming Language Design and Implementation
PZ07B - Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
PZ05B - Type equality Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 6.4 PZ05B.
Parameter transmission
Polymorphism Programming Language Design and Implementation
CH 4 - Language semantics
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Presentation transcript:

PZ04A - Scalar and composite data Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section 5.1-5.3 PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Data objects Scalar data objects: Numeric (Integers, Real) Booleans Characters Enumerations Composite objects: String Pointer Structured objects: Arrays Records Lists Sets Abstract data types: Classes Active Objects: Tasks Processes PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Binding of data objects A compiler creates two classes of objects: Memory locations Numeric values A variable is a binding of a name to a memory location: Contents of the location may change PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Data types Each data object has a type: Values: for objects of that type Operations: for objects of that type Implementation: (Storage representation) for objects of that type Attributes: (e.g., name) for objects of that type Signature: (of operation f): f: type x type  type PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

L-value and R-value Location for an object is its L-value. Contents of that location is its R-value. Where did names L-value and R-value come from? Consider executing: A = B + C; 1. Pick up contents of location B 2. Add contents of location C 3. Store result into address A. For each named object, its position on the right-hand-side of the assignment operator (=) is a content-of access, and its position on the left-hand-side of the assignment operator is an address-of access. address-of then is an L-value contents-of then is an R-value Value, by itself, generally means R-value PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Subtypes A is a subtype of B if every value of A is a value of B. Note: In C almost everything is a subtype of integer. Conversion between types: Given 2 variables A and B, when is A:=B legal? Explicit: All conversion between different types must be specified Implicit: Some conversions between different types implied by language definition PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Coersion examples Examples in Pascal: var A: real; B: integer; A := B - Implicit, called a coersion - an automatic conversion from one type to another A := B is called a widening since the type of A has more values than B. B := A (if it were allowed) would be called a narrowing since B has fewer values than A. Information could be lost in this case. In most languages widening coersions are usually allowed; narrowing coersions must be explicit: B := round(A); Go to integer nearest A B := trunc(A); Delete fractional part of A PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Enumerations typedef enum thing {A, B, C, D } NewType; Implemented as small integers with values: A = 0, B = 1, C = 2, D = 3 NewType X, Y, Z; X = A Why not simply write: X=0 instead of X=A? Readability Error detection Example: enum { fresh, soph, junior, senior} ClassLevel; enum { old, new } BreadStatus; BreadStatus = fresh; An error which can be detected PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

String implementations PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

String operations In C, arrays and character strings are the same. Implementation: L-value(A[I]) = L-value(A[0]) + I PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Pointer data Use of pointers to create arbitrary data structures Each pointer can point to an object of another data structure In general a very error prone construct and should be avoided PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000

Pointer aliasing PZ04A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, 2000