CS 326 Programming Languages, Concepts and Implementation

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.
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.
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.
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.
Copyright © 1995 by Addison-Wesley Publishing Co. 1 Names - Design issues: - Maximum length? - Are connector characters allowed? - Are names case sensitive?
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 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.
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 COSC3306: Programming Paradigms Lecture 2: Data Types Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003.
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.
Chapter 4 of Programming Languages by Ravi Sethi.
Ch. 5 Ch. 51 jcmt Summer 2003Programming Languages CSE3302 Programming Languages (more notes) Summer 2003 Dr. Carter Tiernan.
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.
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
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.
 Data Type is a basic classification which identifies different types of data.  Data Types helps in: › Determining the possible values of a variable.
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.
5.2 Names - We discuss all user-defined names here
Data Types In Text: Chapter 6.
Type Checking and Type Inference
CS 326 Programming Languages, Concepts and Implementation
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
CS 326 Programming Languages, Concepts and Implementation
CS 326 Programming Languages, Concepts and Implementation
Chapter 6: Data Types Lectures # 10.
CS 326 Programming Languages, Concepts and Implementation
Lecture 16: Introduction to Data Types
Instructor : Ahmed Alalawi Slides from Chung –Ta King
Representation, Syntax, Paradigms, Types
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.
Data.
Introduction to Abstract Data Types
Final Review In Text: Chapters 1-3, 5-10, 12,
Final Review In Text: Chapters 1-3, 5-10, 12,
CS 3304 Comparative Languages
Representation, Syntax, Paradigms, Types
High Level Programming Languages
Representation, Syntax, Paradigms, Types
CS 363 – Chapter 7 Chapter 7 – type systems Types that are supported
Names and Binding In Text: Chapter 5.
Introduction to Data Structure
Representation, Syntax, Paradigms, Types
Compiler Construction
Midterm Review In Text: Chapters 1-3, 5-11, 15.
Compiler Construction
Types and Related Issues
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Presentation transcript:

CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 15 Good afternoon and thank you everyone for coming. My talk today will describe the research I performed at the IRIS at USC, the object of this work being to build a computational framework that addresses the problem of motion analysis and interpretation.

Language Specification General issues in the design and implementation of a language: Syntax and semantics Naming, scopes and bindings Control flow Data types Subroutines

Data Types Why are types useful? Implicit context Checking a + b var p ^integer; new (p); integer or floating-point addition, depending on the types of operands allocate the "right size", depending on the pointer type in C++: call the appropriate constructor Checking make sure that certain meaningless operations do not occur cannot check everything, but enough to be useful

Type Systems A type system consists of: Mechanism for defining types (syntax, semantics) Rules for: type equivalence (when are the types of two values the same?) type compatibility (when can a value of type A be used in a context that expects type B?) type inference (what is the type of an expression, given the types of the operands?) Type checking - ensure that a program obeys the compatibility rules Type clash - violation of compatibility rules

Type Systems A language may have: Examples: Strong typing - language prevents you from applying an operation to data for which it is not appropriate Static typing - language has strong typing, and it does type checking at compile time Dynamic typing - type checking done at run time Examples: Scheme - strong typing, but dynamic Smalltalk - strong typing, but dynamic (operations <=> messages sent to objects) Ada - strong and static typing Pascal - "almost" strong and "almost" static typing C - weaker than Pascal, but static (not much done at run time) Java - strong typing, part done at compile time, part at run time

Definition of Types Several ways to think about types: Denotational - collection of values for a domain Constructive - internal structure of data, described down to the level of fundamental types built-in types (integer, character, real, etc), also called primitive or predefined types composite types (array, record, set, etc) Abstraction - interface that specifies the operations that can be applied to objects Denotational – formal way of thinking → denotational semantics Constructive – widely used, introduced by Algol Abstraction – object-oriented way of thinking, introduced by Simula-67 and Smalltalk

Classification of Types Discrete (ordinal) types countable domains well defined notions of predecessor and successor character, integer, boolean, enumeration, subrange Non-discrete real, rational, complex Scalar (simple) types each value conceptually corresponds to one number (either discrete or not) discrete types, reals Composite types have internal structure, defined in terms of simpler types arrays, records, sets, lists

Scalar Types Boolean Character Integer Fixed point implemented on one byte, 1 → true, 0 → false Character one byte - ASCII encoding two bytes ("wide characters") - Unicode character set (Java) Integer length may not be specified by language - vary with implementation signed or unsigned varieties Fixed point represented as integers, but with implied decimal point at a specified position currency values: 129.99

Scalar Types Floating point (real) Complex Rational internally represented as sign s, mantissa m and exponent exp value = (-1)s  m  2exp Complex pair of floating point numbers - real and imaginary parts Rational pair of integers - numerator and denominator

Enumeration Types Introduced in Pascal: type weekday = (sun, mon, tue, wed, thu, fri, sat); Values are ordered - allows for comparisons: mon < tue Predecessor and successor: tomorrow := succ (today); Enumeration-controlled loops: for today := mon to fri do begin ... Index in arrays: var daily_attendance : array [weekday] of integer; daily_attendance [mon] := 40; Ordinal value: ord (sun) => 1

Subrange Types Subrange – contiguous subset of values from a discrete base type Also introduced in Pascal: type test_score = 0..100; workday = mon..fri; Why are subranges useful (why not just use integers)? easier to read/document programs semantic checks to ensure values are within range efficient representation test_score can be represented on a single byte

Composite Types Record (structure) Variant record Array introduced in Cobol collection of fields, with (potentially different) simpler types mathematical formulation: type of a record → Variant record only one field is valid at any moment type of a variant record → Array components have the same type type of an array → Cartesian product of field types union of field types function that maps an index type to a component type

Composite Types Set Pointer Lists Files collection of distinct elements of a base type Pointer reference to an object of the pointer's base type Lists sequence of elements, no indexing implemented as linked lists Files notion of current position usually accessed in sequential order

Type Checking Relation between an object type and the context where it is used: Type equivalence Type compatibility Type inference Type equivalence vs. type compatibility: equivalence - are the types the same? minimal implementation - use an object only if the object type and the type expected by the context are equivalent too restrictive → use compatibility Compatibility issues: conversion (casting) - explicit coercion - implicit non-converting cast - does not change the bits, just interpret them as another type

Type Equivalence Two ways to define type equivalence: Structural equivalence - same components, put together in the same way Name equivalence - each definition introduces a new type Structural equivalence Algol 68, Modula-3, C, ML early Pascal Name equivalence more popular lately Java, standard Pascal, Ada

Structural Equivalence Are the following equivalent? type T1 = record a, b : integer end; type T2 = record a : integer b : integer type T3 = record T1 and T2 - yes T2 and T3 – in ML no, in most other languages yes

Structural Equivalence Implementation-level way of thinking about types: type student = record name, address : string age : integer type school = record x : student y : school x := y; Should this be an error? probably yes, although the types are structurally equivalent

Announcements Readings Chapters 7, 8