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
10 val errorText
= ref
""
14 val sourceStream
= ref
TextIO.stdIn
16 fun print msg
= (errorText
:= !errorText ^ msg
;
19 (* Reset compiler to initial state
*)
20 fun reset() = (anyErrors
:=false;
26 sourceStream
:=TextIO.stdIn
)
28 fun notify f prefix
posopt (msg
:string) =
30 val (startpos
, endpos
) = Option
.getOpt (posopt
, (0, 0))
31 fun look(pos
,a
::rest
,n
) =
32 if a
<pos
then app print
[Int.toString n
,
35 else look(pos
,rest
,n
-1)
36 | look _
= print
"0.0"
39 print (!fileName
); print
":";
40 look(startpos
, !linePos
, !lineNum
);
41 if startpos
=endpos
then () else (print
"-"; look(endpos
, !linePos
, !lineNum
));
42 app print
[":", prefix
, ": ", msg
, "\n"]
45 val error
= notify (fn () => anyErrors
:= true) "error"
46 val warning
= notify (fn () => anyWarnings
:= true) "warning"