Docsity

Exercises on Programming Languages - Homework 1 | CS 615, Assignments of Programming Languages

Toggle sidebar
bg1
CS615 — Homework Assignment 1
Wes Weimer
Exercise 1: Bookkeeping. Send me email with your name and indicate
whether you are taking the class for a letter grade, taking it pass/fail, or just
sitting in. In addition, indicate one thing you like about the class and one
thing you would change about it. I will use the email address you provide to
send bulletins related to the course (e.g., notifications of updates or correc-
tions to future homeworks). You can simplify things by attaching a PDF of
your written answers to this assignment and your source code for question 5
(see below) in that same email.
Exercise 2: Language Design. Comment on some aspect from Hoare’s
Hints On Programming Language Design that relates to your programming
experience. Provide additional evidence in favor of one his points and against
one of his points. Do not exceed three paragraphs. Both your ideas and also
the clarity with which they are expressed (i.e., your English prose) matter. I
should be able to identify your main claim, the arguments you are bringing
to bear, and your conclusion.
Exercise 3: Set Theory. This exercise is meant to help you refresh your
knowledge of set theory and functions. Let Xand Ybe sets. Let P(X)
denote the powerset of X(the set of all subsets of X). There is a 1-1
correspondence (i.e., a bijection) between the sets Aand B, where A=
X→ P(Y) and B=P(X×Y). Note that Ais a set of functions and Bis
a (or can be viewed as a) set of relations. This correspondence will allow us
to use functional notation for certain sets in class. This is Exercise 1.4 from
page 8 of Winskel’s book. Do one of the following:
•Demonstrate the correspondence between Aand Bby presenting an
appropriate function and proving that it is a bijection. For example,
you might construct a function f:B→Aand prove that fis an
injection and a surjection.
•Write “I understand this background material” but do not do the prob-
lem. You will receive full credit for this question. We use the Honor
system.
1
pf3

Partial preview of the text

Download Exercises on Programming Languages - Homework 1 | CS 615 and more Assignments Programming Languages in PDF only on Docsity!

CS615 — Homework Assignment 1

Wes Weimer

Exercise 1: Bookkeeping. Send me email with your name and indicate whether you are taking the class for a letter grade, taking it pass/fail, or just sitting in. In addition, indicate one thing you like about the class and one thing you would change about it. I will use the email address you provide to send bulletins related to the course (e.g., notifications of updates or correc- tions to future homeworks). You can simplify things by attaching a PDF of your written answers to this assignment and your source code for question 5 (see below) in that same email.

Exercise 2: Language Design. Comment on some aspect from Hoare’s Hints On Programming Language Design that relates to your programming experience. Provide additional evidence in favor of one his points and against one of his points. Do not exceed three paragraphs. Both your ideas and also the clarity with which they are expressed (i.e., your English prose) matter. I should be able to identify your main claim, the arguments you are bringing to bear, and your conclusion.

Exercise 3: Set Theory. This exercise is meant to help you refresh your knowledge of set theory and functions. Let X and Y be sets. Let P(X) denote the powerset of X (the set of all subsets of X). There is a 1- correspondence (i.e., a bijection) between the sets A and B, where A = X → P(Y ) and B = P(X × Y ). Note that A is a set of functions and B is a (or can be viewed as a) set of relations. This correspondence will allow us to use functional notation for certain sets in class. This is Exercise 1.4 from page 8 of Winskel’s book. Do one of the following:

  • Demonstrate the correspondence between A and B by presenting an appropriate function and proving that it is a bijection. For example, you might construct a function f : B → A and prove that f is an injection and a surjection.
  • Write “I understand this background material” but do not do the prob- lem. You will receive full credit for this question. We use the Honor system.

Exercise 4: Simple Operational Semantics. Consider the IMP lan- guage discussed in class, with the Aexp sub-language extended with a di- vision operator. Explain what changes must be made to the operational semantics (big-step only). Write out formally any new rules of inference you introduce.

Exercise 5: Language Feature Design. Consider the IMP language with a new command construct “let x = e in c”. The informal semantics of this construct is that the Aexp e is evaluated and then a new local variable x is created with lexical scope c and initialized with the result of evaluating e. Then the command c is evaluated. We also extend IMP with a new command “print e” which evaluates the Aexp e and “displays the result” in some un-modeled manner but is otherwise similar to skip. We expect (the curly braces are syntactic sugar):

x := 1 ; y := 2 ; { let x = 3 in print x ; print y ; x := 4 ; y := 5 } ; print x ; print y

to display “3 2 1 5”.

  • Extend the natural-style operational semantics judgment < c, σ >⇓ σ′ with one new rule for dealing with the let command. Pay careful attention to the scope of the newly declared variable and to changes to other variables.
  • Extend the set of redexes, contexts and reduction rules for the contextual- style operational semantics that we discussed in class to account for the let command.
  • Download the Homework 1 code pack from the course web page. Mod- ify hw1.ml so that it implements a complete interpreter for IMP (in- cluding let and print). Base your interpreter on IMP’s large-step operational semantics. The Makefile includes a “make test” target that you should use (at least) to test your work.