1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* The lexer generator. Command-line parsing. *)
|
|
|
|
|
|
|
|
open Syntax
|
|
|
|
open Lexgen
|
|
|
|
open Output
|
|
|
|
|
|
|
|
let main () =
|
|
|
|
if Array.length Sys.argv != 2 then begin
|
1996-06-04 08:12:23 -07:00
|
|
|
prerr_endline "Usage: ocamllex <input file>";
|
1995-05-04 03:15:53 -07:00
|
|
|
exit 2
|
|
|
|
end;
|
|
|
|
let source_name = Sys.argv.(1) in
|
|
|
|
let dest_name =
|
|
|
|
if Filename.check_suffix source_name ".mll" then
|
|
|
|
Filename.chop_suffix source_name ".mll" ^ ".ml"
|
|
|
|
else
|
|
|
|
source_name ^ ".ml" in
|
1996-02-25 06:45:47 -08:00
|
|
|
let ic = open_in_bin source_name in
|
|
|
|
let oc = open_out dest_name in
|
|
|
|
let lexbuf = Lexing.from_channel ic in
|
1995-08-25 06:54:14 -07:00
|
|
|
let def =
|
1995-05-04 03:15:53 -07:00
|
|
|
try
|
|
|
|
Parser.lexer_definition Lexer.main lexbuf
|
|
|
|
with exn ->
|
1996-02-25 06:45:47 -08:00
|
|
|
close_out oc;
|
1995-05-04 03:15:53 -07:00
|
|
|
Sys.remove dest_name;
|
|
|
|
begin match exn with
|
|
|
|
Parsing.Parse_error ->
|
|
|
|
prerr_string "Syntax error around char ";
|
|
|
|
prerr_int (Lexing.lexeme_start lexbuf);
|
|
|
|
prerr_endline "."
|
|
|
|
| Lexer.Lexical_error s ->
|
|
|
|
prerr_string "Lexical error around char ";
|
|
|
|
prerr_int (Lexing.lexeme_start lexbuf);
|
|
|
|
prerr_string ": ";
|
|
|
|
prerr_string s;
|
|
|
|
prerr_endline "."
|
|
|
|
| _ -> raise exn
|
|
|
|
end;
|
|
|
|
exit 2 in
|
1996-02-25 06:45:47 -08:00
|
|
|
let (entries, transitions) = Lexgen.make_dfa def in
|
|
|
|
let tables = Compact.compact_tables transitions in
|
|
|
|
Output.output_lexdef ic oc def.header tables entries def.trailer;
|
|
|
|
close_in ic;
|
|
|
|
close_out oc
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
let _ = Printexc.catch main (); exit 0
|
|
|
|
|