mp9 - MP 9 An Evaluator for PicoML CS 421 Fall 2007...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: MP 9 An Evaluator for PicoML CS 421 Fall 2007 Revision 1 . Assigned November 13, 2007 Due November 27, 2007 23:59 Extension 48 hours (20% penalty) 1 Change Log 1.0 Initial Release. 2 Overview Previously, you created a lexer, a parser, and a type inferencer for PicoML. Finally, your hard work will pay off it is time to create an evaluator for PicoML programs. Lexing, parsing, and type inferencing will be taken care of automatically (you have already implemented these parts in previous MPs). Your evaluator can assume that its input is correctly typed. Your evaluator will be responsible for evaluating two kinds of things: declarations, and expressions. At top level, your evaluator will be called on a declaration or an expression with an empty memory. It will recurse on the parts, eventually returning the binding. 3 Types For this assignment, one should note the difference between expressions and values. An expression is a syntax tree, like 2 + (4 * 3) or (3 < 4) , whereas a value is a single object, like 14 or true . A value is the result of evaluating an expression; or it can be a closure. Recall that we represent PicoML programs with following OCaml types: ( * declarations * ) type declaration = Let of string option * exp | LetRec of string * exp ( * expressions for PicoML * ) type const = BoolConst of bool | IntConst of int | FloatConst of float | StringConst of string | NilConst | UnitConst | Hd | Tl | Fst | Snd type bin_op = IntPlusOp | IntMinusOp | IntTimesOp | IntDivOp | FloatPlusOp | FloatMinusOp | FloatTimesOp | FloatDivOp | ExpoOp | ConcatOp | Cons | Comma | EqOp | OrOp | AndOp | LtOp 1 | GtOp | LeqOp | GeqOp type exp = | VarExp of string | ConstExp of const | BinOpExp of bin_op | IfExp of exp * exp * exp | AppExp of exp * exp | FunExp of string * exp | LetInExp of string * exp * exp | LetRecInExp of string * exp * exp | RaiseExp of exp | TryWithExp of exp * (int option * exp) * ((int option * exp) list) With these, we form a PicoML abstract syntax tree. A PicoML AST will be the input to your evaluator. Now look at the following types defined in Mp9common : type memory = (string * value) list and value = Unitval | Intval of int | Boolval of bool | Stringval of string | Realval of float | UnOpval of un_op | Pairval of value * value | Listval of value list | Closure of string * exp * memory | Recvar of exp * memory | Exn of int ( * Only neeed in Part 2 * ) The type value is output from your evaluator when evaluating expressions. The type memory serves as both input to evaluator in general, and output from your evaluator when evaluating declarations. For example, one evaluates a declaration starting from some initial memory, and a binding and a final memory is returned....
View Full Document

Page1 / 13

mp9 - MP 9 An Evaluator for PicoML CS 421 Fall 2007...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online