| 1 |
(* parser.sml *) |
| 2 |
(* driver for Pascal parser *) |
| 3 |
|
| 4 |
structure Parser = |
| 5 |
struct |
| 6 |
|
| 7 |
structure PascalLrVals = PascalLrValsFun(structure Token = LrParser.Token) |
| 8 |
|
| 9 |
structure PascalLex = PascalLexFun(structure Tokens = PascalLrVals.Tokens) |
| 10 |
|
| 11 |
structure PascalParser = Join(structure Lex= PascalLex |
| 12 |
structure LrParser = LrParser |
| 13 |
structure ParserData = PascalLrVals.ParserData) |
| 14 |
|
| 15 |
fun parse s = |
| 16 |
let val dev = TextIO.openIn s |
| 17 |
val stream = PascalParser.makeLexer(fn i => TextIO.inputN(dev,i)) |
| 18 |
fun error (e,i:int,_) = |
| 19 |
TextIO.output(TextIO.stdOut, |
| 20 |
s ^ "," ^ " line " ^ (Int.toString i) ^ ", Error: " ^ e ^ "\n") |
| 21 |
in PascalLex.UserDeclarations.lineNum := 1; |
| 22 |
PascalParser.parse(30,stream,error,()) |
| 23 |
before TextIO.closeIn dev |
| 24 |
end |
| 25 |
|
| 26 |
fun keybd () = |
| 27 |
let val stream = |
| 28 |
PascalParser.makeLexer (fn i => (case TextIO.inputLine TextIO.stdIn |
| 29 |
of SOME s => s |
| 30 |
| _ => "")) |
| 31 |
fun error (e,i:int,_) = |
| 32 |
TextIO.output(TextIO.stdOut, |
| 33 |
"std_in," ^ " line " ^ (Int.toString i) ^ ", Error: " ^ e ^ "\n") |
| 34 |
in PascalLex.UserDeclarations.lineNum := 1; |
| 35 |
PascalParser.parse(0,stream,error,()) |
| 36 |
end |
| 37 |
|
| 38 |
end (* structure Parser *) |