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.

Slides:



Advertisements
Similar presentations
Modules Program is built out of components. Each component defines a set of logically related entities (strong internal coupling) A component has a public.
Advertisements

Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Programming Languages and Paradigms
Chapter 7:: Data Types Programming Language Pragmatics
Copyright © 2005 Elsevier Chapter 7:: Data Types Programming Language Pragmatics Michael L. Scott.
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,
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.
CS 331, Principles of Programming Languages Chapter 4 Types: Data Representation.
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;
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 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.
Trey Mack James Moore Osa Osar-Emokpae
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
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
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.
C Tokens Identifiers Keywords Constants Operators Special symbols.
March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341)
1 COSC3306: Programming Paradigms Lecture 2: Data Types Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003.
Lecture #5 Introduction to C++
1 Type Checking Type checking ensures that the operands and the operator are of compatible types Generalized to include subprograms and assignments Compatible.
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.
CS 330 Programming Languages 10 / 30 / 2007 Instructor: Michael Eckmann.
Chapter 4 of Programming Languages by Ravi Sethi.
CS 330 Programming Languages 10 / 31 / 2006 Boo! Instructor: Michael Eckmann.
Structure of Programming Languages Names, Bindings, Type Checking, and Scopes.
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.
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.
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
CS 330 Programming Languages 11 / 01 / 2007 Instructor: Michael Eckmann.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
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.
Names, Scope, and Bindings Programming Languages and Paradigms.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Programming Language Theory 2011, 1 Chap. 7 :: Data Type Michael L. Scott.
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.
1 Announcements Exam 2 graded Rainbow grades: HW1-5, Exam 1-2, Quiz 1-6 Part 1: Problem 1, Problem 2, will go over 2 Part 2: Problem 1, Problem 2 Part.
CSC 533: Programming Languages Spring 2016
Chapter 6 – Data Types CSCE 343.
CSC 533: Programming Languages Spring 2015
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
Instructor : Ahmed Alalawi Slides from Chung –Ta King
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.
Types and Related Issues
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Presentation transcript:

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 Scott

2 Data Types Computers manipulate sequences of bitsComputers manipulate sequences of bits But most programs manipulate more general dataBut most programs manipulate more general data –Numbers –String –Lists –… Programming languages provide data types that raise the level of abstraction from bits to dataProgramming languages provide data types that raise the level of abstraction from bits to data –But computer hardware only knows about bits!

3 Data Types The Purpose of Types Types provide implicit contextTypes 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 operationsTypes provides a set of semantically valid operations –Compilers can detect semantic mistakes –Make sure that certain meaningless operations do not occur. Type checking cannot prevent all meaningless operations, but it catches enough of them to be useful.

4 Type Systems High-level languages have type systemsHigh-level languages have type systems –All objects and expressions have a type –E.g. int (*)(const void *, const void *) is the type of a C++ function: int compare(const void *, const void *) A type system consists ofA 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

5 Type Systems Type Checking Type checking is the process of ensuring that a program obeys the language’s type compatibility rulesType checking is the process of ensuring that a program obeys the language’s type compatibility rules Strongly typed languages always detect types errorsStrongly typed languages always detect types errors –Weakly typed languages do not –It means that the language prevents you from applying an operation to data on which it is not appropriate. –All expressions and objects must have a type –All operations must be applied in appropriate type contexts

6 Static Typing means that the compiler can do all the checking at compile time.Static Typing means that the compiler can do all the checking at compile time. –Common Lisp is strongly typed, but not statically typed. –Ada is statically typed. –Pascal is almost statically typed. –Java is strongly typed, with a non-trivial mix of things that can be checked statically and things that have to be checked dynamically. Type Systems Static Type Checking

7 Dynamic type checking is performed at run time. It is a form of late binding.Dynamic type checking is performed at run time. It is a form of late binding. It tends to be found in languages that delay other issues as well.It tends to be found in languages that delay other issues as well. –Lisp, Scheme, and Smalltalk are dynamically typed Languages with dynamic scoping are generally dynamically typed.Languages with dynamic scoping are generally dynamically typed. Type Systems Dynamic Type Checking

8 What is a type? Three points of view: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 otherThese points of view complement each other

9 Classification of Types Built-in Types Built-in/Primitive/Elementary typesBuilt-in/Primitive/Elementary types –Mimic hardware units –E.g. boolean, character, integer, real (float) Their terminology and implementation varies across languagesTheir terminology and implementation varies across languages Characters are traditionally one-byte quantities using the ASCII character setCharacters 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 –Newer languages use the Unicode character set

10 Built-in Types Numeric Types Most languages support integers and floatsMost languages support integers and floats –The range of value is implementation dependent Some languages support other numeric typesSome 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 precisionSome languages distinguish numeric types depending on their precision –Single vs. double precision numbers »C’s int (4 bytes) and long (8 bytes)

11 Classification of Types Enumerations Enumeration improve program readability and error checkingEnumeration improve program readability and error checking They were first introduced in PascalThey 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

12 Classification of Types Subranges Subranges improve program readability and error checkingSubranges improve program readability and error checking They were first introduced in PascalThey were first introduced in Pascal –E.g. type test_score = ; type workday = mon..fri; –They define an order, so they can be used in enumeration- controlled loops –The distinction between derived types and subranges (i.e., subtypes) is a feature of Ada. type test_score is new integer range ; subtype workday is weekday range mon..fri;

13 Classification of Types Composite Types Composite/Constructed types are created applying a constructor to one or more simpler typesComposite/Constructed types are created applying a constructor to one or more simpler types ExamplesExamples –Records –Variant Records –Arrays –Sets –Pointers –Lists –Files

14 Classification of Types Orthogonality Orthogonality is an important property in the design of type systemsOrthogonality is an important property in the design of type systems A collection of features is orthogonal if there are no restrictions on the ways in which the features can be combined.A collection of features is orthogonal if there are no restrictions on the ways in which the features can be combined. –Pascal is more orthogonal than Fortran, because it allows arrays of anything, for instance. Orthogonality is nice primarily because it makes a language easy to understand, easy to use, and easy to reason about.Orthogonality is nice primarily because it makes a language easy to understand, easy to use, and easy to reason about.