CSE431 Translation of Computer Languages

Similar documents
Administration. Exceptions. Leftovers. Agenda. When Things Go Wrong. Handling Errors. CS 99 Summer 2000 Michael Clarkson Lecture 11

2018/2/5 话费券企业客户接入文档 语雀

COE318 Lecture Notes Week 10 (Nov 7, 2011)

CSC207H: Software Design. Exceptions. CSC207 Winter 2018

CS159. Nathan Sprague

Object Oriented Programming

COSC 123 Computer Creativity. I/O Streams and Exceptions. Dr. Ramon Lawrence University of British Columbia Okanagan


Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling

About this exam review

CS61B Lecture #12. Today: Various odds and ends in support of abstraction.

C16b: Exception Handling

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

Basics of Java: Expressions & Statements. Nathaniel Osgood CMPT 858 February 15, 2011

Exceptions. CSC207 Winter 2017

Introduction to JavaCard Dynamic Logic

CS 520 Theory and Practice of Software Engineering Fall 2017

Programming II (CS300)

Declarations and Access Control SCJP tips

The University of Melbourne Department of Computer Science and Software Engineering Software Design Semester 2, 2003

Introduction to Computation and Problem Solving. Class 25: Error Handling in Java. Prof. Steven R. Lerman and Dr. V. Judson Harward.

Language Fundamentals Summary

Software Testing Prof. Meenakshi D Souza Department of Computer Science and Engineering International Institute of Information Technology, Bangalore

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

Java Programming: from the Beginning. Chapter 8 More Control Structures. CSc 2310: Principle of Programming g( (Java) Spring 2013

Exceptions Handling Errors using Exceptions

A Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1

Exceptions and Design

CS61B, Spring 2003 Discussion #17 Amir Kamil UC Berkeley 5/12/03

CSE 373 Data Structures and Algorithms. Lecture 2: Queues

Input Space Partitioning

Programming II (CS300)

Types, Values and Variables (Chapter 4, JLS)

Adding Machine Run 2

DOWNLOAD PDF CORE JAVA APTITUDE QUESTIONS AND ANSWERS

CS Programming I: Exceptions

Introduction to Programming Using Java (98-388)

Comp 311: Sample Midterm Examination

Oracle Corporation

Assertions, pre/postconditions

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

CSE 143 Lecture 1. Arrays (review) slides created by Marty Stepp

Formal Methods for Java

FLOW CONTROL. Author: Boaz Kantor The Interdisciplinary Center, Herzliya Introduction to Computer Science Winter Semester

Exception Handling in Java. An Exception is a compile time / runtime error that breaks off the

Java Primer. CITS2200 Data Structures and Algorithms. Topic 2

Fundamentals of Object Oriented Programming

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 11

Following is the general form of a typical decision making structure found in most of the programming languages:

Recreation. MyClass.mogrify(new int[] { 1, 2, 4, 6 }));

Lecture 5: Implementing Lists, Version 1

Exception Handling. General idea Checked vs. unchecked exceptions Semantics of... Example from text: DataAnalyzer.

Type Conversion. and. Statements

Exception Examples. All examples written by Edith Hemaspaandra and modified by Jessica Bayliss

Array. Prepared By - Rifat Shahriyar

Name Section Number. CS210 Exam #1 *** TURN OFF ALL ELECTRONIC DEVICES *** Practice

CSC Java Programming, Fall Java Data Types and Control Constructs

Example: Monte Carlo Simulation 1

Introduction to Software Design

CS 520 Theory and Practice of Software Engineering Fall 2018

Flow-sensitive rewritings and Inliner improvements for the Graal JIT compiler

Chapter 12 Exception Handling

National University. Faculty of Computer Since and Technology Object Oriented Programming

Fun facts about recursion

CS 520 Theory and Practice of Software Engineering Fall 2017

Object Oriented Programming Exception Handling

CSCI-142 Exam 2 Review November 2, 2018 Presented by the RIT Computer Science Community

CS 455: INTRODUCTION TO DISTRIBUTED SYSTEMS [THREADS] Frequently asked questions from the previous class survey

Java Loose Ends. 11 December 2017 OSU CSE 1

A problem?... Exceptions. A problem?... A problem?... Suggested Reading: Bruce Eckel, Thinking in Java (Fourth Edition) Error Handling with Exceptions

EXCEPTIONS. Objectives. The try and catch Statements. Define exceptions. Use try, catch and finally statements. Describe exception categories

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

S.No Question Blooms Level Course Outcome UNIT I. Programming Language Syntax and semantics

BBM 102 Introduction to Programming II Spring Exceptions

Solutions Manual. Data Structures and Algorithms in Java, 5th edition International Student Version. M. T. Goodrich and R.

EXCEPTIONS. Java Programming

COMP-202. Exceptions. COMP Exceptions, 2011 Jörg Kienzle and others

Data Structures G5029

ECE 122. Engineering Problem Solving with Java

LECTURE 18. Control Flow

Introduction to Programming (Java) 4/12

Exceptions in Java

Java Review Outline. basics exceptions variables arrays modulo operator if statements, booleans, comparisons loops: while and for

Basic Data Structures

COMP 110/L Lecture 10. Kyle Dewey

CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Winter /15/ Hal Perkins & UW CSE C-1

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

CS Programming I: Exceptions

CS1020 Data Structures and Algorithms I Lecture Note #8. Exceptions Handling exceptional events

Exception Handling. Sometimes when the computer tries to execute a statement something goes wrong:

Chapter 13 Exception Handling

Topic 6: Exceptions. Exceptions are a Java mechanism for dealing with errors & unusual situations

COMP-202 Unit 9: Exceptions

Introduction to Computer Science II CS S-22 Exceptions

Index COPYRIGHTED MATERIAL

CS 211: Methods, Memory, Equality

COMP-202: Foundations of Programming. Lecture 26: Review; Wrap-Up Jackie Cheung, Winter 2016

Transcription:

CSE431 Translation of Computer Languages Semantic Analysis Doug Shook

Control Structure Analysis Three major phases for Java: Type Checking How might this apply to control structures? Reachability Analysis Can we reach this statement? Throwing and Exceptions If we throw something, where do we end up? 2

Type Checking Review How would the following statement be type checked? if (i > 7 + x)...; else...; Constraints are often language specific Could the predicate be a type other than boolean? 3

Reachability Analysis Performed by a ReachabilityVisitor Responsible for setting two flags: isreachable Can we get here? terminatesnormally Does this statement terminate normally? Why do we care? 4

Reachability Rules If isreachable is true for a list of statements, then it must also be true for the first statement in the list Corresponding rule for terminatesnormally For statements in a list, there is a relationship between isreachable and terminatesnormally Statement lists for method bodies or static initializers are always considered reachable 5

Reachability Rules Some statements will never terminate normally Also, some special cases Some statements will always terminate normally How should we handle null statements? Example: void example() { int v; v++; return; ; v = 10; v = 20;} 6

Reachability Control Structures if/else Assume all parts are reachable Unless...? Terminates normally if...? Loops Assume it terminates normally Unless...? Body is reachable Unless...? 7

Reachability Control Structures break/continue Never terminates normally What happens to statements that follow? return Check the type does it match return type of method? Always terminates abnormally 8

Reachability Control Structures switch/case Case labels must be type checked Checked against what? Reachability of case labels? Should the switch block as a whole terminate normally? What determines this? Method body Can it terminate abnormally? Can it terminate normally? 9

Exercises Determine the reachability of the final assignment statement in each of the following code snippets: for (i=0; i<10; i++) a += i; a = 0; for (;;) a++; a = 0; 10

Exercises Determine the reachability of the final assignment statement in each of the following code snippets: for (i = 0; i == new Random(i).nextInt();) a += i; a = 0; for (i=0; i<10; i++) { a += i; if (i > 0) return i; } a = 0; 11

Exercises Determine the reachability of the final assignment statement in each of the following code snippets: for (i = 0; i == new Random(i).nextInt();) a += i; a = 0; for (i=0; i<10; i++) { a += i; if (i > 0) return i; } a = 0; 12

Exercises Determine the values of isreachable and terminatesnormally for the following statements: a = 0; for (;;) { i = new Random(a).nextInt(); a += i; if (i == 10) break; else continue; i++; } // Include the For List flags here if (i == 10) return i; return a+i; 13

Exceptions Exceptions allow for abnormal termination of a block How does this differ from return? Exceptions have a type Can be checked or unchecked Difference? 14

Semantics - Exceptions Try Check body normally, no special treatment Catch/finally Type checking? Multiple catches? Exception scope Catch lists 15

Reachability - Exceptions Throw Always terminates abnormally Try / Finally Reachability? Termination? Catch Reachability? Checked vs. Unchecked? Termination? 16

Exception Example class ExitComputation extends Exception{}; try {... if (cond) throw new ExitComputation(); if (v < 0.0) throw new ArithmeticException(); else a = Math.sqrt(v);... } catch (e ExitComputation) {return 0;} How will this be processed? 17

Semantics Method calls Pieces of a method call Identifier Qualifiers (optional) Parameter list Disambiguation Gather all possible matches Choose the nearest possible match What can we use to make this decision? 18

Call Disambiguation Identify the class Qualifier: Type vs. Instance? Collect matching method names Current class Super classes Filter based on parameter types Length of list Bindable Do parameters have to have the exact same type? 19

Call Selection Examine the list that was generated What if it is empty? What if there s only one method? What if there are multiple methods? Which to match first? 20

Calls - Example class A { void M(A parm) {...} void M() {...} } class B extends A { void M(B parm) {...} void test(b arg) {M(arg);}} How should M(arg) be resolved? 21