-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexceptions.ml
36 lines (32 loc) · 1 KB
/
exceptions.ml
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
exception LexerError of string
(* Messge, line number, char numbers *)
exception UnsuportedError of string * int * ((int * int) option)
(* Messge, line number *)
exception SyntaxError of string * (int option)
(* Message, line number *)
exception TypeError of string * int
(* Warnings (message, line number) *)
type warning = Warning of string * int
(*
All steps of the compilers will add warnings to this reference that
will be analized by main at the end of the compilation
*)
let warnings = ref [];;
let new_warning (w: warning) =
warnings := w :: (!warnings)
;;
(* Print all warnings that were accumulated *)
let print_warnings () =
let print_warning w =
match w with
| Warning (msg, l) ->
print_endline ("Line " ^ string_of_int l ^ "\nWarning: " ^ msg)
in
let rec print_warnings' ws =
match ws with
| [] -> ()
| w::ws' -> print_warning w; print_warnings' ws'
in
warnings := List.sort (fun (Warning (_, l1)) (Warning (_, l2)) -> l1 - l2) (!warnings);
print_warnings' (!warnings)
;;