SML# Document Version 4.0.0
30 A parser generator smlyacc and smllex

30.5 The interface file for the generated lexer

smllex generate a structure containing a lexer creating function makeLexer. In order to use the generated lexer program file, a interface file must be written. The minimal interface is of the following form.

    _require "basis.smi"
    _require "coreML.grm.smi"

    structure CoreMLLex =
    struct
      val makeLexer : (int -> string) -> unit -> CoreML.Tokens.token
    end

The first argument to the makeLexer is a function that takes a number and return an input string of that specified size. Applying this function to an input function like makeLexer (fn n => TextIO.inputN(TextIO.stdIn,n) generates a lexer function of type unit -> token. This lexer function can be specified as an argument to the makeStream function of the parser to obtain a token stream for the parser input.

User declarations such as extra arguments are placed in the UserDeclarations structure. Its interface file should be of the following form.

    _require "basis.smi"
    _require "<YaccInputFile>.grm.smi"

    structure MLLex =
    struct
      structure UserDeclarations =
      struct
        type token = <YaccName>.Tokens.token
        type pos = <YaccName>.Tokens.pos
        type arg (= boxed)
      end
      val makeLexer
          : (int -> string) -> UserDeclarations.arg -> unit -> UserDeclarations.token
    end