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
9 val anyWarnings
= ref
false
13 val sourceStream
= ref
TextIO.stdIn
15 fun print msg
= (TextIO.print msg
)
17 (* Reset compiler to initial state
*)
18 fun reset() = (anyErrors
:=false;
23 sourceStream
:=TextIO.stdIn
)
25 fun notify f prefix
posopt (msg
:string) =
27 val (startpos
, endpos
) = Option
.getOpt (posopt
, (0, 0))
28 fun look(pos
,a
::rest
,n
) =
29 if a
<pos
then app print
[Int.toString n
,
32 else look(pos
,rest
,n
-1)
33 | look _
= print
"0.0"
36 print (!fileName
); print
":";
37 look(startpos
, !linePos
, !lineNum
);
38 if startpos
=endpos
then () else (print
"-"; look(endpos
, !linePos
, !lineNum
));
39 app print
[":", prefix
, ": ", msg
, "\n"]
42 val error
= notify (fn () => anyErrors
:= true) "error"
43 val warning
= notify (fn () => anyWarnings
:= true) "warning"