1: # 808 "./lpsrc/flx_tokeniser.ipk" 2: open Flx_mtypes2 3: open Flx_flxopt 4: open Flx_getopt 5: open Flx_types 6: open Flx_version 7: open Flx_parse 8: open Flx_prelex 9: ;; 10: 11: let print_elkhound_tokens toks = 12: let nt x = name_of_token x in 13: List.iter 14: ( 15: fun x -> 16: match x with 17: | NAME (s,id) -> 18: print_endline (nt x ^ " " ^ id) 19: | INTEGER (s,t,v) -> 20: print_endline (nt x ^ " " ^ 21: t^","^Big_int.string_of_big_int v 22: ) 23: | FLOAT (s,t,v) -> 24: print_endline (nt x ^ " " ^ 25: t^","^v 26: ) 27: | STRING (sr,s) -> 28: print_endline (nt x ^ " " ^ 29: Flx_string.c_quote_of_string s 30: ) 31: | CSTRING (sr,s) -> 32: print_endline (nt x ^ " " ^ 33: Flx_string.c_quote_of_string s 34: ) 35: | WSTRING (sr,s) -> 36: print_endline (nt x ^ " " ^ 37: Flx_string.c_quote_of_string s 38: ) 39: | USTRING (sr,s) -> 40: print_endline (nt x ^ " " ^ 41: Flx_string.c_quote_of_string s 42: ) 43: | _ -> 44: print_endline (Flx_prelex.name_of_token x) 45: ) 46: toks 47: ;; 48: 49: let print_help () = print_options(); exit(0) 50: ;; 51: 52: let run() = 53: let raw_options = parse_options Sys.argv in 54: let compiler_options = get_felix_options raw_options in 55: 56: if check_keys raw_options ["h"; "help"] 57: then print_help () 58: ; 59: if check_key raw_options "version" 60: then (print_endline ("Felix Version " ^ !version_data.version_string)) 61: ; 62: if compiler_options.print_flag then begin 63: print_string "//Include directories = "; 64: List.iter (fun d -> print_string (d ^ " ")) 65: compiler_options.include_dirs; 66: print_endline "" 67: end 68: ; 69: 70: let elkhound_test = check_key raw_options "elkhound" in 71: let filename = 72: match get_key_value raw_options "" with 73: | Some s -> s 74: | None -> exit 0 75: in 76: let filebase = filename in 77: let input_file_name = filebase ^ ".flx" in 78: 79: if compiler_options.print_flag then begin 80: print_endline "---------------------------------------"; 81: print_endline ("Lexing " ^ input_file_name); 82: print_endline "---------------------------------------"; 83: print_endline "Pre tokens" 84: end; 85: 86: let pretokens = 87: Flx_pretok.pre_tokens_of_filename 88: input_file_name 89: (Filename.dirname input_file_name) 90: compiler_options.include_dirs 91: Flx_macro.expand_expression 92: in 93: if compiler_options.print_flag then begin 94: Flx_tok.print_pre_tokens pretokens; 95: print_endline "---------------------------------------"; 96: print_endline "Tokens" 97: end 98: ; 99: let tokens = Flx_lex1.translate pretokens in 100: if not elkhound_test || compiler_options.print_flag then 101: Flx_tok.print_tokens tokens; 102: if compiler_options.print_flag then begin 103: print_endline "---------------------------------------" 104: end 105: ; 106: if elkhound_test then begin 107: print_elkhound_tokens tokens; 108: end 109: 110: in 111: run() 112: ;; 113: