-
Notifications
You must be signed in to change notification settings - Fork 1
/
expr.mli
64 lines (51 loc) · 1.92 KB
/
expr.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(*
CS 51 Final Project
MiniML -- Expressions
Spring 2017
*)
(* Abstract syntax of MiniML expressions *)
type unop =
| Negate
;;
type binop =
| Plus
| Minus
| Times
| Equals
| LessThan
;;
type expr =
| Var of varid (* variables *)
| Num of int (* integers *)
| Bool of bool (* booleans *)
| Unop of unop * expr (* unary operators *)
| Binop of binop * expr * expr (* binary operators *)
| Conditional of expr * expr * expr (* if then else *)
| Fun of varid * expr (* function definitions *)
| Let of varid * expr * expr (* local naming *)
| Letrec of varid * expr * expr (* recursive local naming *)
| Raise (* exceptions *)
| Unassigned (* (temporarily) unassigned *)
| App of expr * expr (* function applications *)
and varid = string
type varidset ;;
(* same_vars varids -- Test to see if two sets have the same elements
(for testing purposes) *)
val same_vars : varidset -> varidset -> bool ;;
(* vars_of_list varids -- Generate a set of variable names from a list
of varids (for testing purposes) *)
val vars_of_list : varid list -> varidset ;;
(* free_vars e -- Returns the set of varids corresponding to free
variables in e *)
val free_vars : expr -> varidset
(* new_varname () -- Return a freshly minted varid *)
val new_varname : unit -> varid
(* subst x p q -- Return the expression q with p substituted for free
occurrences of x *)
val subst : varid -> expr -> expr -> expr
(* exp_to_string e -- Return a string representation of the concrete
syntax of the expression e *)
val exp_to_string : expr -> string
(* exp_to_abstract_string e -- Return a string representation of the
abstract syntax of the expression e *)
val exp_to_abstract_string : expr -> string