Static Type Checking. Static Type Checking. The Type Checker. Type Annotations. Types Describe Possible Values
|
|
- Percival Johns
- 5 years ago
- Views:
Transcription
1 The Type Checker Compilation 2007 The type checker has several tasks: determine the types of all expressions check that values and variables are used correctly resolve certain ambiguities by transformations Some languages have no type checker no compile-time guarantees runtime tagging and checking become necessary Michael I. Schwartzbach BRICS, University of Aarhus 2 Types Describe Possible Values Type Annotations The Joos types are: void(the empty set of values) byte short int char boolean C (objects of class C or any subclass) null(the polymorphic null constant) σ[] (for any type σ) Type annotations: int x; Foo y; specify invariants about the runtime behavior: xwill always contain an integer value ywill always contain null or an object of class Foo or any subclass Type annotations are not very expressive viewed as invariants 3 4 1
2 Type Correctness Static Type Correctness A program is type correct if the type annotations are valid invariants Type correctness is trivially undecidable: int x = 0; TM(j); x = false; The program is type correct iff the j'th Turing machine does not halt on empty input A program is statically type correct if it satisfies some type rules The rules are chosen to be: simple to understand efficient to decide conservative with respect to type correctness Type systems are not canonical They are designed like the rest of the language 5 6 Slack Examples of Slack Static type systems are necessarily flawed: Trivial example: type correct statically type correct x = 87; if (false) x = true; Useful example: slack Map m = new Hashmap(); m.put("bar","foo"); String x = m.get("bar"); Java 1.5 is designed to pick up some slack There is always slack: programs that are unfairly rejected by the type checker 7 8 2
3 Specifying Type Rules The Shortcomings of Prose Prose: "The argument of the sqrt function must be of type int, the result is of type double" Logical rules: C - x: int C - sqrt(x): double The first expression must be of type boolean, or a compile-time error occurs. The conditional operator may be used to choose between second and third operands of numeric type, or second and third operands of type boolean, or second and third operands that are each of either reference type or the null type. All other cases result in a compile-time error. Note that it is not permitted for either the second or the third operand expression to be an invocation of a void method. In fact, it is not permitted for a conditional expression to appear in any context where an invocation of a void method could appear. The type of a conditional expression is determined as follows: If the second and third operands have the same type (which may be the null type), then that is the type of the conditional expression. Otherwise, if the second and third operands have numeric type, then there are several cases:if one of the operands is of type byte and the other is of type short, then the type of the conditional expression is short. If one of the operands is of type T where T is byte, short, or char, and the other operand is a constant expression of type int whose value is representable in type T, then the type of the conditional expression is T. Otherwise, binary numeric promotion is applied to the operand types, and the type of the conditional expression is the promoted type of the second and third operands. Note that binary numeric promotion performs value set conversion. If one of the second and third operands is of the null type and the type of the other is a reference type, then the type of the conditional expression is that reference type. If the second and third operands are of different reference types, then it must be possible to convert one of the types to the other type (call this latter type T) by assignment conversion; the type of the conditional expression is T. It is a compile-time error if neither type is assignment compatible with the other type Three Kinds of Type Rules Judging Expressions Declarations: this variable is declared to have this type Propagations: if the argument is of this type, then the result is of that type Restrictions: the argument must be of this type or that type The logical notation handles all three uniformly The judgment: C, L, X, σ - E: τ means that the expression E is statically type correct and has type τ in a context where: C is the current class L is the current local environment X is the current set of exceptions σ is the return type of the current method
4 Judging Statements Class Environments The judgment: C, L, X, σ - S means that the statement S is statically type correct in a context where: C is the current class L is the current local environment X is the current set of exceptions σ is the return type of the current method 13 The class environment is implicitly available The notation D C means that D is a subclass of C We can query a class C: C - extends D (super class) C - σ f (fields) C - static σ f (static fields) C - (σ 1,..., σ k ) X (constructors) C - σ m (σ 1,..., σ k ) X (methods) C - static σ m (σ 1,..., σ k ) X (static methods) return type name argument types thrown exceptions 14 Assignment Compatibility The relation σ := τ means that values of type τ may be assigned to variables of type σ: σ := σ short := byte σ :- σ int := byte int := short σ[] :- τ[], if σ :- τ int := char C := null java.lang.cloneable :- σ[] σ[] := null Object := σ[] java.io.serializable :- σ[] java.lang.cloneable := σ[] Object :- σ[] java.io.serializable := σ[] C :- D, if D C σ[] := τ[], if σ :- τ C := D, if D C Assignment Compatibility The relation σ := τ means that values of type τ may be assigned to variables of type σ: σ := σ short := byte σ :- σ int := byte int := short σ[] :- τ[], if σ :- τ int := char C := null java.lang.cloneable Turbo-Pascal: :- σ[] σ[] := null Object := σ[] java.io.serializable :- σ[] java.lang.cloneable := σ[] C :- D, if D reflexive C transitive java.io.serializable := σ[] anti-symmetric σ[] := τ[], if σ :- τ symmetric C := D, if D C It is reflexive, transitive, and anti-symmetric It is reflexive, transitive, and anti-symmetric
5 Statements Control Statements C,L,X,σ - S 1 C,L,X,σ - S 2 C, L, X, σ - S 1 S 2 C,L,X,σ - E: boolean C, L, X, σ - if (E) S C,L,X,σ - S C, L[n τ], X, σ - S C, L, X, σ - { τ n; S } C,L,X,σ - E: boolean C,L,X,σ - S i C, L, X, σ - if (E) S 1 else S 2 C, L, X, σ - E: τ C, L, X, σ - E; C,L,X,σ - E: boolean C, L, X, σ - while (E) S C,L,X,σ - S Return Statements Throw Statement σ = void C, L, X, σ - return C,L,X, σ - E: τ throwok({τ},x) C, L, X, σ - throw E C, L, X, σ - E: τ σ := τ C, L, X, σ - return E throwok(a,b) α A: Error:= α RuntimeException:= α β B: β:=α
6 Locals Fields L(n) = τ C, L, X, σ - n: τ C,L,X,σ - this: C D - static τ f C,L,X,σ - D.f: τ C,L,X,σ - E: D D - τ f C, L, X, σ - E.f: τ Assignments Arrays C,L,X,σ - E: τ 2 L(n)=τ 1 τ 1 :=τ 2 C, L, X, σ - n = E: τ 1 C,L,X,σ - E 1 : τ 1 [] C,L,X,σ - E 2 : τ 2 num(τ 2 ) C, L, X, σ - E 1 [E 2 ]: τ 1 C,L,X,σ - E: τ 2 D - static τ 1 f τ 1 :=τ 2 C, L, X, σ - D.f = E: τ 1 C,L,X,σ - E 2 : τ 2 C,L,X,σ - E 1 : D D - τ 1 f τ 1 :=τ 2 C, L, X, σ - E 1.f = E 2 : τ 1 C, L, X, σ - E 1 : τ 1 [] C, L, X, σ - E 2 : τ 2 C, L, X, σ - E 3 : τ 3 num(τ 2 ) τ 1 := τ 3 C, L, X, σ - E 1 [E 2 ]= E 3 : τ 1 num(σ) σ { byte, short, int, char }
7 Array Operations Operators C,L,X,σ - E: τ[] C,L,X,σ - E.clone(): Object C,L,X,σ - E: τ[] C,L,X,σ - E.length: int C,L,X,σ - E: boolean C,L,X,σ -!E: boolean C,L,X,σ - E 1 : τ 1 C,L,X,σ - E 2 : τ 2 num(τ 1 ) num(τ 2 ) C, L, X, σ - E 1 *E 2 : int C,L,X,σ - E: τ 2 num(τ 2 ) C,L,X,σ - new τ 1 [E]: τ 1 [] Literals Plus C,L,X,σ - true: boolean C,L,X,σ - E 1 : τ 1 C,L,X,σ - E 2 : τ 2 num(τ 1 ) num(τ 2 ) C, L, X, σ - E 1 +E 2 : int C,L,X,σ - 42: int C,L,X,σ - "abc": String C,L,X,σ - E 1 : String C,L,X,σ - E 2 : τ 2 τ 2 void C, L, X, σ - E 1 +E 2 : String C,L,X,σ - null: null C,L,X,σ - '@': char C,L,X,σ - E 1 : τ 1 C,L,X,σ - E 2 : String τ 1 void C, L, X, σ - E 1 +E 2 : String
8 Equality Casts and Instanceof C,L,X,σ - E 1 : τ 1 C,L,X,σ - E 2 : τ 2 (num(τ 1 ) num(τ 2 )) τ 1 :=τ 2 τ 2 :=τ 1 C, L, X, σ - E 1 ==E 2 : boolean C,L,X,σ - E: τ 1 (num(τ 1 ) num(τ 2 )) τ 1 :=τ 2 τ 2 :=τ 1 C, L, X, σ - (τ 2 )E: τ 2 C,L,X,σ - E: τ τ:=d D:=τ C, L, X, σ - E instanceof D: boolean Why Restrict Casts? Method Invocation τ 2 τ 1 τ 1 τ 2 Alway succeeds, but downcasting is useful for selecting different methods τ 2 := τ 1 Really useful, the object may or may not by a subclass of τ 2 C,L,X,σ - E: D C,L,X,σ - E i : τ i D - τ m(τ 1,...,τ k ) Y C, L, X, σ - E.m(E 1,...,E k ): τ τ 1 := τ 2 C,L,X,σ - E i : τ i τ 2 τ 1 Always fails, don't bother to execute D - static τ m(τ 1,...,τ k ) Y C, L, X, σ - D.m(E 1,...,E k ): τ τ 1 : τ 2 τ 1 : τ
9 Constructor Invocation Closest Match Method Invocation C,L,X,σ - E i : τ i D - (τ 1,...,τ k ) Y throwok(y,x) C, L, X, σ - new D(E 1,...,E k ): D C,L,X,σ - E i : τ i C - extends D D - (τ 1,...,τ k ) Y throwok(y,x) C, L, X, σ - super(e 1,...,E k ) C,L,X,σ - E: D C,L,X,σ - E i : σ i D - τ m(τ 1,...,τ k ) Y τ i := σ i D - γ m(γ 1,..., γ k ) Z : ( i : γ i := σ i ) ( i : γ i := τ i ) C, L, X, σ - E.m(E 1,...,E k ): τ This rule does not describe access modifiers Checking Exceptions Judging Methods and Constructors C, L, X, σ - E: D C, L, X, σ - E.m(E 1,...,E k ): τ C, [a i σ i ], { X i }, σ - S Throwable := X i C - σ m(σ 1 a 1,...,σ k a k )throws X 1,...,X n { S } throwok( {Y i D - τ m(τ 1,...,τ k ) Y i }, X) C, [a i σ i ], { X i }, void - S Throwable := X i Y Z = Y Z Z Y C - C(σ 1 a 1,...,σ k a k )throws X 1,...,X n { S } Y Z = { y Y throwok({y},z) }
10 Different Kinds of Type Rules Type Proofs Axioms: C,L,X,σ - this: C A type proof is a tree in which: nodes are inferences leaves are axioms or true predicates Predicates: τ 1 :=τ 2 τ 1 :=τ 2 Inferences: C,L,X,σ - E: D D - τ f A judgment is valid it is the root of some type proof C, L, X, σ - E.f: τ A Type Proof Static Type Correctness [x A,y B](x)=A C,[x A,y B],X,σ - x:a A B B A [x A,y B](y)=B C,[x A,y B],X,σ - (B)x: B B:=B C,[x A,y B],X, σ - y=(b)x: B C,[x A,y B],X, σ - y=(b)x; C,[x A],X, σ - {B y; y=(b)x;} C,[],X,σ - {A x; {B y; y=(b)x;}} (Assuming that B is a subclass of A) A program is statically type correct all method and constructor judgments are valid A type system is sound static type correctness implies type correctness Equal to a trace of a successful run of the type checker
11 Java's Type System is Unsound Greed The following is a valid judgement: Java's type system is too greedy: C, [b B,x A[],y B[],c C], X, σ - x=y; x[0]=c; b=y[0]; where B A, C A, and B and C are incomparable Afterward, b contains an object of class C But its declared type only allows B objects type correct statically type correct unsound Runtime type checks catch the unsound cases Fixed Assignment Compatibility Complexity of Inference Systems By design, the rule for assignment of arrays has been chosen to be convenient but unsound It should have looked like: σ := σ short := byte σ :- σ int := byte int := short σ[] :- τ[], if σ :- τ int := char C := null java.lang.cloneable :- σ[] σ[] := null Object := σ[] java.io.serializable :- σ[] java.lang.cloneable := σ[] C :- D, if D C java.io.serializable := σ[] σ[] := τ[], if σ :- τ C := D, if D C Deciding valid judgments of an inference system depends on its rules and axioms and may be: undecidable (hyper)exponential time (backtracking) linear time The Java type system is designed to be simple A type checker performs a single traversal of the parse tree in linear time But that would then introduce annoying slack
12 Type Checking in Java Implicit Coercions Type checking is performed bottom-up The rule to apply is uniquely determined by the types of subexpressions and the syntax The type proof also specifies how to transform the program with respect to: address comparisons implicit string conversions concat(...) code Suppose we add a coercion type rule: C,L,X,σ - E: int C,L,X,σ - E: float corresponding to the JVM bytecode i2f Type proofs are now no longer unique! Ambiguous Type Proofs Semantic Coherence L(i)=int L(j)=int C,L,X,σ -i: int C,L,X,σ - j: int C,L,X,σ -i: float C,L,X,σ - j: float L(f)=float C,L,X,σ - i+j: float C,L,X,σ - f: float C,L,X,σ - i+j==f: boolean L(i)=int L(j)=int C,L,X,σ -i: int C,L,X,σ - j: int C,L,X,σ -i+j: int L(f)=float C,L,X,σ - i+j: float C,L,X,σ - f: float C,L,X,σ - i+j==f: boolean Different type proofs generate different transformed programs The type system is semantically coherent if they always have the same semantics The previous hypothetical type system is not: i = j = f = E9 Java chooses the proof with coercions as near the root as possible
Compilation 2012 Static Type Checking
Compilation 2012 Jan Midtgaard Michael I. Schwartzbach Aarhus University The Type Checker The type checker has several tasks: determine the types of all expressions check that values and variables are
More informationType Checking. COMP 520: Compiler Design (4 credits) Alexander Krolik MWF 9:30-10:30, TR Bob, from Accounting.
COMP 520 Winter 2018 Type Checking (1) Type Checking COMP 520: Compiler Design (4 credits) Alexander Krolik alexander.krolik@mail.mcgill.ca MWF 9:30-10:30, TR 1080 http://www.cs.mcgill.ca/~cs520/2018/
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationIntermediate Code Generation Part II
Intermediate Code Generation Part II Chapter 6: Type checking, Control Flow Slides adapted from : Robert van Engelen, Florida State University Static versus Dynamic Checking Static checking: the compiler
More informationOperators and Expressions
Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions
More informationAP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS
AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this
More informationIntroduction A Tiny Example Language Type Analysis Static Analysis 2009
Introduction A Tiny Example Language Type Analysis 2009 Michael I. Schwartzbach Computer Science, University of Aarhus 1 Questions About Programs Does the program terminate? How large can the heap become
More informationSubtyping. Lecture 13 CS 565 3/27/06
Subtyping Lecture 13 CS 565 3/27/06 Polymorphism Different varieties of polymorphism: Parametric (ML) type variables are abstract, and used to encode the fact that the same term can be used in many different
More informationTypes. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus
Types Type checking What is a type? The notion varies from language to language Consensus A set of values A set of operations on those values Classes are one instantiation of the modern notion of type
More informationType Checking and Type Inference
Type Checking and Type Inference Principles of Programming Languages CSE 307 1 Types in Programming Languages 2 Static Type Checking 3 Polymorphic Type Inference Version: 1.8 17:20:56 2014/08/25 Compiled
More informationStatic Checking and Type Systems
1 Static Checking and Type Systems Chapter 6 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2009 2 The Structure of our Compiler Revisited Character stream Lexical
More informationWeiss Chapter 1 terminology (parenthesized numbers are page numbers)
Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement
More informationStatic Program Analysis Part 1 the TIP language
Static Program Analysis Part 1 the TIP language http://cs.au.dk/~amoeller/spa/ Anders Møller & Michael I. Schwartzbach Computer Science, Aarhus University Questions about programs Does the program terminate
More informationCS558 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
More informationContents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix
PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring
More informationInheritance. SOTE notebook. November 06, n Unidirectional association. Inheritance ("extends") Use relationship
Inheritance 1..n Unidirectional association Inheritance ("extends") Use relationship Implementation ("implements") What is inherited public, protected methods public, proteced attributes What is not inherited
More informationType Checking. Error Checking
Type Checking Error Checking Dynamic checking takes place while program is running Static checking takes place during compilation Type checks Flow-of-control checks Uniqueness checks Name-related checks
More informationCompilation 2012 Code Generation
Compilation 2012 Jan Midtgaard Michael I. Schwartzbach Aarhus University Phases Computing resources, such as: layout of data structures offsets register allocation Generating an internal representation
More informationCSE 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
More informationConcepts Introduced in Chapter 6
Concepts Introduced in Chapter 6 types of intermediate code representations translation of declarations arithmetic expressions boolean expressions flow-of-control statements backpatching EECS 665 Compiler
More information1 Shyam sir JAVA Notes
1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write
More informationJava Overview An introduction to the Java Programming Language
Java Overview An introduction to the Java Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Dr. Siobhan Drohan (sdrohan@wit.ie) Department of Computing and Mathematics http://www.wit.ie/
More informationPierce 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
More informationStatic Semantics. Winter /3/ Hal Perkins & UW CSE I-1
CSE 401 Compilers Static Semantics Hal Perkins Winter 2009 2/3/2009 2002-09 Hal Perkins & UW CSE I-1 Agenda Static semantics Types Symbol tables General ideas for now; details later for MiniJava project
More informationTradeoffs. CSE 505: Programming Languages. Lecture 15 Subtyping. Where shall we add useful completeness? Where shall we add completeness?
Tradeoffs CSE 505: Programming Languages Lecture 15 Subtyping Zach Tatlock Autumn 2017 Desirable type system properties (desiderata): soundness - exclude all programs that get stuck completeness - include
More informationContext-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5
Context-Free Languages & Grammars (CFLs & CFGs) Reading: Chapter 5 1 Not all languages are regular So what happens to the languages which are not regular? Can we still come up with a language recognizer?
More informationCompilation 2012 Static Analysis
Compilation 2012 Jan Midtgaard Michael I. Schwartzbach Aarhus University Interesting Questions Is every statement reachable? Does every non-void method return a value? Will local variables definitely be
More informationFrom IMP to Java. Andreas Lochbihler. parts based on work by Gerwin Klein and Tobias Nipkow ETH Zurich
From IMP to Java Andreas Lochbihler ETH Zurich parts based on work by Gerwin Klein and Tobias Nipkow 2015-07-14 1 Subtyping 2 Objects and Inheritance 3 Multithreading 1 Subtyping 2 Objects and Inheritance
More informationAssignment 4: Semantics
Assignment 4: Semantics 15-411: Compiler Design Jan Hoffmann Jonathan Burns, DeeDee Han, Anatol Liu, Alice Rao Due Thursday, November 3, 2016 (9:00am) Reminder: Assignments are individual assignments,
More informationFeatherweight Java (FJ)
x = 1 let x = 1 in... x(1).!x(1) x.set(1) Programming Language Theory Featherweight Java (FJ) Ralf Lämmel This lecture is based on David Walker s lecture: Computer Science 441, Programming Languages, Princeton
More informationExercise 12 Initialization December 15, 2017
Concepts of Object-Oriented Programming AS 2017 Exercise 12 Initialization December 15, 2017 Task 1 Consider a Java class Vector, representing a 2 dimensional vector: public class Vector { public Number!
More information4 CoffeeStrainer Virtues and Limitations
In this chapter, we explain CoffeeStrainer s virtues and limitations and the design decisions that led to them. To illustrate the points we want to make, we contrast CoffeeStrainer with a hypothetical,
More informationJava Primer 1: Types, Classes and Operators
Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,
More informationCOS 320. Compiling Techniques
Topic 5: Types COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Types: potential benefits (I) 2 For programmers: help to eliminate common programming mistakes, particularly
More informationPace University. Fundamental Concepts of CS121 1
Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction
More informationCS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012
CS-XXX: Graduate Programming Languages Lecture 9 Simply Typed Lambda Calculus Dan Grossman 2012 Types Major new topic worthy of several lectures: Type systems Continue to use (CBV) Lambda Caluclus as our
More informationTopic 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
More informationTopic 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
More informationCSC Java Programming, Fall Java Data Types and Control Constructs
CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference
More informationLecture #23: Conversion and Type Inference
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). Last modified: Fri Oct 20 10:46:40 2006 CS164:
More informationConversion vs. Subtyping. Lecture #23: Conversion and Type Inference. Integer Conversions. Conversions: Implicit vs. Explicit. Object x = "Hello";
Lecture #23: Conversion and Type Inference Administrivia. Due date for Project #2 moved to midnight tonight. Midterm mean 20, median 21 (my expectation: 17.5). In Java, this is legal: Object x = "Hello";
More informationMosig M1 - PLSCD Written exam
Mosig M1 - PLSCD 0809 - Written exam 1 Exercise I : Operational semantics - a debugger In this exercise we consider program execution with the help of a debugger. This execution will be defined on an intermediate
More informationPoints To Remember for SCJP
Points To Remember for SCJP www.techfaq360.com The datatype in a switch statement must be convertible to int, i.e., only byte, short, char and int can be used in a switch statement, and the range of the
More informationCLASS DESIGN. Objectives MODULE 4
MODULE 4 CLASS DESIGN Objectives > After completing this lesson, you should be able to do the following: Use access levels: private, protected, default, and public. Override methods Overload constructors
More informationConcepts Introduced in Chapter 6
Concepts Introduced in Chapter 6 types of intermediate code representations translation of declarations arithmetic expressions boolean expressions flow-of-control statements backpatching EECS 665 Compiler
More informationLecture 13: Subtyping
Lecture 13: Subtyping Polyvios Pratikakis Computer Science Department, University of Crete Type Systems and Programming Languages Pratikakis (CSD) Subtyping CS546, 2018-2019 1 / 15 Subtyping Usually found
More informationJava Programming. Atul Prakash
Java Programming Atul Prakash Java Language Fundamentals The language syntax is similar to C/ C++ If you know C/C++, you will have no trouble understanding Java s syntax If you don't, it will be easier
More information5) Attacker causes damage Different to gaining control. For example, the attacker might quit after gaining control.
Feb 23, 2009 CSE, 409/509 Mitigation of Bugs, Life of an exploit 1) Bug inserted into code 2) Bug passes testing 3) Attacker triggers bug 4) The Attacker gains control of the program 5) Attacker causes
More informationProgramming Languages Lecture 15: Recursive Types & Subtyping
CSE 230: Winter 2008 Principles of Programming Languages Lecture 15: Recursive Types & Subtyping Ranjit Jhala UC San Diego News? Formalize first-order type systems Simple types (integers and booleans)
More informationProgramming Lecture 3
Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements
More informationData 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
More informationOutline. 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,
More informationThe Sun s Java Certification and its Possible Role in the Joint Teaching Material
The Sun s Java Certification and its Possible Role in the Joint Teaching Material Nataša Ibrajter Faculty of Science Department of Mathematics and Informatics Novi Sad 1 Contents Kinds of Sun Certified
More informationJAVA Programming Fundamentals
Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol
More informationDD2460 Software Safety and Security: Part III Exercises session 2: Type + Jif
DD2460 Software Safety and Security: Part III Exercises session 2: Type + Jif Gurvan Le Guernic adapted from Aslan Askarov DD2460 (III, E2) February 22 st, 2012 1 Noninterference type systems challenge
More informationIndex COPYRIGHTED MATERIAL
Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes
More information1 Introduction. 3 Syntax
CS 6110 S18 Lecture 19 Typed λ-calculus 1 Introduction Type checking is a lightweight technique for proving simple properties of programs. Unlike theorem-proving techniques based on axiomatic semantics,
More informationGradual Typing for Functional Languages. Jeremy Siek and Walid Taha (presented by Lindsey Kuper)
Gradual Typing for Functional Languages Jeremy Siek and Walid Taha (presented by Lindsey Kuper) 1 Introduction 2 What we want Static and dynamic typing: both are useful! (If you re here, I assume you agree.)
More informationModern Programming Languages. Lecture Java Programming Language. An Introduction
Modern Programming Languages Lecture 27-30 Java Programming Language An Introduction 107 Java was developed at Sun in the early 1990s and is based on C++. It looks very similar to C++ but it is significantly
More informationLECTURE 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)
More information3. Java - Language Constructs I
Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks
More informationCSE P 501 Compilers. Static Semantics Hal Perkins Winter /22/ Hal Perkins & UW CSE I-1
CSE P 501 Compilers Static Semantics Hal Perkins Winter 2008 1/22/2008 2002-08 Hal Perkins & UW CSE I-1 Agenda Static semantics Types Attribute grammars Representing types Symbol tables Note: this covers
More informationComputer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres
Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres dgriol@inf.uc3m.es Introduction He am a driver might be syntactically correct but semantically wrong. Semantic
More informationF1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept
F1 A Java program Ch 1 in PPIJ Introduction to the course The computer and its workings The algorithm concept The structure of a Java program Classes and methods Variables Program statements Comments Naming
More informationTypes, Expressions, and States
8/27: solved Types, Expressions, and States CS 536: Science of Programming, Fall 2018 A. Why? Expressions represent values in programming languages, relative to a state. Types describe common properties
More informationType Systems, Type Inference, and Polymorphism
6 Type Systems, Type Inference, and Polymorphism Programming involves a wide range of computational constructs, such as data structures, functions, objects, communication channels, and threads of control.
More information1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.
1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered
More informationToday. Instance Method Dispatch. Instance Method Dispatch. Instance Method Dispatch 11/29/11. today. last time
CS2110 Fall 2011 Lecture 25 Java program last time Java compiler Java bytecode (.class files) Compile for platform with JIT Interpret with JVM Under the Hood: The Java Virtual Machine, Part II 1 run native
More informationProgram Fundamentals
Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java
More informationMotivation 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
More informationLambda Calculus. Variables and Functions. cs3723 1
Lambda Calculus Variables and Functions cs3723 1 Lambda Calculus Mathematical system for functions Computation with functions Captures essence of variable binding Function parameters and substitution Can
More informationObject Oriented Programming Using C++ Mathematics & Computing IET, Katunayake
Assigning Values // Example 2.3(Mathematical operations in C++) float a; cout > a; cout
More informationDOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS
Chapter 1 : Chapter-wise Java Multiple Choice Questions and Answers Interview MCQs Java Programming questions and answers with explanation for interview, competitive examination and entrance test. Fully
More informationSimply-Typed Lambda Calculus
#1 Simply-Typed Lambda Calculus #2 Back to School What is operational semantics? When would you use contextual (small-step) semantics? What is denotational semantics? What is axiomatic semantics? What
More informationContents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance
Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass
More informationCOMP 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
More informationCSCE 314 Programming Languages. Type System
CSCE 314 Programming Languages Type System Dr. Hyunyoung Lee 1 Names Names refer to different kinds of entities in programs, such as variables, functions, classes, templates, modules,.... Names can be
More informationCSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige
CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors
More informationRelation Overriding. Syntax and Semantics. Simple Semantic Domains. Operational Semantics
SE3E03, 2006 1.59 61 Syntax and Semantics Syntax Shape of PL constructs What are the tokens of the language? Lexical syntax, word level How are programs built from tokens? Mostly use Context-Free Grammars
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationCS260 Intro to Java & Android 03.Java Language Basics
03.Java Language Basics http://www.tutorialspoint.com/java/index.htm CS260 - Intro to Java & Android 1 What is the distinction between fields and variables? Java has the following kinds of variables: Instance
More informationPolymorphism. return a.doublevalue() + b.doublevalue();
Outline Class hierarchy and inheritance Method overriding or overloading, polymorphism Abstract classes Casting and instanceof/getclass Class Object Exception class hierarchy Some Reminders Interfaces
More informationSubtyping (cont) Lecture 15 CS 565 4/3/08
Subtyping (cont) Lecture 15 CS 565 4/3/08 Formalization of Subtyping Inversion of the subtype relation: If σ
More informationProgramming Languages and Compilers (CS 421)
Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC http://courses.engr.illinois.edu/cs421 Based in part on slides by Mattox Beckman, as updated by Vikram Adve and Gul Agha 10/3/17
More informationCS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011
CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine
More informationFirst IS-A Relationship: Inheritance
First IS-A Relationship: Inheritance The relationships among Java classes form class hierarchy. We can define new classes by inheriting commonly used states and behaviors from predefined classes. A class
More informationCS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08
CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 17: Types and Type-Checking 25 Feb 08 CS 412/413 Spring 2008 Introduction to Compilers 1 What Are Types? Types describe the values possibly
More informationChapter 2: Basic Elements of Java
Chapter 2: Basic Elements of Java TRUE/FALSE 1. The pair of characters // is used for single line comments. ANS: T PTS: 1 REF: 29 2. The == characters are a special symbol in Java. ANS: T PTS: 1 REF: 30
More informationPrinciples of Programming Languages
Principles of Programming Languages Lesson 14 Type Checking Collaboration and Management Dana Fisman www.cs.bgu.ac.il/~ppl172 1 Type Checking We return to the issue of type safety we discussed informally,
More informationCSC 467 Lecture 13-14: Semantic Analysis
CSC 467 Lecture 13-14: Semantic Analysis Recall Parsing is to translate token stream to parse tree Today How to build trees: syntax direction translation How to add information to trees: semantic analysis
More informationType checking. Jianguo Lu. November 27, slides adapted from Sean Treichler and Alex Aiken s. Jianguo Lu November 27, / 39
Type checking Jianguo Lu November 27, 2014 slides adapted from Sean Treichler and Alex Aiken s Jianguo Lu November 27, 2014 1 / 39 Outline 1 Language translation 2 Type checking 3 optimization Jianguo
More informationSome instance messages and methods
Some instance messages and methods x ^x y ^y movedx: dx Dy: dy x
More informationSelected Java Topics
Selected Java Topics Introduction Basic Types, Objects and Pointers Modifiers Abstract Classes and Interfaces Exceptions and Runtime Exceptions Static Variables and Static Methods Type Safe Constants Swings
More informationProgramming Lecture 3
Five-Minute Review 1. What is a variable? 2. What is a class? An object? 3. What is a package? 4. What is a method? A constructor? 5. What is an object variable? 1 Programming Lecture 3 Expressions etc.
More informationCompiler Construction I
TECHNISCHE UNIVERSITÄT MÜNCHEN FAKULTÄT FÜR INFORMATIK Compiler Construction I Dr. Michael Petter, Dr. Axel Simon SoSe 2014 1 / 30 Topic: Semantic Analysis 2 / 30 Semantic Analysis Chapter 1: Type Checking
More informationComputer Components. Software{ User Programs. Operating System. Hardware
Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point
More informationpublic class Test { static int age; public static void main (String args []) { age = age + 1; System.out.println("The age is " + age); }
Question No :1 What is the correct ordering for the import, class and package declarations when found in a Java class? 1. package, import, class 2. class, import, package 3. import, package, class 4. package,
More informationfor (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }
Ex: The difference between Compiler and Interpreter The interpreter actually carries out the computations specified in the source program. In other words, the output of a compiler is a program, whereas
More informationCompilers CS S-05 Semantic Analysis
Compilers CS414-2003S-05 Semantic Analysis David Galles Department of Computer Science University of San Francisco 05-0: Syntax Errors/Semantic Errors A program has syntax errors if it cannot be generated
More information