structure Parser : PARSER = struct

  structure LambdaLrVals = LambdaLrValsFun(structure Token = LrParser.Token)
  structure LambdaLex = LambdaLexFun(structure Tokens = LambdaLrVals.Tokens)
  structure LambdaParser = Join(structure LrParser = LrParser
			     structure ParserData = LambdaLrVals.ParserData
			     structure Lex = LambdaLex)
    
  exception Error
  
  val invoke = fn lexstream =>
    let val error = fn (s, i, _) =>
      (print ("ERROR (Line " ^ (Int.toString i) ^ "): " ^ s ^ "\n");
       raise Error)
    in
      LambdaParser.parse(0, lexstream, error, ())
    end
  
  fun parse filename = 
    let
      val _ = LambdaLex.UserDeclarations.pos := 1
      val h = TextIO.openIn filename
      val lexer = LambdaParser.makeLexer (fn _ => TextIO.input h)
      val (result, _) = invoke lexer
    in
      result
    end
			   
end
