Lecture 16: Introduction to Data Types

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms
Advertisements

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
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Type Checking.
ICE1341 Programming Languages Spring 2005 Lecture #9 Lecture #9 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
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 5 Names, Bindings, Type Checking, and Scopes Names Variables The Concept of Binding Type Checking Strong Typing Type Compatibility.
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.
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
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
CS 355 – Programming Languages
Language Evaluation Criteria
1 Adapted from slides for COMP 144 Programming Language Concepts Spring 2002 by Felix Hernandez-Campos The University of North Carolina at Chapel Hill.
ISBN 0-321— Chapter 6 sections 1-4, 9 Primitive Data Types Numbers Strings Ordinal Types Pointers.
CSC3315 (Spring 2009)1 CSC 3315 Programming Languages Hamid Harroud School of Science and Engineering, Akhawayn University
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.
PRIMITIVE DATA TYPES -Integer -Floating Point -Decimal -Boolean -Character STRINGS -Character Array -Class -String Length -Static -Limited Dynamic -Dynamic.
1 COSC3306: Programming Paradigms Lecture 2: Data Types Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003.
Lecture #5 Introduction to C++
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.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
Ch Chapter 4 Basic Data Types and Variables 4.1 Basic Data Types In C TABLE 4.1 Introduction to Basic Data Types in C Type SizeDescription char 1.
CS 330 Programming Languages 10 / 31 / 2006 Boo! Instructor: Michael Eckmann.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved. 6-2 Chapter 6 Topics Introduction Primitive Data Types.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Variables reference, coding, visibility. Rules for making names  permitted character set  maximum length, significant length  case sensitivity  special.
CS 330 Programming Languages 11 / 01 / 2007 Instructor: Michael Eckmann.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
CPS120: Introduction to Computer Science Variables and Constants.
ISBN Chapter 6 Data Types. Copyright © 2006 Addison-Wesley. All rights reserved.2 Primitive Data Types Almost all programming languages.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
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
Dr. M. Al-Mulhem Introduction 1 Chapter 6 Type Systems.
CSC 533: Programming Languages Spring 2016
Types Type Errors Static and Dynamic Typing Basic Types NonBasic Types
Basic Concepts: computer, program, programming …
Type Checking and Type Inference
The Machine Model Memory
Chapter 6 – Data Types CSCE 343.
CSC 533: Programming Languages Spring 2015
Chapter 6 Data Types.
CSE 3302 Programming Languages
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
Chapter 6: Data Types Lectures # 10.
CS 326 Programming Languages, Concepts and Implementation
Instructor : Ahmed Alalawi Slides from Chung –Ta King
INTRODUCTION c is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs.
Data Types.
Chapter 2 Bits, Data Types & Operations Integer Representation
Chapter 6 Data Types.
Introduction to Abstract Data Types
CS 3304 Comparative Languages
CS 363 – Chapter 7 Chapter 7 – type systems Types that are supported
Semantic Analysis Chapter 6.
Names and Binding In Text: Chapter 5.
Chapter 6 Data Types.
Intro to Data Structures and ADTs
Compiler Construction
Type Systems Terms to learn about types: Related concepts: Type
Compiler Construction
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Presentation transcript:

Lecture 16: Introduction to Data Types The University of North Carolina at Chapel Hill COMP 144 Programming Language Concepts Spring 2002 Lecture 16: Introduction to Data Types Felix Hernandez-Campos Feb 18 COMP 144 Programming Language Concepts Felix Hernandez-Campos

Data Types Computers manipulate sequences of bits But most programs manipulate more general data Numbers String Lists … Programming languages provide data types that raise the level of abstraction from bits to data But computer hardware only knows about bits! COMP 144 Programming Language Concepts Felix Hernandez-Campos

Data Types The Purpose of Types Types provide implicit context Compilers can infer more information, so programmers write less code E.g. the expression a+b in Java may be adding two integer, two floats or two strings depending on the context Types provides a set of semantically valid operations Compilers can detect semantic mistakes E.g. Python’s lists support append() and pop(), but complex numbers do not. COMP 144 Programming Language Concepts Felix Hernandez-Campos

Type Systems High-level languages have type systems All objects and expressions have a type E.g. int (*)(const void *) is the type of a C++ function A type system consists of A mechanism for defining types and associating them with certain language constructs A set of rules for type checking Type equivalence Type compatibility Type inference COMP 144 Programming Language Concepts Felix Hernandez-Campos

Type Systems Type Checking Type checking is the process of ensuring that a program obeys the language’s type compatibility rules Strongly typed languages always detect types errors Weakly typed languages do not All expressions and objects must have a type All operations must be applied in appropriate type contexts Statically typed languages are strongly typed language in which all type checking occurs at compile type Dynamically typed languages: some checking at run-time E.g. Haskell vs. Java COMP 144 Programming Language Concepts Felix Hernandez-Campos

What is a type? Three points of view: Denotational: a set of values Constructive: a type is built-in type or a composite type Composite types are created using type constructors E.g. In Java, boolean is a built-in type, while boolean[] is a composite type Abstraction-based: a type is an interface that defines a set of consistent operation These points of view complement each other COMP 144 Programming Language Concepts Felix Hernandez-Campos

Classification of Types Built-in Types Built-in/Primitive/Elementary types Mimic hardware units E.g. boolean, character, integer, real (float) Their implementation varies across languages Characters are traditionally one-byte quantities using the ASCII character set Early computers had a different byte sizes Byte = 8 bits standardized by Fred Brooks et al. thanks to the IBM System/360 Other character sets have also been used COMP 144 Programming Language Concepts Felix Hernandez-Campos

Built-in Types Unicode Characters Newer languages have built-in characters that support the Unicode character set http://www.unicode.org/unicode/standard/WhatIsUnicode.html Unicode is implemented using two-byte quantities E.g. Java http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html E.g. Python u”¡Hola!” http://www.python.org/doc/current/tut/node5.html#SECTION005130000000000000000 COMP 144 Programming Language Concepts Felix Hernandez-Campos

Built-in Types Numeric Types Most languages support integers and floats The range of value is implementation dependent Some languages support other numeric types Complex numbers (e.g. Fortran, Python) Rational numbers (e.g. Scheme, Common Lisp) Signed and unsigned integers (e.g. C, Modula-2) Fixed point numbers (e.g. Ada) Some languages distinguish numeric types depending on their precision Single vs. double precision numbers C’s int (4 bytes) and long (8 bytes) COMP 144 Programming Language Concepts Felix Hernandez-Campos

Classification of Types Enumerations Enumeration improve program readability and error checking They were first introduced in Pascal E.g. type weekday = (sun, mon, tue, wed, thu, fri, sat); They define an order, so they can be used in enumeration-controlled loops The same feature is available in C enum weekday {sun, mon, tue, wed, thu, fri, sat}; Other languages use constants to define enumeration Pascal’s approach is more complete: integers and enumerations are not compatible COMP 144 Programming Language Concepts Felix Hernandez-Campos

Classification of Types Subranges Subranges improve program readability and error checking They were first introduced in Pascal E.g. type test_score = 0..100; workday = mon..fri; They define an order, so they can be used in enumeration-controlled loops COMP 144 Programming Language Concepts Felix Hernandez-Campos

Classification of Types Composite Types Composite/Constructed types are created applying a constructor to one or more simpler types Examples Records Variant Records Arrays Sets Pointers Lists Files COMP 144 Programming Language Concepts Felix Hernandez-Campos

Classification of Types Orthogonality Orthogonality is an important property in the design of type systems More orthogonal languages support have more flexible composite types Python is a good example COMP 144 Programming Language Concepts Felix Hernandez-Campos

Reading Assignment Scott’s chapter 7 Intro Section 7.1 COMP 144 Programming Language Concepts Felix Hernandez-Campos