1 (* This file comes mostly from
"Modern Compiler Implementation in ML," by Andrew Appel
2 * http
://www
.cs
.princeton
.edu
/~appel
/modern
/ml
/
5 structure ErrorMsg
:> ERRORMSG
=
7 (* Initial values
of compiler state variables
*)
8 val anyErrors
= ref
false
13 val sourceStream
= ref
TextIO.stdIn
15 fun print msg
= (errorText
:= !errorText ^ msg
;
18 (* Reset compiler to initial state
*)
19 fun reset() = (anyErrors
:=false;
24 sourceStream
:=TextIO.stdIn
)
26 (* Print the given error message
*)
27 fun error
posopt (msg
:string) =
29 val (startpos
, endpos
) = Option
.getOpt (posopt
, (0, 0))
30 fun look(pos
,a
::rest
,n
) =
31 if a
<pos
then app print
[Int.toString n
,
34 else look(pos
,rest
,n
-1)
35 | look _
= print
"0.0"
38 print (!fileName
); print
":";
39 look(startpos
, !linePos
, !lineNum
);
40 if startpos
=endpos
then () else (print
"-"; look(endpos
, !linePos
, !lineNum
));
41 app print
[":error: ", msg
, "\n"]