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.

Slides:



Advertisements
Similar presentations
Chapter 6 - Data Types Programming Languages:
Advertisements

Types and Arithmetic Operators
Chapter 7:: Data Types Programming Language Pragmatics
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
CSE 425: Semantic Analysis Semantic Analysis Allows rigorous specification of a program’s meaning –Lets (parts of) programming languages be proven correct.
CSE 341, Winter Type Systems Terms to learn about types: –Type –Type system –Statically typed language –Dynamically typed language –Type error –Strongly.
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.
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.
CSE 425: Semantics II Implementing Scopes A symbol table is in essence a dictionary –I.e., every name appears in it, with the info known about it –Usually.
Type Checking.
Compiler Construction
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
ISBN Chapter 5 Names, Bindings, Type Checking, and Scopes Names Variables The Concept of Binding Type Checking Strong Typing Type Compatibility.
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.
CSE 425: Object-Oriented Programming II Implementation of OO Languages Efficient use of instructions and program storage –E.g., a C++ object is stored.
1-1 University of Hail College of Computer Science and Engineering Department of computer Science and Software Engineering Course: ICS313: Fundamentals.
Type Equivalence Rules Ada –Strict name equivalence except for almost everything Unique array constructors give rise to unique types Subtypes can create.
Names and Binding In procedural programming, you write instructions the manipulate the “state” of the process where the “state” is the collection of variables.
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.
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.
March 12, ICE 1341 – Programming Languages (Lecture #6) In-Young Ko Programming Languages (ICE 1341) Lecture #6 Programming Languages (ICE 1341)
Basic Java Syntax CSE301 University of Sunderland Harry R Erwin, PhD.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
CSE 425: Target Machine Architecture Target Machine Details Many architectures can be similar in overall structure –E.g., Von Neumann with CISC instruction.
Arithmetic Expressions
CSE 425: Control Flow I Categories of Control Flow Constructs Sequencing –order of expressions and statements Selection –if, else, switch Iteration –loops.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
Types in programming languages1 What are types, and why do we need them?
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.
Programming Languages Third Edition Chapter 8 Data Types.
CSE 425: Concurrency II Semaphores and Mutexes Can avoid bad inter-leavings by acquiring locks –Guard access to a shared resource to take turns using it.
CSE 425: Control Abstraction I Functions vs. Procedures It is useful to differentiate functions vs. procedures –Procedures have side effects but usually.
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
CS536 Types 1. Roadmap Back from our LR Parsing Detour Name analysis – Static v dynamic – Scope Today – Type checking 2 Scanner Parser Tokens Semantic.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
C++ for Java Programmers Chapter 2. Fundamental Daty Types Timothy Budd.
CSE 425: Control Abstraction II Exception Handling Previous discussion focuses on normal control flow –Sometimes program reaches a point where it cannot.
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.
Data Types (3) 1 Programming Languages – Principles and Practice by Kenneth C Louden.
CSE 425: Functional Programming I Programs as Functions Some programs act like mathematical functions –Associate a set of input values from the function’s.
Object Oriented Programming Lecture 2: BallWorld.
Dr. M. Al-Mulhem Introduction 1 Chapter 6 Type Systems.
Chapter 5 Names, Bindings, Type Checking CSCE 343.
Names and Attributes Names are a key programming language feature
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.
Java Primer 1: Types, Classes and Operators
CS 326 Programming Languages, Concepts and Implementation
Type Systems Terms to learn about types: Related concepts: Type
Introduction to Abstract Data Types
Iteration Implemented through loop constructs (e.g., in C++)
CS 363 – Chapter 7 Chapter 7 – type systems Types that are supported
Delayed Evaluation Special forms in Scheme (e.g., if and cond) do not use applicative order evaluation Only one of two or more expressions is actually.
Names and Binding In Text: Chapter 5.
Data Types and Expressions
Type Systems Terms to learn: Type Type system
Java Programming Language
Type Systems Terms to learn about types: Related concepts: Type
Data Types and Expressions
Lecture 7: Types (Revised based on the Tucker’s slides) 10/4/2019
Data Types and Expressions
CSE 3302 Programming Languages
Presentation transcript:

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 or a standard may define representations –E.g., IEEE floating point standard, sizeof(char) == 1 in C++ Otherwise representations may be platform-dependent –E.g., different int sizes on 32-bit vs. 64-bit platform in C++ Languages also define operations on data –E.g., strong requirements for arithmetic operators in Java –E.g., weaker requirements for them in C++ Languages also differ in when types are checked –E.g., Scheme is dynamically type checked (at run-time) –E.g., C++ is (mostly) statically checked at compile-time

CSE 425: Data Types I Programs and Type Systems A language’s type system has two main parts –Its type constructors –Its rules (and algorithms) for evaluating type equivalence, type compatibility, and type inference Type systems must balance design trade-offs –Static checking can improve efficiency, catch errors earlier –Dynamic checking increases flexibility by delaying type evaluation until run-time (common in functional languages), may consider a larger subset of safe programs to be legal Definition of data types (based on sets) –A data type has a set of values and a type name –A data type also defines operations on those values, along with properties of those operations (e.g., integer division)

CSE 425: Data Types I Predefined Types, Simple Types Languages often predefine types –Simple types (e.g., int and double in C++ or Java) have only a basic mathematic (arithmetic or sequential) structure –Other types with additional structure may be predefined in the language (e.g., the String type in Java) Languages also often allow types to be introduced –Simple types can be specified within a program (e.g., an enum in C++ or a sub-range type in Ada) –Other types (e.g., unions, arrays, structs, classes, pointers) can be declared explicitly but involve type constructors

CSE 425: Data Types I Type Equivalence Structural equivalence –Basic structural equivalence: all types defined as AXB are the same but are all different than those defined as BXA –More complex forms arise if elements are named (so they are not interface polymorphic to member selection operator) Name equivalence –Two types are the same only if they have the same name –Easy to check, but restrictive Declaration equivalence –Improves on name equivalence by allowing new names to be given for a declared type, all of which are equivalent (e.g., in C++ typedefs behave this way)

CSE 425: Data Types I Type Checking Some languages check statically but weakly –E.g., C++ warnings rather than errors for C compatibility Type compatibility in construction and assignment –Variable constructed, or l-value/ref assigned from an r-value –May involve conversion of r-value into a compatible type Overloading introduces inference in type checking –Also may involve type conversion of operands –E.g., passing an int to a long int parameter Casting overrides type checking –E.g., cannot assign long int result back into a short int in Java unless you tell the compiler explicitly to recast r-value –E.g., C++ reinterpret cast tells compiler not to check

CSE 425: Data Types I Type Conversion Often need to use one type in place of another type –Safe implicit conversions often are made automatically –Widening conversions usually don’t lose information –Narrowing conversions may truncate, overflow, etc. Explicit conversions –Explicit construction from a type provides safe conversion –Casting offers alternative when safety can only be determined at run-time (by the program doing the cast) –Static casts are completed at compile-time –Dynamic casts check additional information at run-time (e.g., if polymorphic) may throw exception, return 0 pointer, etc.

CSE 425: Data Types I Today’s Studio Exercises We’ll code up ideas from Scott Chapter , 7.10 –Especially looking at types, type declarations, casting Today’s exercises are all in C++ –Scheme, which we’ll work with later in the course as well, is dynamically (rather than statically) typed –C++ allows us to explore many type system issues –Please take advantage of the on-line tutorial and reference manual pages that are linked on the course web site –As always, please ask us for help as needed When done, your answers with “Data Types Studio I” in the subject line to the course account –Send to