home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-08-18 | 1.7 KB | 54 lines | [TEXT/R*ch] |
- (* The lexer generator. Command-line parsing. *)
-
- open Lexing Parsing Miscsys;
- open Syntax Scanner Grammar Lexgen Output;
-
- (* Lexer of stream *)
-
- fun createLexerStream (is : BasicIO.instream) =
- Lexing.createLexer (fn buff => fn n => Nonstdio.buff_input is buff 0 n)
- ;
-
- fun main () =
- let val () =
- if Vector.length command_line <> 2 then
- (output(std_err, "Usage: mosmllex <input file>\n");
- flush_out std_err;
- BasicIO.exit 2)
- else ()
- val source_name = Vector.sub(command_line, 1)
- val dest_name =
- if Filename.check_suffix source_name ".lex" then
- Filename.chop_suffix source_name ".lex" ^ ".sml"
- else
- source_name ^ ".sml"
- val () = (is := open_in_bin source_name)
- val () = (os := open_out dest_name)
- val lexbuf =
- createLexerStream (!is)
- val def as Lexdef(header,_) =
- lexer_definition Scanner.main lexbuf
- handle
- ParseError x =>
- (output(std_err, "Syntax error around char ");
- output(std_err, makestring (getLexemeStart lexbuf));
- output(std_err, ".\n"); flush_out std_err;
- BasicIO.exit 2)
- | Scan_aux.Lexical_error s =>
- (output(std_err, "Lexical error around char ");
- output(std_err, makestring (getLexemeStart lexbuf));
- output(std_err, ": ");
- output(std_err, s);
- output(std_err, ".\n"); flush_out std_err;
- BasicIO.exit 2)
- val dfa as (init, states, acts) = make_dfa def
- in
- output_lexdef header dfa;
- close_in (!is);
- close_out (!os);
- BasicIO.exit 0
- end
- ;
-
- val () = Printexc.f main ();
-