1 (***********************************************************************)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the Q Public License version 1.0. *)
11 (***********************************************************************)
15 (* The lexer generator. Command-line parsing. *)
24 if Array.length
Sys.argv
<> 2 then begin
25 prerr_string
"Usage: camllex <input file>\n";
28 let source_name = Sys.argv
.(1) in
30 if Filename.check_suffix
source_name ".mll" then
31 Filename.chop_suffix
source_name ".mll" ^
".ml"
33 source_name ^
".ml" in
34 ic
:= open_in
source_name;
35 oc
:= open_out
dest_name;
36 let lexbuf = Lexing.from_channel
!ic
in
37 let (Lexdef
(header
,_
) as def
) =
39 Grammar.lexer_definition
Scanner.main lexbuf
41 Parsing.Parse_error
->
42 prerr_string
"Syntax error around char ";
43 prerr_int
(Lexing.lexeme_start
lexbuf);
46 | Scan_aux.Lexical_error s
->
47 prerr_string
"Lexical error around char ";
48 prerr_int
(Lexing.lexeme_start
lexbuf);
53 let ((init
, states
, acts
) as dfa
) = make_dfa def
in
54 output_lexdef header dfa
;
58 let _ = main(); exit
0
65 let lexbuf = lexing.from_channel ic in
66 let (Lexdef(header,_) as def) =
68 grammar.lexer_definition scanner.main lexbuf
70 parsing.Parse_error x ->
71 prerr_string "Syntax error around char ";
72 prerr_int (lexing.lexeme_start lexbuf);
75 | scan_aux.Lexical_error s ->
76 prerr_string "Lexical error around char ";
77 prerr_int (lexing.lexeme_start lexbuf);
82 let ((init, states, acts) as dfa) = make_dfa def in
83 output_lexdef header dfa
88 let debug_scanner lexbuf =
89 let tok = scanner.main lexbuf in
91 Tident s -> prerr_string "Tident "; prerr_string s
92 | Tchar c -> prerr_string "Tchar "; prerr_char c
93 | Tstring s -> prerr_string "Tstring "; prerr_string s
94 | Taction(Location(i1,i2)) ->
95 prerr_string "Taction "; prerr_int i1; prerr_string "-";
97 | Trule -> prerr_string "Trule"
98 | Tparse -> prerr_string "Tparse"
99 | Tand -> prerr_string "Tand"
100 | Tequal -> prerr_string "Tequal"
101 | Tend -> prerr_string "Tend"
102 | Tor -> prerr_string "Tor"
103 | Tunderscore -> prerr_string "Tunderscore"
104 | Teof -> prerr_string "Teof"
105 | Tlbracket -> prerr_string "Tlbracket"
106 | Trbracket -> prerr_string "Trbracket"
107 | Tstar -> prerr_string "Tstar"
108 | Tmaybe -> prerr_string "Tmaybe"
109 | Tplus -> prerr_string "Tplus"
110 | Tlparen -> prerr_string "Tlparen"
111 | Trparen -> prerr_string "Trparen"
112 | Tcaret -> prerr_string "Tcaret"
113 | Tdash -> prerr_string "Tdash"