Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006



Similar documents
Semester Review. CSC 301, Fall 2015

CSCI 3136 Principles of Programming Languages

Designing with Exceptions. CSE219, Computer Science III Stony Brook University

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Lecture 9. Semantic Analysis Scoping and Symbol Table

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

I. INTRODUCTION. International Journal of Computer Science Trends and Technology (IJCST) Volume 3 Issue 2, Mar-Apr 2015

J a v a Quiz (Unit 3, Test 0 Practice)

Programming Languages CIS 443

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

Introduction to Programming

Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Semantic Analysis: Types and Type Checking

Chapter 5 Names, Bindings, Type Checking, and Scopes

ML for the Working Programmer

Moving from CS 61A Scheme to CS 61B Java

Symbol Tables. Introduction

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Using Files as Input/Output in Java 5.0 Applications

Lecture J - Exceptions

02 B The Java Virtual Machine

CSCE-608 Database Systems COURSE PROJECT #2

13 File Output and Input

Programming Languages

Integration of Application Business Logic and Business Rules with DSL and AOP

The Needle Programming Language

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.

Chapter 6: Programming Languages

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

CSC Software II: Principles of Programming Languages

CS 111 Classes I 1. Software Organization View to this point:

FPGA area allocation for parallel C applications

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Binary Search Trees (BST)

Full and Complete Binary Trees

Java Application Developer Certificate Program Competencies

What is ODBC? Database Connectivity ODBC, JDBC and SQLJ. ODBC Architecture. More on ODBC. JDBC vs ODBC. What is JDBC?

Programming and Software Development CTAG Alignments

CS 106 Introduction to Computer Science I

Software Testing. Definition: Testing is a process of executing a program with data, with the sole intention of finding errors in the program.

CS 2112 Spring Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

HW3: Programming with stacks

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

Stacks. Data Structures and Data Types. Collections

Software Metrics in Static Program Analysis

CS506 Web Design and Development Solved Online Quiz No. 01

Output: struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;

Java Basics: Data Types, Variables, and Loops

Lecture 1: Introduction

Crash Course in Java

CS510 Software Engineering

Introduction to Object-Oriented Programming

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Regression Verification: Status Report

CHAPTER 5 INTELLIGENT TECHNIQUES TO PREVENT SQL INJECTION ATTACKS

Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Object-Oriented Software Specification in Programming Language Design and Implementation

CS193j, Stanford Handout #10 OOP 3

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Habanero Extreme Scale Software Research Project

ECE 122. Engineering Problem Solving with Java

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Programming Language Pragmatics

Chapter 2 Introduction to Java programming

Departamento de Investigación. LaST: Language Study Tool. Nº 143 Edgard Lindner y Enrique Molinari Coordinación: Graciela Matich

A Scala Tutorial for Java programmers

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

Integration of Application Business Logic and Business Rules with DSL and AOP

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Chapter 7: Functional Programming Languages

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

Parsing Technology and its role in Legacy Modernization. A Metaware White Paper

Compiler Construction

Chapter 3. Input and output. 3.1 The System class

Fundamentals of Java Programming

International Journal of Scientific & Engineering Research, Volume 4, Issue 11, November ISSN

API for java.util.iterator. ! hasnext() Are there more items in the list? ! next() Return the next item in the list.

Computer Programming. Course Details An Introduction to Computational Tools. Prof. Mauro Gaspari:

Physical Data Organization

1.1 WHAT IS A PROGRAMMING LANGUAGE?

Application Centric Infrastructure Object-Oriented Data Model: Gain Advanced Network Control and Programmability

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Software Engineering Techniques

1 The Java Virtual Machine

Sample CSE8A midterm Multiple Choice (circle one)

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Transcription:

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006 Final Examination January 24 th, 2006 NAME: Please read all instructions carefully before start answering. The exam will be 120 minutes in length. The exam is open book; any written materials may be used. Answer all questions on the exam paper itself; the backs of the pages may be used if needed. The exam has 7 problems, with varying number of points for each problem, for a total of 100 points Problem 1 2 3 4 5 6 7 Total Max. Points 10 15 15 15 15 15 15 100 Points João Correia Lopes 1

1. Fundamentals [10 pontos] Consider the following BNF gramar: pop ::= [ bop, pop ] bop bop ::= boop ( pop ) boop ::= x y z FEUP/MEI/PP/2005-06 For each of the following strings, identify the syntactic categories to which it belongs, showing the sequence of derivations from production pop. a) z b) (x) c) [y] d) [(x),y] e) [(x),[y,x]] João Correia Lopes Página 2 de 8

2. Type Systems and Type Inference [15 points] Consider the following ML function: fun append(nil, l) = l append(x::l, m) = append(l, m) FEUP/MEI/PP/2005-06 a) Write one or two sentences to explain succinctly and informally why append has the type you give. b) Following the steps of the ML type-inference algorithm, write the parse graph for the first clause of function append. João Correia Lopes Página 3 de 8

FEUP/MEI/PP/2005-06 c) This function is intended to append one list onto another. However it has a bug. How might knowing the type of this function help the programmer to find the bug 3. Scope, Functions and Store Management [15 points] Consider the following statically scoped ML expression: val x= 5; fun f(y) = (x+y) -2; fun g(h) = let x = 7 in h(x) end; let val x = 10 in g(f) end; a) Fill in the missing information in the following illustration of the runtime stack after the call to h inside the body of g. Remember that function values are represented by closures and that a closure is a pair consisting of an environment (pointer to an activation record) and compiled code 1. Activation Records Closures Compiled Code (1) access link ( 0 ) x (2) access link ( 1 ) f (3) access link ( ) ( ), g code for f (4) access link ( ) ( ), x (5) g(f) access link ( ) h code for g x (6) h(x) access link ( ) y b) What is the value of this expression? Why? 1 You should use the same conventions as in Mitchell s book. João Correia Lopes Página 4 de 8

4. Control in Sequential Languages [15 points] FEUP/MEI/PP/2005-06 Binding name occurrences to declarations may occur at compilation time (lexical scope) or at runtime (dynamic scope). Consider the following ML program: let y = 11 in let f x = x + y in let y = 22 in f 3 end end a) Explain what is lexical scope. Identify the binding of y which is used in f with lexical scope and evaluate the result of the call f 3. b) Explain what is dynamic scope. Identify the binding of y which is used in f with dynamic scope and evaluate the result of the call f 3. 5. Object-Oriented Languages [15 points] Consider the following ML program: (* A tree is either a Leaf containing an integer value or an interior Node with two subtrees. *) datatype Tree = Leaf of int Node of Tree * Tree (* Return the sum of all the integers stored in Leaf nodes. *) fun sum (Leaf i) = i sum (Node (l, r)) = sum l + sum r João Correia Lopes Página 5 de 8

FEUP/MEI/PP/2005-06 a) Without using if-then-else write in C ++ the class hierarchy of Tree, Leaf and Node, such that the following code works (using C ++ syntax): Tree * left = new Leaf(1); Tree * right = new Node(new Leaf(2), new Leaf(3)); Tree * root = new Node(left, right); int h = root->sum(); where sum() is a virtual function. 6. Portability and Safety: Java [15 points] Consider the following Java program in which an exception may be raised in procedure proc A at the point indicated in the program. class X { static void proc_a() { try { System.out.println ("begin proc_a"); /* throw NullPointerException, RuntimeException, Exception, etc */ catch (NullPointerException e) { System.out.println("handler in proc_a"); finally { System.out.println ("end proc_a"); João Correia Lopes Página 6 de 8

static void proc_b() { try { System.out.println("begin proc_b"); proc_a(); catch (RuntimeException e) { System.out.println("handler in proc_b"); finally { System.out.println("end proc_b"); public static void main (String args[]) { try { System.out.println("begin main"); proc_b(); catch (Exception e) { System.out.println("handler in main"); finally { System.out.println("end main"); FEUP/MEI/PP/2005-06 Describe the execution of the entire program for each of the following scenarios by showing the output and saying how the program terminates. a) Suppose procedure proc A raises no exception. b) Procedure proc A raises the exception RuntimeException. c) Procedure proc A raises the exception NullPointerException. d) Procedure proc A raises the exception Exception. João Correia Lopes Página 7 de 8

FEUP/MEI/PP/2005-06 7. Logic Programming [15 points] Consider the following Prolog database: a(x) :- b(x),c(x). a(x) :- d. a(x) :- e(x). b(1). b(2). c(2). c(3). e(4). a) Draw the Prolog search tree and identify the answer of the interpreter when all solutions of the following query are evaluated. a(z). b) What is the result when the second rule is changed, by introducing a cut, to: a(x) :-!, d. c) What is the result when the second rule is changed, by introducing a cut, to: a(x) :- d,!. The End. João Correia Lopes Página 8 de 8