annotate lab3/tree.mli @ 0:bfdcc3820b32

Basis
author Mike Spivey <mike@cs.ox.ac.uk>
date Thu, 05 Oct 2017 08:04:15 +0100
parents
children
rev   line source
0
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
1 (* lab3/tree.mli *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
2 (* Copyright (c) 2017 J. M. Spivey *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
3
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
4 open Dict
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 (* |name| -- type for applied occurrences with annotations *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 type name =
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 { x_name: ident; (* Name of the reference *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 x_line: int; (* Line number *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 mutable x_def: def option} (* Definition in scope *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 type expr =
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 Constant of int
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 | Variable of name
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 | Monop of Keiko.op * expr
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 | Binop of Keiko.op * expr * expr
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 | Call of name * expr list
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 type stmt =
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 Skip
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21 | Seq of stmt list
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 | Assign of name * expr
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 | Return of expr
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
24 | IfStmt of expr * stmt * stmt
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
25 | WhileStmt of expr * stmt
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
26 | Print of expr
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
27 | Newline
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
28
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
29 type block = Block of ident list * proc list * stmt
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
30
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
31 and proc = Proc of name * ident list * block
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
32
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
33 type program = Program of block
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
34
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
35
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
36 (* seq -- neatly join a list of statements into a sequence *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
37 val seq : stmt list -> stmt
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
38
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
39 val makeName : ident -> int -> name
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
40
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
41 (* |get_def| -- rerieve definition from name *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
42 val get_def : name -> def
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
43
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
44 (* |print_tree| -- pretty-print a tree *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
45 val print_tree : out_channel -> program -> unit