|
|
1.1 root 1: (* Copyright 1989 by AT&T Bell Laboratories *)
2: signature LEX = sig
3: type lexer
4: val mkLex : {stream : instream, interactive : bool} ->
5: {nextToken : Token.token ref,
6: prompt : string ref,
7: advance : unit -> unit}
8: end
9:
10: structure Lex : LEX =
11: struct
12: type lexer ={nextToken : Token.token ref,
13: prompt : string ref,
14: advance : unit -> unit}
15:
16: fun mkLex{stream,interactive} =
17: let val prompt = ref ""
18: val lexarg = {comLevel = ref 0, lineNum = ErrorMsg.lineNum,
19: complain = ErrorMsg.complain}
20:
21: val nextToken = ref Token.SEMICOLON
22:
23: val doprompt = ref true
24:
25: fun getline _ =(if !doprompt then (output std_out (!prompt);
26: flush_out std_out;
27: doprompt := false)
28: else ();
29: let val s = input_line stream
30: in doprompt := (ordof(s,size s - 1)=ord("\n")
31: handle Ord => false);
32: s
33: end)
34:
35: val get = Mlex.makeLexer(if interactive then getline else input stream)
36: lexarg
37: fun advance() = nextToken := get()
38:
39: in {nextToken=nextToken, prompt=prompt, advance=advance}
40: end
41:
42: end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.