CSCI312 Principles of Programming Languages!

Size: px
Start display at page:

Transcription

1 CSCI312 Principles of Programming Languages! Chapter 5 Types Xu Liu!

2 ! 5.1!Type Errors! 5.2!Static and Dynamic Typing! 5.3!Basic Types! 5.4!NonBasic Types! 5.5!Recursive Data Types! 5.6!Functions as Types! 5.7!Type Equivalence! 5.8!Subtypes! 5.9!Polymorphism and Generics! 5.10!Programmer-Defined Types

3 A type is a collection of values and operations on! those values. Example: Integer type has values..., -2, -1, 0, 1, 2,... and operations +, -, *, /, <,... The Boolean type has values true and false and operations,,.

4 Computer! types have a finite number of values due to fixed size allocation; problematic for numeric types. Exceptions: Smalltalk uses unbounded fractions. Haskell type Integer represents unbounded integers. Floating point problems?

5 ! Even more problematic is fixed sized floating point numbers: 0.2 is not exact in binary. So 0.2 * 5 is not exactly 1.0 Floating point is inconsistent with real numbers in mathematics.

6 ! In the early languages, Fortran, Algol, Cobol, all of the types were built in. If needed a type color, could use integers; but what does it mean to multiply two colors. Purpose of types in programming languages is to provide ways of effectively modeling a problem solution.

7 5.1 Type Errors! Machine data carries no type information. Basically, just a sequence of bits. Example:

8 ! The floating point number The 32-bit integer 1,079,508,992 Two 16-bit integers and 0 Four ASCII X NUL NUL!

9 A! type error is any error that arises because an operation is attempted on a data type for which it is undefined. Type errors are common in assembly language programming. High level languages reduce the number of type errors. A type system provides a basis for detecting type errors.

10 5.2 Static and Dynamic Typing! A type system imposes constraints such as the values used in an addition must be numeric. Cannot be expressed syntactically in EBNF. Some languages perform type checking at compile time (eg, C). Other languages (eg, Python) perform type checking at run time. Still others (eg, Java) do both.

11 ! A language is statically typed if the types of all variables are fixed when they are declared at compile time. A language is dynamically typed if the type of a variable can vary at run time depending on the value assigned. Can you give examples of each?

12 A language is strongly typed if its type system allows all type errors in a program to be detected either at compile time or at run time. A strongly typed language can be either statically (e.g., Ada, Java) or dynamically typed (e.g., Python and Perl).

13 An Example C Program int main(){ union {int a; float p;} u; u.a = -1; float x=0; x = x + u.p; printf ("x=%f\n", x); float y=0; y = y + (float)u.a; printf ("y=%f\n", y); return 0; } u.a u.p x = -nan y = Union makes a hole in type checking. C/C++ are not strongly typed.

14 5.3 Basic Types! Terminology in use with current 32-bit computers: Nibble: 4 bits Byte: 8 bits Half-word: 16 bits Word: 32 bits Double word: 64 bits Quad word: 128 bits

15 ! In most languages, the numeric types are finite in size. So a + b may overflow the finite range. Unlike mathematics: a + (b + c) (a + b) + c! Also in C-like languages, the equality and relational operators produce an int, not a Boolean

16 Overloading An operator or function is overloaded when its meaning varies depending on the types of its operands or arguments or result. Python: a + b (ignoring size) integer add floating point add string concatenation What if a is integer while b is floating point?

17 Type Conversion A type conversion is a narrowing conversion if the result type permits fewer bits, thus potentially losing information. E.g., float -> int Otherwise it is termed a widening conversion. E.g., int -> float Explicit conversion: 2 + int(1.3); Implicit conversion: ; Should languages use narrowing or widening for implicit conversions?

18 5.4 Nonbasic Types! Enumeration: enum day {Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday};! enum day myday = Wednesday;! In C/C++ the above values of this type are 0,..., 6. More powerful in Java: for (day d : day.values())!!sytem.out.println(d);!

19 Pointers! C, C++, Ada, Pascal Java??? Value is a memory address Indirect referencing Operator in C: *

20 Pointer Operations If T is a type and reft is a pointer: & : T reft. Eg. &x: returns the address of x * : reft T. Eg. *p: returns the value in the location that p references. For an arbitrary variable x: *(&x) = x

21 Example int main(){ int v = 3; int * p = &v; (*p) = -3; printf("v=%d\n", v); return 0; }

22 Pointers are convenient in some cases Example: Linked List struct Node {! int key;! struct Node* next; }; struct Node* head;

23 But Error-Prone E.g. Buffer overflow problem String copy: while (*p++ == *q++); q points to a string\$ p points to a 3-char buffer. Particularly troublesome in C as points and array are regarded the same.

24 Equivalence between arrays and pointers int a[100]; // declare an array a == &a[0] a[i] == *(a + i) float sum(float a[ ], int n) { int i; float s = 0.0; for (i = 0; i<n; i++)!!!! s += a[i]; return s; float sum(float *a, int n) { int i; float s = 0.0; for (i = 0; i<n; i++)! s += *a++; return s;

25 Arrays and Lists int a[10]; float x[3][5]; /* odd syntax vs. math */ char s[40];

26 Indexing The only operation for arrays and lists in many languages Type signature [ ] : T[ ] int T Example float x[3] [5]; type of x: float[ ][ ] type of x[1]: float[ ] type of x[1][2]: float

27 Strings Now so fundamental, directly supported. In C, a string is a 1D array with the string value terminated by a NUL character (value = 0). In Java, Perl, Python, a string variable can hold an unbounded number of characters. Libraries of string operations and functions.

28 Structures Analogous to a tuple in mathematics Collection of elements of different types Used first in Cobol, PL/I Absent from Fortran, Algol 60 Common to Pascal-like, C-like languages Omitted from Java as redundant

29 struct employeetype { int id; char name[25]; int age; float salary; char dept; }; struct employeetype employee;... employee.age = 45;

30 Unions C: union Pascal: case-variant record union {int a; float p;} u; Logically: multiple views of same storage Useful in some systems applications

31 Contents 5.1! Type Errors 5.2! Static and Dynamic Typing 5.3! Basic Types 5.4! NonBasic Types 5.5! Recursive Data Types 5.6! Functions as Types 5.7! Type Equivalence 5.8! Subtypes 5.9! Polymorphism and Generics 5.10!Programmer-Defined Types

32 5.5 Recursive Data Type Example: Linked List struct Node {! int key;! struct Node* next; }; struct Node* head; Others?

33 5.6 Functions as Types Needs example: a function to draw the curve for y=f(x). Pascal example:! function newton(a, b: real; function f: real): real; Know that f returns a real value, but the arguments to f are unspecified.

34 Addressed by Java Interface public interface RootSolvable { double valueat(double x); } public double Newton(double a, double b, RootSolvable f);

35 5.7 Type Equivalence Pascal Report: The assignment statement serves to replace the current value of a variable with a new value specified as an expression.... The variable (or the function) and the expression must be of identical type. Nowhere does it define identical type.

36 struct complex { float re, im; }; struct polar { float x, y; }; struct { float re, im; } a, b; struct complex c, d; struct polar e; int f[5], g[10]; // which are equivalent types?

37 Kinds of Type Equivalence Name equivalence Structural equivalence: # and order of fields of a structure, and the name and type of each field. Ada, Java: name equivalence. C: name equivalence for structs and unions, structural equivalence for other constructed types (arrays and pointers). Size of an array doesn t matter.

38 struct complex { float re, im; }; struct polar { float x, y; }; struct { float re, im; } a, b; struct complex c, d; struct polar e; int f[5], g[10]; // which are equivalent types? Name equivalence: a, b Structural equivalence: a, b, c, d f, g are equivalent in both cases.

39 5.8 Subtypes A subtype is a type that has certain constraints placed on its values or operations. In Ada subtypes can be directly specified.

40 subtype one_to_ten is Integer range ; type Day is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday); subtype Weekend is Day range Saturday.. Sunday; type Salary is delta 0.01 digits 9 range _999_999.99; subtype Author_Salary is Salary digits 5 range ;

41 Example in Java Integer i = new Integer(3);... Number v = i;... Integer x = (Integer) v; //Integer is a subclass of Number, // and therefore a subtype

42 Polymorphism and Generics A function or operation is polymorphic if it can be applied to any one of several related types and achieve the same result. An advantage of polymorphism is that it enables code reuse.

43 Polymorphism Comes from Greek Means: having many forms Example: overloaded built-in operators and functions + - * / ==!=... Java: + also used for string concatenation

44 Ada, C++: define for new types Java overloaded methods: number or type of parameters Example: class PrintStream print, println defined for: boolean, char, int, long, float, double, char[ ], String, Object

45 Java: instance variable, method name, name( ) Ada generics: generic sort parametric polymorphism type binding delayed from code implementation to compile time procedure sort is new generic_sort(integer);

46 generic type element is private; type list is array(natural range <>) of element; with function ">"(a, b : element) return boolean; package sort_pck is procedure sort (in out a : list); end sort_pck;

47 package sort_pck is procedure sort (in out a : list) is begin for i in a'first.. a'last - 1 loop for j in i+1.. a'last loop if a(i) > a(j) then declare t : element; begin t := a(i); a(i) := a(j); a(j) := t; end; end if;

48 Instantiation package integer_sort is new generic_sort( Integer, ">" );

49 Programmer-defined Types Recall the definition of a type: A set of values and a set of operations on those values. Structures allow a definition of a representation; problems: Representation is not hidden Type operations cannot be defined Defer further until Chapter 12.

22c:111 Programming Language Concepts. Fall Types I

22c:111 Programming Language Concepts Fall 2008 Types I Copyright 2007-08, The McGraw-Hill Company and Cesare Tinelli. These notes were originally developed by Allen Tucker, Robert Noonan and modified

HANDLING NONLOCAL REFERENCES

SYMBOL TABLE A symbol table is a data structure kept by a translator that allows it to keep track of each declared name and its binding. Assume for now that each name is unique within its local scope.

Names and Types. standard hue names. Dr. Philip Cannata 1

Names and Types standard hue names Dr. Philip Cannata 1 10 High Level Languages This Course Jython in Java Java (Object Oriented) ACL2 (Propositional Induction) Relation Algorithmic Information Theory

TYPES, VALUES AND DECLARATIONS

COSC 2P90 TYPES, VALUES AND DECLARATIONS (c) S. Thompson, M. Winters 1 Names, References, Values & Types data items have a value and a type type determines set of operations variables Have an identifier

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

Every program uses data, either explicitly or implicitly to arrive at a result. Data in a program is collected into data structures, and is manipulated by algorithms. Algorithms + Data Structures = Programs

Types. What is a type?

Types What is a type? Type checking Type conversion Aggregates: strings, arrays, structures Enumeration types Subtypes Types, CS314 Fall 01 BGRyder 1 What is a type? A set of values and the valid operations

CPSC 3740 Programming Languages University of Lethbridge. Data Types

Data Types A data type defines a collection of data values and a set of predefined operations on those values Some languages allow user to define additional types Useful for error detection through type

Chapter 6. Structured Data Types. Topics. Structured Data Types. Vectors and Arrays. Vectors. Vectors: subscripts

Topics Chapter 6 Structured Data Types Vectors Arrays Slices Associative Arrays Records Unions Lists Sets 2 Structured Data Types Virtually all languages have included some mechanisms for creating complex

Chapter 7:: Data Types. Mid-Term Test. Mid-Term Test (cont.) Administrative Notes

Chapter 7:: Data Types Programming Language Pragmatics Michael L. Scott Administrative Notes Mid-Term Test Thursday, July 27 2006 at 11:30am No lecture before or after the mid-term test You are responsible

Fundamentals of Programming Languages. Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila

Fundamentals of Programming Languages Data Types Lecture 07 sl. dr. ing. Ciprian-Bogdan Chirila Predefined types Programmer defined types Scalar types Structured data types Cartesian product Finite projection

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

G22.2110-001 Programming Languages Spring 2010 Lecture 6 Robert Grimm, New York University 1 Review Last week Function Languages Lambda Calculus SCHEME review 2 Outline Promises, promises, promises Types,

Data Types. Outline. In Text: Chapter 6. What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 5-1. Chapter 6: Data Types 2

Data Types In Text: Chapter 6 1 Outline What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers Chapter 6: Data Types 2 5-1 Data Types Two components: Set of objects in the type (domain

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

MUHAMMAD FAISAL MIT 4 th Semester Al-Barq Campus (VGJW01) Gujranwala faisalgrw123@gmail.com MEGA File Solved MCQ s For Final TERM EXAMS CS508- Modern Programming Languages Question No: 1 ( Marks: 1 ) -

Names, Scopes, and Bindings II. Hwansoo Han

Names, Scopes, and Bindings II Hwansoo Han Scope Rules A scope is textual region where bindings are active A program section of maximal size Bindings become active at the entry No bindings change in the

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

Data Types (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011 Based in part on slides and notes by Bjoern 1 Brandenburg, S. Olivier and A. Block. 1 Data Types Hardware-level:

Fundamentals of Programming Languages

Fundamentals of Programming Languages 1. DEFINITIONS... 2 2. BUILT-IN TYPES AND PRIMITIVE TYPES... 3 TYPE COMPATIBILITY... 9 GENERIC TYPES... 14 MONOMORPHIC VERSUS POLYMORPHIC... 16 TYPE IMPLEMENTATION

Note 3. Types. Yunheung Paek. Associate Professor Software Optimizations and Restructuring Lab. Seoul National University

Note 3 Types Yunheung Paek Associate Professor Software Optimizations and Restructuring Lab. Seoul National University Topics Definition of a type Kinds of types Issues on types Type checking Type conversion

Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types

Chapter 6 Topics WEEK E FOUR Data Types Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer and Reference

Topic 9: Type Checking

Recommended Exercises and Readings Topic 9: Type Checking From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 13.17, 13.18, 13.19, 13.20, 13.21, 13.22 Readings: Chapter 13.5, 13.6 and

Topic 9: Type Checking

Topic 9: Type Checking 1 Recommended Exercises and Readings From Haskell: The craft of functional programming (3 rd Ed.) Exercises: 13.17, 13.18, 13.19, 13.20, 13.21, 13.22 Readings: Chapter 13.5, 13.6

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

Agenda COMP 181 Type checking October 21, 2009 Next week OOPSLA: Object-oriented Programming Systems Languages and Applications One of the top PL conferences Monday (Oct 26 th ) In-class midterm Review

CS558 Programming Languages

CS558 Programming Languages Winter 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Values and Types We divide the universe of values according to types A type is a set of values and

Data Types In Text: Ch C apter 6 1

Data Types In Text: Chapter 6 1 Outline What is a type? Primitives Strings Ordinals Arrays Records Sets Pointers 2 Data Types Two components: Set of objects in the type (domain of values) Set of applicable

CS349/SE382 A1 C Programming Tutorial

CS349/SE382 A1 C Programming Tutorial Erin Lester January 2005 Outline Comments Variable Declarations Objects Dynamic Memory Boolean Type structs, enums and unions Other Differences The Event Loop Comments

COS 140: Foundations of Computer Science

COS 140: Foundations of Computer Science Variables and Primitive Data Types Fall 2017 Introduction 3 What is a variable?......................................................... 3 Variable attributes..........................................................

Programming Languages

Programming Languages Types CSCI-GA.2110-003 Fall 2011 What is a type? An interpretation of numbers Consists of a set of values The compiler/interpreter defines a mapping of these values onto the underlying

SE352b Software Engineering Design Tools W3: Programming Paradigms Feb. 3, 2005 SE352b, ECE,UWO, Hamada Ghenniwa SE352b: Roadmap CASE Tools: Introduction System Programming Tools Programming Paradigms

Programming Languages

Programming Languages Types CSCI-GA.2110-001 Summer 2011 What is a type? A type consists of a set of values The compiler/interpreter defines a mapping of these values onto the underlying hardware. 2 /

Chapter 7. Expressions and Assignment Statements ISBN

Chapter 7 Expressions and Assignment Statements ISBN 0-321-33025-0 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit

Lecture 12: Data Types (and Some Leftover ML)

Lecture 12: Data Types (and Some Leftover ML) COMP 524 Programming Language Concepts Stephen Olivier March 3, 2009 Based on slides by A. Block, notes by N. Fisher, F. Hernandez-Campos, and D. Stotts Goals

CSCI312 Principles of Programming Languages!

CSCI312 Principles of Programming Languages! Scope Xu Liu ! 4.1 Syntactic Issues! 4.2 Variables! 4.3 Scope! 4.4 Symbol Table! 4.5 Resolving References! 4.6 Dynamic Scoping! 4.7 Visibility! 4.8 Overloading!

Chapter 5 Names, Binding, Type Checking and Scopes

Chapter 5 Names, Binding, Type Checking and Scopes Names - We discuss all user-defined names here - Design issues for names: -Maximum length? - Are connector characters allowed? - Are names case sensitive?

CSC2/454 Programming Languages Design and Implementation Records and Arrays

CSC2/454 Programming Languages Design and Implementation Records and Arrays Sreepathi Pai November 6, 2017 URCS Outline Scalar and Composite Types Arrays Records and Variants Outline Scalar and Composite

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

CS Programming In C

CS 24000 - Programming In C Week Two: Basic C Program Organization and Data Types Zhiyuan Li Department of Computer Science Purdue University, USA 2 int main() { } return 0; The Simplest C Program C programs

Data Types. Data Types. Introduction. Data Types. Data Types. Data Types. Introduction

Introduction Primitive Composite Structured Abstract Introduction Introduction Data Type is a Collection of Data Objects Possible r-values for a memory cell Set of operations on those objects Descriptor

Lecture Overview. [Scott, chapter 7] [Sebesta, chapter 6]

1 Lecture Overview Types 1. Type systems 2. How to think about types 3. The classification of types 4. Type equivalence structural equivalence name equivalence 5. Type compatibility 6. Type inference [Scott,

Programming Languages, Summary CSC419; Odelia Schwartz

Programming Languages, Summary CSC419; Odelia Schwartz Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design

Expressions & Assignment Statements

Expressions & Assignment Statements 1 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment Statements

CS321 Languages and Compiler Design I Winter 2012 Lecture 13

STATIC SEMANTICS Static Semantics are those aspects of a program s meaning that can be studied at at compile time (i.e., without running the program). Contrasts with Dynamic Semantics, which describe how

Principles of Programming Languages

Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 23! Type systems Type safety Type checking Equivalence,

COS 140: Foundations of Computer Science

COS 140: Foundations of Variables and Primitive Data Types Fall 2017 Copyright c 2002 2017 UMaine School of Computing and Information S 1 / 29 Homework Reading: Chapter 16 Homework: Exercises at end of

Preview from Notesale.co.uk Page 6 of 52

Binary System: The information, which it is stored or manipulated by the computer memory it will be done in binary mode. RAM: This is also called as real memory, physical memory or simply memory. In order

Data Types (cont.) Administrative Issues. Academic Dishonesty. How do we detect plagiarism? Strongly Typed Languages. Type System

CSE 3302 Programming Languages Data Types (cont.) Chengkai Li Fall 2007 1 Administrative Issues Midterm Exam (in class) Tuesday, Oct. 16 th Schedule Change HW1 HW1 part1 & HW1 part2 Due at the same time,

Organization of Programming Languages CS320/520N. Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science

Organization of Programming Languages CS320/520N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects and

CS 430 Spring Mike Lam, Professor. Data Types and Type Checking

CS 430 Spring 2015 Mike Lam, Professor Data Types and Type Checking Type Systems Type system Rules about valid types, type compatibility, and how data values can be used Benefits of a robust type system

CSI33 Data Structures

Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence

Types and Type Inference

CS 242 2012 Types and Type Inference Notes modified from John Mitchell and Kathleen Fisher Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on Web!! Outline General discussion of

Chapter 7. Expressions and Assignment Statements (updated edition 11) ISBN

Chapter 7 Expressions and Assignment Statements (updated edition 11) ISBN 0-321-49362-1 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean

LECTURE 18. Control Flow

LECTURE 18 Control Flow CONTROL FLOW Sequencing: the execution of statements and evaluation of expressions is usually in the order in which they appear in a program text. Selection (or alternation): a

Chapter 7. Expressions and Assignment Statements

Chapter 7 Expressions and Assignment Statements Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment

Chapter 5. Names, Bindings, and Scopes

Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes 長庚大學資訊工程學系 陳仁暉 助理教授 Tel: (03) 211-8800 Ext: 5990 E-mail: jhchen@mail.cgu.edu.tw URL: http://www.csie.cgu.edu.tw/jhchen All rights reserved. No part

UNIT II Structuring the Data, Computations and Program. Kainjan Sanghavi

UNIT II Structuring the Data, Computations and Program B y Kainjan Sanghavi Contents Monomorphic versus polymorphic type systems Case Study- The type structure of C++ and Java Structuring the computation

Motivation for typed languages

Motivation for typed languages Untyped Languages: perform any operation on any data. Example: Assembly movi 5 r0 // Move integer 5 (some representation) to r0 addf 3.6 r0 // Treat bit representation in

CSE 431S Type Checking. Washington University Spring 2013

CSE 431S Type Checking Washington University Spring 2013 Type Checking When are types checked? Statically at compile time Compiler does type checking during compilation Ideally eliminate runtime checks

LECTURE 17. Expressions and Assignment

LECTURE 17 Expressions and Assignment EXPRESSION SYNTAX An expression consists of An atomic object, e.g. number or variable. An operator (or function) applied to a collection of operands (or arguments)

Types and Type Inference

Types and Type Inference Mooly Sagiv Slides by Kathleen Fisher and John Mitchell Reading: Concepts in Programming Languages, Revised Chapter 6 - handout on the course homepage Outline General discussion

Simple Data Types in C. Alan L. Cox

Simple Data Types in C Alan L. Cox alc@rice.edu Objectives Be able to explain to others what a data type is Be able to use basic data types in C programs Be able to see the inaccuracies and limitations

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Java basics: Compilation vs Interpretation Program structure Statements Values Variables Types Operators and Expressions

CS558 Programming Languages

CS558 Programming Languages Fall 2016 Lecture 7a Andrew Tolmach Portland State University 1994-2016 Values and Types We divide the universe of values according to types A type is a set of values and a

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Overview of OOP Dr. Zhang COSC 1436 Summer, 2017 7/18/2017 Review Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in square brackets: l = [1, 2, "a"] (access by index, is mutable

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Outline Name, Scope and Binding In Text: Chapter 5 Names Variable Binding Type bindings, type conversion Storage bindings and lifetime Scope Lifetime vs. Scope Referencing Environments N. Meng, S. Arthur

G Programming Languages - Fall 2012

G22.2110-003 Programming Languages - Fall 2012 Lecture 6 Thomas Wies New York University Review Last week Functional Languages Lambda Calculus Scheme Outline Types Sources: PLP, ch. 7 Types What is a type?

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

CS 0 Lecture 8 Chapter 5 Louden Outline The symbol table Static scoping vs dynamic scoping Symbol table Dictionary associates names to attributes In general: hash tables, tree and lists (assignment ) can

INF 212/CS 253 Type Systems. Instructors: Harry Xu Crista Lopes

INF 212/CS 253 Type Systems Instructors: Harry Xu Crista Lopes What is a Data Type? A type is a collection of computational entities that share some common property Programming languages are designed to

Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

Expressions and Assignment Statements

Expressions and Assignment Statements Introduction Expressions are the fundamental means of specifying computations in a programming language To understand expression evaluation, need to be familiar with

Darshan Institute of Engineering & Technology for Diploma Studies Unit 5

1 What is structure? How to declare a Structure? Explain with Example Structure is a collection of logically related data items of different data types grouped together under a single name. Structure is

Informatica 3 Syntax and Semantics

Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

Organization of Programming Languages (CSE452) Instructor: Dr. B. Cheng Fall 2004 1 Why are there so many programming languages? Evolution -- we've learned better ways of doing things over time Socio-economic

CSCI-GA Scripting Languages

CSCI-GA.3033.003 Scripting Languages 12/02/2013 OCaml 1 Acknowledgement The material on these slides is based on notes provided by Dexter Kozen. 2 About OCaml A functional programming language All computation

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413

CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 13: Types and Type-Checking 19 Feb 07 Semantic Analysis Last time: Semantic errors related to scopes Symbol tables Name resolution This lecture:

CSc 520 Principles of Programming Languages. 26 : Control Structures Introduction

CSc 520 Principles of Programming Languages 26 : Control Structures Introduction Christian Collberg Department of Computer Science University of Arizona collberg+520@gmail.com Copyright c 2008 Christian

Introduction. Primitive Data Types: Integer. Primitive Data Types. ICOM 4036 Programming Languages

ICOM 4036 Programming Languages Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer and Reference Types Data Types This

Primitive Data Types: Intro

Primitive Data Types: Intro Primitive data types represent single values and are built into a language Java primitive numeric data types: 1. Integral types (a) byte (b) int (c) short (d) long 2. Real types

For each of the following variables named x, specify whether they are static, stack-dynamic, or heapdynamic:

For each of the following variables named x, specify whether they are static, stack-dynamic, or heapdynamic: a) in C++: int* x = new(int); b) in Java: class book { protected string title; book(string x)

Haskell 98 in short! CPSC 449 Principles of Programming Languages

Haskell 98 in short! n Syntax and type inferencing similar to ML! n Strongly typed! n Allows for pattern matching in definitions! n Uses lazy evaluation" F definition of infinite lists possible! n Has

Subprograms. Bilkent University. CS315 Programming Languages Pinar Duygulu

1 Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University Introduction 2 Two fundamental abstraction facilities Process abstraction Emphasized from early days Data abstraction Emphasized

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad-00 014 Subject: PPL Class : CSE III 1 P a g e DEPARTMENT COMPUTER SCIENCE AND ENGINEERING S No QUESTION Blooms Course taxonomy level Outcomes UNIT-I

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

CS-3160 Concepts of Programming Languages Spring 2015 EXAM #1 (Chapters 1-6) Name: SCORES MC: /75 PROB #1: /15 PROB #2: /10 TOTAL: /100 Multiple Choice Responses Each multiple choice question in the separate

Organization of Programming Languages CS3200 / 5200N. Lecture 06

Organization of Programming Languages CS3200 / 5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Data Types A data type defines a collection of data objects

Structures and Pointers

Structures and Pointers Comp-206 : Introduction to Software Systems Lecture 11 Alexandre Denault Computer Science McGill University Fall 2006 Note on Assignment 1 Please note that handin does not allow

Continuations provide a novel way to suspend and reexecute

Continuations provide a novel way to suspend and reexecute computations. 2. ML ( Meta Language ) Strong, compile-time type checking. Types are determined by inference rather than declaration. Naturally

Chapter 8. Fundamental Characteristics of Subprograms. 1. A subprogram has a single entry point

Fundamental Characteristics of Subprograms 1. A subprogram has a single entry point 2. The caller is suspended during execution of the called subprogram 3. Control always returns to the caller when the

Chapter 7 Expressions and Assignment statements

Chapter 7 Expressions and Assignment statements 1 7.1 Introduction Expressions are the fundamental means of specifying computations in a programming language Semantics of expressions are discussed in this

first class citizens

Data Types, Memory Data Types Values held in machine locations Integers, reals, characters, Booleans are built into languages as primitive types Machine location directly contains the value Efficiently

Information Science 1

Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting

INF 212 ANALYSIS OF PROG. LANGS Type Systems. Instructors: Crista Lopes Copyright Instructors.

INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright Instructors. What is a Data Type? A type is a collection of computational entities that share some common property Programming

9. Subprograms. 9.2 Fundamentals of Subprograms

9. Subprograms 9.2 Fundamentals of Subprograms General characteristics of subprograms A subprogram has a single entry point The caller is suspended during execution of the called subprogram Control always

Final-Term Papers Solved MCQS with Reference

Solved MCQ(S) From FinalTerm Papers BY Arslan Jan 14, 2018 V-U For Updated Files Visit Our Site : Www.VirtualUstaad.blogspot.com Updated. Final-Term Papers Solved MCQS with Reference 1. The syntax of PHP

Object Oriented Paradigm History Simula 67 A Simulation Language 1967 (Algol 60 based) Smalltalk OO Language 1972 (1 st version) 1980 (standard) Background Ideas Record + code OBJECT (attributes + methods)

Software II: Principles of Programming Languages. Why Expressions?

Software II: Principles of Programming Languages Lecture 7 Expressions and Assignment Statements Why Expressions? Expressions are the fundamental means of specifying computations in a programming language

Expressions and Assignment

Expressions and Assignment COS 301: Programming Languages Outline Other assignment mechanisms Introduction Expressions: fundamental means of specifying computations Imperative languages: usually RHS of

Organization of Programming Languages CS 3200/5200N. Lecture 09

Organization of Programming Languages CS 3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Control Flow Control flow = the flow of control, or execution

Type systems. Static typing

Type system A type is a set of values and operations on those values A language s type system specifies which operations are valid for a type The aim of type checking is to ensure that operations are used

Pierce Ch. 3, 8, 11, 15. Type Systems

Pierce Ch. 3, 8, 11, 15 Type Systems Goals Define the simple language of expressions A small subset of Lisp, with minor modifications Define the type system of this language Mathematical definition using

Imperative Programming

Naming, scoping, binding, etc. Instructor: Dr. B. Cheng Fall 2004 1 Imperative Programming The central feature of imperative languages are variables Variables are abstractions for memory cells in a Von