Programming Languages and Compilers (CS 421)

Slides:



Advertisements
Similar presentations
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
Advertisements

CSE 341, Winter Type Systems Terms to learn about types: –Type –Type system –Statically typed language –Dynamically typed language –Type error –Strongly.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
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.
9/18/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
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.
10/14/20151 Programming Languages and Compilers (CS 421) Grigore Rosu 2110 SC, UIUC Slides by Elsa Gunter, based.
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.
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
10/16/081 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
2/6/20161 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
6/21/20161 Programming Languages and Compilers (CS 421) Reza Zamani Based in part on slides by Mattox Beckman,
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Chapter 5 Names, Bindings, Type Checking CSCE 343.
Data Types In Text: Chapter 6.
Type Checking and Type Inference
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Names and Attributes Names are a key programming language feature
CS 326 Programming Languages, Concepts and Implementation
Programming Languages and Compilers (CS 421)
Semantic Analysis Type Checking
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Context-Sensitive Analysis
Type Checking, and Scopes
A Simple Syntax-Directed Translator
Programming Languages and Compilers (CS 421)
Expressions and Assignment
Compiler Construction (CS-636)
Lecture 4: Type Systems.
Lecture 16: Introduction to Data Types
Representation, Syntax, Paradigms, Types
Programming Languages and Compilers (CS 421)
CNIT 133 Interactive Web Pags – JavaScript and AJAX
Type Systems Terms to learn about types: Related concepts: Type
Programming Languages and Compilers (CS 421)
Expressions and Assignment Statements
Names, Binding, and Scope
Final Review In Text: Chapters 1-3, 5-11,
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421)
Representation, Syntax, Paradigms, Types
Programming Languages and Compilers (CS 421)
Final Review In Text: Chapters 1-3, 5-12,
Representation, Syntax, Paradigms, Types
Madhusudan Parthasarathy
Final Review In Text: Chapters 1-3, 5-16.
Names and Binding In Text: Chapter 5.
Programming Languages and Compilers (CS 421)
Madhusudan Parthasarathy (madhu) 3112 Siebel Center
Chapter 1 Preliminaries.
Type Systems Terms to learn: Type Type system
Programming Languages and Compilers (CS 421)
Final Review In Text: Chapters 1-3, 5-16.
C Data Types and Variable
Type Systems Terms to learn about types: Related concepts: Type
point when a program element is bound to a characteristic or property
Programming Languages and Compilers (CS 421)
Expressions and Assignment Statements
Programming Languages and Compilers (CS 421)
Classes and Objects Object Creation
Run-time environments
Presentation transcript:

Programming Languages and Compilers (CS 421) Munawar Hafiz 2219 SC, UIUC http://www.cs.illinois.edu/class/cs421/ Based in part on slides by Mattox Beckman, as updated by Vikram Adve, Gul Agha and Elsa Gunter 9/22/09

Data types play a key role in: Why Data Types? Data types play a key role in: Data abstraction in the design of programs Type checking in the analysis of programs Compile-time code generation in the translation and execution of programs 9/22/09

Type: A type t defines a set of possible data values Terminology Type: A type t defines a set of possible data values E.g. short in C is {x| 215 - 1  x  -215} A value in this set is said to have type t Type system: rules of a language assigning types to expressions 9/22/09

Types as Specifications Types describe properties Different type systems describe different properties, eg Data is read-write versus read-only Operation has authority to access data Data came from “right” source Operation might or could not raise an exception Common type systems focus on types describing same data layout and access methods 9/22/09

Sound Type System If an expression is assigned type t, and it evaluates to a value v, then v is in the set of values defined by t SML, OCAML, Scheme and Ada have sound type systems Most implementations of C and C++ do not 9/22/09

Strongly Typed Language When no application of an operator to arguments can lead to a run-time type error, language is strongly typed Eg: 1 + 2.3;; Depends on definition of “type error” 9/22/09

Strongly Typed Language C++ claimed to be “strongly typed”, but Union types allow creating a value at one type and using it at another Type coercions may cause unexpected (undesirable) effects No array bounds check (in fact, no runtime checks at all) SML, OCAML “strongly typed” but still must do dynamic array bounds checks, runtime type case analysis, and other checks 9/22/09

Static vs Dynamic Types Static type: type assigned to an expression at compile time Dynamic type: type assigned to a storage location at run time Statically typed language: static type assigned to every expression at compile time Dynamically typed language: type of an expression determined at run time 9/22/09

Type Checking When is op(arg1,…,argn) allowed? Type checking assures that operations are applied to the right number of arguments of the right types Right type may mean same type as was specified, or may mean that there is a predefined implicit coercion that will be applied Used to resolve overloaded operations 9/22/09

Statically typed languages can do most type checking statically Type checking may be done statically at compile time or dynamically at run time Dynamically typed (aka untyped) languages (eg LISP, Prolog) do only dynamic type checking Statically typed languages can do most type checking statically 9/22/09

Performed at run-time before each operation is applied Dynamic Type Checking Performed at run-time before each operation is applied Types of variables and operations left unspecified until run-time Same variable may be used at different types 9/22/09

Data object must contain type information Dynamic Type Checking Data object must contain type information Errors aren’t detected until violating application is executed (maybe years after the code was written) 9/22/09

Performed after parsing, before code generation Static Type Checking Performed after parsing, before code generation Type of every variable and signature of every operator must be known at compile time 9/22/09

Catches many programming errors at earliest point Static Type Checking Can eliminate need to store type information in data object if no dynamic type checking is needed Catches many programming errors at earliest point Can’t check types that depend on dynamically computed values Eg: array bounds 9/22/09

Static Type Checking Typically places restrictions on languages Garbage collection References instead of pointers All variables initialized when created Variable only used at one type Union types allow for work-arounds, but effectively introduce dynamic type checks 9/22/09