【问题标题】:Unbound structure Int when compiling useing CM.make使用 CM.make 编译时未绑定的结构 Int
【发布时间】:2019-10-22 12:07:07
【问题描述】:

我正在使用 CM 和 ML-Lex 编译一个词法分析器。当我尝试使用 CM.make "sources.cm" 进行编译时,它会抛出错误。

errormsg.sml:7.24-7.39 Error: unbound structure: TextIO in path TextIO.instream
errormsg.sml:21.26-21.38 Error: unbound structure: TextIO in path TextIO.stdIn
errormsg.sml:27.18-27.30 Error: unbound structure: TextIO in path TextIO.stdIn
errormsg.sml:36.12-36.24 Error: unbound structure: Int in path Int.toString

还有更多,就像以前的一样。如果我尝试使用“errormsg.sml”,一切正常。我尝试在 sources.cm 中移动 errormsg.sml。

来源.cm:

Group is

$/smlnj-lib.cm
driver.sml
tokens.sig
tokens.sml
errormsg.sml
tiger.lex

errormsg.sml:

signature ERRORMSG =
sig
    val anyErrors : bool ref
    val fileName : string ref
    val lineNum : int ref
    val linePos : int list ref
    val sourceStream : TextIO.instream ref
    val error : int -> string -> unit
    exception Error
    val impossible : string -> 'a   (* raises Error *)
    val reset : unit -> unit
end

structure ErrorMsg : ERRORMSG =
struct

  val anyErrors = ref false
  val fileName = ref ""
  val lineNum = ref 1
  val linePos = ref [1]
  val sourceStream = ref TextIO.stdIn

  fun reset() = (anyErrors:=false;
                 fileName:="";
                 lineNum:=1;
                 linePos:=[1];
                 sourceStream:=TextIO.stdIn)

  exception Error

  fun error pos (msg:string) =
      let fun look(a::rest,n) =
            if a<pos then app print [":",
                               Int.toString n,
                                       ".",
                                       Int.toString (pos-a)]
               else look(rest,n-1)
            | look _ = print "0.0"
       in anyErrors := true;
          print (!fileName);
          look(!linePos,!lineNum);
          print ":";
          print msg;
          print "\n"
      end

  fun impossible msg =
      (app print ["Error: Compiler bug: ",msg,"\n"];
       TextIO.flushOut TextIO.stdOut;
       raise Error)

end

【问题讨论】:

    标签: sml smlnj cm


    【解决方案1】:

    您需要将$/basis.cm 添加到您的sources.cm。这将导入标准 ML 基础库:

    Group is
    
    $/basis.cm
    $/smlnj-lib.cm
    driver.sml
    tokens.sig
    tokens.sml
    errormsg.sml
    tiger.lex
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-09
      • 1970-01-01
      相关资源
      最近更新 更多