/* Use the expression datatype defined in expressions.ml: */
%cfw_
open Mp9common
let andsugar l r = IfExp(l,r,ConstExp (BoolConst false)
let orsugar l r = IfExp(l,ConstExp (BoolConst true),r)
let ltsugar l r = BinOpAppExp(GreaterOp,r,l)
let leqsugar
HW 1 Evaluation and Environments
CS 421 Fall 2007
Revision 1.0 Assigned September 4, 2007 Due September 11, 2007, 2:00 pM, in class Extension 48 hours (20% penalty)
1
Change Log
1.0 Initial Release.
2
Turn-In Procedure
Your answers to the fol
(* CS421 - Fall 2014
* MP1
*
* Please keep in mind that there may be more than one
* way to solve a problem. You will want to change how a number of these start.
*)
open Mp1common
(* Problem 1 *)
let random = 17;
(* Problem 2 *)
let pi = 3.14159;
(*
open Hw9common
open Type_lex
(* The original grammar was
<ty> := <var> | int | ( <ty> ) | <ty> * <ty> | <ty> list
<var> := 'a | 'b
*)
(* The grammar I gave in 1b was
<ty>: = <not_star_top> | <not_star_top> '*' <not_list>
<not_list> := <atom> | <atom> '*'
(* File: hw5-sol.ml *)
type suit = Club | Diamond | Heart | Spade ;
type rank = Two | Three | Four | Five | Six | Seven | Eight | Nine | Ten | Jack | Queen | King | Ace;
type card = Card of suit * rank;
type color = Red | Black;
let color_of_card x =
ma
MP 11 A Transition Semantics Evaluator for
CPS
CS 421 Fall 2014
Revision 1.0
Assigned November 21, 2014
Due December 5, 2014 23:59
Extension No extension
1
Change Log
1.0 Initial Release.
2
Overview
In MP10, you saw how to write an interpreter for PicoML
MP 10 An Evaluator for PicoML
CS 421 Fall 2014
Revision 1.1
Assigned November 14, 2014
Due November 21, 2014 23:59
Extension 48 hours (20% penalty)
1
Change Log
1.1 Added a problem for LetRecInExp as an extra credit problem for all. Corrected the use of +
MP 9 A Parser for PicoML
CS 421 Fall 2014
Revision 1.2
Assigned Tuesday October 28, 2014
Due Thursday November 13, 2014 23:59 PM
Extension 48 hours (20% penalty)
1
Change Log
1.2 Added the precedence of <monop> application
1.1 Added <> to <binop> and the
MP 7 Unication Algorithm
CS 421 Fall 2014
Revision 1.0
Assigned October 14, 2014
Due October 21, 2014, at 23:59
Extension 48 hours (20% penalty)
1
Change Log
1.0 Initial Release.
2
Objectives
Your objective for this assignment is to understand the details
MP 8 A Lexer for PicoML
CS 421 Fall 2014
Revision 1.0
Assigned October 21, 2014
Due October 28, 2014, at 11:59pm
Extension 48 hours (20% penalty)
1
Change Log
1.0 Initial Release.
2
Overview
To complete this MP, make sure you are familiar with the lecture
(* Problem 1 *)
let verbose_inc = (print_string "declaring f\n";
fun y -> print_string "evaluating:\n"; y+1 );
(* Problem 2 *)
let f1 g = (print_string "a"; let x = g() in (print_string "b"; 2+x);
(* Problem 3 *)
(*a*)
let f2 g = (let x = g() in (print
MP 5 Working with ADTs
CS 421 Fall 2014
Revision 1.0
Assigned Sep 23, 2014
Due Sep 30, 2014 23:59
Extension 48 hours (20% penalty)
1
Change Log
1.0 Initial Release.
2
Caution
This assignment can appear quite complicated at rst. It is essential that you un
MP 6 A Unication-Based Type Inferencer
CS 421 Fall 2014
Revision 1.2
Assigned Sep 30, 2014
Due Oct 14, 2014 23:59
Extension 48 hours (20% penalty)
1
Change Log
1.2 Corrected teh sample output for Problem 8 (LetRecInExp).
1.1 Corrected the description of P
MP 4 Higher-order Functions and
Continuation-Passing Style
CS 421 Fall 2014
Revision 1.1
Assigned September 16, 2014
Due September 23, 2014 23:59
Extension 48 hours (20% penalty)
1
Change Log
1.0 Initial Release.
1.1 Removed the subsection Using Continuat
MP 1 Basic OCaml
CS 421 Fall 2014
Revision 1.0
Assigned August 26, 2014
Due September 2, 2014, 23:59 PM
Extension 48 hours (penalty 20% of total points possible)
1
Change Log
1.0 Initial Release.
2
Objectives and Background
The purpose of this MP is to te
(* CS421 - Fall 2014
* MP1
*
* Please keep in mind that there may be more than one
* way to solve a problem. You will want to change how a number of these start.
*)
open Mp1common
(* Problem 1 *)
let random = 0 (* You want to change this *)
(* Proble
(* This is fragile and assumes Solution is run second, and that each
Solution function uses print_string at most once, and that the
students don't use print_string when the problem doesn't call for
it. *)
let output = ref ";
let last_string_length = ref (
(* File: mp3-sol.ml *)
open List
(* Problem 1 *)
let rec get_nth l n =
match l with
[] -> []
| x : xs -> if n = 0 then [x]
else if n < 0 then [] else (get_nth xs (n-1);
(* Problem 2 *)
let rec count_change money coins =
if money = 0 then 1
else
HW 8 Regular Expression
CS 421 Fall 2013
Revision 1.0
Assigned October 22, 2012
Due October 29, 2012, 19:59
Extension 48 hours (20% penalty)
1
Change Log
1.0 Initial Release.
2
Turn-In Procedure
Answer the problem below, save your work as a PDF (either sc
HW 5 Algebraic Datatypes
CS 421 Fall 2013
Revision 1.0
Assigned September 24, 2013
Due October 1, 2013, 19:59 pm
Extension 48 hours (20% penalty)
1
Change Log
1.0 Initial Release.
2
Turn-In Procedure
Solve the problem below in Ocaml. You must turn in an O
HW 3 Order of Evaluation
CS 421 Fall 2013
Revision 1.0
Assigned Wednesday, September 11, 2013
Due Tuesday, September 17, 2013, 19:59pm
Extension 48 hours (20% penalty)
1
Change Log
1.0 Initial Release.
2
Objectives and Background
The purpose of this HW is
HW 1 Evaluation and Environments
CS 421 Fall 2013
Revision 1.1
Assigned August 27, 2013
Due September 3, 2013, 11:59 pm
Extension 48 hours (20% penalty)
1
Change Log
1.1 Corrected the handin due to to Tuesday September 3, 2013.
1.0 Initial Release.
2
Turn
open Mp10common;
let const_to_val c =
match c with
BoolConst b -> BoolVal b
| IntConst i -> IntVal i
| FloatConst f -> FloatVal f
| StringConst s -> StringVal s
| NilConst -> ListVal []
| UnitConst -> UnitVal
let monOpApply op v =
match op, v wit
(* File: mp11-sol.ml *)
open Mp11common;
let rec match_lookup l n =
match l with [] -> None
| (Some m, v):more -> if n = m then Some v else match_lookup more n
| (None, v):_ -> Some v
let rec app_exn_handler_cont env ce n =
match ce with EmptyExnContC