X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=compiler%2Fsrc%2Fexe%2Ftigerc.ml;h=c6be0d80926355649a68abe103a853e0da0766f0;hb=b197ea75a0b71adaa09c3f6c95c93a2393512066;hp=708ff17c97bada7eba22402ffcfd2437ca3d1b2b;hpb=cda83e5ec171672a59966d2bd9cd28bd7a8fe083;p=tiger.ml.git diff --git a/compiler/src/exe/tigerc.ml b/compiler/src/exe/tigerc.ml index 708ff17..c6be0d8 100644 --- a/compiler/src/exe/tigerc.ml +++ b/compiler/src/exe/tigerc.ml @@ -1,16 +1,19 @@ +let lexbuf_set_filename lb filename : unit = + let Lexing.({lex_start_p; lex_curr_p; _}) = lb in + lb.Lexing.lex_start_p <- {lex_start_p with Lexing.pos_fname = filename}; + lb.Lexing.lex_curr_p <- {lex_curr_p with Lexing.pos_fname = filename} + let () = let path_to_program_file = Sys.argv.(1) in let ic = open_in path_to_program_file in let lexbuf = Lexing.from_channel ic in + lexbuf_set_filename lexbuf path_to_program_file; (match Tiger.Parser.program Tiger.Lexer.token lexbuf with - | exception Parsing.Parse_error -> - let - Lexing.({lex_curr_p = {pos_lnum; pos_bol; pos_cnum; _}; _}) = lexbuf - in - Printf.printf - "Syntax error in file %S, around line: %d, column: %d\n" - path_to_program_file pos_lnum (pos_cnum - pos_bol) + | exception Tiger.Error.T error -> + Printf.eprintf "%s\n" (Tiger.Error.to_string error); + exit 1; | absyn -> + Tiger.Semant.transProg absyn; print_endline (Tiger.Absyn.to_string absyn) ); close_in ic;