(* File: ddktoploop.ml Author: Scott Smith This file allows interactive testing of your interpreter using the DDK. Before this file can be #use-d you need to execute make byte from the src/ directory of the DDK-1.1 distribution. *) (* First load all the relevant compiled structs. These commands assume ocaml was launched from src/DSR/ directory. If not, do a # #cd "my/directory/src/DSR";; to get there. *) #load "dsrast.cmo";; #load "dsrparser.cmo";; #load "dsrlexer.cmo";; #load "dsrpp.cmo";; #load "dsrinterp.cmo";; (* Make some structs available at the top for easier use *) open Dsrast;; open Dsrinterp;; (* function parse parses DSR concrete syntax you enter as a string *) let parse s = let lexbuf = Lexing.from_string s in Dsrparser.main Dsrlexer.token lexbuf;; (* Function pp is a top-loop pretty printer using DDK's pretty printer *) let pp e = print_string (Dsrpp.pretty_print e);; (* ppeval evals then pretty prints the result *) let ppeval x = print_string "==> ";pp (eval x);; (* function rep is a read-eval-print function for DSR programs *) let rep s = ppeval (parse s);; (* Examples. *) let s1 = "Let Rec x1 x2 = If x2 = 1 Then (Function x3 -> x3 (x2 - 1)) (Function x4 -> x4) Else x1 (x2 - 1) In x1 100";; let ex1 = parse s1;; let result1 = eval ex1;; pp result1;; ppeval ex1;; rep s1;;