Assignment IV for COP 4020: Programming Languages (Fall 2008) - Prof. Jarred Ligatti, Assignments of Programming Languages

Information about assignment iv for the programming languages course (cop 4020) at the university of south florida, which was offered in the fall 2008 semester. The assignment focuses on proving the soundness of programming languages by proving progress and preservation theorems for a new language, implementing a type checker and interpreter for a simple language with references, and gaining experience with recursively defined data types and exceptions in ml. Students are required to complete the programming portion of the assignment on specific lab computers and submit their files through blackboard.

Typology: Assignments

Pre 2010

Uploaded on 09/17/2009

koofers-user-qmw
koofers-user-qmw 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Programming Languages (COP 4020) [Fall 2008]
Assignment IV
Objectives
1. To practice proving the soundness of programming languages by proving Progress
and Preservation Theorems for a new language.
2. To demonstrate an understanding of the semantics of references in strongly typed
languages by implementing a type checker and interpreter for a simple language
with references.
3. To gain experience with recursively defined data types and exceptions in ML.
Due Date for Language-theory Portion: Wednesday, December 3, 2008, at 6:05pm.
Due Date for Programming Portion: Friday, December 5, 2008, at 11:59pm.
Machine Details
Complete the programming portion of this assignment on the following CSEE network
computers: c4labpc11, c4labpc12, ..., c4labpc29. These machines are physically located
in the Center 4 lab (ENB 220). Do not use any server machines like grad, babbage,
sunblast, etc. You can connect to the C4 machines from home using SSH. (Example:
Host name: c4labpc11.csee.usf.edu Login ID and Password: <your login id and
password>) You are responsible for ensuring that your programs compile and execute
properly on these machines.
Assignment Description
1. [5 points]
Recall language L from Assignment III:
expressions e ::= x | n | e1+e2 | let val x = e1 in e2 end | if e1 then e2 else e3 | T | F | B
(a) Provide rules for L’s static and dynamic semantics.
(b) State a Canonical Forms Lemma for L. You do not need to prove the lemma.
(c) State and prove Progress and Preservation Theorems for L.
For this problem, you may assume without proof that all the standard programming-
language lemmas besides Progress and Preservation (e.g., the Inversion and Substitution
Lemmas) hold for L. You may also assume that all auxiliary programming-language
definitions (e.g., of values and capture-avoiding substitution) already exist. As usual, you
may assume that all expressions are implicitly alpha-converted, so you never have to
consider contexts (Γ) containing more than one entry for the same variable. Finally, in
part (c), and in all proofs for this class, you need not prove cases where the logic would
be identical to an existing proof case. For example, if your proof has cases T-T, T-F, and
T-B, but all three cases have identical proof logic, then you could simply prove case T-T
and then write something like, “Cases T-F and T-B are analogous to case T-T.”
Extra Credit
For an extra 25% credit on this assignment, prove that the Substitution Lemma holds for
language L.
1
pf3

Partial preview of the text

Download Assignment IV for COP 4020: Programming Languages (Fall 2008) - Prof. Jarred Ligatti and more Assignments Programming Languages in PDF only on Docsity!

Programming Languages (COP 4020) [Fall 2008]

Assignment IV

Objectives

  1. To practice proving the soundness of programming languages by proving Progress and Preservation Theorems for a new language.
  2. To demonstrate an understanding of the semantics of references in strongly typed languages by implementing a type checker and interpreter for a simple language with references.
  3. To gain experience with recursively defined data types and exceptions in ML. Due Date for Language-theory Portion: Wednesday, December 3, 2008, at 6:05pm. Due Date for Programming Portion: Friday, December 5, 2008, at 11:59pm. Machine Details Complete the programming portion of this assignment on the following CSEE network computers: c4labpc11, c4labpc12, ..., c4labpc29. These machines are physically located in the Center 4 lab (ENB 220). Do not use any server machines like grad, babbage, sunblast, etc. You can connect to the C4 machines from home using SSH. (Example: Host name: c4labpc11.csee.usf.edu Login ID and Password: ) You are responsible for ensuring that your programs compile and execute properly on these machines. Assignment Description
  4. [5 points] Recall language L from Assignment III: expressions e ::= x | n | e 1 +e 2 | let val x = e 1 in e 2 end | if e 1 then e 2 else e 3 | T | F | B (a) Provide rules for L’s static and dynamic semantics. (b) State a Canonical Forms Lemma for L. You do not need to prove the lemma. (c) State and prove Progress and Preservation Theorems for L. For this problem, you may assume without proof that all the standard programming- language lemmas besides Progress and Preservation (e.g., the Inversion and Substitution Lemmas) hold for L. You may also assume that all auxiliary programming-language definitions (e.g., of values and capture-avoiding substitution) already exist. As usual, you may assume that all expressions are implicitly alpha-converted, so you never have to consider contexts (Γ) containing more than one entry for the same variable. Finally, in part (c), and in all proofs for this class, you need not prove cases where the logic would be identical to an existing proof case. For example, if your proof has cases T-T, T-F, and T-B, but all three cases have identical proof logic, then you could simply prove case T-T and then write something like, “Cases T-F and T-B are analogous to case T-T.” Extra Credit For an extra 25% credit on this assignment, prove that the Substitution Lemma holds for language L.
  1. [1 point] Correct any mistakes in the tc.sml file you submitted for Assignment III. Then copy the contents of your tc.sml file to a new file called tc-refs.sml and extend your type-checker code in tc-refs.sml to handle MinML reference expressions. Function tc in tc-refs.sml will only be used to type check MinML expressions statically , so your type checker never needs to provide types for location expressions (which may only appear dynamically). If an expression input to your type checker contains a location value, function tc should raise an exception called tcLocationVal. Hence, tc-refs.sml needs to define two top- level values: exception tcLocationVal and function tc. You can find data-type definitions for MinML with references in file types-refs.sml at: http://www.cse.usf.edu/~ligatti/pl-08/as4/types-refs.sml. As on Assignment III, you may assume that all variable names in expressions being type checked are unique.
  2. [4 points] In a new file named eval-refs.sml , implement a function eval : expr -> expr. Function eval takes a MinML expression e (which may use references) and evaluates e for as many steps as possible. If evaluation of e converges to a value v , then eval (e) returns v ; if e diverges then so does eval (e). Thus, function eval is an interpreter of MinML expressions (i.e., eval performs step-by-step evaluation of MinML expressions). You will want to create several helper functions to implement eval. I recommend making one of these the following. step:(intexpr) list -> int -> expr -> ((intexpr) listintexpr) This curried step function takes (1) the current memory (stored as a list of location- value bindings), (2) the next location (memory address) available for use, and (3) an expression e’ currently being evaluated. Then step returns a triple containing (1) the possibly updated memory that results from taking one evaluation step, (2) the next location (memory address) available for use after taking this step, and (3) the expression e’’ that results from taking a step from e’. However, if no e’’ exists—perhaps because e’ is ill typed or is already a value—then step should raise a cannotStep exception. In fact, eval must raise cannotStep at any point that execution gets “stuck” without a value being produced (but note that because MinML with references is type safe, only ill- typed expressions get “stuck” before becoming values). File eval-refs.sml must therefore define only two top-level values: exception cannotStep and function eval. To help you test your interpreter, we provide two files called fact.sml and fact-refs.sml at: http://www.cse.usf.edu/~ligatti/pl-08/as4/. These files build, type check, and evaluate MinML expressions that compute six factorial ( 6! ). The sample executions on the following page illustrate how to use these files. Please note, though, that we will grade your submissions using MinML expressions that are not in fact.sml or fact-refs.sml. In Problems 2 and 3, you may assume that all variable names in expressions being type checked and interpreted are unique (so you never have to alpha-convert expressions).