Problem Set 1 Due: 11:59pm Wednesday, February 7

Similar documents
Problem Set 3 Due: 11:59 pm on Thursday, September 25

Problem Set 5 Due:??

Problem Set 6 Due: 11:59 Sunday, April 29

Problem Set 1 Due: 1:30pm Tuesday, February 13

Problem Set 6 Due: 6pm Friday, November 12

Problem Set 6 (Optional) Due: 5pm on Thursday, December 20

Homework 1. Notes. What To Turn In. Unix Accounts. Reading. Handout 3 CSCI 334: Spring, 2017

by the evening of Tuesday, Feb 6

CS1110 Lab 1 (Jan 27-28, 2015)

Problem Set 6 Due: Tuesday, November 27

Temple University Computer Science Programming Under the Linux Operating System January 2017

Programming Project 4: COOL Code Generation

Problem Set 5 Due: Friday, November 2

CS251 Programming Languages Handout # 47 Prof. Lyn Turbak May 22, 2005 Wellesley College. Scheme

List Processing in Ocaml

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Using the Zoo Workstations

last time in cs recitations. computer commands. today s topics.

Homework 1. Reading. Problems. Handout 3 CSCI 334: Spring, 2012

Computer Science 385 Design and Analysis of Algorithms Siena College Spring Lab 8: Search Trees Due: Start of your next lab session

Programming Assignment IV Due Thursday, November 18th, 2010 at 11:59 PM

Homework 5. Notes. Turn-In Instructions. Reading. Problems. Handout 19 CSCI 334: Spring (Required) Read Mitchell, Chapters 6 and 7.

CS251 Programming Languages Handout # 3 Wellesley College 30 January Linux, X, and Emacs

Problem Set 2 Due: 11:59pm, Monday October 4

CS 1653: Applied Cryptography and Network Security Fall Term Project, Phase 2

Prof. Dr. A. Podelski, Sommersemester 2017 Dr. B. Westphal. Softwaretechnik/Software Engineering

ENCE 3241 Data Lab. 60 points Due February 19, 2010, by 11:59 PM

C++ For Science and Engineering Lecture 2

CS 2110 Fall Instructions. 1 Installing the code. Homework 4 Paint Program. 0.1 Grading, Partners, Academic Integrity, Help

CSE Theory of Computing Fall 2017 Project 4-Combinator Project

CS159 - Assignment 2b

Problem Set 2 Solutions

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

:

CS Fundamentals of Programming II Fall Very Basic UNIX

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

Assignment 0. Computer Science 52. Due Friday, September 7, 2018, at 5:00 pm

15-110: Principles of Computing, Spring 2018

CPSC 150 Laboratory Manual. Lab 1 Introduction to Program Creation

COP4530 Data Structures, Algorithms and Generic Programming Recitation 3 Date: January 20 & 22, 2009

CS 241 Data Organization. August 21, 2018

Lab 7 1 Due Thu., 6 Apr. 2017

CS 61: Systems programming and machine organization. Prof. Stephen Chong November 15, 2010

The print queue was too long. The print queue is always too long shortly before assignments are due. Print your documentation

C152 Laboratory Exercise 1

Getting started with Hugs on Linux

NOTE: All references to Python on this exam mean Python 3, so you should answer accordingly.

Check the entries in the home directory again with an ls command and then change to the java directory:

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

CS301 Compiler Design and Implementation Handout # 18 Prof. Lyn Turbak February 19, 2003 Wellesley College

CS 356, Fall 2018 Data Lab (Part 1): Manipulating Bits Due: Wednesday, Sep. 5, 11:59PM

Repetitive Program Execution

Computer Science 62 Lab 8

// class variable that gives the path where my text files are public static final String path = "C:\\java\\sampledir\\PS10"

CMSC 201 Spring 2017 Lab 01 Hello World

Writeup for first project of CMSC 420: Data Structures Section 0102, Summer Theme: Threaded AVL Trees

Eat (we provide) link. Eater. Goal: Eater(Self) == Self()

CSC111 Computer Science II

Pace University. Fundamental Concepts of CS121 1

Lecture 5: Methods CS2301

CpSc 1111 Lab 9 2-D Arrays

This assignment has four parts. You should write your solution to each part in a separate file:

CS Programming Languages Fall Homework #2

Project 4: ATM Design and Implementation

Lab 1 1 Due Wed., 2 Sept. 2015

Project #1 Exceptions and Simple System Calls

HMC CS 158, Fall 2017 Problem Set 3 Programming: Regularized Polynomial Regression

CS 553 Compiler Construction Fall 2009 Project #1 Adding doubles to MiniJava Due September 8, 2009

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall 2002 Problem Set 3 Due: Day 11. Problem 1. Finding the Median (15%)

Systems Programming Advanced Software Development

COSE212: Programming Languages. Lecture 0 Course Overview

15-110: Principles of Computing, Spring 2018

CSC D84 Assignment 2 Game Trees and Mini-Max

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points

CS 4218 Software Testing and Debugging Ack: Tan Shin Hwei for project description formulation

It is academic misconduct to share your work with others in any form including posting it on publicly accessible web sites, such as GitHub.

Welcome to Solving Problems with Computers I

CS2110 Assignment 3 Inheritance and Trees, Summer 2008

CMPSC 111 Introduction to Computer Science I Fall 2016 Lab 2 Assigned: September 7, 2016 Due: Wednesday, September 14, 2016 by 2:30 pm

Lab 1 Introduction to UNIX and C

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

CS212 - COMPUTATIONAL STRUCTURES AND ALGORITHMS

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

CS4023 Week04 Lab Exercise

School of Informatics, University of Edinburgh

CSc 372, Fall 2006; Quiz 1 Time: 3:00; Value: 2 points. 1. What is a fundamental difference between the if-then-else constructs in Java (or C) and ML?

Programming Assignment 1

Q1: Multiple choice / 20 Q2: C input/output; operators / 40 Q3: Conditional statements / 40 TOTAL SCORE / 100 EXTRA CREDIT / 10

CSC209. Software Tools and Systems Programming.

CS 356, Fall 2018 Data Lab (Part 2): Manipulating Bits Due: Mon, Sep. 17, 11:59PM

Compilers for Modern Architectures Course Syllabus, Spring 2015

CS 2505 Fall 2018 Data Lab: Data and Bitwise Operations Assigned: November 1 Due: Friday November 30, 23:59 Ends: Friday November 30, 23:59

Laboratory Assignment #3 Eclipse CDT

Tips from the experts: How to waste a lot of time on this assignment

CSE 143: Computer Programming II Spring 2015 HW7: 20 Questions (due Thursday, May 28, :30pm)

General Instructions. You can use QtSpim simulator to work on these assignments.

Important Project Dates

Project 4: ATM Design and Implementation

Programming Languages ML Programming Project Due 9/28/2001, 5:00 p.m.

Transcription:

CS251 Programming Languages Handout # 13 Prof. Lyn Turbak January 31, 2007 Wellesley College Reading: Problem Set 1 Due: 11:59pm Wednesday, February 7 Handouts #1 #12 (only Chapters 1 5 of Handout #9 = Introduction to the Objective Caml Programming Language) Overview: In this assignment, you will (1) think about programming language implementation and (2) do some simple experimentation with Ocaml. All problems on this problem set are group problems. You are encouraged to solve them in two-person teams. Submission: Each team should turn in a single hardcopy submission packet for all problems by slipping it under Lyn s office door by 11:59pm on the due date. The packet should include: 1. a team header sheet (see the end of this assignment for the header sheet) indicating the time that you (and your partner, if you are working with one) spent on the parts of the assignment. 2. your written solutions to Problems 1, 2, and 3. 3. your final version of ps1.ml for Problem 4. Each team should also submit a single softcopy (consisting of your final ps1 directory) to the drop directory ~cs251/drop/ps1/username, where username is the username of one of the team members (indicate which drop folder you used on your hardcopy header sheet). To do this, execute the following commands in Linux in the account of the team member being used to store the code. cd /students/username/cs251 cp -R ps1 ~cs251/drop/ps1/username/ Group Problem 0: Getting Started Problems 1 and 2 are pencil-and-paper problems that you can do without a computer. But you will need a computer to check your answers to Problem 3 and to program your answers to Problem 4. You should complete the following steps before using the computer in Problems 3 and 4. a. : Linux You should begin this assignment by learning (or reminding yourself) how to use Linux. See the information in Handouts #3 and #4 on using Linux/Unix. b. : Emacs Next you should learn (or remind yourself) how to use Emacs. See the information in Handouts #3, #5, and #6 on using Emacs. Learning to execute all cursor-motion and editing commands via keystrokes (rather than via mouse and menus) is an important skill that will save you lots of time over the semester. It will also make it easier for you to work remotely via ssh. A good way to begin learning the keystroke commands is taking the online interactive Emacs tutorial (see Handout #3 for how to do this). 1

c. : CVS In order to download code for your CS251 assignments, you will need to update your local copies of files that are in the CVS-controlled CS251 repository. Follow the directions in Handout #7 for how to install your local CVS filesystem. You only need to install it once. Once you have installed your local CVS filesystem, you can access all CVS-controlled files by executing the following in a Linux shell: cd ~/cs251 cvs update -d Indeed, every time you log in to a Linux machine to work on a CS251 assignment, you should execute the above commands to ensure that you have the most up-to-date versions of the problem set materials. On this assignment, executing the above commands will create the local directory ~/cs251/ps1 containing the file ps1.ml. This file contains simple stubs for the functions f and g you will define in Problem 4. d. : Ocaml Interpreter For problems 3 and 4, you will need to launch the Ocaml interpreter. There are several ways to do this; see Handout #10. It is recommended that you choose one of the ways that works within Emacs, since this simplifies many interactions. Group Problem 1 [25]: Interpreters and Compilers As seen in Lecture #1, there are two basic reasoning rules involving interpreters and translators (a.k.a. compilers): 1. The Interpreter Rule (I) 2. The Translator Rule (T) P-in-L program; L intepreter machine (I) P machine P-in-S program; S-to-T translator machine (T ) P-in-T program In practice, we will often elide the word machine for intepreter machines and translator machines. E.g., we will refer to an L interpreter machine as an L interpreter, and an S-to-T translator machine as an S-to-T translator. We will also often elide the word program ; e.g., we will refer to a P-in-L program as P-in-L. a. [10] Suppose you are given the following: a Java-to-C-in-Scheme compiler (that is, a Java-to-C compiler written in Scheme); a Scheme-in-Pentium interpreter; a C-to-Pentium-in-Pentium compiler; a Pentium-based computer. Using the two reasoning rules above, construct a proof that demonstrates how to execute a given Java program on the computer. 2

b. [15] Suppose you are given the following: a Ocaml-in-MIPS interpreter; a Ocaml-to-MIPS-in-Ocaml compiler; a MIPS-based computer. i Show how to generate a Ocaml-to-MIPS-in-MIPS compiler. (Use the reasoning rules to construct a proof.) ii After you successfully complete part i, you accidentally delete the Ocaml-in-MIPS interpreter. Show how you can still execute any Ocaml program on your MIPS-based computer. (Use the reasoning rules to construct a proof.) Group Problem 2 [25]: Trusting Trust In his paper Reflections on Trusting Trust (Handout #12), Ken Thompson describes how a compiler can harbor a so-called Trojan horse that can make compiled programs insecure. Read this paper carefully and do the following tasks to demonstrate your understanding of the paper: a. [10] Section II of the paper describes how a C compiler can be taught to recognize \v as the vertical tab character. Using the same kinds of components and processes used in Problem 1, summarize the content of Section II by carefully listing the components involved and describing (by constructing a proof) how a C compiler that understands the code in Figure 2.2 can be generated. (Note that the labels for Figures 2.1 and 2.2 are accidentally swapped in the paper.) b. [15] Section III of the paper describes how to generate a compiler binary harboring a Trojan horse. Using the same kinds of components and processes used in Problem 1, summarize the content of Section III by carefully listing the components involved and describing (by constructing a proof) how the Trojaned compiler can be generated. Group Problem 3 [20]: Ocaml Evaluation Fig. 1 shows a sequence of Ocaml declarations and expressions. Show the type and value of each declaration and expression, assuming that they are evaluated sequentially. You should predict the answers without using the Ocaml interpreter, but may use it to check your answers. Group Problem 4 [30]: Ocaml Functions Consider the following Java class method: public static int f (int n) { if (n <= 2) { return n; } else { return n + f(n/2) + f(n/3); } } Fig. 2 shows an invocation tree for the invocation f(30). In the tree, each node labeled f(n):r denotes an invocation of the method f on the argument n that yields the result r. a. [10]: Translating f to Ocaml In the file ps1.ml (see Problem 0(c) for how to create this), flesh out an Ocaml declaration for the function f. Within the Ocaml interpreter, execute the following to load ps1.ml the first time: 3

let a = 5;; let b = a * a;; 2*a + (b-a);; let avg = fun x y -> (x+y)/2;; let avg a b = (a+b)/2;; avg (2*a) (b-a);; let app_3_5 = fun f -> f 3 5;; app_3_5 (+);; app_3_5 (-);; app_3_5 ( * );; app_3_5 avg;; app_3_5 (fun x y -> x);; app_3_5 (if 1>2 then (+) else ( * ));; app_3_5 (fun x y -> if x < y then (+) else (-));; let add_a x = x + a;; add_a 100;; let a = 17;; b;; add_a 100;; let try_a a = add_a (2*a);; try_a 100;; Figure 1: A sequence of Ocaml declarations and expressions. f(30):90 f(15):37 f(10):23 f(7):14 f(5):8 f(5):8 f(3):5 f(3):5 f(2):2 f(2):2 f(2):2 Figure 2: Invocation tree for f(30). 4

# #cd "/students/username/cs251/ps1";; # #use "ps1.ml";; Note that the first hash mark (#) in each line is the prompt of the Ocaml interpreter, while the second hash mark in each line is part of the command name. For some reason, Ocaml does not understand the abbreviation ~ for /students/username, so you must write out the long form. When ps1.ml loads properly, you should see the following: val f : int -> int = <fun> val g : int -> int * int = <fun> You are now ready to test you definition of f. The following is a transcript of some tests for a working f: # f 1;; - : int = 1 # f 2;; - : int = 2 # f 3;; - : int = 5 # f 5;; - : int = 8 # f 7;; - : int = 14 # f 10;; - : int = 23 # f 15;; - : int = 37 # f 30;; - : int = 90 If your definition of f contains an error, you will need to edit ps1.ml. After making any changes to ps1.ml, you need to re-execute # #use "ps1.ml";; to inform the Ocaml interpreter of your changes. b. [20]: Counting nodes In this part your goal is to define an Ocaml function g that takes an integer argument n and returns a pair of numbers (r,c), where r is the result of f(n) and c is the count of the number of f nodes in the invocation tree for f(n). For example, f(30) yields 90 and the number of nodes in the invocation tree for f(30) is 17, so g(30) should return the pair (90,17). To achieve full credit for this part, you must define g as a single recursive function that does not call the function f and does not use any local functions. However, partial credit will be awarded for definitions of g that invoke f. The following is a transcript of some tests for a working g: # g 1;; - : int * int = (1, 1) # g 2;; - : int * int = (2, 1) # g 3;; - : int * int = (5, 3) # g 5;; 5

- : int * int = (8, 3) # g 7;; - : int * int = (14, 5) # g 10;; - : int * int = (23, 7) # g 15;; - : int * int = (37, 9) # g 30;; - : int * int = (90, 17) Extra Credit 1 [25]: Self-printing Program In his article Reflections on Trusting Trust, Ken Thompson notes that it is an interesting puzzle to write a program in a language whose effect is to print out a copy of the program. We will call this a self-printing program. Write a self-printing program in any general-purpose programming language you choose. Your program should be self-contained it should not read anything from the file system. 6

Problem Set Header Page Please make this the first page of your hardcopy submission. CS251 Problem Set 1 Due 11:59pm Wednesday, February 7 Names of Team Members: Date & Time Submitted: Collaborators (anyone you or your team collaborated with on the problem set): In the Time column, please estimate the time you or your team spent on the parts of this problem set. Team members should be working closely together, so it will be assumed that the time reported is the time for each team member. Please try to be as accurate as possible; this information will help me design future problem sets. I will fill out the Score column when grading your problem set. Part Time Score General Reading Problem 1 [25] Problem 2 [25] Problem 3 [20] Problem 4 [30] Total 7