Data Types (1) 1 Programming Languages – Principles and Practice by Kenneth C Louden.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
1 Chapter 6 Data Types What is a data type? A set of values versus A set of values + set of operations on those values.
1 Chapter 6 Data Types What is a data type? A set of values versus A set of values + set of operations on those values.
Chapter 7:: Data Types Programming Language Pragmatics
1 Introduction to Data Types (Section 7.1) CSCI 431 Programming Languages Fall 2003 A compilation of material developed by Felix Hernandez-Campos and Michael.
CSCI 330: Programming Language Concepts Instructor: Pranava K. Jha
Type Checking.
Compiler Construction
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;
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
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.
Mark Hennessy CS351 Dept Computer Science NUI Maynooth 1 Types CS351 – Programming Paradigms.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
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.
Primitive Data Types: Numbers Strings Ordinal Types Pointers
1 Type Type system for a programming language = –set of types AND – rules that specify how a typed program is allowed to behave Why? –to generate better.
Chapter 6 Structured Data Types Arrays Records. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Definitions data type –collection of data objects.
Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common.
Programming Languages
1 CS 2104 Prog. Lang. Concepts Lecture 3 Dr. Abhik Roychoudhury School of Computing.
Types Chapter SixModern Programming Languages, 2nd ed.1.
Type Checking and Data Type Implementation (Sections )
Names Variables Type Checking Strong Typing Type Compatibility 1.
CSE 425: Data Types II Survey of Common Types I Records –E.g., structs in C++ –If elements are named, a record is projected into its fields (e.g., via.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Chapter SixModern Programming Languages1 Types. Chapter SixModern Programming Languages2 A Type Is A Set n When you declare that a variable has a certain.
CSE 3302 Programming Languages Chengkai Li, Weimin He Spring 2008 Data Types Lecture 7 – Data Types, Spring CSE3302 Programming Languages, UT-Arlington.
1 COMP313A Programming Languages Data Types (2). 2 Overview Type Constructors Type Equivalence Type Checking Type Conversion.
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.
TYPES Chapter Six Modern Programming Languages 1.
10/31/2015IT 3271 A Type is a Set 1. A set of values 2. A low-level representation 3. A collection of operations on those values int n; Chapter 6: Types.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
Programming Languages Third Edition Chapter 8 Data Types.
Chapter 4 of Programming Languages by Ravi Sethi.
ISBN Chapter 6 Structured Data Types Array Types Associative Arrays Record Types Union Types.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Type Systems CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
Data Types (3) 1 Programming Languages – Principles and Practice by Kenneth C Louden.
Structures and Union. Review bitwise operations –you need them for performance in terms of space and time –shifts are equivalent to arithmetics enumeration.
Data Types Always data types will decide which type of information we are storing into variables In C programming language we are having 3 types of basic.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Types Chapter SixModern Programming Languages 1. Elements of a Type Its set of values Its operations How its stored internally How its presented externally.
Names, Scope, and Bindings Programming Languages and Paradigms.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
Data Types Chapter 6: Data Types Lectures # 12. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.
Types Chapter SixModern Programming Languages 1. Elements of a Type Its set of values Its operations How its stored internally How its presented externally.
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
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Data Types In Text: Chapter 6.
Chapter 6 – Data Types CSCE 343.
COM S 326X Deep C Programming for the 21st Century Prof. Rozier
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Chapter 6: Data Types Lectures # 10.
Lecture 16: Introduction to Data Types
CS 326 Programming Languages, Concepts and Implementation
Semantic Analysis 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.
Introduction to Abstract Data Types
CS 363 – Chapter 7 Chapter 7 – type systems Types that are supported
Semantic Analysis Chapter 6.
Chapter 6 Data Types.
Compiler Construction
Chapter 6 Part 1.
Compiler Construction
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Presentation transcript:

Data Types (1) 1 Programming Languages – Principles and Practice by Kenneth C Louden

Overview of topic Simple Types Type Constructors Type Equivalence Type Checking Type Conversion 2

What is a data type? A set of values versus A set of values + set of operations on those values 3

Why data types? Data abstraction ◦ Programming style ◦ Modifiability Type checking (semantic analysis) can be done at compile time Compiler uses type information to allocate space for variables Type conversion (coercion) can be done at compile time 4

Overview cont… Declarations ◦ Explicit type information Type declarations ◦ Give new names to types in type declararion Type checking ◦ Type Inference Rules for determining the types of constructs from available type information ◦ Type equivalence determines if two types are the same Type system ◦ Type construction methods + type inference rules + type equivalence algorithm 5

Simple Types Predefined types ◦ Integer, real, boolean, and char ◦ Predefined numeric types with specific precision  Longint, double ◦ Different formats for reals  Fixed, float 6

Simple Types … Enumerated types Pascal type fruit = (apple, orange, banana); C/C++ enum fruit { apple, orange, banana }; 7

Simple Types Subrange types Pascal type byte = ; minors = 0..19; teens = ; ADA subtype teens is INTEGER range ; 8

Data Aggregrates and Type Constructors Aggregate (compound) objects and types are constructed from simple types Recursive – can also construct aggregrate objects and types from aggregrate types Predefined – records, arrays, strings…… 9

Constructors - Cartesian Product U X V = { (u, v) | u is in U and v is in V} Projection functions ◦ p 1 : U X V -> U and P 2 : U X V -> V Pascal family of languages - record 10 type reg_polygon = record no_of_edges: integer; edge_size: real end; var a_poly : reg_polygon; Cartesian product type INTEGER X REAL Projections a_poly.no_of_edges a_poly.edge_size

Constructors – Cartesian Product C/C++ 11 typedef struct { int no_of_edges; float edge_size; } reg_polygon ; reg_polygon a_poly = {3, 3.45} Projections a_poly.no_of_edges a_poly.edge_size

Constructors – Mapping (arrays) The array constructor defines mappings as data aggregates Mapping from an array index to the value stored in that position in the array The domain is the values of the index The range is the values stored in the array 12

Constructors Mapping (arrays) C/C++ 13 typedef int little_people_num[3]; little_people_num gollum_city = {0, 0, 0} gollum_city[3] = 5 typedef int matrix[10][20];

Constructors – Mapping (arrays)… Pascal ADA 14 Type intarray = array[2..5] of integer; little_people = (dwarf, elf, goblin); little_people_num = array[little_people] of integer; intmatrix = array[1..10, 1..20] of integer; x:array(INTEGER range 2.6) of INTEGER := (0,2,0,5,-33)

Constructors Union Cartesian products – conjunction of fields Union – disjunction of fields Discriminated or undiscriminated 15

Constructors Unions Undiscriminated C/C++ 16 typedef union { short int offset; long unsigned int absolute; } address;

Constructors Union… Discriminated 17 typedef struct { address location; descriptor kind; } safe_address; enum descriptor{rel, abs}; safe_address an_address; if (an_address == rel) an_address.location.offset = 255;

Pascal Variant Record 18 type address_range = 0..maxint; address_type = (absolute, offset); safe_address = record case kind: address_type of absolute: (abs_addr:address_range); offset: (off_addr: integer); end