annotate lab2/check.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 (* lab2/check.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 (*
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
5 This module is the semantic analysis pass of the compiler. It
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
6 provides a single function |annotate| that takes a program, checks it
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
7 for semantic errors, and annotates each applied occurrence of an
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
8 identifier with the corresponding definition. These annotations are
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
9 used by the code generation pass to generate code for variable
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
10 references.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
11
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
12 If a semantic error is detected, |annotate| raises the exception
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
13 |Semantic_error|. Its arguments are a line number and a format and
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
14 argument list that can be passed to printf to print the message.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
15 Because there is no way of resuming the analysis, only one error can
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
16 be detected per run of the compiler.
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
17 *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
18
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
19 (* |annotate| -- check tree for type errors and annotate with definitions *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
20 val annotate : Tree.program -> unit
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
21
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
22 (* |Semantic_error| -- exception raised if error detected *)
Mike Spivey <mike@cs.ox.ac.uk>
parents:
diff changeset
23 exception Semantic_error of string * Print.arg list * int