(* This file comes mostly from "Modern Compiler Implementation in ML," by Andrew Appel * http://www.cs.princeton.edu/~appel/modern/ml/ *) structure ErrorMsg :> ERRORMSG = struct (* Initial values of compiler state variables *) val anyErrors = ref false val errorText = ref "" val fileName = ref "" val lineNum = ref 1 val linePos = ref [1] val sourceStream = ref TextIO.stdIn fun print msg = (errorText := !errorText ^ msg; TextIO.print msg) (* Reset compiler to initial state *) fun reset() = (anyErrors:=false; errorText:=""; fileName:=""; lineNum:=1; linePos:=[1]; sourceStream:=TextIO.stdIn) (* Print the given error message *) fun error posopt (msg:string) = let val (startpos, endpos) = Option.getOpt (posopt, (0, 0)) fun look(pos,a::rest,n) = if a