modern-compiler-ml/tiger/chap3/parsetest.sml
jmug 33d8bac511 Add the tiger source code bundle from the book site
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
2024-12-18 15:18:45 -08:00

22 lines
773 B
Standard ML

structure Parse : sig val parse : string -> unit end =
struct
structure TigerLrVals = TigerLrValsFun(structure Token = LrParser.Token)
structure Lex = TigerLexFun(structure Tokens = TigerLrVals.Tokens)
structure TigerP = Join(structure ParserData = TigerLrVals.ParserData
structure Lex=Lex
structure LrParser = LrParser)
fun parse filename =
let val _ = (ErrorMsg.reset(); ErrorMsg.fileName := filename)
val file = TextIO.openIn filename
fun get _ = TextIO.input file
fun parseerror(s,p1,p2) = ErrorMsg.error p1 s
val lexer = LrParser.Stream.streamify (Lex.makeLexer get)
val (absyn, _) = TigerP.parse(30,lexer,parseerror,())
in TextIO.closeIn file;
absyn
end handle LrParser.ParseError => raise ErrorMsg.Error
end