Static Checking and Type Systems Chapter 6. 2 Static versus Dynamic Checking Static checking: the compiler enforces programming language’s static semantics.

Slides:



Advertisements
Similar presentations
CS3012: Formal Languages and Compilers Static Analysis the last of the analysis phases of compilation type checking - is an operator applied to an incompatible.
Advertisements

CPSC 388 – Compiler Design and Construction
Semantic Analysis and Symbol Tables
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
CS7100 (Prasad)L16-7AG1 Attribute Grammars Attribute Grammar is a Framework for specifying semantics and enables Modular specification.
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
Chapter 6 Type Checking Section 0 Overview 1.Static Checking Check that the source program follows both the syntactic and semantic conventions of the source.
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;
1 Pertemuan 18 & 19 Semantic Analyzer (type checking) Matakuliah: T0174 / Teknik Kompilasi Tahun: 2005 Versi: 1/6.
Chapter 6 Type Checking Section 0 Overview
Type Checking  Legality checks  Operator determination  Overload resolution.
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.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
CS784 (Prasad)L167AG1 Attribute Grammars Attribute Grammar is a Framework for specifying semantics and enables Modular specification.
Static checking and symbol table Chapter 6, Chapter 7.6 and Chapter 8.2 Static checking: check whether the program follows both the syntactic and semantic.
CSc 453 Semantic Analysis Saumya Debray The University of Arizona Tucson.
Semantic Analysis CS 671 February 5, CS 671 – Spring The Compiler So Far Lexical analysis Detects inputs with illegal tokens –e.g.: main$
COP4020 Programming Languages
Type Equivalence Rules Ada –Strict name equivalence except for almost everything Unique array constructors give rise to unique types Subtypes can create.
1 Static Checking and Type Systems Chapter 6 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
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.
Lesson 11 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
410/510 1 of 18 Week 5 – Lecture 1 Semantic Analysis Compiler Construction.
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.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
1 Static Checking and Type Systems Chapter 6 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
More on Type Checking. Conversion and Coercion Int C; A = C;
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
Data Types (3) 1 Programming Languages – Principles and Practice by Kenneth C Louden.
1 February 17, February 17, 2016February 17, 2016February 17, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
©SoftMoore ConsultingSlide 1 Structure of Compilers.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
ENEE150 – 0102 ANDREW GOFFIN Abstract Data Types.
COP4020 Programming Languages Introduction Prof. Robert van Engelen (modified by Prof. Em. Chris Lacher)
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Object Oriented Programming Lecture 2: BallWorld.
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Arvind Computer Science and Artificial Intelligence Laboratory M.I.T. L05-1 September 21, 2006http:// Types and Simple Type.
Dr. M. Al-Mulhem Introduction 1 Chapter 6 Type Systems.
1 Static Checking and Type Systems Chapter 6 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007.
Lecture 9 Symbol Table and Attributed Grammars
Compiler Design – CSE 504 Type Checking
Type Checking and Type Inference
Semantic Analysis Type Checking
Constructing Precedence Table
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Semantic Analysis with Emphasis on Name Analysis
Overview of Compilation The Compiler BACK End
Semantic Analysis Chapter 6.
Static Checking and Type Systems
Chapter 6 Intermediate-Code Generation
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Overview of Compilation The Compiler BACK End
Compilers B V Sai Aravind (11CS10008).
ML’s Type Inference and Polymorphism
Semantic Analysis Chapter 6.
ML’s Type Inference and Polymorphism
Compiler Construction
ML’s Type Inference and Polymorphism
ML’s Type Inference and Polymorphism
Type equality Programming Language Design and Implementation
Type equality Programming Language Design and Implementation
Type equality Programming Language Design and Implementation
Type equality Programming Language Design and Implementation
Compiler Construction
Type equality Programming Language Design and Implementation
Presentation transcript:

Static Checking and Type Systems Chapter 6

2 Static versus Dynamic Checking Static checking: the compiler enforces programming language’s static semantics –Program properties that can be checked at compile time Dynamic semantics: checked at run time –Compiler generates verification code to enforce programming language’s dynamic semantics

3 Static Checking Typical examples of static checking are –Type checks –Flow-of-control checks –Uniqueness checks –Name-related checks

4 Type Checks, Overloading, Coercion, and Polymorphism int op(int), op(float); int f(float); int a, c[10], d; d = c+d;// FAIL *d = a;// FAIL a = op(d);// OK: overloading (C++) a = f(d);// OK: coersion of d to float vector v;// OK: template instantiation

5 Flow-of-Control Checks myfunc() { … break; // ERROR } myfunc() { … switch (a) { case 0: … break; // OK case 1: … } myfunc() { … while (n) { … if (i>10) break; // OK }

6 Uniqueness Checks myfunc() { int i, j, i; // ERROR … } cnufym(int a, int a) // ERROR { … } struct myrec { int name; }; struct myrec // ERROR { int id; };

7 Name-Related Checks LoopA: for (int I = 0; I < n; I++) { … if (a[I] == 0) break LoopB; // Java labeled loop … }

8 One-Pass versus Multi-Pass Static Checking One-pass compiler: static checking in C, Pascal, Fortran, and many other languages is performed in one pass while intermediate code is generated –Influences design of a language: placement constraints Multi-pass compiler: static checking in Ada, Java, and C# is performed in a separate phase, sometimes by traversing a syntax tree multiple times

9 Type Expressions Type expressions are used in declarations and type casts to define or refer to a type –Primitive types, such as int and bool –Type constructors, such as pointer-to, array-of, records and classes, templates, and functions –Type names, such as typedefs in C and named types in Pascal, refer to type expressions

10 Graph Representations for Type Expressions int *fun(char*,char*) fun argspointer char intpointer char pointer Tree forms fun argspointer char intpointer DAGs

11 Name Equivalence Each type name is a distinct type, even when the type expressions the names refer to are the same Types are identical only if names match Used by Pascal (inconsistently) type link = ^node; var next : link; last : link; p : ^node; q, r : ^node; With name equivalence in Pascal: p ≠ next p ≠ last p = q = r next = last